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

client: add completion for proxy property names and values

This commit is contained in:
Tim Kourt 2018-07-25 12:54:42 -07:00 committed by Denis Kenzior
parent 1e78ed5a7d
commit 6ba707fca8
2 changed files with 82 additions and 0 deletions

View File

@ -30,6 +30,8 @@
#include "agent-manager.h"
#include "dbus-proxy.h"
#include "display.h"
#include "command.h"
#include "properties.h"
#define IWD_SERVICE "net.connman.iwd"
#define IWD_ROOT_PATH "/"
@ -175,6 +177,80 @@ char *proxy_property_str_completion(const struct proxy_interface_type *type,
return NULL;
}
static char *proxy_property_completion_value_options(
const struct property_value_options *options,
const char *text, int state)
{
static int index;
static int len;
const char *opt;
if (!state) {
index = 0;
len = strlen(text);
}
while ((opt = options[index++].value_str)) {
if (strncmp(opt, text, len))
continue;
return l_strdup(opt);
}
return NULL;
}
char *proxy_property_completion(
const struct proxy_interface_property *properties,
const char *text, int state)
{
static size_t i;
static size_t j;
static size_t len;
static bool first_pass;
const char *name;
if (!state) {
j = 0;
first_pass = true;
}
while (first_pass && (name = properties[j].name)) {
if (!properties[j].is_read_write)
goto next;
if (!command_line_find_token(name, 2))
goto next;
if (!properties[j].options)
goto next;
return proxy_property_completion_value_options(
properties[j].options, text,
state);
next:
j++;
}
if (first_pass) {
i = 0;
first_pass = false;
len = strlen(text);
}
while ((name = properties[i].name)) {
if (!properties[i++].is_read_write)
continue;
if (strncmp(name, text, len))
continue;
return l_strdup(name);
}
return NULL;
}
static const struct proxy_interface_property *proxy_property_find(
const struct proxy_interface_property *types,
const char *name)

View File

@ -23,6 +23,7 @@
#include <stdio.h>
struct proxy_interface;
struct property_value_options;
#define IWD_ADAPTER_INTERFACE "net.connman.iwd.Adapter"
#define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
@ -40,6 +41,7 @@ struct proxy_interface_property {
const bool is_read_write;
bool (*append)(struct l_dbus_message_builder *builder,
const char *value_str);
const struct property_value_options *options;
};
struct proxy_interface_type_ops {
@ -59,6 +61,10 @@ struct proxy_interface_type {
const struct proxy_interface_type_ops *ops;
};
char *proxy_property_completion(
const struct proxy_interface_property *properties,
const char *text, int state);
bool proxy_property_set(const struct proxy_interface *proxy, const char *name,
const char *value_str, l_dbus_message_func_t callback);