diff options
author | Alok Barsode <alok.barsode@linux.intel.com> | 2012-04-05 13:20:18 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-04-05 18:55:49 +0300 |
commit | 447256cd6424680afb92d633ba4ee60e84c6cb77 (patch) | |
tree | d6a601babe60c9f7456acd4e5218b433d9f3ff93 | |
parent | bbd19813c457227a2861c05e9ebc676f8feb7f10 (diff) | |
download | connman-447256cd6424680afb92d633ba4ee60e84c6cb77.tar.gz connman-447256cd6424680afb92d633ba4ee60e84c6cb77.tar.bz2 connman-447256cd6424680afb92d633ba4ee60e84c6cb77.zip |
service: Add Timeservers.Configuration Property
This property helps to add service specific timeservers. These are set by the
user and are per service.
-rw-r--r-- | include/service.h | 1 | ||||
-rw-r--r-- | src/service.c | 79 |
2 files changed, 80 insertions, 0 deletions
diff --git a/include/service.h b/include/service.h index d7aaca5c..b55ea515 100644 --- a/include/service.h +++ b/include/service.h @@ -107,6 +107,7 @@ char *connman_service_get_interface(struct connman_service *service); const char *connman_service_get_domainname(struct connman_service *service); char **connman_service_get_nameservers(struct connman_service *service); +char **connman_service_get_timeservers_config(struct connman_service *service); char **connman_service_get_timeservers(struct connman_service *service); void connman_service_set_proxy_method(struct connman_service *service, enum connman_service_proxy_method method); enum connman_service_proxy_method connman_service_get_proxy_method(struct connman_service *service); diff --git a/src/service.c b/src/service.c index 54d29a66..fd628e8e 100644 --- a/src/service.c +++ b/src/service.c @@ -89,6 +89,7 @@ struct connman_service { char **domains; char *domainname; char **timeservers; + char **timeservers_config; /* 802.1x settings from the config files */ char *eap; char *identity; @@ -408,6 +409,13 @@ static int service_load(struct connman_service *service) service->nameservers_config = NULL; } + service->timeservers_config = g_key_file_get_string_list(keyfile, + service->identifier, "Timeservers", &length, NULL); + if (service->timeservers_config != NULL && length == 0) { + g_strfreev(service->timeservers_config); + service->timeservers_config = NULL; + } + service->domains = g_key_file_get_string_list(keyfile, service->identifier, "Domains", &length, NULL); if (service->domains != NULL && length == 0) { @@ -570,6 +578,16 @@ static int service_save(struct connman_service *service) g_key_file_remove_key(keyfile, service->identifier, "Nameservers", NULL); + if (service->timeservers_config != NULL) { + guint len = g_strv_length(service->timeservers_config); + + g_key_file_set_string_list(keyfile, service->identifier, + "Timeservers", + (const gchar **) service->timeservers_config, len); + } else + g_key_file_remove_key(keyfile, service->identifier, + "Timeservers", NULL); + if (service->domains != NULL) { guint len = g_strv_length(service->domains); @@ -1414,6 +1432,21 @@ static void append_dnsconfig(DBusMessageIter *iter, void *user_data) } } +static void append_tsconfig(DBusMessageIter *iter, void *user_data) +{ + struct connman_service *service = user_data; + int i; + + if (service->timeservers_config == NULL) + return; + + for (i = 0; service->timeservers_config[i]; i++) { + dbus_message_iter_append_basic(iter, + DBUS_TYPE_STRING, + &service->timeservers_config[i]); + } +} + static void append_domain(DBusMessageIter *iter, void *user_data) { struct connman_service *service = user_data; @@ -2034,6 +2067,9 @@ static void append_properties(DBusMessageIter *dict, dbus_bool_t limited, connman_dbus_dict_append_array(dict, "Nameservers.Configuration", DBUS_TYPE_STRING, append_dnsconfig, service); + connman_dbus_dict_append_array(dict, "Timeservers.Configuration", + DBUS_TYPE_STRING, append_tsconfig, service); + connman_dbus_dict_append_array(dict, "Domains", DBUS_TYPE_STRING, append_domain, service); @@ -2172,6 +2208,14 @@ char **connman_service_get_nameservers(struct connman_service *service) return NULL; } +char **connman_service_get_timeservers_config(struct connman_service *service) +{ + if (service == NULL) + return NULL; + + return service->timeservers_config; +} + char **connman_service_get_timeservers(struct connman_service *service) { if (service == NULL) @@ -2764,6 +2808,40 @@ static DBusMessage *set_property(DBusConnection *conn, dns_configuration_changed(service); service_save(service); + } else if (g_str_equal(name, "Timeservers.Configuration") == TRUE) { + DBusMessageIter entry; + GSList *list = NULL; + int count = 0; + + if (type != DBUS_TYPE_ARRAY) + return __connman_error_invalid_arguments(msg); + + dbus_message_iter_recurse(&value, &entry); + + while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) { + const char *val; + dbus_message_iter_get_basic(&entry, &val); + + list = g_slist_prepend(list, strdup(val)); + count++; + + dbus_message_iter_next(&entry); + } + + g_strfreev(service->timeservers_config); + service->timeservers_config = NULL; + + if (list != NULL) { + service->timeservers_config = g_new0(char *, count+1); + + while (list != NULL) { + count--; + service->timeservers_config[count] = list->data; + list = g_slist_delete_link(list, list); + }; + } + + service_save(service); } else if (g_str_equal(name, "Domains.Configuration") == TRUE) { DBusMessageIter entry; GString *str; @@ -3562,6 +3640,7 @@ static void service_free(gpointer user_data) } g_strfreev(service->timeservers); + g_strfreev(service->timeservers_config); g_strfreev(service->nameservers); g_strfreev(service->nameservers_config); g_strfreev(service->nameservers_auto); |