@@ -598,6 +598,41 @@ int PLUGIN_GLOBAL(hfile_plugin_init,_libcurl)(struct hFILE_plugin *self)
598
598
* Rewrite S3 URLs *
599
599
*******************/
600
600
601
+ static size_t kput_callback (char * ptr , size_t size , size_t nmemb , void * strv )
602
+ {
603
+ kstring_t * str = (kstring_t * ) strv ;
604
+ size_t len = size * nmemb ;
605
+ return (kputsn (ptr , len , str ) >= 0 )? len : 0 ;
606
+ }
607
+
608
+ static int curl_kput (const char * url , kstring_t * str )
609
+ {
610
+ CURLcode err ;
611
+ CURL * easy = curl_easy_init ();
612
+ if (easy == NULL ) { errno = ENOMEM ; return -1 ; }
613
+
614
+ err = curl_easy_setopt (easy , CURLOPT_URL , url );
615
+ err |= curl_easy_setopt (easy , CURLOPT_WRITEFUNCTION , kput_callback );
616
+ err |= curl_easy_setopt (easy , CURLOPT_WRITEDATA , str );
617
+ err |= curl_easy_setopt (easy , CURLOPT_USERAGENT , curl .useragent .s );
618
+ err |= curl_easy_setopt (easy , CURLOPT_FOLLOWLOCATION , 1L );
619
+ err |= curl_easy_setopt (easy , CURLOPT_FAILONERROR , 1L );
620
+ if (hts_verbose >= 8 ) err |= curl_easy_setopt (easy , CURLOPT_VERBOSE , 1L );
621
+ if (err != 0 ) { curl_easy_cleanup (easy ); errno = ENOSYS ; return -1 ; }
622
+
623
+ err = curl_easy_perform (easy );
624
+ if (err != CURLE_OK ) {
625
+ int save_errno = easy_errno (easy , err );
626
+ curl_easy_cleanup (easy );
627
+ errno = save_errno ;
628
+ return -1 ;
629
+ }
630
+
631
+ curl_easy_cleanup (easy );
632
+ return 0 ;
633
+ }
634
+
635
+
601
636
#if defined HAVE_COMMONCRYPTO
602
637
603
638
#include <CommonCrypto/CommonHMAC.h>
0 commit comments