*
* 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
static char **load_timeservers()
{
GKeyFile *keyfile;
- GError *error = NULL;
char **servers = NULL;
keyfile = __connman_storage_load_global();
return NULL;
servers = g_key_file_get_string_list(keyfile, "global",
- "Timeservers", NULL, &error);
- if (error) {
- DBG("Error loading timeservers: %s", error->message);
- g_error_free(error);
- }
+ "Timeservers", NULL, NULL);
g_key_file_free(keyfile);
void __connman_timeserver_sync_next()
{
char *server;
- int ret;
- struct addrinfo hints;
- struct addrinfo *addr;
__connman_ntp_stop();
ts_list = g_slist_delete_link(ts_list, ts_list);
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_flags = AI_NUMERICHOST;
- addr = NULL;
-
- ret = getaddrinfo(server, NULL, &hints, &addr);
- freeaddrinfo(addr);
-
/* if its a IP , directly query it. */
- if (ret == 0) {
+ if (connman_inet_check_ipaddress(server) > 0) {
DBG("Using timeservers %s", server);
__connman_ntp_start(server);
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.
/* 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);
/* 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);
}
ts_list = __connman_timeserver_get_all(service);
+ __connman_service_timeserver_changed(service, ts_list);
+
if (ts_list == NULL) {
DBG("No timeservers set.");
return 0;