ModSecurity/src/operators/pm_from_file.cc
2015-10-30 18:59:08 -03:00

63 lines
1.6 KiB
C++

/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include "operators/pm_from_file.h"
#include <string>
#include "operators/operator.h"
#include "utils/https_client.h"
#include "src/utils.h"
namespace ModSecurity {
namespace operators {
bool PmFromFile::init(const std::string &config, const char **error) {
std::istream *iss;
if (param.compare(0, 8, "https://") == 0) {
Utils::HttpsClient client;
bool ret = client.download(param);
if (ret == false) {
*error = client.error.c_str();
return false;
}
iss = new std::stringstream(client.content);
} else {
std::string resource = find_resource(param, config);
iss = new std::ifstream(resource, std::ios::in);
if (((std::ifstream *)iss)->is_open() == false) {
*error = std::string("Failed to open file: " + param).c_str();
delete iss;
return false;
}
}
for (std::string line; std::getline(*iss, line); ) {
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
}
acmp_prepare(m_p);
delete iss;
return true;
}
} // namespace operators
} // namespace ModSecurity