summaryrefslogtreecommitdiff
path: root/src/libmbim-glib
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-07-27 19:45:53 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-07-28 09:47:54 +0200
commit8e64510e706d7192ec9e0db6c506d05beda9820c (patch)
treecf2385f5e14b9e5977c4e6a8a0f554c684d17049 /src/libmbim-glib
parent0e2ad4993ebcbcbc52ca0b0cc13a65ecfcbd81c8 (diff)
mbim-common: turn __mbim_utils_str_hex into mbim_common_str_hex
__mbim_utils_str_hex is a useful utility method for returning a hexadecimal string representation of a sequence of bytes in memory. This patch turns it into 'mbim_common_str_hex', which can be shared between libmbim-glib and mbimcli.
Diffstat (limited to 'src/libmbim-glib')
-rw-r--r--src/libmbim-glib/Makefile.am2
-rw-r--r--src/libmbim-glib/mbim-device.c15
-rw-r--r--src/libmbim-glib/mbim-utils.c36
-rw-r--r--src/libmbim-glib/mbim-utils.h3
-rw-r--r--src/libmbim-glib/test/Makefile.am4
-rw-r--r--src/libmbim-glib/test/test-message-builder.c6
-rw-r--r--src/libmbim-glib/test/test-message-parser.c6
7 files changed, 20 insertions, 52 deletions
diff --git a/src/libmbim-glib/Makefile.am b/src/libmbim-glib/Makefile.am
index d2a675d..49b2190 100644
--- a/src/libmbim-glib/Makefile.am
+++ b/src/libmbim-glib/Makefile.am
@@ -8,6 +8,7 @@ libmbim_glib_core_la_CPPFLAGS = \
$(GUDEV_CFLAGS) \
-I$(top_srcdir) \
-I$(top_builddir) \
+ -I$(top_srcdir)/src/common \
-I$(top_srcdir)/src/libmbim-glib \
-I$(top_srcdir)/src/libmbim-glib/generated \
-I$(top_builddir)/src/libmbim-glib \
@@ -36,6 +37,7 @@ libmbim_glib_la_SOURCES = \
libmbim_glib_la_LIBADD = \
libmbim-glib-core.la \
+ ${top_builddir}/src/common/libmbim-common.la \
${top_builddir}/src/libmbim-glib/generated/libmbim-glib-generated.la \
$(LIBMBIM_GLIB_LIBS) \
$(GUDEV_LIBS)
diff --git a/src/libmbim-glib/mbim-device.c b/src/libmbim-glib/mbim-device.c
index 612ffe1..68544af 100644
--- a/src/libmbim-glib/mbim-device.c
+++ b/src/libmbim-glib/mbim-device.c
@@ -43,6 +43,7 @@
# include <gudev/gudev.h>
#endif
+#include "mbim-common.h"
#include "mbim-utils.h"
#include "mbim-device.h"
#include "mbim-message.h"
@@ -495,9 +496,9 @@ process_message (MbimDevice *self,
if (mbim_utils_get_traces_enabled ()) {
gchar *printable;
- printable = __mbim_utils_str_hex (((GByteArray *)message)->data,
- ((GByteArray *)message)->len,
- ':');
+ printable = mbim_common_str_hex (((GByteArray *)message)->data,
+ ((GByteArray *)message)->len,
+ ':');
g_debug ("[%s] Received message...%s\n"
">>>>>> RAW:\n"
">>>>>> length = %u\n"
@@ -1812,7 +1813,7 @@ device_send (MbimDevice *self,
if (mbim_utils_get_traces_enabled ()) {
gchar *printable;
- printable = __mbim_utils_str_hex (raw_message, raw_message_len, ':');
+ printable = mbim_common_str_hex (raw_message, raw_message_len, ':');
g_debug ("[%s] Sent message...\n"
"<<<<<< RAW:\n"
"<<<<<< length = %u\n"
@@ -1847,9 +1848,9 @@ device_send (MbimDevice *self,
gchar *printable_fh;
gchar *printable_d;
- printable_h = __mbim_utils_str_hex (&fragments[i].header, sizeof (fragments[i].header), ':');
- printable_fh = __mbim_utils_str_hex (&fragments[i].fragment_header, sizeof (fragments[i].fragment_header), ':');
- printable_d = __mbim_utils_str_hex (fragments[i].data, fragments[i].data_length, ':');
+ printable_h = mbim_common_str_hex (&fragments[i].header, sizeof (fragments[i].header), ':');
+ printable_fh = mbim_common_str_hex (&fragments[i].fragment_header, sizeof (fragments[i].fragment_header), ':');
+ printable_d = mbim_common_str_hex (fragments[i].data, fragments[i].data_length, ':');
g_debug ("[%s] Sent fragment (%u)...\n"
"<<<<<< RAW:\n"
"<<<<<< length = %u\n"
diff --git a/src/libmbim-glib/mbim-utils.c b/src/libmbim-glib/mbim-utils.c
index a7541ae..f360542 100644
--- a/src/libmbim-glib/mbim-utils.c
+++ b/src/libmbim-glib/mbim-utils.c
@@ -39,42 +39,6 @@
**/
/*****************************************************************************/
-
-gchar *
-__mbim_utils_str_hex (gconstpointer mem,
- gsize size,
- gchar delimiter)
-{
- const guint8 *data = mem;
- gsize i;
- gsize j;
- gsize new_str_length;
- gchar *new_str;
-
- /* Get new string length. If input string has N bytes, we need:
- * - 1 byte for last NUL char
- * - 2N bytes for hexadecimal char representation of each byte...
- * - N-1 bytes for the separator ':'
- * So... a total of (1+2N+N-1) = 3N bytes are needed... */
- new_str_length = 3 * size;
-
- /* Allocate memory for new array and initialize contents to NUL */
- new_str = g_malloc0 (new_str_length);
-
- /* Print hexadecimal representation of each byte... */
- for (i = 0, j = 0; i < size; i++, j += 3) {
- /* Print character in output string... */
- snprintf (&new_str[j], 3, "%02X", data[i]);
- /* And if needed, add separator */
- if (i != (size - 1) )
- new_str[j + 2] = delimiter;
- }
-
- /* Set output string */
- return new_str;
-}
-
-/*****************************************************************************/
gboolean
__mbim_user_allowed (uid_t uid,
GError **error)
diff --git a/src/libmbim-glib/mbim-utils.h b/src/libmbim-glib/mbim-utils.h
index ee5632f..77ed4ca 100644
--- a/src/libmbim-glib/mbim-utils.h
+++ b/src/libmbim-glib/mbim-utils.h
@@ -39,9 +39,6 @@ void mbim_utils_set_traces_enabled (gboolean enabled);
/* Other private methods */
#if defined (LIBMBIM_GLIB_COMPILATION)
-gchar *__mbim_utils_str_hex (gconstpointer mem,
- gsize size,
- gchar delimiter);
gboolean __mbim_user_allowed (uid_t uid,
GError **error);
#endif
diff --git a/src/libmbim-glib/test/Makefile.am b/src/libmbim-glib/test/Makefile.am
index cddfb26..d492ed8 100644
--- a/src/libmbim-glib/test/Makefile.am
+++ b/src/libmbim-glib/test/Makefile.am
@@ -69,11 +69,13 @@ test_message_parser_SOURCES = \
test_message_parser_CPPFLAGS = \
$(LIBMBIM_GLIB_CFLAGS) \
-I$(top_srcdir) \
+ -I$(top_srcdir)/src/common \
-I$(top_srcdir)/src/libmbim-glib \
-I$(top_builddir)/src/libmbim-glib \
-I$(top_builddir)/src/libmbim-glib/generated \
-DLIBMBIM_GLIB_COMPILATION
test_message_parser_LDADD = \
+ $(top_builddir)/src/common/libmbim-common.la \
$(top_builddir)/src/libmbim-glib/libmbim-glib-core.la \
$(top_builddir)/src/libmbim-glib/generated/libmbim-glib-generated.la \
$(LIBMBIM_GLIB_LIBS)
@@ -83,11 +85,13 @@ test_message_builder_SOURCES = \
test_message_builder_CPPFLAGS = \
$(LIBMBIM_GLIB_CFLAGS) \
-I$(top_srcdir) \
+ -I$(top_srcdir)/src/common \
-I$(top_srcdir)/src/libmbim-glib \
-I$(top_builddir)/src/libmbim-glib \
-I$(top_builddir)/src/libmbim-glib/generated \
-DLIBMBIM_GLIB_COMPILATION
test_message_builder_LDADD = \
+ $(top_builddir)/src/common/libmbim-common.la \
$(top_builddir)/src/libmbim-glib/libmbim-glib-core.la \
$(top_builddir)/src/libmbim-glib/generated/libmbim-glib-generated.la \
$(LIBMBIM_GLIB_LIBS)
diff --git a/src/libmbim-glib/test/test-message-builder.c b/src/libmbim-glib/test/test-message-builder.c
index 18fd29d..c467eef 100644
--- a/src/libmbim-glib/test/test-message-builder.c
+++ b/src/libmbim-glib/test/test-message-builder.c
@@ -20,7 +20,7 @@
#include "mbim-message-private.h"
#include "mbim-cid.h"
#include "mbim-enums.h"
-#include "mbim-utils.h"
+#include "mbim-common.h"
#include "mbim-basic-connect.h"
#include "mbim-ussd.h"
#include "mbim-auth.h"
@@ -38,8 +38,8 @@ test_message_trace (const guint8 *computed,
gchar *message_str;
gchar *expected_str;
- message_str = __mbim_utils_str_hex (computed, computed_size, ':');
- expected_str = __mbim_utils_str_hex (expected, expected_size, ':');
+ message_str = mbim_common_str_hex (computed, computed_size, ':');
+ expected_str = mbim_common_str_hex (expected, expected_size, ':');
/* Dump all message contents */
g_print ("\n"
diff --git a/src/libmbim-glib/test/test-message-parser.c b/src/libmbim-glib/test/test-message-parser.c
index a71c8c5..3ba4946 100644
--- a/src/libmbim-glib/test/test-message-parser.c
+++ b/src/libmbim-glib/test/test-message-parser.c
@@ -24,7 +24,7 @@
#include "mbim-ms-firmware-id.h"
#include "mbim-message.h"
#include "mbim-cid.h"
-#include "mbim-utils.h"
+#include "mbim-common.h"
#if defined ENABLE_TEST_MESSAGE_TRACES
static void
@@ -36,8 +36,8 @@ test_message_trace (const guint8 *computed,
gchar *message_str;
gchar *expected_str;
- message_str = __mbim_utils_str_hex (computed, computed_size, ':');
- expected_str = __mbim_utils_str_hex (expected, expected_size, ':');
+ message_str = mbim_common_str_hex (computed, computed_size, ':');
+ expected_str = mbim_common_str_hex (expected, expected_size, ':');
/* Dump all message contents */
g_print ("\n"