From bfbffa1111937e05774bee738dc9e602fa0429fc Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Tue, 25 Apr 2017 18:13:59 -0700 Subject: [PATCH] client: Add 'forget' cmd for known network --- client/command.c | 3 ++ client/command.h | 1 + client/known-networks.c | 86 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/client/command.c b/client/command.c index 2db85e25..322f741f 100644 --- a/client/command.c +++ b/client/command.c @@ -306,6 +306,9 @@ error: display_command_line(family, cmd); break; + case CMD_STATUS_INVALID_VALUE: + break; + case CMD_STATUS_UNSUPPORTED: display_refresh_reset(); diff --git a/client/command.h b/client/command.h index f9211b4b..e4b1dc18 100644 --- a/client/command.h +++ b/client/command.h @@ -25,6 +25,7 @@ typedef char *(*command_completion_func_t) (const char *text, int state); enum cmd_status { CMD_STATUS_OK, CMD_STATUS_INVALID_ARGS, + CMD_STATUS_INVALID_VALUE, CMD_STATUS_UNSUPPORTED, CMD_STATUS_FAILED, }; diff --git a/client/known-networks.c b/client/known-networks.c index aed003cd..970d4c88 100644 --- a/client/known-networks.c +++ b/client/known-networks.c @@ -261,7 +261,91 @@ static enum cmd_status cmd_list(const char *entity, char *args) static enum cmd_status cmd_forget(const char *entity, char *args) { - return CMD_STATUS_UNSUPPORTED; + char **arg_arr; + const char *network_name; + const char *network_type; + const struct l_queue_entry *entry; + struct known_network *network = NULL; + struct known_network *net; + struct l_queue *known_networks; + struct l_queue *match; + struct proxy_interface *proxy = + proxy_interface_find(IWD_KNOWN_NETWORKS_INTREFACE, + IWD_KNOWN_NETWORKS_PATH); + + if (!proxy) + return CMD_STATUS_FAILED; + + arg_arr = l_strsplit(args, ' '); + if (!arg_arr || !arg_arr[0]) { + l_strfreev(arg_arr); + + return CMD_STATUS_INVALID_ARGS; + } + + network_name = arg_arr[0]; + known_networks = proxy_interface_get_data(proxy); + match = NULL; + + for (entry = l_queue_get_entries(known_networks); entry; + entry = entry->next) { + net = entry->data; + + if (strcmp(net->name, network_name)) + continue; + + if (!match) + match = l_queue_new(); + + l_queue_push_tail(match, net); + } + + if (!match) { + display("Invalid network name '%s'\n", network_name); + l_strfreev(arg_arr); + + return CMD_STATUS_INVALID_VALUE; + } + + if (l_queue_length(match) > 1) { + if (!arg_arr[1]) { + display("Provided network name is ambiguous. " + "Please specify security type.\n"); + + l_queue_destroy(match, NULL); + l_strfreev(arg_arr); + + return CMD_STATUS_INVALID_VALUE; + } + + network_type = arg_arr[1]; + + for (entry = l_queue_get_entries(match); entry; + entry = entry->next) { + net = entry->data; + + if (!strcmp(net->type, network_type)) { + network = net; + break; + } + } + } else { + network = l_queue_pop_head(match); + } + + l_queue_destroy(match, NULL); + l_strfreev(arg_arr); + + if (!network) { + display("No network with specified parameters was found\n"); + + return CMD_STATUS_INVALID_VALUE; + } + + proxy_interface_method_call(proxy, "ForgetNetwork", "ss", NULL, + network->name, network->type); + + return CMD_STATUS_OK; } static const struct command known_networks_commands[] = {