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