Line data Source code
1 : /********************************************************************** 2 : * 3 : * Name: cpl_alibaba_oss.h 4 : * Project: CPL - Common Portability Library 5 : * Purpose: Alibaba Cloud Object Storage Service 6 : * Author: Even Rouault <even.rouault at spatialys.com> 7 : * 8 : ********************************************************************** 9 : * Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #ifndef CPL_ALIBABA_OSS_INCLUDED_H 15 : #define CPL_ALIBABA_OSS_INCLUDED_H 16 : 17 : #ifndef DOXYGEN_SKIP 18 : 19 : #include <cstddef> 20 : 21 : #include "cpl_string.h" 22 : 23 : #ifdef HAVE_CURL 24 : 25 : #include <curl/curl.h> 26 : #include <map> 27 : #include "cpl_aws.h" 28 : 29 : class VSIOSSHandleHelper final : public IVSIS3LikeHandleHelper 30 : { 31 : CPL_DISALLOW_COPY_ASSIGN(VSIOSSHandleHelper) 32 : 33 : std::string m_osURL{}; 34 : std::string m_osSecretAccessKey{}; 35 : std::string m_osAccessKeyId{}; 36 : std::string m_osEndpoint{}; 37 : std::string m_osBucket{}; 38 : std::string m_osObjectKey{}; 39 : bool m_bUseHTTPS = false; 40 : bool m_bUseVirtualHosting = false; 41 : 42 : void RebuildURL() override; 43 : 44 : static bool GetConfiguration(const std::string &osPathForOption, 45 : CSLConstList papszOptions, 46 : std::string &osSecretAccessKey, 47 : std::string &osAccessKeyId); 48 : 49 : protected: 50 : public: 51 : VSIOSSHandleHelper(const std::string &osSecretAccessKey, 52 : const std::string &osAccessKeyId, 53 : const std::string &osEndpoint, 54 : const std::string &osBucket, 55 : const std::string &osObjectKey, bool bUseHTTPS, 56 : bool bUseVirtualHosting); 57 : ~VSIOSSHandleHelper(); 58 : 59 : static VSIOSSHandleHelper * 60 : BuildFromURI(const char *pszURI, const char *pszFSPrefix, 61 : bool bAllowNoObject, CSLConstList papszOptions = nullptr); 62 : static std::string BuildURL(const std::string &osEndpoint, 63 : const std::string &osBucket, 64 : const std::string &osObjectKey, bool bUseHTTPS, 65 : bool bUseVirtualHosting); 66 : 67 : struct curl_slist *GetCurlHeaders(const std::string &osVerb, 68 : struct curl_slist *psHeaders, 69 : const void *pabyDataContent = nullptr, 70 : size_t nBytesContent = 0) const override; 71 : 72 : bool CanRestartOnError(const char *, const char *pszHeaders, 73 : bool bSetError) override; 74 : 75 118 : const std::string &GetURL() const override 76 : { 77 118 : return m_osURL; 78 : } 79 : 80 88 : const std::string &GetBucket() const 81 : { 82 88 : return m_osBucket; 83 : } 84 : 85 : const std::string &GetObjectKey() const 86 : { 87 : return m_osObjectKey; 88 : } 89 : 90 1 : const std::string &GetEndpoint() const 91 : { 92 1 : return m_osEndpoint; 93 : } 94 : 95 : bool GetVirtualHosting() const 96 : { 97 : return m_bUseVirtualHosting; 98 : } 99 : 100 0 : std::string GetCopySourceHeader() const override 101 : { 102 0 : return "x-oss-copy-source"; 103 : } 104 : 105 : void SetEndpoint(const std::string &osStr); 106 : void SetVirtualHosting(bool b); 107 : 108 : std::string GetSignedURL(CSLConstList papszOptions); 109 : }; 110 : 111 : class VSIOSSUpdateParams 112 : { 113 : private: 114 : std::string m_osEndpoint{}; 115 : 116 1 : explicit VSIOSSUpdateParams(const VSIOSSHandleHelper *poHelper) 117 1 : : m_osEndpoint(poHelper->GetEndpoint()) 118 : { 119 1 : } 120 : 121 7 : void UpdateHandlerHelper(VSIOSSHandleHelper *poHelper) 122 : { 123 7 : poHelper->SetEndpoint(m_osEndpoint); 124 7 : } 125 : 126 : static std::mutex gsMutex; 127 : static std::map<std::string, VSIOSSUpdateParams> goMapBucketsToOSSParams; 128 : 129 : public: 130 1 : VSIOSSUpdateParams() = default; 131 : 132 : static void UpdateMapFromHandle(VSIOSSHandleHelper *poHandleHelper); 133 : static void UpdateHandleFromMap(VSIOSSHandleHelper *poHandleHelper); 134 : static void ClearCache(); 135 : }; 136 : 137 : #endif /* HAVE_CURL */ 138 : 139 : #endif /* #ifndef DOXYGEN_SKIP */ 140 : 141 : #endif /* CPL_ALIBABA_OSS_INCLUDED_H */