Diff between fc41a5af76e825dcf2ef4f1de4a807c4a33ab5b2 and 833773d0914f98a56511a4bc4438ba6ab16f3ac2

Changed Files

File Additions Deletions Status
Makefile.tools +2 -1 modified
client/main.c +45 -30 modified

Full Patch

diff --git a/Makefile.tools b/Makefile.tools
index 6be310e..f53760d 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -4,7 +4,8 @@ bin_PROGRAMS += client/bluetoothctl
 
 client_bluetoothctl_SOURCES = $(gdbus_sources) client/main.c \
 					client/display.h client/display.c \
-					client/agent.h client/agent.c
+					client/agent.h client/agent.c \
+					monitor/uuid.h monitor/uuid.c
 client_bluetoothctl_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lreadline
 endif
 
diff --git a/client/main.c b/client/main.c
index ea83942..b716d95 100644
--- a/client/main.c
+++ b/client/main.c
@@ -37,6 +37,7 @@
 #include <glib.h>
 #include <gdbus.h>
 
+#include "monitor/uuid.h"
 #include "agent.h"
 #include "display.h"
 
@@ -181,6 +182,46 @@ static void print_property(GDBusProxy *proxy, const char *name)
 	print_iter("\t", name, &iter);
 }
 
+static void print_uuids(GDBusProxy *proxy)
+{
+	DBusMessageIter iter, value;
+
+	if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
+		return;
+
+	dbus_message_iter_recurse(&iter, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+		const char *uuid, *text;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+
+		text = uuidstr_to_str(uuid);
+		if (text) {
+			char str[26];
+			unsigned int n;
+
+			str[sizeof(str) - 1] = '\0';
+
+			n = snprintf(str, sizeof(str), "%s", text);
+			if (n > sizeof(str) - 1) {
+				str[sizeof(str) - 2] = '.';
+				str[sizeof(str) - 3] = '.';
+				if (str[sizeof(str) - 4] == ' ')
+					str[sizeof(str) - 4] = '.';
+
+				n = sizeof(str) - 1;
+			}
+
+			rl_printf("\tUUID: %s%*c(%s)\n",
+						str, 26 - n, ' ', uuid);
+		} else
+			rl_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid);
+
+		dbus_message_iter_next(&value);
+	}
+}
+
 static gboolean device_is_child(GDBusProxy *device, GDBusProxy *master)
 {
 	DBusMessageIter iter;
@@ -376,7 +417,7 @@ static void cmd_list(const char *arg)
 static void cmd_show(const char *arg)
 {
 	GDBusProxy *proxy;
-	DBusMessageIter iter, value;
+	DBusMessageIter iter;
 	const char *address;
 
 	if (!arg || !strlen(arg)) {
@@ -403,20 +444,7 @@ static void cmd_show(const char *arg)
 	print_property(proxy, "Powered");
 	print_property(proxy, "Discoverable");
 	print_property(proxy, "Pairable");
-
-	if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
-		goto done;
-
-	dbus_message_iter_recurse(&iter, &value);
-
-	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
-		const char *str;
-		dbus_message_iter_get_basic(&value, &str);
-		rl_printf("\tUUID: %s\n", str);
-		dbus_message_iter_next(&value);
-	}
-
-done:
+	print_uuids(proxy);
 	print_property(proxy, "Discovering");
 }
 
@@ -628,7 +656,7 @@ static void cmd_scan(const char *arg)
 static void cmd_info(const char *arg)
 {
 	GDBusProxy *proxy;
-	DBusMessageIter iter, value;
+	DBusMessageIter iter;
 	const char *address;
 
 	if (!arg || !strlen(arg)) {
@@ -657,20 +685,7 @@ static void cmd_info(const char *arg)
 	print_property(proxy, "Blocked");
 	print_property(proxy, "Connected");
 	print_property(proxy, "LegacyPairing");
-
-	if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
-		goto done;
-
-	dbus_message_iter_recurse(&iter, &value);
-
-	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
-		const char *str;
-		dbus_message_iter_get_basic(&value, &str);
-		rl_printf("\tUUID: %s\n", str);
-		dbus_message_iter_next(&value);
-	}
-
-done:
+	print_uuids(proxy);
 	print_property(proxy, "VendorSource");
 	print_property(proxy, "Vendor");
 	print_property(proxy, "Product");