Better error message for SOUP_STATUS_SSL_FAILED response
authorMilan Crha <mcrha@redhat.com>
Thu, 10 May 2012 18:02:31 +0000 (20:02 +0200)
committerMilan Crha <mcrha@redhat.com>
Thu, 10 May 2012 18:02:31 +0000 (20:02 +0200)
addressbook/backends/webdav/e-book-backend-webdav.c
calendar/backends/caldav/e-cal-backend-caldav.c
calendar/backends/http/e-cal-backend-http.c

index 1e9bc06..4ca5e43 100644 (file)
@@ -1208,7 +1208,6 @@ e_book_backend_webdav_authenticate_user (EBookBackend *backend,
        EBookBackendWebdav        *webdav = E_BOOK_BACKEND_WEBDAV (backend);
        EBookBackendWebdavPrivate *priv   = webdav->priv;
        SoupMessage               *message;
-       guint                      status;
 
        priv->username = e_credentials_get (credentials, E_CREDENTIALS_KEY_USERNAME);
        priv->password = e_credentials_get (credentials, E_CREDENTIALS_KEY_PASSWORD);
@@ -1216,19 +1215,44 @@ e_book_backend_webdav_authenticate_user (EBookBackend *backend,
        /* Evolution API requires a direct feedback on the authentication,
         * so we send a PROPFIND to test wether user/password is correct */
        message = send_propfind (webdav);
-       status  = message->status_code;
-       g_object_unref (message);
 
-       if (status == 401 || status == 407) {
+       if (message->status_code == 401 || message->status_code == 407) {
                g_free (priv->username);
                priv->username = NULL;
                e_credentials_util_safe_free_string (priv->password);
                priv->password = NULL;
 
                e_book_backend_notify_opened (backend, EDB_ERROR (AUTHENTICATION_FAILED));
-       } else {
+       } else if (SOUP_STATUS_IS_SUCCESSFUL (message->status_code) || message->status_code == 207) {
                e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
+       } else if (message->status_code == SOUP_STATUS_SSL_FAILED) {
+               ESource *source = e_backend_get_source (E_BACKEND (backend));
+
+               if (g_strcmp0 (e_source_get_property (source, "ignore-invalid-cert"), "1") == 0) {
+                       e_book_backend_notify_opened (backend,
+                               e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR,
+                               _("Failed to connect to a server using SSL: %s"),
+                               message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+                               (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error"))));
+               } else {
+                       e_book_backend_notify_opened (backend, EDB_ERROR_EX (OTHER_ERROR,
+                               _("Failed to connect to a server using SSL. "
+                               "One possible reason is an invalid certificate being used by the server. "
+                               "If this is expected, like self-signed certificate being used on the server, "
+                               "then disable certificate validity tests by selecting 'Ignore invalid SSL certificate' option "
+                               "in Properties")));
+               }
+       } else {
+               e_book_backend_notify_opened (backend,
+                       e_data_book_create_error_fmt (
+                               E_DATA_BOOK_STATUS_OTHER_ERROR,
+                               _("Unexpected HTTP status code %d returned (%s)"),
+                                       message->status_code,
+                                       message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+                                       (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error"))));
        }
+
+       g_object_unref (message);
 }
 
 /** authentication callback for libsoup */
index cafebb5..aa0d142 100644 (file)
@@ -546,6 +546,7 @@ status_code_to_result (SoupMessage *message,
                        GError **perror)
 {
        ECalBackendCalDAVPrivate *priv;
+       ESource *source;
 
        g_return_val_if_fail (cbdav != NULL, FALSE);
        g_return_val_if_fail (message != NULL, FALSE);
@@ -556,6 +557,8 @@ status_code_to_result (SoupMessage *message,
                return TRUE;
        }
 
+       source = e_backend_get_source (E_BACKEND (cbdav));
+
        switch (message->status_code) {
        case SOUP_STATUS_CANT_CONNECT:
        case SOUP_STATUS_CANT_CONNECT_PROXY:
@@ -588,6 +591,23 @@ status_code_to_result (SoupMessage *message,
                        g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
                break;
 
+       case SOUP_STATUS_SSL_FAILED:
+               if (g_strcmp0 (e_source_get_property (source, "ignore-invalid-cert"), "1") == 0) {
+                       g_propagate_error (perror,
+                               e_data_cal_create_error_fmt ( OtherError,
+                               _("Failed to connect to a server using SSL: %s"),
+                               message->reason_phrase && *message->reason_phrase ? message->reason_phrase :
+                               (soup_status_get_phrase (message->status_code) ? soup_status_get_phrase (message->status_code) : _("Unknown error"))));
+               } else {
+                       g_propagate_error (perror, EDC_ERROR_EX (OtherError,
+                               _("Failed to connect to a server using SSL. "
+                               "One possible reason is an invalid certificate being used by the server. "
+                               "If this is expected, like self-signed certificate being used on the server, "
+                               "then disable certificate validity tests by selecting 'Ignore invalid SSL certificate' option "
+                               "in Properties")));
+               }
+               break;
+
        default:
                d(g_debug ("CalDAV:%s: Unhandled status code %d\n", G_STRFUNC, status_code));
                g_propagate_error (perror,
index c9e8f08..db8ff9f 100644 (file)
@@ -417,6 +417,24 @@ retrieval_done (SoupSession *session,
                                e_cal_backend_notify_auth_required (E_CAL_BACKEND (cbhttp), TRUE, priv->credentials);
                                g_object_unref (cbhttp);
                                return;
+                       } else if (msg->status_code == SOUP_STATUS_SSL_FAILED) {
+                               ESource *source = e_backend_get_source (E_BACKEND (cbhttp));
+                               gchar *err_msg;
+
+                               if (g_strcmp0 (e_source_get_property (source, "ignore-invalid-cert"), "1") == 0) {
+                                       err_msg = g_strdup_printf (_("Failed to connect to a server using SSL: %s"),
+                                               msg->reason_phrase && *msg->reason_phrase ? msg->reason_phrase :
+                                               (soup_status_get_phrase (msg->status_code) ? soup_status_get_phrase (msg->status_code) : _("Unknown error")));
+                               } else {
+                                       err_msg = g_strdup (_("Failed to connect to a server using SSL. "
+                                               "One possible reason is an invalid certificate being used by the server. "
+                                               "If this is expected, like self-signed certificate being used on the server, "
+                                               "then disable certificate validity tests by selecting 'Ignore invalid SSL certificate' option "
+                                               "in Properties"));
+                               }
+               
+                               e_cal_backend_notify_error (E_CAL_BACKEND (cbhttp), err_msg);
+                               g_free (err_msg);
                        } else
                                e_cal_backend_notify_error (E_CAL_BACKEND (cbhttp),
                                        msg->reason_phrase && *msg->reason_phrase ? msg->reason_phrase :