3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

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.
This commit is contained in:
Tim Kourt 2019-09-18 15:18:29 -07:00 committed by Denis Kenzior
parent 27ae3ce14d
commit 0a1cd37228
3 changed files with 14 additions and 11 deletions

View File

@ -66,9 +66,9 @@ static struct l_dbus_message *request_passphrase_command_option(
struct l_dbus_message *message) struct l_dbus_message *message)
{ {
struct l_dbus_message *reply; 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) if (!passphrase)
return NULL; 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 *message)
{ {
struct l_dbus_message *reply; struct l_dbus_message *reply;
const char *username; const char *username = NULL;
const char *password; const char *password = NULL;
username = command_option_get(COMMAND_OPTION_USERNAME); command_option_get(COMMAND_OPTION_USERNAME, &username);
if (!username) if (!username)
return NULL; return NULL;
password = command_option_get(COMMAND_OPTION_PASSWORD); command_option_get(COMMAND_OPTION_PASSWORD, &password);
if (!password) if (!password)
return NULL; return NULL;
@ -213,7 +213,7 @@ static struct l_dbus_message *request_user_password_command_option(
struct l_dbus_message *reply; struct l_dbus_message *reply;
const char *password; const char *password;
password = command_option_get(COMMAND_OPTION_PASSWORD); command_option_get(COMMAND_OPTION_PASSWORD, &password);
if (!password) if (!password)
return NULL; return NULL;

View File

@ -56,7 +56,7 @@ static void command_options_destroy(void *data)
l_free(option); 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; const struct l_queue_entry *entry;
@ -67,10 +67,13 @@ const char *command_option_get(const char *name)
if (strcmp(option->name, name)) if (strcmp(option->name, name))
continue; continue;
return option->value; if (value_out)
*value_out = option->value;
return true;
} }
return NULL; return false;
} }
bool command_has_options(void) bool command_has_options(void)

View File

@ -56,7 +56,7 @@ struct command_family {
void (*reset_default_entity)(void); 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_has_options(void);
bool command_line_find_token(const char *token, uint8_t num_to_inspect); bool command_line_find_token(const char *token, uint8_t num_to_inspect);