GDAL
cpl_aws.h
1 /**********************************************************************
2  * $Id: cpl_aws.h 37174 2017-01-18 20:00:36Z rouault $
3  *
4  * Name: cpl_aws.h
5  * Project: CPL - Common Portability Library
6  * Purpose: Amazon Web Services routines
7  * Author: Even Rouault <even.rouault at spatialys.com>
8  *
9  **********************************************************************
10  * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef CPL_AWS_INCLUDED_H
32 #define CPL_AWS_INCLUDED_H
33 
34 #ifndef DOXYGEN_SKIP
35 
36 #include <cstddef>
37 
38 #include "cpl_string.h"
39 
40 CPLString CPLGetAWS_SIGN4_Authorization(const CPLString& osSecretAccessKey,
41  const CPLString& osAccessKeyId,
42  const CPLString& osAccessToken,
43  const CPLString& osAWSRegion,
44  const CPLString& osRequestPayer,
45  const CPLString& osService,
46  const CPLString& osVerb,
47  const CPLString& osHost,
48  const CPLString& osCanonicalURI,
49  const CPLString& osCanonicalQueryString,
50  const CPLString& osXAMZContentSHA256,
51  const CPLString& osTimestamp);
52 
53 CPLString CPLGetLowerCaseHexSHA256( const void *pabyData, size_t nBytes );
54 CPLString CPLGetLowerCaseHexSHA256( const CPLString& osStr );
55 
56 CPLString CPLGetAWS_SIGN4_Timestamp();
57 
58 CPLString CPLAWSURLEncode(const CPLString& osURL, bool bEncodeSlash = true);
59 
60 #ifdef HAVE_CURL
61 
62 #include <curl/curl.h>
63 #include <map>
64 
65 class VSIS3HandleHelper
66 {
67  CPLString m_osURL;
68  CPLString m_osSecretAccessKey;
69  CPLString m_osAccessKeyId;
70  CPLString m_osSessionToken;
71  CPLString m_osAWSS3Endpoint;
72  CPLString m_osAWSRegion;
73  CPLString m_osRequestPayer;
74  CPLString m_osBucket;
75  CPLString m_osObjectKey;
76  bool m_bUseHTTPS;
77  bool m_bUseVirtualHosting;
78  std::map<CPLString, CPLString> m_oMapQueryParameters;
79 
80  static bool GetBucketAndObjectKey(const char* pszURI, const char* pszFSPrefix,
81  bool bAllowNoObject,
82  CPLString &osBucketOut, CPLString &osObjectKeyOut);
83  void RebuildURL();
84 
85  protected:
86 
87  public:
88  VSIS3HandleHelper(const CPLString& osSecretAccessKey,
89  const CPLString& osAccessKeyId,
90  const CPLString& osSessionToken,
91  const CPLString& osAWSS3Endpoint,
92  const CPLString& osAWSRegion,
93  const CPLString& osRequestPayer,
94  const CPLString& osBucket,
95  const CPLString& osObjectKey,
96  bool bUseHTTPS, bool bUseVirtualHosting);
97  ~VSIS3HandleHelper();
98 
99  static VSIS3HandleHelper* BuildFromURI(const char* pszURI, const char* pszFSPrefix,
100  bool bAllowNoObject);
101  static CPLString BuildURL(const CPLString& osAWSS3Endpoint,
102  const CPLString& osBucket,
103  const CPLString& osObjectKey,
104  bool bUseHTTPS, bool bUseVirtualHosting);
105 
106  void ResetQueryParameters();
107  void AddQueryParameter(const CPLString& osKey, const CPLString& osValue);
108  struct curl_slist* GetCurlHeaders(const CPLString& osVerb,
109  const void *pabyDataContent = NULL,
110  size_t nBytesContent = 0);
111  bool CanRestartOnError(const char* pszErrorMsg) { return CanRestartOnError(pszErrorMsg, false); }
112  bool CanRestartOnError(const char*, bool bSetError);
113 
114  const CPLString& GetURL() const { return m_osURL; }
115  const CPLString& GetBucket() const { return m_osBucket; }
116  const CPLString& GetObjectKey() const { return m_osObjectKey; }
117  const CPLString& GetAWSS3Endpoint()const { return m_osAWSS3Endpoint; }
118  const CPLString& GetAWSRegion() const { return m_osAWSRegion; }
119  const CPLString& GetRequestPayer() const { return m_osRequestPayer; }
120  bool GetVirtualHosting() const { return m_bUseVirtualHosting; }
121  void SetAWSS3Endpoint(const CPLString &osStr);
122  void SetAWSRegion(const CPLString &osStr);
123  void SetRequestPayer(const CPLString &osStr);
124  void SetVirtualHosting(bool b);
125  void SetObjectKey(const CPLString &osStr);
126 };
127 
128 class VSIS3UpdateParams
129 {
130  public:
131  CPLString m_osAWSRegion;
132  CPLString m_osAWSS3Endpoint;
133  CPLString m_osRequestPayer;
134  bool m_bUseVirtualHosting;
135 
136  VSIS3UpdateParams(const CPLString& osAWSRegion = "",
137  const CPLString& osAWSS3Endpoint = "",
138  const CPLString& osRequestPayer = "",
139  bool bUseVirtualHosting = false) :
140  m_osAWSRegion(osAWSRegion),
141  m_osAWSS3Endpoint(osAWSS3Endpoint),
142  m_osRequestPayer(osRequestPayer),
143  m_bUseVirtualHosting(bUseVirtualHosting) {}
144 };
145 
146 #endif /* HAVE_CURL */
147 
148 #endif /* #ifndef DOXYGEN_SKIP */
149 
150 #endif /* CPL_AWS_INCLUDED_H */
Convenient string class based on std::string.
Definition: cpl_string.h:363
Various convenience functions for working with strings and string lists.

Generated for GDAL by doxygen 1.8.8.