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

View File

@ -24,7 +24,7 @@
namespace modsecurity { namespace modsecurity {
namespace operators { namespace operators {
#ifdef WITH_LIBXML2
bool ValidateDTD::init(const std::string &file, std::string *error) { bool ValidateDTD::init(const std::string &file, std::string *error) {
std::string err; std::string err;
m_resource = utils::find_resource(m_param, file, &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; return false;
} }
#endif
} // namespace operators } // namespace operators
} // namespace modsecurity } // namespace modsecurity

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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