Mercurial > pidgin.yaz
annotate libgaim/protocols/jabber/presence.c @ 15285:e8f8749e6182
[gaim-migrate @ 18074]
Fix a crash when adding a buddy to the deny list on a Google Talk account when that buddy doesnot have a resource name, and changed a printf() to a gaim_debug().
committer: Tailor Script <tailor@pidgin.im>
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Thu, 04 Jan 2007 23:38:43 +0000 |
parents | dfaad00e60dd |
children |
rev | line source |
---|---|
14192 | 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 | |
23 #include "cipher.h" | |
24 #include "debug.h" | |
25 #include "notify.h" | |
26 #include "request.h" | |
27 #include "server.h" | |
28 #include "status.h" | |
29 #include "util.h" | |
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; | |
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, | |
50 chat->handle); | |
51 | |
52 xmlnode_set_attrib(presence, "to", chat_full_jid); | |
53 jabber_send(chat->js, presence); | |
54 g_free(chat_full_jid); | |
55 } | |
56 | |
57 void jabber_presence_fake_to_self(JabberStream *js, const GaimStatus *gstatus) { | |
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); | |
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))) { | |
68 JabberBuddyState state; | |
14463 | 69 char *msg; |
14192 | 70 int priority; |
71 | |
72 gaim_status_to_jabber(gstatus, &state, &msg, &priority); | |
73 | |
74 if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { | |
75 jabber_buddy_remove_resource(jb, js->user->resource); | |
76 } else { | |
77 jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); | |
78 } | |
79 if((jbr = jabber_buddy_find_resource(jb, NULL))) { | |
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); | |
81 } else { | |
82 gaim_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL); | |
83 } | |
14463 | 84 |
85 g_free(msg); | |
14192 | 86 } |
87 } | |
88 g_free(my_base_jid); | |
89 } | |
90 | |
91 | |
92 void jabber_presence_send(GaimAccount *account, GaimStatus *status) | |
93 { | |
94 GaimConnection *gc = NULL; | |
95 JabberStream *js = NULL; | |
96 gboolean disconnected; | |
97 int primitive; | |
98 xmlnode *presence, *x, *photo; | |
99 char *stripped = NULL; | |
100 JabberBuddyState state; | |
101 int priority; | |
102 | |
103 if(!gaim_status_is_active(status)) | |
104 return; | |
105 | |
106 disconnected = gaim_account_is_disconnected(account); | |
107 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); | |
108 | |
109 if(disconnected) | |
110 return; | |
111 | |
112 gc = gaim_account_get_connection(account); | |
113 js = gc->proto_data; | |
114 | |
14463 | 115 gaim_status_to_jabber(status, &state, &stripped, &priority); |
14192 | 116 |
117 | |
118 presence = jabber_presence_create(state, stripped, priority); | |
119 g_free(stripped); | |
120 | |
121 if(js->avatar_hash) { | |
122 x = xmlnode_new_child(presence, "x"); | |
123 xmlnode_set_namespace(x, "vcard-temp:x:update"); | |
124 photo = xmlnode_new_child(x, "photo"); | |
125 xmlnode_insert_data(photo, js->avatar_hash, -1); | |
126 } | |
127 | |
128 jabber_send(js, presence); | |
129 | |
130 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); | |
131 xmlnode_free(presence); | |
132 | |
133 jabber_presence_fake_to_self(js, status); | |
134 } | |
135 | |
136 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) | |
137 { | |
138 xmlnode *show, *status, *presence, *pri, *c; | |
139 const char *show_string = NULL; | |
140 | |
141 presence = xmlnode_new("presence"); | |
142 | |
143 if(state == JABBER_BUDDY_STATE_UNAVAILABLE) | |
144 xmlnode_set_attrib(presence, "type", "unavailable"); | |
145 else if(state != JABBER_BUDDY_STATE_ONLINE && | |
146 state != JABBER_BUDDY_STATE_UNKNOWN && | |
147 state != JABBER_BUDDY_STATE_ERROR) | |
148 show_string = jabber_buddy_state_get_show(state); | |
149 | |
150 if(show_string) { | |
151 show = xmlnode_new_child(presence, "show"); | |
152 xmlnode_insert_data(show, show_string, -1); | |
153 } | |
154 | |
155 if(msg) { | |
156 status = xmlnode_new_child(presence, "status"); | |
157 xmlnode_insert_data(status, msg, -1); | |
158 } | |
159 | |
160 if(priority) { | |
161 char *pstr = g_strdup_printf("%d", priority); | |
162 pri = xmlnode_new_child(presence, "priority"); | |
163 xmlnode_insert_data(pri, pstr, -1); | |
164 g_free(pstr); | |
165 } | |
166 | |
167 /* JEP-0115 */ | |
168 c = xmlnode_new_child(presence, "c"); | |
169 xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); | |
170 xmlnode_set_attrib(c, "node", CAPS0115_NODE); | |
171 xmlnode_set_attrib(c, "ver", VERSION); | |
172 | |
173 return presence; | |
174 } | |
175 | |
176 struct _jabber_add_permit { | |
177 GaimConnection *gc; | |
178 JabberStream *js; | |
179 char *who; | |
180 }; | |
181 | |
182 static void authorize_add_cb(struct _jabber_add_permit *jap) | |
183 { | |
184 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
185 "subscribed"); | |
186 g_free(jap->who); | |
187 g_free(jap); | |
188 } | |
189 | |
190 static void deny_add_cb(struct _jabber_add_permit *jap) | |
191 { | |
192 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
193 "unsubscribed"); | |
194 | |
195 g_free(jap->who); | |
196 g_free(jap); | |
197 } | |
198 | |
199 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) | |
200 { | |
201 JabberBuddy *jb = NULL; | |
202 GaimBuddy *b = NULL; | |
203 xmlnode *vcard, *photo, *binval; | |
204 char *text; | |
205 guchar *data; | |
206 gsize size; | |
207 const char *from = xmlnode_get_attrib(packet, "from"); | |
208 | |
209 if(!from) | |
210 return; | |
211 | |
212 jb = jabber_buddy_find(js, from, TRUE); | |
213 | |
214 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); | |
215 | |
216 if((vcard = xmlnode_get_child(packet, "vCard")) || | |
217 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
218 if((photo = xmlnode_get_child(vcard, "PHOTO")) && | |
219 (( (binval = xmlnode_get_child(photo, "BINVAL")) && | |
220 (text = xmlnode_get_data(binval))) || | |
221 (text = xmlnode_get_data(photo)))) { | |
222 data = gaim_base64_decode(text, &size); | |
223 | |
224 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); | |
225 if((b = gaim_find_buddy(js->gc->account, from))) { | |
226 unsigned char hashval[20]; | |
227 char hash[41], *p; | |
228 int i; | |
229 | |
230 gaim_cipher_digest_region("sha1", data, size, | |
231 sizeof(hashval), hashval, NULL); | |
232 p = hash; | |
233 for(i=0; i<20; i++, p+=2) | |
234 snprintf(p, 3, "%02x", hashval[i]); | |
235 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
236 } | |
237 g_free(data); | |
238 g_free(text); | |
239 } | |
240 } | |
241 } | |
242 | |
243 void jabber_presence_parse(JabberStream *js, xmlnode *packet) | |
244 { | |
245 const char *from = xmlnode_get_attrib(packet, "from"); | |
246 const char *type = xmlnode_get_attrib(packet, "type"); | |
247 const char *real_jid = NULL; | |
248 const char *affiliation = NULL; | |
249 const char *role = NULL; | |
250 char *status = NULL; | |
251 int priority = 0; | |
252 JabberID *jid; | |
253 JabberChat *chat; | |
254 JabberBuddy *jb; | |
255 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; | |
256 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; | |
257 gboolean delayed = FALSE; | |
258 GaimBuddy *b = NULL; | |
259 char *buddy_name; | |
260 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; | |
261 xmlnode *y; | |
262 gboolean muc = FALSE; | |
263 char *avatar_hash = NULL; | |
264 | |
265 if(!(jb = jabber_buddy_find(js, from, TRUE))) | |
266 return; | |
267 | |
268 if(!(jid = jabber_id_new(from))) | |
269 return; | |
270 | |
271 if(jb->error_msg) { | |
272 g_free(jb->error_msg); | |
273 jb->error_msg = NULL; | |
274 } | |
275 | |
276 if(type && !strcmp(type, "error")) { | |
277 char *msg = jabber_parse_error(js, packet); | |
278 | |
279 state = JABBER_BUDDY_STATE_ERROR; | |
280 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); | |
281 } else if(type && !strcmp(type, "subscribe")) { | |
282 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); | |
15136 | 283 gboolean onlist = FALSE; |
284 GaimBuddy *buddy = gaim_find_buddy(gaim_connection_get_account(js->gc), from); | |
285 JabberBuddy *jb = NULL; | |
14192 | 286 |
15136 | 287 if (buddy) { |
288 jb = jabber_buddy_find(js, from, TRUE); | |
289 if ((jb->subscription & JABBER_SUB_TO) == 0) | |
290 onlist = TRUE; | |
291 } | |
292 | |
14192 | 293 jap->gc = js->gc; |
294 jap->who = g_strdup(from); | |
295 jap->js = js; | |
296 | |
15136 | 297 gaim_account_request_authorization(gaim_connection_get_account(js->gc), from, NULL, NULL, NULL, onlist, |
298 G_CALLBACK(authorize_add_cb), G_CALLBACK(deny_add_cb), jap); | |
14192 | 299 jabber_id_free(jid); |
300 return; | |
301 } else if(type && !strcmp(type, "subscribed")) { | |
302 /* we've been allowed to see their presence, but we don't care */ | |
303 jabber_id_free(jid); | |
304 return; | |
305 } else if(type && !strcmp(type, "unsubscribe")) { | |
306 /* XXX I'm not sure this is the right way to handle this, it | |
307 * might be better to add "unsubscribe" to the presence status | |
308 * if lower down, but I'm not sure. */ | |
309 /* they are unsubscribing from our presence, we don't care */ | |
310 /* Well, maybe just a little, we might want/need to start | |
311 * acknowledging this (and the others) at some point. */ | |
312 jabber_id_free(jid); | |
313 return; | |
314 } else { | |
315 if((y = xmlnode_get_child(packet, "show"))) { | |
316 char *show = xmlnode_get_data(y); | |
317 state = jabber_buddy_show_get_state(show); | |
318 g_free(show); | |
319 } else { | |
320 state = JABBER_BUDDY_STATE_ONLINE; | |
321 } | |
322 } | |
323 | |
324 | |
325 for(y = packet->child; y; y = y->next) { | |
326 if(y->type != XMLNODE_TYPE_TAG) | |
327 continue; | |
328 | |
329 if(!strcmp(y->name, "status")) { | |
330 g_free(status); | |
331 status = xmlnode_get_data(y); | |
332 } else if(!strcmp(y->name, "priority")) { | |
333 char *p = xmlnode_get_data(y); | |
334 if(p) { | |
335 priority = atoi(p); | |
336 g_free(p); | |
337 } | |
338 } else if(!strcmp(y->name, "x")) { | |
339 const char *xmlns = xmlnode_get_namespace(y); | |
340 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { | |
341 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ | |
342 delayed = TRUE; | |
343 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { | |
344 xmlnode *z; | |
345 | |
346 muc = TRUE; | |
347 if((z = xmlnode_get_child(y, "status"))) { | |
348 const char *code = xmlnode_get_attrib(z, "code"); | |
349 if(code && !strcmp(code, "201")) { | |
350 if((chat = jabber_chat_find(js, jid->node, jid->domain))) { | |
351 chat->config_dialog_type = GAIM_REQUEST_ACTION; | |
352 chat->config_dialog_handle = | |
353 gaim_request_action(js->gc, | |
354 _("Create New Room"), | |
355 _("Create New Room"), | |
356 _("You are creating a new room. Would" | |
357 " you like to configure it, or" | |
358 " accept the default settings?"), | |
359 1, chat, 2, _("_Configure Room"), | |
360 G_CALLBACK(jabber_chat_request_room_configure), | |
361 _("_Accept Defaults"), | |
362 G_CALLBACK(jabber_chat_create_instant_room)); | |
363 } | |
364 } | |
365 } | |
366 if((z = xmlnode_get_child(y, "item"))) { | |
367 real_jid = xmlnode_get_attrib(z, "jid"); | |
368 affiliation = xmlnode_get_attrib(z, "affiliation"); | |
369 role = xmlnode_get_attrib(z, "role"); | |
370 if(affiliation != NULL && !strcmp(affiliation, "owner")) | |
371 flags |= GAIM_CBFLAGS_FOUNDER; | |
372 if (role != NULL) { | |
373 if (!strcmp(role, "moderator")) | |
374 flags |= GAIM_CBFLAGS_OP; | |
375 else if (!strcmp(role, "participant")) | |
376 flags |= GAIM_CBFLAGS_VOICE; | |
377 } | |
378 } | |
379 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { | |
380 xmlnode *photo = xmlnode_get_child(y, "photo"); | |
381 if(photo) { | |
382 if(avatar_hash) | |
383 g_free(avatar_hash); | |
384 avatar_hash = xmlnode_get_data(photo); | |
385 } | |
386 } | |
387 } | |
388 } | |
389 | |
390 | |
391 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { | |
392 static int i = 1; | |
393 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); | |
394 | |
395 if(state == JABBER_BUDDY_STATE_ERROR) { | |
396 char *title, *msg = jabber_parse_error(js, packet); | |
397 | |
398 if(chat->conv) { | |
399 title = g_strdup_printf(_("Error in chat %s"), from); | |
400 serv_got_chat_left(js->gc, chat->id); | |
401 } else { | |
402 title = g_strdup_printf(_("Error joining chat %s"), from); | |
403 } | |
404 gaim_notify_error(js->gc, title, title, msg); | |
405 g_free(title); | |
406 g_free(msg); | |
407 | |
408 jabber_chat_destroy(chat); | |
409 jabber_id_free(jid); | |
410 g_free(status); | |
411 g_free(room_jid); | |
412 if(avatar_hash) | |
413 g_free(avatar_hash); | |
414 return; | |
415 } | |
416 | |
417 | |
418 if(type && !strcmp(type, "unavailable")) { | |
419 gboolean nick_change = FALSE; | |
420 | |
421 /* If we haven't joined the chat yet, we don't care that someone | |
422 * left, or it was us leaving after we closed the chat */ | |
423 if(!chat->conv) { | |
424 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) | |
425 jabber_chat_destroy(chat); | |
426 jabber_id_free(jid); | |
427 g_free(status); | |
428 g_free(room_jid); | |
429 if(avatar_hash) | |
430 g_free(avatar_hash); | |
431 return; | |
432 } | |
433 | |
434 jabber_buddy_remove_resource(jb, jid->resource); | |
435 if(chat->muc) { | |
436 xmlnode *x; | |
437 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { | |
438 const char *xmlns, *nick, *code; | |
439 xmlnode *stat, *item; | |
440 if(!(xmlns = xmlnode_get_namespace(x)) || | |
441 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
442 continue; | |
443 if(!(stat = xmlnode_get_child(x, "status"))) | |
444 continue; | |
445 if(!(code = xmlnode_get_attrib(stat, "code"))) | |
446 continue; | |
447 if(!strcmp(code, "301")) { | |
448 /* XXX: we got banned */ | |
449 } else if(!strcmp(code, "303")) { | |
450 if(!(item = xmlnode_get_child(x, "item"))) | |
451 continue; | |
452 if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
453 continue; | |
454 nick_change = TRUE; | |
455 if(!strcmp(jid->resource, chat->handle)) { | |
456 g_free(chat->handle); | |
457 chat->handle = g_strdup(nick); | |
458 } | |
459 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
460 jabber_chat_remove_handle(chat, jid->resource); | |
461 break; | |
462 } else if(!strcmp(code, "307")) { | |
463 /* XXX: we got kicked */ | |
464 } else if(!strcmp(code, "321")) { | |
465 /* XXX: removed due to an affiliation change */ | |
466 } else if(!strcmp(code, "322")) { | |
467 /* XXX: removed because room is now members-only */ | |
468 } else if(!strcmp(code, "332")) { | |
469 /* XXX: removed due to system shutdown */ | |
470 } | |
471 } | |
472 } | |
473 if(!nick_change) { | |
474 if(!g_utf8_collate(jid->resource, chat->handle)) { | |
475 serv_got_chat_left(js->gc, chat->id); | |
476 jabber_chat_destroy(chat); | |
477 } else { | |
478 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
479 status); | |
480 jabber_chat_remove_handle(chat, jid->resource); | |
481 } | |
482 } | |
483 } else { | |
484 if(!chat->conv) { | |
485 chat->id = i++; | |
486 chat->muc = muc; | |
487 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
488 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle); | |
489 | |
490 jabber_chat_disco_traffic(chat); | |
491 } | |
492 | |
493 jabber_buddy_track_resource(jb, jid->resource, priority, state, | |
494 status); | |
495 | |
496 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); | |
497 | |
498 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) | |
499 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
500 real_jid, flags, !delayed); | |
501 else | |
502 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
503 flags); | |
504 } | |
505 g_free(room_jid); | |
506 } else { | |
507 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", | |
508 jid->node ? "@" : "", jid->domain); | |
509 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { | |
15263
dfaad00e60dd
[gaim-migrate @ 18052]
Evan Schoenberg <evan.s@dreskin.net>
parents:
15136
diff
changeset
|
510 gaim_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%x)", |
dfaad00e60dd
[gaim-migrate @ 18052]
Evan Schoenberg <evan.s@dreskin.net>
parents:
15136
diff
changeset
|
511 buddy_name, gaim_account_get_username(js->gc->account), js->gc->account); |
14192 | 512 jabber_id_free(jid); |
513 if(avatar_hash) | |
514 g_free(avatar_hash); | |
515 g_free(buddy_name); | |
516 g_free(status); | |
517 return; | |
518 } | |
519 | |
520 if(avatar_hash) { | |
521 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
522 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
523 JabberIq *iq; | |
524 xmlnode *vcard; | |
525 | |
526 /* XXX this is a crappy way of trying to prevent | |
527 * someone from spamming us with presence packets | |
528 * and causing us to DoS ourselves...what we really | |
529 * need is a queue system that can throttle itself, | |
530 * but i'm too tired to write that right now */ | |
531 if(!g_slist_find(js->pending_avatar_requests, jb)) { | |
532 | |
533 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb); | |
534 | |
535 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
536 xmlnode_set_attrib(iq->node, "to", buddy_name); | |
537 vcard = xmlnode_new_child(iq->node, "vCard"); | |
538 xmlnode_set_namespace(vcard, "vcard-temp"); | |
539 | |
540 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
541 jabber_iq_send(iq); | |
542 } | |
543 } | |
544 } | |
545 | |
546 if(state == JABBER_BUDDY_STATE_ERROR || | |
547 (type && (!strcmp(type, "unavailable") || | |
548 !strcmp(type, "unsubscribed")))) { | |
549 GaimConversation *conv; | |
550 | |
551 jabber_buddy_remove_resource(jb, jid->resource); | |
552 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) | |
553 gaim_conversation_set_name(conv, buddy_name); | |
554 | |
555 } else { | |
556 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, | |
557 state, status); | |
558 } | |
559 | |
560 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { | |
561 if(!jbr || jbr == found_jbr) { | |
562 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); | |
563 } | |
564 } else { | |
565 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); | |
566 } | |
567 g_free(buddy_name); | |
568 } | |
569 g_free(status); | |
570 jabber_id_free(jid); | |
571 if(avatar_hash) | |
572 g_free(avatar_hash); | |
573 } | |
574 | |
575 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
576 { | |
577 xmlnode *presence = xmlnode_new("presence"); | |
578 | |
579 xmlnode_set_attrib(presence, "to", who); | |
580 xmlnode_set_attrib(presence, "type", type); | |
581 | |
582 jabber_send(js, presence); | |
583 xmlnode_free(presence); | |
584 } | |
585 | |
14463 | 586 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, char **msg, int *priority) |
14192 | 587 { |
588 const char *status_id = NULL; | |
14463 | 589 const char *formatted_msg = NULL; |
14192 | 590 |
591 if(state) *state = JABBER_BUDDY_STATE_UNKNOWN; | |
592 if(msg) *msg = NULL; | |
593 if(priority) *priority = 0; | |
594 | |
595 if(!status) { | |
596 if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE; | |
597 } else { | |
598 if(state) { | |
599 status_id = gaim_status_get_id(status); | |
600 *state = jabber_buddy_status_id_get_state(status_id); | |
601 } | |
602 | |
603 if(msg) { | |
14463 | 604 formatted_msg = gaim_status_get_attr_string(status, "message"); |
14192 | 605 |
606 /* if the message is blank, then there really isn't a message */ | |
14463 | 607 if(formatted_msg && !*formatted_msg) |
608 formatted_msg = NULL; | |
609 | |
610 if(formatted_msg) | |
611 gaim_markup_html_to_xhtml(formatted_msg, NULL, msg); | |
14192 | 612 } |
613 | |
614 if(priority) | |
615 *priority = gaim_status_get_attr_int(status, "priority"); | |
616 } | |
617 } |