diff options
author | Dan Winship <danw@gnome.org> | 2014-07-17 09:09:47 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-07-22 17:35:11 -0400 |
commit | c8813ca1ce955c500e690d0c78ccd44dc29674f5 (patch) | |
tree | 064b16a01fa454ee9174defbb5a0274997723ad7 | |
parent | 58ab466553bae2a0c8168f6e8d569deac2b44cc4 (diff) | |
download | NetworkManager-danw/wip/libnm.tar.gz |
libnm: port to gdbus [WIP]danw/wip/libnm
86 files changed, 2854 insertions, 4102 deletions
diff --git a/.gitignore b/.gitignore index 31452e7aa3..cb084a9475 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ gtk-doc.make cscope.*out valgrind-*.log *-glue.h +*-generated.c +*-generated.h /libgsystem/ diff --git a/libnm-core/Makefile.am b/libnm-core/Makefile.am index 53805e27e2..785db1d7df 100644 --- a/libnm-core/Makefile.am +++ b/libnm-core/Makefile.am @@ -7,8 +7,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""libnm"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_LTLIBRARIES = libnm-core.la @@ -30,7 +29,6 @@ GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM libnm_core_la_LIBADD = \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ $(UUID_LIBS) if WITH_GNUTLS diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core index 0b1d11b582..f9f3f74711 100644 --- a/libnm-core/Makefile.libnm-core +++ b/libnm-core/Makefile.libnm-core @@ -77,6 +77,5 @@ libnm_core_sources = \ $(core)/nm-setting-wireless-security.c \ $(core)/nm-setting-wireless.c \ $(core)/nm-setting.c \ - $(core)/nm-utils.c \ - $(core)/nm-value-transforms.c + $(core)/nm-utils.c diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 2b52e7a340..9fdee460d6 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -22,11 +22,9 @@ #include <glib-object.h> #include <glib/gi18n.h> -#include <dbus/dbus-glib.h> #include <string.h> #include "nm-connection.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" #include "nm-setting-8021x.h" @@ -310,56 +308,62 @@ _get_type_setting (NMConnection *connection) } static gboolean -validate_permissions_type (GHashTable *hash, GError **error) +validate_permissions_type (GVariant *variant, GError **error) { - GHashTable *s_con; - GValue *permissions; + GVariant *s_con; + GVariant *permissions; + gboolean valid = TRUE; /* Ensure the connection::permissions item (if present) is the correct * type, otherwise the g_object_set() will throw a warning and ignore the * error, leaving us with no permissions. */ - s_con = g_hash_table_lookup (hash, NM_SETTING_CONNECTION_SETTING_NAME); - if (s_con) { - permissions = g_hash_table_lookup (s_con, NM_SETTING_CONNECTION_PERMISSIONS); - if (permissions) { - if ( !G_VALUE_HOLDS (permissions, G_TYPE_STRV) - && !G_VALUE_HOLDS (permissions, DBUS_TYPE_G_LIST_OF_STRING)) { - g_set_error_literal (error, - NM_SETTING_ERROR, - NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, - "Wrong permissions property type; should be a list of strings."); - return FALSE; - } + s_con = g_variant_lookup_value (variant, NM_SETTING_CONNECTION_SETTING_NAME, NM_VARIANT_TYPE_SETTING); + if (!s_con) + return TRUE; + + permissions = g_variant_lookup_value (s_con, NM_SETTING_CONNECTION_PERMISSIONS, NULL); + if (permissions) { + if (!g_variant_is_of_type (permissions, G_VARIANT_TYPE_STRING_ARRAY)) { + g_set_error_literal (error, + NM_SETTING_ERROR, + NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, + "Wrong permissions property type; should be a list of strings."); + valid = FALSE; } + g_variant_unref (permissions); } - return TRUE; + + g_variant_unref (s_con); + return valid; } static gboolean -hash_to_connection (NMConnection *connection, GHashTable *new, GError **error) +variant_to_connection (NMConnection *connection, GVariant *new, GError **error) { - GHashTableIter iter; + NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection); + GVariantIter iter; const char *setting_name; - GHashTable *setting_hash; + GVariant *setting_vardict; gboolean changed, valid; - NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (connection); if ((changed = g_hash_table_size (priv->settings) > 0)) g_hash_table_remove_all (priv->settings); - g_hash_table_iter_init (&iter, new); - while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) { + g_variant_iter_init (&iter, new); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting_vardict)) { GType type = nm_connection_lookup_setting_type (setting_name); if (type) { - NMSetting *setting = nm_setting_new_from_hash (type, setting_hash); + NMSetting *setting = nm_setting_new_from_variant (type, setting_vardict); if (setting) { _nm_connection_add_setting (connection, setting); changed = TRUE; } } + + g_variant_unref (setting_vardict); } valid = nm_connection_verify (connection, error); @@ -371,7 +375,7 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error) /** * nm_connection_replace_settings: * @connection: a #NMConnection - * @new_settings: (element-type utf8 GLib.HashTable): a #GHashTable of settings + * @new_settings: a #GVariant of type `a{sa{sv}}`, with the new settings * @error: location to store error, or %NULL * * Returns: %TRUE if the settings were valid and added to the connection, %FALSE @@ -379,18 +383,18 @@ hash_to_connection (NMConnection *connection, GHashTable *new, GError **error) **/ gboolean nm_connection_replace_settings (NMConnection *connection, - GHashTable *new_settings, + GVariant *new_settings, GError **error) { gboolean valid = FALSE; g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); - g_return_val_if_fail (new_settings != NULL, FALSE); + g_return_val_if_fail (g_variant_is_of_type (new_settings, NM_VARIANT_TYPE_CONNECTION), FALSE); if (error) g_return_val_if_fail (*error == NULL, FALSE); if (validate_permissions_type (new_settings, error)) - valid = hash_to_connection (connection, new_settings, error); + valid = variant_to_connection (connection, new_settings, error); return valid; } @@ -944,16 +948,16 @@ EXIT: * nm_connection_update_secrets: * @connection: the #NMConnection * @setting_name: the setting object name to which the secrets apply - * @secrets: (element-type utf8 GObject.Value): a #GHashTable mapping - * string:#GValue of setting property names and secrets of the given @setting_name + * @secrets: a #GVariant of secrets, in either "connection" format (`a{sa{sv}}`) + * or "setting" format (`a{sv}`) * @error: location to store error, or %NULL * - * Update the specified setting's secrets, given a hash table of secrets - * intended for that setting (deserialized from D-Bus for example). Will also - * extract the given setting's secrets hash if given a hash of hashes, as would - * be returned from nm_connection_to_hash(). If @setting_name is %NULL, expects - * a fully serialized #NMConnection as returned by nm_connection_to_hash() and - * will update all secrets from all settings contained in @secrets. + * Update the specified setting's secrets, given a dictionary of secrets + * intended for that setting (deserialized from D-Bus for example). @secrets + * can be either an `a{sv}` containing secrets only for @setting_name, or else + * an `a{sa{sv}}` containing @setting_name's secrets as one of its items. If + * @setting_name is %NULL, @secrets must be an `a{sa{sv}}`, and all secrets + * it contains will be updated in @connection. * * Returns: %TRUE if the secrets were successfully updated, %FALSE if the update * failed (tried to update secrets for a setting that doesn't exist, etc) @@ -961,38 +965,28 @@ EXIT: gboolean nm_connection_update_secrets (NMConnection *connection, const char *setting_name, - GHashTable *secrets, + GVariant *secrets, GError **error) { NMSetting *setting; gboolean success = TRUE, updated = FALSE; - GHashTable *setting_hash = NULL; - GHashTableIter iter; + GVariant *setting_dict = NULL; + GVariantIter iter; const char *key; - gboolean hashed_connection = FALSE; + gboolean hashed_connection; int success_detail; g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); - g_return_val_if_fail (secrets != NULL, FALSE); + g_return_val_if_fail ( g_variant_is_of_type (secrets, NM_VARIANT_TYPE_SETTING) + || g_variant_is_of_type (secrets, NM_VARIANT_TYPE_CONNECTION), FALSE); if (error) g_return_val_if_fail (*error == NULL, FALSE); /* Empty @secrets means success */ - if (g_hash_table_size (secrets) == 0) + if (g_variant_n_children (secrets) == 0) return TRUE; - /* For backwards compatibility, this function accepts either a hashed - * connection (GHashTable of GHashTables of GValues) or a single hashed - * setting (GHashTable of GValues). - */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL)) { - if (_nm_setting_lookup_setting_type (key) != G_TYPE_INVALID) { - /* @secrets looks like a hashed connection */ - hashed_connection = TRUE; - break; - } - } + hashed_connection = g_variant_is_of_type (secrets, NM_VARIANT_TYPE_CONNECTION); if (setting_name) { /* Update just one setting's secrets */ @@ -1006,9 +1000,9 @@ nm_connection_update_secrets (NMConnection *connection, } if (hashed_connection) { - setting_hash = g_hash_table_lookup (secrets, setting_name); - if (!setting_hash) { - /* The hashed connection that didn't contain any secrets for + setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING); + if (!setting_dict) { + /* The hashed connection didn't contain any secrets for * @setting_name; just return success. */ return TRUE; @@ -1017,10 +1011,12 @@ nm_connection_update_secrets (NMConnection *connection, g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection); success_detail = _nm_setting_update_secrets (setting, - setting_hash ? setting_hash : secrets, + setting_dict ? setting_dict : secrets, error); g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection); + g_clear_pointer (&setting_dict, g_variant_unref); + if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR) return FALSE; if (success_detail == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED) @@ -1035,8 +1031,8 @@ nm_connection_update_secrets (NMConnection *connection, } /* check first, whether all the settings exist... */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer) &key, NULL)) { + g_variant_iter_init (&iter, secrets); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &key, NULL)) { setting = nm_connection_get_setting_by_name (connection, key); if (!setting) { g_set_error_literal (error, @@ -1048,15 +1044,17 @@ nm_connection_update_secrets (NMConnection *connection, } /* Update each setting with any secrets from the hashed connection */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &setting_hash)) { + g_variant_iter_init (&iter, secrets); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &key, &setting_dict)) { /* Update the secrets for this setting */ setting = nm_connection_get_setting_by_name (connection, key); g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection); - success_detail = _nm_setting_update_secrets (setting, setting_hash, error); + success_detail = _nm_setting_update_secrets (setting, setting_dict, error); g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection); + g_variant_unref (setting_dict); + if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR) { success = FALSE; break; @@ -1196,50 +1194,49 @@ nm_connection_clear_secrets_with_flags (NMConnection *connection, } /** - * nm_connection_to_hash: + * nm_connection_to_variant: * @connection: the #NMConnection * @flags: hash flags, e.g. %NM_SETTING_HASH_FLAG_ALL * - * Converts the #NMConnection into a #GHashTable describing the connection, - * suitable for marshalling over D-Bus or serializing. The hash table mapping - * is string:#GHashTable with each element in the returned hash representing - * a #NMSetting object. The keys are setting object names, and the values - * are #GHashTables mapping string:GValue, each of which represents the - * properties of the #NMSetting object. - * - * Returns: (transfer full) (element-type utf8 GLib.HashTable): a new - * #GHashTable describing the connection, its settings, and each setting's - * properties. The caller owns the hash table and must unref the hash table - * with g_hash_table_unref() when it is no longer needed. + * Converts the #NMConnection into a #GVariant describing the connection, + * suitable for marshalling over D-Bus or serializing. The variant is an + * `a{sa{sv}}`, with each element in the outer dictionary representing an + * #NMSetting object, identified by name, and the inner dictionaries as + * with nm_setting_to_variant(). + * + * Returns: (transfer none): a new floating #GVariant describing the connection, + * its settings, and each setting's properties. **/ -GHashTable * -nm_connection_to_hash (NMConnection *connection, NMSettingHashFlags flags) +GVariant * +nm_connection_to_variant (NMConnection *connection, + NMSettingHashFlags flags) { NMConnectionPrivate *priv; + GVariantBuilder builder; GHashTableIter iter; gpointer key, data; - GHashTable *ret, *setting_hash; + GVariant *setting_var, *ret; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); - - ret = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, (GDestroyNotify) g_hash_table_destroy); - priv = NM_CONNECTION_GET_PRIVATE (connection); + g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION); + /* Add each setting's hash to the main hash */ g_hash_table_iter_init (&iter, priv->settings); while (g_hash_table_iter_next (&iter, &key, &data)) { NMSetting *setting = NM_SETTING (data); - setting_hash = nm_setting_to_hash (setting, flags); - if (setting_hash) - g_hash_table_insert (ret, g_strdup (nm_setting_get_name (setting)), setting_hash); + setting_var = nm_setting_to_variant (setting, flags); + if (setting_var) + g_variant_builder_add (&builder, "{s@a{sv}}", nm_setting_get_name (setting), setting_var); } + ret = g_variant_builder_end (&builder); + /* Don't send empty hashes */ - if (g_hash_table_size (ret) < 1) { - g_hash_table_destroy (ret); + if (g_variant_n_children (ret) == 0) { + g_variant_unref (ret); ret = NULL; } @@ -1434,30 +1431,29 @@ nm_connection_new (void) } /** - * nm_connection_new_from_hash: - * @hash: (element-type utf8 GLib.HashTable): the #GHashTable describing - * the connection + * nm_connection_new_from_variant: + * @hash: the #GVariant describing the connection * @error: on unsuccessful return, an error * - * Creates a new #NMConnection from a hash table describing the connection. See - * nm_connection_to_hash() for a description of the expected hash table. + * Creates a new #NMConnection from a #GVariant describing the connection. See + * nm_connection_to_hash() for a description of the expected variant. * * Returns: the new #NMConnection object, populated with settings created - * from the values in the hash table, or %NULL if the connection failed to + * from the values in the variant, or %NULL if the connection failed to * validate **/ NMConnection * -nm_connection_new_from_hash (GHashTable *hash, GError **error) +nm_connection_new_from_variant (GVariant *variant, GError **error) { NMConnection *connection; - g_return_val_if_fail (hash != NULL, NULL); + g_return_val_if_fail (g_variant_is_of_type (variant, NM_VARIANT_TYPE_CONNECTION), NULL); - if (!validate_permissions_type (hash, error)) + if (!validate_permissions_type (variant, error)) return NULL; connection = nm_connection_new (); - if (!hash_to_connection (connection, hash, error)) { + if (!variant_to_connection (connection, variant, error)) { g_object_unref (connection); return NULL; } diff --git a/libnm-core/nm-connection.h b/libnm-core/nm-connection.h index 4662a4fda0..a341356494 100644 --- a/libnm-core/nm-connection.h +++ b/libnm-core/nm-connection.h @@ -136,7 +136,19 @@ GType nm_connection_get_type (void); NMConnection *nm_connection_new (void); -NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error); +NMConnection *nm_connection_new_from_variant (GVariant *variant, GError **error); +GVariant *nm_connection_to_variant (NMConnection *connection, + NMSettingHashFlags flags); + +/** + * NM_VARIANT_TYPE_CONNECTION: + * + * #GVariantType for a dictionary mapping from setting names to + * %NM_VARIANT_TYPE_SETTING variants. This is used to represent an + * #NMConnection, and is the type taken by nm_connection_new_from_variant() and + * returned from nm_connection_to_variant(). + */ +#define NM_VARIANT_TYPE_CONNECTION (G_VARIANT_TYPE ("a{sa{sv}}")) NMConnection *nm_connection_duplicate (NMConnection *connection); @@ -155,7 +167,7 @@ NMSetting *nm_connection_get_setting_by_name (NMConnection *connection, const char *name); gboolean nm_connection_replace_settings (NMConnection *connection, - GHashTable *new_settings, + GVariant *new_settings, GError **error); gboolean nm_connection_replace_settings_from_connection (NMConnection *connection, @@ -188,7 +200,7 @@ void nm_connection_clear_secrets_with_flags (NMConnection *connection, gboolean nm_connection_update_secrets (NMConnection *connection, const char *setting_name, - GHashTable *secrets, + GVariant *secrets, GError **error); void nm_connection_set_path (NMConnection *connection, @@ -206,9 +218,6 @@ void nm_connection_for_each_setting_value (NMConnection *connection, NMSettingValueIterFn func, gpointer user_data); -GHashTable *nm_connection_to_hash (NMConnection *connection, - NMSettingHashFlags flags); - void nm_connection_dump (NMConnection *connection); GType nm_connection_lookup_setting_type (const char *name); diff --git a/libnm-core/nm-param-spec-dbus.c b/libnm-core/nm-param-spec-dbus.c index 035a147c4f..7ce6d71201 100644 --- a/libnm-core/nm-param-spec-dbus.c +++ b/libnm-core/nm-param-spec-dbus.c @@ -23,487 +23,77 @@ #include <string.h> #include <math.h> #include <netinet/in.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #include "nm-param-spec-dbus.h" #include "nm-glib-compat.h" -#include "nm-dbus-glib-types.h" /***********************************************************/ /* _gvalues_compare */ -static gint _gvalues_compare (const GValue *value1, const GValue *value2); - -static gboolean -type_is_fixed_size (GType type, gsize *tsize) -{ - switch (type) { - case G_TYPE_CHAR: - if (tsize) *tsize = sizeof (char); - return TRUE; - case G_TYPE_UCHAR: - if (tsize) *tsize = sizeof (guchar); - return TRUE; - case G_TYPE_BOOLEAN: - if (tsize) *tsize = sizeof (gboolean); - return TRUE; - case G_TYPE_LONG: - if (tsize) *tsize = sizeof (glong); - return TRUE; - case G_TYPE_ULONG: - if (tsize) *tsize = sizeof (gulong); - return TRUE; - case G_TYPE_INT: - if (tsize) *tsize = sizeof (gint); - return TRUE; - case G_TYPE_UINT: - if (tsize) *tsize = sizeof (guint); - return TRUE; - case G_TYPE_INT64: - if (tsize) *tsize = sizeof (gint64); - return TRUE; - case G_TYPE_UINT64: - if (tsize) *tsize = sizeof (guint64); - return TRUE; - case G_TYPE_FLOAT: - if (tsize) *tsize = sizeof (gfloat); - return TRUE; - case G_TYPE_DOUBLE: - if (tsize) *tsize = sizeof (gdouble); - return TRUE; - default: - return FALSE; - } -} - -#define FLOAT_FACTOR 0.00000001 - -static gint -_gvalues_compare_fixed (const GValue *value1, const GValue *value2) -{ - int ret = 0; - - switch (G_VALUE_TYPE (value1)) { - case G_TYPE_CHAR: { - gchar val1 = g_value_get_schar (value1); - gchar val2 = g_value_get_schar (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_UCHAR: { - guchar val1 = g_value_get_uchar (value1); - guchar val2 = g_value_get_uchar (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_BOOLEAN: { - gboolean val1 = g_value_get_boolean (value1); - gboolean val2 = g_value_get_boolean (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_LONG: { - glong val1 = g_value_get_long (value1); - glong val2 = g_value_get_long (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_ULONG: { - gulong val1 = g_value_get_ulong (value1); - gulong val2 = g_value_get_ulong (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_INT: { - gint val1 = g_value_get_int (value1); - gint val2 = g_value_get_int (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_UINT: { - guint val1 = g_value_get_uint (value1); - guint val2 = g_value_get_uint (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_INT64: { - gint64 val1 = g_value_get_int64 (value1); - gint64 val2 = g_value_get_int64 (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_UINT64: { - guint64 val1 = g_value_get_uint64 (value1); - guint64 val2 = g_value_get_uint64 (value2); - if (val1 != val2) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_FLOAT: { - gfloat val1 = g_value_get_float (value1); - gfloat val2 = g_value_get_float (value2); - /* Can't use == or != here due to inexactness of FP */ - if (fabsf (val1 - val2) > FLOAT_FACTOR) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - case G_TYPE_DOUBLE: { - gdouble val1 = g_value_get_double (value1); - gdouble val2 = g_value_get_double (value2); - if (fabs (val1 - val2) > FLOAT_FACTOR) - ret = val1 < val2 ? -1 : val1 > val2; - break; - } - default: - g_warning ("Unhandled fixed size type '%s'", G_VALUE_TYPE_NAME (value1)); - } - - return ret; -} +static gint _nm_variant_compare (GVariant *value1, GVariant *value2); static gint -_gvalues_compare_string (const GValue *value1, const GValue *value2) +_nm_variant_compare_collection (GVariant *value1, GVariant *value2) { - const char *str1 = g_value_get_string (value1); - const char *str2 = g_value_get_string (value2); + GVariant *child1, *child2; + int i, len1, len2; + int ret; - if (str1 == str2) - return 0; - - if (!str1) - return 1; - if (!str2) - return -1; + len1 = g_variant_n_children (value1); + len2 = g_variant_n_children (value2); - return strcmp (str1, str2); -} + if (len1 != len2) + return len1 < len2 ? -1 : len1 > len2; -static gint -_gvalues_compare_strv (const GValue *value1, const GValue *value2) -{ - char **strv1; - char **strv2; - gint ret; - guint i = 0; + for (i = 0; i < len1; i++) { + child1 = g_variant_get_child_value (value1, i); + child2 = g_variant_get_child_value (value2, i); - strv1 = (char **) g_value_get_boxed (value1); - strv2 = (char **) g_value_get_boxed (value2); + ret = _nm_variant_compare (child1, child2); + g_variant_unref (child1); + g_variant_unref (child2); - while (strv1[i] && strv2[i]) { - ret = strcmp (strv1[i], strv2[i]); if (ret) return ret; - i++; - } - - if (strv1[i] == NULL && strv2[i] == NULL) - return 0; - - if (strv1[i]) - return 1; - - return -1; -} - -static void -_gvalue_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - -static GValue * -_gvalue_dup (const GValue *value) -{ - GValue *dup; - - dup = g_slice_new0 (GValue); - g_value_init (dup, G_VALUE_TYPE (value)); - g_value_copy (value, dup); - - return dup; -} - -static void -iterate_collection (const GValue *value, gpointer user_data) -{ - GSList **list = (GSList **) user_data; - - *list = g_slist_prepend (*list, _gvalue_dup (value)); -} - -static gint -_gvalues_compare_collection (const GValue *value1, const GValue *value2) -{ - gint ret; - guint len1; - guint len2; - GType value_type = dbus_g_type_get_collection_specialization (G_VALUE_TYPE (value1)); - gsize element_size = 0; - - if (type_is_fixed_size (value_type, &element_size)) { - gpointer data1 = NULL; - gpointer data2 = NULL; - - dbus_g_type_collection_get_fixed ((GValue *) value1, &data1, &len1); - dbus_g_type_collection_get_fixed ((GValue *) value2, &data2, &len2); - - if (len1 != len2) - ret = len1 < len2 ? -1 : len1 > len2; - else - ret = memcmp (data1, data2, len1 * element_size); - } else { - GSList *list1 = NULL; - GSList *list2 = NULL; - - dbus_g_type_collection_value_iterate (value1, iterate_collection, &list1); - len1 = g_slist_length (list1); - dbus_g_type_collection_value_iterate (value2, iterate_collection, &list2); - len2 = g_slist_length (list2); - - if (len1 != len2) - ret = len1 < len2 ? -1 : len1 > len2; - else { - GSList *iter1; - GSList *iter2; - - for (iter1 = list1, iter2 = list2, ret = 0; - ret == 0 && iter1 && iter2; - iter1 = iter1->next, iter2 = iter2->next) - ret = _gvalues_compare ((GValue *) iter1->data, (GValue *) iter2->data); - } - - g_slist_free_full (list1, _gvalue_destroy); - g_slist_free_full (list2, _gvalue_destroy); } - return ret; -} - -static void -iterate_map (const GValue *key_val, - const GValue *value_val, - gpointer user_data) -{ - GHashTable **hash = (GHashTable **) user_data; - - g_hash_table_insert (*hash, g_value_dup_string (key_val), _gvalue_dup (value_val)); -} - -typedef struct { - GHashTable *hash2; - gint ret; -} CompareMapInfo; - -static void -compare_one_map_item (gpointer key, gpointer val, gpointer user_data) -{ - CompareMapInfo *info = (CompareMapInfo *) user_data; - GValue *value2; - - if (info->ret) - return; - - value2 = (GValue *) g_hash_table_lookup (info->hash2, key); - if (value2) - info->ret = _gvalues_compare ((GValue *) val, value2); - else - info->ret = 1; + return 0; } static gint -_gvalues_compare_map (const GValue *value1, const GValue *value2) +_nm_variant_compare_strdict (GVariant *value1, GVariant *value2) { - GHashTable *hash1 = NULL; - GHashTable *hash2 = NULL; - guint len1; - guint len2; - gint ret = 0; - - if (dbus_g_type_get_map_key_specialization (G_VALUE_TYPE (value1)) != G_TYPE_STRING) { - g_warning ("Can not compare maps with '%s' for keys", - g_type_name (dbus_g_type_get_map_key_specialization (G_VALUE_TYPE (value1)))); - return 0; - } + GVariantIter iter; + int len1, len2; + const char *key, *val1, *val2; + int ret; - hash1 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _gvalue_destroy); - dbus_g_type_map_value_iterate (value1, iterate_map, &hash1); - len1 = g_hash_table_size (hash1); - - hash2 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _gvalue_destroy); - dbus_g_type_map_value_iterate (value2, iterate_map, &hash2); - len2 = g_hash_table_size (hash2); + len1 = g_variant_n_children (value1); + len2 = g_variant_n_children (value2); if (len1 != len2) - ret = len1 < len2 ? -1 : len1 > len2; - else { - CompareMapInfo info; - - info.ret = 0; - info.hash2 = hash2; - g_hash_table_foreach (hash1, compare_one_map_item, &info); - ret = info.ret; - } + return len1 < len2 ? -1 : len1 > len2; - g_hash_table_destroy (hash1); - g_hash_table_destroy (hash2); - - return ret; -} + g_variant_iter_init (&iter, value1); + while (g_variant_iter_next (&iter, "{&s&s}", &key, &val1)) { + if (!g_variant_lookup (value2, key, "&s", &val2)) + return -1; -static gint -_gvalue_ip6_address_compare (const GValue *value1, const GValue *value2) -{ - GValueArray *values1, *values2; - GValue *tmp_val; - GByteArray *addr1, *addr2; - guint32 prefix1, prefix2; - GByteArray *gw1, *gw2; - gint ret = 0; - int i; - - /* IP6 addresses are GValueArrays (see nm-dbus-glib-types.h) */ - values1 = g_value_get_boxed (value1); - values2 = g_value_get_boxed (value2); - - /* Since they are NM IPv6 address structures, we expect both - * to contain two elements as specified in nm-dbus-glib-types.h. - */ - g_return_val_if_fail (values1->n_values == 3, 0); - g_return_val_if_fail (values2->n_values == 3, 0); - - /* First struct IPv6 address */ - tmp_val = g_value_array_get_nth (values1, 0); - addr1 = g_value_get_boxed (tmp_val); - /* First struct IPv6 prefix */ - tmp_val = g_value_array_get_nth (values1, 1); - prefix1 = g_value_get_uint (tmp_val); - /* First struct IPv6 gateway */ - tmp_val = g_value_array_get_nth (values1, 2); - gw1 = g_value_get_boxed (tmp_val); - - /* Second struct IPv6 address */ - tmp_val = g_value_array_get_nth (values2, 0); - addr2 = g_value_get_boxed (tmp_val); - /* Second struct IPv6 prefix */ - tmp_val = g_value_array_get_nth (values2, 1); - prefix2 = g_value_get_uint (tmp_val); - /* Second struct IPv6 gateway */ - tmp_val = g_value_array_get_nth (values2, 2); - gw2 = g_value_get_boxed (tmp_val); - - /* Compare IPv6 addresses */ - if (prefix1 != prefix2) - return prefix1 < prefix2 ? -1 : prefix1 > prefix2; - - if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)addr1->data, (struct in6_addr *)addr2->data)) { - for (i = 0; ret == 0 && i < addr1->len; i++) - ret = addr1->data[i] < addr2->data[i] ? -1 : addr1->data[i] > addr2->data[i]; - } - - if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *) gw1->data, (struct in6_addr *) gw2->data)) { - for (i = 0; ret == 0 && i < gw1->len; i++) - ret = gw1->data[i] < gw2->data[i] ? -1 : gw1->data[i] > gw2->data[i]; - } - - return ret; -} - -static gint -_gvalue_ip6_route_compare (const GValue *value1, const GValue *value2) -{ - GValueArray *values1, *values2; - GValue *tmp_val; - GByteArray *dest1, *dest2; - GByteArray *next_hop1, *next_hop2; - guint32 prefix1, prefix2; - guint32 metric1, metric2; - gint ret = 0; - int i; - - /* IP6 routes are GValueArrays (see nm-dbus-glib-types.h) */ - values1 = g_value_get_boxed (value1); - values2 = g_value_get_boxed (value2); - - /* Since they are NM IPv6 route structures, we expect both - * to contain 4 elements as specified in nm-dbus-glib-types.h. - */ - g_return_val_if_fail (values1->n_values == 4, 0); - g_return_val_if_fail (values2->n_values == 4, 0); - - /* First struct IPv6 route */ - tmp_val = g_value_array_get_nth (values1, 0); - dest1 = g_value_get_boxed (tmp_val); - tmp_val = g_value_array_get_nth (values1, 1); - prefix1 = g_value_get_uint (tmp_val); - tmp_val = g_value_array_get_nth (values1, 2); - next_hop1 = g_value_get_boxed (tmp_val); - tmp_val = g_value_array_get_nth (values1, 3); - metric1 = g_value_get_uint (tmp_val); - - /* Second struct IPv6 route */ - tmp_val = g_value_array_get_nth (values2, 0); - dest2 = g_value_get_boxed (tmp_val); - tmp_val = g_value_array_get_nth (values2, 1); - prefix2 = g_value_get_uint (tmp_val); - tmp_val = g_value_array_get_nth (values2, 2); - next_hop2 = g_value_get_boxed (tmp_val); - tmp_val = g_value_array_get_nth (values2, 3); - metric2 = g_value_get_uint (tmp_val); - - /* Compare the routes */ - if (prefix1 != prefix2) - return prefix1 < prefix2 ? -1 : prefix1 > prefix2; - - if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)dest1->data, (struct in6_addr *)dest2->data)) { - for (i = 0; ret == 0 && i < dest1->len; i++) - ret = dest1->data[i] < dest2->data[i] ? -1 : dest1->data[i] > dest2->data[i]; - } - - if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)next_hop1->data, (struct in6_addr *)next_hop2->data)) { - for (i = 0; ret == 0 && i < next_hop1->len; i++) - ret = next_hop1->data[i] < next_hop2->data[i] ? -1 : next_hop1->data[i] > next_hop2->data[i]; + ret = strcmp (val1, val2); + if (ret) + return ret; } - if (metric1 != metric2) - ret = metric1 < metric2 ? -1 : metric1 > metric2; - - return ret; + return 0; } static gint -_gvalues_compare_struct (const GValue *value1, const GValue *value2) -{ - /* value1 and value2 must contain the same type since - * _gvalues_compare() enforced that already. - */ - - if (G_VALUE_HOLDS (value1, DBUS_TYPE_G_IP6_ADDRESS)) { - return _gvalue_ip6_address_compare (value1, value2); - } else if (G_VALUE_HOLDS (value1, DBUS_TYPE_G_IP6_ROUTE)) { - return _gvalue_ip6_route_compare (value1, value2); - } else { - g_warning ("Don't know how to compare structures"); - return (value1 == value2); - } -} - -gint -_gvalues_compare (const GValue *value1, const GValue *value2) +_nm_variant_compare (GVariant *value1, GVariant *value2) { - GType type1; - GType type2; + const GVariantType *type1; + const GVariantType *type2; gint ret; if (value1 == value2) @@ -513,42 +103,22 @@ _gvalues_compare (const GValue *value1, const GValue *value2) if (!value2) return -1; - type1 = G_VALUE_TYPE (value1); - type2 = G_VALUE_TYPE (value2); + type1 = g_variant_get_type (value1); + type2 = g_variant_get_type (value2); - if (type1 != type2) + if (!g_variant_type_equal (type1, type2)) return type1 < type2 ? -1 : type1 > type2; - if (type_is_fixed_size (type1, NULL)) - ret = _gvalues_compare_fixed (value1, value2); - else if (type1 == G_TYPE_STRING) - ret = _gvalues_compare_string (value1, value2); - else if (G_VALUE_HOLDS_BOXED (value1)) { - gpointer p1 = g_value_get_boxed (value1); - gpointer p2 = g_value_get_boxed (value2); - - if (p1 == p2) - ret = 0; /* Exactly the same values */ - else if (!p1) - ret = 1; /* The comparision functions below don't handle NULLs */ - else if (!p2) - ret = -1; /* The comparision functions below don't handle NULLs */ - else if (type1 == G_TYPE_STRV) - ret = _gvalues_compare_strv (value1, value2); - else if (dbus_g_type_is_collection (type1)) - ret = _gvalues_compare_collection (value1, value2); - else if (dbus_g_type_is_map (type1)) - ret = _gvalues_compare_map (value1, value2); - else if (dbus_g_type_is_struct (type1)) - ret = _gvalues_compare_struct (value1, value2); - else if (type1 == G_TYPE_VALUE) - ret = _gvalues_compare ((GValue *) g_value_get_boxed (value1), (GValue *) g_value_get_boxed (value2)); - else { - g_warning ("Don't know how to compare boxed types '%s'", g_type_name (type1)); - ret = value1 == value2; - } - } else { - g_warning ("Don't know how to compare types '%s'", g_type_name (type1)); + if (g_variant_type_is_basic (type1)) + ret = g_variant_compare (value1, value2); + else if (g_variant_is_of_type (value1, G_VARIANT_TYPE ("a{ss}"))) + ret = _nm_variant_compare_strdict (value1, value2); + else if (g_variant_type_is_array (type1)) + ret = _nm_variant_compare_collection (value1, value2); + else if (g_variant_type_is_tuple (type1)) + ret = _nm_variant_compare_collection (value1, value2); + else { + g_warning ("Don't know how to compare variant type '%s'", (const char *) type1); ret = value1 == value2; } @@ -560,9 +130,9 @@ _gvalues_compare (const GValue *value1, const GValue *value2) struct _NMParamSpecDbus { GParamSpec parent; - GType dbus_type; - NMParamSpecDbusTransformFunc to_dbus; - NMParamSpecDbusTransformFunc from_dbus; + const GVariantType *dbus_type; + NMParamSpecDbusTransformToFunc to_dbus; + NMParamSpecDbusTransformFromFunc from_dbus; }; static void @@ -596,20 +166,17 @@ param_dbus_values_cmp (GParamSpec *pspec, const GValue *value2) { NMParamSpecDbus *pspec_dbus = NM_PARAM_SPEC_DBUS (pspec); - GValue dbus_value1 = { 0, }; - GValue dbus_value2 = { 0, }; + GVariant *dbus_value1; + GVariant *dbus_value2; int cmp; - g_value_init (&dbus_value1, pspec_dbus->dbus_type); - pspec_dbus->to_dbus (value1, &dbus_value1); - - g_value_init (&dbus_value2, pspec_dbus->dbus_type); - pspec_dbus->to_dbus (value2, &dbus_value2); + dbus_value1 = _nm_param_spec_dbus_value_to_dbus (pspec_dbus, value1); + dbus_value2 = _nm_param_spec_dbus_value_to_dbus (pspec_dbus, value2); - cmp = _gvalues_compare (&dbus_value1, &dbus_value2); + cmp = _nm_variant_compare (dbus_value1, dbus_value2); - g_value_unset (&dbus_value1); - g_value_unset (&dbus_value2); + g_variant_unref (dbus_value1); + g_variant_unref (dbus_value2); return cmp; } @@ -641,47 +208,48 @@ _nm_param_spec_dbus (const char *name, const char *nick, const char *blurb, GType property_type, - GType dbus_type, - NMParamSpecDbusTransformFunc to_dbus, - NMParamSpecDbusTransformFunc from_dbus, + const GVariantType *dbus_type, + NMParamSpecDbusTransformToFunc to_dbus, + NMParamSpecDbusTransformFromFunc from_dbus, GParamFlags flags) { NMParamSpecDbus *pspec; - g_return_val_if_fail (g_type_is_a (dbus_type, G_TYPE_BOXED), NULL); - pspec = g_param_spec_internal (NM_TYPE_PARAM_SPEC_DBUS, name, nick, blurb, flags); G_PARAM_SPEC (pspec)->value_type = property_type; pspec->dbus_type = dbus_type; - pspec->to_dbus = to_dbus ? to_dbus : g_value_copy; - pspec->from_dbus = from_dbus ? from_dbus : g_value_copy; + pspec->to_dbus = to_dbus; + pspec->from_dbus = from_dbus; return G_PARAM_SPEC (pspec); } void _nm_param_spec_dbus_value_from_dbus (NMParamSpecDbus *pspec_dbus, - const GValue *dbus_value, + GVariant *dbus_value, GValue *prop_value) { g_return_if_fail (NM_IS_PARAM_SPEC_DBUS (pspec_dbus)); - g_return_if_fail (G_VALUE_HOLDS (dbus_value, pspec_dbus->dbus_type)); + g_return_if_fail (g_variant_is_of_type (dbus_value, pspec_dbus->dbus_type)); g_return_if_fail (G_VALUE_HOLDS (prop_value, pspec_dbus->parent.value_type)); - pspec_dbus->from_dbus (dbus_value, prop_value); + if (pspec_dbus->from_dbus) + pspec_dbus->from_dbus (dbus_value, prop_value); + else + g_dbus_gvariant_to_gvalue (dbus_value, prop_value); } -void +GVariant * _nm_param_spec_dbus_value_to_dbus (NMParamSpecDbus *pspec_dbus, - const GValue *prop_value, - GValue *dbus_value) + const GValue *prop_value) { g_return_if_fail (NM_IS_PARAM_SPEC_DBUS (pspec_dbus)); g_return_if_fail (G_VALUE_HOLDS (prop_value, pspec_dbus->parent.value_type)); - g_return_if_fail (!G_IS_VALUE (dbus_value)); - g_value_init (dbus_value, pspec_dbus->dbus_type); - pspec_dbus->to_dbus (prop_value, dbus_value); + if (pspec_dbus->to_dbus) + return pspec_dbus->to_dbus (prop_value); + else + return g_dbus_gvalue_to_gvariant (prop_value, pspec_dbus->dbus_type); } diff --git a/libnm-core/nm-param-spec-dbus.h b/libnm-core/nm-param-spec-dbus.h index adf3f3fafe..3beea1dfcd 100644 --- a/libnm-core/nm-param-spec-dbus.h +++ b/libnm-core/nm-param-spec-dbus.h @@ -33,21 +33,21 @@ typedef struct _NMParamSpecDbus NMParamSpecDbus; GType _nm_param_spec_dbus_get_type (void); -typedef void (*NMParamSpecDbusTransformFunc) (const GValue *from, GValue *to); +typedef GVariant * (*NMParamSpecDbusTransformToFunc) (const GValue *from); +typedef void (*NMParamSpecDbusTransformFromFunc) (GVariant *from, GValue *to); GParamSpec *_nm_param_spec_dbus (const char *name, const char *nick, const char *blurb, GType property_type, - GType dbus_type, - NMParamSpecDbusTransformFunc to_dbus, - NMParamSpecDbusTransformFunc from_dbus, + const GVariantType *dbus_type, + NMParamSpecDbusTransformToFunc to_dbus, + NMParamSpecDbusTransformFromFunc from_dbus, GParamFlags flags); -void _nm_param_spec_dbus_value_to_dbus (NMParamSpecDbus *pspec_dbus, - const GValue *prop_value, - GValue *dbus_value); -void _nm_param_spec_dbus_value_from_dbus (NMParamSpecDbus *pspec_dbus, - const GValue *dbus_value, - GValue *prop_value); +GVariant *_nm_param_spec_dbus_value_to_dbus (NMParamSpecDbus *pspec_dbus, + const GValue *prop_value); +void _nm_param_spec_dbus_value_from_dbus (NMParamSpecDbus *pspec_dbus, + GVariant *dbus_value, + GValue *prop_value); #endif /* NM_PARAM_SPEC_DBUS_H */ diff --git a/libnm-core/nm-setting-8021x.c b/libnm-core/nm-setting-8021x.c index 1e99f9c172..a2ea491047 100644 --- a/libnm-core/nm-setting-8021x.c +++ b/libnm-core/nm-setting-8021x.c @@ -21,13 +21,11 @@ */ #include <string.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-8021x.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "crypto.h" #include "nm-utils-private.h" #include "nm-setting-private.h" @@ -3121,7 +3119,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_EAP, _nm_param_spec_dbus (NM_SETTING_802_1X_EAP, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -3187,7 +3185,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_CA_CERT, _nm_param_spec_dbus (NM_SETTING_802_1X_CA_CERT, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3232,7 +3230,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_ALTSUBJECT_MATCHES, _nm_param_spec_dbus (NM_SETTING_802_1X_ALTSUBJECT_MATCHES, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -3257,7 +3255,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_CLIENT_CERT, _nm_param_spec_dbus (NM_SETTING_802_1X_CLIENT_CERT, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3369,7 +3367,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PHASE2_CA_CERT, _nm_param_spec_dbus (NM_SETTING_802_1X_PHASE2_CA_CERT, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3416,7 +3414,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PHASE2_ALTSUBJECT_MATCHES, _nm_param_spec_dbus (NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -3444,7 +3442,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PHASE2_CLIENT_CERT, _nm_param_spec_dbus (NM_SETTING_802_1X_PHASE2_CLIENT_CERT, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3490,7 +3488,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PASSWORD_RAW, _nm_param_spec_dbus (NM_SETTING_802_1X_PASSWORD_RAW, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3544,7 +3542,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PRIVATE_KEY, _nm_param_spec_dbus (NM_SETTING_802_1X_PRIVATE_KEY, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -3611,7 +3609,7 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class) (object_class, PROP_PHASE2_PRIVATE_KEY, _nm_param_spec_dbus (NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-bluetooth.c b/libnm-core/nm-setting-bluetooth.c index 5af59a7167..bbe5eabe7f 100644 --- a/libnm-core/nm-setting-bluetooth.c +++ b/libnm-core/nm-setting-bluetooth.c @@ -25,7 +25,6 @@ #include <glib/gi18n.h> #include "nm-param-spec-dbus.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-bluetooth.h" #include "nm-setting-cdma.h" #include "nm-setting-gsm.h" @@ -276,7 +275,7 @@ nm_setting_bluetooth_class_init (NMSettingBluetoothClass *setting_class) (object_class, PROP_BDADDR, _nm_param_spec_dbus (NM_SETTING_BLUETOOTH_BDADDR, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index ae93907561..6e2733af86 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -24,14 +24,12 @@ #include <errno.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-bond.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" /** @@ -787,7 +785,7 @@ nm_setting_bond_class_init (NMSettingBondClass *setting_class) (object_class, PROP_OPTIONS, _nm_param_spec_dbus (NM_SETTING_BOND_OPTIONS, "", "", G_TYPE_HASH_TABLE, - DBUS_TYPE_G_MAP_OF_STRING, + G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index 243f4668dd..8efbf7779c 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -22,7 +22,6 @@ #include <string.h> #include <ctype.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-bridge-port.h" diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index 5d63c46614..ea8c732bc4 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -22,7 +22,6 @@ #include <string.h> #include <ctype.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-bridge.h" @@ -441,7 +440,7 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class) (object_class, PROP_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_BRIDGE_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index c5b9c4196e..36882251af 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -1181,7 +1181,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) (object_class, PROP_PERMISSIONS, _nm_param_spec_dbus (NM_SETTING_CONNECTION_PERMISSIONS, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -1297,7 +1297,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) (object_class, PROP_SECONDARIES, _nm_param_spec_dbus (NM_SETTING_CONNECTION_SECONDARIES, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | diff --git a/libnm-core/nm-setting-dcb.c b/libnm-core/nm-setting-dcb.c index 89f479f88f..f6c431302e 100644 --- a/libnm-core/nm-setting-dcb.c +++ b/libnm-core/nm-setting-dcb.c @@ -20,14 +20,12 @@ */ #include <string.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-dcb.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" #include "nm-core-enum-types.h" @@ -782,22 +780,23 @@ take_uint_array (GValue *v, uint *a, size_t len) #define TAKE_UINT_ARRAY(v, a) take_uint_array (v, a, G_N_ELEMENTS (a)) -static void -_nm_setting_dcb_uint_array_to_dbus (const GValue *prop_value, - GValue *dbus_value) +static GVariant * +_nm_setting_dcb_uint_array_to_dbus (const GValue *prop_value) { GArray *src = g_value_get_boxed (prop_value); - set_uint_array (dbus_value, (guint *) src->data, src->len); + return g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, src->data, src->len, sizeof (guint32)); } static void -_nm_setting_dcb_uint_array_from_dbus (const GValue *dbus_value, +_nm_setting_dcb_uint_array_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GArray *src = g_value_get_boxed (dbus_value); + gconstpointer array; + gsize length; - take_uint_array (prop_value, (guint *) src->data, src->len); + array = g_variant_get_fixed_array (dbus_value, &length, sizeof (guint32)); + take_uint_array (prop_value, (guint *) array, length); } static void @@ -1063,7 +1062,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PFC, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | @@ -1097,7 +1096,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PRIORITY_GROUP_ID, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_GROUP_ID, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | @@ -1117,7 +1116,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PRIORITY_GROUP_BANDWIDTH, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | @@ -1138,7 +1137,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PRIORITY_BANDWIDTH, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_BANDWIDTH, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | @@ -1157,7 +1156,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PRIORITY_STRICT, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | @@ -1176,7 +1175,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class) (object_class, PROP_PRIORITY_TRAFFIC_CLASS, _nm_param_spec_dbus (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, "", "", G_TYPE_ARRAY, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_setting_dcb_uint_array_to_dbus, _nm_setting_dcb_uint_array_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-infiniband.c b/libnm-core/nm-setting-infiniband.c index 0015816906..d028fd384c 100644 --- a/libnm-core/nm-setting-infiniband.c +++ b/libnm-core/nm-setting-infiniband.c @@ -20,7 +20,6 @@ */ #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-infiniband.h" @@ -397,7 +396,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *setting_class) (object_class, PROP_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_INFINIBAND_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index bd7e8f947f..554bc55c8f 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -21,13 +21,11 @@ */ #include <string.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-ip4-config.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-setting-private.h" #include "nm-utils-private.h" @@ -1289,7 +1287,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) (object_class, PROP_DNS, _nm_param_spec_dbus (NM_SETTING_IP4_CONFIG_DNS, "", "", G_TYPE_STRV, - DBUS_TYPE_G_UINT_ARRAY, + G_VARIANT_TYPE ("au"), _nm_utils_ip4_dns_to_dbus, _nm_utils_ip4_dns_from_dbus, G_PARAM_READWRITE | @@ -1308,7 +1306,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) (object_class, PROP_DNS_SEARCH, _nm_param_spec_dbus (NM_SETTING_IP4_CONFIG_DNS_SEARCH, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -1328,7 +1326,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) (object_class, PROP_ADDRESSES, _nm_param_spec_dbus (NM_SETTING_IP4_CONFIG_ADDRESSES, "", "", G_TYPE_PTR_ARRAY, - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, + G_VARIANT_TYPE ("aau"), _nm_utils_ip4_addresses_to_dbus, _nm_utils_ip4_addresses_from_dbus, G_PARAM_READWRITE | @@ -1344,7 +1342,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) (object_class, PROP_ADDRESS_LABELS, _nm_param_spec_dbus ("address-labels", "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | @@ -1364,7 +1362,7 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *setting_class) (object_class, PROP_ROUTES, _nm_param_spec_dbus (NM_SETTING_IP4_CONFIG_ROUTES, "", "", G_TYPE_PTR_ARRAY, - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, + G_VARIANT_TYPE ("aau"), _nm_utils_ip4_routes_to_dbus, _nm_utils_ip4_routes_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c index 688a3118d0..73395fb9ea 100644 --- a/libnm-core/nm-setting-ip6-config.c +++ b/libnm-core/nm-setting-ip6-config.c @@ -20,14 +20,12 @@ */ #include <string.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-ip6-config.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-setting-private.h" #include "nm-core-enum-types.h" @@ -1107,7 +1105,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) (object_class, PROP_DNS, _nm_param_spec_dbus (NM_SETTING_IP6_CONFIG_DNS, "", "", G_TYPE_STRV, - DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR, + G_VARIANT_TYPE ("aau"), _nm_utils_ip6_dns_to_dbus, _nm_utils_ip6_dns_from_dbus, G_PARAM_READWRITE | @@ -1126,7 +1124,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) (object_class, PROP_DNS_SEARCH, _nm_param_spec_dbus (NM_SETTING_IP6_CONFIG_DNS_SEARCH, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -1145,7 +1143,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) (object_class, PROP_ADDRESSES, _nm_param_spec_dbus (NM_SETTING_IP6_CONFIG_ADDRESSES, "", "", G_TYPE_PTR_ARRAY, - DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, + G_VARIANT_TYPE ("a(auuau)"), _nm_utils_ip6_addresses_to_dbus, _nm_utils_ip6_addresses_from_dbus, G_PARAM_READWRITE | @@ -1165,7 +1163,7 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *setting_class) (object_class, PROP_ROUTES, _nm_param_spec_dbus (NM_SETTING_IP6_CONFIG_ROUTES, "", "", G_TYPE_PTR_ARRAY, - DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE, + G_VARIANT_TYPE ("a(auuauu)"), _nm_utils_ip6_routes_to_dbus, _nm_utils_ip6_routes_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-olpc-mesh.c b/libnm-core/nm-setting-olpc-mesh.c index 4e16b87598..e4fb605f2e 100644 --- a/libnm-core/nm-setting-olpc-mesh.c +++ b/libnm-core/nm-setting-olpc-mesh.c @@ -21,13 +21,11 @@ */ #include <string.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-olpc-mesh.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-utils-private.h" #include "nm-setting-private.h" @@ -238,7 +236,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class) (object_class, PROP_SSID, _nm_param_spec_dbus (NM_SETTING_OLPC_MESH_SSID, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -270,7 +268,7 @@ nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class) (object_class, PROP_DHCP_ANYCAST_ADDRESS, _nm_param_spec_dbus (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 99590b9e14..d1c42d58c9 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -67,7 +67,7 @@ typedef enum NMSettingUpdateSecretResult { } NMSettingUpdateSecretResult; NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting, - GHashTable *secrets, + GVariant *secrets, GError **error); gboolean _nm_setting_clear_secrets (NMSetting *setting); gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting, diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index cb8d00c38f..2a0e244e06 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -21,7 +21,6 @@ #include <string.h> #include <ctype.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-team-port.h" diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 95b5d7ce5a..b29e637a57 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -20,13 +20,11 @@ #include <string.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-team.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" /** diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 2ed8903754..c7b613e10c 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -821,7 +821,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *setting_class) (object_class, PROP_INGRESS_PRIORITY_MAP, _nm_param_spec_dbus (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | @@ -838,7 +838,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *setting_class) (object_class, PROP_EGRESS_PRIORITY_MAP, _nm_param_spec_dbus (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index f056437da5..b2ba42914e 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -22,14 +22,12 @@ #include <string.h> #include <errno.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-vpn.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" /** @@ -453,19 +451,19 @@ update_secret_string (NMSetting *setting, static NMSettingUpdateSecretResult update_secret_hash (NMSetting *setting, - GHashTable *secrets, + GVariant *secrets, GError **error) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); - GHashTableIter iter; + GVariantIter iter; const char *name, *value; NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; g_return_val_if_fail (secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR); /* Make sure the items are valid */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { + g_variant_iter_init (&iter, secrets); + while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) { if (!name || !strlen (name)) { g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, @@ -482,8 +480,8 @@ update_secret_hash (NMSetting *setting, } /* Now add the items to the settings' secrets list */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { + g_variant_iter_init (&iter, secrets); + while (g_variant_iter_next (&iter, "{&s&s}", &name, &value)) { if (value == NULL) { g_warn_if_fail (value != NULL); continue; @@ -504,26 +502,26 @@ update_secret_hash (NMSetting *setting, } static int -update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error) +update_one_secret (NMSetting *setting, const char *key, GVariant *value, GError **error) { NMSettingUpdateSecretResult success = NM_SETTING_UPDATE_SECRET_ERROR; g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR); g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR); - if (G_VALUE_HOLDS_STRING (value)) { + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { /* Passing the string properties individually isn't correct, and won't * produce the correct result, but for some reason that's how it used * to be done. So even though it's not correct, keep the code around * for compatibility's sake. */ - success = update_secret_string (setting, key, g_value_get_string (value), error); - } else if (G_VALUE_HOLDS (value, G_TYPE_HASH_TABLE)) { + success = update_secret_string (setting, key, g_variant_get_string (value, NULL), error); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("a{ss}"))) { if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_SECRET, "Property %s not a secret property", key); } else - success = update_secret_hash (setting, g_value_get_boxed (value), error); + success = update_secret_hash (setting, value, error); } else g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, key); @@ -853,7 +851,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *setting_class) (object_class, PROP_DATA, _nm_param_spec_dbus (NM_SETTING_VPN_DATA, "", "", G_TYPE_HASH_TABLE, - DBUS_TYPE_G_MAP_OF_STRING, + G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus, G_PARAM_READWRITE | @@ -871,7 +869,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *setting_class) (object_class, PROP_SECRETS, _nm_param_spec_dbus (NM_SETTING_VPN_SECRETS, "", "", G_TYPE_HASH_TABLE, - DBUS_TYPE_G_MAP_OF_STRING, + G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-wimax.c b/libnm-core/nm-setting-wimax.c index 169b2d6a58..cd4befa374 100644 --- a/libnm-core/nm-setting-wimax.c +++ b/libnm-core/nm-setting-wimax.c @@ -22,7 +22,6 @@ #include <string.h> #include <net/ethernet.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-wimax.h" @@ -256,7 +255,7 @@ nm_setting_wimax_class_init (NMSettingWimaxClass *setting_class) (object_class, PROP_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_WIMAX_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 553bfd4ab5..0ad800e3b9 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -22,14 +22,12 @@ #include <string.h> #include <net/ethernet.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-wired.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" /** @@ -905,7 +903,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) (object_class, PROP_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_WIRED_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | @@ -922,7 +920,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) (object_class, PROP_CLONED_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | @@ -941,7 +939,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) (object_class, PROP_MAC_ADDRESS_BLACKLIST, _nm_param_spec_dbus (NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | @@ -977,7 +975,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) (object_class, PROP_S390_SUBCHANNELS, _nm_param_spec_dbus (NM_SETTING_WIRED_S390_SUBCHANNELS, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | @@ -1011,7 +1009,7 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) (object_class, PROP_S390_OPTIONS, _nm_param_spec_dbus (NM_SETTING_WIRED_S390_OPTIONS, "", "", G_TYPE_HASH_TABLE, - DBUS_TYPE_G_MAP_OF_STRING, + G_VARIANT_TYPE ("a{ss}"), _nm_utils_strdict_to_dbus, _nm_utils_strdict_from_dbus, G_PARAM_READWRITE | diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c index eb4030783a..5f40f9cf74 100644 --- a/libnm-core/nm-setting-wireless-security.c +++ b/libnm-core/nm-setting-wireless-security.c @@ -1393,7 +1393,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting (object_class, PROP_PROTO, _nm_param_spec_dbus (NM_SETTING_WIRELESS_SECURITY_PROTO, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -1410,7 +1410,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting (object_class, PROP_PAIRWISE, _nm_param_spec_dbus (NM_SETTING_WIRELESS_SECURITY_PAIRWISE, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -1427,7 +1427,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting (object_class, PROP_GROUP, _nm_param_spec_dbus (NM_SETTING_WIRELESS_SECURITY_GROUP, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index e1e427898b..e3d130a04e 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -22,13 +22,11 @@ #include <string.h> #include <net/ethernet.h> -#include <dbus/dbus-glib.h> #include <glib/gi18n.h> #include "nm-setting-wireless.h" #include "nm-param-spec-dbus.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-utils-private.h" #include "nm-setting-private.h" @@ -995,7 +993,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_SSID, _nm_param_spec_dbus (NM_SETTING_WIRELESS_SSID, "", "", G_TYPE_BYTES, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_bytes_to_dbus, _nm_utils_bytes_from_dbus, G_PARAM_READWRITE | @@ -1059,7 +1057,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_BSSID, _nm_param_spec_dbus (NM_SETTING_WIRELESS_BSSID, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | @@ -1109,7 +1107,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_WIRELESS_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | @@ -1125,7 +1123,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_CLONED_MAC_ADDRESS, _nm_param_spec_dbus (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "", "", G_TYPE_STRING, - DBUS_TYPE_G_UCHAR_ARRAY, + G_VARIANT_TYPE_BYTESTRING, _nm_utils_hwaddr_to_dbus, _nm_utils_hwaddr_from_dbus, G_PARAM_READWRITE | @@ -1142,7 +1140,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_MAC_ADDRESS_BLACKLIST, _nm_param_spec_dbus (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | @@ -1162,7 +1160,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class) (object_class, PROP_SEEN_BSSIDS, _nm_param_spec_dbus (NM_SETTING_WIRELESS_SEEN_BSSIDS, "", "", G_TYPE_STRV, - G_TYPE_STRV, + G_VARIANT_TYPE_STRING_ARRAY, NULL, NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 460dafac7d..ba606d5a47 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -22,6 +22,7 @@ #include <string.h> #include <glib/gi18n.h> +#include <gio/gio.h> #include "nm-setting.h" #include "nm-setting-private.h" @@ -104,7 +105,6 @@ _ensure_registered (void) #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif - _nm_value_transforms_register (); registered_settings = g_hash_table_new (g_str_hash, g_str_equal); registered_settings_by_type = g_hash_table_new (_nm_gtype_hash, _nm_gtype_equal); } @@ -272,31 +272,81 @@ _nm_setting_compare_priority (gconstpointer a, gconstpointer b) /*************************************************************/ +static const GVariantType * +variant_type_for_gtype (GType type) +{ + if (type == G_TYPE_BOOLEAN) + return G_VARIANT_TYPE_BOOLEAN; + else if (type == G_TYPE_UCHAR) + return G_VARIANT_TYPE_BYTE; + else if (type == G_TYPE_INT) + return G_VARIANT_TYPE_INT32; + else if (type == G_TYPE_UINT) + return G_VARIANT_TYPE_UINT32; + else if (type == G_TYPE_STRING) + return G_VARIANT_TYPE_STRING; + else if (type == G_TYPE_DOUBLE) + return G_VARIANT_TYPE_DOUBLE; + else + g_assert_not_reached (); +} + +static GVariant * +get_property_for_dbus (NMSetting *setting, GParamSpec *prop_spec, gboolean ignore_default) +{ + GValue prop_value = { 0, }; + GVariant *dbus_value; + + g_value_init (&prop_value, prop_spec->value_type); + g_object_get_property (G_OBJECT (setting), prop_spec->name, &prop_value); + + if (ignore_default && g_param_value_defaults (prop_spec, &prop_value)) { + g_value_unset (&prop_value); + return NULL; + } + + if (NM_IS_PARAM_SPEC_DBUS (prop_spec)) + dbus_value = _nm_param_spec_dbus_value_to_dbus (NM_PARAM_SPEC_DBUS (prop_spec), &prop_value); + else + dbus_value = g_dbus_gvalue_to_gvariant (&prop_value, variant_type_for_gtype (prop_value.g_type)); + + g_value_unset (&prop_value); + return dbus_value; +} + static void -destroy_gvalue (gpointer data) +set_property_from_dbus (NMSetting *setting, GParamSpec *prop_spec, GVariant *dbus_value) { - GValue *value = (GValue *) data; + GValue prop_value = { 0, }; + + g_value_init (&prop_value, prop_spec->value_type); + if (NM_IS_PARAM_SPEC_DBUS (prop_spec)) { + _nm_param_spec_dbus_value_from_dbus (NM_PARAM_SPEC_DBUS (prop_spec), + dbus_value, &prop_value); + } else + g_dbus_gvariant_to_gvalue (dbus_value, &prop_value); - g_value_unset (value); - g_slice_free (GValue, value); + g_object_set_property (G_OBJECT (setting), prop_spec->name, &prop_value); + g_value_unset (&prop_value); } /** - * nm_setting_to_hash: + * nm_setting_to_variant: * @setting: the #NMSetting * @flags: hash flags, e.g. %NM_SETTING_HASH_FLAG_ALL * - * Converts the #NMSetting into a #GHashTable mapping each setting property - * name to a GValue describing that property, suitable for marshalling over - * D-Bus or serializing. The mapping is string to GValue. + * Converts the #NMSetting into a #GVariant of type #NM_VARIANT_TYPE_SETTING + * (`a{sv}`), mapping each setting property name to a value describing that + * property, suitable for marshalling over D-Bus or serializing. * - * Returns: (transfer full) (element-type utf8 GObject.Value): a new #GHashTable - * describing the setting's properties + * Returns: (transfer none): a new floating #GVariant describing the setting's + * properties **/ -GHashTable * -nm_setting_to_hash (NMSetting *setting, NMSettingHashFlags flags) +GVariant * +nm_setting_to_variant (NMSetting *setting, NMSettingHashFlags flags) { - GHashTable *hash; + GVariantBuilder builder; + GVariant *dbus_value, *ret; GParamSpec **property_specs; guint n_property_specs; guint i; @@ -310,12 +360,10 @@ nm_setting_to_hash (NMSetting *setting, NMSettingHashFlags flags) return NULL; } - hash = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, destroy_gvalue); + g_variant_builder_init (&builder, NM_VARIANT_TYPE_SETTING); for (i = 0; i < n_property_specs; i++) { GParamSpec *prop_spec = property_specs[i]; - GValue *value; /* Don't serialize properties that can't be deserialized */ if ( !(prop_spec->flags & G_PARAM_WRITABLE) @@ -325,60 +373,46 @@ nm_setting_to_hash (NMSetting *setting, NMSettingHashFlags flags) if ( (flags & NM_SETTING_HASH_FLAG_NO_SECRETS) && (prop_spec->flags & NM_SETTING_PARAM_SECRET)) continue; + if ( (flags & NM_SETTING_HASH_FLAG_ONLY_SECRETS) && !(prop_spec->flags & NM_SETTING_PARAM_SECRET)) continue; - value = g_slice_new0 (GValue); - g_value_init (value, prop_spec->value_type); - g_object_get_property (G_OBJECT (setting), prop_spec->name, value); - - /* Don't serialize values with default values */ - if (g_param_value_defaults (prop_spec, value)) { - destroy_gvalue (value); - continue; - } - - if (NM_IS_PARAM_SPEC_DBUS (prop_spec)) { - GValue *dbus_value = g_slice_new0 (GValue); - - _nm_param_spec_dbus_value_to_dbus (NM_PARAM_SPEC_DBUS (prop_spec), - value, dbus_value); - destroy_gvalue (value); - value = dbus_value; - } - - g_hash_table_insert (hash, g_strdup (prop_spec->name), value); + dbus_value = get_property_for_dbus (setting, prop_spec, TRUE); + if (dbus_value) + g_variant_builder_add (&builder, "{sv}", prop_spec->name, dbus_value); } g_free (property_specs); + ret = g_variant_builder_end (&builder); + /* Don't return empty hashes, except for base types */ - if (g_hash_table_size (hash) < 1 && !_nm_setting_is_base_type (setting)) { - g_hash_table_destroy (hash); - hash = NULL; + if (g_variant_n_children (ret) < 1 && !_nm_setting_is_base_type (setting)) { + g_variant_unref (ret); + ret = NULL; } - return hash; + return ret; } /** - * nm_setting_new_from_hash: + * nm_setting_new_from_variant: * @setting_type: the #NMSetting type which the hash contains properties for - * @hash: (element-type utf8 GObject.Value): the #GHashTable containing a - * string to GValue mapping of properties that apply to the setting + * @variant: the #GVariant containing an %NM_VARIANT_TYPE_SETTING dictionary mapping + * property names to values * * Creates a new #NMSetting object and populates that object with the properties - * contained in the hash table, using each hash key as the property to set, - * and each hash value as the value to set that property to. Setting properties - * are strongly typed, thus the GValue type of the hash value must be correct. - * See the documentation on each #NMSetting object subclass for the correct - * property names and value types. + * contained in the vardict, using each key as the property to set, and each + * value as the value to set that property to. Setting properties are strongly + * typed, thus the #GVariantType of the dict value must be correct. See the + * documentation on each #NMSetting object subclass for the correct property + * names and value types. * * Returns: a new #NMSetting object populated with the properties from the * hash table, or %NULL on failure **/ NMSetting * -nm_setting_new_from_hash (GType setting_type, GHashTable *hash) +nm_setting_new_from_variant (GType setting_type, GVariant *variant) { NMSetting *setting; GObjectClass *class; @@ -387,7 +421,7 @@ nm_setting_new_from_hash (GType setting_type, GHashTable *hash) int i; g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (setting_type), NULL); - g_return_val_if_fail (hash != NULL, NULL); + g_return_val_if_fail (g_variant_is_of_type (variant, NM_VARIANT_TYPE_SETTING), NULL); class = g_type_class_ref (setting_type); property_specs = g_object_class_list_properties (class, &n_property_specs); @@ -403,26 +437,18 @@ nm_setting_new_from_hash (GType setting_type, GHashTable *hash) for (i = 0; i < n_property_specs; i++) { GParamSpec *prop_spec = property_specs[i]; - GValue *value; + GVariant *value; if ( !(prop_spec->flags & G_PARAM_WRITABLE) || (prop_spec->flags & G_PARAM_CONSTRUCT_ONLY)) continue; - value = g_hash_table_lookup (hash, prop_spec->name); + value = g_variant_lookup_value (variant, prop_spec->name, NULL); if (!value) continue; - if (NM_IS_PARAM_SPEC_DBUS (prop_spec)) { - GValue prop_value = { 0, }; - - g_value_init (&prop_value, prop_spec->value_type); - _nm_param_spec_dbus_value_from_dbus (NM_PARAM_SPEC_DBUS (prop_spec), - value, &prop_value); - g_object_set_property (G_OBJECT (setting), prop_spec->name, &prop_value); - g_value_unset (&prop_value); - } else - g_object_set_property (G_OBJECT (setting), prop_spec->name, value); + set_property_from_dbus (setting, prop_spec, value); + g_variant_unref (value); } return setting; @@ -977,10 +1003,9 @@ nm_setting_need_secrets (NMSetting *setting) } static int -update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error) +update_one_secret (NMSetting *setting, const char *key, GVariant *value, GError **error) { GParamSpec *prop_spec; - GValue transformed_value = G_VALUE_INIT; prop_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), key); if (!prop_spec) { @@ -995,76 +1020,67 @@ update_one_secret (NMSetting *setting, const char *key, GValue *value, GError ** if (!(prop_spec->flags & NM_SETTING_PARAM_SECRET)) return NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; - if (g_value_type_compatible (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (prop_spec))) { - if (G_VALUE_HOLDS_STRING (value) && G_IS_PARAM_SPEC_STRING (prop_spec)) { - /* String is expected to be a common case. Handle it specially and check whether - * the value is already set. Otherwise, we just reset the property and - * assume the value got modified. */ - char *v; - - g_object_get (G_OBJECT (setting), prop_spec->name, &v, NULL); - if (g_strcmp0 (v, g_value_get_string (value)) == 0) { - g_free (v); - return NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; - } + if ( g_variant_is_of_type (value, G_VARIANT_TYPE_STRING) + && G_IS_PARAM_SPEC_STRING (prop_spec)) { + /* String is expected to be a common case. Handle it specially and check + * whether the value is already set. Otherwise, we just reset the + * property and assume the value got modified. + */ + char *v; + + g_object_get (G_OBJECT (setting), prop_spec->name, &v, NULL); + if (g_strcmp0 (v, g_variant_get_string (value, NULL)) == 0) { g_free (v); + return NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; } - g_object_set_property (G_OBJECT (setting), prop_spec->name, value); - return NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED; + g_free (v); } - if (g_value_transform (value, &transformed_value)) { - g_object_set_property (G_OBJECT (setting), prop_spec->name, &transformed_value); - g_value_unset (&transformed_value); - return NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED; - } - g_set_error (error, - NM_SETTING_ERROR, - NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, - "%s", key); - return NM_SETTING_UPDATE_SECRET_ERROR; + + set_property_from_dbus (setting, prop_spec, value); + return NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED; } /** * nm_setting_update_secrets: * @setting: the #NMSetting - * @secrets: (element-type utf8 GObject.Value): a #GHashTable mapping - * string to #GValue of setting property names and secrets + * @secrets: a vardict mapping property names to secrets * @error: location to store error, or %NULL * - * Update the setting's secrets, given a hash table of secrets intended for that + * Update the setting's secrets, given a vardict of secrets intended for that * setting (deserialized from D-Bus for example). * * Returns: %TRUE if the secrets were successfully updated, %FALSE on failure to * update one or more of the secrets. **/ gboolean -nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets, GError **error) +nm_setting_update_secrets (NMSetting *setting, GVariant *secrets, GError **error) { return _nm_setting_update_secrets (setting, secrets, error) != NM_SETTING_UPDATE_SECRET_ERROR; } NMSettingUpdateSecretResult -_nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets, GError **error) +_nm_setting_update_secrets (NMSetting *setting, GVariant *secrets, GError **error) { - GHashTableIter iter; - gpointer key, data; + GVariantIter iter; + const char *secret_key; + GVariant *secret_value; GError *tmp_error = NULL; NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED; g_return_val_if_fail (NM_IS_SETTING (setting), NM_SETTING_UPDATE_SECRET_ERROR); - g_return_val_if_fail (secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR); + g_return_val_if_fail (g_variant_is_of_type (secrets, NM_VARIANT_TYPE_SETTING), NM_SETTING_UPDATE_SECRET_ERROR); if (error) g_return_val_if_fail (*error == NULL, NM_SETTING_UPDATE_SECRET_ERROR); - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, &key, &data)) { + g_variant_iter_init (&iter, secrets); + while (g_variant_iter_next (&iter, "{&sv}", &secret_key, &secret_value)) { int success; - const char *secret_key = (const char *) key; - GValue *secret_value = (GValue *) data; success = NM_SETTING_GET_CLASS (setting)->update_one_secret (setting, secret_key, secret_value, &tmp_error); g_assert (!((success == NM_SETTING_UPDATE_SECRET_ERROR) ^ (!!tmp_error))); + g_variant_unref (secret_value); + if (success == NM_SETTING_UPDATE_SECRET_ERROR) { g_propagate_error (error, tmp_error); return NM_SETTING_UPDATE_SECRET_ERROR; diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index 0eeab0c69c..4a9ac0b367 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -179,7 +179,7 @@ typedef struct { int (*update_one_secret) (NMSetting *setting, const char *key, - GValue *value, + GVariant *value, GError **error); gboolean (*get_secret_flags) (NMSetting *setting, @@ -236,7 +236,7 @@ GType nm_setting_get_type (void); * @NM_SETTING_HASH_FLAG_ONLY_SECRETS: only hash secrets * * These flags determine which properties are added to the resulting hash - * when calling nm_setting_to_hash(). + * when calling nm_setting_to_variant(). * **/ typedef enum { @@ -245,11 +245,20 @@ typedef enum { NM_SETTING_HASH_FLAG_ONLY_SECRETS = 0x00000002, } NMSettingHashFlags; -GHashTable *nm_setting_to_hash (NMSetting *setting, - NMSettingHashFlags flags); +GVariant *nm_setting_to_variant (NMSetting *setting, + NMSettingHashFlags flags); -NMSetting *nm_setting_new_from_hash (GType setting_type, - GHashTable *hash); +NMSetting *nm_setting_new_from_variant (GType setting_type, + GVariant *variant); + +/** + * NM_VARIANT_TYPE_SETTING: + * + * #GVariantType for a dictionary mapping from property names to values. This is + * an alias for %G_VARIANT_TYPE_VARDICT, and is the type of variant taken by + * nm_setting_new_from_variant() and returned from nm_setting_to_variant(). + */ +#define NM_VARIANT_TYPE_SETTING G_VARIANT_TYPE_VARDICT NMSetting *nm_setting_duplicate (NMSetting *setting); @@ -298,7 +307,7 @@ void nm_setting_clear_secrets_with_flags (NMSetting *setting, GPtrArray *nm_setting_need_secrets (NMSetting *setting); gboolean nm_setting_update_secrets (NMSetting *setting, - GHashTable *secrets, + GVariant *secrets, GError **error); gboolean nm_setting_get_secret_flags (NMSetting *setting, diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 3b7539c95e..f6e9f76581 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -32,47 +32,36 @@ gboolean _nm_utils_string_slist_validate (GSList *list, gboolean _nm_utils_gvalue_array_validate (GValueArray *elements, guint n_expected, ...); -void _nm_value_transforms_register (void); - -void _nm_utils_hwaddr_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_hwaddr_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_hwaddr_to_dbus (const GValue *prop_value); +void _nm_utils_hwaddr_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_strdict_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_strdict_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_strdict_to_dbus (const GValue *prop_value); +void _nm_utils_strdict_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_bytes_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_bytes_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_bytes_to_dbus (const GValue *prop_value); +void _nm_utils_bytes_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip4_dns_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip4_dns_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip4_dns_to_dbus (const GValue *prop_value); +void _nm_utils_ip4_dns_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip4_addresses_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip4_addresses_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip4_addresses_to_dbus (const GValue *prop_value); +void _nm_utils_ip4_addresses_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip4_routes_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip4_routes_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip4_routes_to_dbus (const GValue *prop_value); +void _nm_utils_ip4_routes_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip6_dns_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip6_dns_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip6_dns_to_dbus (const GValue *prop_value); +void _nm_utils_ip6_dns_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip6_addresses_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip6_addresses_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip6_addresses_to_dbus (const GValue *prop_value); +void _nm_utils_ip6_addresses_from_dbus (GVariant *dbus_value, GValue *prop_value); -void _nm_utils_ip6_routes_to_dbus (const GValue *prop_value, - GValue *dbus_value); -void _nm_utils_ip6_routes_from_dbus (const GValue *dbus_value, +GVariant * _nm_utils_ip6_routes_to_dbus (const GValue *prop_value); +void _nm_utils_ip6_routes_from_dbus (GVariant *dbus_value, GValue *prop_value); GSList * _nm_utils_strv_to_slist (char **strv); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 7e0e52815e..e991ce0b68 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -29,7 +29,6 @@ #include "nm-utils.h" #include "nm-utils-private.h" #include "nm-glib-compat.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-private.h" #include "crypto.h" @@ -221,8 +220,6 @@ nm_utils_init (GError **error) if (!crypto_init (error)) return FALSE; - - _nm_value_transforms_register (); } return TRUE; } @@ -522,46 +519,72 @@ done: return valid; } -void -_nm_utils_strdict_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_strdict_to_dbus (const GValue *prop_value) { - g_value_set_boxed (dbus_value, g_value_get_boxed (prop_value)); + GHashTable *hash; + GHashTableIter iter; + gpointer key, value; + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); + hash = g_value_get_boxed (prop_value); + if (hash) { + g_hash_table_iter_init (&iter, hash); + while (g_hash_table_iter_next (&iter, &key, &value)) + g_variant_builder_add (&builder, "{ss}", key, value); + } + + return g_variant_builder_end (&builder); } void -_nm_utils_strdict_from_dbus (const GValue *dbus_value, +_nm_utils_strdict_from_dbus (GVariant *dbus_value, GValue *prop_value) { - g_value_set_boxed (prop_value, g_value_get_boxed (dbus_value)); + GVariantIter iter; + const char *key, *value; + GHashTable *hash; + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + g_variant_iter_init (&iter, g_value_get_variant (prop_value)); + while (g_variant_iter_next (&iter, "{&s&s}", &key, &value)) + g_hash_table_insert (hash, g_strdup (key), g_strdup (value)); + + g_value_take_boxed (prop_value, hash); } -void -_nm_utils_bytes_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_bytes_to_dbus (const GValue *prop_value) { GBytes *bytes = g_value_get_boxed (prop_value); - GByteArray *ba = NULL; if (bytes) { - ba = g_byte_array_new (); - g_byte_array_append (ba, - g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes)); + return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), + 1); + } else { + return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + NULL, 0, + 1); } - - g_value_take_boxed (dbus_value, ba); } void -_nm_utils_bytes_from_dbus (const GValue *dbus_value, +_nm_utils_bytes_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GByteArray *ba = g_value_dup_boxed (dbus_value); - GBytes *bytes = NULL; + GBytes *bytes; - if (ba) - bytes = g_byte_array_free_to_bytes (ba); + if (g_variant_n_children (dbus_value)) { + gconstpointer data; + gsize length; + + data = g_variant_get_fixed_array (dbus_value, &length, 1); + bytes = g_bytes_new (data, length); + } else + bytes = NULL; g_value_take_boxed (prop_value, bytes); } @@ -927,357 +950,265 @@ nm_utils_wpa_psk_valid (const char *psk) return TRUE; } -void -_nm_utils_ip4_dns_to_dbus (const GValue *prop_value, - GValue *dbus_value) -{ - char **dns; - int i; - GArray *array; - - dns = g_value_get_boxed (prop_value); - array = g_array_new (FALSE, FALSE, sizeof (guint32)); - - if (dns) { - for (i = 0; dns[i]; i++) { - guint32 ip = 0; - - inet_pton (AF_INET, dns[i], &ip); - g_array_append_val (array, ip); - } - } - - g_value_take_boxed (dbus_value, array); -} - -void -_nm_utils_ip4_dns_from_dbus (const GValue *dbus_value, - GValue *prop_value) +/** + * nm_utils_ip4_dns_from_variant: (skip) + * @variant: a #GVariant + * + * Converts a #GVariant containing an "au" of IP4 DNS into an array of + * IP address strings. + * + * Returns: a %NULL-terminated array of IP4 address strings. + */ +char ** +nm_utils_ip4_dns_from_variant (GVariant *variant) { - GArray *array; + const guint32 *array; + gsize length; GPtrArray *dns; int i; - array = g_value_get_boxed (dbus_value); + array = g_variant_get_fixed_array (variant, &length, sizeof (guint32)); dns = g_ptr_array_new (); - if (array) { - for (i = 0; i < array->len; i++) { - guint32 ip = g_array_index (array, guint32, i); - const char *str; + for (i = 0; i < length; i++) { + guint32 ip = array[i]; + const char *str; - str = nm_utils_inet4_ntop (ip, NULL); - g_ptr_array_add (dns, g_strdup (str)); - } + str = nm_utils_inet4_ntop (ip, NULL); + g_ptr_array_add (dns, g_strdup (str)); } g_ptr_array_add (dns, NULL); - g_value_take_boxed (prop_value, g_ptr_array_free (dns, FALSE)); -} - -void -_nm_utils_ip4_addresses_to_dbus (const GValue *prop_value, - GValue *dbus_value) -{ - GPtrArray *addresses, *dbus_addresses; - int i; - - addresses = g_value_get_boxed (prop_value); - dbus_addresses = g_ptr_array_new (); - - if (addresses) { - for (i = 0; i < addresses->len; i++) { - NMIP4Address *addr = addresses->pdata[i]; - GArray *array; - guint32 tmp; - - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); - - tmp = nm_ip4_address_get_address (addr); - g_array_append_val (array, tmp); - - tmp = nm_ip4_address_get_prefix (addr); - g_array_append_val (array, tmp); - - tmp = nm_ip4_address_get_gateway (addr); - g_array_append_val (array, tmp); - - g_ptr_array_add (dbus_addresses, array); - } - } - - g_value_take_boxed (dbus_value, dbus_addresses); -} - -void -_nm_utils_ip4_addresses_from_dbus (const GValue *dbus_value, - GValue *prop_value) -{ - GPtrArray *dbus_addresses; - GPtrArray *addresses; - int i; - - dbus_addresses = g_value_get_boxed (dbus_value); - addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref); - - if (dbus_addresses) { - for (i = 0; i < dbus_addresses->len; i++) { - GArray *array = dbus_addresses->pdata[i]; - NMIP4Address *addr; - - if (array->len < 3) { - g_warning ("Ignoring invalid IP4 address"); - continue; - } - - addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, g_array_index (array, guint32, 0)); - nm_ip4_address_set_prefix (addr, g_array_index (array, guint32, 1)); - nm_ip4_address_set_gateway (addr, g_array_index (array, guint32, 2)); - - g_ptr_array_add (addresses, addr); - } - } - - g_value_take_boxed (prop_value, addresses); -} - -void -_nm_utils_ip4_routes_to_dbus (const GValue *prop_value, - GValue *dbus_value) -{ - GPtrArray *routes, *dbus_routes; - int i; - - routes = g_value_get_boxed (prop_value); - dbus_routes = g_ptr_array_new (); - - if (routes) { - for (i = 0; i < routes->len; i++) { - NMIP4Route *route = routes->pdata[i]; - GArray *array; - guint32 tmp; - - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); - - tmp = nm_ip4_route_get_dest (route); - g_array_append_val (array, tmp); - - tmp = nm_ip4_route_get_prefix (route); - g_array_append_val (array, tmp); - - tmp = nm_ip4_route_get_next_hop (route); - g_array_append_val (array, tmp); - - tmp = nm_ip4_route_get_metric (route); - g_array_append_val (array, tmp); - - g_ptr_array_add (dbus_routes, array); - } - } - - g_value_take_boxed (dbus_value, dbus_routes); + return (char **) g_ptr_array_free (dns, FALSE); } -void -_nm_utils_ip4_routes_from_dbus (const GValue *dbus_value, - GValue *prop_value) +/** + * nm_utils_ip4_dns_to_variant: (skip) + * @dns: a %NULL-termianted array of IP address strings + * + * Utility function to convert an array of IPv4 address strings into an "au" + * variant representing each server's IPv4 addresses in network byte order. + */ +GVariant * +nm_utils_ip4_dns_to_variant (char **dns) { - GPtrArray *dbus_routes, *routes; + GVariantBuilder builder; int i; - dbus_routes = g_value_get_boxed (dbus_value); - routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref); - - if (dbus_routes) { - for (i = 0; i < dbus_routes->len; i++) { - GArray *array = dbus_routes->pdata[i]; - NMIP4Route *route; - - if (array->len < 4) { - g_warning ("Ignoring invalid IP4 route"); - continue; - } + g_variant_builder_init (&builder, G_VARIANT_TYPE ("au")); - route = nm_ip4_route_new (); - nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0)); - nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1)); - nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2)); - nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3)); + if (dns) { + for (i = 0; dns[i]; i++) { + guint32 ip = 0; - g_ptr_array_add (routes, route); + inet_pton (AF_INET, dns[i], &ip); + g_variant_builder_add (&builder, "u", ip); } } - g_value_take_boxed (prop_value, routes); + return g_variant_builder_end (&builder); } /** - * nm_utils_ip4_addresses_from_gvalue: - * @value: #GValue containing a #GPtrArray of #GArrays of #guint32s + * nm_utils_ip4_addresses_from_variant: + * @variant: #GVariant containing an "a(uuu)" * - * Utility function to convert a #GPtrArray of #GArrays of #guint32s representing - * a list of NetworkManager IPv4 addresses (which is a tuple of address, gateway, - * and prefix) into a #GSList of #NMIP4Address objects. The specific format of - * this serialization is not guaranteed to be stable and the #GArray may be - * extended in the future. + * Utility function to convert an "a(uuu)" (array of tuples of address, prefix, + * and gateway) into a #GPtrArray of #NMIP4Address objects. * - * Returns: (transfer full) (element-type NMIP4Address): a newly allocated #GSList of #NMIP4Address objects + * Returns: (transfer full) (element-type NMIP4Address): an array of + * #NMIP4Address objects **/ -GSList * -nm_utils_ip4_addresses_from_gvalue (const GValue *value) +GPtrArray * +nm_utils_ip4_addresses_from_variant (GVariant *variant) { + GVariantIter iter; + GVariant *addr_var; GPtrArray *addresses; - int i; - GSList *list = NULL; - addresses = (GPtrArray *) g_value_get_boxed (value); - for (i = 0; addresses && (i < addresses->len); i++) { - GArray *array = (GArray *) g_ptr_array_index (addresses, i); + g_variant_iter_init (&iter, variant); + addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref); + + while (g_variant_iter_next (&iter, "au", &addr_var)) { + const guint32 *addr_array; NMIP4Address *addr; - if (array->len < 3) { + if (g_variant_n_children (addr_var) != 3) { g_warning ("Ignoring invalid IP4 address"); + g_variant_unref (addr_var); continue; } + addr_array = g_variant_get_fixed_array (addr_var, NULL, sizeof (guint32)); addr = nm_ip4_address_new (); - nm_ip4_address_set_address (addr, g_array_index (array, guint32, 0)); - nm_ip4_address_set_prefix (addr, g_array_index (array, guint32, 1)); - nm_ip4_address_set_gateway (addr, g_array_index (array, guint32, 2)); - list = g_slist_prepend (list, addr); + nm_ip4_address_set_address (addr, addr_array[0]); + nm_ip4_address_set_prefix (addr, addr_array[1]); + nm_ip4_address_set_gateway (addr, addr_array[2]); + + g_ptr_array_add (addresses, addr); + g_variant_unref (addr_var); } - return g_slist_reverse (list); + return addresses; } /** - * nm_utils_ip4_addresses_to_gvalue: - * @list: (element-type NMIP4Address): a list of #NMIP4Address objects - * @value: a pointer to a #GValue into which to place the converted addresses, - * which should be unset by the caller (when no longer needed) with - * g_value_unset(). - * - * Utility function to convert a #GSList of #NMIP4Address objects into a - * #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4 - * addresses (which is a tuple of address, gateway, and prefix). The specific - * format of this serialization is not guaranteed to be stable and may be - * extended in the future. + * nm_utils_ip4_addresses_to_variant: + * @addresses: (element-type NMIP4Address): an array of #NMIP4Address objects + * + * Utility function to convert a #GPtrArray of #NMIP4Address objects into an + * "a(uuu)" variant representing a list of NetworkManager IPv4 addresses (which + * is a tuple of address, prefix, and gateway). + * + * Return value: (transfer none): a new floating #GVariant containing the + * addresses **/ -void -nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value) +GVariant * +nm_utils_ip4_addresses_to_variant (GPtrArray *addresses) { - GPtrArray *addresses; - GSList *iter; - - addresses = g_ptr_array_new (); - - for (iter = list; iter; iter = iter->next) { - NMIP4Address *addr = (NMIP4Address *) iter->data; - GArray *array; - guint32 tmp; - - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); + GVariantBuilder builder; + int i; - tmp = nm_ip4_address_get_address (addr); - g_array_append_val (array, tmp); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aau")); - tmp = nm_ip4_address_get_prefix (addr); - g_array_append_val (array, tmp); + if (addresses) { + for (i = 0; i < addresses->len; i++) { + NMIP4Address *addr = addresses->pdata[i]; + guint32 array[3]; - tmp = nm_ip4_address_get_gateway (addr); - g_array_append_val (array, tmp); + array[0] = nm_ip4_address_get_address (addr); + array[1] = nm_ip4_address_get_prefix (addr); + array[2] = nm_ip4_address_get_gateway (addr); - g_ptr_array_add (addresses, array); + g_variant_builder_add (&builder, "au", + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + array, 3, sizeof (guint32))); + } } - g_value_take_boxed (value, addresses); + return g_variant_builder_end (&builder); } /** - * nm_utils_ip4_routes_from_gvalue: - * @value: #GValue containing a #GPtrArray of #GArrays of #guint32s + * nm_utils_ip4_routes_from_variant: + * @variant: #GVariant containing an "a(uuuu)" * - * Utility function to convert a #GPtrArray of #GArrays of #guint32s representing - * a list of NetworkManager IPv4 routes (which is a tuple of route, next hop, - * prefix, and metric) into a #GSList of #NMIP4Route objects. The specific - * format of this serialization is not guaranteed to be stable and may be - * extended in the future. + * Utility function to convert an "a(uuuu)" representing a list of NetworkManager + * IPv4 routes (which is a tuple of destination, prefix, next hop, and metric) into a + * #GPtrArray of #NMIP4Route objects. * - * Returns: (transfer full) (element-type NMIP4Route): a newly allocated #GSList of #NMIP4Route objects + * Returns: (transfer full) (element-type NMIP4Route): an array of #NMIP4Route + * objects **/ -GSList * -nm_utils_ip4_routes_from_gvalue (const GValue *value) +GPtrArray * +nm_utils_ip4_routes_from_variant (GVariant *variant) { + GVariantIter iter; + GVariant *route_var; GPtrArray *routes; - int i; - GSList *list = NULL; - routes = (GPtrArray *) g_value_get_boxed (value); - for (i = 0; routes && (i < routes->len); i++) { - GArray *array = (GArray *) g_ptr_array_index (routes, i); + g_variant_iter_init (&iter, variant); + routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref); + + while (g_variant_iter_next (&iter, "au", &route_var)) { + const guint32 *route_array; NMIP4Route *route; - if (array->len < 4) { + if (g_variant_n_children (route_var) != 4) { g_warning ("Ignoring invalid IP4 route"); + g_variant_unref (route_var); continue; } + route_array = g_variant_get_fixed_array (route_var, NULL, sizeof (guint32)); route = nm_ip4_route_new (); - nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0)); - nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1)); - nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2)); - nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3)); - list = g_slist_prepend (list, route); + nm_ip4_route_set_dest (route, route_array[0]); + nm_ip4_route_set_prefix (route, route_array[1]); + nm_ip4_route_set_next_hop (route, route_array[2]); + nm_ip4_route_set_metric (route, route_array[3]); + + g_ptr_array_add (routes, route); + g_variant_unref (route_var); } - return g_slist_reverse (list); + return routes; } /** - * nm_utils_ip4_routes_to_gvalue: - * @list: (element-type NMIP4Route): a list of #NMIP4Route objects - * @value: a pointer to a #GValue into which to place the converted routes, - * which should be unset by the caller (when no longer needed) with - * g_value_unset(). - * - * Utility function to convert a #GSList of #NMIP4Route objects into a - * #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4 - * routes (which is a tuple of route, next hop, prefix, and metric). The - * specific format of this serialization is not guaranteed to be stable and may - * be extended in the future. + * nm_utils_ip4_routes_to_variant: + * @routes: (element-type NMIP4Route): an array of #NMIP4Route objects + * + * Utility function to convert an array of #NMIP4Route objects into an + * "a(uuuu)" variant representing a list of NetworkManager IPv4 + * routes (which is a tuple of destination, prefix, next hop, and metric). + * + * Return value: (transfer none): a new floating #GVariant containing the + * routes **/ -void -nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value) +GVariant * +nm_utils_ip4_routes_to_variant (GPtrArray *routes) { - GPtrArray *routes; - GSList *iter; + GVariantBuilder builder; + int i; - routes = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aau")); - for (iter = list; iter; iter = iter->next) { - NMIP4Route *route = (NMIP4Route *) iter->data; - GArray *array; - guint32 tmp; + if (routes) { + for (i = 0; i < routes->len; i++) { + NMIP4Route *route = routes->pdata[i]; + guint32 array[4]; - array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3); + array[0] = nm_ip4_route_get_dest (route); + array[1] = nm_ip4_route_get_prefix (route); + array[2] = nm_ip4_route_get_next_hop (route); + array[3] = nm_ip4_route_get_metric (route); - tmp = nm_ip4_route_get_dest (route); - g_array_append_val (array, tmp); + g_variant_builder_add (&builder, "au", + g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, + array, 4, sizeof (guint32))); + } + } - tmp = nm_ip4_route_get_prefix (route); - g_array_append_val (array, tmp); + return g_variant_builder_end (&builder); +} - tmp = nm_ip4_route_get_next_hop (route); - g_array_append_val (array, tmp); +GVariant * +_nm_utils_ip4_dns_to_dbus (const GValue *prop_value) +{ + return nm_utils_ip4_dns_to_variant (g_value_get_boxed (prop_value)); +} - tmp = nm_ip4_route_get_metric (route); - g_array_append_val (array, tmp); +void +_nm_utils_ip4_dns_from_dbus (GVariant *dbus_value, + GValue *prop_value) +{ + g_value_take_boxed (prop_value, nm_utils_ip4_dns_from_variant (dbus_value)); +} - g_ptr_array_add (routes, array); - } +GVariant * +_nm_utils_ip4_addresses_to_dbus (const GValue *prop_value) +{ + return nm_utils_ip4_addresses_to_variant (g_value_get_boxed (prop_value)); +} + +void +_nm_utils_ip4_addresses_from_dbus (GVariant *dbus_value, + GValue *prop_value) +{ + g_value_take_boxed (prop_value, nm_utils_ip4_addresses_from_variant (dbus_value)); +} + +GVariant * +_nm_utils_ip4_routes_to_dbus (const GValue *prop_value) +{ + return nm_utils_ip4_routes_to_variant (g_value_get_boxed (prop_value)); +} - g_value_take_boxed (value, routes); +void +_nm_utils_ip4_routes_from_dbus (GVariant *dbus_value, + GValue *prop_value) +{ + g_value_take_boxed (prop_value, nm_utils_ip4_routes_from_variant (dbus_value)); } /** @@ -1351,618 +1282,503 @@ nm_utils_ip4_get_default_prefix (guint32 ip) return 24; /* Class C - 255.255.255.0 */ } -void -_nm_utils_ip6_dns_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_ip6_dns_to_dbus (const GValue *prop_value) { + GVariantBuilder builder; char **dns; - GPtrArray *dbus_dns; int i; dns = g_value_get_boxed (prop_value); - dbus_dns = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay")); if (dns) { for (i = 0; dns[i]; i++) { - GByteArray *bytearray; + struct in6_addr ip; - bytearray = g_byte_array_new (); - g_byte_array_set_size (bytearray, 16); - inet_pton (AF_INET6, dns[i], bytearray->data); - g_ptr_array_add (dbus_dns, bytearray); + inet_pton (AF_INET6, dns[i], &ip); + g_variant_builder_add (&builder, "ay", + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + &ip, sizeof (ip), 1)); } } - g_value_take_boxed (dbus_value, dbus_dns); + return g_variant_builder_end (&builder); } void -_nm_utils_ip6_dns_from_dbus (const GValue *dbus_value, +_nm_utils_ip6_dns_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GPtrArray *dbus_dns, *dns; - int i; + GVariantIter iter; + GVariant *ip_var; + GPtrArray *dns; - dbus_dns = g_value_get_boxed (dbus_value); dns = g_ptr_array_new (); - if (dbus_dns) { - for (i = 0; i < dbus_dns->len; i++) { - GByteArray *bytearray = dbus_dns->pdata[i]; - const char *str; - - if (bytearray->len != 16) { - g_warning ("%s: ignoring invalid IP6 address of length %d", - __func__, bytearray->len); - continue; - } + g_variant_iter_init (&iter, dbus_value); + while (g_variant_iter_next (&iter, "ay", &ip_var)) { + gsize length; + const struct in6_addr *ip = g_variant_get_fixed_array (ip_var, &length, 1); + const char *str; - str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL); - g_ptr_array_add (dns, g_strdup (str)); + if (length != sizeof (struct in6_addr)) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) length); + g_variant_unref (ip_var); + continue; } + + str = nm_utils_inet6_ntop (ip, NULL); + g_ptr_array_add (dns, g_strdup (str)); + g_variant_unref (ip_var); } g_ptr_array_add (dns, NULL); g_value_take_boxed (prop_value, g_ptr_array_free (dns, FALSE)); } -void -_nm_utils_ip6_addresses_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_ip6_addresses_to_dbus (const GValue *prop_value) { - GPtrArray *addresses, *dbus_addresses; + GVariantBuilder builder; + GPtrArray *addresses; int i; addresses = g_value_get_boxed (prop_value); - dbus_addresses = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayuay)")); if (addresses) { for (i = 0; i < addresses->len; i++) { NMIP6Address *addr = addresses->pdata[i]; - GValueArray *array; - GValue element = G_VALUE_INIT; - GByteArray *ba; - - array = g_value_array_new (3); - - /* IP address */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - /* Prefix */ - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_address_get_prefix (addr)); - g_value_array_append (array, &element); - g_value_unset (&element); - - /* Gateway */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_gateway (addr), 16); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_ptr_array_add (dbus_addresses, array); + GVariant *ip, *gateway; + guint32 prefix; + + ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_address_get_address (addr), + 16, 1); + prefix = nm_ip6_address_get_prefix (addr); + gateway = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_address_get_gateway (addr), + 16, 1); + + g_variant_builder_add (&builder, "(@au@a)", ip, prefix, gateway); } } - g_value_take_boxed (dbus_value, dbus_addresses); + return g_variant_builder_end (&builder); } void -_nm_utils_ip6_addresses_from_dbus (const GValue *dbus_value, +_nm_utils_ip6_addresses_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GPtrArray *addresses, *dbus_addresses; - int i; + GVariantIter iter; + GVariant *dest_var, *gateway_var; + guint32 prefix, metric; + GPtrArray *addresses; - dbus_addresses = g_value_get_boxed (dbus_value); + g_variant_iter_init (&iter, dbus_value); addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_address_unref); - if (dbus_addresses) { - for (i = 0; i < dbus_addresses->len; i++) { - GValueArray *elements = dbus_addresses->pdata[i]; - GValue *tmp; - GByteArray *ba_addr; - GByteArray *ba_gw = NULL; - NMIP6Address *addr; - guint32 prefix; - - if (elements->n_values < 2 || elements->n_values > 3) { - g_warning ("%s: ignoring invalid IP6 address structure", __func__); - continue; - } - - /* Third element (gateway) is optional */ - if ( !_nm_utils_gvalue_array_validate (elements, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT) - && !_nm_utils_gvalue_array_validate (elements, 3, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY)) { - g_warning ("%s: ignoring invalid IP6 address structure", __func__); - continue; - } - - tmp = g_value_array_get_nth (elements, 0); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { - g_warning ("%s: ignoring invalid IP6 address of length %d", - __func__, ba_addr->len); - continue; - } + while (g_variant_iter_next (&iter, "ayuayu", &dest_var, &prefix, &gateway_var, &metric)) { + NMIP6Address *addr; + const struct in6_addr *dest, *gateway; + gsize dest_len, gateway_len; - tmp = g_value_array_get_nth (elements, 1); - prefix = g_value_get_uint (tmp); - if (prefix > 128) { - g_warning ("%s: ignoring invalid IP6 prefix %d", - __func__, prefix); - continue; - } + if ( !g_variant_is_of_type (dest_var, G_VARIANT_TYPE_BYTESTRING) + || !g_variant_is_of_type (gateway_var, G_VARIANT_TYPE_BYTESTRING)) { + g_warning ("%s: ignoring invalid IP6 address structure", __func__); + goto next; + } - if (elements->n_values == 3) { - tmp = g_value_array_get_nth (elements, 2); - ba_gw = g_value_get_boxed (tmp); - if (ba_gw->len != 16) { - g_warning ("%s: ignoring invalid IP6 gateway address of length %d", - __func__, ba_gw->len); - continue; - } - } + dest = g_variant_get_fixed_array (dest_var, &dest_len, 1); + if (dest_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) dest_len); + goto next; + } + if (prefix > 128) { + g_warning ("%s: ignoring invalid IP6 prefix %d", + __func__, prefix); + goto next; + } + gateway = g_variant_get_fixed_array (gateway_var, &gateway_len, 1); + if (gateway_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) gateway_len); + goto next; + } - addr = nm_ip6_address_new (); - nm_ip6_address_set_prefix (addr, prefix); - nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data); - if (ba_gw) - nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data); + addr = nm_ip6_address_new (); + nm_ip6_address_set_address (addr, dest); + nm_ip6_address_set_prefix (addr, prefix); + nm_ip6_address_set_gateway (addr, gateway); + g_ptr_array_add (addresses, addr); - g_ptr_array_add (addresses, addr); - } + next: + g_variant_unref (dest_var); + g_variant_unref (gateway_var); } g_value_take_boxed (prop_value, addresses); } -void -_nm_utils_ip6_routes_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_ip6_routes_to_dbus (const GValue *prop_value) { - GPtrArray *routes, *dbus_routes; + GPtrArray *routes; + GVariantBuilder builder; int i; routes = g_value_get_boxed (prop_value); - dbus_routes = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayuayu)")); if (routes) { for (i = 0; i < routes->len; i++) { NMIP6Route *route = routes->pdata[i]; - GValueArray *array; - const struct in6_addr *addr; - GByteArray *ba; - GValue element = G_VALUE_INIT; - - array = g_value_array_new (4); - - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - addr = nm_ip6_route_get_dest (route); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_route_get_prefix (route)); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - addr = nm_ip6_route_get_next_hop (route); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_route_get_metric (route)); - g_value_array_append (array, &element); - g_value_unset (&element); - - g_ptr_array_add (dbus_routes, array); + GVariant *dest, *next_hop; + guint32 prefix, metric; + + dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_route_get_dest (route), + 16, 1); + prefix = nm_ip6_route_get_prefix (route); + next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_route_get_next_hop (route), + 16, 1); + metric = nm_ip6_route_get_metric (route); + + g_variant_builder_add (&builder, "(@au@au)", dest, prefix, next_hop, metric); } } - g_value_take_boxed (dbus_value, dbus_routes); + return g_variant_builder_end (&builder); } void -_nm_utils_ip6_routes_from_dbus (const GValue *dbus_value, +_nm_utils_ip6_routes_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GPtrArray *routes, *dbus_routes; - int i; + GPtrArray *routes; + GVariantIter iter; + GVariant *dest_var, *next_hop_var; + const struct in6_addr *dest, *next_hop; + gsize dest_len, next_hop_len; + guint32 prefix, metric; - dbus_routes = g_value_get_boxed (dbus_value); routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref); - if (dbus_routes) { - for (i = 0; i < dbus_routes->len; i++) { - GValueArray *route_values = dbus_routes->pdata[i]; - GByteArray *dest, *next_hop; - guint prefix, metric; - NMIP6Route *route; - - if (!_nm_utils_gvalue_array_validate (route_values, 4, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT)) { - g_warning ("Ignoring invalid IP6 route"); - continue; - } - - dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0)); - if (dest->len != 16) { - g_warning ("%s: ignoring invalid IP6 dest address of length %d", - __func__, dest->len); - continue; - } - - prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1)); + g_variant_iter_init (&iter, dbus_value); + while (g_variant_iter_next (&iter, "(@au@au)", &dest_var, &prefix, &next_hop_var, &metric)) { + NMIP6Route *route; - next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2)); - if (next_hop->len != 16) { - g_warning ("%s: ignoring invalid IP6 next_hop address of length %d", - __func__, next_hop->len); - continue; - } + if ( !g_variant_is_of_type (dest_var, G_VARIANT_TYPE_BYTESTRING) + || !g_variant_is_of_type (next_hop_var, G_VARIANT_TYPE_BYTESTRING)) { + g_warning ("%s: ignoring invalid IP6 address structure", __func__); + goto next; + } - metric = g_value_get_uint (g_value_array_get_nth (route_values, 3)); + dest = g_variant_get_fixed_array (dest_var, &dest_len, 1); + if (dest_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) dest_len); + goto next; + } + next_hop = g_variant_get_fixed_array (next_hop_var, &next_hop_len, 1); + if (next_hop_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) next_hop_len); + goto next; + } - route = nm_ip6_route_new (); - nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data); - nm_ip6_route_set_prefix (route, prefix); - nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data); - nm_ip6_route_set_metric (route, metric); + route = nm_ip6_route_new (); + nm_ip6_route_set_dest (route, dest); + nm_ip6_route_set_prefix (route, prefix); + nm_ip6_route_set_next_hop (route, next_hop); + nm_ip6_route_set_metric (route, metric); + g_ptr_array_add (routes, route); - g_ptr_array_add (routes, route); - } + next: + g_variant_unref (dest_var); + g_variant_unref (next_hop_var); } g_value_take_boxed (prop_value, routes); } /** - * nm_utils_ip6_addresses_from_gvalue: - * @value: gvalue containing a GPtrArray of GValueArrays of (GArray of guchars) and #guint32 + * nm_utils_ip6_addresses_from_variant: + * @variant: #GVariant containing an "a(ayuay)" * - * Utility function to convert a #GPtrArray of #GValueArrays of (#GArray of guchars) and #guint32 - * representing a list of NetworkManager IPv6 addresses (which is a tuple of address, - * prefix, and gateway), into a #GSList of #NMIP6Address objects. The specific format of - * this serialization is not guaranteed to be stable and the #GValueArray may be - * extended in the future. + * Utility function to convert an "a(ayuay)" (array of tuples of address, prefix, + * and gateway), into a #GSList of #NMIP6Address objects. * - * Returns: (transfer full) (element-type NMIP6Address): a newly allocated #GSList of #NMIP6Address objects + * Returns: (transfer full) (element-type NMIP6Address): a newly allocated #GSList of + * #NMIP6Address objects **/ -GSList * -nm_utils_ip6_addresses_from_gvalue (const GValue *value) +GPtrArray * +nm_utils_ip6_addresses_from_variant (GVariant *variant) { + GVariantIter iter; + GVariant *ip_var, *gateway_var; + const struct in6_addr *ip, *gateway; + gsize ip_len, gateway_len; + guint32 prefix; GPtrArray *addresses; - int i; - GSList *list = NULL; - addresses = (GPtrArray *) g_value_get_boxed (value); - - for (i = 0; addresses && (i < addresses->len); i++) { - GValueArray *elements = (GValueArray *) g_ptr_array_index (addresses, i); - GValue *tmp; - GByteArray *ba_addr; - GByteArray *ba_gw = NULL; + addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_address_unref); + g_variant_iter_init (&iter, variant); + while (g_variant_iter_next (&iter, "(@au@a)", &ip_var, &prefix, &gateway_var)) { NMIP6Address *addr; - guint32 prefix; - - if (elements->n_values < 2 || elements->n_values > 3) { - g_warning ("%s: ignoring invalid IP6 address structure", __func__); - continue; - } - /* Third element (gateway) is optional */ - if ( !_nm_utils_gvalue_array_validate (elements, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT) - && !_nm_utils_gvalue_array_validate (elements, 3, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY)) { + if ( !g_variant_is_of_type (ip_var, G_VARIANT_TYPE_BYTESTRING) + || !g_variant_is_of_type (gateway_var, G_VARIANT_TYPE_BYTESTRING)) { g_warning ("%s: ignoring invalid IP6 address structure", __func__); - continue; + goto next; } - tmp = g_value_array_get_nth (elements, 0); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { + ip = g_variant_get_fixed_array (ip_var, &ip_len, 1); + if (ip_len != 16) { g_warning ("%s: ignoring invalid IP6 address of length %d", - __func__, ba_addr->len); - continue; + __func__, (int) ip_len); + goto next; } - - tmp = g_value_array_get_nth (elements, 1); - prefix = g_value_get_uint (tmp); if (prefix > 128) { g_warning ("%s: ignoring invalid IP6 prefix %d", __func__, prefix); - continue; + goto next; } - - if (elements->n_values == 3) { - tmp = g_value_array_get_nth (elements, 2); - ba_gw = g_value_get_boxed (tmp); - if (ba_gw->len != 16) { - g_warning ("%s: ignoring invalid IP6 gateway address of length %d", - __func__, ba_gw->len); - continue; - } + gateway = g_variant_get_fixed_array (gateway_var, &gateway_len, 1); + if (gateway_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) gateway_len); + goto next; } addr = nm_ip6_address_new (); + nm_ip6_address_set_address (addr, ip); nm_ip6_address_set_prefix (addr, prefix); - nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data); - if (ba_gw) - nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data); + nm_ip6_address_set_gateway (addr, gateway); + g_ptr_array_add (addresses, addr); - list = g_slist_prepend (list, addr); + next: + g_variant_unref (ip_var); + g_variant_unref (gateway_var); } - return g_slist_reverse (list); + return addresses; } /** - * nm_utils_ip6_addresses_to_gvalue: - * @list: (element-type NMIP6Address): a list of #NMIP6Address objects - * @value: a pointer to a #GValue into which to place the converted addresses, - * which should be unset by the caller (when no longer needed) with - * g_value_unset(). - * - * Utility function to convert a #GSList of #NMIP6Address objects into a - * #GPtrArray of #GValueArrays representing a list of NetworkManager IPv6 addresses - * (which is a tuple of address, prefix, and gateway). The specific format of - * this serialization is not guaranteed to be stable and may be extended in the - * future. + * nm_utils_ip6_addresses_to_variant: + * @addresses: (element-type NMIP6Address): an array of #NMIP6Address objects + * + * Utility function to convert a #GSList of #NMIP6Address objects into an + * "a(ayuay)" variant representing a list of NetworkManager IPv6 addresses (which + * is a tuple of address, prefix, and gateway). + * + * Return value: (transfer none): a new floating #GVariant containing the + * addresses **/ -void -nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value) +GVariant * +nm_utils_ip6_addresses_to_variant (GPtrArray *addresses) { - GPtrArray *addresses; - GSList *iter; - - addresses = g_ptr_array_new (); - - for (iter = list; iter; iter = iter->next) { - NMIP6Address *addr = (NMIP6Address *) iter->data; - GValueArray *array; - GValue element = G_VALUE_INIT; - GByteArray *ba; - - array = g_value_array_new (3); + GVariantBuilder builder; + int i; - /* IP address */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayuay)")); - /* Prefix */ - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_address_get_prefix (addr)); - g_value_array_append (array, &element); - g_value_unset (&element); + for (i = 0; i < addresses->len; i++) { + NMIP6Address *addr = (NMIP6Address *) addresses->pdata[i]; + GVariant *ip, *gateway; + guint32 prefix; - /* Gateway */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_gateway (addr), 16); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); + ip = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_address_get_address (addr), + 16, 1); + prefix = nm_ip6_address_get_prefix (addr); + gateway = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_address_get_gateway (addr), + 16, 1); - g_ptr_array_add (addresses, array); + g_variant_builder_add (&builder, "(@au@a)", ip, prefix, gateway); } - g_value_take_boxed (value, addresses); + return g_variant_builder_end (&builder); } /** - * nm_utils_ip6_routes_from_gvalue: - * @value: #GValue containing a #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32, - * (#GArray of #guchars), and #guint32 + * nm_utils_ip6_routes_from_variant: + * @variant: #GVariant containing an "a(ayuayu)" * - * Utility function #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32, - * (#GArray of #guchars), and #guint32 representing a list of NetworkManager IPv6 - * routes (which is a tuple of destination, prefix, next hop, and metric) - * into a #GSList of #NMIP6Route objects. The specific format of this serialization - * is not guaranteed to be stable and may be extended in the future. + * Utility function to convert an "a(ayuayu)" representing a list of NetworkManager + * IPv6 routes (which is a tuple of destination, prefix, next hop, and metric) into a + * #GSList of #NMIP6Route objects. * - * Returns: (transfer full) (element-type NMIP6Route): a newly allocated #GSList of #NMIP6Route objects + * Returns: (transfer full) (element-type NMIP6Route): a newly allocated #GSList of + * #NMIP6Route objects **/ -GSList * -nm_utils_ip6_routes_from_gvalue (const GValue *value) -{ +GPtrArray * +nm_utils_ip6_routes_from_variant (GVariant *variant) +{ + GVariantIter iter; + GVariant *dest_var, *next_hop_var; + const struct in6_addr *dest, *next_hop; + gsize dest_len, next_hop_len; + guint32 prefix, metric; GPtrArray *routes; - int i; - GSList *list = NULL; - routes = (GPtrArray *) g_value_get_boxed (value); - for (i = 0; routes && (i < routes->len); i++) { - GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i); - GByteArray *dest, *next_hop; - guint prefix, metric; + routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref); + g_variant_iter_init (&iter, variant); + while (g_variant_iter_next (&iter, "(@au@au)", &dest_var, &prefix, &next_hop_var, &metric)) { NMIP6Route *route; - if (!_nm_utils_gvalue_array_validate (route_values, 4, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT)) { - g_warning ("Ignoring invalid IP6 route"); - continue; + if ( !g_variant_is_of_type (dest_var, G_VARIANT_TYPE_BYTESTRING) + || !g_variant_is_of_type (next_hop_var, G_VARIANT_TYPE_BYTESTRING)) { + g_warning ("%s: ignoring invalid IP6 address structure", __func__); + goto next; } - dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0)); - if (dest->len != 16) { - g_warning ("%s: ignoring invalid IP6 dest address of length %d", - __func__, dest->len); - continue; + dest = g_variant_get_fixed_array (dest_var, &dest_len, 1); + if (dest_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) dest_len); + goto next; } - - prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1)); - - next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2)); - if (next_hop->len != 16) { - g_warning ("%s: ignoring invalid IP6 next_hop address of length %d", - __func__, next_hop->len); - continue; + next_hop = g_variant_get_fixed_array (next_hop_var, &next_hop_len, 1); + if (next_hop_len != 16) { + g_warning ("%s: ignoring invalid IP6 address of length %d", + __func__, (int) next_hop_len); + goto next; } - metric = g_value_get_uint (g_value_array_get_nth (route_values, 3)); - route = nm_ip6_route_new (); - nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data); + nm_ip6_route_set_dest (route, dest); nm_ip6_route_set_prefix (route, prefix); - nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data); + nm_ip6_route_set_next_hop (route, next_hop); nm_ip6_route_set_metric (route, metric); - list = g_slist_prepend (list, route); + g_ptr_array_add (routes, route); + + next: + g_variant_unref (dest_var); + g_variant_unref (next_hop_var); } - return g_slist_reverse (list); + return routes; } /** - * nm_utils_ip6_routes_to_gvalue: - * @list: (element-type NMIP6Route): a list of #NMIP6Route objects - * @value: a pointer to a #GValue into which to place the converted routes, - * which should be unset by the caller (when no longer needed) with - * g_value_unset(). - * - * Utility function to convert a #GSList of #NMIP6Route objects into a #GPtrArray of - * #GValueArrays of (#GArray of #guchars), #guint32, (#GArray of #guchars), and #guint32 - * representing a list of NetworkManager IPv6 routes (which is a tuple of destination, - * prefix, next hop, and metric). The specific format of this serialization is not - * guaranteed to be stable and may be extended in the future. + * nm_utils_ip6_routes_to_variant: + * @routes: (element-type NMIP6Route): an array of #NMIP6Route objects + * + * Utility function to convert a #GSList of #NMIP6Route objects into an + * "a(ayuayu)" variant representing a list of NetworkManager IPv6 + * routes (which is a tuple of destination, prefix, next hop, and metric). + * + * Return value: (transfer none): a new floating #GVariant containing the + * routes **/ -void -nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value) +GVariant * +nm_utils_ip6_routes_to_variant (GPtrArray *routes) { - GPtrArray *routes; - GSList *iter; - - routes = g_ptr_array_new (); - - for (iter = list; iter; iter = iter->next) { - NMIP6Route *route = (NMIP6Route *) iter->data; - GValueArray *array; - const struct in6_addr *addr; - GByteArray *ba; - GValue element = G_VALUE_INIT; - - array = g_value_array_new (4); - - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - addr = nm_ip6_route_get_dest (route); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); + GVariantBuilder builder; + int i; - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_route_get_prefix (route)); - g_value_array_append (array, &element); - g_value_unset (&element); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayuayu)")); - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - addr = nm_ip6_route_get_next_hop (route); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guchar *)addr, sizeof (*addr)); - g_value_take_boxed (&element, ba); - g_value_array_append (array, &element); - g_value_unset (&element); + for (i = 0; i < routes->len; i++) { + NMIP6Route *route = (NMIP6Route *) routes->pdata[i]; + GVariant *dest, *next_hop; + guint32 prefix, metric; - g_value_init (&element, G_TYPE_UINT); - g_value_set_uint (&element, nm_ip6_route_get_metric (route)); - g_value_array_append (array, &element); - g_value_unset (&element); + dest = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_route_get_dest (route), + 16, 1); + prefix = nm_ip6_route_get_prefix (route); + next_hop = g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + nm_ip6_route_get_next_hop (route), + 16, 1); + metric = nm_ip6_route_get_metric (route); - g_ptr_array_add (routes, array); + g_variant_builder_add (&builder, "(@au@au)", dest, prefix, next_hop, metric); } - g_value_take_boxed (value, routes); + return g_variant_builder_end (&builder); } /** - * nm_utils_ip6_dns_from_gvalue: (skip) - * @value: a #GValue + * nm_utils_ip6_dns_from_variant: (skip) + * @variant: a #GVariant * - * Converts a #GValue containing a #GPtrArray of IP6 DNS, represented as - * #GByteArrays into a #GSList of IP address strings. + * Converts a #GVariant containing an "aay" of DNS server IPv6 + * addresses into an array of IPv6 address strings. * - * Returns: a #GSList of IP6 addresses. + * Returns: a %NULL-terminated array of IPv6 address strings. */ -GSList * -nm_utils_ip6_dns_from_gvalue (const GValue *value) +char ** +nm_utils_ip6_dns_from_variant (GVariant *variant) { + GVariantIter iter; + GVariant *ip_var; + const struct in6_addr *ip; + gsize ip_len; + const char *str; GPtrArray *dns; - int i; - GSList *list = NULL; - dns = (GPtrArray *) g_value_get_boxed (value); - for (i = 0; dns && (i < dns->len); i++) { - GByteArray *bytearray = (GByteArray *) g_ptr_array_index (dns, i); - const char *str; + dns = g_ptr_array_new (); - if (bytearray->len != 16) { + g_variant_iter_init (&iter, variant); + while (g_variant_iter_next (&iter, "@a", &ip_var)) { + if (!g_variant_is_of_type (ip_var, G_VARIANT_TYPE_BYTESTRING)) { + g_warning ("%s: ignoring invalid IP6 address structure", __func__); + goto next; + } + + ip = g_variant_get_fixed_array (ip_var, &ip_len, 1); + if (ip_len != 16) { g_warning ("%s: ignoring invalid IP6 address of length %d", - __func__, bytearray->len); - continue; + __func__, (int) ip_len); + goto next; } - str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL); - list = g_slist_prepend (list, g_strdup (str)); + str = nm_utils_inet6_ntop (ip, NULL); + g_ptr_array_add (dns, g_strdup (str)); + + next: + g_variant_unref (ip_var); } - return g_slist_reverse (list); + g_ptr_array_add (dns, NULL); + return (char **) g_ptr_array_free (dns, FALSE); } /** - * nm_utils_ip6_dns_to_gvalue: (skip) - * @list: a list of #NMIP6Route objects - * @value: a pointer to a #GValue into which to place the converted DNS server - * addresses, which should be unset by the caller (when no longer needed) with - * g_value_unset(). - * - * Utility function to convert a #GSList of <literal><type>struct - * in6_addr</type></literal> structs into a #GPtrArray of #GByteArrays - * representing each server's IPv6 addresses in network byte order. - * The specific format of this serialization is not guaranteed to be - * stable and may be extended in the future. + * nm_utils_ip6_dns_to_variant: (skip) + * @dns: a %NULL-termianted array of IP address strings + * + * Utility function to convert an array of IPv6 address strings into an "aay" + * variant representing each server's IPv6 addresses in network byte order. */ -void -nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value) +GVariant * +nm_utils_ip6_dns_to_variant (char **dns) { - GPtrArray *dns; - GSList *iter; + GVariantBuilder builder; + int i; - dns = g_ptr_array_new (); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay")); - for (iter = list; iter; iter = iter->next) { - const char *str = iter->data; - GByteArray *bytearray; + if (dns) { + for (i = 0; dns[i]; i++) { + struct in6_addr ip = IN6ADDR_ANY_INIT; - bytearray = g_byte_array_new (); - g_byte_array_set_size (bytearray, 16); - inet_pton (AF_INET6, str, bytearray->data); - g_ptr_array_add (dns, bytearray); + inet_pton (AF_INET6, dns[i], &ip); + g_variant_builder_add (&builder, "@a", + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, &ip, 16, 1)); + } } - g_value_take_boxed (value, dns); + return g_variant_builder_end (&builder); } /** @@ -2719,25 +2535,33 @@ nm_utils_hwaddr_equal (gconstpointer hwaddr1, return !memcmp (hwaddr1, hwaddr2, hwaddr1_len); } -void -_nm_utils_hwaddr_to_dbus (const GValue *prop_value, - GValue *dbus_value) +GVariant * +_nm_utils_hwaddr_to_dbus (const GValue *prop_value) { const char *str = g_value_get_string (prop_value); - GByteArray *array; + guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; + int len; + + if (str) { + len = hwaddr_binary_len (str); + g_return_val_if_fail (len <= NM_UTILS_HWADDR_LEN_MAX, NULL); + if (!nm_utils_hwaddr_aton (str, buf, len)) + len = 0; + } else + len = 0; - array = str ? nm_utils_hwaddr_atoba (str, hwaddr_binary_len (str)) : NULL; - g_value_take_boxed (dbus_value, array); + return g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, buf, len, 1); } void -_nm_utils_hwaddr_from_dbus (const GValue *dbus_value, +_nm_utils_hwaddr_from_dbus (GVariant *dbus_value, GValue *prop_value) { - GByteArray *array = g_value_get_boxed (dbus_value); + gsize length = 0; + const guint8 *array = g_variant_get_fixed_array (dbus_value, &length, 1); char *str; - str = array ? nm_utils_hwaddr_ntoa (array->data, array->len) : NULL; + str = length ? nm_utils_hwaddr_ntoa (array, length) : NULL; g_value_take_string (prop_value, str); } diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h index 8b23d1b08e..baac9fbb67 100644 --- a/libnm-core/nm-utils.h +++ b/libnm-core/nm-utils.h @@ -94,27 +94,27 @@ gboolean nm_utils_ap_mode_security_valid (NMUtilsSecurityType type, gboolean nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type); gboolean nm_utils_wpa_psk_valid (const char *psk); -GSList *nm_utils_ip4_addresses_from_gvalue (const GValue *value); -void nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value); +char **nm_utils_ip4_dns_from_variant (GVariant *variant); +GVariant *nm_utils_ip4_dns_to_variant (char **dns); -GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value); -void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value); +GPtrArray *nm_utils_ip4_addresses_from_variant (GVariant *variant); +GVariant *nm_utils_ip4_addresses_to_variant (GPtrArray *addresses); -GSList *nm_utils_ip4_dns_from_gvalue (const GValue *value); -void nm_utils_ip4_dns_to_gvalue (GSList *list, GValue *value); +GPtrArray *nm_utils_ip4_routes_from_variant (GVariant *variant); +GVariant *nm_utils_ip4_routes_to_variant (GPtrArray *routes); guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask); guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix); guint32 nm_utils_ip4_get_default_prefix (guint32 ip); -GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value); -void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value); +char **nm_utils_ip6_dns_from_variant (GVariant *variant); +GVariant *nm_utils_ip6_dns_to_variant (char **dns); -GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value); -void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value); +GPtrArray *nm_utils_ip6_addresses_from_variant (GVariant *variant); +GVariant *nm_utils_ip6_addresses_to_variant (GPtrArray *addresses); -GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value); -void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value); +GPtrArray *nm_utils_ip6_routes_from_variant (GVariant *variant); +GVariant *nm_utils_ip6_routes_to_variant (GPtrArray *routes); char *nm_utils_uuid_generate (void); char *nm_utils_uuid_generate_from_string (const char *s); diff --git a/libnm-core/nm-value-transforms.c b/libnm-core/nm-value-transforms.c deleted file mode 100644 index 57da2dfa87..0000000000 --- a/libnm-core/nm-value-transforms.c +++ /dev/null @@ -1,593 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ - -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2005 - 2014 Red Hat, Inc. - */ - -#include "config.h" - -#include <string.h> - -#include "nm-utils.h" -#include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" -#include "nm-glib-compat.h" - -static void -_nm_utils_convert_op_to_string (const GValue *src_value, GValue *dest_value) -{ - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_OBJECT_PATH)); - - g_value_set_string (dest_value, (const char *) g_value_get_boxed (src_value)); -} - -static void -_nm_utils_convert_strv_to_slist (const GValue *src_value, GValue *dest_value) -{ - char **str; - GSList *list = NULL; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), G_TYPE_STRV)); - - str = (char **) g_value_get_boxed (src_value); - - while (str && str[i]) - list = g_slist_prepend (list, g_strdup (str[i++])); - - g_value_take_boxed (dest_value, g_slist_reverse (list)); -} - -static void -_nm_utils_convert_slist_to_strv (const GValue *src_value, GValue *dest_value) -{ - GSList *slist; - char **strv; - int len, i = 0; - - slist = g_value_get_boxed (src_value); - len = g_slist_length (slist); - - strv = g_new (char *, len + 1); - for (i = 0; slist; slist = slist->next, i++) - strv[i] = g_strdup (slist->data); - strv[i] = NULL; - - g_value_take_boxed (dest_value, strv); -} - -static void -_nm_utils_convert_strv_to_ptrarray (const GValue *src_value, GValue *dest_value) -{ - char **str; - GPtrArray *array = NULL; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), G_TYPE_STRV)); - - str = (char **) g_value_get_boxed (src_value); - - array = g_ptr_array_sized_new (3); - while (str && str[i]) - g_ptr_array_add (array, g_strdup (str[i++])); - - g_value_take_boxed (dest_value, array); -} - -static void -_nm_utils_convert_string_list_to_string (const GValue *src_value, GValue *dest_value) -{ - GSList *strings; - GString *printable; - GSList *iter; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_LIST_OF_STRING)); - - strings = (GSList *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - for (iter = strings; iter; iter = iter->next) { - if (iter != strings) - g_string_append_c (printable, ','); - g_string_append (printable, iter->data ? iter->data : "(null)"); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_string_array_to_string (const GPtrArray *strings, GValue *dest_value) -{ - GString *printable; - int i; - - printable = g_string_new (NULL); - for (i = 0; strings && i < strings->len; i++) { - if (i > 0) - g_string_append_c (printable, ','); - g_string_append (printable, strings->pdata[i]); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_string_array_to_string (const GValue *src_value, GValue *dest_value) -{ - const GPtrArray *strings; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_STRING)); - - strings = (const GPtrArray *) g_value_get_boxed (src_value); - _string_array_to_string (strings, dest_value); -} - -static void -_nm_utils_convert_op_array_to_string (const GValue *src_value, GValue *dest_value) -{ - const GPtrArray *strings; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)); - - strings = (const GPtrArray *) g_value_get_boxed (src_value); - _string_array_to_string (strings, dest_value); -} - -static void -_nm_utils_convert_uint_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GArray *array; - GString *printable; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UINT_ARRAY)); - - array = (GArray *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - while (array && (i < array->len)) { - guint32 addr; - - if (i > 0) - g_string_append (printable, ", "); - - addr = g_array_index (array, guint32, i++); - g_string_append (printable, nm_utils_inet4_ntop (addr, NULL)); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GPtrArray *ptr_array; - GString *printable; - guint i = 0; - char buf[INET_ADDRSTRLEN]; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT)); - - ptr_array = (GPtrArray *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - while (ptr_array && (i < ptr_array->len)) { - GArray *array; - gboolean is_addr; /* array contains address x route */ - - if (i > 0) - g_string_append (printable, "; "); - - g_string_append (printable, "{ "); - array = (GArray *) g_ptr_array_index (ptr_array, i++); - if (array->len < 2) { - g_string_append (printable, "invalid"); - continue; - } - is_addr = (array->len < 4); - - nm_utils_inet4_ntop (g_array_index (array, guint32, 0), buf); - if (is_addr) - g_string_append_printf (printable, "ip = %s", buf); - else - g_string_append_printf (printable, "dst = %s", buf); - - g_string_append_printf (printable, "/%u", - g_array_index (array, guint32, 1)); - - if (array->len > 2) { - nm_utils_inet4_ntop (g_array_index (array, guint32, 2), buf); - if (is_addr) - g_string_append_printf (printable, ", gw = %s", buf); - else - g_string_append_printf (printable, ", nh = %s", buf); - } - - if (array->len > 3) { - g_string_append_printf (printable, ", mt = %u", - g_array_index (array, guint32, 3)); - } - - g_string_append (printable, " }"); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -convert_one_gvalue_hash_entry (gpointer key, gpointer value, gpointer user_data) -{ - GString *printable = (GString *) user_data; - char *value_as_string; - - value_as_string = g_strdup_value_contents ((GValue *) value); - g_string_append_printf (printable, " { '%s': %s },", (const char *) key, value_as_string); - g_free (value_as_string); -} - -static void -_nm_utils_convert_gvalue_hash_to_string (const GValue *src_value, GValue *dest_value) -{ - GHashTable *hash; - GString *printable; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_MAP_OF_VARIANT)); - - hash = (GHashTable *) g_value_get_boxed (src_value); - - printable = g_string_new ("["); - g_hash_table_foreach (hash, convert_one_gvalue_hash_entry, printable); - g_string_append (printable, " ]"); - - g_value_take_string (dest_value, printable->str); - g_string_free (printable, FALSE); -} - -static void -convert_one_string_hash_entry (gpointer key, gpointer value, gpointer user_data) -{ - GString *printable = (GString *) user_data; - - if (printable->len) - g_string_append_c (printable, ','); - g_string_append_printf (printable, "%s=%s", (const char *) key, (const char *) value); -} - -static void -_nm_utils_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value) -{ - GHashTable *hash; - GString *printable; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_MAP_OF_STRING)); - - hash = (GHashTable *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - if (hash) - g_hash_table_foreach (hash, convert_one_string_hash_entry, printable); - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GArray *array; - GString *printable; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UCHAR_ARRAY)); - - array = (GArray *) g_value_get_boxed (src_value); - - printable = g_string_new ("["); - if (array) { - while (i < MIN (array->len, 35)) { - if (i > 0) - g_string_append_c (printable, ' '); - g_string_append_printf (printable, "0x%02X", - g_array_index (array, unsigned char, i++)); - } - if (i < array->len) - g_string_append (printable, " ... "); - } - g_string_append_c (printable, ']'); - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GPtrArray *ptr_array; - GString *printable; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)); - - ptr_array = (GPtrArray *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - while (ptr_array && (i < ptr_array->len)) { - GByteArray *bytearray; - struct in6_addr *addr; - - if (i > 0) - g_string_append (printable, ", "); - - bytearray = (GByteArray *) g_ptr_array_index (ptr_array, i++); - if (bytearray->len != 16) { - g_string_append (printable, "invalid"); - continue; - } - addr = (struct in6_addr *) bytearray->data; - g_string_append (printable, nm_utils_inet6_ntop (addr, NULL)); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GPtrArray *ptr_array; - GString *printable; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS)); - - ptr_array = (GPtrArray *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - while (ptr_array && (i < ptr_array->len)) { - GValueArray *elements; - GValue *tmp; - GByteArray *ba_addr; - struct in6_addr *addr; - guint32 prefix; - - if (i > 0) - g_string_append (printable, "; "); - - g_string_append (printable, "{ "); - elements = (GValueArray *) g_ptr_array_index (ptr_array, i++); - if (!_nm_utils_gvalue_array_validate (elements, 3, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT, - DBUS_TYPE_G_UCHAR_ARRAY)) { - g_string_append (printable, "invalid }"); - continue; - } - - /* IPv6 address */ - tmp = g_value_array_get_nth (elements, 0); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { - g_string_append (printable, "invalid }"); - continue; - } - addr = (struct in6_addr *) ba_addr->data; - g_string_append_printf (printable, "ip = %s", nm_utils_inet6_ntop (addr, NULL)); - - /* Prefix */ - tmp = g_value_array_get_nth (elements, 1); - prefix = g_value_get_uint (tmp); - if (prefix > 128) { - g_string_append (printable, "/invalid }"); - continue; - } - g_string_append_printf (printable, "/%u", prefix); - g_string_append (printable, ", "); - - /* IPv6 Gateway */ - tmp = g_value_array_get_nth (elements, 2); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { - g_string_append (printable, "invalid }"); - continue; - } - addr = (struct in6_addr *) ba_addr->data; - g_string_append_printf (printable, "gw = %s", nm_utils_inet6_ntop (addr, NULL)); - g_string_append (printable, " }"); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -static void -_nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GValue *dest_value) -{ - GPtrArray *ptr_array; - GString *printable; - guint i = 0; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE)); - - ptr_array = (GPtrArray *) g_value_get_boxed (src_value); - - printable = g_string_new (NULL); - while (ptr_array && (i < ptr_array->len)) { - GValueArray *elements; - GValue *tmp; - GByteArray *ba_addr; - struct in6_addr *addr; - guint32 prefix, metric; - - if (i > 0) - g_string_append (printable, "; "); - - g_string_append (printable, "{ "); - elements = (GValueArray *) g_ptr_array_index (ptr_array, i++); - if (!_nm_utils_gvalue_array_validate (elements, 4, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT, - DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_UINT)) { - g_string_append (printable, "invalid"); - continue; - } - - /* Destination address */ - tmp = g_value_array_get_nth (elements, 0); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { - g_string_append (printable, "invalid"); - continue; - } - addr = (struct in6_addr *) ba_addr->data; - g_string_append_printf (printable, "dst = %s", nm_utils_inet6_ntop (addr, NULL)); - - /* Prefix */ - tmp = g_value_array_get_nth (elements, 1); - prefix = g_value_get_uint (tmp); - if (prefix > 128) { - g_string_append (printable, "/invalid"); - continue; - } - g_string_append_printf (printable, "/%u", prefix); - g_string_append (printable, ", "); - - /* Next hop addresses */ - tmp = g_value_array_get_nth (elements, 2); - ba_addr = g_value_get_boxed (tmp); - if (ba_addr->len != 16) { - g_string_append (printable, "invalid"); - continue; - } - addr = (struct in6_addr *) ba_addr->data; - g_string_append_printf (printable, "nh = %s", nm_utils_inet6_ntop (addr, NULL)); - g_string_append (printable, ", "); - - /* Metric */ - tmp = g_value_array_get_nth (elements, 3); - metric = g_value_get_uint (tmp); - g_string_append_printf (printable, "mt = %u", metric); - - g_string_append (printable, " }"); - } - - g_value_take_string (dest_value, g_string_free (printable, FALSE)); -} - -#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID)) -#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS)) - -static void -_nm_utils_convert_old_ip6_addr_array (const GValue *src_value, GValue *dst_value) -{ - GPtrArray *src_outer_array; - GPtrArray *dst_outer_array; - guint i; - - g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS)); - - src_outer_array = (GPtrArray *) g_value_get_boxed (src_value); - dst_outer_array = g_ptr_array_new (); - - for (i = 0; src_outer_array && (i < src_outer_array->len); i++) { - GValueArray *src_addr_array; - GValueArray *dst_addr_array; - GValue element = G_VALUE_INIT; - GValue *src_addr, *src_prefix; - GByteArray *ba; - - src_addr_array = (GValueArray *) g_ptr_array_index (src_outer_array, i); - if (!_nm_utils_gvalue_array_validate (src_addr_array, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)) { - g_warning ("%s: invalid old IPv6 address type", __func__); - return; - } - - dst_addr_array = g_value_array_new (3); - - src_addr = g_value_array_get_nth (src_addr_array, 0); - g_value_array_append (dst_addr_array, src_addr); - src_prefix = g_value_array_get_nth (src_addr_array, 1); - g_value_array_append (dst_addr_array, src_prefix); - - /* Blank Gateway */ - g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY); - ba = g_byte_array_new (); - g_byte_array_append (ba, (guint8 *) "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16); - g_value_take_boxed (&element, ba); - g_value_array_append (dst_addr_array, &element); - g_value_unset (&element); - - g_ptr_array_add (dst_outer_array, dst_addr_array); - } - - g_value_take_boxed (dst_value, dst_outer_array); -} - -void -_nm_value_transforms_register (void) -{ - static gboolean registered = FALSE; - - if (G_UNLIKELY (!registered)) { - g_value_register_transform_func (DBUS_TYPE_G_OBJECT_PATH, - G_TYPE_STRING, - _nm_utils_convert_op_to_string); - g_value_register_transform_func (G_TYPE_STRV, - DBUS_TYPE_G_LIST_OF_STRING, - _nm_utils_convert_strv_to_slist); - g_value_register_transform_func (DBUS_TYPE_G_LIST_OF_STRING, - G_TYPE_STRV, - _nm_utils_convert_slist_to_strv); - g_value_register_transform_func (G_TYPE_STRV, - DBUS_TYPE_G_ARRAY_OF_STRING, - _nm_utils_convert_strv_to_ptrarray); - g_value_register_transform_func (DBUS_TYPE_G_LIST_OF_STRING, - G_TYPE_STRING, - _nm_utils_convert_string_list_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_STRING, - G_TYPE_STRING, - _nm_utils_convert_string_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, - G_TYPE_STRING, - _nm_utils_convert_op_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_UINT_ARRAY, - G_TYPE_STRING, - _nm_utils_convert_uint_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, - G_TYPE_STRING, - _nm_utils_convert_ip4_addr_route_struct_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_STRING, - _nm_utils_convert_gvalue_hash_to_string); - g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_STRING, - G_TYPE_STRING, - _nm_utils_convert_string_hash_to_string); - g_value_register_transform_func (DBUS_TYPE_G_UCHAR_ARRAY, - G_TYPE_STRING, - _nm_utils_convert_byte_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR, - G_TYPE_STRING, - _nm_utils_convert_ip6_dns_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, - G_TYPE_STRING, - _nm_utils_convert_ip6_addr_struct_array_to_string); - g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE, - G_TYPE_STRING, - _nm_utils_convert_ip6_route_struct_array_to_string); - g_value_register_transform_func (OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, - DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS, - _nm_utils_convert_old_ip6_addr_array); - registered = TRUE; - } -} diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am index 294b2afd95..bb7173df5c 100644 --- a/libnm-core/tests/Makefile.am +++ b/libnm-core/tests/Makefile.am @@ -9,7 +9,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DTEST_CERT_DIR=\"$(certsdir)\" noinst_PROGRAMS = \ @@ -22,8 +21,7 @@ noinst_PROGRAMS = \ LDADD = \ $(top_builddir)/libnm-core/libnm-core.la \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) + $(GLIB_LIBS) check-local: test-crypto test-setting-8021x # Private key and CA certificate in the same file (PEM) diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 59ff7df39e..9607940584 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -20,7 +20,6 @@ */ #include <glib.h> -#include <dbus/dbus-glib.h> #include <string.h> #include <nm-utils.h> @@ -40,7 +39,6 @@ #include "nm-setting-bond.h" #include "nm-utils.h" #include "nm-utils-private.h" -#include "nm-dbus-glib-types.h" #include "nm-test-utils.h" @@ -181,8 +179,8 @@ test_setting_vpn_update_secrets (void) { NMConnection *connection; NMSettingVpn *s_vpn; - GHashTable *settings, *vpn, *secrets; - GValue val = G_VALUE_INIT; + GVariantBuilder settings_builder, vpn_builder, secrets_builder; + GVariant *settings; gboolean success; GError *error = NULL; const char *tmp; @@ -202,18 +200,20 @@ test_setting_vpn_update_secrets (void) "error creating vpn setting"); nm_connection_add_setting (connection, NM_SETTING (s_vpn)); - settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_hash_table_destroy); - vpn = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_value_unset); - g_hash_table_insert (settings, NM_SETTING_VPN_SETTING_NAME, vpn); + g_variant_builder_init (&settings_builder, NM_VARIANT_TYPE_CONNECTION); + g_variant_builder_init (&vpn_builder, NM_VARIANT_TYPE_SETTING); + g_variant_builder_init (&secrets_builder, G_VARIANT_TYPE ("a{ss}")); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); - g_value_init (&val, G_TYPE_HASH_TABLE); - g_value_take_boxed (&val, secrets); - g_hash_table_insert (vpn, NM_SETTING_VPN_SECRETS, &val); + g_variant_builder_add (&secrets_builder, "{ss}", key1, val1); + g_variant_builder_add (&secrets_builder, "{ss}", key2, val2); - /* Add some secrets */ - g_hash_table_insert (secrets, (char *) key1, (char *) val1); - g_hash_table_insert (secrets, (char *) key2, (char *) val2); + g_variant_builder_add (&vpn_builder, "{sv}", + NM_SETTING_VPN_SECRETS, + g_variant_builder_end (&secrets_builder)); + g_variant_builder_add (&settings_builder, "{sa{sv}}", + NM_SETTING_VPN_SETTING_NAME, + &vpn_builder); + settings = g_variant_builder_end (&settings_builder); success = nm_connection_update_secrets (connection, NM_SETTING_VPN_SETTING_NAME, settings, &error); ASSERT (success == TRUE, @@ -232,7 +232,7 @@ test_setting_vpn_update_secrets (void) ASSERT (strcmp (tmp, val2) == 0, "vpn-update-secrets", "unexpected key #2 value"); - g_hash_table_destroy (settings); + g_variant_unref (settings); g_object_unref (connection); } @@ -581,117 +581,132 @@ make_test_wsec_setting (const char *detail) return s_wsec; } +#define ASSERT_CONTAINS(vardict, key, test_name, msg) \ + { \ + GVariant *value; \ + value = g_variant_lookup_value (vardict, key, NULL); \ + ASSERT (value != NULL, test_name, msg); \ + g_variant_unref (value); \ + } + +#define ASSERT_NOT_CONTAINS(vardict, key, test_name, msg) \ + { \ + GVariant *value; \ + value = g_variant_lookup_value (vardict, key, NULL); \ + ASSERT (value == NULL, test_name, msg); \ + } + static void -test_setting_to_hash_all (void) +test_setting_to_variant_all (void) { NMSettingWirelessSecurity *s_wsec; - GHashTable *hash; + GVariant *hash; s_wsec = make_test_wsec_setting ("setting-to-hash-all"); - hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL); + hash = nm_setting_to_variant (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL); /* Make sure all keys are there */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK), + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_PSK, "setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_PSK); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, "setting-to-hash-all", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); - g_hash_table_destroy (hash); + g_variant_unref (hash); g_object_unref (s_wsec); } static void -test_setting_to_hash_no_secrets (void) +test_setting_to_variant_no_secrets (void) { NMSettingWirelessSecurity *s_wsec; - GHashTable *hash; + GVariant *hash; s_wsec = make_test_wsec_setting ("setting-to-hash-no-secrets"); - hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_NO_SECRETS); + hash = nm_setting_to_variant (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_NO_SECRETS); /* Make sure non-secret keys are there */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), - "setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), - "setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + "setting-to-hash-no-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); /* Make sure secrets are not there */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK) == NULL, - "setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_PSK); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0) == NULL, - "setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); + ASSERT_NOT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_PSK, + "setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_PSK); + ASSERT_NOT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + "setting-to-hash-no-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); - g_hash_table_destroy (hash); + g_variant_unref (hash); g_object_unref (s_wsec); } static void -test_setting_to_hash_only_secrets (void) +test_setting_to_variant_only_secrets (void) { NMSettingWirelessSecurity *s_wsec; - GHashTable *hash; + GVariant *hash; s_wsec = make_test_wsec_setting ("setting-to-hash-only-secrets"); - hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ONLY_SECRETS); + hash = nm_setting_to_variant (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ONLY_SECRETS); - /* Make sure non-secret keys are there */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT) == NULL, - "setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME) == NULL, - "setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); + /* Make sure non-secret keys are not there */ + ASSERT_NOT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); + ASSERT_NOT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + "setting-to-hash-only-secrets", "unexpectedly present " NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); - /* Make sure secrets are not there */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_PSK), - "setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_PSK); - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), - "setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); + /* Make sure secrets are there */ + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_PSK, + "setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_PSK); + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + "setting-to-hash-only-secrets", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); - g_hash_table_destroy (hash); + g_variant_unref (hash); g_object_unref (s_wsec); } static void -test_connection_to_hash_setting_name (void) +test_connection_to_variant_setting_name (void) { NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GHashTable *hash; + GVariant *hash; connection = nm_connection_new (); s_wsec = make_test_wsec_setting ("connection-to-hash-setting-name"); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); - hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); + hash = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ALL); /* Make sure the keys of the first level hash are setting names, not * the GType name of the setting objects. */ - ASSERT (g_hash_table_lookup (hash, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) != NULL, - "connection-to-hash-setting-name", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); + ASSERT_CONTAINS (hash, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, + "connection-to-hash-setting-name", "unexpectedly missing " NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - g_hash_table_destroy (hash); + g_variant_unref (hash); g_object_unref (connection); } static void -test_setting_new_from_hash (void) +test_setting_new_from_variant (void) { NMSettingWirelessSecurity *s_wsec; - GHashTable *hash; + GVariant *hash; s_wsec = make_test_wsec_setting ("setting-to-hash-all"); - hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL); + hash = nm_setting_to_variant (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL); g_object_unref (s_wsec); - s_wsec = (NMSettingWirelessSecurity *) nm_setting_new_from_hash (NM_TYPE_SETTING_WIRELESS_SECURITY, hash); - g_hash_table_destroy (hash); + s_wsec = (NMSettingWirelessSecurity *) nm_setting_new_from_variant (NM_TYPE_SETTING_WIRELESS_SECURITY, hash); + g_variant_unref (hash); g_assert (s_wsec); g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "wpa-psk"); @@ -737,73 +752,61 @@ new_test_connection (void) return connection; } -static GValue * -string_to_gvalue (const char *str) -{ - GValue *val; - - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, str); - return val; -} - -static void -destroy_gvalue (gpointer data) -{ - g_value_unset ((GValue *) data); - g_slice_free (GValue, data); -} - -static GHashTable * +static GVariant * new_connection_hash (char **out_uuid, const char **out_expected_id, const char **out_expected_ip6_method) { - GHashTable *hash; - GHashTable *setting; + GVariantBuilder conn_builder, setting_builder; - hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy); + g_variant_builder_init (&conn_builder, NM_VARIANT_TYPE_CONNECTION); *out_uuid = nm_utils_uuid_generate (); *out_expected_id = "My happy connection"; *out_expected_ip6_method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL; /* Connection setting */ - setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue); - g_hash_table_insert (setting, - g_strdup (NM_SETTING_NAME), - string_to_gvalue (NM_SETTING_CONNECTION_SETTING_NAME)); - g_hash_table_insert (setting, - g_strdup (NM_SETTING_CONNECTION_ID), - string_to_gvalue (*out_expected_id)); - g_hash_table_insert (setting, - g_strdup (NM_SETTING_CONNECTION_UUID), - string_to_gvalue (*out_uuid)); - g_hash_table_insert (setting, - g_strdup (NM_SETTING_CONNECTION_TYPE), - string_to_gvalue (NM_SETTING_WIRED_SETTING_NAME)); - g_hash_table_insert (hash, g_strdup (NM_SETTING_CONNECTION_SETTING_NAME), setting); + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_NAME, + g_variant_new_string (NM_SETTING_CONNECTION_SETTING_NAME)); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_ID, + g_variant_new_string (*out_expected_id)); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_UUID, + g_variant_new_string (*out_uuid)); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_CONNECTION_TYPE, + g_variant_new_string (NM_SETTING_WIRED_SETTING_NAME)); + + g_variant_builder_add (&conn_builder, "{sa{sv}}", + NM_SETTING_CONNECTION_SETTING_NAME, + &setting_builder); /* Wired setting */ - setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue); - g_hash_table_insert (hash, g_strdup (NM_SETTING_WIRED_SETTING_NAME), setting); + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + g_variant_builder_add (&conn_builder, "{sa{sv}}", + NM_SETTING_WIRED_SETTING_NAME, + &setting_builder); /* IP6 */ - setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue); - g_hash_table_insert (setting, - g_strdup (NM_SETTING_IP6_CONFIG_METHOD), - string_to_gvalue (*out_expected_ip6_method)); - g_hash_table_insert (hash, g_strdup (NM_SETTING_IP6_CONFIG_SETTING_NAME), setting); + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_IP6_CONFIG_METHOD, + g_variant_new_string (*out_expected_ip6_method)); + g_variant_builder_add (&conn_builder, "{sa{sv}}", + NM_SETTING_IP6_CONFIG_SETTING_NAME, + &setting_builder); - return hash; + return g_variant_builder_end (&conn_builder); } static void test_connection_replace_settings () { NMConnection *connection; - GHashTable *new_settings; + GVariant *new_settings; GError *error = NULL; gboolean success; NMSettingConnection *s_con; @@ -834,7 +837,7 @@ test_connection_replace_settings () g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method); g_free (uuid); - g_hash_table_destroy (new_settings); + g_variant_unref (new_settings); g_object_unref (connection); } @@ -900,10 +903,10 @@ test_connection_replace_settings_from_connection () } static void -test_connection_new_from_hash () +test_connection_new_from_variant () { NMConnection *connection; - GHashTable *new_settings; + GVariant *new_settings; GError *error = NULL; NMSettingConnection *s_con; NMSettingIP6Config *s_ip6; @@ -914,7 +917,7 @@ test_connection_new_from_hash () g_assert (new_settings); /* Replace settings and test */ - connection = nm_connection_new_from_hash (new_settings, &error); + connection = nm_connection_new_from_variant (new_settings, &error); g_assert_no_error (error); g_assert (connection); @@ -931,7 +934,7 @@ test_connection_new_from_hash () g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method); g_free (uuid); - g_hash_table_destroy (new_settings); + g_variant_unref (new_settings); g_object_unref (connection); } @@ -2579,9 +2582,9 @@ int main (int argc, char **argv) test_setting_gsm_apn_bad_chars (); test_setting_gsm_apn_underscore (); test_setting_gsm_without_number (); - test_setting_to_hash_all (); - test_setting_to_hash_no_secrets (); - test_setting_to_hash_only_secrets (); + test_setting_to_variant_all (); + test_setting_to_variant_no_secrets (); + test_setting_to_variant_only_secrets (); test_setting_compare_id (); test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS, TRUE); test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS, TRUE); @@ -2593,11 +2596,11 @@ int main (int argc, char **argv) test_setting_compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_EXACT, FALSE); test_setting_old_uuid (); - test_connection_to_hash_setting_name (); - test_setting_new_from_hash (); + test_connection_to_variant_setting_name (); + test_setting_new_from_variant (); test_connection_replace_settings (); test_connection_replace_settings_from_connection (); - test_connection_new_from_hash (); + test_connection_new_from_variant (); test_connection_verify_sets_interface_name (); test_connection_normalize_virtual_iface_name (); diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c index faaf60c1a3..c09c3183bd 100644 --- a/libnm-core/tests/test-secrets.c +++ b/libnm-core/tests/test-secrets.c @@ -441,34 +441,20 @@ wifi_connection_new (void) return connection; } -static void -value_destroy (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - -static GValue * -string_to_gvalue (const char *str) +static GVariant * +build_wep_secrets (const char *wepkey) { - GValue *val = g_slice_new0 (GValue); - - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, str); - return val; -} + GVariantBuilder builder; -static GValue * -uint_to_gvalue (guint32 i) -{ - GValue *val; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + g_variant_builder_add (&builder, "{sv}", + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + g_variant_new_string (wepkey)); + g_variant_builder_add (&builder, "{sv}", + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + g_variant_new_uint32 (NM_WEP_KEY_TYPE_KEY)); - val = g_slice_new0 (GValue); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, i); - return val; + return g_variant_builder_end (&builder); } static void @@ -476,7 +462,7 @@ test_update_secrets_wifi_single_setting (void) { NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GHashTable *secrets; + GVariant *secrets; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -486,11 +472,7 @@ test_update_secrets_wifi_single_setting (void) connection = wifi_connection_new (); - /* Build up the secrets hash */ - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY)); - + secrets = build_wep_secrets (wepkey); success = nm_connection_update_secrets (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, secrets, @@ -498,6 +480,8 @@ test_update_secrets_wifi_single_setting (void) g_assert_no_error (error); g_assert (success); + g_variant_unref (secrets); + /* Make sure the secret is now in the connection */ s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); @@ -512,7 +496,8 @@ test_update_secrets_wifi_full_hash (void) { NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GHashTable *secrets, *all; + GVariantBuilder builder; + GVariant *all; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -524,12 +509,11 @@ test_update_secrets_wifi_full_hash (void) connection = wifi_connection_new (); - /* Build up the secrets hash */ - all = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_hash_table_destroy); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY)); - g_hash_table_insert (all, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, secrets); + g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION); + g_variant_builder_add (&builder, "{s@a{sv}}", + NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, + build_wep_secrets (wepkey)); + all = g_variant_builder_end (&builder); success = nm_connection_update_secrets (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, @@ -538,6 +522,8 @@ test_update_secrets_wifi_full_hash (void) g_assert_no_error (error); g_assert (success); + g_variant_unref (all); + /* Make sure the secret is now in the connection */ s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); @@ -551,7 +537,7 @@ static void test_update_secrets_wifi_bad_setting_name (void) { NMConnection *connection; - GHashTable *secrets; + GVariant *secrets; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -562,10 +548,7 @@ test_update_secrets_wifi_bad_setting_name (void) connection = wifi_connection_new (); - /* Build up the secrets hash */ - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY)); + secrets = build_wep_secrets (wepkey); success = nm_connection_update_secrets (connection, "asdfasdfasdfasf", @@ -574,6 +557,8 @@ test_update_secrets_wifi_bad_setting_name (void) g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); g_assert (success == FALSE); + g_variant_unref (secrets); + g_object_unref (connection); } @@ -582,7 +567,10 @@ test_update_secrets_whole_connection (void) { NMConnection *connection; NMSettingWirelessSecurity *s_wsec; - GHashTable *secrets, *wsec_hash; + GVariantBuilder conn_builder, setting_builder; + GVariantIter conn_iter, setting_iter; + GVariant *secrets, *copy, *setting_hash, *property_val; + const char *setting_name, *property_name; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -594,15 +582,41 @@ test_update_secrets_whole_connection (void) connection = wifi_connection_new (); /* Build up the secrets hash */ - secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); - wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - g_assert (wsec_hash); - g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); + secrets = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ALL); - success = nm_connection_update_secrets (connection, NULL, secrets, &error); + /* GVariants are immutable, so we have to copy it, and add the WEP key + * while copying the wireless-security hash... + */ + g_variant_builder_init (&conn_builder, NM_VARIANT_TYPE_CONNECTION); + g_variant_iter_init (&conn_iter, secrets); + while (g_variant_iter_next (&conn_iter, "{&s@a{sv}}", &setting_name, &setting_hash)) { + if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0) { + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + g_variant_iter_init (&setting_iter, setting_hash); + while (g_variant_iter_next (&setting_iter, "{&sv}", &property_name, &property_val)) { + g_variant_builder_add (&setting_builder, "{sv}", + property_name, + property_val); + } + g_variant_builder_add (&setting_builder, "{sv}", + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, + g_variant_new_string (wepkey)); + + g_variant_unref (setting_hash); + setting_hash = g_variant_builder_end (&setting_builder); + } + + g_variant_builder_add (&conn_builder, "{s@a{sv}}", setting_name, setting_hash); + } + copy = g_variant_builder_end (&conn_builder); + g_variant_unref (secrets); + + success = nm_connection_update_secrets (connection, NULL, copy, &error); g_assert_no_error (error); g_assert (success == TRUE); + g_variant_unref (copy); + s_wsec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wsec); g_assert_cmpstr (nm_setting_wireless_security_get_wep_key (s_wsec, 0), ==, wepkey); @@ -614,17 +628,18 @@ static void test_update_secrets_whole_connection_empty_hash (void) { NMConnection *connection; - GHashTable *secrets; + GVariant *secrets; GError *error = NULL; gboolean success; /* Test that updating secrets with an empty hash returns success */ connection = wifi_connection_new (); - secrets = g_hash_table_new (g_str_hash, g_str_equal); + secrets = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); success = nm_connection_update_secrets (connection, NULL, secrets, &error); g_assert_no_error (error); g_assert (success == TRUE); + g_variant_unref (secrets); g_object_unref (connection); } @@ -632,7 +647,11 @@ static void test_update_secrets_whole_connection_bad_setting (void) { NMConnection *connection; - GHashTable *secrets, *wsec_hash; + NMSettingWirelessSecurity *s_wsec; + GVariant *secrets, *copy, *setting_hash; + const char *setting_name; + GVariantBuilder conn_builder; + GVariantIter conn_iter; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -642,25 +661,36 @@ test_update_secrets_whole_connection_bad_setting (void) */ connection = wifi_connection_new (); + s_wsec = nm_connection_get_setting_wireless_security (connection); + g_assert (s_wsec != NULL); + g_object_set (G_OBJECT (s_wsec), + NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, wepkey, + NULL); /* Build up the secrets hash */ - secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); - wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - g_assert (wsec_hash); - g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); - - /* Steal the wsec setting hash so it's not deallocated, and stuff it back - * in with a different name so we ensure libnm is returning the right - * error when it finds an entry in the connection hash that doesn't match - * any setting in the connection. + secrets = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ALL); + + /* Copy the hash, renaming the wireless-security setting in the process + * (so we ensure libnm is returning the right error when it finds an entry + * in the connection hash that doesn't match any setting in the connection). */ - g_hash_table_steal (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - g_hash_table_insert (secrets, "asdfasdfasdfasdf", wsec_hash); + g_variant_builder_init (&conn_builder, NM_VARIANT_TYPE_CONNECTION); + g_variant_iter_init (&conn_iter, secrets); + while (g_variant_iter_next (&conn_iter, "{&s@a{sv}}", &setting_name, &setting_hash)) { + if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0) + setting_name = "asdfasdfasdfasdf"; + + g_variant_builder_add (&conn_builder, "{s@a{sv}}", setting_name, setting_hash); + g_variant_unref (setting_hash); + } + copy = g_variant_builder_end (&conn_builder); + g_variant_unref (secrets); - success = nm_connection_update_secrets (connection, NULL, secrets, &error); + success = nm_connection_update_secrets (connection, NULL, copy, &error); g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); g_assert (success == FALSE); + g_variant_unref (copy); g_object_unref (connection); } @@ -668,7 +698,7 @@ static void test_update_secrets_whole_connection_empty_base_setting (void) { NMConnection *connection; - GHashTable *secrets; + GVariant *secrets, *setting; GError *error = NULL; gboolean success; @@ -677,9 +707,12 @@ test_update_secrets_whole_connection_empty_base_setting (void) */ connection = wifi_connection_new (); - secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ONLY_SECRETS); - g_assert_cmpint (g_hash_table_size (secrets), ==, 1); - g_assert (g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SETTING_NAME)); + secrets = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ONLY_SECRETS); + g_assert_cmpint (g_variant_n_children (secrets), ==, 1); + + setting = g_variant_lookup_value (secrets, NM_SETTING_WIRELESS_SETTING_NAME, NULL); + g_assert (setting != NULL); + g_variant_unref (setting); success = nm_connection_update_secrets (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, @@ -688,7 +721,7 @@ test_update_secrets_whole_connection_empty_base_setting (void) g_assert_no_error (error); g_assert (success); - g_hash_table_destroy (secrets); + g_variant_unref (secrets); g_object_unref (connection); } @@ -696,7 +729,7 @@ static void test_update_secrets_null_setting_name_with_setting_hash (void) { NMConnection *connection; - GHashTable *secrets; + GVariant *secrets; GError *error = NULL; gboolean success; const char *wepkey = "11111111111111111111111111"; @@ -705,15 +738,13 @@ test_update_secrets_null_setting_name_with_setting_hash (void) connection = wifi_connection_new (); - secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); - g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY)); + secrets = build_wep_secrets (wepkey); success = nm_connection_update_secrets (connection, NULL, secrets, &error); g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND); g_assert (!success); - g_hash_table_destroy (secrets); + g_variant_unref (secrets); g_object_unref (connection); } diff --git a/libnm/Makefile.am b/libnm/Makefile.am index 7bfc410a6f..69d3cd9d2c 100644 --- a/libnm/Makefile.am +++ b/libnm/Makefile.am @@ -20,7 +20,6 @@ lib_LTLIBRARIES = libnm.la libnm_la_CFLAGS = \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(GUDEV_CFLAGS) \ -DNMRUNDIR=\"$(nmrundir)\" @@ -62,8 +61,7 @@ libnm_la_private_headers = \ nm-device-private.h \ nm-object-cache.h \ nm-object-private.h \ - nm-remote-connection-private.h \ - nm-types-private.h + nm-remote-connection-private.h libnm_la_csources = \ nm-access-point.c \ @@ -94,6 +92,7 @@ libnm_la_csources = \ nm-remote-connection.c \ nm-remote-settings.c \ nm-secret-agent.c \ + nm-secret-agent-generated.c \ nm-types.c \ nm-vpn-connection.c \ nm-wimax-nsp.c @@ -102,8 +101,14 @@ libnm_la_SOURCES = \ $(libnm_la_csources) \ $(libnm_la_private_headers) -nm-secret-agent-glue.h: $(top_srcdir)/introspection/nm-secret-agent.xml - $(AM_V_GEN) dbus-binding-tool --prefix=nm_secret_agent --mode=glib-server --output=$@ $< +nm-secret-agent-generated.h: $(top_srcdir)/introspection/nm-secret-agent.xml + $(AM_V_GEN) gdbus-codegen \ + --generate-c-code $(basename $@) \ + --c-namespace NMPriv \ + --interface-prefix org.freedesktop.NetworkManager \ + $< + +nm-secret-agent-generated.c: nm-secret-agent-generated.h GLIB_GENERATED = nm-enum-types.h nm-enum-types.c nm_enum_types_sources = $(libnminclude_HEADERS) @@ -111,13 +116,14 @@ GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include <nm-core-enum-t GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM BUILT_SOURCES = \ - nm-vpn-plugin-glue.h \ - nm-secret-agent-glue.h + nm-vpn-plugin-generated.c \ + nm-vpn-plugin-generated.h \ + nm-secret-agent-generated.c \ + nm-secret-agent-generated.h libnm_la_LIBADD = \ $(top_builddir)/libnm-core/libnm-core.la \ $(GLIB_LIBS) \ - $(DBUS_LIBS) \ $(UUID_LIBS) \ $(GUDEV_LIBS) @@ -141,17 +147,24 @@ libnmvpn_HEADERS = \ libnm_vpn_la_SOURCES = \ nm-vpn-plugin.c \ + nm-vpn-plugin-generated.c \ nm-vpn-plugin-ui-interface.c \ nm-vpn-plugin-utils.c \ nm-vpn-enum-types.c -nm-vpn-plugin-glue.h: $(top_srcdir)/introspection/nm-vpn-plugin.xml - $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_plugin --mode=glib-server --output=$@ $< +nm-vpn-plugin-generated.h: $(top_srcdir)/introspection/nm-vpn-plugin.xml + $(AM_V_GEN) gdbus-codegen \ + --generate-c-code $(basename $@) \ + --c-namespace NMPriv \ + --interface-prefix org.freedesktop.NetworkManager \ + $< + +nm-vpn-plugin-generated.c: nm-vpn-plugin-generated.h GLIB_GENERATED += nm-vpn-enum-types.h nm-vpn-enum-types.c nm_vpn_enum_types_sources = $(libnmvpn_HEADERS) -libnm_vpn_la_CFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS) -libnm_vpn_la_LIBADD = $(GLIB_LIBS) $(DBUS_LIBS) +libnm_vpn_la_CFLAGS = $(GLIB_CFLAGS) +libnm_vpn_la_LIBADD = $(GLIB_LIBS) libnm_vpn_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnm-vpn.ver \ -version-info "0:0:0" @@ -184,8 +197,8 @@ introspection_sources = \ $(libnm_la_csources) NM-1.0.gir: libnm.la -NM_1_0_gir_INCLUDES = Gio-2.0 DBusGLib-1.0 -NM_1_0_gir_PACKAGES = gio-2.0 dbus-glib-1 gudev-1.0 +NM_1_0_gir_INCLUDES = Gio-2.0 +NM_1_0_gir_PACKAGES = gio-2.0 gudev-1.0 NM_1_0_gir_EXPORT_PACKAGES = libnm NM_1_0_gir_CFLAGS = $(AM_CPPFLAGS) NM_1_0_gir_LIBS = libnm.la diff --git a/libnm/libnm.ver b/libnm/libnm.ver index c72557b02c..5c2fcd6897 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -131,6 +131,7 @@ global: nm_connection_replace_settings_from_connection; nm_connection_set_path; nm_connection_to_hash; + nm_connection_to_variant; nm_connection_update_secrets; nm_connection_verify; nm_connectivity_state_get_type; @@ -742,6 +743,7 @@ global: nm_setting_team_port_new; nm_setting_to_hash; nm_setting_to_string; + nm_setting_to_variant; nm_setting_update_secrets; nm_setting_verify; nm_setting_vlan_add_priority; @@ -893,18 +895,28 @@ global: nm_utils_inet6_ntop; nm_utils_init; nm_utils_ip4_addresses_from_gvalue; + nm_utils_ip4_addresses_from_variant; nm_utils_ip4_addresses_to_gvalue; + nm_utils_ip4_addresses_to_variant; + nm_utils_ip4_dns_from_variant; + nm_utils_ip4_dns_to_variant; nm_utils_ip4_get_default_prefix; nm_utils_ip4_netmask_to_prefix; nm_utils_ip4_prefix_to_netmask; nm_utils_ip4_routes_from_gvalue; + nm_utils_ip4_routes_from_variant; nm_utils_ip4_routes_to_gvalue; + nm_utils_ip4_routes_to_variant; nm_utils_ip6_addresses_from_gvalue; + nm_utils_ip6_addresses_from_variant; nm_utils_ip6_addresses_to_gvalue; - nm_utils_ip6_dns_from_gvalue; - nm_utils_ip6_dns_to_gvalue; + nm_utils_ip6_addresses_to_variant; + nm_utils_ip6_dns_from_variant; + nm_utils_ip6_dns_to_variant; nm_utils_ip6_routes_from_gvalue; + nm_utils_ip6_routes_from_variant; nm_utils_ip6_routes_to_gvalue; + nm_utils_ip6_routes_to_variant; nm_utils_is_empty_ssid; nm_utils_is_uuid; nm_utils_rsa_key_encrypt; diff --git a/libnm/nm-access-point.c b/libnm/nm-access-point.c index 0b2376d12c..b71f4f5306 100644 --- a/libnm/nm-access-point.c +++ b/libnm/nm-access-point.c @@ -32,7 +32,6 @@ #include "nm-access-point.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT) @@ -40,7 +39,7 @@ G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT) #define NM_ACCESS_POINT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACCESS_POINT, NMAccessPointPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; NM80211ApFlags flags; NM80211ApSecurityFlags wpa_flags; diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 94a9cc5f0f..b3dcf61915 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -24,7 +24,7 @@ #include "nm-dbus-interface.h" #include "nm-active-connection.h" #include "nm-object-private.h" -#include "nm-types-private.h" +#include "nm-types.h" #include "nm-device.h" #include "nm-device-private.h" #include "nm-connection.h" @@ -32,9 +32,9 @@ #include "nm-glib-compat.h" #include "nm-dbus-helpers-private.h" -static GType _nm_active_connection_type_for_path (DBusGConnection *connection, +static GType _nm_active_connection_type_for_path (GDBusConnection *connection, const char *path); -static void _nm_active_connection_type_for_path_async (DBusGConnection *connection, +static void _nm_active_connection_type_for_path_async (GDBusConnection *connection, const char *path, NMObjectTypeCallbackFunc callback, gpointer user_data); @@ -48,7 +48,7 @@ G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJEC #define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *connection; char *id; @@ -89,12 +89,12 @@ enum { }; static GType -_nm_active_connection_type_for_path (DBusGConnection *connection, +_nm_active_connection_type_for_path (GDBusConnection *connection, const char *path) { - DBusGProxy *proxy; + GDBusProxy *proxy; GError *error = NULL; - GValue value = G_VALUE_INIT; + GVariant *ret; GType type; proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties"); @@ -106,13 +106,16 @@ _nm_active_connection_type_for_path (DBusGConnection *connection, /* Have to create an NMVpnConnection if it's a VPN connection, otherwise * a plain NMActiveConnection. */ - if (dbus_g_proxy_call (proxy, - "Get", &error, - G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - G_TYPE_STRING, "Vpn", - G_TYPE_INVALID, - G_TYPE_VALUE, &value, G_TYPE_INVALID)) { - if (g_value_get_boolean (&value)) + ret = g_dbus_proxy_call_sync (proxy, + "Get", + g_variant_new ("(ss)", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Vpn"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (ret) { + gboolean is_vpn; + + g_variant_get (ret, "(b)", &is_vpn); + if (is_vpn) type = NM_TYPE_VPN_CONNECTION; else type = NM_TYPE_ACTIVE_CONNECTION; @@ -128,24 +131,27 @@ _nm_active_connection_type_for_path (DBusGConnection *connection, } typedef struct { - DBusGConnection *connection; + GDBusConnection *connection; NMObjectTypeCallbackFunc callback; gpointer user_data; } NMActiveConnectionAsyncData; static void -async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +async_got_type (GObject *source, GAsyncResult *result, gpointer user_data) { + GDBusProxy *proxy = G_DBUS_PROXY (source); NMActiveConnectionAsyncData *async_data = user_data; - GValue value = G_VALUE_INIT; - const char *path = dbus_g_proxy_get_path (proxy); + GVariant *ret; + const char *path = g_dbus_proxy_get_object_path (proxy); GError *error = NULL; GType type; - if (dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_VALUE, &value, - G_TYPE_INVALID)) { - if (g_value_get_boolean (&value)) + ret = g_dbus_proxy_call_finish (proxy, result, &error); + if (ret) { + gboolean is_vpn; + + g_variant_get (ret, "(b)", &is_vpn); + if (is_vpn) type = NM_TYPE_VPN_CONNECTION; else type = NM_TYPE_ACTIVE_CONNECTION; @@ -161,13 +167,13 @@ async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) } static void -_nm_active_connection_type_for_path_async (DBusGConnection *connection, +_nm_active_connection_type_for_path_async (GDBusConnection *connection, const char *path, NMObjectTypeCallbackFunc callback, gpointer user_data) { NMActiveConnectionAsyncData *async_data; - DBusGProxy *proxy; + GDBusProxy *proxy; async_data = g_slice_new (NMActiveConnectionAsyncData); async_data->connection = connection; @@ -175,11 +181,12 @@ _nm_active_connection_type_for_path_async (DBusGConnection *connection, async_data->user_data = user_data; proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties"); - dbus_g_proxy_begin_call (proxy, "Get", - async_got_type, async_data, NULL, - G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - G_TYPE_STRING, "Vpn", - G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "Get", + g_variant_new ("(ss)", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Vpn"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + async_got_type, async_data); } /** diff --git a/libnm/nm-client.c b/libnm/nm-client.c index a5ddc53f59..f390988f08 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -19,7 +19,6 @@ * Copyright 2007 - 2013 Red Hat, Inc. */ -#include <dbus/dbus-glib.h> #include <string.h> #include <nm-utils.h> @@ -27,12 +26,11 @@ #include "nm-device-ethernet.h" #include "nm-device-wifi.h" #include "nm-device-private.h" -#include "nm-types-private.h" +#include "nm-types.h" #include "nm-object-private.h" #include "nm-active-connection.h" #include "nm-vpn-connection.h" #include "nm-object-cache.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled); @@ -50,7 +48,7 @@ G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, NM_TYPE_OBJECT, #define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate)) typedef struct { - DBusGProxy *client_proxy; + GDBusProxy *client_proxy; char *version; NMState state; gboolean startup; @@ -60,7 +58,7 @@ typedef struct { NMActiveConnection *primary_connection; NMActiveConnection *activating_connection; - DBusGProxyCall *perm_call; + gboolean perm_call; GHashTable *permissions; /* Activations waiting for their NMActiveConnection @@ -166,7 +164,8 @@ wireless_enabled_cb (GObject *object, GParamSpec *pspec, gpointer user_data) poke_wireless_devices_with_rf_status (NM_CLIENT (object)); } -static void client_recheck_permissions (DBusGProxy *proxy, gpointer user_data); +static void client_dbus_signal (GDBusProxy *proxy, const char *sender_name, const char *signal_name, + GVariant *parameters, gpointer user_data); static void active_connections_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data); static void object_creation_failed_cb (GObject *object, GError *error, char *failed_path); @@ -199,12 +198,8 @@ init_dbus_properties (NMObject *object) property_info); /* Permissions */ - dbus_g_proxy_add_signal (priv->client_proxy, "CheckPermissions", G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->client_proxy, - "CheckPermissions", - G_CALLBACK (client_recheck_permissions), - object, - NULL); + g_signal_connect (priv->client_proxy, "g-signal", + G_CALLBACK (client_dbus_signal), object); g_signal_connect (object, "notify::" NM_OBJECT_NM_RUNNING, G_CALLBACK (nm_running_changed_cb), NULL); @@ -273,7 +268,7 @@ nm_permission_result_to_client (const char *nm) } static void -update_permissions (NMClient *self, GHashTable *permissions) +update_permissions (NMClient *self, GVariant *permissions) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); GHashTableIter iter; @@ -287,11 +282,14 @@ update_permissions (NMClient *self, GHashTable *permissions) g_hash_table_remove_all (priv->permissions); if (permissions) { + GVariantIter viter; + const char *pkey, *pvalue; + /* Process new permissions */ - g_hash_table_iter_init (&iter, permissions); - while (g_hash_table_iter_next (&iter, &key, &value)) { - perm = nm_permission_to_client ((const char *) key); - perm_result = nm_permission_result_to_client ((const char *) value); + g_variant_iter_init (&viter, permissions); + while (g_variant_iter_next (&viter, "{&s&s}", &pkey, &pvalue)) { + perm = nm_permission_to_client (pkey); + perm_result = nm_permission_result_to_client (pvalue); if (perm) { g_hash_table_insert (priv->permissions, GUINT_TO_POINTER (perm), @@ -328,50 +326,83 @@ update_permissions (NMClient *self, GHashTable *permissions) static gboolean get_permissions_sync (NMClient *self, GError **error) { - gboolean success; - GHashTable *permissions = NULL; - - success = dbus_g_proxy_call_with_timeout (NM_CLIENT_GET_PRIVATE (self)->client_proxy, - "GetPermissions", 3000, error, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_STRING, &permissions, G_TYPE_INVALID); - update_permissions (self, success ? permissions : NULL); - if (permissions) - g_hash_table_destroy (permissions); - - return success; + GVariant *ret, *permissions; + + ret = g_dbus_proxy_call_sync (NM_CLIENT_GET_PRIVATE (self)->client_proxy, + "GetPermissions", + NULL, + G_DBUS_CALL_FLAGS_NONE, 3000, + NULL, error); + if (ret) { + g_variant_get (ret, "(@a{ss})", &permissions); + update_permissions (self, permissions); + g_variant_unref (permissions); + g_variant_unref (ret); + return TRUE; + } else { + update_permissions (self, NULL); + return FALSE; + } } static void -get_permissions_reply (DBusGProxy *proxy, - DBusGProxyCall *call, +get_permissions_reply (GObject *object, + GAsyncResult *result, gpointer user_data) { + GDBusProxy *proxy = G_DBUS_PROXY (object); NMClient *self = NM_CLIENT (user_data); - GHashTable *permissions; - GError *error = NULL; + NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); + GVariant *ret, *permissions; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_STRING, &permissions, - G_TYPE_INVALID); - NM_CLIENT_GET_PRIVATE (self)->perm_call = NULL; - update_permissions (NM_CLIENT (user_data), error ? NULL : permissions); - g_clear_error (&error); + /* If we are holding the last ref on @self, then abort */ + g_object_add_weak_pointer (G_OBJECT (self), (gpointer *) &self); + g_object_unref (self); + if (!self) + return; + g_object_remove_weak_pointer (G_OBJECT (self), (gpointer *) &self); + + ret = g_dbus_proxy_call_finish (proxy, result, NULL); + if (ret) { + g_variant_get (ret, "(a{ss})", &permissions); + update_permissions (self, permissions); + g_variant_unref (permissions); + g_variant_unref (ret); + } else + update_permissions (self, NULL); + + priv->perm_call = FALSE; } static void -client_recheck_permissions (DBusGProxy *proxy, gpointer user_data) +client_recheck_permissions (NMClient *self) { - NMClient *self = NM_CLIENT (user_data); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); if (!priv->perm_call) { - priv->perm_call = dbus_g_proxy_begin_call (NM_CLIENT_GET_PRIVATE (self)->client_proxy, "GetPermissions", - get_permissions_reply, self, NULL, - G_TYPE_INVALID); + priv->perm_call = TRUE; + g_dbus_proxy_call (NM_CLIENT_GET_PRIVATE (self)->client_proxy, + "GetPermissions", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + get_permissions_reply, g_object_ref (self)); } } +static void +client_dbus_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + if (strcmp (signal_name, "CheckPermissions") != 0) + return; + + client_recheck_permissions (NM_CLIENT (user_data)); +} + /** * nm_client_get_devices: * @client: a #NMClient @@ -559,24 +590,23 @@ recheck_pending_activations (NMClient *self, const char *failed_path, GError *er } static void -activate_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +activate_cb (GObject *object, + GAsyncResult *result, gpointer user_data) { ActivateInfo *info = user_data; - char *path; + GVariant *ret; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_OBJECT_PATH, &path, - G_TYPE_INVALID); - if (error) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, &error); + if (ret) { + g_variant_get (ret, "(o)", &info->active_path); + g_variant_unref (ret); + recheck_pending_activations (info->client, NULL, NULL); + } else { activate_info_complete (info, NULL, error); activate_info_free (info); g_clear_error (&error); - } else { - info->active_path = path; - recheck_pending_activations (info->client, NULL, NULL); } } @@ -653,35 +683,35 @@ nm_client_activate_connection (NMClient *client, return; } - dbus_g_proxy_begin_call (priv->client_proxy, "ActivateConnection", - activate_cb, info, NULL, - DBUS_TYPE_G_OBJECT_PATH, connection ? nm_connection_get_path (connection) : "/", - DBUS_TYPE_G_OBJECT_PATH, device ? nm_object_get_path (NM_OBJECT (device)) : "/", - DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/", - G_TYPE_INVALID); + g_dbus_proxy_call (priv->client_proxy, + "ActivateConnection", + g_variant_new ("(ooo)", + connection ? nm_connection_get_path (connection) : "/", + device ? nm_object_get_path (NM_OBJECT (device)) : "/", + specific_object ? specific_object : "/"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + activate_cb, info); } static void -add_activate_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +add_activate_cb (GObject *object, + GAsyncResult *result, gpointer user_data) { ActivateInfo *info = user_data; - char *connection_path; - char *active_path; + GVariant *ret; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_OBJECT_PATH, &connection_path, - DBUS_TYPE_G_OBJECT_PATH, &active_path, - G_TYPE_INVALID); - if (error) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, &error); + if (ret) { + g_variant_get (ret, "(oo)", &info->new_connection_path, &info->active_path); + g_variant_unref (ret); + recheck_pending_activations (info->client, NULL, NULL); + } else { activate_info_complete (info, NULL, error); activate_info_free (info); - } else { - info->new_connection_path = connection_path; - info->active_path = active_path; - recheck_pending_activations (info->client, NULL, NULL); + g_clear_error (&error); } } @@ -717,7 +747,7 @@ nm_client_add_and_activate_connection (NMClient *client, { NMClientPrivate *priv; ActivateInfo *info; - GHashTable *hash = NULL; + GVariant *dict = NULL; g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_DEVICE (device)); @@ -728,24 +758,27 @@ nm_client_add_and_activate_connection (NMClient *client, info->client = client; if (partial) - hash = nm_connection_to_hash (partial, NM_SETTING_HASH_FLAG_ALL); - if (!hash) - hash = g_hash_table_new (g_str_hash, g_str_equal); + dict = nm_connection_to_variant (partial, NM_SETTING_HASH_FLAG_ALL); + if (!dict) + dict = g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0); priv = NM_CLIENT_GET_PRIVATE (client); priv->pending_activations = g_slist_prepend (priv->pending_activations, info); if (nm_client_get_manager_running (client)) { - dbus_g_proxy_begin_call (priv->client_proxy, "AddAndActivateConnection", - add_activate_cb, info, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - DBUS_TYPE_G_OBJECT_PATH, nm_object_get_path (NM_OBJECT (device)), - DBUS_TYPE_G_OBJECT_PATH, specific_object ? specific_object : "/", - G_TYPE_INVALID); + g_dbus_proxy_call (priv->client_proxy, + "AddAndActivateConnection", + g_variant_new ("(a{sv}oo)", + dict, + nm_object_get_path (NM_OBJECT (device)), + specific_object ? specific_object : "/"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + add_activate_cb, info); } else info->idle_id = g_idle_add (activate_nm_not_running, info); - g_hash_table_unref (hash); + g_variant_unref (dict); } static void @@ -773,6 +806,7 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active) { NMClientPrivate *priv; const char *path; + GVariant *ret; GError *error = NULL; g_return_if_fail (NM_IS_CLIENT (client)); @@ -783,10 +817,14 @@ nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active) return; path = nm_object_get_path (NM_OBJECT (active)); - if (!dbus_g_proxy_call (priv->client_proxy, "DeactivateConnection", &error, - DBUS_TYPE_G_OBJECT_PATH, path, - G_TYPE_INVALID, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (priv->client_proxy, + "DeactivateConnection", + g_variant_new ("(o)", path), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (ret) + g_variant_unref (ret); + else { g_warning ("Could not deactivate connection '%s': %s", path, error->message); g_error_free (error); } @@ -842,20 +880,15 @@ nm_client_wireless_get_enabled (NMClient *client) void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled) { - GValue value = G_VALUE_INIT; - g_return_if_fail (NM_IS_CLIENT (client)); if (!nm_client_get_manager_running (client)) return; - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, enabled); - _nm_object_set_property (NM_OBJECT (client), NM_DBUS_INTERFACE, "WirelessEnabled", - &value); + "b", enabled); } /** @@ -900,20 +933,15 @@ nm_client_wwan_get_enabled (NMClient *client) void nm_client_wwan_set_enabled (NMClient *client, gboolean enabled) { - GValue value = G_VALUE_INIT; - g_return_if_fail (NM_IS_CLIENT (client)); if (!nm_client_get_manager_running (client)) return; - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, enabled); - _nm_object_set_property (NM_OBJECT (client), NM_DBUS_INTERFACE, "WwanEnabled", - &value); + "b", enabled); } /** @@ -958,20 +986,15 @@ nm_client_wimax_get_enabled (NMClient *client) void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled) { - GValue value = G_VALUE_INIT; - g_return_if_fail (NM_IS_CLIENT (client)); if (!nm_client_get_manager_running (client)) return; - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, enabled); - _nm_object_set_property (NM_OBJECT (client), NM_DBUS_INTERFACE, "WimaxEnabled", - &value); + "b", enabled); } /** @@ -1070,6 +1093,7 @@ nm_client_networking_get_enabled (NMClient *client) void nm_client_networking_set_enabled (NMClient *client, gboolean enable) { + GVariant *ret; GError *err = NULL; g_return_if_fail (NM_IS_CLIENT (client)); @@ -1077,10 +1101,14 @@ nm_client_networking_set_enabled (NMClient *client, gboolean enable) if (!nm_client_get_manager_running (client)) return; - if (!dbus_g_proxy_call (NM_CLIENT_GET_PRIVATE (client)->client_proxy, "Enable", &err, - G_TYPE_BOOLEAN, enable, - G_TYPE_INVALID, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (NM_CLIENT_GET_PRIVATE (client)->client_proxy, + "Enable", + g_variant_new ("(b)", enable), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &err); + if (ret) + g_variant_unref (ret); + else { g_warning ("Error enabling/disabling networking: %s", err->message); g_error_free (err); } @@ -1140,6 +1168,7 @@ gboolean nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error) { NMClientPrivate *priv; + GVariant *ret; g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (level == NULL || *level == NULL, FALSE); @@ -1158,11 +1187,17 @@ nm_client_get_logging (NMClient *client, char **level, char **domains, GError ** if (!level && !domains) return TRUE; - return dbus_g_proxy_call (priv->client_proxy, "GetLogging", error, - G_TYPE_INVALID, - G_TYPE_STRING, level, - G_TYPE_STRING, domains, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_sync (priv->client_proxy, + "GetLogging", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, error); + if (ret) { + g_variant_get (ret, "(ss)", level, domains); + g_variant_unref (ret); + return TRUE; + } else + return FALSE; } /** @@ -1181,6 +1216,7 @@ gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error) { NMClientPrivate *priv; + GVariant *ret; g_return_val_if_fail (NM_IS_CLIENT (client), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -1197,11 +1233,18 @@ nm_client_set_logging (NMClient *client, const char *level, const char *domains, if (!level && !domains) return TRUE; - return dbus_g_proxy_call (priv->client_proxy, "SetLogging", error, - G_TYPE_STRING, level ? level : "", - G_TYPE_STRING, domains ? domains : "", - G_TYPE_INVALID, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_sync (priv->client_proxy, + "SetLogging", + g_variant_new ("(ss)", + level ? level : "", + domains ? domains : ""), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, error); + if (ret) { + g_variant_unref (ret); + return TRUE; + } else + return FALSE; } /** @@ -1346,7 +1389,7 @@ nm_running_changed_cb (GObject *object, } else { _nm_object_suppress_property_updates (NM_OBJECT (client), FALSE); _nm_object_reload_properties_async (NM_OBJECT (client), updated_properties, client); - client_recheck_permissions (priv->client_proxy, client); + client_recheck_permissions (client); } } @@ -1391,71 +1434,48 @@ nm_client_check_connectivity (NMClient *client, { NMClientPrivate *priv; NMConnectivityState connectivity; + GVariant *ret; g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); priv = NM_CLIENT_GET_PRIVATE (client); - if (!dbus_g_proxy_call (priv->client_proxy, "CheckConnectivity", error, - G_TYPE_INVALID, - G_TYPE_UINT, &connectivity, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->client_proxy, + "CheckConnectivity", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (ret) { + g_variant_get (ret, "(u)", &connectivity); + g_variant_unref (ret); + } else connectivity = NM_CONNECTIVITY_UNKNOWN; return connectivity; } -typedef struct { - NMClient *client; - DBusGProxyCall *call; - GCancellable *cancellable; - guint cancelled_id; - NMConnectivityState connectivity; -} CheckConnectivityData; - static void -check_connectivity_data_free (CheckConnectivityData *ccd) -{ - if (ccd->cancellable) { - if (ccd->cancelled_id) - g_signal_handler_disconnect (ccd->cancellable, ccd->cancelled_id); - g_object_unref (ccd->cancellable); - } - - g_slice_free (CheckConnectivityData, ccd); -} - -static void -check_connectivity_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +check_connectivity_cb (GObject *object, + GAsyncResult *result, gpointer user_data) { GSimpleAsyncResult *simple = user_data; - CheckConnectivityData *ccd = g_simple_async_result_get_op_res_gpointer (simple); + GVariant *ret; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_UINT, &ccd->connectivity, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, &error); + if (ret) { + guint connectivity; + + g_variant_get (ret, "(u)", &connectivity); + g_variant_unref (ret); + g_simple_async_result_set_op_res_gssize (simple, connectivity); + } else g_simple_async_result_take_error (simple, error); g_simple_async_result_complete (simple); g_object_unref (simple); } -static void -check_connectivity_cancelled_cb (GCancellable *cancellable, - gpointer user_data) -{ - GSimpleAsyncResult *simple = user_data; - CheckConnectivityData *ccd = g_simple_async_result_get_op_res_gpointer (simple); - - g_signal_handler_disconnect (cancellable, ccd->cancelled_id); - ccd->cancelled_id = 0; - - dbus_g_proxy_cancel_call (NM_CLIENT_GET_PRIVATE (ccd->client)->client_proxy, ccd->call); - g_simple_async_result_complete_in_idle (simple); -} - /** * nm_client_check_connectivity_async: * @client: an #NMClient @@ -1476,29 +1496,18 @@ nm_client_check_connectivity_async (NMClient *client, { NMClientPrivate *priv; GSimpleAsyncResult *simple; - CheckConnectivityData *ccd; g_return_if_fail (NM_IS_CLIENT (client)); priv = NM_CLIENT_GET_PRIVATE (client); - ccd = g_slice_new (CheckConnectivityData); - ccd->client = client; - simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, nm_client_check_connectivity_async); - g_simple_async_result_set_op_res_gpointer (simple, ccd, (GDestroyNotify) check_connectivity_data_free); - - if (cancellable) { - ccd->cancellable = g_object_ref (cancellable); - ccd->cancelled_id = g_signal_connect (cancellable, "cancelled", - G_CALLBACK (check_connectivity_cancelled_cb), - simple); - g_simple_async_result_set_check_cancellable (simple, cancellable); - } - - ccd->call = dbus_g_proxy_begin_call (priv->client_proxy, "CheckConnectivity", - check_connectivity_cb, simple, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->client_proxy, + "CheckConnectivity", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, + check_connectivity_cb, simple); } /** @@ -1518,17 +1527,14 @@ nm_client_check_connectivity_finish (NMClient *client, GError **error) { GSimpleAsyncResult *simple; - CheckConnectivityData *ccd; g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN); simple = G_SIMPLE_ASYNC_RESULT (result); - ccd = g_simple_async_result_get_op_res_gpointer (simple); if (g_simple_async_result_propagate_error (simple, error)) return NM_CONNECTIVITY_UNKNOWN; - - return ccd->connectivity; + return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple); } /****************************************************************/ @@ -1560,15 +1566,15 @@ nm_client_new (GCancellable *cancellable, } static void -client_inited (GObject *source, GAsyncResult *result, gpointer user_data) +client_inited (GObject *object, GAsyncResult *result, gpointer user_data) { GSimpleAsyncResult *simple = user_data; GError *error = NULL; - if (!g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error)) + if (!g_async_initable_new_finish (G_ASYNC_INITABLE (object), result, &error)) g_simple_async_result_take_error (simple, error); else - g_simple_async_result_set_op_res_gpointer (simple, source, g_object_unref); + g_simple_async_result_set_op_res_gpointer (simple, object, g_object_unref); g_simple_async_result_complete (simple); g_object_unref (simple); } @@ -1719,30 +1725,31 @@ init_async_complete (NMClientInitData *init_data) } static void -init_async_got_permissions (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +init_async_got_permissions (GObject *object, GAsyncResult *result, gpointer user_data) { NMClientInitData *init_data = user_data; - GHashTable *permissions; - GError *error = NULL; - - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_STRING, &permissions, - G_TYPE_INVALID); - update_permissions (init_data->client, error ? NULL : permissions); - if (error) - g_simple_async_result_take_error (init_data->result, error); + GVariant *ret, *permissions; + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), result, NULL); + if (ret) { + g_variant_get (ret, "(a{ss})", &permissions); + update_permissions (init_data->client, permissions); + g_variant_unref (permissions); + g_variant_unref (ret); + } else + update_permissions (init_data->client, NULL); init_async_complete (init_data); } static void -init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data) +init_async_parent_inited (GObject *object, GAsyncResult *result, gpointer user_data) { NMClientInitData *init_data = user_data; NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (init_data->client); GError *error = NULL; - if (!nm_client_parent_async_initable_iface->init_finish (G_ASYNC_INITABLE (source), result, &error)) { + if (!nm_client_parent_async_initable_iface->init_finish (G_ASYNC_INITABLE (object), result, &error)) { g_simple_async_result_take_error (init_data->result, error); init_async_complete (init_data); return; @@ -1753,9 +1760,12 @@ init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_d return; } - dbus_g_proxy_begin_call (priv->client_proxy, "GetPermissions", - init_async_got_permissions, init_data, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->client_proxy, + "GetPermissions", + NULL, + G_DBUS_CALL_FLAGS_NONE, 3000, + NULL, + init_async_got_permissions, init_data); } static void @@ -1799,11 +1809,6 @@ dispose (GObject *object) NMClient *client = NM_CLIENT (object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); - if (priv->perm_call) { - dbus_g_proxy_cancel_call (priv->client_proxy, priv->perm_call); - priv->perm_call = NULL; - } - g_clear_object (&priv->client_proxy); free_devices (client, FALSE); diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 66d5f2e8db..52043aab94 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -29,7 +29,6 @@ #include <glib.h> #include <glib-object.h> #include <gio/gio.h> -#include <dbus/dbus-glib.h> #include <nm-dbus-interface.h> #include "nm-object.h" #include "nm-device.h" diff --git a/libnm/nm-dbus-helpers-private.h b/libnm/nm-dbus-helpers-private.h index 8a350e783d..e735c6ce89 100644 --- a/libnm/nm-dbus-helpers-private.h +++ b/libnm/nm-dbus-helpers-private.h @@ -22,15 +22,17 @@ #define NM_DBUS_HELPERS_PRIVATE_H #include <gio/gio.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> -DBusGConnection *_nm_dbus_new_connection (GError **error); +GDBusConnection *_nm_dbus_new_connection (GError **error); -gboolean _nm_dbus_is_connection_private (DBusGConnection *connection); +gboolean _nm_dbus_is_connection_private (GDBusConnection *connection); -DBusGProxy * _nm_dbus_new_proxy_for_connection (DBusGConnection *connection, +GDBusProxy * _nm_dbus_new_proxy_for_connection (GDBusConnection *connection, const char *path, const char *interface); +void _nm_dbus_register_error_domain (GQuark domain, + const char *interface, + GType enum_type); + #endif /* NM_DBUS_HELPERS_PRIVATE_H */ diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c index f80cb375a3..5d6cd9f74d 100644 --- a/libnm/nm-dbus-helpers.c +++ b/libnm/nm-dbus-helpers.c @@ -21,79 +21,86 @@ #include <string.h> #include <config.h> #include <gio/gio.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> #include "nm-dbus-helpers-private.h" #include "nm-dbus-interface.h" -static dbus_int32_t priv_slot = -1; +#define NM_DBUS_PRIVATE_CONNECTION_TAG "libnm-private-connection" -static gboolean -_ensure_dbus_data_slot (void) -{ - static gsize init_value = 0; - gboolean success = TRUE; - - if (g_once_init_enter (&init_value)) { - success = dbus_connection_allocate_data_slot (&priv_slot); - g_once_init_leave (&init_value, 1); - } - return success; -} - -DBusGConnection * +GDBusConnection * _nm_dbus_new_connection (GError **error) { - DBusGConnection *connection = NULL; + GDBusConnection *connection = NULL; - if (!_ensure_dbus_data_slot ()) { - g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED, "failed to allocated data slot"); - return NULL; - } - -#if HAVE_DBUS_GLIB_100 /* If running as root try the private bus first */ if (0 == geteuid ()) { - connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error); + connection = g_dbus_connection_new_for_address_sync ("unix:path=" NMRUNDIR "/private", + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, + NULL, NULL, NULL); if (connection) { - DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection); - /* Mark this connection as private */ - dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL); - dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE); + g_object_set_data (G_OBJECT (connection), + NM_DBUS_PRIVATE_CONNECTION_TAG, + GUINT_TO_POINTER (TRUE)); return connection; } - /* Fall back to a bus if for some reason private socket isn't available */ - g_clear_error (error); } -#endif - - if (connection == NULL) - connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); - return connection; + return g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); } gboolean -_nm_dbus_is_connection_private (DBusGConnection *connection) +_nm_dbus_is_connection_private (GDBusConnection *connection) { - if (!_ensure_dbus_data_slot ()) - return FALSE; - return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot); + return !!g_object_get_data (G_OBJECT (connection), NM_DBUS_PRIVATE_CONNECTION_TAG); } -DBusGProxy * -_nm_dbus_new_proxy_for_connection (DBusGConnection *connection, +GDBusProxy * +_nm_dbus_new_proxy_for_connection (GDBusConnection *connection, const char *path, const char *interface) { - /* Private connections can't use dbus_g_proxy_new_for_name() or - * dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't - * have either a bus daemon or name owners, both of which those functions - * require. - */ + GDBusProxy *proxy; + const char *name; + GError *error = NULL; + if (_nm_dbus_is_connection_private (connection)) - return dbus_g_proxy_new_for_peer (connection, path, interface); + name = NULL; + else + name = NM_DBUS_SERVICE; + + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + name, path, interface, + NULL, + &error); + if (error) { + /* FIXME */ + g_warning ("Could not create proxy for %s on %s: %s", + path, interface, error->message); + g_clear_error (&error); + } + + return proxy; +} + +void +_nm_dbus_register_error_domain (GQuark domain, + const char *interface, + GType enum_type) +{ + GEnumClass *enum_class; + GEnumValue *e; + char *error_name; + int i; + + enum_class = g_type_class_ref (enum_type); + for (i = 0; i < enum_class->n_values; i++) { + e = &enum_class->values[i]; + error_name = g_strdup_printf ("%s.%s", interface, e->value_nick); + g_dbus_error_register_error (domain, e->value, error_name); + g_free (error_name); + } - return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface); + g_type_class_unref (enum_class); } diff --git a/libnm/nm-device-adsl.c b/libnm/nm-device-adsl.c index 3d4a25e400..3391aaebda 100644 --- a/libnm/nm-device-adsl.c +++ b/libnm/nm-device-adsl.c @@ -32,7 +32,7 @@ G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE) #define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; gboolean carrier; diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c index 51385145c0..77f69d5df0 100644 --- a/libnm/nm-device-bond.c +++ b/libnm/nm-device-bond.c @@ -37,7 +37,7 @@ G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE) #define NM_DEVICE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BOND, NMDeviceBondPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; gboolean carrier; diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index 5f7df36086..75d695c98c 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -37,7 +37,7 @@ G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE) #define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; gboolean carrier; diff --git a/libnm/nm-device-bridge.h b/libnm/nm-device-bridge.h index 15ea42f254..fb806acb78 100644 --- a/libnm/nm-device-bridge.h +++ b/libnm/nm-device-bridge.h @@ -70,7 +70,7 @@ typedef struct { GType nm_device_bridge_get_type (void); -GObject * nm_device_bridge_new (DBusGConnection *connection, const char *path); +GObject * nm_device_bridge_new (GDBusConnection *connection, const char *path); const char *nm_device_bridge_get_hw_address (NMDeviceBridge *device); gboolean nm_device_bridge_get_carrier (NMDeviceBridge *device); diff --git a/libnm/nm-device-bt.c b/libnm/nm-device-bt.c index b2820e2f87..a90ecdfb02 100644 --- a/libnm/nm-device-bt.c +++ b/libnm/nm-device-bt.c @@ -38,7 +38,7 @@ G_DEFINE_TYPE (NMDeviceBt, nm_device_bt, NM_TYPE_DEVICE) #define NM_DEVICE_BT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BT, NMDeviceBtPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; char *name; diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 3e9f46bbab..7c9e64bc69 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -38,7 +38,7 @@ G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE) #define NM_DEVICE_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; char *perm_hw_address; diff --git a/libnm/nm-device-generic.c b/libnm/nm-device-generic.c index 3ca3ac7b1f..de4e3b5135 100644 --- a/libnm/nm-device-generic.c +++ b/libnm/nm-device-generic.c @@ -32,7 +32,7 @@ G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) #define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; char *type_description; diff --git a/libnm/nm-device-infiniband.c b/libnm/nm-device-infiniband.c index 33176200ea..0b4b9a8146 100644 --- a/libnm/nm-device-infiniband.c +++ b/libnm/nm-device-infiniband.c @@ -36,7 +36,7 @@ G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) #define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; gboolean carrier; diff --git a/libnm/nm-device-modem.c b/libnm/nm-device-modem.c index dd50714fa7..87e5ebee17 100644 --- a/libnm/nm-device-modem.c +++ b/libnm/nm-device-modem.c @@ -38,7 +38,7 @@ G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; NMDeviceModemCapabilities caps; NMDeviceModemCapabilities current_caps; diff --git a/libnm/nm-device-olpc-mesh.c b/libnm/nm-device-olpc-mesh.c index c778b9f089..f766a47057 100644 --- a/libnm/nm-device-olpc-mesh.c +++ b/libnm/nm-device-olpc-mesh.c @@ -36,7 +36,7 @@ G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE) #define NM_DEVICE_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; NMDeviceWifi *companion; diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c index c59af821ba..be6de7da53 100644 --- a/libnm/nm-device-team.c +++ b/libnm/nm-device-team.c @@ -37,7 +37,7 @@ G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE) #define NM_DEVICE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TEAM, NMDeviceTeamPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; gboolean carrier; diff --git a/libnm/nm-device-vlan.c b/libnm/nm-device-vlan.c index 5a7037af07..60b4be4e75 100644 --- a/libnm/nm-device-vlan.c +++ b/libnm/nm-device-vlan.c @@ -36,7 +36,7 @@ G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE) #define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VLAN, NMDeviceVlanPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; gboolean carrier; diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c index 0f8828b391..ac850aeae5 100644 --- a/libnm/nm-device-wifi.c +++ b/libnm/nm-device-wifi.c @@ -33,8 +33,7 @@ #include "nm-device-private.h" #include "nm-object-private.h" #include "nm-object-cache.h" -#include "nm-dbus-glib-types.h" -#include "nm-types-private.h" +#include "nm-types.h" G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) @@ -45,12 +44,13 @@ static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user typedef struct { NMDeviceWifi *device; + GCancellable *cancellable; NMDeviceWifiRequestScanFn callback; gpointer user_data; } RequestScanInfo; typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; char *perm_hw_address; @@ -60,7 +60,6 @@ typedef struct { NMDeviceWifiCapabilities wireless_caps; GPtrArray *aps; - DBusGProxyCall *scan_call; RequestScanInfo *scan_info; } NMDeviceWifiPrivate; @@ -286,24 +285,29 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device, } static void -request_scan_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +request_scan_cb (GObject *source, + GAsyncResult *result, gpointer user_data) { RequestScanInfo *info = user_data; - NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device); - GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + if (info->callback) { + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device); + GVariant *ret; + GError *error = NULL; + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error); + if (ret) + g_variant_unref (ret); - if (info->callback) info->callback (info->device, error, info->user_data); - g_clear_error (&error); - g_slice_free (RequestScanInfo, info); + g_clear_error (&error); + priv->scan_info = NULL; + } - priv->scan_call = NULL; - priv->scan_info = NULL; + g_clear_object (&info->cancellable); + g_slice_free (RequestScanInfo, info); } /** @@ -322,29 +326,28 @@ nm_device_wifi_request_scan_simple (NMDeviceWifi *device, gpointer user_data) { RequestScanInfo *info; - GHashTable *options; NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); g_return_if_fail (NM_IS_DEVICE_WIFI (device)); /* If a scan is in progress, just return */ - if (priv->scan_call) + if (priv->scan_info) return; - options = g_hash_table_new (g_str_hash, g_str_equal); - info = g_slice_new0 (RequestScanInfo); info->device = device; + info->cancellable = g_cancellable_new (); info->callback = callback; info->user_data = user_data; priv->scan_info = info; - priv->scan_call = dbus_g_proxy_begin_call (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, "RequestScan", - request_scan_cb, info, NULL, - DBUS_TYPE_G_MAP_OF_VARIANT, options, - G_TYPE_INVALID); - - g_hash_table_unref (options); + g_dbus_proxy_call (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, + "RequestScan", + g_variant_new ("(a{sv})", + g_variant_new_array (G_VARIANT_TYPE_VARDICT, NULL, 0)), + G_DBUS_CALL_FLAGS_NONE, -1, + info->cancellable, + request_scan_cb, info); } static void @@ -616,19 +619,22 @@ dispose (GObject *object) NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); GError *error = NULL; - if (priv->scan_call) { - g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN, - "Wi-Fi device was destroyed"); - if (priv->scan_info) { - if (priv->scan_info->callback) - priv->scan_info->callback (NULL, error, priv->scan_info->user_data); - g_slice_free (RequestScanInfo, priv->scan_info); - priv->scan_info = NULL; + if (priv->scan_info) { + RequestScanInfo *scan_info; + + scan_info = priv->scan_info; + priv->scan_info = NULL; + + if (scan_info->callback) { + g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN, + "Wi-Fi device was destroyed"); + scan_info->callback (NULL, error, scan_info->user_data); + scan_info->callback = NULL; + g_clear_error (&error); } - g_clear_error (&error); - dbus_g_proxy_cancel_call (priv->proxy, priv->scan_call); - priv->scan_call = NULL; + g_cancellable_cancel (scan_info->cancellable); + /* request_scan_cb() will free scan_info */ } clean_up_aps (NM_DEVICE_WIFI (object), FALSE); diff --git a/libnm/nm-device-wimax.c b/libnm/nm-device-wimax.c index 23571a8a89..617d73ef3e 100644 --- a/libnm/nm-device-wimax.c +++ b/libnm/nm-device-wimax.c @@ -31,7 +31,7 @@ #include "nm-device-wimax.h" #include "nm-object-private.h" #include "nm-object-cache.h" -#include "nm-types-private.h" +#include "nm-types.h" #include "nm-device-private.h" G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) @@ -42,7 +42,7 @@ void _nm_device_wimax_set_wireless_enabled (NMDeviceWimax *wimax, gboolean enabl static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data); typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *hw_address; NMWimaxNsp *active_nsp; diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 2084b3e74f..b0a5163a90 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -48,9 +48,9 @@ #include "nm-utils.h" #include "nm-dbus-helpers-private.h" -static GType _nm_device_type_for_path (DBusGConnection *connection, +static GType _nm_device_type_for_path (GDBusConnection *connection, const char *path); -static void _nm_device_type_for_path_async (DBusGConnection *connection, +static void _nm_device_type_for_path_async (GDBusConnection *connection, const char *path, NMObjectTypeCallbackFunc callback, gpointer user_data); @@ -66,7 +66,7 @@ G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT, #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *iface; char *ip_iface; @@ -164,28 +164,21 @@ nm_device_init (NMDevice *device) } static gboolean -demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_state_reason (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); - if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT)) - return FALSE; - - dbus_g_type_struct_get (value, - 0, &priv->state, - 1, &priv->reason, - G_MAXUINT); - + g_variant_get (value, "(uu)", &priv->state, &priv->reason); _nm_object_queue_notify (object, NM_DEVICE_STATE_REASON); return TRUE; } static void -device_state_changed (DBusGProxy *proxy, - NMDeviceState new_state, - NMDeviceState old_state, - NMDeviceStateReason reason, - gpointer user_data); +device_proxy_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data); static void init_dbus_properties (NMObject *object) @@ -227,21 +220,8 @@ init_dbus_properties (NMObject *object) priv->proxy, property_info); - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, - G_TYPE_INVALID); - - dbus_g_proxy_add_signal (priv->proxy, - "StateChanged", - G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", - G_CALLBACK (device_state_changed), - NM_DEVICE (object), - NULL); - + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (device_proxy_signal), object); } typedef struct { @@ -284,14 +264,21 @@ device_state_change_reloaded (GObject *object, } static void -device_state_changed (DBusGProxy *proxy, - NMDeviceState new_state, - NMDeviceState old_state, - NMDeviceStateReason reason, - gpointer user_data) +device_proxy_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDeviceState new_state, old_state; + NMDeviceStateReason reason; + + if (strcmp (signal_name, "StateChanged") != 0) + return; + + g_variant_get (parameters, "(uuu)", &new_state, &old_state, &reason); if (old_state != new_state) { StateChangeData *data; @@ -417,7 +404,6 @@ get_property (GObject *object, GParamSpec *pspec) { NMDevice *device = NM_DEVICE (object); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); switch (prop_id) { case PROP_DEVICE_TYPE: @@ -469,12 +455,7 @@ get_property (GObject *object, g_value_set_enum (value, nm_device_get_state (device)); break; case PROP_STATE_REASON: - g_value_set_boxed (value, - dbus_g_type_specialized_construct (DBUS_G_TYPE_UINT_STRUCT)); - dbus_g_type_struct_set (value, - 0, priv->state, - 1, priv->reason, - G_MAXUINT); + g_value_set_enum (value, nm_device_get_state_reason (device)); break; case PROP_ACTIVE_CONNECTION: g_value_set_object (value, nm_device_get_active_connection (device)); @@ -755,10 +736,11 @@ nm_device_class_init (NMDeviceClass *device_class) **/ g_object_class_install_property (object_class, PROP_STATE_REASON, - g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "", - DBUS_G_TYPE_UINT_STRUCT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_enum (NM_DEVICE_STATE_REASON, "", "", + NM_TYPE_DEVICE_STATE_REASON, + NM_DEVICE_STATE_REASON_UNKNOWN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * NMDevice:active-connection: @@ -878,12 +860,12 @@ _nm_device_set_device_type (NMDevice *device, NMDeviceType dtype) } static GType -_nm_device_type_for_path (DBusGConnection *connection, +_nm_device_type_for_path (GDBusConnection *connection, const char *path) { - DBusGProxy *proxy; + GDBusProxy *proxy; GError *err = NULL; - GValue value = G_VALUE_INIT; + GVariant *ret, *val; NMDeviceType nm_dtype; proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties"); @@ -892,44 +874,51 @@ _nm_device_type_for_path (DBusGConnection *connection, return G_TYPE_INVALID; } - if (!dbus_g_proxy_call (proxy, - "Get", &err, - G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE, - G_TYPE_STRING, "DeviceType", - G_TYPE_INVALID, - G_TYPE_VALUE, &value, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (proxy, + "Get", + g_variant_new ("(ss)", NM_DBUS_INTERFACE_DEVICE, "DeviceType"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &err); + g_object_unref (proxy); + + if (ret) { + g_variant_get (ret, "(v)", &val); + nm_dtype = g_variant_get_uint32 (val); + g_variant_unref (val); + g_variant_unref (ret); + + return _nm_device_gtype_from_dtype (nm_dtype); + } else { g_warning ("Error in get_property: %s\n", err->message); g_error_free (err); - g_object_unref (proxy); return G_TYPE_INVALID; } - g_object_unref (proxy); - - nm_dtype = g_value_get_uint (&value); - return _nm_device_gtype_from_dtype (nm_dtype); } typedef struct { - DBusGConnection *connection; + GDBusConnection *connection; NMObjectTypeCallbackFunc callback; gpointer user_data; } NMDeviceAsyncData; static void -async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +async_got_type (GObject *object, GAsyncResult *result, gpointer user_data) { NMDeviceAsyncData *async_data = user_data; - GValue value = G_VALUE_INIT; - const char *path = dbus_g_proxy_get_path (proxy); + GDBusProxy *proxy = G_DBUS_PROXY (object); + GVariant *ret, *val; + const char *path = g_dbus_proxy_get_object_path (proxy); GError *error = NULL; GType type; - if (dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_VALUE, &value, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (proxy, result, &error); + if (ret) { NMDeviceType dtype; - dtype = g_value_get_uint (&value); + g_variant_get (ret, "(v)", &val); + dtype = g_variant_get_uint32 (val); + g_variant_unref (val); + g_variant_unref (ret); type = _nm_device_gtype_from_dtype (dtype); } else { g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message); @@ -943,13 +932,13 @@ async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) } static void -_nm_device_type_for_path_async (DBusGConnection *connection, +_nm_device_type_for_path_async (GDBusConnection *connection, const char *path, NMObjectTypeCallbackFunc callback, gpointer user_data) { NMDeviceAsyncData *async_data; - DBusGProxy *proxy; + GDBusProxy *proxy; async_data = g_slice_new (NMDeviceAsyncData); async_data->connection = connection; @@ -957,11 +946,12 @@ _nm_device_type_for_path_async (DBusGConnection *connection, async_data->user_data = user_data; proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties"); - dbus_g_proxy_begin_call (proxy, "Get", - async_got_type, async_data, NULL, - G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE, - G_TYPE_STRING, "DeviceType", - G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "Get", + g_variant_new ("(ss)", NM_DBUS_INTERFACE_DEVICE, "DeviceType"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + async_got_type, async_data); } /** @@ -1197,20 +1187,14 @@ nm_device_get_autoconnect (NMDevice *device) void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect) { - GValue value = G_VALUE_INIT; - g_return_if_fail (NM_IS_DEVICE (device)); - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, autoconnect); - - NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect; _nm_object_set_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Autoconnect", - &value); + "b", autoconnect); } /** @@ -1332,21 +1316,17 @@ nm_device_get_state (NMDevice *device) /** * nm_device_get_state_reason: * @device: a #NMDevice - * @reason: (out) (allow-none): location to store reason (#NMDeviceStateReason), or %NULL * - * Gets the current #NMDevice state (return value) and the reason for entering - * the state (@reason argument). + * Gets the reason associated with the current #NMDevice state. * - * Returns: the current device state + * Returns: the reason for the current device state **/ -NMDeviceState -nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason) +NMDeviceStateReason +nm_device_get_state_reason (NMDevice *device) { - g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_UNKNOWN); + g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_REASON_UNKNOWN); - if (reason) - *reason = NM_DEVICE_GET_PRIVATE (device)->reason; - return NM_DEVICE_GET_PRIVATE (device)->state; + return NM_DEVICE_GET_PRIVATE (device)->reason; } /** @@ -2026,15 +2006,15 @@ typedef struct { } DeviceCallbackInfo; static void -device_operation_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +device_operation_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { DeviceCallbackInfo *info = user_data; + GVariant *ret; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); if (info->fn) info->fn (info->device, error, info->user_data); else if (error) { @@ -2047,6 +2027,9 @@ device_operation_cb (DBusGProxy *proxy, } g_clear_error (&error); + if (ret) + g_variant_unref (ret); + g_object_unref (info->device); g_slice_free (DeviceCallbackInfo, info); } @@ -2077,9 +2060,12 @@ nm_device_disconnect (NMDevice *device, info->method = "Disconnect"; info->device = g_object_ref (device); - dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Disconnect", - device_operation_cb, info, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (NM_DEVICE_GET_PRIVATE (device)->proxy, + "Disconnect", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + device_operation_cb, info); } /** @@ -2106,9 +2092,12 @@ nm_device_delete (NMDevice *device, info->method = "Delete"; info->device = g_object_ref (device); - dbus_g_proxy_begin_call (NM_DEVICE_GET_PRIVATE (device)->proxy, "Delete", - device_operation_cb, info, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (NM_DEVICE_GET_PRIVATE (device)->proxy, + "Delete", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + device_operation_cb, info); } /** diff --git a/libnm/nm-device.h b/libnm/nm-device.h index df6f450aae..a473d4f05a 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-object.h" #include "nm-dbus-interface.h" #include "nm-ip4-config.h" @@ -133,7 +132,7 @@ NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *device); NMIP6Config * nm_device_get_ip6_config (NMDevice *device); NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); -NMDeviceState nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason); +NMDeviceStateReason nm_device_get_state_reason (NMDevice *device); NMActiveConnection * nm_device_get_active_connection(NMDevice *device); const GPtrArray * nm_device_get_available_connections(NMDevice *device); const char * nm_device_get_physical_port_id (NMDevice *device); diff --git a/libnm/nm-dhcp4-config.c b/libnm/nm-dhcp4-config.c index 3cdbb4a183..88e6898216 100644 --- a/libnm/nm-dhcp4-config.c +++ b/libnm/nm-dhcp4-config.c @@ -23,7 +23,6 @@ #include "nm-dhcp4-config.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" #include "nm-utils.h" @@ -32,7 +31,7 @@ G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_OBJECT) #define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; GHashTable *options; } NMDhcp4ConfigPrivate; @@ -53,21 +52,19 @@ nm_dhcp4_config_init (NMDhcp4Config *config) } static gboolean -demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object); - GHashTable *new_options; - GHashTableIter iter; + GVariantIter iter; const char *key; - GValue *opt; + GVariant *opt; g_hash_table_remove_all (priv->options); - new_options = g_value_get_boxed (value); - if (new_options) { - g_hash_table_iter_init (&iter, new_options); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt)) - g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt)); + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) { + g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL)); + g_variant_unref (opt); } _nm_object_queue_notify (object, NM_DHCP4_CONFIG_OPTIONS); diff --git a/libnm/nm-dhcp4-config.h b/libnm/nm-dhcp4-config.h index 036e5d6473..15fc448348 100644 --- a/libnm/nm-dhcp4-config.h +++ b/libnm/nm-dhcp4-config.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-object.h" G_BEGIN_DECLS diff --git a/libnm/nm-dhcp6-config.c b/libnm/nm-dhcp6-config.c index 938e02b54f..1c6eb60184 100644 --- a/libnm/nm-dhcp6-config.c +++ b/libnm/nm-dhcp6-config.c @@ -23,7 +23,6 @@ #include "nm-dhcp6-config.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" #include "nm-utils.h" @@ -32,7 +31,7 @@ G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_OBJECT) #define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; GHashTable *options; } NMDhcp6ConfigPrivate; @@ -53,21 +52,19 @@ nm_dhcp6_config_init (NMDhcp6Config *config) } static gboolean -demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); - GHashTable *new_options; - GHashTableIter iter; + GVariantIter iter; const char *key; - GValue *opt; + GVariant *opt; g_hash_table_remove_all (priv->options); - new_options = g_value_get_boxed (value); - if (new_options) { - g_hash_table_iter_init (&iter, new_options); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &opt)) - g_hash_table_insert (priv->options, g_strdup (key), g_value_dup_string (opt)); + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) { + g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL)); + g_variant_unref (opt); } _nm_object_queue_notify (object, NM_DHCP6_CONFIG_OPTIONS); diff --git a/libnm/nm-dhcp6-config.h b/libnm/nm-dhcp6-config.h index 9d538e3681..d7f6819dd7 100644 --- a/libnm/nm-dhcp6-config.h +++ b/libnm/nm-dhcp6-config.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-object.h" G_BEGIN_DECLS diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index ce6c6660f8..02d5ff2569 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -24,7 +24,6 @@ #include <nm-setting-ip4-config.h> #include "nm-ip4-config.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" #include "nm-utils.h" @@ -33,11 +32,11 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT) #define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *gateway; - GSList *addresses; - GSList *routes; + GPtrArray *addresses; + GPtrArray *routes; char **nameservers; char **domains; char **searches; @@ -62,6 +61,8 @@ nm_ip4_config_init (NMIP4Config *config) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + priv->addresses = g_ptr_array_new (); + priv->routes = g_ptr_array_new (); priv->nameservers = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1); @@ -69,58 +70,39 @@ nm_ip4_config_init (NMIP4Config *config) } static gboolean -demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); - g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref); - priv->addresses = NULL; - - priv->addresses = nm_utils_ip4_addresses_from_gvalue (value); + g_ptr_array_unref (priv->addresses); + priv->addresses = nm_utils_ip4_addresses_from_variant (value); _nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES); return TRUE; } static gboolean -demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { - GArray *ip_array; char ***obj_field; - int i; - - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)) - return FALSE; - - ip_array = g_value_get_boxed (value); obj_field = field; if (*obj_field) g_strfreev (*obj_field); - *obj_field = g_new (char *, ip_array->len + 1); - for (i = 0; i < ip_array->len; i++) { - guint32 ip = g_array_index (ip_array, guint32, i); - const char *str; - - str = nm_utils_inet4_ntop (ip, NULL); - (*obj_field)[i] = g_strdup (str); - } - (*obj_field)[i] = NULL; + *obj_field = nm_utils_ip4_dns_from_variant (value); _nm_object_queue_notify (object, pspec->name); return TRUE; } static gboolean -demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object); - g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref); - priv->routes = NULL; - - priv->routes = nm_utils_ip4_routes_from_gvalue (value); + g_ptr_array_unref (priv->routes); + priv->routes = nm_utils_ip4_routes_from_variant (value); _nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES); return TRUE; @@ -156,8 +138,8 @@ finalize (GObject *object) g_free (priv->gateway); - g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref); - g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref); + g_ptr_array_unref (priv->addresses); + g_ptr_array_unref (priv->routes); g_strfreev (priv->nameservers); g_strfreev (priv->domains); @@ -176,17 +158,16 @@ get_property (GObject *object, GParamSpec *pspec) { NMIP4Config *self = NM_IP4_CONFIG (object); - NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self); switch (prop_id) { case PROP_GATEWAY: g_value_set_string (value, nm_ip4_config_get_gateway (self)); break; case PROP_ADDRESSES: - nm_utils_ip4_addresses_to_gvalue (priv->addresses, value); + g_value_set_boxed (value, nm_ip4_config_get_addresses (self)); break; case PROP_ROUTES: - nm_utils_ip4_routes_to_gvalue (priv->routes, value); + g_value_set_boxed (value, nm_ip4_config_get_routes (self)); break; case PROP_NAMESERVERS: g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self)); @@ -238,23 +219,29 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) * NMIP4Config:addresses: * * The #GPtrArray containing #NMIP4Address<!-- -->es of the configuration. + * + * Element-type: NMIP4Address **/ g_object_class_install_property (object_class, PROP_ADDRESSES, - g_param_spec_pointer (NM_IP4_CONFIG_ADDRESSES, "", "", - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * NMIP4Config:routes: * * The #GPtrArray containing #NMSettingIP4Routes of the configuration. + * + * Element-type: NMIP4Route **/ g_object_class_install_property (object_class, PROP_ROUTES, - g_param_spec_pointer (NM_IP4_CONFIG_ROUTES, "", "", - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "", + G_TYPE_PTR_ARRAY, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * NMIP4Config:nameservers: @@ -327,10 +314,10 @@ nm_ip4_config_get_gateway (NMIP4Config *config) * * Gets the IP4 addresses (containing the address, prefix, and gateway). * - * Returns: (element-type NMIP4Address): the #GSList containing #NMIP4Address<!-- -->es. + * Returns: (element-type NMIP4Address): the #GPtrArray containing #NMIP4Address<!-- -->es. * This is the internal copy used by the configuration and must not be modified. **/ -const GSList * +GPtrArray * nm_ip4_config_get_addresses (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); @@ -410,11 +397,11 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config) * * Gets the routes. * - * Returns: (element-type NMIP4Route): the #GSList containing + * Returns: (element-type NMIP4Route): the #GPtrArray containing * #NMIP4Routes. This is the internal copy used by the configuration, * and must not be modified. **/ -const GSList * +GPtrArray * nm_ip4_config_get_routes (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); diff --git a/libnm/nm-ip4-config.h b/libnm/nm-ip4-config.h index c315f1045b..cd4b801f42 100644 --- a/libnm/nm-ip4-config.h +++ b/libnm/nm-ip4-config.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-object.h" G_BEGIN_DECLS @@ -62,8 +61,8 @@ typedef struct { GType nm_ip4_config_get_type (void); const char * nm_ip4_config_get_gateway (NMIP4Config *config); -const GSList * nm_ip4_config_get_addresses (NMIP4Config *config); -const GSList * nm_ip4_config_get_routes (NMIP4Config *config); +GPtrArray * nm_ip4_config_get_addresses (NMIP4Config *config); +GPtrArray * nm_ip4_config_get_routes (NMIP4Config *config); const char * const *nm_ip4_config_get_nameservers (NMIP4Config *config); const char * const *nm_ip4_config_get_domains (NMIP4Config *config); const char * const *nm_ip4_config_get_searches (NMIP4Config *config); diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index c4872126d6..68c6bcdcf3 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -24,21 +24,19 @@ #include <nm-setting-ip6-config.h> #include "nm-ip6-config.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" #include "nm-utils.h" -#include "nm-dbus-glib-types.h" G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT) #define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *gateway; - GSList *addresses; - GSList *routes; + GPtrArray *addresses; + GPtrArray *routes; char **nameservers; char **domains; char **searches; @@ -57,58 +55,39 @@ enum { }; static gboolean -demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object); - g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref); - priv->addresses = NULL; - - priv->addresses = nm_utils_ip6_addresses_from_gvalue (value); + g_ptr_array_unref (priv->addresses); + priv->addresses = nm_utils_ip6_addresses_from_variant (value); _nm_object_queue_notify (object, NM_IP6_CONFIG_ADDRESSES); return TRUE; } static gboolean -demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { - GPtrArray *ip_array; char ***obj_field; - int i; - - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)) - return FALSE; - - ip_array = g_value_get_boxed (value); obj_field = field; if (*obj_field) g_strfreev (*obj_field); - *obj_field = g_new (char *, ip_array ? ip_array->len + 1 : 1); - for (i = 0; ip_array && i < ip_array->len; i++) { - GByteArray *ip = g_ptr_array_index (ip_array, i); - const char *str; - - str = nm_utils_inet6_ntop ((struct in6_addr *) ip->data, NULL); - (*obj_field)[i] = g_strdup (str); - } - (*obj_field)[i] = NULL; + *obj_field = nm_utils_ip6_dns_from_variant (value); _nm_object_queue_notify (object, pspec->name); return TRUE; } static gboolean -demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object); - g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref); - priv->routes = NULL; - - priv->routes = nm_utils_ip6_routes_from_gvalue (value); + g_ptr_array_unref (priv->routes); + priv->routes = nm_utils_ip6_routes_from_variant (value); _nm_object_queue_notify (object, NM_IP6_CONFIG_ROUTES); return TRUE; @@ -158,11 +137,11 @@ nm_ip6_config_get_gateway (NMIP6Config *config) * * Gets the IP6 addresses (containing the address, prefix, and gateway). * - * Returns: (element-type NMIP6Address): the #GSList containing + * Returns: (element-type NMIP6Address): the #GPtrArray containing * #NMIP6Address<!-- -->es. This is the internal copy used by the configuration * and must not be modified. **/ -const GSList * +GPtrArray * nm_ip6_config_get_addresses (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); @@ -224,11 +203,11 @@ nm_ip6_config_get_searches (NMIP6Config *config) * * Gets the routes. * - * Returns: (element-type NMIP6Route): the #GSList containing + * Returns: (element-type NMIP6Route): the #GPtrArray containing * #NMIP6Routes. This is the internal copy used by the configuration, * and must not be modified. **/ -const GSList * +GPtrArray * nm_ip6_config_get_routes (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); @@ -243,8 +222,8 @@ finalize (GObject *object) g_free (priv->gateway); - g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref); - g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref); + g_ptr_array_unref (priv->addresses); + g_ptr_array_unref (priv->routes); g_strfreev (priv->nameservers); g_strfreev (priv->domains); @@ -262,17 +241,16 @@ get_property (GObject *object, GParamSpec *pspec) { NMIP6Config *self = NM_IP6_CONFIG (object); - NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (self); switch (prop_id) { case PROP_GATEWAY: g_value_set_string (value, nm_ip6_config_get_gateway (self)); break; case PROP_ADDRESSES: - nm_utils_ip6_addresses_to_gvalue (priv->addresses, value); + g_value_set_boxed (value, nm_ip6_config_get_addresses (self)); break; case PROP_ROUTES: - nm_utils_ip6_routes_to_gvalue (priv->routes, value); + g_value_set_boxed (value, nm_ip6_config_get_routes (self)); break; case PROP_NAMESERVERS: g_value_set_boxed (value, (char **) nm_ip6_config_get_nameservers (self)); @@ -294,6 +272,8 @@ nm_ip6_config_init (NMIP6Config *config) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); + priv->addresses = g_ptr_array_new (); + priv->routes = g_ptr_array_new (); priv->nameservers = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1); @@ -330,28 +310,28 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) /** * NMIP6Config:addresses: * - * The #GPtrArray containing the IPv6 addresses; use - * nm_utils_ip6_addresses_from_gvalue() to return a #GSList of - * #NMSettingIP6Address objects that is more usable than the raw data. + * The #GPtrArray containing the IPv6 addresses. + * + * Element-type: NMIP6Address **/ g_object_class_install_property (object_class, PROP_ADDRESSES, g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES, "", "", - NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY, + G_TYPE_PTR_ARRAY, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); /** * NMIP6Config:routes: * - * The #GPtrArray containing the IPv6 routes; use - * nm_utils_ip6_routes_from_gvalue() to return a #GSList of - * #NMSettingIP6Address objects that is more usable than the raw data. + * The #GPtrArray containing the IPv6 routes. + * + * Element-type: NMIP6Route **/ g_object_class_install_property (object_class, PROP_ROUTES, g_param_spec_boxed (NM_IP6_CONFIG_ROUTES, "", "", - NM_TYPE_IP6_ROUTE_OBJECT_ARRAY, + G_TYPE_PTR_ARRAY, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); diff --git a/libnm/nm-ip6-config.h b/libnm/nm-ip6-config.h index 544b3e2a72..d31db97553 100644 --- a/libnm/nm-ip6-config.h +++ b/libnm/nm-ip6-config.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-object.h" G_BEGIN_DECLS @@ -61,8 +60,8 @@ typedef struct { GType nm_ip6_config_get_type (void); const char * nm_ip6_config_get_gateway (NMIP6Config *config); -const GSList * nm_ip6_config_get_addresses (NMIP6Config *config); -const GSList * nm_ip6_config_get_routes (NMIP6Config *config); +GPtrArray * nm_ip6_config_get_addresses (NMIP6Config *config); +GPtrArray * nm_ip6_config_get_routes (NMIP6Config *config); const char * const * nm_ip6_config_get_nameservers (NMIP6Config *config); const char * const * nm_ip6_config_get_domains (NMIP6Config *config); const char * const * nm_ip6_config_get_searches (NMIP6Config *config); diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h index 8f72b120b7..0e5218450d 100644 --- a/libnm/nm-object-private.h +++ b/libnm/nm-object-private.h @@ -24,9 +24,9 @@ #include <gio/gio.h> #include "nm-object.h" -typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GValue *, gpointer); +typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GVariant *, gpointer); -typedef GObject * (*NMObjectCreatorFunc) (DBusGConnection *, const char *); +typedef GObject * (*NMObjectCreatorFunc) (GDBusConnection *, const char *); typedef struct { const char *name; @@ -36,14 +36,14 @@ typedef struct { const char *signal_prefix; } NMPropertiesInfo; -DBusGProxy *_nm_object_new_proxy (NMObject *self, +GDBusProxy *_nm_object_new_proxy (NMObject *self, const char *path, const char *interface); gboolean _nm_object_is_connection_private (NMObject *self); void _nm_object_register_properties (NMObject *object, - DBusGProxy *proxy, + GDBusProxy *proxy, const NMPropertiesInfo *info); gboolean _nm_object_reload_properties (NMObject *object, GError **error); @@ -68,7 +68,8 @@ void _nm_object_reload_property (NMObject *object, void _nm_object_set_property (NMObject *object, const char *interface, const char *prop_name, - GValue *value); + const char *format_string, + ...); static inline const GPtrArray * handle_ptr_array_return (GPtrArray *array) @@ -80,9 +81,9 @@ handle_ptr_array_return (GPtrArray *array) } /* object demarshalling support */ -typedef GType (*NMObjectTypeFunc) (DBusGConnection *, const char *); +typedef GType (*NMObjectTypeFunc) (GDBusConnection *, const char *); typedef void (*NMObjectTypeCallbackFunc) (GType, gpointer); -typedef void (*NMObjectTypeAsyncFunc) (DBusGConnection *, const char *, NMObjectTypeCallbackFunc, gpointer); +typedef void (*NMObjectTypeAsyncFunc) (GDBusConnection *, const char *, NMObjectTypeCallbackFunc, gpointer); void _nm_object_register_type_func (GType base_type, NMObjectTypeFunc type_func, NMObjectTypeAsyncFunc type_async_func); diff --git a/libnm/nm-object.c b/libnm/nm-object.c index 072fdc0c16..724d7d1ef9 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -29,7 +29,6 @@ #include "nm-object.h" #include "nm-object-cache.h" #include "nm-object-private.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-types.h" #include "nm-dbus-helpers-private.h" @@ -61,12 +60,13 @@ typedef struct { static void reload_complete (NMObject *object); typedef struct { - DBusGConnection *connection; - DBusGProxy *bus_proxy; + GDBusConnection *connection; + gboolean private_connection; gboolean nm_running; + guint bus_nameownerchanged_id; char *path; - DBusGProxy *properties_proxy; + GDBusProxy *properties_proxy; GSList *property_interfaces; GSList *property_tables; NMObject *parent; @@ -115,27 +115,36 @@ nm_object_error_quark (void) } static void -proxy_name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) +on_name_owner_changed (GDBusConnection *connection, + const char *sender_name, + const char *object_path, + const char *interface_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { NMObject *self = NM_OBJECT (user_data); NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + const char *name; + const char *old_owner; + const char *new_owner; + gboolean old_good, new_good; + + g_variant_get (parameters, + "(&s&s&s)", + &name, + &old_owner, + &new_owner); + + old_good = (old_owner && old_owner[0]); + new_good = (new_owner && new_owner[0]); + if (!old_good && new_good) + priv->nm_running = TRUE; + else if (old_good && !new_good) + priv->nm_running = FALSE; - if (g_strcmp0 (name, NM_DBUS_SERVICE) == 0) { - gboolean old_good = (old_owner && old_owner[0]); - gboolean new_good = (new_owner && new_owner[0]); - - if (!old_good && new_good) - priv->nm_running = TRUE; - else if (old_good && !new_good) - priv->nm_running = FALSE; - - if (old_good != new_good) - g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING); - } + if (old_good != new_good) + g_object_notify (G_OBJECT (self), NM_OBJECT_NM_RUNNING); } static void @@ -160,22 +169,21 @@ init_common (NMObject *self, GError **error) priv->properties_proxy = _nm_object_new_proxy (self, NULL, "org.freedesktop.DBus.Properties"); - if (_nm_object_is_connection_private (self)) + if (_nm_object_is_connection_private (self)) { + priv->private_connection = TRUE; priv->nm_running = TRUE; - else { - priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - g_assert (priv->bus_proxy); - - dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->bus_proxy, - "NameOwnerChanged", - G_CALLBACK (proxy_name_owner_changed), - self, NULL); + } else { + /* FIXME: use gdbusnamewatching? But it has no sync API */ + priv->bus_nameownerchanged_id = + g_dbus_connection_signal_subscribe (priv->connection, + "org.freedesktop.DBus", + "org.freedesktop.DBus", + "NameOwnerChanged", + "/org/freedesktop/DBus", + NM_DBUS_SERVICE, + G_DBUS_SIGNAL_FLAGS_NONE, + on_name_owner_changed, + self, NULL); } return TRUE; @@ -200,14 +208,24 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) if (!init_common (self, error)) return FALSE; - if (priv->bus_proxy) { - if (!dbus_g_proxy_call (priv->bus_proxy, - "NameHasOwner", error, - G_TYPE_STRING, NM_DBUS_SERVICE, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &priv->nm_running, - G_TYPE_INVALID)) + if (!priv->private_connection) { + GVariant *ret; + + ret = g_dbus_connection_call_sync (priv->connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "NameHasOwner", + g_variant_new ("(s)", NM_DBUS_SERVICE), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, error); + if (!ret) return FALSE; + + g_variant_get (ret, "(b)", &priv->nm_running); + g_variant_unref (ret); } return _nm_object_reload_properties (self, error); @@ -237,28 +255,32 @@ init_async_got_properties (GObject *object, GAsyncResult *result, gpointer user_ } static void -init_async_got_nm_running (DBusGProxy *proxy, DBusGProxyCall *call, - gpointer user_data) +init_async_got_nm_running (GObject *object, GAsyncResult *result, gpointer user_data) { GSimpleAsyncResult *simple = user_data; NMObject *self; NMObjectPrivate *priv; + GVariant *ret; GError *error = NULL; self = NM_OBJECT (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); + /* g_async_result_get_source_object() adds a ref */ + g_object_unref (self); priv = NM_OBJECT_GET_PRIVATE (self); - if (!dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_BOOLEAN, &priv->nm_running, - G_TYPE_INVALID)) { + ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), result, &error); + if (!ret) { init_async_complete (simple, error); - } else if (!priv->nm_running) + return; + } + + g_variant_get (ret, "(b)", &priv->nm_running); + g_variant_unref (ret); + + if (!priv->nm_running) init_async_complete (simple, NULL); else _nm_object_reload_properties_async (self, init_async_got_properties, simple); - - /* g_async_result_get_source_object() adds a ref */ - g_object_unref (self); } static void @@ -293,11 +315,18 @@ init_async (GAsyncInitable *initable, int io_priority, _nm_object_reload_properties_async (self, init_async_got_properties, simple); else { /* Check if NM is running */ - dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner", - init_async_got_nm_running, - simple, NULL, - G_TYPE_STRING, NM_DBUS_SERVICE, - G_TYPE_INVALID); + g_dbus_connection_call (priv->connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "NameHasOwner", + g_variant_new ("(s)", NM_DBUS_SERVICE), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + init_async_got_nm_running, + simple); } } @@ -329,12 +358,12 @@ dispose (GObject *object) priv->property_interfaces = NULL; g_clear_object (&priv->properties_proxy); - g_clear_object (&priv->bus_proxy); - if (priv->connection) { - dbus_g_connection_unref (priv->connection); - priv->connection = NULL; + if (priv->bus_nameownerchanged_id) { + g_dbus_connection_signal_unsubscribe (priv->connection, priv->bus_nameownerchanged_id); + priv->bus_nameownerchanged_id = 0; } + g_clear_object (&priv->connection); G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); } @@ -359,7 +388,7 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DBUS_CONNECTION: /* Construct only */ - priv->connection = g_value_dup_boxed (value); + priv->connection = g_value_dup_object (value); break; case PROP_DBUS_PATH: /* Construct only */ @@ -379,7 +408,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DBUS_CONNECTION: - g_value_set_boxed (value, priv->connection); + g_value_set_object (value, priv->connection); break; case PROP_DBUS_PATH: g_value_set_string (value, priv->path); @@ -413,15 +442,15 @@ nm_object_class_init (NMObjectClass *nm_object_class) /** * NMObject:connection: * - * The #DBusGConnection of the object. + * The #GDBusConnection of the object. **/ g_object_class_install_property (object_class, PROP_DBUS_CONNECTION, - g_param_spec_boxed (NM_OBJECT_DBUS_CONNECTION, "", "", - DBUS_TYPE_G_CONNECTION, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_object (NM_OBJECT_DBUS_CONNECTION, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /** * NMObject:path: @@ -488,11 +517,11 @@ nm_object_async_initable_iface_init (GAsyncInitableIface *iface) * nm_object_get_connection: * @object: a #NMObject * - * Gets the #NMObject's DBusGConnection. + * Gets the #NMObject's GDBusConnection. * * Returns: (transfer none): the connection **/ -DBusGConnection * +GDBusConnection * nm_object_get_connection (NMObject *object) { g_return_val_if_fail (NM_IS_OBJECT (object), NULL); @@ -583,7 +612,7 @@ _nm_object_register_type_func (GType base_type, NMObjectTypeFunc type_func, } static GObject * -_nm_object_create (GType type, DBusGConnection *connection, const char *path) +_nm_object_create (GType type, GDBusConnection *connection, const char *path) { NMObjectTypeFunc type_func; GObject *object; @@ -612,7 +641,7 @@ _nm_object_create (GType type, DBusGConnection *connection, const char *path) typedef void (*NMObjectCreateCallbackFunc) (GObject *, const char *, gpointer); typedef struct { - DBusGConnection *connection; + GDBusConnection *connection; char *path; NMObjectCreateCallbackFunc callback; gpointer user_data; @@ -686,7 +715,7 @@ async_got_type (GType type, gpointer user_data) } static void -_nm_object_create_async (GType type, DBusGConnection *connection, const char *path, +_nm_object_create_async (GType type, GDBusConnection *connection, const char *path, NMObjectCreateCallbackFunc callback, gpointer user_data) { NMObjectTypeAsyncFunc type_async_func; @@ -912,7 +941,7 @@ object_created (GObject *obj, const char *path, gpointer user_data) } static gboolean -handle_object_property (NMObject *self, const char *property_name, GValue *value, +handle_object_property (NMObject *self, const char *property_name, GVariant *value, PropertyInfo *pi, gboolean synchronously) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); @@ -931,7 +960,7 @@ handle_object_property (NMObject *self, const char *property_name, GValue *value if (priv->reload_results) priv->reload_remaining++; - path = g_value_get_boxed (value); + path = g_variant_get_string (value, NULL); if (!strcmp (path, "/")) { object_created (NULL, path, odata); @@ -955,37 +984,37 @@ handle_object_property (NMObject *self, const char *property_name, GValue *value } static gboolean -handle_object_array_property (NMObject *self, const char *property_name, GValue *value, +handle_object_array_property (NMObject *self, const char *property_name, GVariant *value, PropertyInfo *pi, gboolean synchronously) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); GObject *obj; - GPtrArray *paths; + GVariantIter iter; + gsize npaths; GPtrArray **array = pi->field; const char *path; ObjectCreatedData *odata; - int i; - paths = g_value_get_boxed (value); + npaths = g_variant_n_children (value); odata = g_slice_new (ObjectCreatedData); odata->self = g_object_ref (self); odata->pi = pi; - odata->objects = g_new0 (GObject *, paths->len); - odata->length = odata->remaining = paths->len; + odata->objects = g_new0 (GObject *, npaths); + odata->length = odata->remaining = npaths; odata->array = TRUE; odata->property_name = property_name; if (priv->reload_results) priv->reload_remaining++; - if (paths->len == 0) { + if (npaths == 0) { object_property_complete (odata); return TRUE; } - for (i = 0; i < paths->len; i++) { - path = paths->pdata[i]; + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "&o", &path)) { if (!strcmp (path, "/")) { /* FIXME: can't happen? */ continue; @@ -1008,11 +1037,12 @@ handle_object_array_property (NMObject *self, const char *property_name, GValue return TRUE; } - return *array && ((*array)->len == paths->len); + return *array && ((*array)->len == npaths); } static void -handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, gboolean synchronously) +handle_property_changed (NMObject *self, const char *dbus_name, + GVariant *value, gboolean synchronously) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); char *prop_name; @@ -1053,7 +1083,7 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g if (G_UNLIKELY (debug)) { char *s; - s = g_strdup_value_contents (value); + s = g_variant_print (value, FALSE); dbgmsg ("PC: (%p) %s::%s => '%s' (%s%s%s)", self, G_OBJECT_TYPE_NAME (self), prop_name, @@ -1065,9 +1095,9 @@ handle_property_changed (NMObject *self, const char *dbus_name, GValue *value, g } if (pi->object_type) { - if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) + if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) success = handle_object_property (self, pspec->name, value, pi, synchronously); - else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) + else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("ao"))) success = handle_object_array_property (self, pspec->name, value, pi, synchronously); else { g_warn_if_reached (); @@ -1088,39 +1118,43 @@ out: } static void -process_properties_changed (NMObject *self, GHashTable *properties, gboolean synchronously) +process_properties_changed (NMObject *self, GVariant *properties, gboolean synchronously) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); - GHashTableIter iter; - gpointer name, value; + GVariantIter iter; + const char *name; + GVariant *value; if (priv->suppress_property_updates) return; - g_hash_table_iter_init (&iter, properties); - while (g_hash_table_iter_next (&iter, &name, &value)) { - if (value) - handle_property_changed (self, name, value, synchronously); - else { - dbgmsg ("%s:%d %s(): object %s property '%s' value is unexpectedly NULL", - __FILE__, __LINE__, __func__, G_OBJECT_TYPE_NAME (self), (const char *) name); - } - } + g_variant_iter_init (&iter, properties); + while (g_variant_iter_next (&iter, "{sv}", &name, &value)) + handle_property_changed (self, name, value, synchronously); } static void -properties_changed_proxy (DBusGProxy *proxy, - GHashTable *properties, - gpointer user_data) +property_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { + GVariant *properties; + + if (strcmp (signal_name, "PropertiesChanged") != 0) + return; + + properties = g_variant_get_child_value (parameters, 0); process_properties_changed (NM_OBJECT (user_data), properties, FALSE); + g_variant_unref (properties); } -#define HANDLE_TYPE(ucase, lcase, getter) \ - } else if (pspec->value_type == G_TYPE_##ucase) { \ - if (G_VALUE_HOLDS_##ucase (value)) { \ - g##lcase *param = (g##lcase *) field; \ - *param = g_value_get_##getter (value); \ +#define HANDLE_TYPE(gtype, vtype, ctype, getter) \ + } else if (pspec->value_type == gtype) { \ + if (g_variant_is_of_type (value, vtype)) { \ + ctype *param = (ctype *) field; \ + *param = getter (value); \ } else { \ success = FALSE; \ goto done; \ @@ -1129,20 +1163,20 @@ properties_changed_proxy (DBusGProxy *proxy, static gboolean demarshal_generic (NMObject *object, GParamSpec *pspec, - GValue *value, + GVariant *value, gpointer field) { gboolean success = TRUE; if (pspec->value_type == G_TYPE_STRING) { - if (G_VALUE_HOLDS_STRING (value)) { + if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { char **param = (char **) field; g_free (*param); - *param = g_value_dup_string (value); - } else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) { + *param = g_variant_dup_string (value, NULL); + } else if (g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH)) { char **param = (char **) field; g_free (*param); - *param = g_strdup (g_value_get_boxed (value)); + *param = g_variant_dup_string (value, NULL); /* Handle "NULL" object paths */ if (g_strcmp0 (*param, "/") == 0) { g_free (*param); @@ -1156,24 +1190,25 @@ demarshal_generic (NMObject *object, char ***param = (char ***)field; if (*param) g_strfreev (*param); - *param = g_value_dup_boxed (value); + *param = g_variant_dup_strv (value, NULL); } else if (pspec->value_type == G_TYPE_BYTES) { GBytes **param = (GBytes **)field; - GByteArray *val; + gconstpointer val; + gsize length; + if (*param) g_bytes_unref (*param); - val = g_value_get_boxed (value); - *param = g_bytes_new (val->data, val->len); - HANDLE_TYPE(BOOLEAN, boolean, boolean) - HANDLE_TYPE(CHAR, char, schar) - HANDLE_TYPE(UCHAR, uchar, uchar) - HANDLE_TYPE(DOUBLE, double, double) - HANDLE_TYPE(INT, int, int) - HANDLE_TYPE(UINT, uint, uint) - HANDLE_TYPE(INT64, int, int) - HANDLE_TYPE(UINT64, uint, uint) - HANDLE_TYPE(LONG, long, long) - HANDLE_TYPE(ULONG, ulong, ulong) + val = g_variant_get_fixed_array (value, &length, 1); + *param = g_bytes_new (val, length); + HANDLE_TYPE (G_TYPE_BOOLEAN, G_VARIANT_TYPE_BOOLEAN, gboolean, g_variant_get_boolean) + HANDLE_TYPE (G_TYPE_UCHAR, G_VARIANT_TYPE_BYTE, guchar, g_variant_get_byte) + HANDLE_TYPE (G_TYPE_DOUBLE, G_VARIANT_TYPE_DOUBLE, gdouble, g_variant_get_double) + HANDLE_TYPE (G_TYPE_INT, G_VARIANT_TYPE_INT32, gint, g_variant_get_int32) + HANDLE_TYPE (G_TYPE_UINT, G_VARIANT_TYPE_UINT32, guint, g_variant_get_uint32) + HANDLE_TYPE (G_TYPE_INT64, G_VARIANT_TYPE_INT64, gint, g_variant_get_int64) + HANDLE_TYPE (G_TYPE_UINT64, G_VARIANT_TYPE_UINT64, guint, g_variant_get_uint64) + HANDLE_TYPE (G_TYPE_LONG, G_VARIANT_TYPE_INT64, glong, g_variant_get_int64) + HANDLE_TYPE (G_TYPE_ULONG, G_VARIANT_TYPE_UINT64, gulong, g_variant_get_uint64) } else { dbgmsg ("%s: %s/%s unhandled type %s.", __func__, @@ -1196,7 +1231,7 @@ done: void _nm_object_register_properties (NMObject *object, - DBusGProxy *proxy, + GDBusProxy *proxy, const NMPropertiesInfo *info) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); @@ -1217,14 +1252,10 @@ _nm_object_register_properties (NMObject *object, } priv->property_interfaces = g_slist_prepend (priv->property_interfaces, - g_strdup (dbus_g_proxy_get_interface (proxy))); + g_strdup (g_dbus_proxy_get_interface_name (proxy))); - dbus_g_proxy_add_signal (proxy, "PropertiesChanged", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (proxy, - "PropertiesChanged", - G_CALLBACK (properties_changed_proxy), - object, - NULL); + g_signal_connect (proxy, "g-signal", + G_CALLBACK (property_proxy_signal), object); instance = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->property_tables = g_slist_prepend (priv->property_tables, instance); @@ -1250,22 +1281,25 @@ gboolean _nm_object_reload_properties (NMObject *object, GError **error) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GHashTable *props = NULL; + GVariant *ret, *props; GSList *p; if (!priv->property_interfaces || !priv->nm_running) return TRUE; for (p = priv->property_interfaces; p; p = p->next) { - if (!dbus_g_proxy_call (priv->properties_proxy, "GetAll", error, - G_TYPE_STRING, p->data, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->properties_proxy, + "GetAll", + g_variant_new ("(s)", p->data), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, error); + if (!ret) return FALSE; + props = g_variant_get_child_value (ret, 0); process_properties_changed (object, props, TRUE); - g_hash_table_destroy (props); + g_variant_unref (props); + g_variant_unref (ret); } return TRUE; @@ -1285,7 +1319,7 @@ _nm_object_reload_property (NMObject *object, const char *interface, const char *prop_name) { - GValue value = G_VALUE_INIT; + GVariant *ret, *value; GError *err = NULL; g_return_if_fail (NM_IS_OBJECT (object)); @@ -1295,13 +1329,12 @@ _nm_object_reload_property (NMObject *object, if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) return; - if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, - "Get", 15000, &err, - G_TYPE_STRING, interface, - G_TYPE_STRING, prop_name, - G_TYPE_INVALID, - G_TYPE_VALUE, &value, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, + "Get", + g_variant_new ("(ss)", interface, prop_name), + G_DBUS_CALL_FLAGS_NONE, 15000, + NULL, &err); + if (!ret) { dbgmsg ("%s: Error getting '%s' for %s: (%d) %s\n", __func__, prop_name, @@ -1312,35 +1345,43 @@ _nm_object_reload_property (NMObject *object, return; } - handle_property_changed (object, prop_name, &value, TRUE); - g_value_unset (&value); + value = g_variant_get_child_value (ret, 0); + handle_property_changed (object, prop_name, value, TRUE); + g_variant_unref (value); + g_variant_unref (ret); } void _nm_object_set_property (NMObject *object, const char *interface, const char *prop_name, - GValue *value) + const char *format_string, + ...) { + GVariant *val, *ret; + va_list ap; + g_return_if_fail (NM_IS_OBJECT (object)); g_return_if_fail (interface != NULL); g_return_if_fail (prop_name != NULL); - g_return_if_fail (G_IS_VALUE (value)); + g_return_if_fail (format_string != NULL); if (!NM_OBJECT_GET_PRIVATE (object)->nm_running) return; - if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, - "Set", 2000, NULL, - G_TYPE_STRING, interface, - G_TYPE_STRING, prop_name, - G_TYPE_VALUE, value, - G_TYPE_INVALID)) { - - /* Ignore errors. dbus_g_proxy_call_with_timeout() is called instead of - * dbus_g_proxy_call_no_reply() to give NM chance to authenticate the caller. - */ - } + va_start (ap, format_string); + val = g_variant_new_va (format_string, NULL, &ap); + va_end (ap); + g_return_if_fail (val != NULL); + + ret = g_dbus_proxy_call_sync (NM_OBJECT_GET_PRIVATE (object)->properties_proxy, + "Set", + g_variant_new ("(ssv)", interface, prop_name, val), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, NULL); + /* Ignore errors. */ + if (ret) + g_variant_unref (ret); } static void @@ -1372,19 +1413,21 @@ reload_complete (NMObject *object) } static void -reload_got_properties (DBusGProxy *proxy, DBusGProxyCall *call, +reload_got_properties (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMObject *object = user_data; NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); - GHashTable *props = NULL; + GVariant *ret, *props; GError *error = NULL; - if (dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + props = g_variant_get_child_value (ret, 0); process_properties_changed (object, props, FALSE); - g_hash_table_destroy (props); + g_variant_unref (props); + g_variant_unref (ret); } else { if (priv->reload_error) g_error_free (error); @@ -1423,10 +1466,12 @@ _nm_object_reload_properties_async (NMObject *object, GAsyncReadyCallback callba for (p = priv->property_interfaces; p; p = p->next) { priv->reload_remaining++; - dbus_g_proxy_begin_call (priv->properties_proxy, "GetAll", - reload_got_properties, object, NULL, - G_TYPE_STRING, p->data, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->properties_proxy, + "GetAll", + g_variant_new ("(s)", p->data), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + reload_got_properties, object); } } @@ -1445,7 +1490,7 @@ _nm_object_reload_properties_finish (NMObject *object, GAsyncResult *result, GEr return g_simple_async_result_get_op_res_gboolean (simple); } -DBusGProxy * +GDBusProxy * _nm_object_new_proxy (NMObject *self, const char *path, const char *interface) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); diff --git a/libnm/nm-object.h b/libnm/nm-object.h index 314313402a..467b391d23 100644 --- a/libnm/nm-object.h +++ b/libnm/nm-object.h @@ -26,9 +26,7 @@ #error "Only <NetworkManager.h> can be included directly." #endif -#include <glib.h> -#include <glib-object.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #include <nm-version.h> @@ -85,7 +83,7 @@ typedef struct { GType nm_object_get_type (void); -DBusGConnection *nm_object_get_connection (NMObject *object); +GDBusConnection *nm_object_get_connection (NMObject *object); const char *nm_object_get_path (NMObject *object); G_END_DECLS diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 1b124452b9..88c03a6969 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -29,7 +29,6 @@ #include "nm-remote-connection.h" #include "nm-remote-connection-private.h" #include "nm-object-private.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-dbus-helpers-private.h" @@ -63,21 +62,20 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; typedef struct RemoteCall RemoteCall; -typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error); +typedef void (*RemoteCallFetchResultCb) (RemoteCall *call, GAsyncResult *result, GError *error); typedef struct RemoteCall { NMRemoteConnection *self; - DBusGProxyCall *call; RemoteCallFetchResultCb fetch_result_cb; GFunc callback; gpointer user_data; } RemoteCall; typedef struct { - DBusGConnection *bus; - DBusGProxy *proxy; - DBusGProxy *props_proxy; + GDBusConnection *bus; + GDBusProxy *proxy; + GDBusProxy *props_proxy; gboolean proxy_is_destroyed; GSList *calls; @@ -108,21 +106,18 @@ nm_remote_connection_error_quark (void) /****************************************************************/ static void -remote_call_dbus_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data) +remote_call_dbus_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { RemoteCall *call = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (call->self); GError *error = NULL; - g_assert ( (!proxy && !proxy_call && priv->proxy_is_destroyed) || - ( proxy && proxy_call && !priv->proxy_is_destroyed && proxy == priv->proxy) ); - if (priv->proxy_is_destroyed) { error = g_error_new_literal (NM_REMOTE_CONNECTION_ERROR, NM_REMOTE_CONNECTION_ERROR_DISCONNECTED, _("Disconnected by D-Bus")); } - call->fetch_result_cb (call, proxy_call, error); + call->fetch_result_cb (call, result, error); g_clear_error (&error); priv->calls = g_slist_remove (priv->calls, call); @@ -165,39 +160,20 @@ remote_call_new (NMRemoteConnection *self, return call; } -static void -proxy_set_destroyed (NMRemoteConnection *self) -{ - NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - - if (priv->proxy_is_destroyed) { - g_assert (!priv->calls); - return; - } - - priv->proxy_is_destroyed = TRUE; - - priv->calls = g_slist_reverse (priv->calls); - while (priv->calls) - remote_call_dbus_cb (NULL, NULL, priv->calls->data); -} - -static void -proxy_destroy_cb (DBusGProxy* proxy, gpointer user_data) { - proxy_set_destroyed (user_data); -} - /****************************************************************/ static void -result_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) +result_cb (RemoteCall *call, GAsyncResult *result, GError *error) { NMRemoteConnectionResultFunc func = (NMRemoteConnectionResultFunc) call->callback; GError *local_error = NULL; + GVariant *ret; if (!error) { - dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, - proxy_call, &local_error, G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, + result, &local_error); + if (ret) + g_variant_unref (ret); error = local_error; } if (func) @@ -222,7 +198,7 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self, { NMRemoteConnectionPrivate *priv; RemoteCall *call; - GHashTable *settings; + GVariant *settings; g_return_if_fail (NM_IS_REMOTE_CONNECTION (self)); @@ -232,13 +208,14 @@ nm_remote_connection_commit_changes (NMRemoteConnection *self, if (!call) return; - settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL); - call->call = dbus_g_proxy_begin_call (priv->proxy, "Update", - remote_call_dbus_cb, call, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, - G_TYPE_INVALID); - g_assert (call->call); - g_hash_table_destroy (settings); + settings = nm_connection_to_variant (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "Update", + g_variant_new ("@a{sa{sv}}", settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); + g_variant_unref (settings); } /** @@ -259,7 +236,7 @@ nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, gpointer user_data) { NMRemoteConnectionPrivate *priv; - GHashTable *settings = NULL; + GVariant *settings; RemoteCall *call; g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); @@ -270,13 +247,14 @@ nm_remote_connection_commit_changes_unsaved (NMRemoteConnection *connection, if (!call) return; - settings = nm_connection_to_hash (NM_CONNECTION (connection), NM_SETTING_HASH_FLAG_ALL); - call->call = dbus_g_proxy_begin_call (priv->proxy, "UpdateUnsaved", - remote_call_dbus_cb, call, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings, - G_TYPE_INVALID); - g_assert (call->call); - g_hash_table_destroy (settings); + settings = nm_connection_to_variant (NM_CONNECTION (connection), NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "UpdateUnsaved", + g_variant_new ("@a{sa{sv}}", settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); + g_variant_unref (settings); } /** @@ -305,8 +283,12 @@ nm_remote_connection_save (NMRemoteConnection *connection, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "Save", remote_call_dbus_cb, call, NULL, G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "Save", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } /** @@ -333,31 +315,34 @@ nm_remote_connection_delete (NMRemoteConnection *self, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete", - remote_call_dbus_cb, call, NULL, - G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "Delete", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } static void -get_secrets_cb (RemoteCall *call, DBusGProxyCall *proxy_call, GError *error) +get_secrets_cb (RemoteCall *call, GAsyncResult *result, GError *error) { NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback; - GHashTable *secrets = NULL; + GVariant *ret, *secrets = NULL; GError *local_error = NULL; if (!error) { - dbus_g_proxy_end_call (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, - proxy_call, &local_error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, - G_TYPE_INVALID); - error = local_error; + ret = g_dbus_proxy_call_finish (NM_REMOTE_CONNECTION_GET_PRIVATE (call->self)->proxy, + result, &local_error); + if (ret) + g_variant_get (ret, "(@a{sa{sv}})", &secrets); + else + error = local_error; } if (func) (*func) (call->self, error ? NULL : secrets, error, call->user_data); g_clear_error (&local_error); if (secrets) - g_hash_table_destroy (secrets); + g_variant_unref (secrets); } @@ -389,11 +374,12 @@ nm_remote_connection_get_secrets (NMRemoteConnection *self, if (!call) return; - call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets", - remote_call_dbus_cb, call, NULL, - G_TYPE_STRING, setting_name, - G_TYPE_INVALID); - g_assert (call->call); + g_dbus_proxy_call (priv->proxy, + "GetSecrets", + g_variant_new ("(s)", setting_name), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remote_call_dbus_cb, call); } /** @@ -439,7 +425,7 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection) /****************************************************************/ static void -replace_settings (NMRemoteConnection *self, GHashTable *new_settings) +replace_settings (NMRemoteConnection *self, GVariant *new_settings) { GError *error = NULL; @@ -456,33 +442,28 @@ replace_settings (NMRemoteConnection *self, GHashTable *new_settings) } static void -updated_get_settings_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +updated_get_settings_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMRemoteConnection *self = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - GHashTable *new_settings; - GError *error = NULL; + GVariant *ret, *new_settings; gboolean visible; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings, - G_TYPE_INVALID); - if (error) { - GHashTable *hash; - - g_error_free (error); - + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, NULL); + if (!ret) { /* Connection is no longer visible to this user. */ - hash = g_hash_table_new (g_str_hash, g_str_equal); - nm_connection_replace_settings (NM_CONNECTION (self), hash, NULL); - g_hash_table_destroy (hash); + new_settings = g_variant_new ("a{sa{sv}}", NULL); + nm_connection_replace_settings (NM_CONNECTION (self), new_settings, NULL); + g_variant_unref (new_settings); visible = FALSE; } else { + g_variant_get (ret, "(@a{sa{sv}})", &new_settings); replace_settings (self, new_settings); - g_hash_table_destroy (new_settings); + g_variant_unref (new_settings); + g_variant_unref (ret); visible = TRUE; } @@ -494,35 +475,49 @@ updated_get_settings_cb (DBusGProxy *proxy, } static void -updated_cb (DBusGProxy *proxy, gpointer user_data) +updated_cb (GDBusProxy *proxy, gpointer user_data) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); /* The connection got updated; request the replacement settings */ if (!priv->proxy_is_destroyed) { - dbus_g_proxy_begin_call (priv->proxy, "GetSettings", - updated_get_settings_cb, self, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + updated_get_settings_cb, self); } } static void -properties_changed_cb (DBusGProxy *proxy, - GHashTable *properties, +properties_changed_cb (GDBusProxy *proxy, + GVariant *properties, gpointer user_data) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data); - GHashTableIter iter; - const char *key; - GValue *value; - - g_hash_table_iter_init (&iter, properties); - while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) { - if (!strcmp (key, "Unsaved")) { - NM_REMOTE_CONNECTION_GET_PRIVATE (self)->unsaved = g_value_get_boolean (value); - g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_UNSAVED); - } + NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); + + if (g_variant_lookup (properties, "Unsaved", "b", &priv->unsaved)) + g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_UNSAVED); +} + +static void +dbus_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + if (!strcmp (signal_name, "Updated")) + updated_cb (proxy, user_data); + else if (!strcmp (signal_name, "PropertiesChanged")) { + GVariant *dict; + + g_variant_get (parameters, "(@a{sv})", &dict); + properties_changed_cb (proxy, dict, user_data); + g_variant_unref (dict); } } @@ -540,29 +535,13 @@ init_common (NMRemoteConnection *self) nm_connection_get_path (NM_CONNECTION (self)), NM_DBUS_INTERFACE_SETTINGS_CONNECTION); g_assert (priv->proxy); - dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); - - dbus_g_proxy_add_signal (priv->proxy, "Updated", G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Updated", G_CALLBACK (updated_cb), self, NULL); - - g_signal_connect (priv->proxy, "destroy", G_CALLBACK (proxy_destroy_cb), self); - - /* Monitor properties */ - dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", - G_CALLBACK (properties_changed_cb), - self, - NULL); + + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (dbus_proxy_signal), self); priv->props_proxy = _nm_dbus_new_proxy_for_connection (priv->bus, nm_connection_get_path (NM_CONNECTION (self)), - DBUS_INTERFACE_PROPERTIES); + "org.freedesktop.DBus.Properties"); g_assert (priv->props_proxy); } @@ -571,29 +550,37 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable); - GHashTable *hash; + GVariant *ret, *dict; init_common (self); - if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (!ret) return FALSE; + priv->visible = TRUE; - replace_settings (self, hash); - g_hash_table_destroy (hash); + g_variant_get (ret, "(@a{sa{sv}})", &dict); + replace_settings (self, dict); + g_variant_unref (dict); + g_variant_unref (ret); /* Get properties */ - hash = NULL; - if (!dbus_g_proxy_call (priv->props_proxy, "GetAll", error, - G_TYPE_STRING, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - G_TYPE_INVALID, - DBUS_TYPE_G_MAP_OF_VARIANT, &hash, - G_TYPE_INVALID)) + ret = g_dbus_proxy_call_sync (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", NM_DBUS_INTERFACE_SETTINGS_CONNECTION), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (!ret) return FALSE; - properties_changed_cb (priv->props_proxy, hash, self); - g_hash_table_destroy (hash); + + g_variant_get (ret, "(@a{sv})", &dict); + properties_changed_cb (priv->props_proxy, dict, self); + g_variant_unref (dict); + g_variant_unref (ret); return TRUE; } @@ -617,49 +604,54 @@ init_async_complete (NMRemoteConnectionInitData *init_data, GError *error) } static void -init_async_got_properties (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +init_async_got_properties (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); - GHashTable *props; + GVariant *ret, *props; GError *error = NULL; - if (dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + g_variant_get (ret, "(@a{sv})", &props); properties_changed_cb (priv->props_proxy, props, init_data->connection); - g_hash_table_destroy (props); + g_variant_unref (props); + g_variant_unref (ret); } init_async_complete (init_data, error); } static void -init_get_settings_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +init_get_settings_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMRemoteConnectionInitData *init_data = user_data; NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection); - GHashTable *settings; + GVariant *ret, *settings; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); if (error) { init_async_complete (init_data, error); return; } priv->visible = TRUE; + g_variant_get (ret, "(@a{sa{sv}})", &settings); replace_settings (init_data->connection, settings); - g_hash_table_destroy (settings); + g_variant_unref (settings); + g_variant_unref (ret); /* Grab properties */ - dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", - init_async_got_properties, init_data, NULL, - G_TYPE_STRING, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", NM_DBUS_INTERFACE_SETTINGS_CONNECTION), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + init_async_got_properties, init_data); } static void @@ -677,9 +669,12 @@ init_async (GAsyncInitable *initable, int io_priority, init_common (init_data->connection); - dbus_g_proxy_begin_call (priv->proxy, "GetSettings", - init_get_settings_cb, init_data, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "GetSettings", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + init_get_settings_cb, init_data); } static gboolean @@ -770,7 +765,7 @@ set_property (GObject *object, guint prop_id, * properties isn't specified at construction time. */ if (!priv->bus) - priv->bus = g_value_dup_boxed (value); + priv->bus = g_value_dup_object (value); break; case PROP_DBUS_PATH: /* Don't need to do anything; see constructor(). */ @@ -787,18 +782,11 @@ dispose (GObject *object) NMRemoteConnection *self = NM_REMOTE_CONNECTION (object); NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); - proxy_set_destroyed (self); + priv->proxy_is_destroyed = TRUE; - if (priv->proxy) { - g_signal_handlers_disconnect_by_func (priv->proxy, proxy_destroy_cb, object); - g_clear_object (&priv->proxy); - } + g_clear_object (&priv->proxy); g_clear_object (&priv->props_proxy); - - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } + g_clear_object (&priv->bus); G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object); } @@ -819,20 +807,20 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class) /* Properties */ g_object_class_install_property (object_class, PROP_BUS, - g_param_spec_boxed (NM_REMOTE_CONNECTION_BUS, "", "", - DBUS_TYPE_G_CONNECTION, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_object (NM_REMOTE_CONNECTION_BUS, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); /* These are needed so _nm_object_create() can create NMRemoteConnections */ g_object_class_install_property (object_class, PROP_DBUS_CONNECTION, - g_param_spec_boxed (NM_REMOTE_CONNECTION_DBUS_CONNECTION, "", "", - DBUS_TYPE_G_CONNECTION, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_object (NM_REMOTE_CONNECTION_DBUS_CONNECTION, "", "", + G_TYPE_DBUS_CONNECTION, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DBUS_PATH, g_param_spec_string (NM_REMOTE_CONNECTION_DBUS_PATH, "", "", diff --git a/libnm/nm-remote-connection.h b/libnm/nm-remote-connection.h index de2ed2c4b4..12e4d0722e 100644 --- a/libnm/nm-remote-connection.h +++ b/libnm/nm-remote-connection.h @@ -27,7 +27,6 @@ #endif #include <glib-object.h> -#include <dbus/dbus-glib.h> #include <nm-connection.h> @@ -71,7 +70,7 @@ typedef struct { /* Signals */ void (*updated) (NMRemoteConnection *connection, - GHashTable *new_settings); + GVariant *new_settings); /* Padding for future expansion */ gpointer padding[8]; @@ -97,9 +96,7 @@ typedef NMRemoteConnectionResultFunc NMRemoteConnectionDeleteFunc; /** * NMRemoteConnectionGetSecretsFunc: * @connection: the connection for which secrets were requested - * @secrets: (element-type utf8 GLib.HashTable): on success, a hash table of - * hash tables, with each inner hash mapping a setting property to a #GValue - * containing that property's value + * @secrets: on success, a #GVariant of type %NM_VARIANT_TYPE_CONNECTION. * @error: on failure, a descriptive error * @user_data: user data passed to nm_remote_connection_get_secrets() * @@ -107,7 +104,7 @@ typedef NMRemoteConnectionResultFunc NMRemoteConnectionDeleteFunc; * secrets via nm_remote_connection_get_secrets(). */ typedef void (*NMRemoteConnectionGetSecretsFunc) (NMRemoteConnection *connection, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data); diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index f07b56db3e..3358295688 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -23,7 +23,6 @@ #include <nm-dbus-interface.h> #include <nm-connection.h> -#include "nm-dbus-glib-types.h" #include "nm-remote-settings.h" #include "nm-remote-connection-private.h" #include "nm-object-private.h" @@ -124,7 +123,7 @@ G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT) #define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; GPtrArray *all_connections; GPtrArray *visible_connections; @@ -429,14 +428,15 @@ nm_remote_settings_list_connections (NMRemoteSettings *settings) } static void -add_connection_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) +add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { AddConnectionInfo *info = user_data; GError *error = NULL; - char *path = NULL; + GVariant *ret; - if (dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_OBJECT_PATH, &path, G_TYPE_INVALID)) { - info->path = path; + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + g_variant_get (ret, "(o)", &info->path); /* Wait until this connection is fully initialized before calling the callback */ } else add_connection_info_complete (info->self, info, NULL, error); @@ -472,7 +472,7 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings, { NMRemoteSettingsPrivate *priv; AddConnectionInfo *info; - GHashTable *new_settings; + GVariant *new_settings; g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); @@ -488,14 +488,13 @@ nm_remote_settings_add_connection (NMRemoteSettings *settings, info->callback = callback; info->callback_data = user_data; - new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); - dbus_g_proxy_begin_call (priv->proxy, "AddConnection", - add_connection_done, - info, - NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings, - G_TYPE_INVALID); - g_hash_table_destroy (new_settings); + new_settings = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "AddConnection", + g_variant_new ("(@a{sa{sv}})", new_settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + add_connection_done, info); priv->add_list = g_slist_append (priv->add_list, info); @@ -525,7 +524,7 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings, { NMRemoteSettingsPrivate *priv; AddConnectionInfo *info; - GHashTable *new_settings; + GVariant *new_settings; g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); @@ -541,14 +540,13 @@ nm_remote_settings_add_connection_unsaved (NMRemoteSettings *settings, info->callback = callback; info->callback_data = user_data; - new_settings = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL); - dbus_g_proxy_begin_call (priv->proxy, "AddConnectionUnsaved", - add_connection_done, - info, - NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, new_settings, - G_TYPE_INVALID); - g_hash_table_destroy (new_settings); + new_settings = nm_connection_to_variant (connection, NM_SETTING_HASH_FLAG_ALL); + g_dbus_proxy_call (priv->proxy, + "AddConnectionUnsaved", + g_variant_new ("(@a{sa{sv}})", new_settings), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + add_connection_done, info); priv->add_list = g_slist_append (priv->add_list, info); @@ -585,8 +583,8 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings, GError **error) { NMRemoteSettingsPrivate *priv; - char **my_failures = NULL; - gboolean ret; + GVariant *ret; + gboolean success; g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); g_return_val_if_fail (filenames != NULL, FALSE); @@ -600,22 +598,18 @@ nm_remote_settings_load_connections (NMRemoteSettings *settings, return FALSE; } - if (!dbus_g_proxy_call (priv->proxy, "LoadConnections", error, - G_TYPE_STRV, filenames, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &ret, - G_TYPE_STRV, &my_failures, - G_TYPE_INVALID)) - ret = FALSE; - - if (failures) { - if (my_failures && !*my_failures) - g_clear_pointer (&my_failures, g_free); - *failures = my_failures; + ret = g_dbus_proxy_call_sync (priv->proxy, + "LoadConnections", + g_variant_new ("(as)", filenames), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, error); + if (ret) { + g_variant_get (ret, "(b^as)", &success, failures); + g_variant_unref (ret); } else - g_strfreev (my_failures); + success = FALSE; - return ret; + return success; } /** @@ -634,6 +628,7 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings, GError **error) { NMRemoteSettingsPrivate *priv; + GVariant *ret; gboolean success; g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE); @@ -647,11 +642,17 @@ nm_remote_settings_reload_connections (NMRemoteSettings *settings, return FALSE; } - if (!dbus_g_proxy_call (priv->proxy, "ReloadConnections", error, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &success, - G_TYPE_INVALID)) - return FALSE; + ret = g_dbus_proxy_call_sync (priv->proxy, + "ReloadConnections", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, error); + if (ret) { + g_variant_get (ret, "(b)", &success); + g_variant_unref (ret); + } else + success = FALSE; + return success; } @@ -662,17 +663,19 @@ typedef struct { } SaveHostnameInfo; static void -save_hostname_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +save_hostname_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { SaveHostnameInfo *info = user_data; + GVariant *ret; GError *error = NULL; - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); if (info->callback != NULL) info->callback (info->settings, error, info->callback_data); g_clear_error (&error); + g_clear_pointer (&ret, g_variant_unref); } /** @@ -712,12 +715,12 @@ nm_remote_settings_save_hostname (NMRemoteSettings *settings, info->callback = callback; info->callback_data = user_data; - dbus_g_proxy_begin_call (priv->proxy, "SaveHostname", - save_hostname_cb, - info, - g_free, - G_TYPE_STRING, hostname ? hostname : "", - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "SaveHostname", + g_variant_new ("(s)", hostname ? hostname : ""), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + save_hostname_cb, info); return TRUE; } diff --git a/libnm/nm-secret-agent.c b/libnm/nm-secret-agent.c index 1832ba73c9..46525aa095 100644 --- a/libnm/nm-secret-agent.c +++ b/libnm/nm-secret-agent.c @@ -20,7 +20,6 @@ #include <config.h> #include <string.h> -#include <dbus/dbus-glib-lowlevel.h> #include "nm-glib-compat.h" #include "nm-dbus-interface.h" @@ -28,30 +27,7 @@ #include "nm-enum-types.h" #include "nm-dbus-helpers-private.h" -static void impl_secret_agent_get_secrets (NMSecretAgent *self, - GHashTable *connection_hash, - const char *connection_path, - const char *setting_name, - const char **hints, - guint32 flags, - DBusGMethodInvocation *context); - -static void impl_secret_agent_cancel_get_secrets (NMSecretAgent *self, - const char *connection_path, - const char *setting_name, - DBusGMethodInvocation *context); - -static void impl_secret_agent_save_secrets (NMSecretAgent *self, - GHashTable *connection_hash, - const char *connection_path, - DBusGMethodInvocation *context); - -static void impl_secret_agent_delete_secrets (NMSecretAgent *self, - GHashTable *connection_hash, - const char *connection_path, - DBusGMethodInvocation *context); - -#include "nm-secret-agent-glue.h" +#include "nm-secret-agent-generated.h" G_DEFINE_ABSTRACT_TYPE (NMSecretAgent, nm_secret_agent, G_TYPE_OBJECT) @@ -63,15 +39,16 @@ typedef struct { gboolean registered; NMSecretAgentCapabilities capabilities; - DBusGConnection *bus; + GDBusConnection *bus; gboolean private_bus; - DBusGProxy *dbus_proxy; - DBusGProxy *manager_proxy; - DBusGProxyCall *reg_call; + GDBusProxy *manager_proxy; + gboolean registering; + NMPrivSecretAgent *gdbus_agent; /* GetSecretsInfo structs of in-flight GetSecrets requests */ GSList *pending_gets; + guint nm_watch; char *nm_owner; char *identifier; @@ -113,36 +90,13 @@ nm_secret_agent_error_quark (void) /*************************************************************/ -static const char * -get_nm_owner (NMSecretAgent *self) -{ - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - GError *error = NULL; - char *owner; - - if (!priv->nm_owner) { - if (!dbus_g_proxy_call_with_timeout (priv->dbus_proxy, - "GetNameOwner", 2000, &error, - G_TYPE_STRING, NM_DBUS_SERVICE, - G_TYPE_INVALID, - G_TYPE_STRING, &owner, - G_TYPE_INVALID)) - return NULL; - - priv->nm_owner = g_strdup (owner); - g_free (owner); - } - - return priv->nm_owner; -} - static void _internal_unregister (NMSecretAgent *self) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); if (priv->registered) { - dbus_g_connection_unregister_g_object (priv->bus, G_OBJECT (self)); + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (priv->gdbus_agent)); priv->registered = FALSE; g_object_notify (G_OBJECT (self), NM_SECRET_AGENT_REGISTERED); } @@ -151,7 +105,7 @@ _internal_unregister (NMSecretAgent *self) typedef struct { char *path; char *setting_name; - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; } GetSecretsInfo; static void @@ -169,60 +123,13 @@ get_secrets_info_finalize (NMSecretAgent *self, GetSecretsInfo *info) g_free (info); } -static void -name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) -{ - NMSecretAgent *self = NM_SECRET_AGENT (user_data); - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - gboolean old_owner_good = (old_owner && strlen (old_owner)); - gboolean new_owner_good = (new_owner && strlen (new_owner)); - GSList *iter; - - if (strcmp (name, NM_DBUS_SERVICE) == 0) { - g_free (priv->nm_owner); - priv->nm_owner = g_strdup (new_owner); - - if (!old_owner_good && new_owner_good) { - /* NM appeared */ - auto_register_cb (self); - } else if (old_owner_good && !new_owner_good) { - /* Cancel any pending secrets requests */ - for (iter = priv->pending_gets; iter; iter = g_slist_next (iter)) { - GetSecretsInfo *info = iter->data; - - NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, - info->path, - info->setting_name); - } - g_slist_free (priv->pending_gets); - priv->pending_gets = NULL; - - /* NM disappeared */ - _internal_unregister (self); - } else if (old_owner_good && new_owner_good && strcmp (old_owner, new_owner)) { - /* Hmm, NM magically restarted */ - _internal_unregister (self); - auto_register_cb (self); - } - } -} - static gboolean verify_sender (NMSecretAgent *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, GError **error) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); - DBusConnection *bus; - char *sender; - const char *nm_owner; - DBusError dbus_error; - uid_t sender_uid = G_MAXUINT; - gboolean allowed = FALSE; + const char *sender; g_return_val_if_fail (context != NULL, FALSE); @@ -235,9 +142,7 @@ verify_sender (NMSecretAgent *self, /* Verify the sender's UID is 0, and that the sender is the same as * NetworkManager's bus name owner. */ - - nm_owner = get_nm_owner (self); - if (!nm_owner) { + if (!priv->nm_owner) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, @@ -245,16 +150,7 @@ verify_sender (NMSecretAgent *self, return FALSE; } - bus = dbus_g_connection_get_connection (priv->bus); - if (!bus) { - g_set_error_literal (error, - NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, - "Failed to get DBus connection."); - return FALSE; - } - - sender = dbus_g_method_get_sender (context); + sender = g_dbus_method_invocation_get_sender (context); if (!sender) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, @@ -264,15 +160,15 @@ verify_sender (NMSecretAgent *self, } /* Check that the sender matches the current NM bus name owner */ - if (strcmp (sender, nm_owner) != 0) { + if (strcmp (sender, priv->nm_owner) != 0) { g_set_error_literal (error, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, "Request sender does not match NetworkManager bus name owner."); - goto out; + return FALSE; } - dbus_error_init (&dbus_error); +#if 0 /* FIXME: check the UID of the sender */ sender_uid = dbus_bus_get_unix_user (bus, sender, &dbus_error); if (dbus_error_is_set (&dbus_error)) { g_set_error (error, @@ -281,7 +177,7 @@ verify_sender (NMSecretAgent *self, "Failed to get request unix user: (%s) %s.", dbus_error.name, dbus_error.message); dbus_error_free (&dbus_error); - goto out; + return FALSE; } /* We only accept requests from NM, which always runs as root */ @@ -290,20 +186,17 @@ verify_sender (NMSecretAgent *self, NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED, "Request sender is not root."); - goto out; + return FALSE; } +#endif - allowed = TRUE; - -out: - g_free (sender); - return allowed; + return TRUE; } static gboolean verify_request (NMSecretAgent *self, - DBusGMethodInvocation *context, - GHashTable *connection_hash, + GDBusMethodInvocation *context, + GVariant *connection_hash, const char *connection_path, NMConnection **out_connection, GError **error) @@ -329,7 +222,7 @@ verify_request (NMSecretAgent *self, /* Make sure the given connection is valid */ g_assert (out_connection); - connection = nm_connection_new_from_hash (connection_hash, &local); + connection = nm_connection_new_from_variant (connection_hash, &local); if (connection) { nm_connection_set_path (connection, connection_path); *out_connection = connection; @@ -349,30 +242,34 @@ verify_request (NMSecretAgent *self, static void get_secrets_cb (NMSecretAgent *self, NMConnection *connection, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { GetSecretsInfo *info = user_data; if (error) - dbus_g_method_return_error (info->context, error); - else - dbus_g_method_return (info->context, secrets); + g_dbus_method_invocation_return_gerror (info->context, error); + else { + g_dbus_method_invocation_return_value (info->context, + g_variant_new ("(@a{sa{sv}})", secrets)); + } /* Remove the request from internal tracking */ get_secrets_info_finalize (self, info); } static void -impl_secret_agent_get_secrets (NMSecretAgent *self, - GHashTable *connection_hash, +impl_secret_agent_get_secrets (NMPrivSecretAgent *gdbus_agent, + GDBusMethodInvocation *context, + GVariant *connection_hash, const char *connection_path, const char *setting_name, - const char **hints, - guint32 flags, - DBusGMethodInvocation *context) + const char * const *hints, + guint flags, + gpointer user_data) { + NMSecretAgent *self = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); GError *error = NULL; NMConnection *connection = NULL; @@ -380,8 +277,7 @@ impl_secret_agent_get_secrets (NMSecretAgent *self, /* Make sure the request comes from NetworkManager and is valid */ if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -395,7 +291,7 @@ impl_secret_agent_get_secrets (NMSecretAgent *self, connection, connection_path, setting_name, - hints, + (const char **) hints, flags, get_secrets_cb, info); @@ -418,30 +314,29 @@ find_get_secrets_info (GSList *list, const char *path, const char *setting_name) } static void -impl_secret_agent_cancel_get_secrets (NMSecretAgent *self, +impl_secret_agent_cancel_get_secrets (NMPrivSecretAgent *gdbus_agent, + GDBusMethodInvocation *context, const char *connection_path, const char *setting_name, - DBusGMethodInvocation *context) + gpointer user_data) { + NMSecretAgent *self = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); GError *error = NULL; GetSecretsInfo *info; /* Make sure the request comes from NetworkManager and is valid */ if (!verify_request (self, context, NULL, NULL, NULL, &error)) { - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } info = find_get_secrets_info (priv->pending_gets, connection_path, setting_name); if (!info) { - g_set_error_literal (&error, - NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, - "No secrets request in progress for this connection."); - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_return_error (context, + NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, + "No secrets request in progress for this connection."); return; } @@ -449,7 +344,7 @@ impl_secret_agent_cancel_get_secrets (NMSecretAgent *self, NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, info->path, info->setting_name); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void @@ -458,27 +353,28 @@ save_secrets_cb (NMSecretAgent *self, GError *error, gpointer user_data) { - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void -impl_secret_agent_save_secrets (NMSecretAgent *self, - GHashTable *connection_hash, +impl_secret_agent_save_secrets (NMPrivSecretAgent *gdbus_agent, + GDBusMethodInvocation *context, + GVariant *connection_hash, const char *connection_path, - DBusGMethodInvocation *context) + gpointer user_data) { + NMSecretAgent *self = user_data; GError *error = NULL; NMConnection *connection = NULL; /* Make sure the request comes from NetworkManager and is valid */ if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -496,27 +392,28 @@ delete_secrets_cb (NMSecretAgent *self, GError *error, gpointer user_data) { - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void -impl_secret_agent_delete_secrets (NMSecretAgent *self, - GHashTable *connection_hash, +impl_secret_agent_delete_secrets (NMPrivSecretAgent *gdbus_agent, + GDBusMethodInvocation *context, + GVariant *connection_hash, const char *connection_path, - DBusGMethodInvocation *context) + gpointer user_data) { + NMSecretAgent *self = user_data; GError *error = NULL; NMConnection *connection = NULL; /* Make sure the request comes from NetworkManager and is valid */ if (!verify_request (self, context, connection_hash, connection_path, &connection, &error)) { - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); return; } @@ -535,6 +432,8 @@ reg_result (NMSecretAgent *self, GError *error) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + priv->registering = FALSE; + if (error) { /* If registration failed we shouldn't expose ourselves on the bus */ _internal_unregister (self); @@ -547,32 +446,32 @@ reg_result (NMSecretAgent *self, GError *error) } static void -reg_request_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +reg_request_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMSecretAgent *self = NM_SECRET_AGENT (user_data); - NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + GVariant *ret; GError *error = NULL; - priv->reg_call = NULL; - - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); reg_result (self, error); g_clear_error (&error); + g_clear_pointer (&ret, g_variant_unref); } static void -reg_with_caps_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +reg_with_caps_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { NMSecretAgent *self = NM_SECRET_AGENT (user_data); NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + GVariant *ret; - priv->reg_call = NULL; - - if (dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, NULL); + if (ret) { + g_variant_unref (ret); reg_result (self, NULL); return; } @@ -580,14 +479,12 @@ reg_with_caps_cb (DBusGProxy *proxy, /* Might be an old NetworkManager that doesn't support capabilities; * fall back to old Register() method instead. */ - priv->reg_call = dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy, - "Register", - reg_request_cb, - self, - NULL, - 5000, - G_TYPE_STRING, priv->identifier, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->manager_proxy, + "Register", + g_variant_new ("(s)", priv->identifier), + G_DBUS_CALL_FLAGS_NONE, 5000, + NULL, + reg_request_cb, self); } /** @@ -609,13 +506,14 @@ nm_secret_agent_register (NMSecretAgent *self) { NMSecretAgentPrivate *priv; NMSecretAgentClass *class; + GError *error = NULL; g_return_val_if_fail (NM_IS_SECRET_AGENT (self), FALSE); priv = NM_SECRET_AGENT_GET_PRIVATE (self); g_return_val_if_fail (priv->registered == FALSE, FALSE); - g_return_val_if_fail (priv->reg_call == NULL, FALSE); + g_return_val_if_fail (priv->registering == FALSE, FALSE); g_return_val_if_fail (priv->bus != NULL, FALSE); g_return_val_if_fail (priv->manager_proxy != NULL, FALSE); @@ -628,22 +526,25 @@ nm_secret_agent_register (NMSecretAgent *self) if (!priv->nm_owner && !priv->private_bus) return FALSE; - priv->suppress_auto = FALSE; - /* Export our secret agent interface before registering with the manager */ - dbus_g_connection_register_g_object (priv->bus, - NM_DBUS_PATH_SECRET_AGENT, - G_OBJECT (self)); - - priv->reg_call = dbus_g_proxy_begin_call_with_timeout (priv->manager_proxy, - "RegisterWithCapabilities", - reg_with_caps_cb, - self, - NULL, - 5000, - G_TYPE_STRING, priv->identifier, - G_TYPE_UINT, priv->capabilities, - G_TYPE_INVALID); + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->gdbus_agent), + priv->bus, + NM_DBUS_PATH_SECRET_AGENT, + &error)) { + g_warning ("NMSecretAgent registration failed: %s", error->message); + g_error_free (error); + return FALSE; + } + + priv->suppress_auto = FALSE; + priv->registering = TRUE; + + g_dbus_proxy_call (priv->manager_proxy, + "RegisterWithCapabilities", + g_variant_new ("(su)", priv->identifier, priv->capabilities), + G_DBUS_CALL_FLAGS_NONE, 5000, + NULL, + reg_with_caps_cb, self); return TRUE; } @@ -661,6 +562,7 @@ gboolean nm_secret_agent_unregister (NMSecretAgent *self) { NMSecretAgentPrivate *priv; + GVariant *ret; g_return_val_if_fail (NM_IS_SECRET_AGENT (self), FALSE); @@ -673,7 +575,12 @@ nm_secret_agent_unregister (NMSecretAgent *self) if (!priv->nm_owner && !priv->private_bus) return FALSE; - dbus_g_proxy_call_no_reply (priv->manager_proxy, "Unregister", G_TYPE_INVALID); + ret = g_dbus_proxy_call_sync (priv->manager_proxy, + "Unregister", + NULL, + G_DBUS_CALL_FLAGS_NONE, 0, + NULL, NULL); + g_variant_unref (ret); _internal_unregister (self); priv->suppress_auto = TRUE; @@ -702,7 +609,7 @@ auto_register_cb (gpointer user_data) NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); priv->auto_register_id = 0; - if (priv->auto_register && !priv->suppress_auto && (priv->reg_call == NULL)) + if (priv->auto_register && !priv->suppress_auto && !priv->registering) nm_secret_agent_register (self); return FALSE; } @@ -840,6 +747,48 @@ validate_identifier (const char *identifier) } static void +nm_service_appeared (GDBusConnection *connection, + const char *name, + const char *name_owner, + gpointer user_data) +{ + NMSecretAgent *self = NM_SECRET_AGENT (user_data); + NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + + g_free (priv->nm_owner); + priv->nm_owner = g_strdup (name_owner); + + _internal_unregister (self); + auto_register_cb (self); +} + +static void +nm_service_vanished (GDBusConnection *connection, + const char *name, + gpointer user_data) +{ + NMSecretAgent *self = NM_SECRET_AGENT (user_data); + NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); + GSList *iter; + + g_free (priv->nm_owner); + priv->nm_owner = NULL; + + /* Cancel any pending secrets requests */ + for (iter = priv->pending_gets; iter; iter = g_slist_next (iter)) { + GetSecretsInfo *info = iter->data; + + NM_SECRET_AGENT_GET_CLASS (self)->cancel_get_secrets (self, + info->path, + info->setting_name); + } + g_slist_free (priv->pending_gets); + priv->pending_gets = NULL; + + _internal_unregister (self); +} + +static void nm_secret_agent_init (NMSecretAgent *self) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); @@ -854,25 +803,12 @@ nm_secret_agent_init (NMSecretAgent *self) priv->private_bus = _nm_dbus_is_connection_private (priv->bus); if (priv->private_bus == FALSE) { - priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - g_assert (priv->dbus_proxy); - - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->dbus_proxy, - "NameOwnerChanged", - G_CALLBACK (name_owner_changed), - self, NULL); - - get_nm_owner (self); + priv->nm_watch = g_bus_watch_name_on_connection (priv->bus, + NM_DBUS_SERVICE, + G_BUS_NAME_WATCHER_FLAGS_NONE, + nm_service_appeared, + nm_service_vanished, + self, NULL); } priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus, @@ -883,7 +819,17 @@ nm_secret_agent_init (NMSecretAgent *self) return; } - if (priv->nm_owner || priv->private_bus) + priv->gdbus_agent = nmpriv_secret_agent_skeleton_new (); + g_signal_connect (priv->gdbus_agent, "handle-get-secrets", + G_CALLBACK (impl_secret_agent_get_secrets), self); + g_signal_connect (priv->gdbus_agent, "handle-cancel-get-secrets", + G_CALLBACK (impl_secret_agent_cancel_get_secrets), self); + g_signal_connect (priv->gdbus_agent, "handle-delete-secrets", + G_CALLBACK (impl_secret_agent_delete_secrets), self); + g_signal_connect (priv->gdbus_agent, "handle-save-secrets", + G_CALLBACK (impl_secret_agent_save_secrets), self); + + if (priv->private_bus) priv->auto_register_id = g_idle_add (auto_register_cb, self); } @@ -962,17 +908,20 @@ dispose (GObject *object) priv->identifier = NULL; g_free (priv->nm_owner); priv->nm_owner = NULL; + if (priv->nm_watch) { + g_bus_unwatch_name (priv->nm_watch); + priv->nm_watch = 0; + } while (priv->pending_gets) get_secrets_info_finalize (self, priv->pending_gets->data); - g_clear_object (&priv->dbus_proxy); - g_clear_object (&priv->manager_proxy); + g_signal_handlers_disconnect_matched (priv->gdbus_agent, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, self); + g_object_unref (priv->gdbus_agent); - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } + g_clear_object (&priv->manager_proxy); + g_clear_object (&priv->bus); G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object); } @@ -1068,10 +1017,7 @@ nm_secret_agent_class_init (NMSecretAgentClass *class) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_POINTER); - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (class), - &dbus_glib_nm_secret_agent_object_info); - - dbus_g_error_domain_register (NM_SECRET_AGENT_ERROR, - NM_DBUS_INTERFACE_SECRET_AGENT, - NM_TYPE_SECRET_AGENT_ERROR); + _nm_dbus_register_error_domain (NM_SECRET_AGENT_ERROR, + NM_DBUS_INTERFACE_SECRET_AGENT, + NM_TYPE_SECRET_AGENT_ERROR); } diff --git a/libnm/nm-secret-agent.h b/libnm/nm-secret-agent.h index c5ef2640d9..1ff86e5842 100644 --- a/libnm/nm-secret-agent.h +++ b/libnm/nm-secret-agent.h @@ -128,13 +128,8 @@ typedef struct { * note that this object will be unrefed after the callback has returned, use * g_object_ref()/g_object_unref() if you want to use this object after the callback * has returned - * @secrets: (element-type utf8 GLib.HashTable): the #GHashTable containing - * the requested secrets in the same format as an #NMConnection hash (as - * created by nm_connection_to_hash() for example). Each key in @secrets - * should be the name of a #NMSetting object (like "802-11-wireless-security") - * and each value should be a #GHashTable. The sub-hashes map string:#GValue - * where the string is the setting property name (like "psk") and the value - * is the secret + * @secrets: the #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing + * the requested secrets. * @error: if the secrets request failed, give a descriptive error here * @user_data: caller-specific data to be passed to the function * @@ -143,14 +138,14 @@ typedef struct { * return them, or to return an error, this function should be called with * those secrets or the error. * - * To easily create the hash table to return the Wi-Fi PSK, you could do + * To easily create the variant to return the Wi-Fi PSK, you could do * something like this: * <example> * <title>Creating a secrets hash</title> * <programlisting> * NMConnection *secrets; * NMSettingWirelessSecurity *s_wsec; - * GHashTable *secrets_hash; + * GVariant *secrets_hash; * * secrets = nm_connection_new (); * s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); @@ -158,18 +153,18 @@ typedef struct { * NM_SETTING_WIRELESS_SECURITY_PSK, "my really cool PSK", * NULL); * nm_connection_add_setting (secrets, NM_SETTING (s_wsec)); - * secrets_hash = nm_connection_to_hash (secrets, NM_SETTING_HASH_FLAG_ALL); + * secrets_hash = nm_connection_to_variant (secrets, NM_SETTING_HASH_FLAG_ALL); * * (call the NMSecretAgentGetSecretsFunc with secrets_hash) * * g_object_unref (secrets); - * g_hash_table_unref (secrets_hash); + * g_variant_unref (secrets_hash); * </programlisting> * </example> */ typedef void (*NMSecretAgentGetSecretsFunc) (NMSecretAgent *agent, NMConnection *connection, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data); diff --git a/libnm/nm-types-private.h b/libnm/nm-types-private.h deleted file mode 100644 index c34d9a8f7c..0000000000 --- a/libnm/nm-types-private.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2008 Red Hat, Inc. - */ - -#ifndef NM_TYPES_PRIVATE_H -#define NM_TYPES_PRIVATE_H - -#include <dbus/dbus-glib.h> -#include "nm-types.h" -#include "nm-object-private.h" - -gboolean _nm_ssid_demarshal (GValue *value, GByteArray **dest); -gboolean _nm_uint_array_demarshal (GValue *value, GArray **dest); -gboolean _nm_string_array_demarshal (GValue *value, GPtrArray **dest); -gboolean _nm_object_array_demarshal (GValue *value, - GPtrArray **dest, - DBusGConnection *connection, - NMObjectCreatorFunc func); -gboolean _nm_ip6_address_array_demarshal (GValue *value, GSList **dest); - -#endif /* NM_TYPES_PRIVATE_H */ diff --git a/libnm/nm-types.c b/libnm/nm-types.c index 47c5c9b2d8..e41f76353c 100644 --- a/libnm/nm-types.c +++ b/libnm/nm-types.c @@ -19,13 +19,10 @@ */ #include <glib.h> -#include <dbus/dbus-glib.h> #include <string.h> #include "nm-types.h" -#include "nm-types-private.h" #include "nm-object-private.h" #include "nm-object-cache.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-ip6-config.h" static gpointer @@ -62,52 +59,6 @@ nm_object_array_get_type (void) return our_type; } -gboolean -_nm_object_array_demarshal (GValue *value, - GPtrArray **dest, - DBusGConnection *connection, - NMObjectCreatorFunc func) -{ - GPtrArray *temp = NULL; - GPtrArray *array; - - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) - return FALSE; - - array = (GPtrArray *) g_value_get_boxed (value); - if (array && array->len) { - int i; - - temp = g_ptr_array_sized_new (array->len); - for (i = 0; i < array->len; i++) { - const char *path; - GObject *object; - - path = g_ptr_array_index (array, i); - object = G_OBJECT (_nm_object_cache_get (path)); - if (object) - g_ptr_array_add (temp, object); - else { - object = (*func) (connection, path); - if (object) - g_ptr_array_add (temp, object); - else - g_warning ("%s: couldn't create object for %s", __func__, path); - } - } - } else - temp = g_ptr_array_new (); - - /* Deallocate after to ensure that an object that might already - * be in the array doesn't get destroyed due to refcounting. - */ - if (*dest) - g_boxed_free (NM_TYPE_OBJECT_ARRAY, *dest); - *dest = temp; - - return TRUE; -} - /*****************************/ static gpointer diff --git a/libnm/nm-vpn-connection.c b/libnm/nm-vpn-connection.c index 8ee207e519..2a1e1e4ca1 100644 --- a/libnm/nm-vpn-connection.c +++ b/libnm/nm-vpn-connection.c @@ -31,7 +31,7 @@ G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) #define NM_VPN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_CONNECTION, NMVpnConnectionPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *banner; NMVpnConnectionState vpn_state; } NMVpnConnectionPrivate; @@ -94,14 +94,23 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn) } static void -vpn_state_changed_proxy (DBusGProxy *proxy, - NMVpnConnectionState vpn_state, - NMVpnConnectionStateReason reason, - gpointer user_data) +vpn_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); + NMVpnConnectionState vpn_state; + NMVpnConnectionStateReason reason; + + if (strcmp (signal_name, "VpnStateChanged") != 0) + return; + + g_return_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(uu)"))); + g_variant_get (parameters, "(uu)", &vpn_state, &reason); if (priv->vpn_state != vpn_state) { priv->vpn_state = vpn_state; g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason); @@ -136,16 +145,8 @@ init_dbus_properties (NMObject *object) priv->proxy, property_info); - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - G_TYPE_UINT, G_TYPE_UINT, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "VpnStateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, - "VpnStateChanged", - G_CALLBACK (vpn_state_changed_proxy), - object, - NULL); + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (vpn_proxy_signal), object); } static void diff --git a/libnm/nm-vpn-connection.h b/libnm/nm-vpn-connection.h index 598c824b1b..8a34ccc70c 100644 --- a/libnm/nm-vpn-connection.h +++ b/libnm/nm-vpn-connection.h @@ -28,7 +28,6 @@ #include <glib.h> #include <glib-object.h> -#include <dbus/dbus-glib.h> #include "nm-active-connection.h" #include "nm-vpn-dbus-interface.h" diff --git a/libnm/nm-vpn-plugin.c b/libnm/nm-vpn-plugin.c index 18f288cd03..b684499b16 100644 --- a/libnm/nm-vpn-plugin.c +++ b/libnm/nm-vpn-plugin.c @@ -29,45 +29,9 @@ #include "nm-vpn-enum-types.h" #include "nm-utils.h" #include "nm-connection.h" +#include "nm-dbus-helpers-private.h" -static gboolean impl_vpn_plugin_connect (NMVpnPlugin *plugin, - GHashTable *connection, - GError **error); - -static gboolean impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin, - GHashTable *connection, - GHashTable *details, - GError **error); - -static gboolean impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, - GHashTable *connection, - char **service_name, - GError **err); - -static gboolean impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, - GHashTable *connection, - GError **err); - -static gboolean impl_vpn_plugin_disconnect (NMVpnPlugin *plugin, - GError **err); - -static gboolean impl_vpn_plugin_set_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err); - -static gboolean impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err); - -static gboolean impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err); - -static gboolean impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, - char *reason, - GError **err); - -#include "nm-vpn-plugin-glue.h" +#include "nm-vpn-plugin-generated.h" #define NM_VPN_PLUGIN_QUIT_TIMER 20 @@ -81,7 +45,8 @@ typedef struct { NMVpnServiceState state; /* DBUS-y stuff */ - DBusGConnection *connection; + GDBusConnection *connection; + NMPrivVPNPlugin *gdbus_plugin; char *dbus_service_name; /* Temporary stuff */ @@ -95,7 +60,7 @@ typedef struct { gboolean has_ip6, got_ip6; /* Config stuff copied from config to ip4config */ - GValue banner, tundev, gateway, mtu; + char *banner, *tundev, *gateway, *mtu; } NMVpnPluginPrivate; #define NM_VPN_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_PLUGIN, NMVpnPluginPrivate)) @@ -140,27 +105,27 @@ nm_vpn_plugin_error_quark (void) static void nm_vpn_plugin_set_connection (NMVpnPlugin *plugin, - DBusGConnection *connection) + GDBusConnection *connection) { NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); if (priv->connection) - dbus_g_connection_unref (priv->connection); + g_object_unref (priv->connection); - priv->connection = connection; + priv->connection = g_object_ref (connection); } -DBusGConnection * +GDBusConnection * nm_vpn_plugin_get_connection (NMVpnPlugin *plugin) { - DBusGConnection *connection; + GDBusConnection *connection; g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), NULL); connection = NM_VPN_PLUGIN_GET_PRIVATE (plugin)->connection; if (connection) - dbus_g_connection_ref (connection); + g_object_ref (connection); return connection; } @@ -301,60 +266,46 @@ schedule_fail_stop (NMVpnPlugin *plugin) priv->fail_stop_id = g_idle_add (fail_stop, plugin); } -static void -_g_value_set (GValue *dst, GValue *src) -{ - if (src) { - GType type = G_VALUE_TYPE (src); - - if (G_IS_VALUE (dst)) - g_value_unset (dst); - g_value_init (dst, type); - g_value_copy (src, dst); - } else if (G_IS_VALUE (dst)) - g_value_unset (dst); -} - void nm_vpn_plugin_set_config (NMVpnPlugin *plugin, - GHashTable *config) + GVariant *config) { NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); - GValue *val; g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); g_return_if_fail (config != NULL); priv->got_config = TRUE; - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4); - if (val && g_value_get_boolean (val)) - priv->has_ip4 = TRUE; - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6); - if (val && g_value_get_boolean (val)) - priv->has_ip6 = TRUE; + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &priv->has_ip4); + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &priv->has_ip6); g_warn_if_fail (priv->has_ip4 || priv->has_ip6); /* Record the items that need to also be inserted into the * ip4config, for compatibility with older daemons. */ - _g_value_set (&priv->banner, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER)); - _g_value_set (&priv->tundev, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV)); - _g_value_set (&priv->gateway, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY)); - _g_value_set (&priv->mtu, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU)); + g_clear_pointer (&priv->banner, g_free); + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &priv->banner); + g_clear_pointer (&priv->tundev, g_free); + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &priv->tundev); + g_clear_pointer (&priv->gateway, g_free); + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "&s", &priv->gateway); + g_clear_pointer (&priv->mtu, g_free); + g_variant_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU, "&s", &priv->mtu); g_signal_emit (plugin, signals[CONFIG], 0, config); } void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GHashTable *ip4_config) + GVariant *ip4_config) { NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); - GHashTable *combined_config; - GHashTableIter iter; - gpointer key, value; + GVariant *combined_config; + GVariantBuilder builder; + GVariantIter iter; + const char *key, *value; g_return_if_fail (NM_IS_VPN_PLUGIN (plugin)); g_return_if_fail (ip4_config != NULL); @@ -374,22 +325,24 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, * being emitted. So just copy all of that data into the ip4 * config too. */ - combined_config = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_iter_init (&iter, ip4_config); - while (g_hash_table_iter_next (&iter, &key, &value)) - g_hash_table_insert (combined_config, key, value); - - if (G_VALUE_TYPE (&priv->banner) != G_TYPE_INVALID) - g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner); - if (G_VALUE_TYPE (&priv->tundev) != G_TYPE_INVALID) - g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev); - if (G_VALUE_TYPE (&priv->gateway) != G_TYPE_INVALID) - g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway); - if (G_VALUE_TYPE (&priv->mtu) != G_TYPE_INVALID) - g_hash_table_insert (combined_config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, &priv->mtu); - + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); + g_variant_iter_init (&iter, ip4_config); + while (g_variant_iter_next (&iter, "{&s&s}", &key, &value)) + g_variant_builder_add (&builder, "{ss}", key, value); + + if (priv->banner) + g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_BANNER, &priv->banner); + if (priv->tundev) + g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, &priv->tundev); + if (priv->gateway) + g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY, &priv->gateway); + if (priv->mtu) + g_variant_builder_add (&builder, "{ss}", NM_VPN_PLUGIN_IP4_CONFIG_MTU, &priv->mtu); + + combined_config = g_variant_builder_end (&builder); + g_variant_ref_sink (combined_config); g_signal_emit (plugin, signals[IP4_CONFIG], 0, combined_config); - g_hash_table_destroy (combined_config); + g_variant_unref (combined_config); if ( priv->has_ip4 == priv->got_ip4 && priv->has_ip6 == priv->got_ip6) @@ -398,7 +351,7 @@ nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GHashTable *ip6_config) + GVariant *ip6_config) { NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); @@ -431,55 +384,63 @@ connect_timer_start (NMVpnPlugin *plugin) connect_timer_removed); } -static gboolean +static void _connect_generic (NMVpnPlugin *plugin, - GHashTable *properties, - GHashTable *details, - GError **error) + GDBusMethodInvocation *context, + GVariant *properties, + GVariant *details) { NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMVpnPluginClass *vpn_class = NM_VPN_PLUGIN_GET_CLASS (plugin); NMConnection *connection; gboolean success = FALSE; - GError *local = NULL; + GError *error = NULL; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE, - "Could not start connection: wrong plugin state %d", - priv->state); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_WRONG_STATE, + "Could not start connection: wrong plugin state %d", + priv->state); + return; } - connection = nm_connection_new_from_hash (properties, &local); + connection = nm_connection_new_from_variant (properties, &error); if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, + "Invalid connection: (%d) %s", + error->code, error->message); + g_clear_error (&error); } - priv->interactive = FALSE; if (details && !vpn_class->connect_interactive) { - g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, - "Plugin does not implement ConnectInteractive()"); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, + "Plugin does not implement ConnectInteractive()"); + return; } nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); if (details) { priv->interactive = TRUE; - success = vpn_class->connect_interactive (plugin, connection, details, error); + success = vpn_class->connect_interactive (plugin, connection, details, &error); } else - success = vpn_class->connect (plugin, connection, error); + success = vpn_class->connect (plugin, connection, &error); if (success) { + g_dbus_method_invocation_return_value (context, NULL); + /* Add a timer to make sure we do not wait indefinitely for the successful connect. */ connect_timer_start (plugin); } else { + g_dbus_method_invocation_take_error (context, error); + /* Stop the plugin from an idle handler so that the Connect * method return gets sent before the STOP StateChanged signal. */ @@ -487,120 +448,131 @@ _connect_generic (NMVpnPlugin *plugin, } g_object_unref (connection); - return success; } -static gboolean -impl_vpn_plugin_connect (NMVpnPlugin *plugin, - GHashTable *connection, - GError **error) +static void +impl_vpn_plugin_connect (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *connection, + gpointer user_data) { - return _connect_generic (plugin, connection, NULL, error); + NMVpnPlugin *plugin = user_data; + + _connect_generic (plugin, context, connection, NULL); } -static gboolean -impl_vpn_plugin_connect_interactive (NMVpnPlugin *plugin, - GHashTable *connection, - GHashTable *details, - GError **error) +static void +impl_vpn_plugin_connect_interactive (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *connection, + GVariant *details, + gpointer user_data) { - return _connect_generic (plugin, connection, details, error); + NMVpnPlugin *plugin = user_data; + + _connect_generic (plugin, context, connection, details); } /***************************************************************/ -static gboolean -impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin, - GHashTable *properties, - char **setting_name, - GError **err) +static void +impl_vpn_plugin_need_secrets (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *properties, + gpointer user_data) { - gboolean ret = FALSE; + NMVpnPlugin *plugin = user_data; NMConnection *connection; - char *sn = NULL; - GError *ns_err = NULL; - gboolean needed = FALSE; - GError *cnfh_err = NULL; - - g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); - g_return_val_if_fail (properties != NULL, FALSE); + char *setting_name; + gboolean needed; + GError *error = NULL; - connection = nm_connection_new_from_hash (properties, &cnfh_err); + connection = nm_connection_new_from_variant (properties, &error); if (!connection) { - g_set_error (err, - NM_VPN_PLUGIN_ERROR, - NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, - "The connection was invalid: '%s' / '%s' invalid: %d.", - g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_err->domain)), - cnfh_err->message, cnfh_err->code); - g_error_free (cnfh_err); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, + "The connection was invalid: '%s' / '%s' invalid: %d.", + g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)), + error->message, error->code); + g_error_free (error); + return; } if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) { - *setting_name = ""; - ret = TRUE; - goto out; + g_dbus_method_invocation_return_value (context, + g_variant_new ("(s)", "")); + return; } - needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &sn, &ns_err); - if (ns_err) { - *err = g_error_copy (ns_err); - g_error_free (ns_err); - goto out; + needed = NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets (plugin, connection, &setting_name, &error); + if (error) { + g_dbus_method_invocation_take_error (context, error); + return; } - ret = TRUE; if (needed) { - g_assert (sn); - *setting_name = g_strdup (sn); + g_assert (setting_name); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(s)", setting_name)); + g_free (setting_name); } else { /* No secrets required */ - *setting_name = g_strdup (""); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(s)", "")); } - -out: - return ret; } -static gboolean -impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, - GHashTable *properties, - GError **error) +static void +impl_vpn_plugin_new_secrets (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *properties, + gpointer user_data) { + NMVpnPlugin *plugin = user_data; NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMConnection *connection; - GError *local = NULL; + GError *error = NULL; gboolean success; if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_WRONG_STATE, - "Could not accept new secrets: wrong plugin state %d", - priv->state); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_WRONG_STATE, + "Could not accept new secrets: wrong plugin state %d", + priv->state); + return; } - connection = nm_connection_new_from_hash (properties, &local); + connection = nm_connection_new_from_variant (properties, &error); if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, + "Invalid connection: (%d) %s", + error->code, error->message); + g_clear_error (&error); + return; } if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) { - g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, - "Could not accept new secrets: plugin cannot process interactive secrets"); + g_dbus_method_invocation_return_error (context, + NM_VPN_PLUGIN_ERROR, + NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, + "Could not accept new secrets: plugin cannot process interactive secrets"); g_object_unref (connection); - return FALSE; + return; } - success = NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets (plugin, connection, error); + success = NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets (plugin, connection, &error); if (success) { + g_dbus_method_invocation_return_value (context, NULL); + /* Add a timer to make sure we do not wait indefinitely for the successful connect. */ connect_timer_start (plugin); } else { + g_dbus_method_invocation_take_error (context, error); + /* Stop the plugin from and idle handler so that the NewSecrets * method return gets sent before the STOP StateChanged signal. */ @@ -608,7 +580,6 @@ impl_vpn_plugin_new_secrets (NMVpnPlugin *plugin, } g_object_unref (connection); - return success; } /** @@ -649,51 +620,66 @@ nm_vpn_plugin_secrets_required (NMVpnPlugin *plugin, /***************************************************************/ -static gboolean -impl_vpn_plugin_disconnect (NMVpnPlugin *plugin, - GError **err) +static void +impl_vpn_plugin_disconnect (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + gpointer user_data) { - return nm_vpn_plugin_disconnect (plugin, err); + NMVpnPlugin *plugin = user_data; + GError *error = NULL; + + if (nm_vpn_plugin_disconnect (plugin, &error)) + g_dbus_method_invocation_return_value (context, NULL); + else + g_dbus_method_invocation_take_error (context, error); } -static gboolean -impl_vpn_plugin_set_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err) +static void +impl_vpn_plugin_set_config (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_config (plugin, config); + NMVpnPlugin *plugin = user_data; - return TRUE; + nm_vpn_plugin_set_config (plugin, config); + g_dbus_method_invocation_return_value (context, NULL); } -static gboolean -impl_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err) +static void +impl_vpn_plugin_set_ip4_config (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_ip4_config (plugin, config); + NMVpnPlugin *plugin = user_data; - return TRUE; + nm_vpn_plugin_set_ip4_config (plugin, config); + g_dbus_method_invocation_return_value (context, NULL); } -static gboolean -impl_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GHashTable *config, - GError **err) +static void +impl_vpn_plugin_set_ip6_config (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, + GVariant *config, + gpointer user_data) { - nm_vpn_plugin_set_ip6_config (plugin, config); + NMVpnPlugin *plugin = user_data; - return TRUE; + nm_vpn_plugin_set_ip6_config (plugin, config); + g_dbus_method_invocation_return_value (context, NULL); } -static gboolean -impl_vpn_plugin_set_failure (NMVpnPlugin *plugin, +static void +impl_vpn_plugin_set_failure (NMPrivVPNPlugin *gdbus_plugin, + GDBusMethodInvocation *context, char *reason, - GError **err) + gpointer user_data) { - nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); + NMVpnPlugin *plugin = user_data; - return TRUE; + nm_vpn_plugin_failure (plugin, NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG); + g_dbus_method_invocation_return_value (context, NULL); } /*********************************************************************/ @@ -739,11 +725,12 @@ nm_vpn_plugin_init (NMVpnPlugin *plugin) static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { - NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (initable); - NMVpnPlugin *plugin; - DBusGConnection *connection; - DBusGProxy *proxy; - guint request_name_result; + NMVpnPlugin *plugin = NM_VPN_PLUGIN (initable); + NMVpnPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); + GDBusConnection *connection = NULL; + GDBusProxy *proxy; + GVariant *ret; + gboolean success = FALSE; if (!priv->dbus_service_name) { g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, @@ -751,36 +738,67 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) return FALSE; } - connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); if (!connection) return FALSE; - proxy = dbus_g_proxy_new_for_name (connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!dbus_g_proxy_call (proxy, "RequestName", error, - G_TYPE_STRING, priv->dbus_service_name, - G_TYPE_UINT, 0, - G_TYPE_INVALID, - G_TYPE_UINT, &request_name_result, - G_TYPE_INVALID)) { - g_object_unref (proxy); - return FALSE; - } + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + cancellable, error); + if (!proxy) + goto out; + + ret = g_dbus_proxy_call_sync (proxy, + "RequestName", + g_variant_new ("(s)", priv->dbus_service_name), + G_DBUS_CALL_FLAGS_NONE, 0, + cancellable, error); g_object_unref (proxy); + if (!ret) + goto out; + g_variant_unref (ret); - dbus_g_connection_register_g_object (connection, - NM_VPN_DBUS_PLUGIN_PATH, - G_OBJECT (initable)); + priv->gdbus_plugin = nmpriv_vpnplugin_skeleton_new (); + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->gdbus_plugin), + connection, + NM_VPN_DBUS_PLUGIN_PATH, + error)) + goto out; - plugin = NM_VPN_PLUGIN (initable); + g_signal_connect (priv->gdbus_plugin, "handle-connect", + G_CALLBACK (impl_vpn_plugin_connect), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-connect-interactive", + G_CALLBACK (impl_vpn_plugin_connect_interactive), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-need-secrets", + G_CALLBACK (impl_vpn_plugin_need_secrets), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-new-secrets", + G_CALLBACK (impl_vpn_plugin_new_secrets), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-disconnect", + G_CALLBACK (impl_vpn_plugin_disconnect), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-set-config", + G_CALLBACK (impl_vpn_plugin_set_config), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-set-ip4-config", + G_CALLBACK (impl_vpn_plugin_set_ip4_config), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-set-ip6-config", + G_CALLBACK (impl_vpn_plugin_set_ip6_config), plugin); + g_signal_connect (priv->gdbus_plugin, "handle-set-failure", + G_CALLBACK (impl_vpn_plugin_set_failure), plugin); nm_vpn_plugin_set_connection (plugin, connection); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_INIT); - return TRUE; + success = TRUE; + + out: + if (connection) + g_object_unref (connection); + + return success; } static void @@ -859,14 +877,10 @@ finalize (GObject *object) nm_vpn_plugin_set_connection (plugin, NULL); g_free (priv->dbus_service_name); - if (G_IS_VALUE (&priv->banner)) - g_value_unset (&priv->banner); - if (G_IS_VALUE (&priv->tundev)) - g_value_unset (&priv->tundev); - if (G_IS_VALUE (&priv->gateway)) - g_value_unset (&priv->gateway); - if (G_IS_VALUE (&priv->mtu)) - g_value_unset (&priv->mtu); + g_clear_pointer (&priv->banner, g_free); + g_clear_pointer (&priv->tundev, g_free); + g_clear_pointer (&priv->gateway, g_free); + g_clear_pointer (&priv->mtu, g_free); G_OBJECT_CLASS (nm_vpn_plugin_parent_class)->finalize (object); } @@ -923,9 +937,6 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) g_type_class_add_private (object_class, sizeof (NMVpnPluginPrivate)); - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (plugin_class), - &dbus_glib_nm_vpn_plugin_object_info); - /* virtual methods */ object_class->set_property = set_property; object_class->get_property = get_property; @@ -958,7 +969,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, state_changed), NULL, NULL, - g_cclosure_marshal_VOID__UINT, + NULL, G_TYPE_NONE, 1, G_TYPE_UINT); @@ -976,7 +987,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, config), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, + NULL, G_TYPE_NONE, 1, G_TYPE_VARIANT); @@ -986,7 +997,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, ip4_config), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, + NULL, G_TYPE_NONE, 1, G_TYPE_VARIANT); @@ -996,7 +1007,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, ip6_config), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, + NULL, G_TYPE_NONE, 1, G_TYPE_VARIANT); @@ -1006,7 +1017,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, login_banner), NULL, NULL, - g_cclosure_marshal_VOID__STRING, + NULL, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -1016,7 +1027,7 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, failure), NULL, NULL, - g_cclosure_marshal_VOID__UINT, + NULL, G_TYPE_NONE, 1, G_TYPE_UINT); @@ -1026,13 +1037,13 @@ nm_vpn_plugin_class_init (NMVpnPluginClass *plugin_class) G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (NMVpnPluginClass, quit), NULL, NULL, - g_cclosure_marshal_VOID__VOID, + NULL, G_TYPE_NONE, 0, G_TYPE_NONE); - dbus_g_error_domain_register (NM_VPN_PLUGIN_ERROR, - NM_DBUS_VPN_ERROR_PREFIX, - NM_TYPE_VPN_PLUGIN_ERROR); + _nm_dbus_register_error_domain (NM_VPN_PLUGIN_ERROR, + NM_DBUS_VPN_ERROR_PREFIX, + NM_TYPE_VPN_PLUGIN_ERROR); setup_unix_signal_handler (); } diff --git a/libnm/nm-vpn-plugin.h b/libnm/nm-vpn-plugin.h index d4fdf9a1f8..72b7a9a2df 100644 --- a/libnm/nm-vpn-plugin.h +++ b/libnm/nm-vpn-plugin.h @@ -26,9 +26,7 @@ #error "Only <NetworkManager.h> can be included directly." #endif -#include <glib.h> -#include <glib-object.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #include <nm-vpn-dbus-interface.h> #include <nm-connection.h> @@ -98,7 +96,7 @@ typedef struct { NMVpnServiceState state); void (*ip4_config) (NMVpnPlugin *plugin, - GHashTable *ip4_config); + GVariant *ip4_config); void (*login_banner) (NMVpnPlugin *plugin, const char *banner); @@ -109,10 +107,10 @@ typedef struct { void (*quit) (NMVpnPlugin *plugin); void (*config) (NMVpnPlugin *plugin, - GHashTable *config); + GVariant *config); void (*ip6_config) (NMVpnPlugin *plugin, - GHashTable *config); + GVariant *config); /* virtual methods */ gboolean (*connect) (NMVpnPlugin *plugin, @@ -133,7 +131,7 @@ typedef struct { gboolean (*connect_interactive) (NMVpnPlugin *plugin, NMConnection *connection, - GHashTable *details, + GVariant *details, GError **error); /* Padding for future expansion */ @@ -144,7 +142,7 @@ GType nm_vpn_plugin_get_type (void); GQuark nm_vpn_plugin_error_quark (void); GType nm_vpn_plugin_error_get_type (void); -DBusGConnection *nm_vpn_plugin_get_connection (NMVpnPlugin *plugin); +GDBusConnection *nm_vpn_plugin_get_connection (NMVpnPlugin *plugin); NMVpnServiceState nm_vpn_plugin_get_state (NMVpnPlugin *plugin); void nm_vpn_plugin_set_state (NMVpnPlugin *plugin, NMVpnServiceState state); @@ -160,13 +158,13 @@ void nm_vpn_plugin_failure (NMVpnPlugin *plugin, NMVpnPluginFailure reason); void nm_vpn_plugin_set_config (NMVpnPlugin *plugin, - GHashTable *config); + GVariant *config); void nm_vpn_plugin_set_ip4_config (NMVpnPlugin *plugin, - GHashTable *ip4_config); + GVariant *ip4_config); void nm_vpn_plugin_set_ip6_config (NMVpnPlugin *plugin, - GHashTable *ip6_config); + GVariant *ip6_config); gboolean nm_vpn_plugin_disconnect (NMVpnPlugin *plugin, GError **err); diff --git a/libnm/nm-wimax-nsp.c b/libnm/nm-wimax-nsp.c index d7eab00fe6..1a8ce988e0 100644 --- a/libnm/nm-wimax-nsp.c +++ b/libnm/nm-wimax-nsp.c @@ -29,15 +29,15 @@ #include "nm-wimax-nsp.h" #include "nm-dbus-interface.h" -#include "nm-types-private.h" #include "nm-object-private.h" +#include "nm-enum-types.h" G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, NM_TYPE_OBJECT) #define NM_WIMAX_NSP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_WIMAX_NSP, NMWimaxNspPrivate)) typedef struct { - DBusGProxy *proxy; + GDBusProxy *proxy; char *name; guint32 signal_quality; diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index eeeb31b84b..3b9909ef62 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -11,7 +11,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DTEST_CERT_DIR=\"$(certsdir)\" noinst_PROGRAMS = \ @@ -20,8 +19,7 @@ noinst_PROGRAMS = \ LDADD = \ $(top_builddir)/libnm/libnm.la \ - $(GLIB_LIBS) \ - $(DBUS_LIBS) + $(GLIB_LIBS) TEST_NM_BIN = test-fake-nm.py TEST_RSS_BIN = test-remote-settings-service.py diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c index 3c59144be3..5c47907a14 100644 --- a/libnm/tests/test-nm-client.c +++ b/libnm/tests/test-nm-client.c @@ -18,9 +18,6 @@ * */ -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> #include <glib.h> #include <string.h> #include <sys/types.h> @@ -106,9 +103,9 @@ name_exists (GDBusConnection *c, const char *name) gboolean exists = FALSE; reply = g_dbus_connection_call_sync (c, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", "GetNameOwner", g_variant_new ("(s)", name), NULL, @@ -127,7 +124,6 @@ name_exists (GDBusConnection *c, const char *name) static ServiceInfo * service_init (void) { - DBusGConnection *bus; ServiceInfo *sinfo; const char *args[2] = { fake_exec, NULL }; GError *error = NULL; @@ -139,7 +135,7 @@ service_init (void) sinfo_static = sinfo; - sinfo->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + sinfo->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); test_assert (sinfo->bus); if (!g_spawn_async (fake_path, (char **) args, NULL, 0, NULL, NULL, &sinfo->pid, &error)) @@ -166,16 +162,12 @@ service_init (void) NULL, NULL); test_assert (sinfo->proxy); - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - g_assert_no_error (error); - sinfo->client = g_object_new (NM_TYPE_CLIENT, - NM_OBJECT_DBUS_CONNECTION, bus, + NM_OBJECT_DBUS_CONNECTION, sinfo->bus, NM_OBJECT_DBUS_PATH, NM_DBUS_PATH, NULL); test_assert (sinfo->client != NULL); - dbus_g_connection_unref (bus); g_initable_init (G_INITABLE (sinfo->client), NULL, &error); g_assert_no_error (error); diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 9010abb857..2aa28848bd 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -18,9 +18,6 @@ * */ -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> #include <glib.h> #include <string.h> #include <sys/types.h> @@ -35,7 +32,7 @@ static GPid spid = 0; static NMRemoteSettings *settings = NULL; -DBusGConnection *bus = NULL; +GDBusConnection *bus = NULL; NMRemoteConnection *remote = NULL; /*******************************************************************/ @@ -122,18 +119,19 @@ test_add_connection (void) /*******************************************************************/ static void -set_visible_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +set_visible_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { GError *error = NULL; - gboolean success; + GVariant *ret; - success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); - if (!success) + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (!ret) g_warning ("Failed to change connection visibility: %s", error->message); - test_assert (success == TRUE); + test_assert (ret != NULL); test_assert (error == NULL); + g_variant_unref (ret); } static void @@ -165,7 +163,7 @@ test_make_invisible (void) { time_t start, now; GSList *list, *iter; - DBusGProxy *proxy; + GDBusProxy *proxy; gboolean visible_changed = FALSE, connection_removed = FALSE; gboolean has_settings = FALSE; char *path; @@ -177,15 +175,23 @@ test_make_invisible (void) g_signal_connect (settings, "connection-removed", G_CALLBACK (connection_removed_cb), &connection_removed); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - path, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION); + proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + NULL, + NULL); test_assert (proxy != NULL); /* Bypass the NMRemoteSettings object so we can test it independently */ - dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL, - G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "SetVisible", + g_variant_new ("(b)", FALSE), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + set_visible_cb, NULL); /* Wait for the connection to be removed */ start = time (NULL); @@ -230,7 +236,7 @@ test_make_visible (void) { time_t start, now; GSList *list, *iter; - DBusGProxy *proxy; + GDBusProxy *proxy; gboolean found = FALSE; char *path; NMRemoteConnection *new = NULL; @@ -242,16 +248,23 @@ test_make_visible (void) G_CALLBACK (vis_new_connection_cb), &new); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - path, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION); + proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + NULL, + NULL); test_assert (proxy != NULL); /* Bypass the NMRemoteSettings object so we can test it independently */ - dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL, - G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID); - + g_dbus_proxy_call (proxy, + "SetVisible", + g_variant_new ("(b)", TRUE), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + set_visible_cb, NULL); /* Wait for the settings service to announce the connection again */ start = time (NULL); @@ -284,18 +297,19 @@ test_make_visible (void) /*******************************************************************/ static void -deleted_cb (DBusGProxy *proxy, - DBusGProxyCall *call, +deleted_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data) { GError *error = NULL; - gboolean success; + GVariant *ret; - success = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); - if (!success) + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (!ret) g_warning ("Failed to delete connection: %s", error->message); - test_assert (success == TRUE); + test_assert (ret != NULL); test_assert (error == NULL); + g_variant_unref (ret); } static void @@ -311,7 +325,7 @@ test_remove_connection (void) NMRemoteConnection *connection; time_t start, now; GSList *list, *iter; - DBusGProxy *proxy; + GDBusProxy *proxy; gboolean done = FALSE; char *path; @@ -323,14 +337,23 @@ test_remove_connection (void) path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection))); g_signal_connect (settings, "connection-removed", G_CALLBACK (removed_cb), &done); - proxy = dbus_g_proxy_new_for_name (bus, - NM_DBUS_SERVICE, - path, - NM_DBUS_INTERFACE_SETTINGS_CONNECTION); + proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_SETTINGS_CONNECTION, + NULL, + NULL); test_assert (proxy != NULL); /* Bypass the NMRemoteSettings object so we can test it independently */ - dbus_g_proxy_begin_call (proxy, "Delete", deleted_cb, NULL, NULL, G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "Delete", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + deleted_cb, NULL); start = time (NULL); do { @@ -354,13 +377,34 @@ test_remove_connection (void) /*******************************************************************/ +static gboolean +startup_timeout (gpointer data) +{ + gboolean *timed_out = data; + + *timed_out = TRUE; + return G_SOURCE_REMOVE; +} + +static void +nm_appeared_cb (GDBusConnection *connection, + const char *name, + const char *name_owner, + gpointer user_data) +{ + gboolean *nm_running = user_data; + + *nm_running = TRUE; +} + int main (int argc, char **argv) { char *service_argv[3] = { NULL, NULL, NULL }; int ret; GError *error = NULL; - int i = 100; + gboolean nm_running = FALSE, timed_out = FALSE; + guint name_watch; g_assert (argc == 3); @@ -370,7 +414,7 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (!bus) { g_warning ("Error connecting to D-Bus: %s", error->message); g_assert (error == NULL); @@ -383,15 +427,18 @@ main (int argc, char **argv) } /* Wait until the service is registered on the bus */ - while (i > 0) { - g_usleep (G_USEC_PER_SEC / 50); - if (dbus_bus_name_has_owner (dbus_g_connection_get_connection (bus), - "org.freedesktop.NetworkManager", - NULL)) - break; - i--; - } - test_assert (i > 0); + name_watch = g_bus_watch_name_on_connection (bus, + "org.freedesktop.NetworkManager", + G_BUS_NAME_WATCHER_FLAGS_NONE, + nm_appeared_cb, NULL, + &nm_running, NULL); + g_timeout_add_seconds (5, startup_timeout, &timed_out); + + while (!timed_out && !nm_running) + g_main_context_iteration (NULL, TRUE); + test_assert (nm_running); + + g_bus_unwatch_name (name_watch); settings = g_initable_new (NM_TYPE_REMOTE_SETTINGS, NULL, &error, NM_OBJECT_DBUS_CONNECTION, bus, @@ -408,7 +455,7 @@ main (int argc, char **argv) cleanup (); g_object_unref (settings); - dbus_g_connection_unref (bus); + g_object_unref (bus); return ret; } |