From: Mohamed Abbas <mab...@linux.intel.com>

Change task notify to allow client to send dbus reply. This
will allow vpn plugin to send requested user/password info.
---
 include/task.h |    2 +-
 plugins/vpn.c  |    8 +++++---
 src/task.c     |   30 +++++++++++++++++-------------
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/include/task.h b/include/task.h
index bde2a29..d93df2d 100644
--- a/include/task.h
+++ b/include/task.h
@@ -39,7 +39,7 @@ struct connman_task;
 typedef void (* connman_task_exit_t) (struct connman_task *task,
                                                int exit_code, void *user_data);
 
-typedef void (* connman_task_notify_t) (struct connman_task *task,
+typedef DBusMessage * (* connman_task_notify_t) (struct connman_task *task,
                                DBusMessage *message, void *user_data);
 
 struct connman_task *connman_task_create(const char *program);
diff --git a/plugins/vpn.c b/plugins/vpn.c
index a1759c9..ee85dd7 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -196,7 +196,7 @@ static void vpn_newlink(unsigned flags, unsigned change, 
void *user_data)
        data->flags = flags;
 }
 
-static void vpn_notify(struct connman_task *task,
+static DBusMessage *vpn_notify(struct connman_task *task,
                        DBusMessage *msg, void *user_data)
 {
        struct connman_provider *provider = user_data;
@@ -209,11 +209,11 @@ static void vpn_notify(struct connman_task *task,
 
        name = connman_provider_get_driver_name(provider);
        if (name == NULL)
-               return;
+               return NULL;
 
        vpn_driver_data = g_hash_table_lookup(driver_hash, name);
        if (vpn_driver_data == NULL)
-               return;
+               return NULL;
 
        state = vpn_driver_data->vpn_driver->notify(msg, provider);
        switch (state) {
@@ -238,6 +238,8 @@ static void vpn_notify(struct connman_task *task,
                                        CONNMAN_PROVIDER_ERROR_AUTH_FAILED);
                break;
        }
+
+       return NULL;
 }
 
 static int vpn_create_tun(struct connman_provider *provider)
diff --git a/src/task.c b/src/task.c
index b5b9ef7..51b4898 100644
--- a/src/task.c
+++ b/src/task.c
@@ -366,6 +366,7 @@ static DBusHandlerResult task_filter(DBusConnection 
*connection,
        struct connman_task *task;
        struct notify_data *notify;
        const char *path, *member;
+       DBusMessage *reply = NULL;
 
        if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -382,29 +383,32 @@ static DBusHandlerResult task_filter(DBusConnection 
*connection,
        if (task == NULL)
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-       if (dbus_message_get_no_reply(message) == FALSE) {
-               DBusMessage *reply;
+       member = dbus_message_get_member(message);
+       if (member == NULL)
+               goto send_reply;
+
+       notify = g_hash_table_lookup(task->notify, member);
+       if (notify == NULL)
+               goto send_reply;
+
+       if (notify->func)
+               reply = notify->func(task, message, notify->data);
+
+send_reply:
+       if (dbus_message_get_no_reply(message) == FALSE &&
+                                               reply == NULL) {
 
                reply = dbus_message_new_method_return(message);
                if (reply == NULL)
                        return DBUS_HANDLER_RESULT_NEED_MEMORY;
+       }
 
+       if (reply != NULL) {
                dbus_connection_send(connection, reply, NULL);
 
                dbus_message_unref(reply);
        }
 
-       member = dbus_message_get_member(message);
-       if (member == NULL)
-               return DBUS_HANDLER_RESULT_HANDLED;
-
-       notify = g_hash_table_lookup(task->notify, member);
-       if (notify == NULL)
-               return DBUS_HANDLER_RESULT_HANDLED;
-
-       if (notify->func)
-               notify->func(task, message, notify->data);
-
        return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-- 
1.7.1

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to