diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index 8e1eaafd..4fcd27e8 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -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) diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index 955ad2ff..c791a1f5 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -23,6 +23,7 @@ #include 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);