static void get_one_connection (DBusGConnection *bus, const char *path, NMConnectionScope scope, GHashTable *table) { DBusGProxy *proxy; NMConnection *connection = NULL; const char *service; GError *error = NULL; GHashTable *settings = NULL; g_return_if_fail (bus != NULL); g_return_if_fail (path != NULL); g_return_if_fail (table != NULL); service = (scope == NM_CONNECTION_SCOPE_SYSTEM) ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS; proxy = dbus_g_proxy_new_for_name (bus, service, path, NM_DBUS_IFACE_SETTINGS_CONNECTION); if (!proxy) return; if (!dbus_g_proxy_call (proxy, "GetSettings", &error, G_TYPE_INVALID, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, G_TYPE_INVALID)) { nm_warning ("error: cannot retrieve connection: %s", error ? error->message : "(unknown)"); goto out; } connection = nm_connection_new_from_hash (settings, &error); g_hash_table_destroy (settings); if (!connection) { nm_warning ("error: invalid connection: '%s' / '%s' invalid: %d", error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(unknown)", error ? error->message : "(unknown)", error ? error->code : -1); goto out; } nm_connection_set_scope (connection, scope); nm_connection_set_path (connection, path); g_hash_table_insert (table, g_strdup (path), g_object_ref (connection)); out: g_clear_error (&error); if (connection) g_object_unref (connection); g_object_unref (proxy); }
void nm_settings_service_export_connection (NMSettingsService *self, NMSettingsConnectionInterface *connection) { NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (self); static guint32 ec_counter = 0; char *path; g_return_if_fail (connection != NULL); g_return_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection)); g_return_if_fail (priv->bus != NULL); /* Don't allow exporting twice */ g_return_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL); path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++); nm_connection_set_path (NM_CONNECTION (connection), path); nm_connection_set_scope (NM_CONNECTION (connection), priv->scope); dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (connection)); g_free (path); }