/soc/2012/tomkiewicz/gg: 63bf52ec9e1e: Gadu-Gadu: roster - tidyi...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Jul 14 20:02:46 EDT 2012


Changeset: 63bf52ec9e1ec15818cc79793fbd6a564c0d25fe
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-07-15 02:02 +0200
Branch:	 soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/63bf52ec9e1e

Description:

Gadu-Gadu: roster - tidying. Fixes #9463

diffstat:

 libpurple/protocols/gg/purplew.c |   28 ++
 libpurple/protocols/gg/purplew.h |    3 +
 libpurple/protocols/gg/roster.c  |  491 +++++++++++++++++++-------------------
 libpurple/protocols/gg/roster.h  |    8 +-
 4 files changed, 280 insertions(+), 250 deletions(-)

diffs (truncated from 722 to 300 lines):

diff --git a/libpurple/protocols/gg/purplew.c b/libpurple/protocols/gg/purplew.c
--- a/libpurple/protocols/gg/purplew.c
+++ b/libpurple/protocols/gg/purplew.c
@@ -90,3 +90,31 @@
 	
 	return buddies;
 }
+
+GList * ggp_purplew_account_get_groups(PurpleAccount *account, gboolean exclusive)
+{
+	PurpleBlistNode *bnode;
+	GList *groups = NULL;
+	for (bnode = purple_blist_get_root(); bnode; bnode = bnode->next)
+	{
+		PurpleGroup *group;
+		GSList *accounts;
+		gboolean have_specified = FALSE, have_others = FALSE;
+		
+		if (!PURPLE_BLIST_NODE_IS_GROUP(bnode))
+			continue;
+		
+		group = PURPLE_GROUP(bnode);
+		for (accounts = purple_group_get_accounts(group); accounts; accounts = g_slist_delete_link(accounts, accounts))
+		{
+			if (accounts->data == account)
+				have_specified = TRUE;
+			else
+				have_others = TRUE;
+		}
+		
+		if (have_specified && (!exclusive || !have_others))
+			groups = g_list_append(groups, group);
+	}
+	return groups;
+}
diff --git a/libpurple/protocols/gg/purplew.h b/libpurple/protocols/gg/purplew.h
--- a/libpurple/protocols/gg/purplew.h
+++ b/libpurple/protocols/gg/purplew.h
@@ -43,4 +43,7 @@
 
 GList * ggp_purplew_group_get_buddies(PurpleGroup *group, PurpleAccount *account);
 
+// you must g_free returned list
+GList * ggp_purplew_account_get_groups(PurpleAccount *account, gboolean exclusive);
+
 #endif /* _GGP_PURPLEW_H */
diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -15,6 +15,8 @@
 
 typedef struct
 {
+	int version;
+	
 	xmlnode *xml;
 	
 	xmlnode *groups_node, *contacts_node;
@@ -67,38 +69,33 @@
 	} data;
 } ggp_roster_change;
 
+static inline ggp_roster_session_data * ggp_roster_get_rdata(PurpleConnection *gc);
 static void ggp_roster_content_free(ggp_roster_content *content);
 static void ggp_roster_change_free(gpointer change);
-
-static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy);
-static void ggp_roster_set_synchronized(PurpleConnection *gc, PurpleBuddy *buddy, gboolean synchronized);
-static const gchar * ggp_roster_add_group(ggp_roster_content *content, PurpleGroup *group);
-
 static gboolean ggp_roster_timer_cb(gpointer _gc);
-
-static void ggp_roster_reply_ack(PurpleConnection *gc, uint32_t version);
-static void ggp_roster_reply_reject(PurpleConnection *gc, uint32_t version);
-static void ggp_roster_reply_list(PurpleConnection *gc, uint32_t version, const char *reply);
-static void ggp_roster_send_update(PurpleConnection *gc);
-
 #if GGP_ROSTER_DEBUG
 static void ggp_roster_dump(ggp_roster_content *content);
 #endif
 
-/********/
+// synchronization control
+static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy);
+static void ggp_roster_set_synchronized(PurpleConnection *gc, PurpleBuddy *buddy, gboolean synchronized);
 
-gboolean ggp_roster_enabled(void)
-{
-	static gboolean checked = FALSE;
-	static gboolean enabled;
-	
-	if (!checked)
-	{
-		enabled = gg_libgadu_check_feature(GG_LIBGADU_FEATURE_USERLIST100);
-		checked = TRUE;
-	}
-	return enabled;
-}
+// buddy list import
+static gboolean ggp_roster_reply_list_read_group(xmlnode *node, ggp_roster_content *content);
+static gboolean ggp_roster_reply_list_read_buddy(PurpleConnection *gc, xmlnode *node, ggp_roster_content *content, GHashTable *remove_buddies);
+static void ggp_roster_reply_list(PurpleConnection *gc, uint32_t version, const char *reply);
+
+// buddy list export
+static const gchar * ggp_roster_send_update_group_add(ggp_roster_content *content, PurpleGroup *group);
+static gboolean ggp_roster_send_update_contact_update(PurpleConnection *gc, ggp_roster_change *change);
+static gboolean ggp_roster_send_update_contact_remove(PurpleConnection *gc, ggp_roster_change *change);
+static gboolean ggp_roster_send_update_group_rename(PurpleConnection *gc, ggp_roster_change *change);
+static void ggp_roster_send_update(PurpleConnection *gc);
+static void ggp_roster_reply_ack(PurpleConnection *gc, uint32_t version);
+static void ggp_roster_reply_reject(PurpleConnection *gc, uint32_t version);
+
+/******************************************************************************/
 
 static inline ggp_roster_session_data *
 ggp_roster_get_rdata(PurpleConnection *gc)
@@ -107,32 +104,6 @@
 	return &accdata->roster_data;
 } 
 
-void ggp_roster_setup(PurpleConnection *gc)
-{
-	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
-
-	rdata->version = 0;
-	rdata->content = NULL;
-	rdata->sent_updates = NULL;
-	rdata->pending_updates = NULL;
-	rdata->timer = 0;
-	rdata->is_updating = FALSE;
-	
-	if (ggp_roster_enabled())
-		rdata->timer = purple_timeout_add_seconds(2, ggp_roster_timer_cb, gc);
-}
-
-void ggp_roster_cleanup(PurpleConnection *gc)
-{
-	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
-
-	if (rdata->timer)
-		purple_timeout_remove(rdata->timer);
-	ggp_roster_content_free(rdata->content);
-	g_list_free_full(rdata->sent_updates, ggp_roster_change_free);
-	g_list_free_full(rdata->pending_updates, ggp_roster_change_free);
-}
-
 static void ggp_roster_content_free(ggp_roster_content *content)
 {
 	if (content == NULL)
@@ -165,6 +136,84 @@
 	g_free(change);
 }
 
+static gboolean ggp_roster_timer_cb(gpointer _gc)
+{
+	PurpleConnection *gc = _gc;
+	
+	g_return_val_if_fail(PURPLE_CONNECTION_IS_VALID(gc), FALSE);
+	
+	ggp_roster_send_update(gc);
+	
+	return TRUE;
+}
+
+#if GGP_ROSTER_DEBUG
+static void ggp_roster_dump(ggp_roster_content *content)
+{
+	char *str;
+	int len;
+	
+	g_return_if_fail(content != NULL);
+	g_return_if_fail(content->xml != NULL);
+	
+	str = xmlnode_to_formatted_str(content->xml, &len);
+	purple_debug_misc("gg", "ggp_roster_reply_list: [%s]\n", str);
+	g_free(str);
+}
+#endif
+
+/*******************************************************************************
+ * Setup.
+ ******************************************************************************/
+
+gboolean ggp_roster_enabled(void)
+{
+	static gboolean checked = FALSE;
+	static gboolean enabled;
+	
+	if (!checked)
+	{
+		enabled = gg_libgadu_check_feature(GG_LIBGADU_FEATURE_USERLIST100);
+		checked = TRUE;
+	}
+	return enabled;
+}
+
+void ggp_roster_setup(PurpleConnection *gc)
+{
+	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
+
+	rdata->content = NULL;
+	rdata->sent_updates = NULL;
+	rdata->pending_updates = NULL;
+	rdata->timer = 0;
+	rdata->is_updating = FALSE;
+	
+	if (ggp_roster_enabled())
+		rdata->timer = purple_timeout_add_seconds(2, ggp_roster_timer_cb, gc);
+}
+
+void ggp_roster_cleanup(PurpleConnection *gc)
+{
+	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
+
+	if (rdata->timer)
+		purple_timeout_remove(rdata->timer);
+	ggp_roster_content_free(rdata->content);
+	g_list_free_full(rdata->sent_updates, ggp_roster_change_free);
+	g_list_free_full(rdata->pending_updates, ggp_roster_change_free);
+}
+
+/*******************************************************************************
+ * Synchronization control.
+ ******************************************************************************/
+
+static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy)
+{
+	gboolean ret = purple_blist_node_get_bool(PURPLE_BLIST_NODE(buddy), GGP_ROSTER_SYNC_SETT);
+	return ret;
+}
+
 static void ggp_roster_set_synchronized(PurpleConnection *gc, PurpleBuddy *buddy, gboolean synchronized)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
@@ -181,27 +230,11 @@
 	}
 }
 
-static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy)
-{
-	gboolean ret = purple_blist_node_get_bool(PURPLE_BLIST_NODE(buddy), GGP_ROSTER_SYNC_SETT);
-	return ret;
-}
-
-static gboolean ggp_roster_timer_cb(gpointer _gc)
-{
-	PurpleConnection *gc = _gc;
-	
-	g_return_val_if_fail(PURPLE_CONNECTION_IS_VALID(gc), FALSE);
-	
-	ggp_roster_send_update(gc);
-	
-	return TRUE;
-}
-
 void ggp_roster_request_update(PurpleConnection *gc)
 {
 	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
+	int local_version = rdata->content ? ((ggp_roster_content*)rdata->content)->version : 0;
 	
 	if (!ggp_roster_enabled())
 	{
@@ -209,11 +242,15 @@
 		return;
 	}
 	
-	purple_debug_info("gg", "ggp_roster_request_update: local=%u\n", rdata->version);
+	purple_debug_info("gg", "ggp_roster_request_update: local=%u\n", local_version);
 	
-	gg_userlist100_request(accdata->session, GG_USERLIST100_GET, rdata->version, GG_USERLIST100_FORMAT_TYPE_GG100, NULL);
+	gg_userlist100_request(accdata->session, GG_USERLIST100_GET, local_version, GG_USERLIST100_FORMAT_TYPE_GG100, NULL);
 }
 
+/*******************************************************************************
+ * Libgadu callbacks.
+ ******************************************************************************/
+
 void ggp_roster_reply(PurpleConnection *gc, struct gg_event_userlist100_reply *reply)
 {
 	if (GG_USERLIST100_FORMAT_TYPE_GG100 != reply->format_type)
@@ -237,7 +274,7 @@
 void ggp_roster_version(PurpleConnection *gc, struct gg_event_userlist100_version *version)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
-	int local_version = rdata->version;
+	int local_version = rdata->content ? ((ggp_roster_content*)rdata->content)->version : 0;
 	int remote_version = version->version;
 
 	purple_debug_info("gg", "ggp_roster_version: local=%u, remote=%u\n", local_version, remote_version);
@@ -246,82 +283,87 @@
 		ggp_roster_request_update(gc);
 }
 
-static void ggp_roster_reply_ack(PurpleConnection *gc, uint32_t version)
+/*******************************************************************************
+ * Libpurple callbacks.
+ ******************************************************************************/
+
+void ggp_roster_alias_buddy(PurpleConnection *gc, const char *who, const char *alias)



More information about the Commits mailing list