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 #include "src/operators/contains.h"
17
18 #include <string>
19
20
21 namespace modsecurity {
22 namespace operators {
23
evaluate(Transaction * transaction,RuleWithActions * rule,const std::string & input,std::shared_ptr<RuleMessage> ruleMessage)24 bool Contains::evaluate(Transaction *transaction, RuleWithActions *rule,
25 const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
26 std::string p(m_string->evaluate(transaction));
27 size_t offset = input.find(p);
28
29 bool contains = offset != std::string::npos;
30
31 if (contains && transaction) {
32 logOffset(ruleMessage, offset, p.size());
33 transaction->m_matched.push_back(p);
34 }
35
36 return contains;
37 }
38
39 } // namespace operators
40 } // namespace modsecurity
41