26
27
static int min_curl_sessions = 1;
28
static int curl_session_count;
29
-#ifdef USE_CURL_MULTI
29
static int max_requests = -1;
30
static CURLM *curlm;
32
-#endif
31
#ifndef NO_CURL_EASY_DUPHANDLE
32
static CURL *curl_default;
33
#endif
115
116
enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
117
120
-#if LIBCURL_VERSION_NUM >= 0x071700
121
-/* Use CURLOPT_KEYPASSWD as is */
122
-#elif LIBCURL_VERSION_NUM >= 0x070903
123
-#define CURLOPT_KEYPASSWD CURLOPT_SSLKEYPASSWD
124
-#else
125
-#define CURLOPT_KEYPASSWD CURLOPT_SSLCERTPASSWD
126
-#endif
127
-
118
static struct credential cert_auth = CREDENTIAL_INIT;
119
static int ssl_cert_password_required;
120
static unsigned long http_auth_methods = CURLAUTH_ANY;
158
return size / eltsize;
159
}
160
171
-#ifndef NO_CURL_IOCTL
161
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
162
{
163
struct buffer *buffer = clientp;
174
return CURLIOE_UNKNOWNCMD;
175
}
176
}
188
-#endif
177
178
size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
179
{
221
222
static void xmulti_remove_handle(struct active_request_slot *slot)
223
{
236
-#ifdef USE_CURL_MULTI
224
curl_multi_remove_handle(curlm, slot->curl);
238
-#endif
225
}
226
241
-#ifdef USE_CURL_MULTI
227
static void process_curl_messages(void)
228
{
229
int num_messages;
251
curl_message = curl_multi_info_read(curlm, &num_messages);
252
}
253
}
269
-#endif
254
255
static int http_options(const char *var, const char *value, void *cb)
256
{
299
300
if (!strcmp("http.minsessions", var)) {
301
min_curl_sessions = git_config_int(var, value);
318
-#ifndef USE_CURL_MULTI
302
if (min_curl_sessions > 1)
303
min_curl_sessions = 1;
321
-#endif
304
return 0;
305
}
324
-#ifdef USE_CURL_MULTI
306
if (!strcmp("http.maxrequests", var)) {
307
max_requests = git_config_int(var, value);
308
return 0;
309
}
329
-#endif
310
if (!strcmp("http.lowspeedlimit", var)) {
311
curl_low_speed_limit = (long)git_config_int(var, value);
312
return 0;
554
curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1);
555
}
556
577
-#elif LIBCURL_VERSION_NUM >= 0x071000
557
+#else
558
static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
559
{
560
int ka = 1;
575
{
576
curl_easy_setopt(c, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
577
}
598
-
599
-#else
600
-static void set_curl_keepalive(CURL *c)
601
-{
602
- /* not supported on older curl versions */
603
-}
578
#endif
579
580
static void redact_sensitive_header(struct strbuf *header)
1095
no_pragma_header = curl_slist_append(http_copy_default_headers(),
1096
"Pragma:");
1097
1124
-#ifdef USE_CURL_MULTI
1098
{
1099
char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
1100
if (http_max_requests != NULL)
1104
curlm = curl_multi_init();
1105
if (!curlm)
1106
die("curl_multi_init failed");
1134
-#endif
1107
1108
if (getenv("GIT_SSL_NO_VERIFY"))
1109
curl_ssl_verify = 0;
1126
curl_ssl_verify = 1;
1127
1128
curl_session_count = 0;
1157
-#ifdef USE_CURL_MULTI
1129
if (max_requests < 1)
1130
max_requests = DEFAULT_MAX_REQUESTS;
1160
-#endif
1131
1132
set_from_env(&http_proxy_ssl_cert, "GIT_PROXY_SSL_CERT");
1133
set_from_env(&http_proxy_ssl_key, "GIT_PROXY_SSL_KEY");
1171
curl_easy_cleanup(curl_default);
1172
#endif
1173
1204
-#ifdef USE_CURL_MULTI
1174
curl_multi_cleanup(curlm);
1206
-#endif
1175
curl_global_cleanup();
1176
1177
string_list_clear(&extra_http_headers, 0);
1218
struct active_request_slot *slot = active_queue_head;
1219
struct active_request_slot *newslot;
1220
1253
-#ifdef USE_CURL_MULTI
1221
int num_transfers;
1222
1223
/* Wait for a slot to open up if the queue is full */
1226
if (num_transfers < active_requests)
1227
process_curl_messages();
1228
}
1262
-#endif
1229
1230
while (slot != NULL && slot->in_use)
1231
slot = slot->next;
1296
1297
int start_active_slot(struct active_request_slot *slot)
1298
{
1333
-#ifdef USE_CURL_MULTI
1299
CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
1300
int num_transfers;
1301
1313
* something.
1314
*/
1315
curl_multi_perform(curlm, &num_transfers);
1351
-#endif
1316
return 1;
1317
}
1318
1355
-#ifdef USE_CURL_MULTI
1319
struct fill_chain {
1320
void *data;
1321
int (*fill)(void *);
1374
fill_active_slots();
1375
}
1376
}
1414
-#endif
1377
1378
void run_active_slot(struct active_request_slot *slot)
1379
{
1418
-#ifdef USE_CURL_MULTI
1380
fd_set readfds;
1381
fd_set writefds;
1382
fd_set excfds;
1389
step_active_slots();
1390
1391
if (slot->in_use) {
1431
-#if LIBCURL_VERSION_NUM >= 0x070f04
1392
long curl_timeout;
1393
curl_multi_timeout(curlm, &curl_timeout);
1394
if (curl_timeout == 0) {
1400
select_timeout.tv_sec = curl_timeout / 1000;
1401
select_timeout.tv_usec = (curl_timeout % 1000) * 1000;
1402
}
1443
-#else
1444
- select_timeout.tv_sec = 0;
1445
- select_timeout.tv_usec = 50000;
1446
-#endif
1403
1404
max_fd = -1;
1405
FD_ZERO(&readfds);
1422
select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
1423
}
1424
}
1469
-#else
1470
- while (slot->in_use) {
1471
- slot->curl_result = curl_easy_perform(slot->curl);
1472
- finish_active_slot(slot);
1473
- }
1474
-#endif
1425
}
1426
1427
static void release_active_slot(struct active_request_slot *slot)
1435
curl_session_count--;
1436
}
1437
}
1488
-#ifdef USE_CURL_MULTI
1438
fill_active_slots();
1490
-#endif
1439
}
1440
1441
void finish_all_active_slots(void)
1561
} else {
1562
if (results->http_connectcode == 407)
1563
credential_reject(&proxy_auth);
1616
-#if LIBCURL_VERSION_NUM >= 0x070c00
1564
if (!curl_errorstr[0])
1565
strlcpy(curl_errorstr,
1566
curl_easy_strerror(results->curl_result),
1567
sizeof(curl_errorstr));
1621
-#endif
1568
return HTTP_ERROR;
1569
}
1570
}