Skip to content

Commit 7baa3e8

Browse files
dschoJunio C Hamano
authored andcommitted
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>
1 parent 4546738 commit 7baa3e8

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

http-fetch.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#define curl_global_init(a) do { /* nothing */ } while(0)
1919
#endif
2020

21+
#if LIBCURL_VERSION_NUM < 0x070c04
22+
#define NO_CURL_EASY_DUPHANDLE
23+
#endif
24+
2125
#define PREV_BUF_SIZE 4096
2226
#define RANGE_HEADER_SIZE 30
2327

@@ -28,7 +32,9 @@ static int data_received;
2832
static int max_requests = -1;
2933
static CURLM *curlm;
3034
#endif
35+
#ifndef NO_CURL_EASY_DUPHANDLE
3136
static CURL *curl_default;
37+
#endif
3238
static struct curl_slist *pragma_header;
3339
static struct curl_slist *no_pragma_header;
3440
static struct curl_slist *no_range_header;
@@ -87,8 +93,12 @@ static struct active_request_slot *active_queue_head = NULL;
8793

8894
static int curl_ssl_verify = -1;
8995
static char *ssl_cert = NULL;
96+
#if LIBCURL_VERSION_NUM >= 0x070902
9097
static char *ssl_key = NULL;
98+
#endif
99+
#if LIBCURL_VERSION_NUM >= 0x070908
91100
static char *ssl_capath = NULL;
101+
#endif
92102
static char *ssl_cainfo = NULL;
93103

94104
struct buffer
@@ -213,6 +223,32 @@ void process_curl_messages();
213223
void process_request_queue();
214224
#endif
215225

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+
216252
struct active_request_slot *get_active_slot()
217253
{
218254
struct active_request_slot *slot = active_queue_head;
@@ -235,7 +271,11 @@ struct active_request_slot *get_active_slot()
235271
}
236272
if (slot == NULL) {
237273
newslot = xmalloc(sizeof(*newslot));
274+
#ifdef NO_CURL_EASY_DUPHANDLE
275+
newslot->curl = get_curl_handle();
276+
#else
238277
newslot->curl = curl_easy_duphandle(curl_default);
278+
#endif
239279
newslot->in_use = 0;
240280
newslot->next = NULL;
241281

@@ -1202,24 +1242,10 @@ int main(int argc, char **argv)
12021242
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
12031243
no_range_header = curl_slist_append(no_range_header, "Range:");
12041244

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();
12101247
#endif
12111248

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-
12231249
alt = xmalloc(sizeof(*alt));
12241250
alt->base = url;
12251251
alt->got_indices = 0;
@@ -1233,7 +1259,9 @@ int main(int argc, char **argv)
12331259
curl_slist_free_all(pragma_header);
12341260
curl_slist_free_all(no_pragma_header);
12351261
curl_slist_free_all(no_range_header);
1262+
#ifndef NO_CURL_EASY_DUPHANDLE
12361263
curl_easy_cleanup(curl_default);
1264+
#endif
12371265
slot = active_queue_head;
12381266
while (slot != NULL) {
12391267
curl_easy_cleanup(slot->curl);

0 commit comments

Comments
 (0)