Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
29class TSocket;
30
31namespace ROOT::Deprecated {
32
33class TWebSocket;
34class TWebSystem;
35
36class TWebFile : public TFile {
37
40
41private:
42 TWebFile() : fSocket(nullptr) {}
43
44protected:
45 mutable Long64_t fSize; // file size
46 TSocket *fSocket; // socket for HTTP/1.1 (stays alive between calls)
47 TUrl fProxy; // proxy URL
48 Bool_t fHasModRoot; // true if server has mod_root installed
49 Bool_t fHTTP11; // true if server support HTTP/1.1
50 Bool_t fNoProxy; // don't use proxy
51 TString fMsgReadBuffer; // cache ReadBuffer() msg
52 TString fMsgReadBuffer10; // cache ReadBuffer10() msg
53 TString fMsgGetHead; // cache GetHead() msg
54 TString fBasicUrl; // basic url without authentication and options
55 TUrl fUrlOrg; // save original url in case of temp redirection
56 TString fBasicUrlOrg; // save original url in case of temp redirection
57 void *fFullCache; ///<! complete content of the file, some http server may return complete content
58 Long64_t fFullCacheSize; ///<! size of the cached content
59
60 static TUrl fgProxy; // globally set proxy URL
61 static Long64_t fgMaxFullCacheSize; // maximal size of full-cached content, 500 MB by default
62
63 void Init(Bool_t readHeadOnly) override;
64 virtual void CheckProxy();
66 virtual Int_t GetHead();
67 virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize);
68 virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize);
69 virtual const char *HttpTerminator(const char *start, const char *peeked, Int_t peeklen);
70 virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg);
71 virtual Int_t GetFromWeb10(char *buf, Int_t len, const TString &msg, Int_t nseg = 0, Long64_t *seg_pos = nullptr, Int_t *seg_len = nullptr);
73 virtual Bool_t ReadBuffer10(char *buf, Int_t len);
74 virtual Bool_t ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
75 virtual void SetMsgReadBuffer10(const char *redirectLocation = nullptr, Bool_t tempRedirect = kFALSE);
76 virtual void ProcessHttpHeader(const TString& headerLine);
77
78public:
79 TWebFile(const char *url, Option_t *opt="");
80 TWebFile(TUrl url, Option_t *opt="");
81 virtual ~TWebFile();
82
83 void Close(Option_t *option="") override;
84 Long64_t GetSize() const override;
85 Bool_t IsOpen() const override;
86 Int_t ReOpen(Option_t *mode) override;
87 Bool_t ReadBuffer(char *buf, Int_t len) override;
88 Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len) override;
89 Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override;
90 void Seek(Long64_t offset, ERelativeTo pos = kBeg) override;
91
92 static void SetProxy(const char *url);
93 static const char *GetProxy();
94
96 static void SetMaxFullCacheSize(Long64_t sz);
97
98 ClassDefOverride(TWebFile,2) //A ROOT file that reads via a http server
99};
100
101
102class TWebSystem : public TSystem {
103
104private:
105 void *fDirp; // directory handler
106
107 void *GetDirPtr() const override { return fDirp; }
108
109public:
110 TWebSystem();
111 virtual ~TWebSystem() {}
112
113 Int_t MakeDirectory(const char *name) override;
114 void *OpenDirectory(const char *name) override;
115 void FreeDirectory(void *dirp) override;
116 const char *GetDirEntry(void *dirp) override;
117 Int_t GetPathInfo(const char *path, FileStat_t &buf) override;
118 Bool_t AccessPathName(const char *path, EAccessMode mode) override;
119 Int_t Unlink(const char *path) override;
120
121 ClassDefOverride(TWebSystem,0) // Directory handler for HTTP (TWebFiles)
122};
123
124} // namespace ROOT::Deprecated
125
126using TWebFile R__DEPRECATED(6, 42, "TWebFile is deprecated") = ROOT::Deprecated::TWebFile;
127using TWebSystem R__DEPRECATED(6, 42, "TWebSystem is deprecated") = ROOT::Deprecated::TWebSystem;
128
129#endif
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:510
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:146
EAccessMode
Definition TSystem.h:51
static void SetProxy(const char *url)
Static method setting global proxy URL.
virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg)
Read request from web server.
Definition TWebFile.cxx:633
static Long64_t fgMaxFullCacheSize
Definition TWebFile.h:61
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:574
virtual Int_t GetFromWeb10(char *buf, Int_t len, const TString &msg, Int_t nseg=0, Long64_t *seg_pos=nullptr, Int_t *seg_len=nullptr)
Read multiple byte range request from web server.
Definition TWebFile.cxx:700
void Seek(Long64_t offset, ERelativeTo pos=kBeg) override
Set position from where to start reading.
Definition TWebFile.cxx:984
virtual void CheckProxy()
Check if shell var "http_proxy" has been set and should be used.
Definition TWebFile.cxx:361
Bool_t ReadBuffer(char *buf, Int_t len) override
Read specified byte range from remote file via HTTP daemon.
Definition TWebFile.cxx:437
virtual TString BasicAuthentication()
Return basic authentication scheme, to be added to the request.
void * fFullCache
! complete content of the file, some http server may return complete content
Definition TWebFile.h:57
static const char * GetProxy()
Static method returning the global proxy URL.
void Init(Bool_t readHeadOnly) override
Initialize a TWebFile object.
Definition TWebFile.cxx:214
virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize)
Read a hunk of data from the socket, up until a terminator.
virtual ~TWebFile()
Cleanup.
Definition TWebFile.cxx:201
virtual void ProcessHttpHeader(const TString &headerLine)
Process the HTTP header in the argument.
virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize)
Read a line from the socket.
Bool_t IsOpen() const override
A TWebFile that has been correctly constructed is always considered open.
Definition TWebFile.cxx:388
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:486
static void SetMaxFullCacheSize(Long64_t sz)
Static method, set maxmimal size of full cache,.
Int_t ReOpen(Option_t *mode) override
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE,...
Definition TWebFile.cxx:402
virtual Int_t GetHead()
Get the HTTP header.
virtual void SetMsgReadBuffer10(const char *redirectLocation=nullptr, Bool_t tempRedirect=kFALSE)
Set GET command for use by ReadBuffer(s)10(), handle redirection if needed.
Definition TWebFile.cxx:274
void Close(Option_t *option="") override
Close a Web file.
Definition TWebFile.cxx:420
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.
Long64_t GetSize() const override
Return maximum file size.
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override
Read specified byte ranges from remote file via HTTP daemon.
Definition TWebFile.cxx:525
Long64_t fFullCacheSize
! size of the cached content
Definition TWebFile.h:58
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:608
static Long64_t GetMaxFullCacheSize()
Static method returning maxmimal size of full cache, which can be preserved by file instance.
TWebSystem()
Create helper class that allows directory access via httpd.
Bool_t AccessPathName(const char *path, EAccessMode mode) override
Returns FALSE if one can access a file using the specified access mode.
void * GetDirPtr() const override
Definition TWebFile.h:107
const char * GetDirEntry(void *dirp) override
Get directory entry via httpd. Returns 0 in case no more entries.
void FreeDirectory(void *dirp) override
Free directory via httpd.
Int_t GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
Int_t Unlink(const char *path) override
Unlink, i.e.
Int_t MakeDirectory(const char *name) override
Make a directory via httpd. Not supported.
void * OpenDirectory(const char *name) override
Open a directory via httpd.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
ERelativeTo
Definition TFile.h:277
@ kBeg
Definition TFile.h:277
This class implements client sockets.
Definition TSocket.h:41
Basic string class.
Definition TString.h:138
Abstract base class defining a generic interface to the underlying Operating System.
Definition TSystem.h:276
This class represents a WWW compatible URL.
Definition TUrl.h:33
TLine * line