Wed, 13 May 2009 20:29:03 +0000
Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.
| 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) { |
| 285 | groups = grps; | |
| 286 | } else { | |
| 15884 | 287 | GSList *buddies = purple_find_buddies(js->gc->account, name); |
| 7014 | 288 | if(!buddies) |
| 289 | return; | |
| 290 | while(buddies) { | |
| 291 | b = buddies->data; | |
| 15884 | 292 | 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
|
293 | groups = g_slist_append(groups, (char *)purple_group_get_name(g)); |
| 7014 | 294 | buddies = g_slist_remove(buddies, b); |
| 295 | } | |
| 296 | } | |
| 297 | ||
| 298 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 299 | ||
| 300 | query = xmlnode_get_child(iq->node, "query"); | |
| 301 | item = xmlnode_new_child(query, "item"); | |
| 302 | ||
| 303 | xmlnode_set_attrib(item, "jid", name); | |
| 304 | ||
|
24950
143f594f0cd0
Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24398
diff
changeset
|
305 | 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
|
306 | xmlnode_set_attrib(item, "name", balias ? balias : ""); |
| 7014 | 307 | |
| 308 | for(l = groups; l; l = l->next) { | |
| 309 | group = xmlnode_new_child(item, "group"); | |
| 310 | xmlnode_insert_data(group, l->data, -1); | |
| 311 | } | |
| 312 | ||
| 313 | if(!grps) | |
| 314 | 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
|
315 | |
| 15265 | 316 | if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) { |
| 317 | jabber_google_roster_outgoing(js, query, item); | |
| 318 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 319 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 320 | } | |
| 7014 | 321 | jabber_iq_send(iq); |
| 322 | } | |
| 323 | ||
| 15884 | 324 | void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 325 | PurpleGroup *group) | |
| 7014 | 326 | { |
| 327 | JabberStream *js = gc->proto_data; | |
| 328 | char *who; | |
| 329 | JabberBuddy *jb; | |
| 7488 | 330 | JabberBuddyResource *jbr; |
| 8194 | 331 | char *my_bare_jid; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
332 | const char *name; |
| 7014 | 333 | |
| 334 | if(!js->roster_parsed) | |
| 335 | return; | |
| 336 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
337 | name = purple_buddy_get_name(buddy); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
338 | if(!(who = jabber_get_bare_jid(name))) |
| 7425 | 339 | return; |
| 7014 | 340 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
341 | jb = jabber_buddy_find(js, name, FALSE); |
| 7425 | 342 | |
|
23566
fabe91dee1e1
Alright, I'm getting rid of this "groups" thing for the reason listed
Mark Doliner <markdoliner@pidgin.im>
parents:
22993
diff
changeset
|
343 | jabber_roster_update(js, who, NULL); |
| 7014 | 344 | |
| 8194 | 345 | my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
| 9954 | 346 | if(!strcmp(who, my_bare_jid)) { |
| 15884 | 347 | PurplePresence *gpresence; |
| 348 | PurpleStatus *status; | |
| 9954 | 349 | |
| 15884 | 350 | gpresence = purple_account_get_presence(js->gc->account); |
| 351 | status = purple_presence_get_active_status(gpresence); | |
| 9954 | 352 | jabber_presence_fake_to_self(js, status); |
| 353 | } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { | |
| 7014 | 354 | jabber_presence_subscription_set(js, who, "subscribe"); |
| 9954 | 355 | } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { |
| 15884 | 356 | purple_prpl_got_user_status(gc->account, who, |
| 9954 | 357 | jabber_buddy_state_get_status_id(jbr->state), |
| 9990 | 358 | "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); |
| 9954 | 359 | } |
| 7425 | 360 | |
| 8194 | 361 | g_free(my_bare_jid); |
| 7014 | 362 | g_free(who); |
| 363 | } | |
| 364 | ||
| 15884 | 365 | void jabber_roster_alias_change(PurpleConnection *gc, const char *name, const char *alias) |
| 7014 | 366 | { |
| 15884 | 367 | PurpleBuddy *b = purple_find_buddy(gc->account, name); |
| 7449 | 368 | |
| 15321 | 369 | if(b != NULL) { |
| 15884 | 370 | purple_blist_alias_buddy(b, alias); |
| 7449 | 371 | |
| 15321 | 372 | jabber_roster_update(gc->proto_data, name, NULL); |
| 373 | } | |
| 7014 | 374 | } |
| 375 | ||
| 15884 | 376 | void jabber_roster_group_change(PurpleConnection *gc, const char *name, |
| 7014 | 377 | const char *old_group, const char *new_group) |
| 378 | { | |
| 379 | GSList *buddies, *groups = NULL; | |
| 15884 | 380 | PurpleBuddy *b; |
| 381 | PurpleGroup *g; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
382 | const char *gname; |
| 7014 | 383 | |
| 384 | if(!old_group || !new_group || !strcmp(old_group, new_group)) | |
| 385 | return; | |
| 386 | ||
| 15884 | 387 | buddies = purple_find_buddies(gc->account, name); |
| 7014 | 388 | while(buddies) { |
| 389 | b = buddies->data; | |
| 15884 | 390 | 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
|
391 | gname = purple_group_get_name(g); |
|
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
392 | if(!strcmp(gname, old_group)) |
| 7014 | 393 | groups = g_slist_append(groups, (char*)new_group); /* ick */ |
| 394 | else | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
395 | groups = g_slist_append(groups, (char*)gname); |
| 7014 | 396 | buddies = g_slist_remove(buddies, b); |
| 397 | } | |
| 398 | jabber_roster_update(gc->proto_data, name, groups); | |
| 399 | g_slist_free(groups); | |
| 400 | } | |
| 401 | ||
| 15884 | 402 | void jabber_roster_group_rename(PurpleConnection *gc, const char *old_name, |
| 403 | PurpleGroup *group, GList *moved_buddies) | |
| 7014 | 404 | { |
| 405 | GList *l; | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
406 | const char *gname = purple_group_get_name(group); |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
407 | for(l = moved_buddies; l; l = l->next) { |
| 15884 | 408 | PurpleBuddy *buddy = l->data; |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
409 | jabber_roster_group_change(gc, purple_buddy_get_name(buddy), old_name, gname); |
| 7014 | 410 | } |
| 411 | } | |
| 412 | ||
| 15884 | 413 | void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 414 | PurpleGroup *group) { | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
415 | 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
|
416 | GSList *buddies = purple_find_buddies(purple_connection_get_account(gc), name); |
| 7014 | 417 | |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
418 | 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
|
419 | if(buddies != NULL) { |
| 15884 | 420 | PurpleBuddy *tmpbuddy; |
| 421 | PurpleGroup *tmpgroup; | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20221
diff
changeset
|
422 | GSList *groups = NULL; |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
423 | |
| 7014 | 424 | while(buddies) { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
425 | tmpbuddy = buddies->data; |
| 15884 | 426 | 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
|
427 | 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
|
428 | buddies = g_slist_remove(buddies, tmpbuddy); |
| 7014 | 429 | } |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
8347
diff
changeset
|
430 | |
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
431 | jabber_roster_update(gc->proto_data, name, groups); |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20221
diff
changeset
|
432 | g_slist_free(groups); |
| 7014 | 433 | } else { |
| 7171 | 434 | JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET, |
| 435 | "jabber:iq:roster"); | |
| 436 | xmlnode *query = xmlnode_get_child(iq->node, "query"); | |
| 437 | xmlnode *item = xmlnode_new_child(query, "item"); | |
| 438 | ||
|
24398
4865c2ee6ea8
Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24199
diff
changeset
|
439 | xmlnode_set_attrib(item, "jid", name); |
| 7171 | 440 | xmlnode_set_attrib(item, "subscription", "remove"); |
| 441 | ||
| 442 | jabber_iq_send(iq); | |
| 7014 | 443 | } |
| 444 | } |