GDAL
cpl_aws.h
00001 /**********************************************************************
00002  * $Id: cpl_aws.h 37174 2017-01-18 20:00:36Z rouault $
00003  *
00004  * Name:     cpl_aws.h
00005  * Project:  CPL - Common Portability Library
00006  * Purpose:  Amazon Web Services routines
00007  * Author:   Even Rouault <even.rouault at spatialys.com>
00008  *
00009  **********************************************************************
00010  * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00028  * DEALINGS IN THE SOFTWARE.
00029  ****************************************************************************/
00030 
00031 #ifndef CPL_AWS_INCLUDED_H
00032 #define CPL_AWS_INCLUDED_H
00033 
00034 #ifndef DOXYGEN_SKIP
00035 
00036 #include <cstddef>
00037 
00038 #include "cpl_string.h"
00039 
00040 CPLString CPLGetAWS_SIGN4_Authorization(const CPLString& osSecretAccessKey,
00041                                         const CPLString& osAccessKeyId,
00042                                         const CPLString& osAccessToken,
00043                                         const CPLString& osAWSRegion,
00044                                         const CPLString& osRequestPayer,
00045                                         const CPLString& osService,
00046                                         const CPLString& osVerb,
00047                                         const CPLString& osHost,
00048                                         const CPLString& osCanonicalURI,
00049                                         const CPLString& osCanonicalQueryString,
00050                                         const CPLString& osXAMZContentSHA256,
00051                                         const CPLString& osTimestamp);
00052 
00053 CPLString CPLGetLowerCaseHexSHA256( const void *pabyData, size_t nBytes );
00054 CPLString CPLGetLowerCaseHexSHA256( const CPLString& osStr );
00055 
00056 CPLString CPLGetAWS_SIGN4_Timestamp();
00057 
00058 CPLString CPLAWSURLEncode(const CPLString& osURL, bool bEncodeSlash = true);
00059 
00060 #ifdef HAVE_CURL
00061 
00062 #include <curl/curl.h>
00063 #include <map>
00064 
00065 class VSIS3HandleHelper
00066 {
00067         CPLString m_osURL;
00068         CPLString m_osSecretAccessKey;
00069         CPLString m_osAccessKeyId;
00070         CPLString m_osSessionToken;
00071         CPLString m_osAWSS3Endpoint;
00072         CPLString m_osAWSRegion;
00073         CPLString m_osRequestPayer;
00074         CPLString m_osBucket;
00075         CPLString m_osObjectKey;
00076         bool m_bUseHTTPS;
00077         bool m_bUseVirtualHosting;
00078         std::map<CPLString, CPLString> m_oMapQueryParameters;
00079 
00080         static bool GetBucketAndObjectKey(const char* pszURI, const char* pszFSPrefix,
00081                                           bool bAllowNoObject,
00082                                           CPLString &osBucketOut, CPLString &osObjectKeyOut);
00083         void RebuildURL();
00084 
00085   protected:
00086 
00087     public:
00088         VSIS3HandleHelper(const CPLString& osSecretAccessKey,
00089                     const CPLString& osAccessKeyId,
00090                     const CPLString& osSessionToken,
00091                     const CPLString& osAWSS3Endpoint,
00092                     const CPLString& osAWSRegion,
00093                     const CPLString& osRequestPayer,
00094                     const CPLString& osBucket,
00095                     const CPLString& osObjectKey,
00096                     bool bUseHTTPS, bool bUseVirtualHosting);
00097        ~VSIS3HandleHelper();
00098 
00099         static VSIS3HandleHelper* BuildFromURI(const char* pszURI, const char* pszFSPrefix,
00100                                                bool bAllowNoObject);
00101         static CPLString BuildURL(const CPLString& osAWSS3Endpoint,
00102                                   const CPLString& osBucket,
00103                                   const CPLString& osObjectKey,
00104                                   bool bUseHTTPS, bool bUseVirtualHosting);
00105 
00106         void ResetQueryParameters();
00107         void AddQueryParameter(const CPLString& osKey, const CPLString& osValue);
00108         struct curl_slist* GetCurlHeaders(const CPLString& osVerb,
00109                                           const void *pabyDataContent = NULL,
00110                                           size_t nBytesContent = 0);
00111         bool CanRestartOnError(const char* pszErrorMsg) { return CanRestartOnError(pszErrorMsg, false); }
00112         bool CanRestartOnError(const char*, bool bSetError);
00113 
00114         const CPLString& GetURL() const { return m_osURL; }
00115         const CPLString& GetBucket() const { return m_osBucket; }
00116         const CPLString& GetObjectKey() const { return m_osObjectKey; }
00117         const CPLString& GetAWSS3Endpoint()const  { return m_osAWSS3Endpoint; }
00118         const CPLString& GetAWSRegion() const { return m_osAWSRegion; }
00119         const CPLString& GetRequestPayer() const { return m_osRequestPayer; }
00120         bool GetVirtualHosting() const { return m_bUseVirtualHosting; }
00121         void SetAWSS3Endpoint(const CPLString &osStr);
00122         void SetAWSRegion(const CPLString &osStr);
00123         void SetRequestPayer(const CPLString &osStr);
00124         void SetVirtualHosting(bool b);
00125         void SetObjectKey(const CPLString &osStr);
00126 };
00127 
00128 class VSIS3UpdateParams
00129 {
00130     public:
00131         CPLString m_osAWSRegion;
00132         CPLString m_osAWSS3Endpoint;
00133         CPLString m_osRequestPayer;
00134         bool m_bUseVirtualHosting;
00135 
00136         VSIS3UpdateParams(const CPLString& osAWSRegion = "",
00137                           const CPLString& osAWSS3Endpoint = "",
00138                           const CPLString& osRequestPayer = "",
00139                           bool bUseVirtualHosting = false) :
00140             m_osAWSRegion(osAWSRegion),
00141             m_osAWSS3Endpoint(osAWSS3Endpoint),
00142             m_osRequestPayer(osRequestPayer),
00143             m_bUseVirtualHosting(bUseVirtualHosting) {}
00144 };
00145 
00146 #endif /* HAVE_CURL */
00147 
00148 #endif /* #ifndef DOXYGEN_SKIP */
00149 
00150 #endif /* CPL_AWS_INCLUDED_H */

Generated for GDAL by doxygen 1.7.6.1.