diff options
author | Charles E. Rolke <chug@apache.org> | 2012-02-17 17:16:33 +0000 |
---|---|---|
committer | Charles E. Rolke <chug@apache.org> | 2012-02-17 17:16:33 +0000 |
commit | 1b56500400c5f846c8f828af3385b035b63f8f66 (patch) | |
tree | 4454c23619b028968a072ba9feb4828723b7dcf7 /cpp/src/qpid/acl/AclValidator.cpp | |
parent | 5b18da896e9889e1e9382d7f6ebcfe8012d95aef (diff) | |
download | qpid-python-1b56500400c5f846c8f828af3385b035b63f8f66.tar.gz |
NO-JIRA ACL whitespace police.
No code change.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1245660 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/acl/AclValidator.cpp')
-rw-r--r-- | cpp/src/qpid/acl/AclValidator.cpp | 232 |
1 files changed, 116 insertions, 116 deletions
diff --git a/cpp/src/qpid/acl/AclValidator.cpp b/cpp/src/qpid/acl/AclValidator.cpp index 57b68e520a..d5a00b005b 100644 --- a/cpp/src/qpid/acl/AclValidator.cpp +++ b/cpp/src/qpid/acl/AclValidator.cpp @@ -29,122 +29,122 @@ namespace qpid { namespace acl { -AclValidator::IntPropertyType::IntPropertyType(int64_t i,int64_t j) : min(i), max(j){ -} - -bool AclValidator::IntPropertyType::validate(const std::string& val) { - int64_t v; - try - { - v = boost::lexical_cast<int64_t>(val); - }catch(const boost::bad_lexical_cast&){ - return 0; - } - - if (v < min || v >= max){ - return 0; - }else{ - return 1; - } -} - -std::string AclValidator::IntPropertyType::allowedValues() { - return "values should be between " + - boost::lexical_cast<std::string>(min) + " and " + - boost::lexical_cast<std::string>(max); -} - -AclValidator::EnumPropertyType::EnumPropertyType(std::vector<std::string>& allowed): values(allowed){ -} - -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; - } - } - - return 0; -} - -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++ ){ - oss << "'" << *itr << "' "; - } - oss << "}"; - return oss.str(); -} - -AclValidator::AclValidator(){ - validators.insert(Validator(acl::PROP_MAXQUEUESIZE, - boost::shared_ptr<PropertyType>( - new IntPropertyType(0,std::numeric_limits<int64_t>::max())) - ) - ); - - validators.insert(Validator(acl::PROP_MAXQUEUECOUNT, - 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<PropertyType>(new EnumPropertyType(v)) - ) - ); - -} - -AclValidator::~AclValidator(){ -} - -/* Iterate through the data model and validate the parameters. */ -void AclValidator::validate(boost::shared_ptr<AclData> d) { - - for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){ - - if (d->actionList[cnt]){ - - for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++){ - - if (d->actionList[cnt][cnt1]){ - - 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()); - } + AclValidator::IntPropertyType::IntPropertyType(int64_t i,int64_t j) : min(i), max(j){ + } + + bool AclValidator::IntPropertyType::validate(const std::string& val) { + int64_t v; + try + { + v = boost::lexical_cast<int64_t>(val); + }catch(const boost::bad_lexical_cast&){ + return 0; + } + + if (v < min || v >= max){ + return 0; + }else{ + return 1; + } + } + + std::string AclValidator::IntPropertyType::allowedValues() { + return "values should be between " + + boost::lexical_cast<std::string>(min) + " and " + + boost::lexical_cast<std::string>(max); + } + + AclValidator::EnumPropertyType::EnumPropertyType(std::vector<std::string>& allowed): values(allowed){ + } + + 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; + } + } + + return 0; + } + + 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++ ){ + oss << "'" << *itr << "' "; + } + oss << "}"; + return oss.str(); + } + + AclValidator::AclValidator(){ + validators.insert(Validator(acl::PROP_MAXQUEUESIZE, + boost::shared_ptr<PropertyType>( + new IntPropertyType(0,std::numeric_limits<int64_t>::max())) + ) + ); + + validators.insert(Validator(acl::PROP_MAXQUEUECOUNT, + 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<PropertyType>(new EnumPropertyType(v)) + ) + ); + + } + + AclValidator::~AclValidator(){ + } + + /* Iterate through the data model and validate the parameters. */ + void AclValidator::validate(boost::shared_ptr<AclData> d) { + + for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){ + + if (d->actionList[cnt]){ + + for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++){ + + if (d->actionList[cnt][cnt1]){ + + 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()); + } + } } -} }} |