Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:35

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 class TWebSocket;
0031 
0032 
0033 class TWebFile : public TFile {
0034 
0035 friend class TWebSocket;
0036 friend class TWebSystem;
0037 
0038 private:
0039    TWebFile() : fSocket(nullptr) {}
0040 
0041 protected:
0042    mutable Long64_t  fSize;             // file size
0043    TSocket          *fSocket;           // socket for HTTP/1.1 (stays alive between calls)
0044    TUrl              fProxy;            // proxy URL
0045    Bool_t            fHasModRoot;       // true if server has mod_root installed
0046    Bool_t            fHTTP11;           // true if server support HTTP/1.1
0047    Bool_t            fNoProxy;          // don't use proxy
0048    TString           fMsgReadBuffer;    // cache ReadBuffer() msg
0049    TString           fMsgReadBuffer10;  // cache ReadBuffer10() msg
0050    TString           fMsgGetHead;       // cache GetHead() msg
0051    TString           fBasicUrl;         // basic url without authentication and options
0052    TUrl              fUrlOrg;           // save original url in case of temp redirection
0053    TString           fBasicUrlOrg;      // save original url in case of temp redirection
0054    void             *fFullCache;        //! complete content of the file, some http server may return complete content
0055    Long64_t          fFullCacheSize;    //! size of the cached content
0056 
0057    static TUrl       fgProxy;           // globally set proxy URL
0058    static Long64_t   fgMaxFullCacheSize; // maximal size of full-cached content, 500 MB by default
0059 
0060            void        Init(Bool_t readHeadOnly) override;
0061    virtual void        CheckProxy();
0062    virtual TString     BasicAuthentication();
0063    virtual Int_t       GetHead();
0064    virtual Int_t       GetLine(TSocket *s, char *line, Int_t maxsize);
0065    virtual Int_t       GetHunk(TSocket *s, char *hunk, Int_t maxsize);
0066    virtual const char *HttpTerminator(const char *start, const char *peeked, Int_t peeklen);
0067    virtual Int_t       GetFromWeb(char *buf, Int_t len, const TString &msg);
0068    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);
0069    virtual Int_t       GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len);
0070    virtual Bool_t      ReadBuffer10(char *buf, Int_t len);
0071    virtual Bool_t      ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
0072    virtual void        SetMsgReadBuffer10(const char *redirectLocation = nullptr, Bool_t tempRedirect = kFALSE);
0073    virtual void        ProcessHttpHeader(const TString& headerLine);
0074 
0075 public:
0076    TWebFile(const char *url, Option_t *opt="");
0077    TWebFile(TUrl url, Option_t *opt="");
0078    virtual ~TWebFile();
0079 
0080    void        Close(Option_t *option="") override;
0081    Long64_t    GetSize() const override;
0082    Bool_t      IsOpen() const override;
0083    Int_t       ReOpen(Option_t *mode) override;
0084    Bool_t      ReadBuffer(char *buf, Int_t len) override;
0085    Bool_t      ReadBuffer(char *buf, Long64_t pos, Int_t len) override;
0086    Bool_t      ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override;
0087    void        Seek(Long64_t offset, ERelativeTo pos = kBeg) override;
0088 
0089    static void        SetProxy(const char *url);
0090    static const char *GetProxy();
0091 
0092    static Long64_t    GetMaxFullCacheSize();
0093    static void        SetMaxFullCacheSize(Long64_t sz);
0094 
0095    ClassDefOverride(TWebFile,2)  //A ROOT file that reads via a http server
0096 };
0097 
0098 
0099 class TWebSystem : public TSystem {
0100 
0101 private:
0102    void *fDirp;    // directory handler
0103 
0104    void *GetDirPtr() const override { return fDirp; }
0105 
0106 public:
0107    TWebSystem();
0108    virtual ~TWebSystem() {}
0109 
0110    Int_t       MakeDirectory(const char *name) override;
0111    void       *OpenDirectory(const char *name) override;
0112    void        FreeDirectory(void *dirp) override;
0113    const char *GetDirEntry(void *dirp) override;
0114    Int_t       GetPathInfo(const char *path, FileStat_t &buf) override;
0115    Bool_t      AccessPathName(const char *path, EAccessMode mode) override;
0116    Int_t       Unlink(const char *path) override;
0117 
0118    ClassDefOverride(TWebSystem,0)  // Directory handler for HTTP (TWebFiles)
0119 };
0120 
0121 #endif