summaryrefslogtreecommitdiff
path: root/vpn
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-11-12 14:07:35 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-11-23 12:58:51 +0200
commit8bcd6b1b075bf2024ce2ba422e1f19d2f9f24652 (patch)
treee787c3795b1eede08c0df421e40ae00594a41510 /vpn
parent09440bcf20bec60eb1186e7ad1f0990c74dc4c56 (diff)
downloadconnman-8bcd6b1b075bf2024ce2ba422e1f19d2f9f24652.tar.gz
connman-8bcd6b1b075bf2024ce2ba422e1f19d2f9f24652.tar.bz2
connman-8bcd6b1b075bf2024ce2ba422e1f19d2f9f24652.zip
vpn: Introduce config file for vpnd
Diffstat (limited to 'vpn')
-rw-r--r--vpn/main.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/vpn/main.c b/vpn/main.c
index dcf3a78c..eb074d4a 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();