@@ -33,11 +33,10 @@ extern "C"
33
33
XrdOucName2Name *XrdOucgetName2Name (XrdSysError *eDest, const char *confg,
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;
43
42
}
@@ -70,6 +69,24 @@ inline XMLCh* _toDOMS(std::string temp){
70
69
return buff;
71
70
}
72
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
+ }
89
+
73
90
void XrdCmsTfc::TrivialFileCatalog::freeProtocolRules (ProtocolRules protRules) {
74
91
ProtocolRules::iterator it;
75
92
Rules::iterator it2;
@@ -124,7 +141,9 @@ XrdCmsTfc::TrivialFileCatalog::parseRule (DOMNode *ruleNode,
124
141
const char *error;
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 ) {
130
149
char *err = (char *)malloc (BUFFSIZE*sizeof (char ));
@@ -144,7 +163,7 @@ XrdCmsTfc::TrivialFileCatalog::parseRule (DOMNode *ruleNode,
144
163
}
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
}
150
169
@@ -204,7 +223,7 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
204
223
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 ())
210
229
{
@@ -213,11 +232,11 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
213
232
}
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);
223
242
@@ -234,6 +253,7 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
234
253
*/
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" ));
239
259
unsigned int ruleTagsNum =
@@ -300,7 +320,11 @@ XrdCmsTfc::TrivialFileCatalog::lfn2pfn(const char *lfn, char *buff, int blen)
300
320
return XRDCMSTFC_ERR_NOLFN2PFN;
301
321
}
302
322
323
+ int XrdCmsTfc::TrivialFileCatalog::lfn2rfn (const char *lfn, char *buff, int blen) {
303
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) {
306
330
@@ -375,7 +399,7 @@ XrdCmsTfc::TrivialFileCatalog::applyRules (const ProtocolRules& protocolRules,
375
399
std::cerr << " Calling apply rules with protocol: " << protocol << " \n destination: " << destination << " \n " << " on name " << name << std::endl;
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
381
405
const Rules &rules=(*(rulesIterator)).second ;
@@ -387,36 +411,46 @@ XrdCmsTfc::TrivialFileCatalog::applyRules (const ProtocolRules& protocolRules,
387
411
{
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 ;
417
+ } else {
418
+ std::cerr << " Destination did match; my destination " << destination << " , regexp: " << i->destinationMatchStr << std::endl;
419
+ }
393
420
394
- pcre_exec (i->pathMatch , NULL , name.c_str (), name.length (), 0 , 0 , ovector, OVECCOUNT);
395
- if (rc < 0 )
421
+ rc = pcre_exec (i->pathMatch , NULL , name.c_str (), name.length (), 0 , 0 , ovector, OVECCOUNT);
422
+ if (rc < 0 ) {
396
423
continue ;
424
+ } else {
425
+ std::cerr << " Path did match; my path " << name << " , regexp: " << i->pathMatchStr << std::endl;
426
+ }
397
427
398
- std::cerr << " Rule matched! " << std::endl;
428
+ std::cerr << " Rule matched; path: " << i-> pathMatchStr << std::endl;
399
429
400
430
std::string chain = i->chain ;
401
431
if ((direct==true ) && (chain != " " ))
402
432
{
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
414
448
if ((direct == false ) && (chain !=" " ))
415
449
{
416
450
name =
417
451
applyRules (protocolRules, chain, destination, direct, name);
418
452
}
419
-
453
+ std::cerr << " Result " << name << endl;
420
454
return name;
421
455
}
422
456
return " " ;
0 commit comments