Back to index

nordugrid-arc-nox  1.1.0~rc6
PolicyStore.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <fstream>
00006 #include <iostream>
00007 #include "PolicyParser.h"
00008 #include "PolicyStore.h"
00009 
00010 using namespace Arc;
00011 using namespace ArcSec;
00012 
00013 //PolicyStore::PolicyStore(const std::list<std::string>& filelist, const std::string& alg, const std::string& policyclassname, EvaluatorContext* ctx){
00014 PolicyStore::PolicyStore(const std::string& /* alg */, const std::string& policyclassname, EvaluatorContext* /* ctx */){
00015   //combalg = alg;
00016   policy_classname = policyclassname;
00017 
00018   //PolicyParser plparser;  
00020   //for(std::list<std::string>::const_iterator it = filelist.begin(); it != filelist.end(); it++){
00021   //  policies.push_back(PolicyElement(plparser.parsePolicy((*it).c_str(), policy_classname, ctx)));
00022   //}    
00023 }
00024 
00025 //Policy list  
00026 //there also can be a class "PolicySet", which includes a few policies
00027 std::list<PolicyStore::PolicyElement> PolicyStore::findPolicy(EvaluationCtx*) { //ctx){
00028   //For the existing Arc policy expression, we only need to return all the policies, because there is 
00029   //no Target definition in ArcPolicy (the Target is only in ArcRule)
00030 
00031   return policies;
00032 
00033 /* 
00034   std::list<Policy*> ret;
00035   std::list<Policy*>::iterator it; 
00036   for(it = policies.begin(); it!=policies.end(); it++ ){
00037     MatchResult res = (*it)->match(ctx);
00038     if (res == MATCH )
00039       ret.push_back(*it);
00040   }
00041   return ret;
00042 */
00043  //TODO 
00044 }
00045 
00046 void PolicyStore::addPolicy(const Source& policy, EvaluatorContext* ctx, const std::string& id) {
00047   PolicyParser plparser;
00048   Policy* pls;
00049   pls = PolicyElement(plparser.parsePolicy(policy, policy_classname, ctx),id);
00050   if(pls != NULL)
00051     policies.push_back(pls);
00052 }
00053 
00054 void PolicyStore::addPolicy(Policy* policy, EvaluatorContext* ctx,const std::string& id) {
00055   Policy* pls = dynamic_cast<Policy*>(policy);
00056   pls->setEvaluatorContext(ctx);
00057   pls->make_policy();
00058   if(pls!=NULL) {
00059     policies.push_back(PolicyElement(pls, id));
00060   }
00061 }
00062 
00063 void PolicyStore::removePolicies(void) {
00064   while(!(policies.empty())){
00065     delete (Policy*)(policies.back());
00066     policies.pop_back();
00067   }
00068 }
00069 
00070 void PolicyStore::releasePolicies(void) {
00071   while(!(policies.empty())){
00072     policies.pop_back();
00073   }
00074 }
00075 
00076 PolicyStore::~PolicyStore(){
00077   removePolicies();
00078 }