Audacity 3.2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
audacity::network_manager::CurlHandleManager::Handle Class Referencefinal

#include <CurlHandleManager.h>

Collaboration diagram for audacity::network_manager::CurlHandleManager::Handle:
[legend]

Classes

struct  Result
 

Public Member Functions

 Handle (Handle &&rhs) noexcept
 
 ~Handle () noexcept
 
Handleoperator= (Handle &&rhs) noexcept
 
template<typename... Args>
CURLcode setOption (CURLoption option, Args... value) noexcept
 
CURLcode setOption (CURLoption option, const std::string &value) noexcept
 
CURLcode appendCookie (const Cookie &cookie) noexcept
 
CURLcode appendCookies (const CookiesList &cookie) noexcept
 
void appendHeader (const Header &header)
 
void appendHeaders (const HeadersList &headers)
 
Result perform ()
 
void markKeepAlive ()
 
bool isHandleFromCache () const noexcept
 
unsigned getHTTPCode () const noexcept
 
void reset () noexcept
 
CURL * getCurlHandle () const noexcept
 
void disableSSLValidation ()
 
void enableSSLValidation ()
 

Private Member Functions

 Handle (CurlHandleManager *owner, CURL *handle, RequestVerb verb, std::string url) noexcept
 

Private Attributes

CURL * mHandle { nullptr }
 
CurlHandleManagermOwner { nullptr }
 
RequestVerb mVerb
 
std::string mUrl
 
CurlStringList mHeaders
 
bool mUserAgentSet { false }
 
bool mReuse { false }
 
bool mHandleFromCache { false }
 

Friends

class CurlHandleManager
 

Detailed Description

Definition at line 34 of file CurlHandleManager.h.

Constructor & Destructor Documentation

◆ Handle() [1/2]

audacity::network_manager::CurlHandleManager::Handle::Handle ( CurlHandleManager owner,
CURL *  handle,
RequestVerb  verb,
std::string  url 
)
privatenoexcept

Definition at line 87 of file CurlHandleManager.cpp.

88 : mHandle (handle),
89 mOwner (owner),
90 mVerb (verb),
91 mUrl (std::move (url)),
92 mHandleFromCache (handle != nullptr)
93{
94 if (mHandle == nullptr)
95 mHandle = curl_easy_init ();
96
97 setOption (CURLOPT_URL, mUrl);
98
99 switch (verb)
100 {
102 setOption (CURLOPT_NOBODY, 1);
103 break;
104 case RequestVerb::Get:
105 // This is a default, no additional setup is needed
106 // We cache handles by the verb, so there is no need to
107 // reset the handle state
108 break;
110 setOption (CURLOPT_POST, 1);
111 break;
112 case RequestVerb::Put:
113 setOption (CURLOPT_UPLOAD, 1);
114 break;
116 setOption (CURLOPT_CUSTOMREQUEST, "DELETE");
117 break;
119 setOption(CURLOPT_UPLOAD, 1);
120 setOption(CURLOPT_CUSTOMREQUEST, "PATCH");
121 break;
122 }
123
124 setOption (CURLOPT_NOSIGNAL, 1L);
125
128 else
130
131 setOption (CURLOPT_ACCEPT_ENCODING, "");
132}
CURLcode setOption(CURLoption option, Args... value) noexcept

References audacity::network_manager::Delete, audacity::network_manager::anonymous_namespace{CurlHandleManager.cpp}::gCurlConfig, audacity::network_manager::Get, audacity::network_manager::Head, audacity::network_manager::Patch, audacity::network_manager::Post, audacity::network_manager::Put, and audacity::network_manager::anonymous_namespace{CurlHandleManager.cpp}::CurlConfig::SSLValidation.

◆ Handle() [2/2]

audacity::network_manager::CurlHandleManager::Handle::Handle ( Handle &&  rhs)
noexcept

Definition at line 134 of file CurlHandleManager.cpp.

135{
136 *this = std::move (rhs);
137}

◆ ~Handle()

audacity::network_manager::CurlHandleManager::Handle::~Handle ( )
noexcept

Definition at line 139 of file CurlHandleManager.cpp.

140{
141 if (mReuse)
142 mOwner->cacheHandle (*this);
143 else
144 curl_easy_cleanup (mHandle);
145}

References audacity::network_manager::CurlHandleManager::cacheHandle(), mHandle, mOwner, and mReuse.

Here is the call graph for this function:

Member Function Documentation

◆ appendCookie()

CURLcode audacity::network_manager::CurlHandleManager::Handle::appendCookie ( const Cookie cookie)
noexcept

Definition at line 168 of file CurlHandleManager.cpp.

169{
170 return setOption(CURLOPT_COOKIE, "Set-Cookie: " + cookie.Name + "=" + cookie.Value);
171}

◆ appendCookies()

CURLcode audacity::network_manager::CurlHandleManager::Handle::appendCookies ( const CookiesList cookie)
noexcept

Definition at line 173 of file CurlHandleManager.cpp.

174{
175 for (const Cookie& cookie : cookies)
176 {
177 const CURLcode result = appendCookie (cookie);
178
179 if (result != CURLE_OK)
180 return result;
181 }
182
183 return CURLE_OK;
184}
CURLcode appendCookie(const Cookie &cookie) noexcept

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ appendHeader()

void audacity::network_manager::CurlHandleManager::Handle::appendHeader ( const Header header)

Definition at line 186 of file CurlHandleManager.cpp.

187{
188 if (header.hasSameName ("User-Agent"))
189 mUserAgentSet = true;
190
191 mHeaders.append(header.Name + ": " + header.Value);
192}
void append(const std::string &string) noexcept

References audacity::network_manager::Header::hasSameName(), audacity::network_manager::Header::Name, and audacity::network_manager::Header::Value.

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ appendHeaders()

void audacity::network_manager::CurlHandleManager::Handle::appendHeaders ( const HeadersList headers)

Definition at line 194 of file CurlHandleManager.cpp.

195{
196 for (const Header& header : headers)
197 appendHeader (header);
198}
A string pair, representing HTTP header.

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ disableSSLValidation()

void audacity::network_manager::CurlHandleManager::Handle::disableSSLValidation ( )

Definition at line 254 of file CurlHandleManager.cpp.

255{
256 setOption(CURLOPT_SSL_VERIFYPEER, 0L);
257 setOption(CURLOPT_SSL_VERIFYHOST, 0L);
258}

◆ enableSSLValidation()

void audacity::network_manager::CurlHandleManager::Handle::enableSSLValidation ( )

Definition at line 260 of file CurlHandleManager.cpp.

261{
262 setOption(CURLOPT_SSL_VERIFYPEER, 1L);
263 setOption(CURLOPT_SSL_VERIFYHOST, 2L);
264}

◆ getCurlHandle()

CURL * audacity::network_manager::CurlHandleManager::Handle::getCurlHandle ( ) const
noexcept

Definition at line 249 of file CurlHandleManager.cpp.

250{
251 return mHandle;
252}

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ getHTTPCode()

unsigned audacity::network_manager::CurlHandleManager::Handle::getHTTPCode ( ) const
noexcept

Definition at line 230 of file CurlHandleManager.cpp.

231{
232 long code = 0;
233
234 if (CURLE_OK != curl_easy_getinfo(mHandle, CURLINFO_RESPONSE_CODE, &code))
235 return 0;
236
237 return code;
238}

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ isHandleFromCache()

bool audacity::network_manager::CurlHandleManager::Handle::isHandleFromCache ( ) const
noexcept

Definition at line 225 of file CurlHandleManager.cpp.

226{
227 return mHandleFromCache;
228}

◆ markKeepAlive()

void audacity::network_manager::CurlHandleManager::Handle::markKeepAlive ( )

Definition at line 220 of file CurlHandleManager.cpp.

221{
222 mReuse = true;
223}

◆ operator=()

CurlHandleManager::Handle & audacity::network_manager::CurlHandleManager::Handle::operator= ( Handle &&  rhs)
noexcept

Definition at line 147 of file CurlHandleManager.cpp.

148{
149 std::swap (mHandle, rhs.mHandle);
150 std::swap (mOwner, rhs.mOwner);
151
152 std::swap (mVerb, rhs.mVerb);
153
154 mUrl = std::move (rhs.mUrl);
155 mHeaders = std::move (rhs.mHeaders);
156
157 mReuse = rhs.mReuse;
158 rhs.mReuse = false;
159
160 return *this;
161}
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

References anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ perform()

CurlHandleManager::Handle::Result audacity::network_manager::CurlHandleManager::Handle::perform ( )

Definition at line 200 of file CurlHandleManager.cpp.

201{
202 if (!mUserAgentSet)
203 mHeaders.append ("User-Agent: " + mOwner->getUserAgent ());
204
205 CURLcode result = setOption (CURLOPT_HTTPHEADER, mHeaders.getCurlList ());
206
207 if (result != CURLE_OK)
208 return { result, std::string () };
209
210 char currentError[CURL_ERROR_SIZE] = {};
211 setOption(CURLOPT_ERRORBUFFER, currentError);
212
213 result = curl_easy_perform (mHandle);
214
215 mReuse = mReuse && result == CURLE_OK;
216
217 return { result, std::string (currentError) };
218}
curl_slist * getCurlList() const noexcept

Referenced by audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ reset()

void audacity::network_manager::CurlHandleManager::Handle::reset ( )
noexcept

Definition at line 240 of file CurlHandleManager.cpp.

241{
242 setOption (CURLOPT_COOKIELIST, nullptr);
243 setOption (CURLOPT_PROXY, nullptr);
244 setOption (CURLOPT_SSL_OPTIONS, 0);
245
246 mUserAgentSet = false;
247}

Referenced by audacity::network_manager::CurlHandleManager::cacheHandle().

Here is the caller graph for this function:

◆ setOption() [1/2]

template<typename... Args>
CURLcode audacity::network_manager::CurlHandleManager::Handle::setOption ( CURLoption  option,
Args...  value 
)
inlinenoexcept

Definition at line 45 of file CurlHandleManager.h.

46 {
47 return curl_easy_setopt (mHandle, option, value...);
48 }

References mHandle.

Referenced by audacity::network_manager::CurlHandleManager::getHandle(), and audacity::network_manager::CurlResponse::perform().

Here is the caller graph for this function:

◆ setOption() [2/2]

CURLcode audacity::network_manager::CurlHandleManager::Handle::setOption ( CURLoption  option,
const std::string &  value 
)
noexcept

Definition at line 163 of file CurlHandleManager.cpp.

164{
165 return setOption (option, value.c_str ());
166}

Friends And Related Function Documentation

◆ CurlHandleManager

friend class CurlHandleManager
friend

Definition at line 36 of file CurlHandleManager.h.

Member Data Documentation

◆ mHandle

CURL* audacity::network_manager::CurlHandleManager::Handle::mHandle { nullptr }
private

◆ mHandleFromCache

bool audacity::network_manager::CurlHandleManager::Handle::mHandleFromCache { false }
private

Definition at line 89 of file CurlHandleManager.h.

◆ mHeaders

CurlStringList audacity::network_manager::CurlHandleManager::Handle::mHeaders
private

Definition at line 85 of file CurlHandleManager.h.

◆ mOwner

CurlHandleManager* audacity::network_manager::CurlHandleManager::Handle::mOwner { nullptr }
private

Definition at line 80 of file CurlHandleManager.h.

Referenced by ~Handle().

◆ mReuse

bool audacity::network_manager::CurlHandleManager::Handle::mReuse { false }
private

Definition at line 88 of file CurlHandleManager.h.

Referenced by ~Handle().

◆ mUrl

std::string audacity::network_manager::CurlHandleManager::Handle::mUrl
private

◆ mUserAgentSet

bool audacity::network_manager::CurlHandleManager::Handle::mUserAgentSet { false }
private

Definition at line 87 of file CurlHandleManager.h.

◆ mVerb

RequestVerb audacity::network_manager::CurlHandleManager::Handle::mVerb
private

The documentation for this class was generated from the following files: