| 138 | } |
| 139 | |
| 140 | bool GetRemoteFile(const char *url, std::string &str, std::string &error, long *responseCode, const char *contentType, |
| 141 | std::string request_type, const char *postData, std::vector<std::string> headers, |
| 142 | std::string *signature, int timeoutSec, bool fail_on_error, int postDataSize) |
| 143 | { |
| 144 | vector<string> header_in_list; |
| 145 | char error_in[CURL_ERROR_SIZE]; |
| 146 | CURLcode code = CURLE_FAILED_INIT; |
| 147 | |
| 148 | error_in[0] = 0; |
| 149 | |
| 150 | //string versionString("User-Agent: obs-basic "); |
| 151 | //versionString += App()->GetVersionString(); |
| 152 | |
| 153 | string contentTypeString; |
| 154 | if (contentType) { |
| 155 | contentTypeString += "Content-Type: "; |
| 156 | contentTypeString += contentType; |
| 157 | } |
| 158 | |
| 159 | Curl curl{curl_easy_init(), curl_deleter}; |
| 160 | if (curl) { |
| 161 | struct curl_slist *header = nullptr; |
| 162 | |
| 163 | //header = curl_slist_append(header, versionString.c_str()); |
| 164 | |
| 165 | if (!contentTypeString.empty()) { |
| 166 | header = curl_slist_append(header, contentTypeString.c_str()); |
| 167 | } |
| 168 | |
| 169 | for (std::string &h : headers) |
| 170 | header = curl_slist_append(header, h.c_str()); |
| 171 | |
| 172 | curl_easy_setopt(curl.get(), CURLOPT_URL, url); |
| 173 | curl_easy_setopt(curl.get(), CURLOPT_ACCEPT_ENCODING, ""); |
| 174 | curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, header); |
| 175 | curl_easy_setopt(curl.get(), CURLOPT_ERRORBUFFER, error_in); |
| 176 | if (fail_on_error) |
| 177 | curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L); |
| 178 | curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, string_write); |
| 179 | curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &str); |
| 180 | curl_obs_set_revoke_setting(curl.get()); |
| 181 | |
| 182 | if (signature) { |
| 183 | curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION, header_write); |
| 184 | curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA, &header_in_list); |
| 185 | } |
| 186 | |
| 187 | if (timeoutSec) |
| 188 | curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, timeoutSec); |
| 189 | |
| 190 | if (!request_type.empty()) { |
| 191 | if (request_type != "GET") |
| 192 | curl_easy_setopt(curl.get(), CURLOPT_CUSTOMREQUEST, request_type.c_str()); |
| 193 | |
| 194 | // Special case of "POST" |
| 195 | if (request_type == "POST") { |
| 196 | curl_easy_setopt(curl.get(), CURLOPT_POST, 1); |
| 197 | if (!postData) |
nothing calls this directly
no outgoing calls
no test coverage detected