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"),
 
  252      if (strncmp(buf, 
"root", 4) && strncmp(buf, 
"PK", 2)) {  
 
  273   if (redirectLocation) {
 
  295      if (rdl.
Index(
"?") >= 0) {
 
  303      if (oldBasicUrl != 
"") {
 
  366      if (strcmp(
p.GetProtocol(), 
"http")) {
 
  367         Error(
"CheckProxy", 
"protocol must be HTTP in proxy URL %s",
 
  399   if (opt != 
"READ" && opt != 
"UPDATE")
 
  400      Error(
"ReOpen", 
"mode must be either READ or UPDATE, not %s", opt.
Data());
 
  403      Error(
"ReOpen", 
"update mode not allowed for a TWebFile");
 
  532   Int_t k = 0, 
n = 0, cnt = 0;
 
  533   for (
Int_t i = 0; i < nbuf; i++) {
 
  540      if ((msg.
Length() > 8000) || (cnt >= 200)) {
 
  573   Int_t k = 0, 
n = 0, 
r, cnt = 0;
 
  574   for (
Int_t i = 0; i < nbuf; i++) {
 
  581      if ((msg.
Length() > 8000) || (cnt >= 200) || (i+1 == nbuf)) {
 
  606      Info(
"GetFromCache", 
"Extract %d segments total len %d from cached data", nseg, 
len);
 
  609   for (
Int_t cnt=0;cnt<nseg;cnt++) {
 
  611      if (curr + seg_len[cnt] > 
len) 
return -1;
 
  615      memcpy(buf + curr, 
src, seg_len[cnt]);
 
  616      curr += seg_len[cnt];
 
  645      Error(
"GetFromWeb", 
"library compiled without SSL, https not supported");
 
  713      Info(
"GetFromWeb10", 
"sending HTTP request:\n%s", msg.
Data());
 
  721   Int_t n, ret = 0, nranges = 0, ltot = 0, redirect = 0;
 
  733              Error(
"GetFromWeb10", 
"error - redirect without location from host %s", 
fUrl.
GetHost());
 
  754            else if (ll != rsize) {
 
  755               Error(
"GetFromWeb10", 
"expected %d bytes, got %d", ll, rsize);
 
  769               Error(
"GetFromWeb10",
"Need segments data to extract parts from full size %lld", fullsize);
 
  773            if (
len > fullsize) {
 
  774               Error(
"GetFromWeb10",
"Requested part %d longer than full size %lld", 
len, fullsize);
 
  794            for (
Int_t cnt=0;cnt<nseg;cnt++) {
 
  796                  Error(
"GetFromWeb10",
"Requested segment %lld len %d is outside of full range %lld",  seg_pos[cnt], seg_len[cnt], fullsize);
 
  799               if ((cnt>0) &&  (seg_pos[cnt-1] + seg_len[cnt-1] > seg_pos[cnt])) {
 
  800                  Error(
"GetFromWeb10",
"Requested segments are not in sorted order");
 
  810            for (
Int_t cnt=0; cnt<nseg; cnt++) {
 
  814                  if (ll > 
Int_t(
sizeof(dbuf))) ll = 
sizeof(dbuf);
 
  827               curr += seg_len[cnt];
 
  829               ltot += seg_len[cnt];
 
  833            while (pos < fullsize) {
 
  835               if (ll > 
Int_t(
sizeof(dbuf))) ll = 
sizeof(dbuf);
 
  843            if (
gDebug>0) 
Info(
"GetFromWeb10",
"Complete reading %d bytes in %d segments out of full size %lld", 
len, nseg, fullsize);
 
  852         Info(
"GetFromWeb10", 
"header: %s", 
line);
 
  854      if (boundaryEnd == 
line) {
 
  856            Info(
"GetFromWeb10", 
"got all headers");
 
  859      if (boundary == 
line) {
 
  862            Info(
"GetFromWeb10", 
"get new multipart byte range (%d)", nranges);
 
  879         } 
else if (code >= 400) {
 
  887         } 
else if (code >= 300) {
 
  888            if (code == 301 || code == 303) {
 
  890            } 
else if (code == 302 || code == 307) {
 
  899         } 
else if (code > 200) {
 
  905         } 
else if (code == 200) {
 
  908                    "Server %s response with complete file, but only part of it was requested.\n" 
  909                    "Check MaxRanges configuration parameter (if Apache is used)",
 
  913      } 
else if (res.
BeginsWith(
"Content-Type: multipart")) {
 
  914         boundary = res(res.
Index(
"boundary=")+9, 1000);
 
  915         if (boundary[0]==
'"' && boundary[boundary.
Length()-1]==
'"') {
 
  916            boundary = boundary(1,boundary.
Length()-2);
 
  918         boundary = 
"--" + boundary;
 
  919         boundaryEnd = boundary + 
"--";
 
  920      } 
else if (res.
BeginsWith(
"Content-range:")) {
 
  922         sscanf(res.
Data(), 
"Content-range: bytes %I64d-%I64d/%I64d", &
first, &last, &tot);
 
  924         sscanf(res.
Data(), 
"Content-range: bytes %lld-%lld/%lld", &
first, &last, &tot);
 
  927      } 
else if (res.
BeginsWith(
"Content-Range:")) {
 
  929         sscanf(res.
Data(), 
"Content-Range: bytes %I64d-%I64d/%I64d", &
first, &last, &tot);
 
  931         sscanf(res.
Data(), 
"Content-Range: bytes %lld-%lld/%lld", &
first, &last, &tot);
 
  934      } 
else if (res.
BeginsWith(
"Content-Length:") && (fullsize == -200)) {
 
  936         sscanf(res.
Data(), 
"Content-Length: %I64d", &fullsize);
 
  938         sscanf(res.
Data(), 
"Content-Length: %lld", &fullsize);
 
  940      } 
else if (res.
BeginsWith(
"Location:") && redirect) {
 
  941         redir = res(10, 1000);
 
  949   if (redirect && redir.
IsNull()) {
 
  950      Error(
"GetFromWeb10", 
"error - redirect without location from host %s", 
fUrl.
GetHost());
 
  955         Info(
"GetFromWeb10", 
"HTTP/1.1 socket closed, reopen");
 
  965      Error(
"GetFromWeb10", 
"error receiving expected amount of data (got %d, expected %d) from host %s",
 
 1002         Error(
"Seek", 
"seeking from end in archive is not (yet) supported");
 
 1029   size = atoll(asize);
 
 1031   size = _atoi64(asize);
 
 1075   for (
Int_t i = 0; i < 5; i++) {
 
 1076      if (strcmp(connurl.
GetProtocol(), 
"https") == 0) {
 
 1080         Error(
"GetHead", 
"library compiled without SSL, https not supported");
 
 1103      Info(
"GetHead", 
"connected to host %s", connurl.
GetHost());
 
 1104      Info(
"GetHead", 
"sending HTTP request:\n%s", msg.
Data());
 
 1114   Int_t n, ret = 0, redirect = 0;
 
 1120            Info(
"GetHead", 
"got all headers");
 
 1132               Error(
"GetHead", 
"error - redirect without location from host %s", 
fUrl.
GetHost());
 
 1141         Info(
"GetHead", 
"header: %s", 
line);
 
 1163         } 
else if (code >= 400) {
 
 1166            else if (code == 404)
 
 1173         } 
else if (code >= 300) {
 
 1174            if (code == 301 || code == 303)
 
 1176            else if (code == 302 || code == 307)
 
 1183         } 
else if (code > 200) {
 
 1188      } 
else if (res.
BeginsWith(
"Content-Length:")) {
 
 1191      } 
else if (res.
BeginsWith(
"Location:") && redirect) {
 
 1192         redir = res(10, 1000);
 
 1222   if (
n > 0 && 
line[
n-1] == 
'\n') {
 
 1224      if (
n > 0 && 
line[
n-1] == 
'\r')
 
 1278   if (maxsize <= 0) 
return 0;
 
 1280   Int_t bufsize = maxsize;
 
 1285      Int_t pklen, rdlen, remain;
 
 1296         remain = end - (hunk + tail);
 
 1302         if (bufsize - 1 < tail + remain) {
 
 1303            Error(
"GetHunk", 
"hunk buffer too small for data from host %s (%d bytes needed)",
 
 1328      if (end && rdlen == remain) {
 
 1336      if (tail == bufsize - 1) {
 
 1337         Error(
"GetHunk", 
"hunk buffer too small for data from host %s",
 
 1355   const char *
p, *end;
 
 1360   p = peeked - start < 1 ? start : peeked - 1;
 
 1361   end = peeked + peeklen;
 
 1364   for (; 
p < end - 1; 
p++)
 
 1365      if (
p[0] == 
'\r' && 
p[1] == 
'\n')
 
 1369   if (
p[0] == 
'\r' && 
p[1] == 
'\n')
 
 1374      const char *
p = (
const char*) memchr(peeked, 
'\n', peeklen);
 
 1395      msg += 
"Authorization: Basic ";
 
 1407   if (proxy && *proxy) {
 
 1409      if (strcmp(
p.GetProtocol(), 
"http")) {
 
 1410         :: Error(
"TWebFile::SetProxy", 
"protocol must be HTTP in proxy URL %s",
 
 1482      Error(
"OpenDirectory", 
"invalid directory pointer (should never happen)");
 
 1496   if (dirp != 
fDirp) {
 
 1497      Error(
"FreeDirectory", 
"invalid directory pointer (should never happen)");
 
 1509   if (dirp != 
fDirp) {
 
 1510      Error(
"GetDirEntry", 
"invalid directory pointer (should never happen)");
 
 1527   if (
f->fWritten == 0) {
 
 1534      buf.
fSize   = 
f->GetSize();
 
 1554   if (
f->fWritten == 0) {
 
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
 
static const std::string gUserAgent
 
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
 
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 a suite of consecutive data records (TKey instances) with a well defined format.
 
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
 
Int_t Atoi() const
Return integer value of string.
 
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
 
Long64_t Atoll() const
Return long long value of string.
 
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.