]> git.ipfire.org Git - thirdparty/git.git/blobdiff - http.c
Merge branch 'ml/cvsserver'
[thirdparty/git.git] / http.c
diff --git a/http.c b/http.c
index 470b56eab5adad69e866a243fd1bb4dc83d0baab..14a7669cd427e101985d4acf8f3da3314937eeaa 100644 (file)
--- a/http.c
+++ b/http.c
@@ -160,6 +160,44 @@ static int http_options(const char *var, const char *value)
        return git_default_config(var, value);
 }
 
+static CURL* get_curl_handle(void)
+{
+       CURL* result = curl_easy_init();
+
+       curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
+#if LIBCURL_VERSION_NUM >= 0x070907
+       curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
+#endif
+
+       if (ssl_cert != NULL)
+               curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
+#if LIBCURL_VERSION_NUM >= 0x070902
+       if (ssl_key != NULL)
+               curl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);
+#endif
+#if LIBCURL_VERSION_NUM >= 0x070908
+       if (ssl_capath != NULL)
+               curl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);
+#endif
+       if (ssl_cainfo != NULL)
+               curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
+       curl_easy_setopt(result, CURLOPT_FAILONERROR, 1);
+
+       if (curl_low_speed_limit > 0 && curl_low_speed_time > 0) {
+               curl_easy_setopt(result, CURLOPT_LOW_SPEED_LIMIT,
+                                curl_low_speed_limit);
+               curl_easy_setopt(result, CURLOPT_LOW_SPEED_TIME,
+                                curl_low_speed_time);
+       }
+
+       curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
+
+       if (getenv("GIT_CURL_VERBOSE"))
+               curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
+
+       return result;
+}
+
 void http_init(void)
 {
        char *low_speed_limit;
@@ -223,7 +261,6 @@ void http_cleanup(void)
        struct active_request_slot *slot = active_queue_head;
 #ifdef USE_CURL_MULTI
        char *wait_url;
-       CURLMcode curlm_result;
 #endif
 
        while (slot != NULL) {
@@ -252,41 +289,6 @@ void http_cleanup(void)
        
 }
 
-static CURL* get_curl_handle(void)
-{
-       CURL* result = curl_easy_init();
-
-       curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
-#if LIBCURL_VERSION_NUM >= 0x070907
-       curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
-#endif
-
-       if (ssl_cert != NULL)
-               curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
-#if LIBCURL_VERSION_NUM >= 0x070902
-       if (ssl_key != NULL)
-               curl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);
-#endif
-#if LIBCURL_VERSION_NUM >= 0x070908
-       if (ssl_capath != NULL)
-               curl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);
-#endif
-       if (ssl_cainfo != NULL)
-               curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
-       curl_easy_setopt(result, CURLOPT_FAILONERROR, 1);
-
-       if (curl_low_speed_limit > 0 && curl_low_speed_time > 0) {
-               curl_easy_setopt(result, CURLOPT_LOW_SPEED_LIMIT,
-                                curl_low_speed_limit);
-               curl_easy_setopt(result, CURLOPT_LOW_SPEED_TIME,
-                                curl_low_speed_time);
-       }
-
-       curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
-
-       return result;
-}
-
 struct active_request_slot *get_active_slot(void)
 {
        struct active_request_slot *slot = active_queue_head;
@@ -336,6 +338,7 @@ struct active_request_slot *get_active_slot(void)
        active_requests++;
        slot->in_use = 1;
        slot->local = NULL;
+       slot->results = NULL;
        slot->callback_data = NULL;
        slot->callback_func = NULL;
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
@@ -417,12 +420,34 @@ void run_active_slot(struct active_request_slot *slot)
 #endif
 }
 
-static void finish_active_slot(struct active_request_slot *slot)
+static void closedown_active_slot(struct active_request_slot *slot)
 {
         active_requests--;
         slot->in_use = 0;
+}
+
+void release_active_slot(struct active_request_slot *slot)
+{
+       closedown_active_slot(slot);
+       if (slot->curl) {
+               curl_multi_remove_handle(curlm, slot->curl);
+               curl_easy_cleanup(slot->curl);
+               slot->curl = NULL;
+       }
+       fill_active_slots();
+}
+
+static void finish_active_slot(struct active_request_slot *slot)
+{
+       closedown_active_slot(slot);
         curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
+
+       /* Store slot results so they can be read after the slot is reused */
+       if (slot->results != NULL) {
+               slot->results->curl_result = slot->curl_result;
+               slot->results->http_code = slot->http_code;
+       }
+
         /* Run callback if appropriate */
         if (slot->callback_func != NULL) {
                 slot->callback_func(slot->callback_data);