summaryrefslogtreecommitdiff
path: root/src/timeserver.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-04-20 16:07:30 +0300
committerMarcel Holtmann <marcel@holtmann.org>2012-04-20 15:11:40 +0200
commit87aec23ff8b680fde1a26a5883aa6576f0a15a1a (patch)
tree152c51bc1f22c9e360d5bb36b295f20c60ff904a /src/timeserver.c
parentf8f3ec594db48e27857356b2a64a54f8817aedf9 (diff)
downloadconnman-87aec23ff8b680fde1a26a5883aa6576f0a15a1a.tar.gz
connman-87aec23ff8b680fde1a26a5883aa6576f0a15a1a.tar.bz2
connman-87aec23ff8b680fde1a26a5883aa6576f0a15a1a.zip
timeserver: Refactor __connman_timeserver_sync()
Factor out code that creates the timeserver list in __connman_timeserver_sync().
Diffstat (limited to 'src/timeserver.c')
-rw-r--r--src/timeserver.c93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/timeserver.c b/src/timeserver.c
index 64d6dce1..9a5827a2 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -156,17 +156,14 @@ void __connman_timeserver_sync_next()
return;
}
-
/*
- * __connman_timeserver_sync function recreates the timeserver
+ * __connman_timeserver_get_all function creates the timeserver
* list which will be used to determine NTP server for time corrections.
- * It must be called everytime the default service changes, the service
- * timeserver(s) or gatway changes or the global timeserver(s) changes.
* The service settings take priority over the global timeservers.
*/
-int __connman_timeserver_sync(struct connman_service *default_service)
+GSList *__connman_timeserver_get_all(struct connman_service *service)
{
- struct connman_service *service;
+ GSList *list = NULL;
struct connman_network *network;
char **timeservers;
char **service_ts;
@@ -175,42 +172,18 @@ int __connman_timeserver_sync(struct connman_service *default_service)
char **fallback_ts;
int index, i;
- if (default_service != NULL)
- service = default_service;
- else
- service = __connman_service_get_default();
-
- if (service == NULL)
- return -EINVAL;
-
- if (resolv == NULL)
- return 0;
- /*
- * Before be start creating the new timeserver list we must stop
- * any ongoing ntp query and server resolution.
- */
-
- __connman_ntp_stop();
-
- if (resolv_id > 0)
- g_resolv_cancel_lookup(resolv, resolv_id);
-
- if (ts_list != NULL) {
- g_slist_free_full(ts_list, g_free);
- ts_list = NULL;
- }
-
service_ts_config = connman_service_get_timeservers_config(service);
/* First add Service Timeservers.Configuration to the list */
- for (i=0; service_ts_config != NULL && service_ts_config[i] != NULL; i++)
- ts_list = g_slist_prepend(ts_list, g_strdup(service_ts_config[i]));
+ for (i = 0; service_ts_config != NULL && service_ts_config[i] != NULL;
+ i++)
+ list = g_slist_prepend(list, g_strdup(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++)
- ts_list = g_slist_prepend(ts_list, g_strdup(service_ts[i]));
+ for (i = 0; service_ts != NULL && service_ts[i] != NULL; i++)
+ list = g_slist_prepend(list, g_strdup(service_ts[i]));
network = __connman_service_get_network(service);
@@ -220,29 +193,62 @@ int __connman_timeserver_sync(struct connman_service *default_service)
/* Then add Service Gateway to the list */
if (service_gw != NULL)
- ts_list = g_slist_prepend(ts_list, g_strdup(service_gw));
+ list = g_slist_prepend(list, g_strdup(service_gw));
/* Then add Global Timeservers to the list */
timeservers = load_timeservers();
- for (i=0; timeservers != NULL && timeservers[i] != NULL; i++)
- ts_list = g_slist_prepend(ts_list, g_strdup(timeservers[i]));
+ for (i = 0; timeservers != NULL && timeservers[i] != NULL; i++)
+ list = g_slist_prepend(list, g_strdup(timeservers[i]));
g_strfreev(timeservers);
fallback_ts = connman_setting_get_string_list("FallbackTimeservers");
/* Lastly add the fallback servers */
- for (i=0; fallback_ts != NULL && fallback_ts[i] != NULL; i++)
- ts_list = g_slist_prepend(ts_list, g_strdup(fallback_ts[i]));
+ for (i = 0; fallback_ts != NULL && fallback_ts[i] != NULL; i++)
+ list = g_slist_prepend(list, g_strdup(fallback_ts[i]));
+
+ return g_slist_reverse(list);
+}
+
+/*
+ * This function must be called everytime the default service changes, the
+ * service timeserver(s) or gatway changes or the global timeserver(s) changes.
+ */
+int __connman_timeserver_sync(struct connman_service *default_service)
+{
+ struct connman_service *service;
+
+ if (default_service != NULL)
+ service = default_service;
+ else
+ service = __connman_service_get_default();
+
+ if (service == NULL)
+ return -EINVAL;
+
+ if (resolv == NULL)
+ return 0;
+ /*
+ * Before we start creating the new timeserver list we must stop
+ * any ongoing ntp query and server resolution.
+ */
+
+ __connman_ntp_stop();
+
+ if (resolv_id > 0)
+ g_resolv_cancel_lookup(resolv, resolv_id);
+
+ g_slist_free_full(ts_list, g_free);
+
+ ts_list = __connman_timeserver_get_all(service);
if (ts_list == NULL) {
DBG("No timeservers set.");
return 0;
}
- ts_list = g_slist_reverse(ts_list);
-
__connman_timeserver_sync_next();
return 0;
@@ -299,8 +305,7 @@ static void timeserver_stop()
resolv = NULL;
}
- if (ts_list != NULL)
- g_slist_free_full(ts_list, g_free);
+ g_slist_free_full(ts_list, g_free);
ts_list = NULL;