Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / libpurple / protocols / jabber / google / google_roster.c
blob92935cbb633b55ae088b5edfe5ed7bdd376c52b9
1 /**
2 * Purple is the legal property of its developers, whose names are too numerous
3 * to list here. Please refer to the COPYRIGHT file distributed with this
4 * source distribution.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 #include "internal.h"
22 #include "google_roster.h"
23 #include "jabber.h"
24 #include "presence.h"
25 #include "debug.h"
26 #include "xmlnode.h"
27 #include "roster.h"
29 void jabber_google_roster_outgoing(JabberStream *js, PurpleXmlNode *query, PurpleXmlNode *item)
31 PurpleAccount *account = purple_connection_get_account(js->gc);
32 GSList *list = purple_account_privacy_get_denied(account);
33 const char *jid = purple_xmlnode_get_attrib(item, "jid");
34 char *jid_norm = (char *)jabber_normalize(account, jid);
36 while (list) {
37 if (!strcmp(jid_norm, (char*)list->data)) {
38 purple_xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
39 purple_xmlnode_set_attrib(query, "gr:ext", "2");
40 purple_xmlnode_set_attrib(item, "gr:t", "B");
41 return;
43 list = list->next;
47 gboolean jabber_google_roster_incoming(JabberStream *js, PurpleXmlNode *item)
49 PurpleAccount *account = purple_connection_get_account(js->gc);
50 const char *jid = purple_xmlnode_get_attrib(item, "jid");
51 gboolean on_block_list = FALSE;
53 char *jid_norm;
55 const char *grt = purple_xmlnode_get_attrib_with_namespace(item, "t", NS_GOOGLE_ROSTER);
56 const char *subscription = purple_xmlnode_get_attrib(item, "subscription");
57 const char *ask = purple_xmlnode_get_attrib(item, "ask");
59 if ((!subscription || !strcmp(subscription, "none")) && !ask) {
60 /* The Google Talk servers will automatically add people from your Gmail address book
61 * with subscription=none. If we see someone with subscription=none, ignore them.
63 return FALSE;
66 jid_norm = g_strdup(jabber_normalize(account, jid));
68 on_block_list = NULL != g_slist_find_custom(purple_account_privacy_get_denied(account),
69 jid_norm, (GCompareFunc)strcmp);
71 if (grt && (*grt == 'H' || *grt == 'h')) {
72 /* Hidden; don't show this buddy. */
73 GSList *buddies = purple_blist_find_buddies(account, jid_norm);
74 if (buddies) {
75 purple_debug_info("jabber", "Removing %s from local buddy list\n",
76 jid_norm);
78 do {
79 purple_blist_remove_buddy(buddies->data);
80 buddies = g_slist_delete_link(buddies, buddies);
81 } while (buddies);
84 g_free(jid_norm);
85 return FALSE;
88 if (!on_block_list && (grt && (*grt == 'B' || *grt == 'b'))) {
89 purple_debug_info("jabber", "Blocking %s\n", jid_norm);
90 purple_account_privacy_deny_add(account, jid_norm, TRUE);
91 } else if (on_block_list && (!grt || (*grt != 'B' && *grt != 'b' ))){
92 purple_debug_info("jabber", "Unblocking %s\n", jid_norm);
93 purple_account_privacy_deny_remove(account, jid_norm, TRUE);
96 g_free(jid_norm);
97 return TRUE;
100 void jabber_google_roster_add_deny(JabberStream *js, const char *who)
102 PurpleAccount *account;
103 GSList *buddies;
104 JabberIq *iq;
105 PurpleXmlNode *query;
106 PurpleXmlNode *item;
107 PurpleXmlNode *group;
108 PurpleBuddy *b;
109 JabberBuddy *jb;
110 const char *balias;
112 jb = jabber_buddy_find(js, who, TRUE);
114 account = purple_connection_get_account(js->gc);
115 buddies = purple_blist_find_buddies(account, who);
116 if(!buddies)
117 return;
119 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
121 query = purple_xmlnode_get_child(iq->node, "query");
122 item = purple_xmlnode_new_child(query, "item");
124 do {
125 PurpleGroup *g;
127 b = buddies->data;
128 g = purple_buddy_get_group(b);
130 group = purple_xmlnode_new_child(item, "group");
131 purple_xmlnode_insert_data(group,
132 jabber_roster_group_get_global_name(g), -1);
134 buddies = g_slist_delete_link(buddies, buddies);
135 } while (buddies);
137 balias = purple_buddy_get_local_alias(b);
138 purple_xmlnode_set_attrib(item, "jid", who);
139 purple_xmlnode_set_attrib(item, "name", balias ? balias : "");
140 purple_xmlnode_set_attrib(item, "gr:t", "B");
141 purple_xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
142 purple_xmlnode_set_attrib(query, "gr:ext", "2");
144 jabber_iq_send(iq);
146 /* Synthesize a sign-off */
147 if (jb) {
148 JabberBuddyResource *jbr;
149 GList *l = jb->resources;
150 while (l) {
151 jbr = l->data;
152 if (jbr && jbr->name)
154 purple_debug_misc("jabber", "Removing resource %s\n", jbr->name);
155 jabber_buddy_remove_resource(jb, jbr->name);
157 l = l->next;
161 purple_protocol_got_user_status(account, who, "offline", NULL);
164 void jabber_google_roster_rem_deny(JabberStream *js, const char *who)
166 GSList *buddies;
167 JabberIq *iq;
168 PurpleXmlNode *query;
169 PurpleXmlNode *item;
170 PurpleXmlNode *group;
171 PurpleBuddy *b;
172 const char *balias;
174 buddies = purple_blist_find_buddies(purple_connection_get_account(js->gc), who);
175 if(!buddies)
176 return;
178 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
180 query = purple_xmlnode_get_child(iq->node, "query");
181 item = purple_xmlnode_new_child(query, "item");
183 do {
184 PurpleGroup *g;
186 b = buddies->data;
187 g = purple_buddy_get_group(b);
189 group = purple_xmlnode_new_child(item, "group");
190 purple_xmlnode_insert_data(group,
191 jabber_roster_group_get_global_name(g), -1);
193 buddies = g_slist_delete_link(buddies, buddies);
194 } while (buddies);
196 balias = purple_buddy_get_local_alias(b);
197 purple_xmlnode_set_attrib(item, "jid", who);
198 purple_xmlnode_set_attrib(item, "name", balias ? balias : "");
199 purple_xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
200 purple_xmlnode_set_attrib(query, "gr:ext", "2");
202 jabber_iq_send(iq);
204 /* See if he's online */
205 jabber_presence_subscription_set(js, who, "probe");