* msHTTPExecuteRequests() * * Fetch a map slide via HTTP request and save to specified temp file. * * If bCheckLocalCache==MS_TRUE then if the pszOutputfile already exists * then is is not downloaded again, and status 242 is returned. * * Return value: * MS_SUCCESS if all requests completed succesfully. * MS_FAILURE if a fatal error happened * MS_DONE if some re
| 305 | * MS_DONE if some requests failed with 40x status for instance (not fatal) |
| 306 | **********************************************************************/ |
| 307 | int msHTTPExecuteRequests(httpRequestObj *pasReqInfo, int numRequests, |
| 308 | int bCheckLocalCache) |
| 309 | { |
| 310 | int i, nStatus = MS_SUCCESS, nTimeout, still_running=0, num_msgs=0; |
| 311 | CURLM *multi_handle; |
| 312 | CURLMsg *curl_msg; |
| 313 | char debug = MS_FALSE; |
| 314 | const char *pszCurlCABundle = NULL; |
| 315 | |
| 316 | if (numRequests == 0) |
| 317 | return MS_SUCCESS; /* Nothing to do */ |
| 318 | |
| 319 | if (!gbCurlInitialized) |
| 320 | msHTTPInit(); |
| 321 | |
| 322 | /* Establish the timeout (seconds) for how long we are going to wait |
| 323 | * for a response. |
| 324 | * We use the longest timeout value in the array of requests |
| 325 | */ |
| 326 | nTimeout = pasReqInfo[0].nTimeout; |
| 327 | for (i=0; i<numRequests; i++) |
| 328 | { |
| 329 | if (pasReqInfo[i].nTimeout > nTimeout) |
| 330 | nTimeout = pasReqInfo[i].nTimeout; |
| 331 | |
| 332 | if (pasReqInfo[i].debug) |
| 333 | debug = MS_TRUE; /* For the download loop */ |
| 334 | } |
| 335 | |
| 336 | if (nTimeout <= 0) |
| 337 | nTimeout = 30; |
| 338 | |
| 339 | /* Check if we've got a CURL_CA_BUNDLE env. var. |
| 340 | * If set then the value is the full path to the ca-bundle.crt file |
| 341 | * e.g. CURL_CA_BUNDLE=/usr/local/share/curl/curl-ca-bundle.crt |
| 342 | */ |
| 343 | pszCurlCABundle = getenv("CURL_CA_BUNDLE"); |
| 344 | |
| 345 | if (debug) |
| 346 | { |
| 347 | msDebug("HTTP: Starting to prepare HTTP requests.\n"); |
| 348 | if (pszCurlCABundle) |
| 349 | msDebug("Using CURL_CA_BUNDLE=%s\n", pszCurlCABundle); |
| 350 | } |
| 351 | |
| 352 | /* Alloc a curl-multi handle, and add a curl-easy handle to it for each |
| 353 | * file to download. |
| 354 | */ |
| 355 | multi_handle = curl_multi_init(); |
| 356 | if (multi_handle == NULL) |
| 357 | { |
| 358 | msSetError(MS_HTTPERR, "curl_multi_init() failed.", |
| 359 | "msHTTPExecuteRequests()"); |
| 360 | return(MS_FAILURE); |
| 361 | } |
| 362 | |
| 363 | for (i=0; i<numRequests; i++) |
| 364 | { |
no test coverage detected