3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

client: Unify device sibling interface arg completion

Station, WSC, Ad-Hoc and AP family_arg_completion functions were
identical except for which commands they were referencing and the
interface type they were interested in.  Combine all these into a single
function.
This commit is contained in:
Denis Kenzior 2018-09-14 22:58:10 -05:00
parent d347100ac2
commit 405de7019c
6 changed files with 22 additions and 140 deletions

View File

@ -229,31 +229,8 @@ static const struct command ad_hoc_commands[] = {
static char *family_arg_completion(const char *text, int state)
{
static bool first_pass;
static size_t index;
static size_t len;
const char *cmd;
if (!state) {
index = 0;
len = strlen(text);
first_pass = true;
}
while ((cmd = ad_hoc_commands[index].cmd)) {
if (ad_hoc_commands[index++].entity)
continue;
if (!strncmp(cmd, text, len))
return l_strdup(cmd);
}
if (first_pass) {
state = 0;
first_pass = false;
}
return device_ad_hoc_family_arg_completion(text, state);
return device_arg_completion(text, state, ad_hoc_commands,
IWD_AD_HOC_INTERFACE);
}
static char *entity_arg_completion(const char *text, int state)

View File

@ -201,31 +201,8 @@ static const struct command ap_commands[] = {
static char *family_arg_completion(const char *text, int state)
{
static bool first_pass;
static size_t index;
static size_t len;
const char *cmd;
if (!state) {
index = 0;
len = strlen(text);
first_pass = true;
}
while ((cmd = ap_commands[index].cmd)) {
if (ap_commands[index++].entity)
continue;
if (!strncmp(cmd, text, len))
return l_strdup(cmd);
}
if (first_pass) {
state = 0;
first_pass = false;
}
return device_ap_family_arg_completion(text, state);
return device_arg_completion(text, state, ap_commands,
IWD_ACCESS_POINT_INTERFACE);
}
static char *entity_arg_completion(const char *text, int state)

View File

@ -435,39 +435,9 @@ static const struct command device_commands[] = {
{ }
};
char *device_wsc_family_arg_completion(const char *text, int state)
{
return proxy_property_str_completion(&device_interface_type,
match_by_partial_name,
"Name", text, state,
IWD_WSC_INTERFACE);
}
char *device_ap_family_arg_completion(const char *text, int state)
{
return proxy_property_str_completion(&device_interface_type,
match_by_partial_name,
"Name", text, state,
IWD_ACCESS_POINT_INTERFACE);
}
char *device_ad_hoc_family_arg_completion(const char *text, int state)
{
return proxy_property_str_completion(&device_interface_type,
match_by_partial_name,
"Name", text, state,
IWD_AD_HOC_INTERFACE);
}
char *device_station_family_arg_completion(const char *text, int state)
{
return proxy_property_str_completion(&device_interface_type,
match_by_partial_name,
"Name", text, state,
IWD_STATION_INTERFACE);
}
static char *family_arg_completion(const char *text, int state)
char *device_arg_completion(const char *text, int state,
const struct command *commands,
const char *extra_interface)
{
static bool first_pass;
static size_t index;
@ -480,8 +450,8 @@ static char *family_arg_completion(const char *text, int state)
first_pass = true;
}
while ((cmd = device_commands[index].cmd)) {
if (device_commands[index++].entity)
while ((cmd = commands[index].cmd)) {
if (commands[index++].entity)
continue;
if (!strncmp(cmd, text, len))
@ -495,7 +465,12 @@ static char *family_arg_completion(const char *text, int state)
return proxy_property_str_completion(&device_interface_type,
match_by_partial_name, "Name",
text, state, NULL);
text, state, extra_interface);
}
static char *family_arg_completion(const char *text, int state)
{
return device_arg_completion(text, state, device_commands, NULL);
}
static char *entity_arg_completion(const char *text, int state)

View File

@ -22,10 +22,9 @@
struct proxy_interface;
char *device_wsc_family_arg_completion(const char *text, int state);
char *device_ap_family_arg_completion(const char *text, int state);
char *device_ad_hoc_family_arg_completion(const char *text, int state);
char *device_station_family_arg_completion(const char *text, int state);
char *device_arg_completion(const char *text, int state,
const struct command *commands,
const char *extra_interface);
const struct proxy_interface *device_proxy_find_by_name(const char *name);
const struct proxy_interface *device_proxy_find(const char *device_name,

View File

@ -494,31 +494,8 @@ static const struct command station_commands[] = {
static char *family_arg_completion(const char *text, int state)
{
static bool first_pass;
static size_t index;
static size_t len;
const char *cmd;
if (!state) {
index = 0;
len = strlen(text);
first_pass = true;
}
while ((cmd = station_commands[index].cmd)) {
if (station_commands[index++].entity)
continue;
if (!strncmp(cmd, text, len))
return l_strdup(cmd);
}
if (first_pass) {
state = 0;
first_pass = false;
}
return device_station_family_arg_completion(text, state);
return device_arg_completion(text, state, station_commands,
IWD_STATION_INTERFACE);
}
static char *entity_arg_completion(const char *text, int state)

View File

@ -214,31 +214,8 @@ static const struct command wsc_commands[] = {
static char *family_arg_completion(const char *text, int state)
{
static bool first_pass;
static size_t index;
static size_t len;
const char *cmd;
if (!state) {
index = 0;
len = strlen(text);
first_pass = true;
}
while ((cmd = wsc_commands[index].cmd)) {
if (wsc_commands[index++].entity)
continue;
if (!strncmp(cmd, text, len))
return l_strdup(cmd);
}
if (first_pass) {
state = 0;
first_pass = false;
}
return device_wsc_family_arg_completion(text, state);
return device_arg_completion(text, state, wsc_commands,
IWD_WSC_INTERFACE);
}
static char *entity_arg_completion(const char *text, int state)