diff libpurple/protocols/qq/utils.c @ 23051:190bc4ecf6c3

patch-03-add-qq_hex_dump
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 24 Jun 2008 12:09:16 +0000
parents 44b4e8bd759b
children 51dbe83ebbd3
line wrap: on
line diff
--- a/libpurple/protocols/qq/utils.c	Tue Jun 24 11:58:57 2008 +0000
+++ b/libpurple/protocols/qq/utils.c	Tue Jun 24 12:09:16 2008 +0000
@@ -294,7 +294,7 @@
 
 /* Dumps a chunk of raw data into an ASCII hex string.
  * The return should be freed later. */
-gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes)
+static gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes)
 {
 	GString *str;
 	gchar *ret;
@@ -331,6 +331,31 @@
 	return ret;
 }
 
+void qq_hex_dump(PurpleDebugLevel level, const char *category,
+		const guint8 *pdata, gint bytes,	
+		const char *format, ...)
+{
+	va_list args;
+	char *arg_s = NULL;
+	gchar *phex = NULL;
+
+	g_return_if_fail(level != PURPLE_DEBUG_ALL);
+	g_return_if_fail(format != NULL);
+
+	va_start(args, format);
+	arg_s = g_strdup_vprintf(format, args);
+	va_end(args);
+
+	if (bytes <= 0) {
+		purple_debug(level, category, arg_s);
+		return;
+	}
+
+	phex = hex_dump_to_str(pdata, bytes);
+	purple_debug(level, category, "%s - (len %d)\n%s", arg_s, bytes, phex);
+	g_free(phex);
+}
+
 /* convert face num from packet (0-299) to local face (1-100) */
 gchar *face_to_icon_str(gint face)
 {