summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2010-04-23 00:57:35 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2010-04-23 00:57:35 +0000
commit0151d3f521ac13e626209aca8ddf1b91487c0359 (patch)
tree2d39ffa3f622ac73cef94ec1a07ac810a4bfd6b0 /cpp/src
parent329f1b6a959ab19f345ca4499c43590cf60c963d (diff)
downloadqpid-python-0151d3f521ac13e626209aca8ddf1b91487c0359.tar.gz
Changed from using arrays to using vectors.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@937119 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/acl/AclData.cpp46
-rw-r--r--cpp/src/qpid/acl/AclData.h34
-rw-r--r--cpp/src/qpid/acl/AclReader.cpp31
-rw-r--r--cpp/src/qpid/acl/AclValidator.cpp25
-rw-r--r--cpp/src/qpid/acl/AclValidator.h4
5 files changed, 62 insertions, 78 deletions
diff --git a/cpp/src/qpid/acl/AclData.cpp b/cpp/src/qpid/acl/AclData.cpp
index a03d5b4d55..f7143c33c1 100644
--- a/cpp/src/qpid/acl/AclData.cpp
+++ b/cpp/src/qpid/acl/AclData.cpp
@@ -26,22 +26,12 @@ namespace acl {
AclData::AclData():decisionMode(qpid::acl::DENY),transferAcl(false),aclSource("UNKNOWN")
{
- for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
- actionList[cnt]=0;
- }
-
+ actionList.resize(qpid::acl::ACTIONSIZE);
}
void AclData::clear ()
{
- for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
- if (actionList[cnt]){
- for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++)
- delete actionList[cnt][cnt1];
- }
- delete[] actionList[cnt];
- }
-
+ actionList.clear();
}
bool AclData::matchProp(const std::string & src, const std::string& src1)
@@ -62,21 +52,21 @@ AclResult AclData::lookup(const std::string& id, const Action& action, const Obj
<< " with params " << AclHelper::propertyMapToString(params));
AclResult aclresult = decisionMode;
- if (actionList[action] && actionList[action][objType]) {
- AclData::actObjItr itrRule = actionList[action][objType]->find(id);
- if (itrRule == actionList[action][objType]->end())
- itrRule = actionList[action][objType]->find("*");
+ if (!actionList[action].empty() && !actionList[action][objType].empty()) {
+ AclData::ActObjItr itrRule = actionList[action][objType].find(id);
+ if (itrRule == actionList[action][objType].end())
+ itrRule = actionList[action][objType].find("*");
- if (itrRule != actionList[action][objType]->end()) {
+ if (itrRule != actionList[action][objType].end()) {
QPID_LOG(debug, "ACL: checking the following rules for : " << itrRule->first );
//loop the vector
- for (ruleSetItr i = itrRule->second.begin(); i < itrRule->second.end(); i++) {
+ for (RuleSetItr i = itrRule->second.begin(); i < itrRule->second.end(); i++) {
QPID_LOG(debug, "ACL: checking rule " << i->toString());
// loop the names looking for match
bool match = true;
- for (propertyMapItr pMItr = i->props.begin(); (pMItr != i->props.end()) && match; pMItr++) {
+ for (PropertyMapItr pMItr = i->props.begin(); (pMItr != i->props.end()) && match; pMItr++) {
//match name is exists first
if (pMItr->first == acl::PROP_NAME) {
if (matchProp(pMItr->second, name)){
@@ -88,7 +78,7 @@ AclResult AclData::lookup(const std::string& id, const Action& action, const Obj
<< pMItr->second << "' given in the rule");
}
} else if (params) { //match pMItr against params
- propertyMapItr paramItr = params->find(pMItr->first);
+ PropertyMapItr paramItr = params->find(pMItr->first);
if (paramItr == params->end()) {
match = false;
QPID_LOG(debug, "ACL: the given parameter map in lookup doesn't contain the property '"
@@ -172,24 +162,24 @@ AclResult AclData::lookup(const std::string& id, const Action& action, const Obj
<< " with routing key " << RoutingKey);
AclResult aclresult = decisionMode;
-
- if (actionList[action] && actionList[action][objType]){
- AclData::actObjItr itrRule = actionList[action][objType]->find(id);
+
+ if (!actionList[action].empty() && !actionList[action][objType].empty()) {
+ AclData::ActObjItr itrRule = actionList[action][objType].find(id);
- if (itrRule == actionList[action][objType]->end())
- itrRule = actionList[action][objType]->find("*");
+ if (itrRule == actionList[action][objType].end())
+ itrRule = actionList[action][objType].find("*");
- if (itrRule != actionList[action][objType]->end() ) {
+ if (itrRule != actionList[action][objType].end() ) {
QPID_LOG(debug, "ACL: checking the following rules for : " << itrRule->first );
//loop the vector
- for (ruleSetItr i=itrRule->second.begin(); i<itrRule->second.end(); i++) {
+ for (RuleSetItr i=itrRule->second.begin(); i<itrRule->second.end(); i++) {
QPID_LOG(debug, "ACL: checking rule " << i->toString());
// loop the names looking for match
bool match =true;
- for (propertyMapItr pMItr = i->props.begin(); (pMItr != i->props.end()) && match; pMItr++)
+ for (PropertyMapItr pMItr = i->props.begin(); (pMItr != i->props.end()) && match; pMItr++)
{
//match name is exists first
if (pMItr->first == acl::PROP_NAME){
diff --git a/cpp/src/qpid/acl/AclData.h b/cpp/src/qpid/acl/AclData.h
index efd3b60145..f33aca4bc1 100644
--- a/cpp/src/qpid/acl/AclData.h
+++ b/cpp/src/qpid/acl/AclData.h
@@ -32,38 +32,42 @@ class AclData {
public:
- typedef std::map<qpid::acl::Property, std::string> propertyMap;
- typedef propertyMap::const_iterator propertyMapItr;
- struct rule {
+ typedef std::map<qpid::acl::Property, std::string> PropertyMap;
+ typedef PropertyMap::const_iterator PropertyMapItr;
+ struct Rule {
bool log;
bool logOnly; // this is a rule is to log only
// key value map
//??
- propertyMap props;
+ PropertyMap props;
- rule (propertyMap& p):log(false),logOnly(false),props(p) {};
+ Rule (PropertyMap& p):log(false),logOnly(false),props(p) {};
std::string toString () const {
std::ostringstream ruleStr;
ruleStr << "[log=" << log << ", logOnly=" << logOnly << " props{";
- for (propertyMapItr pMItr = props.begin(); pMItr != props.end(); pMItr++) {
+ for (PropertyMapItr pMItr = props.begin(); pMItr != props.end(); pMItr++) {
ruleStr << " " << AclHelper::getPropertyStr((Property) pMItr-> first) << "=" << pMItr->second;
}
ruleStr << " }]";
return ruleStr.str();
- }
+ }
};
- typedef std::vector<rule> ruleSet;
- typedef ruleSet::const_iterator ruleSetItr;
- typedef std::map<std::string, ruleSet > actionObject; // user
- typedef actionObject::iterator actObjItr;
- typedef actionObject* aclAction;
-
- // Action*[] -> Object*[] -> map<user -> set<Rule> >
- aclAction* actionList[qpid::acl::ACTIONSIZE];
+
+ typedef std::vector<Rule> RuleSet;
+ typedef RuleSet::const_iterator RuleSetItr;
+ typedef std::map<std::string, RuleSet > ActionObject; // user
+ typedef ActionObject::iterator ActObjItr;
+ typedef std::vector<ActionObject> AclAction;
+ typedef std::vector<AclAction> ActionList;
+
+ // vector<action> -> vector<objects> -> map<user -> vector<Rule> > -> map <AclProperty -> string>
+
+ ActionList actionList;
+
qpid::acl::AclResult decisionMode; // determines if the rule set is a deny or allow mode.
bool transferAcl;
std::string aclSource;
diff --git a/cpp/src/qpid/acl/AclReader.cpp b/cpp/src/qpid/acl/AclReader.cpp
index 2f59f4453f..966e69d9f5 100644
--- a/cpp/src/qpid/acl/AclReader.cpp
+++ b/cpp/src/qpid/acl/AclReader.cpp
@@ -101,7 +101,7 @@ void AclReader::loadDecisionData(boost::shared_ptr<AclData> d) {
<< AclHelper::getAclResultStr(d->decisionMode));
foundmode = true;
} else {
- AclData::rule rule((*i)->props);
+ AclData::Rule rule((*i)->props);
bool addrule = true;
switch ((*i)->res) {
@@ -138,17 +138,15 @@ void AclReader::loadDecisionData(boost::shared_ptr<AclData> d) {
acnt < acl::ACTIONSIZE;
(*i)->actionAll ? acnt++ : acnt = acl::ACTIONSIZE) {
- if (acnt == acl::ACT_PUBLISH)
+ if (acnt == acl::ACT_PUBLISH) {
d->transferAcl = true; // we have transfer ACL
-
+ QPID_LOG(debug, "Transfer ACL enabled !");
+ }
+
actionstr << AclHelper::getActionStr((Action) acnt) << ",";
- //find the Action, create if not exist
- if (d->actionList[acnt] == NULL) {
- d->actionList[acnt] =
- new AclData::aclAction[qpid::acl::OBJECTSIZE];
- for (int j = 0; j < qpid::acl::OBJECTSIZE; j++)
- d->actionList[acnt][j] = NULL;
+ if (d->actionList[acnt].empty()){
+ d->actionList[acnt] = AclData::AclAction(qpid::acl::OBJECTSIZE);
}
// optimize this loop to limit to valid options only!!
@@ -157,11 +155,6 @@ void AclReader::loadDecisionData(boost::shared_ptr<AclData> d) {
ocnt < acl::OBJECTSIZE;
(*i)->objStatus != aclRule::VALUE ? ocnt++ : ocnt = acl::OBJECTSIZE) {
- //find the Object, create if not exist
- if (d->actionList[acnt][ocnt] == NULL)
- d->actionList[acnt][ocnt] =
- new AclData::actionObject;
-
// add users and Rule to object set
bool allNames = false;
// check to see if names.begin is '*'
@@ -173,13 +166,13 @@ void AclReader::loadDecisionData(boost::shared_ptr<AclData> d) {
itr != (allNames ? names.end() : (*i)->names.end());
itr++) {
- AclData::actObjItr itrRule =
- d->actionList[acnt][ocnt]->find(*itr);
+ AclData::ActObjItr itrRule =
+ d->actionList[acnt][ocnt].find(*itr);
- if (itrRule == d->actionList[acnt][ocnt]->end()) {
- AclData::ruleSet rSet;
+ if (itrRule == d->actionList[acnt][ocnt].end()) {
+ AclData::RuleSet rSet;
rSet.push_back(rule);
- d->actionList[acnt][ocnt]->insert
+ d->actionList[acnt][ocnt].insert
(make_pair(std::string(*itr), rSet));
} else {
// TODO add code to check for dead rules
diff --git a/cpp/src/qpid/acl/AclValidator.cpp b/cpp/src/qpid/acl/AclValidator.cpp
index aeaf638f54..e2d13fea92 100644
--- a/cpp/src/qpid/acl/AclValidator.cpp
+++ b/cpp/src/qpid/acl/AclValidator.cpp
@@ -104,31 +104,28 @@ 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 cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
- for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++){
+ for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++){
- if (d->actionList[cnt][cnt1]){
+ if (!d->actionList[cnt].empty() && !d->actionList[cnt][cnt1].empty()){
+ std::for_each(d->actionList[cnt][cnt1].begin(),
+ d->actionList[cnt][cnt1].end(),
+ boost::bind(&AclValidator::validateRuleSet, this, _1));
+ }
+ }
+ }
- 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){
+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){
+void AclValidator::validateRule(qpid::acl::AclData::Rule& rule){
std::for_each(rule.props.begin(),
rule.props.end(),
boost::bind(&AclValidator::validateProperty, this, _1));
diff --git a/cpp/src/qpid/acl/AclValidator.h b/cpp/src/qpid/acl/AclValidator.h
index 966e5d326b..8504a7f2ae 100644
--- a/cpp/src/qpid/acl/AclValidator.h
+++ b/cpp/src/qpid/acl/AclValidator.h
@@ -70,8 +70,8 @@ class AclValidator {
public:
- void validateRuleSet(std::pair<const std::string, qpid::acl::AclData::ruleSet>& rules);
- void validateRule(qpid::acl::AclData::rule& rule);
+ 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();