summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-16 16:56:58 +0100
committerThomas Haller <thaller@redhat.com>2019-12-16 18:16:12 +0100
commitce36494c0a483b51275b9818d58e1ad150e4efbc (patch)
tree8ad1b74f96d0334e75e6629ca5b1d8a74931f81d
parent4a3ca7115aabbbe9dfb649d116b06e3af73d4bdf (diff)
downloadNetworkManager-ce36494c0a483b51275b9818d58e1ad150e4efbc.tar.gz
shared: add nm_dbus_error_is() helper
-rw-r--r--shared/nm-glib-aux/nm-dbus-aux.c23
-rw-r--r--shared/nm-glib-aux/nm-dbus-aux.h13
2 files changed, 36 insertions, 0 deletions
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__ */