Changeset 3548
- Timestamp:
- 10/19/2009 06:26:20 PM (1 month ago)
- Files:
-
- XrdCmsTfc/Makefile.am (modified) (1 diff)
- XrdCmsTfc/XrdCmsTfc.cc (modified) (12 diffs)
- XrdCmsTfc/XrdCmsTfc.hh (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
XrdCmsTfc/Makefile.am
r3547 r3548 20 20 XrdCmsTfc.cc XrdCmsTfc.hh 21 21 22 libXrd Hdfs_la_LDFLAGS = -lxerces-c22 libXrdCmsTfc_la_LDFLAGS = -lxerces-c -lpcre 23 23 XrdCmsTfc/XrdCmsTfc.cc
r3547 r3548 34 34 const char *parms, const char *lroot, const char *rroot) 35 35 { 36 TrivialFileCatalog *myTFC = new TrivialFileCatalog(eDest, "/tmp/test");37 36 eDest->Say("Copr. 2009 University of Nebraska-Lincoln TFC plugin v 1.0"); 38 37 39 eDest->Say("Params: " );40 eDest->Say(parms);38 eDest->Say("Params: ", parms); 39 TrivialFileCatalog *myTFC = new TrivialFileCatalog(eDest, parms); 41 40 42 41 return myTFC; … … 70 69 return buff; 71 70 } 71 72 int XrdCmsTfc::TrivialFileCatalog::s_numberOfInstances = 0; 73 XrdCmsTfc::TrivialFileCatalog::TrivialFileCatalog(XrdSysError *lp, const char * tfc_file) : XrdOucName2Name(), m_destination("any") { 74 m_url = tfc_file; 75 eDest = lp; 76 try { 77 if (s_numberOfInstances==0) { 78 XMLPlatformUtils::Initialize(); 79 eDest->Say("Xerces-c has been initialized."); 80 } 81 } catch (const XMLException& e) { 82 eDest->Say("Xerces-c error in initialization. Exception message is " 83 , _toChar(e.getMessage())); 84 } 85 ++s_numberOfInstances; 86 87 parse(); 88 } 72 89 73 90 void XrdCmsTfc::TrivialFileCatalog::freeProtocolRules(ProtocolRules protRules) { … … 125 142 int erroffset; 126 143 rule.pathMatch = NULL; 144 rule.pathMatchStr = pathMatchRegexp; 127 145 rule.destinationMatch = NULL; 146 rule.destinationMatchStr = destinationMatchRegexp; 128 147 rule.pathMatch = pcre_compile(pathMatchRegexp, 0, &error, &erroffset, NULL); 129 148 if (rule.pathMatch == NULL) { … … 145 164 rule.result = result; 146 165 rule.chain = chain; 147 rules[protocol].push_back (rule);166 rules[protocol].push_back(rule); 148 167 return 0; 149 168 } … … 205 224 std::ifstream configFile; 206 225 configFile.open(m_filename.c_str()); 207 eDest->Say("Using catalog configuration", m_filename.c_str());226 eDest->Say("Using catalog file ", m_filename.c_str()); 208 227 209 228 if (!configFile.good() || !configFile.is_open()) … … 214 233 215 234 configFile.close(); 216 217 XercesDOMParser* parser = new XercesDOMParser ;235 236 XercesDOMParser* parser = new XercesDOMParser(); 218 237 parser->setValidationScheme(XercesDOMParser::Val_Auto); 219 238 parser->setDoNamespaces(false); 220 parser->parse(m_filename.c_str()); 239 parser->parse(m_filename.c_str()); 221 240 DOMDocument* doc = parser->getDocument(); 222 241 assert(doc); … … 235 254 236 255 /*first of all do the lfn-to-pfn bit*/ 256 237 257 { 238 258 DOMNodeList *rules =doc->getElementsByTagName(_toDOMS("lfn-to-pfn")); … … 301 321 } 302 322 303 323 int XrdCmsTfc::TrivialFileCatalog::lfn2rfn(const char *lfn, char *buff, int blen) { 324 325 return lfn2pfn(lfn, buff, blen); 326 327 } 304 328 305 329 std::string replace(const std::string inputString, pcre * re, std::string replacementString) { … … 376 400 377 401 const ProtocolRules::const_iterator rulesIterator = protocolRules.find (protocol); 378 if (rulesIterator == protocolRules.end ())402 if (rulesIterator == protocolRules.end()) 379 403 return ""; 380 404 … … 388 412 int ovector[OVECCOUNT]; 389 413 int rc=0; 390 pcre_exec(i->destinationMatch, NULL, destination.c_str(), destination.length(), 0, 0, ovector, OVECCOUNT);391 if (rc < 0) 414 rc = pcre_exec(i->destinationMatch, NULL, destination.c_str(), destination.length(), 0, 0, ovector, OVECCOUNT); 415 if (rc < 0) { 392 416 continue; 393 394 pcre_exec(i->pathMatch, NULL, name.c_str(), name.length(), 0, 0, ovector, OVECCOUNT); 395 if (rc < 0) 417 } else { 418 std::cerr << "Destination did match; my destination " << destination << ", regexp: " << i->destinationMatchStr << std::endl; 419 } 420 421 rc = pcre_exec(i->pathMatch, NULL, name.c_str(), name.length(), 0, 0, ovector, OVECCOUNT); 422 if (rc < 0) { 396 423 continue; 397 398 std::cerr << "Rule matched! " << std::endl; 424 } else { 425 std::cerr << "Path did match; my path " << name << ", regexp: " << i->pathMatchStr << std::endl; 426 } 427 428 std::cerr << "Rule matched; path: " << i->pathMatchStr << std::endl; 399 429 400 430 std::string chain = i->chain; … … 403 433 name = 404 434 applyRules (protocolRules, chain, destination, direct, name); 405 } 435 } else { 436 std::cerr << "Not chaining another rule." << std::endl; 437 } 406 438 407 pcre_exec(i->pathMatch, NULL, name.c_str(), name.length(), 0, 0, ovector,439 rc = pcre_exec(i->pathMatch, NULL, name.c_str(), name.length(), 0, 0, ovector, 408 440 OVECCOUNT); 409 441 410 if (rc > 0) {442 if (rc >= 0) { 411 443 name = replaceWithRegexp(ovector, rc, name, i->result); 444 } else { 445 std::cerr << "No replacements necessary." << std::endl; 412 446 } 413 447 … … 417 451 applyRules (protocolRules, chain, destination, direct, name); 418 452 } 419 453 std::cerr << "Result " << name << endl; 420 454 return name; 421 455 } XrdCmsTfc/XrdCmsTfc.hh
r3547 r3548 34 34 public: 35 35 36 TrivialFileCatalog (XrdSysError *lp, const char * tfc_file) : XrdOucName2Name() 37 {m_url = tfc_file; eDest = lp; m_destination="any"; 38 m_protocols.push_back("direct"); parse();} 36 TrivialFileCatalog (XrdSysError *lp, const char * tfc_file); 39 37 40 38 virtual ~TrivialFileCatalog (); … … 49 47 50 48 private: 51 mutable bool m_connectionStatus;52 49 53 50 typedef struct { 54 51 pcre *pathMatch; 52 std::string pathMatchStr; 55 53 pcre *destinationMatch; 54 std::string destinationMatchStr; 56 55 std::string result; 57 56 std::string chain; … … 85 84 std::string m_url; 86 85 87 static XrdSysError *eDest; 86 static int s_numberOfInstances; 87 88 XrdSysError *eDest; 88 89 89 90 };
