20
20
#include " src/operators/operator.h"
21
21
#include " src/utils/https_client.h"
22
22
#include " src/utils/system.h"
23
+ #include " src/utils/string.h"
23
24
25
+ using namespace modsecurity ::utils::string;
24
26
25
27
namespace modsecurity {
26
28
namespace operators {
@@ -44,39 +46,47 @@ bool PmFromFile::isComment(const std::string &s) {
44
46
}
45
47
46
48
bool PmFromFile::init (const std::string &config, std::string *error) {
47
- std::istream *iss;
48
-
49
- if (m_param.compare (0 , 8 , " https://" ) == 0 ) {
50
- Utils::HttpsClient client;
51
- bool ret = client.download (m_param);
52
- if (ret == false ) {
53
- error->assign (client.error );
54
- return false ;
55
- }
56
- iss = new std::stringstream (client.content );
57
- } else {
58
- std::string err;
59
- std::string resource = utils::find_resource (m_param, config, &err);
60
- iss = new std::ifstream (resource, std::ios::in);
49
+ std::vector<std::string> tokens = split (m_param, ' ' );
50
+
51
+ for (const auto & token : tokens) {
52
+ if (! token.empty ()) {
53
+
54
+ std::istream *iss;
55
+
56
+ if (token.compare (0 , 8 , " https://" ) == 0 ) {
57
+ Utils::HttpsClient client;
58
+ bool ret = client.download (token);
59
+ if (ret == false ) {
60
+ error->assign (client.error );
61
+ return false ;
62
+ }
63
+ iss = new std::stringstream (client.content );
64
+ } else {
65
+ std::string err;
66
+ std::string resource = utils::find_resource (token, config, &err);
67
+ iss = new std::ifstream (resource, std::ios::in);
68
+
69
+ if (((std::ifstream *)iss)->is_open () == false ) {
70
+ error->assign (" Failed to open file: '" + token + " '. " + err);
71
+ delete iss;
72
+ return false ;
73
+ }
74
+ }
75
+
76
+ for (std::string line; std::getline (*iss, line); ) {
77
+ if (isComment (line) == false ) {
78
+ acmp_add_pattern (m_p, line.c_str (), NULL , NULL , line.length ());
79
+ }
80
+ }
61
81
62
- if (((std::ifstream *)iss)->is_open () == false ) {
63
- error->assign (" Failed to open file: " + m_param + " . " + err);
64
82
delete iss;
65
- return false ;
66
83
}
67
84
}
68
85
69
- for (std::string line; std::getline (*iss, line); ) {
70
- if (isComment (line) == false ) {
71
- acmp_add_pattern (m_p, line.c_str (), NULL , NULL , line.length ());
72
- }
73
- }
74
-
75
86
while (m_p->is_failtree_done == 0 ) {
76
87
acmp_prepare (m_p);
77
88
}
78
89
79
- delete iss;
80
90
return true ;
81
91
}
82
92
0 commit comments