X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftimeserver.c;h=2601d3631ab9a076bf2c770c5ef25fcba55c8b93;hb=2aa593bceff2698fe3ca714152064e4758cf5593;hp=f39d64ec7843adeb74403ac0e86167059bc390fa;hpb=e09da202614b79bb0e568b7d67db1aa75d95527c;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/timeserver.c b/src/timeserver.c index f39d64e..2601d36 100644 --- a/src/timeserver.c +++ b/src/timeserver.c @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2010 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2012 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 @@ -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. @@ -177,29 +194,31 @@ GSList *__connman_timeserver_get_all(struct connman_service *service) /* First add Service Timeservers.Configuration to the list */ for (i = 0; service_ts_config != NULL && service_ts_config[i] != NULL; i++) - list = g_slist_prepend(list, g_strdup(service_ts_config[i])); + list = __connman_timeserver_add_list(list, + service_ts_config[i]); service_ts = connman_service_get_timeservers(service); /* First add Service Timeservers via DHCP to the list */ for (i = 0; service_ts != NULL && service_ts[i] != NULL; i++) - list = g_slist_prepend(list, g_strdup(service_ts[i])); + list = __connman_timeserver_add_list(list, service_ts[i]); network = __connman_service_get_network(service); - - index = connman_network_get_index(network); - - service_gw = __connman_ipconfig_get_gateway_from_index(index); - - /* Then add Service Gateway to the list */ - if (service_gw != NULL) - list = g_slist_prepend(list, g_strdup(service_gw)); + if (network != NULL) { + index = connman_network_get_index(network); + service_gw = __connman_ipconfig_get_gateway_from_index(index, + CONNMAN_IPCONFIG_TYPE_ALL); + + /* Then add Service Gateway to the list */ + if (service_gw != NULL) + list = __connman_timeserver_add_list(list, service_gw); + } /* Then add Global Timeservers to the list */ timeservers = load_timeservers(); for (i = 0; timeservers != NULL && timeservers[i] != NULL; i++) - list = g_slist_prepend(list, g_strdup(timeservers[i])); + list = __connman_timeserver_add_list(list, timeservers[i]); g_strfreev(timeservers); @@ -207,7 +226,7 @@ GSList *__connman_timeserver_get_all(struct connman_service *service) /* Lastly add the fallback servers */ for (i = 0; fallback_ts != NULL && fallback_ts[i] != NULL; i++) - list = g_slist_prepend(list, g_strdup(fallback_ts[i])); + list = __connman_timeserver_add_list(list, fallback_ts[i]); return g_slist_reverse(list); }