diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-08-05 23:55:22 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-08-06 00:09:42 +0200 |
commit | 4867a22ce4eaa9ab4144df927a1d3f1469695e42 (patch) | |
tree | 81d53113fd8171cf2d60b491111b84e58276c9dc | |
parent | b0f5ddb0a06498d35ad3c12f42cc07e0a36e96cb (diff) | |
download | connman-4867a22ce4eaa9ab4144df927a1d3f1469695e42.tar.gz connman-4867a22ce4eaa9ab4144df927a1d3f1469695e42.tar.bz2 connman-4867a22ce4eaa9ab4144df927a1d3f1469695e42.zip |
Build VPN services based on VPN host and domain strings
-rw-r--r-- | doc/service-api.txt | 8 | ||||
-rw-r--r-- | plugins/openconnect.c | 4 | ||||
-rw-r--r-- | src/provider.c | 40 | ||||
-rwxr-xr-x | test/connect-vpn | 6 |
4 files changed, 46 insertions, 12 deletions
diff --git a/doc/service-api.txt b/doc/service-api.txt index 0e06da56..c1dd5419 100644 --- a/doc/service-api.txt +++ b/doc/service-api.txt @@ -419,6 +419,14 @@ Properties string State [readonly] dict Provider [readonly] + string Host [readonly] + + VPN host IP. + + string Domain [readonly] + + VPN Domain. + string Name [readonly] VPN provider Name. diff --git a/plugins/openconnect.c b/plugins/openconnect.c index 9232781d..cdd18cfe 100644 --- a/plugins/openconnect.c +++ b/plugins/openconnect.c @@ -248,9 +248,9 @@ static int oc_connect(struct connman_provider *provider) connman_provider_set_data(provider, data); - vpnhost = connman_provider_get_string(provider, "OpenConnect.Host"); + vpnhost = connman_provider_get_string(provider, "Host"); if (!vpnhost) { - connman_error("OpenConnect.Host not set; cannot enable VPN"); + connman_error("Host not set; cannot enable VPN"); ret = -EINVAL; goto exist_err; } diff --git a/src/provider.c b/src/provider.c index 4190f102..5b602ad4 100644 --- a/src/provider.c +++ b/src/provider.c @@ -41,6 +41,7 @@ struct connman_provider { char *identifier; char *name; char *type; + char *host; char *dns; char *domain; struct connman_provider_driver *driver; @@ -50,9 +51,13 @@ struct connman_provider { void __connman_provider_append_properties(struct connman_provider *provider, DBusMessageIter *iter) { - if (provider->name != NULL) - connman_dbus_dict_append_basic(iter, "Name", - DBUS_TYPE_STRING, &provider->name); + if (provider->host != NULL) + connman_dbus_dict_append_basic(iter, "Host", + DBUS_TYPE_STRING, &provider->host); + + if (provider->domain != NULL) + connman_dbus_dict_append_basic(iter, "Domain", + DBUS_TYPE_STRING, &provider->domain); if (provider->type != NULL) connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING, @@ -405,11 +410,21 @@ static struct connman_provider *connman_provider_get(const char *identifier) return provider; } +static void provider_dbus_ident(char *ident) +{ + int i, len = strlen(ident); + + for (i = 0; i < len; i++) + if (ident[i] == '.') + ident[i] = '_'; +} + int __connman_provider_create_and_connect(DBusMessage *msg) { struct connman_provider *provider; DBusMessageIter iter, array; const char *type = NULL, *name = NULL, *service_path = NULL; + const char *host = NULL, *domain = NULL; char *ident; gboolean created = FALSE; int err; @@ -433,15 +448,21 @@ int __connman_provider_create_and_connect(DBusMessage *msg) dbus_message_iter_get_basic(&value, &type); else if (g_str_equal(key, "Name") == TRUE) dbus_message_iter_get_basic(&value, &name); + else if (g_str_equal(key, "Host") == TRUE) + dbus_message_iter_get_basic(&value, &host); + else if (g_str_equal(key, "VPN.Domain") == TRUE) + dbus_message_iter_get_basic(&value, &domain); break; } - if (type != NULL && name != NULL) - break; - dbus_message_iter_next(&array); } + if (host == NULL && domain == NULL) { + err = -EINVAL; + goto failed; + } + DBG("Type %s name %s", type, name); if (type == NULL || name == NULL) { @@ -449,7 +470,10 @@ int __connman_provider_create_and_connect(DBusMessage *msg) goto failed; } - ident = g_strdup_printf("%s_%s", type, name); + ident = g_strdup_printf("%s_%s", host, domain); + provider_dbus_ident(ident); + + DBG("ident %s", ident); provider = connman_provider_lookup(ident); @@ -457,6 +481,8 @@ int __connman_provider_create_and_connect(DBusMessage *msg) created = TRUE; provider = connman_provider_get(ident); if (provider) { + provider->host = g_strdup(host); + provider->domain = g_strdup(domain); provider->name = g_strdup(name); provider->type = g_strdup(type); } diff --git a/test/connect-vpn b/test/connect-vpn index c9cbd89d..22f13709 100755 --- a/test/connect-vpn +++ b/test/connect-vpn @@ -16,14 +16,14 @@ print "Attempting to connect service %s" % (sys.argv[1]) if (len(sys.argv) > 4): path = manager.ConnectProvider(({ "Type": "openconnect", "Name": sys.argv[1], - "OpenConnect.Host": sys.argv[2], + "Host": sys.argv[2], "OpenConnect.Cookie": sys.argv[3], "OpenConnect.CACert": sys.argv[4], "VPN.Domain": "intel.com"})) else: path = manager.ConnectProvider(({ "Type": "openconnect", "Name": sys.argv[1], - "OpenConnect.Host": sys.argv[2], + "Host": sys.argv[2], "OpenConnect.Cookie": sys.argv[3], "VPN.Domain": "intel.com"})) -print "Provider path is %s" %(path) +print "VPN service path is %s" %(path) |