diff options
Diffstat (limited to 'libnm')
50 files changed, 1632 insertions, 1704 deletions
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; } |