annotate src/protocols/jabber/roster.c @ 13967:99b9b58b19dd

[gaim-migrate @ 16523] Fix a crazy MSN crash. Basically it's possible to have more than one slplink associated with a given switchboard, but our code did not allow for that. I think it happens when you're in a multi-user chat and you do stuff with multiple users that involves slplinks. Like maybe file transfer and buddy icon related stuff. Tracking this down took an ungodly amount of time, but thanks to Meebo for letting me do it :-) committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 20 Jul 2006 07:31:15 +0000
parents 60f39c405dff
children 6fc412e59214
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 #include "debug.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "server.h"
13807
a415805c7456 [gaim-migrate @ 16232]
Ethan Blanton <elb@pidgin.im>
parents: 12285
diff changeset
24 #include "util.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "buddy.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "presence.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "roster.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "iq.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include <string.h>
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 void jabber_roster_request(JabberStream *js)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 static void remove_gaim_buddies(JabberStream *js, const char *jid)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 GSList *buddies, *l;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 buddies = gaim_find_buddies(js->gc->account, jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 for(l = buddies; l; l = l->next)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 gaim_blist_remove_buddy(l->data);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 g_slist_free(buddies);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 static void add_gaim_buddies_in_groups(JabberStream *js, const char *jid,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 const char *alias, GSList *groups)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 GSList *buddies, *g2, *l;
13925
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
59 gchar *my_bare_jid;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 buddies = gaim_find_buddies(js->gc->account, jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 g2 = groups;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 if(!groups) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 if(!buddies)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 g2 = g_slist_append(g2, g_strdup(_("Buddies")));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71
13925
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
72 my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
73
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 while(buddies) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 GaimBuddy *b = buddies->data;
12088
980c877bd238 [gaim-migrate @ 14385]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
76 GaimGroup *g = gaim_buddy_get_group(b);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 buddies = g_slist_remove(buddies, b);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 if((l = g_slist_find_custom(g2, g->name, (GCompareFunc)strcmp))) {
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
81 const char *servernick;
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
82
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
83 if((servernick = gaim_blist_node_get_string((GaimBlistNode*)b, "servernick")))
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
84 serv_got_alias(js->gc, jid, servernick);
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
85
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 if(alias && (!b->alias || strcmp(b->alias, alias)))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 gaim_blist_alias_buddy(b, alias);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 g_free(l->data);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 g2 = g_slist_delete_link(g2, l);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 gaim_blist_remove_buddy(b);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 while(g2) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 GaimBuddy *b = gaim_buddy_new(js->gc->account, jid, alias);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 GaimGroup *g = gaim_find_group(g2->data);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 if(!g) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 g = gaim_group_new(g2->data);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 gaim_blist_add_group(g, NULL);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 gaim_blist_add_buddy(b, NULL, g, NULL);
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7488
diff changeset
105 gaim_blist_alias_buddy(b, alias);
13925
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
106
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
107
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
108 /* If we just learned about ourself, then fake our status,
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
109 * because we won't be receiving a normal presence message
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
110 * about ourself. */
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
111 if(!strcmp(b->name, my_bare_jid)) {
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
112 GaimPresence *gpresence;
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
113 GaimStatus *status;
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
114
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
115 gpresence = gaim_account_get_presence(js->gc->account);
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
116 status = gaim_presence_get_active_status(gpresence);
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
117 jabber_presence_fake_to_self(js, status);
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
118 }
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
119
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
120
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
121
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 g_free(g2->data);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 g2 = g_slist_delete_link(g2, g2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125
13925
60f39c405dff [gaim-migrate @ 16442]
Mark Doliner <mark@kingant.net>
parents: 13807
diff changeset
126 g_free(my_bare_jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 g_slist_free(buddies);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130 void jabber_roster_parse(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 xmlnode *query, *item, *group;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 const char *from = xmlnode_get_attrib(packet, "from");
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
134
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
135 if(from) {
7445
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
136 char *from_norm;
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
137 gboolean invalid;
7175
3a1b5a9b09c8 [gaim-migrate @ 7743]
Nathan Walp <nwalp@pidgin.im>
parents: 7171
diff changeset
138
7445
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
139 from_norm = g_strdup(jabber_normalize(js->gc->account, from));
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
140
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
141 if(!from_norm)
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
142 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
143
7445
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
144 invalid = g_utf8_collate(from_norm,
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
145 jabber_normalize(js->gc->account,
6ea4a49b4b51 [gaim-migrate @ 8052]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
146 gaim_account_get_username(js->gc->account)));
7175
3a1b5a9b09c8 [gaim-migrate @ 7743]
Nathan Walp <nwalp@pidgin.im>
parents: 7171
diff changeset
147
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
148 g_free(from_norm);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
149
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
150 if(invalid)
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7244
diff changeset
151 return;
7175
3a1b5a9b09c8 [gaim-migrate @ 7743]
Nathan Walp <nwalp@pidgin.im>
parents: 7171
diff changeset
152 }
3a1b5a9b09c8 [gaim-migrate @ 7743]
Nathan Walp <nwalp@pidgin.im>
parents: 7171
diff changeset
153
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 query = xmlnode_get_child(packet, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 if(!query)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 js->roster_parsed = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
160 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item))
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 const char *jid, *name, *subscription, *ask;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 JabberBuddy *jb;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 subscription = xmlnode_get_attrib(item, "subscription");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 jid = xmlnode_get_attrib(item, "jid");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 name = xmlnode_get_attrib(item, "name");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 ask = xmlnode_get_attrib(item, "ask");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169
8347
5d039bc19350 [gaim-migrate @ 9071]
Nathan Walp <nwalp@pidgin.im>
parents: 8194
diff changeset
170 if(!jid)
5d039bc19350 [gaim-migrate @ 9071]
Nathan Walp <nwalp@pidgin.im>
parents: 8194
diff changeset
171 continue;
5d039bc19350 [gaim-migrate @ 9071]
Nathan Walp <nwalp@pidgin.im>
parents: 8194
diff changeset
172
5d039bc19350 [gaim-migrate @ 9071]
Nathan Walp <nwalp@pidgin.im>
parents: 8194
diff changeset
173 if(!(jb = jabber_buddy_find(js, jid, TRUE)))
5d039bc19350 [gaim-migrate @ 9071]
Nathan Walp <nwalp@pidgin.im>
parents: 8194
diff changeset
174 continue;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175
10289
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
176 if(subscription) {
12285
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
177 gint me = -1;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
178 char *jid_norm;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
179 const char *username;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
180
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
181 jid_norm = g_strdup(jabber_normalize(js->gc->account, jid));
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
182 username = gaim_account_get_username(js->gc->account);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
183 me = g_utf8_collate(jid_norm,
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
184 jabber_normalize(js->gc->account,
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
185 username));
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
186
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
187 if(me == 0)
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
188 jb->subscription = JABBER_SUB_BOTH;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
189 else if(!strcmp(subscription, "none"))
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
190 jb->subscription = JABBER_SUB_NONE;
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
191 else if(!strcmp(subscription, "to"))
10289
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
192 jb->subscription = JABBER_SUB_TO;
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
193 else if(!strcmp(subscription, "from"))
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
194 jb->subscription = JABBER_SUB_FROM;
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
195 else if(!strcmp(subscription, "both"))
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
196 jb->subscription = JABBER_SUB_BOTH;
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
197 else if(!strcmp(subscription, "remove"))
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
198 jb->subscription = JABBER_SUB_REMOVE;
10941
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10725
diff changeset
199 /* XXX: if subscription is now "from" or "none" we need to
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10725
diff changeset
200 * fake a signoff, since we won't get any presence from them
cef48e318125 [gaim-migrate @ 12731]
Nathan Walp <nwalp@pidgin.im>
parents: 10725
diff changeset
201 * anymore */
12285
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
202 /* YYY: I was going to use this, but I'm not sure it's necessary
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
203 * anymore, but it's here in case it is. */
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
204 /*
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
205 if ((jb->subscription & JABBER_SUB_FROM) ||
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
206 (jb->subscription & JABBER_SUB_NONE)) {
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
207 gaim_prpl_got_user_status(js->gc->account, jid, "offline", NULL);
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
208 }
af257d8679fe [gaim-migrate @ 14589]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12088
diff changeset
209 */
10289
5683613ea692 [gaim-migrate @ 11464]
Nathan Walp <nwalp@pidgin.im>
parents: 9990
diff changeset
210 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 if(ask && !strcmp(ask, "subscribe"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 jb->subscription |= JABBER_SUB_PENDING;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 jb->subscription &= ~JABBER_SUB_PENDING;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216
8194
22b3974dc1af [gaim-migrate @ 8916]
Nathan Walp <nwalp@pidgin.im>
parents: 8185
diff changeset
217 if(jb->subscription == JABBER_SUB_REMOVE) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 remove_gaim_buddies(js, jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 GSList *groups = NULL;
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8120
diff changeset
221 for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) {
7316
5b408a3fc6f4 [gaim-migrate @ 7900]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
222 char *group_name;
5b408a3fc6f4 [gaim-migrate @ 7900]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
223
5b408a3fc6f4 [gaim-migrate @ 7900]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
224 if(!(group_name = xmlnode_get_data(group)))
5b408a3fc6f4 [gaim-migrate @ 7900]
Nathan Walp <nwalp@pidgin.im>
parents: 7310
diff changeset
225 group_name = g_strdup("");
13807
a415805c7456 [gaim-migrate @ 16232]
Ethan Blanton <elb@pidgin.im>
parents: 12285
diff changeset
226
a415805c7456 [gaim-migrate @ 16232]
Ethan Blanton <elb@pidgin.im>
parents: 12285
diff changeset
227 if (g_slist_find_custom(groups, group_name, (GCompareFunc)gaim_utf8_strcasecmp) == NULL)
a415805c7456 [gaim-migrate @ 16232]
Ethan Blanton <elb@pidgin.im>
parents: 12285
diff changeset
228 groups = g_slist_append(groups, group_name);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 add_gaim_buddies_in_groups(js, jid, name, groups);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235 static void jabber_roster_update(JabberStream *js, const char *name,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 GSList *grps)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 GaimBuddy *b;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 GaimGroup *g;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 GSList *groups = NULL, *l;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 xmlnode *query, *item, *group;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 if(grps) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 groups = grps;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 GSList *buddies = gaim_find_buddies(js->gc->account, name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 if(!buddies)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 while(buddies) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 b = buddies->data;
12088
980c877bd238 [gaim-migrate @ 14385]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
252 g = gaim_buddy_get_group(b);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 groups = g_slist_append(groups, g->name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 buddies = g_slist_remove(buddies, b);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257
8120
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
258 if(!(b = gaim_find_buddy(js->gc->account, name)))
81a63a9bff88 [gaim-migrate @ 8824]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
259 return;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 query = xmlnode_get_child(iq->node, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 item = xmlnode_new_child(query, "item");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 xmlnode_set_attrib(item, "jid", name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 if(b->alias)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 xmlnode_set_attrib(item, "name", b->alias);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 for(l = groups; l; l = l->next) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 group = xmlnode_new_child(item, "group");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 xmlnode_insert_data(group, l->data, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 if(!grps)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 g_slist_free(groups);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
282 void jabber_roster_add_buddy(GaimConnection *gc, GaimBuddy *buddy,
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
283 GaimGroup *group)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 JabberStream *js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 char *who;
7425
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
287 GSList *groups = NULL;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 JabberBuddy *jb;
7488
c42d1532faab [gaim-migrate @ 8101]
Nathan Walp <nwalp@pidgin.im>
parents: 7482
diff changeset
289 JabberBuddyResource *jbr;
8194
22b3974dc1af [gaim-migrate @ 8916]
Nathan Walp <nwalp@pidgin.im>
parents: 8185
diff changeset
290 char *my_bare_jid;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 if(!js->roster_parsed)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
295 if(!(who = jabber_get_bare_jid(buddy->name)))
7425
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
296 return;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
298 jb = jabber_buddy_find(js, buddy->name, FALSE);
7425
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
299
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
300 if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
301 groups = g_slist_append(groups, group->name);
7425
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
302 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303
7449
126fceb88bec [gaim-migrate @ 8060]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
304 jabber_roster_update(js, who, groups);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305
8194
22b3974dc1af [gaim-migrate @ 8916]
Nathan Walp <nwalp@pidgin.im>
parents: 8185
diff changeset
306 my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
307 if(!strcmp(who, my_bare_jid)) {
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
308 GaimPresence *gpresence;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
309 GaimStatus *status;
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
310
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
311 gpresence = gaim_account_get_presence(js->gc->account);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
312 status = gaim_presence_get_active_status(gpresence);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
313 jabber_presence_fake_to_self(js, status);
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
314 } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 jabber_presence_subscription_set(js, who, "subscribe");
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
316 } else if((jbr =jabber_buddy_find_resource(jb, NULL))) {
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
317 gaim_prpl_got_user_status(gc->account, who,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
318 jabber_buddy_state_get_status_id(jbr->state),
9990
bd5517471d99 [gaim-migrate @ 10903]
Nathan Walp <nwalp@pidgin.im>
parents: 9954
diff changeset
319 "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9927
diff changeset
320 }
7425
85cd2e71bff7 [gaim-migrate @ 8028]
Nathan Walp <nwalp@pidgin.im>
parents: 7316
diff changeset
321
8194
22b3974dc1af [gaim-migrate @ 8916]
Nathan Walp <nwalp@pidgin.im>
parents: 8185
diff changeset
322 g_free(my_bare_jid);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323 g_free(who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 void jabber_roster_alias_change(GaimConnection *gc, const char *name, const char *alias)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 {
7449
126fceb88bec [gaim-migrate @ 8060]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
328 GaimBuddy *b = gaim_find_buddy(gc->account, name);
7482
9b69fdd148fc [gaim-migrate @ 8095]
Nathan Walp <nwalp@pidgin.im>
parents: 7449
diff changeset
329 char *a;
7449
126fceb88bec [gaim-migrate @ 8060]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
330
7482
9b69fdd148fc [gaim-migrate @ 8095]
Nathan Walp <nwalp@pidgin.im>
parents: 7449
diff changeset
331 a = g_strdup(alias);
9b69fdd148fc [gaim-migrate @ 8095]
Nathan Walp <nwalp@pidgin.im>
parents: 7449
diff changeset
332 gaim_blist_alias_buddy(b, a);
9b69fdd148fc [gaim-migrate @ 8095]
Nathan Walp <nwalp@pidgin.im>
parents: 7449
diff changeset
333 g_free(a);
7449
126fceb88bec [gaim-migrate @ 8060]
Nathan Walp <nwalp@pidgin.im>
parents: 7445
diff changeset
334
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 jabber_roster_update(gc->proto_data, name, NULL);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 void jabber_roster_group_change(GaimConnection *gc, const char *name,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 const char *old_group, const char *new_group)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 GSList *buddies, *groups = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 GaimBuddy *b;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 GaimGroup *g;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 if(!old_group || !new_group || !strcmp(old_group, new_group))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 buddies = gaim_find_buddies(gc->account, name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 while(buddies) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 b = buddies->data;
12088
980c877bd238 [gaim-migrate @ 14385]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
351 g = gaim_buddy_get_group(b);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 if(!strcmp(g->name, old_group))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 groups = g_slist_append(groups, (char*)new_group); /* ick */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355 groups = g_slist_append(groups, g->name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 buddies = g_slist_remove(buddies, b);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 jabber_roster_update(gc->proto_data, name, groups);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 g_slist_free(groups);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
362 void jabber_roster_group_rename(GaimConnection *gc, const char *old_name,
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
363 GaimGroup *group, GList *moved_buddies)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
365 GList *l;
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
366 for(l = moved_buddies; l; l = l->next) {
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
367 GaimBuddy *buddy = l->data;
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
368 jabber_roster_group_change(gc, buddy->name, old_name, group->name);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
370 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
371
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
372 void jabber_roster_remove_buddy(GaimConnection *gc, GaimBuddy *buddy,
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
373 GaimGroup *group) {
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
374 GSList *buddies = gaim_find_buddies(gc->account, buddy->name);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
375 GSList *groups = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
376
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
377 buddies = g_slist_remove(buddies, buddy);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
378 if(g_slist_length(buddies)) {
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
379 GaimBuddy *tmpbuddy;
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
380 GaimGroup *tmpgroup;
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
381
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382 while(buddies) {
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
383 tmpbuddy = buddies->data;
12088
980c877bd238 [gaim-migrate @ 14385]
Mark Doliner <mark@kingant.net>
parents: 10941
diff changeset
384 tmpgroup = gaim_buddy_get_group(tmpbuddy);
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
385 groups = g_slist_append(groups, tmpgroup->name);
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
386 buddies = g_slist_remove(buddies, tmpbuddy);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
387 }
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
388
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
389 jabber_roster_update(gc->proto_data, buddy->name, groups);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
390 } else {
7171
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
391 JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET,
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
392 "jabber:iq:roster");
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
393 xmlnode *query = xmlnode_get_child(iq->node, "query");
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
394 xmlnode *item = xmlnode_new_child(query, "item");
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
395
9285
7a8aa87164ae [gaim-migrate @ 10088]
Mark Doliner <mark@kingant.net>
parents: 8347
diff changeset
396 xmlnode_set_attrib(item, "jid", buddy->name);
7171
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
397 xmlnode_set_attrib(item, "subscription", "remove");
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
398
511b4edb467c [gaim-migrate @ 7738]
Nathan Walp <nwalp@pidgin.im>
parents: 7014
diff changeset
399 jabber_iq_send(iq);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
400 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
401
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
402 if(buddies)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
403 g_slist_free(buddies);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
404 if(groups)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
405 g_slist_free(groups);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406 }