Mercurial > pidgin.yaz
annotate src/protocols/jabber/presence.c @ 11879:20479a2cf911
[gaim-migrate @ 14170]
Didn't realize this wasn't saved until I tried quitting emacs.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 28 Oct 2005 23:16:37 +0000 |
parents | ea0f39933003 |
children | f82b6d559ea7 |
rev | line source |
---|---|
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
72a5babfa8b4
[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
c8bf2da398e3
[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 | 75 jabber_buddy_remove_resource(jb, js->user->resource); |
76 } else { | |
9954 | 77 jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); |
9744 | 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
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
92 GaimConnection *gc = NULL; |
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
93 JabberStream *js = NULL; |
11251 | 94 gboolean disconnected; |
10755 | 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 | |
11251 | 105 disconnected = gaim_account_is_disconnected(account); |
10755 | 106 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
107 | |
11251 | 108 if(disconnected) |
10755 | 109 return; |
110 | |
111 gc = gaim_account_get_connection(account); | |
112 js = gc->proto_data; | |
113 | |
9954 | 114 gaim_status_to_jabber(status, &state, &msg, &priority); |
115 | |
116 if(msg) | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
117 gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
7014 | 118 |
9954 | 119 presence = jabber_presence_create(state, stripped, priority); |
120 g_free(stripped); | |
7014 | 121 |
122 jabber_send(js, presence); | |
10189 | 123 |
124 if(js->avatar_hash) { | |
125 x = xmlnode_new_child(presence, "x"); | |
126 xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update"); | |
127 photo = xmlnode_new_child(x, "photo"); | |
128 xmlnode_insert_data(photo, js->avatar_hash, -1); | |
129 } | |
130 | |
7014 | 131 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
132 xmlnode_free(presence); | |
8185 | 133 |
9954 | 134 jabber_presence_fake_to_self(js, status); |
7014 | 135 } |
136 | |
9954 | 137 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
7014 | 138 { |
11568 | 139 xmlnode *show, *status, *presence, *pri; |
9954 | 140 const char *show_string = NULL; |
7014 | 141 |
142 | |
143 presence = xmlnode_new("presence"); | |
144 | |
145 | |
9954 | 146 if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
147 xmlnode_set_attrib(presence, "type", "unavailable"); | |
148 else if(state != JABBER_BUDDY_STATE_ONLINE && | |
149 state != JABBER_BUDDY_STATE_UNKNOWN && | |
150 state != JABBER_BUDDY_STATE_ERROR) | |
151 show_string = jabber_buddy_state_get_status_id(state); | |
152 | |
153 if(show_string) { | |
154 show = xmlnode_new_child(presence, "show"); | |
155 xmlnode_insert_data(show, show_string, -1); | |
7014 | 156 } |
157 | |
9954 | 158 if(msg) { |
7014 | 159 status = xmlnode_new_child(presence, "status"); |
160 xmlnode_insert_data(status, msg, -1); | |
161 } | |
162 | |
11568 | 163 if(priority) { |
164 char *pstr = g_strdup_printf("%d", priority); | |
165 pri = xmlnode_new_child(presence, "priority"); | |
166 xmlnode_insert_data(pri, pstr, -1); | |
167 g_free(pstr); | |
168 } | |
169 | |
7014 | 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
dece74f05509
[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 { | |
10941 | 205 JabberBuddy *jb = NULL; |
10189 | 206 GaimBuddy *b = NULL; |
10941 | 207 xmlnode *vcard, *photo, *binval; |
11127 | 208 char *text; |
11137 | 209 guchar *data; |
11127 | 210 gsize size; |
10189 | 211 const char *from = xmlnode_get_attrib(packet, "from"); |
212 | |
213 if(!from) | |
214 return; | |
215 | |
10941 | 216 jb = jabber_buddy_find(js, from, TRUE); |
217 | |
218 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
219 | |
10189 | 220 if((vcard = xmlnode_get_child(packet, "vCard")) || |
221 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
10941 | 222 if((photo = xmlnode_get_child(vcard, "PHOTO")) && |
11361 | 223 (( (binval = xmlnode_get_child(photo, "BINVAL")) && |
224 (text = xmlnode_get_data(binval))) || | |
225 (text = xmlnode_get_data(photo)))) { | |
11127 | 226 data = gaim_base64_decode(text, &size); |
10189 | 227 |
10941 | 228 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); |
229 if((b = gaim_find_buddy(js->gc->account, from))) { | |
230 unsigned char hashval[20]; | |
231 char hash[41], *p; | |
232 int i; | |
10189 | 233 |
11183 | 234 gaim_cipher_digest_region("sha1", (guchar *)data, size, |
10941 | 235 sizeof(hashval), hashval, NULL); |
236 p = hash; | |
237 for(i=0; i<20; i++, p+=2) | |
238 snprintf(p, 3, "%02x", hashval[i]); | |
239 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
10189 | 240 } |
10941 | 241 g_free(text); |
10189 | 242 } |
243 } | |
244 } | |
245 | |
7014 | 246 void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
247 { | |
248 const char *from = xmlnode_get_attrib(packet, "from"); | |
249 const char *type = xmlnode_get_attrib(packet, "type"); | |
7944 | 250 const char *real_jid = NULL; |
9152 | 251 const char *affiliation = NULL; |
252 const char *role = NULL; | |
7014 | 253 char *status = NULL; |
254 int priority = 0; | |
255 JabberID *jid; | |
256 JabberChat *chat; | |
257 JabberBuddy *jb; | |
9954 | 258 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
9554 | 259 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
9846 | 260 gboolean delayed = FALSE; |
10189 | 261 GaimBuddy *b = NULL; |
7014 | 262 char *buddy_name; |
9954 | 263 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
7014 | 264 xmlnode *y; |
265 gboolean muc = FALSE; | |
10189 | 266 char *avatar_hash = NULL; |
7014 | 267 |
268 | |
8043 | 269 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
270 return; | |
271 | |
272 if(!(jid = jabber_id_new(from))) | |
7280 | 273 return; |
274 | |
7014 | 275 if(jb->error_msg) { |
276 g_free(jb->error_msg); | |
277 jb->error_msg = NULL; | |
278 } | |
279 | |
7813 | 280 if(type && !strcmp(type, "error")) { |
8401 | 281 char *msg = jabber_parse_error(js, packet); |
7644 | 282 |
9954 | 283 state = JABBER_BUDDY_STATE_ERROR; |
8401 | 284 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
7813 | 285 } else if(type && !strcmp(type, "subscribe")) { |
7014 | 286 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
10949 | 287 char *msg; |
288 | |
289 msg = g_strdup_printf(_("The user %s wants to add %s to his or " | |
290 "her buddy list."), | |
291 from, gaim_account_get_username(js->gc->account)); | |
7014 | 292 jap->gc = js->gc; |
293 jap->who = g_strdup(from); | |
294 | |
10189 | 295 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
10116 | 296 jap, 2, |
7014 | 297 _("Authorize"), G_CALLBACK(authorize_add_cb), |
298 _("Deny"), G_CALLBACK(deny_add_cb)); | |
299 g_free(msg); | |
8043 | 300 jabber_id_free(jid); |
7145 | 301 return; |
7813 | 302 } else if(type && !strcmp(type, "subscribed")) { |
7014 | 303 /* we've been allowed to see their presence, but we don't care */ |
8043 | 304 jabber_id_free(jid); |
7014 | 305 return; |
306 } else { | |
307 if((y = xmlnode_get_child(packet, "show"))) { | |
308 char *show = xmlnode_get_data(y); | |
9954 | 309 state = jabber_buddy_status_id_get_state(show); |
7014 | 310 g_free(show); |
311 } else { | |
9954 | 312 state = JABBER_BUDDY_STATE_ONLINE; |
7014 | 313 } |
314 } | |
315 | |
7310 | 316 |
7014 | 317 for(y = packet->child; y; y = y->next) { |
8135 | 318 if(y->type != XMLNODE_TYPE_TAG) |
7014 | 319 continue; |
320 | |
321 if(!strcmp(y->name, "status")) { | |
7615 | 322 g_free(status); |
7014 | 323 status = xmlnode_get_data(y); |
324 } else if(!strcmp(y->name, "priority")) { | |
325 char *p = xmlnode_get_data(y); | |
326 if(p) { | |
327 priority = atoi(p); | |
328 g_free(p); | |
329 } | |
330 } else if(!strcmp(y->name, "x")) { | |
331 const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
9846 | 332 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
9847 | 333 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
9846 | 334 delayed = TRUE; |
335 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { | |
7629 | 336 xmlnode *z; |
337 | |
7014 | 338 muc = TRUE; |
7629 | 339 if((z = xmlnode_get_child(y, "status"))) { |
340 const char *code = xmlnode_get_attrib(z, "code"); | |
341 if(code && !strcmp(code, "201")) { | |
7895 | 342 chat = jabber_chat_find(js, jid->node, jid->domain); |
8396 | 343 chat->config_dialog_type = GAIM_REQUEST_ACTION; |
344 chat->config_dialog_handle = | |
345 gaim_request_action(js->gc, _("Create New Room"), | |
7895 | 346 _("Create New Room"), |
347 _("You are creating a new room. Would you like to " | |
348 "configure it, or accept the default settings?"), | |
349 1, chat, 2, _("Configure Room"), | |
7923 | 350 G_CALLBACK(jabber_chat_request_room_configure), |
7895 | 351 _("Accept Defaults"), |
352 G_CALLBACK(jabber_chat_create_instant_room)); | |
7629 | 353 } |
354 } | |
7944 | 355 if((z = xmlnode_get_child(y, "item"))) { |
356 real_jid = xmlnode_get_attrib(z, "jid"); | |
9152 | 357 affiliation = xmlnode_get_attrib(z, "affiliation"); |
358 role = xmlnode_get_attrib(z, "role"); | |
9931 | 359 if(affiliation != NULL && !strcmp(affiliation, "owner")) |
360 flags |= GAIM_CBFLAGS_FOUNDER; | |
9743 | 361 if (role != NULL) { |
362 if (!strcmp(role, "moderator")) | |
9931 | 363 flags |= GAIM_CBFLAGS_OP; |
9743 | 364 else if (!strcmp(role, "participant")) |
9931 | 365 flags |= GAIM_CBFLAGS_VOICE; |
9743 | 366 } |
7944 | 367 } |
10189 | 368 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
369 xmlnode *photo = xmlnode_get_child(y, "photo"); | |
370 if(photo) { | |
371 if(avatar_hash) | |
372 g_free(avatar_hash); | |
373 avatar_hash = xmlnode_get_data(photo); | |
374 } | |
7014 | 375 } |
376 } | |
377 } | |
378 | |
379 | |
7322 | 380 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
8462 | 381 static int i = 1; |
7014 | 382 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
383 | |
9954 | 384 if(state == JABBER_BUDDY_STATE_ERROR) { |
8401 | 385 char *title, *msg = jabber_parse_error(js, packet); |
7014 | 386 |
7321 | 387 if(chat->conv) { |
8401 | 388 title = g_strdup_printf(_("Error in chat %s"), from); |
7321 | 389 serv_got_chat_left(js->gc, chat->id); |
390 } else { | |
8401 | 391 title = g_strdup_printf(_("Error joining chat %s"), from); |
7321 | 392 } |
8401 | 393 gaim_notify_error(js->gc, title, title, msg); |
394 g_free(title); | |
395 g_free(msg); | |
7014 | 396 |
397 jabber_chat_destroy(chat); | |
7310 | 398 jabber_id_free(jid); |
7615 | 399 g_free(status); |
8182 | 400 g_free(room_jid); |
10189 | 401 if(avatar_hash) |
402 g_free(avatar_hash); | |
7014 | 403 return; |
404 } | |
405 | |
406 | |
7813 | 407 if(type && !strcmp(type, "unavailable")) { |
7972 | 408 gboolean nick_change = FALSE; |
7973 | 409 |
9152 | 410 /* If we haven't joined the chat yet, we don't care that someone |
411 * left, or it was us leaving after we closed the chat */ | |
8182 | 412 if(!chat->conv) { |
10558 | 413 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
9152 | 414 jabber_chat_destroy(chat); |
8182 | 415 jabber_id_free(jid); |
416 g_free(status); | |
417 g_free(room_jid); | |
10189 | 418 if(avatar_hash) |
419 g_free(avatar_hash); | |
8182 | 420 return; |
421 } | |
422 | |
7973 | 423 jabber_buddy_remove_resource(jb, jid->resource); |
7972 | 424 if(chat->muc) { |
425 xmlnode *x; | |
8135 | 426 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
7972 | 427 const char *xmlns, *nick, *code; |
428 xmlnode *stat, *item; | |
429 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
430 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
431 continue; | |
432 if(!(stat = xmlnode_get_child(x, "status"))) | |
433 continue; | |
9152 | 434 if(!(code = xmlnode_get_attrib(stat, "code"))) |
7972 | 435 continue; |
9152 | 436 if(!strcmp(code, "301")) { |
437 /* XXX: we got banned */ | |
438 } else if(!strcmp(code, "303")) { | |
439 if(!(item = xmlnode_get_child(x, "item"))) | |
440 continue; | |
441 if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
442 continue; | |
443 nick_change = TRUE; | |
444 if(!strcmp(jid->resource, chat->handle)) { | |
445 g_free(chat->handle); | |
446 chat->handle = g_strdup(nick); | |
447 } | |
448 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
449 jabber_chat_remove_handle(chat, jid->resource); | |
450 break; | |
451 } else if(!strcmp(code, "307")) { | |
452 /* XXX: we got kicked */ | |
453 } else if(!strcmp(code, "321")) { | |
454 /* XXX: removed due to an affiliation change */ | |
455 } else if(!strcmp(code, "322")) { | |
456 /* XXX: removed because room is now members-only */ | |
457 } else if(!strcmp(code, "332")) { | |
458 /* XXX: removed due to system shutdown */ | |
8401 | 459 } |
7972 | 460 } |
461 } | |
462 if(!nick_change) { | |
9152 | 463 if(!g_utf8_collate(jid->resource, chat->handle)) { |
7972 | 464 serv_got_chat_left(js->gc, chat->id); |
465 jabber_chat_destroy(chat); | |
466 } else { | |
467 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
7974 | 468 status); |
9152 | 469 jabber_chat_remove_handle(chat, jid->resource); |
7972 | 470 } |
7014 | 471 } |
472 } else { | |
8182 | 473 if(!chat->conv) { |
474 chat->id = i++; | |
475 chat->muc = muc; | |
476 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
10722 | 477 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); |
10486 | 478 |
10941 | 479 jabber_chat_disco_traffic(chat); |
8182 | 480 } |
481 | |
7973 | 482 jabber_buddy_track_resource(jb, jid->resource, priority, state, |
483 status); | |
484 | |
9152 | 485 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
486 | |
7014 | 487 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
488 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
9846 | 489 real_jid, flags, !delayed); |
9554 | 490 else |
491 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
492 flags); | |
7014 | 493 } |
494 g_free(room_jid); | |
495 } else { | |
10486 | 496 if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) { |
7014 | 497 gaim_debug(GAIM_DEBUG_INFO, "jabber", |
498 "got unexpected presence from %s, ignoring\n", from); | |
499 jabber_id_free(jid); | |
7615 | 500 g_free(status); |
10189 | 501 if(avatar_hash) |
502 g_free(avatar_hash); | |
7014 | 503 return; |
504 } | |
505 | |
7322 | 506 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
507 jid->node ? "@" : "", jid->domain); | |
7014 | 508 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
509 jabber_id_free(jid); | |
10189 | 510 if(avatar_hash) |
511 g_free(avatar_hash); | |
7014 | 512 g_free(buddy_name); |
7615 | 513 g_free(status); |
7014 | 514 return; |
515 } | |
516 | |
10189 | 517 if(avatar_hash) { |
518 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
519 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
520 JabberIq *iq; | |
521 xmlnode *vcard; | |
522 | |
10941 | 523 /* XXX this is a crappy way of trying to prevent |
524 * someone from spamming us with presence packets | |
525 * and causing us to DoS ourselves...what we really | |
526 * need is a queue system that can throttle itself, | |
527 * but i'm too tired to write that right now */ | |
528 if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
529 | |
530 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
10189 | 531 |
10941 | 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 } | |
10189 | 540 } |
541 } | |
542 | |
9954 | 543 if(state == JABBER_BUDDY_STATE_ERROR || |
7813 | 544 (type && (!strcmp(type, "unavailable") || |
545 !strcmp(type, "unsubscribed")))) { | |
8043 | 546 GaimConversation *conv; |
547 | |
7014 | 548 jabber_buddy_remove_resource(jb, jid->resource); |
8043 | 549 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
550 gaim_conversation_set_name(conv, buddy_name); | |
551 | |
7395 | 552 } else { |
9954 | 553 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
554 state, status); | |
7395 | 555 } |
7014 | 556 |
9954 | 557 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
558 if(!jbr || jbr == found_jbr) { | |
9990 | 559 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 | 560 } |
561 } else { | |
9990 | 562 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
9954 | 563 } |
7014 | 564 g_free(buddy_name); |
565 } | |
566 g_free(status); | |
567 jabber_id_free(jid); | |
10189 | 568 if(avatar_hash) |
569 g_free(avatar_hash); | |
7014 | 570 } |
571 | |
572 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
573 { | |
574 xmlnode *presence = xmlnode_new("presence"); | |
575 | |
576 xmlnode_set_attrib(presence, "to", who); | |
577 xmlnode_set_attrib(presence, "type", type); | |
578 | |
579 jabber_send(js, presence); | |
580 xmlnode_free(presence); | |
581 } | |
9954 | 582 |
583 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
584 { | |
10216 | 585 const char *status_id = NULL; |
586 | |
587 *state = JABBER_BUDDY_STATE_UNKNOWN; | |
588 *msg = NULL; | |
589 *priority = 0; | |
9954 | 590 |
591 if(!status) { | |
10216 | 592 *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
593 } else { | |
594 if(state) { | |
595 status_id = gaim_status_get_id(status); | |
596 *state = jabber_buddy_status_id_get_state(status_id); | |
597 } | |
598 | |
599 if(msg) | |
600 *msg = gaim_status_get_attr_string(status, "message"); | |
601 | |
11872 | 602 /* if the message is blank, then there really isn't a message */ |
603 if(*msg && !**msg) | |
604 *msg = NULL; | |
605 | |
10216 | 606 if(priority) |
607 *priority = gaim_status_get_attr_int(status, "priority"); | |
9954 | 608 } |
609 | |
610 } |