libnm-core: expose internal _nm_dbus_typecheck_response() helper
This commit is contained in:
@@ -305,6 +305,10 @@ void _nm_dbus_errors_init (void);
|
|||||||
|
|
||||||
extern gboolean _nm_utils_is_manager_process;
|
extern gboolean _nm_utils_is_manager_process;
|
||||||
|
|
||||||
|
gboolean _nm_dbus_typecheck_response (GVariant *response,
|
||||||
|
const GVariantType *reply_type,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
|
gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy,
|
||||||
const char *signal_name,
|
const char *signal_name,
|
||||||
const GVariantType *signature,
|
const GVariantType *signature,
|
||||||
@@ -329,6 +333,11 @@ GVariant *_nm_dbus_proxy_call_sync (GDBusProxy *proxy,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
GVariant * _nm_dbus_connection_call_finish (GDBusConnection *dbus_connection,
|
||||||
|
GAsyncResult *result,
|
||||||
|
const GVariantType *reply_type,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean _nm_dbus_error_has_name (GError *error,
|
gboolean _nm_dbus_error_has_name (GError *error,
|
||||||
const char *dbus_error_name);
|
const char *dbus_error_name);
|
||||||
|
|
||||||
|
@@ -174,23 +174,35 @@ _nm_dbus_signal_connect_data (GDBusProxy *proxy,
|
|||||||
* Returns: the signal handler ID, as with _nm_signal_connect_data().
|
* Returns: the signal handler ID, as with _nm_signal_connect_data().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
/**
|
||||||
typecheck_response (GVariant **response,
|
* _nm_dbus_typecheck_response:
|
||||||
const GVariantType *reply_type,
|
* @response: the #GVariant response to check.
|
||||||
GError **error)
|
* @reply_type: the expected reply type. It may be %NULL to perform no
|
||||||
|
* checking.
|
||||||
|
* @error: (allow-none): the error in case the @reply_type does not match.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE, if @response is of the expected @reply_type.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
_nm_dbus_typecheck_response (GVariant *response,
|
||||||
|
const GVariantType *reply_type,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
if ( *response
|
g_return_val_if_fail (response, FALSE);
|
||||||
&& reply_type
|
|
||||||
&& !g_variant_is_of_type (*response, reply_type)) {
|
if (!reply_type)
|
||||||
/* This is the same error code that g_dbus_connection_call() returns if
|
return TRUE;
|
||||||
* @reply_type doesn't match.
|
if (g_variant_is_of_type (response, reply_type))
|
||||||
*/
|
return TRUE;
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
||||||
_("Method returned type '%s', but expected '%s'"),
|
/* This is the same error code that g_dbus_connection_call() returns if
|
||||||
g_variant_get_type_string (*response),
|
* @reply_type doesn't match.
|
||||||
g_variant_type_peek_string (reply_type));
|
*/
|
||||||
g_clear_pointer (response, g_variant_unref);
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
||||||
}
|
_("Method returned type '%s', but expected '%s'"),
|
||||||
|
g_variant_get_type_string (response),
|
||||||
|
g_variant_type_peek_string (reply_type));
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,11 +227,15 @@ _nm_dbus_proxy_call_finish (GDBusProxy *proxy,
|
|||||||
const GVariantType *reply_type,
|
const GVariantType *reply_type,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GVariant *ret;
|
GVariant *variant;
|
||||||
|
|
||||||
ret = g_dbus_proxy_call_finish (proxy, res, error);
|
variant = g_dbus_proxy_call_finish (proxy,
|
||||||
typecheck_response (&ret, reply_type, error);
|
res,
|
||||||
return ret;
|
error);
|
||||||
|
if ( variant
|
||||||
|
&& !_nm_dbus_typecheck_response (variant, reply_type, error))
|
||||||
|
nm_clear_pointer (&variant, g_variant_unref);
|
||||||
|
return variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,13 +269,34 @@ _nm_dbus_proxy_call_sync (GDBusProxy *proxy,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GVariant *ret;
|
GVariant *variant;
|
||||||
|
|
||||||
ret = g_dbus_proxy_call_sync (proxy, method_name, parameters,
|
variant = g_dbus_proxy_call_sync (proxy,
|
||||||
flags, timeout_msec,
|
method_name,
|
||||||
cancellable, error);
|
parameters,
|
||||||
typecheck_response (&ret, reply_type, error);
|
flags,
|
||||||
return ret;
|
timeout_msec,
|
||||||
|
cancellable,
|
||||||
|
error);
|
||||||
|
if ( variant
|
||||||
|
&& !_nm_dbus_typecheck_response (variant, reply_type, error))
|
||||||
|
nm_clear_pointer (&variant, g_variant_unref);
|
||||||
|
return variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariant *
|
||||||
|
_nm_dbus_connection_call_finish (GDBusConnection *dbus_connection,
|
||||||
|
GAsyncResult *result,
|
||||||
|
const GVariantType *reply_type,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GVariant *variant;
|
||||||
|
|
||||||
|
variant = g_dbus_connection_call_finish (dbus_connection, result, error);
|
||||||
|
if ( variant
|
||||||
|
&& !_nm_dbus_typecheck_response (variant, reply_type, error))
|
||||||
|
nm_clear_pointer (&variant, g_variant_unref);
|
||||||
|
return variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user