diff options
| -rw-r--r-- | include/swaybar/tray/dbus.h | 6 | ||||
| -rw-r--r-- | swaybar/tray/dbus.c | 8 | ||||
| -rw-r--r-- | swaybar/tray/sni.c | 18 | ||||
| -rw-r--r-- | swaybar/tray/tray.c | 2 |
4 files changed, 20 insertions, 14 deletions
diff --git a/include/swaybar/tray/dbus.h b/include/swaybar/tray/dbus.h index eb9cfea7..51754464 100644 --- a/include/swaybar/tray/dbus.h +++ b/include/swaybar/tray/dbus.h @@ -6,6 +6,12 @@ extern DBusConnection *conn; /** + * Checks the signature of the given iter against `sig`. Prefer to + * `dbus_message_iter_get_signature` as this one frees the intermediate string. + */ +bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig); + +/** * Should be called in main loop to dispatch events */ void dispatch_dbus(); diff --git a/swaybar/tray/dbus.c b/swaybar/tray/dbus.c index 8e719fd9..46a1c807 100644 --- a/swaybar/tray/dbus.c +++ b/swaybar/tray/dbus.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 700 #include <stdio.h> +#include <string.h> #include <stdlib.h> #include <stdint.h> #include <stdbool.h> @@ -137,6 +138,13 @@ static void dispatch_status(DBusConnection *connection, DBusDispatchStatus new_s /* Public functions below */ +bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig) { + char *msg_sig = dbus_message_iter_get_signature(iter); + int result = strcmp(msg_sig, sig); + dbus_free(msg_sig); + return (result == 0); +} + void dispatch_dbus() { if (!should_dispatch || !conn) { return; diff --git a/swaybar/tray/sni.c b/swaybar/tray/sni.c index 7e09f414..401a0091 100644 --- a/swaybar/tray/sni.c +++ b/swaybar/tray/sni.c @@ -71,17 +71,13 @@ static void reply_icon(DBusPendingCall *pending, void *_data) { // Each if here checks the types above before recursing if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { - sway_log(L_ERROR, "Relpy type incorrect"); - sway_log(L_ERROR, "Should be \"v\", is \"%s\"", - dbus_message_iter_get_signature(&iter)); + sway_log(L_ERROR, "Icon relpy type incorrect"); goto bail; } dbus_message_iter_recurse(&iter, &variant); - if (strcmp("a(iiay)", dbus_message_iter_get_signature(&variant)) != 0) { - sway_log(L_ERROR, "Relpy type incorrect"); - sway_log(L_ERROR, "Should be \"a(iiay)\", is \"%s\"", - dbus_message_iter_get_signature(&variant)); + if (dbus_message_iter_check_signature(&variant, "a(iiay)")) { + sway_log(L_ERROR, "Icon relpy type incorrect"); goto bail; } @@ -237,18 +233,14 @@ static void reply_icon_name(DBusPendingCall *pending, void *_data) { dbus_message_iter_init(reply, &iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { - sway_log(L_ERROR, "Relpy type incorrect"); - sway_log(L_ERROR, "Should be \"v\", is \"%s\"", - dbus_message_iter_get_signature(&iter)); + sway_log(L_ERROR, "Icon name relpy type incorrect"); goto bail; } dbus_message_iter_recurse(&iter, &variant); if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_STRING) { - sway_log(L_ERROR, "Relpy type incorrect"); - sway_log(L_ERROR, "Should be \"s\", is \"%s\"", - dbus_message_iter_get_signature(&iter)); + sway_log(L_ERROR, "Icon name relpy type incorrect"); goto bail; } diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 924ff1a0..f1ecb429 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -131,7 +131,7 @@ static void get_obj_items_reply(DBusPendingCall *pending, void *_data) { goto bail; } dbus_message_iter_recurse(&iter, &variant); - if (strcmp(dbus_message_iter_get_signature(&variant), "a(os)") != 0) { + if (dbus_message_iter_check_signature(&iter, "a(os)")) { sway_log(L_ERROR, "Replyed with wrong type not a(os)"); goto bail; } |
