Changeset 3548

Show
Ignore:
Timestamp:
10/19/2009 06:26:20 PM (1 month ago)
Author:
brian
Message:

Semi-working version.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • XrdCmsTfc/Makefile.am

    r3547 r3548  
    2020         XrdCmsTfc.cc XrdCmsTfc.hh 
    2121 
    22 libXrdHdfs_la_LDFLAGS = -lxerces-c 
     22libXrdCmsTfc_la_LDFLAGS = -lxerces-c -lpcre 
    2323 
  • XrdCmsTfc/XrdCmsTfc.cc

    r3547 r3548  
    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; 
     
    7069    return  buff; 
    7170} 
     71 
     72int XrdCmsTfc::TrivialFileCatalog::s_numberOfInstances = 0; 
     73XrdCmsTfc::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  } 
    7289 
    7390void XrdCmsTfc::TrivialFileCatalog::freeProtocolRules(ProtocolRules protRules) { 
     
    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) { 
     
    145164    rule.result = result; 
    146165    rule.chain = chain; 
    147     rules[protocol].push_back (rule); 
     166    rules[protocol].push_back(rule); 
    148167    return 0; 
    149168} 
     
    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()) 
     
    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); 
     
    235254 
    236255        /*first of all do the lfn-to-pfn bit*/ 
     256 
    237257        { 
    238258            DOMNodeList *rules =doc->getElementsByTagName(_toDOMS("lfn-to-pfn")); 
     
    301321} 
    302322 
    303  
     323int XrdCmsTfc::TrivialFileCatalog::lfn2rfn(const char *lfn, char *buff, int blen) { 
     324 
     325    return lfn2pfn(lfn, buff, blen); 
     326 
     327
    304328 
    305329std::string replace(const std::string inputString, pcre * re, std::string replacementString) { 
     
    376400     
    377401    const ProtocolRules::const_iterator rulesIterator = protocolRules.find (protocol); 
    378     if (rulesIterator == protocolRules.end ()) 
     402    if (rulesIterator == protocolRules.end()) 
    379403        return ""; 
    380404     
     
    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; 
    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) { 
    396423            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;     
    399429         
    400430        std::string chain = i->chain; 
     
    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         
     
    417451                applyRules (protocolRules, chain, destination, direct, name);            
    418452        } 
    419          
     453        std::cerr << "Result " << name << endl; 
    420454        return name; 
    421455    } 
  • XrdCmsTfc/XrdCmsTfc.hh

    r3547 r3548  
    3434public: 
    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 (); 
     
    4947 
    5048private: 
    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; 
     
    8584    std::string                 m_url; 
    8685 
    87     static XrdSysError *eDest; 
     86    static int s_numberOfInstances; 
     87 
     88    XrdSysError *eDest; 
    8889 
    8990};