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