Fri, 16 Nov 2007 23:27:01 +0000
disapproval of revision '32d8e16cb7a9027ee3bcbba209d2fb36a6394a2f'
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 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 | |
|
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
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 19 | * |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | #include "debug.h" | |
| 23 | #include "server.h" | |
| 13809 | 24 | #include "util.h" |
| 7014 | 25 | |
| 26 | #include "buddy.h" | |
| 15265 | 27 | #include "google.h" |
| 7014 | 28 | #include "presence.h" |
| 29 | #include "roster.h" | |
| 30 | #include "iq.h" | |
| 31 | ||
| 32 | #include <string.h> | |
| 33 | ||
| 34 | ||
| 35 | void jabber_roster_request(JabberStream *js) | |
| 36 | { | |
| 37 | JabberIq *iq; | |
| 38 | ||
| 39 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster"); | |
| 40 | ||
| 41 | jabber_iq_send(iq); | |
| 42 | } | |
| 43 | ||
| 15884 | 44 | static void remove_purple_buddies(JabberStream *js, const char *jid) |
| 7014 | 45 | { |
| 46 | GSList *buddies, *l; | |
| 47 | ||
| 15884 | 48 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 49 | |
| 50 | for(l = buddies; l; l = l->next) | |
| 15884 | 51 | purple_blist_remove_buddy(l->data); |
| 7014 | 52 | |
| 53 | g_slist_free(buddies); | |
| 54 | } | |
| 55 | ||
| 15884 | 56 | static void add_purple_buddies_to_groups(JabberStream *js, const char *jid, |
| 7014 | 57 | const char *alias, GSList *groups) |
| 58 | { | |
| 59 | GSList *buddies, *g2, *l; | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
60 | gchar *my_bare_jid; |
|
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
|
61 | GList *pool = NULL; |
| 7014 | 62 | |
| 15884 | 63 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 64 | |
| 65 | g2 = groups; | |
| 66 | ||
| 67 | if(!groups) { | |
| 68 | if(!buddies) | |
| 69 | g2 = g_slist_append(g2, g_strdup(_("Buddies"))); | |
|
20913
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
70 | else { |
|
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
71 | g_slist_free(buddies); |
| 7014 | 72 | return; |
|
20913
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
73 | } |
| 7014 | 74 | } |
| 75 | ||
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
76 | my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
77 | |
| 7014 | 78 | while(buddies) { |
| 15884 | 79 | PurpleBuddy *b = buddies->data; |
| 80 | PurpleGroup *g = purple_buddy_get_group(b); | |
| 7014 | 81 | |
| 82 | buddies = g_slist_remove(buddies, b); | |
| 83 | ||
| 84 | if((l = g_slist_find_custom(g2, g->name, (GCompareFunc)strcmp))) { | |
| 7955 | 85 | const char *servernick; |
| 86 | ||
| 15884 | 87 | if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"))) |
| 7955 | 88 | serv_got_alias(js->gc, jid, servernick); |
| 89 | ||
| 7014 | 90 | if(alias && (!b->alias || strcmp(b->alias, alias))) |
| 15884 | 91 | purple_blist_alias_buddy(b, alias); |
| 7014 | 92 | g_free(l->data); |
| 93 | g2 = g_slist_delete_link(g2, l); | |
| 94 | } 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
|
95 | pool = g_list_prepend(pool, b); |
| 7014 | 96 | } |
| 97 | } | |
| 98 | ||
| 99 | while(g2) { | |
| 15884 | 100 | PurpleGroup *g = purple_find_group(g2->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
|
101 | 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
|
102 | |
|
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
|
103 | 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
|
104 | 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
|
105 | pool = g_list_delete_link(pool, 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
|
106 | } else { |
|
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
|
107 | 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
|
108 | } |
| 7014 | 109 | |
| 110 | if(!g) { | |
| 15884 | 111 | g = purple_group_new(g2->data); |
| 112 | purple_blist_add_group(g, NULL); | |
| 7014 | 113 | } |
| 114 | ||
| 15884 | 115 | purple_blist_add_buddy(b, NULL, g, NULL); |
| 116 | purple_blist_alias_buddy(b, alias); | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
117 | |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
118 | /* If we just learned about ourself, then fake our status, |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
119 | * because we won't be receiving a normal presence message |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
120 | * about ourself. */ |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
121 | if(!strcmp(b->name, my_bare_jid)) { |
| 15884 | 122 | PurplePresence *gpresence; |
| 123 | PurpleStatus *status; | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
124 | |
| 15884 | 125 | gpresence = purple_account_get_presence(js->gc->account); |
| 126 | status = purple_presence_get_active_status(gpresence); | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
127 | jabber_presence_fake_to_self(js, status); |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
128 | } |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
129 | |
| 7014 | 130 | g_free(g2->data); |
| 131 | g2 = g_slist_delete_link(g2, g2); | |
| 132 | } | |
| 133 | ||
|
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
|
134 | 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
|
135 | 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
|
136 | purple_blist_remove_buddy(b); |
|
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
|
137 | pool = g_list_delete_link(pool, 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
|
138 | } |
|
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
|
139 | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
140 | g_free(my_bare_jid); |
| 7014 | 141 | g_slist_free(buddies); |
| 142 | } | |
| 143 | ||
| 144 | void jabber_roster_parse(JabberStream *js, xmlnode *packet) | |
| 145 | { | |
| 146 | xmlnode *query, *item, *group; | |
| 147 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 7310 | 148 | |
| 149 | if(from) { | |
| 7445 | 150 | char *from_norm; |
| 7310 | 151 | gboolean invalid; |
| 7175 | 152 | |
| 7445 | 153 | from_norm = g_strdup(jabber_normalize(js->gc->account, from)); |
| 154 | ||
| 155 | if(!from_norm) | |
| 7310 | 156 | return; |
| 157 | ||
| 7445 | 158 | invalid = g_utf8_collate(from_norm, |
| 159 | jabber_normalize(js->gc->account, | |
| 15884 | 160 | purple_account_get_username(js->gc->account))); |
| 7175 | 161 | |
| 7310 | 162 | g_free(from_norm); |
| 163 | ||
| 164 | if(invalid) | |
| 165 | return; | |
| 7175 | 166 | } |
| 167 | ||
| 7014 | 168 | query = xmlnode_get_child(packet, "query"); |
| 169 | if(!query) | |
| 170 | return; | |
| 171 | ||
| 8135 | 172 | for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) |
| 7014 | 173 | { |
| 174 | const char *jid, *name, *subscription, *ask; | |
| 175 | JabberBuddy *jb; | |
| 176 | ||
| 177 | subscription = xmlnode_get_attrib(item, "subscription"); | |
| 178 | jid = xmlnode_get_attrib(item, "jid"); | |
| 179 | name = xmlnode_get_attrib(item, "name"); | |
| 180 | ask = xmlnode_get_attrib(item, "ask"); | |
| 181 | ||
| 8347 | 182 | if(!jid) |
| 183 | continue; | |
| 184 | ||
| 185 | if(!(jb = jabber_buddy_find(js, jid, TRUE))) | |
| 186 | continue; | |
| 7014 | 187 | |
| 10289 | 188 | if(subscription) { |
| 12285 | 189 | gint me = -1; |
| 190 | char *jid_norm; | |
| 191 | const char *username; | |
| 192 | ||
|
15695
0377506eda60
Fix problem with the previous leak fix pointed out by Etan.
Evan Schoenberg <evands@pidgin.im>
parents:
15688
diff
changeset
|
193 | jid_norm = g_strdup(jabber_normalize(js->gc->account, jid)); |
| 15884 | 194 | username = purple_account_get_username(js->gc->account); |
| 12285 | 195 | me = g_utf8_collate(jid_norm, |
| 196 | jabber_normalize(js->gc->account, | |
| 197 | username)); | |
|
15695
0377506eda60
Fix problem with the previous leak fix pointed out by Etan.
Evan Schoenberg <evands@pidgin.im>
parents:
15688
diff
changeset
|
198 | g_free(jid_norm); |
| 12285 | 199 | |
| 200 | if(me == 0) | |
| 201 | jb->subscription = JABBER_SUB_BOTH; | |
| 202 | else if(!strcmp(subscription, "none")) | |
| 203 | jb->subscription = JABBER_SUB_NONE; | |
| 204 | else if(!strcmp(subscription, "to")) | |
| 10289 | 205 | jb->subscription = JABBER_SUB_TO; |
| 206 | else if(!strcmp(subscription, "from")) | |
| 207 | jb->subscription = JABBER_SUB_FROM; | |
| 208 | else if(!strcmp(subscription, "both")) | |
| 209 | jb->subscription = JABBER_SUB_BOTH; | |
| 210 | else if(!strcmp(subscription, "remove")) | |
| 211 | jb->subscription = JABBER_SUB_REMOVE; | |
| 10941 | 212 | /* XXX: if subscription is now "from" or "none" we need to |
| 213 | * fake a signoff, since we won't get any presence from them | |
| 214 | * anymore */ | |
| 12285 | 215 | /* YYY: I was going to use this, but I'm not sure it's necessary |
| 216 | * anymore, but it's here in case it is. */ | |
| 217 | /* | |
| 218 | if ((jb->subscription & JABBER_SUB_FROM) || | |
| 219 | (jb->subscription & JABBER_SUB_NONE)) { | |
| 15884 | 220 | purple_prpl_got_user_status(js->gc->account, jid, "offline", NULL); |
| 12285 | 221 | } |
| 222 | */ | |
| 10289 | 223 | } |
| 7014 | 224 | |
| 225 | if(ask && !strcmp(ask, "subscribe")) | |
| 226 | jb->subscription |= JABBER_SUB_PENDING; | |
| 227 | else | |
| 228 | jb->subscription &= ~JABBER_SUB_PENDING; | |
| 229 | ||
| 8194 | 230 | if(jb->subscription == JABBER_SUB_REMOVE) { |
| 15884 | 231 | remove_purple_buddies(js, jid); |
| 7014 | 232 | } else { |
| 233 | GSList *groups = NULL; | |
|
20911
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
234 | |
|
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
235 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) |
|
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
236 | if (!jabber_google_roster_incoming(js, item)) |
|
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
237 | continue; |
|
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
238 | |
| 8135 | 239 | for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) { |
| 7316 | 240 | char *group_name; |
| 241 | ||
| 242 | if(!(group_name = xmlnode_get_data(group))) | |
| 243 | group_name = g_strdup(""); | |
| 13809 | 244 | |
| 15884 | 245 | if (g_slist_find_custom(groups, group_name, (GCompareFunc)purple_utf8_strcasecmp) == NULL) |
| 13809 | 246 | groups = g_slist_append(groups, group_name); |
|
20911
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
247 | else |
|
554739ed406e
Fix a couple leaks in parsing the xmpp roster.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
248 | g_free(group_name); |
| 7014 | 249 | } |
| 15884 | 250 | add_purple_buddies_to_groups(js, jid, name, groups); |
| 7014 | 251 | } |
| 252 | } | |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
253 | |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
254 | /* if we're just now parsing the roster for the first time, |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
255 | * then now would be the time to send our initial presence */ |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
256 | if(!js->roster_parsed) { |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
257 | js->roster_parsed = TRUE; |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
258 | |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
259 | jabber_presence_send(js->gc->account, NULL); |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
260 | } |
| 7014 | 261 | } |
| 262 | ||
| 263 | static void jabber_roster_update(JabberStream *js, const char *name, | |
| 264 | GSList *grps) | |
| 265 | { | |
| 15884 | 266 | PurpleBuddy *b; |
| 267 | PurpleGroup *g; | |
| 7014 | 268 | GSList *groups = NULL, *l; |
| 269 | JabberIq *iq; | |
| 270 | xmlnode *query, *item, *group; | |
| 271 | ||
|
20913
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
272 | if(!(b = purple_find_buddy(js->gc->account, name))) |
|
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
273 | return; |
|
30eb3334d381
Another couple leak fixes in the xmpp roster parsing.
Daniel Atallah <datallah@pidgin.im>
parents:
20911
diff
changeset
|
274 | |
| 7014 | 275 | if(grps) { |
| 276 | groups = grps; | |
| 277 | } else { | |
| 15884 | 278 | GSList *buddies = purple_find_buddies(js->gc->account, name); |
| 7014 | 279 | if(!buddies) |
| 280 | return; | |
| 281 | while(buddies) { | |
| 282 | b = buddies->data; | |
| 15884 | 283 | g = purple_buddy_get_group(b); |
| 7014 | 284 | groups = g_slist_append(groups, g->name); |
| 285 | buddies = g_slist_remove(buddies, b); | |
| 286 | } | |
| 287 | } | |
| 288 | ||
| 289 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 290 | ||
| 291 | query = xmlnode_get_child(iq->node, "query"); | |
| 292 | item = xmlnode_new_child(query, "item"); | |
| 293 | ||
| 294 | xmlnode_set_attrib(item, "jid", name); | |
| 295 | ||
| 15162 | 296 | xmlnode_set_attrib(item, "name", b->alias ? b->alias : ""); |
| 7014 | 297 | |
| 298 | for(l = groups; l; l = l->next) { | |
| 299 | group = xmlnode_new_child(item, "group"); | |
| 300 | xmlnode_insert_data(group, l->data, -1); | |
| 301 | } | |
| 302 | ||
| 303 | if(!grps) | |
| 304 | g_slist_free(groups); | |
| 15265 | 305 | |
| 306 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) { | |
| 307 | jabber_google_roster_outgoing(js, query, item); | |
| 308 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 309 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 310 | } | |
| 7014 | 311 | jabber_iq_send(iq); |
| 312 | } | |
| 313 | ||
| 15884 | 314 | void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 315 | PurpleGroup *group) | |
| 7014 | 316 | { |
| 317 | JabberStream *js = gc->proto_data; | |
| 318 | char *who; | |
| 7425 | 319 | GSList *groups = NULL; |
| 7014 | 320 | JabberBuddy *jb; |
| 7488 | 321 | JabberBuddyResource *jbr; |
| 8194 | 322 | char *my_bare_jid; |
| 7014 | 323 | |
| 324 | if(!js->roster_parsed) | |
| 325 | return; | |
| 326 | ||
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
327 | if(!(who = jabber_get_bare_jid(buddy->name))) |
| 7425 | 328 | return; |
| 7014 | 329 | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
330 | jb = jabber_buddy_find(js, buddy->name, FALSE); |
| 7425 | 331 | |
| 332 | if(!jb || !(jb->subscription & JABBER_SUB_TO)) { | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
333 | groups = g_slist_append(groups, group->name); |
| 7425 | 334 | } |
| 7014 | 335 | |
| 7449 | 336 | jabber_roster_update(js, who, groups); |
| 7014 | 337 | |
| 8194 | 338 | my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
| 9954 | 339 | if(!strcmp(who, my_bare_jid)) { |
| 15884 | 340 | PurplePresence *gpresence; |
| 341 | PurpleStatus *status; | |
| 9954 | 342 | |
| 15884 | 343 | gpresence = purple_account_get_presence(js->gc->account); |
| 344 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 345 | jabber_presence_fake_to_self(js, status); |
| 346 | } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { | |
| 7014 | 347 | jabber_presence_subscription_set(js, who, "subscribe"); |
| 9954 | 348 | } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { |
| 15884 | 349 | purple_prpl_got_user_status(gc->account, who, |
| 9954 | 350 | jabber_buddy_state_get_status_id(jbr->state), |
| 9990 | 351 | "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 352 | } |
| 7425 | 353 | |
| 8194 | 354 | g_free(my_bare_jid); |
| 7014 | 355 | g_free(who); |
| 356 | } | |
| 357 | ||
| 15884 | 358 | void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias) |
| 7014 | 359 | { |
| 15884 | 360 | PurpleBuddy *b = purple_find_buddy(gc->account, name); |
| 7449 | 361 | |
| 15321 | 362 | if(b != NULL) { |
| 15884 | 363 | purple_blist_alias_buddy(b, alias); |
| 7449 | 364 | |
| 15321 | 365 | jabber_roster_update(gc->proto_data, name, NULL); |
| 366 | } | |
| 7014 | 367 | } |
| 368 | ||
| 15884 | 369 | void jabber_roster_group_change(PurpleConnection *gc, const char *name, |
| 7014 | 370 | const char *old_group, const char *new_group) |
| 371 | { | |
| 372 | GSList *buddies, *groups = NULL; | |
| 15884 | 373 | PurpleBuddy *b; |
| 374 | PurpleGroup *g; | |
| 7014 | 375 | |
| 376 | if(!old_group || !new_group || !strcmp(old_group, new_group)) | |
| 377 | return; | |
| 378 | ||
| 15884 | 379 | buddies = purple_find_buddies(gc->account, name); |
| 7014 | 380 | while(buddies) { |
| 381 | b = buddies->data; | |
| 15884 | 382 | g = purple_buddy_get_group(b); |
| 7014 | 383 | if(!strcmp(g->name, old_group)) |
| 384 | groups = g_slist_append(groups, (char*)new_group); /* ick */ | |
| 385 | else | |
| 386 | groups = g_slist_append(groups, g->name); | |
| 387 | buddies = g_slist_remove(buddies, b); | |
| 388 | } | |
| 389 | jabber_roster_update(gc->proto_data, name, groups); | |
| 390 | g_slist_free(groups); | |
| 391 | } | |
| 392 | ||
| 15884 | 393 | void jabber_roster_group_rename(PurpleConnection *gc, const char *old_name, |
| 394 | PurpleGroup *group, GList *moved_buddies) | |
| 7014 | 395 | { |
| 396 | GList *l; | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
397 | for(l = moved_buddies; l; l = l->next) { |
| 15884 | 398 | PurpleBuddy *buddy = l->data; |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
399 | jabber_roster_group_change(gc, buddy->name, old_name, group->name); |
| 7014 | 400 | } |
| 401 | } | |
| 402 | ||
| 15884 | 403 | void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 404 | PurpleGroup *group) { | |
| 405 | GSList *buddies = purple_find_buddies(gc->account, buddy->name); | |
| 7014 | 406 | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
407 | 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
|
408 | if(buddies != NULL) { |
| 15884 | 409 | PurpleBuddy *tmpbuddy; |
| 410 | PurpleGroup *tmpgroup; | |
|
20926
1b7b1089c83d
Fix CID 312 (Dead code).
Daniel Atallah <datallah@pidgin.im>
parents:
20913
diff
changeset
|
411 | GSList *groups = NULL; |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
412 | |
| 7014 | 413 | while(buddies) { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
414 | tmpbuddy = buddies->data; |
| 15884 | 415 | tmpgroup = purple_buddy_get_group(tmpbuddy); |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
416 | groups = g_slist_append(groups, tmpgroup->name); |
|
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
417 | buddies = g_slist_remove(buddies, tmpbuddy); |
| 7014 | 418 | } |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
419 | |
|
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
420 | jabber_roster_update(gc->proto_data, buddy->name, groups); |
|
20926
1b7b1089c83d
Fix CID 312 (Dead code).
Daniel Atallah <datallah@pidgin.im>
parents:
20913
diff
changeset
|
421 | g_slist_free(groups); |
| 7014 | 422 | } else { |
| 7171 | 423 | JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET, |
| 424 | "jabber:iq:roster"); | |
| 425 | xmlnode *query = xmlnode_get_child(iq->node, "query"); | |
| 426 | xmlnode *item = xmlnode_new_child(query, "item"); | |
| 427 | ||
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
428 | xmlnode_set_attrib(item, "jid", buddy->name); |
| 7171 | 429 | xmlnode_set_attrib(item, "subscription", "remove"); |
| 430 | ||
| 431 | jabber_iq_send(iq); | |
| 7014 | 432 | } |
| 433 | } |