From 28c144c7443301030f2f12ab1b75e9cf843fe6e4 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 14 Feb 2019 08:58:42 +0100 Subject: [PATCH] serialization: move TreeNode definition and add getters Change-Id: I40c7bc6c59f29bfc6b35930893aa54eacbab6fb4 --- src/internal/own_tree.cpp | 43 +++++++++++++++++++------------------- src/internal/own_tree.hpp | 28 +++++++++++++++++++++++-- src/internal/policy.cpp | 39 ++++++++++++++++++++++++++++++++++ src/internal/policy.hpp | 10 ++++++++- src/internal/policy_containers.hpp | 4 ++++ 5 files changed, 99 insertions(+), 25 deletions(-) diff --git a/src/internal/own_tree.cpp b/src/internal/own_tree.cpp index 3f25963..21ea4a9 100644 --- a/src/internal/own_tree.cpp +++ b/src/internal/own_tree.cpp @@ -12,23 +12,6 @@ using namespace ldp_xml_parser; -class OwnershipTree::TreeNode{ -public: - TreeNode(std::string token); - void add(std::deque& tokens, const DecisionItem& decision, const bool is_prefix); - void setDecisionItem(const DecisionItem& decision, const bool is_prefix); - DecisionItem getDecisionItem(std::deque& 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> __children; - size_t getSize() const; - friend class OwnershipTree; -}; OwnershipTree::OwnershipTree() { @@ -89,11 +72,11 @@ size_t OwnershipTree::getSize() const } -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& tokens, const DecisionItem& decision, const bool is_prefix) +void TreeNode::add(std::deque& tokens, const DecisionItem& decision, const bool is_prefix) { if (tokens.empty()) { setDecisionItem(decision, is_prefix); @@ -115,7 +98,7 @@ void OwnershipTree::TreeNode::add(std::deque& tokens, const Decisio 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(); @@ -126,7 +109,7 @@ size_t OwnershipTree::TreeNode::getSize() const 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; @@ -137,7 +120,23 @@ void OwnershipTree::TreeNode::setDecisionItem(const DecisionItem& decision, cons } } -DecisionItem OwnershipTree::TreeNode::getDecisionItem(std::deque& 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> &TreeNode::getChildren() const { + return __children; +} + +DecisionItem TreeNode::getDecisionItem(std::deque& tokens) const { if (tokens.empty()) { if (__own_decision_item.getDecision() != Decision::ANY) { diff --git a/src/internal/own_tree.hpp b/src/internal/own_tree.hpp index 4f986b3..cd67969 100644 --- a/src/internal/own_tree.hpp +++ b/src/internal/own_tree.hpp @@ -25,9 +25,34 @@ #include "policy.hpp" #include +#include +#include namespace ldp_xml_parser { + + class TreeNode{ + public: + TreeNode(std::string token); + void add(std::deque& tokens, const DecisionItem& decision, const bool is_prefix); + void setDecisionItem(const DecisionItem& decision, const bool is_prefix); + DecisionItem getDecisionItem(std::deque& tokens) const; + const std::string &getToken() const; + const DecisionItem &getOwnPrefixDecisionItem() const; + const DecisionItem &getOwnDecisionItem() const; + const std::unordered_map> &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> __children; + size_t getSize() const; + friend class OwnershipTree; + }; + + class OwnershipTree{ public: OwnershipTree(); @@ -35,9 +60,8 @@ namespace ldp_xml_parser DecisionItem getDecisionItem(const MatchItemOwn& item) const; void printTree() const; size_t getSize() const; - + const std::shared_ptr getRoot() const { return __root; }; private: - class TreeNode; std::shared_ptr __root; void printTreeLevel(const TreeNode& node, const std::string& indent) const; }; diff --git a/src/internal/policy.cpp b/src/internal/policy.cpp index c2422ac..06f4322 100644 --- a/src/internal/policy.cpp +++ b/src/internal/policy.cpp @@ -175,6 +175,32 @@ const DecisionItem& ItemSendReceive::getDecision() 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(); @@ -225,6 +251,19 @@ size_t ItemAccess::getSize() const 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 &gids) : __uid(uid), __gids(gids) { diff --git a/src/internal/policy.hpp b/src/internal/policy.hpp index 7ebc8cc..008151c 100644 --- a/src/internal/policy.hpp +++ b/src/internal/policy.hpp @@ -198,8 +198,13 @@ namespace ldp_xml_parser 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); @@ -254,6 +259,9 @@ namespace ldp_xml_parser 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); }; diff --git a/src/internal/policy_containers.hpp b/src/internal/policy_containers.hpp index e2b2664..3f24431 100644 --- a/src/internal/policy_containers.hpp +++ b/src/internal/policy_containers.hpp @@ -47,6 +47,8 @@ public: size += i.getSize(); return size; } + + const std::vector &getItems() const { return m_items; } }; /****************** PolicySend ************************/ @@ -80,6 +82,7 @@ public: 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"; }; @@ -99,5 +102,6 @@ public: size_t getSize() const; static constexpr const char *name = "access"; + const std::vector &getItems() const { return m_items; } }; } -- 2.7.4