Use PBD::CCurl for libardour HTTP/S requests

This commit is contained in:
Robin Gareus 2025-05-20 00:00:23 +02:00
parent 7b6ca334df
commit b92fa1d0e4
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
5 changed files with 20 additions and 20 deletions

View file

@ -16,12 +16,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <curl/curl.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <glibmm/fileutils.h> #include <glibmm/fileutils.h>
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include "pbd/ccurl.h"
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
#include "pbd/file_archive.h" #include "pbd/file_archive.h"
@ -61,9 +61,9 @@ LibraryFetcher::LibraryFetcher ()
int int
LibraryFetcher::get_descriptions () LibraryFetcher::get_descriptions ()
{ {
CURL* curl; PBD::CCurl ccurl;
CURL* curl = ccurl.curl ();
curl = curl_easy_init ();
if (!curl) { if (!curl) {
return -1; return -1;
} }
@ -75,7 +75,6 @@ LibraryFetcher::get_descriptions ()
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L);
CURLcode res = curl_easy_perform (curl); CURLcode res = curl_easy_perform (curl);
curl_easy_cleanup (curl);
if (res != CURLE_OK) { if (res != CURLE_OK) {
return -2; return -2;

View file

@ -26,6 +26,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <iostream> #include <iostream>
#include "pbd/ccurl.h"
#include "pbd/gstdio_compat.h" #include "pbd/gstdio_compat.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -54,6 +56,7 @@ SoundcloudUploader::SoundcloudUploader()
{ {
curl_handle = curl_easy_init(); curl_handle = curl_easy_init();
multi_handle = curl_multi_init(); multi_handle = curl_multi_init();
PBD::CCurl::ca_setopt (curl_handle);
} }
std::string std::string

View file

@ -133,7 +133,8 @@ Downloader::download ()
* progress meter * progress meter
*/ */
curl = curl_easy_init (); CURL* curl = _ccurl.curl ();
if (!curl) { if (!curl) {
_status = -1; _status = -1;
return; return;
@ -155,7 +156,7 @@ Downloader::download ()
_download_size = dsize; _download_size = dsize;
} }
curl_easy_cleanup (curl); _ccurl.reset ();
if (res != CURLE_OK ) { if (res != CURLE_OK ) {
error << string_compose (_("Download failed, error code %1 (%2)"), curl_easy_strerror (res), curl_error) << endmsg; error << string_compose (_("Download failed, error code %1 (%2)"), curl_easy_strerror (res), curl_error) << endmsg;
@ -164,7 +165,7 @@ Downloader::download ()
} }
} }
curl = curl_easy_init (); CURL* curl = _ccurl.curl ();
if (!curl) { if (!curl) {
_status = -1; _status = -1;
return; return;
@ -175,7 +176,6 @@ Downloader::download ()
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_Downloader); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_Downloader);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this);
CURLcode res = curl_easy_perform (curl); CURLcode res = curl_easy_perform (curl);
curl_easy_cleanup (curl);
if (res == CURLE_OK) { if (res == CURLE_OK) {
_status = 1; _status = 1;

View file

@ -31,8 +31,7 @@
#include "pbd/gstdio_compat.h" #include "pbd/gstdio_compat.h"
#include <glibmm.h> #include <glibmm.h>
#include <curl/curl.h> #include "pbd/ccurl.h"
#include "pbd/failed_constructor.h" #include "pbd/failed_constructor.h"
#include "pbd/file_archive.h" #include "pbd/file_archive.h"
#include "pbd/file_utils.h" #include "pbd/file_utils.h"
@ -60,9 +59,9 @@ static void*
get_url (void* arg) get_url (void* arg)
{ {
FileArchive::Request* r = (FileArchive::Request*) arg; FileArchive::Request* r = (FileArchive::Request*) arg;
CURL* curl; PBD::CCurl ccurl;
CURL* curl = ccurl.curl ();
curl = curl_easy_init ();
curl_easy_setopt (curl, CURLOPT_URL, r->url); curl_easy_setopt (curl, CURLOPT_URL, r->url);
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
@ -81,7 +80,6 @@ get_url (void* arg)
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void*) &r->mp); curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void*) &r->mp);
curl_easy_perform (curl); curl_easy_perform (curl);
curl_easy_cleanup (curl);
r->mp.lock (); r->mp.lock ();
r->mp.done = 1; r->mp.done = 1;
@ -190,7 +188,8 @@ FileArchive::fetch (const std::string & url, const std::string & destdir) const
return std::string(); return std::string();
} }
CURL* curl = curl_easy_init (); PBD::CCurl ccurl;
CURL* curl = ccurl.curl ();
if (!curl) { if (!curl) {
return std::string (); return std::string ();
@ -199,7 +198,6 @@ FileArchive::fetch (const std::string & url, const std::string & destdir) const
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ()); curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
CURLcode res = curl_easy_perform (curl); CURLcode res = curl_easy_perform (curl);
curl_easy_cleanup (curl);
g_chdir (pwd.c_str()); g_chdir (pwd.c_str());
if (res != CURLE_OK) { if (res != CURLE_OK) {

View file

@ -21,7 +21,7 @@
#include <atomic> #include <atomic>
#include <string> #include <string>
#include <curl/curl.h> #include "pbd/ccurl.h"
#include "pbd/libpbd_visibility.h" #include "pbd/libpbd_visibility.h"
@ -53,7 +53,7 @@ class LIBPBD_API Downloader {
std::string destdir; std::string destdir;
std::string file_path; std::string file_path;
FILE* file; FILE* file;
CURL* curl; CCurl _ccurl;
bool _cancel; bool _cancel;
std::atomic<uint64_t> _download_size; /* read-only from requestor thread */ std::atomic<uint64_t> _download_size; /* read-only from requestor thread */
std::atomic<uint64_t> _downloaded; /* read-only from requestor thread */ std::atomic<uint64_t> _downloaded; /* read-only from requestor thread */