Refactor Code
[platform/upstream/connman.git] / plugins / vpn.c
old mode 100644 (file)
new mode 100755 (executable)
index d708d1f..42396d2
@@ -3,6 +3,7 @@
  *  Connection Manager
  *
  *  Copyright (C) 2012-2013  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2019-2021  Jolla Ltd. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -491,6 +492,9 @@ static int errorstr2val(const char *error) {
        if (g_strcmp0(error, CONNMAN_ERROR_INTERFACE ".AlreadyConnected") == 0)
                return -EISCONN;
 
+       if (g_strcmp0(error, CONNMAN_ERROR_INTERFACE ".NoCarrier") == 0)
+               return -ENOLINK;
+
        if (g_strcmp0(error, CONNMAN_ERROR_INTERFACE ".OperationCanceled") == 0)
                return -ECANCELED;
 
@@ -529,16 +533,23 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
        if (dbus_set_error_from_message(&error, reply)) {
                int err = errorstr2val(error.name);
 
+               switch (err) {
+               case -EINPROGRESS:
+                       break;
                /*
                 * ECANCELED means that user has canceled authentication
                 * dialog. That's not really an error, it's part of a normal
                 * workflow. We also take it as a request to turn autoconnect
                 * off, in case if it was on.
                 */
-               if (err == -ECANCELED) {
+               case -ECANCELED:
                        DBG("%s connect canceled", data->path);
                        connman_provider_set_autoconnect(data->provider, false);
-               } else if (err != -EINPROGRESS) {
+                       break;
+               case -ENOLINK: /* vpnd reports that connmand is not online. */
+               case -EISCONN:
+               case -ECONNREFUSED:
+               default:
                        connman_error("Connect reply: %s (%s)", error.message,
                                                                error.name);
                        DBG("data %p cb_data %p", data, cb_data);
@@ -1016,7 +1027,7 @@ static int disconnect_provider(struct connection_data *data)
 
        if (data->disconnect_call) {
                DBG("already disconnecting");
-               return -EINVAL;
+               return -EALREADY;
        }
 
        message = dbus_message_new_method_call(VPN_SERVICE, data->path,