summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-04-05 22:38:33 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-04-11 13:24:18 +0300
commit4ac6fb6c041115c6226c1e527b7b8f8236ed44f2 (patch)
tree870d4a3b0fb06328cf71ecfe60cfa7a0fe5f6e8a /src/main.c
parent277eb409c909f4f7361bf441984656b0a7941de3 (diff)
downloadconnman-4ac6fb6c041115c6226c1e527b7b8f8236ed44f2.tar.gz
connman-4ac6fb6c041115c6226c1e527b7b8f8236ed44f2.tar.bz2
connman-4ac6fb6c041115c6226c1e527b7b8f8236ed44f2.zip
main: Add 'DefaultAutoConnectTechnologies' configuration option
The main.conf 'DefaultAutoConnectTechnologies' is a list of service type strings. It is converted to a list of service type enums, and thus the configuration option is accessible via the function connman_setting_get_uint_list(). If this option is not specified, the default technologies to autoconnect are wifi, ethernet and cellular just like before.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 6e0d64df..e539e6d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -45,9 +45,11 @@
static struct {
connman_bool_t bg_scan;
char **pref_timeservers;
+ unsigned int *auto_connect;
} connman_settings = {
.bg_scan = TRUE,
.pref_timeservers = NULL,
+ .auto_connect = NULL,
};
static GKeyFile *load_config(const char *file)
@@ -73,11 +75,44 @@ static GKeyFile *load_config(const char *file)
return keyfile;
}
+static uint *parse_service_types(char **str_list, gsize len)
+{
+ unsigned int *type_list;
+ int i, j;
+ enum connman_service_type type;
+
+ type_list = g_try_new0(unsigned int, len + 1);
+ if (type_list == NULL)
+ return NULL;
+
+ i = 0;
+ j = 0;
+ while (str_list[i] != NULL)
+ {
+ type = __connman_service_string2type(str_list[i]);
+
+ if (type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
+ type_list[j] = type;
+ j += 1;
+ }
+ i += 1;
+ }
+
+ return type_list;
+}
+
static void parse_config(GKeyFile *config)
{
GError *error = NULL;
gboolean boolean;
char **timeservers;
+ char **str_list;
+ gsize len;
+ char *default_auto_connect[] = {
+ "wifi",
+ "ethernet",
+ "cellular",
+ };
if (config == NULL)
return;
@@ -97,6 +132,20 @@ static void parse_config(GKeyFile *config)
connman_settings.pref_timeservers = timeservers;
g_clear_error(&error);
+
+ str_list = g_key_file_get_string_list(config, "General",
+ "DefaultAutoConnectTechnologies", &len, &error);
+
+ if (error == NULL)
+ connman_settings.auto_connect =
+ parse_service_types(str_list, len);
+ else
+ connman_settings.auto_connect =
+ parse_service_types(default_auto_connect, 3);
+
+ g_strfreev(str_list);
+
+ g_clear_error(&error);
}
static GMainLoop *main_loop = NULL;
@@ -255,6 +304,14 @@ char **connman_setting_get_string_list(const char *key)
return NULL;
}
+unsigned int *connman_setting_get_uint_list(const char *key)
+{
+ if (g_str_equal(key, "DefaultAutoConnectTechnologies") == TRUE)
+ return connman_settings.auto_connect;
+
+ return NULL;
+}
+
int main(int argc, char *argv[])
{
GOptionContext *context;
@@ -440,6 +497,8 @@ int main(int argc, char *argv[])
if (connman_settings.pref_timeservers != NULL)
g_strfreev(connman_settings.pref_timeservers);
+ g_free(connman_settings.auto_connect);
+
g_free(option_debug);
return 0;