39# define EADDRINUSE 10048
46static const char *
gUserAgent =
"User-Agent: ROOT-TWebFile/1.1";
101 for (
Int_t i = 0; i < 5; i++) {
106 ::Error(
"TWebSocket::ReOpen",
"library compiled without SSL, https not supported");
118 ::Error(
"TWebSocket::ReOpen",
"cannot connect to host %s (errno=%d)",
147 :
TFile(
url,
strstr(opt,
"_WITHOUT_GLOBALREGISTRATION") != nullptr ?
"WEB_WITHOUT_GLOBALREGISTRATION" :
"WEB"),
220#if defined(R__WIN32) && defined(R__SSL)
299 if (
rdl.Index(
"?") >= 0) {
370 if (
strcmp(
p.GetProtocol(),
"http")) {
371 Error(
"CheckProxy",
"protocol must be HTTP in proxy URL %s",
403 if (opt !=
"READ" && opt !=
"UPDATE")
404 Error(
"ReOpen",
"mode must be either READ or UPDATE, not %s", opt.
Data());
407 Error(
"ReOpen",
"update mode not allowed for a TWebFile");
535 Int_t k = 0,
n = 0, cnt = 0;
543 if ((
msg.Length() > 8000) || (cnt >= 200)) {
576 Int_t k = 0,
n = 0,
r, cnt = 0;
584 if ((
msg.Length() > 8000) || (cnt >= 200) || (i+1 ==
nbuf)) {
609 Info(
"GetFromCache",
"Extract %d segments total len %d from cached data",
nseg,
len);
648 Error(
"GetFromWeb",
"library compiled without SSL, https not supported");
716 Info(
"GetFromWeb10",
"sending HTTP request:\n%s",
msg.Data());
734 if (
redir.IsNull()) {
736 Error(
"GetFromWeb10",
"error - redirect without location from host %s",
fUrl.
GetHost());
757 else if (ll !=
rsize) {
758 Error(
"GetFromWeb10",
"expected %d bytes, got %d", ll,
rsize);
772 Error(
"GetFromWeb10",
"Need segments data to extract parts from full size %lld",
fullsize);
777 Error(
"GetFromWeb10",
"Requested part %d longer than full size %lld",
len,
fullsize);
803 Error(
"GetFromWeb10",
"Requested segments are not in sorted order");
847 Info(
"GetFromWeb10",
"Complete reading %d bytes in %d segments out of full size %lld",
len,
nseg,
fullsize);
856 Info(
"GetFromWeb10",
"header: %s",
line);
860 Info(
"GetFromWeb10",
"got all headers");
866 Info(
"GetFromWeb10",
"get new multipart byte range (%d)",
nranges);
883 }
else if (code >= 400) {
891 }
else if (code >= 300) {
892 if (code == 301 || code == 303) {
894 }
else if (code == 302 || code == 307) {
903 }
else if (code > 200) {
909 }
else if (code == 200) {
912 "Server %s response with complete file, but only part of it was requested.\n"
913 "Check MaxRanges configuration parameter (if Apache is used)",
925 sscanf(res.
Data(),
"content-range: bytes %lld-%lld/%lld", &first, &last, &
tot);
930 redir = res(10, 1000);
939 Error(
"GetFromWeb10",
"error - redirect without location from host %s",
fUrl.
GetHost());
944 Info(
"GetFromWeb10",
"HTTP/1.1 socket closed, reopen");
954 Error(
"GetFromWeb10",
"error receiving expected amount of data (got %d, expected %d) from host %s",
991 Error(
"Seek",
"seeking from end in archive is not (yet) supported");
1064 for (
Int_t i = 0; i < 5; i++) {
1069 Error(
"GetHead",
"library compiled without SSL, https not supported");
1092 Info(
"GetHead",
"connected to host %s",
connurl.GetHost());
1093 Info(
"GetHead",
"sending HTTP request:\n%s",
msg.Data());
1109 Info(
"GetHead",
"got all headers");
1119 if (
redir.IsNull()) {
1121 Error(
"GetHead",
"error - redirect without location from host %s",
fUrl.
GetHost());
1130 Info(
"GetHead",
"header: %s",
line);
1152 }
else if (code >= 400) {
1155 else if (code == 404)
1162 }
else if (code >= 300) {
1163 if (code == 301 || code == 303)
1165 else if (code == 302 || code == 307)
1172 }
else if (code > 200) {
1181 redir = res(10, 1000);
1211 if (
n > 0 &&
line[
n-1] ==
'\n') {
1213 if (
n > 0 &&
line[
n-1] ==
'\r')
1292 Error(
"GetHunk",
"hunk buffer too small for data from host %s (%d bytes needed)",
1326 Error(
"GetHunk",
"hunk buffer too small for data from host %s",
1344 const char *
p, *end;
1353 for (;
p < end - 1;
p++)
1354 if (
p[0] ==
'\r' &&
p[1] ==
'\n')
1358 if (
p[0] ==
'\r' &&
p[1] ==
'\n')
1384 msg +=
"Authorization: Basic ";
1398 if (
strcmp(
p.GetProtocol(),
"http")) {
1399 :: Error(
"TWebFile::SetProxy",
"protocol must be HTTP in proxy URL %s",
1471 Error(
"OpenDirectory",
"invalid directory pointer (should never happen)");
1486 Error(
"FreeDirectory",
"invalid directory pointer (should never happen)");
1499 Error(
"GetDirEntry",
"invalid directory pointer (should never happen)");
1516 if (
f->fWritten == 0) {
1523 buf.
fSize =
f->GetSize();
1543 if (
f->fWritten == 0) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static const std::string gUserAgent
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
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 r
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
R__EXTERN TSystem * gSystem
static const char * gUserAgent
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
static std::atomic< Long64_t > fgBytesRead
Number of bytes read by all TFile objects.
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Long64_t fBytesRead
Number of bytes read from this file.
static void SetFileBytesRead(Long64_t bytes=0)
static void SetFileReadCalls(Int_t readcalls=0)
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Long64_t fArchiveOffset
!Offset at which file starts in archive
virtual void Init(Bool_t create)
Initialize a TFile object.
Bool_t fIsRootFile
!True is this is a ROOT file, raw file otherwise
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Long64_t fOffset
!Seek offset cache
Long64_t fEND
Last used byte in file.
void Close(Option_t *option="") override
Close a file.
static std::atomic< Int_t > fgReadCalls
Number of bytes read from all TFile objects.
Int_t fWritten
Number of objects written so far.
static Int_t GetFileReadCalls()
Static function returning the total number of read calls from all files.
virtual void SetName(const char *name)
Set the name of the TNamed.
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
virtual Bool_t IsValid() const
void ToLower()
Change string to lower-case.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
void ToUpper()
Change string to upper case.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Abstract base class defining a generic interface to the underlying Operating System.
static Int_t GetErrno()
Static function returning system error number.
virtual const char * Getenv(const char *env)
Get environment variable.
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
The TTimeStamp encapsulates seconds and ns since EPOCH.
This class represents a WWW compatible URL.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
const char * GetFile() const
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
const char * GetUser() const
const char * GetHost() const
const char * GetPasswd() const
const char * GetOptions() const
const char * GetProtocol() const
virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize)
Read a line from the socket.
virtual ~TWebFile()
Cleanup.
virtual Int_t GetHead()
Get the HTTP header.
virtual Int_t GetFromWeb(char *buf, Int_t len, const TString &msg)
Read request from web server.
virtual TString BasicAuthentication()
Return basic authentication scheme, to be added to the request.
static const char * GetProxy()
Static method returning the global proxy URL.
static void SetProxy(const char *url)
Static method setting global proxy URL.
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.
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.
Bool_t IsOpen() const override
A TWebFile that has been correctly constructed is always considered open.
virtual void CheckProxy()
Check if shell var "http_proxy" has been set and should be used.
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).
Bool_t ReadBuffer(char *buf, Int_t len) override
Read specified byte range from remote file via HTTP daemon.
Long64_t fFullCacheSize
complete content of the file, some http server may return complete content
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.
void Seek(Long64_t offset, ERelativeTo pos=kBeg) override
Set position from where to start reading.
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).
void Init(Bool_t readHeadOnly) override
Initialize a TWebFile object.
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.
static TUrl fgProxy
size of the cached content
static void SetMaxFullCacheSize(Long64_t sz)
Static method, set maxmimal size of full cache,.
virtual void SetMsgReadBuffer10(const char *redirectLocation=nullptr, Bool_t tempRedirect=kFALSE)
Set GET command for use by ReadBuffer(s)10(), handle redirection if needed.
Int_t ReOpen(Option_t *mode) override
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE,...
static Long64_t GetMaxFullCacheSize()
Static method returning maxmimal size of full cache, which can be preserved by file instance.
virtual void ProcessHttpHeader(const TString &headerLine)
Process the HTTP header in the argument.
void Close(Option_t *option="") override
Close a Web file.
virtual Int_t GetHunk(TSocket *s, char *hunk, Int_t maxsize)
Read a hunk of data from the socket, up until a terminator.
static Long64_t fgMaxFullCacheSize
~TWebSocket()
Close socket in case not HTTP/1.1 protocol or when explicitly requested.
void ReOpen()
Re-open web file socket.
TWebSocket(TWebFile *f)
Open web file socket.
void * OpenDirectory(const char *name) override
Open a directory via httpd.
Int_t MakeDirectory(const char *name) override
Make a directory via httpd. Not supported.
TWebSystem()
Create helper class that allows directory access via httpd.
void FreeDirectory(void *dirp) override
Free directory via httpd.
Bool_t AccessPathName(const char *path, EAccessMode mode) override
Returns FALSE if one can access a file using the specified access mode.
Int_t GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
const char * GetDirEntry(void *dirp) override
Get directory entry via httpd. Returns 0 in case no more entries.
Int_t Unlink(const char *path) override
Unlink, i.e.