Add rule data get method 42/176342/2
authorseolheui kim <s414.kim@samsung.com>
Wed, 18 Apr 2018 12:13:42 +0000 (21:13 +0900)
committerseolheui kim <s414.kim@samsung.com>
Fri, 20 Apr 2018 02:28:16 +0000 (11:28 +0900)
Change-Id: I5022f87162e85eff80f503c6c3f95551251e4207
Signed-off-by: seolheui kim <s414.kim@samsung.com>
lib/rule/rule.cpp
lib/rule/rule.h

index b90f229a020271a7bbc600d31671789cde7a51b2..a95523e7dd417efdeea7801988836e30e9dcf53b 100644 (file)
@@ -40,6 +40,16 @@ Rule::~Rule()
 {
 }
 
+std::vector<char> Rule::data() const
+{
+       std::vector<char> ret(buf);
+       for (auto &c : conditions) {
+               if (c.second)
+                       c.second->emit(ret);
+       }
+       return ret;
+}
+
 void Rule::setTag(const std::string &tag)
 {
        //[TODO]: save tags
@@ -137,10 +147,3 @@ void Rule::setComponents(const std::vector<char> &rule)
                }
        }
 }
-
-void Rule::updateConditions()
-{
-       for (auto &c : conditions) {
-               c.second->emit(buf);
-       }
-}
index 065ebc422b1b518380f1c7f981c4954c9637ffa4..28a30a4d9239269b1eb0da323cefff9e62341b48 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __AUDIT_RULE_H__
 #define __AUDIT_RULE_H__
 
-#include <unordered_map>
+#include <map>
 #include <memory>
 
 #include <linux/audit.h>
@@ -67,7 +67,7 @@ public:
 
        bool operator == (const Rule &rule)
        {
-               return buf == rule.buf;
+               return (data() == rule.data());
        }
 
        RuleType type() const
@@ -75,6 +75,8 @@ public:
                return _type;
        }
 
+       std::vector<char> data() const;
+
        void set(RuleType type)
        {
                _type = type;
@@ -111,11 +113,10 @@ private:
 
        bool isStringField(unsigned int type) const;
        void setComponents(const std::vector<char> &rule);
-       void updateConditions();
 private:
        RuleType _type;
        std::vector<char> buf;
-       std::unordered_map<unsigned int, std::shared_ptr<FieldBase>> conditions;
+       std::map<unsigned int, std::shared_ptr<FieldBase>> conditions;
 };
 
 template <typename T>