[PATCH v5 19/42] vpn: Introduce config file for vpnd

Jukka Rissanen jukka.rissanen at linux.intel.com
Mon Nov 12 04:07:35 PST 2012


---
 vpn/main.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/vpn/main.c b/vpn/main.c
index dcf3a78..eb074d4 100644
--- a/vpn/main.c
+++ b/vpn/main.c
@@ -42,10 +42,73 @@
 
 #include "connman/vpn-dbus.h"
 
+#define CONFIGMAINFILE CONFIGDIR "/connman-vpn.conf"
+
+#define DEFAULT_INPUT_REQUEST_TIMEOUT 300 * 1000
+
 static GMainLoop *main_loop = NULL;
 
 static unsigned int __terminated = 0;
 
+static struct {
+	unsigned int timeout_inputreq;
+} connman_vpn_settings  = {
+	.timeout_inputreq = DEFAULT_INPUT_REQUEST_TIMEOUT,
+};
+
+static GKeyFile *load_config(const char *file)
+{
+	GError *err = NULL;
+	GKeyFile *keyfile;
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
+		if (err->code != G_FILE_ERROR_NOENT) {
+			connman_error("Parsing %s failed: %s", file,
+								err->message);
+		}
+
+		g_error_free(err);
+		g_key_file_free(keyfile);
+		return NULL;
+	}
+
+	return keyfile;
+}
+
+static void parse_config(GKeyFile *config, const char *file)
+{
+	GError *error = NULL;
+	int timeout;
+
+	if (config == NULL)
+		return;
+
+	DBG("parsing %s", file);
+
+	timeout = g_key_file_get_integer(config, "General",
+			"InputRequestTimeout", &error);
+	if (error == NULL && timeout >= 0)
+		connman_vpn_settings.timeout_inputreq = timeout * 1000;
+
+	g_clear_error(&error);
+}
+
+static int config_init(const char *file)
+{
+	GKeyFile *config;
+
+	config = load_config(file);
+	parse_config(config, file);
+	if (config != NULL)
+		g_key_file_free(config);
+
+	return 0;
+}
+
 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
 							gpointer user_data)
 {
@@ -121,6 +184,7 @@ static void disconnect_callback(DBusConnection *conn, void *user_data)
 	g_main_loop_quit(main_loop);
 }
 
+static gchar *option_config = NULL;
 static gchar *option_debug = NULL;
 static gchar *option_plugin = NULL;
 static gchar *option_noplugin = NULL;
@@ -140,6 +204,9 @@ static gboolean parse_debug(const char *key, const char *value,
 }
 
 static GOptionEntry options[] = {
+	{ "config", 'c', 0, G_OPTION_ARG_STRING, &option_config,
+				"Load the specified configuration file "
+				"instead of " CONFIGMAINFILE, "FILE" },
 	{ "debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
 				G_OPTION_ARG_CALLBACK, parse_debug,
 				"Specify debug options to enable", "DEBUG" },
@@ -157,6 +224,15 @@ static GOptionEntry options[] = {
 	{ NULL },
 };
 
+/*
+ * This function will be called from generic src/agent.c code so we have
+ * to use connman_ prefix instead of vpn_ one.
+ */
+unsigned int connman_timeout_input_request(void)
+{
+	return connman_vpn_settings.timeout_inputreq;
+}
+
 int main(int argc, char *argv[])
 {
 	GOptionContext *context;
@@ -226,6 +302,12 @@ int main(int argc, char *argv[])
 	__connman_log_init(argv[0], option_debug, option_detach, FALSE,
 			"Connection Manager VPN daemon", VERSION);
 	__connman_dbus_init(conn);
+
+	if (option_config == NULL)
+		config_init(CONFIGMAINFILE);
+	else
+		config_init(option_config);
+
 	__vpn_provider_init(option_routes);
 	__vpn_manager_init();
 	__vpn_ipconfig_init();
-- 
1.7.11.4




More information about the connman mailing list