summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/timeserver.h3
-rw-r--r--src/clock.c26
-rw-r--r--src/timeserver.c93
3 files changed, 24 insertions, 98 deletions
diff --git a/include/timeserver.h b/include/timeserver.h
index d1245376..269bcaa8 100644
--- a/include/timeserver.h
+++ b/include/timeserver.h
@@ -26,8 +26,7 @@
extern "C" {
#endif
-int __connman_timeserver_system_append(const char *server);
-int __connman_timeserver_system_remove(const char *server);
+int __connman_timeserver_system_set(char **server);
#ifdef __cplusplus
}
diff --git a/src/clock.c b/src/clock.c
index c3644ea9..adb18869 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -260,23 +260,41 @@ static DBusMessage *set_property(DBusConnection *conn,
DBUS_TYPE_STRING, &strval);
} else if (g_str_equal(name, "Timeservers") == TRUE) {
DBusMessageIter entry;
+ char **str = NULL;
+ GSList *list = NULL;
+ int count = 0;
if (type != DBUS_TYPE_ARRAY)
return __connman_error_invalid_arguments(msg);
dbus_message_iter_recurse(&value, &entry);
- if (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_INVALID)
- __connman_timeserver_system_append(NULL);
-
while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
const char *val;
dbus_message_iter_get_basic(&entry, &val);
- __connman_timeserver_system_append(val);
+
+ list = g_slist_prepend(list, strdup(val));
+ count++;
+
dbus_message_iter_next(&entry);
}
+ if (list != NULL) {
+ str = g_new0(char *, count+1);
+
+ while (list != NULL) {
+ count--;
+ str[count] = list->data;
+ list = g_slist_delete_link(list, list);
+ };
+ }
+
+ __connman_timeserver_system_set(str);
+
+ if (str != NULL)
+ g_strfreev(str);
+
connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
CONNMAN_CLOCK_INTERFACE, "Timeservers",
DBUS_TYPE_STRING, append_timeservers, NULL);
diff --git a/src/timeserver.c b/src/timeserver.c
index d31801f0..08dd81b5 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -225,100 +225,9 @@ void __connman_timeserver_stop()
__connman_ntp_stop();
}
-int __connman_timeserver_system_append(const char *server)
+int __connman_timeserver_system_set(char **servers)
{
- int len;
- char **servers = NULL;
-
- if (server == NULL) {
- save_timeservers(servers);
- goto restart;
- }
-
- DBG("server %s", server);
-
- servers = load_timeservers();
-
- if (servers != NULL) {
- int i;
-
- for (i = 0; servers[i] != NULL; i++)
- if (g_strcmp0(servers[i], server) == 0) {
- g_strfreev(servers);
- return -EEXIST;
- }
-
- len = g_strv_length(servers);
- servers = g_try_renew(char *, servers, len + 2);
- } else {
- len = 0;
- servers = g_try_new0(char *, len + 2);
- }
-
- if (servers == NULL)
- return -ENOMEM;
-
- servers[len] = g_strdup(server);
- servers[len + 1] = NULL;
-
- save_timeservers(servers);
-
- g_strfreev(servers);
-restart:
- connman_timeserver_restart();
-
- return 0;
-}
-
-int __connman_timeserver_system_remove(const char *server)
-{
- char **servers;
- char **temp;
- int len, i, j;
-
- if (server == NULL)
- return -EINVAL;
-
- DBG("server %s", server);
-
- servers = load_timeservers();
-
- if (servers == NULL)
- return 0;
-
- len = g_strv_length(servers);
- if (len == 1) {
- if (g_strcmp0(servers[0], server) != 0) {
- g_strfreev(servers);
- return 0;
- }
-
- g_strfreev(servers);
- servers = NULL;
- save_timeservers(servers);
- return 0;
- }
-
- temp = g_try_new0(char *, len - 1);
- if (temp == NULL) {
- g_strfreev(servers);
- return -ENOMEM;
- }
-
- for (i = 0, j = 0; i < len; i++) {
- if (g_strcmp0(servers[i], server) != 0) {
- temp[j] = g_strdup(servers[i]);
- j++;
- }
- }
- temp[len - 1] = NULL;
-
- g_strfreev(servers);
- servers = g_strdupv(temp);
- g_strfreev(temp);
-
save_timeservers(servers);
- g_strfreev(servers);
connman_timeserver_restart();