Back to index

nordugrid-arc-nox  1.1.0~rc6
conf_map.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <fstream>
00007 
00008 #include <arc/Logger.h>
00009 
00010 #include "conf_sections.h"
00011 #include "environment.h"
00012 #include "conf.h"
00013 
00014 #include "conf_map.h"
00015 
00016 static Arc::Logger& glogger = Arc::Logger::getRootLogger();
00017 
00018 UrlMapConfig::UrlMapConfig(void) {
00019   std::ifstream cfile;
00020   ConfigSections* cf = NULL;
00021   if(nordugrid_config_loc().empty()) read_env_vars(true);
00022   if(!config_open(cfile)) {
00023     glogger.msg(Arc::ERROR,"Can't open configuration file");
00024     return;
00025   };
00026   switch(config_detect(cfile)) {
00027     case config_file_XML: {
00028       Arc::XMLNode cfg;
00029       if(!cfg.ReadFromStream(cfile)) {
00030         glogger.msg(Arc::ERROR,"Can't interpret configuration file as XML");
00031       } else {
00032         /*
00033          dataTransfer
00034            mapURL (link)
00035             from
00036             to
00037             at
00038          */
00039         Arc::XMLNode datanode = cfg["dataTransfer"];
00040         if(datanode) {
00041           Arc::XMLNode mapnode = datanode["mapURL"];
00042           for(;mapnode;++mapnode) {
00043             bool is_link = false;
00044             if(!elementtobool(mapnode,"link",is_link,&glogger)) continue;
00045             std::string initial = mapnode["from"];
00046             std::string replacement = mapnode["to"];
00047             if(initial.empty()) {
00048               glogger.msg(Arc::ERROR,"Missing 'from' element in mapURL");
00049               continue;
00050             };
00051             if(replacement.empty()) {
00052               glogger.msg(Arc::ERROR,"Missing 'to' element in mapURL");
00053               continue;
00054             };
00055             if(is_link) {
00056               std::string access = mapnode["at"];
00057               if(access.empty()) access = replacement;
00058               add(initial,replacement,access);
00059             } else {
00060               add(initial,replacement);
00061             };
00062           };
00063         };
00064       };
00065     }; break;
00066     case config_file_INI: {
00067       cf=new ConfigSections(cfile);
00068       cf->AddSection("common");
00069       cf->AddSection("grid-manager");
00070       for(;;) {
00071         std::string rest;
00072         std::string command;
00073         cf->ReadNext(command,rest);
00074         if(command.length() == 0) break;
00075         else if(command == "copyurl") {
00076           std::string initial = config_next_arg(rest);
00077           std::string replacement = config_next_arg(rest);
00078           if((initial.length() == 0) || (replacement.length() == 0)) {
00079             glogger.msg(Arc::ERROR,"Not enough parameters in copyurl");
00080             continue;
00081           };
00082           add(initial,replacement);
00083         }
00084         else if(command == "linkurl") {
00085           std::string initial = config_next_arg(rest);
00086           std::string replacement = config_next_arg(rest);
00087           if((initial.length() == 0) || (replacement.length() == 0)) {
00088             glogger.msg(Arc::ERROR,"Not enough parameters in linkurl");
00089             continue;
00090           };
00091           std::string access = config_next_arg(rest);
00092           if(access.length() == 0) access = replacement;
00093           add(initial,replacement,access);
00094         };
00095       };
00096     }; break;
00097     default: {
00098       glogger.msg(Arc::ERROR,"Can't recognize type of configuration file");
00099     }; break;
00100   };
00101   config_close(cfile);
00102   if(cf) delete cf;
00103 }
00104 
00105 UrlMapConfig::~UrlMapConfig(void) {
00106 }
00107