From ce36494c0a483b51275b9818d58e1ad150e4efbc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 Dec 2019 16:56:58 +0100 Subject: [PATCH] shared: add nm_dbus_error_is() helper --- shared/nm-glib-aux/nm-dbus-aux.c | 23 +++++++++++++++++++++++ shared/nm-glib-aux/nm-dbus-aux.h | 13 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/shared/nm-glib-aux/nm-dbus-aux.c b/shared/nm-glib-aux/nm-dbus-aux.c index f55958b489..75b282bc14 100644 --- a/shared/nm-glib-aux/nm-dbus-aux.c +++ b/shared/nm-glib-aux/nm-dbus-aux.c @@ -341,3 +341,26 @@ nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source, { _call_finish_cb (source, result, user_data, FALSE, TRUE); } + +/*****************************************************************************/ + +gboolean +_nm_dbus_error_is (GError *error, ...) +{ + gs_free char *dbus_error = NULL; + const char *name; + va_list ap; + + dbus_error = g_dbus_error_get_remote_error (error); + if (!dbus_error) + return FALSE; + + va_start (ap, error); + while ((name = va_arg (ap, const char *))) { + if (nm_streq (dbus_error, name)) + return TRUE; + } + va_end (ap); + + return FALSE; +} diff --git a/shared/nm-glib-aux/nm-dbus-aux.h b/shared/nm-glib-aux/nm-dbus-aux.h index bf7731d22f..840e23c275 100644 --- a/shared/nm-glib-aux/nm-dbus-aux.h +++ b/shared/nm-glib-aux/nm-dbus-aux.h @@ -192,4 +192,17 @@ void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source /*****************************************************************************/ +gboolean _nm_dbus_error_is (GError *error, ...) G_GNUC_NULL_TERMINATED; + +#define nm_dbus_error_is(error, ...) \ + ({ \ + GError *const _error = (error); \ + \ + _error && _nm_dbus_error_is (_error, __VA_ARGS__, NULL); \ + }) + +#define NM_DBUS_ERROR_NAME_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod" + +/*****************************************************************************/ + #endif /* __NM_DBUS_AUX_H__ */