service: Add helpers for removing nameservers and search domains
[framework/connectivity/connman.git] / src / service.c
index 9220ad9..fae3729 100644 (file)
@@ -840,6 +840,74 @@ static connman_bool_t is_connected(struct connman_service *service)
        return is_connected_state(service, service->state);
 }
 
+static const char *nameserver_get_ifname(struct connman_service *service)
+{
+       const char *ifname;
+
+       if (service->ipconfig_ipv4)
+               ifname = __connman_ipconfig_get_ifname(service->ipconfig_ipv4);
+       else if (service->ipconfig_ipv6)
+               ifname = __connman_ipconfig_get_ifname(service->ipconfig_ipv6);
+       else
+               ifname = NULL;
+
+       if (ifname == NULL)
+               return NULL;
+
+       switch (combine_state(service->state_ipv4, service->state_ipv6)) {
+       case CONNMAN_SERVICE_STATE_UNKNOWN:
+       case CONNMAN_SERVICE_STATE_IDLE:
+       case CONNMAN_SERVICE_STATE_ASSOCIATION:
+       case CONNMAN_SERVICE_STATE_CONFIGURATION:
+       case CONNMAN_SERVICE_STATE_FAILURE:
+       case CONNMAN_SERVICE_STATE_DISCONNECT:
+               return NULL;
+       case CONNMAN_SERVICE_STATE_READY:
+       case CONNMAN_SERVICE_STATE_ONLINE:
+               break;
+       }
+
+       return ifname;
+}
+
+static void remove_nameservers(struct connman_service *service,
+               const char* interface, char **ns)
+{
+       const char *ifname = interface;
+       int i;
+
+       if (ns == NULL)
+               return;
+
+       if (interface == NULL)
+               ifname = nameserver_get_ifname(service);
+
+       if (ifname == NULL)
+                       return;
+
+       for (i = 0; ns[i] != NULL; i++)
+               connman_resolver_remove(ifname, NULL, ns[i]);
+}
+
+static void remove_searchdomains(struct connman_service *service,
+               const char *interface, char **sd)
+{
+       const char *ifname = interface;
+       int i;
+
+       if (sd == NULL)
+               return;
+
+       if (interface == NULL)
+               ifname = nameserver_get_ifname(service);
+
+       if (ifname == NULL)
+               return;
+
+       for (i = 0; sd[i] != NULL; i++)
+               connman_resolver_remove(ifname, sd[i], NULL);
+}
+
 static void update_nameservers(struct connman_service *service)
 {
        const char *ifname;
@@ -4718,7 +4786,7 @@ static int service_indicate_state(struct connman_service *service)
                if (service->userconnect == TRUE &&
                        __connman_agent_report_error(service,
                                        error2string(service->error),
-                                       report_error_cb, NULL) == -EIO)
+                                       report_error_cb, NULL) == -EINPROGRESS)
                        return 0;
                service_complete(service);
        } else
@@ -5252,13 +5320,6 @@ int __connman_service_connect(struct connman_service *service)
                return -EINPROGRESS;
        }
 
-       __connman_service_ipconfig_indicate_state(service,
-                                       CONNMAN_SERVICE_STATE_FAILURE,
-                                       CONNMAN_IPCONFIG_TYPE_IPV4);
-       __connman_service_ipconfig_indicate_state(service,
-                                       CONNMAN_SERVICE_STATE_FAILURE,
-                                       CONNMAN_IPCONFIG_TYPE_IPV6);
-
        if (service->network != NULL)
                __connman_network_disconnect(service->network);
        else if (service->type == CONNMAN_SERVICE_TYPE_VPN &&
@@ -5267,10 +5328,8 @@ int __connman_service_connect(struct connman_service *service)
 
        if (service->userconnect == TRUE) {
                if (err == -ENOKEY || err == -EPERM) {
-                       if (__connman_agent_request_passphrase_input(service,
-                                                       request_input_cb,
-                                                       NULL) == -EIO)
-                               return -EINPROGRESS;
+                       return __connman_agent_request_passphrase_input(service,
+                                       request_input_cb, NULL);
                }
                reply_pending(service, -err);
        }
@@ -5936,7 +5995,7 @@ struct connman_service * __connman_service_create_from_network(struct connman_ne
 
        if (service->favorite == TRUE) {
                device = connman_network_get_device(service->network);
-               if (device && __connman_device_scanning(device) == FALSE)
+               if (device && connman_device_get_scanning(device) == FALSE)
                        __connman_service_auto_connect();
        }