13#ifndef CPL_VSIL_CURL_CLASS_H_INCLUDED
14#define CPL_VSIL_CURL_CLASS_H_INCLUDED
24#include "cpl_vsil_curl_priv.h"
25#include "cpl_mem_cache.h"
26#include "cpl_multiproc.h"
28#include "cpl_curl_priv.h"
32#include <condition_variable>
48#define HAVE_CURLINFO_REDIRECT_URL
50void VSICurlStreamingClearCache(
void);
52struct curl_slist *VSICurlSetOptions(CURL *hCurlHandle,
const char *pszURL,
53 const char *
const *papszOptions);
55struct curl_slist *VSICurlSetContentTypeFromExt(
struct curl_slist *polist,
58struct curl_slist *VSICurlSetCreationHeadersFromOptions(
59 struct curl_slist *headers,
CSLConstList papszOptions,
const char *pszPath);
74 unsigned int nGenerationAuthParameters = 0;
75 ExistStatus eExists = EXIST_UNKNOWN;
79 time_t nExpireTimestampLocal = 0;
80 std::string osRedirectURL{};
81 bool bHasComputedFileSize =
false;
82 bool bIsDirectory =
false;
83 bool bIsAzureFolder =
false;
85 bool bS3LikeRedirect =
false;
91 bool bGotFileList =
false;
92 unsigned int nGenerationAuthParameters = 0;
93 CPLStringList oFileList{};
98 char *pBuffer =
nullptr;
100 bool bIsHTTP =
false;
101 bool bMultiRange =
false;
105 int nFirstHTTPCode = 0;
107 bool bFoundContentRange =
false;
109 bool bInterruptDownload =
false;
110 bool bDetectRangeDownloadingError =
false;
114 VSICurlReadCbkFunc pfnReadCbk =
nullptr;
115 void *pReadCbkUserData =
nullptr;
116 bool bInterrupted =
false;
121 const GByte *pabyData =
nullptr;
123 size_t nTotalSize = 0;
125 static size_t ReadCallBackBuffer(
char *buffer,
size_t size,
size_t nitems,
128 PutData *poThis =
static_cast<PutData *
>(instream);
129 const size_t nSizeMax = size * nitems;
130 const size_t nSizeToWrite =
131 std::min(nSizeMax, poThis->nTotalSize - poThis->nOff);
132 memcpy(buffer, poThis->pabyData + poThis->nOff, nSizeToWrite);
133 poThis->nOff += nSizeToWrite;
144class VSICurlFilesystemHandlerBase :
public VSIFilesystemHandler
148 struct FilenameOffsetPair
150 std::string filename_;
153 FilenameOffsetPair(
const std::string &filename,
vsi_l_offset offset)
154 : filename_(filename), offset_(offset)
158 bool operator==(
const FilenameOffsetPair &other)
const
160 return filename_ == other.filename_ && offset_ == other.offset_;
164 struct FilenameOffsetPairHasher
166 std::size_t operator()(
const FilenameOffsetPair &k)
const
168 return std::hash<std::string>()(k.filename_) ^
169 std::hash<vsi_l_offset>()(k.offset_);
173 using RegionCacheType = lru11::Cache<
174 FilenameOffsetPair, std::shared_ptr<std::string>, lru11::NullLock,
177 typename std::list<lru11::KeyValuePair<
178 FilenameOffsetPair, std::shared_ptr<std::string>>>::iterator,
179 FilenameOffsetPairHasher>>;
181 std::unique_ptr<RegionCacheType>
182 m_poRegionCacheDoNotUseDirectly{};
184 RegionCacheType *GetRegionCache();
191 lru11::Cache<std::string, bool> oCacheFileProp;
193 int nCachedFilesInDirList = 0;
194 lru11::Cache<std::string, CachedDirList> oCacheDirList;
196 char **ParseHTMLFileList(
const char *pszFilename,
int nMaxFiles,
197 char *pszData,
bool *pbGotFileList);
202 struct RegionInDownload
205 std::condition_variable oCond{};
206 bool bDownloadInProgress =
false;
208 std::string osData{};
211 std::mutex m_oMutex{};
212 std::map<std::string, std::unique_ptr<RegionInDownload>>
213 m_oMapRegionInDownload{};
216 CPLMutex *hMutex =
nullptr;
218 virtual VSICurlHandle *CreateFileHandle(
const char *pszFilename);
219 virtual char **GetFileList(
const char *pszFilename,
int nMaxFiles,
220 bool *pbGotFileList);
222 void RegisterEmptyDir(
const std::string &osDirname);
225 AnalyseS3FileList(
const std::string &osBaseURL,
const char *pszXML,
226 CPLStringList &osFileList,
int nMaxFiles,
227 const std::set<std::string> &oSetIgnoredStorageClasses,
230 void AnalyseSwiftFileList(
const std::string &osBaseURL,
231 const std::string &osPrefix,
const char *pszJson,
232 CPLStringList &osFileList,
int nMaxFilesThisQuery,
233 int nMaxFiles,
bool &bIsTruncated,
234 std::string &osNextMarker);
236 static const char *GetOptionsStatic();
238 VSICurlFilesystemHandlerBase();
241 ~VSICurlFilesystemHandlerBase()
override;
243 static bool IsAllowedFilename(
const char *pszFilename);
245 VSIVirtualHandleUniquePtr Open(
const char *pszFilename,
246 const char *pszAccess,
bool bSetError,
249 int Stat(
const char *pszFilename,
VSIStatBufL *pStatBuf,
250 int nFlags)
override;
251 char **ReadDirEx(
const char *pszDirname,
int nMaxFiles)
override;
252 char **SiblingFiles(
const char *pszFilename)
override;
254 int HasOptimizedReadMultiRange(
const char * )
override
259 const char *GetActualURL(
const char *pszFilename)
override;
261 const char *GetOptions()
override;
263 char **GetFileMetadata(
const char *pszFilename,
const char *pszDomain,
266 char **ReadDirInternal(
const char *pszDirname,
int nMaxFiles,
267 bool *pbGotFileList);
268 void InvalidateDirContent(
const std::string &osDirname);
270 virtual const char *GetDebugKey()
const = 0;
272 virtual std::string GetFSPrefix()
const = 0;
273 virtual bool AllowCachedDataFor(
const char *pszFilename);
275 bool IsLocal(
const char * )
const override
281 SupportsSequentialWrite(
const char * ,
287 virtual bool SupportsRandomWrite(
const char * ,
293 std::shared_ptr<std::string> GetRegion(
const char *pszURL,
296 void AddRegion(
const char *pszURL,
vsi_l_offset nFileOffsetStart,
297 size_t nSize,
const char *pData);
299 std::pair<bool, std::string>
300 NotifyStartDownloadRegion(
const std::string &osURL,
302 void NotifyStopDownloadRegion(
const std::string &osURL,
304 const std::string &osData);
306 bool GetCachedFileProp(
const char *pszURL, FileProp &oFileProp);
307 void SetCachedFileProp(
const char *pszURL, FileProp &oFileProp);
308 void InvalidateCachedData(
const char *pszURL);
310 CURLM *GetCurlMultiHandleFor(
const std::string &osURL);
312 virtual void ClearCache();
313 virtual void PartialClearCache(
const char *pszFilename);
315 bool GetCachedDirList(
const char *pszURL, CachedDirList &oCachedDirList);
316 void SetCachedDirList(
const char *pszURL, CachedDirList &oCachedDirList);
317 bool ExistsInCacheDirList(
const std::string &osDirname,
bool *pbIsDir);
319 virtual std::string GetURLFromFilename(
const std::string &osFilename)
const;
322 GetStreamingFilename(
const std::string &osFilename)
const override = 0;
324 static std::set<std::string> GetS3IgnoredStorageClasses();
327class VSICurlFilesystemHandler final :
public VSICurlFilesystemHandlerBase
332 VSICurlFilesystemHandler() =
default;
334 const char *GetDebugKey()
const override
339 std::string GetFSPrefix()
const override
345 GetStreamingFilename(
const std::string &osFilename)
const override;
352class VSICurlHandle :
public VSIVirtualHandle
357 VSICurlFilesystemHandlerBase *poFS =
nullptr;
359 bool m_bCached =
true;
361 mutable FileProp oFileProp{};
363 mutable std::mutex m_oMutex{};
364 std::string m_osFilename{};
365 char *m_pszURL =
nullptr;
366 mutable std::string m_osQueryString{};
368 CPLStringList m_aosHTTPOptions{};
369 CPLHTTPRetryParameters
373 int nBlocksToDownload = 1;
375 bool bStopOnInterruptUntilUninstall =
false;
376 bool bInterrupted =
false;
377 VSICurlReadCbkFunc pfnReadCbk =
nullptr;
378 void *pReadCbkUserData =
nullptr;
380 CPLStringList m_aosHeaders{};
382 void DownloadRegionPostProcess(
const vsi_l_offset startOffset,
383 const int nBlocks,
const char *pBuffer,
392 virtual std::string DownloadRegion(
vsi_l_offset startOffset,
int nBlocks);
394 bool m_bUseHead =
false;
395 bool m_bUseRedirectURLIfNoQueryStringParams =
false;
397 mutable std::atomic<bool> m_bInterrupt =
false;
401 mutable bool m_bPlanetaryComputerURLSigning =
false;
402 mutable std::string m_osPlanetaryComputerCollection{};
403 void ManagePlanetaryComputerSigning()
const;
405 void UpdateQueryString()
const;
407 int ReadMultiRangeSingleGet(
int nRanges,
void **ppData,
409 const size_t *panSizes);
410 std::string GetRedirectURLIfValid(
bool &bHasExpired,
411 CPLStringList &aosHTTPOptions)
const;
413 void UpdateRedirectInfo(CURL *hCurlHandle,
414 const WriteFuncStruct &sWriteFuncHeaderData);
417 struct AdviseReadRange
420 bool bToRetry =
true;
421 double dfSleepDelay = 0.0;
423 std::condition_variable oCV{};
426 std::vector<GByte> abyData{};
427 CPLHTTPRetryContext retryContext;
429 explicit AdviseReadRange(
const CPLHTTPRetryParameters &oRetryParameters)
430 : retryContext(oRetryParameters)
434 AdviseReadRange(
const AdviseReadRange &) =
delete;
435 AdviseReadRange &operator=(
const AdviseReadRange &) =
delete;
436 AdviseReadRange(AdviseReadRange &&) =
delete;
437 AdviseReadRange &operator=(AdviseReadRange &&) =
delete;
440 std::vector<std::unique_ptr<AdviseReadRange>> m_aoAdviseReadRanges{};
441 std::thread m_oThreadAdviseRead{};
442 CURLM *m_hCurlMultiHandleForAdviseRead =
nullptr;
445 virtual struct curl_slist *GetCurlHeaders(
const std::string & ,
446 struct curl_slist *psHeaders)
451 virtual bool AllowAutomaticRedirection()
456 virtual bool CanRestartOnError(
const char *,
const char *,
bool)
461 virtual bool UseLimitRangeGetInsteadOfHead()
466 virtual bool IsDirectoryFromExists(
const char * ,
472 virtual void ProcessGetFileSizeResult(
const char * )
476 void SetURL(
const char *pszURL);
478 virtual bool Authenticate(
const char * )
484 VSICurlHandle(VSICurlFilesystemHandlerBase *poFS,
const char *pszFilename,
485 const char *pszURLIn =
nullptr);
486 ~VSICurlHandle()
override;
490 size_t Read(
void *pBuffer,
size_t nSize,
size_t nMemb)
override;
491 int ReadMultiRange(
int nRanges,
void **ppData,
493 const size_t *panSizes)
override;
494 size_t Write(
const void *pBuffer,
size_t nSize,
size_t nMemb)
override;
495 void ClearErr()
override;
497 int Error()
override;
498 int Flush()
override;
499 int Close()
override;
501 void Interrupt()
override
506 bool HasPRead()
const override
511 size_t PRead(
void *pBuffer,
size_t nSize,
514 void AdviseRead(
int nRanges,
const vsi_l_offset *panOffsets,
515 const size_t *panSizes)
override;
517 size_t GetAdviseReadTotalBytesLimit()
const override;
519 bool IsKnownFileSize()
const
521 return oFileProp.bHasComputedFileSize;
524 vsi_l_offset GetFileSizeOrHeaders(
bool bSetError,
bool bGetHeaders);
528 return GetFileSizeOrHeaders(bSetError,
false);
531 bool Exists(
bool bSetError);
533 bool IsDirectory()
const
535 return oFileProp.bIsDirectory;
540 return oFileProp.nMode;
543 time_t GetMTime()
const
545 return oFileProp.mTime;
548 const CPLStringList &GetHeaders()
553 int InstallReadCbk(VSICurlReadCbkFunc pfnReadCbk,
void *pfnUserData,
554 int bStopOnInterruptUntilUninstall);
555 int UninstallReadCbk();
557 const char *GetURL()
const
563 void SetCache(
bool bCache)
573class VSICurlFilesystemHandlerBaseWritable
574 :
public VSICurlFilesystemHandlerBase
579 VSICurlFilesystemHandlerBaseWritable() =
default;
581 virtual VSIVirtualHandleUniquePtr
582 CreateWriteHandle(
const char *pszFilename,
CSLConstList papszOptions) = 0;
585 VSIVirtualHandleUniquePtr Open(
const char *pszFilename,
586 const char *pszAccess,
bool bSetError,
589 bool SupportsSequentialWrite(
const char * ,
595 bool SupportsRandomWrite(
const char * ,
603class IVSIS3LikeFSHandler
604 :
public VSICurlFilesystemHandlerBaseWritable
608 virtual int MkdirInternal(
const char *pszDirname,
long nMode,
612 char **GetFileList(
const char *pszFilename,
int nMaxFiles,
613 bool *pbGotFileList)
override;
615 virtual IVSIS3LikeHandleHelper *CreateHandleHelper(
const char *pszURI,
616 bool bAllowNoObject) = 0;
618 virtual int CopyObject(
const char *oldpath,
const char *newpath,
621 int RmdirRecursiveInternal(
const char *pszDirname,
int nBatchSize);
624 IsAllowedHeaderForObjectCreation(
const char * )
629 IVSIS3LikeFSHandler() =
default;
632 int Unlink(
const char *pszFilename)
override;
633 int Mkdir(
const char *pszDirname,
long nMode)
override;
634 int Rmdir(
const char *pszDirname)
override;
635 int Stat(
const char *pszFilename,
VSIStatBufL *pStatBuf,
636 int nFlags)
override;
637 int Rename(
const char *oldpath,
const char *newpath, GDALProgressFunc,
640 virtual int CopyFile(
const char *pszSource,
const char *pszTarget,
642 const char *
const *papszOptions,
643 GDALProgressFunc pProgressFunc,
644 void *pProgressData)
override;
646 virtual int DeleteObject(
const char *pszFilename);
648 virtual int *DeleteObjectBatch(
CSLConstList papszFilesOrDirs);
650 bool Sync(
const char *pszSource,
const char *pszTarget,
651 const char *
const *papszOptions, GDALProgressFunc pProgressFunc,
652 void *pProgressData,
char ***ppapszOutputs)
override;
654 VSIDIR *OpenDir(
const char *pszPath,
int nRecurseDepth,
655 const char *
const *papszOptions)
override;
662class IVSIS3LikeFSHandlerWithMultipartUpload
663 :
public IVSIS3LikeFSHandler
668 IVSIS3LikeFSHandlerWithMultipartUpload() =
default;
671 virtual bool SupportsNonSequentialMultipartUpload()
const
676 virtual bool SupportsParallelMultipartUpload()
const
681 virtual bool SupportsMultipartAbort()
const = 0;
683 size_t GetUploadChunkSizeInBytes(
const char *pszFilename,
684 const char *pszSpecifiedValInBytes);
686 virtual int CopyFileRestartable(
const char *pszSource,
687 const char *pszTarget,
688 const char *pszInputPayload,
689 char **ppszOutputPayload,
691 GDALProgressFunc pProgressFunc,
692 void *pProgressData)
override;
698 virtual int GetMaximumPartCount()
707 virtual int GetMinimumPartSizeInMiB()
716 virtual int GetMaximumPartSizeInMiB()
728 virtual int GetDefaultPartSizeInMiB()
734 InitiateMultipartUpload(
const std::string &osFilename,
735 IVSIS3LikeHandleHelper *poS3HandleHelper,
736 const CPLHTTPRetryParameters &oRetryParameters,
740 UploadPart(
const std::string &osFilename,
int nPartNumber,
742 const void *pabyBuffer,
size_t nBufferSize,
743 IVSIS3LikeHandleHelper *poS3HandleHelper,
744 const CPLHTTPRetryParameters &oRetryParameters,
747 virtual bool CompleteMultipart(
748 const std::string &osFilename,
const std::string &osUploadID,
749 const std::vector<std::string> &aosEtags,
vsi_l_offset nTotalSize,
750 IVSIS3LikeHandleHelper *poS3HandleHelper,
751 const CPLHTTPRetryParameters &oRetryParameters);
753 virtual bool AbortMultipart(
const std::string &osFilename,
754 const std::string &osUploadID,
755 IVSIS3LikeHandleHelper *poS3HandleHelper,
756 const CPLHTTPRetryParameters &oRetryParameters);
758 bool AbortPendingUploads(
const char *pszFilename)
override;
760 bool MultipartUploadGetCapabilities(
int *pbNonSequentialUploadSupported,
761 int *pbParallelUploadSupported,
762 int *pbAbortSupported,
763 size_t *pnMinPartSize,
764 size_t *pnMaxPartSize,
765 int *pnMaxPartCount)
override;
767 char *MultipartUploadStart(
const char *pszFilename,
770 char *MultipartUploadAddPart(
const char *pszFilename,
771 const char *pszUploadId,
int nPartNumber,
776 bool MultipartUploadEnd(
const char *pszFilename,
const char *pszUploadId,
777 size_t nPartIdsCount,
778 const char *
const *apszPartIds,
782 bool MultipartUploadAbort(
const char *pszFilename,
const char *pszUploadId,
790class IVSIS3LikeHandle :
public VSICurlHandle
795 bool UseLimitRangeGetInsteadOfHead()
override
800 bool IsDirectoryFromExists(
const char *pszVerb,
int response_code)
override
803 return response_code == 416 &&
EQUAL(pszVerb,
"GET") &&
804 std::string(m_pszURL).back() ==
'/';
807 void ProcessGetFileSizeResult(
const char *pszContent)
override
809 oFileProp.bIsDirectory =
810 strstr(pszContent,
"ListBucketResult") !=
nullptr;
814 IVSIS3LikeHandle(VSICurlFilesystemHandlerBase *poFSIn,
815 const char *pszFilename,
const char *pszURLIn)
816 : VSICurlHandle(poFSIn, pszFilename, pszURLIn)
820 ~IVSIS3LikeHandle()
override;
827class VSIMultipartWriteHandle final :
public VSIVirtualHandle
831 IVSIS3LikeFSHandlerWithMultipartUpload *m_poFS =
nullptr;
832 std::string m_osFilename{};
833 IVSIS3LikeHandleHelper *m_poS3HandleHelper =
nullptr;
834 CPLStringList m_aosOptions{};
835 CPLStringList m_aosHTTPOptions{};
836 CPLHTTPRetryParameters m_oRetryParameters;
839 size_t m_nBufferOff = 0;
840 size_t m_nBufferSize = 0;
841 bool m_bClosed =
false;
842 GByte *m_pabyBuffer =
nullptr;
843 std::string m_osUploadID{};
844 int m_nPartNumber = 0;
845 std::vector<std::string> m_aosEtags{};
846 bool m_bError =
false;
848 WriteFuncStruct m_sWriteFuncHeaderData{};
851 bool DoSinglePartPUT();
853 void InvalidateParentDirectory();
856 VSIMultipartWriteHandle(IVSIS3LikeFSHandlerWithMultipartUpload *poFS,
857 const char *pszFilename,
858 IVSIS3LikeHandleHelper *poS3HandleHelper,
860 ~VSIMultipartWriteHandle()
override;
864 size_t Read(
void *pBuffer,
size_t nSize,
size_t nMemb)
override;
865 size_t Write(
const void *pBuffer,
size_t nSize,
size_t nMemb)
override;
867 void ClearErr()
override
881 int Close()
override;
885 return m_pabyBuffer !=
nullptr;
896class VSIChunkedWriteHandle final :
public VSIVirtualHandle
900 IVSIS3LikeFSHandler *m_poFS =
nullptr;
901 std::string m_osFilename{};
902 IVSIS3LikeHandleHelper *m_poS3HandleHelper =
nullptr;
903 CPLStringList m_aosOptions{};
904 CPLStringList m_aosHTTPOptions{};
905 CPLHTTPRetryParameters m_oRetryParameters;
908 size_t m_nBufferOff = 0;
909 bool m_bError =
false;
910 bool m_bClosed =
false;
912 CURLM *m_hCurlMulti =
nullptr;
913 CURL *m_hCurl =
nullptr;
914 const void *m_pBuffer =
nullptr;
915 std::string m_osCurlErrBuf{};
916 size_t m_nChunkedBufferOff = 0;
917 size_t m_nChunkedBufferSize = 0;
918 size_t m_nWrittenInPUT = 0;
920 WriteFuncStruct m_sWriteFuncHeaderData{};
922 static size_t ReadCallBackBufferChunked(
char *buffer,
size_t size,
923 size_t nitems,
void *instream);
924 int FinishChunkedTransfer();
928 void InvalidateParentDirectory();
931 VSIChunkedWriteHandle(IVSIS3LikeFSHandler *poFS,
const char *pszFilename,
932 IVSIS3LikeHandleHelper *poS3HandleHelper,
934 ~VSIChunkedWriteHandle()
override;
938 size_t Read(
void *pBuffer,
size_t nSize,
size_t nMemb)
override;
939 size_t Write(
const void *pBuffer,
size_t nSize,
size_t nMemb)
override;
941 void ClearErr()
override
955 int Close()
override;
962class VSIAppendWriteHandle
CPL_NON_FINAL :
public VSIVirtualHandle
967 VSICurlFilesystemHandlerBase *m_poFS =
nullptr;
968 std::string m_osFSPrefix{};
969 std::string m_osFilename{};
970 CPLHTTPRetryParameters m_oRetryParameters{};
973 int m_nBufferOff = 0;
974 int m_nBufferSize = 0;
975 int m_nBufferOffReadCallback = 0;
976 bool m_bClosed =
false;
977 GByte *m_pabyBuffer =
nullptr;
978 bool m_bError =
false;
980 static size_t ReadCallBackBuffer(
char *buffer,
size_t size,
size_t nitems,
982 virtual bool Send(
bool bIsLastBlock) = 0;
985 VSIAppendWriteHandle(VSICurlFilesystemHandlerBase *poFS,
986 const char *pszFSPrefix,
const char *pszFilename,
988 ~VSIAppendWriteHandle()
override;
992 size_t Read(
void *pBuffer,
size_t nSize,
size_t nMemb)
override;
993 size_t Write(
const void *pBuffer,
size_t nSize,
size_t nMemb)
override;
995 void ClearErr()
override
1009 int Close()
override;
1013 return m_pabyBuffer !=
nullptr;
1021struct VSIDIRWithMissingDirSynthesis :
public VSIDIR
1023 std::vector<std::unique_ptr<VSIDIREntry>> aoEntries{};
1026 ~VSIDIRWithMissingDirSynthesis()
override;
1028 std::vector<std::string> m_aosSubpathsStack{};
1030 void SynthetizeMissingDirectories(
const std::string &osCurSubdir,
1031 bool bAddEntryForThisSubdir);
1038struct VSIDIRS3Like :
public VSIDIRWithMissingDirSynthesis
1040 const std::string m_osDirName;
1042 int nRecurseDepth = 0;
1044 std::string osNextMarker{};
1047 std::string osBucket{};
1048 std::string osObjectKey{};
1049 VSICurlFilesystemHandlerBase *poFS =
nullptr;
1050 IVSIS3LikeFSHandler *poS3FS =
nullptr;
1051 std::unique_ptr<IVSIS3LikeHandleHelper> poHandleHelper{};
1053 bool bCacheEntries =
true;
1054 bool m_bSynthetizeMissingDirectories =
false;
1055 std::string m_osFilterPrefix{};
1061 VSIDIRS3Like(
const std::string &osDirName, IVSIS3LikeFSHandler *poFSIn)
1062 : m_osDirName(osDirName), poFS(poFSIn), poS3FS(poFSIn)
1066 VSIDIRS3Like(
const std::string &osDirName,
1067 VSICurlFilesystemHandlerBase *poFSIn)
1068 : m_osDirName(osDirName), poFS(poFSIn)
1072 VSIDIRS3Like(
const VSIDIRS3Like &) =
delete;
1073 VSIDIRS3Like &operator=(
const VSIDIRS3Like &) =
delete;
1075 const VSIDIREntry *NextDirEntry()
override;
1077 virtual bool IssueListDir() = 0;
1085struct CurlRequestHelper
1087 WriteFuncStruct sWriteFuncData{};
1088 WriteFuncStruct sWriteFuncHeaderData{};
1089 char szCurlErrBuf[CURL_ERROR_SIZE + 1] = {};
1091 CurlRequestHelper();
1092 ~CurlRequestHelper();
1093 long perform(CURL *hCurlHandle,
1094 struct curl_slist *headers,
1095 VSICurlFilesystemHandlerBase *poFS,
1096 IVSIS3LikeHandleHelper *poS3HandleHelper);
1103class NetworkStatisticsLogger
1105 static int gnEnabled;
1106 static NetworkStatisticsLogger gInstance;
1108 NetworkStatisticsLogger() =
default;
1110 std::mutex m_mutex{};
1119 GIntBig nGETDownloadedBytes = 0;
1120 GIntBig nPUTUploadedBytes = 0;
1121 GIntBig nPOSTDownloadedBytes = 0;
1122 GIntBig nPOSTUploadedBytes = 0;
1125 enum class ContextPathType
1132 struct ContextPathItem
1134 ContextPathType eType;
1137 ContextPathItem(ContextPathType eTypeIn,
const std::string &osNameIn)
1138 : eType(eTypeIn), osName(osNameIn)
1142 bool operator<(
const ContextPathItem &other)
const
1144 if (
static_cast<int>(eType) <
static_cast<int>(other.eType))
1146 if (
static_cast<int>(eType) >
static_cast<int>(other.eType))
1148 return osName < other.osName;
1154 Counters counters{};
1155 std::map<ContextPathItem, Stats> children{};
1157 void AsJSON(CPLJSONObject &oJSON)
const;
1163 std::map<GIntBig, std::vector<ContextPathItem>>
1164 m_mapThreadIdToContextPath{};
1166 static void ReadEnabled();
1168 std::vector<Counters *> GetCountersForContext();
1171 static inline bool IsEnabled()
1177 return gnEnabled == TRUE;
1180 static void EnterFileSystem(
const char *pszName);
1182 static void LeaveFileSystem();
1184 static void EnterFile(
const char *pszName);
1186 static void LeaveFile();
1188 static void EnterAction(
const char *pszName);
1190 static void LeaveAction();
1192 static void LogHEAD();
1194 static void LogGET(
size_t nDownloadedBytes);
1196 static void LogPUT(
size_t nUploadedBytes);
1198 static void LogPOST(
size_t nUploadedBytes,
size_t nDownloadedBytes);
1200 static void LogDELETE();
1202 static void Reset();
1204 static std::string GetReportAsSerializedJSON();
1207struct NetworkStatisticsFileSystem
1209 inline explicit NetworkStatisticsFileSystem(
const char *pszName)
1211 NetworkStatisticsLogger::EnterFileSystem(pszName);
1214 inline ~NetworkStatisticsFileSystem()
1216 NetworkStatisticsLogger::LeaveFileSystem();
1220struct NetworkStatisticsFile
1222 inline explicit NetworkStatisticsFile(
const char *pszName)
1224 NetworkStatisticsLogger::EnterFile(pszName);
1227 inline ~NetworkStatisticsFile()
1229 NetworkStatisticsLogger::LeaveFile();
1233struct NetworkStatisticsAction
1235 inline explicit NetworkStatisticsAction(
const char *pszName)
1237 NetworkStatisticsLogger::EnterAction(pszName);
1240 inline ~NetworkStatisticsAction()
1242 NetworkStatisticsLogger::LeaveAction();
1248int VSICURLGetDownloadChunkSize();
1250void VSICURLInitWriteFuncStruct(cpl::WriteFuncStruct *psStruct,
VSILFILE *fp,
1251 VSICurlReadCbkFunc pfnReadCbk,
1252 void *pReadCbkUserData);
1253size_t VSICurlHandleWriteFunc(
void *buffer,
size_t count,
size_t nmemb,
1255void VSICURLMultiPerform(CURLM *hCurlMultiHandle, CURL *hEasyHandle =
nullptr,
1256 std::atomic<bool> *pbInterrupt =
nullptr);
1257void VSICURLResetHeaderAndWriterFunctions(CURL *hCurlHandle);
1259int VSICurlParseUnixPermissions(
const char *pszPermissions);
1262bool VSICURLGetCachedFileProp(
const char *pszURL, cpl::FileProp &oFileProp);
1263void VSICURLSetCachedFileProp(
const char *pszURL, cpl::FileProp &oFileProp);
1264void VSICURLInvalidateCachedFileProp(
const char *pszURL);
1265void VSICURLInvalidateCachedFilePropPrefix(
const char *pszURL);
1266void VSICURLDestroyCacheFileProp();
1268void VSICURLMultiCleanup(CURLM *hCurlMultiHandle);
Interface for downloading HTTP, FTP documents.
Interface for read and write JSON documents.
Core portability definitions for CPL.
#define CPL_NON_FINAL
Mark that a class is explicitly recognized as non-final.
Definition cpl_port.h:929
#define EQUAL(a, b)
Alias for strcasecmp() == 0.
Definition cpl_port.h:541
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:175
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
Various convenience functions for working with strings and string lists.
#define VSIStatBufL
Type for VSIStatL().
Definition cpl_vsi.h:195
struct VSIVirtualHandle VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition cpl_vsi.h:141
#define VSI_L_OFFSET_MAX
Maximum value for a file offset.
Definition cpl_vsi.h:138
struct VSIDIR VSIDIR
Opaque type for a directory iterator.
Definition cpl_vsi.h:396
void VSICloseDir(VSIDIR *dir)
Close a directory.
Definition cpl_vsil.cpp:599
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136