From 5d74e1124dd3cc2e7c27fa6ded77e87329e28796 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 25 Nov 2023 15:50:49 +1100 Subject: [PATCH] Fix compilation for curl 7.68.0 --- client.cpp | 12 +++++++++++- lxb_wrapper.h | 4 ++-- models.h | 2 +- servehelper.cpp | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/client.cpp b/client.cpp index b4b0c1f..f231e09 100644 --- a/client.cpp +++ b/client.cpp @@ -43,9 +43,15 @@ MastodonClient::MastodonClient() { try { setopt(this->_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); setopt(this->_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION); +#if CURL_AT_LEAST_VERSION(7, 57, 0) setopt(this->_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); +#endif +#if CURL_AT_LEAST_VERSION(7, 61, 0) setopt(this->_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_PSL); +#endif +#if CURL_AT_LEAST_VERSION(7, 88, 0) setopt(this->_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_HSTS); +#endif setopt(this->_share, CURLSHOPT_LOCKFUNC, share_lock); setopt(this->_share, CURLSHOPT_UNLOCKFUNC, share_unlock); @@ -206,7 +212,11 @@ CURL* MastodonClient::_get_easy() { try { setopt(curl, CURLOPT_TIMEOUT_MS, 10000L); +#if CURL_AT_LEAST_VERSION(7, 85, 0) setopt(curl, CURLOPT_PROTOCOLS_STR, "https"); +#else + setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); +#endif setopt(curl, CURLOPT_USERAGENT, "Coyote (https://gitlab.com/blankX/coyote; blankie@nixnetmail.com)"); setopt(curl, CURLOPT_SHARE, this->_share); } catch (const std::exception& e) { @@ -266,7 +276,7 @@ long MastodonClient::_response_status_code() { static void lowercase(std::string& str) { for (size_t i = 0; i < str.size(); i++) { if (str[i] >= 'A' && str[i] <= 'Z') { - str[i] = str[i] - static_cast('A' + 'a'); + str[i] = static_cast(str[i] - 'A' + 'a'); } } } diff --git a/lxb_wrapper.h b/lxb_wrapper.h index 5008f86..b2ccc01 100644 --- a/lxb_wrapper.h +++ b/lxb_wrapper.h @@ -89,6 +89,6 @@ private: lxb_html_document_t* _document; }; -}; // namespace HTML +} // namespace HTML -}; // namespace LXB +} // namespace LXB diff --git a/models.h b/models.h index ca1f4e0..8c8a4d0 100644 --- a/models.h +++ b/models.h @@ -41,7 +41,7 @@ struct Account { std::vector emojis; std::vector fields; - constexpr std::string acct(bool always_show_domain = true) const { + inline std::string acct(bool always_show_domain = true) const { std::string res = this->username; if (always_show_domain || !this->same_server) { res += '@'; diff --git a/servehelper.cpp b/servehelper.cpp index 4f0cf91..ffe7104 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -29,13 +29,26 @@ static inline Element serialize_poll(const httplib::Request& req, const Poll& po class CurlUrlException : public std::exception { public: - CurlUrlException(CURLUcode code_) : code(code_) {} + CurlUrlException(CURLUcode code_) : code(code_) { +#if !CURL_AT_LEAST_VERSION(7, 80, 0) + snprintf(this->_id_buf, 64, "curl url error %d", this->code); +#endif + } const char* what() const noexcept { +#if CURL_AT_LEAST_VERSION(7, 80, 0) return curl_url_strerror(this->code); +#else + return this->_id_buf; +#endif } CURLUcode code; + +private: +#if !CURL_AT_LEAST_VERSION(7, 80, 0) + char _id_buf[64]; +#endif };