Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Protected Attributes | Private Attributes
ArcSec::EvaluatorLoader Class Reference

EvaluatorLoader is implemented as a helper class for loading different Evaluator objects, like ArcEvaluator. More...

#include <EvaluatorLoader.h>

Collaboration diagram for ArcSec::EvaluatorLoader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EvaluatorLoader ()
EvaluatorgetEvaluator (const std::string &classname)
 Get evaluator object according to the class name.
EvaluatorgetEvaluator (const Policy *policy)
 Get evaluator object suitable for presented policy.
EvaluatorgetEvaluator (const Request *request)
 Get evaluator object suitable for presented request.
RequestgetRequest (const std::string &classname, const Source &requestsource)
 Get request object according to the class name, based on the request source.
RequestgetRequest (const Source &requestsource)
 Get request object according to the request source.
PolicygetPolicy (const std::string &classname, const Source &policysource)
 Get policy object according to the class name, based on the policy source.
PolicygetPolicy (const Source &policysource)
 Get proper policy object according to the policy source.

Static Protected Attributes

static Arc::Logger logger

Private Attributes

std::list< Arc::XMLNodeclass_config_list_
 configuration information for loading objects; there could be more than one suits of configuration

Detailed Description

EvaluatorLoader is implemented as a helper class for loading different Evaluator objects, like ArcEvaluator.

The object loading is based on the configuration information about evaluator, including information for factory class, request, policy and evaluator itself

Definition at line 19 of file EvaluatorLoader.h.


Constructor & Destructor Documentation


Member Function Documentation

Evaluator * ArcSec::EvaluatorLoader::getEvaluator ( const std::string &  classname)

Get evaluator object according to the class name.

Definition at line 74 of file EvaluatorLoader.cpp.

                                                                   {
  ArcSec::Evaluator* eval = NULL;
  Arc::ClassLoader* classloader = NULL;

  //Get the lib path from environment, and put it into the configuration xml node
  std::list<std::string> plugins = Arc::ArcLocation::GetPlugins();

  Arc::XMLNode node;
  std::list<Arc::XMLNode>::iterator it;
  bool found = false;
  for( it = class_config_list_.begin(); it != class_config_list_.end(); it++) {
    node = (*it);
    if((std::string)(node["PDPConfig"]["Evaluator"].Attribute("name")) == classname) { found = true; break; }
  }
  if(found) {
    bool has_covered = false;
    for(std::list<std::string>::iterator p = plugins.begin();p!=plugins.end();++p) {
      for(int i=0;;i++) {
        Arc::XMLNode cn = node["ModuleManager"]["Path"][i];
        if(!cn) break;
        if((std::string)(cn) == (*p)){ has_covered = true; break; }
      }
      if(!has_covered)
        node["ModuleManager"].NewChild("Path")=*p;
    }
  } else {
    // Loading unknown evaluator
    Arc::XMLNode cfg("\
      <ArcConfig\
       xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\">\
       <ModuleManager/>\
      </ArcConfig>");
    for(std::list<std::string>::iterator plugin = plugins.begin();plugin!=plugins.end();++plugin) {
      cfg["ModuleManager"].NewChild("Path")=*plugin;
      try {
        Glib::Dir dir(*plugin);
        for(Glib::DirIterator file = dir.begin(); file != dir.end(); file++) {
          std::string name = *file;
          if(name.substr(0, 3) != "lib") continue;
          std::size_t pos = name.rfind(".");
          std::string subname;
          if(pos!=std::string::npos) subname = name.substr(pos);
          if(subname != G_MODULE_SUFFIX) continue;
          std::string fname = Glib::build_filename(*plugin,name);
          // Few tests just in case
          if(!file_test(fname,Glib::FILE_TEST_IS_EXECUTABLE)) continue;
          if(!file_test(fname,Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)) continue;
          name = name.substr(3,name.find('.')-3);
          Arc::XMLNode plugcfg = cfg.NewChild("Plugins");
          plugcfg.NewAttribute("Name")=name;
          plugcfg.NewChild("Plugin").NewAttribute("Name")="__arc_evaluator_modules__";
        };
      } catch (Glib::FileError) {};
    }
    cfg.New(node);
  }
  Arc::Config modulecfg(node);
  classloader = Arc::ClassLoader::getClassLoader(&modulecfg);
  //Dynamically load Evaluator object according to configure information. 
  //It should be the caller to free the object
  eval = (Evaluator*)(classloader->Instance(classname, &node, "__arc_evaluator_modules__"));

  if(!eval) logger.msg(Arc::ERROR, "Can not load arc evaluator object: %s",classname); 
  return eval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get evaluator object suitable for presented policy.

Definition at line 140 of file EvaluatorLoader.cpp.

                                                             {
  if(!policy) return NULL;
  return getEvaluator(policy->getEvalName());
}

Here is the call graph for this function:

Get evaluator object suitable for presented request.

Definition at line 145 of file EvaluatorLoader.cpp.

                                                               {
  if(!request) return NULL;
  return getEvaluator(request->getEvalName());
}

Here is the call graph for this function:

Policy * ArcSec::EvaluatorLoader::getPolicy ( const std::string &  classname,
const Source policysource 
)

Get policy object according to the class name, based on the policy source.

Definition at line 191 of file EvaluatorLoader.cpp.

                                                                                         {
  ArcSec::Policy* policy = NULL;
  Arc::ClassLoader* classloader = NULL;

  //Get policy node
  Arc::XMLNode policynode = policysource.Get();

  //Get the lib path from environment, and put it into the configuration xml node
  std::list<std::string> plugins = Arc::ArcLocation::GetPlugins();

  Arc::XMLNode node;
  std::list<Arc::XMLNode>::iterator it;
  bool found = false;
  for( it = class_config_list_.begin(); it != class_config_list_.end(); it++) {
    node = (*it);
    if((std::string)(node["PDPConfig"]["Policy"].Attribute("name")) == classname) { found = true; break; }
  }

  if(found) {
    bool has_covered = false;
    for(std::list<std::string>::iterator p = plugins.begin();p!=plugins.end();++p) {
      for(int i=0;;i++) {
        Arc::XMLNode cn = node["ModuleManager"]["Path"][i];
        if(!cn) break;
        if((std::string)(cn) == (*p)){ has_covered = true; break; }
      }
      if(!has_covered)
        node["ModuleManager"].NewChild("Path")=*p;
    }

    Arc::Config modulecfg(node);
    classloader = Arc::ClassLoader::getClassLoader(&modulecfg);
    //Dynamically load Policy object according to configure information. 
    //It should be the caller to free the object
    policy = (Policy*)(classloader->Instance(classname, &policynode, "__arc_policy_modules__"));
  }

  if(!policy) logger.msg(Arc::ERROR, "Can not load policy object: %s",classname); 
  return policy;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Policy * ArcSec::EvaluatorLoader::getPolicy ( const Source policysource)

Get proper policy object according to the policy source.

Definition at line 232 of file EvaluatorLoader.cpp.

                                                             {
  ArcSec::Policy* policy = NULL;
  Arc::ClassLoader* classloader = NULL;

  //Get policy node
  Arc::XMLNode policynode = policysource.Get();

  //Get the lib path from environment, and put it into the configuration xml node
  std::list<std::string> plugins = Arc::ArcLocation::GetPlugins();

  Arc::XMLNode cfg("\
    <ArcConfig\
     xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\">\
     <ModuleManager/>\
    </ArcConfig>");
  for(std::list<std::string>::iterator plugin = plugins.begin();plugin!=plugins.end();++plugin) {
    cfg["ModuleManager"].NewChild("Path")=*plugin;
    try {
      Glib::Dir dir(*plugin);
      for(Glib::DirIterator file = dir.begin(); file != dir.end(); file++) {
        std::string name = *file;
        if(name.substr(0, 3) != "lib") continue;
         // TODO: This won't work on windows and maybe even on some
         // unices which do have shared libraries ending with .so
        if(name.substr(name.length()-3, 3) != ".so") continue;
        std::string fname = Glib::build_filename(*plugin,name);
        // Few tests just in case
        if(!file_test(fname,Glib::FILE_TEST_IS_EXECUTABLE)) continue;
        if(!file_test(fname,Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)) continue;
        name = name.substr(3,name.find('.')-3);
        Arc::XMLNode plugcfg = cfg.NewChild("Plugins");
        plugcfg.NewAttribute("Name")=name;
        plugcfg.NewChild("Plugin").NewAttribute("Name")="__arc_policy_modules__";
        // ?? plugcfg["Plugin"]="policy"; ??
      };
    } catch (Glib::FileError) {};
  };

  Arc::Config modulecfg(cfg);
  classloader = Arc::ClassLoader::getClassLoader(&modulecfg);
  //Dynamically load Policy object according to configure information. 
  //It should be the caller to free the object
  policy = (Policy*)(classloader->Instance(&policynode, "__arc_policy_modules__"));

  if(!policy) logger.msg(Arc::ERROR, "Can not load policy object"); 
  return policy;
}

Here is the call graph for this function:

Request * ArcSec::EvaluatorLoader::getRequest ( const std::string &  classname,
const Source requestsource 
)

Get request object according to the class name, based on the request source.

Definition at line 150 of file EvaluatorLoader.cpp.

                                                                                            {
  ArcSec::Request* req = NULL;
  Arc::ClassLoader* classloader = NULL;
  
  //Get the request node
  Arc::XMLNode reqnode = requestsource.Get();

  //Get the lib path from environment, and put it into the configuration xml node
  std::list<std::string> plugins = Arc::ArcLocation::GetPlugins();

  Arc::XMLNode node;
  std::list<Arc::XMLNode>::iterator it;
  bool found = false;
  for( it = class_config_list_.begin(); it != class_config_list_.end(); it++) {
    node = (*it);
    if((std::string)(node["PDPConfig"]["Request"].Attribute("name")) == classname) { found = true; break; }
  }

  if(found) {
    bool has_covered = false;
    for(std::list<std::string>::iterator p = plugins.begin();p!=plugins.end();++p) {
      for(int i=0;;i++) {
        Arc::XMLNode cn = node["ModuleManager"]["Path"][i];
        if(!cn) break;
        if((std::string)(cn) == (*p)){ has_covered = true; break; }
      }
      if(!has_covered)
        node["ModuleManager"].NewChild("Path")=*p;
    }

    Arc::Config modulecfg(node);
    classloader = Arc::ClassLoader::getClassLoader(&modulecfg);
    //Dynamically load Request object according to configure information. 
    //It should be the caller to free the object
    req = (Request*)(classloader->Instance(classname, &reqnode, "__arc_request_modules__"));
  }
  
  if(!req) logger.msg(Arc::ERROR, "Can not load arc request object: %s",classname); 
  return req;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Request * ArcSec::EvaluatorLoader::getRequest ( const Source requestsource)

Get request object according to the request source.

Definition at line 280 of file EvaluatorLoader.cpp.

                                                                {
  ArcSec::Request* request = NULL;
  Arc::ClassLoader* classloader = NULL;

  //Get policy node
  Arc::XMLNode requestnode = requestsource.Get();

  //Get the lib path from environment, and put it into the configuration xml node
  std::list<std::string> plugins = Arc::ArcLocation::GetPlugins();

  Arc::XMLNode cfg("\
    <ArcConfig\
     xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\">\
     <ModuleManager/>\
    </ArcConfig>");
  for(std::list<std::string>::iterator plugin = plugins.begin();plugin!=plugins.end();++plugin) {
    cfg["ModuleManager"].NewChild("Path")=*plugin;
    try {
      Glib::Dir dir(*plugin);
      for(Glib::DirIterator file = dir.begin(); file != dir.end(); file++) {
        std::string name = *file;
        if(name.substr(0, 3) != "lib") continue;
         // TODO: This won't work on windows and maybe even on some
         // unices which do have shared libraries ending with .so
        if(name.substr(name.length()-3, 3) != ".so") continue;
        std::string fname = Glib::build_filename(*plugin,name);
        // Few tests just in case
        if(!file_test(fname,Glib::FILE_TEST_IS_EXECUTABLE)) continue;
        if(!file_test(fname,Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)) continue;
        name = name.substr(3,name.find('.')-3);
        Arc::XMLNode plugcfg = cfg.NewChild("Plugins");
        plugcfg.NewAttribute("Name")=name;
        plugcfg.NewChild("Plugin").NewAttribute("Name")="__arc_request_modules__";
        // ?? plugcfg["Plugin"]="request"; ??
      };
    } catch (Glib::FileError) {};
  };

  Arc::Config modulecfg(cfg);
  classloader = Arc::ClassLoader::getClassLoader(&modulecfg);
  //Dynamically load Request object according to configure information. 
  //It should be the caller to free the object
  request = (Request*)(classloader->Instance(&requestnode, "__arc_request_modules__"));

  if(!request) logger.msg(Arc::ERROR, "Can not load request object"); 
  return request;
}

Here is the call graph for this function:


Member Data Documentation

configuration information for loading objects; there could be more than one suits of configuration

Definition at line 41 of file EvaluatorLoader.h.

Definition at line 37 of file EvaluatorLoader.h.


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