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/ip_match_from_file.h"
17 #include "src/utils/system.h"
18 
19 #include <string>
20 
21 #include <string.h>
22 
23 #include "src/operators/operator.h"
24 
25 namespace modsecurity {
26 namespace operators {
27 
28 
init(const std::string & file,std::string * error)29 bool IpMatchFromFile::init(const std::string &file,
30     std::string *error) {
31     std::string e("");
32     bool res = false;
33 
34     if (m_param.compare(0, 8, "https://") == 0) {
35         res = m_tree.addFromUrl(m_param, &e);
36     } else {
37         std::string resf = utils::find_resource(m_param, file, error);
38         if (resf == "") {
39             return false;
40         }
41         res = m_tree.addFromFile(resf, &e);
42     }
43 
44     if (res == false) {
45         error->assign(e);
46     }
47 
48     return res;
49 }
50 
51 
52 }  // namespace operators
53 }  // namespace modsecurity
54