diff --git a/src/network/state.c b/src/network/state.c index c2ce88fd..09491e17 100644 --- a/src/network/state.c +++ b/src/network/state.c @@ -4,6 +4,10 @@ #include "config.h" #endif +#ifdef CONFIG_LIBCURL +#include +#endif + #include #include "elinks.h" @@ -158,6 +162,12 @@ get_state_message(struct connection_state state, struct terminal *term) int len; char *unknown_error = _("Unknown error", term); +#ifdef CONFIG_LIBCURL + if (state.basic < S_CURL_ERROR) { + return (char *)curl_easy_strerror(S_CURL_ERROR - state.basic); + } +#endif + if (!is_system_error(state)) { int i; diff --git a/src/network/state.h b/src/network/state.h index d03c060c..09dc6953 100644 --- a/src/network/state.h +++ b/src/network/state.h @@ -114,6 +114,8 @@ enum connection_basic_state { S_BITTORRENT_PEER_URL = -100804, S_FSP_OPEN_SESSION_UNKN = -100900, + + S_CURL_ERROR = -101000, }; typedef int connection_basic_state_T; diff --git a/src/protocol/curl/ftp.c b/src/protocol/curl/ftp.c index e9e6a8bc..92d5179c 100644 --- a/src/protocol/curl/ftp.c +++ b/src/protocol/curl/ftp.c @@ -616,24 +616,22 @@ check_multi_info(GlobalInfo *g) res = msg->data.result; curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); - if (res == CURLE_REMOTE_FILE_NOT_FOUND || res == CURLE_SSH) { - ftp = (struct ftpes_connection_info *)conn->info; + if (conn->uri->protocol == PROTOCOL_HTTP || conn->uri->protocol == PROTOCOL_HTTPS) { + http_curl_handle_error(conn, res); + continue; + } - if (ftp && !ftp->dir) { - retry_connection(conn, connection_state(S_RESTART)); - } else { - abort_connection(conn, connection_state(S_OK)); - } - } else { - if (conn->uri->protocol == PROTOCOL_HTTP || conn->uri->protocol == PROTOCOL_HTTPS) { - char *url = http_curl_check_redirect(conn); + if (conn->uri->protocol == PROTOCOL_FTP || conn->uri->protocol == PROTOCOL_FTPES || conn->uri->protocol == PROTOCOL_SFTP) { + if (res == CURLE_REMOTE_FILE_NOT_FOUND || res == CURLE_SSH) { + ftp = (struct ftpes_connection_info *)conn->info; - if (url) { - redirect_cache(conn->cached, url, 0, 0); + if (ftp && !ftp->dir) { + retry_connection(conn, connection_state(S_RESTART)); + } else { abort_connection(conn, connection_state(S_OK)); - return; } } + } else { abort_connection(conn, connection_state(S_OK)); } } diff --git a/src/protocol/curl/http.c b/src/protocol/curl/http.c index c1220180..714bb40d 100644 --- a/src/protocol/curl/http.c +++ b/src/protocol/curl/http.c @@ -360,7 +360,7 @@ http_got_data(void *stream, void *buf, size_t len) abort_connection(conn, connection_state(S_OK)); } -char * +static char * http_curl_check_redirect(struct connection *conn) { struct http_curl_connection_info *http; @@ -383,6 +383,24 @@ http_curl_check_redirect(struct connection *conn) return NULL; } +void +http_curl_handle_error(struct connection *conn, CURLcode res) +{ + if (res == CURLE_OK) { + char *url = http_curl_check_redirect(conn); + + if (url) { + redirect_cache(conn->cached, url, 0, 0); + abort_connection(conn, connection_state(S_OK)); + return; + } + abort_connection(conn, connection_state(S_OK)); + return; + } else { + abort_connection(conn, connection_state(S_CURL_ERROR - res)); + } +} + void http_curl_protocol_handler(struct connection *conn) { diff --git a/src/protocol/curl/http.h b/src/protocol/curl/http.h index deca4186..988d0278 100644 --- a/src/protocol/curl/http.h +++ b/src/protocol/curl/http.h @@ -1,6 +1,8 @@ #ifndef EL__PROTOCOL_CURL_HTTP_H #define EL__PROTOCOL_CURL_HTTP_H +#include + #include "main/module.h" #include "protocol/protocol.h" @@ -13,7 +15,7 @@ struct connection; extern protocol_handler_T http_curl_protocol_handler; -char *http_curl_check_redirect(struct connection *conn); +void http_curl_handle_error(struct connection *conn, CURLcode res); #endif