Wed, 03 Jun 2009 15:50:08 +0000
Add a few more roster debug messages and improve.
| 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 | void jabber_roster_request(JabberStream *js) | |
| 35 | { | |
| 36 | JabberIq *iq; | |
| 37 | ||
| 38 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster"); | |
| 39 | ||
| 40 | jabber_iq_send(iq); | |
| 41 | } | |
| 42 | ||
| 15884 | 43 | static void remove_purple_buddies(JabberStream *js, const char *jid) |
| 7014 | 44 | { |
| 45 | GSList *buddies, *l; | |
| 46 | ||
| 15884 | 47 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 48 | |
| 49 | for(l = buddies; l; l = l->next) | |
| 15884 | 50 | purple_blist_remove_buddy(l->data); |
| 7014 | 51 | |
| 52 | g_slist_free(buddies); | |
| 53 | } | |
| 54 | ||
| 15884 | 55 | static void add_purple_buddies_to_groups(JabberStream *js, const char *jid, |
| 7014 | 56 | const char *alias, GSList *groups) |
| 57 | { | |
| 58 | GSList *buddies, *g2, *l; | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
59 | 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
|
60 | GList *pool = NULL; |
| 7014 | 61 | |
| 15884 | 62 | buddies = purple_find_buddies(js->gc->account, jid); |
| 7014 | 63 | |
| 64 | g2 = groups; | |
| 65 | ||
| 66 | if(!groups) { | |
| 67 | if(!buddies) | |
| 68 | g2 = g_slist_append(g2, g_strdup(_("Buddies"))); | |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
69 | else { |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
70 | g_slist_free(buddies); |
| 7014 | 71 | return; |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
72 | } |
| 7014 | 73 | } |
| 74 | ||
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
75 | 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
|
76 | |
| 7014 | 77 | while(buddies) { |
| 15884 | 78 | PurpleBuddy *b = buddies->data; |
| 79 | PurpleGroup *g = purple_buddy_get_group(b); | |
| 7014 | 80 | |
| 81 | buddies = g_slist_remove(buddies, b); | |
| 82 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
83 | if((l = g_slist_find_custom(g2, purple_group_get_name(g), (GCompareFunc)strcmp))) { |
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
84 | const char *servernick, *balias; |
| 7955 | 85 | |
|
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
|
86 | /* Previously stored serverside / buddy-supplied alias */ |
| 15884 | 87 | if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"))) |
| 7955 | 88 | serv_got_alias(js->gc, jid, servernick); |
| 89 | ||
|
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
|
90 | /* 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
|
91 | 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
|
92 | if(alias && (!balias || strcmp(balias, alias))) |
|
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
|
93 | purple_serv_got_private_alias(js->gc, jid, alias); |
| 7014 | 94 | g_free(l->data); |
| 95 | g2 = g_slist_delete_link(g2, l); | |
| 96 | } 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
|
97 | pool = g_list_prepend(pool, b); |
| 7014 | 98 | } |
| 99 | } | |
| 100 | ||
| 101 | while(g2) { | |
| 15884 | 102 | 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
|
103 | 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
|
104 | |
|
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 | 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
|
106 | 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
|
107 | pool = g_list_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
|
108 | } 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
|
109 | 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
|
110 | } |
| 7014 | 111 | |
| 112 | if(!g) { | |
| 15884 | 113 | g = purple_group_new(g2->data); |
| 114 | purple_blist_add_group(g, NULL); | |
| 7014 | 115 | } |
| 116 | ||
| 15884 | 117 | purple_blist_add_buddy(b, NULL, g, NULL); |
| 118 | purple_blist_alias_buddy(b, alias); | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
119 | |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
120 | /* If we just learned about ourself, then fake our status, |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
121 | * because we won't be receiving a normal presence message |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
122 | * about ourself. */ |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
123 | if(!strcmp(purple_buddy_get_name(b), my_bare_jid)) { |
| 15884 | 124 | PurplePresence *gpresence; |
| 125 | PurpleStatus *status; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
126 | PurpleAccount *account; |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
127 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
128 | account = purple_connection_get_account(js->gc); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
129 | gpresence = purple_account_get_presence(account); |
| 15884 | 130 | status = purple_presence_get_active_status(gpresence); |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
131 | jabber_presence_fake_to_self(js, status); |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
132 | } |
|
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
133 | |
| 7014 | 134 | g_free(g2->data); |
| 135 | g2 = g_slist_delete_link(g2, g2); | |
| 136 | } | |
| 137 | ||
|
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
|
138 | 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
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | } |
|
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
|
143 | |
|
13987
b5b1db6007b0
[gaim-migrate @ 16442]
Mark Doliner <markdoliner@pidgin.im>
parents:
13809
diff
changeset
|
144 | g_free(my_bare_jid); |
| 7014 | 145 | g_slist_free(buddies); |
| 146 | } | |
| 147 | ||
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
24672
diff
changeset
|
148 | 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
|
149 | JabberIqType type, const char *id, xmlnode *query) |
| 7014 | 150 | { |
|
25817
09d6a40a341d
Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents:
24672
diff
changeset
|
151 | xmlnode *item, *group; |
| 7310 | 152 | |
| 153 | if(from) { | |
| 7445 | 154 | char *from_norm; |
| 7310 | 155 | gboolean invalid; |
| 7175 | 156 | |
| 7445 | 157 | from_norm = g_strdup(jabber_normalize(js->gc->account, from)); |
| 158 | ||
| 159 | if(!from_norm) | |
| 7310 | 160 | return; |
| 161 | ||
| 7445 | 162 | invalid = g_utf8_collate(from_norm, |
| 163 | jabber_normalize(js->gc->account, | |
| 15884 | 164 | purple_account_get_username(js->gc->account))); |
| 7175 | 165 | |
| 7310 | 166 | g_free(from_norm); |
| 167 | ||
| 168 | if(invalid) | |
| 169 | return; | |
| 7175 | 170 | } |
| 171 | ||
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
172 | 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
|
173 | |
| 8135 | 174 | for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) |
| 7014 | 175 | { |
| 176 | const char *jid, *name, *subscription, *ask; | |
| 177 | JabberBuddy *jb; | |
| 178 | ||
| 179 | subscription = xmlnode_get_attrib(item, "subscription"); | |
| 180 | jid = xmlnode_get_attrib(item, "jid"); | |
| 181 | name = xmlnode_get_attrib(item, "name"); | |
| 182 | ask = xmlnode_get_attrib(item, "ask"); | |
| 183 | ||
| 8347 | 184 | if(!jid) |
| 185 | continue; | |
| 186 | ||
| 187 | if(!(jb = jabber_buddy_find(js, jid, TRUE))) | |
| 188 | continue; | |
| 7014 | 189 | |
| 10289 | 190 | if(subscription) { |
| 12285 | 191 | gint me = -1; |
| 192 | char *jid_norm; | |
| 193 | const char *username; | |
| 194 | ||
|
15695
0377506eda60
Fix problem with the previous leak fix pointed out by Etan.
Evan Schoenberg <evands@pidgin.im>
parents:
15688
diff
changeset
|
195 | jid_norm = g_strdup(jabber_normalize(js->gc->account, jid)); |
| 15884 | 196 | username = purple_account_get_username(js->gc->account); |
| 12285 | 197 | me = g_utf8_collate(jid_norm, |
| 198 | jabber_normalize(js->gc->account, | |
| 199 | username)); | |
|
15695
0377506eda60
Fix problem with the previous leak fix pointed out by Etan.
Evan Schoenberg <evands@pidgin.im>
parents:
15688
diff
changeset
|
200 | g_free(jid_norm); |
| 12285 | 201 | |
| 202 | if(me == 0) | |
| 203 | jb->subscription = JABBER_SUB_BOTH; | |
| 204 | else if(!strcmp(subscription, "none")) | |
| 205 | jb->subscription = JABBER_SUB_NONE; | |
| 206 | else if(!strcmp(subscription, "to")) | |
| 10289 | 207 | jb->subscription = JABBER_SUB_TO; |
| 208 | else if(!strcmp(subscription, "from")) | |
| 209 | jb->subscription = JABBER_SUB_FROM; | |
| 210 | else if(!strcmp(subscription, "both")) | |
| 211 | jb->subscription = JABBER_SUB_BOTH; | |
| 212 | else if(!strcmp(subscription, "remove")) | |
| 213 | jb->subscription = JABBER_SUB_REMOVE; | |
| 10941 | 214 | /* XXX: if subscription is now "from" or "none" we need to |
| 215 | * fake a signoff, since we won't get any presence from them | |
| 216 | * anymore */ | |
| 12285 | 217 | /* YYY: I was going to use this, but I'm not sure it's necessary |
| 218 | * anymore, but it's here in case it is. */ | |
| 219 | /* | |
| 220 | if ((jb->subscription & JABBER_SUB_FROM) || | |
| 221 | (jb->subscription & JABBER_SUB_NONE)) { | |
| 15884 | 222 | purple_prpl_got_user_status(js->gc->account, jid, "offline", NULL); |
| 12285 | 223 | } |
| 224 | */ | |
| 10289 | 225 | } |
| 7014 | 226 | |
| 227 | if(ask && !strcmp(ask, "subscribe")) | |
| 228 | jb->subscription |= JABBER_SUB_PENDING; | |
| 229 | else | |
| 230 | jb->subscription &= ~JABBER_SUB_PENDING; | |
| 231 | ||
| 8194 | 232 | if(jb->subscription == JABBER_SUB_REMOVE) { |
| 15884 | 233 | remove_purple_buddies(js, jid); |
| 7014 | 234 | } else { |
| 235 | GSList *groups = NULL; | |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
236 | |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
237 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
238 | if (!jabber_google_roster_incoming(js, item)) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
239 | continue; |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
240 | |
| 8135 | 241 | for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) { |
| 7316 | 242 | char *group_name; |
| 243 | ||
| 244 | if(!(group_name = xmlnode_get_data(group))) | |
| 245 | group_name = g_strdup(""); | |
| 13809 | 246 | |
| 15884 | 247 | if (g_slist_find_custom(groups, group_name, (GCompareFunc)purple_utf8_strcasecmp) == NULL) |
| 13809 | 248 | groups = g_slist_append(groups, group_name); |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
249 | else |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
250 | g_free(group_name); |
| 7014 | 251 | } |
| 15884 | 252 | add_purple_buddies_to_groups(js, jid, name, groups); |
| 7014 | 253 | } |
| 254 | } | |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
255 | |
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
256 | 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
|
257 | |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
258 | /* if we're just now parsing the roster for the first time, |
|
25799
f2b56ff62042
Wait until receiving the roster to tell the core we're logged in
Paul Aurich <darkrain42@pidgin.im>
parents:
24717
diff
changeset
|
259 | * then now would be the time to declare ourselves connected and |
|
f2b56ff62042
Wait until receiving the roster to tell the core we're logged in
Paul Aurich <darkrain42@pidgin.im>
parents:
24717
diff
changeset
|
260 | * send our initial presence */ |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
261 | if(!js->roster_parsed) { |
|
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
262 | js->roster_parsed = TRUE; |
|
25800
649ac8f00e04
Send initial presence before declaring us connected (I like this a little better)
Paul Aurich <darkrain42@pidgin.im>
parents:
25799
diff
changeset
|
263 | jabber_presence_send(js, TRUE); |
|
25799
f2b56ff62042
Wait until receiving the roster to tell the core we're logged in
Paul Aurich <darkrain42@pidgin.im>
parents:
24717
diff
changeset
|
264 | jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
|
18196
a7992a42dc3d
fix inital presence (fixes #1395)
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
265 | } |
| 7014 | 266 | } |
| 267 | ||
| 268 | static void jabber_roster_update(JabberStream *js, const char *name, | |
| 269 | GSList *grps) | |
| 270 | { | |
| 15884 | 271 | PurpleBuddy *b; |
| 272 | PurpleGroup *g; | |
| 7014 | 273 | GSList *groups = NULL, *l; |
| 274 | JabberIq *iq; | |
| 275 | 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
|
276 | const char *balias; |
| 7014 | 277 | |
|
23975
8ee397f04ca9
We talked about this and decided it was probably cleaner to not use
Mark Doliner <markdoliner@pidgin.im>
parents:
23961
diff
changeset
|
278 | 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
|
279 | return; |
|
0a9e9676f7b5
Hopefully fix the XMPP contact flipping/swapping between groups bug
Mark Doliner <markdoliner@pidgin.im>
parents:
23566
diff
changeset
|
280 | |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
281 | if(!(b = purple_find_buddy(js->gc->account, name))) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
282 | return; |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
283 | |
| 7014 | 284 | if(grps) { |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
285 | GString *out = g_string_new(NULL); |
| 7014 | 286 | groups = grps; |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
287 | |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
288 | for (l = groups; l; l = l->next) { |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
289 | out = g_string_append(out, (const char *)l->data); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
290 | if (l->next) |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
291 | out = g_string_append(out, ", "); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
292 | } |
|
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
293 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
294 | purple_debug_info("jabber", "jabber_roster_update(%s): [Source: grps]: groups: %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
295 | name, out->str); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
296 | g_string_free(out, TRUE); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
297 | |
| 7014 | 298 | } else { |
| 15884 | 299 | GSList *buddies = purple_find_buddies(js->gc->account, name); |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
300 | GString *out = g_string_new(NULL); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
301 | |
| 7014 | 302 | if(!buddies) |
| 303 | return; | |
| 304 | while(buddies) { | |
| 305 | b = buddies->data; | |
| 15884 | 306 | 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
|
307 | groups = g_slist_append(groups, (char *)purple_group_get_name(g)); |
| 7014 | 308 | buddies = g_slist_remove(buddies, b); |
| 309 | } | |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
310 | for (l = groups; l; l = l->next) { |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
311 | out = g_string_append(out, (const char *)l->data); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
312 | if (l->next) |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
313 | out = g_string_append(out, ", "); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
314 | } |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
315 | |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
316 | purple_debug_info("jabber", "jabber_roster_update(%s): [Source: local blist]: groups: %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
317 | name, out->str); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
318 | g_string_free(out, TRUE); |
| 7014 | 319 | } |
| 320 | ||
| 321 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 322 | ||
| 323 | query = xmlnode_get_child(iq->node, "query"); | |
| 324 | item = xmlnode_new_child(query, "item"); | |
| 325 | ||
| 326 | xmlnode_set_attrib(item, "jid", name); | |
| 327 | ||
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
328 | 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
|
329 | xmlnode_set_attrib(item, "name", balias ? balias : ""); |
| 7014 | 330 | |
| 331 | for(l = groups; l; l = l->next) { | |
| 332 | group = xmlnode_new_child(item, "group"); | |
| 333 | xmlnode_insert_data(group, l->data, -1); | |
| 334 | } | |
| 335 | ||
| 336 | if(!grps) | |
| 337 | 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
|
338 | |
| 15265 | 339 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) { |
| 340 | jabber_google_roster_outgoing(js, query, item); | |
| 341 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 342 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 343 | } | |
| 7014 | 344 | jabber_iq_send(iq); |
| 345 | } | |
| 346 | ||
| 15884 | 347 | void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 348 | PurpleGroup *group) | |
| 7014 | 349 | { |
| 350 | JabberStream *js = gc->proto_data; | |
| 351 | char *who; | |
| 352 | JabberBuddy *jb; | |
| 7488 | 353 | JabberBuddyResource *jbr; |
| 8194 | 354 | char *my_bare_jid; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
355 | const char *name; |
| 7014 | 356 | |
| 357 | if(!js->roster_parsed) | |
| 358 | return; | |
| 359 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
360 | name = purple_buddy_get_name(buddy); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
361 | if(!(who = jabber_get_bare_jid(name))) |
| 7425 | 362 | return; |
| 7014 | 363 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
364 | jb = jabber_buddy_find(js, name, FALSE); |
| 7425 | 365 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
366 | purple_debug_info("jabber", "jabber_roster_add_buddy(): Adding %s\n", |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
367 | name); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
368 | |
|
23566
fabe91dee1e1
Alright, I'm getting rid of this "groups" thing for the reason listed
Mark Doliner <markdoliner@pidgin.im>
parents:
22993
diff
changeset
|
369 | jabber_roster_update(js, who, NULL); |
| 7014 | 370 | |
| 8194 | 371 | my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
| 9954 | 372 | if(!strcmp(who, my_bare_jid)) { |
| 15884 | 373 | PurplePresence *gpresence; |
| 374 | PurpleStatus *status; | |
| 9954 | 375 | |
| 15884 | 376 | gpresence = purple_account_get_presence(js->gc->account); |
| 377 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 378 | jabber_presence_fake_to_self(js, status); |
| 379 | } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { | |
| 7014 | 380 | jabber_presence_subscription_set(js, who, "subscribe"); |
| 9954 | 381 | } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { |
| 15884 | 382 | purple_prpl_got_user_status(gc->account, who, |
| 9954 | 383 | jabber_buddy_state_get_status_id(jbr->state), |
| 9990 | 384 | "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 385 | } |
| 7425 | 386 | |
| 8194 | 387 | g_free(my_bare_jid); |
| 7014 | 388 | g_free(who); |
| 389 | } | |
| 390 | ||
| 15884 | 391 | void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias) |
| 7014 | 392 | { |
| 15884 | 393 | PurpleBuddy *b = purple_find_buddy(gc->account, name); |
| 7449 | 394 | |
| 15321 | 395 | if(b != NULL) { |
| 15884 | 396 | purple_blist_alias_buddy(b, alias); |
| 7449 | 397 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
398 | purple_debug_info("jabber", "jabber_roster_alias_change(): Aliased %s to %s\n", |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
399 | name, alias); |
|
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
400 | |
| 15321 | 401 | jabber_roster_update(gc->proto_data, name, NULL); |
| 402 | } | |
| 7014 | 403 | } |
| 404 | ||
| 15884 | 405 | void jabber_roster_group_change(PurpleConnection *gc, const char *name, |
| 7014 | 406 | const char *old_group, const char *new_group) |
| 407 | { | |
| 408 | GSList *buddies, *groups = NULL; | |
| 15884 | 409 | PurpleBuddy *b; |
| 410 | PurpleGroup *g; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
411 | const char *gname; |
| 7014 | 412 | |
| 413 | if(!old_group || !new_group || !strcmp(old_group, new_group)) | |
| 414 | return; | |
| 415 | ||
| 15884 | 416 | buddies = purple_find_buddies(gc->account, name); |
| 7014 | 417 | while(buddies) { |
| 418 | b = buddies->data; | |
| 15884 | 419 | 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
|
420 | gname = purple_group_get_name(g); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
421 | if(!strcmp(gname, old_group)) |
| 7014 | 422 | groups = g_slist_append(groups, (char*)new_group); /* ick */ |
| 423 | else | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
424 | groups = g_slist_append(groups, (char*)gname); |
| 7014 | 425 | buddies = g_slist_remove(buddies, b); |
| 426 | } | |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
427 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
428 | 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
|
429 | name, old_group, new_group); |
|
27229
3a0922120d87
Pluck Adium's roster debugging from 86720de21a854aa
Paul Aurich <darkrain42@pidgin.im>
parents:
26707
diff
changeset
|
430 | |
| 7014 | 431 | jabber_roster_update(gc->proto_data, name, groups); |
| 432 | g_slist_free(groups); | |
| 433 | } | |
| 434 | ||
| 15884 | 435 | void jabber_roster_group_rename(PurpleConnection *gc, const char *old_name, |
| 436 | PurpleGroup *group, GList *moved_buddies) | |
| 7014 | 437 | { |
| 438 | GList *l; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
439 | const char *gname = purple_group_get_name(group); |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
440 | for(l = moved_buddies; l; l = l->next) { |
| 15884 | 441 | PurpleBuddy *buddy = l->data; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
442 | jabber_roster_group_change(gc, purple_buddy_get_name(buddy), old_name, gname); |
| 7014 | 443 | } |
| 444 | } | |
| 445 | ||
| 15884 | 446 | void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 447 | PurpleGroup *group) { | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
448 | 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
|
449 | GSList *buddies = purple_find_buddies(purple_connection_get_account(gc), name); |
| 7014 | 450 | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
451 | 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
|
452 | if(buddies != NULL) { |
| 15884 | 453 | PurpleBuddy *tmpbuddy; |
| 454 | PurpleGroup *tmpgroup; | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20221
diff
changeset
|
455 | GSList *groups = NULL; |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
456 | |
| 7014 | 457 | while(buddies) { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
458 | tmpbuddy = buddies->data; |
| 15884 | 459 | 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
|
460 | 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
|
461 | buddies = g_slist_remove(buddies, tmpbuddy); |
| 7014 | 462 | } |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
463 | |
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
464 | 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
|
465 | 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
|
466 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
467 | jabber_roster_update(gc->proto_data, name, groups); |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20221
diff
changeset
|
468 | g_slist_free(groups); |
| 7014 | 469 | } else { |
| 7171 | 470 | JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET, |
| 471 | "jabber:iq:roster"); | |
| 472 | xmlnode *query = xmlnode_get_child(iq->node, "query"); | |
| 473 | xmlnode *item = xmlnode_new_child(query, "item"); | |
| 474 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
475 | xmlnode_set_attrib(item, "jid", name); |
| 7171 | 476 | xmlnode_set_attrib(item, "subscription", "remove"); |
| 477 | ||
|
27230
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
478 | 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
|
479 | purple_buddy_get_name(buddy)); |
|
17f893b060d7
Add a few more roster debug messages and improve.
Paul Aurich <darkrain42@pidgin.im>
parents:
27229
diff
changeset
|
480 | |
| 7171 | 481 | jabber_iq_send(iq); |
| 7014 | 482 | } |
| 483 | } |