mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Decrease code nest level
This commit is contained in:
parent
12809656a6
commit
47bc24a808
@ -49,32 +49,33 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
|
|||||||
std::vector<std::string> tokens = split(m_param, ' ');
|
std::vector<std::string> tokens = split(m_param, ' ');
|
||||||
|
|
||||||
for (const auto& token : tokens) {
|
for (const auto& token : tokens) {
|
||||||
if (! token.empty()) {
|
if (token.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::istream> iss;
|
std::unique_ptr<std::istream> iss;
|
||||||
|
|
||||||
if (token.compare(0, 8, "https://") == 0) {
|
if (token.compare(0, 8, "https://") == 0) {
|
||||||
Utils::HttpsClient client;
|
Utils::HttpsClient client;
|
||||||
bool ret = client.download(token);
|
bool ret = client.download(token);
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
error->assign(client.error);
|
error->assign(client.error);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
iss = std::make_unique<std::stringstream>(client.content);
|
|
||||||
} else {
|
|
||||||
std::string err;
|
|
||||||
std::string resource = utils::find_resource(token, config, &err);
|
|
||||||
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
|
|
||||||
if (file->is_open() == false) {
|
|
||||||
error->assign("Failed to open file: '" + token + "'. " + err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
iss = std::move(file);
|
|
||||||
}
|
}
|
||||||
for (std::string line; std::getline(*iss, line); ) {
|
iss = std::make_unique<std::stringstream>(client.content);
|
||||||
if (isComment(line) == false) {
|
} else {
|
||||||
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
std::string err;
|
||||||
}
|
std::string resource = utils::find_resource(token, config, &err);
|
||||||
|
auto file = std::make_unique<std::ifstream>(resource, std::ios::in);
|
||||||
|
if (file->is_open() == false) {
|
||||||
|
error->assign("Failed to open file: '" + token + "'. " + err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
iss = std::move(file);
|
||||||
|
}
|
||||||
|
for (std::string line; std::getline(*iss, line); ) {
|
||||||
|
if (isComment(line) == false) {
|
||||||
|
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user