From: Brulhart <unknown@domain.tld>
Date: Sat, 15 Mar 2025 09:03:11 +0100
Subject: extend the versions of libcurl that can be used to build ffs

Co-authored-by: "B. Stack" <bgstack15@gmail.com>
Co-authored-by: Fab Stz <fabstz-it@yahoo.fr>
Origin: multiple sources
Forwarded: https://freefilesync.org/forum/viewtopic.php?t=9687
Last-Update: 2025-03-04


Minimal version supported by this patch is libcurl >= 7.66

FreeFileSync makes an 'assert' that it supports all error codes of the curl
version that it links to. Since FreeFileSync code is shipped to build
with a specific version of curl, there is a hard coded assertion.

To avoid a build failure when curl is not in line with the one used upstream
we make conditional checks on the curl version to determine which assertion
should be made.

While this works fine to build with any old version of curl > 7.66, there
will be a build fairure as soon as a new error code appears in a newer version
of curl. In that case it is required to add it here.

Error codes can be found in the 'enum' named 'CURLcode' at
https://github.com/curl/curl/blob/master/include/curl/curl.h
---
 libcurl/curl_wrap.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/libcurl/curl_wrap.cpp b/libcurl/curl_wrap.cpp
index b2a7560..2a1a71a 100644
--- a/libcurl/curl_wrap.cpp
+++ b/libcurl/curl_wrap.cpp
@@ -335,14 +335,22 @@ std::wstring zen::formatCurlStatusCode(CURLcode sc)
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE32);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_RANGE_ERROR);
+#if LIBCURL_VERSION_NUM >= 0x080B01 // 8.11.1
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE34);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_HTTP_POST_ERROR);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSL_CONNECT_ERROR);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_LDAP_CANNOT_BIND);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE40);
+#if LIBCURL_VERSION_NUM >= 0x080B01 // 8.11.1
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE41);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE44);
@@ -350,7 +358,11 @@ std::wstring zen::formatCurlStatusCode(CURLcode sc)
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE46);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_UNKNOWN_OPTION);
+#if LIBCURL_VERSION_NUM >= 0x074E00 // 7.78.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SETOPT_OPTION_SYNTAX);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE50);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE51);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_GOT_NOTHING);
@@ -363,7 +375,11 @@ std::wstring zen::formatCurlStatusCode(CURLcode sc)
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSL_CIPHER);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_PEER_FAILED_VERIFICATION);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
+#if LIBCURL_VERSION_NUM >= 0x075200 // 7.82.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE62);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_LDAP_INVALID_URL);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_FILESIZE_EXCEEDED);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_USE_SSL_FAILED);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SEND_FAIL_REWIND);
@@ -376,8 +392,16 @@ std::wstring zen::formatCurlStatusCode(CURLcode sc)
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_TFTP_UNKNOWNID);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_REMOTE_FILE_EXISTS);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_TFTP_NOSUCHUSER);
+#if LIBCURL_VERSION_NUM >= 0x075500 // 7.85.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE75);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_CONV_FAILED);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x075200 // 7.82.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_OBSOLETE76);
+#else
+            ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_CONV_REQD);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSL_CACERT_BADFILE);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_REMOTE_FILE_NOT_FOUND);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSH);
@@ -395,17 +419,51 @@ std::wstring zen::formatCurlStatusCode(CURLcode sc)
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSL_INVALIDCERTSTATUS);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_HTTP2_STREAM);
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_RECURSIVE_API_CALL);
+#if LIBCURL_VERSION_NUM >= 0x074200 // 7.66.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_AUTH_ERROR);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x074400 // 7.68.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_HTTP3);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x074500 // 7.69.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_QUIC_CONNECT_ERROR);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x074900 // 7.73.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_PROXY);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x074D00 // 7.77.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_SSL_CLIENTCERT);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x075400 // 7.84.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_UNRECOVERABLE_POLL);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x080600 // 8.6.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_TOO_LARGE);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x080800 // 8.8.0
             ZEN_CHECK_CASE_FOR_CONSTANT(CURLE_ECH_REQUIRED);
+#endif
             ZEN_CHECK_CASE_FOR_CONSTANT(CURL_LAST);
     }
+#if LIBCURL_VERSION_NUM >= 0x080800 // 8.8.0
     static_assert(CURL_LAST == CURLE_ECH_REQUIRED + 1);
+#elif LIBCURL_VERSION_NUM >= 0x080600 // 8.6.0
+    static_assert(CURL_LAST == CURLE_TOO_LARGE + 1);
+#elif LIBCURL_VERSION_NUM >= 0x075400 // 7.84.0
+    static_assert(CURL_LAST == CURLE_UNRECOVERABLE_POLL + 1);
+#elif LIBCURL_VERSION_NUM >= 0x074D00 // 7.77.0
+    static_assert(CURL_LAST == CURLE_SSL_CLIENTCERT + 1);
+#elif LIBCURL_VERSION_NUM >= 0x074900 // 7.73.0
+    static_assert(CURL_LAST == CURLE_PROXY + 1);
+#elif LIBCURL_VERSION_NUM >= 0x074500 // 7.69.0
+    static_assert(CURL_LAST == CURLE_QUIC_CONNECT_ERROR + 1);
+#elif LIBCURL_VERSION_NUM >= 0x074400 // 7.68.0
+    static_assert(CURL_LAST == CURLE_HTTP3 + 1);
+#elif LIBCURL_VERSION_NUM >= 0x074200 // 7.66.0
+    static_assert(CURL_LAST == CURLE_AUTH_ERROR + 1);
+#else
+    static_assert(CURL_LAST == CURLE_RECURSIVE_API_CALL + 1);
+#endif
 
     return replaceCpy<std::wstring>(L"Curl status %x", L"%x", numberTo<std::wstring>(static_cast<int>(sc)));
 }
