]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1655 in SNORT/snort3 from ~AMSATHYA/snort3:identity_plugin to...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 26 Jun 2019 22:39:52 +0000 (18:39 -0400)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 26 Jun 2019 22:39:52 +0000 (18:39 -0400)
Squashed commit of the following:

commit c02b0069cf999ed917432358ee7df8c5734b0bf0
Author: haow3 <haow3@cisco.com>
Date:   Mon Jun 24 12:56:26 2019 -0400

    flow: Extend stash to support uint32_t and make it SO_PUBLIC

src/flow/flow_stash.cc
src/flow/flow_stash.h
src/flow/stash_item.h
src/flow/test/flow_stash_test.cc

index 7a9681cbae35b68ea2f090727d4020071f56582b..13a2f31563834f445f458e5113a24e119d506a7d 100644 (file)
 
 // flow_stash.cc author Shravan Rangaraju <shrarang@cisco.com>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "flow_stash.h"
 
 #include <cassert>
@@ -46,6 +50,11 @@ bool FlowStash::get(const string& key, int32_t& val)
     return get(key, val, STASH_ITEM_TYPE_INT32);
 }
 
+bool FlowStash::get(const string& key, uint32_t& val)
+{
+    return get(key, val, STASH_ITEM_TYPE_UINT32);
+}
+
 bool FlowStash::get(const string& key, string& val)
 {
     return get(key, val, STASH_ITEM_TYPE_STRING);
@@ -61,6 +70,11 @@ void FlowStash::store(const string& key, int32_t val)
     store(key, val, STASH_ITEM_TYPE_INT32);
 }
 
+void FlowStash::store(const string& key, uint32_t val)
+{
+    store(key, val, STASH_ITEM_TYPE_UINT32);
+}
+
 void FlowStash::store(const string& key, const string& val)
 {
     store(key, val, STASH_ITEM_TYPE_STRING);
index 5e53d98447628af51303de4219d58dbfe32d07c7..a422555e31d11413916887b204cb0be8790b3d54 100644 (file)
 namespace snort
 {
 
-class FlowStash
+class SO_PUBLIC FlowStash
 {
 public:
     ~FlowStash();
     void reset();
     bool get(const std::string& key, int32_t& val);
+    bool get(const std::string& key, uint32_t& val);
     bool get(const std::string& key, std::string& val);
     bool get(const std::string& key, StashGenericObject* &val);
     void store(const std::string& key, int32_t val);
+    void store(const std::string& key, uint32_t val);
     void store(const std::string& key, const std::string& val);
     void store(const std::string& key, std::string* val);
     void store(const std::string& key, StashGenericObject* val);
index df26f0f473df8e67ae12d7c4eab59fcff465f519..63daf304cefaeafd62feb43a83e6c5f7a1fba7ca 100644 (file)
@@ -46,6 +46,7 @@ private:
 enum StashItemType
 {
     STASH_ITEM_TYPE_INT32,
+    STASH_ITEM_TYPE_UINT32,
     STASH_ITEM_TYPE_STRING,
     STASH_ITEM_TYPE_GENERIC_OBJECT
 };
@@ -53,6 +54,7 @@ enum StashItemType
 union StashItemVal
 {
     int32_t int32_val;
+    uint32_t uint32_val;
     std::string* str_val;
     StashGenericObject* generic_obj_val;
 };
@@ -66,6 +68,12 @@ public:
         val.int32_val = int32_val;
     }
 
+    StashItem(uint32_t uint32_val)
+    {
+        type = STASH_ITEM_TYPE_UINT32;
+        val.uint32_val = uint32_val;
+    }
+
     StashItem(const std::string& str_val)
     {
         type = STASH_ITEM_TYPE_STRING;
@@ -104,6 +112,9 @@ public:
     void get_val(int32_t& int32_val) const
     { int32_val = val.int32_val; }
 
+    void get_val(uint32_t& uint32_val) const
+    { uint32_val = val.uint32_val; }
+
     void get_val(std::string& str_val) const
     { str_val = *(val.str_val); }
 
index 74f554e6db417344f9aa74f8acf8b99ddacf6f11..ffd1200e41c9fef13c67c01ea3070a0a3e1163c2 100644 (file)
@@ -209,6 +209,31 @@ TEST(stash_tests, update_int32_item)
     CHECK_EQUAL(val, 20);
 }
 
+TEST(stash_tests, new_uint32_item)
+{
+    FlowStash stash;
+
+    stash.store("item_1", 10u);
+
+    uint32_t val;
+
+    CHECK(stash.get("item_1", val));
+    CHECK_EQUAL(val, 10u);
+}
+
+TEST(stash_tests, update_uint32_item)
+{
+    FlowStash stash;
+
+    stash.store("item_1", 10u);
+    stash.store("item_1", 20u);
+
+    uint32_t val;
+
+    CHECK(stash.get("item_1", val));
+    CHECK_EQUAL(val, 20u);
+}
+
 TEST(stash_tests, new_str_item_ref)
 {
     FlowStash stash;