cpl_aws.h

00001 /**********************************************************************
00002  * $Id: cpl_aws.h 33758 2016-03-21 09:06:22Z 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 #include "cpl_string.h"
00035 
00036 CPLString CPLGetAWS_SIGN4_Authorization(const CPLString& osSecretAccessKey,
00037                                         const CPLString& osAccessKeyId,
00038                                         const CPLString& osAccessToken,
00039                                         const CPLString& osAWSRegion,
00040                                         const CPLString& osService,
00041                                         const CPLString& osVerb,
00042                                         const CPLString& osHost,
00043                                         const CPLString& osCanonicalURI,
00044                                         const CPLString& osCanonicalQueryString,
00045                                         const CPLString& osXAMZContentSHA256,
00046                                         const CPLString& osTimestamp);
00047 
00048 CPLString CPLGetLowerCaseHexSHA256( const void *pabyData, size_t nBytes );
00049 CPLString CPLGetLowerCaseHexSHA256( const CPLString& osStr );
00050 
00051 CPLString CPLGetAWS_SIGN4_Timestamp();
00052 
00053 CPLString CPLAWSURLEncode(const CPLString& osURL, bool bEncodeSlash = true);
00054 
00055 #ifdef HAVE_CURL
00056 
00057 #include <curl/curl.h>
00058 #include <map>
00059 
00060 class VSIS3HandleHelper
00061 {
00062         CPLString m_osURL;
00063         CPLString m_osSecretAccessKey;
00064         CPLString m_osAccessKeyId;
00065         CPLString m_osSessionToken;
00066         CPLString m_osAWSS3Endpoint;
00067         CPLString m_osAWSRegion;
00068         CPLString m_osBucket;
00069         CPLString m_osObjectKey;
00070         bool m_bUseHTTPS;
00071         bool m_bUseVirtualHosting;
00072         std::map<CPLString, CPLString> m_oMapQueryParameters;
00073 
00074         static bool GetBucketAndObjectKey(const char* pszURI, const char* pszFSPrefix,
00075                                           bool bAllowNoObject,
00076                                           CPLString &osBucketOut, CPLString &osObjectKeyOut);
00077         void RebuildURL();
00078 
00079   protected:
00080 
00081     public:
00082         VSIS3HandleHelper(const CPLString& osSecretAccessKey,
00083                     const CPLString& osAccessKeyId,
00084                     const CPLString& osSessionToken,
00085                     const CPLString& osAWSS3Endpoint,
00086                     const CPLString& osAWSRegion,
00087                     const CPLString& osBucket,
00088                     const CPLString& osObjectKey,
00089                     bool bUseHTTPS, bool bUseVirtualHosting);
00090        ~VSIS3HandleHelper();
00091 
00092         static VSIS3HandleHelper* BuildFromURI(const char* pszURI, const char* pszFSPrefix,
00093                                                bool bAllowNoObject);
00094         static CPLString BuildURL(const CPLString& osAWSS3Endpoint,
00095                                   const CPLString& osBucket,
00096                                   const CPLString& osObjectKey,
00097                                   bool bUseHTTPS, bool bUseVirtualHosting);
00098 
00099         void ResetQueryParameters();
00100         void AddQueryParameter(const CPLString& osKey, const CPLString& osValue);
00101         struct curl_slist* GetCurlHeaders(const CPLString& osVerb,
00102                                           const void *pabyDataContent = NULL,
00103                                           size_t nBytesContent = 0);
00104         bool CanRestartOnError(const char* pszErrorMsg) { return CanRestartOnError(pszErrorMsg, false); }
00105         bool CanRestartOnError(const char*, bool bSetError);
00106 
00107         const CPLString& GetURL() const { return m_osURL; }
00108         const CPLString& GetBucket() const { return m_osBucket; }
00109         const CPLString& GetObjectKey() const { return m_osObjectKey; }
00110         const CPLString& GetAWSS3Endpoint()const  { return m_osAWSS3Endpoint; }
00111         const CPLString& GetAWSRegion() const { return m_osAWSRegion; }
00112         bool GetVirtualHosting() const { return m_bUseVirtualHosting; }
00113         void SetAWSS3Endpoint(const CPLString &osStr);
00114         void SetAWSRegion(const CPLString &osStr);
00115         void SetVirtualHosting(bool b);
00116         void SetObjectKey(const CPLString &osStr);
00117 };
00118 
00119 class VSIS3UpdateParams
00120 {
00121     public:
00122         CPLString m_osAWSRegion;
00123         CPLString m_osAWSS3Endpoint;
00124         bool m_bUseVirtualHosting;
00125 
00126         VSIS3UpdateParams(const CPLString& osAWSRegion = "",
00127                           const CPLString& osAWSS3Endpoint = "",
00128                           bool bUseVirtualHosting = false) :
00129             m_osAWSRegion(osAWSRegion),
00130             m_osAWSS3Endpoint(osAWSS3Endpoint),
00131             m_bUseVirtualHosting(bUseVirtualHosting) {}
00132 };
00133 
00134 #endif /* HAVE_CURL */
00135 
00136 #endif /* CPL_AWS_INCLUDED_H */

Generated for GDAL by doxygen 1.6.1.