From e3d15a5f73b5c5df841d2f7ec4fdd9a3f85eb605 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 14 Aug 2007 14:09:57 +0000 Subject: [PATCH] 2007-08-14 Dan Williams * include/NetworkManagerVPN.h src/vpn-manager/nm-dbus-vpn.c src/vpn-manager/nm-dbus-vpn.h src/vpn-manager/nm-vpn-act-request.c src/vpn-manager/nm-vpn-act-request.h src/vpn-manager/nm-vpn-service.c src/vpn-manager/nm-vpn-service.h libnm-glib/nm-vpn-connection.c libnm-glib/nm-vpn-connection.h libnm-glib/nm-client.h - Rename NM_VPN_STATE_* -> NM_VPN_SERVICE_STATE_* and NMVPNState -> NMVPNServiceState to clarify what they apply to - Rename NM_VPN_ACT_STAGE_* -> NM_VPN_CONNECTION_STATE_* and NMVPNActStage -> NMVPNConnectionState for the same reason * libnm-glib/nm-client.c - Constant + type renames from above - Properly handle NameOwnerChanged/manager_running signals for NM service; only emit when state really changes - Use hash tables correctly so that the key (which was previously owned by the D-Bus message) now has the same lifetime as the value, since the key is now taken from the the NMVPNConnection itself. This really fixes the double-VPN names in the applet git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2677 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 26 +++++ include/NetworkManagerVPN.h | 40 ++++---- libnm-glib/nm-client.c | 66 ++++++++----- libnm-glib/nm-client.h | 4 +- libnm-glib/nm-vpn-connection.c | 26 ++--- libnm-glib/nm-vpn-connection.h | 6 +- src/vpn-manager/nm-dbus-vpn.c | 14 +-- src/vpn-manager/nm-dbus-vpn.h | 35 +++++-- src/vpn-manager/nm-vpn-act-request.c | 56 ++++++----- src/vpn-manager/nm-vpn-act-request.h | 4 +- src/vpn-manager/nm-vpn-service.c | 137 +++++++++++++++------------ src/vpn-manager/nm-vpn-service.h | 2 +- 12 files changed, 250 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52a46aa8af..2f88072bd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2007-08-14 Dan Williams + + * include/NetworkManagerVPN.h + src/vpn-manager/nm-dbus-vpn.c + src/vpn-manager/nm-dbus-vpn.h + src/vpn-manager/nm-vpn-act-request.c + src/vpn-manager/nm-vpn-act-request.h + src/vpn-manager/nm-vpn-service.c + src/vpn-manager/nm-vpn-service.h + libnm-glib/nm-vpn-connection.c + libnm-glib/nm-vpn-connection.h + libnm-glib/nm-client.h + - Rename NM_VPN_STATE_* -> NM_VPN_SERVICE_STATE_* and NMVPNState -> + NMVPNServiceState to clarify what they apply to + - Rename NM_VPN_ACT_STAGE_* -> NM_VPN_CONNECTION_STATE_* and + NMVPNActStage -> NMVPNConnectionState for the same reason + + * libnm-glib/nm-client.c + - Constant + type renames from above + - Properly handle NameOwnerChanged/manager_running signals + for NM service; only emit when state really changes + - Use hash tables correctly so that the key (which was previously owned + by the D-Bus message) now has the same lifetime as the value, since + the key is now taken from the the NMVPNConnection itself. This + really fixes the double-VPN names in the applet + 2007-08-13 Dan Williams Patch from Michael Biebl diff --git a/include/NetworkManagerVPN.h b/include/NetworkManagerVPN.h index 6927da105d..7ff6c275c1 100644 --- a/include/NetworkManagerVPN.h +++ b/include/NetworkManagerVPN.h @@ -59,32 +59,32 @@ /* * VPN daemon states */ -typedef enum NMVPNState +typedef enum NMVPNServiceState { - NM_VPN_STATE_UNKNOWN = 0, - NM_VPN_STATE_INIT, - NM_VPN_STATE_SHUTDOWN, - NM_VPN_STATE_STARTING, - NM_VPN_STATE_STARTED, - NM_VPN_STATE_STOPPING, - NM_VPN_STATE_STOPPED -} NMVPNState; + NM_VPN_SERVICE_STATE_UNKNOWN = 0, + NM_VPN_SERVICE_STATE_INIT, + NM_VPN_SERVICE_STATE_SHUTDOWN, + NM_VPN_SERVICE_STATE_STARTING, + NM_VPN_SERVICE_STATE_STARTED, + NM_VPN_SERVICE_STATE_STOPPING, + NM_VPN_SERVICE_STATE_STOPPED +} NMVPNServiceState; /* - * VPN connection activation stages + * VPN connection states */ -typedef enum NMVPNActStage +typedef enum NMVPNConnectionState { - NM_VPN_ACT_STAGE_UNKNOWN = 0, - NM_VPN_ACT_STAGE_DISCONNECTED, - NM_VPN_ACT_STAGE_PREPARE, - NM_VPN_ACT_STAGE_CONNECT, - NM_VPN_ACT_STAGE_IP_CONFIG_GET, - NM_VPN_ACT_STAGE_ACTIVATED, - NM_VPN_ACT_STAGE_FAILED, - NM_VPN_ACT_STAGE_CANCELED -} NMVPNActStage; + NM_VPN_CONNECTION_STATE_UNKNOWN = 0, + NM_VPN_CONNECTION_STATE_DISCONNECTED, + NM_VPN_CONNECTION_STATE_PREPARE, + NM_VPN_CONNECTION_STATE_CONNECT, + NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, + NM_VPN_CONNECTION_STATE_ACTIVATED, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_CANCELED +} NMVPNConnectionState; #endif /* NETWORK_MANAGER_VPN_H */ diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index 98ed2884b9..8c0b08f1c8 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -21,7 +21,7 @@ typedef struct { GHashTable *devices; DBusGProxy *vpn_proxy; - NMVPNActStage vpn_state; + NMVPNConnectionState vpn_state; gboolean have_vpn_connections; GHashTable *vpn_connections; } NMClientPrivate; @@ -64,12 +64,9 @@ nm_client_init (NMClient *client) (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); - priv->vpn_connections = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); + priv->vpn_connections = g_hash_table_new (g_str_hash, g_str_equal); - priv->vpn_state = NM_VPN_ACT_STAGE_UNKNOWN; + priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN; } static GObject* @@ -284,13 +281,22 @@ proxy_name_owner_changed (DBusGProxy *proxy, { if (name && !strcmp (name, NM_DBUS_SERVICE)) { NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (user_data); + gboolean old_good = (old_owner && strlen (old_owner)); + gboolean new_good = (new_owner && strlen (new_owner)); + gboolean new_running = FALSE; - if (new_owner && strlen (new_owner) > 0) - priv->manager_running = TRUE; - else - priv->manager_running = FALSE; + if (!old_good && new_good) + new_running = TRUE; + else if (old_good && !new_good) + new_running = FALSE; - g_signal_emit (NM_CLIENT (user_data), signals[MANAGER_RUNNING], 0, priv->manager_running); + if (new_running != priv->manager_running) { + priv->manager_running = new_running; + g_signal_emit (NM_CLIENT (user_data), + signals[MANAGER_RUNNING], + 0, + priv->manager_running); + } } } @@ -499,16 +505,16 @@ nm_client_sleep (NMClient *client, gboolean sleep) * For the exact state, each connection has it's own state which' changes * are also signalled. */ -static NMVPNActStage +static NMVPNConnectionState nm_client_get_best_vpn_state (NMClient *client) { GSList *iter; - NMVPNActStage state; - NMVPNActStage best_state = NM_VPN_ACT_STAGE_UNKNOWN; + NMVPNConnectionState state; + NMVPNConnectionState best_state = NM_VPN_CONNECTION_STATE_UNKNOWN; for (iter = nm_client_get_vpn_connections (client); iter; iter = iter->next) { state = nm_vpn_connection_get_state (NM_VPN_CONNECTION (iter->data)); - if (state > best_state && state < NM_VPN_ACT_STAGE_FAILED) + if (state > best_state && state < NM_VPN_CONNECTION_STATE_FAILED) best_state = state; } @@ -516,12 +522,15 @@ nm_client_get_best_vpn_state (NMClient *client) } static void -proxy_vpn_state_change (DBusGProxy *proxy, char *connection_name, NMVPNActStage state, gpointer user_data) +proxy_vpn_state_change (DBusGProxy *proxy, + char *connection_name, + NMVPNConnectionState state, + gpointer user_data) { NMClient *client = NM_CLIENT (user_data); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); NMVPNConnection *connection; - NMVPNActStage best_state; + NMVPNConnectionState best_state; connection = nm_client_get_vpn_connection_by_name (client, connection_name); if (connection) @@ -540,6 +549,7 @@ proxy_vpn_connection_added (DBusGProxy *proxy, char *name, gpointer user_data) NMClient *client = NM_CLIENT (user_data); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client); NMVPNConnection *connection; + const char * vpn_name; if (g_hash_table_lookup (priv->vpn_connections, name)) return; @@ -553,7 +563,11 @@ proxy_vpn_connection_added (DBusGProxy *proxy, char *name, gpointer user_data) return; } - g_hash_table_insert (priv->vpn_connections, name, connection); + /* Use the vpn connection object's name to insert into the hash table + * so that it's lifetime is the same as the vpn connection object. + */ + vpn_name = nm_vpn_connection_get_name (connection); + g_hash_table_insert (priv->vpn_connections, (char *) vpn_name, connection); g_signal_emit (client, signals[VPN_CONNECTION_ADDED], 0, connection); } @@ -638,8 +652,8 @@ get_connections (NMClient *client) } static void -clear_one_vpn_connection (gpointer data, - gpointer user_data) +signal_one_vpn_connection_removed (gpointer data, + gpointer user_data) { NMClient * client = NM_CLIENT (user_data); NMVPNConnection * connection = NM_VPN_CONNECTION (data); @@ -658,9 +672,9 @@ clear_vpn_connections (NMClient * client) priv = NM_CLIENT_GET_PRIVATE (client); list = nm_client_get_vpn_connections (client); - g_hash_table_steal_all (priv->vpn_connections); + g_hash_table_remove_all (priv->vpn_connections); - g_slist_foreach (list, clear_one_vpn_connection, client); + g_slist_foreach (list, signal_one_vpn_connection_removed, client); g_slist_foreach (list, (GFunc) g_object_unref, NULL); g_slist_free (list); } @@ -751,21 +765,21 @@ nm_client_remove_vpn_connection (NMClient *client, NMVPNConnection *connection) return; } - g_hash_table_steal (priv->vpn_connections, info.found_key); + g_hash_table_remove (priv->vpn_connections, info.found_key); g_signal_emit (client, signals[VPN_CONNECTION_REMOVED], 0, connection); g_object_unref (connection); } -NMVPNActStage +NMVPNConnectionState nm_client_get_vpn_state (NMClient *client) { NMClientPrivate *priv; - g_return_val_if_fail (NM_IS_CLIENT (client), NM_VPN_ACT_STAGE_UNKNOWN); + g_return_val_if_fail (NM_IS_CLIENT (client), NM_VPN_CONNECTION_STATE_UNKNOWN); priv = NM_CLIENT_GET_PRIVATE (client); - if (priv->vpn_state == NM_VPN_ACT_STAGE_UNKNOWN) + if (priv->vpn_state == NM_VPN_CONNECTION_STATE_UNKNOWN) priv->vpn_state = nm_client_get_best_vpn_state (client); return priv->vpn_state; diff --git a/libnm-glib/nm-client.h b/libnm-glib/nm-client.h index 3c78352798..f6cb3375b9 100644 --- a/libnm-glib/nm-client.h +++ b/libnm-glib/nm-client.h @@ -35,7 +35,7 @@ typedef struct { void (*vpn_connection_added) (NMClient *client, NMVPNConnection *connection); void (*vpn_connection_removed) (NMClient *client, NMVPNConnection *connection); - void (*vpn_state_change) (NMClient *client, NMVPNActStage state); + void (*vpn_state_change) (NMClient *client, NMVPNConnectionState state); } NMClientClass; GType nm_client_get_type (void); @@ -62,7 +62,7 @@ NMVPNConnection *nm_client_get_vpn_connection_by_name (NMClient *client, void nm_client_remove_vpn_connection (NMClient *client, NMVPNConnection *connection); -NMVPNActStage nm_client_get_vpn_state (NMClient *client); +NMVPNConnectionState nm_client_get_vpn_state (NMClient *client); G_END_DECLS diff --git a/libnm-glib/nm-vpn-connection.c b/libnm-glib/nm-vpn-connection.c index b77152f8e0..1f6c10d70a 100644 --- a/libnm-glib/nm-vpn-connection.c +++ b/libnm-glib/nm-vpn-connection.c @@ -31,7 +31,7 @@ typedef struct { char *name; char *user_name; char *service; - NMVPNActStage state; + NMVPNConnectionState state; } NMVPNConnectionPrivate; enum { @@ -48,7 +48,7 @@ nm_vpn_connection_init (NMVPNConnection *connection) { NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - priv->state = NM_VPN_ACT_STAGE_UNKNOWN; + priv->state = NM_VPN_CONNECTION_STATE_UNKNOWN; } static void @@ -99,7 +99,7 @@ update_properties (NMVPNConnection *connection) char *name = NULL; char *user_name = NULL; char *service = NULL; - NMVPNActStage state; + NMVPNConnectionState state; GError *err = NULL; priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -125,7 +125,7 @@ update_properties (NMVPNConnection *connection) priv->user_name = user_name; priv->service = service; - nm_vpn_connection_set_state (connection, (NMVPNActStage) state); + nm_vpn_connection_set_state (connection, (NMVPNConnectionState) state); return TRUE; } @@ -192,16 +192,16 @@ nm_vpn_connection_get_service (NMVPNConnection *vpn) return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->service; } -NMVPNActStage +NMVPNConnectionState nm_vpn_connection_get_state (NMVPNConnection *vpn) { - g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_ACT_STAGE_UNKNOWN); + g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_CONNECTION_STATE_UNKNOWN); return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->state; } void -nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state) +nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNConnectionState state) { NMVPNConnectionPrivate *priv; @@ -217,14 +217,14 @@ nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state) gboolean nm_vpn_connection_is_activating (NMVPNConnection *vpn) { - NMVPNActStage state; + NMVPNConnectionState state; g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); state = nm_vpn_connection_get_state (vpn); - if (state == NM_VPN_ACT_STAGE_PREPARE || - state == NM_VPN_ACT_STAGE_CONNECT || - state == NM_VPN_ACT_STAGE_IP_CONFIG_GET) + if (state == NM_VPN_CONNECTION_STATE_PREPARE || + state == NM_VPN_CONNECTION_STATE_CONNECT || + state == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET) return TRUE; return FALSE; @@ -240,7 +240,7 @@ nm_vpn_connection_activate (NMVPNConnection *vpn, GSList *passwords) g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); g_return_val_if_fail (passwords != NULL, FALSE); - if (nm_vpn_connection_get_state (vpn) != NM_VPN_ACT_STAGE_DISCONNECTED) { + if (nm_vpn_connection_get_state (vpn) != NM_VPN_CONNECTION_STATE_DISCONNECTED) { g_warning ("VPN connection is already connected or connecting"); return FALSE; } @@ -269,7 +269,7 @@ nm_vpn_connection_deactivate (NMVPNConnection *vpn) { g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE); - if (nm_vpn_connection_get_state (vpn) != NM_VPN_ACT_STAGE_ACTIVATED && + if (nm_vpn_connection_get_state (vpn) != NM_VPN_CONNECTION_STATE_ACTIVATED && !nm_vpn_connection_is_activating (vpn)) { g_warning ("VPN connection isn't activated"); return FALSE; diff --git a/libnm-glib/nm-vpn-connection.h b/libnm-glib/nm-vpn-connection.h index 0a02253da1..ade2d6de03 100644 --- a/libnm-glib/nm-vpn-connection.h +++ b/libnm-glib/nm-vpn-connection.h @@ -45,7 +45,7 @@ typedef struct { /* Signals */ void (*updated) (NMVPNConnection *connection); - void (*state_changed) (NMVPNConnection *connection, NMVPNActStage state); + void (*state_changed) (NMVPNConnection *connection, NMVPNConnectionState state); } NMVPNConnectionClass; GType nm_vpn_connection_get_type (void); @@ -57,7 +57,7 @@ gboolean nm_vpn_connection_update (NMVPNConnection *vpn); const char *nm_vpn_connection_get_name (NMVPNConnection *vpn); const char *nm_vpn_connection_get_user_name (NMVPNConnection *vpn); const char *nm_vpn_connection_get_service (NMVPNConnection *vpn); -NMVPNActStage nm_vpn_connection_get_state (NMVPNConnection *vpn); +NMVPNConnectionState nm_vpn_connection_get_state (NMVPNConnection *vpn); gboolean nm_vpn_connection_is_activating (NMVPNConnection *vpn); gboolean nm_vpn_connection_activate (NMVPNConnection *vpn, @@ -65,7 +65,7 @@ gboolean nm_vpn_connection_activate (NMVPNConnection *vpn, gboolean nm_vpn_connection_deactivate (NMVPNConnection *vpn); -void nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNActStage state); +void nm_vpn_connection_set_state (NMVPNConnection *vpn, NMVPNConnectionState state); G_END_DECLS diff --git a/src/vpn-manager/nm-dbus-vpn.c b/src/vpn-manager/nm-dbus-vpn.c index 414c335f12..157d7c4ca3 100644 --- a/src/vpn-manager/nm-dbus-vpn.c +++ b/src/vpn-manager/nm-dbus-vpn.c @@ -85,11 +85,11 @@ nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *connection, void nm_dbus_vpn_signal_vpn_connection_state_change (DBusConnection *connection, NMVPNConnection *vpn, - NMVPNActStage new_stage) + NMVPNConnectionState new_state) { DBusMessage * message; const char * vpn_name; - dbus_uint32_t int_stage = (dbus_uint32_t) new_stage; + dbus_uint32_t int_state = (dbus_uint32_t) new_state; g_return_if_fail (connection != NULL); g_return_if_fail (vpn != NULL); @@ -105,7 +105,7 @@ nm_dbus_vpn_signal_vpn_connection_state_change (DBusConnection *connection, vpn_name = nm_vpn_connection_get_name (vpn); dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, - DBUS_TYPE_UINT32, &int_stage, + DBUS_TYPE_UINT32, &int_state, DBUS_TYPE_INVALID); dbus_connection_send (connection, message, NULL); dbus_message_unref (message); @@ -753,7 +753,7 @@ nm_dbus_vpn_get_vpn_connection_properties (DBusConnection *connection, const char * service_name; NMVPNService * service; NMVPNActRequest * req; - dbus_uint32_t stage; + dbus_uint32_t state; g_return_val_if_fail (vpn_mgr != NULL, NULL); g_return_val_if_fail (connection != NULL, NULL); @@ -780,14 +780,14 @@ nm_dbus_vpn_get_vpn_connection_properties (DBusConnection *connection, goto out; req = nm_vpn_manager_get_vpn_act_request (vpn_mgr); - stage = (dbus_uint32_t) NM_VPN_ACT_STAGE_DISCONNECTED; + state = (dbus_uint32_t) NM_VPN_CONNECTION_STATE_DISCONNECTED; if (req && (nm_vpn_act_request_get_connection (req) == vpn)) - stage = nm_vpn_act_request_get_stage (req); + state = nm_vpn_act_request_get_state (req); dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &user_name, DBUS_TYPE_STRING, &service_name, - DBUS_TYPE_UINT32, &stage, + DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID); success = TRUE; diff --git a/src/vpn-manager/nm-dbus-vpn.h b/src/vpn-manager/nm-dbus-vpn.h index 02bc4a91ab..c775ae5f41 100644 --- a/src/vpn-manager/nm-dbus-vpn.h +++ b/src/vpn-manager/nm-dbus-vpn.h @@ -26,18 +26,33 @@ #include "nm-vpn-manager.h" #include "nm-vpn-connection.h" -void nm_dbus_vpn_schedule_vpn_connections_update (NMVPNManager *manager); -void nm_dbus_vpn_update_one_vpn_connection (DBusConnection *connection, - NMVPNManager *manager, - const char *vpn); +void nm_dbus_vpn_schedule_vpn_connections_update (NMVPNManager *manager); -void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn, const char *signal); -void nm_dbus_vpn_signal_vpn_failed (DBusConnection *con, const char *signal, NMVPNConnection *vpn, const char *error_msg); -void nm_dbus_vpn_signal_vpn_login_banner (DBusConnection *con, NMVPNConnection *vpn, const char *banner); -void nm_dbus_vpn_signal_vpn_connection_state_change (DBusConnection *con, NMVPNConnection *vpn, NMVPNActStage new_stage); +void nm_dbus_vpn_update_one_vpn_connection (DBusConnection *connection, + NMVPNManager *manager, + const char *vpn); -char ** nm_dbus_vpn_get_routes (DBusConnection *connection, NMVPNConnection *vpn, int *num_items); +void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, + NMVPNConnection *vpn, + const char *signal); -gboolean nm_dbus_vpn_methods_setup (NMVPNManager *mgr); +void nm_dbus_vpn_signal_vpn_failed (DBusConnection *con, + const char *signal, + NMVPNConnection *vpn, + const char *error_msg); + +void nm_dbus_vpn_signal_vpn_login_banner (DBusConnection *con, + NMVPNConnection *vpn, + const char *banner); + +void nm_dbus_vpn_signal_vpn_connection_state_change (DBusConnection *con, + NMVPNConnection *vpn, + NMVPNConnectionState new_state); + +char ** nm_dbus_vpn_get_routes (DBusConnection *connection, + NMVPNConnection *vpn, + int *num_items); + +gboolean nm_dbus_vpn_methods_setup (NMVPNManager *mgr); #endif diff --git a/src/vpn-manager/nm-vpn-act-request.c b/src/vpn-manager/nm-vpn-act-request.c index 5cee9bc412..d987a35f32 100644 --- a/src/vpn-manager/nm-vpn-act-request.c +++ b/src/vpn-manager/nm-vpn-act-request.c @@ -31,7 +31,7 @@ struct NMVPNActRequest { guint refcount; - NMVPNActStage stage; + NMVPNConnectionState state; NMDevice * parent_dev; NMVPNManager * manager; @@ -51,9 +51,17 @@ struct NMVPNActRequest }; -NMVPNActRequest *nm_vpn_act_request_new (NMVPNManager *manager, NMVPNService *service, NMVPNConnection *vpn, - NMDevice *parent_dev, char **password_items, int password_count, - char **data_items, int data_count, char **user_routes, int user_routes_count) +NMVPNActRequest * +nm_vpn_act_request_new (NMVPNManager *manager, + NMVPNService *service, + NMVPNConnection *vpn, + NMDevice *parent_dev, + char **password_items, + int password_count, + char **data_items, + int data_count, + char **user_routes, + int user_routes_count) { NMVPNActRequest *req; @@ -66,7 +74,7 @@ NMVPNActRequest *nm_vpn_act_request_new (NMVPNManager *manager, NMVPNService *se req = g_malloc0 (sizeof (NMVPNActRequest)); req->refcount = 1; - req->stage = NM_VPN_ACT_STAGE_PREPARE; + req->state = NM_VPN_CONNECTION_STATE_PREPARE; req->manager = manager; g_object_ref (G_OBJECT (parent_dev)); @@ -114,17 +122,17 @@ void nm_vpn_act_request_unref (NMVPNActRequest *req) } } -gboolean nm_vpn_act_request_is_activating (NMVPNActRequest *req) +gboolean +nm_vpn_act_request_is_activating (NMVPNActRequest *req) { gboolean activating = FALSE; g_return_val_if_fail (req != NULL, FALSE); - switch (req->stage) - { - case NM_VPN_ACT_STAGE_PREPARE: - case NM_VPN_ACT_STAGE_CONNECT: - case NM_VPN_ACT_STAGE_IP_CONFIG_GET: + switch (req->state) { + case NM_VPN_CONNECTION_STATE_PREPARE: + case NM_VPN_CONNECTION_STATE_CONNECT: + case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: activating = TRUE; break; @@ -139,14 +147,14 @@ gboolean nm_vpn_act_request_is_activated (NMVPNActRequest *req) { g_return_val_if_fail (req != NULL, FALSE); - return (req->stage == NM_VPN_ACT_STAGE_ACTIVATED) ? TRUE : FALSE; + return (req->state == NM_VPN_CONNECTION_STATE_ACTIVATED) ? TRUE : FALSE; } gboolean nm_vpn_act_request_is_failed (NMVPNActRequest *req) { g_return_val_if_fail (req != NULL, FALSE); - return (req->stage == NM_VPN_ACT_STAGE_FAILED) ? TRUE : FALSE; + return (req->state == NM_VPN_CONNECTION_STATE_FAILED) ? TRUE : FALSE; } NMVPNManager *nm_vpn_act_request_get_manager (NMVPNActRequest *req) @@ -219,32 +227,34 @@ gboolean nm_vpn_act_request_should_cancel (NMVPNActRequest *req) return req->canceled; } -NMVPNActStage nm_vpn_act_request_get_stage (NMVPNActRequest *req) +NMVPNConnectionState +nm_vpn_act_request_get_state (NMVPNActRequest *req) { - g_return_val_if_fail (req != NULL, NM_VPN_ACT_STAGE_UNKNOWN); + g_return_val_if_fail (req != NULL, NM_VPN_CONNECTION_STATE_UNKNOWN); - return req->stage; + return req->state; } -void nm_vpn_act_request_set_stage (NMVPNActRequest *req, NMVPNActStage stage) +void +nm_vpn_act_request_set_state (NMVPNActRequest *req, + NMVPNConnectionState state) { - NMVPNActStage old_stage; + NMVPNConnectionState old_state; g_return_if_fail (req != NULL); - old_stage = req->stage; - if (old_stage != stage) - { + old_state = req->state; + if (old_state != state) { NMDBusManager *dbus_mgr; DBusConnection *dbus_connection; dbus_mgr = nm_dbus_manager_get (); dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); if (dbus_connection) { - req->stage = stage; + req->state = state; nm_dbus_vpn_signal_vpn_connection_state_change (dbus_connection, req->vpn, - req->stage); + req->state); } else { nm_warning ("could not get dbus connection."); } diff --git a/src/vpn-manager/nm-vpn-act-request.h b/src/vpn-manager/nm-vpn-act-request.h index 566e865981..6ba7e1a476 100644 --- a/src/vpn-manager/nm-vpn-act-request.h +++ b/src/vpn-manager/nm-vpn-act-request.h @@ -50,8 +50,8 @@ const char ** nm_vpn_act_request_get_user_routes (NMVPNActRequest *req, guint * void nm_vpn_act_request_cancel (NMVPNActRequest *req); gboolean nm_vpn_act_request_should_cancel (NMVPNActRequest *req); -NMVPNActStage nm_vpn_act_request_get_stage (NMVPNActRequest *req); -void nm_vpn_act_request_set_stage (NMVPNActRequest *req, NMVPNActStage stage); +NMVPNConnectionState nm_vpn_act_request_get_state (NMVPNActRequest *req); +void nm_vpn_act_request_set_state (NMVPNActRequest *req, NMVPNConnectionState state); guint nm_vpn_act_request_get_daemon_wait_count (NMVPNActRequest *req); void nm_vpn_act_request_set_daemon_wait_count (NMVPNActRequest *req, guint count); diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index bf833a6b7d..075461962a 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -54,7 +54,7 @@ struct NMVPNService char * name; char * service; char * program; - NMVPNState state; + NMVPNServiceState state; }; @@ -100,7 +100,7 @@ NMVPNService *nm_vpn_service_new (NMVPNManager *manager, NMData *app_data) NMVPNService *service = g_malloc0 (sizeof (NMVPNService)); service->refcount = 1; - service->state = NM_VPN_STATE_SHUTDOWN; + service->state = NM_VPN_SERVICE_STATE_SHUTDOWN; service->app_data = app_data; service->manager = manager; service->dbus_mgr = nm_dbus_manager_get (); @@ -192,15 +192,18 @@ void nm_vpn_service_set_program (NMVPNService *service, const char *program) } -NMVPNState nm_vpn_service_get_state (NMVPNService *service) +NMVPNServiceState +nm_vpn_service_get_state (NMVPNService *service) { - g_return_val_if_fail (service != NULL, NM_VPN_STATE_UNKNOWN); + g_return_val_if_fail (service != NULL, NM_VPN_SERVICE_STATE_UNKNOWN); return service->state; } -static void nm_vpn_service_set_state (NMVPNService *service, const NMVPNState state) +static void +nm_vpn_service_set_state (NMVPNService *service, + const NMVPNServiceState state) { g_return_if_fail (service != NULL); @@ -243,8 +246,9 @@ static char *construct_op_from_service_name (const char *service_name) * has failed. * */ -static void nm_vpn_service_act_request_failed (NMVPNService *service, - NMVPNActRequest *req) +static void +nm_vpn_service_act_request_failed (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection *vpn; @@ -260,7 +264,7 @@ static void nm_vpn_service_act_request_failed (NMVPNService *service, nm_vpn_service_cancel_callback (service, req); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_FAILED); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_FAILED); nm_info ("VPN Activation (%s) failed.", nm_vpn_connection_get_name (vpn)); nm_vpn_act_request_unref (req); @@ -268,7 +272,9 @@ static void nm_vpn_service_act_request_failed (NMVPNService *service, } -static void nm_vpn_service_activation_success (NMVPNService *service, NMVPNActRequest *req) +static void +nm_vpn_service_activation_success (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection * vpn = NULL; @@ -280,7 +286,7 @@ static void nm_vpn_service_activation_success (NMVPNService *service, NMVPNActRe nm_vpn_service_cancel_callback (service, req); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_ACTIVATED); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_ACTIVATED); nm_info ("VPN Activation (%s) successful.", nm_vpn_connection_get_name (vpn)); } @@ -291,12 +297,14 @@ static void nm_vpn_service_activation_success (NMVPNService *service, NMVPNActRe * Kick off the VPN connection process. * */ -void nm_vpn_service_start_connection (NMVPNService *service, NMVPNActRequest *req) +void +nm_vpn_service_start_connection (NMVPNService *service, + NMVPNActRequest *req) { g_return_if_fail (service != NULL); g_return_if_fail (req != NULL); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_PREPARE); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_PREPARE); nm_vpn_service_add_watch (service); /* Start the daemon if it's not already running */ @@ -387,7 +395,9 @@ out: } -static void nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, NMVPNActRequest *req) +static void +nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection * vpn = NULL; guint id; @@ -398,8 +408,8 @@ static void nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, N vpn = nm_vpn_act_request_get_connection (req); g_assert (vpn); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_PREPARE); - nm_vpn_service_set_state (service, NM_VPN_STATE_SHUTDOWN); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_PREPARE); + nm_vpn_service_set_state (service, NM_VPN_SERVICE_STATE_SHUTDOWN); id = g_idle_add (nm_vpn_service_stage1_daemon_exec, req); nm_vpn_act_request_set_callback_id (req, id); @@ -414,7 +424,8 @@ static void nm_vpn_service_schedule_stage1_daemon_exec (NMVPNService *service, N * Wait until the VPN daemon has become active. * */ -static gboolean nm_vpn_service_stage2_daemon_wait (gpointer user_data) +static gboolean +nm_vpn_service_stage2_daemon_wait (gpointer user_data) { NMVPNActRequest * req = (NMVPNActRequest *) user_data; NMVPNService * service; @@ -436,27 +447,26 @@ static gboolean nm_vpn_service_stage2_daemon_wait (gpointer user_data) service_exists = nm_dbus_manager_name_has_owner (service->dbus_mgr, service->service); - if (service_exists && (service->state == NM_VPN_STATE_STOPPED)) - { + if (service_exists && (service->state == NM_VPN_SERVICE_STATE_STOPPED)) { nm_info ("VPN Activation (%s) Stage 2 of 4 (Connection Prepare Wait) " "complete.", nm_vpn_connection_get_name (vpn)); nm_vpn_service_schedule_stage3_connect (service, req); - } - else if (nm_vpn_act_request_get_daemon_wait_count (req) > 10) - { + } else if (nm_vpn_act_request_get_daemon_wait_count (req) > 10) { /* We only wait 2s (10 * 200 milliseconds) for the service to * become available. */ nm_vpn_service_act_request_failed (service, req); - } - else + } else { nm_vpn_service_schedule_stage2_daemon_wait (service, req); + } return FALSE; } -static void nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, NMVPNActRequest *req) +static void +nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection * vpn = NULL; guint id; @@ -467,7 +477,7 @@ static void nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, N vpn = nm_vpn_act_request_get_connection (req); g_assert (vpn); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_PREPARE); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_PREPARE); nm_vpn_act_request_set_daemon_wait_count (req, nm_vpn_act_request_get_daemon_wait_count (req) + 1); @@ -479,7 +489,9 @@ static void nm_vpn_service_schedule_stage2_daemon_wait (NMVPNService *service, N } -static void nm_vpn_service_stage3_connect_cb (DBusPendingCall *pcall, void *user_data) +static void +nm_vpn_service_stage3_connect_cb (DBusPendingCall *pcall, + void *user_data) { DBusMessage * reply; NMVPNActRequest * req = (NMVPNActRequest *) user_data; @@ -498,16 +510,14 @@ static void nm_vpn_service_stage3_connect_cb (DBusPendingCall *pcall, void *user nm_info ("VPN Activation (%s) Stage 3 of 4 (Connect) reply received.", nm_vpn_connection_get_name (vpn)); - if (!(reply = dbus_pending_call_steal_reply (pcall))) - { + if (!(reply = dbus_pending_call_steal_reply (pcall))) { nm_warning ("(VPN Service %s): could not obtain VPN service's reply.", service->service); nm_vpn_service_act_request_failed (service, req); goto out; } - if (message_is_error (reply)) - { + if (message_is_error (reply)) { const char *member = dbus_message_get_member (reply); char *message; @@ -517,10 +527,8 @@ static void nm_vpn_service_stage3_connect_cb (DBusPendingCall *pcall, void *user nm_warning ("(VPN Service %s): could not start the VPN '%s'. dbus says: '%s' '%s'.", service->service, nm_vpn_connection_get_name (vpn), member, message); nm_vpn_service_act_request_failed (service, req); - } - else - { - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_IP_CONFIG_GET); + } else { + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_IP_CONFIG_GET); nm_vpn_service_schedule_stage4_ip_config_get_timeout (service, req); nm_info ("VPN Activation (%s) Stage 3 of 4 (Connect) complete, " "waiting for IP configuration...", nm_vpn_connection_get_name (vpn)); @@ -641,7 +649,9 @@ out: } -static void nm_vpn_service_schedule_stage3_connect (NMVPNService *service, NMVPNActRequest *req) +static void +nm_vpn_service_schedule_stage3_connect (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection * vpn = NULL; guint id; @@ -652,7 +662,7 @@ static void nm_vpn_service_schedule_stage3_connect (NMVPNService *service, NMVPN vpn = nm_vpn_act_request_get_connection (req); g_assert (vpn); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_CONNECT); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_CONNECT); id = g_idle_add (nm_vpn_service_stage3_connect, req); nm_vpn_act_request_set_callback_id (req, id); @@ -661,7 +671,8 @@ static void nm_vpn_service_schedule_stage3_connect (NMVPNService *service, NMVPN } -static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer user_data) +static gboolean +nm_vpn_service_stage4_ip_config_get_timeout (gpointer user_data) { NMVPNActRequest * req = (NMVPNActRequest *) user_data; NMVPNService * service; @@ -680,9 +691,10 @@ static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer user_data) /* If the activation request's state is still IP_CONFIG_GET and we're * in this timeout, cancel activation because it's taken too long. */ - if (nm_vpn_act_request_get_stage (req) == NM_VPN_ACT_STAGE_IP_CONFIG_GET) - { - nm_info ("VPN Activation (%s) Stage 4 of 4 (IP Config Get) timeout exceeded.", nm_vpn_connection_get_name (vpn)); + if (nm_vpn_act_request_get_state (req) == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET) { + nm_info ("VPN Activation (%s) Stage 4 of 4 (IP Config Get) timeout " + "exceeded.", + nm_vpn_connection_get_name (vpn)); nm_vpn_service_act_request_failed (service, req); } @@ -690,7 +702,9 @@ static gboolean nm_vpn_service_stage4_ip_config_get_timeout (gpointer user_data) } -static void nm_vpn_service_schedule_stage4_ip_config_get_timeout (NMVPNService *service, NMVPNActRequest *req) +static void +nm_vpn_service_schedule_stage4_ip_config_get_timeout (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection * vpn = NULL; guint id; @@ -701,7 +715,7 @@ static void nm_vpn_service_schedule_stage4_ip_config_get_timeout (NMVPNService * vpn = nm_vpn_act_request_get_connection (req); g_assert (vpn); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_IP_CONFIG_GET); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_IP_CONFIG_GET); /* 20 second timeout waiting for IP config signal from VPN service */ id = g_timeout_add (20000, nm_vpn_service_stage4_ip_config_get_timeout, req); @@ -1103,7 +1117,9 @@ nm_vpn_service_stop_connection_internal (NMVPNService *service) } -void nm_vpn_service_stop_connection (NMVPNService *service, NMVPNActRequest *req) +void +nm_vpn_service_stop_connection (NMVPNService *service, + NMVPNActRequest *req) { NMVPNConnection *vpn; @@ -1114,18 +1130,21 @@ void nm_vpn_service_stop_connection (NMVPNService *service, NMVPNActRequest *req g_assert (vpn); nm_vpn_service_cancel_callback (service, req); - nm_vpn_act_request_set_stage (req, NM_VPN_ACT_STAGE_DISCONNECTED); + nm_vpn_act_request_set_state (req, NM_VPN_CONNECTION_STATE_DISCONNECTED); /* Ensure we can stop the connection in this state */ - if ((service->state != NM_VPN_STATE_STARTED) && (service->state != NM_VPN_STATE_STARTING)) - { - nm_warning ("(VPN Service %s): could not stop connection '%s' because service was %d.", - service->service, nm_vpn_connection_get_name (vpn), service->state); + if ( (service->state != NM_VPN_SERVICE_STATE_STARTED) + && (service->state != NM_VPN_SERVICE_STATE_STARTING)) { + nm_warning ("(VPN Service %s): could not stop connection '%s' because " + " service was %d.", + service->service, + nm_vpn_connection_get_name (vpn), + service->state); return; } nm_vpn_service_stop_connection_internal (service); - nm_vpn_service_set_state (service, NM_VPN_STATE_STOPPED); + nm_vpn_service_set_state (service, NM_VPN_SERVICE_STATE_STOPPED); } @@ -1198,7 +1217,7 @@ nm_vpn_service_dbus_connection_changed (NMDBusManager *mgr, gboolean valid_vpn = FALSE; /* Kill the VPN service since we can't talk to it anymore anyway */ - nm_vpn_service_set_state (service, NM_VPN_STATE_SHUTDOWN); + nm_vpn_service_set_state (service, NM_VPN_SERVICE_STATE_SHUTDOWN); nm_vpn_service_remove_watch (service); req = nm_vpn_manager_get_vpn_act_request (service->manager); @@ -1238,10 +1257,10 @@ nm_vpn_service_name_owner_changed (NMDBusManager *mgr, if (!old_owner_good && new_owner_good) { /* VPN service started. */ nm_vpn_service_add_watch (service); - nm_vpn_service_set_state (service, NM_VPN_STATE_INIT); + nm_vpn_service_set_state (service, NM_VPN_SERVICE_STATE_INIT); } else if (old_owner_good && !new_owner_good) { /* VPN service went away. */ - nm_vpn_service_set_state (service, NM_VPN_STATE_SHUTDOWN); + nm_vpn_service_set_state (service, NM_VPN_SERVICE_STATE_SHUTDOWN); nm_vpn_service_remove_watch (service); if (valid_vpn) { @@ -1307,8 +1326,8 @@ nm_vpn_service_process_signal (DBusConnection *connection, DBUS_TYPE_UINT32, &old_state_int, DBUS_TYPE_UINT32, &new_state_int, DBUS_TYPE_INVALID)) { - NMVPNState old_state = (NMVPNState) old_state_int; - NMVPNState new_state = (NMVPNState) new_state_int; + NMVPNServiceState old_state = (NMVPNServiceState) old_state_int; + NMVPNServiceState new_state = (NMVPNServiceState) new_state_int; nm_info ("VPN service '%s' signaled state change %d -> %d.", service->service, @@ -1319,11 +1338,11 @@ nm_vpn_service_process_signal (DBusConnection *connection, /* If the VPN daemon state is now stopped and it was starting, * clear the active connection. */ - if ( ( (new_state == NM_VPN_STATE_STOPPED) - || (new_state == NM_VPN_STATE_SHUTDOWN) - || (new_state == NM_VPN_STATE_STOPPING)) - && ( (old_state == NM_VPN_STATE_STARTED) - || (old_state == NM_VPN_STATE_STARTING)) + if ( ( (new_state == NM_VPN_SERVICE_STATE_STOPPED) + || (new_state == NM_VPN_SERVICE_STATE_SHUTDOWN) + || (new_state == NM_VPN_SERVICE_STATE_STOPPING)) + && ( (old_state == NM_VPN_SERVICE_STATE_STARTED) + || (old_state == NM_VPN_SERVICE_STATE_STARTING)) && valid_vpn) { nm_vpn_act_request_unref (req); nm_vpn_manager_schedule_vpn_connection_died (service->manager, req); diff --git a/src/vpn-manager/nm-vpn-service.h b/src/vpn-manager/nm-vpn-service.h index 6e9ad9b09f..840a2784aa 100644 --- a/src/vpn-manager/nm-vpn-service.h +++ b/src/vpn-manager/nm-vpn-service.h @@ -46,7 +46,7 @@ void nm_vpn_service_set_service_name (NMVPNService *service, const char *name) const char * nm_vpn_service_get_program (NMVPNService *service); void nm_vpn_service_set_program (NMVPNService *service, const char *program); -NMVPNState nm_vpn_service_get_state (NMVPNService *service); +NMVPNServiceState nm_vpn_service_get_state (NMVPNService *service); void nm_vpn_service_start_connection (NMVPNService *service, NMVPNActRequest *req); void nm_vpn_service_stop_connection (NMVPNService *service, NMVPNActRequest *req);