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
);
36 if (g_slist_find_custom(list
, jid_norm
, (GCompareFunc
)g_strcmp0
)) {
37 purple_xmlnode_set_attrib(query
, "xmlns:gr", NS_GOOGLE_ROSTER
);
38 purple_xmlnode_set_attrib(query
, "gr:ext", "2");
39 purple_xmlnode_set_attrib(item
, "gr:t", "B");
44 gboolean
jabber_google_roster_incoming(JabberStream
*js
, PurpleXmlNode
*item
)
46 PurpleAccount
*account
= purple_connection_get_account(js
->gc
);
47 const char *jid
= purple_xmlnode_get_attrib(item
, "jid");
48 gboolean on_block_list
= FALSE
;
52 const char *grt
= purple_xmlnode_get_attrib_with_namespace(item
, "t", NS_GOOGLE_ROSTER
);
53 const char *subscription
= purple_xmlnode_get_attrib(item
, "subscription");
54 const char *ask
= purple_xmlnode_get_attrib(item
, "ask");
56 if ((!subscription
|| purple_strequal(subscription
, "none")) && !ask
) {
57 /* The Google Talk servers will automatically add people from your Gmail address book
58 * with subscription=none. If we see someone with subscription=none, ignore them.
63 jid_norm
= g_strdup(jabber_normalize(account
, jid
));
65 on_block_list
= NULL
!= g_slist_find_custom(purple_account_privacy_get_denied(account
),
66 jid_norm
, (GCompareFunc
)strcmp
);
68 if (grt
&& (*grt
== 'H' || *grt
== 'h')) {
69 /* Hidden; don't show this buddy. */
70 GSList
*buddies
= purple_blist_find_buddies(account
, jid_norm
);
72 purple_debug_info("jabber", "Removing %s from local buddy list\n",
75 g_slist_free_full(buddies
, (GDestroyNotify
)purple_blist_remove_buddy
);
82 if (!on_block_list
&& (grt
&& (*grt
== 'B' || *grt
== 'b'))) {
83 purple_debug_info("jabber", "Blocking %s\n", jid_norm
);
84 purple_account_privacy_deny_add(account
, jid_norm
, TRUE
);
85 } else if (on_block_list
&& (!grt
|| (*grt
!= 'B' && *grt
!= 'b' ))){
86 purple_debug_info("jabber", "Unblocking %s\n", jid_norm
);
87 purple_account_privacy_deny_remove(account
, jid_norm
, TRUE
);
94 void jabber_google_roster_add_deny(JabberStream
*js
, const char *who
)
96 PurpleAccount
*account
;
101 PurpleXmlNode
*group
;
106 jb
= jabber_buddy_find(js
, who
, TRUE
);
108 account
= purple_connection_get_account(js
->gc
);
109 buddies
= purple_blist_find_buddies(account
, who
);
113 iq
= jabber_iq_new_query(js
, JABBER_IQ_SET
, "jabber:iq:roster");
115 query
= purple_xmlnode_get_child(iq
->node
, "query");
116 item
= purple_xmlnode_new_child(query
, "item");
122 g
= purple_buddy_get_group(b
);
124 group
= purple_xmlnode_new_child(item
, "group");
125 purple_xmlnode_insert_data(group
,
126 jabber_roster_group_get_global_name(g
), -1);
128 buddies
= g_slist_delete_link(buddies
, buddies
);
131 balias
= purple_buddy_get_local_alias(b
);
132 purple_xmlnode_set_attrib(item
, "jid", who
);
133 purple_xmlnode_set_attrib(item
, "name", balias
? balias
: "");
134 purple_xmlnode_set_attrib(item
, "gr:t", "B");
135 purple_xmlnode_set_attrib(query
, "xmlns:gr", NS_GOOGLE_ROSTER
);
136 purple_xmlnode_set_attrib(query
, "gr:ext", "2");
140 /* Synthesize a sign-off */
142 JabberBuddyResource
*jbr
;
143 GList
*l
= jb
->resources
;
146 if (jbr
&& jbr
->name
)
148 purple_debug_misc("jabber", "Removing resource %s\n", jbr
->name
);
149 jabber_buddy_remove_resource(jb
, jbr
->name
);
155 purple_protocol_got_user_status(account
, who
, "offline", NULL
);
158 void jabber_google_roster_rem_deny(JabberStream
*js
, const char *who
)
162 PurpleXmlNode
*query
;
164 PurpleXmlNode
*group
;
168 buddies
= purple_blist_find_buddies(purple_connection_get_account(js
->gc
), who
);
172 iq
= jabber_iq_new_query(js
, JABBER_IQ_SET
, "jabber:iq:roster");
174 query
= purple_xmlnode_get_child(iq
->node
, "query");
175 item
= purple_xmlnode_new_child(query
, "item");
181 g
= purple_buddy_get_group(b
);
183 group
= purple_xmlnode_new_child(item
, "group");
184 purple_xmlnode_insert_data(group
,
185 jabber_roster_group_get_global_name(g
), -1);
187 buddies
= g_slist_delete_link(buddies
, buddies
);
190 balias
= purple_buddy_get_local_alias(b
);
191 purple_xmlnode_set_attrib(item
, "jid", who
);
192 purple_xmlnode_set_attrib(item
, "name", balias
? balias
: "");
193 purple_xmlnode_set_attrib(query
, "xmlns:gr", NS_GOOGLE_ROSTER
);
194 purple_xmlnode_set_attrib(query
, "gr:ext", "2");
198 /* See if he's online */
199 jabber_presence_subscription_set(js
, who
, "probe");