soc.2009.privacy_rewrite: 871bf6a2: Initial changes to jabber
sulabh at soc.pidgin.im
sulabh at soc.pidgin.im
Wed Jul 22 17:25:29 EDT 2009
-----------------------------------------------------------------
Revision: 871bf6a232b2c0da41670f16571cd49bb23bbad8
Ancestor: 8b3cb040b585640a5ae6b625cf40b636fd66a760
Author: sulabh at soc.pidgin.im
Date: 2009-07-22T20:59:31
Branch: im.pidgin.soc.2009.privacy_rewrite
URL: http://d.pidgin.im/viewmtn/revision/info/871bf6a232b2c0da41670f16571cd49bb23bbad8
Modified files:
libpurple/protocols/jabber/google.c
libpurple/protocols/jabber/google.h
libpurple/protocols/jabber/jabber.c
libpurple/protocols/jabber/roster.c
ChangeLog:
Initial changes to jabber
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google.c 09df1f85644de5f16cd96457278025c8b548493a
+++ libpurple/protocols/jabber/google.c cd85681d82027184a268e62f803a3ee47caabb46
@@ -984,7 +984,7 @@ void jabber_google_roster_outgoing(Jabbe
void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item)
{
PurpleAccount *account = purple_connection_get_account(js->gc);
- GSList *list = account->deny;
+ GSList *list = purple_privacy_list_get_members_by_account(js->gc->account, PURPLE_PRIVACY_BLOCK_BOTH_LIST);
const char *jid = xmlnode_get_attrib(item, "jid");
char *jid_norm = g_strdup(jabber_normalize(account, jid));
@@ -996,22 +996,19 @@ void jabber_google_roster_outgoing(Jabbe
xmlnode_set_attrib(query, "gr:ext", "2");
return;
}
- list = list->next;
+ list = g_slist_delete_link(list, list);
}
g_free(jid_norm);
}
-gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item)
+gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item, gpointer block_l)
{
+ GSList **list = block_l;
PurpleAccount *account = purple_connection_get_account(js->gc);
- GSList *list = account->deny;
const char *jid = xmlnode_get_attrib(item, "jid");
- gboolean on_block_list = FALSE;
-
char *jid_norm;
-
const char *grt = xmlnode_get_attrib_with_namespace(item, "t", "google:roster");
const char *subscription = xmlnode_get_attrib(item, "subscription");
@@ -1024,14 +1021,6 @@ gboolean jabber_google_roster_incoming(J
jid_norm = g_strdup(jabber_normalize(account, jid));
- while (list) {
- if (!strcmp(jid_norm, (char*)list->data)) {
- on_block_list = TRUE;
- break;
- }
- list = list->next;
- }
-
if (grt && (*grt == 'H' || *grt == 'h')) {
PurpleBuddy *buddy = purple_find_buddy(account, jid_norm);
if (buddy)
@@ -1040,12 +1029,9 @@ gboolean jabber_google_roster_incoming(J
return FALSE;
}
- if (!on_block_list && (grt && (*grt == 'B' || *grt == 'b'))) {
+ if (grt && (*grt == 'B' || *grt == 'b')) {
purple_debug_info("jabber", "Blocking %s\n", jid_norm);
- purple_privacy_deny_add(account, jid_norm, TRUE);
- } else if (on_block_list && (!grt || (*grt != 'B' && *grt != 'b' ))){
- purple_debug_info("jabber", "Unblocking %s\n", jid_norm);
- purple_privacy_deny_remove(account, jid_norm, TRUE);
+ *list = g_slist_prepend(*list, g_strdup(jid_norm));
}
g_free(jid_norm);
============================================================
--- libpurple/protocols/jabber/google.h 7c3fbd371479a0b8cd7ab1661dc925d1d84fd8c8
+++ libpurple/protocols/jabber/google.h 971ed8841d8a7d92e33aa079486e8990392b5947
@@ -39,9 +39,10 @@ void jabber_google_roster_outgoing(Jabbe
void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item);
/* Returns FALSE if this should short-circuit processing of this roster item, or TRUE
- * if this roster item should continue to be processed
+ * if this roster item should continue to be processed. The item is added to the block_l
+ * if it has been blocked. block_l is used to sync with the privacy system.
*/
-gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item);
+gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item, gpointer block_l);
void jabber_google_presence_incoming(JabberStream *js, const char *who, JabberBuddyResource *jbr);
char *jabber_google_presence_outgoing(PurpleStatus *tune);
============================================================
--- libpurple/protocols/jabber/jabber.c c5c70221a012e8a06a4e5a4ff5cf88cf0da211fc
+++ libpurple/protocols/jabber/jabber.c 29cca66d9f4892e181f32afbb5cdcd461e0f6d80
@@ -1681,11 +1681,11 @@ void jabber_blocklist_parse_push(JabberS
item = xmlnode_get_child(child, "item");
if (!is_block && item == NULL) {
/* Unblock everyone */
+ GSList *l = NULL, *block_both_l = purple_privacy_list_get_members_by_account(account, PURPLE_PRIVACY_BLOCK_BOTH_LIST);
purple_debug_info("jabber", "Received unblock push. Unblocking everyone.\n");
- while (account->deny != NULL) {
- purple_privacy_deny_remove(account, account->deny->data, TRUE);
- }
+ for(l = block_both_l; l; l=l->next)
+ purple_privacy_deny_remove(account, (char *)l->data, TRUE);
} else if (item == NULL) {
/* An empty <block/> is bogus */
xmlnode *error, *x;
@@ -1723,6 +1723,8 @@ static void jabber_blocklist_parse(Jabbe
{
xmlnode *blocklist, *item;
PurpleAccount *account;
+ GSList *buddy_l = NULL, *block_both_l = NULL, *buddies = NULL;
+ PurpleBuddy *b = NULL;
blocklist = xmlnode_get_child_with_namespace(packet,
"blocklist", "urn:xmpp:blocking");
@@ -1735,19 +1737,27 @@ static void jabber_blocklist_parse(Jabbe
if (account->perm_deny != PURPLE_PRIVACY_DENY_USERS)
account->perm_deny = PURPLE_PRIVACY_DENY_USERS;
- /*
- * TODO: When account->deny is something more than a hash table, this can
- * be re-written to find the set intersection and difference.
- */
- while (account->deny)
- purple_privacy_deny_remove(account, account->deny->data, TRUE);
+ /* Privacy: We receive the block list here, to sync with the privacy subsystem, we need to have the buddy list too */
+ for(buddies = purple_find_buddies(account, NULL); buddies; buddies = g_slist_delete_link(buddies, buddies))
+ {
+ b = buddies->data;
+ buddy_l = g_slist_prepend(buddy_l, b->name);
+ }
item = xmlnode_get_child(blocklist, "item");
while (item != NULL) {
const char *jid = xmlnode_get_attrib(item, "jid");
- purple_privacy_deny_add(account, jid, TRUE);
+ block_both_l = g_slist_prepend(block_both_l, (char *)jid);
+ purple_debug_info("jabber","Adding %s to the block list", jid);
item = xmlnode_get_next_twin(item);
}
+
+ /* Provide the privacy subsystem with the lists on the server*/
+ purple_privacy_sync_lists(account, buddy_l, NULL, NULL, block_both_l, NULL, NULL);
+ purple_debug_info("jabber","Privacy Lists synchronized\n");
+
+ g_slist_free(block_both_l);
+ g_slist_free(buddy_l);
}
void jabber_request_block_list(JabberStream *js)
============================================================
--- libpurple/protocols/jabber/roster.c 8f8c9bf266e6ebccf7ec893511335fb5baa7b692
+++ libpurple/protocols/jabber/roster.c 1917e18d7d57a90326bd0a6df7314288de57ee29
@@ -148,6 +148,7 @@ void jabber_roster_parse(JabberStream *j
void jabber_roster_parse(JabberStream *js, const char *from,
JabberIqType type, const char *id, xmlnode *query)
{
+ GSList *block_l = NULL; /* Used to sync with privacy subsystem in case of Gtalk */
xmlnode *item, *group;
if(from) {
@@ -235,7 +236,7 @@ void jabber_roster_parse(JabberStream *j
GSList *groups = NULL;
if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
- if (!jabber_google_roster_incoming(js, item))
+ if (!jabber_google_roster_incoming(js, item, &block_l))
continue;
for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) {
@@ -255,6 +256,26 @@ void jabber_roster_parse(JabberStream *j
js->currently_parsing_roster_push = FALSE;
+ /* In case of Gtalk, sync with the privacy subsystem now */
+ if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
+ {
+ PurpleBuddy *b = NULL;
+ GSList *buddy_l = NULL, *buddies = NULL;
+ for(buddies = purple_find_buddies(js->gc->account, NULL); buddies; buddies = g_slist_delete_link(buddies, buddies))
+ {
+ /* Privacy laters: check if this list is the local list or the one sync with the server */
+ b = buddies->data;
+ buddy_l = g_slist_prepend(buddy_l, b->name);
+ }
+
+ /* Provide the privacy subsystem with the lists on the server */
+ purple_privacy_sync_lists(js->gc->account, buddy_l, NULL, NULL, block_l, NULL, NULL);
+ purple_debug_info("jabber","Privacy Lists synchronized\n");
+
+ g_slist_free(block_l);
+ g_slist_free(buddy_l);
+ }
+
/* if we're just now parsing the roster for the first time,
* then now would be the time to declare ourselves connected and
* send our initial presence */
More information about the Commits
mailing list