provider: Add IP setters
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 23 Feb 2011 18:57:08 +0000 (19:57 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 23 Feb 2011 18:57:08 +0000 (19:57 +0100)
include/provider.h
src/provider.c

index 03700aa159d069e54594ab5d1467ab404a3a716c..d0e8c35113b035f5af9aed7394aaf3b0fbb254df 100644 (file)
@@ -56,6 +56,7 @@ enum connman_provider_error {
 };
 
 struct connman_provider;
+struct connman_ipaddress;
 
 struct connman_provider *connman_provider_ref(struct connman_provider *provider);
 void connman_provider_unref(struct connman_provider *provider);
@@ -76,18 +77,14 @@ int connman_provider_get_index(struct connman_provider *provider);
 
 void connman_provider_set_data(struct connman_provider *provider, void *data);
 void *connman_provider_get_data(struct connman_provider *provider);
-
-void connman_provider_set_gateway(struct connman_provider *provider,
-                                                       const char *gateway);
-void connman_provider_set_address(struct connman_provider *provider,
-                                                       const char *address);
-void connman_provider_set_netmask(struct connman_provider *provider,
-                                                       const char *netmask);
-void connman_provider_set_dns(struct connman_provider *provider,
-                                                       const char *dns);
-void connman_provider_set_domain(struct connman_provider *provider,
-                                                       const char *domain);
-
+int connman_provider_set_ipaddress(struct connman_provider *provider,
+                                       struct connman_ipaddress *ipaddress);
+int connman_provider_set_pac(struct connman_provider *provider,
+                               const char *pac);
+int connman_provider_set_domain(struct connman_provider *provider,
+                               const char *domain);
+int connman_provider_set_nameservers(struct connman_provider *provider,
+                                       const char *nameservers);
 int connman_provider_append_route(struct connman_provider *provider,
                                        const char *key, const char *value);
 
index 2b9f0f263827865fb26ce0f290f74e8588addfbf..3aa35371aad876a8d7360328e456b0702335e4a1 100644 (file)
@@ -800,6 +800,75 @@ int connman_provider_get_index(struct connman_provider *provider)
        return provider->element.index;
 }
 
+int connman_provider_set_ipaddress(struct connman_provider *provider,
+                                       struct connman_ipaddress *ipaddress)
+{
+       struct connman_ipconfig *ipconfig = NULL;
+
+       if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV4) {
+               ipconfig = __connman_service_get_ip4config(
+                                               provider->vpn_service);
+       } else if (ipaddress->family == CONNMAN_IPCONFIG_TYPE_IPV6) {
+               ipconfig = __connman_service_get_ip6config(
+                                               provider->vpn_service);
+       }
+
+       if (ipconfig == NULL)
+               return -EINVAL;
+
+       __connman_ipconfig_set_local(ipconfig, ipaddress->local);
+       __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
+       __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+       __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+       __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
+
+       return 0;
+}
+
+int connman_provider_set_pac(struct connman_provider *provider, const char *pac)
+{
+       DBG("provider %p pac %s", provider, pac);
+
+       __connman_service_set_pac(provider->vpn_service, pac);
+
+       return 0;
+}
+
+
+int connman_provider_set_domain(struct connman_provider *provider,
+                                       const char *domain)
+{
+       DBG("provider %p domain %s", provider, domain);
+
+       g_free(provider->domain);
+       provider->domain = g_strdup(domain);
+
+       __connman_service_set_domainname(provider->vpn_service, domain);
+
+       return 0;
+}
+
+int connman_provider_set_nameservers(struct connman_provider *provider,
+                                       const char *nameservers)
+{
+       int i;
+       char **nameservers_array = NULL;
+
+       DBG("provider %p nameservers %s", provider, nameservers);
+
+       __connman_service_nameserver_clear(provider->vpn_service);
+
+       if (nameservers != NULL)
+               nameservers_array = g_strsplit(nameservers, " ", 0);
+
+       for (i = 0; nameservers_array[i] == NULL; i++) {
+               __connman_service_nameserver_append(provider->vpn_service,
+                                                       nameservers_array[i]);
+       }
+
+       return 0;
+}
+
 enum provider_route_type {
        PROVIDER_ROUTE_TYPE_NONE = 0,
        PROVIDER_ROUTE_TYPE_MASK = 1,