@@ -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
0 commit comments