You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2010/04/12 23:10:30 UTC
svn commit: r933417 - in /qpid/trunk/qpid/cpp/src/qpid/acl: AclValidator.cpp
AclValidator.h
Author: rajith
Date: Mon Apr 12 21:10:29 2010
New Revision: 933417
URL: http://svn.apache.org/viewvc?rev=933417&view=rev
Log:
Simplified the vaidate method using for_each to make it more readable.
Also renamed AclProperty to PropertyType to avoid any confusion with acl::Property.
Modified:
qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp
qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h
Modified: qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp?rev=933417&r1=933416&r2=933417&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp Mon Apr 12 21:10:29 2010
@@ -22,16 +22,17 @@
#include "qpid/log/Statement.h"
#include "qpid/sys/IntegerTypes.h"
#include <boost/lexical_cast.hpp>
+#include <boost/bind.hpp>
#include <numeric>
#include <sstream>
namespace qpid {
namespace acl {
-AclValidator::AclIntProperty::AclIntProperty(int64_t i,int64_t j) : min(i), max(j){
+AclValidator::IntPropertyType::IntPropertyType(int64_t i,int64_t j) : min(i), max(j){
}
-bool AclValidator::AclIntProperty::validate(const std::string& val) {
+bool AclValidator::IntPropertyType::validate(const std::string& val) {
int64_t v;
try
{
@@ -47,16 +48,16 @@ bool AclValidator::AclIntProperty::valid
}
}
-std::string AclValidator::AclIntProperty::allowedValues() {
+std::string AclValidator::IntPropertyType::allowedValues() {
return "values should be between " +
boost::lexical_cast<std::string>(min) + " and " +
boost::lexical_cast<std::string>(max);
}
-AclValidator::AclEnumProperty::AclEnumProperty(std::vector<std::string>& allowed): values(allowed){
+AclValidator::EnumPropertyType::EnumPropertyType(std::vector<std::string>& allowed): values(allowed){
}
-bool AclValidator::AclEnumProperty::validate(const std::string& val) {
+bool AclValidator::EnumPropertyType::validate(const std::string& val) {
for (std::vector<std::string>::iterator itr = values.begin(); itr != values.end(); ++itr ){
if (val.compare(*itr) == 0){
return 1;
@@ -66,7 +67,7 @@ bool AclValidator::AclEnumProperty::vali
return 0;
}
-std::string AclValidator::AclEnumProperty::allowedValues() {
+std::string AclValidator::EnumPropertyType::allowedValues() {
std::ostringstream oss;
oss << "possible values are one of { ";
for (std::vector<std::string>::iterator itr = values.begin(); itr != values.end(); itr++ ){
@@ -78,21 +79,21 @@ std::string AclValidator::AclEnumPropert
AclValidator::AclValidator(){
validators.insert(Validator(acl::PROP_MAXQUEUESIZE,
- boost::shared_ptr<AclProperty>(
- new AclIntProperty(0,std::numeric_limits<int64_t>::max()))
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))
)
);
validators.insert(Validator(acl::PROP_MAXQUEUECOUNT,
- boost::shared_ptr<AclProperty>(
- new AclIntProperty(0,std::numeric_limits<int64_t>::max()))
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))
)
);
std::string policyTypes[] = {"ring", "ring_strict", "flow_to_disk", "reject"};
std::vector<std::string> v(policyTypes, policyTypes + sizeof(policyTypes) / sizeof(std::string));
validators.insert(Validator(acl::PROP_POLICYTYPE,
- boost::shared_ptr<AclProperty>(new AclEnumProperty(v))
+ boost::shared_ptr<PropertyType>(new EnumPropertyType(v))
)
);
@@ -112,30 +113,38 @@ void AclValidator::validate(boost::share
if (d->actionList[cnt][cnt1]){
- for (AclData::actObjItr actionMapItr = d->actionList[cnt][cnt1]->begin();
- actionMapItr != d->actionList[cnt][cnt1]->end(); actionMapItr++) {
-
- for (AclData::ruleSetItr i = actionMapItr->second.begin(); i < actionMapItr->second.end(); i++) {
-
- for (AclData::propertyMapItr pMItr = i->props.begin(); pMItr != i->props.end(); pMItr++) {
-
- ValidatorItr itr = validators.find(pMItr->first);
- if (itr != validators.end()){
- QPID_LOG(debug,"Found validator for property " << itr->second->allowedValues());
-
- if (!itr->second->validate(pMItr->second)){
- throw Exception( pMItr->second + " is not a valid value for '" +
- AclHelper::getPropertyStr(pMItr->first) + "', " +
- itr->second->allowedValues());
- }//if
- }//if
- }//for
- }//for
- }//for
+ std::for_each(d->actionList[cnt][cnt1]->begin(),
+ d->actionList[cnt][cnt1]->end(),
+ boost::bind(&AclValidator::validateRuleSet, this, _1));
}//if
}//for
}//if
}//for
}
+void AclValidator::validateRuleSet(std::pair<const std::string, qpid::acl::AclData::ruleSet>& rules){
+ std::for_each(rules.second.begin(),
+ rules.second.end(),
+ boost::bind(&AclValidator::validateRule, this, _1));
+}
+
+void AclValidator::validateRule(qpid::acl::AclData::rule& rule){
+ std::for_each(rule.props.begin(),
+ rule.props.end(),
+ boost::bind(&AclValidator::validateProperty, this, _1));
+}
+
+void AclValidator::validateProperty(std::pair<const qpid::acl::Property, std::string>& prop){
+ ValidatorItr itr = validators.find(prop.first);
+ if (itr != validators.end()){
+ QPID_LOG(debug,"Found validator for property " << itr->second->allowedValues());
+
+ if (!itr->second->validate(prop.second)){
+ throw Exception( prop.second + " is not a valid value for '" +
+ AclHelper::getPropertyStr(prop.first) + "', " +
+ itr->second->allowedValues());
+ }
+ }
+}
+
}}
Modified: qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h?rev=933417&r1=933416&r2=933417&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h Mon Apr 12 21:10:29 2010
@@ -33,49 +33,47 @@ namespace acl {
class AclValidator {
/* Base Property */
- class AclProperty{
- public:
- enum PropertyType { INT, STRING, ENUM };
-
+ class PropertyType{
+
public:
- virtual ~AclProperty(){};
- virtual int getType()=0;
+ virtual ~PropertyType(){};
virtual bool validate(const std::string& val)=0;
virtual std::string allowedValues()=0;
};
- class AclIntProperty : public AclProperty{
+ class IntPropertyType : public PropertyType{
int64_t min;
int64_t max;
public:
- AclIntProperty(int64_t min,int64_t max);
- virtual ~AclIntProperty (){};
- int getType(){ return AclProperty::INT; }
+ IntPropertyType(int64_t min,int64_t max);
+ virtual ~IntPropertyType (){};
virtual bool validate(const std::string& val);
virtual std::string allowedValues();
};
- class AclEnumProperty : public AclProperty{
+ class EnumPropertyType : public PropertyType{
std::vector<std::string> values;
public:
- AclEnumProperty(std::vector<std::string>& allowed);
- virtual ~AclEnumProperty (){};
- int getType(){ return AclProperty::ENUM; }
+ EnumPropertyType(std::vector<std::string>& allowed);
+ virtual ~EnumPropertyType (){};
virtual bool validate(const std::string& val);
virtual std::string allowedValues();
};
- typedef std::pair<acl::Property,boost::shared_ptr<AclProperty> > Validator;
- typedef std::map<acl::Property,boost::shared_ptr<AclProperty> > ValidatorMap;
+ typedef std::pair<acl::Property,boost::shared_ptr<PropertyType> > Validator;
+ typedef std::map<acl::Property,boost::shared_ptr<PropertyType> > ValidatorMap;
typedef ValidatorMap::iterator ValidatorItr;
ValidatorMap validators;
public:
-
- void validate(boost::shared_ptr<AclData> d);
+
+ void validateRuleSet(std::pair<const std::string, qpid::acl::AclData::ruleSet>& rules);
+ void validateRule(qpid::acl::AclData::rule& rule);
+ void validateProperty(std::pair<const qpid::acl::Property, std::string>& prop);
+ void validate(boost::shared_ptr<AclData> d);
AclValidator();
~AclValidator();
};
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org