[PATCH v3 04/21] vpn: Make VPN plugin connection function async

Jukka Rissanen jukka.rissanen at linux.intel.com
Fri Nov 30 01:30:37 PST 2012


This is needed as we want to ask user the passwords etc.
---
 vpn/plugins/vpn.c  |  2 +-
 vpn/vpn-provider.c | 29 ++++++++++++++++++++++-------
 vpn/vpn-provider.h |  4 ++++
 vpn/vpn.h          |  2 +-
 4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 66a75d2..a8603d9 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -412,7 +412,7 @@ static int vpn_connect(struct vpn_provider *provider,
 
 	ret = vpn_driver_data->vpn_driver->connect(provider, data->task,
 						data->if_name, cb, user_data);
-	if (ret < 0) {
+	if (ret < 0 && ret != -EINPROGRESS) {
 		stop_vpn(provider);
 		connman_task_destroy(data->task);
 		data->task = NULL;
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index a5980e6..c6b86de 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -440,11 +440,11 @@ static DBusMessage *do_connect(DBusConnection *conn, DBusMessage *msg,
 
 	DBG("conn %p provider %p", conn, provider);
 
-	err = __vpn_provider_connect(provider);
+	err = __vpn_provider_connect(provider, msg);
 	if (err < 0)
 		return __connman_error_failed(msg, -err);
 
-	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+	return NULL;
 }
 
 static DBusMessage *do_disconnect(DBusConnection *conn, DBusMessage *msg,
@@ -978,19 +978,34 @@ int __vpn_provider_disconnect(struct vpn_provider *provider)
 static void connect_cb(struct vpn_provider *provider, void *user_data,
 								int error)
 {
+	DBusMessage *pending = user_data;
+
 	DBG("provider %p user %p error %d", provider, user_data, error);
+
+	if (error != 0) {
+		DBusMessage *reply = __connman_error_failed(pending, error);
+		if (reply != NULL)
+			g_dbus_send_message(connection, reply);
+
+		vpn_provider_indicate_error(provider,
+					VPN_PROVIDER_ERROR_CONNECT_FAILED);
+		vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
+	} else
+		g_dbus_send_reply(connection, pending, DBUS_TYPE_INVALID);
+
+	dbus_message_unref(pending);
 }
 
-int __vpn_provider_connect(struct vpn_provider *provider)
+int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg)
 {
 	int err;
 
 	DBG("provider %p", provider);
 
-	if (provider->driver != NULL && provider->driver->connect != NULL)
-		err = provider->driver->connect(provider,
-						connect_cb, NULL);
-	else
+	if (provider->driver != NULL && provider->driver->connect != NULL) {
+		dbus_message_ref(msg);
+		err = provider->driver->connect(provider, connect_cb, msg);
+	} else
 		return -EOPNOTSUPP;
 
 	return err;
diff --git a/vpn/vpn-provider.h b/vpn/vpn-provider.h
index b3c1048..b290bd1 100644
--- a/vpn/vpn-provider.h
+++ b/vpn/vpn-provider.h
@@ -108,6 +108,10 @@ const char *vpn_provider_get_path(struct vpn_provider *provider);
 typedef void (* vpn_provider_connect_cb_t) (struct vpn_provider *provider,
 					void *user_data, int error);
 
+typedef void (* vpn_provider_auth_cb_t) (struct vpn_provider *provider,
+					const char *authenticator,
+					const char *error, void *user_data);
+
 struct vpn_provider_driver {
 	const char *name;
 	enum vpn_provider_type type;
diff --git a/vpn/vpn.h b/vpn/vpn.h
index 2b36b30..fed66a8 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -83,7 +83,7 @@ int __vpn_provider_indicate_state(struct vpn_provider *provider,
 					enum vpn_provider_state state);
 int __vpn_provider_indicate_error(struct vpn_provider *provider,
 					enum vpn_provider_error error);
-int __vpn_provider_connect(struct vpn_provider *provider);
+int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg);
 int __vpn_provider_connect_path(const char *path);
 int __vpn_provider_disconnect(struct vpn_provider *provider);
 int __vpn_provider_remove(const char *path);
-- 
1.7.11.4




More information about the connman mailing list