From 90438269a0a7932755c14f436310f3436d98efd4 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Mon, 30 Apr 2012 14:12:58 +0300 Subject: [PATCH] timeserver: Helper function for adding timeservers once to a list --- src/connman.h | 2 ++ src/timeserver.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/connman.h b/src/connman.h index 8610d9b..550107c 100644 --- a/src/connman.h +++ b/src/connman.h @@ -369,6 +369,8 @@ void __connman_timeserver_cleanup(void); char **__connman_timeserver_system_get(); +GSList *__connman_timeserver_add_list(GSList *server_list, + const char *timeserver); GSList *__connman_timeserver_get_all(struct connman_service *service); int __connman_timeserver_sync(struct connman_service *service); void __connman_timeserver_sync_next(); diff --git a/src/timeserver.c b/src/timeserver.c index 62e050e..847f74f 100644 --- a/src/timeserver.c +++ b/src/timeserver.c @@ -156,6 +156,23 @@ void __connman_timeserver_sync_next() return; } +GSList *__connman_timeserver_add_list(GSList *server_list, + const char *timeserver) +{ + GSList *list = server_list; + + if (timeserver == NULL) + return server_list; + + while (list != NULL) { + char *existing_server = list->data; + if (strcmp(timeserver, existing_server) == 0) + return server_list; + list = g_slist_next(list); + } + return g_slist_prepend(server_list, g_strdup(timeserver)); +} + /* * __connman_timeserver_get_all function creates the timeserver * list which will be used to determine NTP server for time corrections. -- 2.7.4