Skip to content

Commit 3c7896e

Browse files
gitsterdscho
authored andcommitted
Merge branch 'backport/jk/curl-avoid-deprecated-api' into maint-2.30
Deal with a few deprecation warning from cURL library. * jk/curl-avoid-deprecated-api: http: support CURLOPT_PROTOCOLS_STR http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
2 parents 6f5ff3a + 07f91e5 commit 3c7896e

File tree

5 files changed

+81
-50
lines changed

5 files changed

+81
-50
lines changed

INSTALL

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ Issues of note:
145145
patches into an IMAP mailbox, you do not have to have them
146146
(use NO_CURL).
147147

148+
Git requires version "7.19.5" or later of "libcurl" to build
149+
without NO_CURL. This version requirement may be bumped in
150+
the future.
151+
148152
- "expat" library; git-http-push uses it for remote lock
149153
management over DAV. Similar to "curl" above, this is optional
150154
(with NO_EXPAT).

http-push.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ static void curl_setup_http(CURL *curl, const char *url,
198198
const char *custom_req, struct buffer *buffer,
199199
curl_write_callback write_fn)
200200
{
201-
curl_easy_setopt(curl, CURLOPT_PUT, 1);
201+
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
202202
curl_easy_setopt(curl, CURLOPT_URL, url);
203203
curl_easy_setopt(curl, CURLOPT_INFILE, buffer);
204204
curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len);
205205
curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
206-
#ifndef NO_CURL_IOCTL
207-
curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
208-
curl_easy_setopt(curl, CURLOPT_IOCTLDATA, buffer);
206+
#ifndef NO_CURL_SEEK
207+
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_buffer);
208+
curl_easy_setopt(curl, CURLOPT_SEEKDATA, buffer);
209209
#endif
210210
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_fn);
211211
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);

http.c

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,20 @@ size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
186186
return size / eltsize;
187187
}
188188

189-
#ifndef NO_CURL_IOCTL
190-
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
189+
#ifndef NO_CURL_SEEK
190+
int seek_buffer(void *clientp, curl_off_t offset, int origin)
191191
{
192192
struct buffer *buffer = clientp;
193193

194-
switch (cmd) {
195-
case CURLIOCMD_NOP:
196-
return CURLIOE_OK;
197-
198-
case CURLIOCMD_RESTARTREAD:
199-
buffer->posn = 0;
200-
return CURLIOE_OK;
201-
202-
default:
203-
return CURLIOE_UNKNOWNCMD;
194+
if (origin != SEEK_SET)
195+
BUG("seek_buffer only handles SEEK_SET");
196+
if (offset < 0 || offset >= buffer->buf.len) {
197+
error("curl seek would be outside of buffer");
198+
return CURL_SEEKFUNC_FAIL;
204199
}
200+
201+
buffer->posn = offset;
202+
return CURL_SEEKFUNC_OK;
205203
}
206204
#endif
207205

@@ -810,20 +808,37 @@ void setup_curl_trace(CURL *handle)
810808
}
811809

812810
#ifdef CURLPROTO_HTTP
813-
static long get_curl_allowed_protocols(int from_user)
811+
static void proto_list_append(struct strbuf *list, const char *proto)
814812
{
815-
long allowed_protocols = 0;
813+
if (!list)
814+
return;
815+
if (list->len)
816+
strbuf_addch(list, ',');
817+
strbuf_addstr(list, proto);
818+
}
816819

817-
if (is_transport_allowed("http", from_user))
818-
allowed_protocols |= CURLPROTO_HTTP;
819-
if (is_transport_allowed("https", from_user))
820-
allowed_protocols |= CURLPROTO_HTTPS;
821-
if (is_transport_allowed("ftp", from_user))
822-
allowed_protocols |= CURLPROTO_FTP;
823-
if (is_transport_allowed("ftps", from_user))
824-
allowed_protocols |= CURLPROTO_FTPS;
820+
static long get_curl_allowed_protocols(int from_user, struct strbuf *list)
821+
{
822+
long bits = 0;
825823

826-
return allowed_protocols;
824+
if (is_transport_allowed("http", from_user)) {
825+
bits |= CURLPROTO_HTTP;
826+
proto_list_append(list, "http");
827+
}
828+
if (is_transport_allowed("https", from_user)) {
829+
bits |= CURLPROTO_HTTPS;
830+
proto_list_append(list, "https");
831+
}
832+
if (is_transport_allowed("ftp", from_user)) {
833+
bits |= CURLPROTO_FTP;
834+
proto_list_append(list, "ftp");
835+
}
836+
if (is_transport_allowed("ftps", from_user)) {
837+
bits |= CURLPROTO_FTPS;
838+
proto_list_append(list, "ftps");
839+
}
840+
841+
return bits;
827842
}
828843
#endif
829844

@@ -981,10 +996,24 @@ static CURL *get_curl_handle(void)
981996
curl_easy_setopt(result, CURLOPT_POST301, 1);
982997
#endif
983998
#ifdef CURLPROTO_HTTP
999+
#if LIBCURL_VERSION_NUM >= 0x075500
1000+
{
1001+
struct strbuf buf = STRBUF_INIT;
1002+
1003+
get_curl_allowed_protocols(0, &buf);
1004+
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS_STR, buf.buf);
1005+
strbuf_reset(&buf);
1006+
1007+
get_curl_allowed_protocols(-1, &buf);
1008+
curl_easy_setopt(result, CURLOPT_PROTOCOLS_STR, buf.buf);
1009+
strbuf_release(&buf);
1010+
}
1011+
#else
9841012
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS,
985-
get_curl_allowed_protocols(0));
1013+
get_curl_allowed_protocols(0, NULL));
9861014
curl_easy_setopt(result, CURLOPT_PROTOCOLS,
987-
get_curl_allowed_protocols(-1));
1015+
get_curl_allowed_protocols(-1, NULL));
1016+
#endif
9881017
#else
9891018
warning(_("Protocol restrictions not supported with cURL < 7.19.4"));
9901019
#endif

http.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
4242
#endif
4343

44-
#if LIBCURL_VERSION_NUM < 0x070c03
45-
#define NO_CURL_IOCTL
44+
#if LIBCURL_VERSION_NUM < 0x071200
45+
#define NO_CURL_SEEK
4646
#endif
4747

4848
/*
@@ -82,8 +82,8 @@ struct buffer {
8282
size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
8383
size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
8484
size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
85-
#ifndef NO_CURL_IOCTL
86-
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
85+
#ifndef NO_CURL_SEEK
86+
int seek_buffer(void *clientp, curl_off_t offset, int origin);
8787
#endif
8888

8989
/* Slot lifecycle functions */

remote-curl.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -707,26 +707,24 @@ static size_t rpc_out(void *ptr, size_t eltsize,
707707
return avail;
708708
}
709709

710-
#ifndef NO_CURL_IOCTL
711-
static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
710+
#ifndef NO_CURL_SEEK
711+
static int rpc_seek(void *clientp, curl_off_t offset, int origin)
712712
{
713713
struct rpc_state *rpc = clientp;
714714

715-
switch (cmd) {
716-
case CURLIOCMD_NOP:
717-
return CURLIOE_OK;
715+
if (origin != SEEK_SET)
716+
BUG("rpc_seek only handles SEEK_SET, not %d", origin);
718717

719-
case CURLIOCMD_RESTARTREAD:
720-
if (rpc->initial_buffer) {
721-
rpc->pos = 0;
722-
return CURLIOE_OK;
718+
if (rpc->initial_buffer) {
719+
if (offset < 0 || offset > rpc->len) {
720+
error("curl seek would be outside of rpc buffer");
721+
return CURL_SEEKFUNC_FAIL;
723722
}
724-
error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
725-
return CURLIOE_FAILRESTART;
726-
727-
default:
728-
return CURLIOE_UNKNOWNCMD;
723+
rpc->pos = offset;
724+
return CURL_SEEKFUNC_OK;
729725
}
726+
error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
727+
return CURL_SEEKFUNC_FAIL;
730728
}
731729
#endif
732730

@@ -947,9 +945,9 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
947945
rpc->initial_buffer = 1;
948946
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
949947
curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
950-
#ifndef NO_CURL_IOCTL
951-
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl);
952-
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc);
948+
#ifndef NO_CURL_SEEK
949+
curl_easy_setopt(slot->curl, CURLOPT_SEEKFUNCTION, rpc_seek);
950+
curl_easy_setopt(slot->curl, CURLOPT_SEEKDATA, rpc);
953951
#endif
954952
if (options.verbosity > 1) {
955953
fprintf(stderr, "POST %s (chunked)\n", rpc->service_name);

0 commit comments

Comments
 (0)