Mercurial > pidgin
annotate src/protocols/jabber/presence.c @ 10646:6a618db0a404
[gaim-migrate @ 12162]
Made IRC, Jabber, MSN, and ICQ not crash on login. Note that these don't
necessarily work the way they should yet, they just don't crash.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 01 Mar 2005 21:15:58 +0000 |
parents | 8bcf7909bec8 |
children | 72a5babfa8b4 |
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 | |
23 #include "debug.h" | |
24 #include "notify.h" | |
25 #include "request.h" | |
26 #include "server.h" | |
9954 | 27 #include "status.h" |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
28 #include "util.h" |
7014 | 29 |
30 #include "buddy.h" | |
31 #include "chat.h" | |
32 #include "presence.h" | |
33 #include "iq.h" | |
34 #include "jutil.h" | |
10189 | 35 #include "sha.h" |
7014 | 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; |
10189 | 94 xmlnode *presence, *x, *photo; |
7014 | 95 char *stripped = NULL; |
9954 | 96 const char *msg; |
97 JabberBuddyState state; | |
98 int priority; | |
7014 | 99 |
10486 | 100 if(!gaim_status_is_active(status)) |
101 return; | |
102 | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
103 if(!account) return ; |
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
104 gc = account->gc; |
10646 | 105 |
106 if (!gc && strcmp(gaim_status_get_id(status), "offline")) | |
107 gaim_account_connect(account, status); | |
108 | |
109 if(!gc) return; | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10286
diff
changeset
|
110 js= gc->proto_data; |
10646 | 111 |
9954 | 112 gaim_status_to_jabber(status, &state, &msg, &priority); |
113 | |
114 if(msg) | |
7095
c8bf2da398e3
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7015
diff
changeset
|
115 gaim_markup_html_to_xhtml(msg, NULL, &stripped); |
7014 | 116 |
9954 | 117 presence = jabber_presence_create(state, stripped, priority); |
118 g_free(stripped); | |
7014 | 119 |
120 jabber_send(js, presence); | |
10189 | 121 |
122 if(js->avatar_hash) { | |
123 x = xmlnode_new_child(presence, "x"); | |
124 xmlnode_set_attrib(x, "xmlns", "vcard-temp:x:update"); | |
125 photo = xmlnode_new_child(x, "photo"); | |
126 xmlnode_insert_data(photo, js->avatar_hash, -1); | |
127 } | |
128 | |
7014 | 129 g_hash_table_foreach(js->chats, chats_send_presence_foreach, presence); |
130 xmlnode_free(presence); | |
8185 | 131 |
9954 | 132 jabber_presence_fake_to_self(js, status); |
133 | |
7014 | 134 } |
135 | |
9954 | 136 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority) |
7014 | 137 { |
138 xmlnode *show, *status, *presence; | |
9954 | 139 const char *show_string = NULL; |
7014 | 140 |
141 | |
142 presence = xmlnode_new("presence"); | |
143 | |
144 | |
9954 | 145 if(state == JABBER_BUDDY_STATE_UNAVAILABLE) |
146 xmlnode_set_attrib(presence, "type", "unavailable"); | |
147 else if(state != JABBER_BUDDY_STATE_ONLINE && | |
148 state != JABBER_BUDDY_STATE_UNKNOWN && | |
149 state != JABBER_BUDDY_STATE_ERROR) | |
150 show_string = jabber_buddy_state_get_status_id(state); | |
151 | |
152 if(show_string) { | |
153 show = xmlnode_new_child(presence, "show"); | |
154 xmlnode_insert_data(show, show_string, -1); | |
7014 | 155 } |
156 | |
9954 | 157 if(msg) { |
7014 | 158 status = xmlnode_new_child(presence, "status"); |
159 xmlnode_insert_data(status, msg, -1); | |
160 } | |
161 | |
162 return presence; | |
163 } | |
164 | |
165 struct _jabber_add_permit { | |
166 GaimConnection *gc; | |
167 char *who; | |
168 }; | |
169 | |
170 static void authorize_add_cb(struct _jabber_add_permit *jap) | |
171 { | |
172 if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
173 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
174 "subscribed"); | |
175 | |
176 if(!gaim_find_buddy(jap->gc->account, jap->who)) | |
7015
dece74f05509
[gaim-migrate @ 7578]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
177 gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); |
7014 | 178 } |
179 | |
180 g_free(jap->who); | |
181 g_free(jap); | |
182 } | |
183 | |
184 static void deny_add_cb(struct _jabber_add_permit *jap) | |
185 { | |
186 if(g_list_find(gaim_connections_get_all(), jap->gc)) { | |
187 jabber_presence_subscription_set(jap->gc->proto_data, jap->who, | |
188 "unsubscribed"); | |
189 } | |
190 | |
191 g_free(jap->who); | |
192 g_free(jap); | |
193 } | |
194 | |
10189 | 195 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah) |
196 { | |
197 GaimBuddy *b = NULL; | |
198 xmlnode *vcard, *photo; | |
199 char *text, *data; | |
200 int size; | |
201 const char *from = xmlnode_get_attrib(packet, "from"); | |
202 | |
203 if(!from) | |
204 return; | |
205 | |
206 if((vcard = xmlnode_get_child(packet, "vCard")) || | |
207 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
208 if((photo = xmlnode_get_child(vcard, "PHOTO"))) { | |
209 if((text = xmlnode_get_data(photo))) { | |
210 gaim_base64_decode(text, &data, &size); | |
211 | |
212 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size); | |
213 if((b = gaim_find_buddy(js->gc->account, from))) { | |
214 unsigned char hashval[20]; | |
215 char hash[41], *p; | |
216 int i; | |
217 | |
218 shaBlock((unsigned char *)data, size, hashval); | |
219 p = hash; | |
220 for(i=0; i<20; i++, p+=2) | |
221 snprintf(p, 3, "%02x", hashval[i]); | |
222 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
223 } | |
224 } | |
225 } | |
226 } | |
227 } | |
228 | |
7014 | 229 void jabber_presence_parse(JabberStream *js, xmlnode *packet) |
230 { | |
231 const char *from = xmlnode_get_attrib(packet, "from"); | |
232 const char *type = xmlnode_get_attrib(packet, "type"); | |
7944 | 233 const char *real_jid = NULL; |
9152 | 234 const char *affiliation = NULL; |
235 const char *role = NULL; | |
7014 | 236 char *status = NULL; |
237 int priority = 0; | |
238 JabberID *jid; | |
239 JabberChat *chat; | |
240 JabberBuddy *jb; | |
9954 | 241 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; |
9554 | 242 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE; |
9846 | 243 gboolean delayed = FALSE; |
10189 | 244 GaimBuddy *b = NULL; |
7014 | 245 char *buddy_name; |
9954 | 246 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; |
7014 | 247 xmlnode *y; |
248 gboolean muc = FALSE; | |
10189 | 249 char *avatar_hash = NULL; |
7014 | 250 |
251 | |
8043 | 252 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
253 return; | |
254 | |
255 if(!(jid = jabber_id_new(from))) | |
7280 | 256 return; |
257 | |
7014 | 258 if(jb->error_msg) { |
259 g_free(jb->error_msg); | |
260 jb->error_msg = NULL; | |
261 } | |
262 | |
7813 | 263 if(type && !strcmp(type, "error")) { |
8401 | 264 char *msg = jabber_parse_error(js, packet); |
7644 | 265 |
9954 | 266 state = JABBER_BUDDY_STATE_ERROR; |
8401 | 267 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); |
7813 | 268 } else if(type && !strcmp(type, "subscribe")) { |
7014 | 269 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); |
270 char *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), from); | |
271 jap->gc = js->gc; | |
272 jap->who = g_strdup(from); | |
273 | |
10189 | 274 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, |
10116 | 275 jap, 2, |
7014 | 276 _("Authorize"), G_CALLBACK(authorize_add_cb), |
277 _("Deny"), G_CALLBACK(deny_add_cb)); | |
278 g_free(msg); | |
8043 | 279 jabber_id_free(jid); |
7145 | 280 return; |
7813 | 281 } else if(type && !strcmp(type, "subscribed")) { |
7014 | 282 /* we've been allowed to see their presence, but we don't care */ |
8043 | 283 jabber_id_free(jid); |
7014 | 284 return; |
285 } else { | |
286 if((y = xmlnode_get_child(packet, "show"))) { | |
287 char *show = xmlnode_get_data(y); | |
9954 | 288 state = jabber_buddy_status_id_get_state(show); |
7014 | 289 g_free(show); |
290 } else { | |
9954 | 291 state = JABBER_BUDDY_STATE_ONLINE; |
7014 | 292 } |
293 } | |
294 | |
7310 | 295 |
7014 | 296 for(y = packet->child; y; y = y->next) { |
8135 | 297 if(y->type != XMLNODE_TYPE_TAG) |
7014 | 298 continue; |
299 | |
300 if(!strcmp(y->name, "status")) { | |
7615 | 301 g_free(status); |
7014 | 302 status = xmlnode_get_data(y); |
303 } else if(!strcmp(y->name, "priority")) { | |
304 char *p = xmlnode_get_data(y); | |
305 if(p) { | |
306 priority = atoi(p); | |
307 g_free(p); | |
308 } | |
309 } else if(!strcmp(y->name, "x")) { | |
310 const char *xmlns = xmlnode_get_attrib(y, "xmlns"); | |
9846 | 311 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
9847 | 312 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ |
9846 | 313 delayed = TRUE; |
314 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { | |
7629 | 315 xmlnode *z; |
316 | |
7014 | 317 muc = TRUE; |
7629 | 318 if((z = xmlnode_get_child(y, "status"))) { |
319 const char *code = xmlnode_get_attrib(z, "code"); | |
320 if(code && !strcmp(code, "201")) { | |
7895 | 321 chat = jabber_chat_find(js, jid->node, jid->domain); |
8396 | 322 chat->config_dialog_type = GAIM_REQUEST_ACTION; |
323 chat->config_dialog_handle = | |
324 gaim_request_action(js->gc, _("Create New Room"), | |
7895 | 325 _("Create New Room"), |
326 _("You are creating a new room. Would you like to " | |
327 "configure it, or accept the default settings?"), | |
328 1, chat, 2, _("Configure Room"), | |
7923 | 329 G_CALLBACK(jabber_chat_request_room_configure), |
7895 | 330 _("Accept Defaults"), |
331 G_CALLBACK(jabber_chat_create_instant_room)); | |
7629 | 332 } |
333 } | |
7944 | 334 if((z = xmlnode_get_child(y, "item"))) { |
335 real_jid = xmlnode_get_attrib(z, "jid"); | |
9152 | 336 affiliation = xmlnode_get_attrib(z, "affiliation"); |
337 role = xmlnode_get_attrib(z, "role"); | |
9931 | 338 if(affiliation != NULL && !strcmp(affiliation, "owner")) |
339 flags |= GAIM_CBFLAGS_FOUNDER; | |
9743 | 340 if (role != NULL) { |
341 if (!strcmp(role, "moderator")) | |
9931 | 342 flags |= GAIM_CBFLAGS_OP; |
9743 | 343 else if (!strcmp(role, "participant")) |
9931 | 344 flags |= GAIM_CBFLAGS_VOICE; |
9743 | 345 } |
7944 | 346 } |
10189 | 347 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) { |
348 xmlnode *photo = xmlnode_get_child(y, "photo"); | |
349 if(photo) { | |
350 if(avatar_hash) | |
351 g_free(avatar_hash); | |
352 avatar_hash = xmlnode_get_data(photo); | |
353 } | |
7014 | 354 } |
355 } | |
356 } | |
357 | |
358 | |
7322 | 359 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { |
8462 | 360 static int i = 1; |
7014 | 361 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); |
362 | |
9954 | 363 if(state == JABBER_BUDDY_STATE_ERROR) { |
8401 | 364 char *title, *msg = jabber_parse_error(js, packet); |
7014 | 365 |
7321 | 366 if(chat->conv) { |
8401 | 367 title = g_strdup_printf(_("Error in chat %s"), from); |
7321 | 368 serv_got_chat_left(js->gc, chat->id); |
369 } else { | |
8401 | 370 title = g_strdup_printf(_("Error joining chat %s"), from); |
7321 | 371 } |
8401 | 372 gaim_notify_error(js->gc, title, title, msg); |
373 g_free(title); | |
374 g_free(msg); | |
7014 | 375 |
376 jabber_chat_destroy(chat); | |
7310 | 377 jabber_id_free(jid); |
7615 | 378 g_free(status); |
8182 | 379 g_free(room_jid); |
10189 | 380 if(avatar_hash) |
381 g_free(avatar_hash); | |
7014 | 382 return; |
383 } | |
384 | |
385 | |
7813 | 386 if(type && !strcmp(type, "unavailable")) { |
7972 | 387 gboolean nick_change = FALSE; |
7973 | 388 |
9152 | 389 /* If we haven't joined the chat yet, we don't care that someone |
390 * left, or it was us leaving after we closed the chat */ | |
8182 | 391 if(!chat->conv) { |
10558 | 392 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle)) |
9152 | 393 jabber_chat_destroy(chat); |
8182 | 394 jabber_id_free(jid); |
395 g_free(status); | |
396 g_free(room_jid); | |
10189 | 397 if(avatar_hash) |
398 g_free(avatar_hash); | |
8182 | 399 return; |
400 } | |
401 | |
7973 | 402 jabber_buddy_remove_resource(jb, jid->resource); |
7972 | 403 if(chat->muc) { |
404 xmlnode *x; | |
8135 | 405 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { |
7972 | 406 const char *xmlns, *nick, *code; |
407 xmlnode *stat, *item; | |
408 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || | |
409 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) | |
410 continue; | |
411 if(!(stat = xmlnode_get_child(x, "status"))) | |
412 continue; | |
9152 | 413 if(!(code = xmlnode_get_attrib(stat, "code"))) |
7972 | 414 continue; |
9152 | 415 if(!strcmp(code, "301")) { |
416 /* XXX: we got banned */ | |
417 } else if(!strcmp(code, "303")) { | |
418 if(!(item = xmlnode_get_child(x, "item"))) | |
419 continue; | |
420 if(!(nick = xmlnode_get_attrib(item, "nick"))) | |
421 continue; | |
422 nick_change = TRUE; | |
423 if(!strcmp(jid->resource, chat->handle)) { | |
424 g_free(chat->handle); | |
425 chat->handle = g_strdup(nick); | |
426 } | |
427 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); | |
428 jabber_chat_remove_handle(chat, jid->resource); | |
429 break; | |
430 } else if(!strcmp(code, "307")) { | |
431 /* XXX: we got kicked */ | |
432 } else if(!strcmp(code, "321")) { | |
433 /* XXX: removed due to an affiliation change */ | |
434 } else if(!strcmp(code, "322")) { | |
435 /* XXX: removed because room is now members-only */ | |
436 } else if(!strcmp(code, "332")) { | |
437 /* XXX: removed due to system shutdown */ | |
8401 | 438 } |
7972 | 439 } |
440 } | |
441 if(!nick_change) { | |
9152 | 442 if(!g_utf8_collate(jid->resource, chat->handle)) { |
7972 | 443 serv_got_chat_left(js->gc, chat->id); |
444 jabber_chat_destroy(chat); | |
445 } else { | |
446 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
7974 | 447 status); |
9152 | 448 jabber_chat_remove_handle(chat, jid->resource); |
7972 | 449 } |
7014 | 450 } |
451 } else { | |
8182 | 452 if(!chat->conv) { |
453 chat->id = i++; | |
454 chat->muc = muc; | |
455 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid); | |
8401 | 456 g_free(chat->handle); |
457 chat->handle = g_strdup(jid->resource); | |
8182 | 458 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), jid->resource); |
10486 | 459 |
460 /* <iq to='room@server' | |
461 type='get'> | |
462 <query xmlns='http://jabber.org/protocol/disco#info' | |
463 node='http://jabber.org/protocol/muc#traffic'/> | |
464 </iq> | |
465 */ | |
466 /* expected response format: | |
467 <iq from='room@server' | |
468 type='get'> | |
469 <query xmlns='http://jabber.org/protocol/disco#info' | |
470 node='http://jabber.org/protocol/muc#traffic'> | |
471 <feature var='http://jabber.org/protocol/xhtml-im'/> | |
472 <feature var='jabber:x:roster/'/> | |
473 </query> | |
474 </iq> | |
475 */ | |
476 /* | |
477 * XXX: i'm not sure if we turn off XHTML unless we get | |
478 * xhtml back in this, or if we turn it off only if we | |
479 * get a response, and it's not there. Ask stpeter to | |
480 * clarify. | |
481 */ | |
8182 | 482 } |
483 | |
7973 | 484 jabber_buddy_track_resource(jb, jid->resource, priority, state, |
485 status); | |
486 | |
9152 | 487 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role); |
488 | |
7014 | 489 if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
490 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource, |
9846 | 491 real_jid, flags, !delayed); |
9554 | 492 else |
493 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource, | |
494 flags); | |
7014 | 495 } |
496 g_free(room_jid); | |
497 } else { | |
10486 | 498 if(state != JABBER_BUDDY_STATE_ERROR && !(jb->subscription & JABBER_SUB_TO || jb->subscription & JABBER_SUB_PENDING)) { |
7014 | 499 gaim_debug(GAIM_DEBUG_INFO, "jabber", |
500 "got unexpected presence from %s, ignoring\n", from); | |
501 jabber_id_free(jid); | |
7615 | 502 g_free(status); |
10189 | 503 if(avatar_hash) |
504 g_free(avatar_hash); | |
7014 | 505 return; |
506 } | |
507 | |
7322 | 508 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", |
509 jid->node ? "@" : "", jid->domain); | |
7014 | 510 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { |
511 jabber_id_free(jid); | |
10189 | 512 if(avatar_hash) |
513 g_free(avatar_hash); | |
7014 | 514 g_free(buddy_name); |
7615 | 515 g_free(status); |
7014 | 516 return; |
517 } | |
518 | |
10189 | 519 if(avatar_hash) { |
520 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash"); | |
521 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) { | |
522 JabberIq *iq; | |
523 xmlnode *vcard; | |
524 | |
525 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
526 xmlnode_set_attrib(iq->node, "to", buddy_name); | |
527 vcard = xmlnode_new_child(iq->node, "vCard"); | |
528 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
529 | |
530 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); | |
531 jabber_iq_send(iq); | |
532 } | |
533 } | |
534 | |
9954 | 535 if(state == JABBER_BUDDY_STATE_ERROR || |
7813 | 536 (type && (!strcmp(type, "unavailable") || |
537 !strcmp(type, "unsubscribed")))) { | |
8043 | 538 GaimConversation *conv; |
539 | |
7014 | 540 jabber_buddy_remove_resource(jb, jid->resource); |
8043 | 541 if((conv = jabber_find_unnormalized_conv(from, js->gc->account))) |
542 gaim_conversation_set_name(conv, buddy_name); | |
543 | |
7395 | 544 } else { |
9954 | 545 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, |
546 state, status); | |
7395 | 547 } |
7014 | 548 |
9954 | 549 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { |
550 if(!jbr || jbr == found_jbr) { | |
9990 | 551 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 | 552 } |
553 } else { | |
9990 | 554 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); |
9954 | 555 } |
7014 | 556 g_free(buddy_name); |
557 } | |
558 g_free(status); | |
559 jabber_id_free(jid); | |
10189 | 560 if(avatar_hash) |
561 g_free(avatar_hash); | |
7014 | 562 } |
563 | |
564 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type) | |
565 { | |
566 xmlnode *presence = xmlnode_new("presence"); | |
567 | |
568 xmlnode_set_attrib(presence, "to", who); | |
569 xmlnode_set_attrib(presence, "type", type); | |
570 | |
571 jabber_send(js, presence); | |
572 xmlnode_free(presence); | |
573 } | |
9954 | 574 |
575 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, const char **msg, int *priority) | |
576 { | |
10216 | 577 const char *status_id = NULL; |
578 | |
579 *state = JABBER_BUDDY_STATE_UNKNOWN; | |
580 *msg = NULL; | |
581 *priority = 0; | |
9954 | 582 |
583 if(!status) { | |
10216 | 584 *state = JABBER_BUDDY_STATE_UNAVAILABLE; |
585 } else { | |
586 if(state) { | |
587 status_id = gaim_status_get_id(status); | |
588 *state = jabber_buddy_status_id_get_state(status_id); | |
589 } | |
590 | |
591 if(msg) | |
592 *msg = gaim_status_get_attr_string(status, "message"); | |
593 | |
594 if(priority) | |
595 *priority = gaim_status_get_attr_int(status, "priority"); | |
9954 | 596 } |
597 | |
598 } |