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);
/* 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 */
GError **perror)
{
ECalBackendCalDAVPrivate *priv;
+ ESource *source;
g_return_val_if_fail (cbdav != NULL, FALSE);
g_return_val_if_fail (message != NULL, FALSE);
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:
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,
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 :