diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake index 97445596e7ace..62e96dd9e9851 100644 --- a/cmake/modules/RootConfiguration.cmake +++ b/cmake/modules/RootConfiguration.cmake @@ -161,10 +161,8 @@ set(davixlib ${DAVIX_LIBRARY}) set(davixincdir ${DAVIX_INCLUDE_DIR}) if(davix) set(hasdavix define) - set(useoldwebfile no) else() set(hasdavix undef) - set(useoldwebfile yes) endif() set(buildnetxng ${value${xrootd}}) diff --git a/config/mimes.unix.in b/config/mimes.unix.in index 0a13a0619f9ae..729e5213b99d7 100644 --- a/config/mimes.unix.in +++ b/config/mimes.unix.in @@ -161,7 +161,7 @@ icon = rootdb_s.xpm rootdb_t.xpm action = THbookFile *ftmp = new THbookFile("%s") [root/tfile] -pattern = TFile TNetFile TWebFile +pattern = TFile icon = rootdb_s.xpm rootdb_t.xpm action = ->Browse() diff --git a/config/mimes.win32.in b/config/mimes.win32.in index e4685a1250a19..96db7421e651b 100644 --- a/config/mimes.win32.in +++ b/config/mimes.win32.in @@ -161,7 +161,7 @@ icon = rootdb_s.xpm rootdb_t.xpm action = THbookFile *ftmp = new THbookFile("%s") [root/tfile] -pattern = TFile TNetFile TWebFile +pattern = TFile icon = rootdb_s.xpm rootdb_t.xpm action = ->Browse() diff --git a/config/rootrc.in b/config/rootrc.in index af28757d2e986..d8aaa908a9a80 100644 --- a/config/rootrc.in +++ b/config/rootrc.in @@ -422,7 +422,7 @@ RSA.KeyType: 1 # UsrPwd: check of host equivalence via /etc/hosts.equiv or $HOME/.rhosts. #SrvAuth.CheckHostsEquivalence: 1 -# Force file opening via TNetFile (TNetXNGFile) if a hostname is specified +# Force file opening via TNetXNGFile if a hostname is specified # in the Url. # By default, for local files TFile::Open() invokes directly TFile #TFile.ForceRemote: yes @@ -452,14 +452,6 @@ TFile.CrossProtocolRedirects: yes # correct value but instead used verbatim the value stored in the file. # TFile.v630forwardCompatibility: no -# List of S3 servers known to support multi-range HTTP GET requests. -# This is the value sent back by the S3 server in the 'Server:' header -# of the HTTP response. -# Please note that Amazon S3 servers do not support this feature. -# Add one line per server type with syntax: -# +TS3WebFile.Root.MultiRangeServer: Mucura -TS3WebFile.Root.MultiRangeServer: Huawei OBS - # Special cases for the TUrl parser, where the special cases are parsed # in a protocol + file part, like file:/path/file.root or /alien/path/file.root. # In case the file namespace descriptor ends with - the namespace @@ -531,9 +523,6 @@ NetXNG.QueryReadVParams: $(ROOT_XRD_QUERY_READV_PARAMS) # with all the goodies (session caching, flexible authentication, support # for different dialects like S3, and others) -# Use the old TWebFile instead of the new libDavix based version -Davix.UseOldClient: @useoldwebfile@ - # Verbosity level of the external Davix library # Davix.Debug: 0 diff --git a/core/base/inc/TROOT.h b/core/base/inc/TROOT.h index 4db7be27a742a..80e6b00639cbd 100644 --- a/core/base/inc/TROOT.h +++ b/core/base/inc/TROOT.h @@ -378,10 +378,10 @@ friend TSeqCollection *ROOT::Deprecated::Internal::GetListOfSecContexts(const TR static const TString& GetDocDir(); static const TString& GetMacroDir(); static const TString& GetTutorialDir(); - static const TString &GetSourceDir() - R__DEPRECATED(6, 42, - "This function is removed because it made only sense in the corner case where the ROOT source is " - "copied inside the ROOT installation, which is never the case unless the user does it by hand."); + static const TString &GetSourceDir() R__DEPRECATED( + 7, 00, + "This function is without any effect because it made only sense in the corner case where the ROOT source is " + "copied inside the ROOT installation, which is never the case unless the user does it by hand."); static const TString& GetIconPath(); static const TString& GetTTFFontDir(); diff --git a/core/base/src/TROOT.cxx b/core/base/src/TROOT.cxx index 85edbf60201a8..92d3f62d77c68 100644 --- a/core/base/src/TROOT.cxx +++ b/core/base/src/TROOT.cxx @@ -3481,23 +3481,12 @@ void TROOT::ShutDown() //////////////////////////////////////////////////////////////////////////////// /// Get the source directory in the installation. Static utility function. +/// \deprecated This function is without any effect because it made only sense in the corner case where the ROOT source +/// is copied inside the ROOT installation, which is never the case unless the user does it by hand. const TString& TROOT::GetSourceDir() { -#ifdef ROOTSRCDIR - if (IgnorePrefix()) { -#endif - static TString rootsrcdir; - if (rootsrcdir.IsNull()) { - rootsrcdir = "src"; - gSystem->PrependPathName(GetRootSys(), rootsrcdir); - } - return rootsrcdir; -#ifdef ROOTSRCDIR - } else { - const static TString rootsrcdir = ROOTSRCDIR; - return rootsrcdir; - } -#endif + static TString ret; + return ret; } //////////////////////////////////////////////////////////////////////////////// diff --git a/core/foundation/inc/ROOT/RConfig.hxx b/core/foundation/inc/ROOT/RConfig.hxx index 550bb7a366bfd..eb0607ae2996b 100644 --- a/core/foundation/inc/ROOT/RConfig.hxx +++ b/core/foundation/inc/ROOT/RConfig.hxx @@ -458,7 +458,7 @@ /*---- deprecation -----------------------------------------------------------*/ #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) # if (__GNUC__ == 5 && (__GNUC_MINOR__ == 1 || __GNUC_MINOR__ == 2)) || defined(R__NO_DEPRECATION) -/* GCC 5.1, 5.2: false positives due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15269 +/* GCC 5.1, 5.2: false positives due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15269 or deprecation turned off */ # define _R__DEPRECATED_LATER(REASON) # else @@ -477,15 +477,9 @@ #define _R_DEPRECATED_REMOVE_NOW(REASON) __attribute__((REMOVE_THIS_NOW)) #endif -/* USE AS `R__DEPRECATED(6,40, "Not threadsafe; use TFoo::Bar().")` - To be removed by 6.40 */ -#if ROOT_VERSION_CODE <= ROOT_VERSION(6, 39, 0) -#define _R__DEPRECATED_640(REASON) _R__DEPRECATED_LATER(REASON) -#else -#define _R__DEPRECATED_640(REASON) _R_DEPRECATED_REMOVE_NOW(REASON) -#endif - -#if ROOT_VERSION_CODE <= ROOT_VERSION(6, 41, 0) +/* USE AS `R__DEPRECATED(6,42, "Not threadsafe; use TFoo::Bar().")` + To be removed by 6.42 */ +#if ROOT_VERSION_CODE < ROOT_VERSION(6, 41, 2) #define _R__DEPRECATED_642(REASON) _R__DEPRECATED_LATER(REASON) #else #define _R__DEPRECATED_642(REASON) _R_DEPRECATED_REMOVE_NOW(REASON) diff --git a/core/foundation/inc/ROOT/RVersion.hxx b/core/foundation/inc/ROOT/RVersion.hxx index fdb4319c069b5..2f23b7c43bf71 100644 --- a/core/foundation/inc/ROOT/RVersion.hxx +++ b/core/foundation/inc/ROOT/RVersion.hxx @@ -3,8 +3,8 @@ /* Update on release: */ #define ROOT_VERSION_MAJOR 6 -#define ROOT_VERSION_MINOR 39 -#define ROOT_VERSION_PATCH 99 // When changing the version number here, never add leading zeroes! +#define ROOT_VERSION_MINOR 41 +#define ROOT_VERSION_PATCH 1 // When changing the version number here, never add leading zeroes! #define ROOT_RELEASE_DATE "Apr 23 2026" /* Don't change the lines below. */ diff --git a/etc/plugins/TFile/P010_TWebFile.C b/etc/plugins/TFile/P010_TWebFile.C deleted file mode 100644 index ef9260032ab12..0000000000000 --- a/etc/plugins/TFile/P010_TWebFile.C +++ /dev/null @@ -1,5 +0,0 @@ -void P010_TWebFile() -{ - gPluginMgr->AddHandler("TFile", "^http[s]?:", "ROOT::Deprecated::TWebFile", - "Net", "ROOT::Deprecated::TWebFile(const char*,Option_t*)"); -} diff --git a/etc/plugins/TFile/P120_TNetFile.C b/etc/plugins/TFile/P120_TNetFile.C deleted file mode 100644 index da9f773e40af2..0000000000000 --- a/etc/plugins/TFile/P120_TNetFile.C +++ /dev/null @@ -1,17 +0,0 @@ -void P120_TNetFile() -{ - gPluginMgr->AddHandler("TFile", "^rootd:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^rootup:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^roots:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^rootk:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^rootg:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^rooth:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); - gPluginMgr->AddHandler("TFile", "^rootug:", "ROOT::Deprecated::TNetFile", - "Net", "ROOT::Deprecated::TNetFile(const char*,Option_t*,const char*,Int_t,Int_t)"); -} diff --git a/etc/plugins/TFile/P150_TS3WebFile.C b/etc/plugins/TFile/P150_TS3WebFile.C deleted file mode 100644 index 14f5434b0bfeb..0000000000000 --- a/etc/plugins/TFile/P150_TS3WebFile.C +++ /dev/null @@ -1,11 +0,0 @@ -void P150_TS3WebFile() -{ - gPluginMgr->AddHandler("TFile", "^[a]?s3:", "ROOT::Deprecated::TS3WebFile", - "Net", "ROOT::Deprecated::TS3WebFile(const char*,Option_t*)"); - gPluginMgr->AddHandler("TFile", "^s3http[s]?:", "ROOT::Deprecated::TS3WebFile", - "Net", "ROOT::Deprecated::TS3WebFile(const char*,Option_t*)"); - gPluginMgr->AddHandler("TFile", "^gs:", "ROOT::Deprecated::TS3WebFile", - "Net", "ROOT::Deprecated::TS3WebFile(const char*,Option_t*)"); - gPluginMgr->AddHandler("TFile", "^gshttp[s]?:", "ROOT::Deprecated::TS3WebFile", - "Net", "ROOT::Deprecated::TS3WebFile(const char*,Option_t*)"); -} diff --git a/etc/plugins/TFileStager/P020_TNetFileStager.C b/etc/plugins/TFileStager/P020_TNetFileStager.C deleted file mode 100644 index f28b6ae9ae9d1..0000000000000 --- a/etc/plugins/TFileStager/P020_TNetFileStager.C +++ /dev/null @@ -1,17 +0,0 @@ -void P020_TNetFileStager() -{ - gPluginMgr->AddHandler("TFileStager", "^rootd:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^rootup:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^roots:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^rootk:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^rootg:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^rooth:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); - gPluginMgr->AddHandler("TFileStager", "^rootug:", "ROOT::Deprecated::TNetFileStager", - "Net", "ROOT::Deprecated::TNetFileStager(const char *)"); -} diff --git a/etc/plugins/TSystem/P050_TWebSystem.C b/etc/plugins/TSystem/P050_TWebSystem.C deleted file mode 100644 index 47e242b362e54..0000000000000 --- a/etc/plugins/TSystem/P050_TWebSystem.C +++ /dev/null @@ -1,5 +0,0 @@ -void P050_TWebSystem() -{ - gPluginMgr->AddHandler("TSystem", "^http:", "TWebSystem", - "Net", "TWebSystem()"); -} diff --git a/etc/plugins/TSystem/P070_TNetSystem.C b/etc/plugins/TSystem/P070_TNetSystem.C deleted file mode 100644 index 96b93493f75d8..0000000000000 --- a/etc/plugins/TSystem/P070_TNetSystem.C +++ /dev/null @@ -1,17 +0,0 @@ -void P070_TNetSystem() -{ - gPluginMgr->AddHandler("TSystem", "^rootd:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^rootup:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^roots:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^rootk:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^rootg:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^rooth:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); - gPluginMgr->AddHandler("TSystem", "^rootug:", "ROOT::Deprecated::TNetSystem", - "Net", "ROOT::Deprecated::TNetSystem(const char *,Bool_t)"); -} diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 3f51fe50873e0..6a1a04eaeab22 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -15,14 +15,15 @@ \ingroup IO \brief A file, usually with extension .root, that stores data and code in the form of serialized objects in a file-system-like logical structure, possibly including subdirectory hierarchies. -\note ROOT files contain data, and executable code, for example through TExec, TMacro, and TFormula instances. As for all files, **do not open ROOT files from an unknown origin!** +\note ROOT files contain data, and executable code, for example through TExec, TMacro, and TFormula instances. As for +all files, **do not open ROOT files from an unknown origin!** \note See also \ref IO \note See also \ref rootio (or `io/doc/TFile` folder in your codebase) -ROOT files a are an efficient mean to store C++ class instances, e.g. data, -both as individual objects, in a so called *row-wise fashion*, and in a +ROOT files a are an efficient mean to store C++ class instances, e.g. data, +both as individual objects, in a so called *row-wise fashion*, and in a *so-called columnar fashion*. Also executable code can be stored in ROOT files, -for example in the form of TMacro, TExec or TFormula instances, and the +for example in the form of TMacro, TExec or TFormula instances, and the related federation of classes. For example, a TCanvas or TPad instance may rely on TExec instances stored in @@ -3984,11 +3985,7 @@ TFile *TFile::Open(const char *url, Option_t *options, const char *ftitle, if ((h = gROOT->GetPluginManager()->FindHandler("TFile", name.Data()))) { if (h->LoadPlugin() == -1) return nullptr; - TClass *cl = TClass::GetClass(h->GetClass()); - if (cl && cl->InheritsFrom("ROOT::Deprecated::TNetFile")) - f = (TFile*) h->ExecPlugin(5, name.Data(), option, ftitle, compress, netopt); - else - f = (TFile*) h->ExecPlugin(4, name.Data(), option, ftitle, compress); + f = (TFile *)h->ExecPlugin(4, name.Data(), option, ftitle, compress); } else { // Just try to open it locally but via TFile::Open, so that we pick-up the correct // plug-in in the case file name contains information about a special backend (e.g.) diff --git a/net/auth/src/TAuthenticate.cxx b/net/auth/src/TAuthenticate.cxx index 5af49f683bfa3..17f020c054677 100644 --- a/net/auth/src/TAuthenticate.cxx +++ b/net/auth/src/TAuthenticate.cxx @@ -24,8 +24,6 @@ #include "THostAuth.h" #include "TRootSecContext.h" #include "TPluginManager.h" -#include "TNetFile.h" -#include "TPSocket.h" #include "TMessage.h" #include "TSystem.h" #include "TError.h" @@ -35,9 +33,9 @@ #include "TList.h" #include "NetErrors.h" #include "TRegexp.h" +#include "TSocket.h" #include "TVirtualMutex.h" #include "TTimer.h" -#include "TBase64.h" #include "strlcpy.h" #include "snprintf.h" diff --git a/net/net/CMakeLists.txt b/net/net/CMakeLists.txt index ff871b1934bf9..19593b177dd56 100644 --- a/net/net/CMakeLists.txt +++ b/net/net/CMakeLists.txt @@ -13,14 +13,10 @@ if(ssl) set(NET_SSL_HEADERS TSSLSocket.h - TS3HTTPRequest.h - TS3WebFile.h ) set(NET_SSL_SOURCES src/TSSLSocket.cxx - src/TS3HTTPRequest.cxx - src/TS3WebFile.cxx ) if(MACOSX_SSL_DEPRECATED) @@ -36,18 +32,8 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Net TApplicationRemote.h TApplicationServer.h TFileStager.h - TFTP.h - TGrid.h - TGridCollection.h - TGridJDL.h - TGridJob.h - TGridJobStatus.h - TGridJobStatusList.h - TGridResult.h TMessage.h TMonitor.h - TNetFile.h - TNetFileStager.h TParallelMergingFile.h TPServerSocket.h TPSocket.h @@ -62,24 +48,14 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Net TSQLStatement.h TSQLTableInfo.h TUDPSocket.h - TWebFile.h ${NET_SSL_HEADERS} SOURCES src/NetErrors.cxx src/TApplicationRemote.cxx src/TApplicationServer.cxx src/TFileStager.cxx - src/TFTP.cxx - src/TGrid.cxx - src/TGridJDL.cxx - src/TGridJob.cxx - src/TGridJobStatus.cxx - src/TGridJobStatusList.cxx - src/TGridResult.cxx src/TMessage.cxx src/TMonitor.cxx - src/TNetFile.cxx - src/TNetFileStager.cxx src/TParallelMergingFile.cxx src/TPServerSocket.cxx src/TPSocket.cxx @@ -94,7 +70,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Net src/TSQLStatement.cxx src/TSQLTableInfo.cxx src/TUDPSocket.cxx - src/TWebFile.cxx ${NET_SSL_SOURCES} DICTIONARY_OPTIONS -writeEmptyRootPCM diff --git a/net/net/inc/LinkDef.h b/net/net/inc/LinkDef.h index 994ee53065d34..b059debfc4915 100644 --- a/net/net/inc/LinkDef.h +++ b/net/net/inc/LinkDef.h @@ -14,21 +14,12 @@ #pragma link C++ enum ESockOptions; #pragma link C++ enum ESendRecvOptions; -#pragma link C++ global ROOT::Deprecated::gGrid; -#pragma link C++ global gGridJobStatusList; - #pragma link C++ class TServerSocket; #pragma link C++ class TSocket; #pragma link C++ class TPServerSocket; #pragma link C++ class TPSocket; #pragma link C++ class TMessage; #pragma link C++ class TMonitor; -#pragma link C++ class ROOT::Deprecated::TNetFile; -#pragma link C++ class ROOT::Deprecated::TNetFileStager; -#pragma link C++ class ROOT::Deprecated::TNetSystem; -#pragma link C++ class ROOT::Deprecated::TWebFile; -#pragma link C++ class ROOT::Deprecated::TWebSystem; -#pragma link C++ class ROOT::Deprecated::TFTP; #pragma link C++ class TSQLServer; #pragma link C++ class TSQLResult; #pragma link C++ class TSQLRow; @@ -36,13 +27,6 @@ #pragma link C++ class TSQLTableInfo; #pragma link C++ class TSQLColumnInfo; #pragma link C++ class TSQLMonitoringWriter; -#pragma link C++ class ROOT::Deprecated::TGrid; -#pragma link C++ class ROOT::Deprecated::TGridResult+; -#pragma link C++ class ROOT::Deprecated::TGridJDL+; -#pragma link C++ class ROOT::Deprecated::TGridJob+; -#pragma link C++ class ROOT::Deprecated::TGridJobStatus+; -#pragma link C++ class ROOT::Deprecated::TGridJobStatusList+; -#pragma link C++ class ROOT::Deprecated::TGridCollection+; #pragma link C++ class ROOT::Deprecated::TSecContext; #pragma link C++ class ROOT::Deprecated::TSecContextCleanup; #pragma link C++ class TFileStager; @@ -52,16 +36,7 @@ #pragma link C++ class TParallelMergingFile+; #ifdef R__SSL -#pragma link C++ class ROOT::Deprecated::TS3HTTPRequest+; -#pragma link C++ class ROOT::Deprecated::TS3WebFile+; #pragma link C++ class TSSLSocket; #endif -#pragma read sourceClass="TGridCollection" version="[-1]" targetClass="ROOT::Deprecated::TGridCollection" -#pragma read sourceClass="TGridJDL" version="[-1]" targetClass="ROOT::Deprecated::TGridJDL" -#pragma read sourceClass="TGridJob" version="[-1]" targetClass="ROOT::Deprecated::TGridJob" -#pragma read sourceClass="TGridJobStatus" version="[-1]" targetClass="ROOT::Deprecated::TGridJobStatus" -#pragma read sourceClass="TGridJobStatusList" version="[-1]" targetClass="ROOT::Deprecated::TGridJobStatusList" -#pragma read sourceClass="TGridResult" version="[-1]" targetClass="ROOT::Deprecated::TGridResult" - #endif diff --git a/net/net/inc/TFTP.h b/net/net/inc/TFTP.h deleted file mode 100644 index e0d00169f908c..0000000000000 --- a/net/net/inc/TFTP.h +++ /dev/null @@ -1,133 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fons Rademakers 13/02/2001 - -/************************************************************************* - * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TFTP -#define ROOT_TFTP - -////////////////////////////////////////////////////////////////////////// -// // -// TFTP // -// // -// This class provides all infrastructure for a performant file // -// transfer protocol. It works in conjuction with the rootd daemon // -// and can use parallel sockets to improve performance over fat pipes. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" -#include "TSystem.h" -#include "TString.h" -#include "MessageTypes.h" - - -class TSocket; - -namespace ROOT::Deprecated { - -class TFTP : public TObject { - -private: - TString fHost; // FQDN of remote host - TString fUser; // remote user - Int_t fPort; // port to which to connect - Int_t fParallel; // number of parallel sockets - Int_t fWindowSize; // tcp window size used - Int_t fProtocol; // rootd protocol level - Int_t fLastBlock; // last block successfully transferred - Int_t fBlockSize; // size of data buffer used to transfer - Int_t fMode; // binary or ascii file transfer mode - Long64_t fRestartAt; // restart transmission at specified offset - TString fCurrentFile; // file currently being get or put - TSocket *fSocket; ///://[:], e.g. alien://alice.cern.ch // -// Depending on the specified an appropriate plugin library // -// will be loaded which will provide the real interface. // -// // -// Related classes are TGridResult. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" - -#include "TString.h" - -#include "TGridJob.h" - -namespace ROOT::Deprecated { - -class TGridCollection; -class TGridJDL; -class TGridJob; -class TGridJobStatusList; -class TGridResult; - -class TGrid : public TObject { - -protected: - TString fGridUrl; // the GRID url used to create the grid connection - TString fGrid; // type of GRID (AliEn, ...) - TString fHost; // GRID portal to which we are connected - TString fUser; // user name - TString fPw; // user passwd - TString fOptions; // options specified - Int_t fPort; // port to which we are connected - -public: - TGrid() : fGridUrl(), fGrid(), fHost(), fUser(), fPw(), fOptions(), fPort(-1) {} - virtual ~TGrid() {} - - const char *GridUrl() const { return fGridUrl; } - const char *GetGrid() const { return fGrid; } - const char *GetHost() const { return fHost; } - const char *GetUser() const { return fUser; } - const char *GetPw() const { return fPw; } - const char *GetOptions() const { return fOptions; } - Int_t GetPort() const { return fPort; } - virtual Bool_t IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; } - - virtual void Shell() { MayNotUse("Shell"); } - virtual void Stdout() { MayNotUse("Stdout"); } - virtual void Stderr() { MayNotUse("Stderr"); } - - virtual TGridResult *Command(const char * /*command*/, - Bool_t /*interactive*/ = kFALSE, - UInt_t /*stream*/ = 2) - { MayNotUse("Command"); return nullptr; } - - virtual TGridResult *Query(const char * /*path*/, const char * /*pattern*/, - const char * /*conditions*/ = "", const char * /*options*/ = "") - { MayNotUse("Query"); return nullptr; } - - virtual TGridResult *LocateSites() { MayNotUse("LocalSites"); return nullptr; } - - //--- Catalogue Interface - virtual TGridResult *Ls(const char* /*ldn*/ ="", Option_t* /*options*/ ="", Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Ls"); return nullptr; } - virtual const char *Pwd(Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Pwd"); return nullptr; } - virtual const char *GetHomeDirectory() - { MayNotUse("GetHomeDirectory"); return nullptr; } - virtual Bool_t Cd(const char* /*ldn*/ ="",Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Cd"); return kFALSE; } - virtual Int_t Mkdir(const char* /*ldn*/ ="", Option_t* /*options*/ ="", Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Mkdir"); return kFALSE; } - virtual Bool_t Rmdir(const char* /*ldn*/ ="", Option_t* /*options*/ ="", Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Mkdir"); return kFALSE; } - virtual Bool_t Register(const char* /*lfn*/ , const char* /*turl*/ , Long_t /*size*/ =-1, const char* /*se*/ =nullptr, const char* /*guid*/ =nullptr, Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Mkdir"); return kFALSE; } - virtual Bool_t Rm(const char* /*lfn*/ , Option_t* /*option*/ ="", Bool_t /*verbose*/ =kFALSE) - { MayNotUse("Mkdir"); return kFALSE; } - - //--- Job Submission Interface - virtual TGridJob *Submit(const char * /*jdl*/) - { MayNotUse("Submit"); return nullptr; } - virtual TGridJDL *GetJDLGenerator() - { MayNotUse("GetJDLGenerator"); return nullptr; } - virtual TGridCollection *OpenCollection(const char *, UInt_t /*maxentries*/ = 1000000) - { MayNotUse("OpenCollection"); return nullptr; } - virtual TGridCollection *OpenCollectionQuery(TGridResult * /*queryresult*/,Bool_t /*nogrouping*/ = kFALSE) - { MayNotUse("OpenCollection"); return nullptr; } - virtual TGridJobStatusList* Ps(const char* /*options*/, Bool_t /*verbose*/ = kTRUE) - { MayNotUse("Ps"); return nullptr; } - virtual Bool_t KillById(TString /*jobid*/) - { MayNotUse("KillById"); return kFALSE; } - virtual Bool_t ResubmitById(TString /*jobid*/) - { MayNotUse("ResubmitById"); return kFALSE; } - virtual Bool_t Kill(TGridJob *gridjob) - { return ((gridjob)?KillById(gridjob->GetJobID()):kFALSE); } - virtual Bool_t Resubmit(TGridJob* gridjob) - { return ((gridjob)?ResubmitById(gridjob->GetJobID()):kFALSE); } - - //--- Load desired plugin and setup conection to GRID - static TGrid *Connect(const char *grid, const char *uid = nullptr, - const char *pw = nullptr, const char *options = nullptr); - - ClassDefOverride(TGrid,0) // ABC defining interface to GRID services -}; - -R__EXTERN TGrid *gGrid; - -} // namespace ROOT::Deprecated - -using TGrid R__DEPRECATED(6, 42, "TGrid is expected to be unused and thus deprecated") = ROOT::Deprecated::TGrid; -R__EXTERN ROOT::Deprecated::TGrid *&gGrid R__DEPRECATED(6, 42, "gGrid is expected to be unused and thus deprecated"); - -#endif diff --git a/net/net/inc/TGridCollection.h b/net/net/inc/TGridCollection.h deleted file mode 100644 index fd08c555e0c75..0000000000000 --- a/net/net/inc/TGridCollection.h +++ /dev/null @@ -1,125 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Andreas-Joachim Peters 2005-05-09 - -/************************************************************************* - * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TGridCollection -#define ROOT_TGridCollection - -////////////////////////////////////////////////////////////////////////// -// // -// TGridCollection // -// // -// Class which manages collection files on the Grid. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" - -class TMap; -class TFile; -class TEntryList; -class TList; -class TDSet; -class TFileCollection; - -namespace ROOT::Deprecated { - -class TGridResult; - -class TGridCollection : public TObject { -public: - TGridCollection() { } - virtual ~TGridCollection() { } - - virtual void Reset() - { MayNotUse("Reset"); } - virtual TMap *Next() - { MayNotUse("Next"); return nullptr;} - virtual Bool_t Remove(TMap *) - { MayNotUse("Remove"); return 0;} - virtual const char *GetTURL(const char * /*name*/ = "") - { MayNotUse("GetTURL"); return nullptr;} - virtual const char *GetSURL(const char * /*name*/ = "") - { MayNotUse("GetSURL"); return nullptr;} - virtual const char *GetLFN(const char * /*name*/ = "") - { MayNotUse("GetLFN"); return nullptr;} - virtual Long64_t GetSize(const char * /*name*/ = "") - { MayNotUse("GetSize"); return -1;} - virtual Bool_t IsOnline(const char * /*name*/ = "") - { MayNotUse("IsOnline"); return 0;} - virtual Bool_t IsSelected(const char * /*name*/ = "") - { MayNotUse("IsSelected"); return 0;} - virtual void Status() - { MayNotUse("Status"); } - virtual void SetTag(const char * , const char * , TMap* ) - { MayNotUse("SetTag"); } - virtual Bool_t SelectFile(const char *, Int_t /*nstart*/ = -1 , Int_t /*nstop*/ = -1) - { MayNotUse("SelectFile"); return kFALSE;} - virtual Bool_t DeselectFile(const char *, Int_t /*nstart*/ = -1, Int_t /*nstop*/ = -1) - { MayNotUse("DeselectFile"); return kFALSE;} - virtual Bool_t InvertSelection() - { MayNotUse("InvertSelection"); return kFALSE;} - virtual Bool_t DownscaleSelection(UInt_t /* scaler */ = 2) - { MayNotUse("DownscaleSelection"); return kFALSE;} - virtual Bool_t ExportXML(const char *, Bool_t /*selected*/ = kTRUE, Bool_t /*online*/ = kTRUE, - const char * /*name*/ = "ROOT xml", const char * /*comment*/ = "Exported XML") - { MayNotUse("ExportXML"); return kFALSE;} - virtual const char* GetExportUrl() - { MayNotUse("GetExportUrl"); return nullptr;} - virtual Bool_t SetExportUrl(const char * /*exporturl*/ = nullptr) - { MayNotUse("SetExportUrl"); return kFALSE;} - virtual void Print(Option_t * = "") const override - { MayNotUse("Print"); } - virtual TFile *OpenFile(const char *) - { MayNotUse("OpenFile"); return nullptr;} - virtual TList *GetFileGroupList() const - { MayNotUse("GetFileGroupList"); return nullptr;} - virtual TEntryList *GetEntryList(const char *) - { MayNotUse("GetEntryList"); return nullptr;} - virtual UInt_t GetNofGroups() const - { MayNotUse("GetNofGroups"); return 0;} - virtual UInt_t GetNofGroupfiles() const - { MayNotUse("GetNofGroupfiles"); return 0;} - virtual Bool_t OverlapCollection(TGridCollection *) - { MayNotUse("OverlapCollection"); return 0;} - virtual void Add(TGridCollection *) - { MayNotUse("Add");} - virtual Bool_t Stage(Bool_t /*bulk*/ = kFALSE, Option_t * /*TFileStager option*/ = "") - { MayNotUse("Stage"); return kFALSE;} - virtual Bool_t Prepare(Bool_t /*bulk*/ = kFALSE) - { MayNotUse("Prepare"); return kFALSE;} - virtual Bool_t CheckIfOnline(Bool_t /*bulk*/ = kFALSE) - { MayNotUse("CheckIfOnline"); return kFALSE;} - virtual TDSet *GetDataset(const char *, const char * , const char *) - { MayNotUse("GetDataset"); return nullptr;} - virtual TGridResult *GetGridResult(const char * /*filename*/ = "", Bool_t /*onlyonline*/ = kTRUE , Bool_t /*publicaccess*/ = kFALSE ) - { MayNotUse("GetGridResult"); return nullptr;} - virtual Bool_t LookupSUrls(Bool_t /*verbose*/ = kTRUE) - { MayNotUse("LookupSUrls"); return kFALSE;} - virtual TList *GetTagFilterList() const - { MayNotUse("GetTagFilterList"); return nullptr;} - virtual void SetTagFilterList(TList *) - { MayNotUse("SetTagFilterList");} - virtual const char* GetCollectionName() const - { MayNotUse("GetCollectionName"); return nullptr;} - virtual const char* GetInfoComment() const - { MayNotUse("GetInfoComment"); return nullptr;} - virtual TFileCollection* GetFileCollection(const char* /*name*/ = "", const char* /*title*/ = "") const - { MayNotUse("GetFileCollection"); return nullptr;} - - ClassDefOverride(TGridCollection,1) // ABC managing collection of files on the Grid -}; - -} // namespace ROOT::Deprecated - -using TGridCollection R__DEPRECATED(6, 42, "TGridCollection is expected to be unused and thus deprecated") = - ROOT::Deprecated::TGridCollection; - -#endif diff --git a/net/net/inc/TGridJDL.h b/net/net/inc/TGridJDL.h deleted file mode 100644 index 6d36ddbb85fbb..0000000000000 --- a/net/net/inc/TGridJDL.h +++ /dev/null @@ -1,84 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 28/9/2004 -// Jancurova.lucia@cern.ch Slovakia 29/9/2008 - -/************************************************************************* - * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TGridJDL -#define ROOT_TGridJDL - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJDL // -// // -// Abstract base class to generate JDL files for job submission to the // -// Grid. // -// // -// Related classes are TGLiteJDL // -// . // -////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" -#include "TString.h" -#include "TMap.h" - -namespace ROOT::Deprecated { - -class TGridJDL : public TObject { -protected: - TMap fMap; // stores the key, value pairs of the JDL - TMap fDescriptionMap; // stores the key, value pairs of the JDL -public: - TGridJDL() : fMap(), fDescriptionMap() { } - virtual ~TGridJDL(); - - void SetValue(const char *key, const char *value); - const char *GetValue(const char *key); - void SetDescription(const char *key, const char *description); - const char *GetDescription(const char *key); - TString AddQuotes(const char *value); - void AddToSet(const char *key, const char *value); - void AddToSetDescription(const char *key, const char *description); - virtual TString Generate(); - void Clear(const Option_t* = "") override; - - virtual void SetExecutable(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void SetArguments(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void SetEMail(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void SetOutputDirectory(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void SetPrice(UInt_t price=1, const char *description=nullptr) = 0; - virtual void SetTTL(UInt_t ttl=72000, const char *description=nullptr) = 0; - virtual void SetJobTag(const char *jobtag=nullptr, const char *description=nullptr) = 0; - virtual void SetInputDataListFormat(const char *format="xml-single", const char *description=nullptr) = 0; - virtual void SetInputDataList(const char *list="collection.xml", const char *description=nullptr) = 0; - - virtual void SetSplitMode(const char *value, UInt_t maxnumberofinputfiles=0, - UInt_t maxinputfilesize=0, const char *d1=nullptr, - const char *d2=nullptr, const char *d3=nullptr) = 0; - virtual void SetSplitArguments(const char *splitarguments=nullptr, const char *description=nullptr) = 0; - virtual void SetValidationCommand(const char *value, const char *description=nullptr) = 0; - - virtual void AddToInputSandbox(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void AddToOutputSandbox(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void AddToInputData(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void AddToInputDataCollection(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void AddToRequirements(const char *value=nullptr, const char *description=nullptr) = 0; - virtual void AddToPackages(const char *name="AliRoot", const char *version="default", - const char *type="VO_ALICE", const char *description=nullptr) = 0; - virtual void AddToOutputArchive(const char *value=nullptr, const char *description=nullptr) = 0; - - ClassDefOverride(TGridJDL,1) // ABC defining interface JDL generator -}; - -} // namespace ROOT::Deprecated - -using TGridJDL R__DEPRECATED(6, 42, "TGridJDL is expected to be unused and thus deprecated") = - ROOT::Deprecated::TGridJDL; - -#endif diff --git a/net/net/inc/TGridJob.h b/net/net/inc/TGridJob.h deleted file mode 100644 index 9e5d7baea4b60..0000000000000 --- a/net/net/inc/TGridJob.h +++ /dev/null @@ -1,56 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 06/10/2004 - -/************************************************************************* - * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TGridJob -#define ROOT_TGridJob - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJob // -// // -// Abstract base class defining interface to a GRID job. // -// // -// Related classes are TGridJobStatus. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" -#include "TString.h" - -namespace ROOT::Deprecated { - -class TGridJobStatus; - -class TGridJob : public TObject { - -protected: - TString fJobID; // the job's ID - -public: - TGridJob(TString jobID) : fJobID(jobID) { } - virtual ~TGridJob() { } - - virtual TString GetJobID() { return fJobID; } - - virtual TGridJobStatus *GetJobStatus() const = 0; - virtual Int_t GetOutputSandbox(const char *localpath, Option_t *opt = nullptr); - - virtual Bool_t Resubmit() = 0; - virtual Bool_t Cancel () = 0; - ClassDefOverride(TGridJob,1) // ABC defining interface to a GRID job -}; - -} // namespace ROOT::Deprecated - -using TGridJob R__DEPRECATED(6, 42, "TGridJob is expected to be unused and thus deprecated") = - ROOT::Deprecated::TGridJob; - -#endif diff --git a/net/net/inc/TGridJobStatus.h b/net/net/inc/TGridJobStatus.h deleted file mode 100644 index bb6264ec038b2..0000000000000 --- a/net/net/inc/TGridJobStatus.h +++ /dev/null @@ -1,59 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 06/10/2004 - -/************************************************************************* - * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TGridJobStatus -#define ROOT_TGridJobStatus - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJobStatus // -// // -// Abstract base class containing the status of a Grid job. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TNamed.h" - -namespace ROOT::Deprecated { - -class TGridJobStatus : public TNamed { - -public: - // Subset of Grid job states for common GetStatus function - enum EGridJobStatus { -// clang++ - -#include -#include -#include -#ifndef R__WIN32 -# include -#else -# define ssize_t int -# include -# include -#endif - -#include "strlcpy.h" -#include "TFTP.h" -#include "TPSocket.h" -#include "TUrl.h" -#include "TStopwatch.h" -#include "TSystem.h" -#include "TROOT.h" -#include "TError.h" -#include "NetErrors.h" -#include "TRegexp.h" -#include "TVirtualMutex.h" - -#if defined(R__UNIX) || defined(R__MACOSX) -#define HAVE_MMAP -#endif - -#ifdef HAVE_MMAP -# include -#ifndef MAP_FILE -#define MAP_FILE 0 /* compatability flag */ -#endif -#endif - - -Long64_t ROOT::Deprecated::TFTP::fgBytesWrite = 0; -Long64_t ROOT::Deprecated::TFTP::fgBytesRead = 0; - - - -//////////////////////////////////////////////////////////////////////////////// -/// Open connection to host specified by the url using par parallel sockets. -/// The url has the form: [root[s,k]://]host[:port]. -/// If port is not specified the default rootd port (1094) will be used. -/// Using wsize one can specify the tcp window size. Normally this is not -/// needed when using parallel sockets. -/// An existing connection (TSocket *sock) can also be used to establish -/// the FTP session. - -ROOT::Deprecated::TFTP::TFTP(const char *url, Int_t par, Int_t wsize, TSocket *sock) -{ - fSocket = sock; - - TString s = url; - if (s.Contains("://")) { - if (!s.BeginsWith("root")) { - Error("TFTP", - "url must be of the form \"[root[up,s,k,g,h,ug]://]host[:port]\""); - MakeZombie(); - return; - } - } else - s = "root://" + s; - - Init(s, par, wsize); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set up the actual connection. - -void ROOT::Deprecated::TFTP::Init(const char *surl, Int_t par, Int_t wsize) -{ - TUrl url(surl); - TString hurl(url.GetProtocol()); - if (hurl.Contains("root")) { - hurl.Insert(4,"dp"); - } else { - hurl = "rootdp"; - } - hurl += TString(Form("://%s@%s:%d", - url.GetUser(), url.GetHost(), url.GetPort())); - fSocket = ROOT::Deprecated::TSocketFriend::CreateAuthSocket(hurl, par, wsize, fSocket); - if (!fSocket || !ROOT::Deprecated::TSocketFriend::IsAuthenticated(*fSocket)) { - if (par > 1) - Error("TFTP", "can't open %d-stream connection to rootd on " - "host %s at port %d", par, url.GetHost(), url.GetPort()); - else - Error("TFTP", "can't open connection to rootd on " - "host %s at port %d", url.GetHost(), url.GetPort()); - goto zombie; - } - - fProtocol = fSocket->GetRemoteProtocol(); - fUser = ROOT::Deprecated::TSocketFriend::GetSecContext(*fSocket)->GetUser(); - - fHost = url.GetHost(); - fPort = url.GetPort(); - fParallel = par; - fWindowSize = wsize; - fLastBlock = 0; - fRestartAt = 0; - fBlockSize = kDfltBlockSize; - fMode = kBinary; - fBytesWrite = 0; - fBytesRead = 0; - - // Replace our socket in the list with this - // for consistency during the final cleanup - // (The socket will be delete by us when everything is ok remotely) - { - R__LOCKGUARD(gROOTMutex); - gROOT->GetListOfSockets()->Remove(fSocket); - gROOT->GetListOfSockets()->Add(this); - } - return; - -zombie: - MakeZombie(); - SafeDelete(fSocket); -} - -//////////////////////////////////////////////////////////////////////////////// -/// TFTP dtor. Send close message and close socket. - -ROOT::Deprecated::TFTP::~TFTP() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print some info about the FTP connection. - -void ROOT::Deprecated::TFTP::Print(Option_t *) const -{ - TString secCont; - - Printf("Local host: %s", gSystem->HostName()); - Printf("Remote host: %s [%d]", fHost.Data(), fPort); - Printf("Remote user: %s", fUser.Data()); - if (ROOT::Deprecated::TSocketFriend::IsAuthenticated(*fSocket)) { - Printf("Security context: %s", - ROOT::Deprecated::TSocketFriend::GetSecContext(*fSocket)->AsString(secCont)); - } - Printf("Rootd protocol vers.: %d", fSocket->GetRemoteProtocol()); - if (fParallel > 1) { - Printf("Parallel sockets: %d", fParallel); - } - Printf("TCP window size: %d", fWindowSize); - Printf("Rootd protocol: %d", fProtocol); - Printf("Transfer block size: %d", fBlockSize); - Printf("Transfer mode: %s", fMode ? "ascii" : "binary"); - Printf("Bytes sent: %lld", fBytesWrite); - Printf("Bytes received: %lld", fBytesRead); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print error string depending on error code. - -void ROOT::Deprecated::TFTP::PrintError(const char *where, Int_t err) const -{ - Error(where, "%s", gRootdErrStr[err]); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return status from rootd server and message kind. Returns -1 in -/// case of error otherwise 8 (sizeof 2 words, status and kind). - -Int_t ROOT::Deprecated::TFTP::Recv(Int_t &status, EMessageTypes &kind) const -{ - kind = kROOTD_ERR; - status = 0; - - if (!fSocket) return -1; - - Int_t what; - Int_t n = fSocket->Recv(status, what); - kind = (EMessageTypes) what; - return n; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Make sure the block size is a power of two, with a minimum of 32768. - -void ROOT::Deprecated::TFTP::SetBlockSize(Int_t blockSize) -{ - if (blockSize < 32768) { - fBlockSize = 32768; - return; - } - - int i; - for (i = 0; i < int(sizeof(blockSize)*8); i++) - if ((blockSize >> i) == 1) - break; - - fBlockSize = 1 << i; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Transfer file to remote host. Returns number of bytes -/// sent or < 0 in case of error. Error -1 connection is still -/// open, error -2 connection has been closed. In case of failure -/// fRestartAt is set to the number of bytes correclty transferred. -/// Calling PutFile() immediately afterwards will restart at fRestartAt. -/// If this is not desired call SetRestartAt(0) before calling PutFile(). -/// If rootd reports that the file is locked, and you are sure this is not -/// the case (e.g. due to a crash), you can force unlock it by prepending -/// the remoteName with a '-'. - -Long64_t ROOT::Deprecated::TFTP::PutFile(const char *file, const char *remoteName) -{ - if (!IsOpen() || !file || !*file) return -1; - -#if defined(R__WIN32) || defined(R__WINGCC) - Int_t fd = open(file, O_RDONLY | O_BINARY); -#elif defined(R__SEEK64) - Int_t fd = open64(file, O_RDONLY); -#else - Int_t fd = open(file, O_RDONLY); -#endif - if (fd < 0) { - Error("PutFile", "cannot open %s in read mode", file); - return -1; - } - - Long64_t size; - Long_t id, flags, modtime; - if (gSystem->GetPathInfo(file, &id, &size, &flags, &modtime) == 0) { - if (flags > 1) { - Error("PutFile", "%s not a regular file (%ld)", file, flags); - close(fd); - return -1; - } - } else { - Warning("PutFile", "could not stat %s", file); - close(fd); - return -1; - } - - if (!remoteName) - remoteName = file; - - Long64_t restartat = fRestartAt; - - // check if restartat value makes sense - if (restartat && (restartat >= size)) - restartat = 0; - - if (fSocket->Send(Form("%s %d %d %lld %lld", remoteName, fBlockSize, fMode, - size, restartat), kROOTD_PUTFILE) < 0) { - Error("PutFile", "error sending kROOTD_PUTFILE command"); - close(fd); - return -2; - } - - Int_t stat; - EMessageTypes kind; - - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - PrintError("PutFile", stat); - close(fd); - return -1; - } - - Info("PutFile", "sending file %s (%lld bytes, starting at %lld)", - file, size, restartat); - - TStopwatch timer; - timer.Start(); - - Long64_t pos = restartat & ~(fBlockSize-1); - Int_t skip = restartat - pos; - -#ifndef HAVE_MMAP - char *buf = new char[fBlockSize]; -#if defined(R__SEEK64) - lseek64(fd, pos, SEEK_SET); -#elif defined(R__WIN32) - _lseeki64(fd, pos, SEEK_SET); -#else - lseek(fd, pos, SEEK_SET); -#endif -#endif - - while (pos < size) { - Long64_t left = Long64_t(size - pos); - if (left > fBlockSize) - left = fBlockSize; -#ifdef HAVE_MMAP -#if defined(R__SEEK64) - char *buf = (char*) mmap64(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos); -#else - char *buf = (char*) mmap(0, left, PROT_READ, MAP_FILE | MAP_SHARED, fd, pos); -#endif - if (buf == (char *) -1) { - Error("PutFile", "mmap of file %s failed", file); - close(fd); - return -1; - } -#else - Int_t siz; - while ((siz = read(fd, buf, left)) < 0 && TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - if (siz < 0 || siz != left) { - Error("PutFile", "error reading from file %s", file); - // Send urgent message to rootd to stop tranfer - delete [] buf; - close(fd); - return -1; - } -#endif - - if (fSocket->SendRaw(buf+skip, left-skip) < 0) { - Error("PutFile", "error sending buffer"); - // Send urgent message to rootd to stop transfer -#ifdef HAVE_MMAP - munmap(buf, left); -#else - delete [] buf; -#endif - close(fd); - return -2; - } - - fBytesWrite += left-skip; - fgBytesWrite += left-skip; - - fRestartAt = pos; // bytes correctly sent up till now - - pos += left; - skip = 0; - -#ifdef HAVE_MMAP - munmap(buf, left); -#endif - } - -#ifndef HAVE_MMAP - delete [] buf; -#endif - - close(fd); - - fRestartAt = 0; - - // get acknowlegdement from server that file was stored correctly - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - PrintError("PutFile", stat); - close(fd); - return -1; - } - - // provide timing numbers - Double_t speed, t = timer.RealTime(); - if (t > 0) - speed = Double_t(size - restartat) / t; - else - speed = 0.0; - if (speed > 524288) - Info("PutFile", "%.3f seconds, %.2f Mbytes per second", - t, speed / 1048576); - else if (speed > 512) - Info("PutFile", "%.3f seconds, %.2f Kbytes per second", - t, speed / 1024); - else - Info("PutFile", "%.3f seconds, %.2f bytes per second", - t, speed); - - return Long64_t(size - restartat); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Transfer file from remote host. Returns number of bytes -/// received or < 0 in case of error. Error -1 connection is still -/// open, error -2 connection has been closed. In case of failure -/// fRestartAt is set to the number of bytes correclty transferred. -/// Calling GetFile() immediately afterwards will restart at fRestartAt. -/// If this is not desired call SetRestartAt(0) before calling GetFile(). -/// If rootd reports that the file is locked, and you are sure this is not -/// the case (e.g. due to a crash), you can force unlock it by prepending -/// the file name with a '-'. - -Long64_t ROOT::Deprecated::TFTP::GetFile(const char *file, const char *localName) -{ - if (!IsOpen() || !file || !*file) return -1; - - if (!localName) { - if (file[0] == '-') - localName = file+1; - else - localName = file; - } - - Long64_t restartat = fRestartAt; - - if (fSocket->Send(Form("%s %d %d %lld", file, fBlockSize, fMode, - restartat), kROOTD_GETFILE) < 0) { - Error("GetFile", "error sending kROOTD_GETFILE command"); - return -2; - } - - Int_t stat; - EMessageTypes kind; - - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - PrintError("GetFile", stat); - return -1; - } - - // get size of remote file - Long64_t size; - Int_t what; - char mess[128]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("GetFile", "error receiving remote file size"); - return -2; - } -#ifdef R__WIN32 - sscanf(mess, "%I64d", &size); -#else - sscanf(mess, "%lld", &size); -#endif - - // check if restartat value makes sense - if (restartat && (restartat >= size)) - restartat = 0; - - // open local file - Int_t fd; - if (!restartat) { -#if defined(R__WIN32) || defined(R__WINGCC) - if (fMode == kBinary) - fd = open(localName, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, - S_IREAD | S_IWRITE); - else - fd = open(localName, O_CREAT | O_TRUNC | O_WRONLY, - S_IREAD | S_IWRITE); -#elif defined(R__SEEK64) - fd = open64(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600); -#else - fd = open(localName, O_CREAT | O_TRUNC | O_WRONLY, 0600); -#endif - } else { -#if defined(R__WIN32) || defined(R__WINGCC) - if (fMode == kBinary) - fd = open(localName, O_WRONLY | O_BINARY, S_IREAD | S_IWRITE); - else - fd = open(localName, O_WRONLY, S_IREAD | S_IWRITE); -#elif defined(R__SEEK64) - fd = open64(localName, O_WRONLY, 0600); -#else - fd = open(localName, O_WRONLY, 0600); -#endif - } - - if (fd < 0) { - Error("GetFile", "cannot open %s", localName); - // send urgent message to rootd to stop tranfer - return -1; - } - - // check file system space - if (strcmp(localName, "/dev/null")) { - Long_t id, bsize, blocks, bfree; - if (gSystem->GetFsInfo(localName, &id, &bsize, &blocks, &bfree) == 0) { - Long64_t space = (Long64_t)bsize * (Long64_t)bfree; - if (space < size - restartat) { - Error("GetFile", "not enough space to store file %s", localName); - // send urgent message to rootd to stop tranfer - close(fd); - return -1; - } - } else - Warning("GetFile", "could not determine if there is enough free space to store file"); - } - - // seek to restartat position - if (restartat) { -#if defined(R__SEEK64) - if (lseek64(fd, restartat, SEEK_SET) < 0) { -#elif defined(R__WIN32) - if (_lseeki64(fd, restartat, SEEK_SET) < 0) { -#else - if (lseek(fd, restartat, SEEK_SET) < 0) { -#endif - Error("GetFile", "cannot seek to position %lld in file %s", - restartat, localName); - // if cannot seek send urgent message to rootd to stop tranfer - close(fd); - return -1; - } - } - - Info("GetFile", "getting file %s (%lld bytes, starting at %lld)", - localName, size, restartat); - - TStopwatch timer; - timer.Start(); - - char *buf = new char[fBlockSize]; - char *buf2 = 0; - if (fMode == kAscii) - buf2 = new char[fBlockSize]; - - Long64_t pos = restartat & ~(fBlockSize-1); - Int_t skip = restartat - pos; - - while (pos < size) { - Long64_t left = size - pos; - if (left > fBlockSize) - left = fBlockSize; - - Int_t n; - while ((n = fSocket->RecvRaw(buf, Int_t(left-skip))) < 0 && - TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - - if (n != Int_t(left-skip)) { - Error("GetFile", "error receiving buffer of length %d, got %d", - Int_t(left-skip), n); - close(fd); - delete [] buf; delete [] buf2; - return -2; - } - - // in case of ascii file, loop over buffer and remove \r's - ssize_t siz; - if (fMode == kAscii) { - Int_t i = 0, j = 0; - while (i < n) { - if (buf[i] == '\r') - i++; - else - buf2[j++] = buf[i++]; - } - n = j; - while ((siz = write(fd, buf2, n)) < 0 && TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - } else { - while ((siz = write(fd, buf, n)) < 0 && TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - } - - if (siz < 0) { - SysError("GetFile", "error writing file %s", localName); - // send urgent message to rootd to stop tranfer - close(fd); - delete [] buf; delete [] buf2; - return -1; - } - - if (siz != n) { - Error("GetFile", "error writing all requested bytes to file %s, wrote %ld of %d", - localName, (Long_t)siz, n); - // send urgent message to rootd to stop tranfer - close(fd); - delete [] buf; delete [] buf2; - return -1; - } - - fBytesRead += left-skip; - fgBytesRead += left-skip; - - fRestartAt = pos; // bytes correctly received up till now - - pos += left; - skip = 0; - } - - delete [] buf; delete [] buf2; - -#ifndef R__WIN32 - fchmod(fd, 0666); -#endif - - close(fd); - - fRestartAt = 0; - - // provide timing numbers - Double_t speed, t = timer.RealTime(); - if (t > 0) - speed = Double_t(size - restartat) / t; - else - speed = 0.0; - if (speed > 524288) - Info("GetFile", "%.3f seconds, %.2f Mbytes per second", - t, speed / 1048576); - else if (speed > 512) - Info("GetFile", "%.3f seconds, %.2f Kbytes per second", - t, speed / 1024); - else - Info("GetFile", "%.3f seconds, %.2f bytes per second", - t, speed); - - return Long64_t(size - restartat); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Change the remote directory. If the remote directory contains a .message -/// file and it is < 1024 characters then the contents is echoed back. -/// Returns 0 in case of success and -1 in case of failure. - -Int_t ROOT::Deprecated::TFTP::ChangeDirectory(const char *dir) const -{ - if (!IsOpen()) return -1; - - if (!dir || !*dir) { - Error("ChangeDirectory", "illegal directory name specified"); - return -1; - } - - if (fSocket->Send(Form("%s", dir), kROOTD_CHDIR) < 0) { - Error("ChangeDirectory", "error sending kROOTD_CHDIR command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("ChangeDirectory", "error receiving chdir confirmation"); - return -1; - } - if (what == kMESS_STRING) { - Printf("%s\n", mess); - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("ChangeDirectory", "error receiving chdir confirmation"); - return -1; - } - } - - Info("ChangeDirectory", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Make a remote directory. Anonymous users may not create directories. -/// Returns 0 in case of success and -1 in case of failure. - -Int_t ROOT::Deprecated::TFTP::MakeDirectory(const char *dir, Bool_t print) const -{ - if (!IsOpen()) return -1; - - if (!dir || !*dir) { - Error("MakeDirectory", "illegal directory name specified"); - return -1; - } - - if (fSocket->Send(Form("%s", dir), kROOTD_MKDIR) < 0) { - Error("MakeDirectory", "error sending kROOTD_MKDIR command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("MakeDirectory", "error receiving mkdir confirmation"); - return -1; - } - - if (print) - Info("MakeDirectory", "%s", mess); - - if (!strncmp(mess,"OK:",3)) - return 1; - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Delete a remote directory. Anonymous users may not delete directories. -/// Returns 0 in case of success and -1 in case of failure. - -Int_t ROOT::Deprecated::TFTP::DeleteDirectory(const char *dir) const -{ - if (!IsOpen()) return -1; - - if (!dir || !*dir) { - Error("DeleteDirectory", "illegal directory name specified"); - return -1; - } - - if (fSocket->Send(Form("%s", dir), kROOTD_RMDIR) < 0) { - Error("DeleteDirectory", "error sending kROOTD_RMDIR command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("DeleteDirectory", "error receiving rmdir confirmation"); - return -1; - } - - Info("DeleteDirectory", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// List remote directory. With cmd you specify the options and directory -/// to be listed to ls. Returns 0 in case of success and -1 in case of -/// failure. - -Int_t ROOT::Deprecated::TFTP::ListDirectory(Option_t *cmd) const -{ - if (!IsOpen()) return -1; - - if (!cmd || !*cmd) - cmd = "ls ."; - - if (fSocket->Send(Form("%s", cmd), kROOTD_LSDIR) < 0) { - Error("ListDirectory", "error sending kROOTD_LSDIR command"); - return -1; - } - - Int_t what; - char mess[1024]; - - do { - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("ListDirectory", "error receiving lsdir confirmation"); - return -1; - } - printf("%s", mess); - } while (what == kMESS_STRING); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print path of remote working directory. Returns 0 in case of succes and -/// -1 in cse of failure. - -Int_t ROOT::Deprecated::TFTP::PrintDirectory() const -{ - if (!IsOpen()) return -1; - - if (fSocket->Send("", kROOTD_PWD) < 0) { - Error("DeleteDirectory", "error sending kROOTD_PWD command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("PrintDirectory", "error receiving pwd confirmation"); - return -1; - } - - Info("PrintDirectory", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Rename a remote file. Anonymous users may not rename files. -/// Returns 0 in case of success and -1 in case of failure. - -Int_t ROOT::Deprecated::TFTP::RenameFile(const char *file1, const char *file2) const -{ - if (!IsOpen()) return -1; - - if (!file1 || !file2 || !*file1 || !*file2) { - Error("RenameFile", "illegal file names specified"); - return -1; - } - - if (fSocket->Send(Form("%s %s", file1, file2), kROOTD_MV) < 0) { - Error("RenameFile", "error sending kROOTD_MV command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("RenameFile", "error receiving mv confirmation"); - return -1; - } - - Info("RenameFile", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Delete a remote file. Anonymous users may not delete files. -/// Returns 0 in case of success and -1 in case of failure. - -Int_t ROOT::Deprecated::TFTP::DeleteFile(const char *file) const -{ - if (!IsOpen()) return -1; - - if (!file || !*file) { - Error("DeleteFile", "illegal file name specified"); - return -1; - } - - if (fSocket->Send(Form("%s", file), kROOTD_RM) < 0) { - Error("DeleteFile", "error sending kROOTD_RM command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("DeleteFile", "error receiving rm confirmation"); - return -1; - } - - Info("DeleteFile", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Change permissions of a remote file. Anonymous users may not -/// chnage permissions. Returns 0 in case of success and -1 in case -/// of failure. - -Int_t ROOT::Deprecated::TFTP::ChangePermission(const char *file, Int_t mode) const -{ - if (!IsOpen()) return -1; - - if (!file || !*file) { - Error("ChangePermission", "illegal file name specified"); - return -1; - } - - if (fSocket->Send(Form("%s %d", file, mode), kROOTD_CHMOD) < 0) { - Error("ChangePermission", "error sending kROOTD_CHMOD command"); - return -1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("ChangePermission", "error receiving chmod confirmation"); - return -1; - } - - Info("ChangePermission", "%s", mess); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close ftp connection. Returns 0 in case of success and -1 in case of -/// failure. - -Int_t ROOT::Deprecated::TFTP::Close() -{ - if (!IsOpen()) return -1; - - if (fSocket->Send(kROOTD_CLOSE) < 0) { - Error("Close", "error sending kROOTD_CLOSE command"); - return -1; - } - - // Ask for remote shutdown - if (fProtocol > 6) - fSocket->Send(kROOTD_BYE); - - // Remove from the list of Sockets - { - R__LOCKGUARD(gROOTMutex); - gROOT->GetListOfSockets()->Remove(this); - } - - // Delete socket here - SafeDelete(fSocket); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Open a directory via rootd. -/// Returns kTRUE in case of success. -/// Returns kFALSE in case of error. - -Bool_t ROOT::Deprecated::TFTP::OpenDirectory(const char *dir, Bool_t print) -{ - fDir = kFALSE; - - if (!IsOpen()) return fDir; - - if (fProtocol < 12) { - Error("OpenDirectory", "call not supported by remote rootd"); - return fDir; - } - - if (!dir || !*dir) { - Error("OpenDirectory", "illegal directory name specified"); - return fDir; - } - - if (fSocket->Send(Form("%s", dir), kROOTD_OPENDIR) < 0) { - Error("OpenDirectory", "error sending kROOTD_OPENDIR command"); - return fDir; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("OpenDirectory", "error receiving opendir confirmation"); - return fDir; - } - - if (print) - Info("OpenDirectory", "%s", mess); - - if (!strncmp(mess,"OK:",3)) { - fDir = kTRUE; - return fDir; - } - return fDir; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Free a remotely open directory via rootd. - -void ROOT::Deprecated::TFTP::FreeDirectory(Bool_t print) -{ - if (!IsOpen() || !fDir) return; - - if (fProtocol < 12) { - Error("FreeDirectory", "call not supported by remote rootd"); - return; - } - - if (fSocket->Send(kROOTD_FREEDIR) < 0) { - Error("FreeDirectory", "error sending kROOTD_FREEDIR command"); - return; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("FreeDirectory", "error receiving freedir confirmation"); - return; - } - - if (print) - Info("FreeDirectory", "%s", mess); - - return; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get directory entry via rootd. -/// Returns 0 in case no more entries or in case of error. - -const char *ROOT::Deprecated::TFTP::GetDirEntry(Bool_t print) -{ - static char dirent[1024] = {0}; - - if (!IsOpen() || !fDir) return 0; - - if (fProtocol < 12) { - Error("GetDirEntry", "call not supported by remote rootd"); - return 0; - } - - if (fSocket->Send(kROOTD_DIRENTRY) < 0) { - Error("GetDirEntry", "error sending kROOTD_DIRENTRY command"); - return 0; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("GetDirEntry", "error receiving dir entry confirmation"); - return 0; - } - - if (print) - Info("GetDirEntry", "%s", mess); - - if (!strncmp(mess,"OK:",3)) { - strlcpy(dirent,mess+3, sizeof(dirent)); - return (const char *)dirent; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get info about a file. Info is returned in the form of a FileStat_t -/// structure (see TSystem.h). -/// The function returns 0 in case of success and 1 if the file could -/// not be stat'ed. - -Int_t ROOT::Deprecated::TFTP::GetPathInfo(const char *path, FileStat_t &buf, Bool_t print) -{ - TUrl url(path); - - if (!IsOpen()) return 1; - - if (fProtocol < 12) { - Error("GetPathInfo", "call not supported by remote rootd"); - return 1; - } - - if (!path || !*path) { - Error("GetPathInfo", "illegal path name specified"); - return 1; - } - - if (fSocket->Send(Form("%s", path), kROOTD_FSTAT) < 0) { - Error("GetPathInfo", "error sending kROOTD_FSTAT command"); - return 1; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("GetPathInfo", "error receiving fstat confirmation"); - return 1; - } - if (print) - Info("GetPathInfo", "%s", mess); - - Int_t mode, uid, gid, islink; - Long_t id, flags, dev, ino, mtime; - Long64_t size; - if (fProtocol > 12) { -#ifdef R__WIN32 - sscanf(mess, "%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode, - &uid, &gid, &size, &mtime, &islink); -#else - sscanf(mess, "%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode, - &uid, &gid, &size, &mtime, &islink); -#endif - if (dev == -1) - return 1; - buf.fDev = dev; - buf.fIno = ino; - buf.fMode = mode; - buf.fUid = uid; - buf.fGid = gid; - buf.fSize = size; - buf.fMtime = mtime; - buf.fIsLink = (islink == 1); - } else { -#ifdef R__WIN32 - sscanf(mess, "%ld %I64d %ld %ld", &id, &size, &flags, &mtime); -#else - sscanf(mess, "%ld %lld %ld %ld", &id, &size, &flags, &mtime); -#endif - if (id == -1) - return 1; - buf.fDev = (id >> 24); - buf.fIno = (id & 0x00FFFFFF); - if (flags == 0) - buf.fMode = kS_IFREG; - if (flags & 1) - buf.fMode = (kS_IFREG|kS_IXUSR|kS_IXGRP|kS_IXOTH); - if (flags & 2) - buf.fMode = kS_IFDIR; - if (flags & 4) - buf.fMode = kS_IFSOCK; - buf.fSize = size; - buf.fMtime = mtime; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns kFALSE if one can access a file using the specified access mode. -/// Mode is the same as for the Unix access(2) function. -/// Attention, bizarre convention of return value!! - -Bool_t ROOT::Deprecated::TFTP::AccessPathName(const char *path, EAccessMode mode, Bool_t print) -{ - if (!IsOpen()) return kTRUE; - - if (fProtocol < 12) { - Error("AccessPathName", "call not supported by remote rootd"); - return kTRUE; - } - - if (!path || !*path) { - Error("AccessPathName", "illegal path name specified"); - return kTRUE; - } - - if (fSocket->Send(Form("%s %d", path, mode), kROOTD_ACCESS) < 0) { - Error("AccessPathName", "error sending kROOTD_ACCESS command"); - return kTRUE; - } - - Int_t what; - char mess[1024]; - - if (fSocket->Recv(mess, sizeof(mess), what) < 0) { - Error("AccessPathName", "error receiving access confirmation"); - return kTRUE; - } - if (print) - Info("AccessPathName", "%s", mess); - - if (!strncmp(mess,"OK",2)) - return kFALSE; - else - return kTRUE; -} diff --git a/net/net/src/TGrid.cxx b/net/net/src/TGrid.cxx deleted file mode 100644 index a049bc53bc6c4..0000000000000 --- a/net/net/src/TGrid.cxx +++ /dev/null @@ -1,77 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fons Rademakers 3/1/2002 - -/************************************************************************* - * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGrid // -// // -// Abstract base class defining interface to common GRID services. // -// // -// To open a connection to a GRID use the static method Connect(). // -// The argument of Connect() is of the form: // -// [://][:], e.g. alien://alice.cern.ch // -// Depending on the specified an appropriate plugin library // -// will be loaded which will provide the real interface. // -// // -// Related classes are TGridResult. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGrid.h" -#include "TROOT.h" -#include "TPluginManager.h" -#include "TError.h" - -ROOT::Deprecated::TGrid *ROOT::Deprecated::gGrid = 0; -ROOT::Deprecated::TGrid *&gGrid = ROOT::Deprecated::gGrid; - - - -//////////////////////////////////////////////////////////////////////////////// -/// The grid should be of the form: `://[:]`, -/// e.g.: alien://alice.cern.ch -/// The uid is the username and pw the password that should be used for -/// the connection. Depending on the `` the shared library (plugin) -/// for the selected system will be loaded. When the connection could not -/// be opened 0 is returned. For AliEn the supported options are: -/// -domain=`` -/// -debug=`` -/// Example: "-domain=cern.ch -debug=5" - -ROOT::Deprecated::TGrid * -ROOT::Deprecated::TGrid::Connect(const char *grid, const char *uid, const char *pw, const char *options) -{ - TPluginHandler *h; - TGrid *g = 0; - - if (!grid) { - ::Error("TGrid::Connect", "no grid specified"); - return 0; - } - if (!uid) - uid = ""; - if (!pw) - pw = ""; - if (!options) - options = ""; - - if ((h = gROOT->GetPluginManager()->FindHandler("TGrid", grid))) { - if (h->LoadPlugin() == -1) { - ::Error("TGrid::Connect", "Loading Plugin failed"); - return 0; - } - g = (TGrid *) h->ExecPlugin(4, grid, uid, pw, options); - } else { - ::Error("TGrid::Connect", "Could not find plugin to handle TGrid"); - } - - return g; -} diff --git a/net/net/src/TGridJDL.cxx b/net/net/src/TGridJDL.cxx deleted file mode 100644 index c573221a0ecf2..0000000000000 --- a/net/net/src/TGridJDL.cxx +++ /dev/null @@ -1,245 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 28/9/2004 -// Jancurova.lucia@cern.ch Slovakia 29/9/2008 - -/************************************************************************* - * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJDL // -// // -// Abstract base class to generate JDL files for job submission to the // -// Grid. // -// // -// Related classes are TGLiteJDL. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGridJDL.h" -#include "TObjString.h" -#include "Riostream.h" - - - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup. - -ROOT::Deprecated::TGridJDL::~TGridJDL() -{ - Clear(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Clears the JDL information. - -void ROOT::Deprecated::TGridJDL::Clear(const Option_t*) -{ - fMap.DeleteAll(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Sets a value. If the entry already exists the old one is replaced. - -void ROOT::Deprecated::TGridJDL::SetValue(const char *key, const char *value) -{ - TObject *object = fMap.FindObject(key); - TPair *pair = dynamic_cast(object); - if (pair) { - TObject *oldObject = pair->Key(); - if (oldObject) { - TObject *oldValue = pair->Value(); - - fMap.Remove(oldObject); - delete oldObject; - oldObject = 0; - - if (oldValue) { - delete oldValue; - oldValue = 0; - } - } - } - - fMap.Add(new TObjString(key), new TObjString(value)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the value corresponding to the provided key. Return 0 in case -/// key is not found. - -const char *ROOT::Deprecated::TGridJDL::GetValue(const char *key) -{ - if (!key) - return 0; - - TObject *object = fMap.FindObject(key); - if (!object) - return 0; - - TPair *pair = dynamic_cast(object); - if (!pair) - return 0; - - TObject *value = pair->Value(); - if (!value) - return 0; - - TObjString *string = dynamic_cast(value); - if (!string) - return 0; - - return string->GetName(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Sets a value. If the entry already exists the old one is replaced. - -void ROOT::Deprecated::TGridJDL::SetDescription(const char *key, const char* description) -{ - TObject *object = fDescriptionMap.FindObject(key); - TPair *pair = dynamic_cast(object); - if (pair) { - TObject *oldObject = pair->Key(); - if (oldObject) { - TObject *oldValue = pair->Value(); - - fDescriptionMap.Remove(oldObject); - delete oldObject; - oldObject = 0; - - if (oldValue) { - delete oldValue; - oldValue = 0; - } - } - } - - fDescriptionMap.Add(new TObjString(key), new TObjString(description)); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the value corresponding to the provided key. Return 0 in case -/// key is not found. - -const char *ROOT::Deprecated::TGridJDL::GetDescription(const char *key) -{ - if (!key) - return 0; - - TObject *object = fDescriptionMap.FindObject(key); - if (!object) - return 0; - - TPair *pair = dynamic_cast(object); - if (!pair) - return 0; - - TObject *value = pair->Value(); - if (!value) - return 0; - - TObjString *string = dynamic_cast(value); - if (!string) - return 0; - - return string->GetName(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Adds quotes to the provided string. -/// E.g. Value --> "Value" - -TString ROOT::Deprecated::TGridJDL::AddQuotes(const char *value) -{ - TString temp = TString("\""); - temp += value; - temp += "\""; - - return temp; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Adds a value to a key value which hosts a set of values. -/// E.g. InputSandbox: {"file1","file2"} - -void ROOT::Deprecated::TGridJDL::AddToSet(const char *key, const char *value) -{ - const char *oldValue = GetValue(key); - TString newString; - if (oldValue) - newString = oldValue; - if (newString.IsNull()) { - newString = "{"; - } else { - newString.Remove(newString.Length()-1); - newString += ","; - } - - newString += AddQuotes(value); - newString += "}"; - - SetValue(key, newString); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Adds a value to a key value which hosts a set of values. -/// E.g. InputSandbox: {"file1","file2"} - -void ROOT::Deprecated::TGridJDL::AddToSetDescription(const char *key, const char *description) -{ - const char *oldValue = GetDescription(key); - TString newString; - if (oldValue) - newString = oldValue; - newString += description; - - SetDescription(key, newString); -} -//////////////////////////////////////////////////////////////////////////////// -/// Generates the JDL snippet. - -TString ROOT::Deprecated::TGridJDL::Generate() -{ - TString output(""); - - TIter next(&fMap); - TIter nextDescription(&fDescriptionMap); - TObject *object = 0; - TObject *objectD = 0; - while ((object = next())) { - TObjString *key = dynamic_cast(object); - if (key) { - TObject *value = fMap.GetValue(object); - TObjString *valueobj = dynamic_cast(value); - - if (valueobj) { - nextDescription.Reset(); - while ((objectD = nextDescription())) { - TObjString *keyD = dynamic_cast(objectD); - if (keyD) { - TObject *valueD = fDescriptionMap.GetValue(objectD); - TObjString *valueobjD = dynamic_cast(valueD); - if (valueobjD && !strcmp(key->GetName(), keyD->GetName())){ - //Info("",Form("%s %s",key->GetString().Data(),keyD->GetString().Data())); - output += "# "; - output += valueobjD->GetName(); - output += "\n"; - } - } - } - output += key->GetName(); - output += " = "; - output += valueobj->GetName(); - output += ";\n\n"; - } - } - } - - return output; -} diff --git a/net/net/src/TGridJob.cxx b/net/net/src/TGridJob.cxx deleted file mode 100644 index 714bc442db0d5..0000000000000 --- a/net/net/src/TGridJob.cxx +++ /dev/null @@ -1,34 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 06/10/2004 - -/************************************************************************* - * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJob // -// // -// Abstract base class defining interface to a GRID job. // -// // -// Related classes are TGridJobStatus. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGridJob.h" - - - -//////////////////////////////////////////////////////////////////////////////// -/// Must be implemented by actual GRID job implementation. Returns -1 in -/// case of error, 0 otherwise. - -Int_t ROOT::Deprecated::TGridJob::GetOutputSandbox(const char *, Option_t *) -{ - MayNotUse("GetOutputSandbox"); - return -1; -} diff --git a/net/net/src/TGridJobStatus.cxx b/net/net/src/TGridJobStatus.cxx deleted file mode 100644 index c7a3aa7483541..0000000000000 --- a/net/net/src/TGridJobStatus.cxx +++ /dev/null @@ -1,22 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Jan Fiete Grosse-Oetringhaus 06/10/2004 - -/************************************************************************* - * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJobStatus // -// // -// Abstract base class containing the status of a Grid job. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGridJobStatus.h" - - diff --git a/net/net/src/TGridJobStatusList.cxx b/net/net/src/TGridJobStatusList.cxx deleted file mode 100644 index d7e2d30d33d1d..0000000000000 --- a/net/net/src/TGridJobStatusList.cxx +++ /dev/null @@ -1,23 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Andreas-Joachim Peters 10/12/2006 - -/************************************************************************* - * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGridJobStatusList // -// // -// Abstract base class defining a list of GRID job status // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGridJobStatusList.h" - -ROOT::Deprecated::TGridJobStatusList *ROOT::Deprecated::gGridJobStatusList = 0; -ROOT::Deprecated::TGridJobStatusList *&gGridJobStatusList = ROOT::Deprecated::gGridJobStatusList; diff --git a/net/net/src/TGridResult.cxx b/net/net/src/TGridResult.cxx deleted file mode 100644 index 6a39822002938..0000000000000 --- a/net/net/src/TGridResult.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fons Rademakers 23/5/2002 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TGridResult // -// // -// Abstract base class defining interface to a GRID result. // -// Objects of this class are created by TGrid methods. // -// // -// Related classes are TGrid. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TGridResult.h" - diff --git a/net/net/src/TNetFile.cxx b/net/net/src/TNetFile.cxx deleted file mode 100644 index 7a2a89c84a693..0000000000000 --- a/net/net/src/TNetFile.cxx +++ /dev/null @@ -1,1163 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fons Rademakers 14/08/97 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -/** -\file TNetFile.cxx -\class TNetFile -\ingroup IO - -A TNetFile is like a normal TFile except that it reads and writes -its data via a rootd server (for more on the rootd daemon see the -source files in `root/rootd/src/`). TNetFile file names are in -standard URL format with protocol "root" or "roots". The following -are valid TNetFile URL's: -- `root://hpbrun.cern.ch/root/hsimple.root` -- `root://pcna49a:5151/~na49/data/run821.root` -- `root://pcna49d.cern.ch:5050//v1/data/run810.root` - -The only difference with the well known httpd URL's is that the root -of the remote file tree is the user's home directory. Therefore an -absolute pathname requires a // after the host or port specifier -(see last example). Further the expansion of the standard shell -characters, like ~, $, .., are handled as expected. -TNetFile (actually TUrl) uses 1094 as default port for rootd. - -Connecting to a rootd requires the remote user id and password. -TNetFile allows three ways for you to provide your login: - Setting it globally via the static functions: -1. TAuthenticate::SetGlobalUser() and TAuthenticate::SetGlobalPasswd() -2. Getting it from the `~/.netrc` file (same file as used by ftp) -3. Command line prompt -The different methods will be tried in the order given above. -On machines with AFS rootd will authenticate using AFS (if it was -compiled with AFS support). - -If the protocol is specified as "rootk" kerberos5 will be used for -authentication. - -The rootd daemon lives in the directory `$ROOTSYS/bin`. It can be -started either via inetd or by hand from the command line (no need -to be super user). -**/ - -#include - -#include "Bytes.h" -#include "NetErrors.h" -#include "TApplication.h" -#include "TEnv.h" -#include "TNetFile.h" -#include "TPSocket.h" -#include "TROOT.h" -#include "TSysEvtHandler.h" -#include "TSystem.h" -#include "TTimeStamp.h" -#include "TVirtualPerfStats.h" - -// fgClientProtocol is now in TAuthenticate - - -//////////////////////////////////////////////////////////////////////////////// -/// Create a TNetFile object. This is actually done inside Create(), so -/// for a description of the options and other arguments see Create(). -/// Normally a TNetFile is created via TFile::Open(). - -ROOT::Deprecated::TNetFile::TNetFile(const char *url, Option_t *option, const char *ftitle, Int_t compress, - Int_t netopt) - : TFile(url, strstr(option, "_WITHOUT_GLOBALREGISTRATION") != nullptr ? "NET_WITHOUT_GLOBALREGISTRATION" : "NET", - ftitle, compress), - fEndpointUrl(url) -{ - fSocket = 0; - Create(url, option, netopt); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a TNetFile object. To be used by derived classes, that need -/// to initialize the TFile base class but not open a connection at this -/// moment. - -ROOT::Deprecated::TNetFile::TNetFile(const char *url, const char *ftitle, Int_t compress, Bool_t) - : TFile(url, "NET", ftitle, compress), fEndpointUrl(url) -{ - fSocket = 0; - fProtocol = 0; - fErrorCode = 0; - fNetopt = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// TNetFile dtor. Send close message and close socket. - -ROOT::Deprecated::TNetFile::~TNetFile() -{ - Close(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Open a remote file. Requires fOption to be set correctly. - -Int_t ROOT::Deprecated::TNetFile::SysOpen(const char * /*file*/, Int_t /*flags*/, UInt_t /*mode*/) -{ - if (!fSocket) { - - Create(fUrl.GetUrl(), fOption, fNetopt); - if (!fSocket) return -1; - - } else { - - if (fProtocol > 15) { - fSocket->Send(Form("%s %s", fUrl.GetFile(), ToLower(fOption).Data()), - kROOTD_OPEN); - } else { - // Old daemon versions expect an additional slash at beginning - fSocket->Send(Form("/%s %s", fUrl.GetFile(), ToLower(fOption).Data()), - kROOTD_OPEN); - } - - EMessageTypes kind; - int stat; - Recv(stat, kind); - - if (kind == kROOTD_ERR) { - PrintError("SysOpen", stat); - return -1; - } - } - - // This means ok for net files - return -2; // set as fD in ReOpen -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close currently open file. - -Int_t ROOT::Deprecated::TNetFile::SysClose(Int_t /*fd*/) -{ - if (fSocket) - fSocket->Send(kROOTD_CLOSE); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return file stat information. The interface and return value is -/// identical to TSystem::GetPathInfo(). - -Int_t ROOT::Deprecated::TNetFile::SysStat(Int_t, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) -{ - if (fProtocol < 3) return 1; - - if (!fSocket) return 1; - - fSocket->Send(kROOTD_FSTAT); - - char msg[1024]; - Int_t kind; - fSocket->Recv(msg, sizeof(msg), kind); - - Int_t mode, uid, gid, islink; - Long_t dev, ino; - - if (fProtocol > 12) { -#ifdef R__WIN32 - sscanf(msg, "%ld %ld %d %d %d %I64d %ld %d", &dev, &ino, &mode, - &uid, &gid, size, modtime, &islink); -#else - sscanf(msg, "%ld %ld %d %d %d %lld %ld %d", &dev, &ino, &mode, - &uid, &gid, size, modtime, &islink); -#endif - if (dev == -1) - return 1; - if (id) - *id = (dev << 24) + ino; - if (flags) { - *flags = 0; - if (mode & (kS_IXUSR|kS_IXGRP|kS_IXOTH)) - *flags |= 1; - if (R_ISDIR(mode)) - *flags |= 2; - if (!R_ISREG(mode) && !R_ISDIR(mode)) - *flags |= 4; - } - } else { -#ifdef R__WIN32 - sscanf(msg, "%ld %I64d %ld %ld", id, size, flags, modtime); -#else - sscanf(msg, "%ld %lld %ld %ld", id, size, flags, modtime); -#endif - if (*id == -1) - return 1; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close remote file. - -void ROOT::Deprecated::TNetFile::Close(Option_t *opt) -{ - if (!fSocket) return; - - TFile::Close(opt); - - if (fProtocol > 6) - fSocket->Send(kROOTD_BYE); - - SafeDelete(fSocket); - - fD = -1; // so TFile::IsOpen() returns false when in TFile::~TFile -} - -//////////////////////////////////////////////////////////////////////////////// -/// Flush file to disk. - -void ROOT::Deprecated::TNetFile::Flush() -{ - FlushWriteCache(); - - if (fSocket && fWritable) - fSocket->Send(kROOTD_FLUSH); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Initialize a TNetFile object. - -void ROOT::Deprecated::TNetFile::Init(Bool_t create) -{ - Seek(0); - - TFile::Init(create); - fD = -2; // so TFile::IsOpen() returns true when in TFile::~TFile -} - -//////////////////////////////////////////////////////////////////////////////// -/// Retruns kTRUE if file is open, kFALSE otherwise. - -Bool_t ROOT::Deprecated::TNetFile::IsOpen() const -{ - return fSocket == 0 ? kFALSE : kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print some info about the net file. - -void ROOT::Deprecated::TNetFile::Print(Option_t *) const -{ - const char *fname = fUrl.GetFile(); - Printf("URL: %s", ((TUrl*)&fUrl)->GetUrl()); - Printf("Remote file: %s", &fname[1]); - Printf("Remote user: %s", fUser.Data()); - Printf("Title: %s", fTitle.Data()); - Printf("Option: %s", fOption.Data()); - Printf("Bytes written: %lld", fBytesWrite); - Printf("Bytes read: %lld", fBytesRead); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print error string depending on error code. - -void ROOT::Deprecated::TNetFile::PrintError(const char *where, Int_t err) -{ - fErrorCode = err; - Error(where, "%s", gRootdErrStr[err]); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Reopen a file with a different access mode, like from READ to -/// UPDATE or from NEW, CREATE, RECREATE, UPDATE to READ. Thus the -/// mode argument can be either "READ" or "UPDATE". The method returns -/// 0 in case the mode was successfully modified, 1 in case the mode -/// did not change (was already as requested or wrong input arguments) -/// and -1 in case of failure, in which case the file cannot be used -/// anymore. - -Int_t ROOT::Deprecated::TNetFile::ReOpen(Option_t *mode) -{ - if (fProtocol < 7) { - Error("ReOpen", "operation not supported by remote rootd (protocol = %d)", - fProtocol); - return 1; - } - - return TFile::ReOpen(mode); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte range from remote file via rootd daemon. -/// Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TNetFile::ReadBuffer(char *buf, Int_t len) -{ - if (!fSocket) return kTRUE; - if (len == 0) - return kFALSE; - - Bool_t result = kFALSE; - - Int_t st; - if ((st = ReadBufferViaCache(buf, len))) { - if (st == 2) - return kTRUE; - return kFALSE; - } - - if (gApplication && gApplication->GetSignalHandler()) - gApplication->GetSignalHandler()->Delay(); - - Double_t start = 0; - if (gPerfStats) start = TTimeStamp(); - - if (fSocket->Send(Form("%lld %d", fOffset, len), kROOTD_GET) < 0) { - Error("ReadBuffer", "error sending kROOTD_GET command"); - result = kTRUE; - goto end; - } - - Int_t stat, n; - EMessageTypes kind; - - fErrorCode = -1; - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - PrintError("ReadBuffer", stat); - result = kTRUE; - goto end; - } - - while ((n = fSocket->RecvRaw(buf, len)) < 0 && TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - - if (n != len) { - Error("ReadBuffer", "error receiving buffer of length %d, got %d", len, n); - result = kTRUE; - goto end; - } - - fOffset += len; - - fBytesRead += len; - fReadCalls++; -#ifdef R__WIN32 - SetFileBytesRead(GetFileBytesRead() + len); - SetFileReadCalls(GetFileReadCalls() + 1); -#else - fgBytesRead += len; - fgReadCalls++; -#endif - -end: - - if (gPerfStats) - gPerfStats->FileReadEvent(this, len, start); - - if (gApplication && gApplication->GetSignalHandler()) - gApplication->GetSignalHandler()->HandleDelayedSignal(); - - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte range from remote file via rootd daemon. -/// Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TNetFile::ReadBuffer(char *buf, Long64_t pos, Int_t len) -{ - SetOffset(pos); - return ReadBuffer(buf, len); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read a list of buffers given in pos[] and len[] and return it in a single -/// buffer. -/// Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TNetFile::ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) -{ - if (!fSocket) return kTRUE; - - // If it's an old version of the protocol try the default TFile::ReadBuffers - if (fProtocol < 17) - return TFile::ReadBuffers(buf, pos, len, nbuf); - - Int_t stat; - Int_t blockSize = 262144; //Let's say we transfer 256KB at the time - Bool_t result = kFALSE; - EMessageTypes kind; - TString data_buf; // buf to put the info - - if (gApplication && gApplication->GetSignalHandler()) - gApplication->GetSignalHandler()->Delay(); - - Double_t start = 0; - if (gPerfStats) start = TTimeStamp(); - - // Make the string with a list of offsets and lengths - Long64_t total_len = 0; - Long64_t actual_pos; - for(Int_t i = 0; i < nbuf; i++) { - data_buf += pos[i] + fArchiveOffset; - data_buf += "-"; - data_buf += len[i]; - data_buf += "/"; - total_len += len[i]; - } - - // Send the command with the length of the info and number of buffers - if (fSocket->Send(Form("%d %d %d", nbuf, data_buf.Length(), blockSize), - kROOTD_GETS) < 0) { - Error("ReadBuffers", "error sending kROOTD_GETS command"); - result = kTRUE; - goto end; - } - // Send buffer with the list of offsets and lengths - if (fSocket->SendRaw(data_buf, data_buf.Length()) < 0) { - Error("ReadBuffers", "error sending buffer"); - result = kTRUE; - goto end; - } - - fErrorCode = -1; - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - PrintError("ReadBuffers", stat); - result = kTRUE; - goto end; - } - - actual_pos = 0; - while (actual_pos < total_len) { - Long64_t left = total_len - actual_pos; - if (left > blockSize) - left = blockSize; - - Int_t n; - while ((n = fSocket->RecvRaw(buf + actual_pos, Int_t(left))) < 0 && - TSystem::GetErrno() == EINTR) - TSystem::ResetErrno(); - - if (n != Int_t(left)) { - Error("GetBuffers", "error receiving buffer of length %d, got %d", - Int_t(left), n); - result = kTRUE ; - goto end; - } - actual_pos += left; - } - - fBytesRead += total_len; - fReadCalls++; -#ifdef R__WIN32 - SetFileBytesRead(GetFileBytesRead() + total_len); - SetFileReadCalls(GetFileReadCalls() + 1); -#else - fgBytesRead += total_len; - fgReadCalls++; -#endif - -end: - - if (gPerfStats) - gPerfStats->FileReadEvent(this, total_len, start); - - if (gApplication && gApplication->GetSignalHandler()) - gApplication->GetSignalHandler()->HandleDelayedSignal(); - - // If found problems try the generic implementation - if (result) { - if (gDebug > 0) - Info("ReadBuffers", "Couldnt use the specific implementation, calling TFile::ReadBuffers"); - return TFile::ReadBuffers(buf, pos, len, nbuf); - } - - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Write specified byte range to remote file via rootd daemon. -/// Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TNetFile::WriteBuffer(const char *buf, Int_t len) -{ - if (!fSocket || !fWritable) return kTRUE; - - Bool_t result = kFALSE; - - Int_t st; - if ((st = WriteBufferViaCache(buf, len))) { - if (st == 2) - return kTRUE; - return kFALSE; - } - - gSystem->IgnoreInterrupt(); - - if (fSocket->Send(Form("%lld %d", fOffset, len), kROOTD_PUT) < 0) { - SetBit(kWriteError); - Error("WriteBuffer", "error sending kROOTD_PUT command"); - result = kTRUE; - goto end; - } - if (fSocket->SendRaw(buf, len) < 0) { - SetBit(kWriteError); - Error("WriteBuffer", "error sending buffer"); - result = kTRUE; - goto end; - } - - Int_t stat; - EMessageTypes kind; - - fErrorCode = -1; - if (Recv(stat, kind) < 0 || kind == kROOTD_ERR) { - SetBit(kWriteError); - PrintError("WriteBuffer", stat); - result = kTRUE; - goto end; - } - - fOffset += len; - - fBytesWrite += len; -#ifdef R__WIN32 - SetFileBytesWritten(GetFileBytesWritten() + len); -#else - fgBytesWrite += len; -#endif - -end: - gSystem->IgnoreInterrupt(kFALSE); - - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return status from rootd server and message kind. Returns -1 in -/// case of error otherwise 8 (sizeof 2 words, status and kind). - -Int_t ROOT::Deprecated::TNetFile::Recv(Int_t &status, EMessageTypes &kind) -{ - kind = kROOTD_ERR; - status = 0; - - if (!fSocket) return -1; - - Int_t what; - Int_t n = fSocket->Recv(status, what); - kind = (EMessageTypes) what; - return n; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set position from where to start reading. - -void ROOT::Deprecated::TNetFile::Seek(Long64_t offset, ERelativeTo pos) -{ - SetOffset(offset, pos); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Connect to remote rootd server. - -void ROOT::Deprecated::TNetFile::ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, - Int_t tcpwindowsize, Bool_t forceOpen, - Bool_t forceRead) -{ - TString fn = fUrl.GetFile(); - - // Create Authenticated socket - Int_t sSize = netopt < -1 ? -netopt : 1; - TString url(fUrl.GetProtocol()); - if (url.Contains("root")) { - url.Insert(4,"dp"); - } else { - url = "rootdp"; - } - url += TString(Form("://%s@%s:%d", - fUrl.GetUser(), fUrl.GetHost(), fUrl.GetPort())); - fSocket = ROOT::Deprecated::TSocketFriend::CreateAuthSocket(url, sSize, tcpwindowsize, fSocket, stat); - if (!fSocket || (fSocket && !ROOT::Deprecated::TSocketFriend::IsAuthenticated(*fSocket))) { - if (sSize > 1) - Error("TNetFile", "can't open %d-stream connection to rootd on " - "host %s at port %d", sSize, fUrl.GetHost(), fUrl.GetPort()); - else - Error("TNetFile", "can't open connection to rootd on " - "host %s at port %d", fUrl.GetHost(), fUrl.GetPort()); - *kind = kROOTD_ERR; - goto zombie; - } - - // Check if rootd supports new options - fProtocol = fSocket->GetRemoteProtocol(); - if (forceRead && fProtocol < 5) { - Warning("ConnectServer", "rootd does not support \"+read\" option"); - forceRead = kFALSE; - } - - // Open the file - if (fProtocol < 16) - // For backward compatibility we need to add a '/' at the beginning - fn.Insert(0,"/"); - if (forceOpen) - fSocket->Send(Form("%s %s", fn.Data(), - ToLower("f"+fOption).Data()), kROOTD_OPEN); - else if (forceRead) - fSocket->Send(Form("%s %s", fn.Data(), "+read"), kROOTD_OPEN); - else - fSocket->Send(Form("%s %s", fn.Data(), - ToLower(fOption).Data()), kROOTD_OPEN); - - EMessageTypes tmpkind; - int tmpstat; - Recv(tmpstat, tmpkind); - *stat = tmpstat; - *kind = tmpkind; - - return; - -zombie: - // error in file opening occurred, make this object a zombie - MakeZombie(); - SafeDelete(fSocket); - gDirectory = gROOT; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a NetFile object. A net file is the same as a TFile -/// except that it is being accessed via a rootd server. The url -/// argument must be of the form: root[k]://host.dom.ain/file.root. -/// When protocol is "rootk" try using kerberos5 authentication. -/// If the file specified in the URL does not exist, is not accessable -/// or can not be created the kZombie bit will be set in the TNetFile -/// object. Use IsZombie() to see if the file is accessable. -/// If the remote daemon thinks the file is still connected, while you are -/// sure this is not the case you can force open the file by preceding the -/// option argument with an "-", e.g.: "-recreate". Do this only -/// in cases when you are very sure nobody else is using the file. -/// To bypass the writelock on a file, to allow the reading of a file -/// that is being written by another process, explicitly specify the -/// "+read" option ("read" being the default option). -/// The netopt argument can be used to specify the size of the tcp window in -/// bytes (for more info see: http://www.psc.edu/networking/perf_tune.html). -/// The default and minimum tcp window size is 65535 bytes. -/// If netopt < -1 then |netopt| is the number of parallel sockets that will -/// be used to connect to rootd. This option should be used on fat pipes -/// (i.e. high bandwidth, high latency links). The ideal number of parallel -/// sockets depends on the bandwidth*delay product. Generally 5-7 is a good -/// number. -/// For a description of the option and other arguments see the TFile ctor. -/// The preferred interface to this constructor is via TFile::Open(). - -void ROOT::Deprecated::TNetFile::Create(const char * /*url*/, Option_t *option, Int_t netopt) -{ - Int_t tcpwindowsize = 65535; - - fErrorCode = -1; - fNetopt = netopt; - fOption = option; - - Bool_t forceOpen = kFALSE; - if (option[0] == '-') { - fOption = &option[1]; - forceOpen = kTRUE; - } - // accept 'f', like 'frecreate' still for backward compatibility - if (option[0] == 'F' || option[0] == 'f') { - fOption = &option[1]; - forceOpen = kTRUE; - } - - Bool_t forceRead = kFALSE; - if (!strcasecmp(option, "+read")) { - fOption = &option[1]; - forceRead = kTRUE; - } - - fOption.ToUpper(); - - if (fOption == "NEW") - fOption = "CREATE"; - - Bool_t create = (fOption == "CREATE") ? kTRUE : kFALSE; - Bool_t recreate = (fOption == "RECREATE") ? kTRUE : kFALSE; - Bool_t update = (fOption == "UPDATE") ? kTRUE : kFALSE; - if (!create && !recreate && !update) { - fOption = "READ"; - } - - if (!fUrl.IsValid()) { - Error("Create", "invalid URL specified: %s", fUrl.GetUrl()); - goto zombie; - } - - if (netopt > tcpwindowsize) - tcpwindowsize = netopt; - - // Open connection to remote rootd server - EMessageTypes kind; - Int_t stat; - ConnectServer(&stat, &kind, netopt, tcpwindowsize, forceOpen, forceRead); - if (gDebug > 2) Info("Create", "got from host %d %d", stat, kind); - - if (kind == kROOTD_ERR) { - PrintError("Create", stat); - Error("Create", "failing on file %s", fUrl.GetUrl()); - goto zombie; - } - - if (recreate) { - create = kTRUE; - fOption = "CREATE"; - } - - if (update && stat > 1) { - create = kTRUE; - stat = 1; - } - - if (stat == 1) - fWritable = kTRUE; - else - fWritable = kFALSE; - - Init(create); - return; - -zombie: - // error in file opening occurred, make this object a zombie - MakeZombie(); - SafeDelete(fSocket); - gDirectory = gROOT; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a NetFile object using an existing connection (socket s). -/// Provided for use in TNetXNGFile. -/// See: -/// TNetFile::Create(const char *url, Option_t *option, Int_t netopt) -/// for details about the arguments. - -void ROOT::Deprecated::TNetFile::Create(TSocket *s, Option_t *option, Int_t netopt) -{ - // Import socket - fSocket = s; - - // Create the connection - Create(s->GetUrl(), option, netopt); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return kTRUE if 'url' matches the coordinates of this file. -/// Check the full URL, including port and FQDN. - -Bool_t ROOT::Deprecated::TNetFile::Matches(const char *url) -{ - // Run standard check on fUrl, first - Bool_t rc = TFile::Matches(url); - if (rc) - // Ok, standard check enough - return kTRUE; - - // Check also endpoint URL - TUrl u(url); - if (!strcmp(u.GetFile(),fEndpointUrl.GetFile())) { - // Candidate info - TString fqdn = u.GetHostFQDN(); - - // Check ports - if (u.GetPort() == fEndpointUrl.GetPort()) { - TString fqdnref = fEndpointUrl.GetHostFQDN(); - if (fqdn == fqdnref) - // Ok, coordinates match - return kTRUE; - } - } - - // Default is not matching - return kFALSE; -} - -// -// TNetSystem: the directory handler for net files -// - -//////////////////////////////////////////////////////////////////////////////// -/// Create helper class that allows directory access via rootd. -/// Use ftpowner = TRUE (default) if this instance is responsible -/// for cleaning of the underlying TFTP connection; this allows -/// to have control on the order of the final cleaning. - -ROOT::Deprecated::TNetSystem::TNetSystem(Bool_t ftpowner) - : TSystem("-root", "Net file Helper System") -{ - // name must start with '-' to bypass the TSystem singleton check - SetName("root"); - - fDir = kFALSE; - fDirp = 0; - fFTP = 0; - fFTPOwner = ftpowner; - fUser = ""; - fHost = ""; - fPort = -1; - fIsLocal = kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create helper class that allows directory access via rootd. -/// Use ftpowner = TRUE (default) if this instance is responsible -/// for cleaning of the underlying TFTP connection; this allows -/// to have control on the order of the final cleaning. - -ROOT::Deprecated::TNetSystem::TNetSystem(const char *url, Bool_t ftpowner) - : TSystem("-root", "Net file Helper System") -{ - // name must start with '-' to bypass the TSystem singleton check - SetName("root"); - - fFTPOwner = ftpowner; - fIsLocal = kFALSE; - Create(url); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Parse and save coordinates of the remote entity (user, host, port, ...) - -void ROOT::Deprecated::TNetSystem::InitRemoteEntity(const char *url) -{ - TUrl turl(url); - - // Remote username: local as default - fUser = turl.GetUser(); - if (!fUser.Length()) { - UserGroup_t *u = gSystem->GetUserInfo(); - if (u) - fUser = u->fUser; - delete u; - } - - // Check and save the host FQDN ... - fHost = turl.GetHostFQDN(); - - // Remote port: the default should be 1094 because we are here - // only if the protocol is "root://" - fPort = turl.GetPort(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a TNetSystem object. - -void ROOT::Deprecated::TNetSystem::Create(const char *url, TSocket *sock) -{ - // If we got here protocol must be at least its short form "^root.*:" : - // make sure that it is in the full form to avoid problems in TFTP - TString surl(url); - if (!surl.Contains("://")) { - surl.Insert(surl.Index(":")+1,"//"); - } - TUrl turl(surl); - - fDir = kFALSE; - fDirp = 0; - fFTP = 0; - - // Check locality, taking into account possible prefixes - fLocalPrefix = ""; - fIsLocal = kFALSE; - // We may have been asked explicitly to go through the daemon - Bool_t forceRemote = gEnv->GetValue("Path.ForceRemote", 0); - TString opts = TUrl(url).GetOptions(); - if (opts.Contains("remote=1")) - forceRemote = kTRUE; - else if (opts.Contains("remote=0")) - forceRemote = kFALSE; - if (!forceRemote) { - if ((fIsLocal = TSystem::IsPathLocal(url))) { - fLocalPrefix = gEnv->GetValue("Path.Localroot",""); - // Nothing more to do - return; - } - } - - // Fill in user, host, port - InitRemoteEntity(surl); - - // Build a TFTP url - if (fHost.Length()) { - TString eurl = ""; - // First the protocol - if (strlen(turl.GetProtocol())) { - eurl = turl.GetProtocol(); - eurl += "://"; - } else - eurl = "root://"; - // Add user, if specified - if (strlen(turl.GetUser())) { - eurl += turl.GetUser(); - eurl += "@"; - } - // Add host - eurl += fHost; - // Add port - eurl += ":"; - eurl += turl.GetPort(); - - fFTP = new TFTP(eurl, 1, TFTP::kDfltWindowSize, sock); - if (fFTP && fFTP->IsOpen()) { - if (fFTP->GetSocket()->GetRemoteProtocol() < 12) { - Error("Create", - "remote daemon does not support 'system' functionality"); - fFTP->Close(); - delete fFTP; - } else { - fUser = ROOT::Deprecated::TSocketFriend::GetSecContext(*fFTP->GetSocket())->GetUser(); - fHost = ROOT::Deprecated::TSocketFriend::GetSecContext(*fFTP->GetSocket())->GetHost(); - // If responsible for the TFTP connection, remove it from the - // socket global list to avoid problems with double deletion - // at final cleanup - if (fFTPOwner) - gROOT->GetListOfSockets()->Remove(fFTP); - } - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor - -ROOT::Deprecated::TNetSystem::~TNetSystem() -{ - // Close FTP connection - if (fFTPOwner) { - if (fFTP) { - if (fFTP->IsOpen()) { - - // Close remote directory if still open - if (fDir) { - fFTP->FreeDirectory(kFALSE); - fDir = kFALSE; - } - fFTP->Close(); - } - delete fFTP; - } - } - fDirp = 0; - fFTP = 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Make a directory via rootd. - -Int_t ROOT::Deprecated::TNetSystem::MakeDirectory(const char *dir) -{ - // If local, use the local TSystem - if (fIsLocal) { - TString edir = TUrl(dir).GetFile(); - if (!fLocalPrefix.IsNull()) - edir.Insert(0, fLocalPrefix); - return gSystem->MakeDirectory(edir); - } - - if (fFTP && fFTP->IsOpen()) { - // Extract the directory name - TString edir = TUrl(dir).GetFile(); - return fFTP->MakeDirectory(edir,kFALSE); - } - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Open a directory and return an opaque pointer to a dir structure. -/// Returns nullptr in case of error. - -void *ROOT::Deprecated::TNetSystem::OpenDirectory(const char *dir) -{ - // If local, use the local TSystem - if (fIsLocal) { - TString edir = TUrl(dir).GetFile(); - if (!fLocalPrefix.IsNull()) - edir.Insert(0, fLocalPrefix); - return gSystem->OpenDirectory(edir); - } - - if (!fFTP || !fFTP->IsOpen()) - return nullptr; - - if (fDir) { - if (gDebug > 0) - Info("OpenDirectory", "a directory is already open: close it first"); - fFTP->FreeDirectory(kFALSE); - fDir = kFALSE; - } - - // Extract the directory name - TString edir = TUrl(dir).GetFile(); - - if (fFTP->OpenDirectory(edir,kFALSE)) { - fDir = kTRUE; - fDirp = (void *)&fDir; - return fDirp; - } else - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Free directory via rootd. - -void ROOT::Deprecated::TNetSystem::FreeDirectory(void *dirp) -{ - // If local, use the local TSystem - if (fIsLocal) { - gSystem->FreeDirectory(dirp); - return; - } - - if (dirp != fDirp) { - Error("FreeDirectory", "invalid directory pointer (should never happen)"); - return; - } - - if (fFTP && fFTP->IsOpen()) { - if (fDir) { - fFTP->FreeDirectory(kFALSE); - fDir = kFALSE; - fDirp = 0; - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get directory entry via rootd. Returns 0 in case no more entries. - -const char *ROOT::Deprecated::TNetSystem::GetDirEntry(void *dirp) -{ - // If local, use the local TSystem - if (fIsLocal) { - return gSystem->GetDirEntry(dirp); - } - - if (dirp != fDirp) { - Error("GetDirEntry", "invalid directory pointer (should never happen)"); - return 0; - } - - if (fFTP && fFTP->IsOpen() && fDir) { - return fFTP->GetDirEntry(kFALSE); - } - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get info about a file. Info is returned in the form of a FileStat_t -/// structure (see TSystem.h). -/// The function returns 0 in case of success and 1 if the file could -/// not be stat'ed. - -Int_t ROOT::Deprecated::TNetSystem::GetPathInfo(const char *path, FileStat_t &buf) -{ - // If local, use the local TSystem - if (fIsLocal) { - TString epath = TUrl(path).GetFile(); - if (!fLocalPrefix.IsNull()) - epath.Insert(0, fLocalPrefix); - return gSystem->GetPathInfo(epath, buf); - } - - if (fFTP && fFTP->IsOpen()) { - // Extract the directory name - TString epath = TUrl(path).GetFile(); - fFTP->GetPathInfo(epath, buf, kFALSE); - return 0; - } - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns FALSE if one can access a file using the specified access mode. -/// Mode is the same as for the Unix access(2) function. -/// Attention, bizarre convention of return value!! - -Bool_t ROOT::Deprecated::TNetSystem::AccessPathName(const char *path, EAccessMode mode) -{ - // If local, use the local TSystem - if (fIsLocal) { - TString epath = TUrl(path).GetFile(); - if (!fLocalPrefix.IsNull()) - epath.Insert(0, fLocalPrefix); - return gSystem->AccessPathName(epath, mode); - } - - if (fFTP && fFTP->IsOpen()) { - // Extract the directory name - TString epath = TUrl(path).GetFile(); - return fFTP->AccessPathName(epath, mode, kFALSE); - } - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check consistency of this helper with the one required -/// by 'path' or 'dirptr'. - -Bool_t ROOT::Deprecated::TNetSystem::ConsistentWith(const char *path, void *dirptr) -{ - // Standard check: only the protocol part of 'path' is required to match - Bool_t checkstd = TSystem::ConsistentWith(path, dirptr); - if (!checkstd) return kFALSE; - - // Require match of 'user' and 'host' - Bool_t checknet = path ? kFALSE : kTRUE; - if (path && strlen(path)) { - - // Get user name - TUrl url(path); - TString user = url.GetUser(); - if (user.IsNull() && !fUser.IsNull()) { - UserGroup_t *u = gSystem->GetUserInfo(); - if (u) - user = u->fUser; - delete u; - } - - // Get host name - TString host = url.GetHostFQDN(); - - // Get port - Int_t port = url.GetPort(); - if (gDebug > 1) - Info("ConsistentWith", "fUser:'%s' (%s), fHost:'%s' (%s), fPort:%d (%d)", - fUser.Data(), user.Data(), fHost.Data(), host.Data(), - fPort, port); - - if (user == fUser && host == fHost && port == fPort) - checknet = kTRUE; - } - - return (checkstd && checknet); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Remove a path - -Int_t ROOT::Deprecated::TNetSystem::Unlink(const char *path) -{ - // If local, use the local TSystem - if (fIsLocal) { - TString epath = TUrl(path).GetFile(); - if (!fLocalPrefix.IsNull()) - epath.Insert(0, fLocalPrefix); - return gSystem->Unlink(epath); - } - - // Not implemented for rootd - Warning("Unlink", "functionality not implemented - ignored (path: %s)", path); - return -1; -} diff --git a/net/net/src/TNetFileStager.cxx b/net/net/src/TNetFileStager.cxx deleted file mode 100644 index 3cfc8c9df5f58..0000000000000 --- a/net/net/src/TNetFileStager.cxx +++ /dev/null @@ -1,135 +0,0 @@ -// @(#)root/net:$Id$ -// Author: G. Ganis Feb 2011 - -/************************************************************************* - * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TNetFileStager // -// // -// TFileStager implementation for a 'rootd' backend. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TError.h" -#include "TUrl.h" -#include "TNetFile.h" -#include "TNetFileStager.h" - -//////////////////////////////////////////////////////////////////////////////// -/// Constructor. Init a TNetSystem instance to the remote rootd. - -ROOT::Deprecated::TNetFileStager::TNetFileStager(const char *url) : TFileStager("net") -{ - fSystem = 0; - if (url && strlen(url) > 0) { - GetPrefix(url, fPrefix); - - fSystem = new TNetSystem(fPrefix); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor - -ROOT::Deprecated::TNetFileStager::~TNetFileStager() -{ - SafeDelete(fSystem); - fPrefix = ""; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if the file defined by 'path' is ready to be used. - -Bool_t ROOT::Deprecated::TNetFileStager::IsStaged(const char *path) -{ - if (!IsValid()) { - GetPrefix(path, fPrefix); - fSystem = new TNetSystem(path); - } - - if (IsValid()) { - TString p(path); - if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix); - return (fSystem->AccessPathName(p, kReadPermission) ? kFALSE : kTRUE); - } - - // Failure - Warning("IsStaged","TNetSystem not initialized"); - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Isolate prefix in url - -void ROOT::Deprecated::TNetFileStager::GetPrefix(const char *url, TString &pfx) -{ - if (gDebug > 1) - ::Info("TNetFileStager::GetPrefix", "enter: %s", url); - - TUrl u(url); - pfx = TString::Format("%s://", u.GetProtocol()); - if (strlen(u.GetUser()) > 0) - pfx += TString::Format("%s@", u.GetUser()); - pfx += u.GetHost(); - if (u.GetPort() != TUrl("root://host").GetPort()) - pfx += TString::Format(":%d", u.GetPort()); - pfx += "/"; - - if (gDebug > 1) - ::Info("TNetFileStager::GetPrefix", "found prefix: %s", pfx.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Print basic info about this stager - -void ROOT::Deprecated::TNetFileStager::Print(Option_t *) const -{ - Printf("+++ stager: %s %s", GetName(), fPrefix.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get actual end-point url for a path -/// Returns 0 in case of success and 1 if any error occurred - -Int_t ROOT::Deprecated::TNetFileStager::Locate(const char *path, TString &eurl) -{ - if (!IsValid()) { - GetPrefix(path, fPrefix); - fSystem = new TNetSystem(path); - } - - if (IsValid()) { - TString p(path); - if (!p.BeginsWith(fPrefix)) p.Insert(0, fPrefix); - if (!fSystem->AccessPathName(p, kReadPermission)) { - eurl = p; - return 0; - } - } - - // Unable to initialize TNetSystem or file does not exist - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns kTRUE if stager 's' is compatible with current stager. -/// Avoids multiple instantiations of the potentially the same TNetSystem. - -Bool_t ROOT::Deprecated::TNetFileStager::Matches(const char *s) -{ - if (IsValid()) { - TString pfx; - GetPrefix(s, pfx); - return ((fPrefix == pfx) ? kTRUE : kFALSE); - } - - // Not valid - return kFALSE; -} diff --git a/net/net/src/TS3HTTPRequest.cxx b/net/net/src/TS3HTTPRequest.cxx deleted file mode 100644 index ca2cf28b98b9b..0000000000000 --- a/net/net/src/TS3HTTPRequest.cxx +++ /dev/null @@ -1,270 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fabio Hernandez 30/01/2013 -// based on an initial version by Marcelo Sousa (class THTTPMessage) - -/************************************************************************* - * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TS3HTTPRequest // -// // -// An object of this class represents an HTTP request extended to be // -// compatible with Amazon's S3 protocol. // -// Specifically, such a request contains an 'Authorization' header with // -// information used by the S3 server for authenticating this request. // -// The authentication information is computed based on a pair of access // -// key and secret key which are both provided to the user by the S3 // -// service provider (e.g. Amazon, Google, etc.). // -// The secret key is used to compute a signature of selected fields in // -// the request. The algorithm for computing the signature is documented // -// in: // -// // -// Google storage: // -// http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html#authentication -// // -// Amazon: // -// http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_Authentication2.html -// // -////////////////////////////////////////////////////////////////////////// - -#include "TS3HTTPRequest.h" -#include "TBase64.h" -#if defined(MAC_OS_X_VERSION_10_7) -#include -#define SHA_DIGEST_LENGTH 20 -#else -#include -#include -#include -#include -#include -#endif - -#include -#include -#include - - -//////////////////////////////////////////////////////////////////////////////// - -ROOT::Deprecated::TS3HTTPRequest::TS3HTTPRequest() - : fAuthType(kNoAuth), fHost("NoHost") -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Default constructor - -ROOT::Deprecated::TS3HTTPRequest::TS3HTTPRequest(EHTTPVerb httpVerb, const TString& host, - const TString& bucket, const TString& objectKey, EAuthType authType, - const TString& accessKey, const TString& secretKey) -{ - fVerb = httpVerb; - fHost = host; - fBucket = bucket; - fObjectKey = objectKey; - fAuthType = authType; - fAccessKey = accessKey; - fSecretKey = secretKey; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Copy constructor - -ROOT::Deprecated::TS3HTTPRequest::TS3HTTPRequest(const TS3HTTPRequest& r) - : TObject(r) -{ - fVerb = r.fVerb; - fHost = r.fHost; - fBucket = r.fBucket; - fObjectKey = r.fObjectKey; - fAuthType = r.fAuthType; - fAccessKey = r.fAccessKey; - fSecretKey = r.fSecretKey; - fTimeStamp = r.fTimeStamp; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns this request's signature - -TString ROOT::Deprecated::TS3HTTPRequest::ComputeSignature(TS3HTTPRequest::EHTTPVerb httpVerb) const -{ - // Please note, the order of the fields used for computing - // the signature is important. Make sure that the changes you - // make are compatible with the reference documentation. - // - // Refs: - // AMAZON http://awsdocs.s3.amazonaws.com/S3/latest/s3-qrc.pdf - // GOOGLE: http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html#authentication - - TString toSign = TString::Format("%s\n\n\n%s\n", // empty Content-MD5 and Content-Type - (const char*)HTTPVerbToTString(httpVerb), - (const char*)fTimeStamp); - if (fAuthType == kGoogle) { - // Must use API version 1. Google Storage API v2 only - // accepts OAuth authentication. - // This header is not strictly needed but if used for computing - // the signature, the request must contain it as a header - // (see method MakeAuthHeader) - // Ref: https://developers.google.com/storage/docs/reference/v1/apiversion1 - toSign += "x-goog-api-version:1\n"; // Lowercase, no spaces around ':' - } - - if (fAuthType == kAmazon) { - if (!fSessionToken.IsNull()) { - toSign += "x-amz-security-token:" + fSessionToken + "\n"; - } - } - - toSign += "/" + fBucket + fObjectKey; - - unsigned char digest[SHA_DIGEST_LENGTH] = {0}; -#if defined(MAC_OS_X_VERSION_10_7) - CCHmac(kCCHmacAlgSHA1, fSecretKey.Data(), fSecretKey.Length() , (unsigned char *)toSign.Data(), toSign.Length(), digest); -#else - unsigned int *sd = NULL; - HMAC(EVP_sha1(), fSecretKey.Data(), fSecretKey.Length() , (unsigned char *)toSign.Data(), toSign.Length(), digest, sd); -#endif - - return TBase64::Encode((const char *)digest, SHA_DIGEST_LENGTH); -} - -//////////////////////////////////////////////////////////////////////////////// - -TString ROOT::Deprecated::TS3HTTPRequest::HTTPVerbToTString(TS3HTTPRequest::EHTTPVerb httpVerb) const -{ - switch (httpVerb) { - case kGET: return TString("GET"); - case kPOST: return TString("POST"); - case kPUT: return TString("PUT"); - case kDELETE: return TString("DELETE"); - case kHEAD: return TString("HEAD"); - case kCOPY: return TString("COPY"); - default: return TString(""); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Sets this request's time stamp according to: -/// http://code.google.com/apis/storage/docs/reference-headers.html#date - -ROOT::Deprecated::TS3HTTPRequest& ROOT::Deprecated::TS3HTTPRequest::SetTimeStamp() -{ - time_t now = time(NULL); - char result[128]; - struct tm dateFormat; -#ifdef R__WIN32 - gmtime_s(&dateFormat, &now); - strftime(result, sizeof(result), "%a, %d %b %Y %H:%M:%S GMT", &dateFormat); -#else - strftime(result, sizeof(result), "%a, %d %b %Y %H:%M:%S GMT", - gmtime_r(&now, &dateFormat)); -#endif - fTimeStamp = result; - return *this; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the first line of a HTTP request for this object. Note that since -/// we don't use the virtual host syntax which is supported by Amazon, we -/// must include the bucket name in thr resource. For example, we don't use -/// http://mybucket.s3.amazonaws.com/path/to/my/file but instead -/// http://s3.amazonaws.com/mybucket/path/to/my/file so the HTTP request -/// will be of the form "GET /mybucket/path/to/my/file HTTP/1.1" -/// Also note that the path must include the leading '/'. - -TString ROOT::Deprecated::TS3HTTPRequest::MakeRequestLine(TS3HTTPRequest::EHTTPVerb httpVerb) const -{ - return TString::Format("%s /%s%s HTTP/1.1", - (const char*)HTTPVerbToTString(httpVerb), - (const char*)fBucket, - (const char*)fObjectKey); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the 'Host' header to include in the HTTP request. - -TString ROOT::Deprecated::TS3HTTPRequest::MakeHostHeader() const -{ - return "Host: " + fHost; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the date header for this HTTP request - -TString ROOT::Deprecated::TS3HTTPRequest::MakeDateHeader() const -{ - return "Date: " + fTimeStamp; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the session security token header for this HTTP request - -TString ROOT::Deprecated::TS3HTTPRequest::MakeTokenHeader() const -{ - if (fAuthType != kAmazon) - return ""; - - if (fSessionToken.IsNull()) - return ""; - - return TString::Format("x-amz-security-token: %s", - (const char*) fSessionToken.Data()); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the authentication prefix - -TString ROOT::Deprecated::TS3HTTPRequest::MakeAuthPrefix() const -{ - switch (fAuthType) { - case kNoAuth: return ""; - case kGoogle: return "GOOG1"; - case kAmazon: - default: return "AWS"; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the authentication header for this HTTP request - -TString ROOT::Deprecated::TS3HTTPRequest::MakeAuthHeader(TS3HTTPRequest::EHTTPVerb httpVerb) const -{ - if (fAuthType == kNoAuth) - return ""; - - return TString::Format("Authorization: %s %s:%s%s", - (const char*)MakeAuthPrefix(), - (const char*)fAccessKey, - (const char*)ComputeSignature(httpVerb), - (fAuthType == kGoogle) ? "\r\nx-goog-api-version: 1" : ""); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns the HTTP request ready to be sent to the server - -TString ROOT::Deprecated::TS3HTTPRequest::GetRequest(TS3HTTPRequest::EHTTPVerb httpVerb, Bool_t appendCRLF) -{ - // Set time stamp before computing this request's signature. The signature - // includes the date. - SetTimeStamp(); - TString request = TString::Format("%s\r\n%s\r\n%s\r\n", - (const char*)MakeRequestLine(httpVerb), - (const char*)MakeHostHeader(), - (const char*)MakeDateHeader()); - TString tokenHeader = MakeTokenHeader(); - if (!tokenHeader.IsNull()) - request += tokenHeader + "\r\n"; - TString authHeader = MakeAuthHeader(httpVerb); - if (!authHeader.IsNull()) - request += authHeader + "\r\n"; - if (appendCRLF) - request += "\r\n"; - return request; -} diff --git a/net/net/src/TS3WebFile.cxx b/net/net/src/TS3WebFile.cxx deleted file mode 100644 index b3ce6d0539cfe..0000000000000 --- a/net/net/src/TS3WebFile.cxx +++ /dev/null @@ -1,400 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fabio Hernandez 22/01/2013 -// extending an initial version by Marcelo Sousa (class TAS3File) - -/************************************************************************* - * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -/** -\file TS3WebFile.cxx -\class TS3WebFile -\ingroup IO - -A TS3WebFile is a TWebFile which retrieves the file contents from a -web server implementing the REST API of the Amazon S3 protocol. This -class is meant to be as generic as possible to be used with files -hosted not only by Amazon S3 servers but also by other providers -implementing the core of the S3 protocol. - -The S3 protocol works on top of HTTPS (and HTTP) and imposes that -each HTTP request be signed using a specific convention: the request -must include an 'Authorization' header which contains the signature -of a concatenation of selected request fields. For signing the -request, an 'Access Key Id' and a 'Secret Access Key' need to be -known. These keys are used by the S3 servers to identify the client -and to authenticate the request as genuine. - -As an end user, you must know the Access Key and Secret Access Key -in order to access each S3 file. They are provided to you by your S3 -service provider. Those two keys can be provided to ROOT when -initializing an object of this class by two means: -a. by using the environmental variables S3_ACCESS_KEY and - S3_SECRET_KEY, or -b. by specifying them when opening each file. - -You can use AWS temporary security credentials (temporary access key -and secret access key), but you must also give the associated -session token. The token may be set in the S3_SESSION_TOKEN -environmental variable, or on open in the TOKEN option. - -The first method is convenient if all the S3 files you want to -access are hosted by a single provider. The second one is more -flexible as it allows you to specify which credentials to use -on a per-file basis. See the documentation of the constructor of -this class for details on the syntax. - -For generating and signing the HTTP request, this class uses -TS3HTTPRequest. - -For more information on the details of S3 protocol please refer to: -"Amazon Simple Storage Service Developer Guide": -http://docs.amazonwebservices.com/AmazonS3/latest/dev/Welcome.html - -"Amazon Simple Storage Service REST API Reference" - http://docs.amazonwebservices.com/AmazonS3/latest/API/APIRest.html - -**/ - -#include "TS3WebFile.h" -#include "TROOT.h" -#include "TError.h" -#include "TSystem.h" -#include "TPRegexp.h" -#include "TEnv.h" - - - -//////////////////////////////////////////////////////////////////////////////// -/// Construct a TS3WebFile object. The path argument is a URL of one of the -/// following forms: -/// -/// ``` -/// s3://host.example.com/bucket/path/to/my/file -/// s3http://host.example.com/bucket/path/to/my/file -/// s3https://host.example.com/bucket/path/to/my/file -/// as3://host.example.com/bucket/path/to/my/file -/// ``` -/// -/// For files hosted by Google Storage, use the following forms: -/// -/// ``` -/// gs://storage.googleapis.com/bucket/path/to/my/file -/// gshttp://storage.googleapis.com/bucket/path/to/my/file -/// gsthttps://storage.googleapis.com/bucket/path/to/my/file -/// ``` -/// -/// The 'as3' scheme is accepted for backwards compatibility but its usage is -/// deprecated. -/// -/// The recommended way to create an instance of this class is through -/// TFile::Open, for instance: -/// -/// ```c++ -/// TFile* f1 = TFile::Open("s3://host.example.com/bucket/path/to/my/file") -/// TFile* f2 = TFile::Open("gs://storage.googleapis.com/bucket/path/to/my/file") -/// ``` -/// -/// The specified scheme (i.e. s3, s3http, s3https, ...) determines the underlying -/// transport protocol to use for downloading the file contents, namely HTTP or HTTPS. -/// The 's3', 's3https', 'gs' and 'gshttps' schemes imply using HTTPS as the transport -/// protocol. The 's3http', 'as3' and 'gshttp' schemes imply using HTTP as the transport -/// protocol. -/// -/// The 'options' argument can contain 'NOPROXY' if you want to bypass -/// the HTTP proxy when retrieving this file's contents. As for any TWebFile-derived -/// object, the URL of the web proxy can be specified by setting an environmental -/// variable 'http_proxy'. If this variable is set, we ask that proxy to route our -/// requests HTTP(S) requests to the file server. -/// -/// In addition, you can also use the 'options' argument to provide the access key -/// and secret key to be used for authentication purposes for this file by using a -/// string of the form "AUTH=myAccessKey:mySecretkey". This may be useful to -/// open several files hosted by different providers in the same program/macro, -/// where the environemntal variables solution is not convenient (see below). -/// -/// To use AWS temporary security credentials you need to specify the session -/// token. This can be added to the options argument with a string of the form -/// TOKEN=mySessionToken. The temporary access and secret keys must also be -/// available, either via the AUTH option or by environmental variable. -/// -/// If you need to specify more than one option separate them by ' ' -/// (blank), for instance: -/// "NOPROXY AUTH=F38XYZABCDeFgH4D0E1F:V+frt4re7J1euSNFnmaf8wwmI4AAAE7kzxZ/TTM+" -/// -/// Examples: -/// ``` -/// TFile* f1 = TFile::Open("s3://host.example.com/bucket/path/to/my/file", -/// "NOPROXY AUTH=F38XYZABCDeFgH4D0E1F:V+frt4re7J1euSNFnmaf8wwmI4AAAE7kzxZ/TTM+"); -/// TFile* f2 = TFile::Open("s3://host.example.com/bucket/path/to/my/file", -/// "AUTH=F38XYZABCDeFgH4D0E1F:V+frt4re7J1euSNFnmaf8wwmI4AAAE7kzxZ/TTM+"); -/// TFile* f3 = TFile::Open("s3://host.example.com/bucket/path/to/my/file", -/// "TOKEN=AQoDYXdzEM///////////wEa8AHEYmCinjD+TsGEjtgKSMAT6wnY"); -/// ``` -/// -/// If there is no authentication information in the 'options' argument -/// (i.e. not AUTH="....") the values of the environmental variables -/// S3_ACCESS_KEY and S3_SECRET_KEY (if set) are expected to contain -/// the access key id and the secret access key, respectively. You have -/// been provided with these credentials by your S3 service provider. -/// -/// If neither the AUTH information is provided in the 'options' argument -/// nor the environmental variables are set, we try to open the file -/// without providing any authentication information to the server. This -/// is useful when the file is set an access control that allows for -/// any unidentified user to read the file. - -ROOT::Deprecated::TS3WebFile::TS3WebFile(const char* path, Option_t* options) : TWebFile(path, "IO") -{ - // Make sure this is a valid S3 path. We accept 'as3' as a scheme, for - // backwards compatibility - Bool_t doMakeZombie = kFALSE; - TString errorMsg; - TString accessKey; - TString secretKey; - TString token; - TPMERegexp rex("^([a]?s3|s3http[s]?|gs|gshttp[s]?){1}://([^/]+)/([^/]+)/([^/].*)", "i"); - if (rex.Match(TString(path)) != 5) { - errorMsg = TString::Format("invalid S3 path '%s'", path); - doMakeZombie = kTRUE; - } - else if (!ParseOptions(options, accessKey, secretKey, token)) { - errorMsg = TString::Format("could not parse options '%s'", options); - doMakeZombie = kTRUE; - } - - // Should we stop initializing this object? - if (doMakeZombie) { - Error("TS3WebFile", "%s", (const char*)errorMsg); - MakeZombie(); - gDirectory = gROOT; - return; - } - - // Set this S3 object's URL, the bucket name this file is located in - // and the object key - fS3Request.SetBucket(rex[3]); - fS3Request.SetObjectKey(TString::Format("/%s", (const char*)rex[4])); - - // Initialize super-classes data members (fUrl is a data member of - // super-super class TFile) - TString protocol = "https"; - if (rex[1].EndsWith("http", TString::kIgnoreCase) || - rex[1].EqualTo("as3", TString::kIgnoreCase)) - protocol = "http"; - fUrl.SetUrl(TString::Format("%s://%s/%s/%s", (const char*)protocol, - (const char*)rex[2], (const char*)rex[3], (const char*)rex[4])); - - // Set S3-specific data members. If the access and secret keys are not - // provided in the 'options' argument we look in the environmental - // variables. - const char* kAccessKeyEnv = "S3_ACCESS_KEY"; - const char* kSecretKeyEnv = "S3_SECRET_KEY"; - const char* kSessionToken = "S3_SESSION_TOKEN"; - if (accessKey.IsNull()) - GetCredentialsFromEnv(kAccessKeyEnv, kSecretKeyEnv, kSessionToken, - accessKey, secretKey, token); - - // Initialize the S3 HTTP request - fS3Request.SetHost(fUrl.GetHost()); - if (accessKey.IsNull() || secretKey.IsNull()) { - // We have no authentication information, neither in the options - // nor in the enviromental variables. So may be this is a - // world-readable file, so let's continue and see if - // we can open it. - fS3Request.SetAuthType(TS3HTTPRequest::kNoAuth); - } else { - // Set the authentication information we need to use - // for this file - fS3Request.SetAuthKeys(accessKey, secretKey); - if (!token.IsNull()) - fS3Request.SetSessionToken(token); - if (rex[1].BeginsWith("gs")) - fS3Request.SetAuthType(TS3HTTPRequest::kGoogle); - else - fS3Request.SetAuthType(TS3HTTPRequest::kAmazon); - } - - // Assume this server does not serve multi-range HTTP GET requests. We - // will detect this when the HTTP headers of this files are retrieved - // later in the initialization process - fUseMultiRange = kFALSE; - - // Call super-class initializer - TWebFile::Init(kFALSE); - - // Were there some errors opening this file? - if (IsZombie() && (accessKey.IsNull() || secretKey.IsNull())) { - // We could not open the file and we have no authentication information - // so inform the user so that they can check. - Error("TS3WebFile", "could not find authentication info in "\ - "'options' argument and at least one of the environment variables '%s' or '%s' is not set", - kAccessKeyEnv, kSecretKeyEnv); - } -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Extracts the S3 authentication key pair (access key and secret key) -/// from the options. The authentication credentials can be specified in -/// the options provided to the constructor of this class as a string -/// containing: "AUTH=:" and can include other -/// options, for instance "NOPROXY" for not using the HTTP proxy for -/// accessing this file's contents. -/// For instance: -/// "NOPROXY AUTH=F38XYZABCDeFgHiJkLm:V+frt4re7J1euSNFnmaf8wwmI401234E7kzxZ/TTM+" -/// A security token may be given by the TOKEN option, in order to allow the -/// use of a temporary key pair. - -Bool_t -ROOT::Deprecated::TS3WebFile::ParseOptions(Option_t* options, TString& accessKey, TString& secretKey, TString& token) -{ - TString optStr = (const char*)options; - if (optStr.IsNull()) - return kTRUE; - - fNoProxy = kFALSE; - if (optStr.Contains("NOPROXY", TString::kIgnoreCase)) - fNoProxy = kTRUE; - CheckProxy(); - - // Look in the options string for the authentication information. - TPMERegexp rex_token("(^TOKEN=|^.* TOKEN=)([\\S]+)[\\s]*.*$", "i"); - if (rex_token.Match(optStr) == 3) { - token = rex_token[2]; - } - TPMERegexp rex("(^AUTH=|^.* AUTH=)([a-z0-9]+):([a-z0-9+/]+)[\\s]*.*$", "i"); - if (rex.Match(optStr) == 4) { - accessKey = rex[2]; - secretKey = rex[3]; - } - if (gDebug > 0) - Info("ParseOptions", "using authentication information from 'options' argument"); - return kTRUE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Overwrites TWebFile::GetHead() for retrieving the HTTP headers of this -/// file. Uses TS3HTTPRequest to generate an HTTP HEAD request which includes -/// the authorization header expected by the S3 server. - -Int_t ROOT::Deprecated::TS3WebFile::GetHead() -{ - fMsgGetHead = fS3Request.GetRequest(TS3HTTPRequest::kHEAD); - return TWebFile::GetHead(); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Overwrites TWebFile::SetMsgReadBuffer10() for setting the HTTP GET -/// request compliant to the authentication mechanism used by the S3 -/// protocol. The GET request must contain an "Authorization" header with -/// the signature of the request, generated using the user's secret access -/// key. - -void ROOT::Deprecated::TS3WebFile::SetMsgReadBuffer10(const char* redirectLocation, Bool_t tempRedirect) -{ - TWebFile::SetMsgReadBuffer10(redirectLocation, tempRedirect); - fMsgReadBuffer10 = fS3Request.GetRequest(TS3HTTPRequest::kGET, kFALSE) + "Range: bytes="; - return; -} - - -//////////////////////////////////////////////////////////////////////////////// - -Bool_t ROOT::Deprecated::TS3WebFile::ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf) -{ - // Overwrites TWebFile::ReadBuffers() for reading specified byte ranges. - // According to the kind of server this file is hosted by, we use a - // single HTTP request with a muti-range header or we generate multiple - // requests with a single range each. - - // Does this server support multi-range GET requests? - if (fUseMultiRange) - return TWebFile::ReadBuffers(buf, pos, len, nbuf); - - // Send multiple GET requests with a single range of bytes - // Adapted from original version by Wang Lu - for (Int_t i=0, offset=0; i < nbuf; i++) { - TString rangeHeader = TString::Format("Range: bytes=%lld-%lld\r\n\r\n", - pos[i], pos[i] + len[i] - 1); - TString s3Request = fS3Request.GetRequest(TS3HTTPRequest::kGET, kFALSE) + rangeHeader; - if (GetFromWeb10(&buf[offset], len[i], s3Request) == -1) - return kTRUE; - offset += len[i]; - } - return kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// This method is called by the super-class TWebFile when a HTTP header -/// for this file is retrieved. We scan the 'Server' header to detect the -/// type of S3 server this file is hosted on and to determine if it is -/// known to support multi-range HTTP GET requests. Some S3 servers (for -/// instance Amazon's) do not support that feature and when they -/// receive a multi-range request they sent back the whole file contents. -/// For this class, if the server do not support multirange requests -/// we issue multiple single-range requests instead. - -void ROOT::Deprecated::TS3WebFile::ProcessHttpHeader(const TString& headerLine) -{ - TPMERegexp rex("^Server: (.+)", "i"); - if (rex.Match(headerLine) != 2) - return; - - // Extract the identity of this server and compare it to the - // identify of the servers known to support multi-range requests. - // The list of server identities is expected to be found in ROOT - // configuration. - TString serverId = rex[1].ReplaceAll("\r", "").ReplaceAll("\n", ""); - TString multirangeServers(gEnv->GetValue("TS3WebFile.Root.MultiRangeServer", "")); - fUseMultiRange = multirangeServers.Contains(serverId, TString::kIgnoreCase) ? kTRUE : kFALSE; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Sets the access and secret keys from the environmental variables, if -/// they are both set. Sets the security session token if it is given. - -Bool_t ROOT::Deprecated::TS3WebFile::GetCredentialsFromEnv(const char* accessKeyEnv, const char* secretKeyEnv, - const char* tokenEnv, TString& outAccessKey, - TString& outSecretKey, TString& outToken) -{ - // Look first in the recommended environmental variables. Both variables - // must be set. - TString accKey = gSystem->Getenv(accessKeyEnv); - TString secKey = gSystem->Getenv(secretKeyEnv); - TString token = gSystem->Getenv(tokenEnv); - if (!token.IsNull()) { - outToken = token; - } - if (!accKey.IsNull() && !secKey.IsNull()) { - outAccessKey = accKey; - outSecretKey = secKey; - if (gDebug > 0) - Info("GetCredentialsFromEnv", "using authentication information from environmental variables '%s' and '%s'", - accessKeyEnv, secretKeyEnv); - return kTRUE; - } - - // Look now in the legacy environmental variables, for keeping backwards - // compatibility. - accKey = gSystem->Getenv("S3_ACCESS_ID"); // Legacy access key - secKey = gSystem->Getenv("S3_ACCESS_KEY"); // Legacy secret key - if (!accKey.IsNull() && !secKey.IsNull()) { - Warning("SetAuthKeys", "usage of S3_ACCESS_ID and S3_ACCESS_KEY environmental variables is deprecated."); - Warning("SetAuthKeys", "please use S3_ACCESS_KEY and S3_SECRET_KEY environmental variables."); - outAccessKey = accKey; - outSecretKey = secKey; - return kTRUE; - } - - return kFALSE; -} - diff --git a/net/net/src/TWebFile.cxx b/net/net/src/TWebFile.cxx deleted file mode 100644 index ce68eb39da1f8..0000000000000 --- a/net/net/src/TWebFile.cxx +++ /dev/null @@ -1,1563 +0,0 @@ -// @(#)root/net:$Id$ -// Author: Fons Rademakers 17/01/97 - -/************************************************************************* - * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -////////////////////////////////////////////////////////////////////////// -// // -// TWebFile // -// // -// A TWebFile is like a normal TFile except that it reads its data // -// via a standard apache web server. A TWebFile is a read-only file. // -// // -////////////////////////////////////////////////////////////////////////// - -#include "TWebFile.h" -#include "TROOT.h" -#include "TSocket.h" -#include "Bytes.h" -#include "TError.h" -#include "TSystem.h" -#include "TBase64.h" -#include "TVirtualPerfStats.h" -#ifdef R__SSL -#include "TSSLSocket.h" -#endif - -#include -#include -#include - -#ifdef WIN32 -# ifndef EADDRINUSE -# define EADDRINUSE 10048 -# endif -# ifndef EISCONN -# define EISCONN 10056 -# endif -#endif - -static const char *gUserAgent = "User-Agent: ROOT-TWebFile/1.1"; - -TUrl ROOT::Deprecated::TWebFile::fgProxy; - -Long64_t ROOT::Deprecated::TWebFile::fgMaxFullCacheSize = 500000000; - -namespace ROOT::Deprecated { - -// Internal class used to manage the socket that may stay open between -// calls when HTTP/1.1 protocol is used -class TWebSocket { -private: - TWebFile *fWebFile; // associated web file -public: - TWebSocket(TWebFile *f); - ~TWebSocket(); - void ReOpen(); -}; - -} // namespace ROOT::Deprecated - -//////////////////////////////////////////////////////////////////////////////// -/// Open web file socket. - -ROOT::Deprecated::TWebSocket::TWebSocket(TWebFile *f) -{ - fWebFile = f; - if (!f->fSocket) - ReOpen(); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close socket in case not HTTP/1.1 protocol or when explicitly requested. - -ROOT::Deprecated::TWebSocket::~TWebSocket() -{ - if (!fWebFile->fHTTP11) { - delete fWebFile->fSocket; - fWebFile->fSocket = nullptr; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Re-open web file socket. - -void ROOT::Deprecated::TWebSocket::ReOpen() -{ - if (fWebFile->fSocket) { - delete fWebFile->fSocket; - fWebFile->fSocket = nullptr; - } - - TUrl connurl; - if (fWebFile->fProxy.IsValid()) - connurl = fWebFile->fProxy; - else - connurl = fWebFile->fUrl; - - for (Int_t i = 0; i < 5; i++) { - if (strcmp(connurl.GetProtocol(), "https") == 0) { -#ifdef R__SSL - fWebFile->fSocket = new TSSLSocket(connurl.GetHost(), connurl.GetPort()); -#else - ::Error("TWebSocket::ReOpen", "library compiled without SSL, https not supported"); - return; -#endif - } else - fWebFile->fSocket = new TSocket(connurl.GetHost(), connurl.GetPort()); - - if (!fWebFile->fSocket || !fWebFile->fSocket->IsValid()) { - delete fWebFile->fSocket; - fWebFile->fSocket = nullptr; - if (gSystem->GetErrno() == EADDRINUSE || gSystem->GetErrno() == EISCONN) { - gSystem->Sleep(i*10); - } else { - ::Error("TWebSocket::ReOpen", "cannot connect to host %s (errno=%d)", - fWebFile->fUrl.GetHost(), gSystem->GetErrno()); - return; - } - } else - return; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Create a Web file object. A web file is the same as a read-only -/// TFile except that it is being read via a HTTP server. The url -/// argument must be of the form: http://host.dom.ain/file.root. -/// The opt can be "NOPROXY", to bypass any set "http_proxy" shell -/// variable. The proxy can be specified as (in sh, or equivalent csh): -/// export http_proxy=http://pcsalo.cern.ch:3128 -/// The proxy can also be specified via the static method TWebFile::SetProxy(). -/// Basic authentication (AuthType Basic) is supported. The user name and -/// passwd can be specified in the url like this: -/// http://username:mypasswd@pcsalo.cern.ch/files/aap.root -/// If the file specified in the URL does not exist or is not accessible -/// the kZombie bit will be set in the TWebFile object. Use IsZombie() -/// to see if the file is accessible. The preferred interface to this -/// constructor is via TFile::Open(). - -ROOT::Deprecated::TWebFile::TWebFile(const char *url, Option_t *opt) - : TFile(url, strstr(opt, "_WITHOUT_GLOBALREGISTRATION") != nullptr ? "WEB_WITHOUT_GLOBALREGISTRATION" : "WEB"), - fSocket(0) -{ - TString option = opt; - fNoProxy = kFALSE; - if (option.Contains("NOPROXY", TString::kIgnoreCase)) - fNoProxy = kTRUE; - CheckProxy(); - - Bool_t headOnly = kFALSE; - if (option.Contains("HEADONLY", TString::kIgnoreCase)) - headOnly = kTRUE; - - if (option == "IO") - return; - - Init(headOnly); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Create a Web file object. A web file is the same as a read-only -/// TFile except that it is being read via a HTTP server. Make sure url -/// is a valid TUrl object. -/// The opt can be "NOPROXY", to bypass any set "http_proxy" shell -/// variable. The proxy can be specified as (in sh, or equivalent csh): -/// export http_proxy=http://pcsalo.cern.ch:3128 -/// The proxy can also be specified via the static method TWebFile::SetProxy(). -/// Basic authentication (AuthType Basic) is supported. The user name and -/// passwd can be specified in the url like this: -/// http://username:mypasswd@pcsalo.cern.ch/files/aap.root -/// If the file specified in the URL does not exist or is not accessible -/// the kZombie bit will be set in the TWebFile object. Use IsZombie() -/// to see if the file is accessible. - -ROOT::Deprecated::TWebFile::TWebFile(TUrl url, Option_t *opt) : TFile(url.GetUrl(), "WEB"), fSocket(0) -{ - TString option = opt; - fNoProxy = kFALSE; - if (option.Contains("NOPROXY", TString::kIgnoreCase)) - fNoProxy = kTRUE; - CheckProxy(); - - Bool_t headOnly = kFALSE; - if (option.Contains("HEADONLY", TString::kIgnoreCase)) - headOnly = kTRUE; - - Init(headOnly); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup. - -ROOT::Deprecated::TWebFile::~TWebFile() -{ - delete fSocket; - if (fFullCache) { - free(fFullCache); - fFullCache = nullptr; - fFullCacheSize = 0; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Initialize a TWebFile object. - -void ROOT::Deprecated::TWebFile::Init(Bool_t readHeadOnly) -{ - char buf[4]; - int err; - - fSocket = nullptr; - fSize = -1; - fHasModRoot = kFALSE; -#if defined(R__WIN32) && defined(R__SSL) - fHTTP11 = kTRUE; -#else - fHTTP11 = kFALSE; -#endif - fFullCache = nullptr; - fFullCacheSize = 0; - SetMsgReadBuffer10(); - - if ((err = GetHead()) < 0) { - if (readHeadOnly) { - fD = -1; - fWritten = err; - return; - } - if (err == -2) { - Error("TWebFile", "%s does not exist", fBasicUrl.Data()); - MakeZombie(); - gDirectory = gROOT; - return; - } - // err == -3 HEAD not supported, fall through and try ReadBuffer() - } - if (readHeadOnly) { - fD = -1; - return; - } - - if (fIsRootFile) { - Seek(0); - if (ReadBuffer(buf, 4)) { - MakeZombie(); - gDirectory = gROOT; - return; - } - - if (strncmp(buf, "root", 4) && strncmp(buf, "PK", 2)) { // PK is zip file - Error("TWebFile", "%s is not a ROOT file", fBasicUrl.Data()); - MakeZombie(); - gDirectory = gROOT; - return; - } - } - - TFile::Init(kFALSE); - fD = -2; // so TFile::IsOpen() will return true when in TFile::~TFile -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set GET command for use by ReadBuffer(s)10(), handle redirection if -/// needed. Give full URL so Apache's virtual hosts solution works. - -void ROOT::Deprecated::TWebFile::SetMsgReadBuffer10(const char *redirectLocation, Bool_t tempRedirect) -{ - TUrl oldUrl; - TString oldBasicUrl; - - if (redirectLocation) { - if (tempRedirect) { // temp redirect - fUrlOrg = fUrl; - fBasicUrlOrg = fBasicUrl; - } else { // permanent redirect - fUrlOrg = ""; - fBasicUrlOrg = ""; - } - - oldUrl = fUrl; - oldBasicUrl = fBasicUrl; - - fUrl.SetUrl(redirectLocation); - fBasicUrl = fUrl.GetProtocol(); - fBasicUrl += "://"; - fBasicUrl += fUrl.GetHost(); - fBasicUrl += ":"; - fBasicUrl += fUrl.GetPort(); - fBasicUrl += "/"; - fBasicUrl += fUrl.GetFile(); - // add query string again - TString rdl(redirectLocation); - if (rdl.Index("?") >= 0) { - rdl = rdl(rdl.Index("?"), rdl.Length()); - fBasicUrl += rdl; - } - } - - if (fMsgReadBuffer10 != "") { - // patch up existing command - if (oldBasicUrl != "") { - // change to redirection location - fMsgReadBuffer10.ReplaceAll(oldBasicUrl, fBasicUrl); - fMsgReadBuffer10.ReplaceAll(TString("Host: ")+oldUrl.GetHost(), TString("Host: ")+fUrl.GetHost()); - } else if (fBasicUrlOrg != "") { - // change back from temp redirection location - fMsgReadBuffer10.ReplaceAll(fBasicUrl, fBasicUrlOrg); - fMsgReadBuffer10.ReplaceAll(TString("Host: ")+fUrl.GetHost(), TString("Host: ")+fUrlOrg.GetHost()); - fUrl = fUrlOrg; - fBasicUrl = fBasicUrlOrg; - fUrlOrg = ""; - fBasicUrlOrg = ""; - } - } - - if (fBasicUrl == "") { - fBasicUrl += fUrl.GetProtocol(); - fBasicUrl += "://"; - fBasicUrl += fUrl.GetHost(); - fBasicUrl += ":"; - fBasicUrl += fUrl.GetPort(); - fBasicUrl += "/"; - fBasicUrl += fUrl.GetFile(); - if (strlen(fUrl.GetOptions())) { - fBasicUrl += "?"; - fBasicUrl += fUrl.GetOptions(); - } - } - - if (fMsgReadBuffer10 == "") { - fMsgReadBuffer10 = "GET "; - fMsgReadBuffer10 += fBasicUrl; - if (fHTTP11) - fMsgReadBuffer10 += " HTTP/1.1"; - else - fMsgReadBuffer10 += " HTTP/1.0"; - fMsgReadBuffer10 += "\r\n"; - if (fHTTP11) { - fMsgReadBuffer10 += "Host: "; - fMsgReadBuffer10 += fUrl.GetHost(); - fMsgReadBuffer10 += "\r\n"; - } - fMsgReadBuffer10 += BasicAuthentication(); - fMsgReadBuffer10 += gUserAgent; - fMsgReadBuffer10 += "\r\n"; - fMsgReadBuffer10 += "Range: bytes="; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Check if shell var "http_proxy" has been set and should be used. - -void ROOT::Deprecated::TWebFile::CheckProxy() -{ - if (fNoProxy) - return; - - if (fgProxy.IsValid()) { - fProxy = fgProxy; - return; - } - - TString proxy = gSystem->Getenv("http_proxy"); - if (proxy != "") { - TUrl p(proxy); - if (strcmp(p.GetProtocol(), "http")) { - Error("CheckProxy", "protocol must be HTTP in proxy URL %s", - proxy.Data()); - return; - } - fProxy = p; - if (gDebug > 0) - Info("CheckProxy", "using HTTP proxy %s", fProxy.GetUrl()); - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// A TWebFile that has been correctly constructed is always considered open. - -Bool_t ROOT::Deprecated::TWebFile::IsOpen() const -{ - return IsZombie() ? kFALSE : kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Reopen a file with a different access mode, like from READ to -/// UPDATE or from NEW, CREATE, RECREATE, UPDATE to READ. Thus the -/// mode argument can be either "READ" or "UPDATE". The method returns -/// 0 in case the mode was successfully modified, 1 in case the mode -/// did not change (was already as requested or wrong input arguments) -/// and -1 in case of failure, in which case the file cannot be used -/// anymore. A TWebFile cannot be reopened in update mode. - -Int_t ROOT::Deprecated::TWebFile::ReOpen(Option_t *mode) -{ - TString opt = mode; - opt.ToUpper(); - - if (opt != "READ" && opt != "UPDATE") - Error("ReOpen", "mode must be either READ or UPDATE, not %s", opt.Data()); - - if (opt == "UPDATE") - Error("ReOpen", "update mode not allowed for a TWebFile"); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Close a Web file. Close the socket connection and delete the cache -/// See also the TFile::Close() function - -void ROOT::Deprecated::TWebFile::Close(Option_t *option) -{ - delete fSocket; - fSocket = nullptr; - if (fFullCache) { - free(fFullCache); - fFullCache = nullptr; - fFullCacheSize = 0; - } - return TFile::Close(option); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte range from remote file via HTTP daemon. This -/// routine connects to the remote host, sends the request and returns -/// the buffer. Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TWebFile::ReadBuffer(char *buf, Int_t len) -{ - Int_t st; - if ((st = ReadBufferViaCache(buf, len))) { - if (st == 2) - return kTRUE; - return kFALSE; - } - - if (!fHasModRoot) - return ReadBuffer10(buf, len); - - // Give full URL so Apache's virtual hosts solution works. - // Use protocol 0.9 for efficiency, we are not interested in the 1.0 headers. - if (fMsgReadBuffer == "") { - fMsgReadBuffer = "GET "; - fMsgReadBuffer += fBasicUrl; - fMsgReadBuffer += "?"; - } - TString msg = fMsgReadBuffer; - msg += fOffset; - msg += ":"; - msg += len; - msg += "\r\n"; - - if (GetFromWeb(buf, len, msg) == -1) - return kTRUE; - - fOffset += len; - - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte range from remote file via HTTP daemon. This -/// routine connects to the remote host, sends the request and returns -/// the buffer. Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TWebFile::ReadBuffer(char *buf, Long64_t pos, Int_t len) -{ - SetOffset(pos); - return ReadBuffer(buf, len); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte range from remote file via HTTP 1.0 daemon (without -/// mod-root installed). This routine connects to the remote host, sends the -/// request and returns the buffer. Returns kTRUE in case of error. - -Bool_t ROOT::Deprecated::TWebFile::ReadBuffer10(char *buf, Int_t len) -{ - SetMsgReadBuffer10(); - - TString msg = fMsgReadBuffer10; - msg += fOffset; - msg += "-"; - msg += fOffset+len-1; - msg += "\r\n\r\n"; - - Long64_t apos = fOffset - fArchiveOffset; - - // in case when server does not support segments, let chance to recover - Int_t n = GetFromWeb10(buf, len, msg, 1, &apos, &len); - if (n == -1) - return kTRUE; - // The -2 error condition typically only happens when - // GetHead() failed because not implemented, in the first call to - // ReadBuffer() in Init(), it is not checked in ReadBuffers10(). - if (n == -2) { - Error("ReadBuffer10", "%s does not exist", fBasicUrl.Data()); - MakeZombie(); - gDirectory = gROOT; - return kTRUE; - } - - fOffset += len; - - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte ranges from remote file via HTTP daemon. -/// Reads the nbuf blocks described in arrays pos and len, -/// where pos[i] is the seek position of block i of length len[i]. -/// Note that for nbuf=1, this call is equivalent to TFile::ReafBuffer -/// This function is overloaded by TNetFile, TWebFile, etc. -/// Returns kTRUE in case of failure. - -Bool_t ROOT::Deprecated::TWebFile::ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) -{ - if (!fHasModRoot) - return ReadBuffers10(buf, pos, len, nbuf); - - // Give full URL so Apache's virtual hosts solution works. - // Use protocol 0.9 for efficiency, we are not interested in the 1.0 headers. - if (fMsgReadBuffer == "") { - fMsgReadBuffer = "GET "; - fMsgReadBuffer += fBasicUrl; - fMsgReadBuffer += "?"; - } - TString msg = fMsgReadBuffer; - - Int_t k = 0, n = 0, cnt = 0; - for (Int_t i = 0; i < nbuf; i++) { - if (n) msg += ","; - msg += pos[i] + fArchiveOffset; - msg += ":"; - msg += len[i]; - n += len[i]; - cnt++; - if ((msg.Length() > 8000) || (cnt >= 200)) { - msg += "\r\n"; - if (GetFromWeb(&buf[k], n, msg) == -1) - return kTRUE; - msg = fMsgReadBuffer; - k += n; - n = 0; - cnt = 0; - } - } - - msg += "\r\n"; - - if (GetFromWeb(&buf[k], n, msg) == -1) - return kTRUE; - - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read specified byte ranges from remote file via HTTP 1.0 daemon (without -/// mod-root installed). Read the nbuf blocks described in arrays pos and len, -/// where pos[i] is the seek position of block i of length len[i]. -/// Note that for nbuf=1, this call is equivalent to TFile::ReafBuffer -/// This function is overloaded by TNetFile, TWebFile, etc. -/// Returns kTRUE in case of failure. - -Bool_t ROOT::Deprecated::TWebFile::ReadBuffers10(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) -{ - SetMsgReadBuffer10(); - - TString msg = fMsgReadBuffer10; - - Int_t k = 0, n = 0, r, cnt = 0; - for (Int_t i = 0; i < nbuf; i++) { - if (n) msg += ","; - msg += pos[i] + fArchiveOffset; - msg += "-"; - msg += pos[i] + fArchiveOffset + len[i] - 1; - n += len[i]; - cnt++; - if ((msg.Length() > 8000) || (cnt >= 200) || (i+1 == nbuf)) { - msg += "\r\n\r\n"; - r = GetFromWeb10(&buf[k], n, msg, cnt, pos + (i+1-cnt), len + (i+1-cnt)); - if (r == -1) - return kTRUE; - msg = fMsgReadBuffer10; - k += n; - n = 0; - cnt = 0; - } - } - - return kFALSE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Extract requested segments from the cached content. -/// Such cache can be produced when server suddenly returns full data instead of segments -/// Returns -1 in case of error, 0 in case of success - -Int_t ROOT::Deprecated::TWebFile::GetFromCache(char *buf, Int_t len, Int_t nseg, Long64_t *seg_pos, Int_t *seg_len) -{ - if (!fFullCache) return -1; - - if (gDebug > 0) - Info("GetFromCache", "Extract %d segments total len %d from cached data", nseg, len); - - Int_t curr = 0; - for (Int_t cnt=0;cnt len) return -1; - // check that segment is inside cached area - if (fArchiveOffset + seg_pos[cnt] + seg_len[cnt] > fFullCacheSize) return -1; - char* src = (char*) fFullCache + fArchiveOffset + seg_pos[cnt]; - memcpy(buf + curr, src, seg_len[cnt]); - curr += seg_len[cnt]; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read request from web server. Returns -1 in case of error, -/// 0 in case of success. - -Int_t ROOT::Deprecated::TWebFile::GetFromWeb(char *buf, Int_t len, const TString &msg) -{ - TSocket *s; - - if (!len) return 0; - - Double_t start = 0; - if (gPerfStats) start = TTimeStamp(); - - TUrl connurl; - if (fProxy.IsValid()) - connurl = fProxy; - else - connurl = fUrl; - - if (strcmp(connurl.GetProtocol(), "https") == 0) { -#ifdef R__SSL - s = new TSSLSocket(connurl.GetHost(), connurl.GetPort()); -#else - Error("GetFromWeb", "library compiled without SSL, https not supported"); - return -1; -#endif - } else - s = new TSocket(connurl.GetHost(), connurl.GetPort()); - - if (!s->IsValid()) { - Error("GetFromWeb", "cannot connect to host %s", fUrl.GetHost()); - delete s; - return -1; - } - - if (s->SendRaw(msg.Data(), msg.Length()) == -1) { - Error("GetFromWeb", "error sending command to host %s", fUrl.GetHost()); - delete s; - return -1; - } - - if (s->RecvRaw(buf, len) == -1) { - Error("GetFromWeb", "error receiving data from host %s", fUrl.GetHost()); - delete s; - return -1; - } - - // collect statistics - fBytesRead += len; - fReadCalls++; -#ifdef R__WIN32 - SetFileBytesRead(GetFileBytesRead() + len); - SetFileReadCalls(GetFileReadCalls() + 1); -#else - fgBytesRead += len; - fgReadCalls++; -#endif - - if (gPerfStats) - gPerfStats->FileReadEvent(this, len, start); - - delete s; - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read multiple byte range request from web server. -/// Uses HTTP 1.0 daemon wihtout mod-root. -/// Returns -2 in case file does not exist, -1 in case -/// of error and 0 in case of success. - -Int_t ROOT::Deprecated::TWebFile::GetFromWeb10(char *buf, Int_t len, const TString &msg, Int_t nseg, Long64_t *seg_pos, - Int_t *seg_len) -{ - if (!len) return 0; - - // if file content was cached, reuse it - if (fFullCache && (nseg>0)) - return GetFromCache(buf, len, nseg, seg_pos, seg_len); - - Double_t start = 0; - if (gPerfStats) start = TTimeStamp(); - - // open fSocket and close it when going out of scope - TWebSocket ws(this); - - if (!fSocket || !fSocket->IsValid()) { - Error("GetFromWeb10", "cannot connect to host %s", fUrl.GetHost()); - return -1; - } - - if (gDebug > 0) - Info("GetFromWeb10", "sending HTTP request:\n%s", msg.Data()); - - if (fSocket->SendRaw(msg.Data(), msg.Length()) == -1) { - Error("GetFromWeb10", "error sending command to host %s", fUrl.GetHost()); - return -1; - } - - char line[8192]; - Int_t n, ret = 0, nranges = 0, ltot = 0, redirect = 0; - TString boundary, boundaryEnd; - Long64_t first = -1, last = -1, tot, fullsize = 0; - TString redir; - - while ((n = GetLine(fSocket, line, sizeof(line))) >= 0) { - if (n == 0) { - if (ret < 0) - return ret; - if (redirect) { - if (redir.IsNull()) { - // Some sites (s3.amazonaws.com) do not return a Location field on 301 - Error("GetFromWeb10", "error - redirect without location from host %s", fUrl.GetHost()); - return -1; - } - - ws.ReOpen(); - // set message to reflect the redirectLocation and add bytes field - TString msg_1 = fMsgReadBuffer10; - msg_1 += fOffset; - msg_1 += "-"; - msg_1 += fOffset+len-1; - msg_1 += "\r\n\r\n"; - return GetFromWeb10(buf, len, msg_1); - } - - if (first >= 0) { - Int_t ll = Int_t(last - first) + 1; - Int_t rsize; - if ((rsize = fSocket->RecvRaw(&buf[ltot], ll)) == -1) { - Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost()); - return -1; - } - else if (ll != rsize) { - Error("GetFromWeb10", "expected %d bytes, got %d", ll, rsize); - return -1; - } - ltot += ll; - - first = -1; - - if (boundary == "") - break; // not a multipart response - } - - if (fullsize > 0) { - - if (nseg <= 0) { - Error("GetFromWeb10","Need segments data to extract parts from full size %lld", fullsize); - return -1; - } - - if (len > fullsize) { - Error("GetFromWeb10","Requested part %d longer than full size %lld", len, fullsize); - return -1; - } - - if ((fFullCache == 0) && (fullsize <= GetMaxFullCacheSize())) { - // try to read file content into cache and than reuse it, limit cache by 2 GB - fFullCache = malloc(fullsize); - if (fFullCache != 0) { - if (fSocket->RecvRaw(fFullCache, fullsize) != fullsize) { - Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost()); - free(fFullCache); fFullCache = nullptr; - return -1; - } - fFullCacheSize = fullsize; - return GetFromCache(buf, len, nseg, seg_pos, seg_len); - } - // when cache allocation failed, try without cache - } - - // check all segemnts are inside range and in sorted order - for (Int_t cnt=0;cnt fullsize) { - Error("GetFromWeb10","Requested segment %lld len %d is outside of full range %lld", seg_pos[cnt], seg_len[cnt], fullsize); - return -1; - } - if ((cnt>0) && (seg_pos[cnt-1] + seg_len[cnt-1] > seg_pos[cnt])) { - Error("GetFromWeb10","Requested segments are not in sorted order"); - return -1; - } - } - - Long64_t pos = 0; - char* curr = buf; - char dbuf[2048]; // dummy buffer for skip data - - // now read complete file and take only requested segments into the buffer - for (Int_t cnt=0; cnt Int_t(sizeof(dbuf))) ll = sizeof(dbuf); - if (fSocket->RecvRaw(dbuf, ll) != ll) { - Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost()); - return -1; - } - pos += ll; - } - - // reading segment itself - if (fSocket->RecvRaw(curr, seg_len[cnt]) != seg_len[cnt]) { - Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost()); - return -1; - } - curr += seg_len[cnt]; - pos += seg_len[cnt]; - ltot += seg_len[cnt]; - } - - // now read file to the end - while (pos < fullsize) { - Long64_t ll = fullsize - pos; - if (ll > Int_t(sizeof(dbuf))) ll = sizeof(dbuf); - if (fSocket->RecvRaw(dbuf, ll) != ll) { - Error("GetFromWeb10", "error receiving data from host %s", fUrl.GetHost()); - return -1; - } - pos += ll; - } - - if (gDebug > 0) - Info("GetFromWeb10", "Complete reading %d bytes in %d segments out of full size %lld", len, nseg, fullsize); - - break; - } - - continue; - } - - if (gDebug > 0) - Info("GetFromWeb10", "header: %s", line); - - if (boundaryEnd == line) { - if (gDebug > 0) - Info("GetFromWeb10", "got all headers"); - break; - } - if (boundary == line) { - nranges++; - if (gDebug > 0) - Info("GetFromWeb10", "get new multipart byte range (%d)", nranges); - } - - TString res = line; - res.ToLower(); - if (res.BeginsWith("HTTP/1.", TString::kIgnoreCase)) { - if (res.BeginsWith("HTTP/1.1", TString::kIgnoreCase)) { - if (!fHTTP11) - fMsgReadBuffer10 = ""; - fHTTP11 = kTRUE; - } - TString scode = res(9, 3); - Int_t code = scode.Atoi(); - if (code >= 500) { - ret = -1; - TString mess = res(13, 1000); - Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } else if (code >= 400) { - if (code == 404) - ret = -2; // file does not exist - else { - ret = -1; - TString mess = res(13, 1000); - Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code >= 300) { - if (code == 301 || code == 303) { - redirect = 1; // permanent redirect - } else if (code == 302 || code == 307) { - // treat 302 as 303: permanent redirect - redirect = 1; - //redirect = 2; // temp redirect - } else { - ret = -1; - TString mess = res(13, 1000); - Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code > 200) { - if (code != 206) { - ret = -1; - TString mess = res(13, 1000); - Error("GetFromWeb10", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code == 200) { - fullsize = -200; // make indication of code 200 - Warning("GetFromWeb10", - "Server %s response with complete file, but only part of it was requested.\n" - "Check MaxRanges configuration parameter (if Apache is used)", - fUrl.GetHost()); - - } - } else if (res.BeginsWith("content-type: multipart", TString::kIgnoreCase)) { - boundary = res(res.Index("boundary=", TString::kIgnoreCase) + 9, 1000); - if (boundary[0] == '"' && boundary[boundary.Length()-1] == '"') { - boundary = boundary(1, boundary.Length() - 2); - } - boundary = "--" + boundary; - boundaryEnd = boundary + "--"; - } else if (res.BeginsWith("content-range:", TString::kIgnoreCase)) { - sscanf(res.Data(), "content-range: bytes %lld-%lld/%lld", &first, &last, &tot); - if (fSize == -1) fSize = tot; - } else if (res.BeginsWith("content-length:", TString::kIgnoreCase) && (fullsize == -200)) { - sscanf(res.Data(), "content-length: %lld", &fullsize); - } else if (res.BeginsWith("location:", TString::kIgnoreCase) && redirect) { - redir = res(10, 1000); - if (redirect == 2) // temp redirect - SetMsgReadBuffer10(redir, kTRUE); - else // permanent redirect - SetMsgReadBuffer10(redir, kFALSE); - } - } - - if (redirect && redir.IsNull()) { - Error("GetFromWeb10", "error - redirect without location from host %s", fUrl.GetHost()); - } - - if (n == -1 && fHTTP11) { - if (gDebug > 0) - Info("GetFromWeb10", "HTTP/1.1 socket closed, reopen"); - if (fBasicUrlOrg != "") { - // if we have to close temp redirection, set back to original url - SetMsgReadBuffer10(); - } - ws.ReOpen(); - return GetFromWeb10(buf, len, msg); - } - - if (ltot != len) { - Error("GetFromWeb10", "error receiving expected amount of data (got %d, expected %d) from host %s", - ltot, len, fUrl.GetHost()); - return -1; - } - - // collect statistics - fBytesRead += len; - fReadCalls++; -#ifdef R__WIN32 - SetFileBytesRead(GetFileBytesRead() + len); - SetFileReadCalls(GetFileReadCalls() + 1); -#else - fgBytesRead += len; - fgReadCalls++; -#endif - - if (gPerfStats) - gPerfStats->FileReadEvent(this, len, start); - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Set position from where to start reading. - -void ROOT::Deprecated::TWebFile::Seek(Long64_t offset, ERelativeTo pos) -{ - switch (pos) { - case kBeg: - fOffset = offset + fArchiveOffset; - break; - case kCur: - fOffset += offset; - break; - case kEnd: - // this option is not used currently in the ROOT code - if (fArchiveOffset) - Error("Seek", "seeking from end in archive is not (yet) supported"); - fOffset = fEND - offset; // is fEND really EOF or logical EOF? - break; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return maximum file size. - -Long64_t ROOT::Deprecated::TWebFile::GetSize() const -{ - if (!fHasModRoot || fSize >= 0) - return fSize; - - Long64_t size; - char asize[64]; - - TString msg = "GET "; - msg += fBasicUrl; - msg += "?"; - msg += -1; - msg += "\r\n"; - - if (const_cast(this)->GetFromWeb(asize, 64, msg) == -1) - return kMaxInt; - -#ifndef R__WIN32 - size = atoll(asize); -#else - size = _atoi64(asize); -#endif - - fSize = size; - - return size; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get the HTTP header. Depending on the return code we can see if -/// the file exists and if the server uses mod_root. -/// Returns -1 in case of an error, -2 in case the file does not exists, -/// -3 in case HEAD is not supported (dCache HTTP door) and -/// 0 in case of success. - -Int_t ROOT::Deprecated::TWebFile::GetHead() -{ - // Give full URL so Apache's virtual hosts solution works. - if (fMsgGetHead == "") { - fMsgGetHead = "HEAD "; - fMsgGetHead += fBasicUrl; - if (fHTTP11) - fMsgGetHead += " HTTP/1.1"; - else - fMsgGetHead += " HTTP/1.0"; - fMsgGetHead += "\r\n"; - if (fHTTP11) { - fMsgGetHead += "Host: "; - fMsgGetHead += fUrl.GetHost(); - fMsgGetHead += "\r\n"; - } - fMsgGetHead += BasicAuthentication(); - fMsgGetHead += gUserAgent; - fMsgGetHead += "\r\n\r\n"; - } - TString msg = fMsgGetHead; - - TUrl connurl; - if (fProxy.IsValid()) - connurl = fProxy; - else - connurl = fUrl; - - TSocket *s = nullptr; - for (Int_t i = 0; i < 5; i++) { - if (strcmp(connurl.GetProtocol(), "https") == 0) { -#ifdef R__SSL - s = new TSSLSocket(connurl.GetHost(), connurl.GetPort()); -#else - Error("GetHead", "library compiled without SSL, https not supported"); - return -1; -#endif - } else - s = new TSocket(connurl.GetHost(), connurl.GetPort()); - - if (!s->IsValid()) { - delete s; - if (gSystem->GetErrno() == EADDRINUSE || gSystem->GetErrno() == EISCONN) { - s = nullptr; - gSystem->Sleep(i*10); - } else { - Error("GetHead", "cannot connect to host %s (errno=%d)", fUrl.GetHost(), - gSystem->GetErrno()); - return -1; - } - } else - break; - } - if (!s) - return -1; - - if (gDebug > 0) { - Info("GetHead", "connected to host %s", connurl.GetHost()); - Info("GetHead", "sending HTTP request:\n%s", msg.Data()); - } - - if (s->SendRaw(msg.Data(), msg.Length()) == -1) { - Error("GetHead", "error sending command to host %s", fUrl.GetHost()); - delete s; - return -1; - } - - char line[8192]; - Int_t n, ret = 0, redirect = 0; - TString redir; - - while ((n = GetLine(s, line, sizeof(line))) >= 0) { - if (n == 0) { - if (gDebug > 0) - Info("GetHead", "got all headers"); - delete s; - if (fBasicUrlOrg != "" && !redirect) { - // set back to original url in case of temp redirect - SetMsgReadBuffer10(); - fMsgGetHead = ""; - } - if (ret < 0) - return ret; - if (redirect) { - if (redir.IsNull()) { - // Some sites (s3.amazonaws.com) do not return a Location field on 301 - Error("GetHead", "error - redirect without location from host %s", fUrl.GetHost()); - return -1; - } - return GetHead(); - } - return 0; - } - - if (gDebug > 0) - Info("GetHead", "header: %s", line); - - TString res = line; - ProcessHttpHeader(res); - if (res.BeginsWith("HTTP/1.")) { - if (res.BeginsWith("HTTP/1.1")) { - if (!fHTTP11) { - fMsgGetHead = ""; - fMsgReadBuffer10 = ""; - } - fHTTP11 = kTRUE; - } - TString scode = res(9, 3); - Int_t code = scode.Atoi(); - if (code >= 500) { - if (code == 500) - fHasModRoot = kTRUE; - else { - ret = -1; - TString mess = res(13, 1000); - Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code >= 400) { - if (code == 400) - ret = -3; // command not supported - else if (code == 404) - ret = -2; // file does not exist - else { - ret = -1; - TString mess = res(13, 1000); - Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code >= 300) { - if (code == 301 || code == 303) - redirect = 1; // permanent redirect - else if (code == 302 || code == 307) - redirect = 2; // temp redirect - else { - ret = -1; - TString mess = res(13, 1000); - Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (code > 200) { - ret = -1; - TString mess = res(13, 1000); - Error("GetHead", "%s: %s (%d)", fBasicUrl.Data(), mess.Data(), code); - } - } else if (res.BeginsWith("Content-Length:", TString::kIgnoreCase)) { - TString slen = res(16, 1000); - fSize = slen.Atoll(); - } else if (res.BeginsWith("Location:", TString::kIgnoreCase) && redirect) { - redir = res(10, 1000); - if (redirect == 2) // temp redirect - SetMsgReadBuffer10(redir, kTRUE); - else // permanent redirect - SetMsgReadBuffer10(redir, kFALSE); - fMsgGetHead = ""; - } - } - - delete s; - - return ret; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read a line from the socket. Reads at most one less than the number of -/// characters specified by maxsize. Reading stops when a newline character -/// is found, The newline (\\n) and cr (\\r), if any, are removed. -/// Returns -1 in case of error, or the number of characters read (>= 0) -/// otherwise. - -Int_t ROOT::Deprecated::TWebFile::GetLine(TSocket *s, char *line, Int_t maxsize) -{ - Int_t n = GetHunk(s, line, maxsize); - if (n < 0) { - if (!fHTTP11 || gDebug > 0) - Error("GetLine", "error receiving data from host %s", fUrl.GetHost()); - return -1; - } - - if (n > 0 && line[n-1] == '\n') { - n--; - if (n > 0 && line[n-1] == '\r') - n--; - line[n] = '\0'; - } - return n; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Read a hunk of data from the socket, up until a terminator. The hunk is -/// limited by whatever the TERMINATOR callback chooses as its -/// terminator. For example, if terminator stops at newline, the hunk -/// will consist of a line of data; if terminator stops at two -/// newlines, it can be used to read the head of an HTTP response. -/// Upon determining the boundary, the function returns the data (up to -/// the terminator) in hunk. -/// -/// In case of read error, -1 is returned. In case of having read some -/// data, but encountering EOF before seeing the terminator, the data -/// that has been read is returned, but it will (obviously) not contain the -/// terminator. -/// -/// The TERMINATOR function is called with three arguments: the -/// beginning of the data read so far, the beginning of the current -/// block of peeked-at data, and the length of the current block. -/// Depending on its needs, the function is free to choose whether to -/// analyze all data or just the newly arrived data. If TERMINATOR -/// returns 0, it means that the terminator has not been seen. -/// Otherwise it should return a pointer to the character immediately -/// following the terminator. -/// -/// The idea is to be able to read a line of input, or otherwise a hunk -/// of text, such as the head of an HTTP request, without crossing the -/// boundary, so that the next call to RecvRaw() etc. reads the data -/// after the hunk. To achieve that, this function does the following: -/// -/// 1. Peek at incoming data. -/// -/// 2. Determine whether the peeked data, along with the previously -/// read data, includes the terminator. -/// -/// 3a. If yes, read the data until the end of the terminator, and -/// exit. -/// -/// 3b. If no, read the peeked data and goto 1. -/// -/// The function is careful to assume as little as possible about the -/// implementation of peeking. For example, every peek is followed by -/// a read. If the read returns a different amount of data, the -/// process is retried until all data arrives safely. -/// -/// Reads at most one less than the number of characters specified by maxsize. - -Int_t ROOT::Deprecated::TWebFile::GetHunk(TSocket *s, char *hunk, Int_t maxsize) -{ - if (maxsize <= 0) return 0; - - Int_t bufsize = maxsize; - Int_t tail = 0; // tail position in HUNK - - while (1) { - const char *end; - Int_t pklen, rdlen, remain; - - // First, peek at the available data. - pklen = s->RecvRaw(hunk+tail, bufsize-1-tail, kPeek); - if (pklen < 0) { - return -1; - } - end = HttpTerminator(hunk, hunk+tail, pklen); - if (end) { - // The data contains the terminator: we'll drain the data up - // to the end of the terminator. - remain = end - (hunk + tail); - if (remain == 0) { - // No more data needs to be read. - hunk[tail] = '\0'; - return tail; - } - if (bufsize - 1 < tail + remain) { - Error("GetHunk", "hunk buffer too small for data from host %s (%d bytes needed)", - fUrl.GetHost(), tail + remain + 1); - hunk[tail] = '\0'; - return -1; - } - } else { - // No terminator: simply read the data we know is (or should - // be) available. - remain = pklen; - } - - // Now, read the data. Note that we make no assumptions about - // how much data we'll get. (Some TCP stacks are notorious for - // read returning less data than the previous MSG_PEEK.) - rdlen = s->RecvRaw(hunk+tail, remain, kDontBlock); - if (rdlen < 0) { - return -1; - } - tail += rdlen; - hunk[tail] = '\0'; - - if (rdlen == 0) { - // in case of EOF: return the data we've read. - return tail; - } - if (end && rdlen == remain) { - // The terminator was seen and the remaining data drained -- - // we got what we came for. - return tail; - } - - // Keep looping until all the data arrives. - - if (tail == bufsize - 1) { - Error("GetHunk", "hunk buffer too small for data from host %s", - fUrl.GetHost()); - return -1; - } - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Determine whether [START, PEEKED + PEEKLEN) contains an HTTP new -/// line [\\r]\\n. If so, return the pointer to the position after the line, -/// otherwise return 0. This is used as callback to GetHunk(). The data -/// between START and PEEKED has been read and cannot be "unread"; the -/// data after PEEKED has only been peeked. - -const char *ROOT::Deprecated::TWebFile::HttpTerminator(const char *start, const char *peeked, - Int_t peeklen) -{ -#if 0 - const char *p, *end; - - // Look for "[\r]\n", and return the following position if found. - // Start one char before the current to cover the possibility that - // part of the terminator (e.g. "\r") arrived in the previous batch. - p = peeked - start < 1 ? start : peeked - 1; - end = peeked + peeklen; - - // Check for \r\n anywhere in [p, end-2). - for (; p < end - 1; p++) - if (p[0] == '\r' && p[1] == '\n') - return p + 2; - - // p==end-1: check for \r\n directly preceding END. - if (p[0] == '\r' && p[1] == '\n') - return p + 2; -#else - (void) start; // start unused, silence compiler - if (peeked) { - const char *p = (const char*) memchr(peeked, '\n', peeklen); - if (p) - // p+1 because the line must include '\n' - return p + 1; - } -#endif - return nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Return basic authentication scheme, to be added to the request. - -TString ROOT::Deprecated::TWebFile::BasicAuthentication() -{ - TString msg; - if (strlen(fUrl.GetUser())) { - TString auth = fUrl.GetUser(); - if (strlen(fUrl.GetPasswd())) { - auth += ":"; - auth += fUrl.GetPasswd(); - } - msg += "Authorization: Basic "; - msg += TBase64::Encode(auth); - msg += "\r\n"; - } - return msg; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Static method setting global proxy URL. - -void ROOT::Deprecated::TWebFile::SetProxy(const char *proxy) -{ - if (proxy && *proxy) { - TUrl p(proxy); - if (strcmp(p.GetProtocol(), "http")) { - :: Error("TWebFile::SetProxy", "protocol must be HTTP in proxy URL %s", - proxy); - return; - } - fgProxy = p; - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Static method returning the global proxy URL. - -const char *ROOT::Deprecated::TWebFile::GetProxy() -{ - if (fgProxy.IsValid()) - return fgProxy.GetUrl(); - return ""; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Process the HTTP header in the argument. This method is intended to be -/// overwritten by subclasses that exploit the information contained in the -/// HTTP headers. - -void ROOT::Deprecated::TWebFile::ProcessHttpHeader(const TString&) -{ -} - -//////////////////////////////////////////////////////////////////////////////// -/// Static method returning maxmimal size of full cache, -/// which can be preserved by file instance - -Long64_t ROOT::Deprecated::TWebFile::GetMaxFullCacheSize() -{ - return fgMaxFullCacheSize; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Static method, set maxmimal size of full cache, -// which can be preserved by file instance - -void ROOT::Deprecated::TWebFile::SetMaxFullCacheSize(Long64_t sz) -{ - fgMaxFullCacheSize = sz; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Create helper class that allows directory access via httpd. -/// The name must start with '-' to bypass the TSystem singleton check. - -ROOT::Deprecated::TWebSystem::TWebSystem() : TSystem("-http", "HTTP Helper System") -{ - SetName("http"); - - fDirp = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Make a directory via httpd. Not supported. - -Int_t ROOT::Deprecated::TWebSystem::MakeDirectory(const char *) -{ - return -1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Open a directory via httpd. Returns an opaque pointer to a dir -/// structure. Returns 0 in case of error. - -void *ROOT::Deprecated::TWebSystem::OpenDirectory(const char *) -{ - if (fDirp) { - Error("OpenDirectory", "invalid directory pointer (should never happen)"); - fDirp = nullptr; - } - - fDirp = nullptr; // not implemented for the time being - - return fDirp; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Free directory via httpd. - -void ROOT::Deprecated::TWebSystem::FreeDirectory(void *dirp) -{ - if (dirp != fDirp) { - Error("FreeDirectory", "invalid directory pointer (should never happen)"); - return; - } - - fDirp = nullptr; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get directory entry via httpd. Returns 0 in case no more entries. - -const char *ROOT::Deprecated::TWebSystem::GetDirEntry(void *dirp) -{ - if (dirp != fDirp) { - Error("GetDirEntry", "invalid directory pointer (should never happen)"); - return 0; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Get info about a file. Info is returned in the form of a FileStat_t -/// structure (see TSystem.h). -/// The function returns 0 in case of success and 1 if the file could -/// not be stat'ed. - -Int_t ROOT::Deprecated::TWebSystem::GetPathInfo(const char *path, FileStat_t &buf) -{ - TWebFile *f = new TWebFile(path, "HEADONLY"); - - if (f->fWritten == 0) { - - buf.fDev = 0; - buf.fIno = 0; - buf.fMode = 0; - buf.fUid = 0; - buf.fGid = 0; - buf.fSize = f->GetSize(); - buf.fMtime = 0; - buf.fIsLink = kFALSE; - - delete f; - return 0; - } - - delete f; - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Returns FALSE if one can access a file using the specified access mode. -/// Mode is the same as for the Unix access(2) function. -/// Attention, bizarre convention of return value!! - -Bool_t ROOT::Deprecated::TWebSystem::AccessPathName(const char *path, EAccessMode) -{ - TWebFile *f = new TWebFile(path, "HEADONLY"); - if (f->fWritten == 0) { - delete f; - return kFALSE; - } - delete f; - return kTRUE; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Unlink, i.e. remove, a file or directory. Returns 0 when successful, -/// -1 in case of failure. Not supported for httpd. - -Int_t ROOT::Deprecated::TWebSystem::Unlink(const char *) -{ - return -1; -} diff --git a/roofit/roofitcore/test/stressRooFit.cxx b/roofit/roofitcore/test/stressRooFit.cxx index f700b1ae60674..554cf9f662ce3 100644 --- a/roofit/roofitcore/test/stressRooFit.cxx +++ b/roofit/roofitcore/test/stressRooFit.cxx @@ -8,7 +8,6 @@ #include "Math/MinimizerOptions.h" -#include "TWebFile.h" #include "TSystem.h" #include "TString.h" #include "TStopwatch.h" diff --git a/roofit/roostats/test/stressRooStats.cxx b/roofit/roostats/test/stressRooStats.cxx index 7b677e9208571..2e3d07b5ca251 100644 --- a/roofit/roostats/test/stressRooStats.cxx +++ b/roofit/roostats/test/stressRooStats.cxx @@ -12,7 +12,6 @@ #include "Math/MinimizerOptions.h" // ROOT headers -#include "TWebFile.h" #include "TSystem.h" #include "TString.h" #include "TStopwatch.h" diff --git a/roottest/root/io/event/MainEvent.cxx b/roottest/root/io/event/MainEvent.cxx index 3fd786ec159f7..e2eb5009ad775 100644 --- a/roottest/root/io/event/MainEvent.cxx +++ b/roottest/root/io/event/MainEvent.cxx @@ -85,7 +85,6 @@ #include "TBranch.h" #include "TFile.h" #include "TH1.h" -#include "TNetFile.h" #include "TRandom.h" #include "TStopwatch.h" #include "TTree.h" @@ -113,7 +112,6 @@ int main(int argc, char** argv) Int_t read = 0; Int_t arg4 = 1; Int_t arg5 = 600; //default number of tracks per event - Int_t netf = 0; const char* arg6 = 0; const char* arg7 = 0; @@ -133,7 +131,6 @@ int main(int argc, char** argv) if (arg4 == 11) { write = 1; hfill = 1;} if (arg4 == 20) { write = 0; read = 1;} //read sequential if (arg4 == 25) { write = 0; read = 2;} //read random - if (arg4 >= 30) { netf = 1; } //use TNetFile if (arg4 == 30) { write = 0; read = 1;} //netfile + read sequential if (arg4 == 35) { write = 0; read = 2;} //netfile + read random if (arg4 == 36) { write = 1; } //netfile + write sequential @@ -179,11 +176,7 @@ int main(int argc, char** argv) if (read) { // -- Read case TFile* hfile = nullptr; - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root"); - } else { - hfile = new TFile(gFilename); - } + hfile = new TFile(gFilename); TTree* tree = (TTree*) hfile->Get("T"); TBranch* branch = tree->GetBranch("event"); Event* event = nullptr; @@ -224,13 +217,7 @@ int main(int argc, char** argv) // Note that this file may contain any kind of ROOT objects, histograms, // pictures, graphics objects, detector geometries, tracks, events, etc.. // This file is now becoming the current directory. - TFile* hfile = 0; - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root", "RECREATE", - "TTree benchmark ROOT file"); - } else { - hfile = new TFile(gFilename, "RECREATE", "TTree benchmark ROOT file"); - } + TFile* hfile = new TFile(gFilename, "RECREATE", "TTree benchmark ROOT file"); hfile->SetCompressionLevel(comp); // Create histogram to show write_time in function of time diff --git a/roottest/root/treeformula/references/TreeFormulaReferencesGenerator.cxx b/roottest/root/treeformula/references/TreeFormulaReferencesGenerator.cxx index 380993bf964cd..4cea9e1299d4c 100644 --- a/roottest/root/treeformula/references/TreeFormulaReferencesGenerator.cxx +++ b/roottest/root/treeformula/references/TreeFormulaReferencesGenerator.cxx @@ -85,7 +85,6 @@ #include "Riostream.h" #include "TROOT.h" #include "TFile.h" -#include "TNetFile.h" #include "TRandom.h" #include "TTree.h" #include "TBranch.h" @@ -109,7 +108,6 @@ int main(int argc, char **argv) Int_t read = 0; Int_t arg4 = 1; Int_t arg5 = 600; //default number of tracks per event - Int_t netf = 0; const char *filename = "Event.root"; if (argc > 1) nevent = atoi(argv[1]); @@ -125,7 +123,6 @@ int main(int argc, char **argv) if (arg4 == 11) { write = 1; hfill = 1;} if (arg4 == 20) { write = 0; read = 1;} //read sequential if (arg4 == 25) { write = 0; read = 2;} //read random - if (arg4 >= 30) { netf = 1; } //use TNetFile if (arg4 == 30) { write = 0; read = 1;} //netfile + read sequential if (arg4 == 35) { write = 0; read = 2;} //netfile + read random if (arg4 == 36) { write = 1; } //netfile + write sequential @@ -153,10 +150,7 @@ int main(int argc, char **argv) // Read case if (read) { - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root"); - } else - hfile = new TFile(filename); + hfile = new TFile(filename); TTree *tree = (TTree*)hfile->Get("T"); TBranch *branch = tree->GetBranch("event"); branch->SetAddress(&event); @@ -186,11 +180,7 @@ int main(int argc, char **argv) // Note that this file may contain any kind of ROOT objects, histograms, // pictures, graphics objects, detector geometries, tracks, events, etc.. // This file is now becoming the current directory. - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root","RECREATE", - "TTree benchmark ROOT file"); - } else - hfile = new TFile(filename,"RECREATE","TTree benchmark ROOT file"); + hfile = new TFile(filename,"RECREATE","TTree benchmark ROOT file"); hfile->SetCompressionLevel(comp); // Create histogram to show write_time in function of time diff --git a/roottest/root/treeformula/schemaEvolution/MainEvent.cxx b/roottest/root/treeformula/schemaEvolution/MainEvent.cxx index ff2fc666cedab..fa20afd458944 100644 --- a/roottest/root/treeformula/schemaEvolution/MainEvent.cxx +++ b/roottest/root/treeformula/schemaEvolution/MainEvent.cxx @@ -85,7 +85,6 @@ #include "TROOT.h" #include "TFile.h" -#include "TNetFile.h" #include "TRandom.h" #include "TTree.h" #include "TBranch.h" @@ -109,7 +108,6 @@ int main(int argc, char **argv) Int_t read = 0; Int_t arg4 = 1; Int_t arg5 = 600; //default number of tracks per event - Int_t netf = 0; if (argc > 1) nevent = atoi(argv[1]); if (argc > 2) comp = atoi(argv[2]); @@ -123,7 +121,6 @@ int main(int argc, char **argv) if (arg4 == 11) { write = 1; hfill = 1;} if (arg4 == 20) { write = 0; read = 1;} //read sequential if (arg4 == 25) { write = 0; read = 2;} //read random - if (arg4 >= 30) { netf = 1; } //use TNetFile if (arg4 == 30) { write = 0; read = 1;} //netfile + read sequential if (arg4 == 35) { write = 0; read = 2;} //netfile + read random if (arg4 == 36) { write = 1; } //netfile + write sequential @@ -152,10 +149,7 @@ int main(int argc, char **argv) // Read case if (read) { - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root"); - } else - hfile = new TFile("Event.root"); + hfile = new TFile("Event.root"); tree = (TTree*)hfile->Get("T"); TBranch *branch = tree->GetBranch("event"); branch->SetAddress(&event); @@ -185,11 +179,7 @@ int main(int argc, char **argv) // Note that this file may contain any kind of ROOT objects, histograms, // pictures, graphics objects, detector geometries, tracks, events, etc.. // This file is now becoming the current directory. - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root","RECREATE", - "TTree benchmark ROOT file"); - } else - hfile = new TFile("Event.root","RECREATE","TTree benchmark ROOT file"); + hfile = new TFile("Event.root","RECREATE","TTree benchmark ROOT file"); hfile->SetCompressionLevel(comp); // Create histogram to show write_time in function of time diff --git a/test/MainEvent.cxx b/test/MainEvent.cxx index 4e58af85a4671..e35c8a2775c80 100644 --- a/test/MainEvent.cxx +++ b/test/MainEvent.cxx @@ -96,7 +96,6 @@ #include "Riostream.h" #include "TROOT.h" #include "TFile.h" -#include "TNetFile.h" #include "TRandom.h" #include "TTree.h" #include "TTreePerfStats.h" @@ -121,7 +120,6 @@ int MainEvent(int nevent, int comp, int split, int arg4, int arg5, int enable_im Int_t write = 1; // by default the tree is filled Int_t hfill = 0; // by default histograms are not filled Int_t read = 0; - Int_t netf = 0; Int_t punzip = 0; if (arg4 == 0) { write = 0; hfill = 0; read = 1;} @@ -132,7 +130,6 @@ int MainEvent(int nevent, int comp, int split, int arg4, int arg5, int enable_im if (arg4 == 20) { write = 0; read = 1;} //read sequential if (arg4 == 21) { write = 0; read = 1; punzip = 1;} //read sequential + parallel unzipping if (arg4 == 25) { write = 0; read = 2;} //read random - if (arg4 >= 30) { netf = 1; } //use TNetFile if (arg4 == 30) { write = 0; read = 1;} //netfile + read sequential if (arg4 == 35) { write = 0; read = 2;} //netfile + read random if (arg4 == 36) { write = 1; } //netfile + write sequential @@ -171,10 +168,7 @@ int MainEvent(int nevent, int comp, int split, int arg4, int arg5, int enable_im // Read case if (read) { - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root"); - } else - hfile = new TFile(outFiles.back().c_str()); + hfile = new TFile(outFiles.back().c_str()); tree = (TTree*)hfile->Get("T"); TBranch *branch = tree->GetBranch("event"); branch->SetAddress(&event); @@ -215,11 +209,7 @@ int MainEvent(int nevent, int comp, int split, int arg4, int arg5, int enable_im // Note that this file may contain any kind of ROOT objects, histograms, // pictures, graphics objects, detector geometries, tracks, events, etc.. // This file is now becoming the current directory. - if (netf) { - hfile = new ROOT::Deprecated::TNetFile("root://localhost/root/test/EventNet.root","RECREATE", - "TTree benchmark ROOT file"); - } else - hfile = new TFile(outFiles.back().c_str(),"RECREATE","TTree benchmark ROOT file"); + hfile = new TFile(outFiles.back().c_str(),"RECREATE","TTree benchmark ROOT file"); hfile->SetCompressionLevel(comp); hfile->SetCompressionAlgorithm(compAlg); diff --git a/tree/ntuple/inc/ROOT/RField.hxx b/tree/ntuple/inc/ROOT/RField.hxx index bc0c4f952877d..0329c436f0654 100644 --- a/tree/ntuple/inc/ROOT/RField.hxx +++ b/tree/ntuple/inc/ROOT/RField.hxx @@ -107,8 +107,6 @@ public: kUnknownStructure, }; - using RCategory R__DEPRECATED(6, 42, "enum renamed to ECategory") = ECategory; - private: std::string fError; ECategory fCategory; diff --git a/tree/ntuple/inc/ROOT/RNTupleDescriptor.hxx b/tree/ntuple/inc/ROOT/RNTupleDescriptor.hxx index a5a736010c223..a9298f2086ace 100644 --- a/tree/ntuple/inc/ROOT/RNTupleDescriptor.hxx +++ b/tree/ntuple/inc/ROOT/RNTupleDescriptor.hxx @@ -192,10 +192,6 @@ public: std::optional GetTypeChecksum() const { return fTypeChecksum; } bool IsProjectedField() const { return fProjectionSourceId != ROOT::kInvalidDescriptorId; } bool IsSoACollection() const { return fIsSoACollection; } - - bool IsCustomClass() const R__DEPRECATED(6, 42, "removed from public interface"); - bool IsCustomEnum(const RNTupleDescriptor &desc) const R__DEPRECATED(6, 42, "removed from public interface"); - bool IsStdAtomic() const R__DEPRECATED(6, 42, "removed from public interface"); }; // clang-format off diff --git a/tree/ntuple/inc/ROOT/RNTupleTypes.hxx b/tree/ntuple/inc/ROOT/RNTupleTypes.hxx index bb87cef5de657..9692a542cb017 100644 --- a/tree/ntuple/inc/ROOT/RNTupleTypes.hxx +++ b/tree/ntuple/inc/ROOT/RNTupleTypes.hxx @@ -112,9 +112,6 @@ enum class ENTupleStructure : std::uint16_t { kVariant, kStreamer, kUnknown, - - // for backwards compatibility - kLeaf R__DEPRECATED(6, 42, "use instead ROOT::ENTupleStructure::kPlain") = kPlain }; inline std::ostream &operator<<(std::ostream &os, ENTupleStructure structure) diff --git a/tree/ntuple/src/RNTupleDescriptor.cxx b/tree/ntuple/src/RNTupleDescriptor.cxx index f4a8b72b62c8b..b51af779c45a9 100644 --- a/tree/ntuple/src/RNTupleDescriptor.cxx +++ b/tree/ntuple/src/RNTupleDescriptor.cxx @@ -151,35 +151,6 @@ ROOT::RFieldDescriptor::CreateField(const RNTupleDescriptor &ntplDesc, const ROO } } -bool ROOT::RFieldDescriptor::IsCustomClass() const -{ - if (fStructure != ROOT::ENTupleStructure::kRecord && fStructure != ROOT::ENTupleStructure::kStreamer) - return false; - - // Skip untyped structs - if (fTypeName.empty()) - return false; - - if (fStructure == ROOT::ENTupleStructure::kRecord) { - if (fTypeName.compare(0, 10, "std::pair<") == 0) - return false; - if (fTypeName.compare(0, 11, "std::tuple<") == 0) - return false; - } - - return true; -} - -bool ROOT::RFieldDescriptor::IsCustomEnum(const RNTupleDescriptor &desc) const -{ - return Internal::IsCustomEnumFieldDesc(desc, *this); -} - -bool ROOT::RFieldDescriptor::IsStdAtomic() const -{ - return Internal::IsStdAtomicFieldDesc(*this); -} - //////////////////////////////////////////////////////////////////////////////// bool ROOT::RColumnDescriptor::operator==(const RColumnDescriptor &other) const