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/ends_with.h"
17
18 #include <string>
19
20 #include "src/operators/operator.h"
21
22 namespace modsecurity {
23 namespace operators {
24
25
evaluate(Transaction * transaction,RuleWithActions * rule,const std::string & str,std::shared_ptr<RuleMessage> ruleMessage)26 bool EndsWith::evaluate(Transaction *transaction, RuleWithActions *rule,
27 const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
28 bool ret = false;
29 std::string p(m_string->evaluate(transaction));
30
31 if (str.length() >= p.length()) {
32 ret = (0 == str.compare(str.length() - p.length(),
33 p.length(), p));
34 if (ret) {
35 logOffset(ruleMessage, str.length() - p.length(),
36 p.size());
37 }
38 }
39
40 return ret;
41 }
42
43
44 } // namespace operators
45 } // namespace modsecurity
46