Logo ROOT  
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 #include "TFile.h"
26 #include "TUrl.h"
27 #include "TSystem.h"
28 
29 class TSocket;
30 class TWebSocket;
31 
32 
33 class TWebFile : public TFile {
34 
35 friend class TWebSocket;
36 friend class TWebSystem;
37 
38 private:
39  TWebFile() : fSocket(0) { }
40 
41 protected:
42  mutable Long64_t fSize; // file size
43  TSocket *fSocket; // socket for HTTP/1.1 (stays alive between calls)
44  TUrl fProxy; // proxy URL
45  Bool_t fHasModRoot; // true if server has mod_root installed
46  Bool_t fHTTP11; // true if server support HTTP/1.1
47  Bool_t fNoProxy; // don't use proxy
48  TString fMsgReadBuffer; // cache ReadBuffer() msg
49  TString fMsgReadBuffer10; // cache ReadBuffer10() msg
50  TString fMsgGetHead; // cache GetHead() msg
51  TString fBasicUrl; // basic url without authentication and options
52  TUrl fUrlOrg; // save original url in case of temp redirection
53  TString fBasicUrlOrg; // save original url in case of temp redirection
54  void *fFullCache; //! complete content of the file, some http server may return complete content
55  Long64_t fFullCacheSize; //! size of the cached content
56 
57  static TUrl fgProxy; // globally set proxy URL
58  static Long64_t fgMaxFullCacheSize; // maximal size of full-cached content, 500 MB by default
59 
60  virtual void Init(Bool_t readHeadOnly);
61  virtual void CheckProxy();
62  virtual TString BasicAuthentication();
63  virtual Int_t GetHead();
64  virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize);
65  virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize);
66  virtual const char *HttpTerminator(const char *start, const char *peeked, Int_t peeklen);
67  virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg);
68  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);
69  virtual Int_t GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len);
70  virtual Bool_t ReadBuffer10(char *buf, Int_t len);
71  virtual Bool_t ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
72  virtual void SetMsgReadBuffer10(const char *redirectLocation = 0, Bool_t tempRedirect = kFALSE);
73  virtual void ProcessHttpHeader(const TString& headerLine);
74 
75 public:
76  TWebFile(const char *url, Option_t *opt="");
77  TWebFile(TUrl url, Option_t *opt="");
78  virtual ~TWebFile();
79 
80  virtual Long64_t GetSize() const;
81  virtual Bool_t IsOpen() const;
82  virtual Int_t ReOpen(Option_t *mode);
83  virtual Bool_t ReadBuffer(char *buf, Int_t len);
84  virtual Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
85  virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
86  virtual void Seek(Long64_t offset, ERelativeTo pos = kBeg);
87 
88  static void SetProxy(const char *url);
89  static const char *GetProxy();
90 
92  static void SetMaxFullCacheSize(Long64_t sz);
93 
94  ClassDef(TWebFile,2) //A ROOT file that reads via a http server
95 };
96 
97 
98 class TWebSystem : public TSystem {
99 
100 private:
101  void *fDirp; // directory handler
102 
103  void *GetDirPtr() const { return fDirp; }
104 
105 public:
106  TWebSystem();
107  virtual ~TWebSystem() { }
108 
109  Int_t MakeDirectory(const char *name);
110  void *OpenDirectory(const char *name);
111  void FreeDirectory(void *dirp);
112  const char *GetDirEntry(void *dirp);
113  Int_t GetPathInfo(const char *path, FileStat_t &buf);
114  Bool_t AccessPathName(const char *path, EAccessMode mode);
115  Int_t Unlink(const char *path);
116 
117  ClassDef(TWebSystem,0) // Directory handler for HTTP (TWebFiles)
118 };
119 
120 #endif
TWebFile::fSize
Long64_t fSize
Definition: TWebFile.h:42
TWebFile::fSocket
TSocket * fSocket
Definition: TWebFile.h:43
TWebFile::GetFromCache
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
TWebFile::SetMaxFullCacheSize
static void SetMaxFullCacheSize(Long64_t sz)
Static method, set maxmimal size of full cache,.
Definition: TWebFile.cxx:1430
TWebFile::fBasicUrlOrg
TString fBasicUrlOrg
Definition: TWebFile.h:53
TWebFile::CheckProxy
virtual void CheckProxy()
Check if shell var "http_proxy" has been set and should be used.
Definition: TWebFile.cxx:351
TFile::kBeg
@ kBeg
Definition: TFile.h:191
TWebFile::fUrlOrg
TUrl fUrlOrg
Definition: TWebFile.h:52
TWebFile::GetHunk
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
FileStat_t
Definition: TSystem.h:124
TWebFile::fgProxy
static TUrl fgProxy
size of the cached content
Definition: TWebFile.h:57
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TFile::ERelativeTo
ERelativeTo
Definition: TFile.h:191
TWebFile::ReOpen
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
TWebFile::fMsgReadBuffer
TString fMsgReadBuffer
Definition: TWebFile.h:48
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TWebFile::fHTTP11
Bool_t fHTTP11
Definition: TWebFile.h:46
TSystem
Definition: TSystem.h:266
Int_t
int Int_t
Definition: RtypesCore.h:45
TWebFile::fHasModRoot
Bool_t fHasModRoot
Definition: TWebFile.h:45
TWebSystem::fDirp
void * fDirp
Definition: TWebFile.h:101
TWebSystem::AccessPathName
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TWebFile.cxx:1531
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TWebFile::SetMsgReadBuffer10
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
TWebSystem::TWebSystem
TWebSystem()
Create helper class that allows directory access via httpd.
Definition: TWebFile.cxx:1440
TWebFile::fFullCacheSize
Long64_t fFullCacheSize
complete content of the file, some http server may return complete content
Definition: TWebFile.h:55
TFile.h
bool
TWebFile::fgMaxFullCacheSize
static Long64_t fgMaxFullCacheSize
Definition: TWebFile.h:58
TWebFile::GetMaxFullCacheSize
static Long64_t GetMaxFullCacheSize()
Static method returning maxmimal size of full cache, which can be preserved by file instance.
Definition: TWebFile.cxx:1421
TWebFile::HttpTerminator
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:1333
TSocket
Definition: TSocket.h:41
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TWebFile::TWebFile
TWebFile()
Definition: TWebFile.h:39
TSystem.h
TWebFile::fFullCache
void * fFullCache
Definition: TWebFile.h:54
TWebFile::ReadBuffer
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via HTTP daemon.
Definition: TWebFile.cxx:411
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TWebFile::SetProxy
static void SetProxy(const char *url)
Static method setting global proxy URL.
Definition: TWebFile.cxx:1385
TWebFile::ReadBuffers
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
TWebFile::Seek
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TWebFile.cxx:972
TWebFile::fProxy
TUrl fProxy
Definition: TWebFile.h:44
TWebFile::fMsgGetHead
TString fMsgGetHead
Definition: TWebFile.h:50
TWebSystem
Definition: TWebFile.h:98
line
TLine * line
Definition: entrylistblock_figure1.C:235
TWebFile::ProcessHttpHeader
virtual void ProcessHttpHeader(const TString &headerLine)
Process the HTTP header in the argument.
Definition: TWebFile.cxx:1413
TUrl
Definition: TUrl.h:33
TFile
Definition: TFile.h:54
TWebSystem::~TWebSystem
virtual ~TWebSystem()
Definition: TWebFile.h:107
TWebFile::BasicAuthentication
virtual TString BasicAuthentication()
Return basic authentication scheme, to be added to the request.
Definition: TWebFile.cxx:1366
TWebFile::ReadBuffer10
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
TWebSystem::GetDirEntry
const char * GetDirEntry(void *dirp)
Get directory entry via httpd. Returns 0 in case no more entries.
Definition: TWebFile.cxx:1487
TWebSystem::Unlink
Int_t Unlink(const char *path)
Unlink, i.e.
Definition: TWebFile.cxx:1546
TWebFile::fNoProxy
Bool_t fNoProxy
Definition: TWebFile.h:47
TWebFile::Init
virtual void Init(Bool_t readHeadOnly)
Initialize a TWebFile object.
Definition: TWebFile.cxx:210
EAccessMode
EAccessMode
Definition: TSystem.h:43
TWebSystem::GetPathInfo
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TWebFile.cxx:1503
TWebSystem::FreeDirectory
void FreeDirectory(void *dirp)
Free directory via httpd.
Definition: TWebFile.cxx:1474
TWebSystem::OpenDirectory
void * OpenDirectory(const char *name)
Open a directory via httpd.
Definition: TWebFile.cxx:1459
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TWebFile::GetHead
virtual Int_t GetHead()
Get the HTTP header.
Definition: TWebFile.cxx:1028
TWebFile::GetLine
virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize)
Read a line from the socket.
Definition: TWebFile.cxx:1195
name
char name[80]
Definition: TGX11.cxx:110
TWebFile::fBasicUrl
TString fBasicUrl
Definition: TWebFile.h:51
TWebSystem::GetDirPtr
void * GetDirPtr() const
Definition: TWebFile.h:103
TWebFile::GetFromWeb
virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg)
Read request from web server.
Definition: TWebFile.cxx:607
TWebFile::~TWebFile
virtual ~TWebFile()
Cleanup.
Definition: TWebFile.cxx:197
TWebFile::ReadBuffers10
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
TWebFile::GetFromWeb10
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
TWebFile
Definition: TWebFile.h:33
TWebFile::TWebSocket
friend class TWebSocket
Definition: TWebFile.h:35
TWebFile::GetProxy
static const char * GetProxy()
Static method returning the global proxy URL.
Definition: TWebFile.cxx:1401
TWebFile::IsOpen
virtual Bool_t IsOpen() const
A TWebFile that has been correctly constructed is always considered open.
Definition: TWebFile.cxx:378
TUrl.h
TWebFile::GetSize
virtual Long64_t GetSize() const
Return maximum file size.
Definition: TWebFile.cxx:993
TWebFile::fMsgReadBuffer10
TString fMsgReadBuffer10
Definition: TWebFile.h:49
int
TWebSystem::MakeDirectory
Int_t MakeDirectory(const char *name)
Make a directory via httpd. Not supported.
Definition: TWebFile.cxx:1450