Fix compilation issue while xml is disabled

This commit is contained in:
Felipe Zimmerle 2018-02-21 16:15:05 -03:00
parent ff782ddfa4
commit ac100785d1
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
9 changed files with 54 additions and 6 deletions

View File

@ -21,8 +21,10 @@
#include <yajl/yajl_tree.h>
#include <yajl/yajl_gen.h>
#endif
#ifdef WITH_LIBXML2
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#endif
#ifdef MSC_WITH_CURL
#include <curl/curl.h>
#endif
@ -78,7 +80,9 @@ ModSecurity::ModSecurity()
#ifdef MSC_WITH_CURL
curl_global_init(CURL_GLOBAL_ALL);
#endif
#ifdef WITH_LIBXML2
xmlInitParser();
#endif
}
@ -89,8 +93,9 @@ ModSecurity::~ModSecurity() {
#ifdef WITH_GEOIP
Utils::GeoLookup::getInstance().cleanUp();
#endif
#ifdef WITH_LIBXML2
xmlCleanupParser();
#endif
delete m_global_collection;
delete m_resource_collection;
delete m_ip_collection;

View File

@ -24,7 +24,7 @@
namespace modsecurity {
namespace operators {
#ifdef WITH_LIBXML2
bool ValidateDTD::init(const std::string &file, std::string *error) {
std::string err;
m_resource = utils::find_resource(m_param, file, &err);
@ -112,7 +112,7 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
return false;
}
#endif
} // namespace operators
} // namespace modsecurity

View File

@ -19,9 +19,10 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#ifdef WITH_LIBXML2
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#endif
#include <string>
#include <memory>
#include <utility>
@ -37,6 +38,7 @@ class ValidateDTD : public Operator {
/** @ingroup ModSecurity_Operator */
explicit ValidateDTD(std::unique_ptr<RunTimeString> param)
: Operator("ValidateDTD", std::move(param)) { }
#ifdef WITH_LIBXML2
~ValidateDTD() {
if (m_dtd != NULL) {
xmlFreeDtd(m_dtd);
@ -92,6 +94,7 @@ class ValidateDTD : public Operator {
private:
std::string m_resource;
xmlDtdPtr m_dtd;
#endif
};
} // namespace operators

View File

@ -25,6 +25,8 @@
namespace modsecurity {
namespace operators {
#ifdef WITH_LIBXML2
bool ValidateSchema::init(const std::string &file, std::string *error) {
std::string err;
m_resource = utils::find_resource(m_param, file, &err);
@ -146,6 +148,7 @@ bool ValidateSchema::evaluate(Transaction *t,
return false;
}
#endif
} // namespace operators
} // namespace modsecurity

View File

@ -19,9 +19,10 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#ifdef WITH_LIBXML2
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#endif
#include <string>
#include <memory>
#include <utility>
@ -35,6 +36,10 @@ namespace operators {
class ValidateSchema : public Operator {
public:
/** @ingroup ModSecurity_Operator */
#ifndef WITH_LIBXML2
explicit ValidateSchema(std::unique_ptr<RunTimeString> param)
: Operator("ValidateSchema", std::move(param)) { }
#else
explicit ValidateSchema(std::unique_ptr<RunTimeString> param)
: Operator("ValidateSchema", std::move(param)),
m_parserCtx(NULL),
@ -133,6 +138,7 @@ class ValidateSchema : public Operator {
xmlSchemaPtr m_schema;
std::string m_resource;
std::string m_err;
#endif
};
} // namespace operators

View File

@ -23,6 +23,7 @@
namespace modsecurity {
namespace RequestBodyProcessor {
#ifdef WITH_LIBXML2
XML::XML(Transaction *transaction)
: m_transaction(transaction) {
@ -148,6 +149,7 @@ bool XML::complete(std::string *error) {
return true;
}
#endif
} // namespace RequestBodyProcessor
} // namespace modsecurity

View File

@ -13,9 +13,10 @@
*
*/
#ifdef WITH_LIBXML2
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#endif
#include <string>
#include <iostream>
@ -30,6 +31,7 @@
namespace modsecurity {
namespace RequestBodyProcessor {
#ifdef WITH_LIBXML2
struct xml_data {
xmlSAXHandler *sax_handler;
@ -63,6 +65,8 @@ class XML {
std::string m_header;
};
#endif
} // namespace RequestBodyProcessor
} // namespace modsecurity

View File

@ -126,7 +126,11 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
#else
m_json(NULL),
#endif
#ifdef WITH_LIBXML2
m_xml(new RequestBodyProcessor::XML(this)),
#else
m_xml(NULL),
#endif
TransactionAnchoredVariables(this) {
m_id = std::to_string(this->m_timeStamp) + \
std::to_string(modsecurity::utils::generate_transaction_unique_id());
@ -159,7 +163,9 @@ Transaction::~Transaction() {
#ifdef WITH_YAJL
delete m_json;
#endif
#ifdef WITH_LIBXML2
delete m_xml;
#endif
}
@ -666,6 +672,7 @@ int Transaction::processRequestBody() {
*/
std::unique_ptr<std::string> a = m_variableRequestHeaders.resolveFirst(
"Content-Type");
#ifdef WITH_LIBXML2
if (m_requestBodyProcessor == XMLRequestBody) {
std::string error;
if (m_xml->init() == true) {
@ -685,8 +692,13 @@ int Transaction::processRequestBody() {
m_variableReqbodyError.set("0", m_variableOffset);
m_variableReqbodyProcessorError.set("0", m_variableOffset);
}
#endif
#if WITH_YAJL
#ifdef WITH_LIBXML2
} else if (m_requestBodyProcessor == JSONRequestBody) {
#else
if (m_requestBodyProcessor == JSONRequestBody) {
#endif
std::string error;
if (m_json->init() == true) {
m_json->processChunk(m_requestBody.str().c_str(),
@ -706,7 +718,11 @@ int Transaction::processRequestBody() {
m_variableReqbodyProcessorError.set("0", m_variableOffset);
}
#endif
#if defined(WITH_LIBXML2) or defined(WITH_YAJL)
} else if (m_requestBodyType == MultiPartRequestBody) {
#else
if (m_requestBodyType == MultiPartRequestBody) {
#endif
std::string error;
if (a != NULL) {
Multipart m(*a, this);

View File

@ -21,11 +21,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef WITH_LIBXML2
#include <libxml/xmlschemas.h>
#include <libxml/xpath.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xpathInternals.h>
#endif
#include <iostream>
#include <string>
@ -44,6 +46,12 @@
namespace modsecurity {
namespace Variables {
#ifndef WITH_LIBXML2
void XML::evaluate(Transaction *t,
Rule *rule,
std::vector<const VariableValue *> *l) { }
#else
void XML::evaluate(Transaction *t,
Rule *rule,
std::vector<const VariableValue *> *l) {
@ -138,6 +146,7 @@ void XML::evaluate(Transaction *t,
xmlXPathFreeContext(xpathCtx);
}
#endif
} // namespace Variables
} // namespace modsecurity