\brief Download content from URL to a string \param url the URL to download from \return the downloaded string
| 217 | /// \param url the URL to download from |
| 218 | /// \return the downloaded string |
| 219 | std::string download_string(const std::string& url) { |
| 220 | CURL* curl = curl_easy_init(); |
| 221 | if (!curl) { |
| 222 | std::cerr << "Failed to initialize CURL" << std::endl; |
| 223 | return ""; |
| 224 | } |
| 225 | |
| 226 | std::string response; |
| 227 | |
| 228 | curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
| 229 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data_to_string); |
| 230 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); |
| 231 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); |
| 232 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); |
| 233 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); |
| 234 | curl_easy_setopt(curl, CURLOPT_USERAGENT, "FastFlowLM/1.0"); |
| 235 | curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L); // 1 minute timeout |
| 236 | |
| 237 | CURLcode res = curl_easy_perform(curl); |
| 238 | curl_easy_cleanup(curl); |
| 239 | |
| 240 | if (res != CURLE_OK) { |
| 241 | std::cerr << "CURL error: " << curl_easy_strerror(res) << std::endl; |
| 242 | return ""; |
| 243 | } |
| 244 | |
| 245 | return response; |
| 246 | } |
| 247 | |
| 248 | /// \brief Download multiple files with progress tracking |
| 249 | /// \param downloads the downloads |
no outgoing calls
no test coverage detected