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
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
22 #include "google_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
);
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");
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
;
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.
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
);
75 purple_debug_info("jabber", "Removing %s from local buddy list\n",
79 purple_blist_remove_buddy(buddies
->data
);
80 buddies
= g_slist_delete_link(buddies
, buddies
);
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
);
100 void jabber_google_roster_add_deny(JabberStream
*js
, const char *who
)
102 PurpleAccount
*account
;
105 PurpleXmlNode
*query
;
107 PurpleXmlNode
*group
;
112 jb
= jabber_buddy_find(js
, who
, TRUE
);
114 account
= purple_connection_get_account(js
->gc
);
115 buddies
= purple_blist_find_buddies(account
, who
);
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");
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
);
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");
146 /* Synthesize a sign-off */
148 JabberBuddyResource
*jbr
;
149 GList
*l
= jb
->resources
;
152 if (jbr
&& jbr
->name
)
154 purple_debug_misc("jabber", "Removing resource %s\n", jbr
->name
);
155 jabber_buddy_remove_resource(jb
, jbr
->name
);
161 purple_protocol_got_user_status(account
, who
, "offline", NULL
);
164 void jabber_google_roster_rem_deny(JabberStream
*js
, const char *who
)
168 PurpleXmlNode
*query
;
170 PurpleXmlNode
*group
;
174 buddies
= purple_blist_find_buddies(purple_connection_get_account(js
->gc
), who
);
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");
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
);
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");
204 /* See if he's online */
205 jabber_presence_subscription_set(js
, who
, "probe");