mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
client: refactor cmd_connect() and add find_network()
This will do all the lookup/searching needed to find a network proxy object.
This commit is contained in:
parent
0d7ff8ebd9
commit
73c79dbd41
@ -283,28 +283,26 @@ static char *connect_cmd_arg_completion(const char *text, int state,
|
|||||||
return network_name_completion(device, text, state);
|
return network_name_completion(device, text, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_status cmd_connect(const char *device_name,
|
static const struct proxy_interface *find_network(const char *device_name,
|
||||||
char **argv, int argc)
|
const char *name,
|
||||||
|
const char *type)
|
||||||
{
|
{
|
||||||
struct network_args network_args;
|
struct network_args network_args;
|
||||||
struct l_queue *match;
|
struct l_queue *match;
|
||||||
const struct proxy_interface *network_proxy;
|
const struct proxy_interface *network_proxy;
|
||||||
const struct proxy_interface *device_proxy;
|
const struct proxy_interface *device_proxy;
|
||||||
|
|
||||||
if (argc < 1)
|
|
||||||
return CMD_STATUS_INVALID_ARGS;
|
|
||||||
|
|
||||||
device_proxy = device_proxy_find_by_name(device_name);
|
device_proxy = device_proxy_find_by_name(device_name);
|
||||||
if (!device_proxy)
|
if (!device_proxy)
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return NULL;
|
||||||
|
|
||||||
network_args.name = argv[0];
|
network_args.name = name;
|
||||||
network_args.type = argc >= 2 ? argv[1] : NULL;
|
network_args.type = type;
|
||||||
|
|
||||||
match = network_match_by_device_and_args(device_proxy, &network_args);
|
match = network_match_by_device_and_args(device_proxy, &network_args);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
display("Invalid network name '%s'\n", network_args.name);
|
display("Invalid network name '%s'\n", network_args.name);
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l_queue_length(match) > 1) {
|
if (l_queue_length(match) > 1) {
|
||||||
@ -315,11 +313,28 @@ static enum cmd_status cmd_connect(const char *device_name,
|
|||||||
|
|
||||||
l_queue_destroy(match, NULL);
|
l_queue_destroy(match, NULL);
|
||||||
|
|
||||||
return CMD_STATUS_INVALID_VALUE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
network_proxy = l_queue_pop_head(match);
|
network_proxy = l_queue_pop_head(match);
|
||||||
l_queue_destroy(match, NULL);
|
l_queue_destroy(match, NULL);
|
||||||
|
|
||||||
|
return network_proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum cmd_status cmd_connect(const char *device_name,
|
||||||
|
char **argv, int argc)
|
||||||
|
{
|
||||||
|
const struct proxy_interface *network_proxy;
|
||||||
|
|
||||||
|
if (argc < 1)
|
||||||
|
return CMD_STATUS_INVALID_ARGS;
|
||||||
|
|
||||||
|
network_proxy = find_network(device_name, argv[0],
|
||||||
|
argc >= 2 ? argv[1] : NULL);
|
||||||
|
if (!network_proxy)
|
||||||
|
return CMD_STATUS_INVALID_VALUE;
|
||||||
|
|
||||||
network_connect(network_proxy);
|
network_connect(network_proxy);
|
||||||
|
|
||||||
return CMD_STATUS_TRIGGERED;
|
return CMD_STATUS_TRIGGERED;
|
||||||
|
Loading…
Reference in New Issue
Block a user