From b92fa1d0e4f04ea8f18067369b9c1a488d255791 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 20 May 2025 00:00:23 +0200 Subject: [PATCH] Use PBD::CCurl for libardour HTTP/S requests --- libs/ardour/library.cc | 13 ++++++------- libs/ardour/soundcloud_upload.cc | 3 +++ libs/pbd/downloader.cc | 8 ++++---- libs/pbd/file_archive.cc | 12 +++++------- libs/pbd/pbd/downloader.h | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libs/ardour/library.cc b/libs/ardour/library.cc index 4b375f0c49..f3ab435ae3 100644 --- a/libs/ardour/library.cc +++ b/libs/ardour/library.cc @@ -16,12 +16,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include #include #include #include +#include "pbd/ccurl.h" #include "pbd/error.h" #include "pbd/i18n.h" #include "pbd/file_archive.h" @@ -61,9 +61,9 @@ LibraryFetcher::LibraryFetcher () int LibraryFetcher::get_descriptions () { - CURL* curl; + PBD::CCurl ccurl; + CURL* curl = ccurl.curl (); - curl = curl_easy_init (); if (!curl) { return -1; } @@ -72,10 +72,9 @@ LibraryFetcher::get_descriptions () curl_easy_setopt (curl, CURLOPT_URL, Config->get_resource_index_url().c_str()); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); - CURLcode res = curl_easy_perform (curl); - curl_easy_cleanup (curl); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); + CURLcode res = curl_easy_perform (curl); if (res != CURLE_OK) { return -2; diff --git a/libs/ardour/soundcloud_upload.cc b/libs/ardour/soundcloud_upload.cc index 7b702c419f..5f758c20dd 100644 --- a/libs/ardour/soundcloud_upload.cc +++ b/libs/ardour/soundcloud_upload.cc @@ -26,6 +26,8 @@ #include #include #include + +#include "pbd/ccurl.h" #include "pbd/gstdio_compat.h" #include "pbd/i18n.h" @@ -54,6 +56,7 @@ SoundcloudUploader::SoundcloudUploader() { curl_handle = curl_easy_init(); multi_handle = curl_multi_init(); + PBD::CCurl::ca_setopt (curl_handle); } std::string diff --git a/libs/pbd/downloader.cc b/libs/pbd/downloader.cc index bcc75ef7e5..3986a796bc 100644 --- a/libs/pbd/downloader.cc +++ b/libs/pbd/downloader.cc @@ -133,7 +133,8 @@ Downloader::download () * progress meter */ - curl = curl_easy_init (); + CURL* curl = _ccurl.curl (); + if (!curl) { _status = -1; return; @@ -155,7 +156,7 @@ Downloader::download () _download_size = dsize; } - curl_easy_cleanup (curl); + _ccurl.reset (); if (res != CURLE_OK ) { 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) { _status = -1; return; @@ -175,7 +176,6 @@ Downloader::download () curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_Downloader); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); CURLcode res = curl_easy_perform (curl); - curl_easy_cleanup (curl); if (res == CURLE_OK) { _status = 1; diff --git a/libs/pbd/file_archive.cc b/libs/pbd/file_archive.cc index 770822d285..f26c7a26f1 100644 --- a/libs/pbd/file_archive.cc +++ b/libs/pbd/file_archive.cc @@ -31,8 +31,7 @@ #include "pbd/gstdio_compat.h" #include -#include - +#include "pbd/ccurl.h" #include "pbd/failed_constructor.h" #include "pbd/file_archive.h" #include "pbd/file_utils.h" @@ -60,9 +59,9 @@ static void* get_url (void* 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_FOLLOWLOCATION, 1L); @@ -81,7 +80,6 @@ get_url (void* arg) curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void*) &r->mp); curl_easy_perform (curl); - curl_easy_cleanup (curl); r->mp.lock (); r->mp.done = 1; @@ -190,7 +188,8 @@ FileArchive::fetch (const std::string & url, const std::string & destdir) const return std::string(); } - CURL* curl = curl_easy_init (); + PBD::CCurl ccurl; + CURL* curl = ccurl.curl (); if (!curl) { 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_FOLLOWLOCATION, 1L); CURLcode res = curl_easy_perform (curl); - curl_easy_cleanup (curl); g_chdir (pwd.c_str()); if (res != CURLE_OK) { diff --git a/libs/pbd/pbd/downloader.h b/libs/pbd/pbd/downloader.h index ebdfa95cb7..91a428582a 100644 --- a/libs/pbd/pbd/downloader.h +++ b/libs/pbd/pbd/downloader.h @@ -21,7 +21,7 @@ #include #include -#include +#include "pbd/ccurl.h" #include "pbd/libpbd_visibility.h" @@ -53,7 +53,7 @@ class LIBPBD_API Downloader { std::string destdir; std::string file_path; FILE* file; - CURL* curl; + CCurl _ccurl; bool _cancel; std::atomic _download_size; /* read-only from requestor thread */ std::atomic _downloaded; /* read-only from requestor thread */