Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:30:48

0001 // @(#)root/net:$Id$
0002 // Author: Fons Rademakers   17/01/97
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TWebFile
0013 #define ROOT_TWebFile
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TWebFile                                                             //
0019 //                                                                      //
0020 // A TWebFile is like a normal TFile except that it reads its data      //
0021 // via a standard apache web server. A TWebFile is a read-only file.    //
0022 //                                                                      //
0023 //////////////////////////////////////////////////////////////////////////
0024 
0025 #include "TFile.h"
0026 #include "TUrl.h"
0027 #include "TSystem.h"
0028 
0029 class TSocket;
0030 
0031 namespace ROOT::Deprecated {
0032 
0033 class TWebSocket;
0034 class TWebSystem;
0035 
0036 class TWebFile : public TFile {
0037 
0038 friend class ROOT::Deprecated::TWebSocket;
0039 friend class ROOT::Deprecated::TWebSystem;
0040 
0041 private:
0042    TWebFile() : fSocket(nullptr) {}
0043 
0044 protected:
0045    mutable Long64_t  fSize;             // file size
0046    TSocket          *fSocket;           // socket for HTTP/1.1 (stays alive between calls)
0047    TUrl              fProxy;            // proxy URL
0048    Bool_t            fHasModRoot;       // true if server has mod_root installed
0049    Bool_t            fHTTP11;           // true if server support HTTP/1.1
0050    Bool_t            fNoProxy;          // don't use proxy
0051    TString           fMsgReadBuffer;    // cache ReadBuffer() msg
0052    TString           fMsgReadBuffer10;  // cache ReadBuffer10() msg
0053    TString           fMsgGetHead;       // cache GetHead() msg
0054    TString           fBasicUrl;         // basic url without authentication and options
0055    TUrl              fUrlOrg;           // save original url in case of temp redirection
0056    TString           fBasicUrlOrg;      // save original url in case of temp redirection
0057    void             *fFullCache;        ///<! complete content of the file, some http server may return complete content
0058    Long64_t          fFullCacheSize;    ///<! size of the cached content
0059 
0060    static TUrl       fgProxy;           // globally set proxy URL
0061    static Long64_t   fgMaxFullCacheSize; // maximal size of full-cached content, 500 MB by default
0062 
0063            void        Init(Bool_t readHeadOnly) override;
0064    virtual void        CheckProxy();
0065    virtual TString     BasicAuthentication();
0066    virtual Int_t       GetHead();
0067    virtual Int_t       GetLine(TSocket *s, char *line, Int_t maxsize);
0068    virtual Int_t       GetHunk(TSocket *s, char *hunk, Int_t maxsize);
0069    virtual const char *HttpTerminator(const char *start, const char *peeked, Int_t peeklen);
0070    virtual Int_t       GetFromWeb(char *buf, Int_t len, const TString &msg);
0071    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);
0072    virtual Int_t       GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len);
0073    virtual Bool_t      ReadBuffer10(char *buf, Int_t len);
0074    virtual Bool_t      ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
0075    virtual void        SetMsgReadBuffer10(const char *redirectLocation = nullptr, Bool_t tempRedirect = kFALSE);
0076    virtual void        ProcessHttpHeader(const TString& headerLine);
0077 
0078 public:
0079    TWebFile(const char *url, Option_t *opt="");
0080    TWebFile(TUrl url, Option_t *opt="");
0081    virtual ~TWebFile();
0082 
0083    void        Close(Option_t *option="") override;
0084    Long64_t    GetSize() const override;
0085    Bool_t      IsOpen() const override;
0086    Int_t       ReOpen(Option_t *mode) override;
0087    Bool_t      ReadBuffer(char *buf, Int_t len) override;
0088    Bool_t      ReadBuffer(char *buf, Long64_t pos, Int_t len) override;
0089    Bool_t      ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override;
0090    void        Seek(Long64_t offset, ERelativeTo pos = kBeg) override;
0091 
0092    static void        SetProxy(const char *url);
0093    static const char *GetProxy();
0094 
0095    static Long64_t    GetMaxFullCacheSize();
0096    static void        SetMaxFullCacheSize(Long64_t sz);
0097 
0098    ClassDefOverride(TWebFile,2)  //A ROOT file that reads via a http server
0099 };
0100 
0101 
0102 class TWebSystem : public TSystem {
0103 
0104 private:
0105    void *fDirp;    // directory handler
0106 
0107    void *GetDirPtr() const override { return fDirp; }
0108 
0109 public:
0110    TWebSystem();
0111    virtual ~TWebSystem() {}
0112 
0113    Int_t       MakeDirectory(const char *name) override;
0114    void       *OpenDirectory(const char *name) override;
0115    void        FreeDirectory(void *dirp) override;
0116    const char *GetDirEntry(void *dirp) override;
0117    Int_t       GetPathInfo(const char *path, FileStat_t &buf) override;
0118    Bool_t      AccessPathName(const char *path, EAccessMode mode) override;
0119    Int_t       Unlink(const char *path) override;
0120 
0121    ClassDefOverride(TWebSystem,0)  // Directory handler for HTTP (TWebFiles)
0122 };
0123 
0124 } // namespace ROOT::Deprecated
0125 
0126 using TWebFile R__DEPRECATED(6, 42, "TWebFile is deprecated") = ROOT::Deprecated::TWebFile;
0127 using TWebSystem R__DEPRECATED(6, 42, "TWebSystem is deprecated") = ROOT::Deprecated::TWebSystem;
0128 
0129 #endif