git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow curl to rewind the read buffers
@ 2009-04-01 15:10 Martin Storsjö
  2009-04-01 16:19 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Storsjö @ 2009-04-01 15:10 UTC (permalink / raw)
  To: git

Rewinding of the read buffers may be needed when doing HTTP PUT or POST
(or PROPFIND) with multi-pass authentication methods.

Depending on the HTTP server, the read buffers may or may not need
rewinding. (Apache returns a 401 error immediately before any data has
been read from the buffers, while Lighttpd doesn't reply until all data
has been sent.)

Signed-off-by: Martin Storsjo <martin@martin.st>
---
 http-push.c |   24 ++++++++++++++++++++++++
 http.c      |   19 +++++++++++++++++++
 http.h      |    7 +++++++
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/http-push.c b/http-push.c
index 6ce5a1d..7dc0dd4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -567,6 +567,10 @@ static void start_put(struct transfer_request *request)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 	curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
@@ -1267,6 +1271,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1508,6 +1516,10 @@ static void remote_ls(const char *path, int flags,
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1584,6 +1596,10 @@ static int locking_available(void)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
@@ -1766,6 +1782,10 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
@@ -1910,6 +1930,10 @@ static void update_remote_info_refs(struct remote_lock *lock)
 		curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
 		curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
 		curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+		curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+		curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);
+#endif
 		curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 		curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 		curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
diff --git a/http.c b/http.c
index eae74aa..3e8d548 100644
--- a/http.c
+++ b/http.c
@@ -44,6 +44,25 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 	return size;
 }
 
+#ifndef NO_CURL_IOCTL
+curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
+{
+	struct buffer *buffer = clientp;
+
+	switch (cmd) {
+	case CURLIOCMD_NOP:
+		return CURLIOE_OK;
+
+	case CURLIOCMD_RESTARTREAD:
+		buffer->posn = 0;
+		return CURLIOE_OK;
+
+	default:
+		return CURLIOE_UNKNOWNCMD;
+	}
+}
+#endif
+
 size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
 	size_t size = eltsize * nmemb;
diff --git a/http.h b/http.h
index 905b462..26abebe 100644
--- a/http.h
+++ b/http.h
@@ -37,6 +37,10 @@
 #define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
 #endif
 
+#if LIBCURL_VERSION_NUM < 0x070c03
+#define NO_CURL_IOCTL
+#endif
+
 struct slot_results
 {
 	CURLcode curl_result;
@@ -67,6 +71,9 @@ struct buffer
 extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
 extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
 extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
+#ifndef NO_CURL_IOCTL
+extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
+#endif
 
 /* Slot lifecycle functions */
 extern struct active_request_slot *get_active_slot(void);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow curl to rewind the read buffers
  2009-04-01 15:10 [PATCH] Allow curl to rewind the read buffers Martin Storsjö
@ 2009-04-01 16:19 ` Junio C Hamano
  2009-04-01 16:46   ` Martin Storsjö
  2009-04-01 16:48   ` Martin Storsjö
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2009-04-01 16:19 UTC (permalink / raw)
  To: Martin Storsjö; +Cc: git

Martin Storsjö <martin@martin.st> writes:

> Rewinding of the read buffers may be needed when doing HTTP PUT or POST
> (or PROPFIND) with multi-pass authentication methods.

It may be obvious to people proficient in cURL, but I had to guess that
you perhaps meant to say "when using multi-pass authentication methods,
cURL library may need to rewind the read buffers (depending on what is fed
by the server), and in order to allow the library to do so, we need to
tell it how by providing the way to manipulate the buffers we supply with
these IOCTL callbacks."

Do I understand you correctly?

My point is that the your two-line statement of fact (with a bit more
explanation of the fact that follows) was clear but it was unclear to me
how that fact translates to the need of what the patch does.  We would
want the commit log message to be helpful to people who look at the code 6
months down the line and wonder why these lines were added.

Please do not make me guess.  I won't claim that other people would be
even less clueful than I am, but I am reasonably sure that more than half
of the people who read this patch would share my uneasiness of not clearly
reading how your statement of fact leads to your conclusion.

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow curl to rewind the read buffers
  2009-04-01 16:19 ` Junio C Hamano
@ 2009-04-01 16:46   ` Martin Storsjö
  2009-04-01 16:48   ` Martin Storsjö
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Storsjö @ 2009-04-01 16:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Wed, 1 Apr 2009, Junio C Hamano wrote:

> It may be obvious to people proficient in cURL, but I had to guess that
> you perhaps meant to say "when using multi-pass authentication methods,
> cURL library may need to rewind the read buffers (depending on what is fed
> by the server), and in order to allow the library to do so, we need to
> tell it how by providing the way to manipulate the buffers we supply with
> these IOCTL callbacks."
> 
> Do I understand you correctly?

Yeah, that's exactly correct.

> My point is that the your two-line statement of fact (with a bit more
> explanation of the fact that follows) was clear but it was unclear to me
> how that fact translates to the need of what the patch does.  We would
> want the commit log message to be helpful to people who look at the code 6
> months down the line and wonder why these lines were added.

The original commit comment was a bit vague in retrospect, yes. I'll reply 
with an updated version soon.

Thanks!

// Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Allow curl to rewind the read buffers
  2009-04-01 16:19 ` Junio C Hamano
  2009-04-01 16:46   ` Martin Storsjö
@ 2009-04-01 16:48   ` Martin Storsjö
  2009-04-02  7:03     ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Storsjö @ 2009-04-01 16:48 UTC (permalink / raw)
  To: git

When using multi-pass authentication methods, the curl library may
need to rewind the read buffers (depending on how much already has
been fed to the server) used for providing data to HTTP PUT, POST or
PROPFIND, and in order to allow the library to do so, we need to tell
it how by providing either an ioctl callback or a seek callback.

This patch adds an ioctl callback, which should be usable on older
curl versions (since 7.12.3) than the seek callback (introduced in
curl 7.18.0).

Some HTTP servers (such as Apache) give an 401 error reply immediately
after receiving the headers (so no data has been read from the read
buffers, and thus no rewinding is needed), but other servers (such
as Lighttpd) only replies after the whole request has been sent and
all data has been read from the read buffers, making rewinding necessary.

Signed-off-by: Martin Storsjo <martin@martin.st>
---

Updated comment to better describe the potential need for this.

 http-push.c |   24 ++++++++++++++++++++++++
 http.c      |   19 +++++++++++++++++++
 http.h      |    7 +++++++
 3 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/http-push.c b/http-push.c
index 6ce5a1d..7dc0dd4 100644
--- a/http-push.c
+++ b/http-push.c
@@ -567,6 +567,10 @@ static void start_put(struct transfer_request *request)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 	curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
@@ -1267,6 +1271,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1508,6 +1516,10 @@ static void remote_ls(const char *path, int flags,
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1584,6 +1596,10 @@ static int locking_available(void)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
@@ -1766,6 +1782,10 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
 	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
 	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
 	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
+#endif
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
@@ -1910,6 +1930,10 @@ static void update_remote_info_refs(struct remote_lock *lock)
 		curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
 		curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
 		curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+		curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+		curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);
+#endif
 		curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 		curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
 		curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
diff --git a/http.c b/http.c
index eae74aa..3e8d548 100644
--- a/http.c
+++ b/http.c
@@ -44,6 +44,25 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 	return size;
 }
 
+#ifndef NO_CURL_IOCTL
+curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
+{
+	struct buffer *buffer = clientp;
+
+	switch (cmd) {
+	case CURLIOCMD_NOP:
+		return CURLIOE_OK;
+
+	case CURLIOCMD_RESTARTREAD:
+		buffer->posn = 0;
+		return CURLIOE_OK;
+
+	default:
+		return CURLIOE_UNKNOWNCMD;
+	}
+}
+#endif
+
 size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
 	size_t size = eltsize * nmemb;
diff --git a/http.h b/http.h
index 905b462..26abebe 100644
--- a/http.h
+++ b/http.h
@@ -37,6 +37,10 @@
 #define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
 #endif
 
+#if LIBCURL_VERSION_NUM < 0x070c03
+#define NO_CURL_IOCTL
+#endif
+
 struct slot_results
 {
 	CURLcode curl_result;
@@ -67,6 +71,9 @@ struct buffer
 extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
 extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
 extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
+#ifndef NO_CURL_IOCTL
+extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
+#endif
 
 /* Slot lifecycle functions */
 extern struct active_request_slot *get_active_slot(void);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow curl to rewind the read buffers
  2009-04-01 16:48   ` Martin Storsjö
@ 2009-04-02  7:03     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2009-04-02  7:03 UTC (permalink / raw)
  To: Martin Storsjö; +Cc: git, Mike Ralphson

Martin Storsjö <martin@martin.st> writes:

> When using multi-pass authentication methods, the curl library may
> need to rewind the read buffers (depending on how much already has
> been fed to the server) used for providing data to HTTP PUT, POST or
> PROPFIND, and in order to allow the library to do so, we need to tell
> it how by providing either an ioctl callback or a seek callback.
>
> This patch adds an ioctl callback, which should be usable on older
> curl versions (since 7.12.3) than the seek callback (introduced in
> curl 7.18.0).
>
> Some HTTP servers (such as Apache) give an 401 error reply immediately
> after receiving the headers (so no data has been read from the read
> buffers, and thus no rewinding is needed), but other servers (such
> as Lighttpd) only replies after the whole request has been sent and
> all data has been read from the read buffers, making rewinding necessary.
>
> Signed-off-by: Martin Storsjo <martin@martin.st>

Looks good, thanks.

Mike, how does this interact with your effort for defining a simplified
dependency rules on libcurl versions? 

> Updated comment to better describe the potential need for this.
>
>  http-push.c |   24 ++++++++++++++++++++++++
>  http.c      |   19 +++++++++++++++++++
>  http.h      |    7 +++++++
>  3 files changed, 50 insertions(+), 0 deletions(-)
>
> diff --git a/http-push.c b/http-push.c
> index 6ce5a1d..7dc0dd4 100644
> --- a/http-push.c
> +++ b/http-push.c
> @@ -567,6 +567,10 @@ static void start_put(struct transfer_request *request)
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
>  	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);
> +#endif
>  	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
>  	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
>  	curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
> @@ -1267,6 +1271,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
>  	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
> +#endif
>  	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
> @@ -1508,6 +1516,10 @@ static void remote_ls(const char *path, int flags,
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
>  	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
> +#endif
>  	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
> @@ -1584,6 +1596,10 @@ static int locking_available(void)
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
>  	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
> +#endif
>  	curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
> @@ -1766,6 +1782,10 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
>  	curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
>  	curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +	curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
> +#endif
>  	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
>  	curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
>  	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
> @@ -1910,6 +1930,10 @@ static void update_remote_info_refs(struct remote_lock *lock)
>  		curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
>  		curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
>  		curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
> +#ifndef NO_CURL_IOCTL
> +		curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
> +		curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);
> +#endif
>  		curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
>  		curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
>  		curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
> diff --git a/http.c b/http.c
> index eae74aa..3e8d548 100644
> --- a/http.c
> +++ b/http.c
> @@ -44,6 +44,25 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
>  	return size;
>  }
>  
> +#ifndef NO_CURL_IOCTL
> +curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
> +{
> +	struct buffer *buffer = clientp;
> +
> +	switch (cmd) {
> +	case CURLIOCMD_NOP:
> +		return CURLIOE_OK;
> +
> +	case CURLIOCMD_RESTARTREAD:
> +		buffer->posn = 0;
> +		return CURLIOE_OK;
> +
> +	default:
> +		return CURLIOE_UNKNOWNCMD;
> +	}
> +}
> +#endif
> +
>  size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
>  {
>  	size_t size = eltsize * nmemb;
> diff --git a/http.h b/http.h
> index 905b462..26abebe 100644
> --- a/http.h
> +++ b/http.h
> @@ -37,6 +37,10 @@
>  #define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
>  #endif
>  
> +#if LIBCURL_VERSION_NUM < 0x070c03
> +#define NO_CURL_IOCTL
> +#endif
> +
>  struct slot_results
>  {
>  	CURLcode curl_result;
> @@ -67,6 +71,9 @@ struct buffer
>  extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
>  extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
>  extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
> +#ifndef NO_CURL_IOCTL
> +extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
> +#endif
>  
>  /* Slot lifecycle functions */
>  extern struct active_request_slot *get_active_slot(void);
> -- 
> 1.6.0.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-04-02  7:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-01 15:10 [PATCH] Allow curl to rewind the read buffers Martin Storsjö
2009-04-01 16:19 ` Junio C Hamano
2009-04-01 16:46   ` Martin Storsjö
2009-04-01 16:48   ` Martin Storsjö
2009-04-02  7:03     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).