refactoring: introduce MatchItemOwn for matching 92/199092/6
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 1 Feb 2019 15:11:29 +0000 (16:11 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Mon, 11 Feb 2019 11:08:47 +0000 (12:08 +0100)
Change-Id: I0c01db965a1b4d61cea0ac7f0b825d93cb331ed9

src/internal/naive_policy_checker.cpp
src/internal/naive_policy_checker.hpp
src/internal/naive_policy_db.cpp
src/internal/naive_policy_db.hpp
src/internal/own_tree.cpp
src/internal/own_tree.hpp
src/internal/policy.cpp
src/internal/policy.hpp

index 389b7db..431f88e 100755 (executable)
@@ -60,7 +60,7 @@ DecisionResult NaivePolicyChecker::check(bool bus_type,
                                                           gid_t gid,
                                                           const char* const label,
                                                           const char* const name) {
-       auto ret = checkItem<NaivePolicyDb::PolicyOwn, ItemOwn>(bus_type, uid, gid, name, ItemType::OWN);
+       auto ret = checkItem<NaivePolicyDb::PolicyOwn, MatchItemOwn>(bus_type, uid, gid, name, ItemType::OWN);
        return parseDecision(ret, uid, label);
 }
 
@@ -91,9 +91,9 @@ DecisionItem NaivePolicyChecker::checkPolicy(const NaivePolicyDb::PolicySR& poli
        return Decision::ANY;
 }
 
-DecisionItem NaivePolicyChecker::checkPolicy(const NaivePolicyDb::PolicyOwn& policy, const ItemOwn& item) const
+DecisionItem NaivePolicyChecker::checkPolicy(const NaivePolicyDb::PolicyOwn& policy, const MatchItemOwn& item) const
 {
-       tslog::log_verbose("Checking policy for name: ", std::string(item.getName() ?  item.getName() : "NULL"), "\n");
+       tslog::log_verbose("Checking policy for name: ", std::string(item.getName().empty() ? "NULL" : item.getName()), "\n");
 
        return policy.getDecisionItem(item);
 }
index c15eab0..807083b 100644 (file)
@@ -62,7 +62,7 @@ namespace ldp_xml_parser
                 * \ingroup Implementation
                 */
                DecisionItem checkPolicy(const NaivePolicyDb::PolicyOwn& policy,
-                                                        const ItemOwn& item) const;
+                                                        const MatchItemOwn& item) const;
 
                /** Checks access policy for given item
                 * \param[in] policy Policy to check
index fe08543..52d8d78 100755 (executable)
@@ -185,7 +185,7 @@ void NaivePolicyDb::PolicyOwn::printContent() const
        ownership_tree.printTree();
 }
 
-DecisionItem NaivePolicyDb::PolicyOwn::getDecisionItem(const ItemOwn& item) const
+DecisionItem NaivePolicyDb::PolicyOwn::getDecisionItem(const MatchItemOwn& item) const
 {
        return ownership_tree.getDecisionItem(item);
 }
index cedc27a..9fd8164 100755 (executable)
@@ -71,7 +71,7 @@ namespace ldp_xml_parser
                         * \param[in] item Item to add to policy
                         */
                        void addItem(ItemOwn* item);
-                       DecisionItem getDecisionItem(const ItemOwn& item) const;
+                       DecisionItem getDecisionItem(const MatchItemOwn& item) const;
                        void printContent() const;
                        size_t getSize() const;
                };
index 9ae9b19..b9cc3d2 100644 (file)
@@ -61,14 +61,13 @@ void OwnershipTree::addItem(ItemOwn* item) {
        __root->add(tokens, item->getDecision(), item->isPrefix());
 }
 
-DecisionItem OwnershipTree::getDecisionItem(const ItemOwn& item) const
+DecisionItem OwnershipTree::getDecisionItem(const MatchItemOwn& item) const
 {
-       if (item.getName() == nullptr) {
+       if (item.getName().length() == 0) {
                return Decision::DENY;
        }
-       std::string name = item.getName();
 
-       auto tokens = tokenize(name);
+       auto tokens = tokenize(item.getName());
        return __root->getDecisionItem(tokens);
 }
 
index 669a3e8..b052fea 100644 (file)
@@ -32,7 +32,7 @@ namespace ldp_xml_parser
        public:
                OwnershipTree();
                void addItem(ItemOwn* item);
-               DecisionItem getDecisionItem(const ItemOwn& item) const;
+               DecisionItem getDecisionItem(const MatchItemOwn& item) const;
                void printTree() const;
                size_t getSize() const;
 
index 0316fb7..d9fe047 100755 (executable)
@@ -585,6 +585,11 @@ std::ostream &operator<<(std::ostream& stream, const ItemOwn &item)
                "), pref(" << item.__is_prefix << ")";
 }
 
+std::ostream &operator<<(std::ostream& stream, const MatchItemOwn &item)
+{
+       return stream << (item._name.empty() ? "NULL" : item._name);
+}
+
 std::ostream &operator<<(std::ostream& stream, const MatchItemSR &item)
 {
        stream << "matcher: services(";
index 0c3a04b..e72d8b3 100755 (executable)
@@ -128,6 +128,17 @@ namespace ldp_xml_parser
        };
        std::ostream &operator<<(std::ostream& stream, const DecisionItem &di);
 
+       class MatchItemOwn {
+       private:
+               std::string _name;
+       public:
+               MatchItemOwn(const char *name) : _name(name) {}
+               const std::string &getName() const { return _name; }
+
+               friend std::ostream &operator<<(std::ostream& stream, const MatchItemOwn &item);
+       };
+       std::ostream &operator<<(std::ostream& stream, const MatchItemOwn &item);
+
        /** Class contains info about ownership policy item */
        class ItemOwn {
        private: