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 GaimBuddy *buddy = NULL;
|
|
185
|
|
186 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
|
|
187 "subscribed");
|
15048
|
188 #if 0
|
14192
|
189 buddy = gaim_find_buddy(jap->gc->account, jap->who);
|
|
190
|
|
191 if (buddy) {
|
|
192 JabberBuddy *jb = NULL;
|
|
193
|
|
194 jb = jabber_buddy_find(jap->js, jap->who, TRUE);
|
|
195
|
|
196 if ((jb->subscription & JABBER_SUB_TO) == 0) {
|
|
197 gaim_account_request_add(jap->gc->account,
|
|
198 jap->who, NULL,
|
|
199 NULL, NULL);
|
|
200 } else {
|
|
201 gaim_account_notify_added(jap->gc->account,
|
|
202 jap->who, NULL,
|
|
203 NULL, NULL);
|
|
204 }
|
|
205 } else {
|
|
206 gaim_account_request_add(jap->gc->account, jap->who,
|
|
207 NULL, NULL, NULL);
|
|
208 }
|
15048
|
209 #endif
|
14192
|
210 g_free(jap->who);
|
|
211 g_free(jap);
|
|
212 }
|
|
213
|
|
214 static void deny_add_cb(struct _jabber_add_permit *jap)
|
|
215 {
|
|
216 jabber_presence_subscription_set(jap->gc->proto_data, jap->who,
|
|
217 "unsubscribed");
|
|
218
|
|
219 g_free(jap->who);
|
|
220 g_free(jap);
|
|
221 }
|
|
222
|
|
223 static void jabber_vcard_parse_avatar(JabberStream *js, xmlnode *packet, gpointer blah)
|
|
224 {
|
|
225 JabberBuddy *jb = NULL;
|
|
226 GaimBuddy *b = NULL;
|
|
227 xmlnode *vcard, *photo, *binval;
|
|
228 char *text;
|
|
229 guchar *data;
|
|
230 gsize size;
|
|
231 const char *from = xmlnode_get_attrib(packet, "from");
|
|
232
|
|
233 if(!from)
|
|
234 return;
|
|
235
|
|
236 jb = jabber_buddy_find(js, from, TRUE);
|
|
237
|
|
238 js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb);
|
|
239
|
|
240 if((vcard = xmlnode_get_child(packet, "vCard")) ||
|
|
241 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
|
|
242 if((photo = xmlnode_get_child(vcard, "PHOTO")) &&
|
|
243 (( (binval = xmlnode_get_child(photo, "BINVAL")) &&
|
|
244 (text = xmlnode_get_data(binval))) ||
|
|
245 (text = xmlnode_get_data(photo)))) {
|
|
246 data = gaim_base64_decode(text, &size);
|
|
247
|
|
248 gaim_buddy_icons_set_for_user(js->gc->account, from, data, size);
|
|
249 if((b = gaim_find_buddy(js->gc->account, from))) {
|
|
250 unsigned char hashval[20];
|
|
251 char hash[41], *p;
|
|
252 int i;
|
|
253
|
|
254 gaim_cipher_digest_region("sha1", data, size,
|
|
255 sizeof(hashval), hashval, NULL);
|
|
256 p = hash;
|
|
257 for(i=0; i<20; i++, p+=2)
|
|
258 snprintf(p, 3, "%02x", hashval[i]);
|
|
259 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash);
|
|
260 }
|
|
261 g_free(data);
|
|
262 g_free(text);
|
|
263 }
|
|
264 }
|
|
265 }
|
|
266
|
|
267 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
|
|
268 {
|
|
269 const char *from = xmlnode_get_attrib(packet, "from");
|
|
270 const char *type = xmlnode_get_attrib(packet, "type");
|
|
271 const char *real_jid = NULL;
|
|
272 const char *affiliation = NULL;
|
|
273 const char *role = NULL;
|
|
274 char *status = NULL;
|
|
275 int priority = 0;
|
|
276 JabberID *jid;
|
|
277 JabberChat *chat;
|
|
278 JabberBuddy *jb;
|
|
279 JabberBuddyResource *jbr = NULL, *found_jbr = NULL;
|
|
280 GaimConvChatBuddyFlags flags = GAIM_CBFLAGS_NONE;
|
|
281 gboolean delayed = FALSE;
|
|
282 GaimBuddy *b = NULL;
|
|
283 char *buddy_name;
|
|
284 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN;
|
|
285 xmlnode *y;
|
|
286 gboolean muc = FALSE;
|
|
287 char *avatar_hash = NULL;
|
|
288
|
|
289 if(!(jb = jabber_buddy_find(js, from, TRUE)))
|
|
290 return;
|
|
291
|
|
292 if(!(jid = jabber_id_new(from)))
|
|
293 return;
|
|
294
|
|
295 if(jb->error_msg) {
|
|
296 g_free(jb->error_msg);
|
|
297 jb->error_msg = NULL;
|
|
298 }
|
|
299
|
|
300 if(type && !strcmp(type, "error")) {
|
|
301 char *msg = jabber_parse_error(js, packet);
|
|
302
|
|
303 state = JABBER_BUDDY_STATE_ERROR;
|
|
304 jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence"));
|
|
305 } else if(type && !strcmp(type, "subscribe")) {
|
|
306 struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1);
|
|
307 char *msg;
|
|
308
|
|
309 msg = g_strdup_printf(_("The user %s wants to add %s to his or "
|
|
310 "her buddy list."),
|
|
311 from, gaim_account_get_username(js->gc->account));
|
|
312 jap->gc = js->gc;
|
|
313 jap->who = g_strdup(from);
|
|
314 jap->js = js;
|
|
315
|
|
316 gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE,
|
|
317 jap, 2,
|
|
318 _("_Authorize"), G_CALLBACK(authorize_add_cb),
|
|
319 _("_Deny"), G_CALLBACK(deny_add_cb));
|
|
320 g_free(msg);
|
|
321 jabber_id_free(jid);
|
|
322 return;
|
|
323 } else if(type && !strcmp(type, "subscribed")) {
|
|
324 /* we've been allowed to see their presence, but we don't care */
|
|
325 jabber_id_free(jid);
|
|
326 return;
|
|
327 } else if(type && !strcmp(type, "unsubscribe")) {
|
|
328 /* XXX I'm not sure this is the right way to handle this, it
|
|
329 * might be better to add "unsubscribe" to the presence status
|
|
330 * if lower down, but I'm not sure. */
|
|
331 /* they are unsubscribing from our presence, we don't care */
|
|
332 /* Well, maybe just a little, we might want/need to start
|
|
333 * acknowledging this (and the others) at some point. */
|
|
334 jabber_id_free(jid);
|
|
335 return;
|
|
336 } else {
|
|
337 if((y = xmlnode_get_child(packet, "show"))) {
|
|
338 char *show = xmlnode_get_data(y);
|
|
339 state = jabber_buddy_show_get_state(show);
|
|
340 g_free(show);
|
|
341 } else {
|
|
342 state = JABBER_BUDDY_STATE_ONLINE;
|
|
343 }
|
|
344 }
|
|
345
|
|
346
|
|
347 for(y = packet->child; y; y = y->next) {
|
|
348 if(y->type != XMLNODE_TYPE_TAG)
|
|
349 continue;
|
|
350
|
|
351 if(!strcmp(y->name, "status")) {
|
|
352 g_free(status);
|
|
353 status = xmlnode_get_data(y);
|
|
354 } else if(!strcmp(y->name, "priority")) {
|
|
355 char *p = xmlnode_get_data(y);
|
|
356 if(p) {
|
|
357 priority = atoi(p);
|
|
358 g_free(p);
|
|
359 }
|
|
360 } else if(!strcmp(y->name, "x")) {
|
|
361 const char *xmlns = xmlnode_get_namespace(y);
|
|
362 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
|
|
363 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */
|
|
364 delayed = TRUE;
|
|
365 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
|
|
366 xmlnode *z;
|
|
367
|
|
368 muc = TRUE;
|
|
369 if((z = xmlnode_get_child(y, "status"))) {
|
|
370 const char *code = xmlnode_get_attrib(z, "code");
|
|
371 if(code && !strcmp(code, "201")) {
|
|
372 if((chat = jabber_chat_find(js, jid->node, jid->domain))) {
|
|
373 chat->config_dialog_type = GAIM_REQUEST_ACTION;
|
|
374 chat->config_dialog_handle =
|
|
375 gaim_request_action(js->gc,
|
|
376 _("Create New Room"),
|
|
377 _("Create New Room"),
|
|
378 _("You are creating a new room. Would"
|
|
379 " you like to configure it, or"
|
|
380 " accept the default settings?"),
|
|
381 1, chat, 2, _("_Configure Room"),
|
|
382 G_CALLBACK(jabber_chat_request_room_configure),
|
|
383 _("_Accept Defaults"),
|
|
384 G_CALLBACK(jabber_chat_create_instant_room));
|
|
385 }
|
|
386 }
|
|
387 }
|
|
388 if((z = xmlnode_get_child(y, "item"))) {
|
|
389 real_jid = xmlnode_get_attrib(z, "jid");
|
|
390 affiliation = xmlnode_get_attrib(z, "affiliation");
|
|
391 role = xmlnode_get_attrib(z, "role");
|
|
392 if(affiliation != NULL && !strcmp(affiliation, "owner"))
|
|
393 flags |= GAIM_CBFLAGS_FOUNDER;
|
|
394 if (role != NULL) {
|
|
395 if (!strcmp(role, "moderator"))
|
|
396 flags |= GAIM_CBFLAGS_OP;
|
|
397 else if (!strcmp(role, "participant"))
|
|
398 flags |= GAIM_CBFLAGS_VOICE;
|
|
399 }
|
|
400 }
|
|
401 } else if(xmlns && !strcmp(xmlns, "vcard-temp:x:update")) {
|
|
402 xmlnode *photo = xmlnode_get_child(y, "photo");
|
|
403 if(photo) {
|
|
404 if(avatar_hash)
|
|
405 g_free(avatar_hash);
|
|
406 avatar_hash = xmlnode_get_data(photo);
|
|
407 }
|
|
408 }
|
|
409 }
|
|
410 }
|
|
411
|
|
412
|
|
413 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) {
|
|
414 static int i = 1;
|
|
415 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
|
|
416
|
|
417 if(state == JABBER_BUDDY_STATE_ERROR) {
|
|
418 char *title, *msg = jabber_parse_error(js, packet);
|
|
419
|
|
420 if(chat->conv) {
|
|
421 title = g_strdup_printf(_("Error in chat %s"), from);
|
|
422 serv_got_chat_left(js->gc, chat->id);
|
|
423 } else {
|
|
424 title = g_strdup_printf(_("Error joining chat %s"), from);
|
|
425 }
|
|
426 gaim_notify_error(js->gc, title, title, msg);
|
|
427 g_free(title);
|
|
428 g_free(msg);
|
|
429
|
|
430 jabber_chat_destroy(chat);
|
|
431 jabber_id_free(jid);
|
|
432 g_free(status);
|
|
433 g_free(room_jid);
|
|
434 if(avatar_hash)
|
|
435 g_free(avatar_hash);
|
|
436 return;
|
|
437 }
|
|
438
|
|
439
|
|
440 if(type && !strcmp(type, "unavailable")) {
|
|
441 gboolean nick_change = FALSE;
|
|
442
|
|
443 /* If we haven't joined the chat yet, we don't care that someone
|
|
444 * left, or it was us leaving after we closed the chat */
|
|
445 if(!chat->conv) {
|
|
446 if(jid->resource && chat->handle && !strcmp(jid->resource, chat->handle))
|
|
447 jabber_chat_destroy(chat);
|
|
448 jabber_id_free(jid);
|
|
449 g_free(status);
|
|
450 g_free(room_jid);
|
|
451 if(avatar_hash)
|
|
452 g_free(avatar_hash);
|
|
453 return;
|
|
454 }
|
|
455
|
|
456 jabber_buddy_remove_resource(jb, jid->resource);
|
|
457 if(chat->muc) {
|
|
458 xmlnode *x;
|
|
459 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) {
|
|
460 const char *xmlns, *nick, *code;
|
|
461 xmlnode *stat, *item;
|
|
462 if(!(xmlns = xmlnode_get_namespace(x)) ||
|
|
463 strcmp(xmlns, "http://jabber.org/protocol/muc#user"))
|
|
464 continue;
|
|
465 if(!(stat = xmlnode_get_child(x, "status")))
|
|
466 continue;
|
|
467 if(!(code = xmlnode_get_attrib(stat, "code")))
|
|
468 continue;
|
|
469 if(!strcmp(code, "301")) {
|
|
470 /* XXX: we got banned */
|
|
471 } else if(!strcmp(code, "303")) {
|
|
472 if(!(item = xmlnode_get_child(x, "item")))
|
|
473 continue;
|
|
474 if(!(nick = xmlnode_get_attrib(item, "nick")))
|
|
475 continue;
|
|
476 nick_change = TRUE;
|
|
477 if(!strcmp(jid->resource, chat->handle)) {
|
|
478 g_free(chat->handle);
|
|
479 chat->handle = g_strdup(nick);
|
|
480 }
|
|
481 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick);
|
|
482 jabber_chat_remove_handle(chat, jid->resource);
|
|
483 break;
|
|
484 } else if(!strcmp(code, "307")) {
|
|
485 /* XXX: we got kicked */
|
|
486 } else if(!strcmp(code, "321")) {
|
|
487 /* XXX: removed due to an affiliation change */
|
|
488 } else if(!strcmp(code, "322")) {
|
|
489 /* XXX: removed because room is now members-only */
|
|
490 } else if(!strcmp(code, "332")) {
|
|
491 /* XXX: removed due to system shutdown */
|
|
492 }
|
|
493 }
|
|
494 }
|
|
495 if(!nick_change) {
|
|
496 if(!g_utf8_collate(jid->resource, chat->handle)) {
|
|
497 serv_got_chat_left(js->gc, chat->id);
|
|
498 jabber_chat_destroy(chat);
|
|
499 } else {
|
|
500 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
|
|
501 status);
|
|
502 jabber_chat_remove_handle(chat, jid->resource);
|
|
503 }
|
|
504 }
|
|
505 } else {
|
|
506 if(!chat->conv) {
|
|
507 chat->id = i++;
|
|
508 chat->muc = muc;
|
|
509 chat->conv = serv_got_joined_chat(js->gc, chat->id, room_jid);
|
|
510 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(chat->conv), chat->handle);
|
|
511
|
|
512 jabber_chat_disco_traffic(chat);
|
|
513 }
|
|
514
|
|
515 jabber_buddy_track_resource(jb, jid->resource, priority, state,
|
|
516 status);
|
|
517
|
|
518 jabber_chat_track_handle(chat, jid->resource, real_jid, affiliation, role);
|
|
519
|
|
520 if(!jabber_chat_find_buddy(chat->conv, jid->resource))
|
|
521 gaim_conv_chat_add_user(GAIM_CONV_CHAT(chat->conv), jid->resource,
|
|
522 real_jid, flags, !delayed);
|
|
523 else
|
|
524 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(chat->conv), jid->resource,
|
|
525 flags);
|
|
526 }
|
|
527 g_free(room_jid);
|
|
528 } else {
|
|
529 buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
|
|
530 jid->node ? "@" : "", jid->domain);
|
|
531 if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
|
|
532 jabber_id_free(jid);
|
|
533 if(avatar_hash)
|
|
534 g_free(avatar_hash);
|
|
535 g_free(buddy_name);
|
|
536 g_free(status);
|
|
537 return;
|
|
538 }
|
|
539
|
|
540 if(avatar_hash) {
|
|
541 const char *avatar_hash2 = gaim_blist_node_get_string((GaimBlistNode*)b, "avatar_hash");
|
|
542 if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) {
|
|
543 JabberIq *iq;
|
|
544 xmlnode *vcard;
|
|
545
|
|
546 /* XXX this is a crappy way of trying to prevent
|
|
547 * someone from spamming us with presence packets
|
|
548 * and causing us to DoS ourselves...what we really
|
|
549 * need is a queue system that can throttle itself,
|
|
550 * but i'm too tired to write that right now */
|
|
551 if(!g_slist_find(js->pending_avatar_requests, jb)) {
|
|
552
|
|
553 js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, jb);
|
|
554
|
|
555 iq = jabber_iq_new(js, JABBER_IQ_GET);
|
|
556 xmlnode_set_attrib(iq->node, "to", buddy_name);
|
|
557 vcard = xmlnode_new_child(iq->node, "vCard");
|
|
558 xmlnode_set_namespace(vcard, "vcard-temp");
|
|
559
|
|
560 jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL);
|
|
561 jabber_iq_send(iq);
|
|
562 }
|
|
563 }
|
|
564 }
|
|
565
|
|
566 if(state == JABBER_BUDDY_STATE_ERROR ||
|
|
567 (type && (!strcmp(type, "unavailable") ||
|
|
568 !strcmp(type, "unsubscribed")))) {
|
|
569 GaimConversation *conv;
|
|
570
|
|
571 jabber_buddy_remove_resource(jb, jid->resource);
|
|
572 if((conv = jabber_find_unnormalized_conv(from, js->gc->account)))
|
|
573 gaim_conversation_set_name(conv, buddy_name);
|
|
574
|
|
575 } else {
|
|
576 jbr = jabber_buddy_track_resource(jb, jid->resource, priority,
|
|
577 state, status);
|
|
578 }
|
|
579
|
|
580 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
|
|
581 if(!jbr || jbr == found_jbr) {
|
|
582 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);
|
|
583 }
|
|
584 } else {
|
|
585 gaim_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
|
|
586 }
|
|
587 g_free(buddy_name);
|
|
588 }
|
|
589 g_free(status);
|
|
590 jabber_id_free(jid);
|
|
591 if(avatar_hash)
|
|
592 g_free(avatar_hash);
|
|
593 }
|
|
594
|
|
595 void jabber_presence_subscription_set(JabberStream *js, const char *who, const char *type)
|
|
596 {
|
|
597 xmlnode *presence = xmlnode_new("presence");
|
|
598
|
|
599 xmlnode_set_attrib(presence, "to", who);
|
|
600 xmlnode_set_attrib(presence, "type", type);
|
|
601
|
|
602 jabber_send(js, presence);
|
|
603 xmlnode_free(presence);
|
|
604 }
|
|
605
|
14463
|
606 void gaim_status_to_jabber(const GaimStatus *status, JabberBuddyState *state, char **msg, int *priority)
|
14192
|
607 {
|
|
608 const char *status_id = NULL;
|
14463
|
609 const char *formatted_msg = NULL;
|
14192
|
610
|
|
611 if(state) *state = JABBER_BUDDY_STATE_UNKNOWN;
|
|
612 if(msg) *msg = NULL;
|
|
613 if(priority) *priority = 0;
|
|
614
|
|
615 if(!status) {
|
|
616 if(state) *state = JABBER_BUDDY_STATE_UNAVAILABLE;
|
|
617 } else {
|
|
618 if(state) {
|
|
619 status_id = gaim_status_get_id(status);
|
|
620 *state = jabber_buddy_status_id_get_state(status_id);
|
|
621 }
|
|
622
|
|
623 if(msg) {
|
14463
|
624 formatted_msg = gaim_status_get_attr_string(status, "message");
|
14192
|
625
|
|
626 /* if the message is blank, then there really isn't a message */
|
14463
|
627 if(formatted_msg && !*formatted_msg)
|
|
628 formatted_msg = NULL;
|
|
629
|
|
630 if(formatted_msg)
|
|
631 gaim_markup_html_to_xhtml(formatted_msg, NULL, msg);
|
14192
|
632 }
|
|
633
|
|
634 if(priority)
|
|
635 *priority = gaim_status_get_attr_int(status, "priority");
|
|
636 }
|
|
637 }
|