summaryrefslogtreecommitdiffstats
path: root/gatchat
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-08-09 19:17:52 -0700
committerMarcel Holtmann <marcel@holtmann.org>2011-08-09 19:17:52 -0700
commit4b76ec7159795d7b32f2355cb584b229abc65077 (patch)
treeb363d4eabfa56940c009f876dbd240a9eb843042 /gatchat
parent5fea0c006a1138e4bad4b6330938033ad7fb0887 (diff)
downloadofono-4b76ec7159795d7b32f2355cb584b229abc65077.tar.bz2
gatchat: Add utility function for hexdump debugs
Diffstat (limited to 'gatchat')
-rw-r--r--gatchat/gatutil.c42
-rw-r--r--gatchat/gatutil.h3
2 files changed, 44 insertions, 1 deletions
diff --git a/gatchat/gatutil.c b/gatchat/gatutil.c
index 6a7e177f..d5f9e0d5 100644
--- a/gatchat/gatutil.c
+++ b/gatchat/gatutil.c
@@ -23,8 +23,9 @@
#include <config.h>
#endif
-#include <string.h>
+#include <stdio.h>
#include <ctype.h>
+#include <string.h>
#include <glib.h>
@@ -132,6 +133,45 @@ void g_at_util_debug_dump(gboolean in, const unsigned char *buf, gsize len,
g_string_free(str, TRUE);
}
+void g_at_util_debug_hexdump(gboolean in, const unsigned char *buf, gsize len,
+ GAtDebugFunc debugf, gpointer user_data)
+{
+ static const char hexdigits[] = "0123456789abcdef";
+ char str[68];
+ gsize i;
+
+ str[0] = in ? '<' : '>';
+
+ for (i = 0; i < len; i++) {
+ str[((i % 16) * 3) + 1] = ' ';
+ str[((i % 16) * 3) + 2] = hexdigits[buf[i] >> 4];
+ str[((i % 16) * 3) + 3] = hexdigits[buf[i] & 0xf];
+ str[(i % 16) + 51] = isprint(buf[i]) ? buf[i] : '.';
+
+ if ((i + 1) % 16 == 0) {
+ str[49] = ' ';
+ str[50] = ' ';
+ str[67] = '\0';
+ debugf(str, user_data);
+ str[0] = ' ';
+ }
+ }
+
+ if ((i + 1) % 16 > 0) {
+ gsize j;
+ for (j = (i % 16); j < 16; j++) {
+ str[(j * 3) + 1] = ' ';
+ str[(j * 3) + 2] = ' ';
+ str[(j * 3) + 3] = ' ';
+ str[j + 51] = ' ';
+ }
+ str[49] = ' ';
+ str[50] = ' ';
+ str[67] = '\0';
+ debugf(str, user_data);
+ }
+}
+
gboolean g_at_util_setup_io(GIOChannel *io, GIOFlags flags)
{
GIOFlags io_flags;
diff --git a/gatchat/gatutil.h b/gatchat/gatutil.h
index 1a065af2..5c891086 100644
--- a/gatchat/gatutil.h
+++ b/gatchat/gatutil.h
@@ -34,6 +34,9 @@ void g_at_util_debug_chat(gboolean in, const char *str, gsize len,
void g_at_util_debug_dump(gboolean in, const unsigned char *buf, gsize len,
GAtDebugFunc debugf, gpointer user_data);
+void g_at_util_debug_hexdump(gboolean in, const unsigned char *buf, gsize len,
+ GAtDebugFunc debugf, gpointer user_data);
+
gboolean g_at_util_setup_io(GIOChannel *io, GIOFlags flags);
#ifdef __cplusplus