Logo ROOT   6.07/09
Reference Guide
TWebFile.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 17/01/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TWebFile
13 #define ROOT_TWebFile
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TWebFile //
19 // //
20 // A TWebFile is like a normal TFile except that it reads its data //
21 // via a standard apache web server. A TWebFile is a read-only file. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #ifndef ROOT_TFile
26 #include "TFile.h"
27 #endif
28 #ifndef ROOT_TUrl
29 #include "TUrl.h"
30 #endif
31 #ifndef ROOT_TSystem
32 #include "TSystem.h"
33 #endif
34 
35 class TSocket;
36 class TWebSocket;
37 
38 
39 class TWebFile : public TFile {
40 
41 friend class TWebSocket;
42 friend class TWebSystem;
43 
44 private:
45  TWebFile() : fSocket(0) { }
46 
47 protected:
48  mutable Long64_t fSize; // file size
49  TSocket *fSocket; // socket for HTTP/1.1 (stays alive between calls)
50  TUrl fProxy; // proxy URL
51  Bool_t fHasModRoot; // true if server has mod_root installed
52  Bool_t fHTTP11; // true if server support HTTP/1.1
53  Bool_t fNoProxy; // don't use proxy
54  TString fMsgReadBuffer; // cache ReadBuffer() msg
55  TString fMsgReadBuffer10; // cache ReadBuffer10() msg
56  TString fMsgGetHead; // cache GetHead() msg
57  TString fBasicUrl; // basic url without authentication and options
58  TUrl fUrlOrg; // save original url in case of temp redirection
59  TString fBasicUrlOrg; // save original url in case of temp redirection
60  void *fFullCache; //! complete content of the file, some http server may return complete content
61  Long64_t fFullCacheSize; //! size of the cached content
62 
63  static TUrl fgProxy; // globally set proxy URL
64  static Long64_t fgMaxFullCacheSize; // maximal size of full-cached content, 500 MB by default
65 
66  virtual void Init(Bool_t readHeadOnly);
67  virtual void CheckProxy();
68  virtual TString BasicAuthentication();
69  virtual Int_t GetHead();
70  virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize);
71  virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize);
72  virtual const char *HttpTerminator(const char *start, const char *peeked, Int_t peeklen);
73  virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg);
74  virtual Int_t GetFromWeb10(char *buf, Int_t len, const TString &msg, Int_t nseg = 0, Long64_t *seg_pos = 0, Int_t *seg_len = 0);
75  virtual Int_t GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len);
76  virtual Bool_t ReadBuffer10(char *buf, Int_t len);
77  virtual Bool_t ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
78  virtual void SetMsgReadBuffer10(const char *redirectLocation = 0, Bool_t tempRedirect = kFALSE);
79  virtual void ProcessHttpHeader(const TString& headerLine);
80 
81 public:
82  TWebFile(const char *url, Option_t *opt="");
83  TWebFile(TUrl url, Option_t *opt="");
84  virtual ~TWebFile();
85 
86  virtual Long64_t GetSize() const;
87  virtual Bool_t IsOpen() const;
88  virtual Int_t ReOpen(Option_t *mode);
89  virtual Bool_t ReadBuffer(char *buf, Int_t len);
90  virtual Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
91  virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
92  virtual void Seek(Long64_t offset, ERelativeTo pos = kBeg);
93 
94  static void SetProxy(const char *url);
95  static const char *GetProxy();
96 
98  static void SetMaxFullCacheSize(Long64_t sz);
99 
100  ClassDef(TWebFile,2) //A ROOT file that reads via a http server
101 };
102 
103 
104 class TWebSystem : public TSystem {
105 
106 private:
107  void *fDirp; // directory handler
108 
109  void *GetDirPtr() const { return fDirp; }
110 
111 public:
112  TWebSystem();
113  virtual ~TWebSystem() { }
114 
115  Int_t MakeDirectory(const char *name);
116  void *OpenDirectory(const char *name);
117  void FreeDirectory(void *dirp);
118  const char *GetDirEntry(void *dirp);
119  Int_t GetPathInfo(const char *path, FileStat_t &buf);
120  Bool_t AccessPathName(const char *path, EAccessMode mode);
121  Int_t Unlink(const char *path);
122 
123  ClassDef(TWebSystem,0) // Directory handler for HTTP (TWebFiles)
124 };
125 
126 #endif
virtual Bool_t ReadBuffer10(char *buf, Int_t len)
Read specified byte range from remote file via HTTP 1.0 daemon (without mod-root installed).
Definition: TWebFile.cxx:460
virtual Bool_t IsOpen() const
A TWebFile that has been correctly constructed is always considered open.
Definition: TWebFile.cxx:378
static Long64_t GetMaxFullCacheSize()
Static method returning maxmimal size of full cache, which can be preserved by file instance...
Definition: TWebFile.cxx:1426
virtual Long64_t GetSize() const
Return maximum file size.
Definition: TWebFile.cxx:993
long long Long64_t
Definition: RtypesCore.h:69
TLine * line
virtual TString BasicAuthentication()
Return basic authentication scheme, to be added to the request.
Definition: TWebFile.cxx:1371
const char Option_t
Definition: RtypesCore.h:62
This class represents a WWW compatible URL.
Definition: TUrl.h:41
Long64_t fFullCacheSize
complete content of the file, some http server may return complete content
Definition: TWebFile.h:61
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize)
Read a hunk of data from the socket, up until a terminator.
Definition: TWebFile.cxx:1258
virtual void SetMsgReadBuffer10(const char *redirectLocation=0, Bool_t tempRedirect=kFALSE)
Set GET command for use by ReadBuffer(s)10(), handle redirection if needed.
Definition: TWebFile.cxx:266
virtual Int_t GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len)
Extract requested segments from the cached content.
Definition: TWebFile.cxx:582
static TUrl fgProxy
size of the cached content
Definition: TWebFile.h:63
Basic string class.
Definition: TString.h:137
TUrl fUrlOrg
Definition: TWebFile.h:58
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Int_t GetFromWeb10(char *buf, Int_t len, const TString &msg, Int_t nseg=0, Long64_t *seg_pos=0, Int_t *seg_len=0)
Read multiple byte range request from web server.
Definition: TWebFile.cxx:674
const Bool_t kFALSE
Definition: Rtypes.h:92
TString fMsgReadBuffer
Definition: TWebFile.h:54
ERelativeTo
Definition: TFile.h:169
static void SetProxy(const char *url)
Static method setting global proxy URL.
Definition: TWebFile.cxx:1390
virtual void ProcessHttpHeader(const TString &headerLine)
Process the HTTP header in the argument.
Definition: TWebFile.cxx:1418
static void SetMaxFullCacheSize(Long64_t sz)
Static method, set maxmimal size of full cache,.
Definition: TWebFile.cxx:1435
virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize)
Read a line from the socket.
Definition: TWebFile.cxx:1195
TUrl fProxy
Definition: TWebFile.h:50
static const char * GetProxy()
Static method returning the global proxy URL.
Definition: TWebFile.cxx:1406
virtual const char * HttpTerminator(const char *start, const char *peeked, Int_t peeklen)
Determine whether [START, PEEKED + PEEKLEN) contains an HTTP new line [\r]\n.
Definition: TWebFile.cxx:1338
#define ClassDef(name, id)
Definition: Rtypes.h:254
Bool_t fHasModRoot
Definition: TWebFile.h:51
Bool_t fNoProxy
Definition: TWebFile.h:53
const int maxsize
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read specified byte ranges from remote file via HTTP daemon.
Definition: TWebFile.cxx:499
friend class TWebSystem
Definition: TWebFile.h:42
TString fBasicUrlOrg
Definition: TWebFile.h:59
void * fFullCache
Definition: TWebFile.h:60
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via HTTP daemon.
Definition: TWebFile.cxx:411
TString fBasicUrl
Definition: TWebFile.h:57
TWebFile()
Definition: TWebFile.h:45
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TWebFile.cxx:972
virtual void CheckProxy()
Check if shell var "http_proxy" has been set and should be used.
Definition: TWebFile.cxx:351
static Long64_t fgMaxFullCacheSize
Definition: TWebFile.h:64
virtual ~TWebFile()
Cleanup.
Definition: TWebFile.cxx:197
EAccessMode
Definition: TSystem.h:54
TString fMsgReadBuffer10
Definition: TWebFile.h:55
TString fMsgGetHead
Definition: TWebFile.h:56
Long64_t fSize
Definition: TWebFile.h:48
friend class TWebSocket
Definition: TWebFile.h:41
virtual Int_t GetHead()
Get the HTTP header.
Definition: TWebFile.cxx:1028
virtual void Init(Bool_t readHeadOnly)
Initialize a TWebFile object.
Definition: TWebFile.cxx:210
Bool_t fHTTP11
Definition: TWebFile.h:52
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:258
virtual ~TWebSystem()
Definition: TWebFile.h:113
void * GetDirPtr() const
Definition: TWebFile.h:109
void * fDirp
Definition: TWebFile.h:107
virtual Bool_t ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read specified byte ranges from remote file via HTTP 1.0 daemon (without mod-root installed)...
Definition: TWebFile.cxx:548
char name[80]
Definition: TGX11.cxx:109
TSocket * fSocket
Definition: TWebFile.h:49
virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg)
Read request from web server.
Definition: TWebFile.cxx:607
virtual Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE...
Definition: TWebFile.cxx:392