GDAL

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