/soc/2012/tomkiewicz/gg: dbcdbdf2f02b: Gadu-Gadu: roster - tidying

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sun Jul 15 06:54:41 EDT 2012


Changeset: dbcdbdf2f02b99007a1dd022fa02f71d84a39a04
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-07-15 12:54 +0200
Branch:	 soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/dbcdbdf2f02b

Description:

Gadu-Gadu: roster - tidying

diffstat:

 libpurple/protocols/gg/roster.c |  365 ++++++++++++++++++++++++++-------------
 libpurple/protocols/gg/roster.h |   21 +-
 2 files changed, 252 insertions(+), 134 deletions(-)

diffs (truncated from 889 to 300 lines):

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
@@ -10,6 +10,7 @@
 #define GGP_ROSTER_SYNC_SETT "gg-synchronized"
 #define GGP_ROSTER_DEBUG 0
 #define GGP_ROSTER_GROUPID_DEFAULT "00000000-0000-0000-0000-000000000000"
+#define GGP_ROSTER_GROUPID_BOTS "0b345af6-0001-0000-0000-000000000004"
 
 // TODO: ignored contacts synchronization (?)
 
@@ -69,9 +70,11 @@
 	} data;
 } ggp_roster_change;
 
-static inline ggp_roster_session_data * ggp_roster_get_rdata(PurpleConnection *gc);
+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 int ggp_roster_get_version(PurpleConnection *gc);
 static gboolean ggp_roster_timer_cb(gpointer _gc);
 #if GGP_ROSTER_DEBUG
 static void ggp_roster_dump(ggp_roster_content *content);
@@ -79,18 +82,26 @@
 
 // synchronization control
 static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy);
-static void ggp_roster_set_synchronized(PurpleConnection *gc, PurpleBuddy *buddy, gboolean synchronized);
+static void ggp_roster_set_synchronized(PurpleConnection *gc,
+	PurpleBuddy *buddy, gboolean synchronized);
 
 // 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);
+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 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);
@@ -136,6 +147,14 @@
 	g_free(change);
 }
 
+static int ggp_roster_get_version(PurpleConnection *gc)
+{
+	ggp_roster_content *content = ggp_roster_get_rdata(gc)->content;
+	if (content == NULL)
+		return 0;
+	return content->version;
+}
+
 static gboolean ggp_roster_timer_cb(gpointer _gc)
 {
 	PurpleConnection *gc = _gc;
@@ -157,7 +176,7 @@
 	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);
+	purple_debug_misc("gg", "ggp_roster_dump: [%s]\n", str);
 	g_free(str);
 }
 #endif
@@ -173,7 +192,8 @@
 	
 	if (!checked)
 	{
-		enabled = gg_libgadu_check_feature(GG_LIBGADU_FEATURE_USERLIST100);
+		enabled = gg_libgadu_check_feature(
+			GG_LIBGADU_FEATURE_USERLIST100);
 		checked = TRUE;
 	}
 	return enabled;
@@ -190,7 +210,8 @@
 	rdata->is_updating = FALSE;
 	
 	if (ggp_roster_enabled())
-		rdata->timer = purple_timeout_add_seconds(2, ggp_roster_timer_cb, gc);
+		rdata->timer = purple_timeout_add_seconds(2,
+			ggp_roster_timer_cb, gc);
 }
 
 void ggp_roster_cleanup(PurpleConnection *gc)
@@ -210,52 +231,60 @@
 
 static gboolean ggp_roster_is_synchronized(PurpleBuddy *buddy)
 {
-	gboolean ret = purple_blist_node_get_bool(PURPLE_BLIST_NODE(buddy), GGP_ROSTER_SYNC_SETT);
+	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)
+static void ggp_roster_set_synchronized(PurpleConnection *gc,
+	PurpleBuddy *buddy, gboolean synchronized)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	uin_t uin = ggp_str_to_uin(purple_buddy_get_name(buddy));
 	ggp_roster_change *change;
 	
-	purple_blist_node_set_bool(PURPLE_BLIST_NODE(buddy), GGP_ROSTER_SYNC_SETT, synchronized);
+	purple_blist_node_set_bool(PURPLE_BLIST_NODE(buddy),
+		GGP_ROSTER_SYNC_SETT, synchronized);
 	if (!synchronized)
 	{
 		change = g_new0(ggp_roster_change, 1);
 		change->type = GGP_ROSTER_CHANGE_CONTACT_UPDATE;
 		change->data.uin = uin;
-		rdata->pending_updates = g_list_append(rdata->pending_updates, change);
+		rdata->pending_updates =
+			g_list_append(rdata->pending_updates, change);
 	}
 }
 
 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;
+	int local_version = ggp_roster_get_version(gc);
 	
 	if (!ggp_roster_enabled())
 	{
-		purple_debug_warning("gg", "ggp_roster_request_update: feature disabled\n");
+		purple_debug_warning("gg", "ggp_roster_request_update: "
+			"feature disabled\n");
 		return;
 	}
 	
-	purple_debug_info("gg", "ggp_roster_request_update: local=%u\n", local_version);
+	purple_debug_info("gg", "ggp_roster_request_update: local=%u\n",
+		local_version);
 	
-	gg_userlist100_request(accdata->session, GG_USERLIST100_GET, local_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)
+void ggp_roster_reply(PurpleConnection *gc,
+	struct gg_event_userlist100_reply *reply)
 {
 	if (GG_USERLIST100_FORMAT_TYPE_GG100 != reply->format_type)
 	{
-		purple_debug_warning("gg", "ggp_roster_reply: unsupported format type (%x)\n", reply->format_type);
+		purple_debug_warning("gg", "ggp_roster_reply: "
+			"unsupported format type (%x)\n", reply->format_type);
 		return;
 	}
 	
@@ -268,16 +297,18 @@
 	else if (reply->type == GG_USERLIST100_REPLY_REJECT)
 		ggp_roster_reply_reject(gc, reply->version);
 	else
-		purple_debug_error("gg", "ggp_roster_reply: unsupported reply (%x)\n", reply->type);
+		purple_debug_error("gg", "ggp_roster_reply: "
+			"unsupported reply (%x)\n", reply->type);
 }
 
-void ggp_roster_version(PurpleConnection *gc, struct gg_event_userlist100_version *version)
+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->content ? ((ggp_roster_content*)rdata->content)->version : 0;
+	int local_version = ggp_roster_get_version(gc);
 	int remote_version = version->version;
 
-	purple_debug_info("gg", "ggp_roster_version: local=%u, remote=%u\n", local_version, remote_version);
+	purple_debug_info("gg", "ggp_roster_version: local=%u, remote=%u\n",
+		local_version, remote_version);
 	
 	if (local_version < remote_version)
 		ggp_roster_request_update(gc);
@@ -287,7 +318,8 @@
  * Libpurple callbacks.
  ******************************************************************************/
 
-void ggp_roster_alias_buddy(PurpleConnection *gc, const char *who, const char *alias)
+void ggp_roster_alias_buddy(PurpleConnection *gc, const char *who,
+	const char *alias)
 {
 	PurpleBuddy *buddy;
 	
@@ -296,7 +328,8 @@
 	if (!ggp_roster_enabled())
 		return;
 	
-	purple_debug_misc("gg", "ggp_roster_alias_buddy(\"%s\", \"%s\")\n", who, alias);
+	purple_debug_misc("gg", "ggp_roster_alias_buddy(\"%s\", \"%s\")\n",
+		who, alias);
 	
 	buddy = purple_find_buddy(purple_connection_get_account(gc), who);
 	g_return_if_fail(buddy != NULL);
@@ -304,7 +337,8 @@
 	ggp_roster_set_synchronized(gc, buddy, FALSE);
 }
 
-void ggp_roster_group_buddy(PurpleConnection *gc, const char *who, const char *old_group, const char *new_group)
+void ggp_roster_group_buddy(PurpleConnection *gc, const char *who,
+	const char *old_group, const char *new_group)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new0(ggp_roster_change, 1);
@@ -314,7 +348,9 @@
 	if (rdata->is_updating)
 		return;
 	
-	purple_debug_misc("gg", "ggp_roster_group_buddy(\"%s\", \"%s\", \"%s\")\n", who, old_group, new_group);
+	purple_debug_misc("gg", "ggp_roster_group_buddy: "
+		"who=\"%s\", group=\"%s\" -> \"%s\")\n",
+		who, old_group, new_group);
 	
 	// purple_find_buddy(..., who) is not accessible at this moment
 	change->type = GGP_ROSTER_CHANGE_CONTACT_UPDATE;
@@ -322,7 +358,8 @@
 	rdata->pending_updates = g_list_append(rdata->pending_updates, change);
 }
 
-void ggp_roster_rename_group(PurpleConnection *gc, const char *old_name, PurpleGroup *group, GList *moved_buddies)
+void ggp_roster_rename_group(PurpleConnection *gc, const char *old_name,
+	PurpleGroup *group, GList *moved_buddies)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new0(ggp_roster_change, 1);
@@ -332,11 +369,13 @@
 	
 	change->type = GGP_ROSTER_CHANGE_GROUP_RENAME;
 	change->data.group_rename.old_name = g_strdup(old_name);
-	change->data.group_rename.new_name = g_strdup(purple_group_get_name(group));
+	change->data.group_rename.new_name =
+		g_strdup(purple_group_get_name(group));
 	rdata->pending_updates = g_list_append(rdata->pending_updates, change);
 }
 
-void ggp_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
+void ggp_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy,
+	PurpleGroup *group, const char *message)
 {
 	g_return_if_fail(gc != NULL);
 	g_return_if_fail(buddy != NULL);
@@ -347,7 +386,8 @@
 	ggp_roster_set_synchronized(gc, buddy, FALSE);
 }
 
-void ggp_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
+void ggp_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy,
+	PurpleGroup *group)
 {
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new0(ggp_roster_change, 1);
@@ -364,7 +404,8 @@
  * Buddy list import.
  ******************************************************************************/
 
-static gboolean ggp_roster_reply_list_read_group(xmlnode *node, ggp_roster_content *content)
+static gboolean ggp_roster_reply_list_read_group(xmlnode *node,
+	ggp_roster_content *content)
 {
 	char *name, *id;
 	gboolean removable;
@@ -381,11 +422,11 @@
 		g_return_val_if_reached(FALSE);
 	}
 	
-	is_bot = (strcmp(id, "0b345af6-0001-0000-0000-000000000004") == 0 ||
+	is_bot = (strcmp(id, GGP_ROSTER_GROUPID_BOTS) == 0 ||
 		g_strcmp0(name, "Pomocnicy") == 0);
 	is_default = (strcmp(id, GGP_ROSTER_GROUPID_DEFAULT) == 0 ||
 		g_strcmp0(name, GGP_PURPLEW_GROUP_DEFAULT) == 0 ||
-		g_strcmp0(name, _("[default]")) == 0);
+		g_strcmp0(name, "[default]") == 0);
 	
 	if (!content->bots_group_id && is_bot)
 		content->bots_group_id = g_strdup(id);



More information about the Commits mailing list