Skip to content

Commit fe42fe4

Browse files
committed
Merge branch 'ms/http-auth'
* ms/http-auth: Allow curl to rewind the read buffers
2 parents a990672 + 3944ba0 commit fe42fe4

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

http-push.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ static void start_put(struct transfer_request *request)
567567
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
568568
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
569569
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
570+
#ifndef NO_CURL_IOCTL
571+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
572+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);
573+
#endif
570574
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
571575
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
572576
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
@@ -1266,6 +1270,10 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
12661270
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
12671271
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
12681272
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1273+
#ifndef NO_CURL_IOCTL
1274+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
1275+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
1276+
#endif
12691277
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
12701278
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
12711279
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1507,6 +1515,10 @@ static void remote_ls(const char *path, int flags,
15071515
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
15081516
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
15091517
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1518+
#ifndef NO_CURL_IOCTL
1519+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
1520+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
1521+
#endif
15101522
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
15111523
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
15121524
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -1583,6 +1595,10 @@ static int locking_available(void)
15831595
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
15841596
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
15851597
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1598+
#ifndef NO_CURL_IOCTL
1599+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
1600+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
1601+
#endif
15861602
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
15871603
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
15881604
curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
@@ -1765,6 +1781,10 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
17651781
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
17661782
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
17671783
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1784+
#ifndef NO_CURL_IOCTL
1785+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
1786+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
1787+
#endif
17681788
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
17691789
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
17701790
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
@@ -1909,6 +1929,10 @@ static void update_remote_info_refs(struct remote_lock *lock)
19091929
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
19101930
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
19111931
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
1932+
#ifndef NO_CURL_IOCTL
1933+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
1934+
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);
1935+
#endif
19121936
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
19131937
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
19141938
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);

http.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
4444
return size;
4545
}
4646

47+
#ifndef NO_CURL_IOCTL
48+
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
49+
{
50+
struct buffer *buffer = clientp;
51+
52+
switch (cmd) {
53+
case CURLIOCMD_NOP:
54+
return CURLIOE_OK;
55+
56+
case CURLIOCMD_RESTARTREAD:
57+
buffer->posn = 0;
58+
return CURLIOE_OK;
59+
60+
default:
61+
return CURLIOE_UNKNOWNCMD;
62+
}
63+
}
64+
#endif
65+
4766
size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
4867
{
4968
size_t size = eltsize * nmemb;

http.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
3838
#endif
3939

40+
#if LIBCURL_VERSION_NUM < 0x070c03
41+
#define NO_CURL_IOCTL
42+
#endif
43+
4044
struct slot_results
4145
{
4246
CURLcode curl_result;
@@ -67,6 +71,9 @@ struct buffer
6771
extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
6872
extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
6973
extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
74+
#ifndef NO_CURL_IOCTL
75+
extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
76+
#endif
7077

7178
/* Slot lifecycle functions */
7279
extern struct active_request_slot *get_active_slot(void);

0 commit comments

Comments
 (0)