/cpw/tomkiewicz/gg11: ee5663c0ffe8: Gadu-Gadu: new libgadu debug...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Fri Nov 16 11:37:56 EST 2012


Changeset: ee5663c0ffe8f341505fee76f19c32734bcf9780
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-11-16 17:37 +0100
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/ee5663c0ffe8

Description:

Gadu-Gadu: new libgadu debug handler

diffstat:

 libpurple/protocols/gg/edisc.c          |   2 +
 libpurple/protocols/gg/gg.c             |  28 +-----------
 libpurple/protocols/gg/libgadu-events.c |   1 +
 libpurple/protocols/gg/libgaduw.c       |  72 ++++++++++++++++++++++++++++----
 libpurple/protocols/gg/libgaduw.h       |   8 ++-
 5 files changed, 73 insertions(+), 38 deletions(-)

diffs (196 lines):

diff --git a/libpurple/protocols/gg/edisc.c b/libpurple/protocols/gg/edisc.c
--- a/libpurple/protocols/gg/edisc.c
+++ b/libpurple/protocols/gg/edisc.c
@@ -237,6 +237,8 @@ void ggp_edisc_xfer_ticket_changed(Purpl
 		json_object_get_string_member(ticket, "ack_status"));
 	send_status = json_object_get_string_member(ticket, "send_status");
 
+	if (ticket_id == NULL)
+		ticket_id = "";
 	xfer = g_hash_table_lookup(sdata->xfers_initialized, ticket_id);
 	if (xfer == NULL) {
 		purple_debug_misc("gg", "ggp_edisc_event_ticket_changed: "
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -54,6 +54,7 @@
 #include "pubdir-prpl.h"
 #include "message-prpl.h"
 #include "html.h"
+#include "libgaduw.h"
 
 /* ---------------------------------------------------------------------- */
 
@@ -1022,29 +1023,6 @@ static PurplePluginInfo info = {
 	NULL
 };
 
-static void purple_gg_debug_handler(int level, const char * format, va_list args) {
-	PurpleDebugLevel purple_level;
-	char *msg = g_strdup_vprintf(format, args);
-
-	/* This is pretty pointless since the GG_DEBUG levels don't correspond to
-	 * the purple ones */
-	switch (level) {
-		case GG_DEBUG_FUNCTION:
-			purple_level = PURPLE_DEBUG_INFO;
-			break;
-		case GG_DEBUG_MISC:
-		case GG_DEBUG_NET:
-		case GG_DEBUG_DUMP:
-		case GG_DEBUG_TRAFFIC:
-		default:
-			purple_level = PURPLE_DEBUG_MISC;
-			break;
-	}
-
-	purple_debug(purple_level, "gg", "%s", msg);
-	g_free(msg);
-}
-
 static PurpleAccountOption *ggp_server_option;
 
 static void init_plugin(PurplePlugin *plugin)
@@ -1081,8 +1059,6 @@ static void init_plugin(PurplePlugin *pl
 		"show_links_from_strangers", 1);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
 		option);
-
-	gg_debug_handler = purple_gg_debug_handler;
 }
 
 static gboolean ggp_load(PurplePlugin *plugin)
@@ -1090,6 +1066,7 @@ static gboolean ggp_load(PurplePlugin *p
 	purple_debug_info("gg", "Loading Gadu-Gadu protocol plugin with "
 		"libgadu %s...\n", gg_libgadu_version());
 
+	ggp_libgaduw_setup();
 	ggp_resolver_purple_setup();
 	ggp_servconn_setup(ggp_server_option);
 	ggp_html_setup();
@@ -1103,6 +1080,7 @@ static gboolean ggp_unload(PurplePlugin 
 	ggp_servconn_cleanup();
 	ggp_html_cleanup();
 	ggp_message_cleanup_global();
+	ggp_libgaduw_cleanup();
 
 	return TRUE;
 }
diff --git a/libpurple/protocols/gg/libgadu-events.c b/libpurple/protocols/gg/libgadu-events.c
--- a/libpurple/protocols/gg/libgadu-events.c
+++ b/libpurple/protocols/gg/libgadu-events.c
@@ -88,6 +88,7 @@ void ggp_events_json(PurpleConnection *g
 	static const gchar *ignored_events[] = {
 		"edisc/scope_files_changed",
 		"notifications/state",
+		"invitations/list",
 		NULL
 	};
 	const gchar **it;
diff --git a/libpurple/protocols/gg/libgaduw.c b/libpurple/protocols/gg/libgaduw.c
--- a/libpurple/protocols/gg/libgaduw.c
+++ b/libpurple/protocols/gg/libgaduw.c
@@ -34,6 +34,68 @@
 #include "purplew.h"
 #include "gg.h"
 
+static void ggp_libgaduw_debug_handler(int level, const char * format,
+	va_list args);
+
+/*******************************************************************************
+ * Setup/cleanup.
+ ******************************************************************************/
+
+void ggp_libgaduw_setup(void)
+{
+	gg_debug_handler = ggp_libgaduw_debug_handler;
+}
+
+void ggp_libgaduw_cleanup(void)
+{
+	gg_debug_handler = NULL;
+}
+
+/*******************************************************************************
+ * General.
+ ******************************************************************************/
+
+const gchar * ggp_libgaduw_version(PurpleConnection *gc)
+{
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	const gchar *ver = accdata->session->client_version;
+	
+	if (ver != NULL && isdigit(ver[0]))
+		return ver;
+	return GG_DEFAULT_CLIENT_VERSION;
+}
+
+static void ggp_libgaduw_debug_handler(int level, const char * format,
+	va_list args)
+{
+	PurpleDebugLevel purple_level;
+	char *msg;
+
+	if ((level & GG_DEBUG_NET) ||
+		(level & GG_DEBUG_FUNCTION)) {
+		if (!purple_debug_is_verbose())
+			return;
+	}
+
+	if ((level & GG_DEBUG_DUMP) || /* GG session protocol packets */
+		(level & GG_DEBUG_TRAFFIC)) { /* HTTP traffic */
+		if (!purple_debug_is_verbose() || !purple_debug_is_unsafe())
+			return;
+	}
+
+	msg = g_strdup_vprintf(format, args);
+
+	if (level & GG_DEBUG_ERROR)
+		purple_level = PURPLE_DEBUG_ERROR;
+	else if (level & GG_DEBUG_WARNING)
+		purple_level = PURPLE_DEBUG_WARNING;
+	else
+		purple_level = PURPLE_DEBUG_MISC;
+
+	purple_debug(purple_level, "gg", "%s", msg);
+	g_free(msg);
+}
+
 /*******************************************************************************
  * HTTP requests.
  ******************************************************************************/
@@ -139,13 +201,3 @@ static void ggp_libgaduw_http_finish(ggp
 	req->h->destroy(req->h);
 	g_free(req);
 }
-
-const gchar * ggp_libgaduw_version(PurpleConnection *gc)
-{
-	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
-	const gchar *ver = accdata->session->client_version;
-	
-	if (ver != NULL && isdigit(ver[0]))
-		return ver;
-	return GG_DEFAULT_CLIENT_VERSION;
-}
diff --git a/libpurple/protocols/gg/libgaduw.h b/libpurple/protocols/gg/libgaduw.h
--- a/libpurple/protocols/gg/libgaduw.h
+++ b/libpurple/protocols/gg/libgaduw.h
@@ -49,12 +49,14 @@ typedef struct
 	guint inpa;
 } ggp_libgaduw_http_req;
 
+void ggp_libgaduw_setup(void);
+void ggp_libgaduw_cleanup(void);
+
+const gchar * ggp_libgaduw_version(PurpleConnection *gc);
+
 ggp_libgaduw_http_req * ggp_libgaduw_http_watch(PurpleConnection *gc,
 	struct gg_http *h, ggp_libgaduw_http_cb cb, gpointer user_data,
 	gboolean show_processing);
 void ggp_libgaduw_http_cancel(ggp_libgaduw_http_req *req);
 
-const gchar * ggp_libgaduw_version(PurpleConnection *gc);
-
-
 #endif /* _GGP_LIBGADUW_H */



More information about the Commits mailing list