/soc/2012/tomkiewicz/gg: 8321461fa2be: Gadu-Gadu: roster - disab...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Thu Jul 12 18:38:18 EDT 2012


Changeset: 8321461fa2be7f8571eb67a7fc14e4b3266830de
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-07-13 00:37 +0200
Branch:	 soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/8321461fa2be

Description:

Gadu-Gadu: roster - disable, when not supported

diffstat:

 libpurple/protocols/gg/roster.c |  44 +++++++++++++++++++++++++++++++++++-----
 libpurple/protocols/gg/roster.h |   1 +
 2 files changed, 39 insertions(+), 6 deletions(-)

diffs (125 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
@@ -69,6 +69,19 @@
 
 /********/
 
+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;
+}
+
 static inline ggp_roster_session_data *
 ggp_roster_get_rdata(PurpleConnection *gc)
 {
@@ -84,15 +97,18 @@
 	rdata->content = NULL;
 	rdata->sent_updates = NULL;
 	rdata->pending_updates = NULL;
+	rdata->timer = 0;
 	
-	rdata->timer = purple_timeout_add_seconds(2, ggp_roster_timer_cb, gc);
+	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);
 
-	purple_timeout_remove(rdata->timer);
+	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);
@@ -159,14 +175,14 @@
 	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	
-	purple_debug_info("gg", "ggp_roster_request_update: local=%u\n", rdata->version);
-	
-	if (!gg_libgadu_check_feature(GG_LIBGADU_FEATURE_USERLIST100))
+	if (!ggp_roster_enabled())
 	{
-		purple_debug_error("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", rdata->version);
+	
 	gg_userlist100_request(accdata->session, GG_USERLIST100_GET, rdata->version, GG_USERLIST100_FORMAT_TYPE_GG100, NULL);
 }
 
@@ -817,6 +833,9 @@
 	
 	g_return_if_fail(who != NULL);
 	
+	if (!ggp_roster_enabled())
+		return;
+	
 	buddy = purple_find_buddy(purple_connection_get_account(gc), who);
 	g_return_if_fail(buddy != NULL);
 	
@@ -828,6 +847,9 @@
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new(ggp_roster_change, 1);
 
+	if (!ggp_roster_enabled())
+		return;
+	
 	// purple_find_buddy(..., who) is not accessible at this moment
 	change->type = GGP_ROSTER_CHANGE_CONTACT_UPDATE;
 	change->data.uin = ggp_str_to_uin(who);
@@ -839,6 +861,9 @@
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new(ggp_roster_change, 1);
 	
+	if (!ggp_roster_enabled())
+		return;
+	
 	change->type = GGP_ROSTER_CHANGE_GROUP_RENAME;
 	change->data.group_name = g_strdup(purple_group_get_name(group));
 	rdata->pending_updates = g_list_append(rdata->pending_updates, change);
@@ -848,6 +873,10 @@
 {
 	g_return_if_fail(gc != NULL);
 	g_return_if_fail(buddy != NULL);
+
+	if (!ggp_roster_enabled())
+		return;
+	
 	ggp_roster_set_synchronized(gc, buddy, FALSE);
 }
 
@@ -856,6 +885,9 @@
 	ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc);
 	ggp_roster_change *change = g_new(ggp_roster_change, 1);
 	
+	if (!ggp_roster_enabled())
+		return;
+	
 	change->type = GGP_ROSTER_CHANGE_CONTACT_REMOVE;
 	change->data.uin = ggp_str_to_uin(purple_buddy_get_name(buddy));
 	rdata->pending_updates = g_list_append(rdata->pending_updates, change);
diff --git a/libpurple/protocols/gg/roster.h b/libpurple/protocols/gg/roster.h
--- a/libpurple/protocols/gg/roster.h
+++ b/libpurple/protocols/gg/roster.h
@@ -16,6 +16,7 @@
 } ggp_roster_session_data;
 
 // setup
+gboolean ggp_roster_enabled(void);
 void ggp_roster_setup(PurpleConnection *gc);
 void ggp_roster_cleanup(PurpleConnection *gc);
 



More information about the Commits mailing list