task: Allow vpn plugins to send reply
authorMohamed Abbas <mabbas@linux.intel.com>
Tue, 15 Nov 2011 11:06:15 +0000 (13:06 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 15 Nov 2011 12:41:44 +0000 (13:41 +0100)
Change task notify to allow client to send dbus reply. This
will allow vpn plugin to send requested user/password info.

include/task.h
plugins/vpn.c
src/task.c

index bde2a29..d93df2d 100644 (file)
@@ -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);
index 226fabe..9f49f32 100644 (file)
@@ -202,7 +202,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;
@@ -215,11 +215,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) {
@@ -244,6 +244,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)
index 41710cd..d26d617 100644 (file)
@@ -372,6 +372,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;
@@ -388,29 +389,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;
 }