Back to index

nordugrid-arc-nox  1.1.0~rc6
InRangeFunction.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include "InRangeFunction.h"
00006 #include "../attr/BooleanAttribute.h"
00007 #include "../attr/DateTimeAttribute.h"
00008 #include "../attr/StringAttribute.h"
00009 
00010 namespace ArcSec {
00011 
00012 std::string InRangeFunction::getFunctionName(std::string datatype){
00013   std::string ret;
00014   if (datatype ==  DateTimeAttribute::getIdentifier()) ret = NAME_TIME_IN_RANGE;
00015   else if (datatype ==  StringAttribute::getIdentifier()) ret = NAME_STRING_IN_RANGE;
00016   return ret;
00017 }
00018 
00019 InRangeFunction::InRangeFunction(std::string functionName, std::string argumentType) : Function(functionName, argumentType) {
00020   fnName = functionName;
00021   argType = argumentType;
00022 }
00023 
00024 AttributeValue* InRangeFunction::evaluate(AttributeValue* arg0, AttributeValue* arg1, bool check_id){
00025   //TODO
00026   //arg0 is the attributevalue in policy
00027   //arg1 is the attributevalue in request
00028   if(check_id) { if(arg0->getId() != arg1->getId()) return new BooleanAttribute(false); }
00029   if(fnName == NAME_TIME_IN_RANGE){
00030     PeriodAttribute* v0;
00031     DateTimeAttribute* v1;
00032     try{
00033       v0 = dynamic_cast<PeriodAttribute*>(arg0);
00034       v1 = dynamic_cast<DateTimeAttribute*>(arg1);
00035     } catch(std::exception&){ };
00036     if(v1->inrange(v0))
00037       return new BooleanAttribute(true);
00038   }
00039   else if(fnName == NAME_STRING_IN_RANGE) {
00040     StringAttribute* v0;
00041     StringAttribute* v1;
00042     try{
00043       v0 = dynamic_cast<StringAttribute*>(arg0);
00044       v1 = dynamic_cast<StringAttribute*>(arg1);
00045     } catch(std::exception&){ };
00046     if(v1->inrange(v0))
00047       return new BooleanAttribute(true);
00048   }
00049   return new BooleanAttribute(false);
00050 }
00051 
00052 std::list<AttributeValue*> InRangeFunction::evaluate(std::list<AttributeValue*> args, bool check_id) {
00053   AttributeValue* arg0 = NULL;
00054   AttributeValue* arg1 = NULL;
00055   std::list<AttributeValue*>::iterator it = args.begin();
00056   arg0 = *it; it++;
00057   if(it!= args.end()) arg1 = *it;
00058   if(check_id) { 
00059     if(arg0->getId() != arg1->getId()) {
00060       std::list<AttributeValue*> ret;
00061       ret.push_back(new BooleanAttribute(false));
00062       return ret;
00063     }
00064   }
00065   AttributeValue* res = evaluate(arg0, arg1);
00066   std::list<AttributeValue*> ret;
00067   ret.push_back(res);
00068   return ret;
00069 }
00070 
00071 }