Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebFile.cxx
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//////////////////////////////////////////////////////////////////////////
13// //
14// TWebFile //
15// //
16// A TWebFile is like a normal TFile except that it reads its data //
17// via a standard apache web server. A TWebFile is a read-only file. //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TWebFile.h"
22#include "TROOT.h"
23#include "TSocket.h"
24#include "Bytes.h"
25#include "TError.h"
26#include "TSystem.h"
27#include "TBase64.h"
28#include "TVirtualPerfStats.h"
29#ifdef R__SSL
30#include "TSSLSocket.h"
31#endif
32
33#include <errno.h>
34#include <stdlib.h>
35#include <string.h>
36
37#ifdef WIN32
38# ifndef EADDRINUSE
39# define EADDRINUSE 10048
40# endif
41# ifndef EISCONN
42# define EISCONN 10056
43# endif
44#endif
45
46static const char *gUserAgent = "User-Agent: ROOT-TWebFile/1.1";
47
49
51
52
53// Internal class used to manage the socket that may stay open between
54// calls when HTTP/1.1 protocol is used
56private:
57 TWebFile *fWebFile; // associated web file
58public:
61 void ReOpen();
62};
63
64////////////////////////////////////////////////////////////////////////////////
65/// Open web file socket.
66
68{
69 fWebFile = f;
70 if (!f->fSocket)
71 ReOpen();
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Close socket in case not HTTP/1.1 protocol or when explicitly requested.
76
78{
79 if (!fWebFile->fHTTP11) {
80 delete fWebFile->fSocket;
81 fWebFile->fSocket = nullptr;
82 }
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Re-open web file socket.
87
89{
90 if (fWebFile->fSocket) {
91 delete fWebFile->fSocket;
92 fWebFile->fSocket = nullptr;
93 }
94
96 if (fWebFile->fProxy.IsValid())
98 else
100
101 for (Int_t i = 0; i < 5; i++) {
102 if (strcmp(connurl.GetProtocol(), "https") == 0) {
103#ifdef R__SSL
104 fWebFile->fSocket = new TSSLSocket(connurl.GetHost(), connurl.GetPort());
105#else
106 ::Error("TWebSocket::ReOpen", "library compiled without SSL, https not supported");
107 return;
108#endif
109 } else
110 fWebFile->fSocket = new TSocket(connurl.GetHost(), connurl.GetPort());
111
112 if (!fWebFile->fSocket || !fWebFile->fSocket->IsValid()) {
113 delete fWebFile->fSocket;
114 fWebFile->fSocket = nullptr;
115 if (gSystem->GetErrno() == EADDRINUSE || gSystem->GetErrno() == EISCONN) {
116 gSystem->Sleep(i*10);
117 } else {
118 ::Error("TWebSocket::ReOpen", "cannot connect to host %s (errno=%d)",
120 return;
121 }
122 } else
123 return;
124 }
125}
126
127
129
130////////////////////////////////////////////////////////////////////////////////
131/// Create a Web file object. A web file is the same as a read-only
132/// TFile except that it is being read via a HTTP server. The url
133/// argument must be of the form: http://host.dom.ain/file.root.
134/// The opt can be "NOPROXY", to bypass any set "http_proxy" shell
135/// variable. The proxy can be specified as (in sh, or equivalent csh):
136/// export http_proxy=http://pcsalo.cern.ch:3128
137/// The proxy can also be specified via the static method TWebFile::SetProxy().
138/// Basic authentication (AuthType Basic) is supported. The user name and
139/// passwd can be specified in the url like this:
140/// http://username:mypasswd@pcsalo.cern.ch/files/aap.root
141/// If the file specified in the URL does not exist or is not accessible
142/// the kZombie bit will be set in the TWebFile object. Use IsZombie()
143/// to see if the file is accessible. The preferred interface to this
144/// constructor is via TFile::Open().
145
147 : TFile(url, strstr(opt, "_WITHOUT_GLOBALREGISTRATION") != nullptr ? "WEB_WITHOUT_GLOBALREGISTRATION" : "WEB"),
148 fSocket(0)
149{
150 TString option = opt;
152 if (option.Contains("NOPROXY", TString::kIgnoreCase))
153 fNoProxy = kTRUE;
154 CheckProxy();
155
157 if (option.Contains("HEADONLY", TString::kIgnoreCase))
158 headOnly = kTRUE;
159
160 if (option == "IO")
161 return;
162
163 Init(headOnly);
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Create a Web file object. A web file is the same as a read-only
168/// TFile except that it is being read via a HTTP server. Make sure url
169/// is a valid TUrl object.
170/// The opt can be "NOPROXY", to bypass any set "http_proxy" shell
171/// variable. The proxy can be specified as (in sh, or equivalent csh):
172/// export http_proxy=http://pcsalo.cern.ch:3128
173/// The proxy can also be specified via the static method TWebFile::SetProxy().
174/// Basic authentication (AuthType Basic) is supported. The user name and
175/// passwd can be specified in the url like this:
176/// http://username:mypasswd@pcsalo.cern.ch/files/aap.root
177/// If the file specified in the URL does not exist or is not accessible
178/// the kZombie bit will be set in the TWebFile object. Use IsZombie()
179/// to see if the file is accessible.
180
181TWebFile::TWebFile(TUrl url, Option_t *opt) : TFile(url.GetUrl(), "WEB"), fSocket(0)
182{
183 TString option = opt;
185 if (option.Contains("NOPROXY", TString::kIgnoreCase))
186 fNoProxy = kTRUE;
187 CheckProxy();
188
190 if (option.Contains("HEADONLY", TString::kIgnoreCase))
191 headOnly = kTRUE;
192
193 Init(headOnly);
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Cleanup.
198
200{
201 delete fSocket;
202 if (fFullCache) {
204 fFullCache = nullptr;
205 fFullCacheSize = 0;
206 }
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Initialize a TWebFile object.
211
213{
214 char buf[4];
215 int err;
216
217 fSocket = nullptr;
218 fSize = -1;
220#if defined(R__WIN32) && defined(R__SSL)
221 fHTTP11 = kTRUE;
222#else
223 fHTTP11 = kFALSE;
224#endif
225 fFullCache = nullptr;
226 fFullCacheSize = 0;
228
229 if ((err = GetHead()) < 0) {
230 if (readHeadOnly) {
231 fD = -1;
232 fWritten = err;
233 return;
234 }
235 if (err == -2) {
236 Error("TWebFile", "%s does not exist", fBasicUrl.Data());
237 MakeZombie();
239 return;
240 }
241 // err == -3 HEAD not supported, fall through and try ReadBuffer()
242 }
243 if (readHeadOnly) {
244 fD = -1;
245 return;
246 }
247
248 if (fIsRootFile) {
249 Seek(0);
250 if (ReadBuffer(buf, 4)) {
251 MakeZombie();
253 return;
254 }
255
256 if (strncmp(buf, "root", 4) && strncmp(buf, "PK", 2)) { // PK is zip file
257 Error("TWebFile", "%s is not a ROOT file", fBasicUrl.Data());
258 MakeZombie();
260 return;
261 }
262 }
263
265 fD = -2; // so TFile::IsOpen() will return true when in TFile::~TFile
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set GET command for use by ReadBuffer(s)10(), handle redirection if
270/// needed. Give full URL so Apache's virtual hosts solution works.
271
273{
274 TUrl oldUrl;
276
277 if (redirectLocation) {
278 if (tempRedirect) { // temp redirect
279 fUrlOrg = fUrl;
281 } else { // permanent redirect
282 fUrlOrg = "";
283 fBasicUrlOrg = "";
284 }
285
286 oldUrl = fUrl;
288
291 fBasicUrl += "://";
293 fBasicUrl += ":";
295 fBasicUrl += "/";
297 // add query string again
299 if (rdl.Index("?") >= 0) {
300 rdl = rdl(rdl.Index("?"), rdl.Length());
301 fBasicUrl += rdl;
302 }
303 }
304
305 if (fMsgReadBuffer10 != "") {
306 // patch up existing command
307 if (oldBasicUrl != "") {
308 // change to redirection location
310 fMsgReadBuffer10.ReplaceAll(TString("Host: ")+oldUrl.GetHost(), TString("Host: ")+fUrl.GetHost());
311 } else if (fBasicUrlOrg != "") {
312 // change back from temp redirection location
315 fUrl = fUrlOrg;
317 fUrlOrg = "";
318 fBasicUrlOrg = "";
319 }
320 }
321
322 if (fBasicUrl == "") {
324 fBasicUrl += "://";
326 fBasicUrl += ":";
328 fBasicUrl += "/";
330 fBasicUrl += "?";
332 }
333
334 if (fMsgReadBuffer10 == "") {
335 fMsgReadBuffer10 = "GET ";
337 if (fHTTP11)
338 fMsgReadBuffer10 += " HTTP/1.1";
339 else
340 fMsgReadBuffer10 += " HTTP/1.0";
341 fMsgReadBuffer10 += "\r\n";
342 if (fHTTP11) {
343 fMsgReadBuffer10 += "Host: ";
345 fMsgReadBuffer10 += "\r\n";
346 }
349 fMsgReadBuffer10 += "\r\n";
350 fMsgReadBuffer10 += "Range: bytes=";
351 }
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Check if shell var "http_proxy" has been set and should be used.
356
358{
359 if (fNoProxy)
360 return;
361
362 if (fgProxy.IsValid()) {
363 fProxy = fgProxy;
364 return;
365 }
366
367 TString proxy = gSystem->Getenv("http_proxy");
368 if (proxy != "") {
369 TUrl p(proxy);
370 if (strcmp(p.GetProtocol(), "http")) {
371 Error("CheckProxy", "protocol must be HTTP in proxy URL %s",
372 proxy.Data());
373 return;
374 }
375 fProxy = p;
376 if (gDebug > 0)
377 Info("CheckProxy", "using HTTP proxy %s", fProxy.GetUrl());
378 }
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// A TWebFile that has been correctly constructed is always considered open.
383
385{
386 return IsZombie() ? kFALSE : kTRUE;
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Reopen a file with a different access mode, like from READ to
391/// UPDATE or from NEW, CREATE, RECREATE, UPDATE to READ. Thus the
392/// mode argument can be either "READ" or "UPDATE". The method returns
393/// 0 in case the mode was successfully modified, 1 in case the mode
394/// did not change (was already as requested or wrong input arguments)
395/// and -1 in case of failure, in which case the file cannot be used
396/// anymore. A TWebFile cannot be reopened in update mode.
397
399{
400 TString opt = mode;
401 opt.ToUpper();
402
403 if (opt != "READ" && opt != "UPDATE")
404 Error("ReOpen", "mode must be either READ or UPDATE, not %s", opt.Data());
405
406 if (opt == "UPDATE")
407 Error("ReOpen", "update mode not allowed for a TWebFile");
408
409 return 1;
410}
411
412////////////////////////////////////////////////////////////////////////////////
413/// Close a Web file. Close the socket connection and delete the cache
414/// See also the TFile::Close() function
415
417{
418 delete fSocket;
419 fSocket = nullptr;
420 if (fFullCache) {
422 fFullCache = nullptr;
423 fFullCacheSize = 0;
424 }
425 return TFile::Close(option);
426}
427
428////////////////////////////////////////////////////////////////////////////////
429/// Read specified byte range from remote file via HTTP daemon. This
430/// routine connects to the remote host, sends the request and returns
431/// the buffer. Returns kTRUE in case of error.
432
434{
435 Int_t st;
436 if ((st = ReadBufferViaCache(buf, len))) {
437 if (st == 2)
438 return kTRUE;
439 return kFALSE;
440 }
441
442 if (!fHasModRoot)
443 return ReadBuffer10(buf, len);
444
445 // Give full URL so Apache's virtual hosts solution works.
446 // Use protocol 0.9 for efficiency, we are not interested in the 1.0 headers.
447 if (fMsgReadBuffer == "") {
448 fMsgReadBuffer = "GET ";
450 fMsgReadBuffer += "?";
451 }
453 msg += fOffset;
454 msg += ":";
455 msg += len;
456 msg += "\r\n";
457
458 if (GetFromWeb(buf, len, msg) == -1)
459 return kTRUE;
460
461 fOffset += len;
462
463 return kFALSE;
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// Read specified byte range from remote file via HTTP daemon. This
468/// routine connects to the remote host, sends the request and returns
469/// the buffer. Returns kTRUE in case of error.
470
472{
473 SetOffset(pos);
474 return ReadBuffer(buf, len);
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Read specified byte range from remote file via HTTP 1.0 daemon (without
479/// mod-root installed). This routine connects to the remote host, sends the
480/// request and returns the buffer. Returns kTRUE in case of error.
481
483{
485
487 msg += fOffset;
488 msg += "-";
489 msg += fOffset+len-1;
490 msg += "\r\n\r\n";
491
493
494 // in case when server does not support segments, let chance to recover
495 Int_t n = GetFromWeb10(buf, len, msg, 1, &apos, &len);
496 if (n == -1)
497 return kTRUE;
498 // The -2 error condition typically only happens when
499 // GetHead() failed because not implemented, in the first call to
500 // ReadBuffer() in Init(), it is not checked in ReadBuffers10().
501 if (n == -2) {
502 Error("ReadBuffer10", "%s does not exist", fBasicUrl.Data());
503 MakeZombie();
505 return kTRUE;
506 }
507
508 fOffset += len;
509
510 return kFALSE;
511}
512
513////////////////////////////////////////////////////////////////////////////////
514/// Read specified byte ranges from remote file via HTTP daemon.
515/// Reads the nbuf blocks described in arrays pos and len,
516/// where pos[i] is the seek position of block i of length len[i].
517/// Note that for nbuf=1, this call is equivalent to TFile::ReafBuffer
518/// This function is overloaded by TNetFile, TWebFile, etc.
519/// Returns kTRUE in case of failure.
520
522{
523 if (!fHasModRoot)
524 return ReadBuffers10(buf, pos, len, nbuf);
525
526 // Give full URL so Apache's virtual hosts solution works.
527 // Use protocol 0.9 for efficiency, we are not interested in the 1.0 headers.
528 if (fMsgReadBuffer == "") {
529 fMsgReadBuffer = "GET ";
531 fMsgReadBuffer += "?";
532 }
534
535 Int_t k = 0, n = 0, cnt = 0;
536 for (Int_t i = 0; i < nbuf; i++) {
537 if (n) msg += ",";
538 msg += pos[i] + fArchiveOffset;
539 msg += ":";
540 msg += len[i];
541 n += len[i];
542 cnt++;
543 if ((msg.Length() > 8000) || (cnt >= 200)) {
544 msg += "\r\n";
545 if (GetFromWeb(&buf[k], n, msg) == -1)
546 return kTRUE;
548 k += n;
549 n = 0;
550 cnt = 0;
551 }
552 }
553
554 msg += "\r\n";
555
556 if (GetFromWeb(&buf[k], n, msg) == -1)
557 return kTRUE;
558
559 return kFALSE;
560}
561
562////////////////////////////////////////////////////////////////////////////////
563/// Read specified byte ranges from remote file via HTTP 1.0 daemon (without
564/// mod-root installed). Read the nbuf blocks described in arrays pos and len,
565/// where pos[i] is the seek position of block i of length len[i].
566/// Note that for nbuf=1, this call is equivalent to TFile::ReafBuffer
567/// This function is overloaded by TNetFile, TWebFile, etc.
568/// Returns kTRUE in case of failure.
569
571{
573
575
576 Int_t k = 0, n = 0, r, cnt = 0;
577 for (Int_t i = 0; i < nbuf; i++) {
578 if (n) msg += ",";
579 msg += pos[i] + fArchiveOffset;
580 msg += "-";
581 msg += pos[i] + fArchiveOffset + len[i] - 1;
582 n += len[i];
583 cnt++;
584 if ((msg.Length() > 8000) || (cnt >= 200) || (i+1 == nbuf)) {
585 msg += "\r\n\r\n";
586 r = GetFromWeb10(&buf[k], n, msg, cnt, pos + (i+1-cnt), len + (i+1-cnt));
587 if (r == -1)
588 return kTRUE;
590 k += n;
591 n = 0;
592 cnt = 0;
593 }
594 }
595
596 return kFALSE;
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Extract requested segments from the cached content.
601/// Such cache can be produced when server suddenly returns full data instead of segments
602/// Returns -1 in case of error, 0 in case of success
603
605{
606 if (!fFullCache) return -1;
607
608 if (gDebug > 0)
609 Info("GetFromCache", "Extract %d segments total len %d from cached data", nseg, len);
610
611 Int_t curr = 0;
612 for (Int_t cnt=0;cnt<nseg;cnt++) {
613 // check that target buffer has enough space
614 if (curr + seg_len[cnt] > len) return -1;
615 // check that segment is inside cached area
616 if (fArchiveOffset + seg_pos[cnt] + seg_len[cnt] > fFullCacheSize) return -1;
617 char* src = (char*) fFullCache + fArchiveOffset + seg_pos[cnt];
618 memcpy(buf + curr, src, seg_len[cnt]);
619 curr += seg_len[cnt];
620 }
621
622 return 0;
623}
624
625////////////////////////////////////////////////////////////////////////////////
626/// Read request from web server. Returns -1 in case of error,
627/// 0 in case of success.
628
630{
631 TSocket *s;
632
633 if (!len) return 0;
634
635 Double_t start = 0;
636 if (gPerfStats) start = TTimeStamp();
637
639 if (fProxy.IsValid())
640 connurl = fProxy;
641 else
642 connurl = fUrl;
643
644 if (strcmp(connurl.GetProtocol(), "https") == 0) {
645#ifdef R__SSL
646 s = new TSSLSocket(connurl.GetHost(), connurl.GetPort());
647#else
648 Error("GetFromWeb", "library compiled without SSL, https not supported");
649 return -1;
650#endif
651 } else
652 s = new TSocket(connurl.GetHost(), connurl.GetPort());
653
654 if (!s->IsValid()) {
655 Error("GetFromWeb", "cannot connect to host %s", fUrl.GetHost());
656 delete s;
657 return -1;
658 }
659
660 if (s->SendRaw(msg.Data(), msg.Length()) == -1) {
661 Error("GetFromWeb", "error sending command to host %s", fUrl.GetHost());
662 delete s;
663 return -1;
664 }
665
666 if (s->RecvRaw(buf, len) == -1) {
667 Error("GetFromWeb", "error receiving data from host %s", fUrl.GetHost());
668 delete s;
669 return -1;
670 }
671
672 // collect statistics
673 fBytesRead += len;
674 fReadCalls++;
675#ifdef R__WIN32
678#else
679 fgBytesRead += len;
680 fgReadCalls++;
681#endif
682
683 if (gPerfStats)
684 gPerfStats->FileReadEvent(this, len, start);
685
686 delete s;
687 return 0;
688}
689
690////////////////////////////////////////////////////////////////////////////////
691/// Read multiple byte range request from web server.
692/// Uses HTTP 1.0 daemon wihtout mod-root.
693/// Returns -2 in case file does not exist, -1 in case
694/// of error and 0 in case of success.
695
697{
698 if (!len) return 0;
699
700 // if file content was cached, reuse it
701 if (fFullCache && (nseg>0))
702 return GetFromCache(buf, len, nseg, seg_pos, seg_len);
703
704 Double_t start = 0;
705 if (gPerfStats) start = TTimeStamp();
706
707 // open fSocket and close it when going out of scope
708 TWebSocket ws(this);
709
710 if (!fSocket || !fSocket->IsValid()) {
711 Error("GetFromWeb10", "cannot connect to host %s", fUrl.GetHost());
712 return -1;
713 }
714
715 if (gDebug > 0)
716 Info("GetFromWeb10", "sending HTTP request:\n%s", msg.Data());
717
718 if (fSocket->SendRaw(msg.Data(), msg.Length()) == -1) {
719 Error("GetFromWeb10", "error sending command to host %s", fUrl.GetHost());
720 return -1;
721 }
722
723 char line[8192];
724 Int_t n, ret = 0, nranges = 0, ltot = 0, redirect = 0;
726 Long64_t first = -1, last = -1, tot, fullsize = 0;
728
729 while ((n = GetLine(fSocket, line, sizeof(line))) >= 0) {
730 if (n == 0) {
731 if (ret < 0)
732 return ret;
733 if (redirect) {
734 if (redir.IsNull()) {
735 // Some sites (s3.amazonaws.com) do not return a Location field on 301
736 Error("GetFromWeb10", "error - redirect without location from host %s", fUrl.GetHost());
737 return -1;
738 }
739
740 ws.ReOpen();
741 // set message to reflect the redirectLocation and add bytes field
743 msg_1 += fOffset;
744 msg_1 += "-";
745 msg_1 += fOffset+len-1;
746 msg_1 += "\r\n\r\n";
747 return GetFromWeb10(buf, len, msg_1);
748 }
749
750 if (first >= 0) {
751 Int_t ll = Int_t(last - first) + 1;
752 Int_t rsize;
753 if ((rsize = fSocket->RecvRaw(&buf[ltot], ll)) == -1) {
754 Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost());
755 return -1;
756 }
757 else if (ll != rsize) {
758 Error("GetFromWeb10", "expected %d bytes, got %d", ll, rsize);
759 return -1;
760 }
761 ltot += ll;
762
763 first = -1;
764
765 if (boundary == "")
766 break; // not a multipart response
767 }
768
769 if (fullsize > 0) {
770
771 if (nseg <= 0) {
772 Error("GetFromWeb10","Need segments data to extract parts from full size %lld", fullsize);
773 return -1;
774 }
775
776 if (len > fullsize) {
777 Error("GetFromWeb10","Requested part %d longer than full size %lld", len, fullsize);
778 return -1;
779 }
780
781 if ((fFullCache == 0) && (fullsize <= GetMaxFullCacheSize())) {
782 // try to read file content into cache and than reuse it, limit cache by 2 GB
784 if (fFullCache != 0) {
786 Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost());
787 free(fFullCache); fFullCache = nullptr;
788 return -1;
789 }
791 return GetFromCache(buf, len, nseg, seg_pos, seg_len);
792 }
793 // when cache allocation failed, try without cache
794 }
795
796 // check all segemnts are inside range and in sorted order
797 for (Int_t cnt=0;cnt<nseg;cnt++) {
798 if (fArchiveOffset + seg_pos[cnt] + seg_len[cnt] > fullsize) {
799 Error("GetFromWeb10","Requested segment %lld len %d is outside of full range %lld", seg_pos[cnt], seg_len[cnt], fullsize);
800 return -1;
801 }
802 if ((cnt>0) && (seg_pos[cnt-1] + seg_len[cnt-1] > seg_pos[cnt])) {
803 Error("GetFromWeb10","Requested segments are not in sorted order");
804 return -1;
805 }
806 }
807
808 Long64_t pos = 0;
809 char* curr = buf;
810 char dbuf[2048]; // dummy buffer for skip data
811
812 // now read complete file and take only requested segments into the buffer
813 for (Int_t cnt=0; cnt<nseg; cnt++) {
814 // first skip data before segment
815 while (pos < fArchiveOffset + seg_pos[cnt]) {
816 Long64_t ll = fArchiveOffset + seg_pos[cnt] - pos;
817 if (ll > Int_t(sizeof(dbuf))) ll = sizeof(dbuf);
818 if (fSocket->RecvRaw(dbuf, ll) != ll) {
819 Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost());
820 return -1;
821 }
822 pos += ll;
823 }
824
825 // reading segment itself
826 if (fSocket->RecvRaw(curr, seg_len[cnt]) != seg_len[cnt]) {
827 Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost());
828 return -1;
829 }
830 curr += seg_len[cnt];
831 pos += seg_len[cnt];
832 ltot += seg_len[cnt];
833 }
834
835 // now read file to the end
836 while (pos < fullsize) {
837 Long64_t ll = fullsize - pos;
838 if (ll > Int_t(sizeof(dbuf))) ll = sizeof(dbuf);
839 if (fSocket->RecvRaw(dbuf, ll) != ll) {
840 Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost());
841 return -1;
842 }
843 pos += ll;
844 }
845
846 if (gDebug > 0)
847 Info("GetFromWeb10", "Complete reading %d bytes in %d segments out of full size %lld", len, nseg, fullsize);
848
849 break;
850 }
851
852 continue;
853 }
854
855 if (gDebug > 0)
856 Info("GetFromWeb10", "header: %s", line);
857
858 if (boundaryEnd == line) {
859 if (gDebug > 0)
860 Info("GetFromWeb10", "got all headers");
861 break;
862 }
863 if (boundary == line) {
864 nranges++;
865 if (gDebug > 0)
866 Info("GetFromWeb10", "get new multipart byte range (%d)", nranges);
867 }
868
869 TString res = line;
870 res.ToLower();
871 if (res.BeginsWith("HTTP/1.", TString::kIgnoreCase)) {
872 if (res.BeginsWith("HTTP/1.1", TString::kIgnoreCase)) {
873 if (!fHTTP11)
874 fMsgReadBuffer10 = "";
875 fHTTP11 = kTRUE;
876 }
877 TString scode = res(9, 3);
878 Int_t code = scode.Atoi();
879 if (code >= 500) {
880 ret = -1;
881 TString mess = res(13, 1000);
882 Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
883 } else if (code >= 400) {
884 if (code == 404)
885 ret = -2; // file does not exist
886 else {
887 ret = -1;
888 TString mess = res(13, 1000);
889 Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
890 }
891 } else if (code >= 300) {
892 if (code == 301 || code == 303) {
893 redirect = 1; // permanent redirect
894 } else if (code == 302 || code == 307) {
895 // treat 302 as 303: permanent redirect
896 redirect = 1;
897 //redirect = 2; // temp redirect
898 } else {
899 ret = -1;
900 TString mess = res(13, 1000);
901 Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
902 }
903 } else if (code > 200) {
904 if (code != 206) {
905 ret = -1;
906 TString mess = res(13, 1000);
907 Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
908 }
909 } else if (code == 200) {
910 fullsize = -200; // make indication of code 200
911 Warning("GetFromWeb10",
912 "Server %s response with complete file, but only part of it was requested.\n"
913 "Check MaxRanges configuration parameter (if Apache is used)",
914 fUrl.GetHost());
915
916 }
917 } else if (res.BeginsWith("content-type: multipart", TString::kIgnoreCase)) {
918 boundary = res(res.Index("boundary=", TString::kIgnoreCase) + 9, 1000);
919 if (boundary[0] == '"' && boundary[boundary.Length()-1] == '"') {
920 boundary = boundary(1, boundary.Length() - 2);
921 }
922 boundary = "--" + boundary;
923 boundaryEnd = boundary + "--";
924 } else if (res.BeginsWith("content-range:", TString::kIgnoreCase)) {
925 sscanf(res.Data(), "content-range: bytes %lld-%lld/%lld", &first, &last, &tot);
926 if (fSize == -1) fSize = tot;
927 } else if (res.BeginsWith("content-length:", TString::kIgnoreCase) && (fullsize == -200)) {
928 sscanf(res.Data(), "content-length: %lld", &fullsize);
929 } else if (res.BeginsWith("location:", TString::kIgnoreCase) && redirect) {
930 redir = res(10, 1000);
931 if (redirect == 2) // temp redirect
933 else // permanent redirect
935 }
936 }
937
938 if (redirect && redir.IsNull()) {
939 Error("GetFromWeb10", "error - redirect without location from host %s", fUrl.GetHost());
940 }
941
942 if (n == -1 && fHTTP11) {
943 if (gDebug > 0)
944 Info("GetFromWeb10", "HTTP/1.1 socket closed, reopen");
945 if (fBasicUrlOrg != "") {
946 // if we have to close temp redirection, set back to original url
948 }
949 ws.ReOpen();
950 return GetFromWeb10(buf, len, msg);
951 }
952
953 if (ltot != len) {
954 Error("GetFromWeb10", "error receiving expected amount of data (got %d, expected %d) from host %s",
955 ltot, len, fUrl.GetHost());
956 return -1;
957 }
958
959 // collect statistics
960 fBytesRead += len;
961 fReadCalls++;
962#ifdef R__WIN32
965#else
966 fgBytesRead += len;
967 fgReadCalls++;
968#endif
969
970 if (gPerfStats)
971 gPerfStats->FileReadEvent(this, len, start);
972
973 return 0;
974}
975
976////////////////////////////////////////////////////////////////////////////////
977/// Set position from where to start reading.
978
980{
981 switch (pos) {
982 case kBeg:
984 break;
985 case kCur:
986 fOffset += offset;
987 break;
988 case kEnd:
989 // this option is not used currently in the ROOT code
990 if (fArchiveOffset)
991 Error("Seek", "seeking from end in archive is not (yet) supported");
992 fOffset = fEND - offset; // is fEND really EOF or logical EOF?
993 break;
994 }
995}
996
997////////////////////////////////////////////////////////////////////////////////
998/// Return maximum file size.
999
1001{
1002 if (!fHasModRoot || fSize >= 0)
1003 return fSize;
1004
1005 Long64_t size;
1006 char asize[64];
1007
1008 TString msg = "GET ";
1009 msg += fBasicUrl;
1010 msg += "?";
1011 msg += -1;
1012 msg += "\r\n";
1013
1014 if (const_cast<TWebFile*>(this)->GetFromWeb(asize, 64, msg) == -1)
1015 return kMaxInt;
1016
1017#ifndef R__WIN32
1018 size = atoll(asize);
1019#else
1020 size = _atoi64(asize);
1021#endif
1022
1023 fSize = size;
1024
1025 return size;
1026}
1027
1028////////////////////////////////////////////////////////////////////////////////
1029/// Get the HTTP header. Depending on the return code we can see if
1030/// the file exists and if the server uses mod_root.
1031/// Returns -1 in case of an error, -2 in case the file does not exists,
1032/// -3 in case HEAD is not supported (dCache HTTP door) and
1033/// 0 in case of success.
1034
1036{
1037 // Give full URL so Apache's virtual hosts solution works.
1038 if (fMsgGetHead == "") {
1039 fMsgGetHead = "HEAD ";
1041 if (fHTTP11)
1042 fMsgGetHead += " HTTP/1.1";
1043 else
1044 fMsgGetHead += " HTTP/1.0";
1045 fMsgGetHead += "\r\n";
1046 if (fHTTP11) {
1047 fMsgGetHead += "Host: ";
1049 fMsgGetHead += "\r\n";
1050 }
1053 fMsgGetHead += "\r\n\r\n";
1054 }
1056
1057 TUrl connurl;
1058 if (fProxy.IsValid())
1059 connurl = fProxy;
1060 else
1061 connurl = fUrl;
1062
1063 TSocket *s = nullptr;
1064 for (Int_t i = 0; i < 5; i++) {
1065 if (strcmp(connurl.GetProtocol(), "https") == 0) {
1066#ifdef R__SSL
1067 s = new TSSLSocket(connurl.GetHost(), connurl.GetPort());
1068#else
1069 Error("GetHead", "library compiled without SSL, https not supported");
1070 return -1;
1071#endif
1072 } else
1073 s = new TSocket(connurl.GetHost(), connurl.GetPort());
1074
1075 if (!s->IsValid()) {
1076 delete s;
1077 if (gSystem->GetErrno() == EADDRINUSE || gSystem->GetErrno() == EISCONN) {
1078 s = nullptr;
1079 gSystem->Sleep(i*10);
1080 } else {
1081 Error("GetHead", "cannot connect to host %s (errno=%d)", fUrl.GetHost(),
1082 gSystem->GetErrno());
1083 return -1;
1084 }
1085 } else
1086 break;
1087 }
1088 if (!s)
1089 return -1;
1090
1091 if (gDebug > 0) {
1092 Info("GetHead", "connected to host %s", connurl.GetHost());
1093 Info("GetHead", "sending HTTP request:\n%s", msg.Data());
1094 }
1095
1096 if (s->SendRaw(msg.Data(), msg.Length()) == -1) {
1097 Error("GetHead", "error sending command to host %s", fUrl.GetHost());
1098 delete s;
1099 return -1;
1100 }
1101
1102 char line[8192];
1103 Int_t n, ret = 0, redirect = 0;
1104 TString redir;
1105
1106 while ((n = GetLine(s, line, sizeof(line))) >= 0) {
1107 if (n == 0) {
1108 if (gDebug > 0)
1109 Info("GetHead", "got all headers");
1110 delete s;
1111 if (fBasicUrlOrg != "" && !redirect) {
1112 // set back to original url in case of temp redirect
1114 fMsgGetHead = "";
1115 }
1116 if (ret < 0)
1117 return ret;
1118 if (redirect) {
1119 if (redir.IsNull()) {
1120 // Some sites (s3.amazonaws.com) do not return a Location field on 301
1121 Error("GetHead", "error - redirect without location from host %s", fUrl.GetHost());
1122 return -1;
1123 }
1124 return GetHead();
1125 }
1126 return 0;
1127 }
1128
1129 if (gDebug > 0)
1130 Info("GetHead", "header: %s", line);
1131
1132 TString res = line;
1133 ProcessHttpHeader(res);
1134 if (res.BeginsWith("HTTP/1.")) {
1135 if (res.BeginsWith("HTTP/1.1")) {
1136 if (!fHTTP11) {
1137 fMsgGetHead = "";
1138 fMsgReadBuffer10 = "";
1139 }
1140 fHTTP11 = kTRUE;
1141 }
1142 TString scode = res(9, 3);
1143 Int_t code = scode.Atoi();
1144 if (code >= 500) {
1145 if (code == 500)
1147 else {
1148 ret = -1;
1149 TString mess = res(13, 1000);
1150 Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
1151 }
1152 } else if (code >= 400) {
1153 if (code == 400)
1154 ret = -3; // command not supported
1155 else if (code == 404)
1156 ret = -2; // file does not exist
1157 else {
1158 ret = -1;
1159 TString mess = res(13, 1000);
1160 Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
1161 }
1162 } else if (code >= 300) {
1163 if (code == 301 || code == 303)
1164 redirect = 1; // permanent redirect
1165 else if (code == 302 || code == 307)
1166 redirect = 2; // temp redirect
1167 else {
1168 ret = -1;
1169 TString mess = res(13, 1000);
1170 Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
1171 }
1172 } else if (code > 200) {
1173 ret = -1;
1174 TString mess = res(13, 1000);
1175 Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code);
1176 }
1177 } else if (res.BeginsWith("Content-Length:", TString::kIgnoreCase)) {
1178 TString slen = res(16, 1000);
1179 fSize = slen.Atoll();
1180 } else if (res.BeginsWith("Location:", TString::kIgnoreCase) && redirect) {
1181 redir = res(10, 1000);
1182 if (redirect == 2) // temp redirect
1184 else // permanent redirect
1186 fMsgGetHead = "";
1187 }
1188 }
1189
1190 delete s;
1191
1192 return ret;
1193}
1194
1195////////////////////////////////////////////////////////////////////////////////
1196/// Read a line from the socket. Reads at most one less than the number of
1197/// characters specified by maxsize. Reading stops when a newline character
1198/// is found, The newline (\\n) and cr (\\r), if any, are removed.
1199/// Returns -1 in case of error, or the number of characters read (>= 0)
1200/// otherwise.
1201
1203{
1204 Int_t n = GetHunk(s, line, maxsize);
1205 if (n < 0) {
1206 if (!fHTTP11 || gDebug > 0)
1207 Error("GetLine", "error receiving data from host %s", fUrl.GetHost());
1208 return -1;
1209 }
1210
1211 if (n > 0 && line[n-1] == '\n') {
1212 n--;
1213 if (n > 0 && line[n-1] == '\r')
1214 n--;
1215 line[n] = '\0';
1216 }
1217 return n;
1218}
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// Read a hunk of data from the socket, up until a terminator. The hunk is
1222/// limited by whatever the TERMINATOR callback chooses as its
1223/// terminator. For example, if terminator stops at newline, the hunk
1224/// will consist of a line of data; if terminator stops at two
1225/// newlines, it can be used to read the head of an HTTP response.
1226/// Upon determining the boundary, the function returns the data (up to
1227/// the terminator) in hunk.
1228///
1229/// In case of read error, -1 is returned. In case of having read some
1230/// data, but encountering EOF before seeing the terminator, the data
1231/// that has been read is returned, but it will (obviously) not contain the
1232/// terminator.
1233///
1234/// The TERMINATOR function is called with three arguments: the
1235/// beginning of the data read so far, the beginning of the current
1236/// block of peeked-at data, and the length of the current block.
1237/// Depending on its needs, the function is free to choose whether to
1238/// analyze all data or just the newly arrived data. If TERMINATOR
1239/// returns 0, it means that the terminator has not been seen.
1240/// Otherwise it should return a pointer to the character immediately
1241/// following the terminator.
1242///
1243/// The idea is to be able to read a line of input, or otherwise a hunk
1244/// of text, such as the head of an HTTP request, without crossing the
1245/// boundary, so that the next call to RecvRaw() etc. reads the data
1246/// after the hunk. To achieve that, this function does the following:
1247///
1248/// 1. Peek at incoming data.
1249///
1250/// 2. Determine whether the peeked data, along with the previously
1251/// read data, includes the terminator.
1252///
1253/// 3a. If yes, read the data until the end of the terminator, and
1254/// exit.
1255///
1256/// 3b. If no, read the peeked data and goto 1.
1257///
1258/// The function is careful to assume as little as possible about the
1259/// implementation of peeking. For example, every peek is followed by
1260/// a read. If the read returns a different amount of data, the
1261/// process is retried until all data arrives safely.
1262///
1263/// Reads at most one less than the number of characters specified by maxsize.
1264
1266{
1267 if (maxsize <= 0) return 0;
1268
1270 Int_t tail = 0; // tail position in HUNK
1271
1272 while (1) {
1273 const char *end;
1275
1276 // First, peek at the available data.
1277 pklen = s->RecvRaw(hunk+tail, bufsize-1-tail, kPeek);
1278 if (pklen < 0) {
1279 return -1;
1280 }
1281 end = HttpTerminator(hunk, hunk+tail, pklen);
1282 if (end) {
1283 // The data contains the terminator: we'll drain the data up
1284 // to the end of the terminator.
1285 remain = end - (hunk + tail);
1286 if (remain == 0) {
1287 // No more data needs to be read.
1288 hunk[tail] = '\0';
1289 return tail;
1290 }
1291 if (bufsize - 1 < tail + remain) {
1292 Error("GetHunk", "hunk buffer too small for data from host %s (%d bytes needed)",
1293 fUrl.GetHost(), tail + remain + 1);
1294 hunk[tail] = '\0';
1295 return -1;
1296 }
1297 } else {
1298 // No terminator: simply read the data we know is (or should
1299 // be) available.
1300 remain = pklen;
1301 }
1302
1303 // Now, read the data. Note that we make no assumptions about
1304 // how much data we'll get. (Some TCP stacks are notorious for
1305 // read returning less data than the previous MSG_PEEK.)
1306 rdlen = s->RecvRaw(hunk+tail, remain, kDontBlock);
1307 if (rdlen < 0) {
1308 return -1;
1309 }
1310 tail += rdlen;
1311 hunk[tail] = '\0';
1312
1313 if (rdlen == 0) {
1314 // in case of EOF: return the data we've read.
1315 return tail;
1316 }
1317 if (end && rdlen == remain) {
1318 // The terminator was seen and the remaining data drained --
1319 // we got what we came for.
1320 return tail;
1321 }
1322
1323 // Keep looping until all the data arrives.
1324
1325 if (tail == bufsize - 1) {
1326 Error("GetHunk", "hunk buffer too small for data from host %s",
1327 fUrl.GetHost());
1328 return -1;
1329 }
1330 }
1331}
1332
1333////////////////////////////////////////////////////////////////////////////////
1334/// Determine whether [START, PEEKED + PEEKLEN) contains an HTTP new
1335/// line [\\r]\\n. If so, return the pointer to the position after the line,
1336/// otherwise return 0. This is used as callback to GetHunk(). The data
1337/// between START and PEEKED has been read and cannot be "unread"; the
1338/// data after PEEKED has only been peeked.
1339
1340const char *TWebFile::HttpTerminator(const char *start, const char *peeked,
1341 Int_t peeklen)
1342{
1343#if 0
1344 const char *p, *end;
1345
1346 // Look for "[\r]\n", and return the following position if found.
1347 // Start one char before the current to cover the possibility that
1348 // part of the terminator (e.g. "\r") arrived in the previous batch.
1349 p = peeked - start < 1 ? start : peeked - 1;
1350 end = peeked + peeklen;
1351
1352 // Check for \r\n anywhere in [p, end-2).
1353 for (; p < end - 1; p++)
1354 if (p[0] == '\r' && p[1] == '\n')
1355 return p + 2;
1356
1357 // p==end-1: check for \r\n directly preceding END.
1358 if (p[0] == '\r' && p[1] == '\n')
1359 return p + 2;
1360#else
1361 (void) start; // start unused, silence compiler
1362 if (peeked) {
1363 const char *p = (const char*) memchr(peeked, '\n', peeklen);
1364 if (p)
1365 // p+1 because the line must include '\n'
1366 return p + 1;
1367 }
1368#endif
1369 return nullptr;
1370}
1371
1372////////////////////////////////////////////////////////////////////////////////
1373/// Return basic authentication scheme, to be added to the request.
1374
1376{
1377 TString msg;
1378 if (strlen(fUrl.GetUser())) {
1380 if (strlen(fUrl.GetPasswd())) {
1381 auth += ":";
1382 auth += fUrl.GetPasswd();
1383 }
1384 msg += "Authorization: Basic ";
1386 msg += "\r\n";
1387 }
1388 return msg;
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// Static method setting global proxy URL.
1393
1394void TWebFile::SetProxy(const char *proxy)
1395{
1396 if (proxy && *proxy) {
1397 TUrl p(proxy);
1398 if (strcmp(p.GetProtocol(), "http")) {
1399 :: Error("TWebFile::SetProxy", "protocol must be HTTP in proxy URL %s",
1400 proxy);
1401 return;
1402 }
1403 fgProxy = p;
1404 }
1405}
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// Static method returning the global proxy URL.
1409
1411{
1412 if (fgProxy.IsValid())
1413 return fgProxy.GetUrl();
1414 return "";
1415}
1416
1417////////////////////////////////////////////////////////////////////////////////
1418/// Process the HTTP header in the argument. This method is intended to be
1419/// overwritten by subclasses that exploit the information contained in the
1420/// HTTP headers.
1421
1423{
1424}
1425
1426////////////////////////////////////////////////////////////////////////////////
1427/// Static method returning maxmimal size of full cache,
1428/// which can be preserved by file instance
1429
1434
1435////////////////////////////////////////////////////////////////////////////////
1436/// Static method, set maxmimal size of full cache,
1437// which can be preserved by file instance
1438
1443
1444
1445////////////////////////////////////////////////////////////////////////////////
1446/// Create helper class that allows directory access via httpd.
1447/// The name must start with '-' to bypass the TSystem singleton check.
1448
1449TWebSystem::TWebSystem() : TSystem("-http", "HTTP Helper System")
1450{
1451 SetName("http");
1452
1453 fDirp = nullptr;
1454}
1455
1456////////////////////////////////////////////////////////////////////////////////
1457/// Make a directory via httpd. Not supported.
1458
1460{
1461 return -1;
1462}
1463
1464////////////////////////////////////////////////////////////////////////////////
1465/// Open a directory via httpd. Returns an opaque pointer to a dir
1466/// structure. Returns 0 in case of error.
1467
1468void *TWebSystem::OpenDirectory(const char *)
1469{
1470 if (fDirp) {
1471 Error("OpenDirectory", "invalid directory pointer (should never happen)");
1472 fDirp = nullptr;
1473 }
1474
1475 fDirp = nullptr; // not implemented for the time being
1476
1477 return fDirp;
1478}
1479
1480////////////////////////////////////////////////////////////////////////////////
1481/// Free directory via httpd.
1482
1484{
1485 if (dirp != fDirp) {
1486 Error("FreeDirectory", "invalid directory pointer (should never happen)");
1487 return;
1488 }
1489
1490 fDirp = nullptr;
1491}
1492
1493////////////////////////////////////////////////////////////////////////////////
1494/// Get directory entry via httpd. Returns 0 in case no more entries.
1495
1497{
1498 if (dirp != fDirp) {
1499 Error("GetDirEntry", "invalid directory pointer (should never happen)");
1500 return 0;
1501 }
1502
1503 return 0;
1504}
1505
1506////////////////////////////////////////////////////////////////////////////////
1507/// Get info about a file. Info is returned in the form of a FileStat_t
1508/// structure (see TSystem.h).
1509/// The function returns 0 in case of success and 1 if the file could
1510/// not be stat'ed.
1511
1513{
1514 TWebFile *f = new TWebFile(path, "HEADONLY");
1515
1516 if (f->fWritten == 0) {
1517
1518 buf.fDev = 0;
1519 buf.fIno = 0;
1520 buf.fMode = 0;
1521 buf.fUid = 0;
1522 buf.fGid = 0;
1523 buf.fSize = f->GetSize();
1524 buf.fMtime = 0;
1525 buf.fIsLink = kFALSE;
1526
1527 delete f;
1528 return 0;
1529 }
1530
1531 delete f;
1532 return 1;
1533}
1534
1535////////////////////////////////////////////////////////////////////////////////
1536/// Returns FALSE if one can access a file using the specified access mode.
1537/// Mode is the same as for the Unix access(2) function.
1538/// Attention, bizarre convention of return value!!
1539
1541{
1542 TWebFile *f = new TWebFile(path, "HEADONLY");
1543 if (f->fWritten == 0) {
1544 delete f;
1545 return kFALSE;
1546 }
1547 delete f;
1548 return kTRUE;
1549}
1550
1551////////////////////////////////////////////////////////////////////////////////
1552/// Unlink, i.e. remove, a file or directory. Returns 0 when successful,
1553/// -1 in case of failure. Not supported for httpd.
1554
1556{
1557 return -1;
1558}
#define f(i)
Definition RSha256.hxx:104
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
constexpr Int_t kMaxInt
Definition RtypesCore.h:105
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static const std::string gUserAgent
#define gDirectory
Definition TDirectory.h:384
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
winID h TVirtualViewer3D TVirtualGLPainter p
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 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
const char * GetUrl()
Definition TProof.h:594
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:406
@ kDontBlock
Definition TSystem.h:246
@ kPeek
Definition TSystem.h:245
EAccessMode
Definition TSystem.h:51
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gPerfStats
static const char * gUserAgent
Definition TWebFile.cxx:46
#define free
Definition civetweb.c:1539
#define malloc
Definition civetweb.c:1536
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
static std::atomic< Long64_t > fgBytesRead
Number of bytes read by all TFile objects.
Definition TFile.h:161
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition TFile.h:168
Long64_t fBytesRead
Number of bytes read from this file.
Definition TFile.h:155
static void SetFileBytesRead(Long64_t bytes=0)
Definition TFile.cxx:4656
static void SetFileReadCalls(Int_t readcalls=0)
Definition TFile.cxx:4662
TUrl fUrl
!URL of file
Definition TFile.h:189
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
Definition TFile.cxx:4622
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Definition TFile.cxx:1930
Long64_t fArchiveOffset
!Offset at which file starts in archive
Definition TFile.h:180
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition TFile.cxx:613
ERelativeTo
Definition TFile.h:282
@ kCur
Definition TFile.h:282
@ kBeg
Definition TFile.h:282
@ kEnd
Definition TFile.h:282
Int_t fD
File descriptor.
Definition TFile.h:161
Bool_t fIsRootFile
!True is this is a ROOT file, raw file otherwise
Definition TFile.h:183
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition TFile.cxx:2294
Long64_t fOffset
!Seek offset cache
Definition TFile.h:175
Long64_t fEND
Last used byte in file.
Definition TFile.h:158
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:955
static std::atomic< Int_t > fgReadCalls
Number of bytes read from all TFile objects.
Definition TFile.h:164
Int_t fWritten
Number of objects written so far.
Definition TFile.h:166
static Int_t GetFileReadCalls()
Static function returning the total number of read calls from all files.
Definition TFile.cxx:4639
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:159
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
void MakeZombie()
Definition TObject.h:53
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition TSocket.cxx:898
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition TSocket.cxx:620
virtual Bool_t IsValid() const
Definition TSocket.h:132
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
@ kIgnoreCase
Definition TString.h:277
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
Abstract base class defining a generic interface to the underlying Operating System.
Definition TSystem.h:276
static Int_t GetErrno()
Static function returning system error number.
Definition TSystem.cxx:276
virtual const char * Getenv(const char *env)
Get environment variable.
Definition TSystem.cxx:1677
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition TTimeStamp.h:45
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition TUrl.cxx:391
const char * GetFile() const
Definition TUrl.h:69
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition TUrl.cxx:110
Bool_t IsValid() const
Definition TUrl.h:79
const char * GetUser() const
Definition TUrl.h:65
const char * GetHost() const
Definition TUrl.h:67
const char * GetPasswd() const
Definition TUrl.h:66
const char * GetOptions() const
Definition TUrl.h:71
const char * GetProtocol() const
Definition TUrl.h:64
Int_t GetPort() const
Definition TUrl.h:78
virtual Int_t GetLine(TSocket *s, char *line, Int_t maxsize)
Read a line from the socket.
virtual ~TWebFile()
Cleanup.
Definition TWebFile.cxx:199
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.
Definition TWebFile.cxx:629
virtual TString BasicAuthentication()
Return basic authentication scheme, to be added to the request.
Long64_t fSize
Definition TWebFile.h:42
TSocket * fSocket
Definition TWebFile.h:43
static const char * GetProxy()
Static method returning the global proxy URL.
TString fBasicUrl
Definition TWebFile.h:51
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.
Definition TWebFile.cxx:604
TString fBasicUrlOrg
Definition TWebFile.h:53
Bool_t IsOpen() const override
A TWebFile that has been correctly constructed is always considered open.
Definition TWebFile.cxx:384
Bool_t fHTTP11
Definition TWebFile.h:46
virtual void CheckProxy()
Check if shell var "http_proxy" has been set and should be used.
Definition TWebFile.cxx:357
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:570
Bool_t ReadBuffer(char *buf, Int_t len) override
Read specified byte range from remote file via HTTP daemon.
Definition TWebFile.cxx:433
Long64_t fFullCacheSize
complete content of the file, some http server may return complete content
Definition TWebFile.h:55
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:521
TUrl fProxy
Definition TWebFile.h:44
TString fMsgGetHead
Definition TWebFile.h:50
void Seek(Long64_t offset, ERelativeTo pos=kBeg) override
Set position from where to start reading.
Definition TWebFile.cxx:979
TString fMsgReadBuffer
Definition TWebFile.h:48
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:482
void Init(Bool_t readHeadOnly) override
Initialize a TWebFile object.
Definition TWebFile.cxx:212
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:696
TWebFile()
Definition TWebFile.h:39
static TUrl fgProxy
size of the cached content
Definition TWebFile.h:57
void * fFullCache
Definition TWebFile.h:54
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.
Definition TWebFile.cxx:272
TString fMsgReadBuffer10
Definition TWebFile.h:49
TUrl fUrlOrg
Definition TWebFile.h:52
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:398
static Long64_t GetMaxFullCacheSize()
Static method returning maxmimal size of full cache, which can be preserved by file instance.
Bool_t fHasModRoot
Definition TWebFile.h:45
virtual void ProcessHttpHeader(const TString &headerLine)
Process the HTTP header in the argument.
void Close(Option_t *option="") override
Close a Web file.
Definition TWebFile.cxx:416
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
Definition TWebFile.h:58
Bool_t fNoProxy
Definition TWebFile.h:47
TWebFile * fWebFile
Definition TWebFile.cxx:57
~TWebSocket()
Close socket in case not HTTP/1.1 protocol or when explicitly requested.
Definition TWebFile.cxx:77
void ReOpen()
Re-open web file socket.
Definition TWebFile.cxx:88
TWebSocket(TWebFile *f)
Open web file socket.
Definition TWebFile.cxx:67
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.
void * fDirp
Definition TWebFile.h:102
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.
TLine * line
std::ostream & Info()
Definition hadd.cxx:171
const Int_t n
Definition legend1.C:16
Int_t fMode
Definition TSystem.h:135
Long64_t fSize
Definition TSystem.h:138
Long_t fDev
Definition TSystem.h:133
Int_t fGid
Definition TSystem.h:137
Long_t fMtime
Definition TSystem.h:139
Long_t fIno
Definition TSystem.h:134
Bool_t fIsLink
Definition TSystem.h:140
Int_t fUid
Definition TSystem.h:136