diff options
-rw-r--r-- | HISTORY.h | 7 | ||||
-rw-r--r-- | lib/curl.c | 10 | ||||
-rw-r--r-- | lib/test.c | 22 |
3 files changed, 29 insertions, 10 deletions
@@ -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 @@ -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; } @@ -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; |