// @(#)root/net:$Id: TS3WebFile.h$
// Author: Fabio Hernandez   22/01/2013
//         extending an initial version by Marcelo Sousa (class TAS3File)

/*************************************************************************
 * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TS3WebFile
#define ROOT_TS3WebFile

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TS3WebFile                                                           //
//                                                                      //
// A TS3WebFile is a TWebFile which retrieves the file contents from a  //
// web server implementing the REST API of the Amazon S3 protocol. This //
// class is meant to be as generic as possible to be used with files    //
// hosted not only by Amazon S3 servers but also by other providers     //
// implementing the core of the S3 protocol.                            //
//                                                                      //
// The S3 protocol works on top of HTTPS (and HTTP) and imposes that    //
// each HTTP request be signed using a specific convention: the request //
// must include an 'Authorization' header which contains the signature  //
// of a concatenation of selected request fields. For signing the       //
// request, an 'Access Key Id' and a 'Secret Access Key' need to be     //
// known. These keys are used by the S3 servers to identify the client  //
// and to authenticate the request as genuine.                          //
//                                                                      //
// As an end user, you must know the Access Key and Secret Access Key   //
// in order to access each S3 file. They are provided to you by your S3 //
// service provider. Those two keys can be provided to ROOT when        //
// initializing an object of this class by two means:                   //
// a) by using the environmental variables S3_ACCESS_KEY and            //
//    S3_SECRET_KEY, or                                                 //
// b) by specifying them as an argument when opening each file.         //
//                                                                      //
// The first method is convenient if all the S3 files you want to       //
// access are hosted by a single provider. The second one is more       //
// flexible as it allows you to specify which credentials to use        //
// on a per-file basis. See the documentation of the constructor of     //
// this class for details on the syntax.                                //
//                                                                      //
// For generating and signing the HTTP request, this class uses         //
// TS3HTTPRequest.                                                      //
//                                                                      //
// For more information on the details of S3 protocol please refer to:  //
// "Amazon Simple Storage Service Developer Guide":                     //
// http://docs.amazonwebservices.com/AmazonS3/latest/dev/Welcome.html   //
//                                                                      //
// "Amazon Simple Storage Service REST API Reference"                   //
//  http://docs.amazonwebservices.com/AmazonS3/latest/API/APIRest.html  //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TWebFile
#include "TWebFile.h"
#endif

#ifndef ROOT_TUrl
#include "TUrl.h"
#endif

#ifndef ROOT_TString
#include "TString.h"
#endif

#ifndef ROOT_TS3HTTPRequest
#include "TS3HTTPRequest.h"
#endif


class TS3WebFile: public TWebFile {

private:
   TS3WebFile();
   Bool_t ParseOptions(Option_t* options, TString& accessKey, TString& secretKey);
   Bool_t GetCredentialsFromEnv(const char* accessKeyEnv, const char* secretKeyEnv,
                                TString& outAccessKey, TString& outSecretKey);

protected:
   // Super-class methods extended by this class
   virtual Int_t GetHead();
   virtual void SetMsgReadBuffer10(const char* redirectLocation = 0, Bool_t tempRedirect = kFALSE);
   virtual void ProcessHttpHeader(const TString& headerLine);

   // Modifiers of data members (to be used mainly by subclasses)
   void SetAccessKey(const TString& accessKey) { fS3Request.SetAccessKey(accessKey); }
   void SetSecretKey(const TString& secretKey) { fS3Request.SetSecretKey(secretKey); }

   // Data members
   TS3HTTPRequest fS3Request;      // S3 HTTP request
   Bool_t         fUseMultiRange;  // Is the S3 server capable of serving multirange requests?

public:
   // Constructors & Destructor
   TS3WebFile(const char* url, Option_t* options="");
   virtual ~TS3WebFile() {}

   // Selectors
   const TString&  GetAccessKey() const { return fS3Request.GetAccessKey(); }
   const TString&  GetSecretKey() const { return fS3Request.GetSecretKey(); }
   const TString&  GetBucket() const { return fS3Request.GetBucket(); }
   const TString&  GetObjectKey() const { return fS3Request.GetObjectKey(); }
   const TUrl&     GetUrl() const { return fUrl; }

   // Modifiers
   virtual Bool_t ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf);

   ClassDef(TS3WebFile, 0)  // Read a ROOT file from a S3 server
};

#endif // ROOT_TS3WebFile
 TS3WebFile.h:1
 TS3WebFile.h:2
 TS3WebFile.h:3
 TS3WebFile.h:4
 TS3WebFile.h:5
 TS3WebFile.h:6
 TS3WebFile.h:7
 TS3WebFile.h:8
 TS3WebFile.h:9
 TS3WebFile.h:10
 TS3WebFile.h:11
 TS3WebFile.h:12
 TS3WebFile.h:13
 TS3WebFile.h:14
 TS3WebFile.h:15
 TS3WebFile.h:16
 TS3WebFile.h:17
 TS3WebFile.h:18
 TS3WebFile.h:19
 TS3WebFile.h:20
 TS3WebFile.h:21
 TS3WebFile.h:22
 TS3WebFile.h:23
 TS3WebFile.h:24
 TS3WebFile.h:25
 TS3WebFile.h:26
 TS3WebFile.h:27
 TS3WebFile.h:28
 TS3WebFile.h:29
 TS3WebFile.h:30
 TS3WebFile.h:31
 TS3WebFile.h:32
 TS3WebFile.h:33
 TS3WebFile.h:34
 TS3WebFile.h:35
 TS3WebFile.h:36
 TS3WebFile.h:37
 TS3WebFile.h:38
 TS3WebFile.h:39
 TS3WebFile.h:40
 TS3WebFile.h:41
 TS3WebFile.h:42
 TS3WebFile.h:43
 TS3WebFile.h:44
 TS3WebFile.h:45
 TS3WebFile.h:46
 TS3WebFile.h:47
 TS3WebFile.h:48
 TS3WebFile.h:49
 TS3WebFile.h:50
 TS3WebFile.h:51
 TS3WebFile.h:52
 TS3WebFile.h:53
 TS3WebFile.h:54
 TS3WebFile.h:55
 TS3WebFile.h:56
 TS3WebFile.h:57
 TS3WebFile.h:58
 TS3WebFile.h:59
 TS3WebFile.h:60
 TS3WebFile.h:61
 TS3WebFile.h:62
 TS3WebFile.h:63
 TS3WebFile.h:64
 TS3WebFile.h:65
 TS3WebFile.h:66
 TS3WebFile.h:67
 TS3WebFile.h:68
 TS3WebFile.h:69
 TS3WebFile.h:70
 TS3WebFile.h:71
 TS3WebFile.h:72
 TS3WebFile.h:73
 TS3WebFile.h:74
 TS3WebFile.h:75
 TS3WebFile.h:76
 TS3WebFile.h:77
 TS3WebFile.h:78
 TS3WebFile.h:79
 TS3WebFile.h:80
 TS3WebFile.h:81
 TS3WebFile.h:82
 TS3WebFile.h:83
 TS3WebFile.h:84
 TS3WebFile.h:85
 TS3WebFile.h:86
 TS3WebFile.h:87
 TS3WebFile.h:88
 TS3WebFile.h:89
 TS3WebFile.h:90
 TS3WebFile.h:91
 TS3WebFile.h:92
 TS3WebFile.h:93
 TS3WebFile.h:94
 TS3WebFile.h:95
 TS3WebFile.h:96
 TS3WebFile.h:97
 TS3WebFile.h:98
 TS3WebFile.h:99
 TS3WebFile.h:100
 TS3WebFile.h:101
 TS3WebFile.h:102
 TS3WebFile.h:103
 TS3WebFile.h:104
 TS3WebFile.h:105
 TS3WebFile.h:106
 TS3WebFile.h:107
 TS3WebFile.h:108
 TS3WebFile.h:109
 TS3WebFile.h:110
 TS3WebFile.h:111
 TS3WebFile.h:112
 TS3WebFile.h:113
 TS3WebFile.h:114
 TS3WebFile.h:115
 TS3WebFile.h:116