Back to index

nordugrid-arc-nox  1.1.0~rc6
Plexer.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 // Plexer.cpp
00006 
00007 #include "Plexer.h"
00008 
00009 namespace Arc {
00010 
00011   PlexerEntry::PlexerEntry(const RegularExpression& label,
00012                         MCCInterface* mcc) :
00013     label(label),
00014     mcc(mcc)
00015   {
00016   }
00017 
00018   Plexer::Plexer(Config *cfg) : MCC(cfg) {
00019   }
00020 
00021   Plexer::~Plexer(){
00022   }
00023 
00024   void Plexer::Next(MCCInterface* next, const std::string& label){
00025     std::list<PlexerEntry>::iterator iter;
00026     if (next!=0) {
00027       RegularExpression regex(label);
00028       if (regex.isOk()) {
00029         mccs.push_front(PlexerEntry(regex,next));
00030       } else {
00031         logger.msg(WARNING, "Bad label: \"%s\"", label);
00032       }
00033     } else {
00034       for (iter=mccs.begin(); iter!=mccs.end();) {
00035         if (iter->label.hasPattern(label)) {
00036           iter = mccs.erase(iter);
00037         } else {
00038           ++iter;
00039         }
00040       }
00041     }
00042   }
00043   
00044   MCC_Status Plexer::process(Message& request, Message& response){
00045     std::string ep = request.Attributes()->get("ENDPOINT");
00046     std::string path = getPath(ep);
00047     logger.msg(VERBOSE, "Operation on path \"%s\"",path);
00048     std::list<PlexerEntry>::iterator iter;
00049     for (iter=mccs.begin(); iter!=mccs.end(); ++iter) {
00050       std::list<std::string> unmatched, matched;
00051       if (iter->label.match(path, unmatched, matched)) {
00052         request.Attributes()->set("PLEXER:PATTERN",iter->label.getPattern());
00053         request.Attributes()->set("PLEXER:EXTENSION", "");
00054         if(unmatched.size() > 0) {
00055           request.Attributes()->set("PLEXER:EXTENSION",*(--unmatched.end()));
00056         };
00057         return iter->mcc->process(request, response);
00058       }
00059     }
00060     logger.msg(WARNING, "No next MCC or Service at path \"%s\"",path);
00061     return MCC_Status(UNKNOWN_SERVICE_ERROR,
00062                         (std::string)("MCC Plexer"),
00063                         path);  
00064   }
00065 
00066   //XXX: workaround because the python bindig segmentation fault
00067   Logger Plexer::logger(Logger::rootLogger,"Plexer");
00068 
00069   std::string Plexer::getPath(std::string url){
00070     // TODO: Need even more reliable URL detection
00071     std::string::size_type ds, ps;
00072     ds=url.find("://");
00073     if (ds==std::string::npos)
00074       ps=url.find("/");
00075     else
00076       ps=url.find("/", ds+3);
00077     if (ps==std::string::npos)
00078       return "";
00079     else
00080       return url.substr(ps);
00081   }
00082   
00083 }