2020#include " src/operators/operator.h"
2121#include " src/utils/https_client.h"
2222#include " src/utils/system.h"
23+ #include " src/utils/string.h"
2324
25+ using namespace modsecurity ::utils::string;
2426
2527namespace modsecurity {
2628namespace operators {
@@ -44,39 +46,47 @@ bool PmFromFile::isComment(const std::string &s) {
4446}
4547
4648bool 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+ }
6181
62- if (((std::ifstream *)iss)->is_open () == false ) {
63- error->assign (" Failed to open file: " + m_param + " . " + err);
6482 delete iss;
65- return false ;
6683 }
6784 }
6885
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-
7586 while (m_p->is_failtree_done == 0 ) {
7687 acmp_prepare (m_p);
7788 }
7889
79- delete iss;
8090 return true ;
8191}
8292
0 commit comments