1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-16 23:27:15 +02:00

Reinstate CPR using system library.

This commit is contained in:
Sandu Liviu Catalin
2021-03-27 00:18:51 +02:00
parent 91bb79403c
commit bee47a44c4
56 changed files with 5861 additions and 2 deletions

229
vendor/CPR/include/cpr/api.h vendored Normal file
View File

@ -0,0 +1,229 @@
#ifndef CPR_API_H
#define CPR_API_H
#include <fstream>
#include <functional>
#include <future>
#include <string>
#include <utility>
#include "cpr/auth.h"
#include "cpr/bearer.h"
#include "cpr/cprtypes.h"
#include "cpr/digest.h"
#include "cpr/multipart.h"
#include "cpr/ntlm.h"
#include "cpr/payload.h"
#include "cpr/response.h"
#include "cpr/session.h"
#include <utility>
namespace cpr {
using AsyncResponse = std::future<Response>;
namespace priv {
template <typename T>
void set_option(Session& session, T&& t) {
session.SetOption(std::forward<T>(t));
}
template <typename T, typename... Ts>
void set_option(Session& session, T&& t, Ts&&... ts) {
set_option(session, std::forward<T>(t));
set_option(session, std::forward<Ts>(ts)...);
}
} // namespace priv
// Get methods
template <typename... Ts>
Response Get(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Get();
}
// Get async methods
template <typename... Ts>
AsyncResponse GetAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Get(std::move(ts)...); }, std::move(ts)...);
}
// Get callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto GetCallback(Then then, Ts... ts) -> std::future<decltype(then(Get(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Get(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Post methods
template <typename... Ts>
Response Post(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Post();
}
// Post async methods
template <typename... Ts>
AsyncResponse PostAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Post(std::move(ts)...); }, std::move(ts)...);
}
// Post callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto PostCallback(Then then, Ts... ts) -> std::future<decltype(then(Post(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Post(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Put methods
template <typename... Ts>
Response Put(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Put();
}
// Put async methods
template <typename... Ts>
AsyncResponse PutAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Put(std::move(ts)...); }, std::move(ts)...);
}
// Put callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto PutCallback(Then then, Ts... ts) -> std::future<decltype(then(Put(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Put(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Head methods
template <typename... Ts>
Response Head(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Head();
}
// Head async methods
template <typename... Ts>
AsyncResponse HeadAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Head(std::move(ts)...); }, std::move(ts)...);
}
// Head callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto HeadCallback(Then then, Ts... ts) -> std::future<decltype(then(Head(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Head(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Delete methods
template <typename... Ts>
Response Delete(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Delete();
}
// Delete async methods
template <typename... Ts>
AsyncResponse DeleteAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Delete(std::move(ts)...); },
std::move(ts)...);
}
// Delete callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto DeleteCallback(Then then, Ts... ts) -> std::future<decltype(then(Delete(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Delete(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Options methods
template <typename... Ts>
Response Options(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Options();
}
// Options async methods
template <typename... Ts>
AsyncResponse OptionsAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Options(std::move(ts)...); },
std::move(ts)...);
}
// Options callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto OptionsCallback(Then then, Ts... ts)
-> std::future<decltype(then(Options(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Options(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Patch methods
template <typename... Ts>
Response Patch(Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Patch();
}
// Patch async methods
template <typename... Ts>
AsyncResponse PatchAsync(Ts... ts) {
return std::async(
std::launch::async, [](Ts... ts) { return Patch(std::move(ts)...); }, std::move(ts)...);
}
// Patch callback methods
template <typename Then, typename... Ts>
// NOLINTNEXTLINE(fuchsia-trailing-return)
auto PatchCallback(Then then, Ts... ts) -> std::future<decltype(then(Patch(std::move(ts)...)))> {
return std::async(
std::launch::async, [](Then then, Ts... ts) { return then(Patch(std::move(ts)...)); },
std::move(then), std::move(ts)...);
}
// Download methods
template <typename... Ts>
Response Download(std::ofstream& file, Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Download(file);
}
// Download with user callback
template <typename... Ts>
Response Download(const WriteCallback& write, Ts&&... ts) {
Session session;
priv::set_option(session, std::forward<Ts>(ts)...);
return session.Download(write);
}
} // namespace cpr
#endif

31
vendor/CPR/include/cpr/auth.h vendored Normal file
View File

@ -0,0 +1,31 @@
#ifndef CPR_AUTH_H
#define CPR_AUTH_H
#include <string>
#include <utility>
namespace cpr {
class Authentication {
public:
Authentication(const std::string& username, const std::string& password)
: auth_string_{username + ":" + password} {}
Authentication(std::string&& username, std::string&& password)
: auth_string_{std::move(username) + ":" + std::move(password)} {}
Authentication(const Authentication& other) = default;
Authentication(Authentication&& old) noexcept = default;
virtual ~Authentication() noexcept = default;
Authentication& operator=(Authentication&& old) noexcept = default;
Authentication& operator=(const Authentication& other) = default;
virtual const char* GetAuthString() const noexcept;
protected:
std::string auth_string_;
};
} // namespace cpr
#endif

36
vendor/CPR/include/cpr/bearer.h vendored Normal file
View File

@ -0,0 +1,36 @@
#ifndef CPR_BEARER_H
#define CPR_BEARER_H
#include <string>
#include <curl/curlver.h>
#include <utility>
namespace cpr {
// Only supported with libcurl >= 7.61.0.
// As an alternative use SetHeader and add the token manually.
#if LIBCURL_VERSION_NUM >= 0x073D00
class Bearer {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Bearer(const std::string& token) : token_string_{token} {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Bearer(std::string&& token) : token_string_{std::move(token)} {}
Bearer(const Bearer& other) = default;
Bearer(Bearer&& old) noexcept = default;
virtual ~Bearer() noexcept = default;
Bearer& operator=(Bearer&& old) noexcept = default;
Bearer& operator=(const Bearer& other) = default;
virtual const char* GetToken() const noexcept;
protected:
std::string token_string_;
};
#endif
} // namespace cpr
#endif

32
vendor/CPR/include/cpr/body.h vendored Normal file
View File

@ -0,0 +1,32 @@
#ifndef CPR_BODY_H
#define CPR_BODY_H
#include <initializer_list>
#include <string>
#include "cpr/cprtypes.h"
namespace cpr {
class Body : public StringHolder<Body> {
public:
Body() : StringHolder<Body>() {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(const std::string& body) : StringHolder<Body>(body) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(std::string&& body) : StringHolder<Body>(std::move(body)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Body(const char* body) : StringHolder<Body>(body) {}
Body(const char* str, size_t len) : StringHolder<Body>(str, len) {}
Body(const std::initializer_list<std::string> args) : StringHolder<Body>(args) {}
Body(const Body& other) = default;
Body(Body&& old) noexcept = default;
~Body() override = default;
Body& operator=(Body&& old) noexcept = default;
Body& operator=(const Body& other) = default;
};
} // namespace cpr
#endif

78
vendor/CPR/include/cpr/callback.h vendored Normal file
View File

@ -0,0 +1,78 @@
#ifndef CPR_CALLBACK_H
#define CPR_CALLBACK_H
#include "cprtypes.h"
#include <functional>
#include <utility>
namespace cpr {
class ReadCallback {
public:
ReadCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
ReadCallback(std::function<bool(char* buffer, size_t& size)> callback)
: size{-1}, callback{std::move(callback)} {}
ReadCallback(cpr_off_t size, std::function<bool(char* buffer, size_t& size)> callback)
: size{size}, callback{std::move(callback)} {}
cpr_off_t size{};
std::function<bool(char* buffer, size_t& size)> callback;
};
class HeaderCallback {
public:
HeaderCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
HeaderCallback(std::function<bool(std::string header)> callback)
: callback(std::move(callback)) {}
std::function<bool(std::string header)> callback;
};
class WriteCallback {
public:
WriteCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
WriteCallback(std::function<bool(std::string data)> callback) : callback(std::move(callback)) {}
std::function<bool(std::string data)> callback;
};
class ProgressCallback {
public:
ProgressCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
ProgressCallback(std::function<bool(size_t downloadTotal, size_t downloadNow,
size_t uploadTotal, size_t uploadNow)>
callback)
: callback(std::move(callback)) {}
std::function<bool(size_t downloadTotal, size_t downloadNow, size_t uploadTotal,
size_t uploadNow)>
callback;
};
class DebugCallback {
public:
enum class InfoType {
TEXT = 0,
HEADER_IN = 1,
HEADER_OUT = 2,
DATA_IN = 3,
DATA_OUT = 4,
SSL_DATA_IN = 5,
SSL_DATA_OUT = 6,
};
DebugCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
DebugCallback(std::function<void(InfoType type, std::string data)> callback)
: callback(std::move(callback)) {}
std::function<void(InfoType type, std::string data)> callback;
};
} // namespace cpr
#endif

View File

@ -0,0 +1,18 @@
#ifndef CPR_CONNECT_TIMEOUT_H
#define CPR_CONNECT_TIMEOUT_H
#include "cpr/timeout.h"
namespace cpr {
class ConnectTimeout : public Timeout {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
ConnectTimeout(const std::chrono::milliseconds& duration) : Timeout{duration} {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
ConnectTimeout(const std::int32_t& milliseconds) : Timeout{milliseconds} {}
};
} // namespace cpr
#endif

55
vendor/CPR/include/cpr/cookies.h vendored Normal file
View File

@ -0,0 +1,55 @@
#ifndef CPR_COOKIES_H
#define CPR_COOKIES_H
#include "cpr/curlholder.h"
#include <initializer_list>
#include <map>
#include <sstream>
#include <string>
namespace cpr {
class Cookies {
public:
/**
* Should we URL-encode cookies when making a request.
* Based on RFC6265, it is recommended but not mandatory to encode cookies.
*
* -------
* To maximize compatibility with user agents, servers that wish to
* store arbitrary data in a cookie-value SHOULD encode that data, for
* example, using Base64 [RFC4648].
* -------
* Source: RFC6265 (https://www.ietf.org/rfc/rfc6265.txt)
**/
bool encode{true};
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Cookies(bool encode = true) : encode(encode) {}
Cookies(const std::initializer_list<std::pair<const std::string, std::string>>& pairs,
bool encode = true)
: encode(encode), map_{pairs} {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Cookies(const std::map<std::string, std::string>& map, bool encode = true)
: encode(encode), map_{map} {}
std::string& operator[](const std::string& key);
std::string GetEncoded(const CurlHolder& holder) const;
using iterator = std::map<std::string, std::string>::iterator;
using const_iterator = std::map<std::string, std::string>::const_iterator;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
protected:
std::map<std::string, std::string> map_;
};
} // namespace cpr
#endif

13
vendor/CPR/include/cpr/cpr.h vendored Normal file
View File

@ -0,0 +1,13 @@
#ifndef CPR_CPR_H
#define CPR_CPR_H
#include "cpr/api.h"
#include "cpr/auth.h"
#include "cpr/cprtypes.h"
#include "cpr/response.h"
#include "cpr/session.h"
#include "cpr/status_codes.h"
#define CPR_LIBCURL_VERSION_NUM LIBCURL_VERSION_NUM
#endif

133
vendor/CPR/include/cpr/cprtypes.h vendored Normal file
View File

@ -0,0 +1,133 @@
#ifndef CPR_CPR_TYPES_H
#define CPR_CPR_TYPES_H
#include <curl/curl.h>
#include <initializer_list>
#include <map>
#include <memory>
#include <numeric>
#include <string>
namespace cpr {
/**
* Wrapper around "curl_off_t" to prevent applications from having to link against libcurl.
**/
using cpr_off_t = curl_off_t;
template <class T>
class StringHolder {
public:
StringHolder() = default;
explicit StringHolder(const std::string& str) : str_(str) {}
explicit StringHolder(std::string&& str) : str_(std::move(str)) {}
explicit StringHolder(const char* str) : str_(str) {}
StringHolder(const char* str, size_t len) : str_(str, len) {}
StringHolder(const std::initializer_list<std::string> args) {
str_ = std::accumulate(args.begin(), args.end(), str_);
}
StringHolder(const StringHolder& other) = default;
StringHolder(StringHolder&& old) noexcept = default;
virtual ~StringHolder() = default;
StringHolder& operator=(StringHolder&& old) noexcept = default;
StringHolder& operator=(const StringHolder& other) = default;
explicit operator std::string() const {
return str_;
}
T operator+(const char* rhs) const {
return T(str_ + rhs);
}
T operator+(const std::string& rhs) const {
return T(str_ + rhs);
}
T operator+(const StringHolder<T>& rhs) const {
return T(str_ + rhs.str_);
}
void operator+=(const char* rhs) {
str_ += rhs;
}
void operator+=(const std::string& rhs) {
str_ += rhs;
}
void operator+=(const StringHolder<T>& rhs) {
str_ += rhs;
}
bool operator==(const char* rhs) const {
return str_ == rhs;
}
bool operator==(const std::string& rhs) const {
return str_ == rhs;
}
bool operator==(const StringHolder<T>& rhs) const {
return str_ == rhs.str_;
}
bool operator!=(const char* rhs) const {
return str_.c_str() != rhs;
}
bool operator!=(const std::string& rhs) const {
return str_ != rhs;
}
bool operator!=(const StringHolder<T>& rhs) const {
return str_ != rhs.str_;
}
const std::string& str() {
return str_;
}
const std::string& str() const {
return str_;
}
const char* c_str() const {
return str_.c_str();
}
const char* data() const {
return str_.data();
}
protected:
std::string str_{};
};
template <class T>
std::ostream& operator<<(std::ostream& os, const StringHolder<T>& s) {
os << s.str();
return os;
}
class Url : public StringHolder<Url> {
public:
Url() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(const std::string& url) : StringHolder<Url>(url) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(std::string&& url) : StringHolder<Url>(std::move(url)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Url(const char* url) : StringHolder<Url>(url) {}
Url(const char* str, size_t len) : StringHolder<Url>(std::string(str, len)) {}
Url(const std::initializer_list<std::string> args) : StringHolder<Url>(args) {}
Url(const Url& other) = default;
Url(Url&& old) noexcept = default;
~Url() override = default;
Url& operator=(Url&& old) noexcept = default;
Url& operator=(const Url& other) = default;
};
struct CaseInsensitiveCompare {
bool operator()(const std::string& a, const std::string& b) const noexcept;
};
using Header = std::map<std::string, std::string, CaseInsensitiveCompare>;
} // namespace cpr
#endif

55
vendor/CPR/include/cpr/curl_container.h vendored Normal file
View File

@ -0,0 +1,55 @@
#ifndef CURL_CONTAINER_H
#define CURL_CONTAINER_H
#include <initializer_list>
#include <memory>
#include <string>
#include <vector>
#include "cpr/curlholder.h"
namespace cpr {
struct Parameter {
Parameter(const std::string& key, const std::string& value) : key{key}, value{value} {}
Parameter(std::string&& key, std::string&& value)
: key{std::move(key)}, value{std::move(value)} {}
std::string key;
std::string value;
};
struct Pair {
Pair(const std::string& p_key, const std::string& p_value) : key(p_key), value(p_value) {}
Pair(std::string&& p_key, std::string&& p_value)
: key(std::move(p_key)), value(std::move(p_value)) {}
std::string key;
std::string value;
};
template <class T>
class CurlContainer {
public:
/**
* Enables or disables URL encoding for keys and values when calling GetContent(...).
**/
bool encode = true;
CurlContainer() = default;
CurlContainer(const std::initializer_list<T>&);
void Add(const std::initializer_list<T>&);
void Add(const T&);
const std::string GetContent(const CurlHolder&) const;
protected:
std::vector<T> containerList_;
};
} // namespace cpr
#endif //

50
vendor/CPR/include/cpr/curlholder.h vendored Normal file
View File

@ -0,0 +1,50 @@
#ifndef CPR_CURL_HOLDER_H
#define CPR_CURL_HOLDER_H
#include <array>
#include <mutex>
#include <string>
#include <curl/curl.h>
namespace cpr {
struct CurlHolder {
private:
/**
* Mutex for curl_easy_init().
* curl_easy_init() is not thread save.
* References:
* https://curl.haxx.se/libcurl/c/curl_easy_init.html
* https://curl.haxx.se/libcurl/c/threadsafe.html
**/
// It does not make sense to make a std::mutex const.
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
static std::mutex curl_easy_init_mutex_;
public:
CURL* handle{nullptr};
struct curl_slist* chunk{nullptr};
struct curl_httppost* formpost{nullptr};
std::array<char, CURL_ERROR_SIZE> error{};
CurlHolder();
CurlHolder(const CurlHolder& other) = default;
CurlHolder(CurlHolder&& old) noexcept = default;
~CurlHolder();
CurlHolder& operator=(CurlHolder&& old) noexcept = default;
CurlHolder& operator=(const CurlHolder& other) = default;
/**
* Uses curl_easy_escape(...) for escaping the given string.
**/
std::string urlEncode(const std::string& s) const;
/**
* Uses curl_easy_unescape(...) for unescaping the given string.
**/
std::string urlDecode(const std::string& s) const;
};
} // namespace cpr
#endif

15
vendor/CPR/include/cpr/digest.h vendored Normal file
View File

@ -0,0 +1,15 @@
#ifndef CPR_DIGEST_H
#define CPR_DIGEST_H
#include "cpr/auth.h"
namespace cpr {
class Digest : public Authentication {
public:
Digest(const std::string& username, const std::string& password)
: Authentication{username, password} {}
};
} // namespace cpr
#endif

54
vendor/CPR/include/cpr/error.h vendored Normal file
View File

@ -0,0 +1,54 @@
#ifndef CPR_ERROR_H
#define CPR_ERROR_H
#include <cstdint>
#include <string>
#include "cpr/cprtypes.h"
#include <utility>
namespace cpr {
enum class ErrorCode {
OK = 0,
CONNECTION_FAILURE,
EMPTY_RESPONSE,
HOST_RESOLUTION_FAILURE,
INTERNAL_ERROR,
INVALID_URL_FORMAT,
NETWORK_RECEIVE_ERROR,
NETWORK_SEND_FAILURE,
OPERATION_TIMEDOUT,
PROXY_RESOLUTION_FAILURE,
SSL_CONNECT_ERROR,
SSL_LOCAL_CERTIFICATE_ERROR,
SSL_REMOTE_CERTIFICATE_ERROR,
SSL_CACERT_ERROR,
GENERIC_SSL_ERROR,
UNSUPPORTED_PROTOCOL,
REQUEST_CANCELLED,
UNKNOWN_ERROR = 1000,
};
class Error {
public:
ErrorCode code = ErrorCode::OK;
std::string message{};
Error() = default;
Error(const std::int32_t& curl_code, std::string&& p_error_message)
: code{getErrorCodeForCurlError(curl_code)},
message(std::move(p_error_message)) {}
explicit operator bool() const {
return code != ErrorCode::OK;
}
private:
static ErrorCode getErrorCodeForCurlError(std::int32_t curl_code);
};
} // namespace cpr
#endif

19
vendor/CPR/include/cpr/limit_rate.h vendored Normal file
View File

@ -0,0 +1,19 @@
#ifndef CPR_SPEED_LIMIT_H
#define CPR_SPEED_LIMIT_H
#include <cstdint>
namespace cpr {
class LimitRate {
public:
LimitRate(const std::int64_t downrate, const std::int64_t uprate)
: downrate(downrate), uprate(uprate) {}
std::int64_t downrate = 0;
std::int64_t uprate = 0;
};
} // namespace cpr
#endif

18
vendor/CPR/include/cpr/low_speed.h vendored Normal file
View File

@ -0,0 +1,18 @@
#ifndef CPR_LOW_SPEED_H
#define CPR_LOW_SPEED_H
#include <cstdint>
namespace cpr {
class LowSpeed {
public:
LowSpeed(const std::int32_t limit, const std::int32_t time) : limit(limit), time(time) {}
std::int32_t limit;
std::int32_t time;
};
} // namespace cpr
#endif

18
vendor/CPR/include/cpr/max_redirects.h vendored Normal file
View File

@ -0,0 +1,18 @@
#ifndef CPR_MAX_REDIRECTS_H
#define CPR_MAX_REDIRECTS_H
#include <cstdint>
namespace cpr {
class MaxRedirects {
public:
explicit MaxRedirects(const std::int32_t number_of_redirects)
: number_of_redirects(number_of_redirects) {}
std::int32_t number_of_redirects;
};
} // namespace cpr
#endif

79
vendor/CPR/include/cpr/multipart.h vendored Normal file
View File

@ -0,0 +1,79 @@
#ifndef CPR_MULTIPART_H
#define CPR_MULTIPART_H
#include <cstdint>
#include <initializer_list>
#include <string>
#include <type_traits>
#include <vector>
namespace cpr {
struct File {
explicit File(std::string&& filepath) : filepath(std::move(filepath)) {}
explicit File(const std::string& filepath) : filepath(filepath) {}
const std::string filepath;
};
struct Buffer {
using data_t = const unsigned char*;
template <typename Iterator>
Buffer(Iterator begin, Iterator end, std::string&& filename)
// Ignored here since libcurl reqires a long.
// There is also no way around the reinterpret_cast.
// NOLINTNEXTLINE(google-runtime-int, cppcoreguidelines-pro-type-reinterpret-cast)
: data{reinterpret_cast<data_t>(&(*begin))}, datalen{static_cast<long>(
std::distance(begin, end))},
filename(std::move(filename)) {
is_random_access_iterator(begin, end);
static_assert(sizeof(*begin) == 1, "only byte buffers can be used");
}
template <typename Iterator>
typename std::enable_if<std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
std::random_access_iterator_tag>::value>::type
is_random_access_iterator(Iterator /* begin */, Iterator /* end */) {}
data_t data;
// Ignored here since libcurl reqires a long:
// NOLINTNEXTLINE(google-runtime-int)
long datalen;
const std::string filename;
};
struct Part {
Part(const std::string& name, const std::string& value, const std::string& content_type = {})
: name{name}, value{value},
content_type{content_type}, is_file{false}, is_buffer{false} {}
Part(const std::string& name, const std::int32_t& value, const std::string& content_type = {})
: name{name}, value{std::to_string(value)},
content_type{content_type}, is_file{false}, is_buffer{false} {}
Part(const std::string& name, const File& file, const std::string& content_type = {})
: name{name}, value{file.filepath},
content_type{content_type}, is_file{true}, is_buffer{false} {}
Part(const std::string& name, const Buffer& buffer, const std::string& content_type = {})
: name{name}, value{buffer.filename}, content_type{content_type}, data{buffer.data},
datalen{buffer.datalen}, is_file{false}, is_buffer{true} {}
std::string name;
std::string value;
std::string content_type;
Buffer::data_t data{nullptr};
// Ignored here since libcurl reqires a long:
// NOLINTNEXTLINE(google-runtime-int)
long datalen{0};
bool is_file;
bool is_buffer;
};
class Multipart {
public:
Multipart(const std::initializer_list<Part>& parts);
std::vector<Part> parts;
};
} // namespace cpr
#endif

15
vendor/CPR/include/cpr/ntlm.h vendored Normal file
View File

@ -0,0 +1,15 @@
#ifndef CPR_NTLM_H
#define CPR_NTLM_H
#include "cpr/auth.h"
namespace cpr {
class NTLM : public Authentication {
public:
NTLM(const std::string& username, const std::string& password)
: Authentication{username, password} {}
};
} // namespace cpr
#endif

18
vendor/CPR/include/cpr/parameters.h vendored Normal file
View File

@ -0,0 +1,18 @@
#ifndef CPR_PARAMETERS_H
#define CPR_PARAMETERS_H
#include <initializer_list>
#include "cpr/curl_container.h"
namespace cpr {
class Parameters : public CurlContainer<Parameter> {
public:
Parameters() = default;
Parameters(const std::initializer_list<Parameter>& parameters);
};
} // namespace cpr
#endif

23
vendor/CPR/include/cpr/payload.h vendored Normal file
View File

@ -0,0 +1,23 @@
#ifndef CPR_PAYLOAD_H
#define CPR_PAYLOAD_H
#include <initializer_list>
#include "cpr/curl_container.h"
namespace cpr {
class Payload : public CurlContainer<Pair> {
public:
template <class It>
Payload(const It begin, const It end) {
for (It pair = begin; pair != end; ++pair) {
Add(*pair);
}
}
Payload(const std::initializer_list<Pair>& pairs);
};
} // namespace cpr
#endif

22
vendor/CPR/include/cpr/proxies.h vendored Normal file
View File

@ -0,0 +1,22 @@
#ifndef CPR_PROXIES_H
#define CPR_PROXIES_H
#include <initializer_list>
#include <map>
#include <string>
namespace cpr {
class Proxies {
public:
Proxies() = default;
Proxies(const std::initializer_list<std::pair<const std::string, std::string>>& hosts);
bool has(const std::string& protocol) const;
const std::string& operator[](const std::string& protocol);
protected:
std::map<std::string, std::string> hosts_;
};
} // namespace cpr
#endif

56
vendor/CPR/include/cpr/response.h vendored Normal file
View File

@ -0,0 +1,56 @@
#ifndef CPR_RESPONSE_H
#define CPR_RESPONSE_H
#include <cassert>
#include <cstdint>
#include <curl/curl.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "cpr/cookies.h"
#include "cpr/cprtypes.h"
#include "cpr/error.h"
#include "cpr/ssl_options.h"
#include "cpr/util.h"
namespace cpr {
class Response {
protected:
std::shared_ptr<CurlHolder> curl_{nullptr};
public:
// Ignored here since libcurl uses a long for this.
// NOLINTNEXTLINE(google-runtime-int)
long status_code{};
std::string text{};
Header header{};
Url url{};
double elapsed{};
Cookies cookies{};
Error error{};
std::string raw_header{};
std::string status_line{};
std::string reason{};
cpr_off_t uploaded_bytes{};
cpr_off_t downloaded_bytes{};
// Ignored here since libcurl uses a long for this.
// NOLINTNEXTLINE(google-runtime-int)
long redirect_count{};
Response() = default;
Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text, std::string&& p_header_string,
Cookies&& p_cookies, Error&& p_error);
std::vector<std::string> GetCertInfo();
Response(const Response& other) = default;
Response(Response&& old) noexcept = default;
~Response() noexcept = default;
Response& operator=(Response&& old) noexcept = default;
Response& operator=(const Response& other) = default;
};
} // namespace cpr
#endif

136
vendor/CPR/include/cpr/session.h vendored Normal file
View File

@ -0,0 +1,136 @@
#ifndef CPR_SESSION_H
#define CPR_SESSION_H
#include <cstdint>
#include <fstream>
#include <memory>
#include "cpr/auth.h"
#include "cpr/bearer.h"
#include "cpr/body.h"
#include "cpr/callback.h"
#include "cpr/connect_timeout.h"
#include "cpr/cookies.h"
#include "cpr/cprtypes.h"
#include "cpr/curlholder.h"
#include "cpr/digest.h"
#include "cpr/limit_rate.h"
#include "cpr/low_speed.h"
#include "cpr/max_redirects.h"
#include "cpr/multipart.h"
#include "cpr/ntlm.h"
#include "cpr/parameters.h"
#include "cpr/payload.h"
#include "cpr/proxies.h"
#include "cpr/response.h"
#include "cpr/ssl_options.h"
#include "cpr/timeout.h"
#include "cpr/unix_socket.h"
#include "cpr/user_agent.h"
#include "cpr/verbose.h"
namespace cpr {
class Session {
public:
Session();
Session(Session&& old) noexcept = default;
Session(const Session& other) = delete;
~Session();
Session& operator=(Session&& old) noexcept = default;
Session& operator=(const Session& other) = delete;
void SetUrl(const Url& url);
void SetParameters(const Parameters& parameters);
void SetParameters(Parameters&& parameters);
void SetHeader(const Header& header);
void UpdateHeader(const Header& header);
void SetTimeout(const Timeout& timeout);
void SetConnectTimeout(const ConnectTimeout& timeout);
void SetAuth(const Authentication& auth);
void SetDigest(const Digest& auth);
void SetUserAgent(const UserAgent& ua);
void SetPayload(Payload&& payload);
void SetPayload(const Payload& payload);
void SetProxies(Proxies&& proxies);
void SetProxies(const Proxies& proxies);
void SetMultipart(Multipart&& multipart);
void SetMultipart(const Multipart& multipart);
void SetNTLM(const NTLM& auth);
void SetRedirect(const bool& redirect);
void SetMaxRedirects(const MaxRedirects& max_redirects);
void SetCookies(const Cookies& cookies);
void SetBody(Body&& body);
void SetBody(const Body& body);
void SetLowSpeed(const LowSpeed& low_speed);
void SetVerifySsl(const VerifySsl& verify);
void SetUnixSocket(const UnixSocket& unix_socket);
void SetSslOptions(const SslOptions& options);
void SetReadCallback(const ReadCallback& read);
void SetHeaderCallback(const HeaderCallback& header);
void SetWriteCallback(const WriteCallback& write);
void SetProgressCallback(const ProgressCallback& progress);
void SetDebugCallback(const DebugCallback& debug);
void SetVerbose(const Verbose& verbose);
// Used in templated functions
void SetOption(const Url& url);
void SetOption(const Parameters& parameters);
void SetOption(Parameters&& parameters);
void SetOption(const Header& header);
void SetOption(const Timeout& timeout);
void SetOption(const ConnectTimeout& timeout);
void SetOption(const Authentication& auth);
// Only supported with libcurl >= 7.61.0.
// As an alternative use SetHeader and add the token manually.
#if LIBCURL_VERSION_NUM >= 0x073D00
void SetOption(const Bearer& auth);
#endif
void SetOption(const Digest& auth);
void SetOption(const UserAgent& ua);
void SetOption(Payload&& payload);
void SetOption(const Payload& payload);
void SetOption(const LimitRate& limit_rate);
void SetOption(Proxies&& proxies);
void SetOption(const Proxies& proxies);
void SetOption(Multipart&& multipart);
void SetOption(const Multipart& multipart);
void SetOption(const NTLM& auth);
void SetOption(const bool& redirect);
void SetOption(const MaxRedirects& max_redirects);
void SetOption(const Cookies& cookies);
void SetOption(Body&& body);
void SetOption(const Body& body);
void SetOption(const ReadCallback& read);
void SetOption(const HeaderCallback& header);
void SetOption(const WriteCallback& write);
void SetOption(const ProgressCallback& progress);
void SetOption(const DebugCallback& debug);
void SetOption(const LowSpeed& low_speed);
void SetOption(const VerifySsl& verify);
void SetOption(const Verbose& verbose);
void SetOption(const UnixSocket& unix_socket);
void SetOption(const SslOptions& options);
Response Delete();
Response Download(const WriteCallback& write);
Response Download(std::ofstream& file);
Response Get();
Response Head();
Response Options();
Response Patch();
Response Post();
Response Put();
std::shared_ptr<CurlHolder> GetCurlHolder();
private:
class Impl;
std::unique_ptr<Impl> pimpl_;
};
} // namespace cpr
#endif

533
vendor/CPR/include/cpr/ssl_options.h vendored Normal file
View File

@ -0,0 +1,533 @@
#ifndef CPR_SSLOPTIONS_H
#define CPR_SSLOPTIONS_H
#include <string>
#include <curl/curl.h>
#include <utility>
#define __LIBCURL_VERSION_GTE(major, minor) \
((LIBCURL_VERSION_MAJOR > (major)) || \
((LIBCURL_VERSION_MAJOR == (major)) && (LIBCURL_VERSION_MINOR >= (minor))))
#define __LIBCURL_VERSION_LT(major, minor) \
((LIBCURL_VERSION_MAJOR < (major)) || \
((LIBCURL_VERSION_MAJOR == (major)) && (LIBCURL_VERSION_MINOR < (minor))))
#ifndef SUPPORT_ALPN
#define SUPPORT_ALPN __LIBCURL_VERSION_GTE(7, 36)
#endif
#ifndef SUPPORT_NPN
#define SUPPORT_NPN __LIBCURL_VERSION_GTE(7, 36)
#endif
#ifndef SUPPORT_SSLv2
#define SUPPORT_SSLv2 __LIBCURL_VERSION_LT(7, 19)
#endif
#ifndef SUPPORT_SSLv3
#define SUPPORT_SSLv3 __LIBCURL_VERSION_LT(7, 39)
#endif
#ifndef SUPPORT_TLSv1_0
#define SUPPORT_TLSv1_0 __LIBCURL_VERSION_GTE(7, 34)
#endif
#ifndef SUPPORT_TLSv1_1
#define SUPPORT_TLSv1_1 __LIBCURL_VERSION_GTE(7, 34)
#endif
#ifndef SUPPORT_TLSv1_2
#define SUPPORT_TLSv1_2 __LIBCURL_VERSION_GTE(7, 34)
#endif
#ifndef SUPPORT_TLSv1_3
#define SUPPORT_TLSv1_3 __LIBCURL_VERSION_GTE(7, 52)
#endif
#ifndef SUPPORT_MAX_TLS_VERSION
#define SUPPORT_MAX_TLS_VERSION __LIBCURL_VERSION_GTE(7, 54)
#endif
#ifndef SUPPORT_MAX_TLSv1_1
#define SUPPORT_MAX_TLSv1_1 __LIBCURL_VERSION_GTE(7, 54)
#endif
#ifndef SUPPORT_MAX_TLSv1_2
#define SUPPORT_MAX_TLSv1_2 __LIBCURL_VERSION_GTE(7, 54)
#endif
#ifndef SUPPORT_MAX_TLSv1_3
#define SUPPORT_MAX_TLSv1_3 __LIBCURL_VERSION_GTE(7, 54)
#endif
#ifndef SUPPORT_TLSv13_CIPHERS
#define SUPPORT_TLSv13_CIPHERS __LIBCURL_VERSION_GTE(7, 61)
#endif
#ifndef SUPPORT_SESSIONID_CACHE
#define SUPPORT_SESSIONID_CACHE __LIBCURL_VERSION_GTE(7, 16)
#endif
#ifndef SUPPORT_SSL_FALSESTART
#define SUPPORT_SSL_FALSESTART __LIBCURL_VERSION_GTE(7, 42)
#endif
#ifndef SUPPORT_SSL_NO_REVOKE
#define SUPPORT_SSL_NO_REVOKE __LIBCURL_VERSION_GTE(7, 44)
#endif
namespace cpr {
class VerifySsl {
public:
VerifySsl() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
VerifySsl(bool verify) : verify(verify) {}
explicit operator bool() const {
return verify;
}
bool verify = true;
};
namespace ssl {
// set SSL client certificate
class CertFile {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
CertFile(std::string&& p_filename) : filename(std::move(p_filename)) {}
const std::string filename;
virtual const char* GetCertType() const {
return "PEM";
}
};
using PemCert = CertFile;
class DerCert : public CertFile {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
DerCert(std::string&& p_filename) : CertFile(std::move(p_filename)) {}
const char* GetCertType() const override {
return "DER";
}
};
// specify private keyfile for TLS and SSL client cert
class KeyFile {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
KeyFile(std::string&& p_filename) : filename(std::move(p_filename)) {}
template <typename FileType, typename PassType>
KeyFile(FileType&& p_filename, PassType p_password)
: filename(std::forward<FileType>(p_filename)), password(std::move(p_password)) {}
std::string filename;
std::string password;
virtual const char* GetKeyType() const {
return "PEM";
}
};
using PemKey = KeyFile;
class DerKey : public KeyFile {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
DerKey(std::string&& p_filename) : KeyFile(std::move(p_filename)) {}
template <typename FileType, typename PassType>
DerKey(FileType&& p_filename, PassType p_password)
: KeyFile(std::forward<FileType>(p_filename), std::move(p_password)) {}
const char* GetKeyType() const override {
return "DER";
}
};
#if SUPPORT_ALPN
// This option enables/disables ALPN in the SSL handshake (if the SSL backend libcurl is built to
// use supports it), which can be used to negotiate http2.
class ALPN {
public:
ALPN() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
ALPN(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = true;
};
#endif // SUPPORT_ALPN
#if SUPPORT_NPN
// This option enables/disables NPN in the SSL handshake (if the SSL backend libcurl is built to
// use supports it), which can be used to negotiate http2.
class NPN {
public:
NPN() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
NPN(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = true;
};
#endif // SUPPORT_NPN
// This option determines whether libcurl verifies that the server cert is for the server it is
// known as.
class VerifyHost {
public:
VerifyHost() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
VerifyHost(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = true;
};
// This option determines whether libcurl verifies the authenticity of the peer's certificate.
class VerifyPeer {
public:
VerifyPeer() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
VerifyPeer(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = true;
};
// This option determines whether libcurl verifies the status of the server cert using the
// "Certificate Status Request" TLS extension (aka. OCSP stapling).
class VerifyStatus {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
VerifyStatus(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = false;
};
// TLS v1.0 or later
struct TLSv1 {};
#if SUPPORT_SSLv2
// SSL v2 (but not SSLv3)
struct SSLv2 {};
#endif
#if SUPPORT_SSLv3
// SSL v3 (but not SSLv2)
struct SSLv3 {};
#endif
#if SUPPORT_TLSv1_0
// TLS v1.0 or later (Added in 7.34.0)
struct TLSv1_0 {};
#endif
#if SUPPORT_TLSv1_1
// TLS v1.1 or later (Added in 7.34.0)
struct TLSv1_1 {};
#endif
#if SUPPORT_TLSv1_2
// TLS v1.2 or later (Added in 7.34.0)
struct TLSv1_2 {};
#endif
#if SUPPORT_TLSv1_3
// TLS v1.3 or later (Added in 7.52.0)
struct TLSv1_3 {};
#endif
#if SUPPORT_MAX_TLS_VERSION
// The flag defines the maximum supported TLS version by libcurl, or the default value from the SSL
// library is used.
struct MaxTLSVersion {};
#endif
#if SUPPORT_MAX_TLSv1_0
// The flag defines maximum supported TLS version as TLSv1.0. (Added in 7.54.0)
struct MaxTLSv1_0 {};
#endif
#if SUPPORT_MAX_TLSv1_1
// The flag defines maximum supported TLS version as TLSv1.1. (Added in 7.54.0)
struct MaxTLSv1_1 {};
#endif
#if SUPPORT_MAX_TLSv1_2
// The flag defines maximum supported TLS version as TLSv1.2. (Added in 7.54.0)
struct MaxTLSv1_2 {};
#endif
#if SUPPORT_MAX_TLSv1_3
// The flag defines maximum supported TLS version as TLSv1.3. (Added in 7.54.0)
struct MaxTLSv1_3 {};
#endif
// path to Certificate Authority (CA) bundle
class CaInfo {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
CaInfo(std::string&& p_filename) : filename(std::move(p_filename)) {}
std::string filename;
};
// specify directory holding CA certificates
class CaPath {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
CaPath(std::string&& p_filename) : filename(std::move(p_filename)) {}
std::string filename;
};
// specify a Certificate Revocation List file
class Crl {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Crl(std::string&& p_filename) : filename(std::move(p_filename)) {}
std::string filename;
};
// specify ciphers to use for TLS
class Ciphers {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Ciphers(std::string&& p_ciphers) : ciphers(std::move(p_ciphers)) {}
std::string ciphers;
};
#if SUPPORT_TLSv13_CIPHERS
// specify ciphers suites to use for TLS 1.3
class TLS13_Ciphers {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
TLS13_Ciphers(std::string&& p_ciphers) : ciphers(std::move(p_ciphers)) {}
std::string ciphers;
};
#endif
#if SUPPORT_SESSIONID_CACHE
// enable/disable use of the SSL session-ID cache
class SessionIdCache {
public:
SessionIdCache() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
SessionIdCache(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = true;
};
#endif
#if SUPPORT_SSL_FALSESTART
class SslFastStart {
public:
SslFastStart() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
SslFastStart(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = false;
};
#endif
class NoRevoke {
public:
NoRevoke() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
NoRevoke(bool enabled) : enabled(enabled) {}
explicit operator bool() const {
return enabled;
}
bool enabled = false;
};
} // namespace ssl
struct SslOptions {
std::string cert_file;
std::string cert_type;
std::string key_file;
std::string key_type;
std::string key_pass;
#if SUPPORT_ALPN
bool enable_alpn = true;
#endif // SUPPORT_ALPN
#if SUPPORT_NPN
bool enable_npn = true;
#endif // SUPPORT_ALPN
bool verify_host = true;
bool verify_peer = true;
bool verify_status = false;
int ssl_version = CURL_SSLVERSION_DEFAULT;
#if SUPPORT_SSL_NO_REVOKE
bool ssl_no_revoke = false;
#endif
#if SUPPORT_MAX_TLS_VERSION
int max_version = CURL_SSLVERSION_MAX_DEFAULT;
#endif
std::string ca_info;
std::string ca_path;
std::string crl_file;
std::string ciphers;
#if SUPPORT_TLSv13_CIPHERS
std::string tls13_ciphers;
#endif
#if SUPPORT_SESSIONID_CACHE
bool session_id_cache = true;
#endif
void SetOption(const ssl::CertFile& opt) {
cert_file = opt.filename;
cert_type = opt.GetCertType();
}
void SetOption(const ssl::KeyFile& opt) {
key_file = opt.filename;
key_type = opt.GetKeyType();
key_pass = opt.password;
}
#if SUPPORT_ALPN
void SetOption(const ssl::ALPN& opt) {
enable_alpn = opt.enabled;
}
#endif // SUPPORT_ALPN
#if SUPPORT_NPN
void SetOption(const ssl::NPN& opt) {
enable_npn = opt.enabled;
}
#endif // SUPPORT_NPN
void SetOption(const ssl::VerifyHost& opt) {
verify_host = opt.enabled;
}
void SetOption(const ssl::VerifyPeer& opt) {
verify_peer = opt.enabled;
}
void SetOption(const ssl::VerifyStatus& opt) {
verify_status = opt.enabled;
}
void SetOption(const ssl::TLSv1& /*opt*/) {
ssl_version = CURL_SSLVERSION_TLSv1;
}
#if SUPPORT_SSL_NO_REVOKE
void SetOption(const ssl::NoRevoke& opt) {
ssl_no_revoke = opt.enabled;
}
#endif
#if SUPPORT_SSLv2
void SetOption(const ssl::SSLv2& /*opt*/) {
ssl_version = CURL_SSLVERSION_SSLv2;
}
#endif
#if SUPPORT_SSLv3
void SetOption(const ssl::SSLv3& /*opt*/) {
ssl_version = CURL_SSLVERSION_SSLv3;
}
#endif
#if SUPPORT_TLSv1_0
void SetOption(const ssl::TLSv1_0& /*opt*/) {
ssl_version = CURL_SSLVERSION_TLSv1_0;
}
#endif
#if SUPPORT_TLSv1_1
void SetOption(const ssl::TLSv1_1& /*opt*/) {
ssl_version = CURL_SSLVERSION_TLSv1_1;
}
#endif
#if SUPPORT_TLSv1_2
void SetOption(const ssl::TLSv1_2& /*opt*/) {
ssl_version = CURL_SSLVERSION_TLSv1_2;
}
#endif
#if SUPPORT_TLSv1_3
void SetOption(const ssl::TLSv1_3& /*opt*/) {
ssl_version = CURL_SSLVERSION_TLSv1_3;
}
#endif
#if SUPPORT_MAX_TLS_VERSION
void SetOption(const ssl::MaxTLSVersion& /*opt*/) {
max_version = CURL_SSLVERSION_DEFAULT;
}
#endif
#if SUPPORT_MAX_TLSv1_0
void SetOption(const ssl::MaxTLSv1_0& opt) {
max_version = CURL_SSLVERSION_MAX_TLSv1_0;
}
#endif
#if SUPPORT_MAX_TLSv1_1
void SetOption(const ssl::MaxTLSv1_1& /*opt*/) {
max_version = CURL_SSLVERSION_MAX_TLSv1_1;
}
#endif
#if SUPPORT_MAX_TLSv1_2
void SetOption(const ssl::MaxTLSv1_2& /*opt*/) {
max_version = CURL_SSLVERSION_MAX_TLSv1_2;
}
#endif
#if SUPPORT_MAX_TLSv1_3
void SetOption(const ssl::MaxTLSv1_3& /*opt*/) {
max_version = CURL_SSLVERSION_MAX_TLSv1_3;
}
#endif
void SetOption(const ssl::CaInfo& opt) {
ca_info = opt.filename;
}
void SetOption(const ssl::CaPath& opt) {
ca_path = opt.filename;
}
void SetOption(const ssl::Crl& opt) {
crl_file = opt.filename;
}
void SetOption(const ssl::Ciphers& opt) {
ciphers = opt.ciphers;
}
#if SUPPORT_TLSv13_CIPHERS
void SetOption(const ssl::TLS13_Ciphers& opt) {
tls13_ciphers = opt.ciphers;
}
#endif
#if SUPPORT_SESSIONID_CACHE
void SetOption(const ssl::SessionIdCache& opt) {
session_id_cache = opt.enabled;
}
#endif
};
namespace priv {
template <typename T>
void set_ssl_option(SslOptions& opts, T&& t) {
opts.SetOption(std::forward<T>(t));
}
template <typename T, typename... Ts>
void set_ssl_option(SslOptions& opts, T&& t, Ts&&... ts) {
set_ssl_option(opts, std::forward<T>(t));
set_ssl_option(opts, std::move(ts)...);
}
} // namespace priv
template <typename... Ts>
SslOptions Ssl(Ts&&... ts) {
SslOptions opts;
priv::set_ssl_option(opts, std::move(ts)...);
return opts;
}
} // namespace cpr
#endif

100
vendor/CPR/include/cpr/status_codes.h vendored Normal file
View File

@ -0,0 +1,100 @@
#ifndef _CPR_STATUS_CODES
#define _CPR_STATUS_CODES
#include <cstdint>
namespace cpr {
namespace status {
// Information responses
constexpr std::int32_t HTTP_CONTINUE = 100;
constexpr std::int32_t HTTP_SWITCHING_PROTOCOL = 101;
constexpr std::int32_t HTTP_PROCESSING = 102;
constexpr std::int32_t HTTP_EARLY_HINTS = 103;
// Successful responses
constexpr std::int32_t HTTP_OK = 200;
constexpr std::int32_t HTTP_CREATED = 201;
constexpr std::int32_t HTTP_ACCEPTED = 202;
constexpr std::int32_t HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
constexpr std::int32_t HTTP_NO_CONTENT = 204;
constexpr std::int32_t HTTP_RESET_CONTENT = 205;
constexpr std::int32_t HTTP_PARTIAL_CONTENT = 206;
constexpr std::int32_t HTTP_MULTI_STATUS = 207;
constexpr std::int32_t HTTP_ALREADY_REPORTED = 208;
constexpr std::int32_t HTTP_IM_USED = 226;
// Redirection messages
constexpr std::int32_t HTTP_MULTIPLE_CHOICE = 300;
constexpr std::int32_t HTTP_MOVED_PERMANENTLY = 301;
constexpr std::int32_t HTTP_FOUND = 302;
constexpr std::int32_t HTTP_SEE_OTHER = 303;
constexpr std::int32_t HTTP_NOT_MODIFIED = 304;
constexpr std::int32_t HTTP_USE_PROXY = 305;
constexpr std::int32_t HTTP_UNUSED = 306;
constexpr std::int32_t HTTP_TEMPORARY_REDIRECT = 307;
constexpr std::int32_t HTTP_PERMANENT_REDIRECT = 308;
// Client error responses
constexpr std::int32_t HTTP_BAD_REQUEST = 400;
constexpr std::int32_t HTTP_UNAUTHORIZED = 401;
constexpr std::int32_t HTTP_PAYMENT_REQUIRED = 402;
constexpr std::int32_t HTTP_FORBIDDEN = 403;
constexpr std::int32_t HTTP_NOT_FOUND = 404;
constexpr std::int32_t HTTP_METHOD_NOT_ALLOWED = 405;
constexpr std::int32_t HTTP_NOT_ACCEPTABLE = 406;
constexpr std::int32_t HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
constexpr std::int32_t HTTP_REQUEST_TIMEOUT = 408;
constexpr std::int32_t HTTP_CONFLICT = 409;
constexpr std::int32_t HTTP_GONE = 410;
constexpr std::int32_t HTTP_LENGTH_REQUIRED = 411;
constexpr std::int32_t HTTP_PRECONDITION_FAILED = 412;
constexpr std::int32_t HTTP_PAYLOAD_TOO_LARGE = 413;
constexpr std::int32_t HTTP_URI_TOO_LONG = 414;
constexpr std::int32_t HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
constexpr std::int32_t HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
constexpr std::int32_t HTTP_EXPECTATION_FAILED = 417;
constexpr std::int32_t HTTP_IM_A_TEAPOT = 418;
constexpr std::int32_t HTTP_MISDIRECTED_REQUEST = 421;
constexpr std::int32_t HTTP_UNPROCESSABLE_ENTITY = 422;
constexpr std::int32_t HTTP_LOCKED = 423;
constexpr std::int32_t HTTP_FAILED_DEPENDENCY = 424;
constexpr std::int32_t HTTP_TOO_EARLY = 425;
constexpr std::int32_t HTTP_UPGRADE_REQUIRED = 426;
constexpr std::int32_t HTTP_PRECONDITION_REQUIRED = 428;
constexpr std::int32_t HTTP_TOO_MANY_REQUESTS = 429;
constexpr std::int32_t HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
constexpr std::int32_t HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451;
// Server response errors
constexpr std::int32_t HTTP_INTERNAL_SERVER_ERROR = 500;
constexpr std::int32_t HTTP_NOT_IMPLEMENTED = 501;
constexpr std::int32_t HTTP_BAD_GATEWAY = 502;
constexpr std::int32_t HTTP_SERVICE_UNAVAILABLE = 503;
constexpr std::int32_t HTTP_GATEWAY_TIMEOUT = 504;
constexpr std::int32_t HTTP_HTTP_VERSION_NOT_SUPPORTED = 505;
constexpr std::int32_t HTTP_VARIANT_ALSO_NEGOTIATES = 506;
constexpr std::int32_t HTTP_INSUFFICIENT_STORAGE = 507;
constexpr std::int32_t HTTP_LOOP_DETECTED = 508;
constexpr std::int32_t HTTP_NOT_EXTENDED = 510;
constexpr std::int32_t HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511;
constexpr std::int32_t INFO_CODE_OFFSET = 100;
constexpr std::int32_t SUCCESS_CODE_OFFSET = 200;
constexpr std::int32_t REDIRECT_CODE_OFFSET = 300;
constexpr std::int32_t CLIENT_ERROR_CODE_OFFSET = 400;
constexpr std::int32_t SERVER_ERROR_CODE_OFFSET = 500;
constexpr std::int32_t MISC_CODE_OFFSET = 600;
constexpr bool is_informational(const std::int32_t code) {
return (code >= INFO_CODE_OFFSET && code < SUCCESS_CODE_OFFSET);
}
constexpr bool is_success(const std::int32_t code) {
return (code >= SUCCESS_CODE_OFFSET && code < REDIRECT_CODE_OFFSET);
}
constexpr bool is_redirect(const std::int32_t code) {
return (code >= REDIRECT_CODE_OFFSET && code < CLIENT_ERROR_CODE_OFFSET);
}
constexpr bool is_client_error(const std::int32_t code) {
return (code >= CLIENT_ERROR_CODE_OFFSET && code < SERVER_ERROR_CODE_OFFSET);
}
constexpr bool is_server_error(const std::int32_t code) {
return (code >= SERVER_ERROR_CODE_OFFSET && code < MISC_CODE_OFFSET);
}
} // namespace status
} // namespace cpr
#endif

25
vendor/CPR/include/cpr/timeout.h vendored Normal file
View File

@ -0,0 +1,25 @@
#ifndef CPR_TIMEOUT_H
#define CPR_TIMEOUT_H
#include <chrono>
#include <cstdint>
namespace cpr {
class Timeout {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::chrono::milliseconds& duration) : ms{duration} {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::int32_t& milliseconds) : Timeout{std::chrono::milliseconds(milliseconds)} {}
// No way around since curl uses a long here.
// NOLINTNEXTLINE(google-runtime-int)
long Milliseconds() const;
std::chrono::milliseconds ms;
};
} // namespace cpr
#endif

21
vendor/CPR/include/cpr/unix_socket.h vendored Normal file
View File

@ -0,0 +1,21 @@
#ifndef CPR_UNIX_SOCKET_H
#define CPR_UNIX_SOCKET_H
#include <string>
namespace cpr {
class UnixSocket {
public:
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UnixSocket(std::string&& unix_socket) : unix_socket_(std::move(unix_socket)) {}
const char* GetUnixSocketString() const noexcept;
private:
const std::string unix_socket_;
};
} // namespace cpr
#endif

31
vendor/CPR/include/cpr/user_agent.h vendored Normal file
View File

@ -0,0 +1,31 @@
#ifndef CPR_USERAGENT_H
#define CPR_USERAGENT_H
#include <initializer_list>
#include <string>
#include "cpr/cprtypes.h"
namespace cpr {
class UserAgent : public StringHolder<UserAgent> {
public:
UserAgent() : StringHolder<UserAgent>() {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(const std::string& useragent) : StringHolder<UserAgent>(useragent) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(std::string&& useragent) : StringHolder<UserAgent>(std::move(useragent)) {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
UserAgent(const char* useragent) : StringHolder<UserAgent>(useragent) {}
UserAgent(const char* str, size_t len) : StringHolder<UserAgent>(str, len) {}
UserAgent(const std::initializer_list<std::string> args) : StringHolder<UserAgent>(args) {}
UserAgent(const UserAgent& other) = default;
UserAgent(UserAgent&& old) noexcept = default;
~UserAgent() override = default;
UserAgent& operator=(UserAgent&& old) noexcept = default;
UserAgent& operator=(const UserAgent& other) = default;
};
} // namespace cpr
#endif

40
vendor/CPR/include/cpr/util.h vendored Normal file
View File

@ -0,0 +1,40 @@
#ifndef CPR_UTIL_H
#define CPR_UTIL_H
#include <fstream>
#include <string>
#include <vector>
#include "cpr/callback.h"
#include "cpr/cookies.h"
#include "cpr/cprtypes.h"
#include "cpr/curlholder.h"
namespace cpr {
namespace util {
Header parseHeader(const std::string& headers, std::string* status_line = nullptr,
std::string* reason = nullptr);
Cookies parseCookies(curl_slist* raw_cookies);
size_t readUserFunction(char* ptr, size_t size, size_t nitems, const ReadCallback* read);
size_t headerUserFunction(char* ptr, size_t size, size_t nmemb, const HeaderCallback* header);
size_t writeFunction(char* ptr, size_t size, size_t nmemb, std::string* data);
size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file);
size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallback* write);
#if LIBCURL_VERSION_NUM < 0x072000
int progressUserFunction(const ProgressCallback* progress, double dltotal, double dlnow,
double ultotal, double ulnow);
#else
int progressUserFunction(const ProgressCallback* progress, curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow);
#endif
int debugUserFunction(CURL* handle, curl_infotype type, char* data, size_t size,
const DebugCallback* debug);
std::vector<std::string> split(const std::string& to_split, char delimiter);
std::string urlEncode(const std::string& s);
std::string urlDecode(const std::string& s);
} // namespace util
} // namespace cpr
#endif

18
vendor/CPR/include/cpr/verbose.h vendored Normal file
View File

@ -0,0 +1,18 @@
#ifndef CPR_VERBOSE_H_
#define CPR_VERBOSE_H_
namespace cpr {
class Verbose {
public:
Verbose() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Verbose(const bool verbose) : verbose{verbose} {}
bool verbose = true;
};
} // namespace cpr
#endif /* CPR_VERBOSE_H_ */