@matheusbsbs / matheus-bagliano / commits / 7baa3e8694
Fork 0

Some curl versions lack curl_easy_duphandle()

Hi, On Fri, 14 Oct 2005, Junio C Hamano wrote: > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > > > This patch looks bigger than it really is: The code to get the > > default handle was refactored into a function, and is called > > instead of curl_easy_duphandle() if that does not exist. > > I'd like to take Nick's config file patch first, which > unfortunately interferes with your patch. I'd hate to ask you > this, but could you rebase it on top of Nick's patch, [...] No need to hate it. Here comes the rebased patch, and this time, I actually tested it a bit. Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Oct 15, 2005 at 11:10 UTC 7baa3e8694d823ce9731172c700bf0d780ae283e
1 file changed +44 -16
http-fetch.c
+44 -16
@@ -18,6 +18,10 @@
18 #define curl_global_init(a) do { /* nothing */ } while(0)
19 #endif
20
21 +#if LIBCURL_VERSION_NUM < 0x070c04
22 +#define NO_CURL_EASY_DUPHANDLE
23 +#endif
24 +
25 #define PREV_BUF_SIZE 4096
26 #define RANGE_HEADER_SIZE 30
27
@@ -28,7 +32,9 @@ static int data_received;
32 static int max_requests = -1;
33 static CURLM *curlm;
34 #endif
35 +#ifndef NO_CURL_EASY_DUPHANDLE
36 static CURL *curl_default;
37 +#endif
38 static struct curl_slist *pragma_header;
39 static struct curl_slist *no_pragma_header;
40 static struct curl_slist *no_range_header;
@@ -87,8 +93,12 @@ static struct active_request_slot *active_queue_head = NULL;
93
94 static int curl_ssl_verify = -1;
95 static char *ssl_cert = NULL;
96 +#if LIBCURL_VERSION_NUM >= 0x070902
97 static char *ssl_key = NULL;
98 +#endif
99 +#if LIBCURL_VERSION_NUM >= 0x070908
100 static char *ssl_capath = NULL;
101 +#endif
102 static char *ssl_cainfo = NULL;
103
104 struct buffer
@@ -213,6 +223,32 @@ void process_curl_messages();
223 void process_request_queue();
224 #endif
225
226 +static CURL* get_curl_handle()
227 +{
228 + CURL* result = curl_easy_init();
229 +
230 + curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
231 +#if LIBCURL_VERSION_NUM >= 0x070907
232 + curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
233 +#endif
234 +
235 + if (ssl_cert != NULL)
236 + curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
237 +#if LIBCURL_VERSION_NUM >= 0x070902
238 + if (ssl_key != NULL)
239 + curl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);
240 +#endif
241 +#if LIBCURL_VERSION_NUM >= 0x070908
242 + if (ssl_capath != NULL)
243 + curl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);
244 +#endif
245 + if (ssl_cainfo != NULL)
246 + curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
247 + curl_easy_setopt(result, CURLOPT_FAILONERROR, 1);
248 +
249 + return result;
250 +}
251 +
252 struct active_request_slot *get_active_slot()
253 {
254 struct active_request_slot *slot = active_queue_head;
@@ -235,7 +271,11 @@ struct active_request_slot *get_active_slot()
271 }
272 if (slot == NULL) {
273 newslot = xmalloc(sizeof(*newslot));
274 +#ifdef NO_CURL_EASY_DUPHANDLE
275 + newslot->curl = get_curl_handle();
276 +#else
277 newslot->curl = curl_easy_duphandle(curl_default);
278 +#endif
279 newslot->in_use = 0;
280 newslot->next = NULL;
281
@@ -1202,24 +1242,10 @@ int main(int argc, char **argv)
1242 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
1243 no_range_header = curl_slist_append(no_range_header, "Range:");
1244
1205 - curl_default = curl_easy_init();
1206 -
1207 - curl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
1208 -#if LIBCURL_VERSION_NUM >= 0x070907
1209 - curl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
1245 +#ifndef NO_CURL_EASY_DUPHANDLE
1246 + curl_default = get_curl_handle();
1247 #endif
1248
1212 - if (ssl_cert != NULL)
1213 - curl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);
1214 - if (ssl_key != NULL)
1215 - curl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);
1216 - if (ssl_capath != NULL)
1217 - curl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);
1218 - if (ssl_cainfo != NULL)
1219 - curl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);
1220 -
1221 - curl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);
1222 -
1249 alt = xmalloc(sizeof(*alt));
1250 alt->base = url;
1251 alt->got_indices = 0;
@@ -1233,7 +1259,9 @@ int main(int argc, char **argv)
1259 curl_slist_free_all(pragma_header);
1260 curl_slist_free_all(no_pragma_header);
1261 curl_slist_free_all(no_range_header);
1262 +#ifndef NO_CURL_EASY_DUPHANDLE
1263 curl_easy_cleanup(curl_default);
1264 +#endif
1265 slot = active_queue_head;
1266 while (slot != NULL) {
1267 curl_easy_cleanup(slot->curl);