summaryrefslogtreecommitdiff
path: root/vpn
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2013-02-18 15:23:37 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-19 10:23:12 (GMT)
commitaabdbc223c0efde63b372063086d8eb017d093a4 (patch)
tree50f0af61892a2cff2a6bb478af911dba54b96f56 /vpn
parent72c6c267396f5346aaae3092d34db3276eef1827 (diff)
downloadconnman-aabdbc223c0efde63b372063086d8eb017d093a4.zip
connman-aabdbc223c0efde63b372063086d8eb017d093a4.tar.gz
connman-aabdbc223c0efde63b372063086d8eb017d093a4.tar.bz2
vpn-provider: Initial .config file support
Diffstat (limited to 'vpn')
-rw-r--r--vpn/vpn-provider.c152
-rw-r--r--vpn/vpn.h5
2 files changed, 140 insertions, 17 deletions
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index 56a9c51..f6753b9 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -818,7 +818,7 @@ static int vpn_provider_save(struct vpn_provider *provider)
return 0;
}
-static struct vpn_provider *vpn_provider_lookup(const char *identifier)
+struct vpn_provider *__vpn_provider_lookup(const char *identifier)
{
struct vpn_provider *provider = NULL;
@@ -840,7 +840,8 @@ static int provider_probe(struct vpn_provider *provider)
{
GSList *list;
- DBG("provider %p name %s", provider, provider->name);
+ DBG("provider %p driver %p name %s", provider, provider->driver,
+ provider->name);
if (provider->driver != NULL)
return -EALREADY;
@@ -1051,20 +1052,26 @@ int __vpn_provider_remove(const char *path)
ident = get_ident(path);
- provider = vpn_provider_lookup(ident);
- if (provider != NULL) {
- DBG("Removing VPN %s", provider->identifier);
+ provider = __vpn_provider_lookup(ident);
+ if (provider != NULL)
+ return __vpn_provider_delete(provider);
- connection_removed_signal(provider);
+ return -ENXIO;
+}
- provider_unregister(provider);
- g_hash_table_remove(provider_hash, provider->identifier);
+int __vpn_provider_delete(struct vpn_provider *provider)
+{
+ DBG("Deleting VPN %s", provider->identifier);
- __connman_storage_remove_provider(ident);
- return 0;
- }
+ connection_removed_signal(provider);
- return -ENXIO;
+ provider_unregister(provider);
+
+ __connman_storage_remove_provider(provider->identifier);
+
+ g_hash_table_remove(provider_hash, provider->identifier);
+
+ return 0;
}
static void append_ipv4(DBusMessageIter *iter, void *user_data)
@@ -1561,7 +1568,7 @@ static struct vpn_provider *provider_create_from_keyfile(GKeyFile *keyfile,
if (keyfile == NULL || ident == NULL)
return NULL;
- provider = vpn_provider_lookup(ident);
+ provider = __vpn_provider_lookup(ident);
if (provider == NULL) {
provider = vpn_provider_get(ident);
if (provider == NULL) {
@@ -1628,6 +1635,19 @@ static void provider_create_all_from_type(const char *provider_type)
g_strfreev(providers);
}
+char *__vpn_provider_create_identifier(const char *host, const char *domain)
+{
+ char *ident;
+
+ ident = g_strdup_printf("%s_%s", host, domain);
+ if (ident == NULL)
+ return NULL;
+
+ provider_dbus_ident(ident);
+
+ return ident;
+}
+
int __vpn_provider_create(DBusMessage *msg)
{
struct vpn_provider *provider;
@@ -1679,12 +1699,10 @@ int __vpn_provider_create(DBusMessage *msg)
if (type == NULL || name == NULL)
return -EOPNOTSUPP;
- ident = g_strdup_printf("%s_%s", host, domain);
- provider_dbus_ident(ident);
-
+ ident = __vpn_provider_create_identifier(host, domain);
DBG("ident %s", ident);
- provider = vpn_provider_lookup(ident);
+ provider = __vpn_provider_lookup(ident);
if (provider == NULL) {
provider = vpn_provider_get(ident);
if (provider == NULL) {
@@ -1755,6 +1773,106 @@ int __vpn_provider_create(DBusMessage *msg)
return 0;
}
+static const char *get_string(GHashTable *settings, const char *key)
+{
+ DBG("settings %p key %s", settings, key);
+
+ return g_hash_table_lookup(settings, key);
+}
+
+static GSList *parse_user_networks(const char *network_str)
+{
+ return NULL;
+}
+
+int __vpn_provider_create_from_config(GHashTable *settings,
+ const char *config_ident,
+ const char *config_entry)
+{
+ struct vpn_provider *provider;
+ const char *type, *name, *host, *domain, *networks_str;
+ GSList *networks;
+ char *ident = NULL;
+ GHashTableIter hash;
+ gpointer value, key;
+ int err;
+
+ type = get_string(settings, "Type");
+ name = get_string(settings, "Name");
+ host = get_string(settings, "Host");
+ domain = get_string(settings, "Domain");
+ networks_str = get_string(settings, "Networks");
+ networks = parse_user_networks(networks_str);
+
+ if (host == NULL || domain == NULL) {
+ err = -EINVAL;
+ goto fail;
+ }
+
+ DBG("type %s name %s networks %s", type, name, networks_str);
+
+ if (type == NULL || name == NULL) {
+ err = -EOPNOTSUPP;
+ goto fail;
+ }
+
+ ident = __vpn_provider_create_identifier(host, domain);
+ DBG("ident %s", ident);
+
+ provider = __vpn_provider_lookup(ident);
+ if (provider == NULL) {
+ provider = vpn_provider_get(ident);
+ if (provider == NULL) {
+ DBG("can not create provider");
+ err = -EOPNOTSUPP;
+ goto fail;
+ }
+
+ provider->host = g_strdup(host);
+ provider->domain = g_strdup(domain);
+ provider->name = g_strdup(name);
+ provider->type = g_ascii_strdown(type, -1);
+
+ if (provider_register(provider) == 0)
+ vpn_provider_load(provider);
+
+ provider_resolv_host_addr(provider);
+ }
+
+ if (networks != NULL) {
+ g_slist_free_full(provider->user_networks, free_route);
+ provider->user_networks = networks;
+ set_user_networks(provider, provider->user_networks);
+ }
+
+ g_hash_table_iter_init(&hash, settings);
+
+ while (g_hash_table_iter_next(&hash, &key, &value) == TRUE)
+ vpn_provider_set_string(provider, key, value);
+
+ vpn_provider_save(provider);
+
+ err = provider_register(provider);
+ if (err != 0 && err != -EALREADY)
+ goto fail;
+
+ connection_register(provider);
+
+ DBG("provider %p index %d path %s", provider, provider->index,
+ provider->path);
+
+ connection_added_signal(provider);
+
+ err = 0;
+
+fail:
+ g_free(ident);
+ if (networks != NULL)
+ g_slist_free_full(networks, free_route);
+
+ return err;
+}
+
static void append_connection_structs(DBusMessageIter *iter, void *user_data)
{
DBusMessageIter entry;
diff --git a/vpn/vpn.h b/vpn/vpn.h
index fed66a8..929c319 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -71,14 +71,18 @@ void __vpn_ipconfig_cleanup(void);
#include "vpn-provider.h"
+char *__vpn_provider_create_identifier(const char *host, const char *domain);
connman_bool_t __vpn_provider_check_routes(struct vpn_provider *provider);
int __vpn_provider_append_user_route(struct vpn_provider *provider,
int family, const char *network, const char *netmask);
void __vpn_provider_append_properties(struct vpn_provider *provider, DBusMessageIter *iter);
void __vpn_provider_list(DBusMessageIter *iter, void *user_data);
int __vpn_provider_create(DBusMessage *msg);
+int __vpn_provider_create_from_config(GHashTable *settings,
+ const char *config_ident, const char *config_entry);
DBusMessage *__vpn_provider_get_connections(DBusMessage *msg);
const char * __vpn_provider_get_ident(struct vpn_provider *provider);
+struct vpn_provider *__vpn_provider_lookup(const char *identifier);
int __vpn_provider_indicate_state(struct vpn_provider *provider,
enum vpn_provider_state state);
int __vpn_provider_indicate_error(struct vpn_provider *provider,
@@ -87,6 +91,7 @@ int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg);
int __vpn_provider_connect_path(const char *path);
int __vpn_provider_disconnect(struct vpn_provider *provider);
int __vpn_provider_remove(const char *path);
+int __vpn_provider_delete(struct vpn_provider *provider);
void __vpn_provider_check_connections(void);
void __vpn_provider_cleanup(void);
int __vpn_provider_init(gboolean handle_routes);