00001 /* 00002 * XrdClMetalinkRedirector.hh 00003 * 00004 * Created on: May 2, 2016 00005 * Author: simonm 00006 */ 00007 00008 #ifndef SRC_XRDCL_XRDCLMETALINKREDIRECTOR_HH_ 00009 #define SRC_XRDCL_XRDCLMETALINKREDIRECTOR_HH_ 00010 00011 #include "XrdCl/XrdClMessageUtils.hh" 00012 #include "XrdCl/XrdClRedirectorRegistry.hh" 00013 00014 #include <string> 00015 #include <list> 00016 #include <map> 00017 00018 00019 class XrdOucFileInfo; 00020 00021 namespace XrdCl 00022 { 00023 00024 class File; 00025 class Message; 00026 00027 //---------------------------------------------------------------------------- 00030 //---------------------------------------------------------------------------- 00031 class MetalinkRedirector : public VirtualRedirector 00032 { 00033 friend class MetalinkOpenHandler; 00034 friend class MetalinkReadHandler; 00035 00036 public: 00037 //---------------------------------------------------------------------------- 00041 //---------------------------------------------------------------------------- 00042 MetalinkRedirector( const std::string &url ); 00043 00044 //---------------------------------------------------------------------------- 00046 //---------------------------------------------------------------------------- 00047 virtual ~MetalinkRedirector(); 00048 00049 //---------------------------------------------------------------------------- 00051 //---------------------------------------------------------------------------- 00052 XRootDStatus Load( ResponseHandler *userHandler ); 00053 00054 //---------------------------------------------------------------------------- 00058 //---------------------------------------------------------------------------- 00059 XRootDStatus HandleRequest( const Message *msg, IncomingMsgHandler *handler ); 00060 00061 //---------------------------------------------------------------------------- 00063 //---------------------------------------------------------------------------- 00064 std::string GetTargetName() const 00065 { 00066 return pTarget; 00067 } 00068 00069 //---------------------------------------------------------------------------- 00072 //---------------------------------------------------------------------------- 00073 std::string GetCheckSum( const std::string &type ) const 00074 { 00075 std::string t = type != "adler32" ? type : "a32"; 00076 CksumMap::const_iterator it = pChecksums.find( t ); 00077 if( it == pChecksums.end() ) return std::string(); 00078 return type + ":" + it->second; 00079 } 00080 00081 //---------------------------------------------------------------------------- 00084 //---------------------------------------------------------------------------- 00085 std::vector<std::string> GetSupportedCheckSums() const 00086 { 00087 std::vector<std::string> ret; 00088 CksumMap::const_iterator itr = pChecksums.begin(); 00089 for( ; itr != pChecksums.end(); ++itr ) 00090 { 00091 if( itr->first == "a32" ) ret.push_back( "adler32" ); 00092 else ret.push_back( itr->first ); 00093 } 00094 return std::move( ret ); 00095 } 00096 00097 //---------------------------------------------------------------------------- 00100 //---------------------------------------------------------------------------- 00101 long long GetSize() const 00102 { 00103 return pFileSize; 00104 } 00105 00106 //---------------------------------------------------------------------------- 00108 //---------------------------------------------------------------------------- 00109 const std::vector<std::string>& GetReplicas() 00110 { 00111 return pReplicas; 00112 } 00113 00114 //---------------------------------------------------------------------------- 00116 //---------------------------------------------------------------------------- 00117 virtual int Count( Message *req ) const; 00118 00119 private: 00120 00121 //---------------------------------------------------------------------------- 00126 //---------------------------------------------------------------------------- 00127 XRootDStatus HandleRequestImpl( const Message *msg, IncomingMsgHandler *handler ); 00128 00129 //---------------------------------------------------------------------------- 00132 //---------------------------------------------------------------------------- 00133 XRootDStatus Parse( const std::string &metalink ); 00134 00135 //---------------------------------------------------------------------------- 00140 //---------------------------------------------------------------------------- 00141 void FinalizeInitialization( const XRootDStatus &status = XRootDStatus() ); 00142 00143 //---------------------------------------------------------------------------- 00145 //---------------------------------------------------------------------------- 00146 Message* GetResponse( const Message *msg ) const; 00147 00148 //---------------------------------------------------------------------------- 00150 //---------------------------------------------------------------------------- 00151 Message* GetErrorMsg( const Message *msg, const std::string &errMsg, XErrorCode code ) const; 00152 00153 //---------------------------------------------------------------------------- 00155 //---------------------------------------------------------------------------- 00156 void InitCksum( XrdOucFileInfo **fileInfos ); 00157 00158 //---------------------------------------------------------------------------- 00160 //---------------------------------------------------------------------------- 00161 void InitReplicas( XrdOucFileInfo **fileInfos ); 00162 00163 //---------------------------------------------------------------------------- 00165 //---------------------------------------------------------------------------- 00166 XRootDStatus GetReplica( const Message *msg, std::string &replica ) const; 00167 00168 //---------------------------------------------------------------------------- 00170 //---------------------------------------------------------------------------- 00171 XRootDStatus GetCgiInfo( const Message *msg, const std::string &key, std::string &out ) const; 00172 00173 typedef std::list< std::pair<const Message*, IncomingMsgHandler*> > RedirectList; 00174 typedef std::map<std::string, std::string> CksumMap; 00175 typedef std::vector<std::string> ReplicaList; 00176 00177 //---------------------------------------------------------------------------- 00179 //---------------------------------------------------------------------------- 00180 ReplicaList::const_iterator GetReplica( const Message *msg ) const; 00181 00182 RedirectList pPendingRedirects; 00183 std::string pUrl; 00184 File *pFile; 00185 CksumMap pChecksums; 00186 ReplicaList pReplicas; 00187 bool pReady; 00188 XRootDStatus pStatus; 00189 std::string pTarget; 00190 long long pFileSize; 00191 00192 XrdSysMutex pMutex; 00193 00194 static const std::string LocalFile; 00195 00196 }; 00197 00198 } /* namespace XrdCl */ 00199 00200 #endif /* SRC_XRDCL_XRDCLMETALINKREDIRECTOR_HH_ */