1 #include "git-compat-util.h"
5 #include "run-command.h"
8 #include "credential.h"
14 size_t http_post_buffer
= 16 * LARGE_PACKET_MAX
;
16 #if LIBCURL_VERSION_NUM >= 0x070a06
17 #define LIBCURL_CAN_HANDLE_AUTH_ANY
20 static int min_curl_sessions
= 1;
21 static int curl_session_count
;
23 static int max_requests
= -1;
26 #ifndef NO_CURL_EASY_DUPHANDLE
27 static CURL
*curl_default
;
30 #define PREV_BUF_SIZE 4096
31 #define RANGE_HEADER_SIZE 30
33 char curl_errorstr
[CURL_ERROR_SIZE
];
35 static int curl_ssl_verify
= -1;
36 static int curl_ssl_try
;
37 static const char *ssl_cert
;
38 #if LIBCURL_VERSION_NUM >= 0x070903
39 static const char *ssl_key
;
41 #if LIBCURL_VERSION_NUM >= 0x070908
42 static const char *ssl_capath
;
44 static const char *ssl_cainfo
;
45 static long curl_low_speed_limit
= -1;
46 static long curl_low_speed_time
= -1;
47 static int curl_ftp_no_epsv
;
48 static const char *curl_http_proxy
;
49 static const char *curl_cookie_file
;
50 static int curl_save_cookies
;
51 struct credential http_auth
= CREDENTIAL_INIT
;
52 static int http_proactive_auth
;
53 static const char *user_agent
;
55 #if LIBCURL_VERSION_NUM >= 0x071700
56 /* Use CURLOPT_KEYPASSWD as is */
57 #elif LIBCURL_VERSION_NUM >= 0x070903
58 #define CURLOPT_KEYPASSWD CURLOPT_SSLKEYPASSWD
60 #define CURLOPT_KEYPASSWD CURLOPT_SSLCERTPASSWD
63 static struct credential cert_auth
= CREDENTIAL_INIT
;
64 static int ssl_cert_password_required
;
65 #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
66 static unsigned long http_auth_methods
= CURLAUTH_ANY
;
69 static struct curl_slist
*pragma_header
;
70 static struct curl_slist
*no_pragma_header
;
72 static struct active_request_slot
*active_queue_head
;
74 size_t fread_buffer(char *ptr
, size_t eltsize
, size_t nmemb
, void *buffer_
)
76 size_t size
= eltsize
* nmemb
;
77 struct buffer
*buffer
= buffer_
;
79 if (size
> buffer
->buf
.len
- buffer
->posn
)
80 size
= buffer
->buf
.len
- buffer
->posn
;
81 memcpy(ptr
, buffer
->buf
.buf
+ buffer
->posn
, size
);
88 curlioerr
ioctl_buffer(CURL
*handle
, int cmd
, void *clientp
)
90 struct buffer
*buffer
= clientp
;
96 case CURLIOCMD_RESTARTREAD
:
101 return CURLIOE_UNKNOWNCMD
;
106 size_t fwrite_buffer(char *ptr
, size_t eltsize
, size_t nmemb
, void *buffer_
)
108 size_t size
= eltsize
* nmemb
;
109 struct strbuf
*buffer
= buffer_
;
111 strbuf_add(buffer
, ptr
, size
);
115 size_t fwrite_null(char *ptr
, size_t eltsize
, size_t nmemb
, void *strbuf
)
117 return eltsize
* nmemb
;
120 static void closedown_active_slot(struct active_request_slot
*slot
)
126 static void finish_active_slot(struct active_request_slot
*slot
)
128 closedown_active_slot(slot
);
129 curl_easy_getinfo(slot
->curl
, CURLINFO_HTTP_CODE
, &slot
->http_code
);
131 if (slot
->finished
!= NULL
)
132 (*slot
->finished
) = 1;
134 /* Store slot results so they can be read after the slot is reused */
135 if (slot
->results
!= NULL
) {
136 slot
->results
->curl_result
= slot
->curl_result
;
137 slot
->results
->http_code
= slot
->http_code
;
138 #if LIBCURL_VERSION_NUM >= 0x070a08
139 curl_easy_getinfo(slot
->curl
, CURLINFO_HTTPAUTH_AVAIL
,
140 &slot
->results
->auth_avail
);
142 slot
->results
->auth_avail
= 0;
146 /* Run callback if appropriate */
147 if (slot
->callback_func
!= NULL
)
148 slot
->callback_func(slot
->callback_data
);
151 #ifdef USE_CURL_MULTI
152 static void process_curl_messages(void)
155 struct active_request_slot
*slot
;
156 CURLMsg
*curl_message
= curl_multi_info_read(curlm
, &num_messages
);
158 while (curl_message
!= NULL
) {
159 if (curl_message
->msg
== CURLMSG_DONE
) {
160 int curl_result
= curl_message
->data
.result
;
161 slot
= active_queue_head
;
162 while (slot
!= NULL
&&
163 slot
->curl
!= curl_message
->easy_handle
)
166 curl_multi_remove_handle(curlm
, slot
->curl
);
167 slot
->curl_result
= curl_result
;
168 finish_active_slot(slot
);
170 fprintf(stderr
, "Received DONE message for unknown request!\n");
173 fprintf(stderr
, "Unknown CURL message received: %d\n",
174 (int)curl_message
->msg
);
176 curl_message
= curl_multi_info_read(curlm
, &num_messages
);
181 static int http_options(const char *var
, const char *value
, void *cb
)
183 if (!strcmp("http.sslverify", var
)) {
184 curl_ssl_verify
= git_config_bool(var
, value
);
187 if (!strcmp("http.sslcert", var
))
188 return git_config_string(&ssl_cert
, var
, value
);
189 #if LIBCURL_VERSION_NUM >= 0x070903
190 if (!strcmp("http.sslkey", var
))
191 return git_config_string(&ssl_key
, var
, value
);
193 #if LIBCURL_VERSION_NUM >= 0x070908
194 if (!strcmp("http.sslcapath", var
))
195 return git_config_string(&ssl_capath
, var
, value
);
197 if (!strcmp("http.sslcainfo", var
))
198 return git_config_string(&ssl_cainfo
, var
, value
);
199 if (!strcmp("http.sslcertpasswordprotected", var
)) {
200 ssl_cert_password_required
= git_config_bool(var
, value
);
203 if (!strcmp("http.ssltry", var
)) {
204 curl_ssl_try
= git_config_bool(var
, value
);
207 if (!strcmp("http.minsessions", var
)) {
208 min_curl_sessions
= git_config_int(var
, value
);
209 #ifndef USE_CURL_MULTI
210 if (min_curl_sessions
> 1)
211 min_curl_sessions
= 1;
215 #ifdef USE_CURL_MULTI
216 if (!strcmp("http.maxrequests", var
)) {
217 max_requests
= git_config_int(var
, value
);
221 if (!strcmp("http.lowspeedlimit", var
)) {
222 curl_low_speed_limit
= (long)git_config_int(var
, value
);
225 if (!strcmp("http.lowspeedtime", var
)) {
226 curl_low_speed_time
= (long)git_config_int(var
, value
);
230 if (!strcmp("http.noepsv", var
)) {
231 curl_ftp_no_epsv
= git_config_bool(var
, value
);
234 if (!strcmp("http.proxy", var
))
235 return git_config_string(&curl_http_proxy
, var
, value
);
237 if (!strcmp("http.cookiefile", var
))
238 return git_config_string(&curl_cookie_file
, var
, value
);
239 if (!strcmp("http.savecookies", var
)) {
240 curl_save_cookies
= git_config_bool(var
, value
);
244 if (!strcmp("http.postbuffer", var
)) {
245 http_post_buffer
= git_config_int(var
, value
);
246 if (http_post_buffer
< LARGE_PACKET_MAX
)
247 http_post_buffer
= LARGE_PACKET_MAX
;
251 if (!strcmp("http.useragent", var
))
252 return git_config_string(&user_agent
, var
, value
);
254 /* Fall back on the default ones */
255 return git_default_config(var
, value
, cb
);
258 static void init_curl_http_auth(CURL
*result
)
260 if (!http_auth
.username
)
263 credential_fill(&http_auth
);
265 #if LIBCURL_VERSION_NUM >= 0x071301
266 curl_easy_setopt(result
, CURLOPT_USERNAME
, http_auth
.username
);
267 curl_easy_setopt(result
, CURLOPT_PASSWORD
, http_auth
.password
);
270 static struct strbuf up
= STRBUF_INIT
;
272 * Note that we assume we only ever have a single set of
273 * credentials in a given program run, so we do not have
274 * to worry about updating this buffer, only setting its
278 strbuf_addf(&up
, "%s:%s",
279 http_auth
.username
, http_auth
.password
);
280 curl_easy_setopt(result
, CURLOPT_USERPWD
, up
.buf
);
285 static int has_cert_password(void)
287 if (ssl_cert
== NULL
|| ssl_cert_password_required
!= 1)
289 if (!cert_auth
.password
) {
290 cert_auth
.protocol
= xstrdup("cert");
291 cert_auth
.username
= xstrdup("");
292 cert_auth
.path
= xstrdup(ssl_cert
);
293 credential_fill(&cert_auth
);
298 #if LIBCURL_VERSION_NUM >= 0x071900
299 static void set_curl_keepalive(CURL
*c
)
301 curl_easy_setopt(c
, CURLOPT_TCP_KEEPALIVE
, 1);
304 #elif LIBCURL_VERSION_NUM >= 0x071000
305 static int sockopt_callback(void *client
, curl_socket_t fd
, curlsocktype type
)
309 socklen_t len
= (socklen_t
)sizeof(ka
);
311 if (type
!= CURLSOCKTYPE_IPCXN
)
314 rc
= setsockopt(fd
, SOL_SOCKET
, SO_KEEPALIVE
, (void *)&ka
, len
);
316 warning("unable to set SO_KEEPALIVE on socket %s",
319 return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
322 static void set_curl_keepalive(CURL
*c
)
324 curl_easy_setopt(c
, CURLOPT_SOCKOPTFUNCTION
, sockopt_callback
);
328 static void set_curl_keepalive(CURL
*c
)
330 /* not supported on older curl versions */
334 static CURL
*get_curl_handle(void)
336 CURL
*result
= curl_easy_init();
339 die("curl_easy_init failed");
341 if (!curl_ssl_verify
) {
342 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYPEER
, 0);
343 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYHOST
, 0);
345 /* Verify authenticity of the peer's certificate */
346 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYPEER
, 1);
347 /* The name in the cert must match whom we tried to connect */
348 curl_easy_setopt(result
, CURLOPT_SSL_VERIFYHOST
, 2);
351 #if LIBCURL_VERSION_NUM >= 0x070907
352 curl_easy_setopt(result
, CURLOPT_NETRC
, CURL_NETRC_OPTIONAL
);
354 #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
355 curl_easy_setopt(result
, CURLOPT_HTTPAUTH
, CURLAUTH_ANY
);
358 if (http_proactive_auth
)
359 init_curl_http_auth(result
);
361 if (ssl_cert
!= NULL
)
362 curl_easy_setopt(result
, CURLOPT_SSLCERT
, ssl_cert
);
363 if (has_cert_password())
364 curl_easy_setopt(result
, CURLOPT_KEYPASSWD
, cert_auth
.password
);
365 #if LIBCURL_VERSION_NUM >= 0x070903
367 curl_easy_setopt(result
, CURLOPT_SSLKEY
, ssl_key
);
369 #if LIBCURL_VERSION_NUM >= 0x070908
370 if (ssl_capath
!= NULL
)
371 curl_easy_setopt(result
, CURLOPT_CAPATH
, ssl_capath
);
373 if (ssl_cainfo
!= NULL
)
374 curl_easy_setopt(result
, CURLOPT_CAINFO
, ssl_cainfo
);
376 if (curl_low_speed_limit
> 0 && curl_low_speed_time
> 0) {
377 curl_easy_setopt(result
, CURLOPT_LOW_SPEED_LIMIT
,
378 curl_low_speed_limit
);
379 curl_easy_setopt(result
, CURLOPT_LOW_SPEED_TIME
,
380 curl_low_speed_time
);
383 curl_easy_setopt(result
, CURLOPT_FOLLOWLOCATION
, 1);
384 #if LIBCURL_VERSION_NUM >= 0x071301
385 curl_easy_setopt(result
, CURLOPT_POSTREDIR
, CURL_REDIR_POST_ALL
);
386 #elif LIBCURL_VERSION_NUM >= 0x071101
387 curl_easy_setopt(result
, CURLOPT_POST301
, 1);
390 if (getenv("GIT_CURL_VERBOSE"))
391 curl_easy_setopt(result
, CURLOPT_VERBOSE
, 1);
393 curl_easy_setopt(result
, CURLOPT_USERAGENT
,
394 user_agent
? user_agent
: git_user_agent());
396 if (curl_ftp_no_epsv
)
397 curl_easy_setopt(result
, CURLOPT_FTP_USE_EPSV
, 0);
399 #ifdef CURLOPT_USE_SSL
401 curl_easy_setopt(result
, CURLOPT_USE_SSL
, CURLUSESSL_TRY
);
404 if (curl_http_proxy
) {
405 curl_easy_setopt(result
, CURLOPT_PROXY
, curl_http_proxy
);
406 curl_easy_setopt(result
, CURLOPT_PROXYAUTH
, CURLAUTH_ANY
);
409 set_curl_keepalive(result
);
414 static void set_from_env(const char **var
, const char *envname
)
416 const char *val
= getenv(envname
);
421 void http_init(struct remote
*remote
, const char *url
, int proactive_auth
)
423 char *low_speed_limit
;
424 char *low_speed_time
;
425 char *normalized_url
;
426 struct urlmatch_config config
= { STRING_LIST_INIT_DUP
};
428 config
.section
= "http";
430 config
.collect_fn
= http_options
;
431 config
.cascade_fn
= git_default_config
;
435 normalized_url
= url_normalize(url
, &config
.url
);
437 git_config(urlmatch_config_entry
, &config
);
438 free(normalized_url
);
440 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
)
441 die("curl_global_init failed");
443 http_proactive_auth
= proactive_auth
;
445 if (remote
&& remote
->http_proxy
)
446 curl_http_proxy
= xstrdup(remote
->http_proxy
);
448 pragma_header
= curl_slist_append(pragma_header
, "Pragma: no-cache");
449 no_pragma_header
= curl_slist_append(no_pragma_header
, "Pragma:");
451 #ifdef USE_CURL_MULTI
453 char *http_max_requests
= getenv("GIT_HTTP_MAX_REQUESTS");
454 if (http_max_requests
!= NULL
)
455 max_requests
= atoi(http_max_requests
);
458 curlm
= curl_multi_init();
460 die("curl_multi_init failed");
463 if (getenv("GIT_SSL_NO_VERIFY"))
466 set_from_env(&ssl_cert
, "GIT_SSL_CERT");
467 #if LIBCURL_VERSION_NUM >= 0x070903
468 set_from_env(&ssl_key
, "GIT_SSL_KEY");
470 #if LIBCURL_VERSION_NUM >= 0x070908
471 set_from_env(&ssl_capath
, "GIT_SSL_CAPATH");
473 set_from_env(&ssl_cainfo
, "GIT_SSL_CAINFO");
475 set_from_env(&user_agent
, "GIT_HTTP_USER_AGENT");
477 low_speed_limit
= getenv("GIT_HTTP_LOW_SPEED_LIMIT");
478 if (low_speed_limit
!= NULL
)
479 curl_low_speed_limit
= strtol(low_speed_limit
, NULL
, 10);
480 low_speed_time
= getenv("GIT_HTTP_LOW_SPEED_TIME");
481 if (low_speed_time
!= NULL
)
482 curl_low_speed_time
= strtol(low_speed_time
, NULL
, 10);
484 if (curl_ssl_verify
== -1)
487 curl_session_count
= 0;
488 #ifdef USE_CURL_MULTI
489 if (max_requests
< 1)
490 max_requests
= DEFAULT_MAX_REQUESTS
;
493 if (getenv("GIT_CURL_FTP_NO_EPSV"))
494 curl_ftp_no_epsv
= 1;
497 credential_from_url(&http_auth
, url
);
498 if (!ssl_cert_password_required
&&
499 getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
500 starts_with(url
, "https://"))
501 ssl_cert_password_required
= 1;
504 #ifndef NO_CURL_EASY_DUPHANDLE
505 curl_default
= get_curl_handle();
509 void http_cleanup(void)
511 struct active_request_slot
*slot
= active_queue_head
;
513 while (slot
!= NULL
) {
514 struct active_request_slot
*next
= slot
->next
;
515 if (slot
->curl
!= NULL
) {
516 #ifdef USE_CURL_MULTI
517 curl_multi_remove_handle(curlm
, slot
->curl
);
519 curl_easy_cleanup(slot
->curl
);
524 active_queue_head
= NULL
;
526 #ifndef NO_CURL_EASY_DUPHANDLE
527 curl_easy_cleanup(curl_default
);
530 #ifdef USE_CURL_MULTI
531 curl_multi_cleanup(curlm
);
533 curl_global_cleanup();
535 curl_slist_free_all(pragma_header
);
536 pragma_header
= NULL
;
538 curl_slist_free_all(no_pragma_header
);
539 no_pragma_header
= NULL
;
541 if (curl_http_proxy
) {
542 free((void *)curl_http_proxy
);
543 curl_http_proxy
= NULL
;
546 if (cert_auth
.password
!= NULL
) {
547 memset(cert_auth
.password
, 0, strlen(cert_auth
.password
));
548 free(cert_auth
.password
);
549 cert_auth
.password
= NULL
;
551 ssl_cert_password_required
= 0;
554 struct active_request_slot
*get_active_slot(void)
556 struct active_request_slot
*slot
= active_queue_head
;
557 struct active_request_slot
*newslot
;
559 #ifdef USE_CURL_MULTI
562 /* Wait for a slot to open up if the queue is full */
563 while (active_requests
>= max_requests
) {
564 curl_multi_perform(curlm
, &num_transfers
);
565 if (num_transfers
< active_requests
)
566 process_curl_messages();
570 while (slot
!= NULL
&& slot
->in_use
)
574 newslot
= xmalloc(sizeof(*newslot
));
575 newslot
->curl
= NULL
;
577 newslot
->next
= NULL
;
579 slot
= active_queue_head
;
581 active_queue_head
= newslot
;
583 while (slot
->next
!= NULL
)
585 slot
->next
= newslot
;
590 if (slot
->curl
== NULL
) {
591 #ifdef NO_CURL_EASY_DUPHANDLE
592 slot
->curl
= get_curl_handle();
594 slot
->curl
= curl_easy_duphandle(curl_default
);
596 curl_session_count
++;
601 slot
->results
= NULL
;
602 slot
->finished
= NULL
;
603 slot
->callback_data
= NULL
;
604 slot
->callback_func
= NULL
;
605 curl_easy_setopt(slot
->curl
, CURLOPT_COOKIEFILE
, curl_cookie_file
);
606 if (curl_save_cookies
)
607 curl_easy_setopt(slot
->curl
, CURLOPT_COOKIEJAR
, curl_cookie_file
);
608 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, pragma_header
);
609 curl_easy_setopt(slot
->curl
, CURLOPT_ERRORBUFFER
, curl_errorstr
);
610 curl_easy_setopt(slot
->curl
, CURLOPT_CUSTOMREQUEST
, NULL
);
611 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, NULL
);
612 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, NULL
);
613 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, NULL
);
614 curl_easy_setopt(slot
->curl
, CURLOPT_UPLOAD
, 0);
615 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPGET
, 1);
616 curl_easy_setopt(slot
->curl
, CURLOPT_FAILONERROR
, 1);
617 #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
618 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPAUTH
, http_auth_methods
);
620 if (http_auth
.password
)
621 init_curl_http_auth(slot
->curl
);
626 int start_active_slot(struct active_request_slot
*slot
)
628 #ifdef USE_CURL_MULTI
629 CURLMcode curlm_result
= curl_multi_add_handle(curlm
, slot
->curl
);
632 if (curlm_result
!= CURLM_OK
&&
633 curlm_result
!= CURLM_CALL_MULTI_PERFORM
) {
640 * We know there must be something to do, since we just added
643 curl_multi_perform(curlm
, &num_transfers
);
648 #ifdef USE_CURL_MULTI
652 struct fill_chain
*next
;
655 static struct fill_chain
*fill_cfg
;
657 void add_fill_function(void *data
, int (*fill
)(void *))
659 struct fill_chain
*new = xmalloc(sizeof(*new));
660 struct fill_chain
**linkp
= &fill_cfg
;
665 linkp
= &(*linkp
)->next
;
669 void fill_active_slots(void)
671 struct active_request_slot
*slot
= active_queue_head
;
673 while (active_requests
< max_requests
) {
674 struct fill_chain
*fill
;
675 for (fill
= fill_cfg
; fill
; fill
= fill
->next
)
676 if (fill
->fill(fill
->data
))
683 while (slot
!= NULL
) {
684 if (!slot
->in_use
&& slot
->curl
!= NULL
685 && curl_session_count
> min_curl_sessions
) {
686 curl_easy_cleanup(slot
->curl
);
688 curl_session_count
--;
694 void step_active_slots(void)
697 CURLMcode curlm_result
;
700 curlm_result
= curl_multi_perform(curlm
, &num_transfers
);
701 } while (curlm_result
== CURLM_CALL_MULTI_PERFORM
);
702 if (num_transfers
< active_requests
) {
703 process_curl_messages();
709 void run_active_slot(struct active_request_slot
*slot
)
711 #ifdef USE_CURL_MULTI
716 struct timeval select_timeout
;
719 slot
->finished
= &finished
;
724 #if LIBCURL_VERSION_NUM >= 0x070f04
726 curl_multi_timeout(curlm
, &curl_timeout
);
727 if (curl_timeout
== 0) {
729 } else if (curl_timeout
== -1) {
730 select_timeout
.tv_sec
= 0;
731 select_timeout
.tv_usec
= 50000;
733 select_timeout
.tv_sec
= curl_timeout
/ 1000;
734 select_timeout
.tv_usec
= (curl_timeout
% 1000) * 1000;
737 select_timeout
.tv_sec
= 0;
738 select_timeout
.tv_usec
= 50000;
745 curl_multi_fdset(curlm
, &readfds
, &writefds
, &excfds
, &max_fd
);
748 * It can happen that curl_multi_timeout returns a pathologically
749 * long timeout when curl_multi_fdset returns no file descriptors
750 * to read. See commit message for more details.
753 (select_timeout
.tv_sec
> 0 ||
754 select_timeout
.tv_usec
> 50000)) {
755 select_timeout
.tv_sec
= 0;
756 select_timeout
.tv_usec
= 50000;
759 select(max_fd
+1, &readfds
, &writefds
, &excfds
, &select_timeout
);
763 while (slot
->in_use
) {
764 slot
->curl_result
= curl_easy_perform(slot
->curl
);
765 finish_active_slot(slot
);
770 static void release_active_slot(struct active_request_slot
*slot
)
772 closedown_active_slot(slot
);
773 if (slot
->curl
&& curl_session_count
> min_curl_sessions
) {
774 #ifdef USE_CURL_MULTI
775 curl_multi_remove_handle(curlm
, slot
->curl
);
777 curl_easy_cleanup(slot
->curl
);
779 curl_session_count
--;
781 #ifdef USE_CURL_MULTI
786 void finish_all_active_slots(void)
788 struct active_request_slot
*slot
= active_queue_head
;
792 run_active_slot(slot
);
793 slot
= active_queue_head
;
799 /* Helpers for modifying and creating URLs */
800 static inline int needs_quote(int ch
)
802 if (((ch
>= 'A') && (ch
<= 'Z'))
803 || ((ch
>= 'a') && (ch
<= 'z'))
804 || ((ch
>= '0') && (ch
<= '9'))
812 static char *quote_ref_url(const char *base
, const char *ref
)
814 struct strbuf buf
= STRBUF_INIT
;
818 end_url_with_slash(&buf
, base
);
820 for (cp
= ref
; (ch
= *cp
) != 0; cp
++)
822 strbuf_addf(&buf
, "%%%02x", ch
);
824 strbuf_addch(&buf
, *cp
);
826 return strbuf_detach(&buf
, NULL
);
829 void append_remote_object_url(struct strbuf
*buf
, const char *url
,
831 int only_two_digit_prefix
)
833 end_url_with_slash(buf
, url
);
835 strbuf_addf(buf
, "objects/%.*s/", 2, hex
);
836 if (!only_two_digit_prefix
)
837 strbuf_addf(buf
, "%s", hex
+2);
840 char *get_remote_object_url(const char *url
, const char *hex
,
841 int only_two_digit_prefix
)
843 struct strbuf buf
= STRBUF_INIT
;
844 append_remote_object_url(&buf
, url
, hex
, only_two_digit_prefix
);
845 return strbuf_detach(&buf
, NULL
);
848 static int handle_curl_result(struct slot_results
*results
)
851 * If we see a failing http code with CURLE_OK, we have turned off
852 * FAILONERROR (to keep the server's custom error response), and should
853 * translate the code into failure here.
855 if (results
->curl_result
== CURLE_OK
&&
856 results
->http_code
>= 400) {
857 results
->curl_result
= CURLE_HTTP_RETURNED_ERROR
;
859 * Normally curl will already have put the "reason phrase"
860 * from the server into curl_errorstr; unfortunately without
861 * FAILONERROR it is lost, so we can give only the numeric
864 snprintf(curl_errorstr
, sizeof(curl_errorstr
),
865 "The requested URL returned error: %ld",
869 if (results
->curl_result
== CURLE_OK
) {
870 credential_approve(&http_auth
);
872 } else if (missing_target(results
))
873 return HTTP_MISSING_TARGET
;
874 else if (results
->http_code
== 401) {
875 if (http_auth
.username
&& http_auth
.password
) {
876 credential_reject(&http_auth
);
879 #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
880 http_auth_methods
&= ~CURLAUTH_GSSNEGOTIATE
;
885 #if LIBCURL_VERSION_NUM >= 0x070c00
886 if (!curl_errorstr
[0])
887 strlcpy(curl_errorstr
,
888 curl_easy_strerror(results
->curl_result
),
889 sizeof(curl_errorstr
));
895 int run_one_slot(struct active_request_slot
*slot
,
896 struct slot_results
*results
)
898 slot
->results
= results
;
899 if (!start_active_slot(slot
)) {
900 snprintf(curl_errorstr
, sizeof(curl_errorstr
),
901 "failed to start HTTP request");
902 return HTTP_START_FAILED
;
905 run_active_slot(slot
);
906 return handle_curl_result(results
);
909 static CURLcode
curlinfo_strbuf(CURL
*curl
, CURLINFO info
, struct strbuf
*buf
)
915 ret
= curl_easy_getinfo(curl
, info
, &ptr
);
917 strbuf_addstr(buf
, ptr
);
922 * Check for and extract a content-type parameter. "raw"
923 * should be positioned at the start of the potential
924 * parameter, with any whitespace already removed.
926 * "name" is the name of the parameter. The value is appended
929 static int extract_param(const char *raw
, const char *name
,
932 size_t len
= strlen(name
);
934 if (strncasecmp(raw
, name
, len
))
942 while (*raw
&& !isspace(*raw
) && *raw
!= ';')
943 strbuf_addch(out
, *raw
++);
948 * Extract a normalized version of the content type, with any
949 * spaces suppressed, all letters lowercased, and no trailing ";"
952 * Note that we will silently remove even invalid whitespace. For
953 * example, "text / plain" is specifically forbidden by RFC 2616,
954 * but "text/plain" is the only reasonable output, and this keeps
957 * If the "charset" argument is not NULL, store the value of any
958 * charset parameter there.
961 * "TEXT/PLAIN; charset=utf-8" -> "text/plain", "utf-8"
962 * "text / plain" -> "text/plain"
964 static void extract_content_type(struct strbuf
*raw
, struct strbuf
*type
,
965 struct strbuf
*charset
)
970 strbuf_grow(type
, raw
->len
);
971 for (p
= raw
->buf
; *p
; p
++) {
978 strbuf_addch(type
, tolower(*p
));
984 strbuf_reset(charset
);
986 while (isspace(*p
) || *p
== ';')
988 if (!extract_param(p
, "charset", charset
))
990 while (*p
&& !isspace(*p
))
994 if (!charset
->len
&& starts_with(type
->buf
, "text/"))
995 strbuf_addstr(charset
, "ISO-8859-1");
999 /* http_request() targets */
1000 #define HTTP_REQUEST_STRBUF 0
1001 #define HTTP_REQUEST_FILE 1
1003 static int http_request(const char *url
,
1004 void *result
, int target
,
1005 const struct http_get_options
*options
)
1007 struct active_request_slot
*slot
;
1008 struct slot_results results
;
1009 struct curl_slist
*headers
= NULL
;
1010 struct strbuf buf
= STRBUF_INIT
;
1013 slot
= get_active_slot();
1014 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPGET
, 1);
1016 if (result
== NULL
) {
1017 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 1);
1019 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
1020 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, result
);
1022 if (target
== HTTP_REQUEST_FILE
) {
1023 long posn
= ftell(result
);
1024 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
,
1027 strbuf_addf(&buf
, "Range: bytes=%ld-", posn
);
1028 headers
= curl_slist_append(headers
, buf
.buf
);
1032 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
,
1036 strbuf_addstr(&buf
, "Pragma:");
1037 if (options
&& options
->no_cache
)
1038 strbuf_addstr(&buf
, " no-cache");
1039 if (options
&& options
->keep_error
)
1040 curl_easy_setopt(slot
->curl
, CURLOPT_FAILONERROR
, 0);
1042 headers
= curl_slist_append(headers
, buf
.buf
);
1044 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, url
);
1045 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
1046 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
1048 ret
= run_one_slot(slot
, &results
);
1050 if (options
&& options
->content_type
) {
1051 struct strbuf raw
= STRBUF_INIT
;
1052 curlinfo_strbuf(slot
->curl
, CURLINFO_CONTENT_TYPE
, &raw
);
1053 extract_content_type(&raw
, options
->content_type
,
1055 strbuf_release(&raw
);
1058 if (options
&& options
->effective_url
)
1059 curlinfo_strbuf(slot
->curl
, CURLINFO_EFFECTIVE_URL
,
1060 options
->effective_url
);
1062 curl_slist_free_all(headers
);
1063 strbuf_release(&buf
);
1069 * Update the "base" url to a more appropriate value, as deduced by
1070 * redirects seen when requesting a URL starting with "url".
1072 * The "asked" parameter is a URL that we asked curl to access, and must begin
1075 * The "got" parameter is the URL that curl reported to us as where we ended
1078 * Returns 1 if we updated the base url, 0 otherwise.
1080 * Our basic strategy is to compare "base" and "asked" to find the bits
1081 * specific to our request. We then strip those bits off of "got" to yield the
1082 * new base. So for example, if our base is "http://example.com/foo.git",
1083 * and we ask for "http://example.com/foo.git/info/refs", we might end up
1084 * with "https://other.example.com/foo.git/info/refs". We would want the
1085 * new URL to become "https://other.example.com/foo.git".
1087 * Note that this assumes a sane redirect scheme. It's entirely possible
1088 * in the example above to end up at a URL that does not even end in
1089 * "info/refs". In such a case we simply punt, as there is not much we can
1090 * do (and such a scheme is unlikely to represent a real git repository,
1091 * which means we are likely about to abort anyway).
1093 static int update_url_from_redirect(struct strbuf
*base
,
1095 const struct strbuf
*got
)
1100 if (!strcmp(asked
, got
->buf
))
1103 if (!skip_prefix(asked
, base
->buf
, &tail
))
1104 die("BUG: update_url_from_redirect: %s is not a superset of %s",
1107 tail_len
= strlen(tail
);
1109 if (got
->len
< tail_len
||
1110 strcmp(tail
, got
->buf
+ got
->len
- tail_len
))
1111 return 0; /* insane redirect scheme */
1114 strbuf_add(base
, got
->buf
, got
->len
- tail_len
);
1118 static int http_request_reauth(const char *url
,
1119 void *result
, int target
,
1120 struct http_get_options
*options
)
1122 int ret
= http_request(url
, result
, target
, options
);
1124 if (options
&& options
->effective_url
&& options
->base_url
) {
1125 if (update_url_from_redirect(options
->base_url
,
1126 url
, options
->effective_url
)) {
1127 credential_from_url(&http_auth
, options
->base_url
->buf
);
1128 url
= options
->effective_url
->buf
;
1132 if (ret
!= HTTP_REAUTH
)
1136 * If we are using KEEP_ERROR, the previous request may have
1137 * put cruft into our output stream; we should clear it out before
1138 * making our next request. We only know how to do this for
1139 * the strbuf case, but that is enough to satisfy current callers.
1141 if (options
&& options
->keep_error
) {
1143 case HTTP_REQUEST_STRBUF
:
1144 strbuf_reset(result
);
1147 die("BUG: HTTP_KEEP_ERROR is only supported with strbufs");
1151 credential_fill(&http_auth
);
1153 return http_request(url
, result
, target
, options
);
1156 int http_get_strbuf(const char *url
,
1157 struct strbuf
*result
,
1158 struct http_get_options
*options
)
1160 return http_request_reauth(url
, result
, HTTP_REQUEST_STRBUF
, options
);
1164 * Downloads a URL and stores the result in the given file.
1166 * If a previous interrupted download is detected (i.e. a previous temporary
1167 * file is still around) the download is resumed.
1169 static int http_get_file(const char *url
, const char *filename
,
1170 struct http_get_options
*options
)
1173 struct strbuf tmpfile
= STRBUF_INIT
;
1176 strbuf_addf(&tmpfile
, "%s.temp", filename
);
1177 result
= fopen(tmpfile
.buf
, "a");
1179 error("Unable to open local file %s", tmpfile
.buf
);
1184 ret
= http_request_reauth(url
, result
, HTTP_REQUEST_FILE
, options
);
1187 if (ret
== HTTP_OK
&& move_temp_to_file(tmpfile
.buf
, filename
))
1190 strbuf_release(&tmpfile
);
1194 int http_fetch_ref(const char *base
, struct ref
*ref
)
1196 struct http_get_options options
= {0};
1198 struct strbuf buffer
= STRBUF_INIT
;
1201 options
.no_cache
= 1;
1203 url
= quote_ref_url(base
, ref
->name
);
1204 if (http_get_strbuf(url
, &buffer
, &options
) == HTTP_OK
) {
1205 strbuf_rtrim(&buffer
);
1206 if (buffer
.len
== 40)
1207 ret
= get_sha1_hex(buffer
.buf
, ref
->old_sha1
);
1208 else if (starts_with(buffer
.buf
, "ref: ")) {
1209 ref
->symref
= xstrdup(buffer
.buf
+ 5);
1214 strbuf_release(&buffer
);
1219 /* Helpers for fetching packs */
1220 static char *fetch_pack_index(unsigned char *sha1
, const char *base_url
)
1223 struct strbuf buf
= STRBUF_INIT
;
1225 if (http_is_verbose
)
1226 fprintf(stderr
, "Getting index for pack %s\n", sha1_to_hex(sha1
));
1228 end_url_with_slash(&buf
, base_url
);
1229 strbuf_addf(&buf
, "objects/pack/pack-%s.idx", sha1_to_hex(sha1
));
1230 url
= strbuf_detach(&buf
, NULL
);
1232 strbuf_addf(&buf
, "%s.temp", sha1_pack_index_name(sha1
));
1233 tmp
= strbuf_detach(&buf
, NULL
);
1235 if (http_get_file(url
, tmp
, NULL
) != HTTP_OK
) {
1236 error("Unable to get pack index %s", url
);
1245 static int fetch_and_setup_pack_index(struct packed_git
**packs_head
,
1246 unsigned char *sha1
, const char *base_url
)
1248 struct packed_git
*new_pack
;
1249 char *tmp_idx
= NULL
;
1252 if (has_pack_index(sha1
)) {
1253 new_pack
= parse_pack_index(sha1
, sha1_pack_index_name(sha1
));
1255 return -1; /* parse_pack_index() already issued error message */
1259 tmp_idx
= fetch_pack_index(sha1
, base_url
);
1263 new_pack
= parse_pack_index(sha1
, tmp_idx
);
1268 return -1; /* parse_pack_index() already issued error message */
1271 ret
= verify_pack_index(new_pack
);
1273 close_pack_index(new_pack
);
1274 ret
= move_temp_to_file(tmp_idx
, sha1_pack_index_name(sha1
));
1281 new_pack
->next
= *packs_head
;
1282 *packs_head
= new_pack
;
1286 int http_get_info_packs(const char *base_url
, struct packed_git
**packs_head
)
1288 struct http_get_options options
= {0};
1291 struct strbuf buf
= STRBUF_INIT
;
1292 unsigned char sha1
[20];
1294 end_url_with_slash(&buf
, base_url
);
1295 strbuf_addstr(&buf
, "objects/info/packs");
1296 url
= strbuf_detach(&buf
, NULL
);
1298 options
.no_cache
= 1;
1299 ret
= http_get_strbuf(url
, &buf
, &options
);
1304 while (i
< buf
.len
) {
1308 if (i
+ 52 <= buf
.len
&&
1309 starts_with(data
+ i
, " pack-") &&
1310 starts_with(data
+ i
+ 46, ".pack\n")) {
1311 get_sha1_hex(data
+ i
+ 6, sha1
);
1312 fetch_and_setup_pack_index(packs_head
, sha1
,
1318 while (i
< buf
.len
&& data
[i
] != '\n')
1329 void release_http_pack_request(struct http_pack_request
*preq
)
1331 if (preq
->packfile
!= NULL
) {
1332 fclose(preq
->packfile
);
1333 preq
->packfile
= NULL
;
1335 if (preq
->range_header
!= NULL
) {
1336 curl_slist_free_all(preq
->range_header
);
1337 preq
->range_header
= NULL
;
1343 int finish_http_pack_request(struct http_pack_request
*preq
)
1345 struct packed_git
**lst
;
1346 struct packed_git
*p
= preq
->target
;
1348 struct child_process ip
= CHILD_PROCESS_INIT
;
1349 const char *ip_argv
[8];
1351 close_pack_index(p
);
1353 fclose(preq
->packfile
);
1354 preq
->packfile
= NULL
;
1358 lst
= &((*lst
)->next
);
1359 *lst
= (*lst
)->next
;
1361 tmp_idx
= xstrdup(preq
->tmpfile
);
1362 strcpy(tmp_idx
+ strlen(tmp_idx
) - strlen(".pack.temp"),
1365 ip_argv
[0] = "index-pack";
1367 ip_argv
[2] = tmp_idx
;
1368 ip_argv
[3] = preq
->tmpfile
;
1376 if (run_command(&ip
)) {
1377 unlink(preq
->tmpfile
);
1383 unlink(sha1_pack_index_name(p
->sha1
));
1385 if (move_temp_to_file(preq
->tmpfile
, sha1_pack_name(p
->sha1
))
1386 || move_temp_to_file(tmp_idx
, sha1_pack_index_name(p
->sha1
))) {
1391 install_packed_git(p
);
1396 struct http_pack_request
*new_http_pack_request(
1397 struct packed_git
*target
, const char *base_url
)
1400 char range
[RANGE_HEADER_SIZE
];
1401 struct strbuf buf
= STRBUF_INIT
;
1402 struct http_pack_request
*preq
;
1404 preq
= xcalloc(1, sizeof(*preq
));
1405 preq
->target
= target
;
1407 end_url_with_slash(&buf
, base_url
);
1408 strbuf_addf(&buf
, "objects/pack/pack-%s.pack",
1409 sha1_to_hex(target
->sha1
));
1410 preq
->url
= strbuf_detach(&buf
, NULL
);
1412 snprintf(preq
->tmpfile
, sizeof(preq
->tmpfile
), "%s.temp",
1413 sha1_pack_name(target
->sha1
));
1414 preq
->packfile
= fopen(preq
->tmpfile
, "a");
1415 if (!preq
->packfile
) {
1416 error("Unable to open local file %s for pack",
1421 preq
->slot
= get_active_slot();
1422 curl_easy_setopt(preq
->slot
->curl
, CURLOPT_FILE
, preq
->packfile
);
1423 curl_easy_setopt(preq
->slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite
);
1424 curl_easy_setopt(preq
->slot
->curl
, CURLOPT_URL
, preq
->url
);
1425 curl_easy_setopt(preq
->slot
->curl
, CURLOPT_HTTPHEADER
,
1429 * If there is data present from a previous transfer attempt,
1430 * resume where it left off
1432 prev_posn
= ftell(preq
->packfile
);
1434 if (http_is_verbose
)
1436 "Resuming fetch of pack %s at byte %ld\n",
1437 sha1_to_hex(target
->sha1
), prev_posn
);
1438 sprintf(range
, "Range: bytes=%ld-", prev_posn
);
1439 preq
->range_header
= curl_slist_append(NULL
, range
);
1440 curl_easy_setopt(preq
->slot
->curl
, CURLOPT_HTTPHEADER
,
1441 preq
->range_header
);
1452 /* Helpers for fetching objects (loose) */
1453 static size_t fwrite_sha1_file(char *ptr
, size_t eltsize
, size_t nmemb
,
1456 unsigned char expn
[4096];
1457 size_t size
= eltsize
* nmemb
;
1459 struct http_object_request
*freq
=
1460 (struct http_object_request
*)data
;
1462 ssize_t retval
= xwrite(freq
->localfile
,
1463 (char *) ptr
+ posn
, size
- posn
);
1467 } while (posn
< size
);
1469 freq
->stream
.avail_in
= size
;
1470 freq
->stream
.next_in
= (void *)ptr
;
1472 freq
->stream
.next_out
= expn
;
1473 freq
->stream
.avail_out
= sizeof(expn
);
1474 freq
->zret
= git_inflate(&freq
->stream
, Z_SYNC_FLUSH
);
1475 git_SHA1_Update(&freq
->c
, expn
,
1476 sizeof(expn
) - freq
->stream
.avail_out
);
1477 } while (freq
->stream
.avail_in
&& freq
->zret
== Z_OK
);
1481 struct http_object_request
*new_http_object_request(const char *base_url
,
1482 unsigned char *sha1
)
1484 char *hex
= sha1_to_hex(sha1
);
1485 const char *filename
;
1486 char prevfile
[PATH_MAX
];
1488 char prev_buf
[PREV_BUF_SIZE
];
1489 ssize_t prev_read
= 0;
1491 char range
[RANGE_HEADER_SIZE
];
1492 struct curl_slist
*range_header
= NULL
;
1493 struct http_object_request
*freq
;
1495 freq
= xcalloc(1, sizeof(*freq
));
1496 hashcpy(freq
->sha1
, sha1
);
1497 freq
->localfile
= -1;
1499 filename
= sha1_file_name(sha1
);
1500 snprintf(freq
->tmpfile
, sizeof(freq
->tmpfile
),
1501 "%s.temp", filename
);
1503 snprintf(prevfile
, sizeof(prevfile
), "%s.prev", filename
);
1504 unlink_or_warn(prevfile
);
1505 rename(freq
->tmpfile
, prevfile
);
1506 unlink_or_warn(freq
->tmpfile
);
1508 if (freq
->localfile
!= -1)
1509 error("fd leakage in start: %d", freq
->localfile
);
1510 freq
->localfile
= open(freq
->tmpfile
,
1511 O_WRONLY
| O_CREAT
| O_EXCL
, 0666);
1513 * This could have failed due to the "lazy directory creation";
1514 * try to mkdir the last path component.
1516 if (freq
->localfile
< 0 && errno
== ENOENT
) {
1517 char *dir
= strrchr(freq
->tmpfile
, '/');
1520 mkdir(freq
->tmpfile
, 0777);
1523 freq
->localfile
= open(freq
->tmpfile
,
1524 O_WRONLY
| O_CREAT
| O_EXCL
, 0666);
1527 if (freq
->localfile
< 0) {
1528 error("Couldn't create temporary file %s: %s",
1529 freq
->tmpfile
, strerror(errno
));
1533 git_inflate_init(&freq
->stream
);
1535 git_SHA1_Init(&freq
->c
);
1537 freq
->url
= get_remote_object_url(base_url
, hex
, 0);
1540 * If a previous temp file is present, process what was already
1543 prevlocal
= open(prevfile
, O_RDONLY
);
1544 if (prevlocal
!= -1) {
1546 prev_read
= xread(prevlocal
, prev_buf
, PREV_BUF_SIZE
);
1548 if (fwrite_sha1_file(prev_buf
,
1551 freq
) == prev_read
) {
1552 prev_posn
+= prev_read
;
1557 } while (prev_read
> 0);
1560 unlink_or_warn(prevfile
);
1563 * Reset inflate/SHA1 if there was an error reading the previous temp
1564 * file; also rewind to the beginning of the local file.
1566 if (prev_read
== -1) {
1567 memset(&freq
->stream
, 0, sizeof(freq
->stream
));
1568 git_inflate_init(&freq
->stream
);
1569 git_SHA1_Init(&freq
->c
);
1572 lseek(freq
->localfile
, 0, SEEK_SET
);
1573 if (ftruncate(freq
->localfile
, 0) < 0) {
1574 error("Couldn't truncate temporary file %s: %s",
1575 freq
->tmpfile
, strerror(errno
));
1581 freq
->slot
= get_active_slot();
1583 curl_easy_setopt(freq
->slot
->curl
, CURLOPT_FILE
, freq
);
1584 curl_easy_setopt(freq
->slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_sha1_file
);
1585 curl_easy_setopt(freq
->slot
->curl
, CURLOPT_ERRORBUFFER
, freq
->errorstr
);
1586 curl_easy_setopt(freq
->slot
->curl
, CURLOPT_URL
, freq
->url
);
1587 curl_easy_setopt(freq
->slot
->curl
, CURLOPT_HTTPHEADER
, no_pragma_header
);
1590 * If we have successfully processed data from a previous fetch
1591 * attempt, only fetch the data we don't already have.
1594 if (http_is_verbose
)
1596 "Resuming fetch of object %s at byte %ld\n",
1598 sprintf(range
, "Range: bytes=%ld-", prev_posn
);
1599 range_header
= curl_slist_append(range_header
, range
);
1600 curl_easy_setopt(freq
->slot
->curl
,
1601 CURLOPT_HTTPHEADER
, range_header
);
1612 void process_http_object_request(struct http_object_request
*freq
)
1614 if (freq
->slot
== NULL
)
1616 freq
->curl_result
= freq
->slot
->curl_result
;
1617 freq
->http_code
= freq
->slot
->http_code
;
1621 int finish_http_object_request(struct http_object_request
*freq
)
1625 close(freq
->localfile
);
1626 freq
->localfile
= -1;
1628 process_http_object_request(freq
);
1630 if (freq
->http_code
== 416) {
1631 warning("requested range invalid; we may already have all the data.");
1632 } else if (freq
->curl_result
!= CURLE_OK
) {
1633 if (stat(freq
->tmpfile
, &st
) == 0)
1634 if (st
.st_size
== 0)
1635 unlink_or_warn(freq
->tmpfile
);
1639 git_inflate_end(&freq
->stream
);
1640 git_SHA1_Final(freq
->real_sha1
, &freq
->c
);
1641 if (freq
->zret
!= Z_STREAM_END
) {
1642 unlink_or_warn(freq
->tmpfile
);
1645 if (hashcmp(freq
->sha1
, freq
->real_sha1
)) {
1646 unlink_or_warn(freq
->tmpfile
);
1650 move_temp_to_file(freq
->tmpfile
, sha1_file_name(freq
->sha1
));
1652 return freq
->rename
;
1655 void abort_http_object_request(struct http_object_request
*freq
)
1657 unlink_or_warn(freq
->tmpfile
);
1659 release_http_object_request(freq
);
1662 void release_http_object_request(struct http_object_request
*freq
)
1664 if (freq
->localfile
!= -1) {
1665 close(freq
->localfile
);
1666 freq
->localfile
= -1;
1668 if (freq
->url
!= NULL
) {
1672 if (freq
->slot
!= NULL
) {
1673 freq
->slot
->callback_func
= NULL
;
1674 freq
->slot
->callback_data
= NULL
;
1675 release_active_slot(freq
->slot
);