| 1573 | } |
| 1574 | |
| 1575 | struct active_request_slot *get_active_slot(void) |
| 1576 | { |
| 1577 | struct active_request_slot *slot = active_queue_head; |
| 1578 | struct active_request_slot *newslot; |
| 1579 | |
| 1580 | int num_transfers; |
| 1581 | |
| 1582 | /* Wait for a slot to open up if the queue is full */ |
| 1583 | while (active_requests >= max_requests) { |
| 1584 | curl_multi_perform(curlm, &num_transfers); |
| 1585 | if (num_transfers < active_requests) |
| 1586 | process_curl_messages(); |
| 1587 | } |
| 1588 | |
| 1589 | while (slot != NULL && slot->in_use) |
| 1590 | slot = slot->next; |
| 1591 | |
| 1592 | if (!slot) { |
| 1593 | newslot = xmalloc(sizeof(*newslot)); |
| 1594 | newslot->curl = NULL; |
| 1595 | newslot->in_use = 0; |
| 1596 | newslot->next = NULL; |
| 1597 | |
| 1598 | slot = active_queue_head; |
| 1599 | if (!slot) { |
| 1600 | active_queue_head = newslot; |
| 1601 | } else { |
| 1602 | while (slot->next != NULL) |
| 1603 | slot = slot->next; |
| 1604 | slot->next = newslot; |
| 1605 | } |
| 1606 | slot = newslot; |
| 1607 | } |
| 1608 | |
| 1609 | if (!slot->curl) { |
| 1610 | slot->curl = curl_easy_duphandle(curl_default); |
| 1611 | curl_session_count++; |
| 1612 | } |
| 1613 | |
| 1614 | active_requests++; |
| 1615 | slot->in_use = 1; |
| 1616 | slot->results = NULL; |
| 1617 | slot->finished = NULL; |
| 1618 | slot->callback_data = NULL; |
| 1619 | slot->callback_func = NULL; |
| 1620 | |
| 1621 | if (curl_cookie_file && !strcmp(curl_cookie_file, "-")) { |
| 1622 | warning(_("refusing to read cookies from http.cookiefile '-'")); |
| 1623 | FREE_AND_NULL(curl_cookie_file); |
| 1624 | } |
| 1625 | curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file); |
| 1626 | if (curl_save_cookies && (!curl_cookie_file || !curl_cookie_file[0])) { |
| 1627 | curl_save_cookies = 0; |
| 1628 | warning(_("ignoring http.savecookies for empty http.cookiefile")); |
| 1629 | } |
| 1630 | if (curl_save_cookies) |
| 1631 | curl_easy_setopt(slot->curl, CURLOPT_COOKIEJAR, curl_cookie_file); |
| 1632 | curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header); |
no test coverage detected