]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1493 in SNORT/snort3 from ~SMINUT/snort3:ips_file_type to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Mon, 28 Jan 2019 18:27:14 +0000 (13:27 -0500)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Mon, 28 Jan 2019 18:27:14 +0000 (13:27 -0500)
Squashed commit of the following:

commit 6c2e6330bb957da3783c47a1406ecebb479af7cf
Author: Silviu Minut <sminut@cisco.com>
Date:   Wed Jan 23 09:25:26 2019 -0500

    ips_options: implement FileTypeOption::hash() and FileTypeOption::operator==(), inherited from IpsOption, using the types bitset array, in order to distinguish between different file type options.

    ips_options: change strncmp to plain strcmp per reviewers' comments.

src/ips_options/ips_file_type.cc

index fc65490dc7f070c4e97a24d065eda86c59d48f17..9bb160f474f396439de39159d1f6b1ac9087e50b 100644 (file)
@@ -29,6 +29,7 @@
 #include "log/messages.h"
 #include "profiler/profiler.h"
 #include "protocols/packet.h"
+#include "hash/hashfcn.h"
 
 using namespace snort;
 
@@ -41,6 +42,9 @@ class FileTypeOption : public IpsOption
 public:
     FileTypeOption(FileTypeBitSet&);
 
+    uint32_t hash() const override;
+    bool operator==(const IpsOption& ips) const override;
+
     CursorActionType get_cursor_type() const override
     { return CAT_NONE; }
 
@@ -58,6 +62,23 @@ FileTypeOption::FileTypeOption(FileTypeBitSet& t) : IpsOption(s_name)
     types = t;
 }
 
+uint32_t FileTypeOption::hash() const
+{
+    uint32_t a = 0, b = 0, c = 0;
+    mix_str(a, b, c, get_name());
+    mix_str(a, b, c, types.to_string().c_str());
+    finalize(a, b, c);
+    return c;
+}
+
+bool FileTypeOption::operator==(const IpsOption& ips) const
+{
+    if ( strcmp(get_name(), ips.get_name()) )
+        return false;
+
+    return types == ((const FileTypeOption&) ips).types;
+}
+
 IpsOption::EvalStatus FileTypeOption::eval(Cursor&, Packet* pkt)
 {
     Profile profile(fileTypePerfStats);
@@ -270,4 +291,3 @@ const BaseApi* ips_file_type[] =
     &file_type_api.base,
     nullptr
 };
-