Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:40

0001 //------------------------------------------------------------------------------
0002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
0003 // Author: Lukasz Janyst <ljanyst@cern.ch>
0004 //------------------------------------------------------------------------------
0005 // XRootD is free software: you can redistribute it and/or modify
0006 // it under the terms of the GNU Lesser General Public License as published by
0007 // the Free Software Foundation, either version 3 of the License, or
0008 // (at your option) any later version.
0009 //
0010 // XRootD is distributed in the hope that it will be useful,
0011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 // GNU General Public License for more details.
0014 //
0015 // You should have received a copy of the GNU Lesser General Public License
0016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
0017 //------------------------------------------------------------------------------
0018 
0019 #ifndef __XRD_CL_XROOTD_RESPONSES_HH__
0020 #define __XRD_CL_XROOTD_RESPONSES_HH__
0021 
0022 #include "XrdCl/XrdClBuffer.hh"
0023 #include "XrdCl/XrdClStatus.hh"
0024 #include "XrdCl/XrdClURL.hh"
0025 #include "XrdCl/XrdClAnyObject.hh"
0026 #include "XProtocol/XProtocol.hh"
0027 
0028 #include <string>
0029 #include <vector>
0030 #include <list>
0031 #include <ctime>
0032 #include <tuple>
0033 #include <memory>
0034 #include <functional>
0035 
0036 #include <sys/uio.h>
0037 
0038 namespace XrdCl
0039 {
0040   //----------------------------------------------------------------------------
0041   //! Path location info
0042   //----------------------------------------------------------------------------
0043   class LocationInfo
0044   {
0045     public:
0046       //------------------------------------------------------------------------
0047       //! Describes the node type and file status for a given location
0048       //------------------------------------------------------------------------
0049       enum LocationType
0050       {
0051         ManagerOnline,   //!< manager node where the file is online
0052         ManagerPending,  //!< manager node where the file is pending to be online
0053         ServerOnline,    //!< server node where the file is online
0054         ServerPending    //!< server node where the file is pending to be online
0055       };
0056 
0057       //------------------------------------------------------------------------
0058       //! Describes the allowed access type for the file at given location
0059       //------------------------------------------------------------------------
0060       enum AccessType
0061       {
0062         Read,            //!< read access is allowed
0063         ReadWrite        //!< write access is allowed
0064       };
0065 
0066       //------------------------------------------------------------------------
0067       //! Location
0068       //------------------------------------------------------------------------
0069       class Location
0070       {
0071         public:
0072 
0073           //--------------------------------------------------------------------
0074           //! Constructor
0075           //--------------------------------------------------------------------
0076           Location( const std::string  &address,
0077                     LocationType        type,
0078                     AccessType          access ):
0079             pAddress( address ),
0080             pType( type ),
0081             pAccess( access ) {}
0082 
0083           //--------------------------------------------------------------------
0084           //! Get address
0085           //--------------------------------------------------------------------
0086           const std::string &GetAddress() const
0087           {
0088             return pAddress;
0089           }
0090 
0091           //--------------------------------------------------------------------
0092           //! Get location type
0093           //--------------------------------------------------------------------
0094           LocationType GetType() const
0095           {
0096             return pType;
0097           }
0098 
0099           //--------------------------------------------------------------------
0100           //! Get access type
0101           //--------------------------------------------------------------------
0102           AccessType GetAccessType() const
0103           {
0104             return pAccess;
0105           }
0106 
0107           //--------------------------------------------------------------------
0108           //! Check whether the location is a server
0109           //--------------------------------------------------------------------
0110           bool IsServer() const
0111           {
0112             return pType == ServerOnline || pType == ServerPending;
0113           }
0114 
0115           //--------------------------------------------------------------------
0116           //! Check whether the location is a manager
0117           //--------------------------------------------------------------------
0118           bool IsManager() const
0119           {
0120             return pType == ManagerOnline || pType == ManagerPending;
0121           }
0122 
0123         private:
0124           std::string  pAddress;
0125           LocationType pType;
0126           AccessType   pAccess;
0127       };
0128 
0129       //------------------------------------------------------------------------
0130       //! List of locations
0131       //------------------------------------------------------------------------
0132       typedef std::vector<Location>        LocationList;
0133 
0134       //------------------------------------------------------------------------
0135       //! Iterator over locations
0136       //------------------------------------------------------------------------
0137       typedef LocationList::iterator       Iterator;
0138 
0139       //------------------------------------------------------------------------
0140       //! Iterator over locations
0141       //------------------------------------------------------------------------
0142       typedef LocationList::const_iterator ConstIterator;
0143 
0144       //------------------------------------------------------------------------
0145       //! Constructor
0146       //------------------------------------------------------------------------
0147       LocationInfo();
0148 
0149       //------------------------------------------------------------------------
0150       //! Get number of locations
0151       //------------------------------------------------------------------------
0152       uint32_t GetSize() const
0153       {
0154         return pLocations.size();
0155       }
0156 
0157       //------------------------------------------------------------------------
0158       //! Get the location at index
0159       //------------------------------------------------------------------------
0160       Location &At( uint32_t index )
0161       {
0162         return pLocations[index];
0163       }
0164 
0165       //------------------------------------------------------------------------
0166       //! Get the location begin iterator
0167       //------------------------------------------------------------------------
0168       Iterator Begin()
0169       {
0170         return pLocations.begin();
0171       }
0172 
0173       //------------------------------------------------------------------------
0174       //! Get the location begin iterator
0175       //------------------------------------------------------------------------
0176       ConstIterator Begin() const
0177       {
0178         return pLocations.begin();
0179       }
0180 
0181       //------------------------------------------------------------------------
0182       //! Get the location end iterator
0183       //------------------------------------------------------------------------
0184       Iterator End()
0185       {
0186         return pLocations.end();
0187       }
0188 
0189       //------------------------------------------------------------------------
0190       //! Get the location end iterator
0191       //------------------------------------------------------------------------
0192       ConstIterator End() const
0193       {
0194         return pLocations.end();
0195       }
0196 
0197       //------------------------------------------------------------------------
0198       //! Add a location
0199       //------------------------------------------------------------------------
0200       void Add( const Location &location )
0201       {
0202         pLocations.push_back( location );
0203       }
0204 
0205       //------------------------------------------------------------------------
0206       //! Parse server response and fill up the object
0207       //------------------------------------------------------------------------
0208       bool ParseServerResponse( const char *data );
0209 
0210     private:
0211       bool ProcessLocation( std::string &location );
0212       LocationList pLocations;
0213   };
0214 
0215   //----------------------------------------------------------------------------
0216   //! Request status
0217   //----------------------------------------------------------------------------
0218   class XRootDStatus: public Status
0219   {
0220     public:
0221       //------------------------------------------------------------------------
0222       //! Constructor
0223       //------------------------------------------------------------------------
0224       XRootDStatus( uint16_t           st      = 0,
0225                     uint16_t           code    = 0,
0226                     uint32_t           errN    = 0,
0227                     const std::string &message = "" ):
0228         Status( st, code, errN ),
0229         pMessage( message ) {}
0230 
0231       //------------------------------------------------------------------------
0232       //! Constructor
0233       //------------------------------------------------------------------------
0234       XRootDStatus( const Status      &st,
0235                     const std::string &message = "" ):
0236         Status( st ),
0237         pMessage( message ) {}
0238 
0239       //------------------------------------------------------------------------
0240       //! Get error message
0241       //------------------------------------------------------------------------
0242       const std::string &GetErrorMessage() const
0243       {
0244         return pMessage;
0245       }
0246 
0247       //------------------------------------------------------------------------
0248       //! Set the error message
0249       //------------------------------------------------------------------------
0250       void SetErrorMessage( const std::string &message )
0251       {
0252         pMessage = message;
0253       }
0254 
0255       //------------------------------------------------------------------------
0256       //! Convert to string
0257       //------------------------------------------------------------------------
0258       std::string ToStr() const
0259       {
0260         if( code == errErrorResponse )
0261         {
0262           std::ostringstream o;
0263           o << "[ERROR] Server responded with an error: [" << errNo << "] ";
0264           o << pMessage << std::endl;
0265           return o.str();
0266         }
0267         std::string str = ToString();
0268         if( !pMessage.empty() )
0269           str += ": " + pMessage;
0270         return str;
0271       }
0272 
0273     private:
0274       std::string pMessage;
0275   };
0276 
0277   //----------------------------------------------------------------------------
0278   //! Tuple indexes of name and value fields in xattr_t
0279   //----------------------------------------------------------------------------
0280   enum
0281   {
0282     xattr_name  = 0,
0283     xattr_value = 1
0284   };
0285 
0286   //----------------------------------------------------------------------------
0287   //! Extended attribute key - value pair
0288   //----------------------------------------------------------------------------
0289   typedef std::tuple<std::string, std::string> xattr_t;
0290 
0291   //----------------------------------------------------------------------------
0292   //! Extended attribute operation status
0293   //----------------------------------------------------------------------------
0294   struct XAttrStatus
0295   {
0296       friend class FileStateHandler;
0297       friend class FileSystem;
0298 
0299       XAttrStatus( const std::string &name, const XRootDStatus &status ) :
0300         name( name ), status( status )
0301       {
0302 
0303       }
0304 
0305       std::string name;
0306       XRootDStatus status;
0307   };
0308 
0309   //----------------------------------------------------------------------------
0310   //! Extended attributes with status
0311   //----------------------------------------------------------------------------
0312   struct XAttr : public XAttrStatus
0313   {
0314       friend class FileStateHandler;
0315       friend class FileSystem;
0316 
0317       XAttr( const std::string  &name, const XRootDStatus &status ) :
0318         XAttrStatus( name, status )
0319       {
0320 
0321       }
0322 
0323       XAttr( const std::string  &name, const std::string &value = "",
0324              const XRootDStatus &status = XRootDStatus() ) :
0325         XAttrStatus( name, status ), value( value )
0326       {
0327 
0328       }
0329 
0330       std::string value;
0331   };
0332 
0333   //----------------------------------------------------------------------------
0334   //! Binary buffer
0335   //----------------------------------------------------------------------------
0336   typedef Buffer BinaryDataInfo;
0337 
0338   //----------------------------------------------------------------------------
0339   //! Protocol response
0340   //----------------------------------------------------------------------------
0341   class ProtocolInfo
0342   {
0343     public:
0344       //------------------------------------------------------------------------
0345       //! Types of XRootD servers
0346       //------------------------------------------------------------------------
0347       enum HostTypes
0348       {
0349         IsManager = kXR_isManager,   //!< Manager
0350         IsServer  = kXR_isServer,    //!< Data server
0351         AttrMeta  = kXR_attrMeta,    //!< Meta attribute
0352         AttrProxy = kXR_attrProxy,   //!< Proxy attribute
0353         AttrSuper = kXR_attrSuper    //!< Supervisor attribute
0354       };
0355 
0356       //------------------------------------------------------------------------
0357       //! Constructor
0358       //------------------------------------------------------------------------
0359       ProtocolInfo( uint32_t version, uint32_t hostInfo ):
0360         pVersion( version ), pHostInfo( hostInfo ) {}
0361 
0362       //------------------------------------------------------------------------
0363       //! Get version info
0364       //------------------------------------------------------------------------
0365       uint32_t GetVersion() const
0366       {
0367         return pVersion;
0368       }
0369 
0370       //------------------------------------------------------------------------
0371       //! Get host info
0372       //------------------------------------------------------------------------
0373       uint32_t GetHostInfo() const
0374       {
0375         return pHostInfo;
0376       }
0377 
0378       //------------------------------------------------------------------------
0379       //! Test host info flags
0380       //------------------------------------------------------------------------
0381       bool TestHostInfo( uint32_t flags )
0382       {
0383         return pHostInfo & flags;
0384       }
0385 
0386     private:
0387       uint32_t pVersion;
0388       uint32_t pHostInfo;
0389   };
0390 
0391   //----------------------------------------------------------------------------
0392   //! Object stat info implementation forward declaration
0393   //----------------------------------------------------------------------------
0394   struct StatInfoImpl;
0395 
0396   //----------------------------------------------------------------------------
0397   //! Object stat info
0398   //----------------------------------------------------------------------------
0399   class StatInfo
0400   {
0401     public:
0402       //------------------------------------------------------------------------
0403       //! Flags
0404       //------------------------------------------------------------------------
0405       enum Flags
0406       {
0407         XBitSet      = kXR_xset,      //!< Executable/searchable bit set
0408         IsDir        = kXR_isDir,     //!< This is a directory
0409         Other        = kXR_other,     //!< Neither a file nor a directory
0410         Offline      = kXR_offline,   //!< File is not online (ie. on disk)
0411         POSCPending  = kXR_poscpend,  //!< File opened with POST flag, not yet
0412                                       //!< successfully closed
0413         IsReadable   = kXR_readable,  //!< Read access is allowed
0414         IsWritable   = kXR_writable,  //!< Write access is allowed
0415         BackUpExists = kXR_bkpexist   //!< Back up copy exists
0416       };
0417 
0418       //------------------------------------------------------------------------
0419       //! Constructor
0420       //------------------------------------------------------------------------
0421       StatInfo();
0422 
0423       //------------------------------------------------------------------------
0424       //! Constructor
0425       //------------------------------------------------------------------------
0426       StatInfo( const std::string &id, uint64_t size, uint32_t flags,
0427                 uint64_t modTime );
0428 
0429       //------------------------------------------------------------------------
0430       //! Copy constructor
0431       //------------------------------------------------------------------------
0432       StatInfo( const StatInfo &info );
0433 
0434       //------------------------------------------------------------------------
0435       //! Destructor
0436       //------------------------------------------------------------------------
0437       ~StatInfo();
0438 
0439       //------------------------------------------------------------------------
0440       //! Get id
0441       //------------------------------------------------------------------------
0442       const std::string& GetId() const;
0443 
0444       //------------------------------------------------------------------------
0445       //! Get size (in bytes)
0446       //------------------------------------------------------------------------
0447       uint64_t GetSize() const;
0448 
0449       //------------------------------------------------------------------------
0450       //! Set size
0451       //------------------------------------------------------------------------
0452       void SetSize( uint64_t size );
0453 
0454       //------------------------------------------------------------------------
0455       //! Get flags
0456       //------------------------------------------------------------------------
0457       uint32_t GetFlags() const;
0458 
0459       //------------------------------------------------------------------------
0460       //! Set flags
0461       //------------------------------------------------------------------------
0462       void SetFlags( uint32_t flags );
0463 
0464       //------------------------------------------------------------------------
0465       //! Test flags
0466       //------------------------------------------------------------------------
0467       bool TestFlags( uint32_t flags ) const;
0468 
0469       //------------------------------------------------------------------------
0470       //! Get modification time (in seconds since epoch)
0471       //------------------------------------------------------------------------
0472       uint64_t GetModTime() const;
0473 
0474       //------------------------------------------------------------------------
0475       //! Get modification time
0476       //------------------------------------------------------------------------
0477       std::string GetModTimeAsString() const;
0478 
0479       //------------------------------------------------------------------------
0480       //! Get change time (in seconds since epoch)
0481       //------------------------------------------------------------------------
0482       uint64_t GetChangeTime() const;
0483 
0484       //------------------------------------------------------------------------
0485       //! Get change time
0486       //------------------------------------------------------------------------
0487       std::string GetChangeTimeAsString() const;
0488 
0489       //------------------------------------------------------------------------
0490       //! Get change time (in seconds since epoch)
0491       //------------------------------------------------------------------------
0492       uint64_t GetAccessTime() const;
0493 
0494       //------------------------------------------------------------------------
0495       //! Get change time
0496       //------------------------------------------------------------------------
0497       std::string GetAccessTimeAsString() const;
0498 
0499       //------------------------------------------------------------------------
0500       //! Get mode
0501       //------------------------------------------------------------------------
0502       const std::string& GetModeAsString() const;
0503 
0504       //------------------------------------------------------------------------
0505       //! Get mode
0506       //------------------------------------------------------------------------
0507       const std::string GetModeAsOctString() const;
0508 
0509       //------------------------------------------------------------------------
0510       //! Get owner
0511       //------------------------------------------------------------------------
0512       const std::string& GetOwner() const;
0513 
0514       //------------------------------------------------------------------------
0515       //! Get group
0516       //------------------------------------------------------------------------
0517       const std::string& GetGroup() const;
0518 
0519       //------------------------------------------------------------------------
0520       //! Get checksum
0521       //------------------------------------------------------------------------
0522       const std::string& GetChecksum() const;
0523 
0524       //------------------------------------------------------------------------
0525       //! Parse server response and fill up the object
0526       //------------------------------------------------------------------------
0527       bool ParseServerResponse( const char *data );
0528 
0529       //------------------------------------------------------------------------
0530       //! Has extended stat information
0531       //------------------------------------------------------------------------
0532       bool ExtendedFormat() const;
0533 
0534       //------------------------------------------------------------------------
0535       //! Has checksum
0536       //------------------------------------------------------------------------
0537       bool HasChecksum() const;
0538 
0539     private:
0540 
0541       static inline std::string TimeToString( uint64_t time )
0542       {
0543         char ts[256];
0544         time_t modTime = time;
0545         tm *t = gmtime( &modTime );
0546         strftime( ts, 255, "%F %T", t );
0547         return ts;
0548       }
0549 
0550       static inline void OctToString( uint8_t oct, std::string &str )
0551       {
0552         static const uint8_t r_mask = 0x4;
0553         static const uint8_t w_mask = 0x2;
0554         static const uint8_t x_mask = 0x1;
0555 
0556         if( r_mask & oct ) str.push_back( 'r' );
0557         else str.push_back( '-' );
0558 
0559         if( w_mask & oct ) str.push_back( 'w' );
0560         else str.push_back( '-' );
0561 
0562         if( x_mask & oct ) str.push_back( 'x' );
0563         else str.push_back( '-' );
0564       }
0565 
0566       std::unique_ptr<StatInfoImpl> pImpl;
0567   };
0568 
0569   //----------------------------------------------------------------------------
0570   //! VFS stat info
0571   //----------------------------------------------------------------------------
0572   class StatInfoVFS
0573   {
0574     public:
0575       //------------------------------------------------------------------------
0576       //! Constructor
0577       //------------------------------------------------------------------------
0578       StatInfoVFS();
0579 
0580       //------------------------------------------------------------------------
0581       //! Get number of nodes that can provide read/write space
0582       //------------------------------------------------------------------------
0583       uint64_t GetNodesRW() const
0584       {
0585         return pNodesRW;
0586       }
0587 
0588       //------------------------------------------------------------------------
0589       //! Get size of the largest contiguous area of free r/w space (in MB)
0590       //------------------------------------------------------------------------
0591       uint64_t GetFreeRW() const
0592       {
0593         return pFreeRW;
0594       }
0595 
0596       //------------------------------------------------------------------------
0597       //! Get percentage of the partition utilization represented by FreeRW
0598       //------------------------------------------------------------------------
0599       uint8_t GetUtilizationRW() const
0600       {
0601         return pUtilizationRW;
0602       }
0603 
0604       //------------------------------------------------------------------------
0605       //! Get number of nodes that can provide staging space
0606       //------------------------------------------------------------------------
0607       uint64_t GetNodesStaging() const
0608       {
0609         return pNodesStaging;
0610       }
0611 
0612       //------------------------------------------------------------------------
0613       //! Get size of the largest contiguous area of free staging space (in MB)
0614       //------------------------------------------------------------------------
0615       uint64_t GetFreeStaging() const
0616       {
0617         return pFreeStaging;
0618       }
0619 
0620       //------------------------------------------------------------------------
0621       //! Get percentage of the partition utilization represented by FreeStaging
0622       //------------------------------------------------------------------------
0623       uint8_t GetUtilizationStaging() const
0624       {
0625         return pUtilizationStaging;
0626       }
0627 
0628       //------------------------------------------------------------------------
0629       //! Parse server response and fill up the object
0630       //------------------------------------------------------------------------
0631       bool ParseServerResponse( const char *data );
0632 
0633     private:
0634 
0635       //------------------------------------------------------------------------
0636       // kXR_vfs stat
0637       //------------------------------------------------------------------------
0638       uint64_t    pNodesRW;
0639       uint64_t    pFreeRW;
0640       uint32_t    pUtilizationRW;
0641       uint64_t    pNodesStaging;
0642       uint64_t    pFreeStaging;
0643       uint32_t    pUtilizationStaging;
0644   };
0645 
0646   //----------------------------------------------------------------------------
0647   //! Directory list
0648   //----------------------------------------------------------------------------
0649   class DirectoryList
0650   {
0651     public:
0652 
0653       //------------------------------------------------------------------------
0654       //! Directory entry
0655       //------------------------------------------------------------------------
0656       class ListEntry
0657       {
0658         public:
0659           //--------------------------------------------------------------------
0660           //! Constructor
0661           //--------------------------------------------------------------------
0662           ListEntry( const std::string &hostAddress,
0663                      const std::string &name,
0664                      StatInfo          *statInfo = 0):
0665             pHostAddress( hostAddress ),
0666             pName( SanitizeName( name ) ),
0667             pStatInfo( statInfo )
0668           {}
0669 
0670           //--------------------------------------------------------------------
0671           //! Destructor
0672           //--------------------------------------------------------------------
0673           ~ListEntry()
0674           {
0675             delete pStatInfo;
0676           }
0677 
0678           //--------------------------------------------------------------------
0679           //! Get host address
0680           //--------------------------------------------------------------------
0681           const std::string &GetHostAddress() const
0682           {
0683             return pHostAddress;
0684           }
0685 
0686           //--------------------------------------------------------------------
0687           //! Get file name
0688           //--------------------------------------------------------------------
0689           const std::string &GetName() const
0690           {
0691             return pName;
0692           }
0693 
0694           //--------------------------------------------------------------------
0695           //! Get the stat info object
0696           //--------------------------------------------------------------------
0697           StatInfo *GetStatInfo()
0698           {
0699             return pStatInfo;
0700           }
0701 
0702           //--------------------------------------------------------------------
0703           //! Get the stat info object
0704           //--------------------------------------------------------------------
0705           const StatInfo *GetStatInfo() const
0706           {
0707             return pStatInfo;
0708           }
0709 
0710           //--------------------------------------------------------------------
0711           //! Set the stat info object (and transfer the ownership)
0712           //--------------------------------------------------------------------
0713           void SetStatInfo( StatInfo *info )
0714           {
0715             pStatInfo = info;
0716           }
0717 
0718         private:
0719 
0720           inline static std::string SanitizeName( const std::string &name )
0721           {
0722             const char *cstr = name.c_str();
0723             while( *cstr == '/' ) // the C string is guaranteed to end with '\0'
0724               ++cstr;
0725             return cstr;
0726           }
0727 
0728           std::string  pHostAddress;
0729           std::string  pName;
0730           StatInfo    *pStatInfo;
0731       };
0732 
0733       //------------------------------------------------------------------------
0734       //! Constructor
0735       //------------------------------------------------------------------------
0736       DirectoryList();
0737 
0738       //------------------------------------------------------------------------
0739       //! Destructor
0740       //------------------------------------------------------------------------
0741       ~DirectoryList();
0742 
0743       //------------------------------------------------------------------------
0744       //! Directory listing
0745       //------------------------------------------------------------------------
0746       typedef std::vector<ListEntry*>  DirList;
0747 
0748       //------------------------------------------------------------------------
0749       //! Directory listing iterator
0750       //------------------------------------------------------------------------
0751       typedef DirList::iterator       Iterator;
0752 
0753       //------------------------------------------------------------------------
0754       //! Directory listing const iterator
0755       //------------------------------------------------------------------------
0756       typedef DirList::const_iterator ConstIterator;
0757 
0758       //------------------------------------------------------------------------
0759       //! Add an entry to the list - takes ownership
0760       //------------------------------------------------------------------------
0761       void Add( ListEntry *entry )
0762       {
0763         pDirList.push_back( entry );
0764       }
0765 
0766       //------------------------------------------------------------------------
0767       //! Get an entry at given index
0768       //------------------------------------------------------------------------
0769       ListEntry *At( uint32_t index )
0770       {
0771         return pDirList[index];
0772       }
0773 
0774       //------------------------------------------------------------------------
0775       //! Get the begin iterator
0776       //------------------------------------------------------------------------
0777       Iterator Begin()
0778       {
0779         return pDirList.begin();
0780       }
0781 
0782       //------------------------------------------------------------------------
0783       //! Get the begin iterator
0784       //------------------------------------------------------------------------
0785       ConstIterator Begin() const
0786       {
0787         return pDirList.begin();
0788       }
0789 
0790       //------------------------------------------------------------------------
0791       //! Get the end iterator
0792       //------------------------------------------------------------------------
0793       Iterator End()
0794       {
0795         return pDirList.end();
0796       }
0797 
0798       //------------------------------------------------------------------------
0799       //! Get the end iterator
0800       //------------------------------------------------------------------------
0801       ConstIterator End() const
0802       {
0803         return pDirList.end();
0804       }
0805 
0806       //------------------------------------------------------------------------
0807       //! Get the size of the listing
0808       //------------------------------------------------------------------------
0809       uint32_t GetSize() const
0810       {
0811         return pDirList.size();
0812       }
0813 
0814       //------------------------------------------------------------------------
0815       //! Get parent directory name
0816       //------------------------------------------------------------------------
0817       const std::string &GetParentName() const
0818       {
0819         return pParent;
0820       }
0821 
0822       //------------------------------------------------------------------------
0823       //! Set name of the parent directory
0824       //------------------------------------------------------------------------
0825       void SetParentName( const std::string &parent )
0826       {
0827         size_t pos = parent.find( '?' );
0828         pParent = pos == std::string::npos ? parent : parent.substr( 0, pos );
0829         if( !pParent.empty() && pParent[pParent.length()-1] != '/' )
0830           pParent += "/";
0831       }
0832 
0833       //------------------------------------------------------------------------
0834       //! Parse server response and fill up the object
0835       //------------------------------------------------------------------------
0836       bool ParseServerResponse( const std::string &hostId,
0837                                 const char *data );
0838 
0839       //------------------------------------------------------------------------
0840       //! Parse chunked server response and fill up the object
0841       //------------------------------------------------------------------------
0842       bool ParseServerResponse( const std::string &hostId,
0843                                 const char *data,
0844                                 bool isDStat );
0845 
0846       //------------------------------------------------------------------------
0847       //! Returns true if data contain stat info
0848       //------------------------------------------------------------------------
0849       static bool HasStatInfo( const char *data );
0850 
0851     private:
0852       DirList     pDirList;
0853       std::string pParent;
0854 
0855       static const std::string dStatPrefix;
0856   };
0857 
0858   //----------------------------------------------------------------------------
0859   //! Information returned by file open operation
0860   //----------------------------------------------------------------------------
0861   class OpenInfo
0862   {
0863     public:
0864       //------------------------------------------------------------------------
0865       //! Constructor
0866       //------------------------------------------------------------------------
0867       OpenInfo( const uint8_t *fileHandle,
0868                 uint64_t       sessionId,
0869                 StatInfo *statInfo        = 0 ):
0870         pSessionId(sessionId), pStatInfo( statInfo )
0871       {
0872         memcpy( pFileHandle, fileHandle, 4 );
0873       }
0874 
0875       //------------------------------------------------------------------------
0876       //! Destructor
0877       //------------------------------------------------------------------------
0878       ~OpenInfo()
0879       {
0880         delete pStatInfo;
0881       }
0882 
0883       //------------------------------------------------------------------------
0884       //! Get the file handle (4bytes)
0885       //------------------------------------------------------------------------
0886       void GetFileHandle( uint8_t *fileHandle ) const
0887       {
0888         memcpy( fileHandle, pFileHandle, 4 );
0889       }
0890 
0891       //------------------------------------------------------------------------
0892       //! Get the stat info
0893       //------------------------------------------------------------------------
0894       const StatInfo *GetStatInfo() const
0895       {
0896         return pStatInfo;
0897       }
0898 
0899       //------------------------------------------------------------------------
0900       // Get session ID
0901       //------------------------------------------------------------------------
0902       uint64_t GetSessionId() const
0903       {
0904         return pSessionId;
0905       }
0906 
0907     private:
0908       uint8_t   pFileHandle[4];
0909       uint64_t  pSessionId;
0910       StatInfo *pStatInfo;
0911   };
0912 
0913   //----------------------------------------------------------------------------
0914   //! Describe a data chunk for vector read
0915   //----------------------------------------------------------------------------
0916   struct ChunkInfo
0917   {
0918     //--------------------------------------------------------------------------
0919     //! Constructor
0920     //--------------------------------------------------------------------------
0921     ChunkInfo( uint64_t off = 0, uint32_t len = 0, void *buff = 0 ):
0922       offset( off ), length( len ), buffer(buff) {}
0923 
0924     //----------------------------------------------------------------------------
0925     //! Get the offset
0926     //----------------------------------------------------------------------------
0927     inline uint64_t GetOffset() const
0928     {
0929       return offset;
0930     }
0931 
0932     //----------------------------------------------------------------------------
0933     //! Get the data length
0934     //----------------------------------------------------------------------------
0935     inline uint32_t GetLength() const
0936     {
0937       return length;
0938     }
0939 
0940     //----------------------------------------------------------------------------
0941     //! Get the buffer
0942     //----------------------------------------------------------------------------
0943     inline void* GetBuffer()
0944     {
0945       return buffer;
0946     }
0947 
0948     uint64_t  offset; //! offset in the file
0949     uint32_t  length; //! length of the chunk
0950     void     *buffer; //! optional buffer pointer
0951   };
0952 
0953   struct PageInfoImpl;
0954 
0955   struct PageInfo
0956   {
0957     //----------------------------------------------------------------------------
0958     //! Default constructor
0959     //----------------------------------------------------------------------------
0960     PageInfo( uint64_t offset = 0, uint32_t length = 0, void *buffer = 0,
0961               std::vector<uint32_t> &&cksums = std::vector<uint32_t>() );
0962 
0963     //----------------------------------------------------------------------------
0964     //! Move constructor
0965     //----------------------------------------------------------------------------
0966     PageInfo( PageInfo &&pginf );
0967 
0968     //----------------------------------------------------------------------------
0969     //! Move assigment operator
0970     //----------------------------------------------------------------------------
0971     PageInfo& operator=( PageInfo &&pginf );
0972 
0973     //----------------------------------------------------------------------------
0974     //! Destructor
0975     //----------------------------------------------------------------------------
0976     ~PageInfo();
0977 
0978     //----------------------------------------------------------------------------
0979     //! Get the offset
0980     //----------------------------------------------------------------------------
0981     uint64_t GetOffset() const;
0982 
0983     //----------------------------------------------------------------------------
0984     //! Get the data length
0985     //----------------------------------------------------------------------------
0986     uint32_t GetLength() const;
0987 
0988     //----------------------------------------------------------------------------
0989     //! Get the buffer
0990     //----------------------------------------------------------------------------
0991     void* GetBuffer();
0992 
0993     //----------------------------------------------------------------------------
0994     //! Get the checksums
0995     //----------------------------------------------------------------------------
0996     std::vector<uint32_t>& GetCksums();
0997 
0998     //----------------------------------------------------------------------------
0999     //! Get number of repaired pages
1000     //----------------------------------------------------------------------------
1001     size_t GetNbRepair();
1002 
1003     //----------------------------------------------------------------------------
1004     //! Set number of repaired pages
1005     //----------------------------------------------------------------------------
1006     void SetNbRepair( size_t nbrepair );
1007 
1008     private:
1009       //--------------------------------------------------------------------------
1010       //! pointer to implementation
1011       //--------------------------------------------------------------------------
1012       std::unique_ptr<PageInfoImpl> pImpl;
1013   };
1014 
1015   struct RetryInfoImpl;
1016 
1017   struct RetryInfo
1018   {
1019     //----------------------------------------------------------------------------
1020     //! Constructor
1021     //----------------------------------------------------------------------------
1022     RetryInfo( std::vector<std::tuple<uint64_t, uint32_t>> && retries );
1023 
1024     //----------------------------------------------------------------------------
1025     //! Destructor
1026     //----------------------------------------------------------------------------
1027     ~RetryInfo();
1028 
1029     //----------------------------------------------------------------------------
1030     //! @return : true if some pages need retrying, false otherwise
1031     //----------------------------------------------------------------------------
1032     bool NeedRetry();
1033 
1034     //----------------------------------------------------------------------------
1035     //! @return number of pages that need to be retransmitted
1036     //----------------------------------------------------------------------------
1037     size_t Size();
1038 
1039     //----------------------------------------------------------------------------
1040     //! @return : offset and size of respective page that requires to be
1041     //            retransmitted
1042     //----------------------------------------------------------------------------
1043     std::tuple<uint64_t, uint32_t> At( size_t i );
1044 
1045     private:
1046       //--------------------------------------------------------------------------
1047       //! pointer to implementation
1048       //--------------------------------------------------------------------------
1049       std::unique_ptr<RetryInfoImpl> pImpl;
1050   };
1051 
1052   //----------------------------------------------------------------------------
1053   //! List of chunks
1054   //----------------------------------------------------------------------------
1055   typedef std::vector<ChunkInfo> ChunkList;
1056 
1057   //----------------------------------------------------------------------------
1058   //! Vector read info
1059   //----------------------------------------------------------------------------
1060   class VectorReadInfo
1061   {
1062     public:
1063       //------------------------------------------------------------------------
1064       //! Constructor
1065       //------------------------------------------------------------------------
1066       VectorReadInfo(): pSize( 0 ) {}
1067 
1068       //------------------------------------------------------------------------
1069       //! Get Size
1070       //------------------------------------------------------------------------
1071       uint32_t GetSize() const
1072       {
1073         return pSize;
1074       }
1075 
1076       //------------------------------------------------------------------------
1077       //! Set size
1078       //------------------------------------------------------------------------
1079       void SetSize( uint32_t size )
1080       {
1081         pSize = size;
1082       }
1083 
1084       //------------------------------------------------------------------------
1085       //! Get chunks
1086       //------------------------------------------------------------------------
1087       ChunkList &GetChunks()
1088       {
1089         return pChunks;
1090       }
1091 
1092       //------------------------------------------------------------------------
1093       //! Get chunks
1094       //------------------------------------------------------------------------
1095       const ChunkList &GetChunks() const
1096       {
1097         return pChunks;
1098       }
1099 
1100     private:
1101       ChunkList pChunks;
1102       uint32_t  pSize;
1103   };
1104 
1105   //----------------------------------------------------------------------------
1106   // List of URLs
1107   //----------------------------------------------------------------------------
1108   struct HostInfo
1109   {
1110     HostInfo():
1111       flags(0), protocol(0), loadBalancer(false) {}
1112     HostInfo( const URL &u, bool lb = false ):
1113       flags(0), protocol(0), loadBalancer(lb), url(u) {}
1114     uint32_t flags;        //!< Host type
1115     uint32_t protocol;     //!< Version of the protocol the host is speaking
1116     bool     loadBalancer; //!< Was the host used as a load balancer
1117     URL      url;          //!< URL of the host
1118   };
1119 
1120   typedef std::vector<HostInfo> HostList;
1121 
1122   //----------------------------------------------------------------------------
1123   //! Handle an async response
1124   //----------------------------------------------------------------------------
1125   class ResponseHandler
1126   {
1127     public:
1128       virtual ~ResponseHandler() {}
1129 
1130       //------------------------------------------------------------------------
1131       //! Called when a response to associated request arrives or an error
1132       //! occurs
1133       //!
1134       //! @param status   status of the request
1135       //! @param response an object associated with the response
1136       //!                 (request dependent)
1137       //! @param hostList list of hosts the request was redirected to
1138       //------------------------------------------------------------------------
1139       virtual void HandleResponseWithHosts( XRootDStatus *status,
1140                                             AnyObject    *response,
1141                                             HostList     *hostList )
1142       {
1143         delete hostList;
1144         HandleResponse( status, response );
1145       }
1146 
1147       //------------------------------------------------------------------------
1148       //! Called when a response to associated request arrives or an error
1149       //! occurs
1150       //!
1151       //! @param status   status of the request
1152       //! @param response an object associated with the response
1153       //!                 (request dependent)
1154       //------------------------------------------------------------------------
1155       virtual void HandleResponse( XRootDStatus *status,
1156                                    AnyObject    *response )
1157       {
1158         (void)status; (void)response;
1159       }
1160 
1161       //------------------------------------------------------------------------
1162       //! Factory function for generating handler objects from lambdas
1163       //!
1164       //! @param func : the callback, must not throw
1165       //! @return     : ResponseHandler wrapper with the user callback
1166       //------------------------------------------------------------------------
1167       static ResponseHandler* Wrap( std::function<void(XRootDStatus&, AnyObject&)> func );
1168 
1169       //------------------------------------------------------------------------
1170       //! Factory function for generating handler objects from lambdas
1171       //!
1172       //! @param func : the callback, must not throw
1173       //! @return     : ResponseHandler wrapper with the user callback
1174       //------------------------------------------------------------------------
1175       static ResponseHandler* Wrap( std::function<void(XRootDStatus*, AnyObject*)> func );
1176   };
1177 }
1178 
1179 #endif // __XRD_CL_XROOTD_RESPONSES_HH__