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