Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions
UrlMapConfig Class Reference

#include <conf_map.h>

Inheritance diagram for UrlMapConfig:
Inheritance graph
[legend]
Collaboration diagram for UrlMapConfig:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 UrlMapConfig (void)
 ~UrlMapConfig (void)
bool map (URL &url) const
bool local (const URL &url) const
void add (const URL &templ, const URL &repl, const URL &accs=URL())

Detailed Description

Definition at line 11 of file conf_map.h.


Constructor & Destructor Documentation

Definition at line 18 of file conf_map.cpp.

                               {
  std::ifstream cfile;
  ConfigSections* cf = NULL;
  if(nordugrid_config_loc().empty()) read_env_vars(true);
  if(!config_open(cfile)) {
    glogger.msg(Arc::ERROR,"Can't open configuration file");
    return;
  };
  switch(config_detect(cfile)) {
    case config_file_XML: {
      Arc::XMLNode cfg;
      if(!cfg.ReadFromStream(cfile)) {
        glogger.msg(Arc::ERROR,"Can't interpret configuration file as XML");
      } else {
        /*
         dataTransfer
           mapURL (link)
            from
            to
            at
         */
        Arc::XMLNode datanode = cfg["dataTransfer"];
        if(datanode) {
          Arc::XMLNode mapnode = datanode["mapURL"];
          for(;mapnode;++mapnode) {
            bool is_link = false;
            if(!elementtobool(mapnode,"link",is_link,&glogger)) continue;
            std::string initial = mapnode["from"];
            std::string replacement = mapnode["to"];
            if(initial.empty()) {
              glogger.msg(Arc::ERROR,"Missing 'from' element in mapURL");
              continue;
            };
            if(replacement.empty()) {
              glogger.msg(Arc::ERROR,"Missing 'to' element in mapURL");
              continue;
            };
            if(is_link) {
              std::string access = mapnode["at"];
              if(access.empty()) access = replacement;
              add(initial,replacement,access);
            } else {
              add(initial,replacement);
            };
          };
        };
      };
    }; break;
    case config_file_INI: {
      cf=new ConfigSections(cfile);
      cf->AddSection("common");
      cf->AddSection("grid-manager");
      for(;;) {
        std::string rest;
        std::string command;
        cf->ReadNext(command,rest);
        if(command.length() == 0) break;
        else if(command == "copyurl") {
          std::string initial = config_next_arg(rest);
          std::string replacement = config_next_arg(rest);
          if((initial.length() == 0) || (replacement.length() == 0)) {
            glogger.msg(Arc::ERROR,"Not enough parameters in copyurl");
            continue;
          };
          add(initial,replacement);
        }
        else if(command == "linkurl") {
          std::string initial = config_next_arg(rest);
          std::string replacement = config_next_arg(rest);
          if((initial.length() == 0) || (replacement.length() == 0)) {
            glogger.msg(Arc::ERROR,"Not enough parameters in linkurl");
            continue;
          };
          std::string access = config_next_arg(rest);
          if(access.length() == 0) access = replacement;
          add(initial,replacement,access);
        };
      };
    }; break;
    default: {
      glogger.msg(Arc::ERROR,"Can't recognize type of configuration file");
    }; break;
  };
  config_close(cfile);
  if(cf) delete cf;
}

Here is the call graph for this function:

Definition at line 105 of file conf_map.cpp.

                                {
}

Member Function Documentation

void Arc::URLMap::add ( const URL templ,
const URL repl,
const URL accs = URL() 
) [inherited]

Definition at line 59 of file URLMap.cpp.

                                                                     {
    entries.push_back(map_entry(templ, repl, accs));
  }

Here is the caller graph for this function:

bool Arc::URLMap::local ( const URL url) const [inherited]

Definition at line 51 of file URLMap.cpp.

                                         {
    for (std::list<map_entry>::const_iterator i = entries.begin();
         i != entries.end(); ++i)
      if (url.str().substr(0, i->initial.str().length()) == i->initial.str())
        return true;
    return false;
  }

Here is the call graph for this function:

bool Arc::URLMap::map ( URL url) const [inherited]

Definition at line 23 of file URLMap.cpp.

                                 {
    for (std::list<map_entry>::const_iterator i = entries.begin();
         i != entries.end(); ++i)
      if (url.str().substr(0, i->initial.str().length()) == i->initial.str()) {
        std::string tmp_url = url.str();
        tmp_url.replace(0, i->initial.str().length(), i->replacement.str());
        URL newurl = tmp_url;
        /* must return semi-valid url */
        if (newurl.Protocol() == "file") { /* local file - check permissions */
          int h = open(newurl.Path().c_str(), O_RDONLY);
          if (h == -1) {
            logger.msg(ERROR, "file %s is not accessible", newurl.Path());
            return false;
          }
          close(h);
          if (i->access) { /* how it should be accessed on nodes */
            tmp_url.replace(0, i->replacement.str().length(), i->access.str());
            newurl = tmp_url;
            newurl.ChangeProtocol("link");
          }
        }
        logger.msg(INFO, "Mapping %s to %s", url.str(), newurl.str());
        url = newurl;
        return true;
      }
    return false;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: