[PATCH 0/8] Connmanctl command completion
Hi, Here's some code adding command completion for most of connmanctl. 'config' and 'session' commands completion has initial completion support, but not all. Cheers, Patrik Patrik Flykt (8): client: Remove extra string duplication when completing commands client: Export command line word count function client: Add helper function for ending readline completion client: Complete only one service or technology where appropriate client: Add on/off completion support for agent modes client: Add completion for tether command client: Add support for monitor command completion client: Add initial completion for config and session commands client/commands.c | 162 ++ client/input.c| 29 +++--- client/input.h| 2 + 3 files changed, 159 insertions(+), 34 deletions(-) -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 8/8] client: Add initial completion for config and session commands
Initial support for config and session completion includes only option completion and service name completion for config commands. --- client/commands.c | 17 +++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/commands.c b/client/commands.c index 82fa782..6b555f7 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1992,6 +1992,19 @@ static char *lookup_monitor(const char *text, int state) return NULL; } +static char *lookup_config(const char *text, int state) +{ + if (__connmanctl_input_calc_level() 2) + return lookup_service(text, state); + + return lookup_options(config_options, text, state); +} + +static char *lookup_session(const char *text, int state) +{ + return lookup_options(session_options, text, state); +} + static const struct { const char *cmd; const char *argument; @@ -2025,7 +2038,7 @@ static const struct { { disconnect, service,NULL,cmd_disconnect, Disconnect a given service, lookup_service_arg }, { config, service,config_options, cmd_config, - Set service configuration options, lookup_service }, + Set service configuration options, lookup_config }, { monitor, [off],monitor_options, cmd_monitor, Monitor signals from interfaces, lookup_monitor }, { agent, on|off, NULL,cmd_agent, @@ -2035,7 +2048,7 @@ static const struct { { vpnagent, on|off, NULL,cmd_vpnagent, VPN Agent mode, lookup_agent }, { session, on|off|connect|disconnect|config, session_options, - cmd_session, Enable or disable a session, NULL }, + cmd_session, Enable or disable a session, lookup_session }, { help, NULL, NULL,cmd_help, Show help, NULL }, { exit, NULL, NULL,cmd_exit, -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 5/8] client: Add on/off completion support for agent modes
--- client/commands.c | 38 -- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/client/commands.c b/client/commands.c index 4cc8336..5625a86 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1867,6 +1867,40 @@ static char *lookup_technology_offline(const char *text, int state) return NULL; } +static char *lookup_on_off(const char *text, int state) +{ + char *onoff[] = { on, off, NULL }; + static int idx = 0; + static int len = 0; + + char *str; + + if (!state) { + idx = 0; + len = strlen(text); + } + + while (onoff[idx]) { + str = onoff[idx]; + idx++; + + if (!strncmp(text, str, len)) + return strdup(str); + } + + return NULL; +} + +static char *lookup_agent(const char *text, int state) +{ + if (__connmanctl_input_calc_level() 1) { + __connmanctl_input_lookup_end(); + return NULL; + } + + return lookup_on_off(text, state); +} + static struct connman_option service_options[] = { {properties, 'p', [service] (obsolete)}, { NULL, } @@ -1940,11 +1974,11 @@ static const struct { { monitor, [off],monitor_options, cmd_monitor, Monitor signals from interfaces, NULL }, { agent, on|off, NULL,cmd_agent, - Agent mode, NULL }, + Agent mode, lookup_agent }, {vpnconnections, [connection], NULL, cmd_vpnconnections, Display VPN connections, NULL }, { vpnagent, on|off, NULL,cmd_vpnagent, - VPN Agent mode, NULL }, + VPN Agent mode, lookup_agent }, { session, on|off|connect|disconnect|config, session_options, cmd_session, Enable or disable a session, NULL }, { help, NULL, NULL,cmd_help, -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 3/8] client: Add helper function for ending readline completion
This helper is useful in keeping readline functionality contained within client/input[hc] only. --- client/input.c | 5 + client/input.h | 1 + 2 files changed, 6 insertions(+) diff --git a/client/input.c b/client/input.c index 67ccbf8..1470cb6 100644 --- a/client/input.c +++ b/client/input.c @@ -157,6 +157,11 @@ int __connmanctl_input_calc_level(void) return count; } +void __connmanctl_input_lookup_end(void) +{ + rl_attempted_completion_over = 1; +} + static char **complete_command(const char *text, int start, int end) { if (start == 0) { diff --git a/client/input.h b/client/input.h index abe45c0..a283e51 100644 --- a/client/input.h +++ b/client/input.h @@ -34,6 +34,7 @@ bool __connmanctl_is_interactive(void); void __connmanctl_save_rl(void); void __connmanctl_redraw_rl(void); int __connmanctl_input_calc_level(void); +void __connmanctl_input_lookup_end(void); typedef void (* connmanctl_input_func_t) (char *input, void *user_data); void __connmanctl_agent_mode(const char *prompt, connmanctl_input_func_t input_handler, void *user_data); -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 2/8] client: Export command line word count function
Export the command line word count function and always use readline input line. --- client/input.c | 6 -- client/input.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/input.c b/client/input.c index 0af1fd4..67ccbf8 100644 --- a/client/input.c +++ b/client/input.c @@ -136,10 +136,12 @@ static char **complete_agent(const char *text, int start, int end) } /* Return how many parameters we have typed */ -static int calc_level(char *line) +int __connmanctl_input_calc_level(void) { int count = 0; - char *ptr = line; + char *ptr; + + ptr = rl_line_buffer; while (*ptr) { if (*ptr == ' ') { diff --git a/client/input.h b/client/input.h index fb80077..abe45c0 100644 --- a/client/input.h +++ b/client/input.h @@ -33,6 +33,7 @@ void __connmanctl_quit(void); bool __connmanctl_is_interactive(void); void __connmanctl_save_rl(void); void __connmanctl_redraw_rl(void); +int __connmanctl_input_calc_level(void); typedef void (* connmanctl_input_func_t) (char *input, void *user_data); void __connmanctl_agent_mode(const char *prompt, connmanctl_input_func_t input_handler, void *user_data); -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 7/8] client: Add support for monitor command completion
Add a helper function for matching monitor arguments. First complete using this helper function, then with on/off. --- client/commands.c | 41 - 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/client/commands.c b/client/commands.c index c0059c0..82fa782 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1953,6 +1953,45 @@ static struct connman_option session_options[] = { { NULL, } }; +static char *lookup_options(struct connman_option *options, const char *text, + int state) +{ + static int idx = 0; + static int len = 0; + const char *str; + + if (state == 0) { + idx = 0; + len = strlen(text); + } + + while (options[idx].name) { + str = options[idx].name; + idx++; + + if (str strncmp(text, str, len) == 0) + return strdup(str); + } + + return NULL; +} + +static char *lookup_monitor(const char *text, int state) +{ + int level; + + level = __connmanctl_input_calc_level(); + + if (level 2) + return lookup_options(monitor_options, text, state); + + if (level == 2) + return lookup_on_off(text, state); + + __connmanctl_input_lookup_end(); + return NULL; +} + static const struct { const char *cmd; const char *argument; @@ -1988,7 +2027,7 @@ static const struct { { config, service,config_options, cmd_config, Set service configuration options, lookup_service }, { monitor, [off],monitor_options, cmd_monitor, - Monitor signals from interfaces, NULL }, + Monitor signals from interfaces, lookup_monitor }, { agent, on|off, NULL,cmd_agent, Agent mode, lookup_agent }, {vpnconnections, [connection], NULL, cmd_vpnconnections, -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 1/8] client: Remove extra string duplication when completing commands
Update the command argument completion callback function __connmanctl_get_lookup_func() to accept the full command line typed so far. In addition to comparing the input line against each command in turn, check also that the input line ends with a space after the command. This allows removal of the string duplication when looking for the command. Also, allow completion if there is a command argument completion callback function. If none found, there is nothing to complete. --- client/commands.c | 14 -- client/input.c| 24 +--- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/client/commands.c b/client/commands.c index 57a72e8..23b6de8 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1970,10 +1970,20 @@ static int cmd_help(char *args[], int num, struct connman_option *options) __connmanctl_lookup_cb __connmanctl_get_lookup_func(const char *text) { - int i; + int i, cmdlen, textlen; + + if (!text) + return NULL; + + textlen = strlen(text); for (i = 0; cmd_table[i].cmd; i++) { - if (g_strcmp0(cmd_table[i].cmd, text) == 0) + cmdlen = strlen(cmd_table[i].cmd); + + if (textlen cmdlen text[cmdlen] != ' ') + continue; + + if (strncmp(cmd_table[i].cmd, text, cmdlen) == 0) return cmd_table[i].cb; } diff --git a/client/input.c b/client/input.c index 719101d..0af1fd4 100644 --- a/client/input.c +++ b/client/input.c @@ -155,18 +155,6 @@ static int calc_level(char *line) return count; } -static char *get_command_name(char *line) -{ - char *start, *ptr; - - start = ptr = line; - - while (*ptr *ptr != ' ') - ptr++; - - return g_strndup(start, ptr - start); -} - static char **complete_command(const char *text, int start, int end) { if (start == 0) { @@ -175,24 +163,14 @@ static char **complete_command(const char *text, int start, int end) } else { __connmanctl_lookup_cb cb; - char *current_command; char **str = NULL; - if (calc_level(rl_line_buffer) 1) { - rl_attempted_completion_over = 1; - return NULL; - } - - current_command = get_command_name(rl_line_buffer); - - cb = __connmanctl_get_lookup_func(current_command); + cb = __connmanctl_get_lookup_func(rl_line_buffer); if (cb) str = rl_completion_matches(text, cb); else rl_attempted_completion_over = 1; - g_free(current_command); - return str; } } -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 6/8] client: Add completion for tether command
First complete with technology, after that complete with on/off. --- client/commands.c | 18 +- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/commands.c b/client/commands.c index 5625a86..c0059c0 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1891,6 +1891,22 @@ static char *lookup_on_off(const char *text, int state) return NULL; } +static char *lookup_tether(const char *text, int state) +{ + int level; + + level = __connmanctl_input_calc_level(); + if (level 2) + return lookup_technology(text, state); + + if (level == 2) + return lookup_on_off(text, state); + + __connmanctl_input_lookup_end(); + + return NULL; +} + static char *lookup_agent(const char *text, int state) { if (__connmanctl_input_calc_level() 1) { @@ -1959,7 +1975,7 @@ static const struct { wifi [on|off] ssid passphrase , NULL,cmd_tether, Enable, disable tethering, set SSID and passphrase for wifi, - NULL }, + lookup_tether }, { services, [service], service_options, cmd_services, Display services, lookup_service_arg }, { scan, technology, NULL,cmd_scan, -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 4/8] client: Complete only one service or technology where appropriate
Create helper functions for completing only one service or technology and use them with enable, disable, services, scan, connect and disconnect commands. --- client/commands.c | 36 +++- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/client/commands.c b/client/commands.c index 23b6de8..4cc8336 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1796,6 +1796,16 @@ static char *lookup_service(const char *text, int state) return NULL; } +static char *lookup_service_arg(const char *text, int state) +{ + if (__connmanctl_input_calc_level() 1) { + __connmanctl_input_lookup_end(); + return NULL; + } + + return lookup_service(text, state); +} + static char *lookup_technology(const char *text, int state) { static int len = 0; @@ -1816,12 +1826,27 @@ static char *lookup_technology(const char *text, int state) return NULL; } +static char *lookup_technology_arg(const char *text, int state) +{ + if (__connmanctl_input_calc_level() 1) { + __connmanctl_input_lookup_end(); + return NULL; + } + + return lookup_technology(text, state); +} + static char *lookup_technology_offline(const char *text, int state) { static int len = 0; static bool end = false; char *str; + if (__connmanctl_input_calc_level() 1) { + __connmanctl_input_lookup_end(); + return NULL; + } + if (state == 0) { len = strlen(text); end = false; @@ -1900,15 +1925,16 @@ static const struct { wifi [on|off] ssid passphrase , NULL,cmd_tether, Enable, disable tethering, set SSID and passphrase for wifi, - lookup_technology }, + NULL }, { services, [service], service_options, cmd_services, - Display services, lookup_service }, + Display services, lookup_service_arg }, { scan, technology, NULL,cmd_scan, - Scans for new services for given technology, lookup_technology }, + Scans for new services for given technology, + lookup_technology_arg }, { connect, service,NULL,cmd_connect, - Connect a given service, lookup_service }, + Connect a given service, lookup_service_arg }, { disconnect, service,NULL,cmd_disconnect, - Disconnect a given service, lookup_service }, + Disconnect a given service, lookup_service_arg }, { config, service,config_options, cmd_config, Set service configuration options, lookup_service }, { monitor, [off],monitor_options, cmd_monitor, -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
Re: Connman doesn't update localtime while setting timezone
On Sun, 2013-12-22 at 01:07 +0200, Yevhen Kyriukha wrote: I've set TimezoneUpdates property to manual and changed time zone with setting Timezone property. After that I expect that local time will be changed also, but it doesn't. date command shows old UTC time. I have all proper timezone info in /usr/share/zoneinfo and noticed that /etc/localtime points to a proper timezone. Just tested, works fine here. Probably depends on the rest of your system? Cheers, Patrik ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH] test: Add script for setting timezone
Notice that the Clock API is experimental and that the 'TimezoneUpdates' property must be set to 'manual'. --- test/set-timezone | 22 ++ 1 file changed, 22 insertions(+) create mode 100755 test/set-timezone diff --git a/test/set-timezone b/test/set-timezone new file mode 100755 index 000..4cbeaea --- /dev/null +++ b/test/set-timezone @@ -0,0 +1,22 @@ +#!/usr/bin/python + +import sys +import dbus + +if (len(sys.argv) != 2): + print Usage: %s timezone % (sys.argv[0]) + sys.exit(1) + +bus = dbus.SystemBus() + +clock = dbus.Interface(bus.get_object('net.connman', '/'), + 'net.connman.Clock') + +print Setting timezone to %s % (sys.argv[1]) + +try: + clock.SetProperty(Timezone, dbus.String(sys.argv[1], variant_level=1), + signature=dbus.Signature('sv')) +except dbus.exceptions.DBusException, e_msg: + print e_msg + -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 3/3] wifi: Remove WiFi.AgentPassphrase from the wifi plugin
Remove WiFi.AgentPassphrase as it no longer is present in the network struct. --- plugins/wifi.c | 18 +++--- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/plugins/wifi.c b/plugins/wifi.c index 533d6df..b820540 100644 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2012 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2014 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -1277,7 +1277,7 @@ static GSupplicantSecurity network_security(const char *security) static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network) { - const char *security, *passphrase, *agent_passphrase; + const char *security; memset(ssid, 0, sizeof(*ssid)); ssid-mode = G_SUPPLICANT_MODE_INFRA; @@ -1286,20 +1286,8 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network) ssid-scan_ssid = 1; security = connman_network_get_string(network, WiFi.Security); ssid-security = network_security(security); - passphrase = connman_network_get_string(network, + ssid-passphrase = connman_network_get_string(network, WiFi.Passphrase); - if (!passphrase || strlen(passphrase) == 0) { - - /* Use agent provided passphrase as a fallback */ - agent_passphrase = connman_network_get_string(network, - WiFi.AgentPassphrase); - - if (!agent_passphrase || strlen(agent_passphrase) == 0) - ssid-passphrase = NULL; - else - ssid-passphrase = agent_passphrase; - } else - ssid-passphrase = passphrase; ssid-eap = connman_network_get_string(network, WiFi.EAP); -- 1.8.5.2 ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman
[PATCH 1/3] service: Remove duplicate EAP AgentPassphrase information
EAP AgentPassphrase has been set on replies from the agent and removed on any error. It has been used by the wifi plugin as a backup if the normal wifi passphrase is unset. The normal passphrase is removed only on invalid key errors with a comment indicating that EAP does not always signal invalid key errors although the key is incorrect. Thus the implementation can end up in a situation where the normal passphrase is wrong but not removed resulting in unnecessarily retrying with an erroneous key. --- src/connman.h | 4 +--- src/service.c | 36 +++- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/connman.h b/src/connman.h index bf59dbf..f18b2f3 100644 --- a/src/connman.h +++ b/src/connman.h @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2012 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2014 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -756,8 +756,6 @@ void __connman_service_set_agent_identity(struct connman_service *service, int __connman_service_set_passphrase(struct connman_service *service, const char *passphrase); const char *__connman_service_get_passphrase(struct connman_service *service); -void __connman_service_set_agent_passphrase(struct connman_service *service, - const char *agent_passphrase); int __connman_service_reset_ipconfig(struct connman_service *service, enum connman_ipconfig_type type, DBusMessageIter *array, enum connman_service_state *new_state); diff --git a/src/service.c b/src/service.c index 33cce14..212c5a4 100644 --- a/src/service.c +++ b/src/service.c @@ -84,7 +84,6 @@ struct connman_service { unsigned int order; char *name; char *passphrase; - char *agent_passphrase; bool roaming; struct connman_ipconfig *ipconfig_ipv4; struct connman_ipconfig *ipconfig_ipv6; @@ -2809,20 +2808,6 @@ const char *__connman_service_get_passphrase(struct connman_service *service) return service-passphrase; } -void __connman_service_set_agent_passphrase(struct connman_service *service, - const char *agent_passphrase) -{ - if (service-hidden) - return; - g_free(service-agent_passphrase); - service-agent_passphrase = g_strdup(agent_passphrase); - - if (service-network) - connman_network_set_string(service-network, - WiFi.AgentPassphrase, - service-agent_passphrase); -} - static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -3982,9 +3967,6 @@ bool __connman_service_remove(struct connman_service *service) g_free(service-passphrase); service-passphrase = NULL; - g_free(service-agent_passphrase); - service-agent_passphrase = NULL; - g_free(service-identity); service-identity = NULL; @@ -4435,7 +4417,6 @@ static void service_free(gpointer user_data) g_free(service-pac); g_free(service-name); g_free(service-passphrase); - g_free(service-agent_passphrase); g_free(service-identifier); g_free(service-eap); g_free(service-identity); @@ -5004,12 +4985,10 @@ int __connman_service_add_passphrase(struct connman_service *service, switch (service-security) { case CONNMAN_SERVICE_SECURITY_WEP: case CONNMAN_SERVICE_SECURITY_PSK: - err = __connman_service_set_passphrase(service, passphrase); - break; case CONNMAN_SERVICE_SECURITY_8021X: - __connman_service_set_agent_passphrase(service, - passphrase); + err = __connman_service_set_passphrase(service, passphrase); break; + case CONNMAN_SERVICE_SECURITY_UNKNOWN: case CONNMAN_SERVICE_SECURITY_NONE: case CONNMAN_SERVICE_SECURITY_WPA: @@ -5424,15 +5403,15 @@ int __connman_service_indicate_error(struct connman_service *service, set_error(service, error); - if (service-error == CONNMAN_SERVICE_ERROR_INVALID_KEY) - __connman_service_set_passphrase(service, NULL); - /* * Supplicant does not always return invalid key error for * WPA-EAP so clear the credentials always. */ + if (service-error == CONNMAN_SERVICE_ERROR_INVALID_KEY || + service-security == CONNMAN_SERVICE_SECURITY_8021X) + __connman_service_set_passphrase(service, NULL); + __connman_service_set_agent_identity(service, NULL); -
Re: [RFC 0/1] dhcp: add notifier event when dhcp is renewed
On Tue, 2014-01-07 at 14:29 -0800, Andrew LeCain wrote: I agree that really all we need is the next major event (T1 or T2 expiring) The plugin is pretty simple and just chooses the earliest expiration to wake up. I included all of these statistics for completeness, but if you think it is better to only provide the next wakeup then that will make the plugin even simpler. However, we will also need some indication that it is okay to sleep. For example, when we send our renewal packet at T1 expiration, we need to keep the system awake for a while to wait for the timeout and and recalculate T1, set T2 timeout, etc. Indeed. Only when the T1 or T2 lease reacquisition has happened, should whatever system be notified with the new timeout. I would suggest then that we need two changes to the API: - void (*wakeup_changed) (struct connman_ipconfig *ipconfig); -- notifier called whenever get_next_wakeup will return a valid sleep value. This will happen whenever we can safely enter sleep, such as a successful renew, successful rebind, or expired lease. - time_t connman_ipconfig_get_next_wakeup() -- added to ipconfig.h to provide the next wakeup time (min(T1, T1 retry, T2, lease_expiration);) Because of the accounting of T1 and T2 in gdhcp, it would be easiest to return an absolute time. If the time returned is in the past then assume we should remain awake until we get another wakeup_changed notifier event. No ipconfig involvement here, please. Just something simple indicated in a generic way after a new lease when the next time of an important event will happen. Internal DHCP timers are not interesting to anyone. Link-local is also of concern, with link-local the device needs to be able to defend its autogenerated IP address. That situation must be addressed too, and also the case with IPv6 with or without DHCP. The other obvious catch is to figure out what needs to be done with more than one service connecting at the same time, perhaps wait for all connecting services? At that point let's hope the other network technologies also can wake up the device, otherwise we have a guaranteed weird situation with other devices knowing our IPv4 DHCP, IPv4 link-local, IPv6 or IPv6 DHCP address trying unsuccessfully to connect. Yet another catch is how to wake up on IP packets destined to us via all the other non-WiFi network technologies. Cheers, Patrik ___ connman mailing list connman@connman.net https://lists.connman.net/mailman/listinfo/connman