Sun, 22 Nov 2009 21:13:20 +0000
Documented chat API. References #10605
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
|
28322
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28071
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28071
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
28071
diff
changeset
|
6 | * source distribution. |
| 7014 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19630
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 21 | * |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | #include "debug.h" | |
| 25 | #include "server.h" | |
| 13809 | 26 | #include "util.h" |
| 7014 | 27 | |
| 28 | #include "buddy.h" | |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
29 | #include "chat.h" |
| 15265 | 30 | #include "google.h" |
| 7014 | 31 | #include "presence.h" |
| 32 | #include "roster.h" | |
| 33 | #include "iq.h" | |
| 34 | ||
| 35 | #include <string.h> | |
| 36 | ||
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
37 | /* Take a list of strings and join them with a ", " separator */ |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
38 | static gchar *roster_groups_join(GSList *list) |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
39 | { |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
40 | GString *out = g_string_new(NULL); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
41 | for ( ; list; list = list->next) { |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
42 | out = g_string_append(out, (const char *)list->data); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
43 | if (list->next) |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
44 | out = g_string_append(out, ", "); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
45 | } |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
46 | |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
47 | return g_string_free(out, FALSE); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
48 | } |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
49 | |
| 7014 | 50 | void jabber_roster_request(JabberStream *js) |
| 51 | { | |
| 52 | JabberIq *iq; | |
| 53 | ||
| 54 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster"); | |
| 55 | ||
| 56 | jabber_iq_send(iq); | |
| 57 | } | |
| 58 | ||
| 15884 | 59 | static void remove_purple_buddies(JabberStream *js, const char *jid) |
| 7014 | 60 | { |
| 61 | GSList *buddies, *l; | |
| 62 | ||
| 15884 | 63 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 64 | |
| 65 | for(l = buddies; l; l = l->next) | |
| 15884 | 66 | purple_blist_remove_buddy(l->data); |
| 7014 | 67 | |
| 68 | g_slist_free(buddies); | |
| 69 | } | |
| 70 | ||
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
71 | static void add_purple_buddy_to_groups(JabberStream *js, const char *jid, |
|
28071
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
72 | const char *alias, GSList *groups) |
| 7014 | 73 | { |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
74 | GSList *buddies, *l; |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
75 | GSList *pool = NULL; |
| 7014 | 76 | |
| 15884 | 77 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 78 | |
| 79 | if(!groups) { | |
| 80 | if(!buddies) | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
81 | groups = g_slist_append(groups, g_strdup(_("Buddies"))); |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
82 | else { |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
83 | /* TODO: What should we do here? Removing the local buddies |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
84 | * is wrong, but so is letting the group state get out of sync with |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
85 | * the server. |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
86 | */ |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
87 | g_slist_free(buddies); |
| 7014 | 88 | return; |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
89 | } |
| 7014 | 90 | } |
| 91 | ||
| 92 | while(buddies) { | |
| 15884 | 93 | PurpleBuddy *b = buddies->data; |
| 94 | PurpleGroup *g = purple_buddy_get_group(b); | |
| 7014 | 95 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
96 | buddies = g_slist_delete_link(buddies, buddies); |
| 7014 | 97 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
98 | /* XMPP groups are case-sensitive, but libpurple groups are |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
99 | * case-insensitive. We treat a buddy in both "Friends" and "friends" |
|
27743
ce49b08a7990
Clarify a comment a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
27742
diff
changeset
|
100 | * as only being in one group, but if we push changes about the buddy |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
101 | * to the server, the buddy will be dropped from one of the groups. |
|
27743
ce49b08a7990
Clarify a comment a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
27742
diff
changeset
|
102 | * Not optimal, but better than the alternative, I think. |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
103 | */ |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
104 | if((l = g_slist_find_custom(groups, purple_group_get_name(g), (GCompareFunc)purple_utf8_strcasecmp))) { |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
105 | /* The buddy is already on the local list. Update info. */ |
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
106 | const char *servernick, *balias; |
| 7955 | 107 | |
|
24199
8606cb4e94f5
The alias we retrieve from the roster is a private alias; use purple_serv_got_private_alias() to tell the core about it
Evan Schoenberg <evands@pidgin.im>
parents:
23975
diff
changeset
|
108 | /* Previously stored serverside / buddy-supplied alias */ |
| 15884 | 109 | if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"))) |
| 7955 | 110 | serv_got_alias(js->gc, jid, servernick); |
| 111 | ||
|
24199
8606cb4e94f5
The alias we retrieve from the roster is a private alias; use purple_serv_got_private_alias() to tell the core about it
Evan Schoenberg <evands@pidgin.im>
parents:
23975
diff
changeset
|
112 | /* Alias from our roster retrieval */ |
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
113 | balias = purple_buddy_get_local_buddy_alias(b); |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
114 | if(alias && !purple_strequal(alias, balias)) |
|
24199
8606cb4e94f5
The alias we retrieve from the roster is a private alias; use purple_serv_got_private_alias() to tell the core about it
Evan Schoenberg <evands@pidgin.im>
parents:
23975
diff
changeset
|
115 | purple_serv_got_private_alias(js->gc, jid, alias); |
| 7014 | 116 | g_free(l->data); |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
117 | groups = g_slist_delete_link(groups, l); |
| 7014 | 118 | } else { |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
119 | /* This buddy isn't in the group on the server anymore */ |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
120 | pool = g_slist_prepend(pool, b); |
| 7014 | 121 | } |
| 122 | } | |
| 123 | ||
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
124 | if (pool) { |
|
27742
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
125 | GString *tmp = g_string_new(NULL); |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
126 | GSList *list = pool; |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
127 | for ( ; list; list = list->next) { |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
128 | tmp = g_string_append(tmp, |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
129 | purple_group_get_name(purple_buddy_get_group(list->data))); |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
130 | if (list->next) |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
131 | tmp = g_string_append(tmp, ", "); |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
132 | } |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
133 | |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
134 | purple_debug_info("jabber", "jabber_roster_parse(): Removing %s from " |
|
27742
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
135 | "groups: %s\n", jid, tmp->str); |
|
d712c8326f8f
Properly print pool, a list of PurpleBuddies, not strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27283
diff
changeset
|
136 | g_string_free(tmp, TRUE); |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
137 | } |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
138 | |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
139 | if (groups) { |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
140 | char *tmp = roster_groups_join(groups); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
141 | purple_debug_info("jabber", "jabber_roster_parse(): Adding %s to " |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
142 | "groups: %s\n", jid, tmp); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
143 | g_free(tmp); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
144 | } |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
145 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
146 | while(groups) { |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
147 | PurpleGroup *g = purple_find_group(groups->data); |
|
19630
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
148 | PurpleBuddy *b = NULL; |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
149 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
150 | /* If there are buddies we would otherwise delete, move them to |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
151 | * the new group (instead of deleting them below) |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
152 | */ |
|
19630
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
153 | if (pool) { |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
154 | b = pool->data; |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
155 | pool = g_slist_delete_link(pool, pool); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24983
diff
changeset
|
156 | } else { |
|
19630
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
157 | b = purple_buddy_new(js->gc->account, jid, alias); |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
158 | } |
| 7014 | 159 | |
| 160 | if(!g) { | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
161 | g = purple_group_new(groups->data); |
| 15884 | 162 | purple_blist_add_group(g, NULL); |
| 7014 | 163 | } |
| 164 | ||
| 15884 | 165 | purple_blist_add_buddy(b, NULL, g, NULL); |
| 166 | purple_blist_alias_buddy(b, alias); | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
167 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
168 | g_free(groups->data); |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
169 | groups = g_slist_delete_link(groups, groups); |
| 7014 | 170 | } |
| 171 | ||
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
172 | /* Remove this person from all the groups they're no longer in on the |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
173 | * server */ |
|
19630
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
174 | while (pool) { |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
175 | PurpleBuddy *b = pool->data; |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
176 | purple_blist_remove_buddy(b); |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
177 | pool = g_slist_delete_link(pool, pool); |
|
19630
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
178 | } |
|
7e24a9784ce8
Update the buddylist if a buddy is moved to another group from a different
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18196
diff
changeset
|
179 | |
| 7014 | 180 | g_slist_free(buddies); |
| 181 | } | |
| 182 | ||
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
24672
diff
changeset
|
183 | void jabber_roster_parse(JabberStream *js, const char *from, |
|
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
24672
diff
changeset
|
184 | JabberIqType type, const char *id, xmlnode *query) |
| 7014 | 185 | { |
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
24672
diff
changeset
|
186 | xmlnode *item, *group; |
| 7445 | 187 | |
|
27275
a7836fbdcfa2
Use jabber_is_own_account and perform way fewer normalizations per iteration
Paul Aurich <darkrain42@pidgin.im>
parents:
27242
diff
changeset
|
188 | if (!jabber_is_own_account(js, from)) { |
|
a7836fbdcfa2
Use jabber_is_own_account and perform way fewer normalizations per iteration
Paul Aurich <darkrain42@pidgin.im>
parents:
27242
diff
changeset
|
189 | purple_debug_warning("jabber", "Received bogon roster push from %s\n", |
|
a7836fbdcfa2
Use jabber_is_own_account and perform way fewer normalizations per iteration
Paul Aurich <darkrain42@pidgin.im>
parents:
27242
diff
changeset
|
190 | from); |
|
a7836fbdcfa2
Use jabber_is_own_account and perform way fewer normalizations per iteration
Paul Aurich <darkrain42@pidgin.im>
parents:
27242
diff
changeset
|
191 | return; |
| 7175 | 192 | } |
| 193 | ||
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
194 | js->currently_parsing_roster_push = TRUE; |
|
23961
0a9e9676f7b5
Hopefully fix the XMPP contact flipping/swapping between groups bug
Mark Doliner <markdoliner@pidgin.im>
parents:
23566
diff
changeset
|
195 | |
| 8135 | 196 | for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) |
| 7014 | 197 | { |
| 198 | const char *jid, *name, *subscription, *ask; | |
| 199 | JabberBuddy *jb; | |
| 200 | ||
| 201 | subscription = xmlnode_get_attrib(item, "subscription"); | |
| 202 | jid = xmlnode_get_attrib(item, "jid"); | |
| 203 | name = xmlnode_get_attrib(item, "name"); | |
| 204 | ask = xmlnode_get_attrib(item, "ask"); | |
| 205 | ||
| 8347 | 206 | if(!jid) |
| 207 | continue; | |
| 208 | ||
| 209 | if(!(jb = jabber_buddy_find(js, jid, TRUE))) | |
| 210 | continue; | |
| 7014 | 211 | |
| 10289 | 212 | if(subscription) { |
|
28071
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
213 | if (jb == js->user_jb) |
| 12285 | 214 | jb->subscription = JABBER_SUB_BOTH; |
| 215 | else if(!strcmp(subscription, "none")) | |
| 216 | jb->subscription = JABBER_SUB_NONE; | |
| 217 | else if(!strcmp(subscription, "to")) | |
| 10289 | 218 | jb->subscription = JABBER_SUB_TO; |
| 219 | else if(!strcmp(subscription, "from")) | |
| 220 | jb->subscription = JABBER_SUB_FROM; | |
| 221 | else if(!strcmp(subscription, "both")) | |
| 222 | jb->subscription = JABBER_SUB_BOTH; | |
| 223 | else if(!strcmp(subscription, "remove")) | |
| 224 | jb->subscription = JABBER_SUB_REMOVE; | |
| 225 | } | |
| 7014 | 226 | |
|
27276
d3c4ec6e0b2f
Remove this; it's been commented out for about 3.5 years.
Paul Aurich <darkrain42@pidgin.im>
parents:
27275
diff
changeset
|
227 | if(purple_strequal(ask, "subscribe")) |
| 7014 | 228 | jb->subscription |= JABBER_SUB_PENDING; |
| 229 | else | |
| 230 | jb->subscription &= ~JABBER_SUB_PENDING; | |
| 231 | ||
|
28622
5d971bd4b001
jabber: Fix removing a buddy with a pending subscription.
Paul Aurich <darkrain42@pidgin.im>
parents:
28584
diff
changeset
|
232 | if(jb->subscription & JABBER_SUB_REMOVE) { |
| 15884 | 233 | remove_purple_buddies(js, jid); |
| 7014 | 234 | } else { |
| 235 | GSList *groups = NULL; | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
236 | gboolean seen_empty = FALSE; |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
237 | |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
238 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
239 | if (!jabber_google_roster_incoming(js, item)) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
240 | continue; |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
241 | |
| 8135 | 242 | for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) { |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
243 | char *group_name = xmlnode_get_data(group); |
| 13809 | 244 | |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
245 | if (!group_name && !seen_empty) { |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
246 | group_name = g_strdup(""); |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
247 | seen_empty = TRUE; |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
248 | } |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
249 | |
|
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
250 | groups = g_slist_prepend(groups, group_name); |
| 7014 | 251 | } |
|
27277
8a2ecbdd70e4
Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents:
27276
diff
changeset
|
252 | |
|
28071
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
253 | add_purple_buddy_to_groups(js, jid, name, groups); |
|
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
254 | if (jb == js->user_jb) |
|
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
255 | jabber_presence_fake_to_self(js, NULL); |
| 7014 | 256 | } |
| 257 | } | |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
258 | |
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
259 | js->currently_parsing_roster_push = FALSE; |
|
23961
0a9e9676f7b5
Hopefully fix the XMPP contact flipping/swapping between groups bug
Mark Doliner <markdoliner@pidgin.im>
parents:
23566
diff
changeset
|
260 | |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
261 | /* if we're just now parsing the roster for the first time, |
|
27278
b34a1cea4872
Use js->state to track whether the roster has been retrieved.
Paul Aurich <darkrain42@pidgin.im>
parents:
27277
diff
changeset
|
262 | * then now would be the time to declare ourselves connected. |
|
b34a1cea4872
Use js->state to track whether the roster has been retrieved.
Paul Aurich <darkrain42@pidgin.im>
parents:
27277
diff
changeset
|
263 | */ |
|
b34a1cea4872
Use js->state to track whether the roster has been retrieved.
Paul Aurich <darkrain42@pidgin.im>
parents:
27277
diff
changeset
|
264 | if (js->state != JABBER_STREAM_CONNECTED) |
|
25799
f2b56ff62042
Wait until receiving the roster to tell the core we're logged in
Paul Aurich <darkrain42@pidgin.im>
parents:
24717
diff
changeset
|
265 | jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
| 7014 | 266 | } |
| 267 | ||
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
268 | /* jabber_roster_update frees the GSList* passed in */ |
| 7014 | 269 | static void jabber_roster_update(JabberStream *js, const char *name, |
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
270 | GSList *groups) |
| 7014 | 271 | { |
| 15884 | 272 | PurpleBuddy *b; |
| 273 | PurpleGroup *g; | |
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
274 | GSList *l; |
| 7014 | 275 | JabberIq *iq; |
| 276 | xmlnode *query, *item, *group; | |
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
277 | const char *balias; |
| 7014 | 278 | |
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
279 | if (js->currently_parsing_roster_push) |
|
23961
0a9e9676f7b5
Hopefully fix the XMPP contact flipping/swapping between groups bug
Mark Doliner <markdoliner@pidgin.im>
parents:
23566
diff
changeset
|
280 | return; |
|
0a9e9676f7b5
Hopefully fix the XMPP contact flipping/swapping between groups bug
Mark Doliner <markdoliner@pidgin.im>
parents:
23566
diff
changeset
|
281 | |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
282 | if(!(b = purple_find_buddy(js->gc->account, name))) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
283 | return; |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
284 | |
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
285 | if (groups) { |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
286 | char *tmp = roster_groups_join(groups); |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
287 | |
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
288 | purple_debug_info("jabber", "jabber_roster_update(%s): [Source: " |
|
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
289 | "groups]: groups: %s\n", name, tmp); |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
290 | g_free(tmp); |
| 7014 | 291 | } else { |
| 15884 | 292 | GSList *buddies = purple_find_buddies(js->gc->account, name); |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
293 | char *tmp; |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
294 | |
| 7014 | 295 | if(!buddies) |
| 296 | return; | |
| 297 | while(buddies) { | |
| 298 | b = buddies->data; | |
| 15884 | 299 | g = purple_buddy_get_group(b); |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
300 | groups = g_slist_append(groups, (char *)purple_group_get_name(g)); |
| 7014 | 301 | buddies = g_slist_remove(buddies, b); |
| 302 | } | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
303 | |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
304 | tmp = roster_groups_join(groups); |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
305 | purple_debug_info("jabber", "jabber_roster_update(%s): [Source: local blist]: groups: %s\n", |
|
27282
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
306 | name, tmp); |
|
791c6a965694
Debug output when changing group memberships.
Paul Aurich <darkrain42@pidgin.im>
parents:
27281
diff
changeset
|
307 | g_free(tmp); |
| 7014 | 308 | } |
| 309 | ||
| 310 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 311 | ||
| 312 | query = xmlnode_get_child(iq->node, "query"); | |
| 313 | item = xmlnode_new_child(query, "item"); | |
| 314 | ||
| 315 | xmlnode_set_attrib(item, "jid", name); | |
| 316 | ||
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
317 | balias = purple_buddy_get_local_buddy_alias(b); |
|
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
318 | xmlnode_set_attrib(item, "name", balias ? balias : ""); |
| 7014 | 319 | |
| 320 | for(l = groups; l; l = l->next) { | |
| 321 | group = xmlnode_new_child(item, "group"); | |
| 322 | xmlnode_insert_data(group, l->data, -1); | |
| 323 | } | |
| 324 | ||
|
27283
9a69f682a3ca
Operate on the passed-in GSList.
Paul Aurich <darkrain42@pidgin.im>
parents:
27282
diff
changeset
|
325 | g_slist_free(groups); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24983
diff
changeset
|
326 | |
| 15265 | 327 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) { |
| 328 | jabber_google_roster_outgoing(js, query, item); | |
| 329 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 330 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 331 | } | |
| 7014 | 332 | jabber_iq_send(iq); |
| 333 | } | |
| 334 | ||
| 15884 | 335 | void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 336 | PurpleGroup *group) | |
| 7014 | 337 | { |
| 338 | JabberStream *js = gc->proto_data; | |
| 339 | char *who; | |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
340 | JabberID *jid; |
| 7014 | 341 | JabberBuddy *jb; |
| 7488 | 342 | JabberBuddyResource *jbr; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
343 | const char *name; |
| 7014 | 344 | |
|
27278
b34a1cea4872
Use js->state to track whether the roster has been retrieved.
Paul Aurich <darkrain42@pidgin.im>
parents:
27277
diff
changeset
|
345 | /* If we haven't received the roster yet, ignore any adds */ |
|
b34a1cea4872
Use js->state to track whether the roster has been retrieved.
Paul Aurich <darkrain42@pidgin.im>
parents:
27277
diff
changeset
|
346 | if (js->state != JABBER_STREAM_CONNECTED) |
| 7014 | 347 | return; |
| 348 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
349 | name = purple_buddy_get_name(buddy); |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
350 | jid = jabber_id_new(name); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
351 | if (jid == NULL) { |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
352 | /* TODO: Remove the buddy from the list? */ |
| 7425 | 353 | return; |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
354 | } |
| 7014 | 355 | |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
356 | /* Adding a chat room or a chat buddy to the roster is *not* supported. */ |
|
28584
1226297d1ba9
jabber: Don't crash when adding a buddy without a node (no '@'). Closes #10261.
Paul Aurich <darkrain42@pidgin.im>
parents:
28431
diff
changeset
|
357 | if (jid->node && jabber_chat_find(js, jid->node, jid->domain) != NULL) { |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
358 | /* |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
359 | * This is the same thing Bonjour does. If it causes problems, move |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
360 | * it to an idle callback. |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
361 | */ |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
362 | purple_debug_warning("jabber", "Cowardly refusing to add a MUC user " |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
363 | "to your buddy list and removing the buddy. " |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
364 | "Buddies can only be added by real (non-MUC) " |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
365 | "JID\n"); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
366 | purple_blist_remove_buddy(buddy); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
367 | jabber_id_free(jid); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
368 | return; |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
369 | } |
| 7425 | 370 | |
|
28431
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
371 | who = jabber_id_get_bare_jid(jid); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
372 | if (jid->resource != NULL) { |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
373 | /* |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
374 | * If the buddy name added contains a resource, strip that off and |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
375 | * rename the buddy. |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
376 | */ |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
377 | purple_blist_rename_buddy(buddy, who); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
378 | } |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
379 | |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
380 | jb = jabber_buddy_find(js, who, FALSE); |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
381 | |
|
8450418b5abd
jabber: Properly handle adding buddies that contain a resource. Closes #10151.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
382 | purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n", who); |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
383 | |
|
23566
fabe91dee1e1
Alright, I'm getting rid of this "groups" thing for the reason listed
Mark Doliner <markdoliner@pidgin.im>
parents:
22993
diff
changeset
|
384 | jabber_roster_update(js, who, NULL); |
| 7014 | 385 | |
|
28071
a0706162fefd
jabber: Store the "own JabberBuddy" in the JabberStream* struct.
Paul Aurich <darkrain42@pidgin.im>
parents:
27743
diff
changeset
|
386 | if (jb == js->user_jb) { |
|
27280
55a39efcf7b8
Simplify the fake_to_self function.
Paul Aurich <darkrain42@pidgin.im>
parents:
27278
diff
changeset
|
387 | jabber_presence_fake_to_self(js, NULL); |
| 9954 | 388 | } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { |
| 7014 | 389 | jabber_presence_subscription_set(js, who, "subscribe"); |
| 9954 | 390 | } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { |
| 15884 | 391 | purple_prpl_got_user_status(gc->account, who, |
| 9954 | 392 | jabber_buddy_state_get_status_id(jbr->state), |
| 9990 | 393 | "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 394 | } |
| 7425 | 395 | |
| 7014 | 396 | g_free(who); |
| 397 | } | |
| 398 | ||
| 15884 | 399 | void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias) |
| 7014 | 400 | { |
| 15884 | 401 | PurpleBuddy *b = purple_find_buddy(gc->account, name); |
| 7449 | 402 | |
| 15321 | 403 | if(b != NULL) { |
| 15884 | 404 | purple_blist_alias_buddy(b, alias); |
| 7449 | 405 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
406 | purple_debug_info("jabber", "jabber_roster_alias_change(): Aliased %s to %s\n", |
|
27242
05618d46ac91
Ladedah I dislike the need to explicitly check for NULL strings.
Paul Aurich <darkrain42@pidgin.im>
parents:
27230
diff
changeset
|
407 | name, alias ? alias : "(null)"); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
408 | |
| 15321 | 409 | jabber_roster_update(gc->proto_data, name, NULL); |
| 410 | } | |
| 7014 | 411 | } |
| 412 | ||
| 15884 | 413 | void jabber_roster_group_change(PurpleConnection *gc, const char *name, |
| 7014 | 414 | const char *old_group, const char *new_group) |
| 415 | { | |
| 416 | GSList *buddies, *groups = NULL; | |
| 15884 | 417 | PurpleBuddy *b; |
| 418 | PurpleGroup *g; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
419 | const char *gname; |
| 7014 | 420 | |
| 421 | if(!old_group || !new_group || !strcmp(old_group, new_group)) | |
| 422 | return; | |
| 423 | ||
| 15884 | 424 | buddies = purple_find_buddies(gc->account, name); |
| 7014 | 425 | while(buddies) { |
| 426 | b = buddies->data; | |
| 15884 | 427 | g = purple_buddy_get_group(b); |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
428 | gname = purple_group_get_name(g); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
429 | if(!strcmp(gname, old_group)) |
| 7014 | 430 | groups = g_slist_append(groups, (char*)new_group); /* ick */ |
| 431 | else | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
432 | groups = g_slist_append(groups, (char*)gname); |
| 7014 | 433 | buddies = g_slist_remove(buddies, b); |
| 434 | } | |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
435 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
436 | purple_debug_info("jabber", "jabber_roster_group_change(): Moving %s from %s to %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
437 | name, old_group, new_group); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
438 | |
| 7014 | 439 | jabber_roster_update(gc->proto_data, name, groups); |
| 440 | } | |
| 441 | ||
| 15884 | 442 | void jabber_roster_group_rename(PurpleConnection *gc, const char *old_name, |
| 443 | PurpleGroup *group, GList *moved_buddies) | |
| 7014 | 444 | { |
| 445 | GList *l; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
446 | const char *gname = purple_group_get_name(group); |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
447 | for(l = moved_buddies; l; l = l->next) { |
| 15884 | 448 | PurpleBuddy *buddy = l->data; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
449 | jabber_roster_group_change(gc, purple_buddy_get_name(buddy), old_name, gname); |
| 7014 | 450 | } |
| 451 | } | |
| 452 | ||
| 15884 | 453 | void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 454 | PurpleGroup *group) { | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
455 | const char *name = purple_buddy_get_name(buddy); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
456 | GSList *buddies = purple_find_buddies(purple_connection_get_account(gc), name); |
| 7014 | 457 | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
458 | buddies = g_slist_remove(buddies, buddy); |
|
15847
da522f9a7743
Don't use g_list_length() and g_slist_length() when all you want to
Mark Doliner <markdoliner@pidgin.im>
parents:
15695
diff
changeset
|
459 | if(buddies != NULL) { |
| 15884 | 460 | PurpleBuddy *tmpbuddy; |
| 461 | PurpleGroup *tmpgroup; | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20221
diff
changeset
|
462 | GSList *groups = NULL; |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
463 | |
| 7014 | 464 | while(buddies) { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
465 | tmpbuddy = buddies->data; |
| 15884 | 466 | tmpgroup = purple_buddy_get_group(tmpbuddy); |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
467 | groups = g_slist_append(groups, (char *)purple_group_get_name(tmpgroup)); |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
468 | buddies = g_slist_remove(buddies, tmpbuddy); |
| 7014 | 469 | } |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
470 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
471 | purple_debug_info("jabber", "jabber_roster_remove_buddy(): Removing %s from %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
472 | purple_buddy_get_name(buddy), purple_group_get_name(group)); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
473 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
474 | jabber_roster_update(gc->proto_data, name, groups); |
| 7014 | 475 | } else { |
| 7171 | 476 | JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET, |
| 477 | "jabber:iq:roster"); | |
| 478 | xmlnode *query = xmlnode_get_child(iq->node, "query"); | |
| 479 | xmlnode *item = xmlnode_new_child(query, "item"); | |
| 480 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
481 | xmlnode_set_attrib(item, "jid", name); |
| 7171 | 482 | xmlnode_set_attrib(item, "subscription", "remove"); |
| 483 | ||
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
484 | purple_debug_info("jabber", "jabber_roster_remove_buddy(): Removing %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
485 | purple_buddy_get_name(buddy)); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
486 | |
| 7171 | 487 | jabber_iq_send(iq); |
| 7014 | 488 | } |
| 489 | } |