3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:19:26 +01:00

client: switch to network argument parser

This commit is contained in:
Tim Kourt 2018-03-28 09:26:34 -07:00 committed by Denis Kenzior
parent 68800c5422
commit 5c765bc886
2 changed files with 28 additions and 34 deletions

View File

@ -588,9 +588,7 @@ static enum cmd_status cmd_set_property(const char *device_name, char *args)
static enum cmd_status cmd_connect(const char *device_name, char *args) static enum cmd_status cmd_connect(const char *device_name, char *args)
{ {
char **arg_arr; struct network_args *network_args;
const char *network_name;
const char *network_type;
struct l_queue *match; struct l_queue *match;
const struct device *device; const struct device *device;
const struct l_queue_entry *entry; const struct l_queue_entry *entry;
@ -601,9 +599,10 @@ static enum cmd_status cmd_connect(const char *device_name, char *args)
if (!proxy) if (!proxy)
return CMD_STATUS_INVALID_VALUE; return CMD_STATUS_INVALID_VALUE;
arg_arr = l_strsplit(args, ' '); network_args = network_parse_args(args);
if (!arg_arr || !arg_arr[0]) {
l_strfreev(arg_arr); if (!network_args || !network_args->name) {
network_args_destroy(network_args);
return CMD_STATUS_INVALID_ARGS; return CMD_STATUS_INVALID_ARGS;
} }
@ -613,19 +612,18 @@ static enum cmd_status cmd_connect(const char *device_name, char *args)
if (!device->ordered_networks) { if (!device->ordered_networks) {
display("Use 'get-networks' command to obtain a list of " display("Use 'get-networks' command to obtain a list of "
"available networks first\n"); "available networks first\n");
l_strfreev(arg_arr); network_args_destroy(network_args);
return CMD_STATUS_OK; return CMD_STATUS_OK;
} }
network_name = arg_arr[0];
match = NULL; match = NULL;
for (entry = l_queue_get_entries(device->ordered_networks); entry; for (entry = l_queue_get_entries(device->ordered_networks); entry;
entry = entry->next) { entry = entry->next) {
ordered_network = entry->data; ordered_network = entry->data;
if (strcmp(ordered_network->name, network_name)) if (strcmp(ordered_network->name, network_args->name))
continue; continue;
if (!match) if (!match)
@ -635,31 +633,30 @@ static enum cmd_status cmd_connect(const char *device_name, char *args)
} }
if (!match) { if (!match) {
display("Invalid network name '%s'\n", network_name); display("Invalid network name '%s'\n", network_args->name);
l_strfreev(arg_arr); network_args_destroy(network_args);
return CMD_STATUS_INVALID_VALUE; return CMD_STATUS_INVALID_VALUE;
} }
if (l_queue_length(match) > 1) { if (l_queue_length(match) > 1) {
if (!arg_arr[1]) { if (!network_args->type) {
display("Provided network name is ambiguous. " display("Provided network name is ambiguous. "
"Please specify security type.\n"); "Please specify security type.\n");
l_queue_destroy(match, NULL); l_queue_destroy(match, NULL);
l_strfreev(arg_arr); network_args_destroy(network_args);
return CMD_STATUS_INVALID_VALUE; return CMD_STATUS_INVALID_VALUE;
} }
network_type = arg_arr[1];
ordered_network = NULL; ordered_network = NULL;
for (entry = l_queue_get_entries(match); entry; for (entry = l_queue_get_entries(match); entry;
entry = entry->next) { entry = entry->next) {
ordered_network = entry->data; ordered_network = entry->data;
if (!strcmp(ordered_network->type, network_type)) if (!strcmp(ordered_network->type, network_args->type))
break; break;
} }
} else { } else {
@ -667,7 +664,7 @@ static enum cmd_status cmd_connect(const char *device_name, char *args)
} }
l_queue_destroy(match, NULL); l_queue_destroy(match, NULL);
l_strfreev(arg_arr); network_args_destroy(network_args);
if (!ordered_network) { if (!ordered_network) {
display("No network with specified parameters was found\n"); display("No network with specified parameters was found\n");
@ -713,7 +710,7 @@ static const struct command device_commands[] = {
cmd_set_property, cmd_set_property,
"Set property", false }, "Set property", false },
{ "<wlan>", "connect", { "<wlan>", "connect",
"<network name> [security]", "<\"network name\"> [security]",
cmd_connect, cmd_connect,
"Connect to network", false }, "Connect to network", false },
{ "<wlan>", "disconnect", { "<wlan>", "disconnect",

View File

@ -32,6 +32,7 @@
#include "command.h" #include "command.h"
#include "dbus-proxy.h" #include "dbus-proxy.h"
#include "display.h" #include "display.h"
#include "network.h"
#define IWD_KNOWN_NETWORKS_PATH "/" #define IWD_KNOWN_NETWORKS_PATH "/"
@ -260,9 +261,7 @@ static enum cmd_status cmd_list(const char *entity, char *args)
static enum cmd_status cmd_forget(const char *entity, char *args) static enum cmd_status cmd_forget(const char *entity, char *args)
{ {
char **arg_arr; struct network_args *network_args;
const char *network_name;
const char *network_type;
const struct l_queue_entry *entry; const struct l_queue_entry *entry;
struct known_network *network = NULL; struct known_network *network = NULL;
struct known_network *net; struct known_network *net;
@ -275,14 +274,14 @@ static enum cmd_status cmd_forget(const char *entity, char *args)
if (!proxy) if (!proxy)
return CMD_STATUS_FAILED; return CMD_STATUS_FAILED;
arg_arr = l_strsplit(args, ' '); network_args = network_parse_args(args);
if (!arg_arr || !arg_arr[0]) {
l_strfreev(arg_arr); if (!network_args || !network_args->name) {
network_args_destroy(network_args);
return CMD_STATUS_INVALID_ARGS; return CMD_STATUS_INVALID_ARGS;
} }
network_name = arg_arr[0];
known_networks = proxy_interface_get_data(proxy); known_networks = proxy_interface_get_data(proxy);
match = NULL; match = NULL;
@ -290,7 +289,7 @@ static enum cmd_status cmd_forget(const char *entity, char *args)
entry = entry->next) { entry = entry->next) {
net = entry->data; net = entry->data;
if (strcmp(net->name, network_name)) if (strcmp(net->name, network_args->name))
continue; continue;
if (!match) if (!match)
@ -300,30 +299,28 @@ static enum cmd_status cmd_forget(const char *entity, char *args)
} }
if (!match) { if (!match) {
display("Invalid network name '%s'\n", network_name); display("Invalid network name '%s'\n", network_args->name);
l_strfreev(arg_arr); network_args_destroy(network_args);
return CMD_STATUS_INVALID_VALUE; return CMD_STATUS_INVALID_VALUE;
} }
if (l_queue_length(match) > 1) { if (l_queue_length(match) > 1) {
if (!arg_arr[1]) { if (!network_args->type) {
display("Provided network name is ambiguous. " display("Provided network name is ambiguous. "
"Please specify security type.\n"); "Please specify security type.\n");
l_queue_destroy(match, NULL); l_queue_destroy(match, NULL);
l_strfreev(arg_arr); network_args_destroy(network_args);
return CMD_STATUS_INVALID_VALUE; return CMD_STATUS_INVALID_VALUE;
} }
network_type = arg_arr[1];
for (entry = l_queue_get_entries(match); entry; for (entry = l_queue_get_entries(match); entry;
entry = entry->next) { entry = entry->next) {
net = entry->data; net = entry->data;
if (!strcmp(net->type, network_type)) { if (!strcmp(net->type, network_args->type)) {
network = net; network = net;
break; break;
} }
@ -333,7 +330,7 @@ static enum cmd_status cmd_forget(const char *entity, char *args)
} }
l_queue_destroy(match, NULL); l_queue_destroy(match, NULL);
l_strfreev(arg_arr); network_args_destroy(network_args);
if (!network) { if (!network) {
display("No network with specified parameters was found\n"); display("No network with specified parameters was found\n");
@ -349,7 +346,7 @@ static enum cmd_status cmd_forget(const char *entity, char *args)
static const struct command known_networks_commands[] = { static const struct command known_networks_commands[] = {
{ NULL, "list", NULL, cmd_list, "List known networks", true }, { NULL, "list", NULL, cmd_list, "List known networks", true },
{ NULL, "forget", "<network name> [security]", { NULL, "forget", "<\"network name\"> [security]",
cmd_forget, "Forget known network" }, cmd_forget, "Forget known network" },
{ } { }
}; };