1 | #ifndef CPR_UTIL_H |
2 | #define CPR_UTIL_H |
3 | |
4 | #include <fstream> |
5 | #include <string> |
6 | #include <vector> |
7 | |
8 | #include "cpr/callback.h" |
9 | #include "cpr/cookies.h" |
10 | #include "cpr/cprtypes.h" |
11 | #include "cpr/curlholder.h" |
12 | |
13 | namespace cpr::util { |
14 | |
15 | Header (const std::string& , std::string* status_line = nullptr, std::string* reason = nullptr); |
16 | Cookies parseCookies(curl_slist* raw_cookies); |
17 | size_t readUserFunction(char* ptr, size_t size, size_t nitems, const ReadCallback* read); |
18 | size_t (char* ptr, size_t size, size_t nmemb, const HeaderCallback* ); |
19 | size_t writeFunction(char* ptr, size_t size, size_t nmemb, std::string* data); |
20 | size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file); |
21 | size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallback* write); |
22 | |
23 | template <typename T = ProgressCallback> |
24 | int progressUserFunction(const T* progress, cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, cpr_pf_arg_t ultotal, cpr_pf_arg_t ulnow) { |
25 | const int cancel_retval{1}; |
26 | static_assert(cancel_retval != 0x10000001); |
27 | return (*progress)(dltotal, dlnow, ultotal, ulnow) ? 0 : cancel_retval; |
28 | } |
29 | int debugUserFunction(CURL* handle, curl_infotype type, char* data, size_t size, const DebugCallback* debug); |
30 | std::vector<std::string> split(const std::string& to_split, char delimiter); |
31 | std::string urlEncode(const std::string& s); |
32 | std::string urlDecode(const std::string& s); |
33 | |
34 | /** |
35 | * Override the content of the provided string to hide sensitive data. The |
36 | * string content after invocation is undefined. The string size is reset to zero. |
37 | * impl. based on: |
38 | * https://github.com/ojeda/secure_clear/blob/master/example-implementation/secure_clear.h |
39 | **/ |
40 | void secureStringClear(std::string& s); |
41 | bool isTrue(const std::string& s); |
42 | |
43 | } // namespace cpr::util |
44 | |
45 | #endif |
46 | |