From b37fc863854a1be34869a939a9072b4be602fa92 Mon Sep 17 00:00:00 2001 From: Tambet Ingo Date: Mon, 22 Sep 2008 15:29:00 +0000 Subject: [PATCH] 2008-09-22 Tambet Ingo * src/vpn-manager/nm-vpn-connection.c: Add a signal handler for the "Failure" signal from VPN plugins, store the failure reason, and use it when the state is changed to failure. * introspection/nm-vpn-plugin.xml: Fix the "Failure" signal's type description. * include/NetworkManagerVPN.h (NMVPNConnectionStateReason): Add a new reason to the end of the list to not break the API. (NMVPNPluginFailure): Move it here (from libnm-glib/nm-vpn-plugin.h) so it can be shared by plugins and daemon. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4088 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 14 +++++++++++ include/NetworkManagerVPN.h | 9 ++++++- introspection/nm-vpn-plugin.xml | 21 +++++++++++++++- libnm-glib/nm-vpn-plugin.h | 6 ----- src/vpn-manager/nm-vpn-connection.c | 37 ++++++++++++++++++++++++++++- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28dd923a2a..40f08a4112 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-09-22 Tambet Ingo + + * src/vpn-manager/nm-vpn-connection.c: Add a signal handler for the + "Failure" signal from VPN plugins, store the failure reason, and + use it when the state is changed to failure. + + * introspection/nm-vpn-plugin.xml: Fix the "Failure" signal's type + description. + + * include/NetworkManagerVPN.h (NMVPNConnectionStateReason): Add a new + reason to the end of the list to not break the API. + (NMVPNPluginFailure): Move it here (from libnm-glib/nm-vpn-plugin.h) + so it can be shared by plugins and daemon. + 2008-09-18 Dan Williams Patch from Alexander Sack diff --git a/include/NetworkManagerVPN.h b/include/NetworkManagerVPN.h index 8b4c89c6ae..84766544e7 100644 --- a/include/NetworkManagerVPN.h +++ b/include/NetworkManagerVPN.h @@ -102,9 +102,16 @@ typedef enum NMVPNConnectionStateReason NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, - NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS + NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, + NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED } NMVPNConnectionStateReason; +typedef enum { + NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED, + NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED, + NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG +} NMVPNPluginFailure; + #define NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY "gateway" #define NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS "address" #define NM_VPN_PLUGIN_IP4_CONFIG_PTP "ptp" diff --git a/introspection/nm-vpn-plugin.xml b/introspection/nm-vpn-plugin.xml index e7647e1d6d..72861f2666 100644 --- a/introspection/nm-vpn-plugin.xml +++ b/introspection/nm-vpn-plugin.xml @@ -122,11 +122,30 @@ Emitted when a failure in the VPN plugin occurs. - + Reason code for the failure. + + + + + Login failed. + + + + + Connect failed. + + + + + Invalid IP configuration returned from the VPN plugin. + + + + diff --git a/libnm-glib/nm-vpn-plugin.h b/libnm-glib/nm-vpn-plugin.h index dc69430ee3..14ab5a43ed 100644 --- a/libnm-glib/nm-vpn-plugin.h +++ b/libnm-glib/nm-vpn-plugin.h @@ -36,12 +36,6 @@ typedef enum { #define NM_VPN_PLUGIN_ERROR (nm_vpn_plugin_error_quark ()) #define NM_TYPE_VPN_PLUGIN_ERROR (nm_vpn_plugin_error_get_type ()) -typedef enum { - NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED, - NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED, - NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG -} NMVPNPluginFailure; - typedef struct { GObject parent; } NMVPNPlugin; diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index ddb8d285f2..6307aaa1c5 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -65,6 +65,7 @@ typedef struct { NMActiveConnectionState state; NMVPNConnectionState vpn_state; + NMVPNConnectionStateReason failure_reason; gulong device_monitor; DBusGProxy *proxy; guint ipconfig_timeout; @@ -231,12 +232,34 @@ nm_vpn_connection_get_service (NMVPNConnection *connection) return setting->service_type; } +static void +plugin_failed (DBusGProxy *proxy, + NMVPNPluginFailure plugin_failure, + gpointer user_data) +{ + NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (user_data); + + nm_info ("VPN plugin failed: %d", plugin_failure); + + switch (plugin_failure) { + case NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED: + priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED; + break; + case NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG: + priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID; + break; + default: + priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_UNKNOWN; + } +} + static void plugin_state_changed (DBusGProxy *proxy, NMVPNServiceState state, gpointer user_data) { NMVPNConnection *connection = NM_VPN_CONNECTION (user_data); + NMVPNConnectionPrivate *priv; nm_info ("VPN plugin state changed: %d", state); @@ -249,9 +272,16 @@ plugin_state_changed (DBusGProxy *proxy, case NM_VPN_CONNECTION_STATE_CONNECT: case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: case NM_VPN_CONNECTION_STATE_ACTIVATED: + + priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); + + nm_info ("VPN plugin state change reason: %d", priv->failure_reason); nm_vpn_connection_set_vpn_state (connection, NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); + priv->failure_reason); + + /* Reset the failure reason */ + priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_UNKNOWN; break; default: break; @@ -539,6 +569,11 @@ nm_vpn_connection_activate (NMVPNConnection *connection) NM_VPN_DBUS_PLUGIN_INTERFACE); g_object_unref (dbus_mgr); + 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",