Back to index

nordugrid-arc-nox  1.1.0~rc6
ArcConfig.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <fstream>
00008 #include <iostream>
00009 #include <string>
00010 
00011 #include <glibmm/miscutils.h>
00012 
00013 #include <arc/ArcConfig.h>
00014 #include <arc/ArcLocation.h>
00015 #include <arc/User.h>
00016 
00017 namespace Arc {
00018 
00019   Config::Config(const char *filename)
00020     : file_name_(filename) {
00021     ReadFromFile(filename);
00022   }
00023 
00024   Config::~Config(void) {
00025     // NOP
00026   }
00027 
00028   static void _print(XMLNode& node, int skip) {
00029     int n;
00030     for (n = 0; n < skip; n++)
00031       std::cout << " ";
00032     std::string content = (std::string)node;
00033     std::cout << "* " << node.Name() << "(" << node.Size() << ")"
00034               << " = " << content << std::endl;
00035     for (n = 0;; n++) {
00036       XMLNode _node = node.Child(n);
00037       if (!_node)
00038         break;
00039       _print(_node, skip + 2);
00040     }
00041   }
00042 
00043   void Config::print(void) {
00044     _print(*((XMLNode*)this), 0);
00045   }
00046 
00047   void Config::parse(const char *filename) {
00048     file_name_ = filename;
00049     ReadFromFile(filename);
00050   }
00051 
00052   Config::Config(long cfg_ptr_addr) {
00053     Config *cfg = (Config*)cfg_ptr_addr;
00054     cfg->New(*this);
00055   }
00056 
00057   Config::Config(const Config& cfg)
00058     : XMLNode() {
00059     cfg.New(*this);
00060   }
00061 
00062   void Config::save(const char *filename) {
00063     std::string str;
00064     GetDoc(str);
00065     std::ofstream out(filename);
00066     out << str;
00067     out.close();
00068   }
00069 
00070   BaseConfig::BaseConfig() {
00071     if (getenv("ARC_PLUGIN_PATH")) {
00072       std::string arcpluginpath = getenv("ARC_PLUGIN_PATH");
00073       std::string::size_type pos = 0;
00074       while (pos != std::string::npos) {
00075         std::string::size_type pos2 = arcpluginpath.find(G_SEARCHPATH_SEPARATOR, pos);
00076         AddPluginsPath(pos2 == std::string::npos ?
00077                        arcpluginpath.substr(pos) :
00078                        arcpluginpath.substr(pos, pos2 - pos));
00079         pos = pos2;
00080         if (pos != std::string::npos)
00081           pos++;
00082       }
00083     }
00084     else
00085 #ifdef WIN32
00086       AddPluginsPath(ArcLocation::Get() + "\\lib\\arc");
00087 #else
00088       AddPluginsPath(ArcLocation::Get() + G_DIR_SEPARATOR_S + PKGLIBSUBDIR);
00089 #endif
00090   }
00091 
00092   void BaseConfig::AddPluginsPath(const std::string& path) {
00093     plugin_paths.push_back(path);
00094   }
00095 
00096   XMLNode BaseConfig::MakeConfig(XMLNode cfg) const {
00097     XMLNode mm = cfg.NewChild("ModuleManager");
00098     for (std::list<std::string>::const_iterator p = plugin_paths.begin();
00099          p != plugin_paths.end(); ++p)
00100       mm.NewChild("Path") = *p;
00101     return mm;
00102   }
00103 
00104   void BaseConfig::AddPrivateKey(const std::string& path) {
00105     key = path;
00106   }
00107 
00108   void BaseConfig::AddCertificate(const std::string& path) {
00109     cert = path;
00110   }
00111 
00112   void BaseConfig::AddProxy(const std::string& path) {
00113     proxy = path;
00114   }
00115 
00116   void BaseConfig::AddCAFile(const std::string& path) {
00117     cafile = path;
00118   }
00119 
00120   void BaseConfig::AddCADir(const std::string& path) {
00121     cadir = path;
00122   }
00123 
00124   void BaseConfig::AddOverlay(XMLNode cfg) {
00125     overlay.Destroy();
00126     cfg.New(overlay);
00127   }
00128 
00129   void BaseConfig::GetOverlay(std::string fname) {
00130     overlay.Destroy();
00131     if (fname.empty())
00132       return;
00133     overlay.ReadFromFile(fname);
00134   }
00135 
00136 } // namespace Arc