{"thread":{"id":"2111","subject":"[PATCH] Some curl versions lack curl_easy_duphandle()","startedAt":"2005-10-14T22:39:17Z","lastAt":"2005-10-17T18:54:08Z","messageCount":7,"participants":["Johannes Schindelin","Junio C Hamano","Nick Hengeveld"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10116","messageId":"Pine.LNX.4.63.0510150038550.2807@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2111","inReplyTo":null,"subject":"[PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-14T22:39:17Z","receivedAt":"2005-10-14T22:39:17Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"This patch looks bigger than it really is: The code to get the default handle\nwas refactored into a function, and is called instead of curl_easy_duphandle()\nif that does not exist.\n\nTested once.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n http-fetch.c |   73 +++++++++++++++++++++++++++++++++++++++-------------------\n 1 files changed, 49 insertions(+), 24 deletions(-)\n\napplies-to: 63f8082177fa17ae2aadd5ab417758f3d53456d8\n1d9c990c46e306b6310fda8ff94bca2feccfbd99\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 0aba891..5f1f7f9 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -18,6 +18,10 @@\n #define curl_global_init(a) do { /* nothing */ } while(0)\n #endif\n \n+#if LIBCURL_VERSION_NUM < 0x070c04\n+#define NO_CURL_EASY_DUPHANDLE\n+#endif\n+\n #define PREV_BUF_SIZE 4096\n #define RANGE_HEADER_SIZE 30\n \n@@ -28,7 +32,9 @@ static int data_received;\n static int max_requests = DEFAULT_MAX_REQUESTS;\n static CURLM *curlm;\n #endif\n+#ifndef NO_CURL_EASY_DUPHANDLE\n static CURL *curl_default;\n+#endif\n static struct curl_slist *pragma_header;\n static struct curl_slist *no_pragma_header;\n static struct curl_slist *no_range_header;\n@@ -87,8 +93,12 @@ static struct active_request_slot *activ\n \n static int curl_ssl_verify;\n static char *ssl_cert;\n+#if LIBCURL_VERSION_NUM >= 0x070902\n static char *ssl_key;\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n static char *ssl_capath;\n+#endif\n static char *ssl_cainfo;\n \n struct buffer\n@@ -143,6 +153,37 @@ void process_curl_messages();\n void process_request_queue();\n #endif\n \n+CURL* get_curl_handle()\n+{\n+\tCURL* result = curl_easy_init();\n+\n+\tcurl_ssl_verify = getenv(\"GIT_SSL_NO_VERIFY\") ? 0 : 1;\n+\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);\n+#if LIBCURL_VERSION_NUM >= 0x070907\n+\tcurl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);\n+#endif\n+\n+\tif ((ssl_cert = getenv(\"GIT_SSL_CERT\")) != NULL) {\n+\t\tcurl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);\n+\t}\n+#if LIBCURL_VERSION_NUM >= 0x070902\n+\tif ((ssl_key = getenv(\"GIT_SSL_KEY\")) != NULL) {\n+\t\tcurl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);\n+\t}\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n+\tif ((ssl_capath = getenv(\"GIT_SSL_CAPATH\")) != NULL) {\n+\t\tcurl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);\n+\t}\n+#endif\n+\tif ((ssl_cainfo = getenv(\"GIT_SSL_CAINFO\")) != NULL) {\n+\t\tcurl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);\n+\t}\n+\tcurl_easy_setopt(result, CURLOPT_FAILONERROR, 1);\n+\n+\treturn result;\n+}\n+\n struct active_request_slot *get_active_slot()\n {\n \tstruct active_request_slot *slot = active_queue_head;\n@@ -165,7 +206,11 @@ struct active_request_slot *get_active_s\n \t}\n \tif (slot == NULL) {\n \t\tnewslot = xmalloc(sizeof(*newslot));\n+#ifdef NO_CURL_EASY_DUPHANDLE\n+\t\tnewslot->curl = get_curl_handle();\n+#else\n \t\tnewslot->curl = curl_easy_duphandle(curl_default);\n+#endif\n \t\tnewslot->in_use = 0;\n \t\tnewslot->next = NULL;\n \n@@ -1098,32 +1143,10 @@ int main(int argc, char **argv)\n \tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n \tno_range_header = curl_slist_append(no_range_header, \"Range:\");\n \n-\tcurl_default = curl_easy_init();\n-\n-\tcurl_ssl_verify = getenv(\"GIT_SSL_NO_VERIFY\") ? 0 : 1;\n-\tcurl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);\n-#if LIBCURL_VERSION_NUM >= 0x070907\n-\tcurl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);\n+#ifndef NO_CURL_EASY_DUPHANDLE\n+\tcurl_default = get_curl_handle();\n #endif\n \n-\tif ((ssl_cert = getenv(\"GIT_SSL_CERT\")) != NULL) {\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);\n-\t}\n-#if LIBCURL_VERSION_NUM >= 0x070902\n-\tif ((ssl_key = getenv(\"GIT_SSL_KEY\")) != NULL) {\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);\n-\t}\n-#endif\n-#if LIBCURL_VERSION_NUM >= 0x070908\n-\tif ((ssl_capath = getenv(\"GIT_SSL_CAPATH\")) != NULL) {\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);\n-\t}\n-#endif\n-\tif ((ssl_cainfo = getenv(\"GIT_SSL_CAINFO\")) != NULL) {\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);\n-\t}\n-\tcurl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);\n-\n \talt = xmalloc(sizeof(*alt));\n \talt->base = url;\n \talt->got_indices = 0;\n@@ -1137,7 +1160,9 @@ int main(int argc, char **argv)\n \tcurl_slist_free_all(pragma_header);\n \tcurl_slist_free_all(no_pragma_header);\n \tcurl_slist_free_all(no_range_header);\n+#ifndef NO_CURL_EASY_DUPHANDLE\n \tcurl_easy_cleanup(curl_default);\n+#endif\n \tslot = active_queue_head;\n \twhile (slot != NULL) {\n \t\tcurl_easy_cleanup(slot->curl);\n---\n0.99.8.GIT\n"},{"id":"10120","messageId":"7vmzlbpbwu.fsf@assigned-by-dhcp.cox.net","threadId":"2111","inReplyTo":"Pine.LNX.4.63.0510150038550.2807@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-15T05:49:37Z","receivedAt":"2005-10-15T05:49:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> This patch looks bigger than it really is: The code to get the\n> default handle was refactored into a function, and is called\n> instead of curl_easy_duphandle() if that does not exist.\n\nI'd like to take Nick's config file patch first, which\nunfortunately interferes with your patch.  I'd hate to ask you\nthis, but could you rebase it on top of Nick's patch, and...\n\n> Tested once.\n\nmaybe repost after some more testing?  And I'd like to ask\neither Nick or Daniel to give an ack on the rebased one.\n"},{"id":"10123","messageId":"Pine.LNX.4.63.0510151348080.12307@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2111","inReplyTo":"7vmzlbpbwu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-15T11:50:16Z","receivedAt":"2005-10-15T11:50:16Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 14 Oct 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > This patch looks bigger than it really is: The code to get the\n> > default handle was refactored into a function, and is called\n> > instead of curl_easy_duphandle() if that does not exist.\n> \n> I'd like to take Nick's config file patch first, which\n> unfortunately interferes with your patch.  I'd hate to ask you\n> this, but could you rebase it on top of Nick's patch, [...]\n\nNo need to hate it. Here comes the rebased patch, and this time, I \nactually tested it a bit.\n\n---\n\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 784aedf..40bd0b4 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -18,6 +18,10 @@\n #define curl_global_init(a) do { /* nothing */ } while(0)\n #endif\n \n+#if LIBCURL_VERSION_NUM < 0x070c04\n+#define NO_CURL_EASY_DUPHANDLE\n+#endif\n+\n #define PREV_BUF_SIZE 4096\n #define RANGE_HEADER_SIZE 30\n \n@@ -28,7 +32,9 @@ static int data_received;\n static int max_requests = -1;\n static CURLM *curlm;\n #endif\n+#ifndef NO_CURL_EASY_DUPHANDLE\n static CURL *curl_default;\n+#endif\n static struct curl_slist *pragma_header;\n static struct curl_slist *no_pragma_header;\n static struct curl_slist *no_range_header;\n@@ -87,8 +93,12 @@ static struct active_request_slot *activ\n \n static int curl_ssl_verify = -1;\n static char *ssl_cert = NULL;\n+#if LIBCURL_VERSION_NUM >= 0x070902\n static char *ssl_key = NULL;\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n static char *ssl_capath = NULL;\n+#endif\n static char *ssl_cainfo = NULL;\n \n struct buffer\n@@ -213,6 +223,32 @@ void process_curl_messages();\n void process_request_queue();\n #endif\n \n+static CURL* get_curl_handle()\n+{\n+\tCURL* result = curl_easy_init();\n+\n+\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);\n+#if LIBCURL_VERSION_NUM >= 0x070907\n+\tcurl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);\n+#endif\n+\n+\tif (ssl_cert != NULL)\n+\t\tcurl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);\n+#if LIBCURL_VERSION_NUM >= 0x070902\n+\tif (ssl_key != NULL)\n+\t\tcurl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);\n+#endif\n+#if LIBCURL_VERSION_NUM >= 0x070908\n+\tif (ssl_capath != NULL)\n+\t\tcurl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);\n+#endif\n+\tif (ssl_cainfo != NULL)\n+\t\tcurl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);\n+\tcurl_easy_setopt(result, CURLOPT_FAILONERROR, 1);\n+\n+\treturn result;\n+}\n+\n struct active_request_slot *get_active_slot()\n {\n \tstruct active_request_slot *slot = active_queue_head;\n@@ -235,7 +271,11 @@ struct active_request_slot *get_active_s\n \t}\n \tif (slot == NULL) {\n \t\tnewslot = xmalloc(sizeof(*newslot));\n+#ifdef NO_CURL_EASY_DUPHANDLE\n+\t\tnewslot->curl = get_curl_handle();\n+#else\n \t\tnewslot->curl = curl_easy_duphandle(curl_default);\n+#endif\n \t\tnewslot->in_use = 0;\n \t\tnewslot->next = NULL;\n \n@@ -1202,24 +1242,10 @@ int main(int argc, char **argv)\n \tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n \tno_range_header = curl_slist_append(no_range_header, \"Range:\");\n \n-\tcurl_default = curl_easy_init();\n-\n-\tcurl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);\n-#if LIBCURL_VERSION_NUM >= 0x070907\n-\tcurl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);\n+#ifndef NO_CURL_EASY_DUPHANDLE\n+\tcurl_default = get_curl_handle();\n #endif\n \n-\tif (ssl_cert != NULL)\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);\n-\tif (ssl_key != NULL)\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);\n-\tif (ssl_capath != NULL)\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);\n-\tif (ssl_cainfo != NULL)\n-\t\tcurl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);\n-\n-\tcurl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);\n-\n \talt = xmalloc(sizeof(*alt));\n \talt->base = url;\n \talt->got_indices = 0;\n@@ -1233,7 +1259,9 @@ int main(int argc, char **argv)\n \tcurl_slist_free_all(pragma_header);\n \tcurl_slist_free_all(no_pragma_header);\n \tcurl_slist_free_all(no_range_header);\n+#ifndef NO_CURL_EASY_DUPHANDLE\n \tcurl_easy_cleanup(curl_default);\n+#endif\n \tslot = active_queue_head;\n \twhile (slot != NULL) {\n \t\tcurl_easy_cleanup(slot->curl);\n"},{"id":"10164","messageId":"20051016215018.GG5509@reactrix.com","threadId":"2111","inReplyTo":"Pine.LNX.4.63.0510151348080.12307@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-10-16T21:50:18Z","receivedAt":"2005-10-16T21:50:18Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"On Sat, Oct 15, 2005 at 01:50:16PM +0200, Johannes Schindelin wrote:\n\n> +#if LIBCURL_VERSION_NUM < 0x070c04\n> +#define NO_CURL_EASY_DUPHANDLE\n> +#endif\n\nIs that the correct version number?  I've been using 7.10.6 and \ncurl_easy_duphandle() has been working fine.\n\n-- \nFor a successful technology, reality must take precedence over public\nrelations, for nature cannot be fooled.\n"},{"id":"10165","messageId":"Pine.LNX.4.63.0510162355480.26678@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2111","inReplyTo":"20051016215018.GG5509@reactrix.com","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-16T21:58:25Z","receivedAt":"2005-10-16T21:58:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 16 Oct 2005, Nick Hengeveld wrote:\n\n> On Sat, Oct 15, 2005 at 01:50:16PM +0200, Johannes Schindelin wrote:\n> \n> > +#if LIBCURL_VERSION_NUM < 0x070c04\n> > +#define NO_CURL_EASY_DUPHANDLE\n> > +#endif\n> \n> Is that the correct version number?  I've been using 7.10.6 and \n> curl_easy_duphandle() has been working fine.\n\nI looked into CVS to find when curl_easy_duphandle() was introduced, and \nit was Nov 9, 2004. So I looked for the corresponding curl.h and found it \nsays 0x070c04. I will look again...\n\nCiao,\nDscho\n"},{"id":"10179","messageId":"20051017180130.GJ5509@reactrix.com","threadId":"2111","inReplyTo":"20051016215018.GG5509@reactrix.com","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-10-17T18:01:30Z","receivedAt":"2005-10-17T18:01:30Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"On Sun, Oct 16, 2005 at 02:50:18PM -0700, Nick Hengeveld wrote:\n\n> Is that the correct version number?  I've been using 7.10.6 and \n> curl_easy_duphandle() has been working fine.\n\nApart from the version number question, this patch looks good.  Although\nI'm now wondering whether it makes sense to bother trying to use\ncurl_easy_duphandle() at all and always use get_curl_handle() instead.\n\n-- \nFor a successful technology, reality must take precedence over public\nrelations, for nature cannot be fooled.\n"},{"id":"10180","messageId":"Pine.LNX.4.63.0510172049330.14782@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2111","inReplyTo":"20051017180130.GJ5509@reactrix.com","subject":"Re: [PATCH] Some curl versions lack curl_easy_duphandle()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-17T18:54:08Z","receivedAt":"2005-10-17T18:54:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 17 Oct 2005, Nick Hengeveld wrote:\n\n> On Sun, Oct 16, 2005 at 02:50:18PM -0700, Nick Hengeveld wrote:\n> \n> > Is that the correct version number?  I've been using 7.10.6 and \n> > curl_easy_duphandle() has been working fine.\n> \n> Apart from the version number question, this patch looks good.\n\nAaargh! Of course I was looking at the annotate output, which said Nov 9, \n2004. But this is just the last change to the signature of the function!\n\nSo, AFAIK Sep 13, 2001, is the correct date, and 0x070900 is the version.\n\n>  Although I'm now wondering whether it makes sense to bother trying to \n> use curl_easy_duphandle() at all and always use get_curl_handle() \n> instead.\n\nThere might well be a substantial overhead involved. I haven't measured \nit, but it seems reasonable to assume that duplicating a handle is \nimplemented using a shorter code path than creating a handle all over \nagain.\n\nCiao,\nDscho\n"}]}