Sat, 16 Apr 2005 18:44:40 +0000
[gaim-migrate @ 12503]
Fix bug #1016434 - "MSN phone numbers don't appear changed until next logon"
| 7014 | 1 | /* |
| 2 | * gaim - Jabber Protocol Plugin | |
| 3 | * | |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | ||
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10646
diff
changeset
|
23 | #include "cipher.h" |
| 7014 | 24 | #include "debug.h" |
| 25 | #include "notify.h" | |
| 26 | #include "request.h" | |
| 27 | #include "server.h" | |
| 9954 | 28 | #include "status.h" |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
29 | #include "util.h" |
| 7014 | 30 | |
| 31 | #include "buddy.h" | |
| 32 | #include "chat.h" | |
| 33 | #include "presence.h" | |
| 34 | #include "iq.h" | |
| 35 | #include "jutil.h" | |
| 36 | #include "xmlnode.h" | |
| 37 | ||
| 38 | ||
| 39 | static void chats_send_presence_foreach(gpointer key, gpointer val, | |
| 40 | gpointer user_data) | |
| 41 | { | |
| 42 | JabberChat *chat = val; | |
| 43 | xmlnode *presence = user_data; | |
| 8577 | 44 | char *chat_full_jid; |
| 45 | ||
| 46 | if(!chat->conv) | |
| 47 | return; | |
| 48 | ||
| 49 | chat_full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, | |
| 8401 | 50 | chat->handle); |
| 7014 | 51 | |
| 8401 | 52 | xmlnode_set_attrib(presence, "to", chat_full_jid); |
| 7014 | 53 | jabber_send(chat->js, presence); |
| 8401 | 54 | g_free(chat_full_jid); |
| 7014 | 55 | } |
| 56 | ||
| 9954 | 57 | void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) { |
| 10286 | 58 | char *my_base_jid; |
| 59 | ||
| 60 | if(!js->user) | |
| 61 | return; | |
| 62 | ||
| 63 | my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
| 8185 | 64 | if(gaim_find_buddy(js->gc->account, my_base_jid)) { |
| 65 | JabberBuddy *jb; | |
| 66 | JabberBuddyResource *jbr; | |
| 67 | if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) { | |
| 9954 | 68 | JabberBuddyState state; |
| 69 | const char *msg; | |
| 70 | int priority; | |
| 71 | ||
| 72 | gaim_status_to_jabber(gstatus, &state, &msg, &priority); | |
| 73 | ||
| 10490 | 74 | if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
75 | jabber_buddy_remove_resource(jb, js->user->resource); |
|
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
76 | } else { |
| 9954 | 77 | jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); |
|
9744
c2b450de1fc0
[gaim-migrate @ 10609]
Daniel Atallah <datallah@pidgin.im>
parents:
9743
diff
changeset
|
78 | } |
| 9954 | 79 | if((jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 9990 | 80 | gaim_prpl_got_user_status(js->gc->account, my_base_jid, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 81 | } else { |
| 9990 | 82 | gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); |
| 9954 | 83 | } |
| 8185 | 84 | } |
| 85 | } | |
| 86 | g_free(my_base_jid); | |
| 87 | } | |
| 88 | ||
| 7014 | 89 | |
| 10216 | 90 | void jabber_presence_send(GaimAccount *account, GaimStatus *status) |
| 7014 | 91 | { |
|
10382
32e07712e224
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
92 | GaimConnection *gc = NULL; |
|
32e07712e224
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
93 | JabberStream *js = NULL; |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
94 | gboolean connected; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
95 | int primitive; |
| 10189 | 96 | xmlnode *presence, *x, *photo; |
| 7014 | 97 | char *stripped = NULL; |
| 9954 | 98 | const char *msg; |
| 99 | JabberBuddyState state; | |
| 100 | int priority; | |
| 7014 | 101 | |
| 10486 | 102 | if(!gaim_status_is_active(status)) |
| 103 | return; | |
| 104 | ||
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
105 | connected = gaim_account_is_connected(account); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
106 | primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
107 | |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
108 | if(primitive != GAIM_STATUS_OFFLINE && !connected) { |
|
10738
63ca8277c234
[gaim-migrate @ 12340]
Mark Doliner <markdoliner@pidgin.im>
parents:
10722
diff
changeset
|
109 | gaim_account_connect(account); |
|
10755
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
110 | } else if(primitive == GAIM_STATUS_OFFLINE && connected) { |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
111 | gaim_account_disconnect(account); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
112 | } |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
113 | |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
114 | if(!connected) |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
115 | return; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
116 | |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
117 | gc = gaim_account_get_connection(account); |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
118 | js = gc->proto_data; |
|
a336a5d3102d
[gaim-migrate @ 12358]
Mark Doliner <markdoliner@pidgin.im>
parents:
10738
diff
changeset
|
119 | |
| 9954 | 120 | gaim_status_to_jabber(status, &state, &msg, &priority); |
| 121 | ||
| 122 | if(msg) | |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
123 | gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
| 7014 | 124 | |
| 9954 | 125 | presence = jabber_presence_create(state, stripped, priority); |
| 126 | g_free(stripped); | |
| 7014 | 127 | |
| 128 | jabber_send(js, presence); | |
| 10189 | 129 | |
| 130 | if(js->avatar_hash) { | |
| 131 | x = xmlnode_new_child(presence, "x"); | |
| 132 | xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update"); | |
| 133 | photo = xmlnode_new_child(x, "photo"); | |
| 134 | xmlnode_insert_data(photo, js->avatar_hash, -1); | |
| 135 | } | |
| 136 | ||
| 7014 | 137 | g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
| 138 | xmlnode_free(presence); | |
| 8185 | 139 | |
| 9954 | 140 | jabber_presence_fake_to_self(js, status); |
| 141 | ||
| 7014 | 142 | } |
| 143 | ||
| 9954 | 144 | xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
| 7014 | 145 | { |
| 146 | xmlnode *show, *status, *presence; | |
| 9954 | 147 | const char *show_string = NULL; |
| 7014 | 148 | |
| 149 | ||
| 150 | presence = xmlnode_new("presence"); | |
| 151 | ||
| 152 | ||
| 9954 | 153 | if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
| 154 | xmlnode_set_attrib(presence, "type", "unavailable"); | |
| 155 | else if(state != JABBER_BUDDY_STATE_ONLINE && | |
| 156 | state != JABBER_BUDDY_STATE_UNKNOWN && | |
| 157 | state != JABBER_BUDDY_STATE_ERROR) | |
| 158 | show_string = jabber_buddy_state_get_status_id(state); | |
| 159 | ||
| 160 | if(show_string) { | |
| 161 | show = xmlnode_new_child(presence, "show"); | |
| 162 | xmlnode_insert_data(show, show_string, -1); | |
| 7014 | 163 | } |
| 164 | ||
| 9954 | 165 | if(msg) { |
| 7014 | 166 | status = xmlnode_new_child(presence, "status"); |
| 167 | xmlnode_insert_data(status, msg, -1); | |
| 168 | } | |
| 169 | ||
| 170 | return presence; | |
| 171 | } | |
| 172 | ||
| 173 | struct _jabber_add_permit { | |
| 174 | GaimConnection *gc; | |
| 175 | char *who; | |
| 176 | }; | |
| 177 | ||
| 178 | static void authorize_add_cb(struct _jabber_add_permit *jap) | |
| 179 | { | |
| 180 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 181 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 182 | "subscribed"); | |
| 183 | ||
| 184 | if(!gaim_find_buddy(jap->gc->account, jap->who)) | |
|
7015
bea9111282b3
[gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
185 | gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); |
| 7014 | 186 | } |
| 187 | ||
| 188 | g_free(jap->who); | |
| 189 | g_free(jap); | |
| 190 | } | |
| 191 | ||
| 192 | static void deny_add_cb(struct _jabber_add_permit *jap) | |
| 193 | { | |
| 194 | if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
| 195 | jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
| 196 | "unsubscribed"); | |
| 197 | } | |
| 198 | ||
| 199 | g_free(jap->who); | |
| 200 | g_free(jap); | |
| 201 | } | |
| 202 | ||
| 10189 | 203 | static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
| 204 | { | |
| 205 | GaimBuddy *b = NULL; | |
| 206 | xmlnode *vcard, *photo; | |
| 207 | char *text, *data; | |
| 208 | int size; | |
| 209 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 210 | ||
| 211 | if(!from) | |
| 212 | return; | |
| 213 | ||
| 214 | if((vcard = xmlnode_get_child(packet, "vCard")) || | |
| 215 | (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 216 | if((photo = xmlnode_get_child(vcard, "PHOTO"))) { | |
| 217 | if((text = xmlnode_get_data(photo))) { | |
| 218 | gaim_base64_decode(text, &data, &size); | |
| 219 | ||
| 220 | gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); | |
| 221 | if((b = gaim_find_buddy(js->gc->account, from))) { | |
| 222 | unsigned char hashval[20]; | |
| 223 | char hash[41], *p; | |
| 224 | int i; | |
| 225 | ||
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10646
diff
changeset
|
226 | gaim_cipher_digest_region("sha1", (guint8 *)data, size, |
| 10687 | 227 | sizeof(hashval), hashval, NULL); |
| 228 | p = hash; | |
| 10189 | 229 | for(i=0; i<20; i++, p+=2) |
| 230 | snprintf(p, 3, "%02x", hashval[i]); | |
| 231 | gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
| 232 | } | |
| 233 | } | |
| 234 | } | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 7014 | 238 | void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
| 239 | { | |
| 240 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 241 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 7944 | 242 | const char *real_jid = NULL; |
| 9152 | 243 | const char *affiliation = NULL; |
| 244 | const char *role = NULL; | |
| 7014 | 245 | char *status = NULL; |
| 246 | int priority = 0; | |
| 247 | JabberID *jid; | |
| 248 | JabberChat *chat; | |
| 249 | JabberBuddy *jb; | |
| 9954 | 250 | JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
251 | GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
252 | gboolean delayed = FALSE; |
| 10189 | 253 | GaimBuddy *b = NULL; |
| 7014 | 254 | char *buddy_name; |
| 9954 | 255 | JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
| 7014 | 256 | xmlnode *y; |
| 257 | gboolean muc = FALSE; | |
| 10189 | 258 | char *avatar_hash = NULL; |
| 7014 | 259 | |
| 260 | ||
| 8043 | 261 | if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 262 | return; | |
| 263 | ||
| 264 | if(!(jid = jabber_id_new(from))) | |
| 7280 | 265 | return; |
| 266 | ||
| 7014 | 267 | if(jb->error_msg) { |
| 268 | g_free(jb->error_msg); | |
| 269 | jb->error_msg = NULL; | |
| 270 | } | |
| 271 | ||
| 7813 | 272 | if(type && !strcmp(type, "error")) { |
| 8401 | 273 | char *msg = jabber_parse_error(js, packet); |
| 7644 | 274 | |
| 9954 | 275 | state = JABBER_BUDDY_STATE_ERROR; |
| 8401 | 276 | jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
| 7813 | 277 | } else if(type && !strcmp(type, "subscribe")) { |
| 7014 | 278 | struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
| 279 | char *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), from); | |
| 280 | jap->gc = js->gc; | |
| 281 | jap->who = g_strdup(from); | |
| 282 | ||
| 10189 | 283 | gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
|
10116
054b064145a1
[gaim-migrate @ 11153]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9990
diff
changeset
|
284 | jap, 2, |
| 7014 | 285 | _("Authorize"), G_CALLBACK(authorize_add_cb), |
| 286 | _("Deny"), G_CALLBACK(deny_add_cb)); | |
| 287 | g_free(msg); | |
| 8043 | 288 | jabber_id_free(jid); |
| 7145 | 289 | return; |
| 7813 | 290 | } else if(type && !strcmp(type, "subscribed")) { |
| 7014 | 291 | /* we've been allowed to see their presence, but we don't care */ |
| 8043 | 292 | jabber_id_free(jid); |
| 7014 | 293 | return; |
| 294 | } else { | |
| 295 | if((y = xmlnode_get_child(packet, "show"))) { | |
| 296 | char *show = xmlnode_get_data(y); | |
| 9954 | 297 | state = jabber_buddy_status_id_get_state(show); |
| 7014 | 298 | g_free(show); |
| 299 | } else { | |
| 9954 | 300 | state = JABBER_BUDDY_STATE_ONLINE; |
| 7014 | 301 | } |
| 302 | } | |
| 303 | ||
| 7310 | 304 | |
| 7014 | 305 | for(y = packet->child; y; y = y->next) { |
| 8135 | 306 | if(y->type != XMLNODE_TYPE_TAG) |
| 7014 | 307 | continue; |
| 308 | ||
| 309 | if(!strcmp(y->name, "status")) { | |
| 7615 | 310 | g_free(status); |
| 7014 | 311 | status = xmlnode_get_data(y); |
| 312 | } else if(!strcmp(y->name, "priority")) { | |
| 313 | char *p = xmlnode_get_data(y); | |
| 314 | if(p) { | |
| 315 | priority = atoi(p); | |
| 316 | g_free(p); | |
| 317 | } | |
| 318 | } else if(!strcmp(y->name, "x")) { | |
| 319 | const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
320 | if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 9847 | 321 | /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
322 | delayed = TRUE; |
|
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
323 | } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { |
| 7629 | 324 | xmlnode *z; |
| 325 | ||
| 7014 | 326 | muc = TRUE; |
| 7629 | 327 | if((z = xmlnode_get_child(y, "status"))) { |
| 328 | const char *code = xmlnode_get_attrib(z, "code"); | |
| 329 | if(code && !strcmp(code, "201")) { | |
| 7895 | 330 | chat = jabber_chat_find(js, jid->node, jid->domain); |
| 8396 | 331 | chat->config_dialog_type = GAIM_REQUEST_ACTION; |
| 332 | chat->config_dialog_handle = | |
| 333 | gaim_request_action(js->gc, _("Create New Room"), | |
| 7895 | 334 | _("Create New Room"), |
| 335 | _("You are creating a new room. Would you like to " | |
| 336 | "configure it, or accept the default settings?"), | |
| 337 | 1, chat, 2, _("Configure Room"), | |
| 7923 | 338 | G_CALLBACK(jabber_chat_request_room_configure), |
| 7895 | 339 | _("Accept Defaults"), |
| 340 | G_CALLBACK(jabber_chat_create_instant_room)); | |
| 7629 | 341 | } |
| 342 | } | |
| 7944 | 343 | if((z = xmlnode_get_child(y, "item"))) { |
| 344 | real_jid = xmlnode_get_attrib(z, "jid"); | |
| 9152 | 345 | affiliation = xmlnode_get_attrib(z, "affiliation"); |
| 346 | role = xmlnode_get_attrib(z, "role"); | |
| 9931 | 347 | if(affiliation != NULL && !strcmp(affiliation, "owner")) |
| 348 | flags |= GAIM_CBFLAGS_FOUNDER; | |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
349 | if (role != NULL) { |
|
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
350 | if (!strcmp(role, "moderator")) |
| 9931 | 351 | flags |= GAIM_CBFLAGS_OP; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
352 | else if (!strcmp(role, "participant")) |
| 9931 | 353 | flags |= GAIM_CBFLAGS_VOICE; |
|
9743
839b2bce3853
[gaim-migrate @ 10608]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9559
diff
changeset
|
354 | } |
| 7944 | 355 | } |
| 10189 | 356 | } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
| 357 | xmlnode *photo = xmlnode_get_child(y, "photo"); | |
| 358 | if(photo) { | |
| 359 | if(avatar_hash) | |
| 360 | g_free(avatar_hash); | |
| 361 | avatar_hash = xmlnode_get_data(photo); | |
| 362 | } | |
| 7014 | 363 | } |
| 364 | } | |
| 365 | } | |
| 366 | ||
| 367 | ||
| 7322 | 368 | if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
| 8462 | 369 | static int i = 1; |
| 7014 | 370 | char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 371 | ||
| 9954 | 372 | if(state == JABBER_BUDDY_STATE_ERROR) { |
| 8401 | 373 | char *title, *msg = jabber_parse_error(js, packet); |
| 7014 | 374 | |
| 7321 | 375 | if(chat->conv) { |
| 8401 | 376 | title = g_strdup_printf(_("Error in chat %s"), from); |
| 7321 | 377 | serv_got_chat_left(js->gc, chat->id); |
| 378 | } else { | |
| 8401 | 379 | title = g_strdup_printf(_("Error joining chat %s"), from); |
| 7321 | 380 | } |
| 8401 | 381 | gaim_notify_error(js->gc, title, title, msg); |
| 382 | g_free(title); | |
| 383 | g_free(msg); | |
| 7014 | 384 | |
| 385 | jabber_chat_destroy(chat); | |
| 7310 | 386 | jabber_id_free(jid); |
| 7615 | 387 | g_free(status); |
| 8182 | 388 | g_free(room_jid); |
| 10189 | 389 | if(avatar_hash) |
| 390 | g_free(avatar_hash); | |
| 7014 | 391 | return; |
| 392 | } | |
| 393 | ||
| 394 | ||
| 7813 | 395 | if(type && !strcmp(type, "unavailable")) { |
| 7972 | 396 | gboolean nick_change = FALSE; |
| 7973 | 397 | |
| 9152 | 398 | /* If we haven't joined the chat yet, we don't care that someone |
| 399 | * left, or it was us leaving after we closed the chat */ | |
| 8182 | 400 | if(!chat->conv) { |
| 10558 | 401 | if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
| 9152 | 402 | jabber_chat_destroy(chat); |
| 8182 | 403 | jabber_id_free(jid); |
| 404 | g_free(status); | |
| 405 | g_free(room_jid); | |
| 10189 | 406 | if(avatar_hash) |
| 407 | g_free(avatar_hash); | |
| 8182 | 408 | return; |
| 409 | } | |
| 410 | ||
| 7973 | 411 | jabber_buddy_remove_resource(jb, jid->resource); |
| 7972 | 412 | if(chat->muc) { |
| 413 | xmlnode *x; | |
| 8135 | 414 | for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
| 7972 | 415 | const char *xmlns, *nick, *code; |
| 416 | xmlnode *stat, *item; | |
| 417 | if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
| 418 | strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
| 419 | continue; | |
| 420 | if(!(stat = xmlnode_get_child(x, "status"))) | |
| 421 | continue; | |
| 9152 | 422 | if(!(code = xmlnode_get_attrib(stat, "code"))) |
| 7972 | 423 | continue; |
| 9152 | 424 | if(!strcmp(code, "301")) { |
| 425 | /* XXX: we got banned */ | |
| 426 | } else if(!strcmp(code, "303")) { | |
| 427 | if(!(item = xmlnode_get_child(x, "item"))) | |
| 428 | continue; | |
| 429 | if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
| 430 | continue; | |
| 431 | nick_change = TRUE; | |
| 432 | if(!strcmp(jid->resource, chat->handle)) { | |
| 433 | g_free(chat->handle); | |
| 434 | chat->handle = g_strdup(nick); | |
| 435 | } | |
| 436 | gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
| 437 | jabber_chat_remove_handle(chat, jid->resource); | |
| 438 | break; | |
| 439 | } else if(!strcmp(code, "307")) { | |
| 440 | /* XXX: we got kicked */ | |
| 441 | } else if(!strcmp(code, "321")) { | |
| 442 | /* XXX: removed due to an affiliation change */ | |
| 443 | } else if(!strcmp(code, "322")) { | |
| 444 | /* XXX: removed because room is now members-only */ | |
| 445 | } else if(!strcmp(code, "332")) { | |
| 446 | /* XXX: removed due to system shutdown */ | |
| 8401 | 447 | } |
| 7972 | 448 | } |
| 449 | } | |
| 450 | if(!nick_change) { | |
| 9152 | 451 | if(!g_utf8_collate(jid->resource, chat->handle)) { |
| 7972 | 452 | serv_got_chat_left(js->gc, chat->id); |
| 453 | jabber_chat_destroy(chat); | |
| 454 | } else { | |
| 455 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
| 7974 | 456 | status); |
| 9152 | 457 | jabber_chat_remove_handle(chat, jid->resource); |
| 7972 | 458 | } |
| 7014 | 459 | } |
| 460 | } else { | |
| 8182 | 461 | if(!chat->conv) { |
| 462 | chat->id = i++; | |
| 463 | chat->muc = muc; | |
| 464 | chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
| 10722 | 465 | gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); |
| 10486 | 466 | |
| 467 | /* <iq to='room@server' | |
| 468 | type='get'> | |
| 469 | <query xmlns='http://jabber.org/protocol/disco#info' | |
| 470 | node='http://jabber.org/protocol/muc#traffic'/> | |
| 471 | </iq> | |
| 472 | */ | |
| 473 | /* expected response format: | |
| 474 | <iq from='room@server' | |
| 475 | type='get'> | |
| 476 | <query xmlns='http://jabber.org/protocol/disco#info' | |
| 477 | node='http://jabber.org/protocol/muc#traffic'> | |
| 478 | <feature var='http://jabber.org/protocol/xhtml-im'/> | |
| 479 | <feature var='jabber:x:roster/'/> | |
| 480 | </query> | |
| 481 | </iq> | |
| 482 | */ | |
| 483 | /* | |
| 484 | * XXX: i'm not sure if we turn off XHTML unless we get | |
| 485 | * xhtml back in this, or if we turn it off only if we | |
| 486 | * get a response, and it's not there. Ask stpeter to | |
| 487 | * clarify. | |
| 488 | */ | |
| 8182 | 489 | } |
| 490 | ||
| 7973 | 491 | jabber_buddy_track_resource(jb, jid->resource, priority, state, |
| 492 | status); | |
| 493 | ||
| 9152 | 494 | jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
| 495 | ||
| 7014 | 496 | if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
497 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9745
diff
changeset
|
498 | real_jid, flags, !delayed); |
|
9554
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
499 | else |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
500 | gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, |
|
1609ba3612c3
[gaim-migrate @ 10387]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9320
diff
changeset
|
501 | flags); |
| 7014 | 502 | } |
| 503 | g_free(room_jid); | |
| 504 | } else { | |
| 10486 | 505 | if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) { |
| 7014 | 506 | gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 507 | "got unexpected presence from %s, ignoring\n", from); | |
| 508 | jabber_id_free(jid); | |
| 7615 | 509 | g_free(status); |
| 10189 | 510 | if(avatar_hash) |
| 511 | g_free(avatar_hash); | |
| 7014 | 512 | return; |
| 513 | } | |
| 514 | ||
| 7322 | 515 | buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
| 516 | jid->node ? "@" : "", jid->domain); | |
| 7014 | 517 | if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
| 518 | jabber_id_free(jid); | |
| 10189 | 519 | if(avatar_hash) |
| 520 | g_free(avatar_hash); | |
| 7014 | 521 | g_free(buddy_name); |
| 7615 | 522 | g_free(status); |
| 7014 | 523 | return; |
| 524 | } | |
| 525 | ||
| 10189 | 526 | if(avatar_hash) { |
| 527 | const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
| 528 | if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
| 529 | JabberIq *iq; | |
| 530 | xmlnode *vcard; | |
| 531 | ||
| 532 | iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 533 | xmlnode_set_attrib(iq->node, "to", buddy_name); | |
| 534 | vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 535 | xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 536 | ||
| 537 | jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
| 538 | jabber_iq_send(iq); | |
| 539 | } | |
| 540 | } | |
| 541 | ||
| 9954 | 542 | if(state == JABBER_BUDDY_STATE_ERROR || |
| 7813 | 543 | (type && (!strcmp(type, "unavailable") || |
| 544 | !strcmp(type, "unsubscribed")))) { | |
| 8043 | 545 | GaimConversation *conv; |
| 546 | ||
| 7014 | 547 | jabber_buddy_remove_resource(jb, jid->resource); |
| 8043 | 548 | if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
| 549 | gaim_conversation_set_name(conv, buddy_name); | |
| 550 | ||
| 7395 | 551 | } else { |
| 9954 | 552 | jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
| 553 | state, status); | |
| 7395 | 554 | } |
| 7014 | 555 | |
| 9954 | 556 | if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
| 557 | if(!jbr || jbr == found_jbr) { | |
| 9990 | 558 | gaim_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(state), "priority", found_jbr->priority, found_jbr->status ? "message" : NULL, found_jbr->status, NULL); |
| 9954 | 559 | } |
| 560 | } else { | |
| 9990 | 561 | gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
| 9954 | 562 | } |
| 7014 | 563 | g_free(buddy_name); |
| 564 | } | |
| 565 | g_free(status); | |
| 566 | jabber_id_free(jid); | |
| 10189 | 567 | if(avatar_hash) |
| 568 | g_free(avatar_hash); | |
| 7014 | 569 | } |
| 570 | ||
| 571 | void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
| 572 | { | |
| 573 | xmlnode *presence = xmlnode_new("presence"); | |
| 574 | ||
| 575 | xmlnode_set_attrib(presence, "to", who); | |
| 576 | xmlnode_set_attrib(presence, "type", type); | |
| 577 | ||
| 578 | jabber_send(js, presence); | |
| 579 | xmlnode_free(presence); | |
| 580 | } | |
| 9954 | 581 | |
| 582 | void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
| 583 | { | |
| 10216 | 584 | const char *status_id = NULL; |
| 585 | ||
| 586 | *state = JABBER_BUDDY_STATE_UNKNOWN; | |
| 587 | *msg = NULL; | |
| 588 | *priority = 0; | |
| 9954 | 589 | |
| 590 | if(!status) { | |
| 10216 | 591 | *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
| 592 | } else { | |
| 593 | if(state) { | |
| 594 | status_id = gaim_status_get_id(status); | |
| 595 | *state = jabber_buddy_status_id_get_state(status_id); | |
| 596 | } | |
| 597 | ||
| 598 | if(msg) | |
| 599 | *msg = gaim_status_get_attr_string(status, "message"); | |
| 600 | ||
| 601 | if(priority) | |
| 602 | *priority = gaim_status_get_attr_int(status, "priority"); | |
| 9954 | 603 | } |
| 604 | ||
| 605 | } |