14#ifndef CPL_HTTP_H_INCLUDED
15#define CPL_HTTP_H_INCLUDED
19#include "cpl_progress.h"
29#ifndef CPL_HTTP_MAX_RETRY
30#define CPL_HTTP_MAX_RETRY 0
33#ifndef CPL_HTTP_RETRY_DELAY
34#define CPL_HTTP_RETRY_DELAY 30.0
81typedef size_t (*CPLHTTPFetchWriteFunc)(
void *pBuffer,
size_t nSize,
82 size_t nMemb,
void *pWriteArg);
85int CPL_DLL CPLHTTPEnabled(
void);
89CPLHTTPFetchEx(
const char *pszURL,
CSLConstList papszOptions,
90 GDALProgressFunc pfnProgress,
void *pProgressArg,
91 CPLHTTPFetchWriteFunc pfnWrite,
void *pWriteArg);
92CPLHTTPResult CPL_DLL **CPLHTTPMultiFetch(
const char *
const *papszURL,
93 int nURLCount,
int nMaxSimultaneous,
96void CPL_DLL CPLHTTPCleanup(
void);
98void CPL_DLL CPLHTTPDestroyMultiResult(
CPLHTTPResult **papsResults,
int nCount);
99int CPL_DLL CPLHTTPParseMultipartMime(
CPLHTTPResult *psResult);
101void CPL_DLL CPLHTTPSetDefaultUserAgent(
const char *pszUserAgent);
125 const char *pszURL,
CSLConstList papszOptions, GDALProgressFunc pfnProgress,
126 void *pProgressArg, CPLHTTPFetchWriteFunc pfnWrite,
void *pWriteArg,
134int CPL_DLL CPLHTTPPopFetchCallback(
void);
144char CPL_DLL *GOA2GetAuthorizationURL(
const char *pszScope);
145char CPL_DLL *GOA2GetRefreshToken(
const char *pszAuthToken,
146 const char *pszScope);
147char CPL_DLL *GOA2GetAccessToken(
const char *pszRefreshToken,
148 const char *pszScope);
150char CPL_DLL **GOA2GetAccessTokenFromServiceAccount(
151 const char *pszPrivateKey,
const char *pszClientEmail,
const char *pszScope,
154char CPL_DLL **GOA2GetAccessTokenFromCloudEngineVM(
CSLConstList papszOptions);
158#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
162void CPL_DLL *CPLHTTPSetOptions(
void *pcurl,
const char *pszURL,
163 const char *
const *papszOptions);
164char **CPLHTTPGetOptionsFromEnv(
const char *pszFilename);
167struct CPLHTTPRetryParameters
169 int nMaxRetry = CPL_HTTP_MAX_RETRY;
170 double dfInitialDelay = CPL_HTTP_RETRY_DELAY;
171 std::string osRetryCodes{};
173 CPLHTTPRetryParameters() =
default;
174 explicit CPLHTTPRetryParameters(
const CPLStringList &aosHTTPOptions);
178class CPLHTTPRetryContext
181 explicit CPLHTTPRetryContext(
const CPLHTTPRetryParameters &oParams);
183 bool CanRetry(
int response_code,
const char *pszErrBuf,
184 const char *pszCurlError);
188 double GetCurrentDelay()
const;
197 CPLHTTPRetryParameters m_oParameters{};
198 int m_nRetryCount = 0;
199 double m_dfCurDelay = 0.0;
200 double m_dfNextDelay = 0.0;
203void CPL_DLL *CPLHTTPIgnoreSigPipe();
204void CPL_DLL CPLHTTPRestoreSigPipeHandler(
void *old_handler);
205bool CPLMultiPerformWait(
void *hCurlMultiHandle,
int &repeats);
208bool CPL_DLL CPLIsMachinePotentiallyGCEInstance();
209bool CPLIsMachineForSureGCEInstance();
227 ACCESS_TOKEN_FROM_REFRESH,
233 const char *pszClientId,
234 const char *pszClientSecret,
237 const char *pszClientEmail,
238 const char *pszScope,
253 return m_osPrivateKey;
259 return m_osClientEmail;
267 std::string osKey(std::to_string(
static_cast<int>(m_eMethod))
268 .append(
",client-id=")
269 .append(m_osClientId)
270 .append(
",client-secret=")
271 .append(m_osClientSecret)
272 .append(
",refresh-token=")
273 .append(m_osRefreshToken)
274 .append(
",private-key=")
275 .append(m_osPrivateKey)
276 .append(
",client-email=")
277 .append(m_osClientEmail)
280 osKey.append(
",additional-claims=");
281 for (
const auto *pszOption : m_aosAdditionalClaims)
283 osKey.append(pszOption);
286 osKey.append(
",options=");
287 for (
const auto *pszOption : m_aosOptions)
289 osKey.append(pszOption);
297 mutable time_t m_nExpirationTime = 0;
302 CPLString m_osClientId{};
303 CPLString m_osClientSecret{};
304 CPLString m_osRefreshToken{};
307 CPLString m_osPrivateKey{};
308 CPLString m_osClientEmail{};
309 CPLString m_osScope{};
310 CPLStringList m_aosAdditionalClaims{};
312 CPLStringList m_aosOptions{};
Convenient string class based on std::string.
Definition cpl_string.h:338
const CPLString & GetClientEmail() const
Returns client email for SERVICE_ACCOUNT method.
Definition cpl_http.h:257
GOA2Manager()
Constructor.
AuthMethod GetAuthMethod() const
Returns the authentication method.
Definition cpl_http.h:243
bool SetAuthFromRefreshToken(const char *pszRefreshToken, const char *pszClientId, const char *pszClientSecret, CSLConstList papszOptions)
Specifies that the authentication will be done using the OAuth2 client id method.
Definition cpl_google_oauth2.cpp:546
std::string GetKey() const
Returns a key that can be used to uniquely identify the instance parameters (excluding bearer).
Definition cpl_http.h:265
bool SetAuthFromServiceAccount(const char *pszPrivateKey, const char *pszClientEmail, const char *pszScope, CSLConstList papszAdditionalClaims, CSLConstList papszOptions)
Specifies that the authentication will be done using the OAuth2 service account method.
Definition cpl_google_oauth2.cpp:581
const CPLString & GetPrivateKey() const
Returns private key for SERVICE_ACCOUNT method.
Definition cpl_http.h:251
const char * GetBearer() const
Return the access token.
Definition cpl_google_oauth2.cpp:624
bool SetAuthFromGCE(CSLConstList papszOptions)
Specifies that the authentication will be done using the local credentials of the current Google Comp...
Definition cpl_google_oauth2.cpp:522
AuthMethod
Authentication method.
Definition cpl_http.h:224
Various convenience functions for CPL.
CPLHTTPResult *(*) CPLHTTPFetchCallbackFunc(const char *pszURL, CSLConstList papszOptions, GDALProgressFunc pfnProgress, void *pProgressArg, CPLHTTPFetchWriteFunc pfnWrite, void *pWriteArg, void *pUserData)
Callback function to process network requests.
Definition cpl_http.h:124
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:279
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:275
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:165
Various convenience functions for working with strings and string lists.
GByte * pabyData
Definition cpl_http.h:67
int nStatus
Definition cpl_http.h:53
CPLMimePart * pasMimePart
Definition cpl_http.h:76
char * pszContentType
Definition cpl_http.h:56
int nDataAlloc
Definition cpl_http.h:64
char ** papszHeaders
Definition cpl_http.h:70
char * pszErrBuf
Definition cpl_http.h:59
int nMimePartCount
Definition cpl_http.h:73
int nDataLen
Definition cpl_http.h:62
char ** papszHeaders
Definition cpl_http.h:43
int nDataLen
Definition cpl_http.h:46
GByte * pabyData
Definition cpl_http.h:45