commit 0a1cd372283614d663d6745b544ca82dfab325f0
parent 27ae3ce14da1dce8ef7929d1d0488896d80a0ee0
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Wed, 18 Sep 2019 15:18:29 -0700
client: Enable lookup of command options with no arguments.
Previously, command_option_get used to return NULL in the following
two scenarios: when command-line option with a such name didn’t exists
or its argument was not provided. This worked great for the cmd-line
options with the required arguments. With introduction of the cmd-line
options with no or optional arguments the function was changed to return
a boolean value indicating the existence of a such option and then, if
it had an argument - value_out variable would have been set.
Thereafter, this patch modifies the current usages of command_option_get.
Note, in these particular applications of command_option_get there is no
need to check the returned value from command_option_get, since these
options have the required arguments and we can only check if the value_out
parameter has been set or not.
Diffstat:
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/client/agent.c b/client/agent.c
@@ -66,9 +66,9 @@ static struct l_dbus_message *request_passphrase_command_option(
struct l_dbus_message *message)
{
struct l_dbus_message *reply;
- const char *passphrase;
+ const char *passphrase = NULL;
- passphrase = command_option_get(COMMAND_OPTION_PASSPHRASE);
+ command_option_get(COMMAND_OPTION_PASSPHRASE, &passphrase);
if (!passphrase)
return NULL;
@@ -154,14 +154,14 @@ static struct l_dbus_message *request_username_and_password_command_option(
struct l_dbus_message *message)
{
struct l_dbus_message *reply;
- const char *username;
- const char *password;
+ const char *username = NULL;
+ const char *password = NULL;
- username = command_option_get(COMMAND_OPTION_USERNAME);
+ command_option_get(COMMAND_OPTION_USERNAME, &username);
if (!username)
return NULL;
- password = command_option_get(COMMAND_OPTION_PASSWORD);
+ command_option_get(COMMAND_OPTION_PASSWORD, &password);
if (!password)
return NULL;
@@ -213,7 +213,7 @@ static struct l_dbus_message *request_user_password_command_option(
struct l_dbus_message *reply;
const char *password;
- password = command_option_get(COMMAND_OPTION_PASSWORD);
+ command_option_get(COMMAND_OPTION_PASSWORD, &password);
if (!password)
return NULL;
diff --git a/client/command.c b/client/command.c
@@ -56,7 +56,7 @@ static void command_options_destroy(void *data)
l_free(option);
}
-const char *command_option_get(const char *name)
+bool command_option_get(const char *name, const char **value_out)
{
const struct l_queue_entry *entry;
@@ -67,10 +67,13 @@ const char *command_option_get(const char *name)
if (strcmp(option->name, name))
continue;
- return option->value;
+ if (value_out)
+ *value_out = option->value;
+
+ return true;
}
- return NULL;
+ return false;
}
bool command_has_options(void)
diff --git a/client/command.h b/client/command.h
@@ -56,7 +56,7 @@ struct command_family {
void (*reset_default_entity)(void);
};
-const char *command_option_get(const char *name);
+bool command_option_get(const char *name, const char **value_out);
bool command_has_options(void);
bool command_line_find_token(const char *token, uint8_t num_to_inspect);