// @(#)root/netx:$Id$
// Author: Frank Winklmeier, Fabrizio Furano

/*************************************************************************
 * Copyright (C) 1995-2005, 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_TXNetSystem
#define ROOT_TXNetSystem

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TXNetSystem                                                          //
//                                                                      //
// Authors: Frank Winklmeier,  Fabrizio Furano                          //
//          INFN Padova, 2005                                           //
//                                                                      //
// TXNetSystem is an extension of TNetSystem able to deal with new      //
// xrootd servers. The class detects the nature of the server and       //
// redirects the calls to TNetSystem in case of a rootd server.         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TNetSystem
#include "TNetFile.h"
#endif

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

#ifndef ROOT_TString
#include "TString.h"
#endif

#ifndef ROOT_THashList
#include "THashList.h"
#endif

class XrdClientAdmin;
class TCollection;
class TXNetSystemConnectGuard;

typedef /*XrdClientVector<XrdOucString>*/ void* VecStringVP_t;

class TXrdClientAdminWrapper : public TNamed {
public:
   TXrdClientAdminWrapper(const char *key, XrdClientAdmin *ca) : TNamed(key,""), fXCA(ca) { }
   virtual ~TXrdClientAdminWrapper();
   XrdClientAdmin *fXCA;
};

class TXNetSystem : public TNetSystem {

friend class TXNetSystemConnectGuard;

private:
   Bool_t          fIsRootd;      // Nature of remote file server
   Bool_t          fIsXRootd;     // Nature of remote file server
   TString         fDir;          // Current directory
   void           *fDirp;         // Directory pointer
   VecStringVP_t   fDirList;      // Buffer for directory content
   TString         fDirEntry;     // Last dir entry
   TString         fUrl;          // Initial url

   static Bool_t   fgInitDone;    // Avoid initializing more than once
   static Bool_t   fgRootdBC;     // Control rootd backward compatibility

   XrdClientAdmin *Connect(const char *url); // Connect to server
   void           *GetDirPtr() const { return fDirp; }
   void            InitXrdClient();

   static THashList fgAddrFQDN;   // Cross-table address<->FQDN
   static THashList fgAdminHash;  // List of existing XrdClientAdmin
   static XrdClientAdmin *GetClientAdmin(const char *url);
   static TString GetKey(const char *url);

public:
   TXNetSystem(Bool_t owner = kTRUE);
   TXNetSystem(const char *url, Bool_t owner = kTRUE);
   virtual ~TXNetSystem() { }

   Bool_t              AccessPathName(const char *path, EAccessMode mode);
   virtual Bool_t      ConsistentWith(const char *path, void *dirptr);
   virtual void        FreeDirectory(void *dirp);
   virtual const char *GetDirEntry(void *dirp);
   virtual Int_t       GetPathInfo(const char* path, FileStat_t &buf);
   virtual Bool_t      IsPathLocal(const char *path);
   virtual Int_t       Locate(const char* path, TString &endurl);
   virtual Int_t       MakeDirectory(const char* dir);
   virtual void       *OpenDirectory(const char* dir);
   virtual int         Unlink(const char *path);

   // TXNetSystem specific
   Bool_t              GetPathsInfo(const char *paths, UChar_t *info);
   Bool_t              IsOnline(const char *path);
   Bool_t              Prepare(const char *path, UChar_t opt = 8, UChar_t prio = 0);
   Int_t               Prepare(TCollection *paths,
                               UChar_t opt = 8, UChar_t prio = 0, TString *buf = 0);

   ClassDef(TXNetSystem,0)   // System management class for xrootd servers
};

//
// Simple guard class for connections
//
class TXNetSystemConnectGuard {

private:
   XrdClientAdmin *fClientAdmin;  // Handle to the client admin object

public:
   TXNetSystemConnectGuard(TXNetSystem *xn, const char *url);
   ~TXNetSystemConnectGuard();

   bool IsValid() const { return ((fClientAdmin) ? 1 : 0); }

   XrdClientAdmin *ClientAdmin() const { return fClientAdmin; }

   void NotifyLastError();
};

#endif
 TXNetSystem.h:1
 TXNetSystem.h:2
 TXNetSystem.h:3
 TXNetSystem.h:4
 TXNetSystem.h:5
 TXNetSystem.h:6
 TXNetSystem.h:7
 TXNetSystem.h:8
 TXNetSystem.h:9
 TXNetSystem.h:10
 TXNetSystem.h:11
 TXNetSystem.h:12
 TXNetSystem.h:13
 TXNetSystem.h:14
 TXNetSystem.h:15
 TXNetSystem.h:16
 TXNetSystem.h:17
 TXNetSystem.h:18
 TXNetSystem.h:19
 TXNetSystem.h:20
 TXNetSystem.h:21
 TXNetSystem.h:22
 TXNetSystem.h:23
 TXNetSystem.h:24
 TXNetSystem.h:25
 TXNetSystem.h:26
 TXNetSystem.h:27
 TXNetSystem.h:28
 TXNetSystem.h:29
 TXNetSystem.h:30
 TXNetSystem.h:31
 TXNetSystem.h:32
 TXNetSystem.h:33
 TXNetSystem.h:34
 TXNetSystem.h:35
 TXNetSystem.h:36
 TXNetSystem.h:37
 TXNetSystem.h:38
 TXNetSystem.h:39
 TXNetSystem.h:40
 TXNetSystem.h:41
 TXNetSystem.h:42
 TXNetSystem.h:43
 TXNetSystem.h:44
 TXNetSystem.h:45
 TXNetSystem.h:46
 TXNetSystem.h:47
 TXNetSystem.h:48
 TXNetSystem.h:49
 TXNetSystem.h:50
 TXNetSystem.h:51
 TXNetSystem.h:52
 TXNetSystem.h:53
 TXNetSystem.h:54
 TXNetSystem.h:55
 TXNetSystem.h:56
 TXNetSystem.h:57
 TXNetSystem.h:58
 TXNetSystem.h:59
 TXNetSystem.h:60
 TXNetSystem.h:61
 TXNetSystem.h:62
 TXNetSystem.h:63
 TXNetSystem.h:64
 TXNetSystem.h:65
 TXNetSystem.h:66
 TXNetSystem.h:67
 TXNetSystem.h:68
 TXNetSystem.h:69
 TXNetSystem.h:70
 TXNetSystem.h:71
 TXNetSystem.h:72
 TXNetSystem.h:73
 TXNetSystem.h:74
 TXNetSystem.h:75
 TXNetSystem.h:76
 TXNetSystem.h:77
 TXNetSystem.h:78
 TXNetSystem.h:79
 TXNetSystem.h:80
 TXNetSystem.h:81
 TXNetSystem.h:82
 TXNetSystem.h:83
 TXNetSystem.h:84
 TXNetSystem.h:85
 TXNetSystem.h:86
 TXNetSystem.h:87
 TXNetSystem.h:88
 TXNetSystem.h:89
 TXNetSystem.h:90
 TXNetSystem.h:91
 TXNetSystem.h:92
 TXNetSystem.h:93
 TXNetSystem.h:94
 TXNetSystem.h:95
 TXNetSystem.h:96
 TXNetSystem.h:97
 TXNetSystem.h:98
 TXNetSystem.h:99
 TXNetSystem.h:100
 TXNetSystem.h:101
 TXNetSystem.h:102
 TXNetSystem.h:103
 TXNetSystem.h:104
 TXNetSystem.h:105
 TXNetSystem.h:106
 TXNetSystem.h:107
 TXNetSystem.h:108
 TXNetSystem.h:109
 TXNetSystem.h:110
 TXNetSystem.h:111
 TXNetSystem.h:112
 TXNetSystem.h:113
 TXNetSystem.h:114
 TXNetSystem.h:115
 TXNetSystem.h:116
 TXNetSystem.h:117
 TXNetSystem.h:118
 TXNetSystem.h:119
 TXNetSystem.h:120
 TXNetSystem.h:121
 TXNetSystem.h:122
 TXNetSystem.h:123
 TXNetSystem.h:124
 TXNetSystem.h:125
 TXNetSystem.h:126
 TXNetSystem.h:127