00001 #ifndef QPID_ACL_ACLREADER_H
00002 #define QPID_ACL_ACLREADER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <boost/shared_ptr.hpp>
00024 #include <map>
00025 #include <set>
00026 #include <string>
00027 #include <vector>
00028
00029 #include "qpid/acl/AclData.h"
00030 #include "qpid/broker/AclModule.h"
00031
00032 namespace qpid {
00033 namespace acl {
00034
00035 class AclReader {
00036 typedef std::set<std::string> nameSet;
00037 typedef nameSet::const_iterator nsCitr;
00038 typedef boost::shared_ptr<nameSet> nameSetPtr;
00039
00040 typedef std::pair<std::string, nameSetPtr> groupPair;
00041 typedef std::map<std::string, nameSetPtr> groupMap;
00042 typedef groupMap::const_iterator gmCitr;
00043 typedef std::pair<gmCitr, bool> gmRes;
00044
00045 typedef std::pair<Property, std::string> propNvPair;
00046 typedef std::map<Property, std::string> propMap;
00047 typedef propMap::const_iterator pmCitr;
00048
00049 class aclRule {
00050 public:
00051 enum objectStatus {NONE, VALUE, ALL};
00052 AclResult res;
00053 nameSet names;
00054 bool actionAll;
00055 Action action;
00056 objectStatus objStatus;
00057 ObjectType object;
00058 propMap props;
00059 public:
00060 aclRule(const AclResult r, const std::string n, const groupMap& groups);
00061 aclRule(const AclResult r, const std::string n, const groupMap& groups, const Action a);
00062 void setObjectType(const ObjectType o);
00063 void setObjectTypeAll();
00064 bool addProperty(const Property p, const std::string v);
00065 bool validate(const AclHelper::objectMapPtr& validationMap);
00066 std::string toString();
00067 private:
00068 void processName(const std::string& name, const groupMap& groups);
00069 };
00070 typedef boost::shared_ptr<aclRule> aclRulePtr;
00071 typedef std::vector<aclRulePtr> ruleList;
00072 typedef ruleList::const_iterator rlCitr;
00073
00074 typedef std::vector<std::string> tokList;
00075 typedef tokList::const_iterator tlCitr;
00076
00077 typedef std::set<std::string> keywordSet;
00078 typedef keywordSet::const_iterator ksCitr;
00079 typedef std::pair<std::string, std::string> nvPair;
00080
00081 std::string fileName;
00082 int lineNumber;
00083 bool contFlag;
00084 std::string groupName;
00085 nameSet names;
00086 groupMap groups;
00087 ruleList rules;
00088 AclHelper::objectMapPtr validationMap;
00089
00090 public:
00091 AclReader();
00092 virtual ~AclReader();
00093 int read(const std::string& fn, boost::shared_ptr<AclData> d);
00094
00095 private:
00096 bool processLine(char* line);
00097 void loadDecisionData( boost::shared_ptr<AclData> d);
00098 int tokenize(char* line, tokList& toks);
00099
00100 bool processGroupLine(tokList& toks, const bool cont);
00101 gmCitr addGroup(const std::string& groupName);
00102 void addName(const std::string& name, nameSetPtr groupNameSet);
00103 void addName(const std::string& name);
00104 void printNames() const;
00105
00106 bool processAclLine(tokList& toks);
00107 void printRules() const;
00108
00109 static bool checkName(const std::string& name);
00110 static nvPair splitNameValuePair(const std::string& nvpString);
00111 };
00112
00113 }}
00114
00115 #endif // QPID_ACL_ACLREADER_H