diff options
author | Dan Winship <danw@gnome.org> | 2014-09-18 12:08:17 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-18 12:08:17 -0400 |
commit | 6d07dab3604beb013b4a66c7b8474a1b445ade3d (patch) | |
tree | 08e913a261fc29c790dd91724546b89cb15dd534 | |
parent | 67853793cf5aaaa3afca9d07b4e9d58b9289e45b (diff) | |
download | NetworkManager-danw/wip/gdbus.tar.gz |
104 files changed, 3250 insertions, 2745 deletions
diff --git a/.gitignore b/.gitignore index b58f499316..593576949b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,6 @@ gtk-doc.make *.pc cscope.*out valgrind-*.log -*-glue.h /ABOUT-NLS /COPYING diff --git a/callouts/nm-dispatcher-api.h b/callouts/nm-dispatcher-api.h index df1bced456..c86efacb59 100644 --- a/callouts/nm-dispatcher-api.h +++ b/callouts/nm-dispatcher-api.h @@ -22,10 +22,6 @@ #define NMD_SCRIPT_DIR_PRE_UP NMD_SCRIPT_DIR_DEFAULT "/pre-up.d" #define NMD_SCRIPT_DIR_PRE_DOWN NMD_SCRIPT_DIR_DEFAULT "/pre-down.d" -/* dbus-glib types for dispatcher call return value (used by src/nm-dispatcher.c) */ -#define DISPATCHER_TYPE_RESULT (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID)) -#define DISPATCHER_TYPE_RESULT_ARRAY (dbus_g_type_get_collection ("GPtrArray", DISPATCHER_TYPE_RESULT)) - #define NM_DISPATCHER_DBUS_SERVICE "org.freedesktop.nm_dispatcher" #define NM_DISPATCHER_DBUS_INTERFACE "org.freedesktop.nm_dispatcher" #define NM_DISPATCHER_DBUS_PATH "/org/freedesktop/nm_dispatcher" diff --git a/introspection/nm-agent-manager.xml b/introspection/nm-agent-manager.xml index d107442860..4b53675cfd 100644 --- a/introspection/nm-agent-manager.xml +++ b/introspection/nm-agent-manager.xml @@ -8,8 +8,6 @@ Called by secret Agents to register their ability to provide and save network secrets. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="identifier" type="s" direction="in"> <tp:docstring> Identifies this agent; only one agent in each user session may use the @@ -27,8 +25,6 @@ <tp:docstring> Like Register() but indicates agent capabilities to NetworkManager. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register_with_capabilities"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="identifier" type="s" direction="in"> <tp:docstring> See the Register() method's identifier argument. @@ -47,8 +43,6 @@ longer handle requests for network secrets. Agents are automatically unregistered when they disconnect from D-Bus. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_unregister"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> </method> </interface> diff --git a/introspection/nm-device-wifi.xml b/introspection/nm-device-wifi.xml index 2476fd7dd9..3ae4de1e34 100644 --- a/introspection/nm-device-wifi.xml +++ b/introspection/nm-device-wifi.xml @@ -5,7 +5,6 @@ <annotation name="org.gtk.GDBus.C.Name" value="DeviceWifi"/> <method name="GetAccessPoints"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_access_points"/> <arg name="access_points" type="ao" direction="out"> <tp:docstring> List of access point object paths. @@ -20,7 +19,6 @@ </method> <method name="GetAllAccessPoints"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_get_all_access_points"/> <arg name="access_points" type="ao" direction="out"> <tp:docstring> List of access point object paths. @@ -33,8 +31,6 @@ </method> <method name="RequestScan"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_request_scan"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="options" type="a{sv}" direction="in"> <tp:docstring> Options of scan diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 0dca23c37d..6531cab0c0 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -140,16 +140,12 @@ </property> <method name="Disconnect"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_disconnect"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Disconnects a device and prevents the device from automatically activating further connections without user intervention. </tp:docstring> </method> <method name="Delete"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_delete"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Deletes a software device from NetworkManager and removes the interface from the system. The method returns an error when called for a hardware device. diff --git a/introspection/nm-manager.xml b/introspection/nm-manager.xml index 78021f73da..e9d75ba7c9 100644 --- a/introspection/nm-manager.xml +++ b/introspection/nm-manager.xml @@ -8,7 +8,6 @@ <tp:docstring> Get the list of network devices. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_devices"/> <arg name="devices" type="ao" direction="out"> <tp:docstring> List of object paths of network devices known to the system. @@ -22,7 +21,6 @@ interface name. Note that some devices (usually modems) only have an IP interface name when they are connected. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_device_by_ip_iface"/> <arg name="iface" type="s" direction="in"> <tp:docstring> Interface name of the device to find. @@ -36,8 +34,6 @@ </method> <method name="ActivateConnection"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_connection"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Activate a connection using the supplied device. </tp:docstring> @@ -86,8 +82,6 @@ </method> <method name="AddAndActivateConnection"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_add_and_activate_connection"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the @@ -138,8 +132,6 @@ <tp:docstring> Deactivate an active connection. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_deactivate_connection"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="active_connection" type="o" direction="in"> <tp:docstring> The currently active connection to deactivate. @@ -148,8 +140,6 @@ </method> <method name="Sleep"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_sleep"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Control the NetworkManager daemon's sleep state. When asleep, all interfaces that it manages are deactivated. When awake, devices are @@ -164,8 +154,6 @@ </method> <method name="Enable"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_enable"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Control whether overall networking is enabled or disabled. When disabled, all interfaces that NM manages are deactivated. When enabled, @@ -182,8 +170,6 @@ </method> <method name="GetPermissions"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_permissions"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Returns the permissions a caller has for various authenticated operations that NetworkManager provides, like Enable/Disable networking, changing @@ -210,8 +196,6 @@ </signal> <method name="SetLogging"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_set_logging"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Set logging verbosity and which operations are logged. </tp:docstring> @@ -240,7 +224,6 @@ </method> <method name="GetLogging"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_logging"/> <tp:docstring> Get current logging verbosity level and operations domains. </tp:docstring> @@ -257,8 +240,6 @@ </method> <method name="CheckConnectivity"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_check_connectivity"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <tp:docstring> Re-check the network connectivity state. </tp:docstring> @@ -274,7 +255,6 @@ The overall networking state as determined by the NetworkManager daemon, based on the state of network devices under it's management. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_state"/> <arg name="state" type="u" direction="out" tp:type="NM_STATE"/> </method> diff --git a/introspection/nm-ppp-manager.xml b/introspection/nm-ppp-manager.xml index 5ea1e8b16b..e4c6a2c869 100644 --- a/introspection/nm-ppp-manager.xml +++ b/introspection/nm-ppp-manager.xml @@ -5,24 +5,19 @@ <annotation name="org.gtk.GDBus.C.Name" value="PPP_Manager"/> <method name="NeedSecrets"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_need_secrets"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="username" type="s" direction="out"/> <arg name="password" type="s" direction="out"/> </method> <method name="SetIp4Config"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_ip4_config"/> <arg name="config" type="a{sv}" direction="in"/> </method> <method name="SetIp6Config"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_ip6_config"/> <arg name="config" type="a{sv}" direction="in"/> </method> <method name="SetState"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_ppp_manager_set_state"/> <arg name="state" type="u" direction="in"/> </method> </interface> diff --git a/introspection/nm-settings-connection.xml b/introspection/nm-settings-connection.xml index b5bd2cd0e0..6c4e995a2e 100644 --- a/introspection/nm-settings-connection.xml +++ b/introspection/nm-settings-connection.xml @@ -15,8 +15,6 @@ stored in persistent storage or sent to a Secret Agent for storage, depending on the flags associated with each secret. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_update"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="properties" type="a{sa{sv}}" direction="in"> <tp:docstring> New connection settings, properties, and (optionally) secrets. @@ -37,8 +35,6 @@ reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_update_unsaved"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="properties" type="a{sa{sv}}" direction="in"> <tp:docstring> New connection settings, properties, and (optionally) secrets. @@ -50,8 +46,6 @@ <tp:docstring> Delete the connection. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_delete"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> </method> <method name="GetSettings"> @@ -61,8 +55,6 @@ to the network, as those are often protected. Secrets must be requested separately using the GetSecrets() call. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_settings"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="settings" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map"> <tp:docstring> The nested settings maps describing this object. @@ -77,8 +69,6 @@ the requestor's session will be returned. The user will never be prompted for secrets as a result of this request. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_get_secrets"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="setting_name" type="s" direction="in"> <tp:docstring> Name of the setting to return secrets for. If empty, all @@ -98,8 +88,6 @@ Saves a "dirty" connection (that had previously been updated with UpdateUnsaved) to persistent storage. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_connection_save"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> </method> <signal name="Updated"> diff --git a/introspection/nm-settings.xml b/introspection/nm-settings.xml index 3a71959cb8..b6ab8260ea 100644 --- a/introspection/nm-settings.xml +++ b/introspection/nm-settings.xml @@ -10,7 +10,6 @@ <tp:docstring> List the saved network connections known to NetworkManager. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_list_connections"/> <arg name="connections" type="ao" direction="out"> <tp:docstring> List of connections. @@ -22,8 +21,6 @@ <tp:docstring> Retrieve the object path of a connection, given that connection's UUID. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_get_connection_by_uuid"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="uuid" type="s" direction="in"> <tp:docstring> The UUID to find the connection object path for. @@ -43,8 +40,6 @@ the network described by the new connection, and (2) the connection is allowed to be started automatically. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="connection" type="a{sa{sv}}" direction="in"> <tp:docstring> Connection settings and properties. @@ -69,8 +64,6 @@ connection is reloaded from disk (either automatically on file change or due to an explicit ReloadConnections call). </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection_unsaved"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="connection" type="a{sa{sv}}" direction="in"> <tp:docstring> Connection settings and properties. @@ -93,8 +86,6 @@ harmless.) As with AddConnection(), this operation does not necessarily start the network connection. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_load_connections"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="filenames" type="as" direction="in"> <tp:docstring> Array of paths to on-disk connection profiles in directories @@ -125,8 +116,6 @@ change, so you only need to use this command if you have set "monitor-connection-files=false" in NetworkManager.conf. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_reload_connections"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="status" type="b" direction="out"> <tp:docstring> Success or failure. @@ -138,8 +127,6 @@ <tp:docstring> Save the hostname to persistent configuration. </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_save_hostname"/> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="hostname" type="s" direction="in"> <tp:docstring> The hostname to save to persistent configuration. If blank, the persistent hostname is cleared. diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core index 22566e0638..78b4838d22 100644 --- a/libnm-core/Makefile.libnm-core +++ b/libnm-core/Makefile.libnm-core @@ -44,6 +44,7 @@ libnm_core_headers = \ libnm_core_private_headers = \ $(core)/crypto.h \ $(core)/nm-core-internal.h \ + $(core)/nm-dbus-utils.h \ $(core)/nm-property-compare.h \ $(core)/nm-setting-private.h \ $(core)/nm-utils-private.h @@ -52,6 +53,7 @@ libnm_core_sources = \ $(core_build)/nm-core-enum-types.c \ $(core)/crypto.c \ $(core)/nm-connection.c \ + $(core)/nm-dbus-utils.c \ $(core)/nm-property-compare.c \ $(core)/nm-setting-8021x.c \ $(core)/nm-setting-adsl.c \ diff --git a/libnm-core/nm-dbus-utils.c b/libnm-core/nm-dbus-utils.c new file mode 100644 index 0000000000..107638dd35 --- /dev/null +++ b/libnm-core/nm-dbus-utils.c @@ -0,0 +1,186 @@ +/* -*- 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 2013-2014 Red Hat, Inc. + */ + +#include <config.h> + +#include "nm-dbus-utils.h" + +void +_nm_dbus_check_name_has_owner (GDBusConnection *connection, + const gchar *name, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_dbus_connection_call (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "NameHasOwner", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, + callback, user_data); +} + +gboolean +_nm_dbus_check_name_has_owner_finish (GDBusConnection *connection, + GAsyncResult *result, + gboolean *has_owner, + GError **error) +{ + GVariant *ret; + + ret = g_dbus_connection_call_finish (connection, result, error); + if (ret) { + g_variant_get (ret, "(b)", has_owner); + g_variant_unref (ret); + } + + return ret != NULL; +} + +gboolean +_nm_dbus_check_name_has_owner_sync (GDBusConnection *connection, + const gchar *name, + gboolean *has_owner, + GCancellable *cancellable, + GError **error) +{ + GVariant *ret; + + ret = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "NameHasOwner", + g_variant_new ("(s)", name), + G_VARIANT_TYPE ("(b)"), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (ret) { + g_variant_get (ret, "(b)", has_owner); + g_variant_unref (ret); + } + + return ret != NULL; +} + +void +_nm_dbus_request_name (GDBusConnection *connection, + const gchar *name, + guint flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_dbus_connection_call (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "RequestName", + g_variant_new ("(su)", name, flags), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, + callback, user_data); +} + +int +_nm_dbus_request_name_finish (GDBusConnection *connection, + GAsyncResult *result, + GError **error) +{ + GVariant *ret; + guint code = 0; + + ret = g_dbus_connection_call_finish (connection, result, error); + if (ret) { + g_variant_get (ret, "(u)", &code); + g_variant_unref (ret); + } + + return code; +} + +gboolean +_nm_dbus_request_name_sync (GDBusConnection *connection, + const gchar *name, + guint flags, + GCancellable *cancellable, + GError **error) +{ + GVariant *ret; + guint code = 0; + + ret = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "RequestName", + g_variant_new ("(su)", name, flags), + G_VARIANT_TYPE ("(u)"), + G_DBUS_CALL_FLAGS_NONE, -1, + cancellable, error); + if (ret) { + g_variant_get (ret, "(u)", &code); + g_variant_unref (ret); + } + + return code; +} + +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); + } + + g_type_class_unref (enum_class); +} + + +void +_nm_dbus_bind_properties (gpointer object, gpointer skeleton) +{ + GParamSpec **properties; + guint n_properties; + int i; + + properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (skeleton), &n_properties); + for (i = 0; i < n_properties; i++) { + g_object_bind_property (object, properties[i]->name, + skeleton, properties[i]->name, + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + } +} diff --git a/libnm-core/nm-dbus-utils.h b/libnm-core/nm-dbus-utils.h new file mode 100644 index 0000000000..f000943c1a --- /dev/null +++ b/libnm-core/nm-dbus-utils.h @@ -0,0 +1,74 @@ +/* -*- 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 2013-2014 Red Hat, Inc. + */ + +#ifndef NM_DBUS_UTILS_H +#define NM_DBUS_UTILS_H + +#include <gio/gio.h> + +void _nm_dbus_check_name_has_owner (GDBusConnection *connection, + const gchar *name, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean _nm_dbus_check_name_has_owner_finish (GDBusConnection *connection, + GAsyncResult *result, + gboolean *has_owner, + GError **error); + +gboolean _nm_dbus_check_name_has_owner_sync (GDBusConnection *connection, + const gchar *name, + gboolean *has_owner, + GCancellable *cancellable, + GError **error); + +#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT 0x1 +#define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2 +#define DBUS_NAME_FLAG_DO_NOT_QUEUE 0x4 + +#define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1 +#define DBUS_REQUEST_NAME_REPLY_IN_QUEUE 2 +#define DBUS_REQUEST_NAME_REPLY_EXISTS 3 +#define DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4 + +void _nm_dbus_request_name (GDBusConnection *connection, + const gchar *name, + guint flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +int _nm_dbus_request_name_finish (GDBusConnection *connection, + GAsyncResult *result, + GError **error); + +int _nm_dbus_request_name_sync (GDBusConnection *connection, + const gchar *name, + guint flags, + GCancellable *cancellable, + GError **error); + +void _nm_dbus_register_error_domain (GQuark domain, + const char *interface, + GType enum_type); + +void _nm_dbus_bind_properties (gpointer object, + gpointer skeleton); + +#endif /* NM_DBUS_UTILS_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 62a4aa55ef..c96239ce78 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,6 +36,7 @@ endif AM_CPPFLAGS = \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/introspection \ -I$(top_srcdir)/libnm-core \ -I$(top_builddir)/libnm-core \ -I$(top_srcdir)/callouts \ @@ -87,7 +88,7 @@ nm_device_headers = \ devices/nm-device-vlan.h \ devices/nm-device-vxlan.h -nm_sources = \ +libNetworkManager_la_SOURCES = \ $(nm_device_headers) \ devices/nm-device.c \ devices/nm-device.h \ @@ -192,8 +193,6 @@ nm_sources = \ supplicant-manager/nm-supplicant-settings-verify.c \ supplicant-manager/nm-supplicant-settings-verify.h \ supplicant-manager/nm-supplicant-types.h \ - supplicant-manager/nm-call-store.c \ - supplicant-manager/nm-call-store.h \ \ vpn-manager/nm-vpn-connection.c \ vpn-manager/nm-vpn-connection.h \ @@ -236,6 +235,8 @@ nm_sources = \ nm-auth-subject.h \ nm-manager.c \ nm-manager.h \ + nm-object.c \ + nm-object.h \ nm-policy.c \ nm-policy.h \ nm-posix-signals.c \ @@ -253,24 +254,24 @@ nm_sources = \ NetworkManagerUtils.h if SESSION_TRACKING_SYSTEMD -nm_sources += nm-session-monitor-systemd.c +libNetworkManager_la_SOURCES += nm-session-monitor-systemd.c else if SESSION_TRACKING_CK -nm_sources += nm-session-monitor-ck.c +libNetworkManager_la_SOURCES += nm-session-monitor-ck.c else -nm_sources += nm-session-monitor-null.c +libNetworkManager_la_SOURCES += nm-session-monitor-null.c endif endif if SUSPEND_RESUME_SYSTEMD -nm_sources += nm-sleep-monitor-systemd.c +libNetworkManager_la_SOURCES += nm-sleep-monitor-systemd.c else # UPower suspend/resume used whenever systemd is not enabled -nm_sources += nm-sleep-monitor-upower.c +libNetworkManager_la_SOURCES += nm-sleep-monitor-upower.c endif if WITH_WEXT -nm_sources += \ +libNetworkManager_la_SOURCES += \ platform/wifi/wifi-utils-wext.c \ platform/wifi/wifi-utils-wext.h endif @@ -279,7 +280,7 @@ endif GLIB_GENERATED = nm-enum-types.h nm-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM -nm_enum_types_sources = $(nm_sources) +nm_enum_types_sources = $(libNetworkManager_la_SOURCES) if WITH_WIMAX nm_enum_types_sources += devices/wimax/nm-device-wimax.h @@ -288,41 +289,7 @@ endif BUILT_SOURCES = $(GLIB_GENERATED) - -glue_sources = \ - nm-access-point-glue.h \ - nm-active-connection-glue.h \ - nm-agent-manager-glue.h \ - nm-device-bond-glue.h \ - nm-device-bridge-glue.h \ - nm-device-ethernet-glue.h \ - nm-device-generic-glue.h \ - nm-device-glue.h \ - nm-device-gre-glue.h \ - nm-device-infiniband-glue.h \ - nm-device-macvlan-glue.h \ - nm-device-tun-glue.h \ - nm-device-veth-glue.h \ - nm-device-vlan-glue.h \ - nm-device-vxlan-glue.h \ - nm-dhcp4-config-glue.h \ - nm-dhcp6-config-glue.h \ - nm-ip4-config-glue.h \ - nm-ip6-config-glue.h \ - nm-manager-glue.h \ - nm-ppp-manager-glue.h \ - nm-settings-connection-glue.h \ - nm-settings-glue.h \ - nm-vpn-connection-glue.h - -BUILT_SOURCES += $(glue_sources) - -%-glue.h: $(top_srcdir)/introspection/%.xml - $(AM_V_GEN) dbus-binding-tool --prefix=$(subst -,_,$(subst -glue.h,,$@)) --mode=glib-server --output=$@ $< - - AM_CPPFLAGS += \ - $(DBUS_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUDEV_CFLAGS) \ $(LIBNL_CFLAGS) \ @@ -355,13 +322,9 @@ if SESSION_TRACKING_CK AM_CPPFLAGS += -DCKDB_PATH=\"${CKDB_PATH}\" endif -libNetworkManager_la_SOURCES = \ - $(nm_sources) \ - $(glue_sources) - libNetworkManager_la_LIBADD = \ $(top_builddir)/libnm-core/libnm-core.la \ - $(DBUS_LIBS) \ + $(top_builddir)/introspection/libnmdbus.la \ $(GLIB_LIBS) \ $(GUDEV_LIBS) \ $(LIBNL_LIBS) \ @@ -392,8 +355,4 @@ install-data-hook: $(mkinstalldirs) -m 0755 $(DESTDIR)$(pkglibdir) CLEANFILES = \ - $(BUILT_SOURCES) \ - settings/*-glue.h \ - devices/*-glue.h \ - devices/*/*-glue.h - + $(BUILT_SOURCES) diff --git a/src/devices/adsl/Makefile.am b/src/devices/adsl/Makefile.am index 07a8f9eeb9..adc25154cb 100644 --- a/src/devices/adsl/Makefile.am +++ b/src/devices/adsl/Makefile.am @@ -13,7 +13,6 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-adsl"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) \ $(GUDEV_CFLAGS) GLIB_GENERATED = nm-adsl-enum-types.h nm-adsl-enum-types.c @@ -43,7 +42,6 @@ libnm_device_plugin_adsl_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_adsl_la_LIBADD = \ - $(DBUS_LIBS) \ $(GUDEV_LIBS) CLEANFILES = $(BUILT_SOURCES) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index abe2b3301f..215b69011b 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -46,7 +46,7 @@ #include "nm-setting-adsl.h" #include "nm-utils.h" -#include "nm-device-adsl-glue.h" +#include "nmdbus-device-adsl.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF (NMDeviceAdsl); diff --git a/src/devices/bluetooth/Makefile.am b/src/devices/bluetooth/Makefile.am index 07c8f01024..a8683b23ea 100644 --- a/src/devices/bluetooth/Makefile.am +++ b/src/devices/bluetooth/Makefile.am @@ -15,7 +15,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-bluetooth"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) GLIB_GENERATED = nm-bt-enum-types.h nm-bt-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM @@ -55,7 +55,6 @@ libnm_device_plugin_bluetooth_la_LDFLAGS = \ libnm_device_plugin_bluetooth_la_LIBADD = \ $(top_builddir)/src/devices/wwan/libnm-wwan.la \ - $(DBUS_LIBS) \ $(GUDEV_LIBS) CLEANFILES = $(BUILT_SOURCES) diff --git a/src/devices/bluetooth/nm-bluez4-adapter.c b/src/devices/bluetooth/nm-bluez4-adapter.c index 7a2cdd6c05..5d2d486afd 100644 --- a/src/devices/bluetooth/nm-bluez4-adapter.c +++ b/src/devices/bluetooth/nm-bluez4-adapter.c @@ -26,7 +26,6 @@ #include "nm-bluez4-adapter.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" -#include "nm-dbus-glib-types.h" #include "nm-logging.h" diff --git a/src/devices/bluetooth/nm-bluez4-manager.c b/src/devices/bluetooth/nm-bluez4-manager.c index 2660cbd924..baa18fdddf 100644 --- a/src/devices/bluetooth/nm-bluez4-manager.c +++ b/src/devices/bluetooth/nm-bluez4-manager.c @@ -22,10 +22,8 @@ #include <signal.h> #include <string.h> #include <stdlib.h> -#include <dbus/dbus-glib.h> #include "nm-logging.h" -#include "nm-dbus-glib-types.h" #include "nm-bluez-manager.h" #include "nm-bluez4-manager.h" #include "nm-bluez4-adapter.h" diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index e08064b120..2803191025 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -40,7 +40,7 @@ #include "nm-setting-gsm.h" #include "nm-setting-serial.h" #include "nm-setting-ppp.h" -#include "nm-device-bt-glue.h" +#include "nmdbus-device-bt.h" #include "NetworkManagerUtils.h" #include "nm-bt-enum-types.h" #include "nm-utils.h" @@ -1227,5 +1227,5 @@ nm_device_bt_class_init (NMDeviceBtClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_bt_object_info); - dbus_g_error_domain_register (NM_BT_ERROR, NULL, NM_TYPE_BT_ERROR); + _nm_dbus_register_error_domain (NM_BT_ERROR, NULL, NM_TYPE_BT_ERROR); } diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 40151d4722..e9fe35aec2 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -33,12 +33,11 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" #include "nm-dbus-manager.h" #include "nm-enum-types.h" #include "nm-device-factory.h" -#include "nm-device-bond-glue.h" +#include "nmdbus-device-bond.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceBond); @@ -475,7 +474,8 @@ get_property (GObject *object, guint prop_id, for (iter = list; iter; iter = iter->next) g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data)))); g_slist_free (list); - g_value_take_boxed (value, slaves); + g_ptr_array_add (slaves, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (slaves, FALSE)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -525,15 +525,15 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) g_object_class_install_property (object_class, PROP_SLAVES, g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_bond_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_BOND, + NULL); - dbus_g_error_domain_register (NM_BOND_ERROR, NULL, NM_TYPE_BOND_ERROR); + _nm_dbus_register_error_domain (NM_BOND_ERROR, NM_DBUS_INTERFACE_DEVICE_BOND, NM_TYPE_BOND_ERROR); } /*************************************************************/ diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index caf62d76d0..eb56eafe93 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -31,13 +31,12 @@ #include "nm-utils.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "nm-dbus-glib-types.h" #include "nm-dbus-manager.h" #include "nm-enum-types.h" #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-bridge-glue.h" +#include "nmdbus-device-bridge.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceBridge); @@ -425,7 +424,8 @@ get_property (GObject *object, guint prop_id, for (iter = list; iter; iter = iter->next) g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data)))); g_slist_free (list); - g_value_take_boxed (value, slaves); + g_ptr_array_add (slaves, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (slaves, FALSE)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -475,15 +475,15 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) g_object_class_install_property (object_class, PROP_SLAVES, g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_bridge_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_BRIDGE, + NULL); - dbus_g_error_domain_register (NM_BRIDGE_ERROR, NULL, NM_TYPE_BRIDGE_ERROR); + _nm_dbus_register_error_domain (NM_BRIDGE_ERROR, NM_DBUS_INTERFACE_DEVICE_BRIDGE, NM_TYPE_BRIDGE_ERROR); } /*************************************************************/ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 92d0b3dc7d..fadf040966 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -60,7 +60,7 @@ #include "nm-connection-provider.h" #include "nm-device-factory.h" -#include "nm-device-ethernet-glue.h" +#include "nmdbus-device-ethernet.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceEthernet); @@ -1744,11 +1744,11 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_ethernet_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_ETHERNET, + NULL); - dbus_g_error_domain_register (NM_ETHERNET_ERROR, NULL, NM_TYPE_ETHERNET_ERROR); + _nm_dbus_register_error_domain (NM_ETHERNET_ERROR, NM_DBUS_INTERFACE_DEVICE_WIRED, NM_TYPE_ETHERNET_ERROR); } /*************************************************************/ diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c index af262f7733..eb1b7e1ad4 100644 --- a/src/devices/nm-device-generic.c +++ b/src/devices/nm-device-generic.c @@ -28,7 +28,7 @@ #include "nm-glib-compat.h" #include "nm-dbus-manager.h" -#include "nm-device-generic-glue.h" +#include "nmdbus-device-generic.h" G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE) @@ -208,9 +208,9 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_generic_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_GENERIC, + NULL); - dbus_g_error_domain_register (NM_DEVICE_GENERIC_ERROR, NULL, NM_TYPE_DEVICE_GENERIC_ERROR); + _nm_dbus_register_error_domain (NM_DEVICE_GENERIC_ERROR, NM_DBUS_INTERFACE_DEVICE_GENERIC, NM_TYPE_DEVICE_GENERIC_ERROR); } diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c index 2f432c18f0..15bcc168e8 100644 --- a/src/devices/nm-device-gre.c +++ b/src/devices/nm-device-gre.c @@ -30,7 +30,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-gre-glue.h" +#include "nmdbus-device-gre.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceGre); @@ -135,7 +135,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PARENT: parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex); - g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/"); + g_value_set_string (value, parent ? nm_device_get_path (parent) : "/"); break; case PROP_INPUT_FLAGS: g_value_set_uint (value, priv->props.input_flags); @@ -186,10 +186,10 @@ nm_device_gre_class_init (NMDeviceGreClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_GRE_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_GRE_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_INPUT_FLAGS, @@ -254,9 +254,9 @@ nm_device_gre_class_init (NMDeviceGreClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_gre_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_GRE, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 8101c3e12c..033fdbce22 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -37,7 +37,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-infiniband-glue.h" +#include "nmdbus-device-infiniband.h" G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE) @@ -290,13 +290,12 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass) parent_class->act_stage1_prepare = act_stage1_prepare; parent_class->ip4_config_pre_commit = ip4_config_pre_commit; - /* properties */ - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_infiniband_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_INFINIBAND, + NULL); - dbus_g_error_domain_register (NM_INFINIBAND_ERROR, NULL, NM_TYPE_INFINIBAND_ERROR); + _nm_dbus_register_error_domain (NM_INFINIBAND_ERROR, NM_DBUS_INTERFACE_DEVICE_INFINIBAND, NM_TYPE_INFINIBAND_ERROR); } /*************************************************************/ diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c index bcd3861774..692c7c5637 100644 --- a/src/devices/nm-device-macvlan.c +++ b/src/devices/nm-device-macvlan.c @@ -30,7 +30,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-macvlan-glue.h" +#include "nmdbus-device-macvlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceMacvlan); @@ -115,7 +115,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PARENT: parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex); - g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/"); + g_value_set_string (value, parent ? nm_device_get_path (parent) : "/"); break; case PROP_MODE: g_value_set_string (value, priv->props.mode); @@ -145,10 +145,10 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_MACVLAN_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_MACVLAN_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_MODE, @@ -164,9 +164,9 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_macvlan_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_MACVLAN, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c index 81442274a0..3d862f93da 100644 --- a/src/devices/nm-device-tun.c +++ b/src/devices/nm-device-tun.c @@ -30,7 +30,7 @@ #include "nm-platform.h" #include "nm-device-factory.h" -#include "nm-device-tun-glue.h" +#include "nmdbus-device-tun.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceTun); @@ -258,9 +258,9 @@ nm_device_tun_class_init (NMDeviceTunClass *klass) FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_tun_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_TUN, + NULL); } diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index db29c00d2f..d1970eca72 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -35,7 +35,7 @@ #include "nm-dbus-manager.h" #include "nm-device-factory.h" -#include "nm-device-veth-glue.h" +#include "nmdbus-device-veth.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVeth); @@ -129,7 +129,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PEER: peer = get_peer (self); - g_value_set_boxed (value, peer ? nm_device_get_path (peer) : "/"); + g_value_set_string (value, peer ? nm_device_get_path (peer) : "/"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -150,14 +150,14 @@ nm_device_veth_class_init (NMDeviceVethClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PEER, - g_param_spec_boxed (NM_DEVICE_VETH_PEER, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_veth_object_info); + g_param_spec_string (NM_DEVICE_VETH_PEER, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_VETH, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 71013a99c8..ab20b5ad4b 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -41,7 +41,7 @@ #include "nm-device-factory.h" #include "nm-manager.h" -#include "nm-device-vlan-glue.h" +#include "nmdbus-device-vlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVlan); @@ -588,11 +588,11 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_vlan_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_VLAN, + NULL); - dbus_g_error_domain_register (NM_VLAN_ERROR, NULL, NM_TYPE_VLAN_ERROR); + _nm_dbus_register_error_domain (NM_VLAN_ERROR, NM_DBUS_INTERFACE_DEVICE_VLAN, NM_TYPE_VLAN_ERROR); } /*************************************************************/ diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c index ed6b8fa051..cbda8baad3 100644 --- a/src/devices/nm-device-vxlan.c +++ b/src/devices/nm-device-vxlan.c @@ -31,7 +31,7 @@ #include "nm-utils.h" #include "nm-device-factory.h" -#include "nm-device-vxlan-glue.h" +#include "nmdbus-device-vxlan.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceVxlan); @@ -157,7 +157,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PARENT: parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex); - g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/"); + g_value_set_string (value, parent ? nm_device_get_path (parent) : "/"); break; case PROP_ID: g_value_set_uint (value, priv->props.id); @@ -232,10 +232,10 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) /* properties */ g_object_class_install_property (object_class, PROP_PARENT, - g_param_spec_boxed (NM_DEVICE_VXLAN_PARENT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_VXLAN_PARENT, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ID, @@ -342,9 +342,9 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_vxlan_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE_VXLAN, + NULL); } /*************************************************************/ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8eb86d9294..2388706cc0 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -22,7 +22,6 @@ #include <config.h> #include <glib.h> #include <glib/gi18n.h> -#include <dbus/dbus.h> #include <netinet/in.h> #include <string.h> #include <unistd.h> @@ -67,7 +66,6 @@ #include "nm-connection-provider.h" #include "nm-posix-signals.h" #include "nm-manager-auth.h" -#include "nm-dbus-glib-types.h" #include "nm-dispatcher.h" #include "nm-config.h" #include "nm-dns-manager.h" @@ -75,10 +73,12 @@ #include "nm-device-logging.h" _LOG_DECLARE_SELF (NMDevice); -static void impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context); -static void impl_device_delete (NMDevice *self, DBusGMethodInvocation *context); +#include "nmdbus-device.h" -#include "nm-device-glue.h" +static gboolean impl_device_disconnect (NMDevice *device, + GDBusMethodInvocation *context); +static gboolean impl_device_delete (NMDevice *device, + GDBusMethodInvocation *context); G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, G_TYPE_OBJECT) @@ -255,7 +255,7 @@ typedef struct { gulong dnsmasq_state_id; /* Firewall */ - DBusGProxyCall *fw_call; + gpointer *fw_call; /* avahi-autoipd stuff */ GPid aipd_pid; @@ -478,7 +478,8 @@ nm_device_dbus_export (NMDevice *self) priv->path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++); _LOGI (LOGD_DEVICE, "exported as %s", priv->path); - nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, self); + + nm_object_export (NM_OBJECT (self), priv->path); } const char * @@ -4969,7 +4970,7 @@ delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex) static void disconnect_cb (NMDevice *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, GError *error, gpointer user_data) { @@ -4977,7 +4978,7 @@ disconnect_cb (NMDevice *self, GError *local = NULL; if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } @@ -4986,20 +4987,20 @@ disconnect_cb (NMDevice *self, local = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_ACTIVE, "Device is not active"); - dbus_g_method_return_error (context, local); - g_error_free (local); + g_dbus_method_invocation_take_error (context, local); } else { priv->autoconnect = FALSE; nm_device_state_changed (self, NM_DEVICE_STATE_DEACTIVATING, NM_DEVICE_STATE_REASON_USER_REQUESTED); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } } -static void -impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) +static gboolean +impl_device_disconnect (NMDevice *self, + GDBusMethodInvocation *context) { NMConnection *connection; GError *error = NULL; @@ -5008,9 +5009,8 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) error = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_ACTIVE, "This device is not active"); - dbus_g_method_return_error (context, error); - g_error_free (error); - return; + g_dbus_method_invocation_take_error (context, error); + return TRUE; } connection = nm_device_get_connection (self); @@ -5024,26 +5024,28 @@ impl_device_disconnect (NMDevice *self, DBusGMethodInvocation *context) TRUE, disconnect_cb, NULL); + return TRUE; } static void delete_cb (NMDevice *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, GError *error, gpointer user_data) { if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } /* Authorized */ nm_platform_link_delete (nm_device_get_ifindex (self)); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } -static void -impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) +static gboolean +impl_device_delete (NMDevice *self, + GDBusMethodInvocation *context) { GError *error = NULL; @@ -5051,9 +5053,8 @@ impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) error = g_error_new_literal (NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE, "This device is not a software device"); - dbus_g_method_return_error (context, error); - g_error_free (error); - return; + g_dbus_method_invocation_take_error (context, error); + return TRUE; } /* Ask the manager to authenticate this request for us */ @@ -5064,6 +5065,7 @@ impl_device_delete (NMDevice *self, DBusGMethodInvocation *context) TRUE, delete_cb, NULL); + return TRUE; } static void @@ -6821,7 +6823,10 @@ _set_state_full (NMDevice *self, g_object_notify (G_OBJECT (self), NM_DEVICE_STATE); g_object_notify (G_OBJECT (self), NM_DEVICE_STATE_REASON); - g_signal_emit_by_name (self, "state-changed", state, old_state, reason); + g_signal_emit (self, signals[STATE_CHANGED], state, old_state, reason); + nm_object_emit_dbus_signal (NM_OBJECT (self), + "StateChanged", + state, old_state, reason); /* Post-process the event after internal notification */ @@ -7567,8 +7572,6 @@ set_property (GObject *object, guint prop_id, } } -#define DBUS_TYPE_STATE_REASON_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID)) - static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -7619,39 +7622,39 @@ get_property (GObject *object, guint prop_id, break; case PROP_IP4_CONFIG: if (ip_config_valid (priv->state) && priv->ip4_config) - g_value_set_boxed (value, nm_ip4_config_get_dbus_path (priv->ip4_config)); + g_value_set_string (value, nm_ip4_config_get_dbus_path (priv->ip4_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP4_CONFIG: if (ip_config_valid (priv->state) && priv->dhcp4_config) - g_value_set_boxed (value, nm_dhcp4_config_get_dbus_path (priv->dhcp4_config)); + g_value_set_string (value, nm_dhcp4_config_get_dbus_path (priv->dhcp4_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_IP6_CONFIG: if (ip_config_valid (priv->state) && priv->ip6_config) - g_value_set_boxed (value, nm_ip6_config_get_dbus_path (priv->ip6_config)); + g_value_set_string (value, nm_ip6_config_get_dbus_path (priv->ip6_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP6_CONFIG: if (ip_config_valid (priv->state) && priv->dhcp6_config) - g_value_set_boxed (value, nm_dhcp6_config_get_dbus_path (priv->dhcp6_config)); + g_value_set_string (value, nm_dhcp6_config_get_dbus_path (priv->dhcp6_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_STATE: g_value_set_uint (value, priv->state); break; case PROP_STATE_REASON: - g_value_take_boxed (value, dbus_g_type_specialized_construct (DBUS_TYPE_STATE_REASON_STRUCT)); - dbus_g_type_struct_set (value, 0, priv->state, 1, priv->state_reason, G_MAXUINT); + g_value_take_variant (value, + g_variant_new ("(uu)", priv->state, priv->state_reason)); break; case PROP_ACTIVE_CONNECTION: if (priv->act_request) ac_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (priv->act_request)); - g_value_set_boxed (value, ac_path ? ac_path : "/"); + g_value_set_string (value, ac_path ? ac_path : "/"); break; case PROP_DEVICE_TYPE: g_value_set_uint (value, priv->type); @@ -7676,7 +7679,8 @@ get_property (GObject *object, guint prop_id, g_hash_table_iter_init (&iter, priv->available_connections); while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection))); - g_value_take_boxed (value, array); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_PHYSICAL_PORT_ID: g_value_set_string (value, priv->physical_port_id); @@ -7814,31 +7818,31 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_IP4_CONFIG, - g_param_spec_boxed (NM_DEVICE_IP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_IP4_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, - g_param_spec_boxed (NM_DEVICE_DHCP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_DHCP4_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_IP6_CONFIG, - g_param_spec_boxed (NM_DEVICE_IP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_IP6_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, - g_param_spec_boxed (NM_DEVICE_DHCP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_DHCP6_CONFIG, "", "", + NULL, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_STATE, @@ -7849,17 +7853,18 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_STATE_REASON, - g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "", - DBUS_TYPE_STATE_REASON_STRUCT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_variant (NM_DEVICE_STATE_REASON, "", "", + G_VARIANT_TYPE ("(uu)"), + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ACTIVE_CONNECTION, - g_param_spec_boxed (NM_DEVICE_ACTIVE_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_DEVICE_ACTIVE_CONNECTION, "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEVICE_TYPE, @@ -7915,7 +7920,7 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_install_property (object_class, PROP_AVAILABLE_CONNECTIONS, g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -8015,10 +8020,11 @@ nm_device_class_init (NMDeviceClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 0); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (klass), - &dbus_glib_nm_device_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (klass), + NMDBUS_TYPE_DEVICE, + "Disconnect", impl_device_disconnect, + "Delete", impl_device_delete, + NULL); - dbus_g_error_domain_register (NM_DEVICE_ERROR, NULL, NM_TYPE_DEVICE_ERROR); + _nm_dbus_register_error_domain (NM_DEVICE_ERROR, NM_DBUS_INTERFACE_DEVICE, NM_TYPE_DEVICE_ERROR); } - diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 28a2ff0be9..2d9338df45 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -22,10 +22,9 @@ #ifndef __NETWORKMANAGER_DEVICE_H__ #define __NETWORKMANAGER_DEVICE_H__ -#include <glib-object.h> -#include <dbus/dbus-glib.h> #include <netinet/in.h> +#include "nm-object.h" #include "nm-dbus-interface.h" #include "nm-types.h" #include "nm-connection.h" @@ -94,11 +93,11 @@ typedef enum { } NMDeviceError; struct _NMDevice { - GObject parent; + NMObject parent; }; typedef struct { - GObjectClass parent; + NMObjectClass parent; const char *connection_type; @@ -215,7 +214,7 @@ typedef struct { typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, GError *error, gpointer user_data); diff --git a/src/devices/team/Makefile.am b/src/devices/team/Makefile.am index 6fea9b3f90..ed9f417fbd 100644 --- a/src/devices/team/Makefile.am +++ b/src/devices/team/Makefile.am @@ -13,7 +13,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-team"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) if WITH_TEAMDCTL AM_CPPFLAGS += ${LIBTEAMDCTL_CFLAGS} @@ -49,7 +49,6 @@ libnm_device_plugin_team_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_team_la_LIBADD = \ - $(DBUS_LIBS) \ $(GUDEV_LIBS) if WITH_TEAMDCTL diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 40055961bd..c4de4dea3e 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -36,13 +36,12 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-platform.h" -#include "nm-dbus-glib-types.h" #include "nm-dbus-manager.h" #include "nm-enum-types.h" #include "nm-team-enum-types.h" #include "nm-posix-signals.h" -#include "nm-device-team-glue.h" +#include "nmdbus-device-team.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceTeam); @@ -782,5 +781,5 @@ nm_device_team_class_init (NMDeviceTeamClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_team_object_info); - dbus_g_error_domain_register (NM_DEVICE_TEAM_ERROR, NULL, NM_TYPE_TEAM_ERROR); + _nm_dbus_register_error_domain (NM_DEVICE_TEAM_ERROR, NULL, NM_TYPE_TEAM_ERROR); } diff --git a/src/devices/wifi/Makefile.am b/src/devices/wifi/Makefile.am index 230c00acc4..2ac3e6f04f 100644 --- a/src/devices/wifi/Makefile.am +++ b/src/devices/wifi/Makefile.am @@ -17,7 +17,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) GLIB_GENERATED = nm-wifi-enum-types.h nm-wifi-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM @@ -58,7 +58,6 @@ libnm_device_plugin_wifi_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_wifi_la_LIBADD = \ - $(DBUS_LIBS) \ $(GUDEV_LIBS) CLEANFILES = $(BUILT_SOURCES) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 2306155019..8a0a71ca45 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -27,7 +27,6 @@ #include "config.h" #include <glib.h> #include <glib/gi18n.h> -#include <dbus/dbus.h> #include <netinet/in.h> #include <string.h> #include <sys/stat.h> @@ -57,7 +56,7 @@ #include "nm-vpn-dbus-interface.h" -#include "nm-device-olpc-mesh-glue.h" +#include "nmdbus-device-olpc-mesh.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceOlpcMesh); @@ -567,6 +566,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_olpc_mesh_object_info); - dbus_g_error_domain_register (NM_OLPC_MESH_ERROR, NULL, NM_TYPE_OLPC_MESH_ERROR); + _nm_dbus_register_error_domain (NM_OLPC_MESH_ERROR, NULL, NM_TYPE_OLPC_MESH_ERROR); } diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 41a75da1a1..d825c8e265 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -21,7 +21,6 @@ #include <glib.h> #include <glib/gi18n.h> -#include <dbus/dbus.h> #include <netinet/in.h> #include <string.h> #include <sys/stat.h> @@ -56,7 +55,6 @@ #include "nm-manager-auth.h" #include "nm-settings-connection.h" #include "nm-enum-types.h" -#include "nm-dbus-glib-types.h" #include "nm-wifi-enum-types.h" #include "nm-connection-provider.h" @@ -71,9 +69,9 @@ static gboolean impl_device_get_all_access_points (NMDeviceWifi *device, static void impl_device_request_scan (NMDeviceWifi *device, GHashTable *options, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); -#include "nm-device-wifi-glue.h" +#include "nmdbus-device-wifi.h" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceWifi); @@ -1279,7 +1277,7 @@ impl_device_get_all_access_points (NMDeviceWifi *self, static void request_scan_cb (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, GError *error, gpointer user_data) { @@ -1287,7 +1285,7 @@ request_scan_cb (NMDevice *device, GError *local = NULL; if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } @@ -1295,20 +1293,20 @@ request_scan_cb (NMDevice *device, local = g_error_new_literal (NM_WIFI_ERROR, NM_WIFI_ERROR_SCAN_NOT_ALLOWED, "Scanning not allowed at this time"); - dbus_g_method_return_error (context, local); + g_dbus_method_invocation_return_gerror (context, local); g_error_free (local); return; } cancel_pending_scan (self); request_wireless_scan (self); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void impl_device_request_scan (NMDeviceWifi *self, GHashTable *options, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self); @@ -1352,7 +1350,7 @@ impl_device_request_scan (NMDeviceWifi *self, return; error: - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } @@ -1863,7 +1861,7 @@ schedule_scanlist_cull (NMDeviceWifi *self) static void supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, const char *object_path, - GHashTable *properties, + GVariant *properties, NMDeviceWifi *self) { NMDeviceState state; @@ -1897,7 +1895,6 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface, static void supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, const char *object_path, - GHashTable *properties, NMDeviceWifi *self) { NMDeviceState state; @@ -1905,7 +1902,6 @@ supplicant_iface_bss_updated_cb (NMSupplicantInterface *iface, g_return_if_fail (self != NULL); g_return_if_fail (object_path != NULL); - g_return_if_fail (properties != NULL); /* Ignore new APs when unavailable or unamnaged */ state = nm_device_get_state (NM_DEVICE (self)); @@ -3453,7 +3449,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_wifi_object_info); - dbus_g_error_domain_register (NM_WIFI_ERROR, NULL, NM_TYPE_WIFI_ERROR); + _nm_dbus_register_error_domain (NM_WIFI_ERROR, NULL, NM_TYPE_WIFI_ERROR); } diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index 0c252218fa..020b44ff53 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -32,7 +32,7 @@ #include "nm-setting-wireless.h" #include "nm-glib-compat.h" -#include "nm-access-point-glue.h" +#include "nmdbus-access-point.h" /* * Encapsulates Access Point information @@ -387,104 +387,107 @@ security_from_dict (GHashTable *security) return flags; } -static void -foreach_property_cb (gpointer key, gpointer value, gpointer user_data) +NMAccessPoint * +nm_ap_new_from_properties (const char *supplicant_path, GVariant *properties) { - GValue *variant = (GValue *) value; - NMAccessPoint *ap = (NMAccessPoint *) user_data; + NMAccessPoint *ap; + const char *addr; + const char bad_bssid1[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + const char bad_bssid2[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + GVariantIter iter; + GVariant *variant; - if (G_VALUE_HOLDS_BOXED (variant)) { - GArray *array = g_value_get_boxed (variant); + g_return_val_if_fail (properties != NULL, NULL); + ap = nm_ap_new (); + + g_object_freeze_notify (G_OBJECT (ap)); + + g_variant_iter_new (&iter, properties); + while (g_variant_iter_next (&iter, "{&sv}", &key, &variant)) { if (!strcmp (key, "SSID")) { - guint32 len = MIN (32, array->len); + const guint8 *array; + gsize length; + + array = g_variant_get_fixed_array (variant, &length, 1); + length = MIN (32, length); /* Stupid ieee80211 layer uses <hidden> */ - if (((len == 8) || (len == 9)) - && (memcmp (array->data, "<hidden>", 8) == 0)) - return; + if ( ((length == 8) || (length == 9)) + && (memcmp (array, "<hidden>", 8) == 0)) + goto next; + + if (nm_utils_is_empty_ssid (array, length)) + goto next; - if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len)) - return; + nm_ap_set_ssid (ap, array, length); - nm_ap_set_ssid (ap, (const guint8 *) array->data, len); } else if (!strcmp (key, "BSSID")) { + const guint8 *array; + gsize length; char *addr; - if (array->len != ETH_ALEN) - return; - addr = nm_utils_hwaddr_ntoa (array->data, array->len); + array = g_variant_get_fixed_array (variant, &length, 1); + if (length != ETH_ALEN) + goto next; + + addr = nm_utils_hwaddr_ntoa (array, length); nm_ap_set_address (ap, addr); g_free (addr); + } else if (!strcmp (key, "Rates")) { + const guint32 *rates; + gsize length; guint32 maxrate = 0; int i; - /* Find the max AP rate */ - for (i = 0; i < array->len; i++) { - guint32 r = g_array_index (array, guint32, i); + rates = g_variant_get_fixed_array (variant, &length, sizeof (guint32)); - if (r > maxrate) { - maxrate = r; - nm_ap_set_max_bitrate (ap, r / 1000); + /* Find the max AP rate */ + for (i = 0; i < length; i++) { + if (rates[i] > maxrate) { + maxrate = rates[i]; + nm_ap_set_max_bitrate (ap, rates[i] / 1000); } } + } else if (!strcmp (key, "WPA")) { NM80211ApSecurityFlags flags = nm_ap_get_wpa_flags (ap); - flags |= security_from_dict (g_value_get_boxed (variant)); + flags |= security_from_dict (variant); nm_ap_set_wpa_flags (ap, flags); + } else if (!strcmp (key, "RSN")) { NM80211ApSecurityFlags flags = nm_ap_get_rsn_flags (ap); - flags |= security_from_dict (g_value_get_boxed (variant)); + flags |= security_from_dict (variant); nm_ap_set_rsn_flags (ap, flags); - } - } else if (G_VALUE_HOLDS_UINT (variant)) { - guint32 val = g_value_get_uint (variant); - if (!strcmp (key, "Frequency")) - nm_ap_set_freq (ap, val); - } else if (G_VALUE_HOLDS_INT (variant)) { - gint val = g_value_get_int (variant); + } else if (!strcmp (key, "Frequency")) { + nm_ap_set_freq (ap, g_variant_get_uint (variant)); + + } else if (!strcmp (key, "Signal")) { + nm_ap_set_strength (ap, g_variant_get_int (variant)); - if (!strcmp (key, "Signal")) - nm_ap_set_strength (ap, nm_ap_utils_level_to_quality (val)); - } else if (G_VALUE_HOLDS_STRING (variant)) { - const char *val = g_value_get_string (variant); + } else if (!strcmp (key, "Mode")) { + const char *val = g_variant_get_string (variant); - if (val && !strcmp (key, "Mode")) { if (strcmp (val, "infrastructure") == 0) nm_ap_set_mode (ap, NM_802_11_MODE_INFRA); else if (strcmp (val, "ad-hoc") == 0) nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC); - } - } else if (G_VALUE_HOLDS_BOOLEAN (variant)) { - gboolean val = g_value_get_boolean (variant); - - if (strcmp (key, "Privacy") == 0) { + } else if (strcmp (key, "Privacy") == 0) { + gboolean val = g_variant_get_boolean (variant); + if (val) { NM80211ApFlags flags = nm_ap_get_flags (ap); nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY); } } - } -} -NMAccessPoint * -nm_ap_new_from_properties (const char *supplicant_path, GHashTable *properties) -{ - NMAccessPoint *ap; - const char *addr; - const char bad_bssid1[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - const char bad_bssid2[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - - g_return_val_if_fail (properties != NULL, NULL); - - ap = nm_ap_new (); - - g_object_freeze_notify (G_OBJECT (ap)); - g_hash_table_foreach (properties, foreach_property_cb, ap); + next: + g_variant_unref (variant); + } nm_ap_set_supplicant_path (ap, supplicant_path); diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h index 0abb28fccd..8ad9acb71b 100644 --- a/src/devices/wifi/nm-wifi-ap.h +++ b/src/devices/wifi/nm-wifi-ap.h @@ -56,7 +56,7 @@ typedef struct { GType nm_ap_get_type (void); NMAccessPoint * nm_ap_new_from_properties (const char *supplicant_path, - GHashTable *properties); + GVariant *properties); NMAccessPoint * nm_ap_new_fake_from_connection (NMConnection *connection); void nm_ap_export_to_dbus (NMAccessPoint *ap); diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 09c6401fef..500fd00a26 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -9,8 +9,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-wifi"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = test-wifi-ap-utils diff --git a/src/devices/wifi/tests/test-wifi-ap-utils.c b/src/devices/wifi/tests/test-wifi-ap-utils.c index 9ca49e4889..0d4bb6cad1 100644 --- a/src/devices/wifi/tests/test-wifi-ap-utils.c +++ b/src/devices/wifi/tests/test-wifi-ap-utils.c @@ -22,7 +22,6 @@ #include <string.h> #include "nm-wifi-ap-utils.h" -#include "nm-dbus-glib-types.h" #include "nm-setting-connection.h" #include "nm-setting-wireless.h" diff --git a/src/devices/wimax/Makefile.am b/src/devices/wimax/Makefile.am index 555b5ff2e3..ffa88b511f 100644 --- a/src/devices/wimax/Makefile.am +++ b/src/devices/wimax/Makefile.am @@ -9,7 +9,6 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-wimax"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) \ $(IWMX_SDK_CFLAGS) pkglib_LTLIBRARIES = libnm-device-plugin-wimax.la @@ -33,7 +32,6 @@ libnm_device_plugin_wimax_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_wimax_la_LIBADD = \ - $(DBUS_LIBS) \ $(IWMX_SDK_LIBS) \ $(GUDEV_LIBS) diff --git a/src/devices/wimax/nm-device-wimax.c b/src/devices/wimax/nm-device-wimax.c index d428f1d2eb..d5315e0475 100644 --- a/src/devices/wimax/nm-device-wimax.c +++ b/src/devices/wimax/nm-device-wimax.c @@ -43,11 +43,10 @@ #include "nm-rfkill-manager.h" #include "iwmxsdk.h" #include "nm-enum-types.h" -#include "nm-dbus-glib-types.h" static gboolean impl_device_get_nsp_list (NMDeviceWimax *device, GPtrArray **list, GError **error); -#include "nm-device-wimax-glue.h" +#include "nmdbus-device-wimax.h" G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE) @@ -1425,5 +1424,5 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass) G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_wimax_object_info); - dbus_g_error_domain_register (NM_WIMAX_ERROR, NULL, NM_TYPE_WIMAX_ERROR); + _nm_dbus_register_error_domain (NM_WIMAX_ERROR, NULL, NM_TYPE_WIMAX_ERROR); } diff --git a/src/devices/wimax/nm-wimax-nsp.c b/src/devices/wimax/nm-wimax-nsp.c index aa4ca5fa03..4bb286842e 100644 --- a/src/devices/wimax/nm-wimax-nsp.c +++ b/src/devices/wimax/nm-wimax-nsp.c @@ -23,7 +23,7 @@ #include "nm-dbus-interface.h" #include "nm-dbus-manager.h" #include "nm-setting-wimax.h" -#include "nm-wimax-nsp-glue.h" +#include "nmdbus-wimax-nsp.h" #include "nm-utils.h" G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, G_TYPE_OBJECT) diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am index 7e5b190bf3..64122f029b 100644 --- a/src/devices/wwan/Makefile.am +++ b/src/devices/wwan/Makefile.am @@ -14,7 +14,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager-wwan"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) \ $(MM_GLIB_CFLAGS) BUILT_SOURCES = $(null) @@ -45,7 +45,7 @@ WWAN_SYMBOL_VIS_FILE=$(srcdir)/wwan-exports.ver libnm_wwan_la_LDFLAGS = \ -avoid-version \ -Wl,--version-script=$(WWAN_SYMBOL_VIS_FILE) -libnm_wwan_la_LIBADD = $(DBUS_LIBS) $(MM_GLIB_LIBS) +libnm_wwan_la_LIBADD = $(GLIB_LIBS) $(MM_GLIB_LIBS) ########################################################### @@ -68,8 +68,7 @@ libnm_device_plugin_wwan_la_LDFLAGS = \ -Wl,--version-script=$(SYMBOL_VIS_FILE) libnm_device_plugin_wwan_la_LIBADD = \ - libnm-wwan.la \ - $(DBUS_LIBS) + libnm-wwan.la ########################################################### diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index ea331a7948..3a628f1b70 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -40,7 +40,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)) -#include "nm-device-modem-glue.h" +#include "nmdbus-device-modem.h" typedef struct { NMModem *modem; diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 3860979902..bdc5dc5e65 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -28,7 +28,6 @@ #include "nm-logging.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "nm-dbus-glib-types.h" #include "nm-modem-enum-types.h" G_DEFINE_TYPE (NMModem, nm_modem, G_TYPE_OBJECT) @@ -1401,7 +1400,7 @@ nm_modem_class_init (NMModemClass *klass) NULL, NULL, NULL, G_TYPE_NONE, 2, NM_TYPE_MODEM_STATE, NM_TYPE_MODEM_STATE); - dbus_g_error_domain_register (NM_MODEM_ERROR, + _nm_dbus_register_error_domain (NM_MODEM_ERROR, NM_DBUS_INTERFACE_DEVICE_MODEM, NM_TYPE_MODEM_ERROR); } diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 75a243649f..290178cf9e 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -31,7 +31,6 @@ #include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-logging.h" -#include "nm-dbus-glib-types.h" #include "nm-dhcp-client.h" #include "nm-dhcp-utils.h" #include "nm-platform.h" @@ -243,7 +242,7 @@ void nm_dhcp_client_set_state (NMDhcpClient *self, NMDhcpState new_state, GObject *ip_config, - GHashTable *options) + GVariant *options) { NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self); @@ -256,7 +255,7 @@ nm_dhcp_client_set_state (NMDhcpClient *self, g_assert ( (priv->ipv6 && NM_IS_IP6_CONFIG (ip_config)) || (!priv->ipv6 && NM_IS_IP4_CONFIG (ip_config))); g_assert (options); - g_assert_cmpint (g_hash_table_size (options), >, 0); + g_assert_cmpint (g_variant_n_children (options), >, 0); } else { g_assert (ip_config == NULL); g_assert (options == NULL); @@ -592,35 +591,33 @@ nm_dhcp_client_stop (NMDhcpClient *self, gboolean release) /********************************************/ static char * -garray_to_string (GArray *array, const char *key) +bytearray_variant_to_string (GVariant *value, const char *key) { - GString *str; - int i; - unsigned char c; - char *converted = NULL; + const guint8 *array, *s; + gsize length; + char *converted, *d; + + g_return_val_if_fail (value != NULL, NULL); - g_return_val_if_fail (array != NULL, NULL); + array = g_variant_get_fixed_array (value, &length, 1); /* Since the DHCP options come through environment variables, they should * already be UTF-8 safe, but just make sure. */ - str = g_string_sized_new (array->len); - for (i = 0; i < array->len; i++) { - c = array->data[i]; - - /* Convert NULLs to spaces and non-ASCII characters to ? */ - if (c == '\0') - c = ' '; - else if (c > 127) - c = '?'; - str = g_string_append_c (str, c); + converted = g_malloc (length + 1); + for (s = array, d = converted; *s; s++, d++) { + /* Convert NULs to spaces and non-ASCII characters to ? */ + if (*s == '\0') + *d = ' '; + else if (*s > 127) + *d = '?'; + else + *d = *s; } - str = g_string_append_c (str, '\0'); + *d = '\0'; - converted = str->str; if (!g_utf8_validate (converted, -1, NULL)) nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key); - g_string_free (str, FALSE); return converted; } @@ -628,11 +625,10 @@ garray_to_string (GArray *array, const char *key) #define NEW_TAG "new_" static void -copy_option (const char * key, - GValue *value, - gpointer user_data) +maybe_add_option (GVariantBuilder *builder, + const char *key, + GVariant *value) { - GHashTable *hash = user_data; char *str_value = NULL; const char **p; static const char *ignored_keys[] = { @@ -643,10 +639,7 @@ copy_option (const char * key, NULL }; - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)) { - nm_log_warn (LOGD_DHCP, "key %s value type was not DBUS_TYPE_G_UCHAR_ARRAY", key); - return; - } + g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_BYTESTRING)); if (g_str_has_prefix (key, OLD_TAG)) return; @@ -662,24 +655,26 @@ copy_option (const char * key, if (!key[0]) return; - str_value = garray_to_string ((GArray *) g_value_get_boxed (value), key); - if (str_value) - g_hash_table_insert (hash, g_strdup (key), str_value); + str_value = bytearray_variant_to_string (value, key); + if (str_value) { + g_variant_builder_add (builder, "{ss}", key, str_value); + g_free (str_value); + } } void nm_dhcp_client_new_options (NMDhcpClient *self, - GHashTable *options, + GVariant *options, const char *reason) { NMDhcpClientPrivate *priv; guint32 old_state; guint32 new_state; - GHashTable *str_options = NULL; + GVariant *str_options = NULL; GObject *ip_config = NULL; g_return_if_fail (NM_IS_DHCP_CLIENT (self)); - g_return_if_fail (options != NULL); + g_return_if_fail (g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}"))); g_return_if_fail (reason != NULL); priv = NM_DHCP_CLIENT_GET_PRIVATE (self); @@ -687,13 +682,21 @@ nm_dhcp_client_new_options (NMDhcpClient *self, new_state = reason_to_state (priv->iface, reason); if (new_state == NM_DHCP_STATE_BOUND) { + GVariantBuilder builder; + GVariantIter iter; + const char *name; + GVariant *value; + /* Copy options */ - str_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - g_hash_table_foreach (options, (GHFunc) copy_option, str_options); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); + g_variant_iter_init (&iter, options); + while (g_variant_iter_next (&iter, "{&sv}", &name, &value)) + maybe_add_option (&builder, name, value); + str_options = g_variant_builder_end (&builder); /* Create the IP config */ - g_warn_if_fail (g_hash_table_size (str_options)); - if (g_hash_table_size (str_options)) { + g_warn_if_fail (g_variant_n_children (str_options)); + if (g_variant_n_children (str_options)) { if (priv->ipv6) { ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (priv->iface, str_options, @@ -711,7 +714,7 @@ nm_dhcp_client_new_options (NMDhcpClient *self, nm_dhcp_client_set_state (self, new_state, ip_config, str_options); if (str_options) - g_hash_table_destroy (str_options); + g_variant_unref (str_options); g_clear_object (&ip_config); } diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h index 89fe821db5..fed9693b56 100644 --- a/src/dhcp-manager/nm-dhcp-client.h +++ b/src/dhcp-manager/nm-dhcp-client.h @@ -94,7 +94,7 @@ typedef struct { void (*state_changed) (NMDhcpClient *self, NMDhcpState state, GObject *ip_config, - GHashTable *options); + GVariant *options); } NMDhcpClientClass; GType nm_dhcp_client_get_type (void); @@ -129,7 +129,7 @@ gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self, void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release); void nm_dhcp_client_new_options (NMDhcpClient *self, - GHashTable *options, + GVariant *options, const char *reason); /* Backend helpers for subclasses */ @@ -142,7 +142,7 @@ void nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid); void nm_dhcp_client_set_state (NMDhcpClient *self, NMDhcpState new_state, GObject *ip_config, /* NMIP4Config or NMIP6Config */ - GHashTable *options); /* str:str hash */ + GVariant *options); /* str:str hash */ #endif /* __NETWORKMANAGER_DHCP_CLIENT_H__ */ diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index f24aad8dcc..01eceffae8 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -23,7 +23,6 @@ #include "config.h" #include <glib.h> #include <glib/gi18n.h> -#include <dbus/dbus.h> #include <sys/socket.h> #include <sys/wait.h> #include <signal.h> @@ -40,7 +39,6 @@ #include "nm-logging.h" #include "nm-dbus-manager.h" #include "nm-config.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "NetworkManagerUtils.h" @@ -77,7 +75,6 @@ typedef struct { GHashTable * proxies; GHashTable * clients; - DBusGProxy * proxy; char * default_hostname; } NMDhcpManagerPrivate; @@ -87,35 +84,33 @@ typedef struct { G_DEFINE_TYPE (NMDhcpManager, nm_dhcp_manager, G_TYPE_OBJECT) static char * -garray_to_string (GArray *array, const char *key) +bytearray_variant_to_string (GVariant *value, const char *key) { - GString *str; - int i; - unsigned char c; - char *converted = NULL; + const guint8 *array, *s; + gsize length; + char *converted, *d; - g_return_val_if_fail (array != NULL, NULL); + g_return_val_if_fail (value != NULL, NULL); + + array = g_variant_get_fixed_array (value, &length, 1); /* Since the DHCP options come through environment variables, they should * already be UTF-8 safe, but just make sure. */ - str = g_string_sized_new (array->len); - for (i = 0; i < array->len; i++) { - c = array->data[i]; - - /* Convert NULLs to spaces and non-ASCII characters to ? */ - if (c == '\0') - c = ' '; - else if (c > 127) - c = '?'; - str = g_string_append_c (str, c); + converted = g_malloc (length + 1); + for (s = array, d = converted; *s; s++, d++) { + /* Convert NULs to spaces and non-ASCII characters to ? */ + if (*s == '\0') + *d = ' '; + else if (*s > 127) + *d = '?'; + else + *d = *s; } - str = g_string_append_c (str, '\0'); + *d = '\0'; - converted = str->str; if (!g_utf8_validate (converted, -1, NULL)) nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key); - g_string_free (str, FALSE); return converted; } @@ -166,30 +161,27 @@ get_client_for_ifindex (NMDhcpManager *manager, int ifindex, gboolean ip6) } static char * -get_option (GHashTable *hash, const char *key) +get_option (GVariant *dict, const char *key) { - GValue *value; + GVariant *value; - value = g_hash_table_lookup (hash, key); + value = g_variant_lookup_value (dict, key, NULL); if (value == NULL) return NULL; - if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) { - nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not " - "DBUS_TYPE_G_UCHAR_ARRAY", + if (!g_variant_is_of_type (value, G_VARIANT_TYPE_BYTESTRING)) { + nm_log_warn (LOGD_DHCP, "unexpected key %s value type was not 'ay'", (char *) key); return NULL; } - return garray_to_string ((GArray *) g_value_get_boxed (value), key); + return bytearray_variant_to_string (value, key); } static void -nm_dhcp_manager_handle_event (DBusGProxy *proxy, - GHashTable *options, - gpointer user_data) +nm_dhcp_manager_handle_event (NMDhcpManager *manager, + GVariant *options) { - NMDhcpManager *manager = NM_DHCP_MANAGER (user_data); NMDhcpClient *client; char *iface = NULL; char *pid_str = NULL; @@ -240,47 +232,58 @@ out: g_free (reason); } -#if HAVE_DBUS_GLIB_100 +static void +nm_dhcp_manager_handle_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMDhcpManager *self = user_data; + GVariant *options; + + if (strcmp (signal_name, "Event") != 0) + return; + if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) + return; + + g_variant_get (parameters, "(@a{sv})", &options); + nm_dhcp_manager_handle_event (self, options); + g_variant_unref (options); +} + static void new_connection_cb (NMDBusManager *mgr, - DBusGConnection *connection, + GDBusConnection *connection, NMDhcpManager *self) { NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self); - DBusGProxy *proxy; + GDBusProxy *proxy; /* Create a new proxy for the client */ - proxy = dbus_g_proxy_new_for_peer (connection, "/", NM_DHCP_CLIENT_DBUS_IFACE); - dbus_g_proxy_add_signal (proxy, - "Event", - DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (proxy, - "Event", - G_CALLBACK (nm_dhcp_manager_handle_event), - self, - NULL); + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + NULL, "/", NM_DHCP_CLIENT_DBUS_IFACE, + NULL, NULL); + g_signal_connect (proxy, "g-signal", G_CALLBACK (nm_dhcp_manager_handle_signal), self); g_hash_table_insert (priv->proxies, connection, proxy); } static void dis_connection_cb (NMDBusManager *mgr, - DBusGConnection *connection, + GDBusConnection *connection, NMDhcpManager *self) { NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self); - DBusGProxy *proxy; + GDBusProxy *proxy; proxy = g_hash_table_lookup (priv->proxies, connection); if (proxy) { - dbus_g_proxy_disconnect_signal (proxy, - "Event", - G_CALLBACK (nm_dhcp_manager_handle_event), - self); + g_signal_handlers_disconnect_by_func (proxy, G_CALLBACK (nm_dhcp_manager_handle_signal), self); g_hash_table_remove (priv->proxies, connection); } } -#endif static GType get_client_type (const char *client, GError **error) @@ -535,9 +538,6 @@ nm_dhcp_manager_init (NMDhcpManager *self) NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self); const char *client; GError *error = NULL; -#if !HAVE_DBUS_GLIB_100 - DBusGConnection *g_connection; -#endif /* Maps DBusGConnection :: DBusGProxy */ priv->proxies = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); @@ -561,7 +561,6 @@ nm_dhcp_manager_init (NMDhcpManager *self) priv->dbus_mgr = nm_dbus_manager_get (); -#if HAVE_DBUS_GLIB_100 /* Register the socket our DHCP clients will return lease info on */ nm_dbus_manager_private_server_register (priv->dbus_mgr, PRIV_SOCK_PATH, PRIV_SOCK_TAG); priv->new_conn_id = g_signal_connect (priv->dbus_mgr, @@ -572,19 +571,6 @@ nm_dhcp_manager_init (NMDhcpManager *self) NM_DBUS_MANAGER_PRIVATE_CONNECTION_DISCONNECTED "::" PRIV_SOCK_TAG, (GCallback) dis_connection_cb, self); -#else - g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr); - priv->proxy = dbus_g_proxy_new_for_name (g_connection, - "org.freedesktop.nm_dhcp_client", - "/", - NM_DHCP_CLIENT_DBUS_IFACE); - g_assert (priv->proxy); - dbus_g_proxy_add_signal (priv->proxy, "Event", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Event", - G_CALLBACK (nm_dhcp_manager_handle_event), - self, - NULL); -#endif } static void @@ -614,8 +600,6 @@ dispose (GObject *object) g_hash_table_destroy (priv->proxies); priv->proxies = NULL; } - if (priv->proxy) - g_object_unref (priv->proxy); G_OBJECT_CLASS (nm_dhcp_manager_parent_class)->dispose (object); } diff --git a/src/dhcp-manager/nm-dhcp-utils.c b/src/dhcp-manager/nm-dhcp-utils.c index c017f6cfb3..fb3c56e445 100644 --- a/src/dhcp-manager/nm-dhcp-utils.c +++ b/src/dhcp-manager/nm-dhcp-utils.c @@ -207,12 +207,12 @@ out: } static gboolean -ip4_process_classless_routes (GHashTable *options, +ip4_process_classless_routes (GVariant *options, guint priority, NMIP4Config *ip4_config, guint32 *gwaddr) { - const char *str, *p; + const char *str = NULL, *p; g_return_val_if_fail (options != NULL, FALSE); g_return_val_if_fail (ip4_config != NULL, FALSE); @@ -233,7 +233,7 @@ ip4_process_classless_routes (GHashTable *options, * * 192.168.10.0/24 192.168.1.1 10.0.0.0/8 10.17.66.41 */ - str = g_hash_table_lookup (options, "classless_static_routes"); + g_variant_lookup (options, "classless_static_routes", "&s", &str); /* dhclient doesn't have actual support for rfc3442 classless static routes * upstream. Thus, people resort to defining the option in dhclient.conf @@ -244,11 +244,11 @@ ip4_process_classless_routes (GHashTable *options, * See https://lists.isc.org/pipermail/dhcp-users/2008-December/007629.html */ if (!str) - str = g_hash_table_lookup (options, "rfc3442_classless_static_routes"); + g_variant_lookup (options, "rfc3442_classless_static_routes", "&s", &str); /* Microsoft version; same as rfc3442 but with a different option # (249) */ if (!str) - str = g_hash_table_lookup (options, "ms_classless_static_routes"); + g_variant_lookup (options, "ms_classless_static_routes", "&s", &str); if (!str || !strlen (str)) return FALSE; @@ -271,13 +271,12 @@ ip4_process_classless_routes (GHashTable *options, } static void -process_classful_routes (GHashTable *options, guint priority, NMIP4Config *ip4_config) +process_classful_routes (GVariant *options, guint priority, NMIP4Config *ip4_config) { const char *str; char **searches, **s; - str = g_hash_table_lookup (options, "static_routes"); - if (!str) + if (!g_variant_lookup (options, "static_routes", "&s", &str)) return; searches = g_strsplit (str, " ", 0); @@ -372,13 +371,13 @@ ip4_add_domain_search (gpointer data, gpointer user_data) NMIP4Config * nm_dhcp_utils_ip4_config_from_options (const char *iface, - GHashTable *options, + GVariant *options, guint priority) { NMIP4Config *ip4_config = NULL; guint32 tmp_addr; NMPlatformIP4Address address; - char *str = NULL; + const char *str; guint32 gwaddr = 0, plen = 0; g_return_val_if_fail (options != NULL, NULL); @@ -387,15 +386,15 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, memset (&address, 0, sizeof (address)); address.timestamp = nm_utils_get_monotonic_timestamp_s (); - str = g_hash_table_lookup (options, "ip_address"); - if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { + if ( g_variant_lookup (options, "ip_address", "&s", &str) + && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { address.address = tmp_addr; nm_log_info (LOGD_DHCP4, " address %s", str); } else goto error; - str = g_hash_table_lookup (options, "subnet_mask"); - if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { + if ( g_variant_lookup (options, "subnet_mask", "&s", &str) + && (inet_pton (AF_INET, str, &tmp_addr) > 0)) { plen = nm_utils_ip4_netmask_to_prefix (tmp_addr); nm_log_info (LOGD_DHCP4, " plen %d (%s)", plen, str); } else { @@ -418,8 +417,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, /* If the gateway wasn't provided as a classless static route with a * subnet length of 0, try to find it using the old-style 'routers' option. */ - str = g_hash_table_lookup (options, "routers"); - if (str) { + if (g_variant_lookup (options, "routers", "&s", &str)) { char **routers = g_strsplit (str, " ", 0); char **s; @@ -448,8 +446,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, * dhcp server may not be reachable via unicast, and a host * specific route is needed. **/ - str = g_hash_table_lookup (options, "dhcp_server_identifier"); - if (str) { + if (g_variant_lookup (options, "dhcp_server_identifier", "&s", &str)) { if (inet_pton (AF_INET, str, &tmp_addr) > 0) { NMPlatformIP4Route route; guint32 mask = nm_utils_ip4_prefix_to_netmask (address.plen); @@ -473,8 +470,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, nm_log_warn (LOGD_DHCP4, "ignoring invalid server identifier '%s'", str); } - str = g_hash_table_lookup (options, "dhcp_lease_time"); - if (str) { + if (g_variant_lookup (options, "dhcp_lease_time", "&s", &str)) { address.lifetime = address.preferred = strtoul (str, NULL, 10); nm_log_info (LOGD_DHCP4, " lease time %d", address.lifetime); } @@ -482,12 +478,10 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, address.source = NM_PLATFORM_SOURCE_DHCP; nm_ip4_config_add_address (ip4_config, &address); - str = g_hash_table_lookup (options, "host_name"); - if (str) + if (g_variant_lookup (options, "host_name", "&s", &str)) nm_log_info (LOGD_DHCP4, " hostname '%s'", str); - str = g_hash_table_lookup (options, "domain_name_servers"); - if (str) { + if (g_variant_lookup (options, "domain_name_servers", "&s", &str)) { char **searches = g_strsplit (str, " ", 0); char **s; @@ -501,8 +495,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, g_strfreev (searches); } - str = g_hash_table_lookup (options, "domain_name"); - if (str) { + if (g_variant_lookup (options, "domain_name", "&s", &str)) { char **domains = g_strsplit (str, " ", 0); char **s; @@ -513,12 +506,10 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, g_strfreev (domains); } - str = g_hash_table_lookup (options, "domain_search"); - if (str) + if (g_variant_lookup (options, "domain_search", "&s", &str)) process_domain_search (str, ip4_add_domain_search, ip4_config); - str = g_hash_table_lookup (options, "netbios_name_servers"); - if (str) { + if (g_variant_lookup (options, "netbios_name_servers", "&s", &str)) { char **searches = g_strsplit (str, " ", 0); char **s; @@ -532,8 +523,7 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, g_strfreev (searches); } - str = g_hash_table_lookup (options, "interface_mtu"); - if (str) { + if (g_variant_lookup (options, "interface_mtu", "&s", &str)) { int int_mtu; errno = 0; @@ -545,14 +535,12 @@ nm_dhcp_utils_ip4_config_from_options (const char *iface, nm_ip4_config_set_mtu (ip4_config, int_mtu); } - str = g_hash_table_lookup (options, "nis_domain"); - if (str) { + if (g_variant_lookup (options, "nis_domain", "&s", &str)) { nm_log_info (LOGD_DHCP4, " NIS domain '%s'", str); nm_ip4_config_set_nis_domain (ip4_config, str); } - str = g_hash_table_lookup (options, "nis_servers"); - if (str) { + if (g_variant_lookup (options, "nis_servers", "&s", &str)) { char **searches = g_strsplit (str, " ", 0); char **s; @@ -583,16 +571,16 @@ ip6_add_domain_search (gpointer data, gpointer user_data) NMIP6Config * nm_dhcp_utils_ip6_config_from_options (const char *iface, - GHashTable *options, + GVariant *options, guint priority, gboolean info_only) { NMIP6Config *ip6_config = NULL; struct in6_addr tmp_addr; NMPlatformIP6Address address; - char *str = NULL; - GHashTableIter iter; - gpointer key, value; + const char *str; + GVariantIter iter; + const char *key, *value; g_return_val_if_fail (options != NULL, NULL); @@ -600,28 +588,25 @@ nm_dhcp_utils_ip6_config_from_options (const char *iface, address.plen = 128; address.timestamp = nm_utils_get_monotonic_timestamp_s (); - g_hash_table_iter_init (&iter, options); - while (g_hash_table_iter_next (&iter, &key, &value)) { + g_variant_iter_init (&iter, options); + while (g_variant_iter_next (&iter, "{&s&s}", &key, &value)) { nm_log_dbg (LOGD_DHCP6, "(%s): option '%s'=>'%s'", - iface, (const char *) key, (const char *) value); + iface, key, value); } ip6_config = nm_ip6_config_new (); - str = g_hash_table_lookup (options, "max_life"); - if (str) { + if (g_variant_lookup (options, "max_life", "&s", &str)) { address.lifetime = strtoul (str, NULL, 10); nm_log_info (LOGD_DHCP6, " valid_lft %d", address.lifetime); } - str = g_hash_table_lookup (options, "preferred_life"); - if (str) { + if (g_variant_lookup (options, "preferred_life", "&s", &str)) { address.preferred = strtoul (str, NULL, 10); nm_log_info (LOGD_DHCP6, " preferred_lft %d", address.preferred); } - str = g_hash_table_lookup (options, "ip6_address"); - if (str) { + if (g_variant_lookup (options, "ip6_address", "&s", &str)) { if (!inet_pton (AF_INET6, str, &tmp_addr)) { nm_log_warn (LOGD_DHCP6, "(%s): DHCP returned invalid address '%s'", iface, str); @@ -637,12 +622,10 @@ nm_dhcp_utils_ip6_config_from_options (const char *iface, goto error; } - str = g_hash_table_lookup (options, "host_name"); - if (str) + if (g_variant_lookup (options, "host_name", "&s", &str)) nm_log_info (LOGD_DHCP6, " hostname '%s'", str); - str = g_hash_table_lookup (options, "dhcp6_name_servers"); - if (str) { + if (g_variant_lookup (options, "dhcp6_name_servers", "&s", &str)) { char **searches = g_strsplit (str, " ", 0); char **s; @@ -656,8 +639,7 @@ nm_dhcp_utils_ip6_config_from_options (const char *iface, g_strfreev (searches); } - str = g_hash_table_lookup (options, "dhcp6_domain_search"); - if (str) + if (g_variant_lookup (options, "dhcp6_domain_search", "&s", &str)) process_domain_search (str, ip6_add_domain_search, ip6_config); return ip6_config; diff --git a/src/dhcp-manager/nm-dhcp-utils.h b/src/dhcp-manager/nm-dhcp-utils.h index ab9d45fe4b..4f7e2cda08 100644 --- a/src/dhcp-manager/nm-dhcp-utils.h +++ b/src/dhcp-manager/nm-dhcp-utils.h @@ -25,11 +25,11 @@ #include <nm-ip6-config.h> NMIP4Config *nm_dhcp_utils_ip4_config_from_options (const char *iface, - GHashTable *options, + GVariant *options, guint priority); NMIP6Config *nm_dhcp_utils_ip6_config_from_options (const char *iface, - GHashTable *options, + GVariant *options, guint priority, gboolean info_only); diff --git a/src/firewall-manager/nm-firewall-manager.c b/src/firewall-manager/nm-firewall-manager.c index d3e3777d44..332c888430 100644 --- a/src/firewall-manager/nm-firewall-manager.c +++ b/src/firewall-manager/nm-firewall-manager.c @@ -20,7 +20,6 @@ #include <string.h> #include <glib.h> -#include <dbus/dbus.h> #include "nm-firewall-manager.h" #include "nm-dbus-manager.h" @@ -42,7 +41,7 @@ enum { typedef struct { NMDBusManager * dbus_mgr; guint name_owner_id; - DBusGProxy * proxy; + GDBusProxy * proxy; gboolean running; } NMFirewallManagerPrivate; @@ -62,6 +61,7 @@ typedef struct { gpointer user_data; guint id; gboolean completed; + GCancellable *cancellable; } CBInfo; static void @@ -73,6 +73,7 @@ cb_info_free (CBInfo *info) nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone call cancelled [%u]", info->iface, info->id); g_free (info->iface); + g_object_unref (info->cancellable); g_free (info); } @@ -88,6 +89,7 @@ _cb_info_create (const char *iface, FwAddToZoneFunc callback, gpointer user_data info->id = id; info->iface = g_strdup (iface); info->completed = FALSE; + info->cancellable = g_cancellable_new (); info->callback = callback; info->user_data = user_data; @@ -95,33 +97,36 @@ _cb_info_create (const char *iface, FwAddToZoneFunc callback, gpointer user_data } static void -add_or_change_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +add_or_change_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { CBInfo *info = user_data; GError *error = NULL; - char *zone = NULL; + GVariant *ret; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, - G_TYPE_STRING, &zone, - G_TYPE_INVALID)) { - g_assert (error); - if (g_strcmp0 (error->message, "ZONE_ALREADY_SET") != 0) { + if (g_cancellable_is_cancelled (info->cancellable)) { + cb_info_free (info); + return; + } + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change succeeded [%u]", + info->iface, info->id); + g_variant_unref (ret); + } else { + if (!strstr (error->message, "ZONE_ALREADY_SET")) { nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone add/change failed [%u]: (%d) %s", info->iface, info->id, error->code, error->message); } else { nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change failed [%u]: (%d) %s", info->iface, info->id, error->code, error->message); } - } else { - nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change succeeded [%u]", - info->iface, info->id); + g_error_free (error); } info->callback (error, info->user_data); - info->completed = TRUE; - g_free (zone); - g_clear_error (&error); + cb_info_free (info); } gpointer @@ -145,44 +150,46 @@ nm_firewall_manager_add_or_change_zone (NMFirewallManager *self, nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s [%u]", iface, add ? "add" : "change", zone?"\"":"", zone ? zone : "default", zone?"\"":"", info->id); - return dbus_g_proxy_begin_call_with_timeout (priv->proxy, - add ? "addInterface" : "changeZone", - add_or_change_cb, - info, - (GDestroyNotify) cb_info_free, - 10000, /* timeout */ - G_TYPE_STRING, zone ? zone : "", - G_TYPE_STRING, iface, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + add ? "addInterface" : "changeZone", + g_variant_new ("(ss)", zone ? zone : "", iface), + G_DBUS_CALL_FLAGS_NONE, 10000, + info->cancellable, + add_or_change_cb, info); + return info; } static void -remove_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +remove_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { CBInfo *info = user_data; GError *error = NULL; - char * zone = NULL; + GVariant *ret; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, - G_TYPE_STRING, &zone, - G_TYPE_INVALID)) { - g_assert (error); + if (g_cancellable_is_cancelled (info->cancellable)) { + cb_info_free (info); + return; + } + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) { + nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove succeeded [%u]", + info->iface, info->id); + g_variant_unref (ret); + } else { /* ignore UNKNOWN_INTERFACE errors */ - if (error->message && !strstr (error->message, "UNKNOWN_INTERFACE")) { + if (!strstr (error->message, "UNKNOWN_INTERFACE")) { nm_log_warn (LOGD_FIREWALL, "(%s) firewall zone remove failed [%u]: (%d) %s", info->iface, info->id, error->code, error->message); } else { nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove failed [%u]: (%d) %s", info->iface, info->id, error->code, error->message); } - } else { - nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove succeeded [%u]", - info->iface, info->id); + g_error_free (error); } info->completed = TRUE; - g_free (zone); - g_clear_error (&error); + cb_info_free (info); } gpointer @@ -202,22 +209,23 @@ nm_firewall_manager_remove_from_zone (NMFirewallManager *self, nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove -> %s%s%s [%u]", iface, zone?"\"":"", zone ? zone : "*", zone?"\"":"", info->id); - return dbus_g_proxy_begin_call_with_timeout (priv->proxy, - "removeInterface", - remove_cb, - info, - (GDestroyNotify) cb_info_free, - 10000, /* timeout */ - G_TYPE_STRING, zone ? zone : "", - G_TYPE_STRING, iface, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "removeInterface", + g_variant_new ("(ss)", zone ? zone : "", iface), + G_DBUS_CALL_FLAGS_NONE, 10000, + info->cancellable, + remove_cb, info); + return info; } -void nm_firewall_manager_cancel_call (NMFirewallManager *self, gpointer call) +void +nm_firewall_manager_cancel_call (NMFirewallManager *self, gpointer call) { + CBInfo *info = call; + g_return_if_fail (NM_IS_FIREWALL_MANAGER (self)); - dbus_g_proxy_cancel_call (NM_FIREWALL_MANAGER_GET_PRIVATE (self)->proxy, - (DBusGProxyCall *) call); + + g_cancellable_cancel (info->cancellable); } static void @@ -275,7 +283,7 @@ static void nm_firewall_manager_init (NMFirewallManager * self) { NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self); - DBusGConnection *bus; + GDBusConnection *bus; priv->dbus_mgr = g_object_ref (nm_dbus_manager_get ()); priv->name_owner_id = g_signal_connect (priv->dbus_mgr, @@ -286,10 +294,14 @@ nm_firewall_manager_init (NMFirewallManager * self) nm_log_dbg (LOGD_FIREWALL, "firewall %s running", priv->running ? "is" : "is not" ); bus = nm_dbus_manager_get_connection (priv->dbus_mgr); - priv->proxy = dbus_g_proxy_new_for_name (bus, - FIREWALL_DBUS_SERVICE, - FIREWALL_DBUS_PATH, - FIREWALL_DBUS_INTERFACE_ZONE); + priv->proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + FIREWALL_DBUS_SERVICE, + FIREWALL_DBUS_PATH, + FIREWALL_DBUS_INTERFACE_ZONE, + NULL, NULL); } static void diff --git a/src/main.c b/src/main.c index d41472d4ff..6ff7a854e9 100644 --- a/src/main.c +++ b/src/main.c @@ -21,9 +21,6 @@ #include <config.h> #include <glib.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <dbus/dbus-glib.h> #include <getopt.h> #include <locale.h> #include <errno.h> diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 30e319b2e2..1462559b59 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -23,7 +23,6 @@ #include "nm-active-connection.h" #include "nm-dbus-interface.h" #include "nm-logging.h" -#include "nm-dbus-glib-types.h" #include "nm-dbus-manager.h" #include "nm-device.h" #include "nm-settings-connection.h" @@ -31,10 +30,10 @@ #include "nm-auth-subject.h" #include "NetworkManagerUtils.h" -#include "nm-active-connection-glue.h" +#include "nmdbus-active-connection.h" /* Base class for anything implementing the Connection.Active D-Bus interface */ -G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT) +G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT) #define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ NM_TYPE_ACTIVE_CONNECTION, \ @@ -561,7 +560,7 @@ nm_active_connection_get_assumed (NMActiveConnection *self) static void auth_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *unused, + GDBusMethodInvocation *unused, gpointer user_data) { NMActiveConnection *self = NM_ACTIVE_CONNECTION (user_data); @@ -695,10 +694,10 @@ set_property (GObject *object, guint prop_id, nm_active_connection_set_master (NM_ACTIVE_CONNECTION (object), g_value_get_object (value)); break; case PROP_SPECIFIC_OBJECT: - tmp = g_value_get_boxed (value); + tmp = g_value_get_string (value); /* NM uses "/" to mean NULL */ if (g_strcmp0 (tmp, "/") != 0) - priv->specific_object = g_value_dup_boxed (value); + priv->specific_object = g_value_dup_string (value); break; case PROP_DEFAULT: priv->is_default = !!g_value_get_boolean (value); @@ -727,7 +726,7 @@ get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_CONNECTION: - g_value_set_boxed (value, nm_connection_get_path (priv->connection)); + g_value_set_string (value, nm_connection_get_path (priv->connection)); break; case PROP_ID: g_value_set_string (value, nm_connection_get_id (priv->connection)); @@ -739,7 +738,7 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, nm_connection_get_connection_type (priv->connection)); break; case PROP_SPECIFIC_OBJECT: - g_value_set_boxed (value, priv->specific_object ? priv->specific_object : "/"); + g_value_set_string (value, priv->specific_object ? priv->specific_object : "/"); break; case PROP_DEVICES: devices = g_ptr_array_sized_new (1); @@ -755,19 +754,19 @@ get_property (GObject *object, guint prop_id, break; case PROP_IP4_CONFIG: /* The IP and DHCP config properties may be overridden by a subclass */ - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP4_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DEFAULT6: g_value_set_boolean (value, priv->is_default6); break; case PROP_IP6_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_DHCP6_CONFIG: - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_VPN: g_value_set_boolean (value, priv->vpn); @@ -775,7 +774,7 @@ get_property (GObject *object, guint prop_id, case PROP_MASTER: if (priv->master) master_device = nm_active_connection_get_device (priv->master); - g_value_set_boxed (value, master_device ? nm_device_get_path (master_device) : "/"); + g_value_set_string (value, master_device ? nm_device_get_path (master_device) : "/"); break; case PROP_INT_SUBJECT: g_value_set_object (value, priv->subject); @@ -854,10 +853,9 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) /* D-Bus exported properties */ g_object_class_install_property (object_class, PROP_CONNECTION, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_CONNECTION, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_ID, @@ -882,10 +880,9 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_SPECIFIC_OBJECT, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEVICES, @@ -912,17 +909,15 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_IP4_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP4_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DEFAULT6, @@ -933,17 +928,15 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_IP6_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_DHCP6_CONFIG, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, PROP_VPN, @@ -954,10 +947,9 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) g_object_class_install_property (object_class, PROP_MASTER, - g_param_spec_boxed (NM_ACTIVE_CONNECTION_MASTER, "", "", - DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "", "", + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /* Internal properties */ g_object_class_install_property diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index 9a6a54711c..8f5d616213 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -21,9 +21,9 @@ #ifndef __NETWORKMANAGER_ACTIVE_CONNECTION_H__ #define __NETWORKMANAGER_ACTIVE_CONNECTION_H__ -#include <glib-object.h> #include "nm-types.h" #include "nm-connection.h" +#include "nm-object.h" #define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ()) #define NM_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnection)) @@ -57,11 +57,11 @@ #define NM_ACTIVE_CONNECTION_INT_MASTER_READY "int-master-ready" struct _NMActiveConnection { - GObject parent; + NMObject parent; }; typedef struct { - GObjectClass parent; + NMObjectClass parent; /* re-emits device state changes as a convenience for subclasses for * device states >= DISCONNECTED. diff --git a/src/nm-auth-subject.c b/src/nm-auth-subject.c index e770af49ec..bdb3c398ca 100644 --- a/src/nm-auth-subject.c +++ b/src/nm-auth-subject.c @@ -54,7 +54,7 @@ typedef struct { } NMAuthSubjectPrivate; static NMAuthSubject * -_new_common (DBusGMethodInvocation *context, +_new_common (GDBusMethodInvocation *invocation, DBusConnection *connection, DBusMessage *message, gboolean internal) @@ -64,9 +64,9 @@ _new_common (DBusGMethodInvocation *context, NMDBusManager *dbus_mgr; gboolean success = FALSE; - g_return_val_if_fail (context || (connection && message) || internal, NULL); + g_return_val_if_fail (invocation || (connection && message) || internal, NULL); if (internal) - g_return_val_if_fail (context == NULL && connection == NULL && message == NULL, NULL); + g_return_val_if_fail (invocation == NULL && connection == NULL && message == NULL, NULL); subject = NM_AUTH_SUBJECT (g_object_new (NM_TYPE_AUTH_SUBJECT, NULL)); priv = NM_AUTH_SUBJECT_GET_PRIVATE (subject); @@ -79,9 +79,9 @@ _new_common (DBusGMethodInvocation *context, return subject; } - if (context) { + if (invocation) { success = nm_dbus_manager_get_caller_info (dbus_mgr, - context, + invocation, &priv->dbus_sender, &priv->uid, &priv->pid); @@ -118,9 +118,9 @@ _new_common (DBusGMethodInvocation *context, NMAuthSubject * -nm_auth_subject_new_from_context (DBusGMethodInvocation *context) +nm_auth_subject_new_from_context (GDBusMethodInvocation *invocation) { - return _new_common (context, NULL, NULL, FALSE); + return _new_common (invocation, NULL, NULL, FALSE); } NMAuthSubject * diff --git a/src/nm-auth-subject.h b/src/nm-auth-subject.h index 4834005e2e..acbc5293e7 100644 --- a/src/nm-auth-subject.h +++ b/src/nm-auth-subject.h @@ -22,10 +22,7 @@ #define __NETWORKMANAGER_AUTH_SUBJECT_H__ #include <config.h> -#include <glib.h> -#include <glib-object.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #if WITH_POLKIT #include <polkit/polkit.h> @@ -51,9 +48,9 @@ typedef struct { GType nm_auth_subject_get_type (void); -NMAuthSubject *nm_auth_subject_new_from_context (DBusGMethodInvocation *context); +NMAuthSubject *nm_auth_subject_new_from_context (GDBusMethodInvocation *context); -NMAuthSubject *nm_auth_subject_new_from_message (DBusConnection *connection, DBusMessage *message); +NMAuthSubject *nm_auth_subject_new_from_message (GDBusConnection *connection, GDBusMessage *message); NMAuthSubject *nm_auth_subject_new_internal (void); diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index d6e4abf662..654f401ddf 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -27,12 +27,10 @@ #include "nm-dbus-interface.h" #include "nm-dbus-manager.h" +#include "nm-dbus-utils.h" #include "nm-glib-compat.h" #include "nm-properties-changed-signal.h" -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> #include <string.h> #include "nm-logging.h" @@ -58,15 +56,14 @@ G_DEFINE_TYPE(NMDBusManager, nm_dbus_manager, G_TYPE_OBJECT) typedef struct _PrivateServer PrivateServer; typedef struct { - DBusConnection *connection; - DBusGConnection *g_connection; + GDBusConnection *connection; GHashTable *exported; gboolean started; GSList *private_servers; PrivateServer *priv_server; - DBusGProxy *proxy; + GDBusProxy *proxy; guint proxy_destroy_id; guint reconnect_id; @@ -99,20 +96,24 @@ struct _PrivateServer { char *tag; GQuark detail; char *address; - DBusServer *server; + GDBusServer *server; GHashTable *connections; NMDBusManager *manager; }; -static DBusHandlerResult -private_server_message_filter (DBusConnection *conn, - DBusMessage *message, - void *data) +static GDBusMessage * +private_server_message_filter (GDBusConnection *conn, + GDBusMessage *message, + gboolean incoming, + gpointer data) { PrivateServer *s = data; - /* Clean up after the connection */ - if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) { + if ( incoming + && (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_SIGNAL) + && !strcmp (g_dbus_message_get_interface (message), DBUS_INTERFACE_LOCAL) + && !strcmp (g_dbus_message_get_member (message), "Disconnected")) { + /* Clean up after the connection */ nm_log_dbg (LOGD_CORE, "(%s) closed connection %p on private socket.", s->tag, conn); @@ -120,38 +121,24 @@ private_server_message_filter (DBusConnection *conn, g_signal_emit (s->manager, signals[PRIVATE_CONNECTION_DISCONNECTED], s->detail, - dbus_connection_get_g_connection (conn)); + conn); g_hash_table_remove (s->connections, conn); - - /* Let dbus-glib process the message too */ - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static dbus_bool_t -allow_only_root (DBusConnection *connection, unsigned long uid, void *data) -{ - return uid == 0; + return message; } -static void -private_server_new_connection (DBusServer *server, - DBusConnection *conn, +static gboolean +private_server_new_connection (GDBusServer *server, + GDBusConnection *conn, gpointer user_data) { PrivateServer *s = user_data; static guint32 counter = 0; char *sender; - if (!dbus_connection_add_filter (conn, private_server_message_filter, s, NULL)) { - dbus_connection_close (conn); - return; - } - dbus_connection_set_unix_user_function (conn, allow_only_root, NULL, NULL); - dbus_connection_setup_with_g_main (conn, NULL); + g_dbus_connection_add_filter (conn, private_server_message_filter, s, NULL); /* Fake a sender since private connections don't have one */ sender = g_strdup_printf ("x:y:%d", counter++); @@ -163,7 +150,7 @@ private_server_new_connection (DBusServer *server, g_signal_emit (s->manager, signals[PRIVATE_CONNECTION_NEW], s->detail, - dbus_connection_get_g_connection (conn)); + conn); } static void @@ -174,35 +161,55 @@ private_server_dbus_connection_destroy (DBusConnection *conn) dbus_connection_unref (conn); } +static gboolean +private_server_authorize (GDBusAuthObserver *observer, + GIOStream *stream, + GCredentials *credentials, + gpointer user_data) +{ + return g_credentials_get_unix_uid (credentials) == 0; +} + static PrivateServer * private_server_new (const char *path, const char *tag, NMDBusManager *manager) { PrivateServer *s; - DBusServer *server; - DBusError error; - char *address; + GDBusAuthObserver *auth_observer; + GDBusServer *server; + GError *error = NULL; + char *address, *guid; unlink (path); address = g_strdup_printf ("unix:path=%s", path); nm_log_dbg (LOGD_CORE, "(%s) creating private socket %s.", tag, address); - dbus_error_init (&error); - server = dbus_server_listen (address, &error); + guid = g_dbus_generate_guid (); + auth_observer = g_dbus_auth_observer_new (); + g_signal_connection (auth_observer, "authorize-authenticated-peer", + private_server_authorize, NULL); + server = g_dbus_server_new_sync (address, + G_DBUS_SERVER_FLAGS_NONE, + guid, + auth_observer, + NULL, &error); + g_free (guid); + g_object_unref (auth_observer); + if (!server) { nm_log_warn (LOGD_CORE, "(%s) failed to set up private socket %s: %s", - tag, address, error.message); - dbus_error_free (&error); + tag, address, error->message); + g_error_free (error); return NULL; } s = g_malloc0 (sizeof (*s)); s->address = address; s->server = server; - dbus_server_setup_with_g_main (s->server, NULL); - dbus_server_set_new_connection_function (s->server, private_server_new_connection, s, NULL); + g_signal_connect (server, "new-connection", + G_CALLBACK (private_server_new_connection), s); s->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) private_server_dbus_connection_destroy, @@ -211,6 +218,8 @@ private_server_new (const char *path, s->tag = g_strdup (tag); s->detail = g_quark_from_string (s->tag); + g_dbus_server_start (server); + return s; } @@ -223,7 +232,10 @@ private_server_free (gpointer ptr) g_free (s->address); g_free (s->tag); g_hash_table_destroy (s->connections); - dbus_server_unref (s->server); + + g_dbus_server-stop (s->server); + g_object_unref (s->server); + memset (s, 0, sizeof (*s)); g_free (s); } @@ -237,10 +249,6 @@ nm_dbus_manager_private_server_register (NMDBusManager *self, PrivateServer *s; GSList *iter; -#if !HAVE_DBUS_GLIB_100 - g_assert_not_reached (); -#endif - g_return_if_fail (self != NULL); g_return_if_fail (path != NULL); g_return_if_fail (tag != NULL); @@ -258,12 +266,12 @@ nm_dbus_manager_private_server_register (NMDBusManager *self, } static const char * -private_server_get_connection_owner (PrivateServer *s, DBusGConnection *connection) +private_server_get_connection_owner (PrivateServer *s, GDBusConnection *connection) { g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); - return g_hash_table_lookup (s->connections, dbus_g_connection_get_connection (connection)); + return g_hash_table_lookup (s->connections, connection) } /**************************************************************/ @@ -275,52 +283,75 @@ _bus_get_unix_pid (NMDBusManager *self, GError **error) { guint32 unix_pid = G_MAXUINT32; - - if (!dbus_g_proxy_call_with_timeout (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, - "GetConnectionUnixProcessID", 2000, error, - G_TYPE_STRING, sender, - G_TYPE_INVALID, - G_TYPE_UINT, &unix_pid, - G_TYPE_INVALID)) { + GVariant *ret; + + ret = g_dbus_proxy_call_sync (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, + "GetConnectionUnixProcessID", + g_variant_new ("(s)", sender), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, error); + if (!ret) return FALSE; - } + + g_return_val_if_fail (g_variant_is_of_type (ret, G_VARIANT_TYPE ("(u)")), FALSE); + g_variant_get (ret, "(u)", &unix_pid); *out_pid = (gulong) unix_pid; return TRUE; } +static gboolean +_bus_get_unix_user (NMDBusManager *self, + const char *sender, + gulong *out_user, + GError **error) +{ + guint32 unix_uid = G_MAXUINT32; + GVariant *ret; + + ret = g_dbus_proxy_call_sync (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, + "GetConnectionUnixUser", + g_variant_new ("(s)", sender), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, error); + if (!ret) + return FALSE; + + g_return_val_if_fail (g_variant_is_of_type (ret, G_VARIANT_TYPE ("(u)")), FALSE); + g_variant_get (ret, "(u)", &unix_uid); + + *out_user = (gulong) unix_uid; + return TRUE; +} + /** * _get_caller_info_from_context(): * - * Given a dbus-glib method invocation, or a DBusConnection + DBusMessage, + * Given a GDBus method invocation, or a GDBusConnection + GDBusMessage, * return the sender and the UID of the sender. */ static gboolean _get_caller_info (NMDBusManager *self, - DBusGMethodInvocation *context, - DBusConnection *connection, - DBusMessage *message, + GDBusMethodInvocation *context, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); - DBusGConnection *gconn; - char *sender; - const char *priv_sender; + const char *sender; DBusError error; GSList *iter; if (context) { - gconn = dbus_g_method_invocation_get_g_connection (context); - g_assert (gconn); - connection = dbus_g_connection_get_connection (gconn); + connection = g_dbus_method_invocation_get_connection (context); /* only bus connections will have a sender */ - sender = dbus_g_method_get_sender (context); + sender = g_dbus_method_invocation_get_sender (context); } else { g_assert (message); - sender = g_strdup (dbus_message_get_sender (message)); + sender = g_dbus_message_get_sender (message); } g_assert (connection); @@ -329,14 +360,19 @@ _get_caller_info (NMDBusManager *self, for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { PrivateServer *s = iter->data; - priv_sender = g_hash_table_lookup (s->connections, connection); - if (priv_sender) { + sender = g_hash_table_lookup (s->connections, connection); + if (sender) { if (out_uid) *out_uid = 0; if (out_sender) - *out_sender = g_strdup (priv_sender); + *out_sender = g_strdup (sender); if (out_pid) { - if (!dbus_connection_get_unix_process_id (connection, out_pid)) + GCredentials *creds; + + creds = g_dbus_connection_get_credentials (connection); + if (creds) + *out_pid = g_credentials_get_unix_pid (creds); + else *out_pid = G_MAXULONG; } return TRUE; @@ -348,11 +384,8 @@ _get_caller_info (NMDBusManager *self, /* Bus connections always have a sender */ g_assert (sender); if (out_uid) { - dbus_error_init (&error); - *out_uid = dbus_bus_get_unix_user (connection, sender, &error); - if (dbus_error_is_set (&error)) { - dbus_error_free (&error); - *out_uid = G_MAXULONG; + if (!_bus_get_unix_user (self, sender, out_user, NULL)) { + *out_user = G_MAXULONG; g_free (sender); return FALSE; } @@ -375,7 +408,7 @@ _get_caller_info (NMDBusManager *self, gboolean nm_dbus_manager_get_caller_info (NMDBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, char **out_sender, gulong *out_uid, gulong *out_pid) @@ -385,8 +418,8 @@ nm_dbus_manager_get_caller_info (NMDBusManager *self, gboolean nm_dbus_manager_get_caller_info_from_message (NMDBusManager *self, - DBusConnection *connection, - DBusMessage *message, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid) @@ -401,7 +434,7 @@ nm_dbus_manager_get_unix_user (NMDBusManager *self, { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); GSList *iter; - DBusError error; + GError *error = NULL; g_return_val_if_fail (sender != NULL, FALSE); g_return_val_if_fail (out_uid != NULL, FALSE); @@ -423,10 +456,10 @@ nm_dbus_manager_get_unix_user (NMDBusManager *self, /* Otherwise, a bus connection */ dbus_error_init (&error); - *out_uid = dbus_bus_get_unix_user (priv->connection, sender, &error); - if (dbus_error_is_set (&error)) { + if (!_bus_get_unix_user (self, sender, out_uid, &error)) { nm_log_warn (LOGD_CORE, "Failed to get unix user for dbus sender '%s': %s", - sender, error.message); + sender, error->message); + g_error_free (error); return FALSE; } @@ -435,21 +468,27 @@ nm_dbus_manager_get_unix_user (NMDBusManager *self, /**************************************************************/ -#if HAVE_DBUS_GLIB_100 static void -private_connection_new (NMDBusManager *self, DBusGConnection *connection) +private_connection_new (NMDBusManager *self, GDBusConnection *connection) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); GHashTableIter iter; - GObject *object; + GDBusInterfaceSkeleton *interface; const char *path; + GError *error = NULL; /* Register all exported objects on this private connection */ g_hash_table_iter_init (&iter, priv->exported); - while (g_hash_table_iter_next (&iter, (gpointer) &object, (gpointer) &path)) { - dbus_g_connection_register_g_object (connection, path, object); - nm_log_dbg (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.", - PRIV_SOCK_TAG, object, G_OBJECT_TYPE_NAME (object), path); + while (g_hash_table_iter_next (&iter, (gpointer) &interface, (gpointer) &path)) { + if (g_dbus_interface_skeleton_export (interface, connection, path, &error)) { + nm_log_dbg (LOGD_CORE, "(%s) registered %p (%s) at '%s' on private socket.", + PRIV_SOCK_TAG, object, G_OBJECT_TYPE_NAME (object), path); + } else { + nm_log_warn (LOGD_CORE, "(%s) could not register %p (%s) at '%s' on private socket: %s.", + PRIV_SOCK_TAG, object, G_OBJECT_TYPE_NAME (object), path, + error->message); + g_clear_error (&error); + } } } @@ -495,7 +534,6 @@ private_server_setup (NMDBusManager *self) NULL); } } -#endif /* HAVE_DBUS_GLIB_100 */ static void nm_dbus_manager_init (NMDBusManager *self) @@ -504,9 +542,7 @@ nm_dbus_manager_init (NMDBusManager *self) priv->exported = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); -#if HAVE_DBUS_GLIB_100 private_server_setup (self); -#endif } static void @@ -598,11 +634,7 @@ nm_dbus_manager_cleanup (NMDBusManager *self, gboolean dispose) priv->proxy = NULL; } - if (priv->g_connection) { - dbus_g_connection_unref (priv->g_connection); - priv->g_connection = NULL; - priv->connection = NULL; - } + g_clear_pointer (&priv->connection); priv->started = FALSE; } @@ -647,6 +679,7 @@ nm_dbus_manager_get_name_owner (NMDBusManager *self, const char *name, GError **error) { + GVariant *ret; char *owner = NULL; g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), NULL); @@ -657,14 +690,17 @@ nm_dbus_manager_get_name_owner (NMDBusManager *self, if (!NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy) return NULL; - if (!dbus_g_proxy_call_with_timeout (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, - "GetNameOwner", 2000, error, - G_TYPE_STRING, name, - G_TYPE_INVALID, - G_TYPE_STRING, &owner, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, + "GetNameOwner", + g_variant_new ("(s)", name), + G_DBUS_CALL_FLAGS_NONE, 2000, + NULL, error); + if (!ret) return NULL; - } + + g_return_val_if_fail (g_variant_is_of_type (ret, G_VARIANT_TYPE ("(s)"))); + g_variant_get (ret, "(s)", &owner); + g_variant_unref (ret); return owner; } @@ -679,15 +715,14 @@ nm_dbus_manager_name_has_owner (NMDBusManager *self, g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), FALSE); g_return_val_if_fail (name != NULL, FALSE); - if (!NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy) + if (!NM_DBUS_MANAGER_GET_PRIVATE (self)->connection) return FALSE; - if (!dbus_g_proxy_call (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy, - "NameHasOwner", &err, - G_TYPE_STRING, name, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &has_owner, - G_TYPE_INVALID)) { + if (!_nm_dbus_check_has_name_owner_sync (NM_DBUS_MANAGER_GET_PRIVATE (self)->connection, + name, + &has_owner, + NULL, + &err)) { nm_log_warn (LOGD_CORE, "NameHasOwner request failed: %s", (err && err->message) ? err->message : "(unknown)"); g_clear_error (&err); @@ -697,16 +732,24 @@ nm_dbus_manager_name_has_owner (NMDBusManager *self, } static void -proxy_name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *old_owner, - const char *new_owner, - gpointer user_data) +proxy_dbus_signal (GDBusProxy *proxy, + const gchar *sender_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { + const char *name, *old_owner, *new_owner; + + if ( strcmp (signal_name, "NameOwnerChanged") != 0 + || !g_variant_is_of_type (parameters, "(sss)")) + return; + + g_variant_get (parameters, "(&s&s&s)", &name, &old_owner, &new_owner); g_signal_emit (G_OBJECT (user_data), signals[NAME_OWNER_CHANGED], 0, name, old_owner, new_owner); } +#if FIXME static void destroy_cb (DBusGProxy *proxy, gpointer user_data) { @@ -722,48 +765,56 @@ destroy_cb (DBusGProxy *proxy, gpointer user_data) start_reconnection_timeout (self); } +#endif static gboolean nm_dbus_manager_init_bus (NMDBusManager *self) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); + GError *error = NULL; if (priv->connection) { nm_log_warn (LOGD_CORE, "DBus Manager already has a valid connection."); return FALSE; } - dbus_connection_set_change_sigpipe (TRUE); - - priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (!priv->g_connection) { /* Log with 'info' severity; there won't be a bus daemon in minimal * environments (eg, initrd) where we only want to use the private * socket. */ - nm_log_info (LOGD_CORE, "Could not connect to the system bus; only the " - "private D-Bus socket will be available."); + nm_log_info (LOGD_CORE, "Could not connect to the system bus (%s); only the " + "private D-Bus socket will be available.", + error->message); + g_error_free (error); return FALSE; } - priv->connection = dbus_g_connection_get_connection (priv->g_connection); - dbus_connection_set_exit_on_disconnect (priv->connection, FALSE); - - priv->proxy = dbus_g_proxy_new_for_name (priv->g_connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); + priv->proxy = g_dbus_proxy_new_sync (priv->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", + NULL, &error); + if (!priv->proxy) { + g_clear_object (&priv->connection); + nm_log_warn (LOGD_CORE, "Could not create org.freedesktop.DBus proxy (%s); only the " + "private D-Bus socket will be available.", + error->message); + g_error_free (error); + return FALSE; + } +#if FIXME priv->proxy_destroy_id = g_signal_connect (priv->proxy, "destroy", G_CALLBACK (destroy_cb), self); +#endif - dbus_g_proxy_add_signal (priv->proxy, "NameOwnerChanged", - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, - "NameOwnerChanged", - G_CALLBACK (proxy_name_owner_changed), - self, NULL); + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (proxy_dbus_signal), self); return TRUE; } @@ -775,6 +826,7 @@ gboolean nm_dbus_manager_start_service (NMDBusManager *self) { NMDBusManagerPrivate *priv; + GVariant *ret; int result; GError *err = NULL; @@ -791,20 +843,24 @@ nm_dbus_manager_start_service (NMDBusManager *self) if (!priv->proxy) return FALSE; - if (!dbus_g_proxy_call (priv->proxy, "RequestName", &err, - G_TYPE_STRING, NM_DBUS_SERVICE, - G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_sync (priv->proxy, + "RequestName", + g_variant_new ("(su)", + NM_DBUS_SERVICE, + 0x4 /* DBUS_NAME_FLAG_DO_NOT_QUEUE */), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &err); + if (!ret) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service.\n" - " Error: '%s'", - (err && err->message) ? err->message : "(unknown)"); + " Error: '%s'", err->message); g_error_free (err); return FALSE; } - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_return_val_if_fail (g_variant_is_of_type (ret, "(u)"), FALSE); + g_variant_get (ret, "(u)", &result); + + if (result != 1 /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service as it is already taken."); return FALSE; } @@ -813,20 +869,12 @@ nm_dbus_manager_start_service (NMDBusManager *self) return priv->started; } -DBusConnection * -nm_dbus_manager_get_dbus_connection (NMDBusManager *self) -{ - g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), NULL); - - return NM_DBUS_MANAGER_GET_PRIVATE (self)->connection; -} - -DBusGConnection * +GDBusConnection * nm_dbus_manager_get_connection (NMDBusManager *self) { g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), NULL); - return NM_DBUS_MANAGER_GET_PRIVATE (self)->g_connection; + return NM_DBUS_MANAGER_GET_PRIVATE (self)->connection; } static void @@ -836,55 +884,29 @@ object_destroyed (NMDBusManager *self, gpointer object) } void -nm_dbus_manager_register_exported_type (NMDBusManager *self, - GType object_type, - const DBusGObjectInfo *info) -{ - const char *properties_info, *dbus_name, *gobject_name, *tmp_access; - - dbus_g_object_type_install_info (object_type, info); - if (!info->exported_properties) - return; - - properties_info = info->exported_properties; - while (*properties_info) { - /* The format is: "interface\0DBusPropertyName\0gobject_property_name\0access\0" */ - dbus_name = strchr (properties_info, '\0') + 1; - gobject_name = strchr (dbus_name, '\0') + 1; - tmp_access = strchr (gobject_name, '\0') + 1; - properties_info = strchr (tmp_access, '\0') + 1; - - /* Note that nm-properties-changed-signal takes advantage of the - * fact that @dbus_name and @gobject_name are static data that won't - * ever be freed. - */ - nm_properties_changed_signal_add_property (object_type, dbus_name, gobject_name); - } -} - -void nm_dbus_manager_register_object (NMDBusManager *self, const char *path, - gpointer object) + gpointer interface) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); GHashTableIter iter; - DBusConnection *connection; + GDBusConnection *connection; - g_assert (G_IS_OBJECT (object)); + g_assert (G_IS_DBUS_INTERFACE_SKELETON (object)); g_warn_if_fail (g_hash_table_lookup (priv->exported, object) == NULL); - g_hash_table_insert (priv->exported, G_OBJECT (object), g_strdup (path)); + g_hash_table_insert (priv->exported, object, g_strdup (path)); - if (priv->g_connection) - dbus_g_connection_register_g_object (priv->g_connection, path, G_OBJECT (object)); + if (priv->connection) { + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object), + priv->connection, path, NULL); + } if (priv->priv_server) { g_hash_table_iter_init (&iter, priv->priv_server->connections); while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) { - dbus_g_connection_register_g_object (dbus_connection_get_g_connection (connection), - path, - G_OBJECT (object)); + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (object), + connection, path, NULL); } } @@ -895,24 +917,13 @@ void nm_dbus_manager_unregister_object (NMDBusManager *self, gpointer object) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); - GHashTableIter iter; - DBusConnection *connection; - g_assert (G_IS_OBJECT (object)); + g_assert (G_IS_DBUS_INTERFACE_SKELETON (object)); - g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, G_OBJECT (object)); + g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, object); g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); - if (priv->g_connection) - dbus_g_connection_unregister_g_object (priv->g_connection, G_OBJECT (object)); - - if (priv->priv_server) { - g_hash_table_iter_init (&iter, priv->priv_server->connections); - while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) { - dbus_g_connection_unregister_g_object (dbus_connection_get_g_connection (connection), - G_OBJECT (object)); - } - } + g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (object)); } /** @@ -925,52 +936,49 @@ nm_dbus_manager_unregister_object (NMDBusManager *self, gpointer object) * * Creates a new proxy for a name on a given bus. Since the process which * called the D-Bus method could be coming from a private connection or the - * system bus connection, differnet proxies must be created for each case. This + * system bus connection, different proxies must be created for each case. This * function abstracts that. * - * Returns: a #DBusGProxy capable of calling D-Bus methods of the calling process + * Returns: a #GDBusProxy capable of calling D-Bus methods of the calling process */ -DBusGProxy * +GDBusProxy * nm_dbus_manager_new_proxy (NMDBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, const char *name, const char *path, const char *iface) { NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self); - DBusGConnection *connection; + GDBusConnection *connection; GSList *iter; const char *owner; + GDBusProxy *proxy; - connection = dbus_g_method_invocation_get_g_connection (context); + connection = g_dbus_method_invocation_get_connection (context); g_assert (connection); - /* Might be a private connection, for which we fake a sender */ + /* Might be a private connection, for which @name is fake */ for (iter = priv->private_servers; iter; iter = g_slist_next (iter)) { PrivateServer *s = iter->data; owner = private_server_get_connection_owner (s, connection); if (owner) { g_assert_cmpstr (owner, ==, name); - return dbus_g_proxy_new_for_peer (connection, path, iface); + name = NULL; + break; } } - return dbus_g_proxy_new_for_name (connection, name, path, iface); -} - -#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION -struct _HACKDBusGMethodInvocation { - DBusGConnection *connection; - /* ... */ -}; - -DBusGConnection * -dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context) -{ - /* Evil hack; this method exists in dbus-glib >= 101, but if we don't - * have that, emulate it. - */ - return ((struct _HACKDBusGMethodInvocation *) context)->connection; + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + name, path, interface, + NULL, &error); + if (!proxy) { + nm_log_warn (LOGD_CORE, "Could not create proxy for %s on connection %s: %s", + interface, name, error->message); + g_error_free (error); + } + return proxy; } -#endif /* HAVE_DBUS_GLIB_GMI_GET_CONNECTION */ diff --git a/src/nm-dbus-manager.h b/src/nm-dbus-manager.h index cc7f3210fd..dd0ea8f9e7 100644 --- a/src/nm-dbus-manager.h +++ b/src/nm-dbus-manager.h @@ -23,17 +23,15 @@ #define __NM_DBUS_MANAGER_H__ #include <config.h> -#include <glib-object.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #include "nm-types.h" G_BEGIN_DECLS -typedef gboolean (* NMDBusSignalHandlerFunc) (DBusConnection * connection, - DBusMessage * message, - gpointer user_data); +typedef gboolean (* NMDBusSignalHandlerFunc) (GDBusConnection * connection, + GDBusMessage * message, + gpointer user_data); #define NM_TYPE_DBUS_MANAGER (nm_dbus_manager_get_type ()) #define NM_DBUS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NM_TYPE_DBUS_MANAGER, NMDBusManager)) @@ -56,7 +54,7 @@ typedef struct { /* Signals */ void (*dbus_connection_changed) (NMDBusManager *mgr, - DBusConnection *connection); + GDBusConnection *connection); void (*name_owner_changed) (NMDBusManager *mgr, const char *name, @@ -64,10 +62,10 @@ typedef struct { const char *new_owner); void (*private_connection_new) (NMDBusManager *mgr, - DBusGConnection *connection); + GDBusConnection *connection); void (*private_connection_disconnected) (NMDBusManager *mgr, - DBusGConnection *connection); + GDBusConnection *connection); } NMDBusManagerClass; GType nm_dbus_manager_get_type (void); @@ -83,11 +81,10 @@ gboolean nm_dbus_manager_start_service (NMDBusManager *self); gboolean nm_dbus_manager_name_has_owner (NMDBusManager *self, const char *name); -DBusConnection * nm_dbus_manager_get_dbus_connection (NMDBusManager *self); -DBusGConnection * nm_dbus_manager_get_connection (NMDBusManager *self); +GDBusConnection * nm_dbus_manager_get_connection (NMDBusManager *self); gboolean nm_dbus_manager_get_caller_info (NMDBusManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, char **out_sender, gulong *out_uid, gulong *out_pid); @@ -97,16 +94,12 @@ gboolean nm_dbus_manager_get_unix_user (NMDBusManager *self, gulong *out_uid); gboolean nm_dbus_manager_get_caller_info_from_message (NMDBusManager *self, - DBusConnection *connection, - DBusMessage *message, + GDBusConnection *connection, + GDBusMessage *message, char **out_sender, gulong *out_uid, gulong *out_pid); -void nm_dbus_manager_register_exported_type (NMDBusManager *self, - GType object_type, - const DBusGObjectInfo *info); - void nm_dbus_manager_register_object (NMDBusManager *self, const char *path, gpointer object); @@ -117,16 +110,12 @@ void nm_dbus_manager_private_server_register (NMDBusManager *self, const char *path, const char *tag); -DBusGProxy *nm_dbus_manager_new_proxy (NMDBusManager *self, - DBusGMethodInvocation *context, +GDBusProxy *nm_dbus_manager_new_proxy (NMDBusManager *self, + GDBusMethodInvocation *context, const char *name, const char *path, const char *iface); -#if !HAVE_DBUS_GLIB_GMI_GET_CONNECTION -DBusGConnection *dbus_g_method_invocation_get_g_connection (DBusGMethodInvocation *context); -#endif - G_END_DECLS #endif /* __NM_DBUS_MANAGER_H__ */ diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp4-config.c index 45cf5c5cf2..00c1c5a979 100644 --- a/src/nm-dhcp4-config.c +++ b/src/nm-dhcp4-config.c @@ -24,8 +24,6 @@ #include "nm-dbus-interface.h" #include "nm-dbus-manager.h" #include "nm-dhcp4-config.h" -#include "nm-dhcp4-config-glue.h" -#include "nm-dbus-glib-types.h" #include "nm-utils.h" diff --git a/src/nm-dhcp6-config.c b/src/nm-dhcp6-config.c index 6a644a95f7..b865db16fa 100644 --- a/src/nm-dhcp6-config.c +++ b/src/nm-dhcp6-config.c @@ -24,8 +24,6 @@ #include "nm-dbus-interface.h" #include "nm-dbus-manager.h" #include "nm-dhcp6-config.h" -#include "nm-dhcp6-config-glue.h" -#include "nm-dbus-glib-types.h" #include "nm-utils.h" diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index e77cca6f5d..c3fe853233 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -33,7 +33,6 @@ #include "nm-device.h" #include "nm-dhcp4-config.h" #include "nm-dhcp6-config.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #define CALL_TIMEOUT (1000 * 60 * 10) /* 10 minutes for all scripts */ diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index aab50aeb8d..913358b14a 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -26,8 +26,6 @@ #include "nm-platform.h" #include "nm-utils.h" #include "nm-dbus-manager.h" -#include "nm-dbus-glib-types.h" -#include "nm-ip4-config-glue.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 9d2b61f2c5..c6c1ed3da0 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -27,8 +27,6 @@ #include "nm-platform.h" #include "nm-utils.h" #include "nm-dbus-manager.h" -#include "nm-dbus-glib-types.h" -#include "nm-ip6-config-glue.h" #include "NetworkManagerUtils.h" G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, G_TYPE_OBJECT) diff --git a/src/nm-manager-auth.c b/src/nm-manager-auth.c index 80a0b87fba..d010fae6e8 100644 --- a/src/nm-manager-auth.c +++ b/src/nm-manager-auth.c @@ -41,7 +41,7 @@ struct NMAuthChain { GSList *calls; GHashTable *data; - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; char *owner; gulong user_uid; NMAuthSubject *subject; @@ -109,7 +109,7 @@ static NMAuthChain * _auth_chain_new (NMAuthSubject *subject, const char *dbus_sender, gulong user_uid, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) { @@ -155,7 +155,7 @@ nm_auth_chain_new_dbus_sender (const char *dbus_sender, /* Creates the NMAuthSubject automatically */ NMAuthChain * -nm_auth_chain_new_context (DBusGMethodInvocation *context, +nm_auth_chain_new_context (GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) { @@ -179,7 +179,7 @@ nm_auth_chain_new_context (DBusGMethodInvocation *context, /* Requires an NMAuthSubject */ NMAuthChain * nm_auth_chain_new_subject (NMAuthSubject *subject, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data) { diff --git a/src/nm-manager-auth.h b/src/nm-manager-auth.h index 25f3cd591e..df28de3653 100644 --- a/src/nm-manager-auth.h +++ b/src/nm-manager-auth.h @@ -21,8 +21,7 @@ #ifndef __NETWORKMANAGER_MANAGER_AUTH_H__ #define __NETWORKMANAGER_MANAGER_AUTH_H__ -#include <glib.h> -#include <dbus/dbus-glib.h> +#include <gio/gio.h> #include <nm-connection.h> #include "nm-types.h" @@ -51,7 +50,7 @@ typedef enum { typedef void (*NMAuthChainResultFunc) (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data); NMAuthChain *nm_auth_chain_new_dbus_sender (const char *dbus_sender, @@ -59,12 +58,12 @@ NMAuthChain *nm_auth_chain_new_dbus_sender (const char *dbus_sender, NMAuthChainResultFunc done_func, gpointer user_data); -NMAuthChain *nm_auth_chain_new_context (DBusGMethodInvocation *context, +NMAuthChain *nm_auth_chain_new_context (GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); NMAuthChain *nm_auth_chain_new_subject (NMAuthSubject *subject, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthChainResultFunc done_func, gpointer user_data); diff --git a/src/nm-manager.c b/src/nm-manager.c index e08e595877..e7502f0be3 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -28,8 +28,6 @@ #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <dbus/dbus-glib.h> #include <gio/gio.h> #include <glib/gi18n.h> @@ -43,7 +41,6 @@ #include "nm-setting-connection.h" #include "nm-setting-wireless.h" #include "nm-setting-vpn.h" -#include "nm-dbus-glib-types.h" #include "nm-platform.h" #include "nm-rfkill-manager.h" #include "nm-dhcp-manager.h" @@ -77,28 +74,28 @@ static void impl_manager_activate_connection (NMManager *manager, const char *connection_path, const char *device_path, const char *specific_object_path, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_add_and_activate_connection (NMManager *manager, GHashTable *settings, const char *device_path, const char *specific_object_path, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_deactivate_connection (NMManager *manager, const char *connection_path, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_sleep (NMManager *manager, gboolean do_sleep, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_enable (NMManager *manager, gboolean enable, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_get_permissions (NMManager *manager, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static gboolean impl_manager_get_state (NMManager *manager, guint32 *state, @@ -107,16 +104,15 @@ static gboolean impl_manager_get_state (NMManager *manager, static void impl_manager_set_logging (NMManager *manager, const char *level, const char *domains, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); static void impl_manager_get_logging (NMManager *manager, char **level, char **domains); static void impl_manager_check_connectivity (NMManager *manager, - DBusGMethodInvocation *context); + GDBusMethodInvocation *context); -#include "nm-manager-glue.h" static void add_device (NMManager *self, NMDevice *device, gboolean generate_con); static void remove_device (NMManager *self, NMDevice *device, gboolean quitting); @@ -1368,7 +1364,7 @@ nm_manager_rfkill_update (NMManager *self, RfKillType rtype) static void device_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -1420,7 +1416,7 @@ device_auth_done_cb (NMAuthChain *chain, static void device_auth_request_cb (NMDevice *device, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMConnection *connection, const char *permission, gboolean allow_interaction, @@ -2948,7 +2944,7 @@ nm_manager_activate_connection (NMManager *self, static NMAuthSubject * validate_activation_request (NMManager *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMConnection *connection, const char *device_path, NMDevice **out_device, @@ -3055,7 +3051,7 @@ _activation_auth_done (NMActiveConnection *active, gpointer user_data2) { NMManager *self = user_data1; - DBusGMethodInvocation *context = user_data2; + GDBusMethodInvocation *context = user_data2; GError *error = NULL; if (success) { @@ -3071,7 +3067,7 @@ _activation_auth_done (NMActiveConnection *active, } g_assert (error); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); _internal_activation_failed (self, active, error->message); g_object_unref (active); g_error_free (error); @@ -3082,7 +3078,7 @@ impl_manager_activate_connection (NMManager *self, const char *connection_path, const char *device_path, const char *specific_object_path, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMActiveConnection *active = NULL; @@ -3184,7 +3180,7 @@ error: g_clear_object (&subject); g_assert (error); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } @@ -3199,7 +3195,7 @@ static void activation_add_done (NMSettings *self, NMSettingsConnection *new_connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { AddAndActivateInfo *info = user_data; @@ -3219,7 +3215,7 @@ activation_add_done (NMSettings *self, g_assert (error); _internal_activation_failed (info->manager, info->active, error->message); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&local); done: @@ -3236,7 +3232,7 @@ _add_and_activate_auth_done (NMActiveConnection *active, { NMManager *self = user_data1; NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); - DBusGMethodInvocation *context = user_data2; + GDBusMethodInvocation *context = user_data2; AddAndActivateInfo *info; GError *error = NULL; @@ -3259,7 +3255,7 @@ _add_and_activate_auth_done (NMActiveConnection *active, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, error_desc); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } @@ -3271,7 +3267,7 @@ impl_manager_add_and_activate_connection (NMManager *self, GHashTable *settings, const char *device_path, const char *specific_object_path, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMConnection *connection = NULL; @@ -3372,7 +3368,7 @@ error: g_clear_object (&active); g_assert (error); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } @@ -3422,7 +3418,7 @@ nm_manager_deactivate_connection (NMManager *manager, static void deactivate_net_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3456,9 +3452,9 @@ deactivate_net_auth_done_cb (NMAuthChain *chain, } 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); g_clear_error (&error); nm_auth_chain_unref (chain); @@ -3467,7 +3463,7 @@ deactivate_net_auth_done_cb (NMAuthChain *chain, static void impl_manager_deactivate_connection (NMManager *self, const char *active_path, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMConnection *connection = NULL; @@ -3531,7 +3527,7 @@ impl_manager_deactivate_connection (NMManager *self, done: g_clear_object (&subject); if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&error); } @@ -3649,7 +3645,7 @@ _internal_sleep (NMManager *self, gboolean do_sleep) static void sleep_auth_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3667,19 +3663,19 @@ sleep_auth_done_cb (NMAuthChain *chain, NM_MANAGER_ERROR_PERMISSION_DENIED, "Sleep/wake request failed: %s", error->message); - dbus_g_method_return_error (context, ret_error); + g_dbus_method_invocation_return_gerror (context, ret_error); g_error_free (ret_error); } else if (result != NM_AUTH_CALL_RESULT_YES) { ret_error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Not authorized to sleep/wake"); - dbus_g_method_return_error (context, ret_error); + g_dbus_method_invocation_return_gerror (context, ret_error); g_error_free (ret_error); } else { /* Auth success */ do_sleep = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "sleep")); _internal_sleep (self, do_sleep); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } nm_auth_chain_unref (chain); @@ -3689,7 +3685,7 @@ sleep_auth_done_cb (NMAuthChain *chain, static void impl_manager_sleep (NMManager *self, gboolean do_sleep, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv; GError *error = NULL; @@ -3706,7 +3702,7 @@ impl_manager_sleep (NMManager *self, error = g_error_new (NM_MANAGER_ERROR, NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE, "Already %s", do_sleep ? "asleep" : "awake"); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); return; } @@ -3720,7 +3716,7 @@ impl_manager_sleep (NMManager *self, * D-Bus permissions to restrict the call to root. */ _internal_sleep (self, do_sleep); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); return; #if 0 @@ -3733,7 +3729,7 @@ impl_manager_sleep (NMManager *self, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, error_desc); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } #endif @@ -3788,7 +3784,7 @@ _internal_enable (NMManager *self, gboolean enable) static void enable_net_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3816,11 +3812,11 @@ enable_net_done_cb (NMAuthChain *chain, /* Auth success */ enable = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "enable")); _internal_enable (self, enable); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } if (ret_error) { - dbus_g_method_return_error (context, ret_error); + g_dbus_method_invocation_return_gerror (context, ret_error); g_error_free (ret_error); } @@ -3830,7 +3826,7 @@ enable_net_done_cb (NMAuthChain *chain, static void impl_manager_enable (NMManager *self, gboolean enable, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv; NMAuthChain *chain; @@ -3861,7 +3857,7 @@ impl_manager_enable (NMManager *self, done: if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&error); } @@ -3887,7 +3883,7 @@ get_perm_add_result (NMAuthChain *chain, GHashTable *results, const char *permis static void get_permissions_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -3904,7 +3900,7 @@ get_permissions_done_cb (NMAuthChain *chain, NM_MANAGER_ERROR_PERMISSION_DENIED, "Permissions request failed: %s", error->message); - dbus_g_method_return_error (context, ret_error); + g_dbus_method_invocation_return_gerror (context, ret_error); g_error_free (ret_error); } else { results = g_hash_table_new (g_str_hash, g_str_equal); @@ -3930,7 +3926,7 @@ get_permissions_done_cb (NMAuthChain *chain, static void impl_manager_get_permissions (NMManager *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMAuthChain *chain; @@ -3941,7 +3937,7 @@ impl_manager_get_permissions (NMManager *self, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Unable to authenticate request."); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&error); return; } @@ -3972,7 +3968,7 @@ static void impl_manager_set_logging (NMManager *manager, const char *level, const char *domains, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); GError *error = NULL; @@ -3999,10 +3995,10 @@ impl_manager_set_logging (NMManager *manager, done: if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); } static void @@ -4019,13 +4015,13 @@ connectivity_check_done (GObject *object, GAsyncResult *result, gpointer user_data) { - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; NMConnectivityState state; GError *error = NULL; state = nm_connectivity_check_finish (NM_CONNECTIVITY (object), result, &error); if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } else dbus_g_method_return (context, state); @@ -4035,7 +4031,7 @@ connectivity_check_done (GObject *object, static void check_connectivity_auth_done_cb (NMAuthChain *chain, GError *auth_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -4065,7 +4061,7 @@ check_connectivity_auth_done_cb (NMAuthChain *chain, } if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } nm_auth_chain_unref (chain); @@ -4073,7 +4069,7 @@ check_connectivity_auth_done_cb (NMAuthChain *chain, static void impl_manager_check_connectivity (NMManager *manager, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); NMAuthChain *chain; @@ -4085,7 +4081,7 @@ impl_manager_check_connectivity (NMManager *manager, error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED, "Unable to authenticate request."); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&error); return; } @@ -4288,7 +4284,7 @@ policy_activating_device_changed (GObject *object, GParamSpec *pspec, gpointer u static void prop_set_auth_done_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMManager *self = NM_MANAGER (user_data); @@ -5219,7 +5215,7 @@ nm_manager_class_init (NMManagerClass *manager_class) G_TYPE_FROM_CLASS (manager_class), &dbus_glib_nm_manager_object_info); - dbus_g_error_domain_register (NM_MANAGER_ERROR, NULL, NM_TYPE_MANAGER_ERROR); - dbus_g_error_domain_register (NM_LOGGING_ERROR, "org.freedesktop.NetworkManager.Logging", NM_TYPE_LOGGING_ERROR); + _nm_dbus_register_error_domain (NM_MANAGER_ERROR, NULL, NM_TYPE_MANAGER_ERROR); + _nm_dbus_register_error_domain (NM_LOGGING_ERROR, "org.freedesktop.NetworkManager.Logging", NM_TYPE_LOGGING_ERROR); } diff --git a/src/nm-object.c b/src/nm-object.c new file mode 100644 index 0000000000..49b6ae62e9 --- /dev/null +++ b/src/nm-object.c @@ -0,0 +1,343 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#include "config.h" + +#include <stdarg.h> + +#include "nm-object.h" +#include "nm-dbus-manager.h" +#include "nm-properties-changed-signal.h" + +typedef struct { + GType dbus_skeleton_type; + char *method_name; + GCallback impl; +} NMObjectDBusMethodImpl; + +typedef struct { + GSList *skeleton_types; + GArray *methods; + GHashTable *signals; +} NMObjectClassPrivate; + +#define NM_OBJECT_CLASS_GET_PRIVATE(k) (G_TYPE_CLASS_GET_PRIVATE ((k), NM_TYPE_OBJECT, NMObjectClassPrivate)) + +G_DEFINE_TYPE_WITH_CODE (NMObject, nm_object, G_TYPE_OBJECT, + g_type_add_class_private (g_define_type_id, sizeof (NMObjectClassPrivate)); + ) + +typedef struct { + GSList *interfaces; + char *path; +} NMObjectPrivate; + +#define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate)) + +static char * +skeletonify_method_name (const char *dbus_method_name) +{ + GString *out; + const char *p; + + out = g_string_new ("handle"); + for (p = dbus_method_name; *p; p++) { + if (g_ascii_isupper (*p)) { + g_string_append_c (out, '-'); + g_string_append_c (out, g_ascii_tolower (*p)); + } else + g_string_append_c (out, *p); + } + + return g_string_free (out, FALSE); +} + +static char * +dbusify_signal_name (const char *gobject_signal_name) +{ + GString *out; + const char *p; + gboolean capitalize = TRUE; + + out = g_string_new (""); + for (p = gobject_signal_name; *p; p++) { + if (capitalize) { + g_string_append_c (out, g_ascii_toupper (*p)); + capitalize = FALSE; + } else if (*p == '-') + capitalize = TRUE; + else + g_string_append_c (out, *p); + } + + return g_string_free (out, FALSE); +} + +/** + * nm_object_class_add_interface: + * @object_class: an #NMObjectClass + * @dbus_skeleton_type: the type of the #GDBusObjectSkeleton to add + * @...: signal name / handler pairs, %NULL-terminated + * + * Adds @dbus_skeleton_type to the list of D-Bus interfaces implemented by + * @object_class. Instances of @object_class will automatically have a skeleton + * of that type created, which will be exported when you call + * nm_object_export(). + * + * The skeleton's properties will be initialized from the #NMObject's (which + * must have corresponding properties of the same type), and bidirectional + * bindings will be set up between them. + * + * The arguments after @dbus_skeleton_type are pairs of D-Bus method names (in + * CamelCase), and the corresponding handlers for them (which must have the same + * prototype as the corresponding signal on @dbus_skeleton_type, but with the + * first argument being an object of @object_class's type, not of + * @dbus_skeleton_type). + * + * FIXME: autoconnect methods somehow? + * + * FIXME: do something clever with D-Bus signals. For now, you have to manually + * emit them via nm_object_emit_dbus_signal(). + */ +void +nm_object_class_add_interface (NMObjectClass *object_class, + GType dbus_skeleton_type, + ...) +{ + NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (object_class); + NMObjectDBusMethodImpl method; + va_list ap; + const char *method_name; + GCallback impl; + guint *signals, n_signals; + GSignalQuery query; + int i; + + g_return_if_fail (NM_IS_OBJECT_CLASS (object_class)); + g_return_if_fail (g_type_is_a (dbus_skeleton_type, G_DBUS_TYPE_OBJECT_SKELETON)); + + cpriv->skeleton_types = g_slist_prepend (cpriv->skeleton_types, + GSIZE_TO_POINTER (dbus_skeleton_type)); + + /* Methods */ + va_start (ap, dbus_skeleton_type); + while ((method_name = va_arg (ap, const char *)) && (impl = va_arg (ap, GCallback))) { + method.dbus_skeleton_type = dbus_skeleton_type; + method.method_name = skeletonify_method_name (method_name); + method.impl = impl; + + g_array_append_val (cpriv->methods, method); + } + va_end (ap); + + /* Signals */ + signals = g_signal_list_ids (dbus_skeleton_type, &n_signals); + for (i = 0; i < n_signals; i++) { + g_signal_query (signals[i], &query); + g_hash_table_insert (cpriv->signals, + dbusify_signal_name (query.signal_name), + g_memdup (&query, sizeof (query))); + } + + nm_properties_changed_signal_setup (G_TYPE_FROM_CLASS (object_class), dbus_skeleton_type) +} + +/** + * nm_object_export: + * @self: an #NMObject + * @path: the path to export @self on + * + * Exports @self on @path on all active and future D-Bus connections. + */ +void +nm_object_export (NMObject *self, + const char *path) +{ + NMObjectPrivate *priv; + NMDBusManager *dbus_mgr; + GSList *iter; + + g_return_if_fail (NM_IS_OBJECT (self)); + priv = NM_OBJECT_GET_PRIVATE (self); + + g_return_if_fail (priv->interfaces != NULL); + g_return_if_fail (priv->path == NULL); + + priv->path = g_strdup (path); + + dbus_mgr = nm_dbus_manager_get (); + for (iter = priv->interfaces; iter; iter = iter->next) + nm_dbus_manager_register_object (dbus_mgr, path, self); +} + +/** + * nm_object_get_path: + * @self: an #NMObject + * + * Gets @self's D-Bus path. + * + * Returns: @self's D-Bus path, or %NULL if @self is not exported. + */ +const char * +nm_object_get_dbus_path (NMObject *self) +{ + g_return_if_fail (NM_IS_OBJECT (self)); + + return NM_OBJECT_GET_PRIVATE (self)->path; +} + +/** + * nm_object_unexport: + * @self: an #NMObject + * + * Unexports @self on all active D-Bus connections (and prevents it from being + * auto-exported on future connections). + */ +void +nm_object_unexport (NMObject *self) +{ + NMObjectPrivate *priv; + NMDBusManager *dbus_mgr; + GSList *iter; + + g_return_if_fail (NM_IS_OBJECT (self)); + priv = NM_OBJECT_GET_PRIVATE (self); + + g_return_if_fail (priv->interfaces != NULL); + g_return_if_fail (priv->path != NULL); + + g_clear_pointer (&priv->path, g_free); + + dbus_mgr = nm_dbus_manager_get (); + for (iter = priv->interfaces; iter; iter = iter->next) + nm_dbus_manager_unregister_object (dbus_mgr, self); +} + +/** + * nm_object_emit_dbus_signal: + * @self: an #NMObject + * @signal_name: the D-Bus signal to emit (in CamelCase) + * @...: signal arguments + * + * Emits the D-Bus signal @signal_name on the appropriate D-Bus interface on + * @self. + */ +void +nm_object_emit_dbus_signal (NMObject *self, + const char *signal_name, + ...) +{ + NMObjectClassPrivate *cpriv; + NMObjectPrivate *priv; + GSignalQuery *signal_info; + GDBusObjectSkeleton *interface = NULL; + GSList *iter; + va_list ap; + + g_return_if_fail (NM_IS_OBJECT (self)); + + priv = NM_OBJECT_GET_PRIVATE (self); + cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (self)); + + signal_info = g_hash_table_lookup (cpriv->signals, signal_name); + g_return_if_fail (signal_info != NULL); + + for (iter = priv->interfaces; iter; iter = iter->next) { + if (G_OBJECT_TYPE (iter->data) == signal_info->itype) { + interface = iter->data; + break; + } + } + g_return_if_fail (interface != NULL); + + va_start (ap, signal_name); + g_signal_emit_valist (interface, signal_info->signal_id, 0, ap); + va_end (ap); +} + +static void +nm_object_init (NMObject *self) +{ +} + +static void +nm_object_constructed (GObject *object) +{ + NMObject *self = NM_OBJECT (object); + NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (NM_OBJECT_GET_CLASS (self)); + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + GSList *iter; + GDBusObjectSkeleton *interface; + GParamSpec **properties; + guint n_properties; + int i; + + for (iter = cpriv->skeleton_types; iter; iter = iter->next) { + GType dbus_skeleton_type = GPOINTER_TO_SIZE (iter->data); + + interface = g_object_new (dbus_skeleton_type, NULL); + priv->interfaces = g_slist_prepend (priv->interfaces, interface); + + /* Bind properties */ + properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (interface), &n_properties); + for (i = 0; i < n_properties; i++) { + g_object_bind_property (self, properties[i]->name, + interface, properties[i]->name, + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + } + + /* Bind methods */ + for (i = 0; i < cpriv->methods->len; i++) { + NMObjectDBusMethodImpl *method = &g_array_index (cpriv->methods, NMObjectDBusMethodImpl, i); + + if (method->dbus_skeleton_type == dbus_skeleton_type) + g_signal_connect_swapped (interface, method->method_name, method->impl, self); + } + } +} + +static void +nm_object_dispose (GObject *object) +{ + NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self); + + if (priv->path) + nm_object_unexport (NM_OBJECT (object)); + + g_slist_free_full (priv->interfaces, g_object_unref); + priv->interfaces = NULL; + + G_OBJECT_CLASS (nm_object_parent_class)->dispose (object); +} + +static void +nm_object_class_init (NMObjectClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMObjectClassPrivate *cpriv = NM_OBJECT_CLASS_GET_PRIVATE (klass); + + cpriv->methods = g_array_new (FALSE, FALSE, sizeof (NMObjectDBusMethodImpl)); + cpriv->signals = g_hash_table_new (g_str_hash, g_str_equal); + + g_type_class_add_private (object_class, sizeof (NMObjectPrivate)); + + object_class->constructed = nm_object_constructed; + object_class->dispose = nm_object_dispose; +} diff --git a/src/nm-object.h b/src/nm-object.h new file mode 100644 index 0000000000..a249118996 --- /dev/null +++ b/src/nm-object.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright 2014 Red Hat, Inc. + */ + +#ifndef NM_OBJECT_H +#define NM_OBJECT_H + +#include <gio/gio.h> + +#include "nm-dbus-utils.h" + +G_BEGIN_DECLS + +#define NM_TYPE_OBJECT (nm_object_get_type ()) +#define NM_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_OBJECT, NMObject)) +#define NM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_OBJECT, NMObjectClass)) +#define NM_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_OBJECT)) +#define NM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_OBJECT)) +#define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OBJECT, NMObjectClass)) + +typedef struct { + GObject parent; +} NMObject; + +typedef struct { + GObjectClass parent; + +} NMObjectClass; + +GType nm_object_get_type (void); + +void nm_object_class_add_interface (NMObjectClass *object_class, + GType dbus_skeleton_type, + ...) G_GNUC_NULL_TERMINATED; + +void nm_object_export (NMObject *self, + const char *path); +const char *nm_object_get_path (NMObject *self); +void nm_object_unexport (NMObject *self); + +void nm_object_emit_dbus_signal (NMObject *self, + const char *signal_name, + ...); + +G_END_DECLS + +#endif /* NM_OBJECT_H */ diff --git a/src/nm-properties-changed-signal.c b/src/nm-properties-changed-signal.c index 6e07c25709..cbfa5b4796 100644 --- a/src/nm-properties-changed-signal.c +++ b/src/nm-properties-changed-signal.c @@ -22,10 +22,8 @@ #include <string.h> #include <stdio.h> -#include <dbus/dbus-glib.h> #include "nm-logging.h" #include "nm-properties-changed-signal.h" -#include "nm-dbus-glib-types.h" typedef struct { GHashTable *exported_props; @@ -171,27 +169,60 @@ notify (GObject *object, GParamSpec *pspec) info->idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, properties_changed, object, idle_id_reset); } -static NMPropertiesChangedClassInfo * -nm_properties_changed_signal_setup_type (GType type) + +static char * +hyphenify (const char *prop_name) +{ + char *hyphenified, *p; + + hyphenified = g_strdup (prop_name); + for (p = hyphenified; *p; p++) { + if (*p == '_') + *p = '-'; + } + return hyphenified; +} + +static char * +dbusify (const char *prop_name) +{ + char *dbusified, *s, *d; + gboolean capitalize = TRUE; + + dbusified = g_malloc (strlen (prop_name)); + for (s = prop_name, d = dbusified; *s; s++) { + if (capitalize) { + *d++ = g_ascii_toupper (*s); + capitalize = FALSE; + } else if (*s == '-') + capitalize = TRUE; + else + *d++ = *s; + } + return dbusified; +} + +void +nm_properties_changed_signal_setup (GType nm_type, GType dbus_type) { NMPropertiesChangedClassInfo *classinfo; NMPropertiesChangedClassInfo *parent_classinfo = NULL; - GObjectClass *object_class; + GObjectClass *nm_object_class, *dbus_object_class; GType parent; classinfo = g_slice_new (NMPropertiesChangedClassInfo); - g_type_set_qdata (type, nm_properties_changed_signal_quark (), classinfo); + g_type_set_qdata (nm_type, nm_properties_changed_signal_quark (), classinfo); - object_class = g_type_class_ref (type); - object_class->notify = notify; - g_type_class_unref (object_class); + nm_object_class = g_type_class_ref (nm_type); + nm_object_class->notify = notify; + g_type_class_unref (nm_object_class); - classinfo->exported_props = g_hash_table_new (g_str_hash, g_str_equal); + classinfo->exported_props = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* See if we've already added the signal to a parent class. (We can't just use * g_signal_lookup() here because it prints a warning if the signal doesn't exist!) */ - parent = g_type_parent (type); + parent = g_type_parent (nm_type); while (parent) { parent_classinfo = g_type_get_qdata (parent, nm_properties_changed_signal_quark ()); if (parent_classinfo) @@ -203,7 +234,7 @@ nm_properties_changed_signal_setup_type (GType type) classinfo->signal_id = parent_classinfo->signal_id; else { classinfo->signal_id = g_signal_new ("properties-changed", - type, + nm_type, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, @@ -211,31 +242,16 @@ nm_properties_changed_signal_setup_type (GType type) G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT); } - return classinfo; -} - -void -nm_properties_changed_signal_add_property (GType type, - const char *dbus_property_name, - const char *gobject_property_name) -{ - NMPropertiesChangedClassInfo *classinfo; - char *hyphen_name, *p; - - classinfo = g_type_get_qdata (type, nm_properties_changed_signal_quark ()); - if (!classinfo) - classinfo = nm_properties_changed_signal_setup_type (type); - - g_hash_table_insert (classinfo->exported_props, - (char *) gobject_property_name, - (char *) dbus_property_name); - - hyphen_name = g_strdup (gobject_property_name); - for (p = hyphen_name; *p; p++) { - if (*p == '_') - *p = '-'; + dbus_object_class = g_type_class_ref (dbus_type); + properties = g_object_class_list_properties (dbus_object_class, &n_properties); + for (i = 0; i < n_properties; i++) { + g_hash_table_insert (classinfo->exported_props, + g_strdup (properties[i].name), + dbusify (properties[i].name)); + g_hash_table_insert (classinfo->exported_props, + hyphenify (properties[i].name), + dbusify (properties[i].name)); } - g_hash_table_insert (classinfo->exported_props, - hyphen_name, - (char *) dbus_property_name); + + return classinfo; } diff --git a/src/nm-properties-changed-signal.h b/src/nm-properties-changed-signal.h index 97a3b2c024..9b495d92bf 100644 --- a/src/nm-properties-changed-signal.h +++ b/src/nm-properties-changed-signal.h @@ -24,8 +24,6 @@ #include <glib-object.h> -void nm_properties_changed_signal_add_property (GType type, - const char *dbus_property_name, - const char *gobject_property_name); +void nm_properties_changed_signal_setup (GObjectClass *nm_type_class, GType dbus_type); #endif /* _NM_PROPERTIES_CHANGED_SIGNAL_H_ */ diff --git a/src/nm-sleep-monitor-upower.c b/src/nm-sleep-monitor-upower.c index 58402abd42..03bd814ef6 100644 --- a/src/nm-sleep-monitor-upower.c +++ b/src/nm-sleep-monitor-upower.c @@ -21,7 +21,6 @@ #include <errno.h> #include <string.h> #include <sys/stat.h> -#include <dbus/dbus-glib.h> #include <gio/gio.h> #include "nm-logging.h" #include "nm-dbus-manager.h" diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index 0b8481d419..9a0da46a9c 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -54,23 +54,7 @@ #include "nm-logging.h" #include "nm-posix-signals.h" #include "nm-platform.h" - -static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context); - -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err); - -static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -#include "nm-ppp-manager-glue.h" +#include "nmdbus-ppp-manager.h" static void _ppp_cleanup (NMPPPManager *manager); @@ -84,7 +68,7 @@ typedef struct { char *parent_iface; NMActRequest *act_req; - DBusGMethodInvocation *pending_secrets_context; + GDBusMethodInvocation *pending_secrets_context; guint32 secrets_id; const char *secrets_setting_name; @@ -99,7 +83,10 @@ typedef struct { #define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate)) -G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT) +static void nm_ppp_manager_dbus_iface_init (NMDBusPPPManagerIface *iface, gpointer iface_data); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (NMDBUS_TYPE_PPP_MANAGER, nm_ppp_manager_dbus_iface_init)) enum { STATE_CHANGED, @@ -143,12 +130,11 @@ static void constructed (GObject *object) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); - DBusGConnection *connection; static guint32 counter = 0; priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/PPP/%d", counter++); - connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); - dbus_g_connection_register_g_object (connection, priv->dbus_path, object); + nm_dbus_manager_register_object (nm_dbus_manager_get (), + priv->dbus_path, object); G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructed (object); } @@ -266,9 +252,6 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class), - &dbus_glib_nm_ppp_manager_object_info); } NMPPPManager * @@ -429,14 +412,13 @@ ppp_secrets_cb (NMActRequest *req, if (error) { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); + g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error); goto out; } if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) { nm_log_warn (LOGD_PPP, "%s", local->message); - dbus_g_method_return_error (priv->pending_secrets_context, local); - g_clear_error (&local); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, local); goto out; } @@ -446,7 +428,8 @@ ppp_secrets_cb (NMActRequest *req, * against libnm just to parse this. So instead, let's just send what * it needs. */ - dbus_g_method_return (priv->pending_secrets_context, username, password); + g_dbus_method_invocation_return_value (priv->pending_secrets_context, + g_variant_new ("(ss)", username, password)); out: priv->pending_secrets_context = NULL; @@ -454,10 +437,11 @@ ppp_secrets_cb (NMActRequest *req, priv->secrets_setting_name = NULL; } -static void -impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context) +static gboolean +handle_ppp_manager_need_secrets (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMConnection *connection; const char *username = NULL; @@ -479,10 +463,9 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); } else { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); } - return; + return TRUE; } /* Only ask for completely new secrets after retrying them once; some devices @@ -504,35 +487,38 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, if (hints) g_ptr_array_free (hints, TRUE); + + return TRUE; } -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err) +static gboolean +handle_ppp_manager_set_state (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + guint32 state) { - g_signal_emit (manager, signals[STATE_CHANGED], 0, state); + g_signal_emit_by_name (dbus_ppp_manager, "state-changed", 0, state); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } static gboolean set_ip_config_common (NMPPPManager *self, - GHashTable *hash, + GVariant *dict, const char *iface_prop, guint32 *out_mtu) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); NMConnection *connection; NMSettingPpp *s_ppp; - GValue *val; + const char *ip_iface; - val = g_hash_table_lookup (hash, iface_prop); - if (!val || !G_VALUE_HOLDS_STRING (val)) { + if (!g_variant_lookup (dict, iface_prop, "&s", &ip_iface)) { nm_log_err (LOGD_PPP, "no interface received!"); return FALSE; } if (priv->ip_iface == NULL) - priv->ip_iface = g_value_dup_string (val); + priv->ip_iface = g_strdup (ip_iface); /* Got successful IP config; obviously the secrets worked */ connection = nm_act_request_get_connection (priv->act_req); @@ -549,16 +535,18 @@ set_ip_config_common (NMPPPManager *self, } static gboolean -impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config_hash, - GError **err) +handle_ppp_manager_set_ip4_config (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + GVariant *config_dict) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP4Config *config; NMPlatformIP4Address address; - GValue *val; + GVariant *val; int i; guint32 mtu = 0; + guint32 uval; nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received."); @@ -568,19 +556,16 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, memset (&address, 0, sizeof (address)); address.plen = 32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); - if (val) { - nm_ip4_config_set_gateway (config, g_value_get_uint (val)); - address.peer_address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &uval)) { + nm_ip4_config_set_gateway (config, uval); + address.peer_address = uval; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); - if (val) - address.address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &uval)) + address.address = uval; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &uval)) + address.plen = uval; if (address.address && address.plen) { address.source = NM_PLATFORM_SOURCE_PPP; @@ -590,23 +575,25 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, goto out; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); - if (val) { - GArray *dns = (GArray *) g_value_get_boxed (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "@au", &val)) { + const guint32 *array; + gsize length; - for (i = 0; i < dns->len; i++) - nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); + for (i = 0; i < length; i++) + nm_ip4_config_add_nameserver (config, array[i]); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); - if (val) { - GArray *wins = (GArray *) g_value_get_boxed (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "@au", &val)) { + const guint32 *array; + gsize length; - for (i = 0; i < wins->len; i++) - nm_ip4_config_add_wins (config, g_array_index (wins, guint, i)); + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); + for (i = 0; i < length; i++) + nm_ip4_config_add_wins (config, array[i]); } - if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) + if (!set_ip_config_common (manager, config_dict, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) goto out; if (mtu) @@ -617,6 +604,7 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, out: g_object_unref (config); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } @@ -624,21 +612,18 @@ out: * returns the IID. */ static gboolean -iid_value_to_ll6_addr (GHashTable *hash, +iid_value_to_ll6_addr (GVariant *dict, const char *prop, struct in6_addr *out_addr, NMUtilsIPv6IfaceId *out_iid) { - GValue *val; guint64 iid; - val = g_hash_table_lookup (hash, prop); - if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) { + if (!g_variant_lookup (dict, prop, "t", &iid)) { nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop); return FALSE; } - iid = g_value_get_uint64 (val); g_return_val_if_fail (iid != 0, FALSE); /* Construct an IPv6 LL address from the interface identifier. See @@ -654,10 +639,11 @@ iid_value_to_ll6_addr (GHashTable *hash, } static gboolean -impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *hash, - GError **err) +handle_ppp_manager_set_ip6_config (NMDBusPPPManager *dbus_ppp_manager, + GDBusMethodInvocation *context, + GVariant *config_dict) { + NMPPPManager *manager = NM_PPP_MANAGER (dbus_ppp_manager); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP6Config *config; NMPlatformIP6Address addr; @@ -673,15 +659,15 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, memset (&addr, 0, sizeof (addr)); addr.plen = 64; - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { nm_ip6_config_set_gateway (config, &a); addr.peer_address = a; } - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { nm_ip6_config_add_address (config, &addr); - if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { + if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { /* Push the IPv6 config and interface identifier up to the device */ g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config); } @@ -689,6 +675,7 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, nm_log_err (LOGD_PPP, "invalid IPv6 address received!"); g_object_unref (config); + g_dbus_method_invocation_return_value (context, NULL); return TRUE; } @@ -1216,3 +1203,13 @@ _ppp_cleanup (NMPPPManager *manager) priv->pid = 0; } } + + +static void +nm_ppp_manager_dbus_iface_init (NMDBusPPPManagerIface *iface, gpointer iface_data) +{ + iface->handle_need_secrets = handle_ppp_manager_need_secrets; + iface->handle_set_state = handle_ppp_manager_set_state; + iface->handle_set_ip4_config = handle_ppp_manager_set_ip4_config; + iface->handle_set_ip6_config = handle_ppp_manager_set_ip6_config; +} diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 333cbb261e..73b4861da3 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -22,16 +22,13 @@ #include <string.h> #include <pwd.h> -#include <glib.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> +#include <gio/gio.h> #include "nm-dbus-interface.h" #include "nm-logging.h" #include "nm-agent-manager.h" #include "nm-secret-agent.h" #include "nm-manager-auth.h" -#include "nm-dbus-glib-types.h" #include "nm-manager-auth.h" #include "nm-setting-vpn.h" #include "nm-setting-connection.h" @@ -40,7 +37,9 @@ #include "nm-dbus-manager.h" #include "nm-session-monitor.h" #include "nm-simple-connection.h" -#include "NetworkManagerUtils.h" +#include "nm-dbus-utils.h" + +#include "nmdbus-agent-manager.h" G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT) @@ -49,6 +48,8 @@ G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT) NMAgentManagerPrivate)) typedef struct { + NMDBusAgentManager *dbus_agent_manager; + gboolean disposed; NMDBusManager *dbus_mgr; @@ -80,20 +81,6 @@ static void request_remove_agent (Request *req, NMSecretAgent *agent, GSList **p static void request_next_agent (Request *req); -static void impl_agent_manager_register (NMAgentManager *self, - const char *identifier, - DBusGMethodInvocation *context); - -static void impl_agent_manager_register_with_capabilities (NMAgentManager *self, - const char *identifier, - NMSecretAgentCapabilities capabilities, - DBusGMethodInvocation *context); - -static void impl_agent_manager_unregister (NMAgentManager *self, - DBusGMethodInvocation *context); - -#include "nm-agent-manager-glue.h" - /********************************************************************/ #define NM_AGENT_MANAGER_ERROR (nm_agent_manager_error_quark ()) @@ -206,7 +193,7 @@ validate_identifier (const char *identifier, GError **error) static void agent_register_permissions_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMAgentManager *self = NM_AGENT_MANAGER (user_data); @@ -227,8 +214,7 @@ agent_register_permissions_done (NMAuthChain *chain, NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED, "Failed to request agent permissions: (%d) %s", error->code, error->message); - dbus_g_method_return_error (context, local); - g_error_free (local); + g_dbus_method_invocation_take_error (context, local); } else { agent = nm_auth_chain_steal_data (chain, "agent"); g_assert (agent); @@ -245,7 +231,7 @@ agent_register_permissions_done (NMAuthChain *chain, g_hash_table_insert (priv->agents, g_strdup (sender), agent); nm_log_dbg (LOGD_AGENTS, "(%s) agent registered", nm_secret_agent_get_description (agent)); - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); /* Signal an agent was registered */ g_signal_emit (self, signals[AGENT_REGISTERED], 0, agent); @@ -277,12 +263,17 @@ find_agent_by_identifier_and_uid (NMAgentManager *self, return NULL; } -static void -impl_agent_manager_register_with_capabilities (NMAgentManager *self, - const char *identifier, - NMSecretAgentCapabilities capabilities, - DBusGMethodInvocation *context) + + + +static gboolean +impl_agent_manager_register_with_capabilities (NMDBusAgentManager *object, + GDBusMethodInvocation *context, + const gchar *identifier, + guint capabilities, + gpointer user_data) { + NMAgentManager *self = NM_AGENT_MANAGER (user_data); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self); NMAuthSubject *subject; gulong sender_uid = G_MAXULONG; @@ -350,24 +341,29 @@ impl_agent_manager_register_with_capabilities (NMAgentManager *self, done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); g_clear_error (&local); g_clear_object (&subject); + + return TRUE; } -static void -impl_agent_manager_register (NMAgentManager *self, - const char *identifier, - DBusGMethodInvocation *context) +static gboolean +impl_agent_manager_register (NMDBusAgentManager *object, + GDBusMethodInvocation *context, + const gchar *identifier, + gpointer user_data) { - impl_agent_manager_register_with_capabilities (self, identifier, 0, context); + impl_agent_manager_register_with_capabilities (object, context, identifier, 0, user_data); + return TRUE; } -static void -impl_agent_manager_unregister (NMAgentManager *self, - DBusGMethodInvocation *context) +static gboolean +impl_agent_manager_unregister (NMDBusAgentManager *object, + GDBusMethodInvocation *context, + gpointer user_data) { + NMAgentManager *self = NM_AGENT_MANAGER (user_data); NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self); GError *error = NULL; char *sender = NULL; @@ -391,19 +387,20 @@ impl_agent_manager_unregister (NMAgentManager *self, goto done; } - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); g_free (sender); + + return TRUE; } /*************************************************************/ typedef void (*RequestCompleteFunc) (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -499,7 +496,7 @@ request_free (Request *req) static void req_complete_success (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_uname) { @@ -680,7 +677,7 @@ typedef struct { char *setting_name; char **hints; - GHashTable *existing_secrets; + GVariant *existing_secrets; NMAgentSecretsResultFunc callback; gpointer callback_data; @@ -704,7 +701,7 @@ connection_request_free (gpointer data) g_free (req->setting_name); g_strfreev (req->hints); if (req->existing_secrets) - g_hash_table_unref (req->existing_secrets); + g_variant_unref (req->existing_secrets); if (req->chain) nm_auth_chain_unref (req->chain); } @@ -732,7 +729,7 @@ connection_request_add_agent (Request *parent, NMSecretAgent *agent) static ConnectionRequest * connection_request_new_get (NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, const char *verb, NMSecretAgentGetSecretsFlags flags, @@ -762,7 +759,7 @@ connection_request_new_get (NMConnection *connection, req->connection = g_object_ref (connection); if (existing_secrets) - req->existing_secrets = g_hash_table_ref (existing_secrets); + req->existing_secrets = g_variant_ref (existing_secrets); req->setting_name = g_strdup (setting_name); req->hints = g_strdupv ((char **) hints); req->flags = flags; @@ -801,13 +798,13 @@ connection_request_new_other (NMConnection *connection, static void get_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { Request *parent = user_data; ConnectionRequest *req = user_data; - GHashTable *setting_secrets; + GVariant *setting_secrets; const char *agent_dbus_owner; struct passwd *pw; char *agent_uname = NULL; @@ -815,13 +812,16 @@ get_done_cb (NMSecretAgent *agent, g_return_if_fail (call_id == parent->current_call_id); if (error) { + char *dbus_error; + nm_log_dbg (LOGD_AGENTS, "(%s) agent failed secrets request %p/%s/%s: (%d) %s", nm_secret_agent_get_description (agent), req, parent->detail, req->setting_name, error ? error->code : -1, (error && error->message) ? error->message : "(unknown)"); - if (dbus_g_error_has_name (error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) { + dbus_error = g_dbus_error_get_remote_error (error); + if (!g_strcmp0 (dbus_error, NM_DBUS_INTERFACE_SECRET_AGENT ".UserCanceled")) { error = g_error_new_literal (NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_USER_CANCELED, "User canceled the secrets request."); @@ -831,12 +831,13 @@ get_done_cb (NMSecretAgent *agent, /* Try the next agent */ request_next_agent (parent); } + g_free (dbus_error); return; } /* Ensure the setting we wanted secrets for got returned and has something in it */ - setting_secrets = g_hash_table_lookup (secrets, req->setting_name); - if (!setting_secrets || !g_hash_table_size (setting_secrets)) { + setting_secrets = g_variant_lookup_value (secrets, req->setting_name, NM_VARIANT_TYPE_SETTING); + if (!setting_secrets || !g_variant_n_children (setting_secrets)) { nm_log_dbg (LOGD_AGENTS, "(%s) agent returned no secrets for request %p/%s/%s", nm_secret_agent_get_description (agent), req, parent->detail, req->setting_name); @@ -863,40 +864,40 @@ get_done_cb (NMSecretAgent *agent, } static void -set_secrets_not_required (NMConnection *connection, GHashTable *hash) +set_secrets_not_required (NMConnection *connection, GVariant *dict) { - GHashTableIter iter, setting_iter; + GVariantIter iter, setting_iter; const char *setting_name = NULL; - GHashTable *setting_hash = NULL; + GVariant *setting_dict = NULL; - /* Iterate through the settings hashes */ - g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, - (gpointer *) &setting_name, - (gpointer *) &setting_hash)) { + /* Iterate through the settings dicts */ + g_variant_iter_init (&iter, dict); + while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting_dict)) { const char *key_name = NULL; NMSetting *setting; - GValue *val; + GVariant *val; setting = nm_connection_get_setting_by_name (connection, setting_name); if (setting) { /* Now through each secret in the setting and mark it as not required */ - g_hash_table_iter_init (&setting_iter, setting_hash); - while (g_hash_table_iter_next (&setting_iter, (gpointer *) &key_name, (gpointer *) &val)) { + g_variant_iter_init (&setting_iter, setting_dict); + while (g_variant_iter_next (&setting_iter, "{&sv}", &key_name, &val)) { /* For each secret, set the flag that it's not required; VPN * secrets need slightly different treatment here since the - * "secrets" property is actually a hash table of secrets. + * "secrets" property is actually a dictionary of secrets. */ if ( strcmp (setting_name, NM_SETTING_VPN_SETTING_NAME) == 0 - && strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0) { - GHashTableIter vpn_secret_iter; - const char *secret_name; + && strcmp (key_name, NM_SETTING_VPN_SECRETS) == 0 + && g_variant_is_of_type (val, G_VARIANT_TYPE ("a{ss}"))) { + GVariantIter vpn_secret_iter; + const char *secret_name, *secret; - g_hash_table_iter_init (&vpn_secret_iter, g_value_get_boxed (val)); - while (g_hash_table_iter_next (&vpn_secret_iter, (gpointer *) &secret_name, NULL)) + g_variant_iter_init (&vpn_secret_iter, val); + while (g_variant_iter_next (&vpn_secret_iter, "{&s&s}", &secret_name, &secret)) nm_setting_set_secret_flags (setting, secret_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); } else nm_setting_set_secret_flags (setting, key_name, NM_SETTING_SECRET_FLAG_NOT_REQUIRED, NULL); + g_variant_unref (val); } } } @@ -946,7 +947,7 @@ get_agent_request_secrets (ConnectionRequest *req, gboolean include_system_secre static void get_agent_modify_auth_cb (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { Request *parent = user_data; @@ -1079,15 +1080,15 @@ get_start (gpointer user_data) { Request *parent = user_data; ConnectionRequest *req = user_data; - GHashTable *setting_secrets = NULL; + GVariant *setting_secrets = NULL; parent->idle_id = 0; /* Check if there are any existing secrets */ if (req->existing_secrets) - setting_secrets = g_hash_table_lookup (req->existing_secrets, req->setting_name); + setting_secrets = g_variant_lookup_value (req->existing_secrets, req->setting_name, NM_VARIANT_TYPE_SETTING); - if (setting_secrets && g_hash_table_size (setting_secrets)) { + if (setting_secrets && g_variant_n_children (setting_secrets)) { NMConnection *tmp; GError *error = NULL; gboolean new_secrets = (req->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW); @@ -1132,12 +1133,15 @@ get_start (gpointer user_data) request_next_agent (parent); } + if (setting_secrets) + g_variant_unref (setting_secrets); + return FALSE; } static void get_complete_cb (Request *parent, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1178,7 +1182,7 @@ guint32 nm_agent_manager_get_secrets (NMAgentManager *self, NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char **hints, @@ -1248,7 +1252,7 @@ nm_agent_manager_cancel_secrets (NMAgentManager *self, static void save_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { @@ -1295,7 +1299,7 @@ save_next_cb (Request *parent) static void save_complete_cb (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1342,7 +1346,7 @@ nm_agent_manager_save_secrets (NMAgentManager *self, static void delete_done_cb (NMSecretAgent *agent, gconstpointer call_id, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data) { @@ -1382,7 +1386,7 @@ delete_next_cb (Request *parent) static void delete_complete_cb (Request *req, - GHashTable *secrets, + GVariant *secrets, const char *agent_dbus_owner, const char *agent_username, GError *error, @@ -1486,7 +1490,7 @@ name_owner_changed_cb (NMDBusManager *dbus_mgr, static void agent_permissions_changed_done (NMAuthChain *chain, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMAgentManager *self = NM_AGENT_MANAGER (user_data); @@ -1587,6 +1591,14 @@ nm_agent_manager_init (NMAgentManager *self) g_direct_equal, NULL, (GDestroyNotify) request_free); + + priv->dbus_agent_manager = nmdbus_agent_manager_skeleton_new (); + g_signal_connect (priv->dbus_agent_manager, "handle-register-with-capabilities", + G_CALLBACK (impl_agent_manager_register_with_capabilities), self); + g_signal_connect (priv->dbus_agent_manager, "handle-register", + G_CALLBACK (impl_agent_manager_register), self); + g_signal_connect (priv->dbus_agent_manager, "handle-unregister", + G_CALLBACK (impl_agent_manager_unregister), self); } static void @@ -1605,6 +1617,12 @@ dispose (GObject *object) g_hash_table_destroy (priv->requests); priv->dbus_mgr = NULL; + + g_signal_handlers_disconnect_matched (priv->dbus_agent_manager, + G_SIGNAL_MATCH_DATA, + 0, 0, NULL, NULL, object); + g_clear_object (&priv->dbus_agent_manager); + } G_OBJECT_CLASS (nm_agent_manager_parent_class)->dispose (object); @@ -1631,10 +1649,7 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class) G_TYPE_NONE, 1, G_TYPE_OBJECT); - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (agent_manager_class), - &dbus_glib_nm_agent_manager_object_info); - - dbus_g_error_domain_register (NM_AGENT_MANAGER_ERROR, - NM_DBUS_INTERFACE_AGENT_MANAGER, - NM_TYPE_AGENT_MANAGER_ERROR); + _nm_dbus_register_error_domain (NM_AGENT_MANAGER_ERROR, + NM_DBUS_INTERFACE_AGENT_MANAGER, + NM_TYPE_AGENT_MANAGER_ERROR); } diff --git a/src/settings/nm-agent-manager.h b/src/settings/nm-agent-manager.h index 1aac2d2ae0..beb9244fdd 100644 --- a/src/settings/nm-agent-manager.h +++ b/src/settings/nm-agent-manager.h @@ -68,7 +68,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager, gboolean agent_has_modify, const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data, gpointer other_data2, @@ -77,7 +77,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager, guint32 nm_agent_manager_get_secrets (NMAgentManager *manager, NMConnection *connection, NMAuthSubject *subject, - GHashTable *existing_secrets, + GVariant *existing_secrets, const char *setting_name, NMSecretAgentGetSecretsFlags flags, const char **hints, diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index a1c6954ee2..9e9822c8c3 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -24,13 +24,10 @@ #include <pwd.h> #include <glib.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> #include "nm-dbus-interface.h" #include "nm-secret-agent.h" #include "nm-dbus-manager.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-logging.h" #include "nm-auth-subject.h" @@ -53,7 +50,7 @@ typedef struct { GSList *permissions; - DBusGProxy *proxy; + GDBusProxy *proxy; guint proxy_destroy_id; GHashTable *requests; @@ -63,7 +60,7 @@ typedef struct { typedef struct { NMSecretAgent *agent; - DBusGProxyCall *call; + GCancellable *cancellable; char *path; char *setting_name; NMSecretAgentCallback callback; @@ -85,6 +82,7 @@ request_new (NMSecretAgent *agent, r->setting_name = g_strdup (setting_name); r->callback = callback; r->callback_data = callback_data; + r->cancellable = g_cancellable_new (); return r; } @@ -93,6 +91,7 @@ request_free (Request *r) { g_free (r->path); g_free (r->setting_name); + g_object_unref (r->cancellable); g_slice_free (Request, r); } @@ -253,25 +252,26 @@ nm_secret_agent_has_permission (NMSecretAgent *agent, const char *permission) /*************************************************************/ static void -get_callback (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +get_callback (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { Request *r = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); GError *error = NULL; - GHashTable *secrets = NULL; - - g_return_if_fail (call == r->call); - - dbus_g_proxy_end_call (proxy, call, &error, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets, - G_TYPE_INVALID); - r->callback (r->agent, r->call, secrets, error, r->callback_data); - if (secrets) - g_hash_table_unref (secrets); - g_clear_error (&error); - g_hash_table_remove (priv->requests, call); + GVariant *ret, *secrets = NULL; + + if (!g_cancellable_is_cancelled (r->cancellable)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret && g_variant_is_of_type (ret, G_VARIANT_TYPE ("(a{sa{sv}})"))) + g_variant_get (ret, "(@a{sa{sv}})", &secrets); + r->callback (r->agent, r, secrets, error, r->callback_data); + if (secrets) + g_variant_unref (secrets); + g_clear_error (&error); + } + + g_hash_table_remove (priv->requests, r); } gconstpointer @@ -285,7 +285,6 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, { NMSecretAgentPrivate *priv; GVariant *dict; - GHashTable *hash; Request *r; g_return_val_if_fail (self != NULL, NULL); @@ -296,88 +295,87 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, g_return_val_if_fail (priv->proxy != NULL, NULL); dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL); - hash = nm_utils_connection_dict_to_hash (dict); - g_variant_unref (dict); /* Mask off the private ONLY_SYSTEM flag if present */ flags &= ~NM_SECRET_AGENT_GET_SECRETS_FLAG_ONLY_SYSTEM; r = request_new (self, nm_connection_get_path (connection), setting_name, callback, callback_data); - r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, - "GetSecrets", - get_callback, - r, - NULL, - 120000, /* 120 seconds */ - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - DBUS_TYPE_G_OBJECT_PATH, nm_connection_get_path (connection), - G_TYPE_STRING, setting_name, - G_TYPE_STRV, hints, - G_TYPE_UINT, flags, - G_TYPE_INVALID); - g_hash_table_insert (priv->requests, r->call, r); - - g_hash_table_destroy (hash); - return r->call; + g_dbus_proxy_call (priv->proxy, + "GetSecrets", + g_variant_new ("(@a{sa{sv}}os^asu)", + dict, + nm_connection_get_path (connection), + setting_name, + hints, + flags), + G_DBUS_CALL_FLAGS_NONE, 120000, /* 120 seconds */ + r->cancellable, + get_callback, r); + g_hash_table_insert (priv->requests, r, r); + + return r; } static void -cancel_done (DBusGProxy *proxy, DBusGProxyCall *call_id, void *user_data) +cancel_done (GObject *proxy, GAsyncResult *result, gpointer user_data) { + char *description = user_data; + GVariant *ret; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (!ret) { nm_log_dbg (LOGD_AGENTS, "(%s): agent failed to cancel secrets: (%d) %s", - (const char *) user_data, - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + description, error->code, error->message); g_clear_error (&error); - } + } else + g_variant_unref (ret); + + g_free (description); } void nm_secret_agent_cancel_secrets (NMSecretAgent *self, gconstpointer call) { NMSecretAgentPrivate *priv; - Request *r; + Request *r = (gpointer) call; g_return_if_fail (self != NULL); priv = NM_SECRET_AGENT_GET_PRIVATE (self); g_return_if_fail (priv->proxy != NULL); - - r = g_hash_table_lookup (priv->requests, call); g_return_if_fail (r != NULL); - dbus_g_proxy_cancel_call (priv->proxy, (gpointer) call); - - dbus_g_proxy_begin_call (priv->proxy, - "CancelGetSecrets", - cancel_done, - g_strdup (nm_secret_agent_get_description (self)), - g_free, - DBUS_TYPE_G_OBJECT_PATH, r->path, - G_TYPE_STRING, r->setting_name, - G_TYPE_INVALID); - g_hash_table_remove (priv->requests, call); + g_cancellable_cancel (r->cancellable); + + g_dbus_proxy_call (priv->proxy, + "CancelGetSecrets", + g_variant_new ("(os)", r->path, r->setting_name), + G_DBUS_CALL_FLAGS_NONE, 0, + NULL, + cancel_done, g_strdup (nm_secret_agent_get_description (self))); } /*************************************************************/ static void -agent_save_delete_cb (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +agent_save_delete_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) { Request *r = user_data; NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (r->agent); + GVariant *ret; GError *error = NULL; - g_return_if_fail (call == r->call); + if (!g_cancellable_is_cancelled (r->cancellable)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) + g_variant_unref (ret); + r->callback (r->agent, r, NULL, error, r->callback_data); + g_clear_error (&error); + } - dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); - r->callback (r->agent, r->call, NULL, error, r->callback_data); - g_clear_error (&error); - g_hash_table_remove (priv->requests, call); + g_hash_table_remove (priv->requests, r); } static gpointer @@ -390,28 +388,21 @@ agent_new_save_delete (NMSecretAgent *self, { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (self); GVariant *dict; - GHashTable *hash; Request *r; const char *cpath = nm_connection_get_path (connection); dict = nm_connection_to_dbus (connection, flags); - hash = nm_utils_connection_dict_to_hash (dict); - g_variant_unref (dict); r = request_new (self, cpath, NULL, callback, callback_data); - r->call = dbus_g_proxy_begin_call_with_timeout (priv->proxy, - method, - agent_save_delete_cb, - r, - NULL, - 10000, /* 10 seconds */ - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - DBUS_TYPE_G_OBJECT_PATH, cpath, - G_TYPE_INVALID); - g_hash_table_insert (priv->requests, r->call, r); - - g_hash_table_destroy (hash); - return r->call; + g_dbus_proxy_call (priv->proxy, + method, + g_variant_new ("(@a{sa{sv}}o)", dict, cpath), + G_DBUS_CALL_FLAGS_NONE, 10000, /* 10 seconds */ + NULL, + agent_save_delete_cb, r); + g_hash_table_insert (priv->requests, r, r); + + return r; } gconstpointer @@ -450,6 +441,7 @@ nm_secret_agent_delete_secrets (NMSecretAgent *self, callback_data); } +#ifdef FIXME static void proxy_cleanup (NMSecretAgent *self) { @@ -461,11 +453,12 @@ proxy_cleanup (NMSecretAgent *self) g_clear_object (&priv->proxy); } } +#endif /*************************************************************/ NMSecretAgent * -nm_secret_agent_new (DBusGMethodInvocation *context, +nm_secret_agent_new (GDBusMethodInvocation *context, NMAuthSubject *subject, const char *identifier, NMSecretAgentCapabilities capabilities) @@ -502,9 +495,10 @@ nm_secret_agent_new (DBusGMethodInvocation *context, NM_DBUS_PATH_SECRET_AGENT, NM_DBUS_INTERFACE_SECRET_AGENT); g_assert (priv->proxy); +#ifdef FIXME priv->proxy_destroy_id = g_signal_connect_swapped (priv->proxy, "destroy", G_CALLBACK (proxy_cleanup), self); - +#endif g_free (username); return self; } @@ -523,7 +517,11 @@ dispose (GObject *object) { NMSecretAgentPrivate *priv = NM_SECRET_AGENT_GET_PRIVATE (object); +#ifdef FIXME proxy_cleanup (NM_SECRET_AGENT (object)); +#else + g_clear_object (&priv->proxy); +#endif g_clear_object (&priv->subject); G_OBJECT_CLASS (nm_secret_agent_parent_class)->dispose (object); diff --git a/src/settings/nm-secret-agent.h b/src/settings/nm-secret-agent.h index f3f4ff89c5..0b985d9722 100644 --- a/src/settings/nm-secret-agent.h +++ b/src/settings/nm-secret-agent.h @@ -21,8 +21,7 @@ #ifndef __NETWORKMANAGER_SECRET_AGENT_H__ #define __NETWORKMANAGER_SECRET_AGENT_H__ -#include <glib.h> -#include <glib-object.h> +#include <gio/gio.h> #include <nm-connection.h> #include "nm-types.h" @@ -44,7 +43,7 @@ typedef struct { GType nm_secret_agent_get_type (void); -NMSecretAgent *nm_secret_agent_new (DBusGMethodInvocation *context, +NMSecretAgent *nm_secret_agent_new (GDBusMethodInvocation *invocation, NMAuthSubject *subject, const char *identifier, NMSecretAgentCapabilities capabilities); @@ -76,7 +75,7 @@ gboolean nm_secret_agent_has_permission (NMSecretAgent *agent, typedef void (*NMSecretAgentCallback) (NMSecretAgent *agent, gconstpointer call, - GHashTable *new_secrets, /* NULL for save & delete */ + GVariant *new_secrets, /* NULL for save & delete */ GError *error, gpointer user_data); diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index db382adb82..d0ad47aed3 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -24,7 +24,6 @@ #include <string.h> #include <nm-dbus-interface.h> -#include <dbus/dbus-glib-lowlevel.h> #include <nm-setting-connection.h> #include <nm-setting-vpn.h> #include <nm-setting-wireless.h> @@ -34,7 +33,6 @@ #include "nm-session-monitor.h" #include "nm-dbus-manager.h" #include "nm-settings-error.h" -#include "nm-dbus-glib-types.h" #include "nm-logging.h" #include "nm-manager-auth.h" #include "nm-auth-subject.h" @@ -42,34 +40,11 @@ #include "NetworkManagerUtils.h" #include "nm-properties-changed-signal.h" +#include "nmdbus-settings-connection.h" + #define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps" #define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids" -static void impl_settings_connection_get_settings (NMSettingsConnection *connection, - DBusGMethodInvocation *context); - -static void impl_settings_connection_update (NMSettingsConnection *connection, - GHashTable *new_settings, - DBusGMethodInvocation *context); - -static void impl_settings_connection_update_unsaved (NMSettingsConnection *connection, - GHashTable *new_settings, - DBusGMethodInvocation *context); - -static void impl_settings_connection_save (NMSettingsConnection *connection, - DBusGMethodInvocation *context); - -static void impl_settings_connection_delete (NMSettingsConnection *connection, - DBusGMethodInvocation *context); - -static void impl_settings_connection_get_secrets (NMSettingsConnection *connection, - const gchar *setting_name, - DBusGMethodInvocation *context); - -#include "nm-settings-connection-glue.h" - -static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface); - G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_settings_connection_connection_interface_init) ) @@ -93,6 +68,8 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { + NMDBusSettingsConnection *dbus_settings_connection; + NMAgentManager *agent_mgr; NMSessionMonitor *session_monitor; guint session_changed_id; @@ -141,80 +118,160 @@ typedef struct { /**************************************************************/ /* Return TRUE to continue, FALSE to stop */ -typedef gboolean (*ForEachSecretFunc) (GHashTableIter *iter, - NMSettingSecretFlags flags, +typedef gboolean (*ForEachSecretFunc) (NMSettingSecretFlags flags, gpointer user_data); +/* These functions, given a dict of dicts representing new secrets of an + * NMConnection, walk through each toplevel dict (which represents a NMSetting), + * and for each setting, walks through that setting's properties. For each + * property that's a secret, they will check that secret's flags in the backing + * NMConnection object, and call a supplied callback. + * + * The one complexity is that the VPN setting's 'secrets' property is *also* a + * dict (since the key/value pairs are arbitrary and known only to the VPN + * plugin itself). That means we have three levels of dicts that we potentially + * have to traverse here. When we hit the VPN setting's 'secrets' property, we + * special-case that and iterate over each item in that 'secrets' dict, calling + * the supplied callback each time. + */ + static void -for_each_secret (NMConnection *connection, - GHashTable *secrets, - ForEachSecretFunc callback, - gpointer callback_data) +find_secret (NMConnection *connection, + GVariant *secrets, + ForEachSecretFunc callback, + gpointer callback_data) { - GHashTableIter iter; + GVariantIter secrets_iter; const char *setting_name; - GHashTable *setting_hash; - - /* This function, given a hash of hashes representing new secrets of - * an NMConnection, walks through each toplevel hash (which represents a - * NMSetting), and for each setting, walks through that setting hash's - * properties. For each property that's a secret, it will check that - * secret's flags in the backing NMConnection object, and call a supplied - * callback. - * - * The one complexity is that the VPN setting's 'secrets' property is - * *also* a hash table (since the key/value pairs are arbitrary and known - * only to the VPN plugin itself). That means we have three levels of - * GHashTables that we potentially have to traverse here. When we hit the - * VPN setting's 'secrets' property, we special-case that and iterate over - * each item in that 'secrets' hash table, calling the supplied callback - * each time. - */ + GVariantIter *setting_iter; - /* Walk through the list of setting hashes */ - g_hash_table_iter_init (&iter, secrets); - while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting_hash)) { + g_variant_iter_init (&secrets_iter, secrets); + while (g_variant_iter_next (&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) { NMSetting *setting; - GHashTableIter secret_iter; const char *secret_name; - GValue *val; + GVariant *val; /* Get the actual NMSetting from the connection so we can get secret flags * from the connection data, since flags aren't secrets. What we're * iterating here is just the secrets, not a whole connection. */ setting = nm_connection_get_setting_by_name (connection, setting_name); - if (setting == NULL) + if (setting == NULL) { + g_variant_iter_free (setting_iter); continue; + } - /* Walk through the list of keys in each setting hash */ - g_hash_table_iter_init (&secret_iter, setting_hash); - while (g_hash_table_iter_next (&secret_iter, (gpointer) &secret_name, (gpointer) &val)) { + /* Walk through the list of keys in each setting dict */ + while (g_variant_iter_next (setting_iter, "{sv}", &secret_name, &val)) { NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; /* VPN secrets need slightly different treatment here since the * "secrets" property is actually a hash table of secrets. */ - if (NM_IS_SETTING_VPN (setting) && (g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS) == 0)) { - GHashTableIter vpn_secrets_iter; + if ( NM_IS_SETTING_VPN (setting) + && !g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS)) { + GVariantIter vpn_secrets_iter; /* Iterate through each secret from the VPN hash in the overall secrets hash */ - g_hash_table_iter_init (&vpn_secrets_iter, g_value_get_boxed (val)); - while (g_hash_table_iter_next (&vpn_secrets_iter, (gpointer) &secret_name, NULL)) { + g_variant_iter_init (&vpn_secrets_iter, val); + while (g_variant_iter_next (&vpn_secrets_iter, "{&s&s}", &secret_name, NULL)) { secret_flags = NM_SETTING_SECRET_FLAG_NONE; nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL); - if (callback (&vpn_secrets_iter, secret_flags, callback_data) == FALSE) + if (!callback (secret_flags, callback_data)) { + g_variant_iter_free (setting_iter); + g_variant_unref (val); return; + } } } else { nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL); - if (callback (&secret_iter, secret_flags, callback_data) == FALSE) + if (!callback (secret_flags, callback_data)) { + g_variant_iter_free (setting_iter); + g_variant_unref (val); return; + } } + + g_variant_unref (val); } + + g_variant_iter_free (setting_iter); } } +static GVariant * +filter_vpn_secrets (NMSetting *setting, + GVariant *vpn_secrets, + ForEachSecretFunc callback, + gpointer callback_data) +{ + GVariantIter iter; + GVariantBuilder builder; + const char *secret_name, *secret; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}")); + g_variant_iter_init (&iter, vpn_secrets); + while (g_variant_iter_next (&iter, "{&s&s}", &secret_name, &secret)) { + NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; + + nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL); + if (callback (secret_flags, callback_data)) + g_variant_builder_add (&builder, "{ss}", secret_name, secret); + } + + return g_variant_builder_end (&builder); +} + +static GVariant * +filter_secrets (NMConnection *connection, + GVariant *secrets, + ForEachSecretFunc callback, + gpointer callback_data) +{ + GVariantBuilder secrets_builder, setting_builder; + GVariantIter secrets_iter, *setting_iter; + const char *setting_name; + + /* Walk through the list of setting hashes */ + g_variant_iter_init (&secrets_iter, secrets); + g_variant_builder_init (&secrets_builder, NM_VARIANT_TYPE_CONNECTION); + while (g_variant_iter_next (&secrets_iter, "{&sa{sv}}", &setting_name, &setting_iter)) { + NMSetting *setting; + const char *secret_name; + GVariant *val; + + setting = nm_connection_get_setting_by_name (connection, setting_name); + if (setting == NULL) { + g_variant_iter_free (setting_iter); + continue; + } + + g_variant_builder_init (&setting_builder, NM_VARIANT_TYPE_SETTING); + while (g_variant_iter_next (setting_iter, "{sv}", &secret_name, &val)) { + NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; + + if ( NM_IS_SETTING_VPN (setting) + && !g_strcmp0 (secret_name, NM_SETTING_VPN_SECRETS)) { + GVariant *vpn_secrets; + + vpn_secrets = filter_vpn_secrets (setting, val, callback, callback_data); + g_variant_builder_add (&setting_builder, "{sv}", secret_name, vpn_secrets); + } else { + nm_setting_get_secret_flags (setting, secret_name, &secret_flags, NULL); + if (callback (secret_flags, callback_data)) + g_variant_builder_add (&setting_builder, "{sv}", &secret_name, val); + } + g_variant_unref (val); + } + + g_variant_iter_free (setting_iter); + g_variant_builder_add (&secrets_builder, "sa{sv}", setting_name, &setting_builder); + } + + g_variant_unref (secrets); + return g_variant_builder_end (&secrets_builder); +} + /**************************************************************/ static void @@ -439,6 +496,7 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self, GError **error) { NMSettingsConnectionPrivate *priv; + GVariant *dict = NULL; gboolean success = FALSE; g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE); @@ -662,28 +720,21 @@ supports_secrets (NMSettingsConnection *connection, const char *setting_name) } static gboolean -clear_nonagent_secrets (GHashTableIter *iter, - NMSettingSecretFlags flags, +clear_nonagent_secrets (NMSettingSecretFlags flags, gpointer user_data) { - if (flags != NM_SETTING_SECRET_FLAG_AGENT_OWNED) - g_hash_table_iter_remove (iter); - return TRUE; + return !!(flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED); } static gboolean -clear_unsaved_secrets (GHashTableIter *iter, - NMSettingSecretFlags flags, +clear_unsaved_secrets (NMSettingSecretFlags flags, gpointer user_data) { - if (flags & (NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) - g_hash_table_iter_remove (iter); - return TRUE; + return !(flags & (NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED)); } static gboolean -has_system_owned_secrets (GHashTableIter *iter, - NMSettingSecretFlags flags, +has_system_owned_secrets (NMSettingSecretFlags flags, gpointer user_data) { gboolean *has_system_owned = user_data; @@ -714,7 +765,7 @@ agent_secrets_done_cb (NMAgentManager *manager, gboolean agent_has_modify, const char *setting_name, NMSecretAgentGetSecretsFlags flags, - GHashTable *secrets, + GVariant *secrets, GError *error, gpointer user_data, gpointer other_data2, @@ -763,7 +814,7 @@ agent_secrets_done_cb (NMAgentManager *manager, * save those system-owned secrets. If not, discard them and use the * existing secrets, or fail the connection. */ - for_each_secret (NM_CONNECTION (self), secrets, has_system_owned_secrets, &agent_had_system); + find_secret (NM_CONNECTION (self), secrets, has_system_owned_secrets, &agent_had_system); if (agent_had_system) { if (flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE) { /* No user interaction was allowed when requesting secrets; the @@ -775,7 +826,7 @@ agent_secrets_done_cb (NMAgentManager *manager, call_id, agent_dbus_owner); - for_each_secret (NM_CONNECTION (self), secrets, clear_nonagent_secrets, NULL); + secrets = filter_secrets (NM_CONNECTION (self), secrets, clear_nonagent_secrets, NULL); } else if (agent_has_modify == FALSE) { /* Agent didn't successfully authenticate; clear system-owned secrets * from the secrets the agent returned. @@ -785,7 +836,7 @@ agent_secrets_done_cb (NMAgentManager *manager, setting_name, call_id); - for_each_secret (NM_CONNECTION (self), secrets, clear_nonagent_secrets, NULL); + secrets = filter_secrets (NM_CONNECTION (self), secrets, clear_nonagent_secrets, NULL); } } } else { @@ -804,7 +855,7 @@ agent_secrets_done_cb (NMAgentManager *manager, * came back. Unsaved secrets by definition require user interaction. */ if (flags == NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE) - for_each_secret (NM_CONNECTION (self), secrets, clear_unsaved_secrets, NULL); + secrets = filter_secrets (NM_CONNECTION (self), secrets, clear_unsaved_secrets, NULL); /* Update the connection with our existing secrets from backing storage */ nm_connection_clear_secrets (NM_CONNECTION (self)); @@ -895,7 +946,6 @@ nm_settings_connection_get_secrets (NMSettingsConnection *self, { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); GVariant *existing_secrets; - GHashTable *existing_secrets_hash; guint32 call_id = 0; char *joined_hints = NULL; @@ -967,7 +1017,7 @@ nm_settings_connection_cancel_secrets (NMSettingsConnection *self, /**** User authorization **************************************/ typedef void (*AuthCallback) (NMSettingsConnection *connection, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data); @@ -975,7 +1025,7 @@ typedef void (*AuthCallback) (NMSettingsConnection *connection, static void pk_auth_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettingsConnection *self = NM_SETTINGS_CONNECTION (user_data); @@ -1024,7 +1074,7 @@ pk_auth_cb (NMAuthChain *chain, * Returns: the #NMAuthSubject on success, or %NULL on failure and sets @error */ static NMAuthSubject * -_new_auth_subject (DBusGMethodInvocation *context, GError **error) +_new_auth_subject (GDBusMethodInvocation *context, GError **error) { NMAuthSubject *subject; @@ -1041,7 +1091,7 @@ _new_auth_subject (DBusGMethodInvocation *context, GError **error) static void auth_start (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, const char *check_permission, AuthCallback callback, @@ -1130,16 +1180,15 @@ check_writable (NMConnection *connection, GError **error) static void get_settings_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) { if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else { GVariant *settings; - GHashTable *settings_hash; NMConnection *dupl_con; NMSettingConnection *s_con; NMSettingWireless *s_wifi; @@ -1177,17 +1226,15 @@ get_settings_auth_cb (NMSettingsConnection *self, */ settings = nm_connection_to_dbus (NM_CONNECTION (dupl_con), NM_CONNECTION_SERIALIZE_NO_SECRETS); g_assert (settings); - settings_hash = nm_utils_connection_dict_to_hash (settings); - dbus_g_method_return (context, settings_hash); - g_hash_table_destroy (settings_hash); - g_variant_unref (settings); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(@a{sa{sv}})", settings)); g_object_unref (dupl_con); } } -static void +static gboolean impl_settings_connection_get_settings (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject; GError *error = NULL; @@ -1197,13 +1244,15 @@ impl_settings_connection_get_settings (NMSettingsConnection *self, auth_start (self, context, subject, NULL, get_settings_auth_cb, NULL); g_object_unref (subject); } else { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } + + return TRUE; } typedef struct { - DBusGMethodInvocation *context; + GDBusMethodInvocation *context; NMAgentManager *agent_mgr; NMAuthSubject *subject; NMConnection *new_settings; @@ -1216,9 +1265,9 @@ update_complete (NMSettingsConnection *self, GError *error) { if (error) - dbus_g_method_return_error (info->context, error); + g_dbus_method_invocation_return_gerror (info->context, error); else - dbus_g_method_return (info->context); + g_dbus_method_invocation_return_value (info->context, NULL); g_clear_object (&info->subject); g_clear_object (&info->agent_mgr); @@ -1253,7 +1302,7 @@ con_update_cb (NMSettingsConnection *self, static void update_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) @@ -1316,8 +1365,8 @@ get_update_modify_permission (NMConnection *old, NMConnection *new) static void impl_settings_connection_update_helper (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context, + GVariant *new_settings, + GDBusMethodInvocation *context, gboolean save_to_disk) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); @@ -1384,37 +1433,43 @@ error: g_clear_object (&tmp); g_clear_object (&subject); - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); g_clear_error (&error); } -static void +static gboolean impl_settings_connection_update (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context) + GVariant *new_settings, + GDBusMethodInvocation *context) { g_assert (new_settings); impl_settings_connection_update_helper (self, new_settings, context, TRUE); + + return TRUE; } -static void +static gboolean impl_settings_connection_update_unsaved (NMSettingsConnection *self, - GHashTable *new_settings, - DBusGMethodInvocation *context) + GVariant *new_settings, + GDBusMethodInvocation *context) { g_assert (new_settings); impl_settings_connection_update_helper (self, new_settings, context, FALSE); + + return TRUE; } -static void +static gboolean impl_settings_connection_save (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { /* Do nothing if the connection is already synced with disk */ if (NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->unsaved == TRUE) impl_settings_connection_update_helper (self, NULL, context, TRUE); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); + + return TRUE; } static void @@ -1422,23 +1477,23 @@ con_delete_cb (NMSettingsConnection *connection, 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 delete_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer data) { if (error) { - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); return; } @@ -1462,27 +1517,26 @@ get_modify_permission_basic (NMSettingsConnection *connection) return NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM; } -static void +static gboolean impl_settings_connection_delete (NMSettingsConnection *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject; GError *error = NULL; if (!check_writable (NM_CONNECTION (self), &error)) { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; + g_dbus_method_invocation_take_error (context, error); + return TRUE; } subject = _new_auth_subject (context, &error); if (subject) { auth_start (self, context, subject, get_modify_permission_basic (self), delete_auth_cb, NULL); g_object_unref (subject); - } else { - dbus_g_method_return_error (context, error); - g_error_free (error); - } + } else + g_dbus_method_invocation_take_error (context, error); + + return TRUE; } /**************************************************************/ @@ -1496,14 +1550,13 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self, gpointer user_data) { NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - DBusGMethodInvocation *context = user_data; + GDBusMethodInvocation *context = user_data; GVariant *dict; - GHashTable *hash; priv->reqs = g_slist_remove (priv->reqs, GUINT_TO_POINTER (call_id)); if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_return_gerror (context, error); else { /* Return secrets from agent and backing storage to the D-Bus caller; * nm_settings_connection_get_secrets() will have updated itself with @@ -1511,20 +1564,14 @@ dbus_get_agent_secrets_cb (NMSettingsConnection *self, * by the time we get here. */ dict = nm_connection_to_dbus (NM_CONNECTION (self), NM_CONNECTION_SERIALIZE_ONLY_SECRETS); - if (dict) - hash = nm_utils_connection_dict_to_hash (dict); - else - hash = g_hash_table_new (NULL, NULL); - dbus_g_method_return (context, hash); - g_hash_table_destroy (hash); - if (dict) - g_variant_unref (dict); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(@a{sa{sv}})", dict)); } } static void dbus_secrets_auth_cb (NMSettingsConnection *self, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMAuthSubject *subject, GError *error, gpointer user_data) @@ -1550,17 +1597,17 @@ dbus_secrets_auth_cb (NMSettingsConnection *self, } if (error || local) { - dbus_g_method_return_error (context, error ? error : local); + g_dbus_method_invocation_return_gerror (context, error ? error : local); g_clear_error (&local); } g_free (setting_name); } -static void +static gboolean impl_settings_connection_get_secrets (NMSettingsConnection *self, const gchar *setting_name, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMAuthSubject *subject; GError *error = NULL; @@ -1574,10 +1621,10 @@ impl_settings_connection_get_secrets (NMSettingsConnection *self, dbus_secrets_auth_cb, g_strdup (setting_name)); g_object_unref (subject); - } else { - dbus_g_method_return_error (context, error); - g_error_free (error); - } + } else + g_dbus_method_invocation_take_error (context, error); + + return TRUE; } /**************************************************************/ @@ -1990,6 +2037,35 @@ nm_settings_connection_set_nm_generated (NMSettingsConnection *connection) /**************************************************************/ +void +nm_settings_connection_export (NMSettingsConnection *self, + const char *path) +{ + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + nm_connection_set_path (NM_CONNECTION (self), path); + nm_dbus_manager_register_object (nm_dbus_manager_get (), path, + priv->dbus_settings_connection); +} + +/**************************************************************/ + +static void +updated (NMSettingsConnection *self) +{ + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + nmdbus_settings_connection_emit_updated (priv->dbus_settings_connection); +} + +static void +removed (NMSettingsConnection *self) +{ + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + nmdbus_settings_connection_emit_removed (priv->dbus_settings_connection); +} + static void nm_settings_connection_init (NMSettingsConnection *self) { @@ -2015,6 +2091,34 @@ nm_settings_connection_init (NMSettingsConnection *self) } static void +constructed (GObject *object) +{ + NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object); + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + priv->dbus_settings_connection = nmdbus_settings_connection_skeleton_new (); + + g_object_bind_property (self, NM_SETTINGS_CONNECTION_UNSAVED, + priv->dbus_settings_connection, "unsaved", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-delete", + G_CALLBACK (impl_settings_connection_delete), self); + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-get-secrets", + G_CALLBACK (impl_settings_connection_get_secrets), self); + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-get-settings", + G_CALLBACK (impl_settings_connection_get_settings), self); + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-save", + G_CALLBACK (impl_settings_connection_save), self); + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-update", + G_CALLBACK (impl_settings_connection_update), self); + g_signal_connect_swapped (priv->dbus_settings_connection, "handle-update-unsaved", + G_CALLBACK (impl_settings_connection_update_unsaved), self); + + G_OBJECT_CLASS (nm_settings_connection_parent_class)->constructed (object); +} + +static void dispose (GObject *object) { NMSettingsConnection *self = NM_SETTINGS_CONNECTION (object); @@ -2094,10 +2198,14 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) g_type_class_add_private (class, sizeof (NMSettingsConnectionPrivate)); /* Virtual methods */ + object_class->constructed = constructed; object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; + class->updated = updated; + class->removed = removed; + class->commit_changes = commit_changes; class->delete = do_delete; class->supports_secrets = supports_secrets; @@ -2124,7 +2232,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) g_signal_new (NM_SETTINGS_CONNECTION_UPDATED, G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, - 0, + G_STRUCT_OFFSET (NMSettingsConnectionClass, updated), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -2142,14 +2250,10 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class) g_signal_new (NM_SETTINGS_CONNECTION_REMOVED, G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, - 0, + G_STRUCT_OFFSET (NMSettingsConnectionClass, removed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (class), - &dbus_glib_nm_settings_connection_object_info); } static void diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index 3ee62465fd..459ee7d2fb 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -66,6 +66,10 @@ struct _NMSettingsConnection { struct _NMSettingsConnectionClass { GObjectClass parent; + /* signals */ + void (*updated) (NMSettingsConnection *connection); + void (*removed) (NMSettingsConnection *connection); + /* virtual methods */ void (*commit_changes) (NMSettingsConnection *connection, NMSettingsConnectionCommitFunc callback, @@ -81,6 +85,9 @@ struct _NMSettingsConnectionClass { GType nm_settings_connection_get_type (void); +void nm_settings_connection_export (NMSettingsConnection *connection, + const char *path); + void nm_settings_connection_commit_changes (NMSettingsConnection *connection, NMSettingsConnectionCommitFunc callback, gpointer user_data); diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index a4339ed492..42a5675392 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -29,8 +29,6 @@ #include <string.h> #include <gmodule.h> #include <pwd.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib-lowlevel.h> #include <nm-dbus-interface.h> #include <nm-connection.h> @@ -55,7 +53,6 @@ #include "nm-core-internal.h" #include "nm-device-ethernet.h" -#include "nm-dbus-glib-types.h" #include "nm-settings.h" #include "nm-settings-connection.h" #include "nm-settings-error.h" @@ -71,6 +68,9 @@ #include "nm-config.h" #include "NetworkManagerUtils.h" +#include "nm-object.h" +#include "nmdbus-settings.h" + /* LINKER CRACKROCK */ #define EXPORT(sym) void * __export_##sym = &sym; @@ -89,35 +89,6 @@ static void claim_connection (NMSettings *self, NMSettingsConnection *connection, gboolean do_export); -static gboolean impl_settings_list_connections (NMSettings *self, - GPtrArray **connections, - GError **error); - -static void impl_settings_get_connection_by_uuid (NMSettings *self, - const char *uuid, - DBusGMethodInvocation *context); - -static void impl_settings_add_connection (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context); - -static void impl_settings_add_connection_unsaved (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context); - -static void impl_settings_load_connections (NMSettings *self, - char **filenames, - DBusGMethodInvocation *context); - -static void impl_settings_reload_connections (NMSettings *self, - DBusGMethodInvocation *context); - -static void impl_settings_save_hostname (NMSettings *self, - const char *hostname, - DBusGMethodInvocation *context); - -#include "nm-settings-glue.h" - static void unmanaged_specs_changed (NMSystemConfigInterface *config, gpointer user_data); static void unrecognized_specs_changed (NMSystemConfigInterface *config, gpointer user_data); @@ -128,8 +99,6 @@ G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, G_TYPE_OBJECT, 0, typedef struct { - NMDBusManager *dbus_mgr; - NMAgentManager *agent_mgr; NMConfig *config; @@ -155,7 +124,6 @@ enum { CONNECTION_VISIBILITY_CHANGED, AGENT_REGISTERED, - NEW_CONNECTION, /* exported, not used internally */ LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -235,17 +203,23 @@ nm_settings_for_each_connection (NMSettings *self, static gboolean impl_settings_list_connections (NMSettings *self, - GPtrArray **connections, - GError **error) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); + GPtrArray *connections; GHashTableIter iter; gpointer key; - *connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); + connections = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); g_hash_table_iter_init (&iter, priv->connections); while (g_hash_table_iter_next (&iter, &key, NULL)) - g_ptr_array_add (*connections, g_strdup ((const char *) key)); + g_ptr_array_add (connections, g_strdup ((const char *) key)); + g_ptr_array_add (connections, NULL); + + g_dbus_method_invocation_return_value (context, + g_variant_new ("(as)", (char **) connections->pdata)); + g_ptr_array_free (connections, TRUE); + return TRUE; } @@ -270,10 +244,10 @@ nm_settings_get_connection_by_uuid (NMSettings *self, const char *uuid) return NULL; } -static void +static gboolean impl_settings_get_connection_by_uuid (NMSettings *self, const char *uuid, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMSettingsConnection *connection = NULL; NMAuthSubject *subject = NULL; @@ -308,14 +282,16 @@ impl_settings_get_connection_by_uuid (NMSettings *self, } g_clear_object (&subject); - dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection))); - return; + g_dbus_method_invocation_return_value (context, + g_variant_new ("(s)", nm_connection_get_path (NM_CONNECTION (connection)))); + return TRUE; error: g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); g_clear_object (&subject); + + return TRUE; } static int @@ -380,51 +356,6 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path) return (NMSettingsConnection *) g_hash_table_lookup (priv->connections, path); } -static char* -uscore_to_wincaps (const char *uscore) -{ - const char *p; - GString *str; - gboolean last_was_uscore; - - last_was_uscore = TRUE; - - str = g_string_new (NULL); - p = uscore; - while (p && *p) { - if (*p == '-' || *p == '_') - last_was_uscore = TRUE; - else { - if (last_was_uscore) { - g_string_append_c (str, g_ascii_toupper (*p)); - last_was_uscore = FALSE; - } else - g_string_append_c (str, *p); - } - ++p; - } - - return g_string_free (str, FALSE); -} - -static void -notify (GObject *object, GParamSpec *pspec) -{ - GValue *value; - GHashTable *hash; - - value = g_slice_new0 (GValue); - hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL); - - g_value_init (value, pspec->value_type); - g_object_get_property (object, pspec->name, value); - g_hash_table_insert (hash, uscore_to_wincaps (pspec->name), value); - g_signal_emit (object, signals[PROPERTIES_CHANGED], 0, hash); - g_hash_table_destroy (hash); - g_value_unset (value); - g_slice_free (GValue, value); -} - const GSList * nm_settings_get_unmanaged_specs (NMSettings *self) { @@ -750,6 +681,9 @@ connection_removed (NMSettingsConnection *connection, gpointer user_data) (gpointer) nm_connection_get_path (NM_CONNECTION (connection))); /* Notify D-Bus */ + nm_object_emit_dbus_signal (NM_OBJECT (self), + "ConnectionRemoved", + nm_connection_get_path (NM_CONNECTION (connection))); g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection); /* Re-emit for listeners like NMPolicy */ @@ -866,9 +800,7 @@ claim_connection (NMSettings *self, /* Export the connection over D-Bus */ g_warn_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL); path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++); - nm_connection_set_path (NM_CONNECTION (connection), path); - nm_dbus_manager_register_object (priv->dbus_mgr, path, G_OBJECT (connection)); - g_free (path); + nm_settings_connection_export (connection, path); g_hash_table_insert (priv->connections, (gpointer) nm_connection_get_path (NM_CONNECTION (connection)), @@ -883,9 +815,10 @@ claim_connection (NMSettings *self, g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_ADDED, connection); g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTIONS); - /* Exported D-Bus signal */ - g_signal_emit (self, signals[NEW_CONNECTION], 0, connection); + nm_object_emit_dbus_signal (NM_OBJECT (self), "NewConnection", path); } + + g_free (path); } /** @@ -1008,7 +941,7 @@ send_agent_owned_secrets (NMSettings *self, static void pk_add_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettings *self = NM_SETTINGS (user_data); @@ -1096,11 +1029,11 @@ is_adhoc_wpa (NMConnection *connection) void nm_settings_add_connection_dbus (NMSettings *self, - NMConnection *connection, - gboolean save_to_disk, - DBusGMethodInvocation *context, - NMSettingsAddCallback callback, - gpointer user_data) + NMConnection *connection, + gboolean save_to_disk, + GDBusMethodInvocation *context, + NMSettingsAddCallback callback, + gpointer user_data) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMSettingConnection *s_con; @@ -1205,20 +1138,20 @@ static void impl_settings_add_connection_add_cb (NMSettings *self, NMSettingsConnection *connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer 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, nm_connection_get_path (NM_CONNECTION (connection))); + g_dbus_method_invocation_return_value (context, g_variant_new ("(s)", nm_connection_get_path (NM_CONNECTION (connection)))); } static void impl_settings_add_connection_helper (NMSettings *self, - GHashTable *settings, + GVariant *settings, gboolean save_to_disk, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMConnection *connection; GVariant *dict; @@ -1237,30 +1170,31 @@ impl_settings_add_connection_helper (NMSettings *self, g_object_unref (connection); } else { g_assert (error); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); } } -static void +static gboolean impl_settings_add_connection (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context) + GVariant *settings, + GDBusMethodInvocation *context) { impl_settings_add_connection_helper (self, settings, TRUE, context); + return TRUE; } -static void +static gboolean impl_settings_add_connection_unsaved (NMSettings *self, - GHashTable *settings, - DBusGMethodInvocation *context) + GVariant *settings, + GDBusMethodInvocation *context) { impl_settings_add_connection_helper (self, settings, FALSE, context); + return TRUE; } static gboolean ensure_root (NMDBusManager *dbus_mgr, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { gulong caller_uid; GError *error = NULL; @@ -1269,34 +1203,32 @@ ensure_root (NMDBusManager *dbus_mgr, error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, "Unable to determine request UID."); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return FALSE; } if (caller_uid != 0) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_PERMISSION_DENIED, "Permission denied"); - dbus_g_method_return_error (context, error); - g_error_free (error); + g_dbus_method_invocation_take_error (context, error); return FALSE; } return TRUE; } -static void +static gboolean impl_settings_load_connections (NMSettings *self, char **filenames, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GPtrArray *failures; GSList *iter; int i; - if (!ensure_root (priv->dbus_mgr, context)) - return; + if (!ensure_root (nm_dbus_manager_get (), context)) + return TRUE; failures = g_ptr_array_new (); @@ -1316,19 +1248,24 @@ impl_settings_load_connections (NMSettings *self, } g_ptr_array_add (failures, NULL); - dbus_g_method_return (context, failures->len == 1, failures->pdata); + g_dbus_method_invocation_return_value (context, + g_variant_new ("(bas)", + failures->len == 1, + (char **) failures->pdata)); g_ptr_array_unref (failures); + + return TRUE; } -static void +static gboolean impl_settings_reload_connections (NMSettings *self, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GSList *iter; - if (!ensure_root (priv->dbus_mgr, context)) - return; + if (!ensure_root (nm_dbus_manager_get (), context)) + return TRUE; for (iter = priv->plugins; iter; iter = g_slist_next (iter)) { NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data); @@ -1336,13 +1273,14 @@ impl_settings_reload_connections (NMSettings *self, nm_system_config_interface_reload_connections (plugin); } - dbus_g_method_return (context, TRUE); + g_dbus_method_invocation_return_value (context, g_variant_new ("(b)", TRUE)); + return TRUE; } static void pk_hostname_cb (NMAuthChain *chain, GError *chain_error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data) { NMSettings *self = NM_SETTINGS (user_data); @@ -1388,11 +1326,10 @@ pk_hostname_cb (NMAuthChain *chain, } if (error) - dbus_g_method_return_error (context, error); + g_dbus_method_invocation_take_error (context, error); else - dbus_g_method_return (context); + g_dbus_method_invocation_return_value (context, NULL); - g_clear_error (&error); nm_auth_chain_unref (chain); } @@ -1423,10 +1360,10 @@ validate_hostname (const char *hostname) return (p - hostname <= HOST_NAME_MAX); } -static void +static gboolean impl_settings_save_hostname (NMSettings *self, const char *hostname, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMAuthChain *chain; @@ -1462,8 +1399,9 @@ impl_settings_save_hostname (NMSettings *self, done: if (error) - dbus_g_method_return_error (context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (context, error); + + return TRUE; } static gboolean @@ -1761,7 +1699,6 @@ nm_settings_new (GError **error) priv = NM_SETTINGS_GET_PRIVATE (self); priv->config = nm_config_get (); - priv->dbus_mgr = nm_dbus_manager_get (); /* Load the plugins; fail if a plugin is not found. */ if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) { @@ -1771,7 +1708,7 @@ nm_settings_new (GError **error) load_connections (self); - nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_SETTINGS, self); + nm_object_export (NM_OBJECT (self), NM_DBUS_PATH_SETTINGS); return self; } @@ -1810,8 +1747,6 @@ dispose (GObject *object) g_slist_free_full (priv->auths, (GDestroyNotify) nm_auth_chain_unref); priv->auths = NULL; - priv->dbus_mgr = NULL; - g_object_unref (priv->agent_mgr); G_OBJECT_CLASS (nm_settings_parent_class)->dispose (object); @@ -1841,17 +1776,18 @@ get_property (GObject *object, guint prop_id, NMSettings *self = NM_SETTINGS (object); NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); const GSList *specs, *iter; - GSList *copy = NULL; GHashTableIter citer; GPtrArray *array; const char *path; switch (prop_id) { case PROP_UNMANAGED_SPECS: + array = g_ptr_array_new (); specs = nm_settings_get_unmanaged_specs (self); for (iter = specs; iter; iter = g_slist_next (iter)) - copy = g_slist_append (copy, g_strdup (iter->data)); - g_value_take_boxed (value, copy); + g_ptr_array_add (array, g_strdup (iter->data)); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; case PROP_HOSTNAME: g_value_take_string (value, nm_settings_get_hostname (self)); @@ -1864,11 +1800,12 @@ get_property (GObject *object, guint prop_id, g_value_set_boolean (value, !!get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS)); break; case PROP_CONNECTIONS: - array = g_ptr_array_sized_new (g_hash_table_size (priv->connections)); + array = g_ptr_array_sized_new (g_hash_table_size (priv->connections) + 1); g_hash_table_iter_init (&citer, priv->connections); while (g_hash_table_iter_next (&citer, (gpointer) &path, NULL)) g_ptr_array_add (array, g_strdup (path)); - g_value_take_boxed (value, array); + g_ptr_array_add (array, NULL); + g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1884,7 +1821,6 @@ nm_settings_class_init (NMSettingsClass *class) g_type_class_add_private (class, sizeof (NMSettingsPrivate)); /* virtual methods */ - object_class->notify = notify; object_class->get_property = get_property; object_class->dispose = dispose; object_class->finalize = finalize; @@ -1894,7 +1830,7 @@ nm_settings_class_init (NMSettingsClass *class) g_object_class_install_property (object_class, PROP_UNMANAGED_SPECS, g_param_spec_boxed (NM_SETTINGS_UNMANAGED_SPECS, "", "", - DBUS_TYPE_G_LIST_OF_STRING, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -1915,19 +1851,11 @@ nm_settings_class_init (NMSettingsClass *class) g_object_class_install_property (object_class, PROP_CONNECTIONS, g_param_spec_boxed (NM_SETTINGS_CONNECTIONS, "", "", - DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); /* signals */ - signals[PROPERTIES_CHANGED] = - g_signal_new ("properties-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMSettingsClass, properties_changed), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT); signals[CONNECTION_ADDED] = g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_ADDED, G_OBJECT_CLASS_TYPE (object_class), @@ -1983,38 +1911,40 @@ nm_settings_class_init (NMSettingsClass *class) G_TYPE_NONE, 1, G_TYPE_OBJECT); - signals[NEW_CONNECTION] = - g_signal_new ("new-connection", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, G_TYPE_OBJECT); + nm_object_class_add_interface (NM_OBJECT_CLASS (class), + NMDBUS_TYPE_SETTINGS, + "AddConnection", impl_settings_add_connection, + "AddConnectionUnsaved", impl_settings_add_connection_unsaved, + "GetConnectionByUuid", impl_settings_get_connection_by_uuid, + "ListConnections", impl_settings_list_connections, + "LoadConnections", impl_settings_load_connections, + "ReloadConnections", impl_settings_reload_connections, + "SaveHostname", impl_settings_save_hostname, + NULL); - dbus_g_error_domain_register (NM_SETTINGS_ERROR, - NM_DBUS_INTERFACE_SETTINGS, - NM_TYPE_SETTINGS_ERROR); + _nm_dbus_register_error_domain (NM_SETTINGS_ERROR, + NM_DBUS_INTERFACE_SETTINGS, + NM_TYPE_SETTINGS_ERROR); /* And register all the settings errors with D-Bus */ - dbus_g_error_domain_register (NM_CONNECTION_ERROR, NULL, NM_TYPE_CONNECTION_ERROR); - dbus_g_error_domain_register (NM_SETTING_802_1X_ERROR, NULL, NM_TYPE_SETTING_802_1X_ERROR); - dbus_g_error_domain_register (NM_SETTING_BLUETOOTH_ERROR, NULL, NM_TYPE_SETTING_BLUETOOTH_ERROR); - dbus_g_error_domain_register (NM_SETTING_CDMA_ERROR, NULL, NM_TYPE_SETTING_CDMA_ERROR); - dbus_g_error_domain_register (NM_SETTING_CONNECTION_ERROR, NULL, NM_TYPE_SETTING_CONNECTION_ERROR); - dbus_g_error_domain_register (NM_SETTING_GSM_ERROR, NULL, NM_TYPE_SETTING_GSM_ERROR); - dbus_g_error_domain_register (NM_SETTING_IP4_CONFIG_ERROR, NULL, NM_TYPE_SETTING_IP4_CONFIG_ERROR); - dbus_g_error_domain_register (NM_SETTING_IP6_CONFIG_ERROR, NULL, NM_TYPE_SETTING_IP6_CONFIG_ERROR); - dbus_g_error_domain_register (NM_SETTING_OLPC_MESH_ERROR, NULL, NM_TYPE_SETTING_OLPC_MESH_ERROR); - dbus_g_error_domain_register (NM_SETTING_PPP_ERROR, NULL, NM_TYPE_SETTING_PPP_ERROR); - dbus_g_error_domain_register (NM_SETTING_PPPOE_ERROR, NULL, NM_TYPE_SETTING_PPPOE_ERROR); - dbus_g_error_domain_register (NM_SETTING_SERIAL_ERROR, NULL, NM_TYPE_SETTING_SERIAL_ERROR); - dbus_g_error_domain_register (NM_SETTING_ADSL_ERROR, NULL, NM_TYPE_SETTING_ADSL_ERROR); - dbus_g_error_domain_register (NM_SETTING_VPN_ERROR, NULL, NM_TYPE_SETTING_VPN_ERROR); - dbus_g_error_domain_register (NM_SETTING_WIRED_ERROR, NULL, NM_TYPE_SETTING_WIRED_ERROR); - dbus_g_error_domain_register (NM_SETTING_WIRELESS_SECURITY_ERROR, NULL, NM_TYPE_SETTING_WIRELESS_SECURITY_ERROR); - dbus_g_error_domain_register (NM_SETTING_WIRELESS_ERROR, NULL, NM_TYPE_SETTING_WIRELESS_ERROR); - dbus_g_error_domain_register (NM_SETTING_ERROR, NULL, NM_TYPE_SETTING_ERROR); - - dbus_g_object_type_install_info (NM_TYPE_SETTINGS, &dbus_glib_nm_settings_object_info); - + // FIXME + _nm_dbus_register_error_domain (NM_CONNECTION_ERROR, NULL, NM_TYPE_CONNECTION_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_802_1X_ERROR, NULL, NM_TYPE_SETTING_802_1X_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_BLUETOOTH_ERROR, NULL, NM_TYPE_SETTING_BLUETOOTH_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_CDMA_ERROR, NULL, NM_TYPE_SETTING_CDMA_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_CONNECTION_ERROR, NULL, NM_TYPE_SETTING_CONNECTION_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_GSM_ERROR, NULL, NM_TYPE_SETTING_GSM_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_IP4_CONFIG_ERROR, NULL, NM_TYPE_SETTING_IP4_CONFIG_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_IP6_CONFIG_ERROR, NULL, NM_TYPE_SETTING_IP6_CONFIG_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_OLPC_MESH_ERROR, NULL, NM_TYPE_SETTING_OLPC_MESH_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_PPP_ERROR, NULL, NM_TYPE_SETTING_PPP_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_PPPOE_ERROR, NULL, NM_TYPE_SETTING_PPPOE_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_SERIAL_ERROR, NULL, NM_TYPE_SETTING_SERIAL_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_ADSL_ERROR, NULL, NM_TYPE_SETTING_ADSL_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_VPN_ERROR, NULL, NM_TYPE_SETTING_VPN_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_WIRED_ERROR, NULL, NM_TYPE_SETTING_WIRED_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_WIRELESS_SECURITY_ERROR, NULL, NM_TYPE_SETTING_WIRELESS_SECURITY_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_WIRELESS_ERROR, NULL, NM_TYPE_SETTING_WIRELESS_ERROR); + _nm_dbus_register_error_domain (NM_SETTING_ERROR, NULL, NM_TYPE_SETTING_ERROR); } diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h index 520c4ec34c..9e444fb539 100644 --- a/src/settings/nm-settings.h +++ b/src/settings/nm-settings.h @@ -29,6 +29,7 @@ #include <nm-connection.h> #include "nm-types.h" +#include "nm-object.h" #define NM_TYPE_SETTINGS (nm_settings_get_type ()) #define NM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS, NMSettings)) @@ -50,11 +51,11 @@ #define NM_SETTINGS_SIGNAL_AGENT_REGISTERED "agent-registered" struct _NMSettings { - GObject parent_instance; + NMObject parent_instance; }; typedef struct { - GObjectClass parent_class; + NMObjectClass parent_class; /* Signals */ void (*properties_changed) (NMSettings *self, GHashTable *properties); @@ -85,13 +86,13 @@ void nm_settings_for_each_connection (NMSettings *settings, typedef void (*NMSettingsAddCallback) (NMSettings *settings, NMSettingsConnection *connection, GError *error, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, gpointer user_data); void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, gboolean save_to_disk, - DBusGMethodInvocation *context, + GDBusMethodInvocation *context, NMSettingsAddCallback callback, gpointer user_data); diff --git a/src/settings/plugins/example/Makefile.am b/src/settings/plugins/example/Makefile.am index 8fc4aa92b1..4b2048e0de 100644 --- a/src/settings/plugins/example/Makefile.am +++ b/src/settings/plugins/example/Makefile.am @@ -8,7 +8,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" # 'noinst' here because this is an example plugin we don't want to install diff --git a/src/settings/plugins/example/nm-example-connection.c b/src/settings/plugins/example/nm-example-connection.c index c634388e9f..f70e309baf 100644 --- a/src/settings/plugins/example/nm-example-connection.c +++ b/src/settings/plugins/example/nm-example-connection.c @@ -25,7 +25,6 @@ #include <nm-utils.h> #include "nm-system-config-interface.h" -#include "nm-dbus-glib-types.h" #include "nm-example-connection.h" #include "common.h" diff --git a/src/settings/plugins/ifcfg-rh/Makefile.am b/src/settings/plugins/ifcfg-rh/Makefile.am index 10064812d0..644fb88d14 100644 --- a/src/settings/plugins/ifcfg-rh/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/Makefile.am @@ -34,7 +34,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(NSS_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-ifcfg-rh"\" \ -DSYSCONFDIR=\"$(sysconfdir)\" \ diff --git a/src/settings/plugins/ifcfg-rh/plugin.c b/src/settings/plugins/ifcfg-rh/plugin.c index f4a25effce..9bae58b50c 100644 --- a/src/settings/plugins/ifcfg-rh/plugin.c +++ b/src/settings/plugins/ifcfg-rh/plugin.c @@ -33,10 +33,6 @@ #include <glib/gi18n.h> #include <gio/gio.h> -#include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> - #if HAVE_SELINUX #include <selinux/selinux.h> #endif @@ -44,13 +40,13 @@ #include <nm-setting-connection.h> #include "common.h" -#include "nm-dbus-glib-types.h" #include "plugin.h" #include "nm-system-config-interface.h" #include "nm-settings-error.h" #include "nm-config.h" #include "nm-logging.h" #include "NetworkManagerUtils.h" +#include "nm-dbus-utils.h" #include "nm-ifcfg-connection.h" #include "nm-inotify-helper.h" @@ -68,7 +64,6 @@ static gboolean impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin, const char **out_path, GError **error); -#include "nm-ifcfg-rh-glue.h" static void connection_new_or_changed (SCPluginIfcfg *plugin, const char *path, @@ -97,7 +92,7 @@ typedef struct { GFileMonitor *ifcfg_monitor; guint ifcfg_monitor_id; - DBusGConnection *bus; + GDBusConnection *bus; } SCPluginIfcfgPrivate; @@ -857,29 +852,18 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) priv->hostname = plugin_get_hostname (plugin); - priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + priv->bus = g_bus_bus_get_sync (G_BUS_SYSTEM, NULL, &error); if (!priv->bus) { nm_log_warn (LOGD_SETTINGS, "Couldn't connect to D-Bus: %s", error->message); g_clear_error (&error); } else { - DBusConnection *tmp; - DBusGProxy *proxy; int result; - tmp = dbus_g_connection_get_connection (priv->bus); - dbus_connection_set_exit_on_disconnect (tmp, FALSE); - - proxy = dbus_g_proxy_new_for_name (priv->bus, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus"); - - if (!dbus_g_proxy_call (proxy, "RequestName", &error, - G_TYPE_STRING, DBUS_SERVICE_NAME, - G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { + result = nm_dbus_request_name (priv->bus, + DBUS_SERVICE_NAME, + DBUS_NAME_FLAG_DO_NOT_QUEUE, + NULL, &error); + if (!result) { nm_log_warn (LOGD_SETTINGS, "Couldn't acquire D-Bus service: %s", error->message); g_clear_error (&error); } else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { @@ -888,12 +872,8 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) success = TRUE; } - if (!success) { - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } - } + if (!success) + g_clear_object (&priv->bus); } static void @@ -903,10 +883,7 @@ dispose (GObject *object) SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); NMInotifyHelper *ih; - if (priv->bus) { - dbus_g_connection_unref (priv->bus); - priv->bus = NULL; - } + g_clear_object (&priv->bus); if (priv->ih_event_id) { ih = nm_inotify_helper_get (); diff --git a/src/settings/plugins/keyfile/Makefile.am b/src/settings/plugins/keyfile/Makefile.am index bf89b06796..248f221639 100644 --- a/src/settings/plugins/keyfile/Makefile.am +++ b/src/settings/plugins/keyfile/Makefile.am @@ -12,7 +12,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DNMCONFDIR=\"$(nmconfdir)\" noinst_LTLIBRARIES = \ diff --git a/src/settings/plugins/keyfile/nm-keyfile-connection.c b/src/settings/plugins/keyfile/nm-keyfile-connection.c index c078b6de09..cd474c239e 100644 --- a/src/settings/plugins/keyfile/nm-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nm-keyfile-connection.c @@ -26,7 +26,6 @@ #include <nm-utils.h> #include "nm-system-config-interface.h" -#include "nm-dbus-glib-types.h" #include "nm-keyfile-connection.h" #include "reader.h" #include "writer.h" diff --git a/src/settings/plugins/keyfile/reader.c b/src/settings/plugins/keyfile/reader.c index 15410bbf6d..a0c966db9d 100644 --- a/src/settings/plugins/keyfile/reader.c +++ b/src/settings/plugins/keyfile/reader.c @@ -37,7 +37,6 @@ #include <arpa/inet.h> #include <string.h> -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-system-config-interface.h" #include "nm-logging.h" diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index 1cd6ab91cd..2612a1d3cc 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -12,7 +12,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/settings \ -I$(srcdir)/../ \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \ -DG_LOG_DOMAIN=\""NetworkManager-keyfile"\" \ -DNETWORKMANAGER_COMPILATION \ @@ -32,7 +31,6 @@ test_keyfile_SOURCES = \ test_keyfile_LDADD = \ $(top_builddir)/src/libNetworkManager.la \ - $(DBUS_LIBS) \ $(CODE_COVERAGE_LDFLAGS) TESTS = test-keyfile diff --git a/src/settings/plugins/keyfile/writer.c b/src/settings/plugins/keyfile/writer.c index ae8f0a912b..d4765a7431 100644 --- a/src/settings/plugins/keyfile/writer.c +++ b/src/settings/plugins/keyfile/writer.c @@ -26,7 +26,6 @@ #include <stdio.h> #include <errno.h> -#include <dbus/dbus-glib.h> #include <nm-setting.h> #include <nm-setting-connection.h> #include <nm-setting-ip4-config.h> @@ -41,7 +40,6 @@ #include <string.h> #include <arpa/inet.h> -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-logging.h" #include "writer.h" @@ -456,19 +454,22 @@ password_raw_writer (GKeyFile *file, const GValue *value) { const char *setting_name = nm_setting_get_name (setting); - GByteArray *array; + GBytes *bytes; + const guint8 *data; + gsize length; int i, *tmp_array; - g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)); + g_return_if_fail (G_VALUE_HOLDS (value, G_TYPE_BYTES)); - array = (GByteArray *) g_value_get_boxed (value); - if (!array || !array->len) + bytes = g_value_get_boxed (value); + if (!bytes || !g_bytes_get_size (bytes)) return; - tmp_array = g_new (gint, array->len); - for (i = 0; i < array->len; i++) - tmp_array[i] = (int) array->data[i]; - nm_keyfile_plugin_kf_set_integer_list (file, setting_name, key, tmp_array, array->len); + data = g_bytes_get_data (bytes, &length); + tmp_array = g_new (gint, length); + for (i = 0; i < length; i++) + tmp_array[i] = (int) data[i]; + nm_keyfile_plugin_kf_set_integer_list (file, setting_name, key, tmp_array, length); g_free (tmp_array); } diff --git a/src/supplicant-manager/nm-call-store.c b/src/supplicant-manager/nm-call-store.c deleted file mode 100644 index 4b427549d5..0000000000 --- a/src/supplicant-manager/nm-call-store.c +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright (C) 2007 Novell, Inc. - * Copyright (C) 2010 Red Hat, Inc. - */ - -#include "nm-call-store.h" -#include "nm-logging.h" - -NMCallStore * -nm_call_store_new (void) -{ - /* Maps { DBusGProxy :: GHashTable { DBusGProxyCall :: NULL } } */ - return g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_hash_table_destroy); -} - -static void -proxy_destroyed_cb (gpointer data, GObject *proxy) -{ - g_hash_table_remove ((NMCallStore *) data, proxy); -} - -void -nm_call_store_add (NMCallStore *store, - DBusGProxy *proxy, - DBusGProxyCall *call) -{ - GHashTable *calls; - - g_return_if_fail (store != NULL); - g_return_if_fail (proxy != NULL); - g_return_if_fail (call != NULL); - - calls = g_hash_table_lookup (store, proxy); - if (!calls) { - calls = g_hash_table_new (NULL, NULL); - g_hash_table_insert (store, proxy, calls); - g_object_weak_ref (G_OBJECT (proxy), proxy_destroyed_cb, store); - } - - g_hash_table_add (calls, call); -} - -void -nm_call_store_remove (NMCallStore *store, - DBusGProxy *proxy, - DBusGProxyCall *call) -{ - GHashTable *calls; - - g_return_if_fail (store != NULL); - g_return_if_fail (proxy != NULL); - g_return_if_fail (call != NULL); - - calls = g_hash_table_lookup (store, proxy); - if (!calls) - return; - - g_hash_table_remove (calls, call); - if (g_hash_table_size (calls) == 0) { - g_hash_table_remove (store, proxy); - g_object_weak_unref (G_OBJECT (proxy), proxy_destroyed_cb, store); - } -} - -void -nm_call_store_clear (NMCallStore *store) -{ - DBusGProxy *proxy; - GHashTable *calls; - GHashTableIter proxies_iter; - - g_return_if_fail (store != NULL); - - g_hash_table_iter_init (&proxies_iter, store); - while (g_hash_table_iter_next (&proxies_iter, (gpointer) &proxy, (gpointer) &calls)) { - GHashTableIter calls_iter; - DBusGProxyCall *call; - - g_hash_table_iter_init (&calls_iter, calls); - while (g_hash_table_iter_next (&calls_iter, (gpointer) &call, NULL)) { - dbus_g_proxy_cancel_call (proxy, call); - g_hash_table_iter_remove (&calls_iter); - } - g_object_weak_unref (G_OBJECT (proxy), proxy_destroyed_cb, store); - g_hash_table_iter_remove (&proxies_iter); - } - g_assert_cmpint (g_hash_table_size (store), ==, 0); -} - -void -nm_call_store_destroy (NMCallStore *store) -{ - g_return_if_fail (store); - g_hash_table_destroy (store); -} diff --git a/src/supplicant-manager/nm-call-store.h b/src/supplicant-manager/nm-call-store.h deleted file mode 100644 index bcee54cfbb..0000000000 --- a/src/supplicant-manager/nm-call-store.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2007 Novell, Inc. - */ - -#ifndef __NETWORKMANAGER_CALLBACK_STORE_H__ -#define __NETWORKMANAGER_CALLBACK_STORE_H__ - -#include <glib-object.h> -#include <dbus/dbus-glib.h> - -typedef GHashTable NMCallStore; - -NMCallStore *nm_call_store_new (void); -void nm_call_store_add (NMCallStore *store, - DBusGProxy *proxy, - DBusGProxyCall *call); - -void nm_call_store_remove (NMCallStore *store, - DBusGProxy *proxy, - DBusGProxyCall *call); - -void nm_call_store_clear (NMCallStore *store); -void nm_call_store_destroy (NMCallStore *store); - -#endif /* __NETWORKMANAGER_CALLBACK_STORE_H__ */ diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c index f4ee4c3a2c..952f7f2bbb 100644 --- a/src/supplicant-manager/nm-supplicant-config.c +++ b/src/supplicant-manager/nm-supplicant-config.c @@ -26,7 +26,6 @@ #include <string.h> #include <stdlib.h> #include <glib.h> -#include <dbus/dbus-glib.h> #include "nm-supplicant-config.h" #include "nm-supplicant-settings-verify.h" @@ -262,73 +261,72 @@ nm_supplicant_config_fast_required (NMSupplicantConfig *self) return NM_SUPPLICANT_CONFIG_GET_PRIVATE (self)->fast_required; } -static void -get_hash_cb (gpointer key, gpointer value, gpointer user_data) +GVariant * +nm_supplicant_config_get_config (NMSupplicantConfig * self) { - ConfigOption *opt = (ConfigOption *) value; - GValue *variant; - GByteArray *array; + NMSupplicantConfigPrivate *priv; + GHashTableIter iter; + GVariantBuilder builder; + const char *key; + ConfigOption *opt; - variant = g_slice_new0 (GValue); + g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), NULL); + priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self); - switch (opt->type) { - case TYPE_INT: - g_value_init (variant, G_TYPE_INT); - g_value_set_int (variant, atoi (opt->value)); - break; - case TYPE_BYTES: - case TYPE_UTF8: - array = g_byte_array_sized_new (opt->len); - g_byte_array_append (array, (const guint8 *) opt->value, opt->len); - g_value_init (variant, DBUS_TYPE_G_UCHAR_ARRAY); - g_value_set_boxed (variant, array); - g_byte_array_free (array, TRUE); - break; - case TYPE_KEYWORD: - case TYPE_STRING: - g_value_init (variant, G_TYPE_STRING); - g_value_set_string (variant, opt->value); - break; - default: - g_slice_free (GValue, variant); - return; + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + g_hash_table_iter_init (&iter, priv->config); + while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &opt)) { + switch (opt->type) { + case TYPE_INT: + g_variant_builder_add (&builder, "{sv}", + key, + g_variant_new_int32 (atoi (opt->value))); + break; + case TYPE_BYTES: + case TYPE_UTF8: + g_variant_builder_add (&builder, "{sv}", + key, + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + opt->value, opt->len, 1)); + break; + case TYPE_KEYWORD: + case TYPE_STRING: + g_variant_builder_add (&builder, "{sv}", + key, + g_variant_new_string (opt->value)); + break; + default: + break; + } } - g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), variant); + return g_variant_builder_end (&builder); } -static void -destroy_hash_value (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - -GHashTable * -nm_supplicant_config_get_hash (NMSupplicantConfig * self) +GVariant * +nm_supplicant_config_get_blobs (NMSupplicantConfig * self) { NMSupplicantConfigPrivate *priv; - GHashTable *hash; + GHashTableIter iter; + GVariantBuilder builder; + const char *key; + GByteArray *blob; g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), NULL); - - hash = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - destroy_hash_value); - priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self); - g_hash_table_foreach (priv->config, get_hash_cb, hash); - return hash; -} -GHashTable * -nm_supplicant_config_get_blobs (NMSupplicantConfig * self) -{ - g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), NULL); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{say}")); + + g_hash_table_iter_init (&iter, priv->config); + while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &blob)) { + g_variant_builder_add (&builder, "{s@ay}", + key, + g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + blob->data, blob->len, 1)); + } - return NM_SUPPLICANT_CONFIG_GET_PRIVATE (self)->blobs; + return g_variant_builder_end (&builder); } #define TWO_GHZ_FREQS "2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462,2467,2472,2484" diff --git a/src/supplicant-manager/nm-supplicant-config.h b/src/supplicant-manager/nm-supplicant-config.h index 482e3545b6..1e51c90f99 100644 --- a/src/supplicant-manager/nm-supplicant-config.h +++ b/src/supplicant-manager/nm-supplicant-config.h @@ -59,9 +59,9 @@ void nm_supplicant_config_set_ap_scan (NMSupplicantConfig *self, gboolean nm_supplicant_config_fast_required (NMSupplicantConfig *self); -GHashTable *nm_supplicant_config_get_hash (NMSupplicantConfig *self); +GVariant *nm_supplicant_config_get_config (NMSupplicantConfig *self); -GHashTable *nm_supplicant_config_get_blobs (NMSupplicantConfig *self); +GVariant *nm_supplicant_config_get_blobs (NMSupplicantConfig *self); gboolean nm_supplicant_config_add_setting_wireless (NMSupplicantConfig *self, NMSettingWireless *setting, diff --git a/src/supplicant-manager/nm-supplicant-interface.c b/src/supplicant-manager/nm-supplicant-interface.c index 77924b3e7a..bb7351bf50 100644 --- a/src/supplicant-manager/nm-supplicant-interface.c +++ b/src/supplicant-manager/nm-supplicant-interface.c @@ -30,8 +30,6 @@ #include "nm-logging.h" #include "nm-supplicant-config.h" #include "nm-dbus-manager.h" -#include "nm-call-store.h" -#include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface" @@ -42,16 +40,14 @@ G_DEFINE_TYPE (NMSupplicantInterface, nm_supplicant_interface, G_TYPE_OBJECT) -static void wpas_iface_properties_changed (DBusGProxy *proxy, - GHashTable *props, - gpointer user_data); - -static void wpas_iface_scan_done (DBusGProxy *proxy, - gboolean success, - gpointer user_data); - static void wpas_iface_get_props (NMSupplicantInterface *self); +static void iface_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data); + #define NM_SUPPLICANT_INTERFACE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ NM_TYPE_SUPPLICANT_INTERFACE, \ NMSupplicantInterfacePrivate)) @@ -94,15 +90,15 @@ typedef struct { char * object_path; guint32 state; int disconnect_reason; - NMCallStore * assoc_pcalls; - NMCallStore * other_pcalls; + GCancellable * assoc_cancellable; + GCancellable * other_cancellable; gboolean scanning; - DBusGProxy * wpas_proxy; - DBusGProxy * introspect_proxy; - DBusGProxy * iface_proxy; - DBusGProxy * props_proxy; + GDBusProxy * wpas_proxy; + GDBusProxy * introspect_proxy; + GDBusProxy * iface_proxy; + GDBusProxy * props_proxy; char * net_path; guint32 blobs_left; GHashTable * bss_proxies; @@ -118,36 +114,47 @@ static void emit_error_helper (NMSupplicantInterface *self, GError *err) { - const char *name = NULL; + char *name = NULL; - if (err->domain == DBUS_GERROR && err->code == DBUS_GERROR_REMOTE_EXCEPTION) - name = dbus_g_error_get_name (err); + name = g_dbus_error_get_remote_error (err); + g_dbus_error_strip_remote_error (err); g_signal_emit (self, signals[CONNECTION_ERROR], 0, name, err->message); + g_free (name); } static void signal_new_bss (NMSupplicantInterface *self, const char *object_path, - GHashTable *props) + GVariant *props) { g_signal_emit (self, signals[NEW_BSS], 0, object_path, props); } static void -bssid_properties_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +bssid_properties_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; GError *error = NULL; - GHashTable *props = NULL; - - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (dbus_g_proxy_end_call (proxy, call_id, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { - signal_new_bss (self, dbus_g_proxy_get_path (proxy), props); - g_hash_table_destroy (props); + GVariant *ret; + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (ret) { + GVariant *props; + + g_variant_get (ret, "(@a{sv})", &props); + signal_new_bss (self, g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy)), props); + g_variant_unref (props); + g_variant_unref (ret); } else { if (!strstr (error->message, "The BSSID requested was invalid")) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't retrieve BSSID properties: %s.", @@ -158,76 +165,73 @@ bssid_properties_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_ } static void -bss_properties_changed (DBusGProxy *proxy, - const char *interface, - GHashTable *props, - const char **unused, - gpointer user_data) +bss_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) { NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - if (priv->scanning) - priv->last_scan = nm_utils_get_monotonic_timestamp_s (); + if ( !strcmp (signal_name, "PropertiesChanged") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)"))) { + const char *interface; - if (g_strcmp0 (interface, WPAS_DBUS_IFACE_BSS) == 0) - g_signal_emit (self, signals[BSS_UPDATED], 0, dbus_g_proxy_get_path (proxy), props); + if (priv->scanning) + priv->last_scan = nm_utils_get_monotonic_timestamp_s (); + + g_variant_get (parameters, "(&sa{sv}as)", &interface, NULL, NULL); + if (g_strcmp0 (interface, WPAS_DBUS_IFACE_BSS) == 0) + g_signal_emit (self, signals[BSS_UPDATED], 0, g_dbus_proxy_get_object_path (proxy)); + } } static void handle_new_bss (NMSupplicantInterface *self, const char *object_path, - GHashTable *props) + GVariant *props) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxy *bss_proxy; - DBusGProxyCall *call; + GDBusProxy *bss_proxy; g_return_if_fail (object_path != NULL); if (g_hash_table_lookup (priv->bss_proxies, object_path)) return; - bss_proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr), - WPAS_DBUS_SERVICE, - object_path, - DBUS_INTERFACE_PROPERTIES); + bss_proxy = g_dbus_proxy_new_sync (nm_dbus_manager_get_connection (nm_dbus_manager_get ()), + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + WPAS_DBUS_SERVICE, + object_path, + "org.freedesktop.DBus.Properties", + NULL, NULL); g_hash_table_insert (priv->bss_proxies, - (gpointer) dbus_g_proxy_get_path (bss_proxy), + (gpointer) g_dbus_proxy_get_object_path (bss_proxy), bss_proxy); - /* Standard D-Bus PropertiesChanged signal */ - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_STRV, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (bss_proxy, "PropertiesChanged", - G_TYPE_STRING, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_STRV, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (bss_proxy, "PropertiesChanged", - G_CALLBACK (bss_properties_changed), - self, NULL); + // FIXME: let GDBusProxy handle properties + g_signal_connect (bss_proxy, "g-signal", + G_CALLBACK (bss_proxy_signal), self); if (props) { signal_new_bss (self, object_path, props); } else { - call = dbus_g_proxy_begin_call (bss_proxy, "GetAll", - bssid_properties_cb, - self, - NULL, - G_TYPE_STRING, WPAS_DBUS_IFACE_BSS, - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, bss_proxy, call); + g_dbus_proxy_call (bss_proxy, + "GetAll", + g_variant_new ("(s)", WPAS_DBUS_IFACE_BSS), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + bssid_properties_cb, self); } } static void -wpas_iface_bss_added (DBusGProxy *proxy, +wpas_iface_bss_added (NMSupplicantInterface *self, const char *object_path, - GHashTable *props, - gpointer user_data) + GVariant *props) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (priv->scanning) @@ -237,11 +241,9 @@ wpas_iface_bss_added (DBusGProxy *proxy, } static void -wpas_iface_bss_removed (DBusGProxy *proxy, - const char *object_path, - gpointer user_data) +wpas_iface_bss_removed (NMSupplicantInterface *self, + const char *object_path) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); g_signal_emit (self, signals[BSS_REMOVED], 0, object_path); @@ -302,8 +304,13 @@ set_state (NMSupplicantInterface *self, guint32 new_state) wpas_iface_get_props (self); } else if (new_state == NM_SUPPLICANT_INTERFACE_STATE_DOWN) { /* Cancel all pending calls when going down */ - nm_call_store_clear (priv->other_pcalls); - nm_call_store_clear (priv->assoc_pcalls); + g_cancellable_cancel (priv->other_cancellable); + g_object_unref (priv->other_cancellable); + priv->other_cancellable = g_cancellable_new (); + + g_cancellable_cancel (priv->assoc_cancellable); + g_object_unref (priv->assoc_cancellable); + priv->assoc_cancellable = g_cancellable_new (); /* Disconnect supplicant manager state listeners since we're done */ if (priv->smgr_avail_id) { @@ -312,22 +319,9 @@ set_state (NMSupplicantInterface *self, guint32 new_state) } if (priv->iface_proxy) { - dbus_g_proxy_disconnect_signal (priv->iface_proxy, - "PropertiesChanged", - G_CALLBACK (wpas_iface_properties_changed), - self); - dbus_g_proxy_disconnect_signal (priv->iface_proxy, - "ScanDone", - G_CALLBACK (wpas_iface_scan_done), - self); - dbus_g_proxy_disconnect_signal (priv->iface_proxy, - "BSSAdded", - G_CALLBACK (wpas_iface_bss_added), - self); - dbus_g_proxy_disconnect_signal (priv->iface_proxy, - "BSSRemoved", - G_CALLBACK (wpas_iface_bss_removed), - self); + g_signal_handlers_disconnect_by_func (priv->iface_proxy, + G_CALLBACK (iface_proxy_signal), + self); } } @@ -396,11 +390,9 @@ nm_supplicant_interface_get_last_scan_time (NMSupplicantInterface *self) } static void -wpas_iface_scan_done (DBusGProxy *proxy, - gboolean success, - gpointer user_data) +wpas_iface_scan_done (NMSupplicantInterface *self, + gboolean success) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* Cache last scan completed time */ @@ -409,18 +401,17 @@ wpas_iface_scan_done (DBusGProxy *proxy, } static void -parse_capabilities (NMSupplicantInterface *self, GHashTable *props) +parse_capabilities (NMSupplicantInterface *self, GVariant *props) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - GValue *value; gboolean have_active = FALSE, have_ssid = FALSE; + char **vals; + gint32 max_scan_ssid; g_return_if_fail (props != NULL); - value = g_hash_table_lookup (props, "Scan"); - if (value && G_VALUE_HOLDS (value, G_TYPE_STRV)) { - const char **vals = g_value_get_boxed (value); - const char **iter = vals; + if (g_variant_lookup (props, "Scan", "^a&s", &vals)) { + char **iter = vals; while (iter && *iter && (!have_active || !have_ssid)) { if (g_strcmp0 (*iter, "active") == 0) @@ -429,17 +420,18 @@ parse_capabilities (NMSupplicantInterface *self, GHashTable *props) have_ssid = TRUE; iter++; } + + g_free (vals); } - value = g_hash_table_lookup (props, "MaxScanSSID"); - if (value && G_VALUE_HOLDS (value, G_TYPE_INT)) { + if (g_variant_lookup (props, "MaxScanSSID", "i", &max_scan_ssid)) { /* We need active scan and SSID probe capabilities to care about MaxScanSSIDs */ if (have_active && have_ssid) { /* wpa_supplicant's WPAS_MAX_SCAN_SSIDS value is 16, but for speed * and to ensure we don't disclose too many SSIDs from the hidden * list, we'll limit to 5. */ - priv->max_scan_ssids = CLAMP (g_value_get_int (value), 0, 5); + priv->max_scan_ssids = CLAMP (max_scan_ssid, 0, 5); nm_log_info (LOGD_SUPPLICANT, "(%s) supports %d scan SSIDs", priv->dev, priv->max_scan_ssids); } @@ -447,42 +439,42 @@ parse_capabilities (NMSupplicantInterface *self, GHashTable *props) } static void -wpas_iface_properties_changed (DBusGProxy *proxy, - GHashTable *props, - gpointer user_data) +wpas_iface_properties_changed (NMSupplicantInterface *self, + GVariant *props) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - GValue *value; + gboolean scanning; + const char *state; + char **paths; + GVariant *capabilities; + gint32 disconnect_reason; - value = g_hash_table_lookup (props, "Scanning"); - if (value && G_VALUE_HOLDS_BOOLEAN (value)) - set_scanning (self, g_value_get_boolean (value)); + if (g_variant_lookup (props, "Scanning", "b", &scanning)) + set_scanning (self, scanning); - value = g_hash_table_lookup (props, "State"); - if (value && G_VALUE_HOLDS_STRING (value)) { + if (g_variant_lookup (props, "State", "&s", &state)) { if (priv->state >= NM_SUPPLICANT_INTERFACE_STATE_READY) { /* Only transition to actual wpa_supplicant interface states (ie, * anything > READY) after the NMSupplicantInterface has had a * chance to initialize, which is signalled by entering the READY * state. */ - set_state_from_string (self, g_value_get_string (value)); + set_state_from_string (self, state); } } - value = g_hash_table_lookup (props, "BSSs"); - if (value && G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH)) { - GPtrArray *paths = g_value_get_boxed (value); + if (g_variant_lookup (props, "BSSs", "^a&o", &paths)) { int i; - for (i = 0; paths && (i < paths->len); i++) - handle_new_bss (self, g_ptr_array_index (paths, i), NULL); + for (i = 0; paths[i]; i++) + handle_new_bss (self, paths[i], NULL); + g_free (paths); } - value = g_hash_table_lookup (props, "Capabilities"); - if (value && G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_VARIANT)) - parse_capabilities (self, g_value_get_boxed (value)); + if (g_variant_lookup (props, "Capabilities", "@a{sv}", &capabilities)) { + parse_capabilities (self, capabilities); + g_variant_unref (capabilities); + } /* Disconnect reason is currently only given for deauthentication events, * not disassociation; currently they are IEEE 802.11 "reason codes", @@ -490,9 +482,8 @@ wpas_iface_properties_changed (DBusGProxy *proxy, * deauthentication will be negative, while authentications caused by the * AP will be positive. */ - value = g_hash_table_lookup (props, "DisconnectReason"); - if (value && G_VALUE_HOLDS (value, G_TYPE_INT)) { - priv->disconnect_reason = g_value_get_int (value); + if (g_variant_lookup (props, "DisconnectReason", "i", &disconnect_reason)) { + priv->disconnect_reason = disconnect_reason; if (priv->disconnect_reason != 0) { nm_log_warn (LOGD_SUPPLICANT, "Connection disconnected (reason %d)", priv->disconnect_reason); @@ -513,22 +504,31 @@ iface_check_ready (NMSupplicantInterface *self) } static void -iface_get_props_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +iface_get_props_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - GHashTable *props = NULL; + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *props = NULL; + GVariant *ret; GError *error = NULL; - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (dbus_g_proxy_end_call (proxy, call_id, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { - wpas_iface_properties_changed (NULL, props, self); - g_hash_table_destroy (props); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (ret) { + g_variant_get (ret, "(@a{sv})", &props); + wpas_iface_properties_changed (self, props); + g_variant_unref (props); + g_variant_unref (ret); } else { nm_log_warn (LOGD_SUPPLICANT, "could not get interface properties: %s.", - error && error->message ? error->message : "(unknown)"); + error->message); g_clear_error (&error); } iface_check_ready (self); @@ -538,15 +538,15 @@ static void wpas_iface_get_props (NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; - - call = dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", - iface_get_props_cb, - self, - NULL, - G_TYPE_STRING, WPAS_DBUS_IFACE_INTERFACE, - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, priv->props_proxy, call); + + // FIXME: we should be letting GDBusProxy handle properties + + g_dbus_proxy_call (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", WPAS_DBUS_IFACE_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + iface_get_props_cb, self); } gboolean @@ -556,6 +556,7 @@ nm_supplicant_interface_credentials_reply (NMSupplicantInterface *self, GError **error) { NMSupplicantInterfacePrivate *priv; + GVariant *ret; g_return_val_if_fail (NM_IS_SUPPLICANT_INTERFACE (self), FALSE); g_return_val_if_fail (field != NULL, FALSE); @@ -566,23 +567,24 @@ nm_supplicant_interface_credentials_reply (NMSupplicantInterface *self, /* Need a network block object path */ g_return_val_if_fail (priv->net_path, FALSE); - return dbus_g_proxy_call_with_timeout (priv->iface_proxy, "NetworkReply", - 5000, - error, - DBUS_TYPE_G_OBJECT_PATH, priv->net_path, - G_TYPE_STRING, field, - G_TYPE_STRING, value, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_sync (priv->iface_proxy, + "NetworkReply", + g_variant_new ("(oss)", priv->net_path, field, value), + G_DBUS_CALL_FLAGS_NONE, 5000, + NULL, error); + if (ret) { + g_variant_unref (ret); + return TRUE; + } else + return FALSE; } static void -wpas_iface_network_request (DBusGProxy *proxy, +wpas_iface_network_request (NMSupplicantInterface *self, const char *object_path, const char *field, - const char *message, - gpointer user_data) + const char *message) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); g_return_if_fail (priv->has_credreq == TRUE); @@ -593,27 +595,43 @@ wpas_iface_network_request (DBusGProxy *proxy, } static void -iface_check_netreply_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +iface_check_netreply_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; GError *error = NULL; - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if ( dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID) - || dbus_g_error_has_name (error, "fi.w1.wpa_supplicant1.InvalidArgs")) { - /* We know NetworkReply is supported if the NetworkReply method returned - * successfully (which is unexpected since we sent a bogus network - * object path) or if we got an "InvalidArgs" (which indicates NetworkReply - * is supported). We know it's not supported if we get an - * "UnknownMethod" error. - */ + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + /* We know NetworkReply is supported if the NetworkReply method returned + * successfully (which is unexpected since we sent a bogus network + * object path) or if we got an "InvalidArgs" (which indicates NetworkReply + * is supported). We know it's not supported if we get an + * "UnknownMethod" error. + */ + if (ret) { + g_variant_unref (ret); priv->has_credreq = TRUE; + } else { + char *remote_error; - nm_log_dbg (LOGD_SUPPLICANT, "Supplicant %s network credentials requests", - priv->has_credreq ? "supports" : "does not support"); + remote_error = g_dbus_error_get_remote_error (error); + if (!g_strcmp0 (remote_error, "fi.w1.wpa_supplicant1.InvalidArgs")) + priv->has_credreq = TRUE; + g_free (remote_error); + g_clear_error (&error); } - g_clear_error (&error); + + nm_log_dbg (LOGD_SUPPLICANT, "Supplicant %s network credentials requests", + priv->has_credreq ? "supports" : "does not support"); iface_check_ready (self); } @@ -622,18 +640,14 @@ static void wpas_iface_check_network_reply (NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; priv->ready_count++; - call = dbus_g_proxy_begin_call (priv->iface_proxy, "NetworkReply", - iface_check_netreply_cb, - self, - NULL, - DBUS_TYPE_G_OBJECT_PATH, "/foobaraasdfasdf", - G_TYPE_STRING, "foobar", - G_TYPE_STRING, "foobar", - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, priv->iface_proxy, call); + g_dbus_proxy_call (priv->iface_proxy, + "NetworkReply", + g_variant_new ("(oss)", "/foobaraasdfasdf", "foobar", "foobar"), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + iface_check_netreply_cb, self); } ApSupport @@ -656,21 +670,29 @@ nm_supplicant_interface_set_ap_support (NMSupplicantInterface *self, } static void -iface_check_ap_mode_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +iface_check_ap_mode_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - char *data; + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; + GError *error = NULL; + const char *data; + + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* The ProbeRequest method only exists if AP mode has been enabled */ - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (dbus_g_proxy_end_call (proxy, call_id, NULL, - G_TYPE_STRING, - &data, - G_TYPE_INVALID)) { - if (data && strstr (data, "ProbeRequest")) + if (ret) { + g_variant_get (ret, "(&s)", &data); + if (strstr (data, "ProbeRequest")) priv->ap_support = AP_SUPPORT_YES; - g_free (data); + g_variant_unref (ret); } iface_check_ready (self); @@ -680,7 +702,6 @@ static void wpas_iface_check_ap_mode (NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; priv->ready_count++; @@ -689,90 +710,104 @@ wpas_iface_check_ap_mode (NMSupplicantInterface *self) * neither of these works we have no way of determining if AP mode is * supported or not. hostap 1.0 and earlier don't support either of these. */ - call = dbus_g_proxy_begin_call (priv->introspect_proxy, "Introspect", - iface_check_ap_mode_cb, - self, - NULL, - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, priv->introspect_proxy, call); + g_dbus_proxy_call (priv->introspect_proxy, + "Introspect", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + iface_check_ap_mode_cb, self); +} + +static void +iface_proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMSupplicantInterface *self = user_data; + + if ( !strcmp (signal_name, "PropertiesChanged") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) { + GVariant *props; + + g_variant_get (parameters, "(@a{sv})", &props); + wpas_iface_properties_changed (self, props); + g_variant_unref (props); + } else if ( !strcmp (signal_name, "ScanDone") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(b)"))) { + gboolean done; + + g_variant_get (parameters, "(b)", &done); + wpas_iface_scan_done (self, done); + } else if ( !strcmp (signal_name, "BSSAdded") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(oa{sv})"))) { + const char *path; + GVariant *props; + + g_variant_get (parameters, "(o@a{sv})", &path, &props); + wpas_iface_bss_added (self, path, props); + g_variant_unref (props); + } else if ( !strcmp (signal_name, "BSSRemoved") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(o)"))) { + const char *path; + + g_variant_get (parameters, "(o)", &path); + wpas_iface_bss_removed (self, path); + } else if ( !strcmp (signal_name, "NetworkRequest") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(oss)"))) { + const char *path, *field, *message; + + g_variant_get (parameters, "(oss)", &path, &field, &message); + wpas_iface_network_request (self, path, field, message); + } else { + nm_log_warn (LOGD_SUPPLICANT, "(%s): unknown %s signal received (%s %s)", + NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->dev, + WPAS_DBUS_IFACE_INTERFACE, signal_name, + g_variant_get_type_string (parameters)); + } } static void interface_add_done (NMSupplicantInterface *self, char *path) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + GDBusConnection *bus; nm_log_dbg (LOGD_SUPPLICANT, "(%s): interface added to supplicant", priv->dev); priv->object_path = path; - priv->iface_proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr), - WPAS_DBUS_SERVICE, - path, - WPAS_DBUS_IFACE_INTERFACE); - - 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->iface_proxy, "PropertiesChanged", - DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->iface_proxy, "PropertiesChanged", - G_CALLBACK (wpas_iface_properties_changed), - self, NULL); - - dbus_g_proxy_add_signal (priv->iface_proxy, "ScanDone", - G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->iface_proxy, "ScanDone", - G_CALLBACK (wpas_iface_scan_done), - self, - NULL); - - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->iface_proxy, "BSSAdded", - DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_MAP_OF_VARIANT, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->iface_proxy, "BSSAdded", - G_CALLBACK (wpas_iface_bss_added), - self, - NULL); - - dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, - DBUS_TYPE_G_OBJECT_PATH, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->iface_proxy, "BSSRemoved", - DBUS_TYPE_G_OBJECT_PATH, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->iface_proxy, "BSSRemoved", - G_CALLBACK (wpas_iface_bss_removed), - self, - NULL); - - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - DBUS_TYPE_G_OBJECT_PATH, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->iface_proxy, "NetworkRequest", - DBUS_TYPE_G_OBJECT_PATH, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->iface_proxy, "NetworkRequest", - G_CALLBACK (wpas_iface_network_request), - self, - NULL); - - priv->introspect_proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr), - WPAS_DBUS_SERVICE, - priv->object_path, - DBUS_INTERFACE_INTROSPECTABLE); - - priv->props_proxy = dbus_g_proxy_new_for_name (nm_dbus_manager_get_connection (priv->dbus_mgr), - WPAS_DBUS_SERVICE, - path, - DBUS_INTERFACE_PROPERTIES); + bus = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); + + priv->iface_proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + WPAS_DBUS_SERVICE, + path, + WPAS_DBUS_IFACE_INTERFACE, + NULL, NULL); + g_signal_connect (priv->iface_proxy, "g-signal", + G_CALLBACK (iface_proxy_signal), self); + + priv->introspect_proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + WPAS_DBUS_SERVICE, + priv->object_path, + "org.freedesktop.DBus.Introspectable", + NULL, NULL); + + priv->props_proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + WPAS_DBUS_SERVICE, + path, + "org.freedesktop.DBus.Properties", + NULL, NULL); + /* Get initial properties and check whether NetworkReply is supported */ priv->ready_count = 1; wpas_iface_get_props (self); @@ -784,17 +819,26 @@ interface_add_done (NMSupplicantInterface *self, char *path) } static void -interface_get_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +interface_get_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; GError *error = NULL; char *path = NULL; - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (dbus_g_proxy_end_call (proxy, call_id, &error, - DBUS_TYPE_G_OBJECT_PATH, &path, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (ret) { + g_variant_get (ret, "(o)", &path); + g_variant_unref (ret); interface_add_done (self, path); } else { nm_log_err (LOGD_SUPPLICANT, "(%s): error getting interface: %s", @@ -808,42 +852,51 @@ static void interface_get (NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; - - call = dbus_g_proxy_begin_call (priv->wpas_proxy, "GetInterface", - interface_get_cb, - self, - NULL, - G_TYPE_STRING, priv->dev, - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, priv->wpas_proxy, call); + + g_dbus_proxy_call (priv->wpas_proxy, + "GetInterface", + g_variant_new ("(s)", priv->dev), + G_DBUS_CALL_FLAGS_NONE, 0, + priv->other_cancellable, + interface_get_cb, self); } static void -interface_add_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +interface_add_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; GError *error = NULL; char *path = NULL; - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (dbus_g_proxy_end_call (proxy, call_id, &error, - DBUS_TYPE_G_OBJECT_PATH, &path, - G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (error); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (ret) { + g_variant_get (ret, "(o)", &path); + g_variant_unref (ret); interface_add_done (self, path); } else { - if (dbus_g_error_has_name (error, WPAS_ERROR_EXISTS_ERROR)) { + char *remote_error = g_dbus_error_get_remote_error (error); + + if (!g_strcmp0 (remote_error, WPAS_ERROR_EXISTS_ERROR)) { /* Interface already added, just get its object path */ interface_get (self); - } else if ( g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SERVICE_UNKNOWN) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SPAWN_EXEC_FAILED) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SPAWN_FORK_FAILED) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_SPAWN_FAILED) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_TIMEOUT) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY) - || g_error_matches (error, DBUS_GERROR, DBUS_GERROR_TIMED_OUT) - || dbus_g_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) { + } else if ( g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_EXEC_FAILED) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FORK_FAILED) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FAILED) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMEOUT) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMED_OUT) + || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) { /* Supplicant wasn't running and could not be launched via service * activation. Wait for it to start by moving back to the INIT * state. @@ -856,6 +909,7 @@ interface_add_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data priv->dev, error->message); set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN); } + g_free (remote_error); g_clear_error (&error); } } @@ -870,10 +924,7 @@ static void interface_add (NMSupplicantInterface *self, gboolean is_wireless) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; - GHashTable *hash; - GValue driver = G_VALUE_INIT; - GValue ifname = G_VALUE_INIT; + GVariantBuilder param_builder; /* Can only start the interface from INIT state */ g_return_if_fail (priv->state == NM_SUPPLICANT_INTERFACE_STATE_INIT); @@ -887,28 +938,20 @@ interface_add (NMSupplicantInterface *self, gboolean is_wireless) * running, this will start it via D-Bus activation and return the response * when the supplicant has started. */ - - hash = g_hash_table_new (g_str_hash, g_str_equal); - - g_value_init (&driver, G_TYPE_STRING); - g_value_set_string (&driver, is_wireless ? DEFAULT_WIFI_DRIVER : "wired"); - g_hash_table_insert (hash, "Driver", &driver); - - g_value_init (&ifname, G_TYPE_STRING); - g_value_set_string (&ifname, priv->dev); - g_hash_table_insert (hash, "Ifname", &ifname); - - call = dbus_g_proxy_begin_call (priv->wpas_proxy, "CreateInterface", - interface_add_cb, - self, - NULL, - DBUS_TYPE_G_MAP_OF_VARIANT, hash, - G_TYPE_INVALID); - nm_call_store_add (priv->other_pcalls, priv->wpas_proxy, call); - - g_hash_table_destroy (hash); - g_value_unset (&driver); - g_value_unset (&ifname); + g_variant_builder_init (¶m_builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add (¶m_builder, "{sv}", + "Driver", + g_variant_new_string (is_wireless ? DEFAULT_WIFI_DRIVER : "wired")); + g_variant_builder_add (¶m_builder, "{sv}", + "Ifname", + g_variant_new_string (priv->dev)); + + g_dbus_proxy_call (priv->wpas_proxy, + "CreateInterface", + g_variant_new ("(a{sv})", ¶m_builder), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + interface_add_cb, self); } static void @@ -932,25 +975,33 @@ smgr_avail_cb (NMSupplicantManager *smgr, } static void -remove_network_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +remove_network_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { + GVariant *ret; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) + g_variant_unref (ret); + else { nm_log_dbg (LOGD_SUPPLICANT, "Couldn't remove network from supplicant interface: %s.", - error && error->message ? error->message : "(unknown)"); + error->message); g_clear_error (&error); } } static void -disconnect_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +disconnect_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { + GVariant *ret; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (ret) + g_variant_unref (ret); + else { nm_log_warn (LOGD_SUPPLICANT, "Couldn't disconnect supplicant interface: %s.", - error && error->message ? error->message : "(unknown)"); + error->message); g_clear_error (&error); } } @@ -964,10 +1015,10 @@ nm_supplicant_interface_disconnect (NMSupplicantInterface * self) priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - /* Clear and cancel all pending calls related to a prior - * connection attempt. - */ - nm_call_store_clear (priv->assoc_pcalls); + /* Cancel all pending calls related to a prior connection attempt. */ + g_cancellable_cancel (priv->assoc_cancellable); + g_object_unref (priv->assoc_cancellable); + priv->assoc_cancellable = g_cancellable_new (); /* Don't do anything if there is no connection to the supplicant yet. */ if (!priv->iface_proxy) @@ -976,93 +1027,118 @@ nm_supplicant_interface_disconnect (NMSupplicantInterface * self) /* Disconnect from the current AP */ if ( (priv->state >= NM_SUPPLICANT_INTERFACE_STATE_SCANNING) && (priv->state <= NM_SUPPLICANT_INTERFACE_STATE_COMPLETED)) { - dbus_g_proxy_begin_call (priv->iface_proxy, "Disconnect", - disconnect_cb, - NULL, NULL, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->iface_proxy, + "Disconnect", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + disconnect_cb, NULL); } /* Remove any network that was added by NetworkManager */ if (priv->net_path) { - dbus_g_proxy_begin_call (priv->iface_proxy, "RemoveNetwork", - remove_network_cb, - NULL, NULL, - DBUS_TYPE_G_OBJECT_PATH, priv->net_path, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->iface_proxy, + "RemoveNetwork", + g_variant_new ("(o)", priv->net_path), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + remove_network_cb, NULL); g_free (priv->net_path); priv->net_path = NULL; } } static void -select_network_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +select_network_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; GError *err = NULL; - nm_call_store_remove (priv->assoc_pcalls, proxy, call_id); - if (!dbus_g_proxy_end_call (proxy, call_id, &err, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (err); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (!ret) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't select network config: %s.", err->message); emit_error_helper (self, err); g_error_free (err); - } + } else + g_variant_unref (ret); } static void call_select_network (NMSupplicantInterface *self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGProxyCall *call; /* We only select the network after all blobs (if any) have been set */ if (priv->blobs_left == 0) { - call = dbus_g_proxy_begin_call (priv->iface_proxy, "SelectNetwork", - select_network_cb, - self, - NULL, - DBUS_TYPE_G_OBJECT_PATH, priv->net_path, - G_TYPE_INVALID); - nm_call_store_add (priv->assoc_pcalls, priv->iface_proxy, call); + g_dbus_proxy_call (priv->iface_proxy, + "SelectNetwork", + g_variant_new ("(o)", priv->net_path), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->assoc_cancellable, + select_network_cb, self); } } static void -add_blob_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +add_blob_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; + GVariant *ret; GError *err = NULL; + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (err); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + priv->blobs_left--; - nm_call_store_remove (priv->assoc_pcalls, proxy, call_id); - if (!dbus_g_proxy_end_call (proxy, call_id, &err, G_TYPE_INVALID)) { + if (!ret) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't set network certificates: %s.", err->message); emit_error_helper (self, err); g_error_free (err); } else - call_select_network (self); + g_variant_unref (ret); + + call_select_network (self); } static void -add_network_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +add_network_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; GError *err = NULL; - GHashTable *blobs; - GHashTableIter iter; - gpointer name, data; - DBusGProxyCall *call; + GVariant *blobs; + GVariantIter iter; + const char *name; + GVariant *ret, *data; - g_free (priv->net_path); - priv->net_path = NULL; + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (err); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - nm_call_store_remove (priv->assoc_pcalls, proxy, call_id); - if (!dbus_g_proxy_end_call (proxy, call_id, &err, - DBUS_TYPE_G_OBJECT_PATH, &priv->net_path, - G_TYPE_INVALID)) { + if (!ret) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't add a network to the supplicant interface: %s.", err->message); emit_error_helper (self, err); @@ -1070,35 +1146,46 @@ add_network_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) return; } + g_free (priv->net_path); + priv->net_path = NULL; + g_variant_get (ret, "(o)", &priv->net_path); + g_variant_unref (ret); + /* Send blobs first; otherwise jump to sending the config settings */ blobs = nm_supplicant_config_get_blobs (priv->cfg); - priv->blobs_left = g_hash_table_size (blobs); - g_hash_table_iter_init (&iter, blobs); - while (g_hash_table_iter_next (&iter, &name, &data)) { - call = dbus_g_proxy_begin_call (priv->iface_proxy, "AddBlob", - add_blob_cb, - self, - NULL, - G_TYPE_STRING, name, - DBUS_TYPE_G_UCHAR_ARRAY, data, - G_TYPE_INVALID); - nm_call_store_add (priv->assoc_pcalls, priv->iface_proxy, call); + priv->blobs_left = g_variant_n_children (blobs); + g_variant_iter_init (&iter, blobs); + while (g_variant_iter_next (&iter, "{&s@ay}", &name, &data)) { + g_dbus_proxy_call (priv->iface_proxy, + "AddBlob", + g_variant_new ("(s@ay)", name, data), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->assoc_cancellable, + add_blob_cb, self); + g_variant_unref (data); } call_select_network (self); } static void -set_ap_scan_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +set_ap_scan_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + NMSupplicantInterfacePrivate *priv; GError *err = NULL; - DBusGProxyCall *call; - GHashTable *config_hash; + GVariant *ret, *config; - nm_call_store_remove (priv->assoc_pcalls, proxy, call_id); - if (!dbus_g_proxy_end_call (proxy, call_id, &err, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (err); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + + if (!ret) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't send AP scan mode to the supplicant interface: %s.", err->message); emit_error_helper (self, err); @@ -1106,18 +1193,18 @@ set_ap_scan_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) return; } + g_variant_unref (ret); + nm_log_info (LOGD_SUPPLICANT, "Config: set interface ap_scan to %d", nm_supplicant_config_get_ap_scan (priv->cfg)); - config_hash = nm_supplicant_config_get_hash (priv->cfg); - call = dbus_g_proxy_begin_call (priv->iface_proxy, "AddNetwork", - add_network_cb, - self, - NULL, - DBUS_TYPE_G_MAP_OF_VARIANT, config_hash, - G_TYPE_INVALID); - g_hash_table_destroy (config_hash); - nm_call_store_add (priv->assoc_pcalls, priv->iface_proxy, call); + config = nm_supplicant_config_get_config (priv->cfg); + g_dbus_proxy_call (priv->iface_proxy, + "AddNetwork", + g_variant_new ("(@a{sv})", config), + G_DBUS_CALL_FLAGS_NONE, 0, + priv->assoc_cancellable, + add_network_cb, self); } gboolean @@ -1125,8 +1212,6 @@ nm_supplicant_interface_set_config (NMSupplicantInterface *self, NMSupplicantConfig *cfg) { NMSupplicantInterfacePrivate *priv; - DBusGProxyCall *call; - GValue value = G_VALUE_INIT; g_return_val_if_fail (NM_IS_SUPPLICANT_INTERFACE (self), FALSE); @@ -1151,94 +1236,83 @@ nm_supplicant_interface_set_config (NMSupplicantInterface *self, g_object_ref (priv->cfg); - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, nm_supplicant_config_get_ap_scan (priv->cfg)); - - call = dbus_g_proxy_begin_call (priv->props_proxy, "Set", - set_ap_scan_cb, - self, - NULL, - G_TYPE_STRING, WPAS_DBUS_IFACE_INTERFACE, - G_TYPE_STRING, "ApScan", - G_TYPE_VALUE, &value, - G_TYPE_INVALID); - nm_call_store_add (priv->assoc_pcalls, priv->props_proxy, call); - - g_value_unset (&value); - return call != NULL; + g_dbus_proxy_call (priv->props_proxy, + "Set", + g_variant_new ("(ssv)", + WPAS_DBUS_IFACE_INTERFACE, + "ApScan", + g_variant_new_uint32 (nm_supplicant_config_get_ap_scan (priv->cfg))), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->assoc_cancellable, + set_ap_scan_cb, self); + return TRUE; } static void -scan_request_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +scan_request_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); + NMSupplicantInterface *self; + GVariant *ret; GError *err = NULL; - nm_call_store_remove (priv->other_pcalls, proxy, call_id); - if (!dbus_g_proxy_end_call (proxy, call_id, &err, G_TYPE_INVALID)) + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_error_free (err); + return; + } + + self = NM_SUPPLICANT_INTERFACE (user_data); + + if (!ret) nm_log_warn (LOGD_SUPPLICANT, "Could not get scan request result: %s", err->message); + else + g_variant_unref (ret); g_signal_emit (self, signals[SCAN_DONE], 0, err ? FALSE : TRUE); g_clear_error (&err); } -static void -destroy_gvalue (gpointer data) -{ - GValue *value = (GValue *) data; - - g_value_unset (value); - g_slice_free (GValue, value); -} - -static GValue * -string_to_gvalue (const char *str) -{ - GValue *val = g_slice_new0 (GValue); - - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, str); - return val; -} - -static GValue * -byte_array_array_to_gvalue (const GPtrArray *array) +static GVariant * +byte_array_array_to_gvariant (const GPtrArray *array) { - GValue *val = g_slice_new0 (GValue); + GVariantBuilder builder; + GByteArray *ba; + int i; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay")); + for (i = 0; i < array->len; i++) { + ba = array->pdata[i]; + g_variant_builder_add (&builder, "@ay", g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, + ba->data, + ba->len, + 1)); + } - g_value_init (val, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR); - g_value_set_boxed (val, array); - return val; + return g_variant_builder_end (&builder); } -gboolean +void nm_supplicant_interface_request_scan (NMSupplicantInterface *self, const GPtrArray *ssids) { NMSupplicantInterfacePrivate *priv; - DBusGProxyCall *call; - GHashTable *hash; + GVariantBuilder param_builder; - g_return_val_if_fail (NM_IS_SUPPLICANT_INTERFACE (self), FALSE); + g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (self)); priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* Scan parameters */ - hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroy_gvalue); - g_hash_table_insert (hash, "Type", string_to_gvalue ("active")); + g_variant_builder_init (¶m_builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add (¶m_builder, "{sv}", "Type", g_variant_new_string ("active")); if (ssids) - g_hash_table_insert (hash, "SSIDs", byte_array_array_to_gvalue (ssids)); - - call = dbus_g_proxy_begin_call (priv->iface_proxy, "Scan", - scan_request_cb, - self, - NULL, - DBUS_TYPE_G_MAP_OF_VARIANT, hash, - G_TYPE_INVALID); - g_hash_table_destroy (hash); - nm_call_store_add (priv->other_pcalls, priv->iface_proxy, call); - - return call != NULL; + g_variant_builder_add (¶m_builder, "{sv}", "SSIDs", byte_array_array_to_gvariant (ssids)); + + g_dbus_proxy_call (priv->iface_proxy, + "Scan", + g_variant_new ("a{sv}", ¶m_builder), + G_DBUS_CALL_FLAGS_NONE, -1, + priv->other_cancellable, + scan_request_cb, self); } guint32 @@ -1361,18 +1435,21 @@ static void nm_supplicant_interface_init (NMSupplicantInterface * self) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - DBusGConnection *bus; + GDBusConnection *bus; priv->state = NM_SUPPLICANT_INTERFACE_STATE_INIT; - priv->assoc_pcalls = nm_call_store_new (); - priv->other_pcalls = nm_call_store_new (); - priv->dbus_mgr = nm_dbus_manager_get (); - - bus = nm_dbus_manager_get_connection (priv->dbus_mgr); - priv->wpas_proxy = dbus_g_proxy_new_for_name (bus, - WPAS_DBUS_SERVICE, - WPAS_DBUS_PATH, - WPAS_DBUS_INTERFACE); + priv->assoc_cancellable = g_cancellable_new (); + priv->other_cancellable = g_cancellable_new (); + + bus = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); + priv->wpas_proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + WPAS_DBUS_SERVICE, + WPAS_DBUS_PATH, + WPAS_DBUS_INTERFACE, + NULL, NULL); priv->bss_proxies = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); } @@ -1417,12 +1494,14 @@ dispose (GObject *object) } priv->disposed = TRUE; - /* Cancel pending calls before unrefing the dbus manager */ - nm_call_store_clear (priv->other_pcalls); - nm_call_store_destroy (priv->other_pcalls); - - nm_call_store_clear (priv->assoc_pcalls); - nm_call_store_destroy (priv->assoc_pcalls); + if (priv->assoc_cancellable) { + g_cancellable_cancel (priv->assoc_cancellable); + g_clear_object (&priv->assoc_cancellable); + } + if (priv->other_cancellable) { + g_cancellable_cancel (priv->other_cancellable); + g_clear_object (&priv->other_cancellable); + } if (priv->props_proxy) g_object_unref (priv->props_proxy); @@ -1448,8 +1527,6 @@ dispose (GObject *object) g_free (priv->dev); - priv->dbus_mgr = NULL; - if (priv->cfg) g_object_unref (priv->cfg); @@ -1501,7 +1578,7 @@ nm_supplicant_interface_class_init (NMSupplicantInterfaceClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (NMSupplicantInterfaceClass, new_bss), NULL, NULL, NULL, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_POINTER); + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VARIANT); signals[BSS_UPDATED] = g_signal_new (NM_SUPPLICANT_INTERFACE_BSS_UPDATED, @@ -1509,7 +1586,7 @@ nm_supplicant_interface_class_init (NMSupplicantInterfaceClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (NMSupplicantInterfaceClass, bss_updated), NULL, NULL, NULL, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_POINTER); + G_TYPE_NONE, 1, G_TYPE_STRING); signals[BSS_REMOVED] = g_signal_new (NM_SUPPLICANT_INTERFACE_BSS_REMOVED, diff --git a/src/supplicant-manager/nm-supplicant-interface.h b/src/supplicant-manager/nm-supplicant-interface.h index 0112e40eae..8ebe70a421 100644 --- a/src/supplicant-manager/nm-supplicant-interface.h +++ b/src/supplicant-manager/nm-supplicant-interface.h @@ -90,12 +90,11 @@ typedef struct { /* interface saw a new BSS */ void (*new_bss) (NMSupplicantInterface *iface, const char *object_path, - GHashTable *props); + GVariant *props); /* a BSS property changed */ void (*bss_updated) (NMSupplicantInterface *iface, - const char *object_path, - GHashTable *props); + const char *object_path); /* supplicant removed a BSS from its scan list */ void (*bss_removed) (NMSupplicantInterface *iface, @@ -135,7 +134,7 @@ const char * nm_supplicant_interface_get_device (NMSupplicantInterface * iface); const char *nm_supplicant_interface_get_object_path (NMSupplicantInterface * iface); -gboolean nm_supplicant_interface_request_scan (NMSupplicantInterface * self, const GPtrArray *ssids); +void nm_supplicant_interface_request_scan (NMSupplicantInterface * self, const GPtrArray *ssids); guint32 nm_supplicant_interface_get_state (NMSupplicantInterface * self); diff --git a/src/supplicant-manager/nm-supplicant-manager.c b/src/supplicant-manager/nm-supplicant-manager.c index c50691d9f5..80b81697ee 100644 --- a/src/supplicant-manager/nm-supplicant-manager.c +++ b/src/supplicant-manager/nm-supplicant-manager.c @@ -21,13 +21,11 @@ #include <string.h> #include <glib.h> -#include <dbus/dbus.h> #include "nm-supplicant-manager.h" #include "nm-supplicant-interface.h" #include "nm-dbus-manager.h" #include "nm-logging.h" -#include "nm-dbus-glib-types.h" #define NM_SUPPLICANT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ NM_TYPE_SUPPLICANT_MANAGER, \ @@ -43,10 +41,9 @@ enum { }; typedef struct { - NMDBusManager * dbus_mgr; guint name_owner_id; - DBusGProxy * proxy; - DBusGProxy * props_proxy; + GDBusProxy * proxy; + GDBusProxy * props_proxy; gboolean running; GHashTable * ifaces; gboolean fast_supported; @@ -123,36 +120,39 @@ nm_supplicant_manager_iface_release (NMSupplicantManager *self, /* Ask wpa_supplicant to remove this interface */ op = nm_supplicant_interface_get_object_path (iface); if (priv->running && priv->proxy && op) { - dbus_g_proxy_call_no_reply (priv->proxy, "RemoveInterface", - DBUS_TYPE_G_OBJECT_PATH, op, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "RemoveInterface", + g_variant_new ("(o)", op), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, NULL, NULL); } g_hash_table_remove (priv->ifaces, ifname); } static void -get_capabilities_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) +get_capabilities_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { NMSupplicantManager *self = NM_SUPPLICANT_MANAGER (user_data); NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); NMSupplicantInterface *iface; GHashTableIter hash_iter; GError *error = NULL; - GHashTable *props = NULL; - GValue *value; + GVariant *ret, *props; + char **capabilities, **methods; char **iter; - if (!dbus_g_proxy_end_call (proxy, call_id, &error, - DBUS_TYPE_G_MAP_OF_VARIANT, &props, - G_TYPE_INVALID)) { - nm_log_warn (LOGD_CORE, "Unexpected error requesting supplicant properties: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (!ret) { + nm_log_warn (LOGD_CORE, "Unexpected error requesting supplicant properties: %s", + error->message); g_clear_error (&error); return; } + g_variant_get (ret, "(@a{sv})", &props); + g_variant_unref (ret); + /* The supplicant only advertises global capabilities if the following * commit has been applied: * @@ -163,13 +163,13 @@ get_capabilities_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_ * dbus: Add global capabilities property */ priv->ap_support = AP_SUPPORT_UNKNOWN; - value = g_hash_table_lookup (props, "Capabilities"); - if (value && G_VALUE_HOLDS (value, G_TYPE_STRV)) { + if (g_variant_lookup (props, "Capabilities", "^as", &capabilities)) { priv->ap_support = AP_SUPPORT_NO; - for (iter = g_value_get_boxed (value); iter && *iter; iter++) { + for (iter = capabilities; iter && *iter; iter++) { if (strcasecmp (*iter, "ap") == 0) priv->ap_support = AP_SUPPORT_YES; } + g_strfreev (capabilities); } /* Tell all interfaces about results of the AP check */ @@ -183,17 +183,17 @@ get_capabilities_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_ /* EAP-FAST */ priv->fast_supported = FALSE; - value = g_hash_table_lookup (props, "EapMethods"); - if (value && G_VALUE_HOLDS (value, G_TYPE_STRV)) { - for (iter = g_value_get_boxed (value); iter && *iter; iter++) { + if (g_variant_lookup (props, "EapMethods", "^as", &methods)) { + for (iter = methods; iter && *iter; iter++) { if (strcasecmp (*iter, "fast") == 0) priv->fast_supported = TRUE; } + g_strfreev (methods); } nm_log_dbg (LOGD_SUPPLICANT, "EAP-FAST is %ssupported", priv->fast_supported ? "" : "not "); - g_hash_table_unref (props); + g_variant_unref (props); } static void @@ -201,10 +201,12 @@ check_capabilities (NMSupplicantManager *self) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); - dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", - get_capabilities_cb, self, NULL, - G_TYPE_STRING, WPAS_DBUS_INTERFACE, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->props_proxy, + "GetAll", + g_variant_new ("(s)", WPAS_DBUS_INTERFACE), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + get_capabilities_cb, self); } gboolean @@ -317,25 +319,34 @@ static void nm_supplicant_manager_init (NMSupplicantManager *self) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); - DBusGConnection *bus; + NMDBusManager *dbus_mgr; + GDBusConnection *bus; - priv->dbus_mgr = nm_dbus_manager_get (); - priv->name_owner_id = g_signal_connect (priv->dbus_mgr, + dbus_mgr = nm_dbus_manager_get (); + priv->name_owner_id = g_signal_connect (dbus_mgr, NM_DBUS_MANAGER_NAME_OWNER_CHANGED, G_CALLBACK (name_owner_changed), self); - priv->running = nm_dbus_manager_name_has_owner (priv->dbus_mgr, WPAS_DBUS_SERVICE); - - bus = nm_dbus_manager_get_connection (priv->dbus_mgr); - priv->proxy = dbus_g_proxy_new_for_name (bus, - WPAS_DBUS_SERVICE, - WPAS_DBUS_PATH, - WPAS_DBUS_INTERFACE); - - priv->props_proxy = dbus_g_proxy_new_for_name (bus, - WPAS_DBUS_SERVICE, - WPAS_DBUS_PATH, - DBUS_INTERFACE_PROPERTIES); + priv->running = nm_dbus_manager_name_has_owner (dbus_mgr, WPAS_DBUS_SERVICE); + + bus = nm_dbus_manager_get_connection (dbus_mgr); + priv->proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + WPAS_DBUS_SERVICE, + WPAS_DBUS_PATH, + WPAS_DBUS_INTERFACE, + NULL, NULL); + + priv->props_proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + WPAS_DBUS_SERVICE, + WPAS_DBUS_PATH, + "org.freedesktop.DBus.Properties", + NULL, NULL); priv->ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); @@ -375,11 +386,8 @@ dispose (GObject *object) if (priv->die_count_reset_id) g_source_remove (priv->die_count_reset_id); - if (priv->dbus_mgr) { - if (priv->name_owner_id) - g_signal_handler_disconnect (priv->dbus_mgr, priv->name_owner_id); - priv->dbus_mgr = NULL; - } + if (priv->name_owner_id) + g_signal_handler_disconnect (nm_dbus_manager_get (), priv->name_owner_id); g_hash_table_destroy (priv->ifaces); diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am index 452ccdc1f7..4b294c3f91 100644 --- a/src/supplicant-manager/tests/Makefile.am +++ b/src/supplicant-manager/tests/Makefile.am @@ -7,8 +7,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = test-supplicant-config diff --git a/src/supplicant-manager/tests/test-supplicant-config.c b/src/supplicant-manager/tests/test-supplicant-config.c index 93de8bb5c8..60a56e1176 100644 --- a/src/supplicant-manager/tests/test-supplicant-config.c +++ b/src/supplicant-manager/tests/test-supplicant-config.c @@ -28,8 +28,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <dbus/dbus-glib.h> - #include <nm-utils.h> #include <nm-setting-connection.h> #include <nm-setting-wired.h> diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 07bdee5bcc..18bb1f613f 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -12,8 +12,7 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\""NetworkManager"\" \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ - $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) + $(GLIB_CFLAGS) noinst_PROGRAMS = \ test-general \ diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am index 66009c877b..ddea4b1140 100644 --- a/src/tests/config/Makefile.am +++ b/src/tests/config/Makefile.am @@ -9,7 +9,6 @@ AM_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) \ - $(DBUS_CFLAGS) \ -DSRCDIR=\""$(srcdir)"\" noinst_PROGRAMS = \ diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 50539d3604..1bc8743b3e 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -41,14 +41,13 @@ #include "nm-logging.h" #include "nm-utils.h" #include "nm-active-connection.h" -#include "nm-dbus-glib-types.h" #include "NetworkManagerUtils.h" #include "nm-glib-compat.h" #include "settings/nm-settings-connection.h" #include "nm-dispatcher.h" #include "nm-agent-manager.h" -#include "nm-vpn-connection-glue.h" +#include "nmdbus-vpn-connection.h" G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) @@ -91,8 +90,8 @@ typedef struct { guint dispatcher_id; NMVpnConnectionStateReason failure_reason; - DBusGProxy *proxy; - GHashTable *connect_hash; + GDBusProxy *proxy; + GVariant *connect_dict; guint connect_timeout; gboolean has_ip4; NMIP4Config *ip4_config; @@ -134,10 +133,9 @@ static void get_secrets (NMVpnConnection *self, SecretsReq secrets_idx, const char **hints); -static void plugin_interactive_secrets_required (DBusGProxy *proxy, +static void plugin_interactive_secrets_required (NMVpnConnection *connection, const char *message, - const char **secrets, - gpointer user_data); + const char **secrets); static void _set_vpn_state (NMVpnConnection *connection, VpnState vpn_state, @@ -212,9 +210,16 @@ call_plugin_disconnect (NMVpnConnection *self) GError *error = NULL; if (priv->proxy) { - if (!dbus_g_proxy_call (priv->proxy, "Disconnect", &error, - G_TYPE_INVALID, - G_TYPE_INVALID)) { + GVariant *ret; + + ret = g_dbus_proxy_call_sync (priv->proxy, + "Disconnect", + NULL, + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + if (ret) + g_variant_unref (ret); + else { nm_log_warn (LOGD_VPN, "error disconnecting VPN: %s", error->message); g_error_free (error); } @@ -605,11 +610,10 @@ vpn_plugin_failure_to_string (NMVpnPluginFailure failure) } static void -plugin_failed (DBusGProxy *proxy, - NMVpnPluginFailure plugin_failure, - gpointer user_data) +plugin_failed (NMVpnConnection *self, + NMVpnPluginFailure plugin_failure) { - NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (user_data); + NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); nm_log_warn (LOGD_VPN, "VPN plugin failed: %s (%d)", vpn_plugin_failure_to_string (plugin_failure), plugin_failure); @@ -703,11 +707,9 @@ vpn_reason_to_string (NMVpnConnectionStateReason reason) } static void -plugin_state_changed (DBusGProxy *proxy, - NMVpnServiceState state, - gpointer user_data) +plugin_state_changed (NMVpnConnection *connection, + NMVpnServiceState state) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); nm_log_info (LOGD_VPN, "VPN plugin state changed: %s (%d)", @@ -939,22 +941,18 @@ nm_vpn_connection_config_maybe_complete (NMVpnConnection *connection, static gboolean process_generic_config (NMVpnConnection *connection, - GHashTable *config_hash) + GVariant *config_dict) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - GValue *val; + const char *tundev; + GVariant *val; + guint32 mtu; g_clear_pointer (&priv->ip_iface, g_free); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_TUNDEV); - if (val) { - if (G_VALUE_HOLDS (val, G_TYPE_STRING)) { - const char *tmp = g_value_get_string (val); - - /* Backwards compat with NM-openswan */ - if (g_strcmp0 (tmp, "_none_") != 0) - priv->ip_iface = g_strdup (tmp); - } else - LOG_INVALID_ARG (NM_VPN_PLUGIN_CONFIG_TUNDEV); + if (g_variant_lookup (config_dict, NM_VPN_PLUGIN_CONFIG_TUNDEV, "&s", &tundev)) { + /* Backwards compat with NM-openswan */ + if (g_strcmp0 (tundev, "_none_") != 0) + priv->ip_iface = g_strdup (tundev); } if (priv->ip_iface) { @@ -968,32 +966,29 @@ process_generic_config (NMVpnConnection *connection, } g_clear_pointer (&priv->banner, g_free); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_BANNER); - if (val) { - if (G_VALUE_HOLDS (val, G_TYPE_STRING)) - priv->banner = g_strdup (g_value_get_string (val)); - else - LOG_INVALID_ARG (NM_VPN_PLUGIN_CONFIG_BANNER); - } + g_variant_lookup (config_dict, NM_VPN_PLUGIN_CONFIG_BANNER, "&s", &priv->banner); /* External world-visible address of the VPN server */ priv->ip4_external_gw = 0; g_clear_pointer (&priv->ip6_external_gw, g_free); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, NULL); if (val) { - GByteArray *ba; - - if (G_VALUE_HOLDS (val, G_TYPE_UINT)) { - priv->ip4_external_gw = g_value_get_uint (val); - } else if (G_VALUE_HOLDS (val, DBUS_TYPE_G_UCHAR_ARRAY) && - (ba = g_value_get_boxed (val)) && - ba->len == sizeof (struct in6_addr)) { - priv->ip6_external_gw = g_memdup (ba->data, ba->len); + const guint8 *data; + gsize length; + + if (g_variant_is_of_type (val, G_VARIANT_TYPE_UINT32)) { + priv->ip4_external_gw = g_variant_get_uint32 (val); + } else if ( g_variant_is_of_type (val, G_VARIANT_TYPE_BYTESTRING) + && (data = g_variant_get_fixed_array (val, &length, 1)) + && length == sizeof (struct in6_addr)) { + priv->ip6_external_gw = g_memdup (data, length); } else { nm_log_err (LOGD_VPN, "(%s): VPN gateway is neither IPv4 nor IPv6", priv->ip_iface); nm_vpn_connection_config_maybe_complete (connection, FALSE); + g_variant_unref (val); return FALSE; } + g_variant_unref (val); } /* MTU; this is a per-connection value, though NM's API treats it @@ -1001,25 +996,17 @@ process_generic_config (NMVpnConnection *connection, * later in ip4_config_get. */ priv->mtu = 0; - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_MTU); - if (val) { - if (G_VALUE_HOLDS (val, G_TYPE_UINT)) { - priv->mtu = g_value_get_uint (val); - } else - LOG_INVALID_ARG (NM_VPN_PLUGIN_CONFIG_MTU); - } + if (g_variant_lookup (config_dict, NM_VPN_PLUGIN_CONFIG_MTU, "u", &mtu)) + priv->mtu = mtu; return TRUE; } static void -nm_vpn_connection_config_get (DBusGProxy *proxy, - GHashTable *config_hash, - gpointer user_data) +nm_vpn_connection_config_get (NMVpnConnection *connection, + GVariant *config_dict) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - GValue *val; nm_log_info (LOGD_VPN, "VPN connection '%s' (IP Config Get) reply received.", nm_connection_get_id (priv->connection)); @@ -1027,29 +1014,17 @@ nm_vpn_connection_config_get (DBusGProxy *proxy, if (priv->vpn_state == STATE_CONNECT) _set_vpn_state (connection, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); - if (!process_generic_config (connection, config_hash)) + if (!process_generic_config (connection, config_dict)) return; /* Note whether to expect IPv4 and IPv6 configs */ - val = g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_HAS_IP4); priv->has_ip4 = FALSE; - if (val) { - if (G_VALUE_HOLDS (val, G_TYPE_BOOLEAN)) - priv->has_ip4 = g_value_get_boolean (val); - else - LOG_INVALID_ARG (NM_VPN_PLUGIN_CONFIG_HAS_IP4); - } g_clear_object (&priv->ip4_config); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_CONFIG_HAS_IP4, "b", &priv->has_ip4); - val = g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_CONFIG_HAS_IP6); priv->has_ip6 = FALSE; - if (val) { - if (G_VALUE_HOLDS (val, G_TYPE_BOOLEAN)) - priv->has_ip6 = g_value_get_boolean (val); - else - LOG_INVALID_ARG (NM_VPN_PLUGIN_CONFIG_HAS_IP6); - } g_clear_object (&priv->ip6_config); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_CONFIG_HAS_IP6, "b", &priv->has_ip6); } static guint @@ -1067,15 +1042,13 @@ vpn_routing_metric (NMVpnConnection *connection) } static void -nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, - GHashTable *config_hash, - gpointer user_data) +nm_vpn_connection_ip4_config_get (NMVpnConnection *connection, + GVariant *config_dict) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); NMPlatformIP4Address address; NMIP4Config *config; - GValue *val; + GVariant *val; int i; if (priv->vpn_state == STATE_CONNECT) @@ -1085,7 +1058,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_log_info (LOGD_VPN, "VPN connection '%s' (IP4 Config Get) reply received.", nm_connection_get_id (priv->connection)); - if (g_hash_table_size (config_hash) == 0) { + if (g_variant_n_children (config_dict) == 0) { priv->has_ip4 = FALSE; nm_vpn_connection_config_maybe_complete (connection, TRUE); return; @@ -1097,7 +1070,7 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, /* In the old API, the generic and IPv4 configuration items * were mixed together. */ - if (!process_generic_config (connection, config_hash)) + if (!process_generic_config (connection, config_dict)) return; priv->has_ip4 = TRUE; @@ -1112,21 +1085,11 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_ip4_config_set_gateway (config, priv->ip4_external_gw); /* Internal address of the VPN subnet's gateway */ - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY); - if (val) - priv->ip4_internal_gw = g_value_get_uint (val); - - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS); - if (val) - address.address = g_value_get_uint (val); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY, "u", &priv->ip4_internal_gw); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_PTP); - if (val) - address.peer_address = g_value_get_uint (val); - - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, "u", &address.address); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_PTP, "u", &address.peer_address); + g_variant_lookup (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, "u", &address.plen); if (address.address && address.plen) { address.source = NM_PLATFORM_SOURCE_VPN; @@ -1138,50 +1101,66 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, return; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_DNS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_DNS, G_VARIANT_TYPE ("au")); if (val) { - GArray *dns = (GArray *) g_value_get_boxed (val); + const guint32 *array; + gsize length; + + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); - for (i = 0; i < dns->len; i++) - nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + for (i = 0; i < length; i++) + nm_ip4_config_add_nameserver (config, array[i]); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_NBNS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, G_VARIANT_TYPE ("au")); if (val) { - GArray *nbns = (GArray *) g_value_get_boxed (val); + const guint32 *array; + gsize length; - for (i = 0; i < nbns->len; i++) - nm_ip4_config_add_wins (config, g_array_index (nbns, guint, i)); + array = g_variant_get_fixed_array (val, &length, sizeof (guint32)); + + for (i = 0; i < length; i++) + nm_ip4_config_add_wins (config, array[i]); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_MSS); - if (val) - nm_ip4_config_set_mss (config, g_value_get_uint (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_MSS, G_VARIANT_TYPE_UINT32); + if (val) { + nm_ip4_config_set_mss (config, g_variant_get_uint32 (val)); + g_variant_unref (val); + } if (priv->mtu) nm_ip4_config_set_mtu (config, priv->mtu); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN); - if (val) - nm_ip4_config_add_domain (config, g_value_get_string (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, G_VARIANT_TYPE_STRING); + if (val) { + nm_ip4_config_add_domain (config, g_variant_get_string (val, NULL)); + g_variant_unref (val); + } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, G_VARIANT_TYPE_STRING_ARRAY); if (val) { - const char **domains = g_value_get_boxed (val); - const char **domain; + char **domains = g_variant_dup_strv (val, NULL); + char **domain; for (domain = domains; domain && *domain; domain++) nm_ip4_config_add_domain (config, *domain); + + g_strfreev (domains); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, G_VARIANT_TYPE ("aau")); if (val) { - GSList *routes; - GSList *iter; + GValue gval = { 0, }; + GPtrArray *routes; - routes = nm_utils_ip4_routes_from_gvalue (val); - for (iter = routes; iter; iter = iter->next) { - NMIP4Route *item = iter->data; + g_value_init (&gval, G_TYPE_PTR_ARRAY); + _nm_utils_ip4_addresses_from_dbus (val, &gval); + routes = g_value_get_boxed (&gval); + + for (i = 0; i < routes->len; i++) { + NMIP4Route *item = routes->pdata[i]; NMPlatformIP4Route route; memset (&route, 0, sizeof (route)); @@ -1203,12 +1182,16 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_ip4_config_add_route (config, &route); } - g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref); + g_ptr_array_unref (routes); + g_value_unset (&gval); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT); - if (val && G_VALUE_HOLDS_BOOLEAN (val)) - nm_ip4_config_set_never_default (config, g_value_get_boolean (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT, G_VARIANT_TYPE_BOOLEAN); + if (val) { + nm_ip4_config_set_never_default (config, g_variant_get_boolean (val)); + g_variant_unref (val); + } /* Merge in user overrides from the NMConnection's IPv4 setting */ nm_ip4_config_merge_setting (config, @@ -1222,16 +1205,13 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, } static void -nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, - GHashTable *config_hash, - gpointer user_data) +nm_vpn_connection_ip6_config_get (NMVpnConnection *connection, + GVariant *config_dict) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); NMPlatformIP6Address address; NMIP6Config *config; - GValue *val; - int i; + GVariant *val; nm_log_info (LOGD_VPN, "VPN connection '%s' (IP6 Config Get) reply received.", nm_connection_get_id (priv->connection)); @@ -1239,7 +1219,7 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, if (priv->vpn_state == STATE_CONNECT) _set_vpn_state (connection, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); - if (g_hash_table_size (config_hash) == 0) { + if (g_variant_n_children (config_dict) == 0) { priv->has_ip6 = FALSE; nm_vpn_connection_config_maybe_complete (connection, TRUE); return; @@ -1254,33 +1234,44 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, /* Internal address of the VPN subnet's gateway */ g_clear_pointer (&priv->ip6_internal_gw, g_free); - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY, G_VARIANT_TYPE_BYTESTRING); if (val) { - GByteArray *ba = g_value_get_boxed (val); + const guint8 *data; + gsize length; - if (ba->len == sizeof (struct in6_addr)) - priv->ip6_internal_gw = g_memdup (ba->data, ba->len); + data = g_variant_get_fixed_array (val, &length, 1); + if (length == sizeof (struct in6_addr)) + priv->ip6_internal_gw = g_memdup (data, length); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS, G_VARIANT_TYPE_BYTESTRING); if (val) { - GByteArray *ba = g_value_get_boxed (val); + const guint8 *data; + gsize length; - if (ba->len == sizeof (struct in6_addr)) - address.address = *(struct in6_addr *) ba->data; + data = g_variant_get_fixed_array (val, &length, 1); + if (length == sizeof (struct in6_addr)) + memcpy (&address.address, data, length); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_PTP); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_PTP, G_VARIANT_TYPE_BYTESTRING); if (val) { - GByteArray *ba = g_value_get_boxed (val); + const guint8 *data; + gsize length; - if (ba->len == sizeof (struct in6_addr)) - address.peer_address = *(struct in6_addr *) ba->data; + data = g_variant_get_fixed_array (val, &length, 1); + if (length == sizeof (struct in6_addr)) + memcpy (&address.peer_address, data, length); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_PREFIX, G_VARIANT_TYPE_UINT32); + if (val) { + address.plen = g_variant_get_uint32 (val); + g_variant_unref (val); + } if (!IN6_IS_ADDR_UNSPECIFIED (&address.address) && address.plen) { address.source = NM_PLATFORM_SOURCE_VPN; @@ -1289,45 +1280,63 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, nm_log_err (LOGD_VPN, "invalid IP6 config received!"); g_object_unref (config); nm_vpn_connection_config_maybe_complete (connection, FALSE); + return; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_DNS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_DNS, G_VARIANT_TYPE ("aay")); if (val) { - GPtrArray *dns = (GPtrArray *) g_value_get_boxed (val); - GByteArray *ba; - - for (i = 0; i < dns->len; i++) { - ba = dns->pdata[i]; - if (ba->len == sizeof (struct in6_addr)) - nm_ip6_config_add_nameserver (config, (struct in6_addr *)ba->data); + GVariantIter iter; + GVariant *addr; + const guint8 *data; + gsize length; + + g_variant_iter_init (&iter, val); + while (g_variant_iter_next (&iter, "@ay", &addr)) { + data = g_variant_get_fixed_array (addr, &length, 1); + if (length == sizeof (struct in6_addr)) + nm_ip6_config_add_nameserver (config, (struct in6_addr *)data); + g_variant_unref (addr); } + + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_MSS); - if (val) - nm_ip6_config_set_mss (config, g_value_get_uint (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_MSS, G_VARIANT_TYPE_UINT32); + if (val) { + nm_ip6_config_set_mss (config, g_variant_get_uint32 (val)); + g_variant_unref (val); + } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN); - if (val) - nm_ip6_config_add_domain (config, g_value_get_string (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, G_VARIANT_TYPE_STRING); + if (val) { + nm_ip6_config_add_domain (config, g_variant_get_string (val, NULL)); + g_variant_unref (val); + } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS, G_VARIANT_TYPE_STRING_ARRAY); if (val) { - const char **domains = g_value_get_boxed (val); - const char **domain; + char **domains = g_variant_dup_strv (val, NULL); + char **domain; for (domain = domains; domain && *domain; domain++) nm_ip6_config_add_domain (config, *domain); + g_free (domains); + + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, G_VARIANT_TYPE ("a(ayuayu)")); if (val) { - GSList *routes; - GSList *iter; + GValue gval = { 0, }; + GPtrArray *routes; + int i; - routes = nm_utils_ip6_routes_from_gvalue (val); - for (iter = routes; iter; iter = iter->next) { - NMIP6Route *item = iter->data; + g_value_init (&gval, G_TYPE_PTR_ARRAY); + _nm_utils_ip6_addresses_from_dbus (val, &gval); + routes = g_value_get_boxed (&gval); + + for (i = 0; i < routes->len; i++) { + NMIP6Route *item = routes->pdata[i]; NMPlatformIP6Route route; memset (&route, 0, sizeof (route)); @@ -1349,12 +1358,16 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, nm_ip6_config_add_route (config, &route); } - g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref); + g_ptr_array_unref (routes); + g_value_unset (&gval); + g_variant_unref (val); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT); - if (val && G_VALUE_HOLDS_BOOLEAN (val)) - nm_ip6_config_set_never_default (config, g_value_get_boolean (val)); + val = g_variant_lookup_value (config_dict, NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT, G_VARIANT_TYPE_BOOLEAN); + if (val) { + nm_ip6_config_set_never_default (config, g_variant_get_boolean (val)); + g_variant_unref (val); + } /* Merge in user overrides from the NMConnection's IPv6 setting */ nm_ip6_config_merge_setting (config, @@ -1367,6 +1380,63 @@ nm_vpn_connection_ip6_config_get (DBusGProxy *proxy, nm_vpn_connection_config_maybe_complete (connection, TRUE); } +static void +proxy_signal (GDBusProxy *proxy, + const char *sender_name, + const char *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMVpnConnection *connection = user_data; + + if ( !strcmp (signal_name, "Config") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) { + GVariant *props; + + g_variant_get (parameters, "(@a{sv})", &props); + nm_vpn_connection_config_get (connection, props); + g_variant_unref (props); + } else if ( !strcmp (signal_name, "Ip4Config") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) { + GVariant *props; + + g_variant_get (parameters, "(@a{sv})", &props); + nm_vpn_connection_ip4_config_get (connection, props); + g_variant_unref (props); + } else if ( !strcmp (signal_name, "Ip6Config") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) { + GVariant *props; + + g_variant_get (parameters, "(@a{sv})", &props); + nm_vpn_connection_ip6_config_get (connection, props); + g_variant_unref (props); + } else if ( !strcmp (signal_name, "Failure") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(u)"))) { + guint32 reason; + + g_variant_get (parameters, "(u)", &reason); + plugin_failed (connection, reason); + } else if ( !strcmp (signal_name, "StateChanged") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(u)"))) { + guint32 state; + + g_variant_get (parameters, "(u)", &state); + plugin_state_changed (connection, state); + } else if ( !strcmp (signal_name, "SecretsRequired") + && g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sas)"))) { + const char *message; + char **secrets; + + g_variant_get (parameters, "(&s^as)", &message, &secrets); + plugin_interactive_secrets_required (connection, message, (const char **) secrets); + g_strfreev (secrets); + } else { + nm_log_warn (LOGD_VPN, "unknown %s signal received (%s %s)", + NM_VPN_DBUS_PLUGIN_INTERFACE, signal_name, + g_variant_get_type_string (parameters)); + } +} + static gboolean connect_timeout_cb (gpointer user_data) { @@ -1394,22 +1464,24 @@ connect_success (NMVpnConnection *connection) /* 40 second timeout waiting for IP config signal from VPN service */ priv->connect_timeout = g_timeout_add_seconds (40, connect_timeout_cb, connection); - g_hash_table_destroy (priv->connect_hash); - priv->connect_hash = NULL; + g_variant_unref (priv->connect_dict); + priv->connect_dict = NULL; } static void -connect_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +connect_cb (GObject *proxy, GAsyncResult *result, void *user_data) { NMVpnConnection *self = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + GVariant *ret; GError *err = NULL; nm_log_info (LOGD_VPN, "VPN connection '%s' (Connect) reply received.", nm_connection_get_id (priv->connection)); - dbus_g_proxy_end_call (proxy, call, &err, G_TYPE_INVALID); - if (!err) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (ret) { + g_variant_unref (ret); connect_success (self); return; } @@ -1421,42 +1493,49 @@ connect_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) } static void -connect_interactive_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +connect_interactive_cb (GObject *proxy, GAsyncResult *result, void *user_data) { NMVpnConnection *self = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + GVariant *ret; GError *err = NULL; + char *remote_error; nm_log_info (LOGD_VPN, "VPN connection '%s' (ConnectInteractive) reply received.", nm_connection_get_id (priv->connection)); - dbus_g_proxy_end_call (proxy, call, &err, G_TYPE_INVALID); - if (!err) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &err); + if (ret) { + g_variant_unref (ret); connect_success (self); return; } - if (dbus_g_error_has_name (err, NM_DBUS_VPN_ERROR_PREFIX "." NM_DBUS_VPN_INTERACTIVE_NOT_SUPPORTED)) { + remote_error = g_dbus_error_get_remote_error (err); + if (!g_strcmp0 (remote_error, NM_DBUS_VPN_ERROR_PREFIX "." NM_DBUS_VPN_INTERACTIVE_NOT_SUPPORTED)) { /* Fall back to Connect() */ - dbus_g_proxy_begin_call (priv->proxy, "Connect", - connect_cb, self, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "Connect", + g_variant_new ("(@a{sv})", priv->connect_dict), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + connect_cb, self); } else { nm_log_warn (LOGD_VPN, "VPN connection '%s' failed to connect interactively: '%s'.", nm_connection_get_id (priv->connection), err->message); - g_error_free (err); _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); } + + g_error_free (err); + g_free (remote_error); } -/* Add a username to a hashed connection */ -static GHashTable * -_hash_with_username (NMConnection *connection, const char *username) +/* Add a username to a serialized connection */ +static GVariant * +_dict_with_username (NMConnection *connection, const char *username) { NMConnection *dup; NMSettingVpn *s_vpn; - GHashTable *hash; GVariant *dict; const char *existing; @@ -1480,10 +1559,7 @@ _hash_with_username (NMConnection *connection, const char *username) g_object_set (s_vpn, NM_SETTING_VPN_USER_NAME, username, NULL); dict = nm_connection_to_dbus (dup, NM_CONNECTION_SERIALIZE_ALL); g_object_unref (dup); - - hash = nm_utils_connection_dict_to_hash (dict); - g_variant_unref (dict); - return hash; + return dict; } static void @@ -1491,37 +1567,20 @@ really_activate (NMVpnConnection *connection, const char *username) { NMVpnConnectionPrivate *priv; NMAgentManager *agent_mgr; - GHashTable *details; + GVariant *details; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); g_return_if_fail (priv->vpn_state == STATE_NEED_AUTH); - dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_INVALID); + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (proxy_signal), connection); - dbus_g_proxy_add_signal (priv->proxy, "Config", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Config", - G_CALLBACK (nm_vpn_connection_config_get), - connection, NULL); - - /* Ip4Config signal */ - dbus_g_proxy_add_signal (priv->proxy, "Ip4Config", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Ip4Config", - G_CALLBACK (nm_vpn_connection_ip4_config_get), - connection, NULL); - - /* Ip6Config signal */ - dbus_g_proxy_add_signal (priv->proxy, "Ip6Config", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Ip6Config", - G_CALLBACK (nm_vpn_connection_ip6_config_get), - connection, NULL); - - if (priv->connect_hash) - g_hash_table_destroy (priv->connect_hash); - priv->connect_hash = _hash_with_username (priv->connection, username); - details = g_hash_table_new (g_str_hash, g_str_equal); + if (priv->connect_dict) + g_variant_unref (priv->connect_dict); + priv->connect_dict = _dict_with_username (priv->connection, username); + g_variant_ref_sink (priv->connect_dict); /* If at least one agent doesn't support VPN hints, then we can't use * ConnectInteractive(), because that agent won't be able to pass hints @@ -1534,20 +1593,23 @@ really_activate (NMVpnConnection *connection, const char *username) nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (connection)), NM_SECRET_AGENT_CAPABILITY_VPN_HINTS)) { nm_log_dbg (LOGD_VPN, "Allowing interactive secrets as all agents have that capability"); - dbus_g_proxy_begin_call (priv->proxy, "ConnectInteractive", - connect_interactive_cb, connection, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash, - DBUS_TYPE_G_MAP_OF_VARIANT, details, - G_TYPE_INVALID); + details = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + g_dbus_proxy_call (priv->proxy, + "ConnectInteractive", + g_variant_new ("(a{sa{sv}}a{sv})", priv->connect_dict, details), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + connect_interactive_cb, connection); } else { nm_log_dbg (LOGD_VPN, "Calling old Connect function as not all agents support interactive secrets"); - dbus_g_proxy_begin_call (priv->proxy, "Connect", - connect_cb, connection, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "Connect", + g_variant_new ("(a{sa{sv}})", priv->connect_dict), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + connect_cb, connection); } g_object_unref (agent_mgr); - g_hash_table_destroy (details); _set_vpn_state (connection, STATE_CONNECT, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); } @@ -1556,7 +1618,7 @@ void nm_vpn_connection_activate (NMVpnConnection *connection) { NMVpnConnectionPrivate *priv; - DBusGConnection *bus; + GDBusConnection *bus; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); @@ -1565,28 +1627,16 @@ nm_vpn_connection_activate (NMVpnConnection *connection) _set_vpn_state (connection, STATE_PREPARE, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); bus = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); - priv->proxy = dbus_g_proxy_new_for_name (bus, - nm_vpn_connection_get_service (connection), - NM_VPN_DBUS_PLUGIN_PATH, - NM_VPN_DBUS_PLUGIN_INTERFACE); - - dbus_g_proxy_add_signal (priv->proxy, "Failure", G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "Failure", - G_CALLBACK (plugin_failed), - connection, NULL); - - /* StateChanged signal */ - dbus_g_proxy_add_signal (priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", - G_CALLBACK (plugin_state_changed), - connection, NULL); - - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRV, G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "SecretsRequired", G_TYPE_STRING, G_TYPE_STRV, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "SecretsRequired", - G_CALLBACK (plugin_interactive_secrets_required), - connection, NULL); + priv->proxy = g_dbus_proxy_new_sync (bus, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + nm_vpn_connection_get_service (connection), + NM_VPN_DBUS_PLUGIN_PATH, + NM_VPN_DBUS_PLUGIN_INTERFACE, + NULL, NULL); + + g_signal_connect (priv->proxy, "g-signal", + G_CALLBACK (proxy_signal), connection); _set_vpn_state (connection, STATE_NEED_AUTH, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); @@ -1701,16 +1751,15 @@ nm_vpn_connection_deactivate (NMVpnConnection *connection, /******************************************************************************/ static void -plugin_need_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +plugin_need_secrets_cb (GObject *proxy, GAsyncResult *result, void *user_data) { NMVpnConnection *self = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + GVariant *ret; GError *error = NULL; - char *setting_name; + const char *setting_name; - dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_STRING, &setting_name, - G_TYPE_INVALID); + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); if (error) { nm_log_err (LOGD_VPN, "(%s/%s) plugin NeedSecrets request #%d failed: %s %s", nm_connection_get_uuid (priv->connection), @@ -1723,7 +1772,8 @@ plugin_need_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_dat return; } - if (setting_name && strlen (setting_name)) { + g_variant_get (ret, "(&s)", &setting_name); + if (*setting_name) { /* More secrets required */ if (priv->secrets_idx == SECRETS_REQ_NEW) { @@ -1738,9 +1788,11 @@ plugin_need_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_dat get_secrets (self, priv->secrets_idx + 1, NULL); } - return; + + g_variant_unref (ret); } + g_variant_unref (ret); nm_log_dbg (LOGD_VPN, "(%s/%s) service indicated no additional secrets required", nm_connection_get_uuid (priv->connection), nm_connection_get_id (priv->connection)); @@ -1750,13 +1802,15 @@ plugin_need_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_dat } static void -plugin_new_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +plugin_new_secrets_cb (GObject *proxy, GAsyncResult *result, void *user_data) { NMVpnConnection *self = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); + GVariant *ret; GError *error = NULL; - if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) { + ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result, &error); + if (!ret) { nm_log_err (LOGD_VPN, "(%s/%s) sending new secrets to the plugin failed: %s %s", nm_connection_get_uuid (priv->connection), nm_connection_get_id (priv->connection), @@ -1765,6 +1819,8 @@ plugin_new_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); g_error_free (error); } + + g_variant_unref (ret); } static void @@ -1777,7 +1833,7 @@ get_secrets_cb (NMSettingsConnection *connection, { NMVpnConnection *self = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); - GHashTable *hash; + GVariant *dict; g_return_if_fail (NM_CONNECTION (connection) == priv->connection); g_return_if_fail (call_id == priv->secrets_id); @@ -1795,7 +1851,7 @@ get_secrets_cb (NMSettingsConnection *connection, priv->username = g_strdup (agent_username); } - hash = _hash_with_username (priv->connection, priv->username); + dict = _dict_with_username (priv->connection, priv->username); if (priv->secrets_idx == SECRETS_REQ_INTERACTIVE) { nm_log_dbg (LOGD_VPN, "(%s/%s) sending secrets to the plugin", @@ -1803,23 +1859,25 @@ get_secrets_cb (NMSettingsConnection *connection, nm_connection_get_id (priv->connection)); /* Send the secrets back to the plugin */ - dbus_g_proxy_begin_call (priv->proxy, "NewSecrets", - plugin_new_secrets_cb, self, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "NewSecrets", + g_variant_new ("(@a{sv})", dict), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + plugin_new_secrets_cb, self); } else { nm_log_dbg (LOGD_VPN, "(%s/%s) asking service if additional secrets are required", nm_connection_get_uuid (priv->connection), nm_connection_get_id (priv->connection)); /* Ask the VPN service if more secrets are required */ - dbus_g_proxy_begin_call (priv->proxy, "NeedSecrets", - plugin_need_secrets_cb, self, NULL, - DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash, - G_TYPE_INVALID); + g_dbus_proxy_call (priv->proxy, + "NeedSecrets", + g_variant_new ("(@a{sv})", dict), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, + plugin_need_secrets_cb, self); } - - g_hash_table_destroy (hash); } } @@ -1877,12 +1935,10 @@ get_secrets (NMVpnConnection *self, } static void -plugin_interactive_secrets_required (DBusGProxy *proxy, +plugin_interactive_secrets_required (NMVpnConnection *connection, const char *message, - const char **secrets, - gpointer user_data) + const char **secrets) { - NMVpnConnection *connection = NM_VPN_CONNECTION (user_data); NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); guint32 secrets_len = secrets ? g_strv_length ((char **) secrets) : 0; char **hints; @@ -1935,10 +1991,7 @@ dispose (GObject *object) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object); - if (priv->connect_hash) { - g_hash_table_destroy (priv->connect_hash); - priv->connect_hash = NULL; - } + g_clear_pointer (&priv->connect_dict, g_variant_unref); if (priv->connect_timeout) { g_source_remove (priv->connect_timeout); @@ -1997,19 +2050,19 @@ get_property (GObject *object, guint prop_id, break; case PROP_IP4_CONFIG: if (ip_config_valid (priv->vpn_state) && priv->ip4_config) - g_value_set_boxed (value, nm_ip4_config_get_dbus_path (priv->ip4_config)); + g_value_set_string (value, nm_ip4_config_get_dbus_path (priv->ip4_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_IP6_CONFIG: if (ip_config_valid (priv->vpn_state) && priv->ip6_config) - g_value_set_boxed (value, nm_ip6_config_get_dbus_path (priv->ip6_config)); + g_value_set_string (value, nm_ip6_config_get_dbus_path (priv->ip6_config)); else - g_value_set_boxed (value, "/"); + g_value_set_string (value, "/"); break; case PROP_MASTER: parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); - g_value_set_boxed (value, parent_dev ? nm_device_get_path (parent_dev) : "/"); + g_value_set_string (value, parent_dev ? nm_device_get_path (parent_dev) : "/"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2071,8 +2124,7 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class) 0, NULL, NULL, NULL, G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); - nm_dbus_manager_register_exported_type (nm_dbus_manager_get (), - G_TYPE_FROM_CLASS (object_class), - &dbus_glib_nm_vpn_connection_object_info); + nm_object_class_add_interface (NM_OBJECT_CLASS (connection_class), + NMDBUS_TYPE_VPN_CONNECTION, + NULL); } - diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index 139a17aca1..e7f0ec46ab 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -303,6 +303,6 @@ nm_vpn_manager_class_init (NMVpnManagerClass *manager_class) /* virtual methods */ object_class->dispose = dispose; - dbus_g_error_domain_register (NM_VPN_MANAGER_ERROR, NULL, NM_TYPE_VPN_MANAGER_ERROR); + _nm_dbus_register_error_domain (NM_VPN_MANAGER_ERROR, NULL, NM_TYPE_VPN_MANAGER_ERROR); } |