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");
531 Int_t k = 0,
n = 0, cnt = 0;
532 for (
Int_t i = 0; i < nbuf; i++) {
539 if ((msg.
Length() > 8000) || (cnt >= 200)) {
572 Int_t k = 0,
n = 0,
r, cnt = 0;
573 for (
Int_t i = 0; i < nbuf; i++) {
580 if ((msg.
Length() > 8000) || (cnt >= 200) || (i+1 == nbuf)) {
605 Info(
"GetFromCache",
"Extract %d segments total len %d from cached data", nseg,
len);
608 for (
Int_t cnt=0;cnt<nseg;cnt++) {
610 if (curr + seg_len[cnt] >
len)
return -1;
614 memcpy(buf + curr,
src, seg_len[cnt]);
615 curr += seg_len[cnt];
644 Error(
"GetFromWeb",
"library compiled without SSL, https not supported");
712 Info(
"GetFromWeb10",
"sending HTTP request:\n%s", msg.
Data());
720 Int_t n, ret = 0, nranges = 0, ltot = 0, redirect = 0;
722 Long64_t first = -1, last = -1, tot, fullsize = 0;
732 Error(
"GetFromWeb10",
"error - redirect without location from host %s",
fUrl.
GetHost());
753 else if (ll != rsize) {
754 Error(
"GetFromWeb10",
"expected %d bytes, got %d", ll, rsize);
768 Error(
"GetFromWeb10",
"Need segments data to extract parts from full size %lld", fullsize);
772 if (
len > fullsize) {
773 Error(
"GetFromWeb10",
"Requested part %d longer than full size %lld",
len, fullsize);
793 for (
Int_t cnt=0;cnt<nseg;cnt++) {
795 Error(
"GetFromWeb10",
"Requested segment %lld len %d is outside of full range %lld", seg_pos[cnt], seg_len[cnt], fullsize);
798 if ((cnt>0) && (seg_pos[cnt-1] + seg_len[cnt-1] > seg_pos[cnt])) {
799 Error(
"GetFromWeb10",
"Requested segments are not in sorted order");
809 for (
Int_t cnt=0; cnt<nseg; cnt++) {
813 if (ll >
Int_t(
sizeof(dbuf))) ll =
sizeof(dbuf);
826 curr += seg_len[cnt];
828 ltot += seg_len[cnt];
832 while (pos < fullsize) {
834 if (ll >
Int_t(
sizeof(dbuf))) ll =
sizeof(dbuf);
842 if (
gDebug>0)
Info(
"GetFromWeb10",
"Complete reading %d bytes in %d segments out of full size %lld",
len, nseg, fullsize);
851 Info(
"GetFromWeb10",
"header: %s",
line);
853 if (boundaryEnd ==
line) {
855 Info(
"GetFromWeb10",
"got all headers");
858 if (boundary ==
line) {
861 Info(
"GetFromWeb10",
"get new multipart byte range (%d)", nranges);
878 }
else if (code >= 400) {
886 }
else if (code >= 300) {
887 if (code == 301 || code == 303) {
889 }
else if (code == 302 || code == 307) {
898 }
else if (code > 200) {
904 }
else if (code == 200) {
907 "Server %s response with complete file, but only part of it was requested.\n"
908 "Check MaxRanges configuration parameter (if Apache is used)",
912 }
else if (res.
BeginsWith(
"Content-Type: multipart")) {
913 boundary = res(res.
Index(
"boundary=")+9, 1000);
914 if (boundary[0]==
'"' && boundary[boundary.
Length()-1]==
'"') {
915 boundary = boundary(1,boundary.
Length()-2);
917 boundary =
"--" + boundary;
918 boundaryEnd = boundary +
"--";
919 }
else if (res.
BeginsWith(
"Content-range:")) {
921 sscanf(res.
Data(),
"Content-range: bytes %I64d-%I64d/%I64d", &first, &last, &tot);
923 sscanf(res.
Data(),
"Content-range: bytes %lld-%lld/%lld", &first, &last, &tot);
926 }
else if (res.
BeginsWith(
"Content-Range:")) {
928 sscanf(res.
Data(),
"Content-Range: bytes %I64d-%I64d/%I64d", &first, &last, &tot);
930 sscanf(res.
Data(),
"Content-Range: bytes %lld-%lld/%lld", &first, &last, &tot);
933 }
else if (res.
BeginsWith(
"Content-Length:") && (fullsize == -200)) {
935 sscanf(res.
Data(),
"Content-Length: %I64d", &fullsize);
937 sscanf(res.
Data(),
"Content-Length: %lld", &fullsize);
939 }
else if (res.
BeginsWith(
"Location:") && redirect) {
940 redir = res(10, 1000);
948 if (redirect && redir.
IsNull()) {
949 Error(
"GetFromWeb10",
"error - redirect without location from host %s",
fUrl.
GetHost());
954 Info(
"GetFromWeb10",
"HTTP/1.1 socket closed, reopen");
964 Error(
"GetFromWeb10",
"error receiving expected amount of data (got %d, expected %d) from host %s",
1001 Error(
"Seek",
"seeking from end in archive is not (yet) supported");
1028 size = atoll(asize);
1030 size = _atoi64(asize);
1074 for (
Int_t i = 0; i < 5; i++) {
1075 if (strcmp(connurl.
GetProtocol(),
"https") == 0) {
1079 Error(
"GetHead",
"library compiled without SSL, https not supported");
1102 Info(
"GetHead",
"connected to host %s", connurl.
GetHost());
1103 Info(
"GetHead",
"sending HTTP request:\n%s", msg.
Data());
1113 Int_t n, ret = 0, redirect = 0;
1119 Info(
"GetHead",
"got all headers");
1131 Error(
"GetHead",
"error - redirect without location from host %s",
fUrl.
GetHost());
1140 Info(
"GetHead",
"header: %s",
line);
1162 }
else if (code >= 400) {
1165 else if (code == 404)
1172 }
else if (code >= 300) {
1173 if (code == 301 || code == 303)
1175 else if (code == 302 || code == 307)
1182 }
else if (code > 200) {
1187 }
else if (res.
BeginsWith(
"Content-Length:")) {
1190 }
else if (res.
BeginsWith(
"Location:") && redirect) {
1191 redir = res(10, 1000);
1221 if (
n > 0 &&
line[
n-1] ==
'\n') {
1223 if (
n > 0 &&
line[
n-1] ==
'\r')
1277 if (maxsize <= 0)
return 0;
1279 Int_t bufsize = maxsize;
1284 Int_t pklen, rdlen, remain;
1295 remain = end - (hunk + tail);
1301 if (bufsize - 1 < tail + remain) {
1302 Error(
"GetHunk",
"hunk buffer too small for data from host %s (%d bytes needed)",
1327 if (end && rdlen == remain) {
1335 if (tail == bufsize - 1) {
1336 Error(
"GetHunk",
"hunk buffer too small for data from host %s",
1354 const char *
p, *end;
1359 p = peeked - start < 1 ? start : peeked - 1;
1360 end = peeked + peeklen;
1363 for (;
p < end - 1;
p++)
1364 if (
p[0] ==
'\r' &&
p[1] ==
'\n')
1368 if (
p[0] ==
'\r' &&
p[1] ==
'\n')
1373 const char *
p = (
const char*) memchr(peeked,
'\n', peeklen);
1394 msg +=
"Authorization: Basic ";
1406 if (proxy && *proxy) {
1408 if (strcmp(
p.GetProtocol(),
"http")) {
1409 :: Error(
"TWebFile::SetProxy",
"protocol must be HTTP in proxy URL %s",
1481 Error(
"OpenDirectory",
"invalid directory pointer (should never happen)");
1495 if (dirp !=
fDirp) {
1496 Error(
"FreeDirectory",
"invalid directory pointer (should never happen)");
1508 if (dirp !=
fDirp) {
1509 Error(
"GetDirEntry",
"invalid directory pointer (should never happen)");
1526 if (
f->fWritten == 0) {
1533 buf.
fSize =
f->GetSize();
1553 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 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
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.