eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit d081f5f8719876d5ad54007ea043df0f8de7f278
parent 4fa5a9869bea1d7464837055fa27a902165ef827
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date:   Wed, 10 Apr 2019 15:58:17 -0700

client: Switch known-networks cmd pattern to common scheme

Switch the command pattern to match the common command scheme
where the entity name (network name) follows the command family name:
From
	known-network forget <network name>
To
	known-network <network name> forget

In addition, it extracts the network match by name logic into its
own function for the further reusability. In the case of ambiguity
between the network objects with the same SSID but different security
types the logic asks to specify the security type in addition
to the network name as follows:
	known-network <network name.security> forget

Diffstat:
Mclient/known-networks.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 49 insertions(+), 14 deletions(-)

diff --git a/client/known-networks.c b/client/known-networks.c @@ -234,17 +234,36 @@ static enum cmd_status cmd_list(const char *entity, char **args, int argc) return CMD_STATUS_DONE; } -static enum cmd_status cmd_forget(const char *entity, char **argv, int argc) +static const struct proxy_interface *known_network_proxy_find_by_name( + const char *name) { struct network_args network_args; struct l_queue *match; - const struct proxy_interface *known_network_proxy; + const struct proxy_interface *proxy; - if (argc < 1) - return CMD_STATUS_INVALID_ARGS; + if (!name) + return NULL; + + if (l_str_has_suffix(name, ".psk")) + network_args.type = "psk"; + else if (l_str_has_suffix(name, ".8021x")) + network_args.type = "8021x"; + else if (l_str_has_suffix(name, ".open")) + network_args.type = "open"; + else + network_args.type = NULL; + + if (network_args.type) { + char *dot = strrchr(name, '.'); - network_args.name = argv[0]; - network_args.type = argc >= 2 ? argv[1] : NULL; + if (!dot) + /* This shouldn't ever be the case */ + return NULL; + + *dot = '\0'; + } + + network_args.name = name; match = proxy_interface_find_all(known_network_interface_type.interface, known_network_match, @@ -252,24 +271,40 @@ static enum cmd_status cmd_forget(const char *entity, char **argv, int argc) if (!match) { display("No network with specified parameters was found\n"); - return CMD_STATUS_INVALID_VALUE; + return NULL; } if (l_queue_length(match) > 1) { if (!network_args.type) { display("Provided network name is ambiguous. " - "Please specify security type.\n"); + "Specify network security type as follows:\n"); + display("<\"network name" COLOR_BOLDGRAY ".security" + COLOR_OFF "\">\n"); + display("\twhere '.security' is [.psk | .8021x | " + ".open]\n"); } l_queue_destroy(match, NULL); - return CMD_STATUS_INVALID_VALUE; + return NULL; } - known_network_proxy = l_queue_pop_head(match); + proxy = l_queue_pop_head(match); l_queue_destroy(match, NULL); - proxy_interface_method_call(known_network_proxy, "Forget", "", - check_errors_method_callback); + return proxy; +} + +static enum cmd_status cmd_forget(const char *network_name, char **argv, + int argc) +{ + const struct proxy_interface *proxy = + known_network_proxy_find_by_name(network_name); + + if (!proxy) + return CMD_STATUS_INVALID_ARGS; + + proxy_interface_method_call(proxy, "Forget", "", + check_errors_method_callback); return CMD_STATUS_TRIGGERED; } @@ -284,8 +319,8 @@ static bool match_by_partial_name(const void *a, const void *b) static const struct command known_networks_commands[] = { { NULL, "list", NULL, cmd_list, "List known networks", true }, - { NULL, "forget", "<\"network name\"> [security]", - cmd_forget, "Forget known network" }, + { "<\"network name\">", "forget", NULL, cmd_forget, + "Forget known network" }, { } };