Skip to content

Commit fe61ac9

Browse files
author
brian
committed
Semi-working version.
git-svn-id: svn://t2.unl.edu/brian/XrdCmsTfc@3548 1fda6f16-4416-0410-bfd6-867a04880151
1 parent 4d036f2 commit fe61ac9

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ INCLUDES = -I$(top_srcdir)/src
1919
libXrdCmsTfc_la_SOURCES = \
2020
XrdCmsTfc.cc XrdCmsTfc.hh
2121

22-
libXrdHdfs_la_LDFLAGS = -lxerces-c
22+
libXrdCmsTfc_la_LDFLAGS = -lxerces-c -lpcre
2323

XrdCmsTfc.cc

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ extern "C"
3333
XrdOucName2Name *XrdOucgetName2Name(XrdSysError *eDest, const char *confg,
3434
const char *parms, const char *lroot, const char *rroot)
3535
{
36-
TrivialFileCatalog *myTFC = new TrivialFileCatalog(eDest, "/tmp/test");
3736
eDest->Say("Copr. 2009 University of Nebraska-Lincoln TFC plugin v 1.0");
3837

39-
eDest->Say("Params: ");
40-
eDest->Say(parms);
38+
eDest->Say("Params: ", parms);
39+
TrivialFileCatalog *myTFC = new TrivialFileCatalog(eDest, parms);
4140

4241
return myTFC;
4342
}
@@ -70,6 +69,24 @@ inline XMLCh* _toDOMS(std::string temp){
7069
return buff;
7170
}
7271

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+
7390
void XrdCmsTfc::TrivialFileCatalog::freeProtocolRules(ProtocolRules protRules) {
7491
ProtocolRules::iterator it;
7592
Rules::iterator it2;
@@ -124,7 +141,9 @@ XrdCmsTfc::TrivialFileCatalog::parseRule (DOMNode *ruleNode,
124141
const char *error;
125142
int erroffset;
126143
rule.pathMatch = NULL;
144+
rule.pathMatchStr = pathMatchRegexp;
127145
rule.destinationMatch = NULL;
146+
rule.destinationMatchStr = destinationMatchRegexp;
128147
rule.pathMatch = pcre_compile(pathMatchRegexp, 0, &error, &erroffset, NULL);
129148
if (rule.pathMatch == NULL) {
130149
char *err = (char *)malloc(BUFFSIZE*sizeof(char));
@@ -144,7 +163,7 @@ XrdCmsTfc::TrivialFileCatalog::parseRule (DOMNode *ruleNode,
144163
}
145164
rule.result = result;
146165
rule.chain = chain;
147-
rules[protocol].push_back (rule);
166+
rules[protocol].push_back(rule);
148167
return 0;
149168
}
150169

@@ -204,7 +223,7 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
204223

205224
std::ifstream configFile;
206225
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());
208227

209228
if (!configFile.good() || !configFile.is_open())
210229
{
@@ -213,11 +232,11 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
213232
}
214233

215234
configFile.close();
216-
217-
XercesDOMParser* parser = new XercesDOMParser;
235+
236+
XercesDOMParser* parser = new XercesDOMParser();
218237
parser->setValidationScheme(XercesDOMParser::Val_Auto);
219238
parser->setDoNamespaces(false);
220-
parser->parse(m_filename.c_str());
239+
parser->parse(m_filename.c_str());
221240
DOMDocument* doc = parser->getDocument();
222241
assert(doc);
223242

@@ -234,6 +253,7 @@ XrdCmsTfc::TrivialFileCatalog::parse ()
234253
*/
235254

236255
/*first of all do the lfn-to-pfn bit*/
256+
237257
{
238258
DOMNodeList *rules =doc->getElementsByTagName(_toDOMS("lfn-to-pfn"));
239259
unsigned int ruleTagsNum =
@@ -300,7 +320,11 @@ XrdCmsTfc::TrivialFileCatalog::lfn2pfn(const char *lfn, char *buff, int blen)
300320
return XRDCMSTFC_ERR_NOLFN2PFN;
301321
}
302322

323+
int XrdCmsTfc::TrivialFileCatalog::lfn2rfn(const char *lfn, char *buff, int blen) {
303324

325+
return lfn2pfn(lfn, buff, blen);
326+
327+
}
304328

305329
std::string replace(const std::string inputString, pcre * re, std::string replacementString) {
306330

@@ -375,7 +399,7 @@ XrdCmsTfc::TrivialFileCatalog::applyRules (const ProtocolRules& protocolRules,
375399
std::cerr << "Calling apply rules with protocol: " << protocol << "\n destination: " << destination << "\n " << " on name " << name << std::endl;
376400

377401
const ProtocolRules::const_iterator rulesIterator = protocolRules.find (protocol);
378-
if (rulesIterator == protocolRules.end ())
402+
if (rulesIterator == protocolRules.end())
379403
return "";
380404

381405
const Rules &rules=(*(rulesIterator)).second;
@@ -387,36 +411,46 @@ XrdCmsTfc::TrivialFileCatalog::applyRules (const ProtocolRules& protocolRules,
387411
{
388412
int ovector[OVECCOUNT];
389413
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) {
392416
continue;
417+
} else {
418+
std::cerr << "Destination did match; my destination " << destination << ", regexp: " << i->destinationMatchStr << std::endl;
419+
}
393420

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) {
396423
continue;
424+
} else {
425+
std::cerr << "Path did match; my path " << name << ", regexp: " << i->pathMatchStr << std::endl;
426+
}
397427

398-
std::cerr << "Rule matched! " << std::endl;
428+
std::cerr << "Rule matched; path: " << i->pathMatchStr << std::endl;
399429

400430
std::string chain = i->chain;
401431
if ((direct==true) && (chain != ""))
402432
{
403433
name =
404434
applyRules (protocolRules, chain, destination, direct, name);
405-
}
435+
} else {
436+
std::cerr << "Not chaining another rule." << std::endl;
437+
}
406438

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,
408440
OVECCOUNT);
409441

410-
if (rc > 0) {
442+
if (rc >= 0) {
411443
name = replaceWithRegexp(ovector, rc, name, i->result);
444+
} else {
445+
std::cerr << "No replacements necessary." << std::endl;
412446
}
413447

414448
if ((direct == false) && (chain !=""))
415449
{
416450
name =
417451
applyRules (protocolRules, chain, destination, direct, name);
418452
}
419-
453+
std::cerr << "Result " << name << endl;
420454
return name;
421455
}
422456
return "";

XrdCmsTfc.hh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class TrivialFileCatalog : public XrdOucName2Name
3333
{
3434
public:
3535

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);
3937

4038
virtual ~TrivialFileCatalog ();
4139

@@ -48,11 +46,12 @@ public:
4846
int parse();
4947

5048
private:
51-
mutable bool m_connectionStatus;
5249

5350
typedef struct {
5451
pcre *pathMatch;
52+
std::string pathMatchStr;
5553
pcre *destinationMatch;
54+
std::string destinationMatchStr;
5655
std::string result;
5756
std::string chain;
5857
} Rule;
@@ -84,7 +83,9 @@ private:
8483
std::string m_destination;
8584
std::string m_url;
8685

87-
static XrdSysError *eDest;
86+
static int s_numberOfInstances;
87+
88+
XrdSysError *eDest;
8889

8990
};
9091

0 commit comments

Comments
 (0)