From 70c9fe498bd1194439c8e0a614fc63f8c8425ba3 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sun, 6 Oct 2024 07:58:20 +0200 Subject: [PATCH] Curl error code version check macro --- cpr/error.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/cpr/error.cpp b/cpr/error.cpp index bb360c3a8..1dd79f80e 100644 --- a/cpr/error.cpp +++ b/cpr/error.cpp @@ -22,7 +22,12 @@ ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) { return ErrorCode::COULDNT_RESOLVE_HOST; case CURLE_COULDNT_CONNECT: return ErrorCode::COULDNT_CONNECT; +// Name changed in curl >= 7.51.0. +#if LIBCURL_VERSION_NUM >= 0x073300 case CURLE_WEIRD_SERVER_REPLY: +#else + case CURLE_FTP_WEIRD_SERVER_REPLY: +#endif return ErrorCode::WEIRD_SERVER_REPLY; case CURLE_REMOTE_ACCESS_DENIED: return ErrorCode::REMOTE_ACCESS_DENIED; @@ -66,8 +71,11 @@ ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) { return ErrorCode::TOO_MANY_REDIRECTS; case CURLE_UNKNOWN_OPTION: return ErrorCode::UNKNOWN_OPTION; +// Added in curl 7.78.0. +#if LIBCURL_VERSION_NUM >= 0x074E00 case CURLE_SETOPT_OPTION_SYNTAX: return ErrorCode::SETOPT_OPTION_SYNTAX; +#endif case CURLE_GOT_NOTHING: return ErrorCode::GOT_NOTHING; case CURLE_SSL_ENGINE_NOTFOUND: @@ -94,44 +102,98 @@ ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) { return ErrorCode::SEND_FAIL_REWIND; case CURLE_SSL_ENGINE_INITFAILED: return ErrorCode::SSL_ENGINE_INITFAILED; +// Added in curl 7.13.1. +#if LIBCURL_VERSION_NUM >= 0x070D01 case CURLE_LOGIN_DENIED: return ErrorCode::LOGIN_DENIED; +#endif +// Added in curl 7.16.0. +#if LIBCURL_VERSION_NUM >= 0x071000 case CURLE_SSL_CACERT_BADFILE: return ErrorCode::SSL_CACERT_BADFILE; +#endif +// Added in curl 7.16.1. +#if LIBCURL_VERSION_NUM >= 0x071001 case CURLE_SSL_SHUTDOWN_FAILED: return ErrorCode::SSL_SHUTDOWN_FAILED; +#endif +// Added in curl 7.18.2. +#if LIBCURL_VERSION_NUM >= 0x071202 case CURLE_AGAIN: return ErrorCode::AGAIN; +#endif +// Added in curl 7.19.0. +#if LIBCURL_VERSION_NUM >= 0x071300 case CURLE_SSL_CRL_BADFILE: return ErrorCode::SSL_CRL_BADFILE; case CURLE_SSL_ISSUER_ERROR: return ErrorCode::SSL_ISSUER_ERROR; +#endif +// Added in curl 7.21.0. +#if LIBCURL_VERSION_NUM >= 0x071500 case CURLE_CHUNK_FAILED: return ErrorCode::CHUNK_FAILED; +#endif +// Added in curl 7.30.0. +#if LIBCURL_VERSION_NUM >= 0x071E00 case CURLE_NO_CONNECTION_AVAILABLE: return ErrorCode::NO_CONNECTION_AVAILABLE; +#endif +// Added in curl 7.39.0. +#if LIBCURL_VERSION_NUM >= 0x072700 case CURLE_SSL_PINNEDPUBKEYNOTMATCH: return ErrorCode::SSL_PINNEDPUBKEYNOTMATCH; +#endif +// Added in curl 7.41.0. +#if LIBCURL_VERSION_NUM >= 0x072900 case CURLE_SSL_INVALIDCERTSTATUS: return ErrorCode::SSL_INVALIDCERTSTATUS; +#endif +// Added in curl 7.49.0. +#if LIBCURL_VERSION_NUM >= 0x073100 case CURLE_HTTP2_STREAM: return ErrorCode::HTTP2_STREAM; +#endif +// Added in curl 7.59.0. +#if LIBCURL_VERSION_NUM >= 0x073B00 case CURLE_RECURSIVE_API_CALL: return ErrorCode::RECURSIVE_API_CALL; +#endif +// Added in curl 7.66.0. +#if LIBCURL_VERSION_NUM >= 0x074200 case CURLE_AUTH_ERROR: return ErrorCode::AUTH_ERROR; +#endif +// Added in curl 7.68.0. +#if LIBCURL_VERSION_NUM >= 0x074400 case CURLE_HTTP3: return ErrorCode::HTTP3; +#endif +// Added in curl 7.69.0. +#if LIBCURL_VERSION_NUM >= 0x074500 case CURLE_QUIC_CONNECT_ERROR: return ErrorCode::QUIC_CONNECT_ERROR; +#endif +// Added in curl 7.73.0. +#if LIBCURL_VERSION_NUM >= 0x074900 case CURLE_PROXY: return ErrorCode::PROXY; +#endif +// Added in curl 7.77.0. +#if LIBCURL_VERSION_NUM >= 0x074D00 case CURLE_SSL_CLIENTCERT: return ErrorCode::SSL_CLIENTCERT; +#endif +// Added in curl 7.84.0. +#if LIBCURL_VERSION_NUM >= 0x075400 case CURLE_UNRECOVERABLE_POLL: return ErrorCode::UNRECOVERABLE_POLL; +#endif +// Added in curl 7.6.0. +#if LIBCURL_VERSION_NUM >= 0x080600 case CURLE_TOO_LARGE: return ErrorCode::TOO_LARGE; +#endif default: return ErrorCode::UNKNOWN_ERROR; }