client: Avoid printing extra prompt on RequestInput
[platform/upstream/connman.git] / client / agent.c
index bc56494..fe357bf 100644 (file)
@@ -57,11 +57,11 @@ static int confirm_input(char *input)
        int i;
 
        if (input == NULL)
-               return false;
+               return -1;
 
        for (i = 0; input[i] != '\0'; i++)
-               if (isspace(input[i]) != 0)
-                       continue;
+               if (isspace(input[i]) == 0)
+                       break;
 
        if (strcasecmp(&input[i], "yes") == 0 ||
                        strcasecmp(&input[i], "y") == 0)
@@ -69,7 +69,7 @@ static int confirm_input(char *input)
 
        if (strcasecmp(&input[i], "no") == 0 ||
                        strcasecmp(&input[i], "n") == 0)
-               return 1;
+               return 0;
 
        return -1;
 }
@@ -112,7 +112,7 @@ static void pending_command_complete(char *message)
 {
        __connmanctl_save_rl();
 
-       fprintf(stdout, message);
+       fprintf(stdout, "%s", message);
 
        __connmanctl_redraw_rl();
 
@@ -284,6 +284,11 @@ static void request_input_next(void)
 
        g_dbus_send_message(agent_connection, agent_reply.reply);
        agent_reply.reply = NULL;
+
+       pending_message_remove();
+       pending_command_complete("");
+
+       __connmanctl_redraw_rl();
 }
 
 static void request_input_append(const char *attribute, char *value)
@@ -311,13 +316,14 @@ static void request_input_passphrase_return(char *input)
 {
        /* TBD passphrase length checking */
 
-       agent_input[PASSPHRASE].requested = false;
-       request_input_append(agent_input[PASSPHRASE].attribute, input);
+       if (input != NULL && strlen(input) > 0) {
+               agent_input[PASSPHRASE].requested = false;
+               request_input_append(agent_input[PASSPHRASE].attribute, input);
 
-       if (input != NULL && strlen(input) > 0)
                agent_input[WPS].requested = false;
 
-       request_input_next();
+               request_input_next();
+       }
 }
 
 static void request_input_string_return(char *input)
@@ -357,7 +363,6 @@ static DBusMessage *agent_request_input(DBusConnection *connection,
        fprintf(stdout, "Agent RequestInput %s\n", service);
        __connmanctl_dbus_print(&dict, "  ", " = ", "\n");
        fprintf(stdout, "\n");
-       __connmanctl_redraw_rl();
 
        dbus_message_iter_recurse(&iter, &dict);
 
@@ -382,10 +387,11 @@ static DBusMessage *agent_request_input(DBusConnection *connection,
 
                        dbus_message_iter_recurse(&field_entry, &field_value);
 
-                       dbus_message_iter_get_basic(&field_value, &value);
-
-                       if (strcmp(argument, "Type") == 0)
+                       if (strcmp(argument, "Type") == 0) {
+                               dbus_message_iter_get_basic(&field_value,
+                                               &value);
                                attr_type = g_strdup(value);
+                       }
 
                        dbus_message_iter_next(&dict_entry);
                }
@@ -472,8 +478,8 @@ int __connmanctl_agent_register(DBusConnection *connection)
                return 0;
        }
 
-       result = __connmanctl_dbus_method_call(connection, "/",
-                       "net.connman.Manager", "RegisterAgent",
+       result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+                       CONNMAN_PATH, "net.connman.Manager", "RegisterAgent",
                        agent_register_return, connection,
                        DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
 
@@ -513,8 +519,8 @@ int __connmanctl_agent_unregister(DBusConnection *connection)
 
        g_dbus_unregister_interface(connection, agent_path(), AGENT_INTERFACE);
 
-       result = __connmanctl_dbus_method_call(connection, "/",
-                       "net.connman.Manager", "UnregisterAgent",
+       result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+                       CONNMAN_PATH, "net.connman.Manager", "UnregisterAgent",
                        agent_unregister_return, NULL,
                        DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);