From 5a765af1c991f855e459db60980df2447b42e380 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 28 Jul 2017 15:02:04 +0300 Subject: [PATCH] client: Use rl_hexdump to print fixed sized iterators This makes the output less clutter with duplicated infomation: before: [CHG] Device 00:1B:DC:07:31:88 ServiceData Key: 00001827-0000-1000-8000-00805f9b34fb [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0xdd [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0xdd [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 [CHG] Device 00:1B:DC:07:31:88 ServiceData Value: 0x00 after: [CHG] Device 00:1B:DC:07:31:88 ServiceData Key: 00001827-0000-1000-8000-00805f9b34fb dd dd 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 .. --- client/main.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/client/main.c b/client/main.c index 5eb83e33f..17de7f81f 100644 --- a/client/main.c +++ b/client/main.c @@ -203,6 +203,72 @@ static void print_device(GDBusProxy *proxy, const char *description) address, name); } +static void print_fixed_iter(const char *label, const char *name, + DBusMessageIter *iter) +{ + dbus_bool_t *valbool; + dbus_uint32_t *valu32; + dbus_uint16_t *valu16; + dbus_int16_t *vals16; + unsigned char *byte; + int len; + + switch (dbus_message_iter_get_arg_type(iter)) { + case DBUS_TYPE_BOOLEAN: + dbus_message_iter_get_fixed_array(iter, &valbool, &len); + + if (len <= 0) + return; + + rl_printf("%s%s:\n", label, name); + rl_hexdump((void *)valbool, len * sizeof(*valbool)); + + break; + case DBUS_TYPE_UINT32: + dbus_message_iter_get_fixed_array(iter, &valu32, &len); + + if (len <= 0) + return; + + rl_printf("%s%s:\n", label, name); + rl_hexdump((void *)valu32, len * sizeof(*valu32)); + + break; + case DBUS_TYPE_UINT16: + dbus_message_iter_get_fixed_array(iter, &valu16, &len); + + if (len <= 0) + return; + + rl_printf("%s%s:\n", label, name); + rl_hexdump((void *)valu16, len * sizeof(*valu16)); + + break; + case DBUS_TYPE_INT16: + dbus_message_iter_get_fixed_array(iter, &vals16, &len); + + if (len <= 0) + return; + + rl_printf("%s%s:\n", label, name); + rl_hexdump((void *)vals16, len * sizeof(*vals16)); + + break; + case DBUS_TYPE_BYTE: + dbus_message_iter_get_fixed_array(iter, &byte, &len); + + if (len <= 0) + return; + + rl_printf("%s%s:\n", label, name); + rl_hexdump((void *)byte, len * sizeof(*byte)); + + break; + default: + return; + }; +} + static void print_iter(const char *label, const char *name, DBusMessageIter *iter) { @@ -256,6 +322,13 @@ static void print_iter(const char *label, const char *name, break; case DBUS_TYPE_ARRAY: dbus_message_iter_recurse(iter, &subiter); + + if (dbus_type_is_fixed( + dbus_message_iter_get_arg_type(&subiter))) { + print_fixed_iter(label, name, &subiter); + break; + } + while (dbus_message_iter_get_arg_type(&subiter) != DBUS_TYPE_INVALID) { print_iter(label, name, &subiter); -- 2.47.3