From 04b0ae3e8101fc36a9df3aa07bf9e6dfdf1b0d38 Mon Sep 17 00:00:00 2001 From: horchi Date: Tue, 28 Jul 2020 12:23:04 +0200 Subject: 2020-07-28: version 1.1.162 (Alexander Grothe, horchi)\n - change: Improved curl handling\n\n --- HISTORY.h | 7 +++++-- lib/curl.c | 10 ++++++++-- lib/test.c | 22 ++++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/HISTORY.h b/HISTORY.h index b1d41ec..c94d01f 100644 --- a/HISTORY.h +++ b/HISTORY.h @@ -4,8 +4,8 @@ * ----------------------------------- */ -#define _VERSION "1.1.161" -#define VERSION_DATE "27.07.2020" +#define _VERSION "1.1.162" +#define VERSION_DATE "28.07.2020" #define DB_API 7 #ifdef GIT_REV @@ -19,6 +19,9 @@ * * +2020-07-28: version 1.1.162 (Alexander Grothe, horchi) + - change: Improved curl handling + 2020-07-27: version 1.1.161 (Alexander Grothe, horchi) - change: Porting to new libmicrohttpd diff --git a/lib/curl.c b/lib/curl.c index 93cb4a3..9f954ec 100644 --- a/lib/curl.c +++ b/lib/curl.c @@ -99,6 +99,10 @@ int cCurl::init(const char* httpproxy) return fail; } } + else + { + curl_easy_reset(handle); + } // Reset Options @@ -451,10 +455,11 @@ int cCurl::downloadFile(const char* url, int& size, MemoryStruct* data, int time long httpCode = 0; curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &httpCode); - tell(1, "Error: Download failed; %s (%d); http code was (%ld) [%s]", - curl_easy_strerror(res), res, httpCode, url); + tell(1, "Error: Download failed, got %ld bytes; %s (%d); http code was (%ld) [%s]", + data->size, curl_easy_strerror(res), res, httpCode, url); data->clear(); + exit(); return fail; } @@ -465,6 +470,7 @@ int cCurl::downloadFile(const char* url, int& size, MemoryStruct* data, int time if (code == 404) { data->clear(); + exit(); return fail; } diff --git a/lib/test.c b/lib/test.c index 705cc2f..8a997e2 100644 --- a/lib/test.c +++ b/lib/test.c @@ -666,26 +666,36 @@ int main(int argc, char** argv) char* url = 0; MemoryStruct data; - data.clear(); + curl.init(""); if (strncmp(argv[1], "http", 4) == 0) asprintf(&url, "%s", argv[1]); else - asprintf(&url, "%s/eplist.cgi?action=show&file=%s", - "www.eplists.de", argv[1]); + asprintf(&url, "%s/eplist.cgi?action=show&file=%s", "www.eplists.de", argv[1]); tell(0, "try to download [%s]", url); - if (curl.downloadFile(url, size, &data) == success) + data.clear(); + data.headerOnly = yes; + + if (curl.downloadFile(url, size, &data, 30, "libcurl-agent/1.0") == success) + tell(0, "Got header for '%s-%s' with %d bytes", data.name, data.tag, size); + else + tell(0, "downloadFile failed!"); + + data.clear(); + + if (curl.downloadFile(url, size, &data, 30, "libcurl-agent/1.0") == success) { tell(0, "succeeded!"); - tell(0, "Got: !"); + tell(0, "Got: %d bytes", size); tell(0, "%s", data.memory); + storeToFile("./data", data.memory, size); + tell(0, "stored to './data'"); } else tell(0, "FAILED!"); - free(url); return 0; -- cgit v1.2.3