Coverage Report

Created: 2025-12-31 08:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/port/cpl_alibaba_oss.h
Line
Count
Source
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() override;
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
    const std::string &GetURL() const override
76
0
    {
77
0
        return m_osURL;
78
0
    }
79
80
    const std::string &GetBucket() const
81
0
    {
82
0
        return m_osBucket;
83
0
    }
84
85
    const std::string &GetObjectKey() const
86
0
    {
87
0
        return m_osObjectKey;
88
0
    }
89
90
    const std::string &GetEndpoint() const
91
0
    {
92
0
        return m_osEndpoint;
93
0
    }
94
95
    bool GetVirtualHosting() const
96
0
    {
97
0
        return m_bUseVirtualHosting;
98
0
    }
99
100
    std::string GetCopySourceHeader() const override
101
0
    {
102
0
        return "x-oss-copy-source";
103
0
    }
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
    explicit VSIOSSUpdateParams(const VSIOSSHandleHelper *poHelper)
117
0
        : m_osEndpoint(poHelper->GetEndpoint())
118
0
    {
119
0
    }
120
121
    void UpdateHandlerHelper(VSIOSSHandleHelper *poHelper)
122
0
    {
123
0
        poHelper->SetEndpoint(m_osEndpoint);
124
0
    }
125
126
    static std::mutex gsMutex;
127
    static std::map<std::string, VSIOSSUpdateParams> goMapBucketsToOSSParams;
128
129
  public:
130
0
    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 */