[PATCH v2 5/8] agent: API changes required for multi agent support

Jukka Rissanen jukka.rissanen at linux.intel.com
Fri Sep 6 04:12:16 PDT 2013


Preparation for API changes in following commits.
---
 include/agent.h           |  9 ++++++---
 src/agent-connman.c       | 23 ++++++++++++++++-------
 src/agent.c               | 14 ++++++++++----
 src/connman.h             |  3 ++-
 src/service.c             | 16 ++++++++++++++--
 vpn/plugins/l2tp.c        | 16 ++++++++++------
 vpn/plugins/openconnect.c | 15 +++++++++------
 vpn/plugins/openvpn.c     |  3 ++-
 vpn/plugins/pptp.c        | 16 ++++++++++------
 vpn/plugins/vpn.c         |  6 ++++--
 vpn/plugins/vpn.h         |  3 ++-
 vpn/plugins/vpnc.c        |  3 ++-
 vpn/vpn-provider.c        |  4 +++-
 vpn/vpn-provider.h        |  3 ++-
 14 files changed, 92 insertions(+), 42 deletions(-)

diff --git a/include/agent.h b/include/agent.h
index 81941dd..fcfc9b2 100644
--- a/include/agent.h
+++ b/include/agent.h
@@ -54,7 +54,8 @@ typedef void (* report_error_cb_t) (void *user_context,
 
 int connman_agent_report_error(void *user_context, const char *path,
 				const char *error,
-				report_error_cb_t callback, void *user_data);
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data);
 
 int connman_agent_register(const char *sender, const char *path);
 int connman_agent_unregister(const char *sender, const char *path);
@@ -64,9 +65,11 @@ typedef void (*agent_queue_cb)(DBusMessage *reply, void *user_data);
 
 int connman_agent_queue_message(void *user_context,
 				DBusMessage *msg, int timeout,
-				agent_queue_cb callback, void *user_data);
+				agent_queue_cb callback, void *user_data,
+				void *agent_data);
 
-void connman_agent_get_info(const char **sender, const char **path);
+void *connman_agent_get_info(const char *dbus_sender, const char **sender,
+							const char **path);
 
 #ifdef __cplusplus
 }
diff --git a/src/agent-connman.c b/src/agent-connman.c
index 664a5b3..8efedc8 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -403,7 +403,8 @@ done:
 }
 
 int __connman_agent_request_passphrase_input(struct connman_service *service,
-				authentication_cb_t callback, void *user_data)
+				authentication_cb_t callback,
+				const char *dbus_sender, void *user_data)
 {
 	DBusMessage *message;
 	const char *path, *agent_sender, *agent_path;
@@ -411,8 +412,12 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
 	DBusMessageIter dict;
 	struct request_input_reply *passphrase_reply;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
+
+	DBG("agent %p service %p path %s", agent, service, agent_path);
 
 	if (!service || !agent_path || !callback)
 		return -ESRCH;
@@ -471,7 +476,7 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
 	err = connman_agent_queue_message(service, message,
 			connman_timeout_input_request(),
 			request_input_passphrase_reply,
-			passphrase_reply);
+			passphrase_reply, agent);
 
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending agent message", err);
@@ -494,8 +499,9 @@ int __connman_agent_request_login_input(struct connman_service *service,
 	DBusMessageIter dict;
 	struct request_input_reply *username_password_reply;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
+	agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
 
 	if (!service || !agent_path || !callback)
 		return -ESRCH;
@@ -534,7 +540,8 @@ int __connman_agent_request_login_input(struct connman_service *service,
 
 	err = connman_agent_queue_message(service, message,
 			connman_timeout_input_request(),
-			request_input_login_reply, username_password_reply);
+			request_input_login_reply, username_password_reply,
+			agent);
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending agent request", err);
 		dbus_message_unref(message);
@@ -581,8 +588,9 @@ int __connman_agent_request_browser(struct connman_service *service,
 	DBusMessageIter iter;
 	const char *path, *agent_sender, *agent_path;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
+	agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
 
 	if (!service || !agent_path || !callback)
 		return -ESRCH;
@@ -615,7 +623,8 @@ int __connman_agent_request_browser(struct connman_service *service,
 
 	err = connman_agent_queue_message(service, message,
 				connman_timeout_browser_launch(),
-				request_browser_reply, browser_reply_data);
+				request_browser_reply, browser_reply_data,
+				agent);
 
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending browser request", err);
diff --git a/src/agent.c b/src/agent.c
index 9031673..49825ed 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -52,10 +52,13 @@ static GList *agent_queue = NULL;
 static struct connman_agent_request *agent_request = NULL;
 static GSList *driver_list = NULL;
 
-void connman_agent_get_info(const char **sender, const char **path)
+void *connman_agent_get_info(const char *dbus_sender, const char **sender,
+							const char **path)
 {
 	*sender = agent_sender;
 	*path = agent_path;
+
+	return NULL;
 }
 
 static void agent_data_free(struct connman_agent_request *data)
@@ -172,7 +175,8 @@ static struct connman_agent_driver *get_driver(void)
 
 int connman_agent_queue_message(void *user_context,
 				DBusMessage *msg, int timeout,
-				agent_queue_cb callback, void *user_data)
+				agent_queue_cb callback, void *user_data,
+				void *agent_data)
 {
 	struct connman_agent_request *queue_data;
 	struct connman_agent_driver *driver;
@@ -326,7 +330,8 @@ static void report_error_reply(DBusMessage *reply, void *user_data)
 
 int connman_agent_report_error(void *user_context, const char *path,
 				const char *error,
-				report_error_cb_t callback, void *user_data)
+				report_error_cb_t callback,
+				const char *dbus_sender, void *user_data)
 {
 	DBusMessage *message;
 	DBusMessageIter iter;
@@ -362,7 +367,8 @@ int connman_agent_report_error(void *user_context, const char *path,
 
 	err = connman_agent_queue_message(user_context, message,
 					connman_timeout_input_request(),
-					report_error_reply, report_error);
+					report_error_reply, report_error,
+					NULL);
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending error request", err);
 		g_free(report_error);
diff --git a/src/connman.h b/src/connman.h
index 38b59dd..c03c9f4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -102,7 +102,8 @@ typedef void (* browser_authentication_cb_t) (struct connman_service *service,
 				bool authentication_done,
 				const char *error, void *user_data);
 int __connman_agent_request_passphrase_input(struct connman_service *service,
-				authentication_cb_t callback, void *user_data);
+				authentication_cb_t callback,
+				const char *dbus_sender, void *user_data);
 int __connman_agent_request_login_input(struct connman_service *service,
 				authentication_cb_t callback, void *user_data);
 int __connman_agent_request_browser(struct connman_service *service,
diff --git a/src/service.c b/src/service.c
index d821d1f..b119479 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5080,6 +5080,14 @@ static void single_connected_tech(struct connman_service *allowed)
 	g_slist_free(services);
 }
 
+static const char *get_dbus_sender(struct connman_service *service)
+{
+	if (!service->pending)
+		return NULL;
+
+	return dbus_message_get_sender(service->pending);
+}
+
 static int service_indicate_state(struct connman_service *service)
 {
 	enum connman_service_state old_state, new_state;
@@ -5242,7 +5250,9 @@ static int service_indicate_state(struct connman_service *service)
 		if (service->userconnect &&
 			connman_agent_report_error(service, service->path,
 					error2string(service->error),
-					report_error_cb, NULL) == -EINPROGRESS)
+					report_error_cb,
+					get_dbus_sender(service),
+					NULL) == -EINPROGRESS)
 			return 0;
 		service_complete(service);
 	} else
@@ -5821,7 +5831,9 @@ int __connman_service_connect(struct connman_service *service)
 			}
 
 			err = __connman_agent_request_passphrase_input(service,
-					request_input_cb, pending);
+					request_input_cb,
+					get_dbus_sender(service),
+					pending);
 			if (service->hidden && err != -EINPROGRESS)
 				service->pending = pending;
 
diff --git a/vpn/plugins/l2tp.c b/vpn/plugins/l2tp.c
index 02108af..3fa39d7 100644
--- a/vpn/plugins/l2tp.c
+++ b/vpn/plugins/l2tp.c
@@ -561,7 +561,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
 				const char *error, void *user_data);
 
 static int request_input(struct vpn_provider *provider,
-				request_cb_t callback, void *user_data)
+			request_cb_t callback, const char *dbus_sender,
+			void *user_data)
 {
 	DBusMessage *message;
 	const char *path, *agent_sender, *agent_path;
@@ -569,9 +570,10 @@ static int request_input(struct vpn_provider *provider,
 	DBusMessageIter dict;
 	struct request_input_reply *l2tp_reply;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
-
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
 	if (!provider || !agent_path || !callback)
 		return -ESRCH;
 
@@ -607,7 +609,7 @@ static int request_input(struct vpn_provider *provider,
 
 	err = connman_agent_queue_message(provider, message,
 			connman_timeout_input_request(),
-			request_input_reply, l2tp_reply);
+			request_input_reply, l2tp_reply, agent);
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending agent request", err);
 		dbus_message_unref(message);
@@ -716,7 +718,8 @@ static void request_input_cb(struct vpn_provider *provider,
 
 static int l2tp_connect(struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
 {
 	const char *username, *password;
 	int err;
@@ -744,7 +747,8 @@ static int l2tp_connect(struct vpn_provider *provider,
 		data->cb = cb;
 		data->user_data = user_data;
 
-		err = request_input(provider, request_input_cb, data);
+		err = request_input(provider, request_input_cb, dbus_sender,
+									data);
 		if (err != -EINPROGRESS) {
 			free_private_data(data);
 			goto done;
diff --git a/vpn/plugins/openconnect.c b/vpn/plugins/openconnect.c
index b341ef9..a19dba9 100644
--- a/vpn/plugins/openconnect.c
+++ b/vpn/plugins/openconnect.c
@@ -392,7 +392,8 @@ err:
 }
 
 static int request_cookie_input(struct vpn_provider *provider,
-		struct oc_private_data *data)
+				struct oc_private_data *data,
+				const char *dbus_sender)
 {
 	DBusMessage *message;
 	const char *path, *agent_sender, *agent_path;
@@ -400,9 +401,10 @@ static int request_cookie_input(struct vpn_provider *provider,
 	DBusMessageIter dict;
 	const char *str;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
-
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
 	if (!provider || !agent_path)
 		return -ESRCH;
 
@@ -447,7 +449,7 @@ static int request_cookie_input(struct vpn_provider *provider,
 
 	err = connman_agent_queue_message(provider, message,
 			connman_timeout_input_request(),
-			request_input_cookie_reply, data);
+			request_input_cookie_reply, data, agent);
 
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending agent request", err);
@@ -463,7 +465,8 @@ static int request_cookie_input(struct vpn_provider *provider,
 
 static int oc_connect(struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb,
+			const char *dbus_sender, void *user_data)
 {
 	const char *vpnhost, *vpncookie, *servercert;
 	int err;
@@ -490,7 +493,7 @@ static int oc_connect(struct vpn_provider *provider,
 		data->cb = cb;
 		data->user_data = user_data;
 
-		err = request_cookie_input(provider, data);
+		err = request_cookie_input(provider, data, dbus_sender);
 		if (err != -EINPROGRESS) {
 			vpn_provider_indicate_error(data->provider,
 					VPN_PROVIDER_ERROR_LOGIN_FAILED);
diff --git a/vpn/plugins/openvpn.c b/vpn/plugins/openvpn.c
index 941275b..35013c4 100644
--- a/vpn/plugins/openvpn.c
+++ b/vpn/plugins/openvpn.c
@@ -308,7 +308,8 @@ static int task_append_config_data(struct vpn_provider *provider,
 
 static int ov_connect(struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
 {
 	const char *option;
 	int err = 0, fd;
diff --git a/vpn/plugins/pptp.c b/vpn/plugins/pptp.c
index 8ae0edc..3ea4414 100644
--- a/vpn/plugins/pptp.c
+++ b/vpn/plugins/pptp.c
@@ -353,7 +353,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
 				const char *error, void *user_data);
 
 static int request_input(struct vpn_provider *provider,
-				request_cb_t callback, void *user_data)
+			request_cb_t callback, const char *dbus_sender,
+			void *user_data)
 {
 	DBusMessage *message;
 	const char *path, *agent_sender, *agent_path;
@@ -361,9 +362,10 @@ static int request_input(struct vpn_provider *provider,
 	DBusMessageIter dict;
 	struct request_input_reply *pptp_reply;
 	int err;
+	void *agent;
 
-	connman_agent_get_info(&agent_sender, &agent_path);
-
+	agent = connman_agent_get_info(dbus_sender, &agent_sender,
+							&agent_path);
 	if (!provider || !agent_path || !callback)
 		return -ESRCH;
 
@@ -399,7 +401,7 @@ static int request_input(struct vpn_provider *provider,
 
 	err = connman_agent_queue_message(provider, message,
 			connman_timeout_input_request(),
-			request_input_reply, pptp_reply);
+			request_input_reply, pptp_reply, agent);
 	if (err < 0 && err != -EBUSY) {
 		DBG("error %d sending agent request", err);
 		dbus_message_unref(message);
@@ -522,7 +524,8 @@ static void request_input_cb(struct vpn_provider *provider,
 
 static int pptp_connect(struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
 {
 	const char *username, *password;
 	int err;
@@ -552,7 +555,8 @@ static int pptp_connect(struct vpn_provider *provider,
 		data->cb = cb;
 		data->user_data = user_data;
 
-		err = request_input(provider, request_input_cb, data);
+		err = request_input(provider, request_input_cb, dbus_sender,
+									data);
 		if (err != -EINPROGRESS) {
 			free_private_data(data);
 			goto done;
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index d86d459..2fdb483 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -354,7 +354,8 @@ exist_err:
 }
 
 static int vpn_connect(struct vpn_provider *provider,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb,
+			const char *dbus_sender, void *user_data)
 {
 	struct vpn_data *data = vpn_provider_get_data(provider);
 	struct vpn_driver_data *vpn_driver_data;
@@ -430,7 +431,8 @@ static int vpn_connect(struct vpn_provider *provider,
 	}
 
 	ret = vpn_driver_data->vpn_driver->connect(provider, data->task,
-						data->if_name, cb, user_data);
+						data->if_name, cb, dbus_sender,
+						user_data);
 	if (ret < 0 && ret != -EINPROGRESS) {
 		stop_vpn(provider);
 		connman_task_destroy(data->task);
diff --git a/vpn/plugins/vpn.h b/vpn/plugins/vpn.h
index 6f86aac..0dd2470 100644
--- a/vpn/plugins/vpn.h
+++ b/vpn/plugins/vpn.h
@@ -45,7 +45,8 @@ struct vpn_driver {
 	int (*notify) (DBusMessage *msg, struct vpn_provider *provider);
 	int (*connect) (struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data);
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data);
 	void (*disconnect) (struct vpn_provider *provider);
 	int (*error_code) (int exit_code);
 	int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
diff --git a/vpn/plugins/vpnc.c b/vpn/plugins/vpnc.c
index d6233f8..4c41efe 100644
--- a/vpn/plugins/vpnc.c
+++ b/vpn/plugins/vpnc.c
@@ -264,7 +264,8 @@ static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
 
 static int vc_connect(struct vpn_provider *provider,
 			struct connman_task *task, const char *if_name,
-			vpn_provider_connect_cb_t cb, void *user_data)
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data)
 {
 	const char *option;
 	int err = 0, fd;
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index 96ea442..cf75523 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -1078,7 +1078,9 @@ int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg)
 
 	if (provider->driver && provider->driver->connect) {
 		dbus_message_ref(msg);
-		err = provider->driver->connect(provider, connect_cb, msg);
+		err = provider->driver->connect(provider, connect_cb,
+						dbus_message_get_sender(msg),
+						msg);
 	} else
 		return -EOPNOTSUPP;
 
diff --git a/vpn/vpn-provider.h b/vpn/vpn-provider.h
index e84b734..ead9330 100644
--- a/vpn/vpn-provider.h
+++ b/vpn/vpn-provider.h
@@ -126,7 +126,8 @@ struct vpn_provider_driver {
 	int (*probe) (struct vpn_provider *provider);
 	int (*remove) (struct vpn_provider *provider);
 	int (*connect) (struct vpn_provider *provider,
-			vpn_provider_connect_cb_t cb, void *user_data);
+			vpn_provider_connect_cb_t cb, const char *dbus_sender,
+			void *user_data);
 	int (*disconnect) (struct vpn_provider *provider);
 	int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
 };
-- 
1.7.11.7




More information about the connman mailing list