summary refs log tree commit diff
path: root/src/nm-config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-config.c')
-rw-r--r--src/nm-config.c93
1 files changed, 70 insertions, 23 deletions
diff --git a/src/nm-config.c b/src/nm-config.c
index 71f67d55..f64b8bdb 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -34,6 +34,9 @@ struct NMConfig {
 	char **dns_plugins;
 	char *log_level;
 	char *log_domains;
+	char *connectivity_uri;
+	guint connectivity_interval;
+	char *connectivity_response;
 };
 
 /************************************************************************/
@@ -47,25 +50,6 @@ nm_config_error_quark (void)
 	return quark;
 }
 
-/* This should really be standard. */
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
-
-GType
-nm_config_error_get_type (void)
-{
-	static GType etype = 0;
-
-	if (etype == 0) {
-		static const GEnumValue values[] = {
-			/* Not enough memory to parse the config file. */
-			ENUM_ENTRY (NM_CONFIG_ERROR_NO_MEMORY, "NoMemory"),
-			{ 0, 0, 0 }
-		};
-		etype = g_enum_register_static ("NMConfigError", values);
-	}
-	return etype;
-}
-
 /************************************************************************/
 
 const char *
@@ -116,6 +100,31 @@ nm_config_get_log_domains (NMConfig *config)
 	return config->log_domains;
 }
 
+const char *
+nm_config_get_connectivity_uri (NMConfig *config)
+{
+	g_return_val_if_fail (config != NULL, NULL);
+
+	return config->connectivity_uri;
+}
+
+const guint
+nm_config_get_connectivity_interval (NMConfig *config)
+{
+	g_return_val_if_fail (config != NULL, -1);
+
+	return config->connectivity_interval;
+}
+
+const char *
+nm_config_get_connectivity_response (NMConfig *config)
+{
+	g_return_val_if_fail (config != NULL, NULL);
+
+	return config->connectivity_response;
+}
+
+
 /************************************************************************/
 
 static gboolean
@@ -124,6 +133,9 @@ fill_from_file (NMConfig *config,
                 const char *cli_plugins,
                 const char *cli_log_level,
                 const char *cli_log_domains,
+                const char *cli_connectivity_uri,
+                const gint cli_connectivity_interval,
+                const char *cli_connectivity_response,
                 GError **error)
 {
 	GKeyFile *kf;
@@ -163,6 +175,22 @@ fill_from_file (NMConfig *config,
 			config->log_domains = g_strdup (cli_log_domains);
 		else
 			config->log_domains = g_key_file_get_value (kf, "logging", "domains", NULL);
+
+		if (cli_connectivity_uri && strlen (cli_connectivity_uri))
+			config->connectivity_uri = g_strdup (cli_connectivity_uri);
+		else
+			config->connectivity_uri = g_key_file_get_value (kf, "connectivity", "uri", NULL);
+
+		if (cli_connectivity_interval >= 0)
+			config->connectivity_interval = cli_connectivity_interval;
+		else
+			config->connectivity_interval = g_key_file_get_integer (kf, "connectivity", "interval", NULL);
+
+		if (cli_connectivity_response && strlen (cli_connectivity_response))
+			config->connectivity_response = g_strdup (cli_connectivity_response);
+		else
+			config->connectivity_response = g_key_file_get_value (kf, "connectivity", "response", NULL);
+
 		success = TRUE;
 	}
 
@@ -175,6 +203,9 @@ nm_config_new (const char *cli_config_path,
                const char *cli_plugins,
                const char *cli_log_level,
                const char *cli_log_domains,
+               const char *cli_connectivity_uri,
+               const gint cli_connectivity_interval,
+               const char *cli_connectivity_response,
                GError **error)
 {
 	NMConfig *config;
@@ -184,7 +215,9 @@ nm_config_new (const char *cli_config_path,
 
 	if (cli_config_path) {
 		/* Bad user-specific config file path is a hard error */
-		if (!fill_from_file (config, cli_config_path, cli_plugins, cli_log_level, cli_log_domains, error)) {
+		if (!fill_from_file (config, cli_config_path, cli_plugins, cli_log_level, cli_log_domains,
+		                     cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
+		                     error)) {
 			nm_config_free (config);
 			return NULL;
 		}
@@ -199,7 +232,9 @@ nm_config_new (const char *cli_config_path,
 	 */
 
 	/* Try deprecated nm-system-settings.conf first */
-	if (fill_from_file (config, NM_OLD_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains, &local))
+	if (fill_from_file (config, NM_OLD_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains,
+	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
+	                    &local))
 		return config;
 
 	if (g_error_matches (local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND) == FALSE) {
@@ -211,7 +246,9 @@ nm_config_new (const char *cli_config_path,
 	g_clear_error (&local);
 
 	/* Try the standard config file location next */
-	if (fill_from_file (config, NM_DEFAULT_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains, &local))
+	if (fill_from_file (config, NM_DEFAULT_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains,
+	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
+	                    &local))
 		return config;
 
 	if (g_error_matches (local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND) == FALSE) {
@@ -224,6 +261,15 @@ nm_config_new (const char *cli_config_path,
 		return NULL;
 	}
 
+	/* If for some reason no config file exists, and NM wasn't given on on
+	 * the command line, just use the default config file path.
+	 */
+	if (config->path == NULL) {
+		config->path = g_strdup (NM_DEFAULT_SYSTEM_CONF_FILE);
+		fprintf (stderr, "No config file found or given; using %s\n",
+		         NM_DEFAULT_SYSTEM_CONF_FILE);
+	}
+
 	/* ignore error if config file not found */
 	g_clear_error (&local);
 	return config;
@@ -240,7 +286,8 @@ nm_config_free (NMConfig *config)
 	g_strfreev (config->dns_plugins);
 	g_free (config->log_level);
 	g_free (config->log_domains);
-
+	g_free (config->connectivity_uri);
+	g_free (config->connectivity_response);
 	memset (config, 0, sizeof (*config));
 	g_free (config);
 }