diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2019-01-25 11:24:41 +0100 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2019-01-25 11:24:41 +0100 |
| commit | bbae86d3d2997a853ca0365e8eb7a3ca7489ee09 (patch) | |
| tree | 1f7fa49b47ab13aea3effbe839559d221f6323b4 /libnm-core/nm-dbus-utils.c | |
| parent | 404ebe62622150e77e311777dff8617eb974e834 (diff) | |
New upstream version 1.15.2
Diffstat (limited to 'libnm-core/nm-dbus-utils.c')
| -rw-r--r-- | libnm-core/nm-dbus-utils.c | 89 |
1 files changed, 63 insertions, 26 deletions
diff --git a/libnm-core/nm-dbus-utils.c b/libnm-core/nm-dbus-utils.c index 25af7c99..69f4bb2f 100644 --- a/libnm-core/nm-dbus-utils.c +++ b/libnm-core/nm-dbus-utils.c @@ -174,23 +174,35 @@ _nm_dbus_signal_connect_data (GDBusProxy *proxy, * Returns: the signal handler ID, as with _nm_signal_connect_data(). */ -static void -typecheck_response (GVariant **response, - const GVariantType *reply_type, - GError **error) +/** + * _nm_dbus_typecheck_response: + * @response: the #GVariant response to check. + * @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 - && reply_type - && !g_variant_is_of_type (*response, reply_type)) { - /* This is the same error code that g_dbus_connection_call() returns if - * @reply_type doesn't match. - */ - 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)); - g_clear_pointer (response, g_variant_unref); - } + g_return_val_if_fail (response, FALSE); + + if (!reply_type) + return TRUE; + if (g_variant_is_of_type (response, reply_type)) + return TRUE; + + /* This is the same error code that g_dbus_connection_call() returns if + * @reply_type doesn't match. + */ + 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, GError **error) { - GVariant *ret; + GVariant *variant; - ret = g_dbus_proxy_call_finish (proxy, res, error); - typecheck_response (&ret, reply_type, error); - return ret; + variant = g_dbus_proxy_call_finish (proxy, + res, + 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, GError **error) { - GVariant *ret; + GVariant *variant; + + variant = g_dbus_proxy_call_sync (proxy, + method_name, + parameters, + flags, + 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; - ret = g_dbus_proxy_call_sync (proxy, method_name, parameters, - flags, timeout_msec, - cancellable, error); - typecheck_response (&ret, reply_type, error); - return ret; + 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; } /** |