GDAL
cpl_aws.h
1 /**********************************************************************
2  * $Id: cpl_aws.h 33758 2016-03-21 09:06:22Z 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 #include "cpl_string.h"
35 
36 CPLString CPLGetAWS_SIGN4_Authorization(const CPLString& osSecretAccessKey,
37  const CPLString& osAccessKeyId,
38  const CPLString& osAccessToken,
39  const CPLString& osAWSRegion,
40  const CPLString& osService,
41  const CPLString& osVerb,
42  const CPLString& osHost,
43  const CPLString& osCanonicalURI,
44  const CPLString& osCanonicalQueryString,
45  const CPLString& osXAMZContentSHA256,
46  const CPLString& osTimestamp);
47 
48 CPLString CPLGetLowerCaseHexSHA256( const void *pabyData, size_t nBytes );
49 CPLString CPLGetLowerCaseHexSHA256( const CPLString& osStr );
50 
51 CPLString CPLGetAWS_SIGN4_Timestamp();
52 
53 CPLString CPLAWSURLEncode(const CPLString& osURL, bool bEncodeSlash = true);
54 
55 #ifdef HAVE_CURL
56 
57 #include <curl/curl.h>
58 #include <map>
59 
61 {
62  CPLString m_osURL;
63  CPLString m_osSecretAccessKey;
64  CPLString m_osAccessKeyId;
65  CPLString m_osSessionToken;
66  CPLString m_osAWSS3Endpoint;
67  CPLString m_osAWSRegion;
68  CPLString m_osBucket;
69  CPLString m_osObjectKey;
70  bool m_bUseHTTPS;
71  bool m_bUseVirtualHosting;
72  std::map<CPLString, CPLString> m_oMapQueryParameters;
73 
74  static bool GetBucketAndObjectKey(const char* pszURI, const char* pszFSPrefix,
75  bool bAllowNoObject,
76  CPLString &osBucketOut, CPLString &osObjectKeyOut);
77  void RebuildURL();
78 
79  protected:
80 
81  public:
82  VSIS3HandleHelper(const CPLString& osSecretAccessKey,
83  const CPLString& osAccessKeyId,
84  const CPLString& osSessionToken,
85  const CPLString& osAWSS3Endpoint,
86  const CPLString& osAWSRegion,
87  const CPLString& osBucket,
88  const CPLString& osObjectKey,
89  bool bUseHTTPS, bool bUseVirtualHosting);
91 
92  static VSIS3HandleHelper* BuildFromURI(const char* pszURI, const char* pszFSPrefix,
93  bool bAllowNoObject);
94  static CPLString BuildURL(const CPLString& osAWSS3Endpoint,
95  const CPLString& osBucket,
96  const CPLString& osObjectKey,
97  bool bUseHTTPS, bool bUseVirtualHosting);
98 
99  void ResetQueryParameters();
100  void AddQueryParameter(const CPLString& osKey, const CPLString& osValue);
101  struct curl_slist* GetCurlHeaders(const CPLString& osVerb,
102  const void *pabyDataContent = NULL,
103  size_t nBytesContent = 0);
104  bool CanRestartOnError(const char* pszErrorMsg) { return CanRestartOnError(pszErrorMsg, false); }
105  bool CanRestartOnError(const char*, bool bSetError);
106 
107  const CPLString& GetURL() const { return m_osURL; }
108  const CPLString& GetBucket() const { return m_osBucket; }
109  const CPLString& GetObjectKey() const { return m_osObjectKey; }
110  const CPLString& GetAWSS3Endpoint()const { return m_osAWSS3Endpoint; }
111  const CPLString& GetAWSRegion() const { return m_osAWSRegion; }
112  bool GetVirtualHosting() const { return m_bUseVirtualHosting; }
113  void SetAWSS3Endpoint(const CPLString &osStr);
114  void SetAWSRegion(const CPLString &osStr);
115  void SetVirtualHosting(bool b);
116  void SetObjectKey(const CPLString &osStr);
117 };
118 
120 {
121  public:
122  CPLString m_osAWSRegion;
123  CPLString m_osAWSS3Endpoint;
124  bool m_bUseVirtualHosting;
125 
126  VSIS3UpdateParams(const CPLString& osAWSRegion = "",
127  const CPLString& osAWSS3Endpoint = "",
128  bool bUseVirtualHosting = false) :
129  m_osAWSRegion(osAWSRegion),
130  m_osAWSS3Endpoint(osAWSS3Endpoint),
131  m_bUseVirtualHosting(bUseVirtualHosting) {}
132 };
133 
134 #endif /* HAVE_CURL */
135 
136 #endif /* CPL_AWS_INCLUDED_H */
Definition: cpl_aws.h:60
Convenient string class based on std::string.
Definition: cpl_string.h:283
Various convenience functions for working with strings and string lists.
Definition: cpl_aws.h:119

Generated for GDAL by doxygen 1.8.12.