shared: add nm_dbus_error_is() helper

(cherry picked from commit ce36494c0a)
This commit is contained in:
Thomas Haller
2019-12-16 16:56:58 +01:00
parent 809d70ee64
commit 452f14216a
2 changed files with 36 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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__ */