1 /*
2  * ModSecurity, http://www.modsecurity.org/
3  * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4  *
5  * You may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * If any of the files related to licensing are missing or if you have any
11  * other questions related to licensing please contact Trustwave Holdings, Inc.
12  * directly using the email address security@modsecurity.org.
13  *
14  */
15 
16 #ifndef SRC_OPERATORS_FUZZY_HASH_H_
17 #define SRC_OPERATORS_FUZZY_HASH_H_
18 
19 #include <string>
20 #include <memory>
21 #include <utility>
22 
23 #ifdef WITH_SSDEEP
24 #include <fuzzy.h>
25 #endif
26 
27 #include "src/operators/operator.h"
28 
29 namespace modsecurity {
30 namespace operators {
31 
32 
33 struct fuzzy_hash_chunk {
34     char *data;
35     struct fuzzy_hash_chunk *next;
36 };
37 
38 class FuzzyHash : public Operator {
39  public:
40     /** @ingroup ModSecurity_Operator */
FuzzyHash(std::unique_ptr<RunTimeString> param)41     explicit FuzzyHash(std::unique_ptr<RunTimeString> param)
42         : Operator("FuzzyHash", std::move(param)),
43         m_threshold(0),
44         m_head(NULL) { }
45     ~FuzzyHash();
46 
47     bool evaluate(Transaction *transaction, const std::string &std) override;
48 
49     bool init(const std::string &param, std::string *error) override;
50  private:
51     int m_threshold;
52     struct fuzzy_hash_chunk *m_head;
53 };
54 
55 }  // namespace operators
56 }  // namespace modsecurity
57 
58 
59 #endif  // SRC_OPERATORS_FUZZY_HASH_H_
60