From 1af3ea100db5ef2708ffd3725d3ef206a4ff9b28 Mon Sep 17 00:00:00 2001 From: Sanchit Saini Date: Sat, 8 Jun 2024 05:34:19 +0530 Subject: [PATCH 1/3] Improved platform independence via curl_version_info() --- src/ucsc/net.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ucsc/net.c b/src/ucsc/net.c index 263c08e..4e1a52a 100644 --- a/src/ucsc/net.c +++ b/src/ucsc/net.c @@ -12,8 +12,21 @@ #include "cheapcgi.h" time_t header_get_last_modified(CURL *curl) { + CURLcode status; curl_off_t last_modified; - CURLcode status = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &last_modified); + + curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW); + unsigned int major = (ver->version_num >> 16) & 0xff; + unsigned int minor = (ver->version_num >> 8) & 0xff; + unsigned int patch = ver->version_num & 0xff; + + if (major > 7) + status = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &last_modified); + if (major == 7 && minor >= 59 && patch >= 0) + status = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &last_modified); + else + status = curl_easy_getinfo(curl, CURLINFO_FILETIME, &last_modified); + if ((CURLE_OK == status) && (last_modified >= 0)) { struct tm *utc_tm_info = gmtime(&last_modified); From 735ab1713f59b884f04e7003140b4e42de111f74 Mon Sep 17 00:00:00 2001 From: Sanchit Saini Date: Tue, 11 Jun 2024 01:54:07 +0530 Subject: [PATCH 2/3] Improved platform independence via LIBCURL_VERSION_NUM --- src/ucsc/net.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ucsc/net.c b/src/ucsc/net.c index 4e1a52a..04be606 100644 --- a/src/ucsc/net.c +++ b/src/ucsc/net.c @@ -12,21 +12,15 @@ #include "cheapcgi.h" time_t header_get_last_modified(CURL *curl) { - CURLcode status; curl_off_t last_modified; - curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW); - unsigned int major = (ver->version_num >> 16) & 0xff; - unsigned int minor = (ver->version_num >> 8) & 0xff; - unsigned int patch = ver->version_num & 0xff; - - if (major > 7) - status = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &last_modified); - if (major == 7 && minor >= 59 && patch >= 0) - status = curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &last_modified); - else - status = curl_easy_getinfo(curl, CURLINFO_FILETIME, &last_modified); + #if LIBCURL_VERSION_NUM >= 0x073b00 + #define FILETIME CURLINFO_FILETIME_T + #else + #define FILETIME CURLINFO_FILETIME + #endif + CURLcode status = curl_easy_getinfo(curl, FILETIME, &last_modified); if ((CURLE_OK == status) && (last_modified >= 0)) { struct tm *utc_tm_info = gmtime(&last_modified); From 30e60d0d5c40394016a996f8bd1a400280a9ab62 Mon Sep 17 00:00:00 2001 From: Sanchit Saini Date: Wed, 21 Aug 2024 14:01:34 +0530 Subject: [PATCH 3/3] Add checks for remaining MACROS to handle older libcurl --- src/ucsc/net.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ucsc/net.c b/src/ucsc/net.c index 04be606..7328f07 100644 --- a/src/ucsc/net.c +++ b/src/ucsc/net.c @@ -15,12 +15,12 @@ time_t header_get_last_modified(CURL *curl) { curl_off_t last_modified; #if LIBCURL_VERSION_NUM >= 0x073b00 - #define FILETIME CURLINFO_FILETIME_T + #define CI_FILETIME CURLINFO_FILETIME_T #else - #define FILETIME CURLINFO_FILETIME + #define CI_FILETIME CURLINFO_FILETIME #endif - CURLcode status = curl_easy_getinfo(curl, FILETIME, &last_modified); + CURLcode status = curl_easy_getinfo(curl, CI_FILETIME, &last_modified); if ((CURLE_OK == status) && (last_modified >= 0)) { struct tm *utc_tm_info = gmtime(&last_modified); @@ -37,8 +37,14 @@ time_t header_get_last_modified(CURL *curl) { long long header_get_content_length(CURL *curl) { curl_off_t content_length; - CURLcode status = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, - &content_length); + + #if LIBCURL_VERSION_NUM >= 0x073700 + #define CI_CONTENT_LENGTH CURLINFO_CONTENT_LENGTH_DOWNLOAD_T + #else + #define CI_CONTENT_LENGTH CURLINFO_CONTENT_LENGTH_DOWNLOAD + #endif + + CURLcode status = curl_easy_getinfo(curl, CI_CONTENT_LENGTH, &content_length); // could not retrieve length if (content_length == -1) @@ -160,7 +166,14 @@ int netUrlOpenSockets(char *url, int *retCtrlSocket) { } else if (startsWith("ftp://", url)) { curl_socket_t ctrlSocket; CURLcode status = wrapped_curl_request(curl, GET); - curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &ctrlSocket); + + #if LIBCURL_VERSION_NUM >= 0x072d00 + #define CI_SOCKET CURLINFO_ACTIVESOCKET + #else + #define CI_SOCKET CURLINFO_LASTSOCKET + #endif + + curl_easy_getinfo(curl, CI_SOCKET, &ctrlSocket); if (retCtrlSocket != NULL) *retCtrlSocket = ctrlSocket;