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
13namespace cpr::util {
14
15Header parseHeader(const std::string& headers, std::string* status_line = nullptr, std::string* reason = nullptr);
16Cookies parseCookies(curl_slist* raw_cookies);
17size_t readUserFunction(char* ptr, size_t size, size_t nitems, const ReadCallback* read);
18size_t headerUserFunction(char* ptr, size_t size, size_t nmemb, const HeaderCallback* header);
19size_t writeFunction(char* ptr, size_t size, size_t nmemb, std::string* data);
20size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file);
21size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallback* write);
22
23template <typename T = ProgressCallback>
24int 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}
29int debugUserFunction(CURL* handle, curl_infotype type, char* data, size_t size, const DebugCallback* debug);
30std::vector<std::string> split(const std::string& to_split, char delimiter);
31std::string urlEncode(const std::string& s);
32std::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 **/
40void secureStringClear(std::string& s);
41bool isTrue(const std::string& s);
42
43} // namespace cpr::util
44
45#endif
46