From ec6f350f4406350b94f9fb28648b02d11421cf0e Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 27 Mar 2015 09:04:13 -0400 Subject: [PATCH] libnm-core: add _nm_dbus_error_has_name() Add a method for checking the D-Bus error name of an error. --- libnm-core/nm-core-internal.h | 2 ++ libnm-core/nm-dbus-utils.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 43021a8fd..f586f4b35 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -165,4 +165,6 @@ GVariant *_nm_dbus_proxy_call_sync (GDBusProxy *proxy, GCancellable *cancellable, GError **error); +gboolean _nm_dbus_error_has_name (GError *error, + const char *dbus_error_name); #endif diff --git a/libnm-core/nm-dbus-utils.c b/libnm-core/nm-dbus-utils.c index 14bd2d803..1f1e20ced 100644 --- a/libnm-core/nm-dbus-utils.c +++ b/libnm-core/nm-dbus-utils.c @@ -262,3 +262,29 @@ _nm_dbus_proxy_call_sync (GDBusProxy *proxy, typecheck_response (&ret, reply_type, error); return ret; } + +/** + * _nm_dbus_error_has_name: + * @error: (allow-none): a #GError, or %NULL + * @dbus_error_name: a D-Bus error name + * + * Checks if @error is set and corresponds to the D-Bus error @dbus_error_name. + * + * Returns: %TRUE or %FALSE + */ +gboolean +_nm_dbus_error_has_name (GError *error, + const char *dbus_error_name) +{ + gboolean has_name = FALSE; + + if (error && g_dbus_error_is_remote_error (error)) { + char *error_name; + + error_name = g_dbus_error_get_remote_error (error); + has_name = !g_strcmp0 (error_name, dbus_error_name); + g_free (error_name); + } + + return has_name; +}