From 571812b40c70f14e2a2d43f548095e2c2f0c9e02 Mon Sep 17 00:00:00 2001 From: Tambet Ingo Date: Wed, 26 Sep 2007 15:42:09 +0000 Subject: [PATCH] 2007-09-26 Tambet Ingo * libnm-glib/nm-vpn-plugin.c (nm_vpn_plugin_connect): Update the * plugin activation method. (impl_vpn_plugin_connect): Convert properties hash to NMConnection, activate, and unreference the connection. * introspection/nm-vpn-plugin.xml: Modify the 'Connect' method * arguments: instead of passing properties hash and routes string list, pass NMConnection (in hashed form). * src/vpn-manager/nm-vpn-connection.c * (nm_vpn_connection_get_routes): Return routes as GSList, no need to copy stuff around anymore. (nm_vpn_connection_activate): Update the plugin activation method. * src/NetworkManagerSystem.c * (nm_system_vpn_device_set_from_ip4_config): Convert routes argument to GSList. * vpn-daemons/vpnc/src/nm-vpnc-service.c (real_connect): The arguments have changed, update. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2890 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 17 ++++++++++ introspection/nm-vpn-plugin.xml | 3 +- libnm-glib/nm-vpn-plugin.c | 16 +++++---- libnm-glib/nm-vpn-plugin.h | 4 +-- src/NetworkManagerSystem.c | 15 ++++----- src/NetworkManagerSystem.h | 2 +- src/vpn-manager/nm-vpn-connection.c | 46 ++++---------------------- vpn-daemons/vpnc/ChangeLog | 4 +++ vpn-daemons/vpnc/src/nm-vpnc-service.c | 9 ++--- 9 files changed, 53 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 209cef25cf..620e17dbca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-09-26 Tambet Ingo + + * libnm-glib/nm-vpn-plugin.c (nm_vpn_plugin_connect): Update the plugin activation + method. + (impl_vpn_plugin_connect): Convert properties hash to NMConnection, activate, and + unreference the connection. + + * introspection/nm-vpn-plugin.xml: Modify the 'Connect' method arguments: instead of + passing properties hash and routes string list, pass NMConnection (in hashed form). + + * src/vpn-manager/nm-vpn-connection.c (nm_vpn_connection_get_routes): Return routes + as GSList, no need to copy stuff around anymore. + (nm_vpn_connection_activate): Update the plugin activation method. + + * src/NetworkManagerSystem.c (nm_system_vpn_device_set_from_ip4_config): Convert + routes argument to GSList. + 2007-09-26 Tambet Ingo * src/nm-manager.c (manager_device_state_changed): Listen to device' NEED_AUTH diff --git a/introspection/nm-vpn-plugin.xml b/introspection/nm-vpn-plugin.xml index a8a3934f90..db03bad185 100644 --- a/introspection/nm-vpn-plugin.xml +++ b/introspection/nm-vpn-plugin.xml @@ -4,8 +4,7 @@ - - + diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c index f96d3cce02..fa5285eccf 100644 --- a/libnm-glib/nm-vpn-plugin.c +++ b/libnm-glib/nm-vpn-plugin.c @@ -6,7 +6,6 @@ static gboolean impl_vpn_plugin_connect (NMVPNPlugin *plugin, GHashTable *connection, - char **routes, GError **err); static gboolean impl_vpn_plugin_disconnect (NMVPNPlugin *plugin, @@ -247,8 +246,7 @@ quit_timer_expired (gpointer data) static gboolean nm_vpn_plugin_connect (NMVPNPlugin *plugin, - GHashTable *properties, - char **routes, + NMConnection *connection, GError **err) { gboolean ret = FALSE; @@ -282,7 +280,7 @@ nm_vpn_plugin_connect (NMVPNPlugin *plugin, case NM_VPN_SERVICE_STATE_STOPPED: case NM_VPN_SERVICE_STATE_INIT: nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); - ret = NM_VPN_PLUGIN_GET_CLASS (plugin)->connect (plugin, properties, routes, err); + ret = NM_VPN_PLUGIN_GET_CLASS (plugin)->connect (plugin, connection, err); if (!ret) nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); break; @@ -311,10 +309,16 @@ nm_vpn_plugin_set_ip4_config (NMVPNPlugin *plugin, static gboolean impl_vpn_plugin_connect (NMVPNPlugin *plugin, GHashTable *properties, - char **routes, GError **err) { - return nm_vpn_plugin_connect (plugin, properties, routes, err); + NMConnection *connection; + gboolean success; + + connection = nm_connection_new_from_hash (properties); + success = nm_vpn_plugin_connect (plugin, connection, err); + g_object_unref (connection); + + return success; } static gboolean diff --git a/libnm-glib/nm-vpn-plugin.h b/libnm-glib/nm-vpn-plugin.h index 59672b0c7d..76b934a856 100644 --- a/libnm-glib/nm-vpn-plugin.h +++ b/libnm-glib/nm-vpn-plugin.h @@ -7,6 +7,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -49,8 +50,7 @@ typedef struct { /* virtual methods */ gboolean (*connect) (NMVPNPlugin *plugin, - GHashTable *properties, - char **routes, + NMConnection *connection, GError **err); gboolean (*disconnect) (NMVPNPlugin *plugin, diff --git a/src/NetworkManagerSystem.c b/src/NetworkManagerSystem.c index 7102518bf6..f2772f4154 100644 --- a/src/NetworkManagerSystem.c +++ b/src/NetworkManagerSystem.c @@ -314,13 +314,12 @@ gboolean nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device, const char *iface, NMIP4Config *config, - char **routes) + GSList *routes) { NMIP4Config * ad_config = NULL; struct nl_handle * nlh = NULL; struct rtnl_addr * addr = NULL; struct rtnl_link * request = NULL; - int num_routes; NMNamedManager *named_mgr; g_return_val_if_fail (config != NULL, FALSE); @@ -371,20 +370,18 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device, sleep (1); - num_routes = g_strv_length (routes); nm_system_device_flush_routes_with_iface (iface); - - if (num_routes <= 0) + if (g_slist_length (routes) == 0) { nm_system_delete_default_route (); nm_system_device_add_default_route_via_device_with_iface (iface); } else { - int i; - for (i = 0; i < num_routes; i++) - { + GSList *iter; + + for (iter = routes; iter; iter = iter->next) { char *valid_ip4_route; /* Make sure the route is valid, otherwise it's a security risk as the route @@ -395,7 +392,7 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device, * * where `rm -rf /` was the route text. As UID 0 (root), we have to be careful. */ - if ((valid_ip4_route = validate_ip4_route (routes[i]))) + if ((valid_ip4_route = validate_ip4_route ((char *) iter->data))) { nm_system_device_add_route_via_device_with_iface (iface, valid_ip4_route); g_free (valid_ip4_route); diff --git a/src/NetworkManagerSystem.h b/src/NetworkManagerSystem.h index c129cb80cf..ebfaf425cf 100644 --- a/src/NetworkManagerSystem.h +++ b/src/NetworkManagerSystem.h @@ -65,7 +65,7 @@ gboolean nm_system_device_set_from_ip4_config (NMDevice *dev); gboolean nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device, const char *iface, NMIP4Config *config, - char **routes); + GSList *routes); gboolean nm_system_vpn_device_unset_from_ip4_config (NMDevice *active_device, const char *iface, diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index ccafbca105..db499b9505 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -133,36 +133,15 @@ nm_vpn_connection_get_service (NMVPNConnection *connection) return setting->service_type; } -static char ** +static GSList * nm_vpn_connection_get_routes (NMVPNConnection *connection) { - NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); NMSettingVPN *setting; - char **routes; - int i; - GSList *iter; - setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN); + setting = (NMSettingVPN *) nm_connection_get_setting (NM_VPN_CONNECTION_GET_PRIVATE (connection)->connection, + NM_SETTING_VPN); - routes = g_new (gchar*, g_slist_length (setting->routes) + 1); - - i = 0; - for (iter = setting->routes; iter; iter = iter->next) - routes[i++] = g_strdup (iter->data); - - routes[i] = NULL; - - return routes; -} - -static GHashTable * -nm_vpn_connection_get_vpn_data (NMVPNConnection *connection) -{ - NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - NMSettingVPNProperties *setting; - - setting = (NMSettingVPNProperties *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN_PROPERTIES); - return setting->data; + return setting->routes; } static void @@ -238,7 +217,6 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, NMIP4Config *config; GValue *val; const char *banner = NULL; - char **routes; int i; nm_info ("VPN connection '%s' (IP Config Get) reply received.", @@ -310,9 +288,8 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); priv->ip4_config = config; - routes = nm_vpn_connection_get_routes (connection); - - if (nm_system_vpn_device_set_from_ip4_config (priv->parent_dev, priv->tundev, priv->ip4_config, routes)) { + if (nm_system_vpn_device_set_from_ip4_config (priv->parent_dev, priv->tundev, priv->ip4_config, + nm_vpn_connection_get_routes (connection))) { nm_info ("VPN connection '%s' (IP Config Get) complete.", nm_vpn_connection_get_name (connection)); nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_ACTIVATED); @@ -321,9 +298,6 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_vpn_connection_get_name (connection)); nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_FAILED); } - - if (routes) - g_strfreev (routes); } static gboolean @@ -373,7 +347,6 @@ nm_vpn_connection_activate (NMVPNConnection *connection) { NMVPNConnectionPrivate *priv; NMDBusManager *dbus_mgr; - char **routes; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); g_return_if_fail (nm_vpn_connection_get_state (connection) == NM_VPN_CONNECTION_STATE_PREPARE); @@ -403,16 +376,11 @@ nm_vpn_connection_activate (NMVPNConnection *connection) G_CALLBACK (nm_vpn_connection_ip4_config_get), connection, NULL); - routes = nm_vpn_connection_get_routes (connection); org_freedesktop_NetworkManager_VPN_Plugin_connect_async (priv->proxy, - nm_vpn_connection_get_vpn_data (connection), - (const char**)routes, + nm_connection_to_hash (priv->connection), nm_vpn_connection_connect_cb, connection); - if (routes) - g_strfreev (routes); - nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_CONNECT); } diff --git a/vpn-daemons/vpnc/ChangeLog b/vpn-daemons/vpnc/ChangeLog index 93bc75d87d..a5dac69404 100644 --- a/vpn-daemons/vpnc/ChangeLog +++ b/vpn-daemons/vpnc/ChangeLog @@ -1,3 +1,7 @@ +2007-09-26 Tambet Ingo + + * src/nm-vpnc-service.c (real_connect): The arguments have changed, update. + 2007-09-12 Tambet Ingo * src/nm-vpnc-service.[ch]: Rewrite. Derive from NMVPNPlugin. diff --git a/vpn-daemons/vpnc/src/nm-vpnc-service.c b/vpn-daemons/vpnc/src/nm-vpnc-service.c index 3db4becbc6..60d477e0bb 100644 --- a/vpn-daemons/vpnc/src/nm-vpnc-service.c +++ b/vpn-daemons/vpnc/src/nm-vpnc-service.c @@ -240,13 +240,14 @@ nm_vpnc_config_write (gint vpnc_fd, GHashTable *properties) static gboolean real_connect (NMVPNPlugin *plugin, - GHashTable *properties, - char **routes, + NMConnection *connection, GError **err) { + NMSettingVPNProperties *properties; gint vpnc_fd; - if (!nm_vpnc_properties_validate (properties)) { + properties = (NMSettingVPNProperties *) nm_connection_get_setting (connection, NM_SETTING_VPN_PROPERTIES); + if (!properties || !nm_vpnc_properties_validate (properties->data)) { g_set_error (err, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, @@ -256,7 +257,7 @@ real_connect (NMVPNPlugin *plugin, } if ((vpnc_fd = nm_vpnc_start_vpnc_binary (NM_VPNC_PLUGIN (plugin))) >= 0) - nm_vpnc_config_write (vpnc_fd, properties); + nm_vpnc_config_write (vpnc_fd, properties->data); else { g_set_error (err, NM_VPN_PLUGIN_ERROR,