1
0
Fork 0

[curl] Display curl error

This commit is contained in:
Witold Filipczyk 2023-06-30 15:57:39 +02:00
parent 62c42d41e3
commit df4a2bedbf
5 changed files with 45 additions and 15 deletions

View File

@ -4,6 +4,10 @@
#include "config.h"
#endif
#ifdef CONFIG_LIBCURL
#include <curl/curl.h>
#endif
#include <string.h>
#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;

View File

@ -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;

View File

@ -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));
}
}

View File

@ -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)
{

View File

@ -1,6 +1,8 @@
#ifndef EL__PROTOCOL_CURL_HTTP_H
#define EL__PROTOCOL_CURL_HTTP_H
#include <curl/curl.h>
#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