Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/roster.c @ 28506:2e3678cd33a0
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Need to strip the resource when adding a buddy, so that the core doesn't
think the buddy is named "juliet@capulet.lit/chamber", which apparently
causes very strange issues.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 31 Aug 2009 03:39:34 +0000 |
parents | c585572e80dd |
children | c42d5c23a9e8 |
comparison
equal
deleted
inserted
replaced
28505:cb8937a8a17f | 28506:2e3678cd33a0 |
---|---|
24 #include "debug.h" | 24 #include "debug.h" |
25 #include "server.h" | 25 #include "server.h" |
26 #include "util.h" | 26 #include "util.h" |
27 | 27 |
28 #include "buddy.h" | 28 #include "buddy.h" |
29 #include "chat.h" | |
29 #include "google.h" | 30 #include "google.h" |
30 #include "presence.h" | 31 #include "presence.h" |
31 #include "roster.h" | 32 #include "roster.h" |
32 #include "iq.h" | 33 #include "iq.h" |
33 | 34 |
334 void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, | 335 void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
335 PurpleGroup *group) | 336 PurpleGroup *group) |
336 { | 337 { |
337 JabberStream *js = gc->proto_data; | 338 JabberStream *js = gc->proto_data; |
338 char *who; | 339 char *who; |
340 JabberID *jid; | |
339 JabberBuddy *jb; | 341 JabberBuddy *jb; |
340 JabberBuddyResource *jbr; | 342 JabberBuddyResource *jbr; |
341 const char *name; | 343 const char *name; |
342 | 344 |
343 /* If we haven't received the roster yet, ignore any adds */ | 345 /* If we haven't received the roster yet, ignore any adds */ |
344 if (js->state != JABBER_STREAM_CONNECTED) | 346 if (js->state != JABBER_STREAM_CONNECTED) |
345 return; | 347 return; |
346 | 348 |
347 name = purple_buddy_get_name(buddy); | 349 name = purple_buddy_get_name(buddy); |
348 if(!(who = jabber_get_bare_jid(name))) | 350 jid = jabber_id_new(name); |
349 return; | 351 if (jid == NULL) { |
350 | 352 /* TODO: Remove the buddy from the list? */ |
351 jb = jabber_buddy_find(js, name, FALSE); | 353 return; |
352 | 354 } |
353 purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n", | 355 |
354 name); | 356 /* Adding a chat room or a chat buddy to the roster is *not* supported. */ |
357 if (jabber_chat_find(js, jid->node, jid->domain) != NULL) { | |
358 /* | |
359 * This is the same thing Bonjour does. If it causes problems, move | |
360 * it to an idle callback. | |
361 */ | |
362 purple_debug_warning("jabber", "Cowardly refusing to add a MUC user " | |
363 "to your buddy list and removing the buddy. " | |
364 "Buddies can only be added by real (non-MUC) " | |
365 "JID\n"); | |
366 purple_blist_remove_buddy(buddy); | |
367 jabber_id_free(jid); | |
368 return; | |
369 } | |
370 | |
371 who = jabber_id_get_bare_jid(jid); | |
372 if (jid->resource != NULL) { | |
373 /* | |
374 * If the buddy name added contains a resource, strip that off and | |
375 * rename the buddy. | |
376 */ | |
377 purple_blist_rename_buddy(buddy, who); | |
378 } | |
379 | |
380 jb = jabber_buddy_find(js, who, FALSE); | |
381 | |
382 purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n", who); | |
355 | 383 |
356 jabber_roster_update(js, who, NULL); | 384 jabber_roster_update(js, who, NULL); |
357 | 385 |
358 if (jb == js->user_jb) { | 386 if (jb == js->user_jb) { |
359 jabber_presence_fake_to_self(js, NULL); | 387 jabber_presence_fake_to_self(js, NULL); |