Back to index

nordugrid-arc-nox  1.1.0~rc6
StringAttribute.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include "StringAttribute.h"
00007 
00008 namespace ArcSec {
00009 
00010 std::string StringAttribute::identifier = "string";
00011 
00012 bool StringAttribute::equal(AttributeValue* o, bool check_id){
00013   StringAttribute *other;
00014   try{
00015     other = dynamic_cast<StringAttribute*>(o);
00016   } catch(std::exception&) { };
00017   if(other==NULL){
00018     //std::cerr<<"not StringAttribute"<<std::endl;
00019     return false;
00020   }
00021   if(check_id) { if(id != other->id) return false; }
00022   if((value.compare(other->getValue()))==0)
00023     return true;
00024   else
00025     return false;
00026 }
00027 
00028 bool StringAttribute::inrange(AttributeValue* o){
00029   StringAttribute *other;
00030   try{
00031     other = dynamic_cast<StringAttribute*>(o);
00032   } catch(std::exception&) { };
00033   if(other==NULL){
00034     //std::cerr<<"not StringAttribute"<<std::endl;
00035     return false;
00036   }
00037   if(id != other->id) return false;
00038 
00039   //if there is a few values in the policy side, e.g.
00040   //<Attribute AttributeId="urn:arc:fileoperation">read; write; delete</Attribute>
00041   std::string other_value = other->getValue();
00042 
00043   size_t p1, p2;
00044   std::string str, str1, str2;
00045   str = value;
00046 
00047   do {
00048     p1 = str.find_first_not_of(" ");
00049     p2 = str.find_first_of(";");
00050     if(p2!=std::string::npos)
00051       str1 = str.substr(p1,p2-p1);
00052     else str1 = str.substr(p1);
00053     
00054     size_t f1, f2;
00055     std::string o_str, o_str1, o_str2;
00056     o_str = other_value;
00057     bool match = false;
00058     do {
00059       f1 = o_str.find_first_not_of(" ");
00060       f2 = o_str.find_first_of(";");
00061       if(f2!=std::string::npos)
00062         o_str1 = o_str.substr(f1,f2-f1);
00063       else o_str1 = o_str.substr(f1);
00064       if((o_str1.compare(str1)) == 0) {
00065         match = true; break;
00066       }
00067       o_str2=o_str.substr(f2+1);
00068       o_str.clear(); o_str = o_str2; o_str2.clear();
00069     } while(f2!=std::string::npos);
00070     
00071     if(match == false) {return false;};
00072 
00073     str2=str.substr(p2+1);
00074     str.clear(); str = str2; str2.clear();
00075 
00076   } while(p2!=std::string::npos);
00077 
00078   return true;
00079 }
00080 
00081 
00082 } //namespace ArcSec