using namespace ldp_xml_parser;
-class OwnershipTree::TreeNode{
-public:
- TreeNode(std::string token);
- void add(std::deque<std::string>& tokens, const DecisionItem& decision, const bool is_prefix);
- void setDecisionItem(const DecisionItem& decision, const bool is_prefix);
- DecisionItem getDecisionItem(std::deque<std::string>& tokens) const;
-
-private:
- DecisionItem prefixBasedDecision() const;
-
- std::string __token; // element of dot-separated name
- DecisionItem __own_prefix_decision_item;
- DecisionItem __own_decision_item;
- std::unordered_map<std::string, std::shared_ptr<TreeNode>> __children;
- size_t getSize() const;
- friend class OwnershipTree;
-};
OwnershipTree::OwnershipTree() {
}
-OwnershipTree::TreeNode::TreeNode(std::string token)
+TreeNode::TreeNode(std::string token)
:__token(token), __own_prefix_decision_item(Decision::ANY), __own_decision_item(Decision::ANY)
{}
-void OwnershipTree::TreeNode::add(std::deque<std::string>& tokens, const DecisionItem& decision, const bool is_prefix)
+void TreeNode::add(std::deque<std::string>& tokens, const DecisionItem& decision, const bool is_prefix)
{
if (tokens.empty()) {
setDecisionItem(decision, is_prefix);
it->second->add(tokens, decision, is_prefix);
}
-size_t OwnershipTree::TreeNode::getSize() const
+size_t TreeNode::getSize() const
{
size_t size = sizeof(*this) + get_string_heap_allocated_memory(__token) + __own_decision_item.getSize()
+ __own_prefix_decision_item.getSize();
return size;
}
-void OwnershipTree::TreeNode::setDecisionItem(const DecisionItem& decision, const bool is_prefix)
+void TreeNode::setDecisionItem(const DecisionItem& decision, const bool is_prefix)
{
if (is_prefix) {
__own_prefix_decision_item = decision;
}
}
-DecisionItem OwnershipTree::TreeNode::getDecisionItem(std::deque<std::string>& tokens) const
+const std::string &TreeNode::getToken() const {
+ return __token;
+}
+
+const DecisionItem &TreeNode::getOwnPrefixDecisionItem() const {
+ return __own_prefix_decision_item;
+}
+
+const DecisionItem &TreeNode::getOwnDecisionItem() const {
+ return __own_decision_item;
+}
+
+const std::unordered_map<std::string, std::shared_ptr<TreeNode>> &TreeNode::getChildren() const {
+ return __children;
+}
+
+DecisionItem TreeNode::getDecisionItem(std::deque<std::string>& tokens) const
{
if (tokens.empty()) {
if (__own_decision_item.getDecision() != Decision::ANY) {
#include "policy.hpp"
#include <memory>
+#include <unordered_map>
+#include <deque>
namespace ldp_xml_parser
{
+
+ class TreeNode{
+ public:
+ TreeNode(std::string token);
+ void add(std::deque<std::string>& tokens, const DecisionItem& decision, const bool is_prefix);
+ void setDecisionItem(const DecisionItem& decision, const bool is_prefix);
+ DecisionItem getDecisionItem(std::deque<std::string>& tokens) const;
+ const std::string &getToken() const;
+ const DecisionItem &getOwnPrefixDecisionItem() const;
+ const DecisionItem &getOwnDecisionItem() const;
+ const std::unordered_map<std::string, std::shared_ptr<TreeNode>> &getChildren() const;
+ private:
+ DecisionItem prefixBasedDecision() const;
+
+ std::string __token; // element of dot-separated name
+ DecisionItem __own_prefix_decision_item;
+ DecisionItem __own_decision_item;
+ std::unordered_map<std::string, std::shared_ptr<TreeNode>> __children;
+ size_t getSize() const;
+ friend class OwnershipTree;
+ };
+
+
class OwnershipTree{
public:
OwnershipTree();
DecisionItem getDecisionItem(const MatchItemOwn& item) const;
void printTree() const;
size_t getSize() const;
-
+ const std::shared_ptr<TreeNode> getRoot() const { return __root; };
private:
- class TreeNode;
std::shared_ptr<TreeNode> __root;
void printTreeLevel(const TreeNode& node, const std::string& indent) const;
};
return __decision;
}
+const std::string &ItemSendReceive::getName() const {
+ return __name;
+}
+
+const std::string &ItemSendReceive::getInterface() const {
+ return __interface;
+}
+
+const std::string &ItemSendReceive::getMember() const {
+ return __member;
+}
+
+const std::string &ItemSendReceive::getPath() const {
+ return __path;
+}
+
+MessageType ItemSendReceive::getType() const {
+ return __type;
+}
+
+bool ItemSendReceive::isNamePrefix() const {
+ return __is_name_prefix;
+}
+
+
+
size_t ItemSendReceive::getSize() const
{
size_t size = __decision.getSize();
return __decision.getSize();
}
+uid_t ItemAccess::getUid() const {
+ return __uid;
+}
+
+gid_t ItemAccess::getGid() const {
+ return __gid;
+}
+
+BusAccessType ItemAccess::getType() const {
+ return __type;
+}
+
+
MatchItemAccess::MatchItemAccess(const uid_t uid, const std::vector<gid_t> &gids)
: __uid(uid),
__gids(gids) {
public:
friend class ItemBuilder;
const DecisionItem& getDecision() const;
+ const std::string &getName() const;
+ const std::string &getInterface() const;
+ const std::string &getMember() const;
+ const std::string &getPath() const;
+ MessageType getType() const;
+ bool isNamePrefix() const;
size_t getSize() const;
-
friend std::ostream &operator<<(std::ostream& stream, const ItemSendReceive &item);
};
std::ostream &operator<<(std::ostream& stream, const ItemSendReceive &item);
friend class ItemBuilder;
const DecisionItem& getDecision() const;
bool match(const MatchItemAccess& query) const;
+ uid_t getUid() const;
+ gid_t getGid() const;
+ BusAccessType getType() const;
size_t getSize() const;
friend std::ostream &operator<<(std::ostream& stream, const ItemAccess &item);
};
size += i.getSize();
return size;
}
+
+ const std::vector<TI> &getItems() const { return m_items; }
};
/****************** PolicySend ************************/
void printContent() const { ownership_tree.printTree(); }
size_t getSize() const { return ownership_tree.getSize(); }
+ const OwnershipTree &getTree() const { return ownership_tree; };
static constexpr const char *name = "own";
};
size_t getSize() const;
static constexpr const char *name = "access";
+ const std::vector<ItemAccess> &getItems() const { return m_items; }
};
}