mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-22 01:57:14 +02:00
Update CPR to latest git.
This commit is contained in:
51
vendor/CPR/include/cpr/callback.h
vendored
51
vendor/CPR/include/cpr/callback.h
vendored
@ -12,46 +12,54 @@ class ReadCallback {
|
||||
public:
|
||||
ReadCallback() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
ReadCallback(std::function<bool(char* buffer, size_t& size)> p_callback)
|
||||
: size{-1}, callback{std::move(p_callback)} {}
|
||||
ReadCallback(cpr_off_t p_size, std::function<bool(char* buffer, size_t& size)> p_callback)
|
||||
: size{p_size}, callback{std::move(p_callback)} {}
|
||||
ReadCallback(std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{-1}, callback{std::move(p_callback)} {}
|
||||
ReadCallback(cpr_off_t p_size, std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{p_size}, callback{std::move(p_callback)} {}
|
||||
bool operator()(char* buffer, size_t& size) const {
|
||||
return callback(buffer, size, userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
cpr_off_t size{};
|
||||
std::function<bool(char* buffer, size_t& size)> callback;
|
||||
std::function<bool(char* buffer, size_t& size, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
class HeaderCallback {
|
||||
public:
|
||||
HeaderCallback() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
HeaderCallback(std::function<bool(std::string header)> p_callback)
|
||||
: callback(std::move(p_callback)) {}
|
||||
HeaderCallback(std::function<bool(std::string header, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
bool operator()(std::string header) const {
|
||||
return callback(std::move(header), userdata);
|
||||
}
|
||||
|
||||
std::function<bool(std::string header)> callback;
|
||||
intptr_t userdata;
|
||||
std::function<bool(std::string header, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
class WriteCallback {
|
||||
public:
|
||||
WriteCallback() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
WriteCallback(std::function<bool(std::string data)> p_callback) : callback(std::move(p_callback)) {}
|
||||
WriteCallback(std::function<bool(std::string data, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
bool operator()(std::string data) const {
|
||||
return callback(std::move(data), userdata);
|
||||
}
|
||||
|
||||
std::function<bool(std::string data)> callback;
|
||||
intptr_t userdata;
|
||||
std::function<bool(std::string data, intptr_t userdata)> 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)>
|
||||
p_callback)
|
||||
: callback(std::move(p_callback)) {}
|
||||
ProgressCallback(std::function<bool(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
bool operator()(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow) const {
|
||||
return callback(downloadTotal, downloadNow, uploadTotal, uploadNow, userdata);
|
||||
}
|
||||
|
||||
std::function<bool(size_t downloadTotal, size_t downloadNow, size_t uploadTotal,
|
||||
size_t uploadNow)>
|
||||
callback;
|
||||
intptr_t userdata;
|
||||
std::function<bool(size_t downloadTotal, size_t downloadNow, size_t uploadTotal, size_t uploadNow, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
class DebugCallback {
|
||||
@ -67,10 +75,13 @@ class DebugCallback {
|
||||
};
|
||||
DebugCallback() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
DebugCallback(std::function<void(InfoType type, std::string data)> p_callback)
|
||||
: callback(std::move(p_callback)) {}
|
||||
DebugCallback(std::function<void(InfoType type, std::string data, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
void operator()(InfoType type, std::string data) const {
|
||||
callback(type, std::move(data), userdata);
|
||||
}
|
||||
|
||||
std::function<void(InfoType type, std::string data)> callback;
|
||||
intptr_t userdata;
|
||||
std::function<void(InfoType type, std::string data, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
2
vendor/CPR/include/cpr/cpr.h
vendored
2
vendor/CPR/include/cpr/cpr.h
vendored
@ -4,6 +4,8 @@
|
||||
#include "cpr/api.h"
|
||||
#include "cpr/auth.h"
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/interface.h"
|
||||
#include "cpr/redirect.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/session.h"
|
||||
#include "cpr/status_codes.h"
|
||||
|
32
vendor/CPR/include/cpr/interface.h
vendored
Normal file
32
vendor/CPR/include/cpr/interface.h
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef CPR_INTERFACE_H
|
||||
#define CPR_INTERFACE_H
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#include "cpr/cprtypes.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class Interface : public StringHolder<Interface> {
|
||||
public:
|
||||
Interface() : StringHolder<Interface>() {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(const std::string& iface) : StringHolder<Interface>(iface) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(std::string&& iface) : StringHolder<Interface>(std::move(iface)) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(const char* iface) : StringHolder<Interface>(iface) {}
|
||||
Interface(const char* str, size_t len) : StringHolder<Interface>(str, len) {}
|
||||
Interface(const std::initializer_list<std::string> args) : StringHolder<Interface>(args) {}
|
||||
Interface(const Interface& other) = default;
|
||||
Interface(Interface&& old) noexcept = default;
|
||||
~Interface() override = default;
|
||||
|
||||
Interface& operator=(Interface&& old) noexcept = default;
|
||||
Interface& operator=(const Interface& other) = default;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
18
vendor/CPR/include/cpr/max_redirects.h
vendored
18
vendor/CPR/include/cpr/max_redirects.h
vendored
@ -1,18 +0,0 @@
|
||||
#ifndef CPR_MAX_REDIRECTS_H
|
||||
#define CPR_MAX_REDIRECTS_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class MaxRedirects {
|
||||
public:
|
||||
explicit MaxRedirects(const std::int32_t p_number_of_redirects)
|
||||
: number_of_redirects(p_number_of_redirects) {}
|
||||
|
||||
std::int32_t number_of_redirects;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
77
vendor/CPR/include/cpr/redirect.h
vendored
Normal file
77
vendor/CPR/include/cpr/redirect.h
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef CPR_REDIRECT_H
|
||||
#define CPR_REDIRECT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace cpr {
|
||||
enum class PostRedirectFlags : uint8_t {
|
||||
/**
|
||||
* Respect RFC 7231 (section 6.4.2 to 6.4.4).
|
||||
* Same as CURL_REDIR_POST_301 (https://curl.se/libcurl/c/CURLOPT_POSTREDIR.html).
|
||||
**/
|
||||
POST_301 = 0x1 << 0,
|
||||
/**
|
||||
* Maintain the request method after a 302 redirect.
|
||||
* Same as CURL_REDIR_POST_302 (https://curl.se/libcurl/c/CURLOPT_POSTREDIR.html).
|
||||
**/
|
||||
POST_302 = 0x1 << 1,
|
||||
/**
|
||||
* Maintain the request method after a 303 redirect.
|
||||
* Same as CURL_REDIR_POST_303 (https://curl.se/libcurl/c/CURLOPT_POSTREDIR.html).
|
||||
**/
|
||||
POST_303 = 0x1 << 2,
|
||||
/**
|
||||
* Default value.
|
||||
* Convenience option to enable all flags.
|
||||
* Same as CURL_REDIR_POST_ALL (https://curl.se/libcurl/c/CURLOPT_POSTREDIR.html).
|
||||
**/
|
||||
POST_ALL = POST_301 | POST_302 | POST_303,
|
||||
/**
|
||||
* * Convenience option to disable all flags.
|
||||
**/
|
||||
NONE = 0x0
|
||||
};
|
||||
|
||||
PostRedirectFlags operator|(PostRedirectFlags lhs, PostRedirectFlags rhs);
|
||||
PostRedirectFlags operator&(PostRedirectFlags lhs, PostRedirectFlags rhs);
|
||||
PostRedirectFlags operator^(PostRedirectFlags lhs, PostRedirectFlags rhs);
|
||||
PostRedirectFlags operator~(PostRedirectFlags flag);
|
||||
PostRedirectFlags& operator|=(PostRedirectFlags& lhs, PostRedirectFlags rhs);
|
||||
PostRedirectFlags& operator&=(PostRedirectFlags& lhs, PostRedirectFlags rhs);
|
||||
PostRedirectFlags& operator^=(PostRedirectFlags& lhs, PostRedirectFlags rhs);
|
||||
bool any(PostRedirectFlags flag);
|
||||
|
||||
class Redirect {
|
||||
public:
|
||||
/**
|
||||
* The maximum number of redirects to follow.
|
||||
* 0: Refuse any redirects.
|
||||
* -1: Infinite number of redirects.
|
||||
* Default: 50
|
||||
* https://curl.se/libcurl/c/CURLOPT_MAXREDIRS.html
|
||||
**/
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-magic-numbers, google-runtime-int)
|
||||
long maximum{50L};
|
||||
/**
|
||||
* Follow 3xx redirects.
|
||||
* Default: true
|
||||
* https://curl.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html
|
||||
**/
|
||||
bool follow{true};
|
||||
/**
|
||||
* Flags to control how to act after a redirect for a post request.
|
||||
* Default: POST_ALL
|
||||
**/
|
||||
PostRedirectFlags post_flags{PostRedirectFlags::POST_ALL};
|
||||
|
||||
Redirect() = default;
|
||||
// NOLINTNEXTLINE (google-runtime-int)
|
||||
Redirect(long p_maximum, bool p_follow, PostRedirectFlags p_post_flags) : maximum(p_maximum), follow(p_follow), post_flags(p_post_flags){};
|
||||
// NOLINTNEXTLINE (google-runtime-int)
|
||||
explicit Redirect(long p_maximum) : maximum(p_maximum){};
|
||||
explicit Redirect(bool p_follow) : follow(p_follow){};
|
||||
explicit Redirect(PostRedirectFlags p_post_flags) : post_flags(p_post_flags){};
|
||||
};
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
12
vendor/CPR/include/cpr/session.h
vendored
12
vendor/CPR/include/cpr/session.h
vendored
@ -14,15 +14,16 @@
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/curlholder.h"
|
||||
#include "cpr/digest.h"
|
||||
#include "cpr/interface.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/proxyauth.h"
|
||||
#include "cpr/redirect.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/ssl_options.h"
|
||||
#include "cpr/timeout.h"
|
||||
@ -62,8 +63,7 @@ class Session {
|
||||
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 SetRedirect(const Redirect& redirect);
|
||||
void SetCookies(const Cookies& cookies);
|
||||
void SetBody(Body&& body);
|
||||
void SetBody(const Body& body);
|
||||
@ -77,6 +77,7 @@ class Session {
|
||||
void SetProgressCallback(const ProgressCallback& progress);
|
||||
void SetDebugCallback(const DebugCallback& debug);
|
||||
void SetVerbose(const Verbose& verbose);
|
||||
void SetInterface(const Interface& iface);
|
||||
|
||||
// Used in templated functions
|
||||
void SetOption(const Url& url);
|
||||
@ -103,8 +104,7 @@ class Session {
|
||||
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 Redirect& redirect);
|
||||
void SetOption(const Cookies& cookies);
|
||||
void SetOption(Body&& body);
|
||||
void SetOption(const Body& body);
|
||||
@ -118,7 +118,9 @@ class Session {
|
||||
void SetOption(const Verbose& verbose);
|
||||
void SetOption(const UnixSocket& unix_socket);
|
||||
void SetOption(const SslOptions& options);
|
||||
void SetOption(const Interface& iface);
|
||||
|
||||
cpr_off_t GetDownloadFileLength();
|
||||
Response Delete();
|
||||
Response Download(const WriteCallback& write);
|
||||
Response Download(std::ofstream& file);
|
||||
|
Reference in New Issue
Block a user