summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2010-04-27 02:19:54 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2010-04-27 02:19:54 +0000
commit1392c781e7b496381f089ce4529c990cd74f00bc (patch)
tree5b0e728ed93ebe014ff6229a6dd59ccce84bd3a0 /qpid/cpp
parent00293798ca499fffa5dc9ea759df02472f4712cd (diff)
downloadqpid-python-1392c781e7b496381f089ce4529c990cd74f00bc.tar.gz
Reverting the change made in rev937119 as it seems to cause a core dump in RHEL5.
I haven't managed to pin point the issue. Once I do I may introduce the fix again with the required changes. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@938298 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/src/qpid/acl/AclData.cpp46
-rw-r--r--qpid/cpp/src/qpid/acl/AclData.h34
-rw-r--r--qpid/cpp/src/qpid/acl/AclReader.cpp31
-rw-r--r--qpid/cpp/src/qpid/acl/AclValidator.cpp25
-rw-r--r--qpid/cpp/src/qpid/acl/AclValidator.h4
5 files changed, 78 insertions, 62 deletions
diff --git a/qpid/cpp/src/qpid/acl/AclData.cpp b/qpid/cpp/src/qpid/acl/AclData.cpp
index f7143c33c1..a03d5b4d55 100644
--- a/qpid/cpp/src/qpid/acl/AclData.cpp
+++ b/qpid/cpp/src/qpid/acl/AclData.cpp
@@ -26,12 +26,22 @@ namespace acl {
AclData::AclData():decisionMode(qpid::acl::DENY),transferAcl(false),aclSource("UNKNOWN")
{
- actionList.resize(qpid::acl::ACTIONSIZE);
+ for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
+ actionList[cnt]=0;
+ }
+
}
void AclData::clear ()
{
- actionList.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];
+ }
+
}
bool AclData::matchProp(const std::string & src, const std::string& src1)
@@ -52,21 +62,21 @@ AclResult AclData::lookup(const std::string& id, const Action& action, const Obj
<< " with params " << AclHelper::propertyMapToString(params));
AclResult aclresult = decisionMode;
- 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 (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 (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)){
@@ -78,7 +88,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 '"
@@ -162,24 +172,24 @@ AclResult AclData::lookup(const std::string& id, const Action& action, const Obj
<< " with routing key " << RoutingKey);
AclResult aclresult = decisionMode;
-
- if (!actionList[action].empty() && !actionList[action][objType].empty()) {
- AclData::ActObjItr itrRule = actionList[action][objType].find(id);
+
+ 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 (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/qpid/cpp/src/qpid/acl/AclData.h b/qpid/cpp/src/qpid/acl/AclData.h
index f33aca4bc1..efd3b60145 100644
--- a/qpid/cpp/src/qpid/acl/AclData.h
+++ b/qpid/cpp/src/qpid/acl/AclData.h
@@ -32,42 +32,38 @@ 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 std::vector<ActionObject> AclAction;
- typedef std::vector<AclAction> ActionList;
-
- // vector<action> -> vector<objects> -> map<user -> vector<Rule> > -> map <AclProperty -> string>
-
- ActionList actionList;
-
+ 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];
qpid::acl::AclResult decisionMode; // determines if the rule set is a deny or allow mode.
bool transferAcl;
std::string aclSource;
diff --git a/qpid/cpp/src/qpid/acl/AclReader.cpp b/qpid/cpp/src/qpid/acl/AclReader.cpp
index 966e69d9f5..2f59f4453f 100644
--- a/qpid/cpp/src/qpid/acl/AclReader.cpp
+++ b/qpid/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,15 +138,17 @@ 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) << ",";
- if (d->actionList[acnt].empty()){
- d->actionList[acnt] = AclData::AclAction(qpid::acl::OBJECTSIZE);
+ //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;
}
// optimize this loop to limit to valid options only!!
@@ -155,6 +157,11 @@ 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 '*'
@@ -166,13 +173,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/qpid/cpp/src/qpid/acl/AclValidator.cpp b/qpid/cpp/src/qpid/acl/AclValidator.cpp
index e2d13fea92..aeaf638f54 100644
--- a/qpid/cpp/src/qpid/acl/AclValidator.cpp
+++ b/qpid/cpp/src/qpid/acl/AclValidator.cpp
@@ -104,28 +104,31 @@ 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++){
- for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
+ if (d->actionList[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].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));
- }
- }
- }
+ 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){
+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/qpid/cpp/src/qpid/acl/AclValidator.h b/qpid/cpp/src/qpid/acl/AclValidator.h
index 8504a7f2ae..966e5d326b 100644
--- a/qpid/cpp/src/qpid/acl/AclValidator.h
+++ b/qpid/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();