Skip to content

Commit ac10078

Browse files
author
Felipe Zimmerle
committed
Fix compilation issue while xml is disabled
1 parent ff782dd commit ac10078

File tree

9 files changed

+54
-6
lines changed

9 files changed

+54
-6
lines changed

src/modsecurity.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#include <yajl/yajl_tree.h>
2222
#include <yajl/yajl_gen.h>
2323
#endif
24+
#ifdef WITH_LIBXML2
2425
#include <libxml/xmlschemas.h>
2526
#include <libxml/xpath.h>
27+
#endif
2628
#ifdef MSC_WITH_CURL
2729
#include <curl/curl.h>
2830
#endif
@@ -78,7 +80,9 @@ ModSecurity::ModSecurity()
7880
#ifdef MSC_WITH_CURL
7981
curl_global_init(CURL_GLOBAL_ALL);
8082
#endif
83+
#ifdef WITH_LIBXML2
8184
xmlInitParser();
85+
#endif
8286
}
8387

8488

@@ -89,8 +93,9 @@ ModSecurity::~ModSecurity() {
8993
#ifdef WITH_GEOIP
9094
Utils::GeoLookup::getInstance().cleanUp();
9195
#endif
96+
#ifdef WITH_LIBXML2
9297
xmlCleanupParser();
93-
98+
#endif
9499
delete m_global_collection;
95100
delete m_resource_collection;
96101
delete m_ip_collection;

src/operators/validate_dtd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace modsecurity {
2525
namespace operators {
2626

27-
27+
#ifdef WITH_LIBXML2
2828
bool ValidateDTD::init(const std::string &file, std::string *error) {
2929
std::string err;
3030
m_resource = utils::find_resource(m_param, file, &err);
@@ -112,7 +112,7 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
112112

113113
return false;
114114
}
115-
115+
#endif
116116

117117
} // namespace operators
118118
} // namespace modsecurity

src/operators/validate_dtd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include <stdio.h>
2020
#include <stdarg.h>
2121
#include <string.h>
22+
#ifdef WITH_LIBXML2
2223
#include <libxml/xmlschemas.h>
2324
#include <libxml/xpath.h>
24-
25+
#endif
2526
#include <string>
2627
#include <memory>
2728
#include <utility>
@@ -37,6 +38,7 @@ class ValidateDTD : public Operator {
3738
/** @ingroup ModSecurity_Operator */
3839
explicit ValidateDTD(std::unique_ptr<RunTimeString> param)
3940
: Operator("ValidateDTD", std::move(param)) { }
41+
#ifdef WITH_LIBXML2
4042
~ValidateDTD() {
4143
if (m_dtd != NULL) {
4244
xmlFreeDtd(m_dtd);
@@ -92,6 +94,7 @@ class ValidateDTD : public Operator {
9294
private:
9395
std::string m_resource;
9496
xmlDtdPtr m_dtd;
97+
#endif
9598
};
9699

97100
} // namespace operators

src/operators/validate_schema.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
namespace modsecurity {
2626
namespace operators {
2727

28+
#ifdef WITH_LIBXML2
29+
2830
bool ValidateSchema::init(const std::string &file, std::string *error) {
2931
std::string err;
3032
m_resource = utils::find_resource(m_param, file, &err);
@@ -146,6 +148,7 @@ bool ValidateSchema::evaluate(Transaction *t,
146148
return false;
147149
}
148150

151+
#endif
149152

150153
} // namespace operators
151154
} // namespace modsecurity

src/operators/validate_schema.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include <stdio.h>
2020
#include <stdarg.h>
2121
#include <string.h>
22+
#ifdef WITH_LIBXML2
2223
#include <libxml/xmlschemas.h>
2324
#include <libxml/xpath.h>
24-
25+
#endif
2526
#include <string>
2627
#include <memory>
2728
#include <utility>
@@ -35,6 +36,10 @@ namespace operators {
3536
class ValidateSchema : public Operator {
3637
public:
3738
/** @ingroup ModSecurity_Operator */
39+
#ifndef WITH_LIBXML2
40+
explicit ValidateSchema(std::unique_ptr<RunTimeString> param)
41+
: Operator("ValidateSchema", std::move(param)) { }
42+
#else
3843
explicit ValidateSchema(std::unique_ptr<RunTimeString> param)
3944
: Operator("ValidateSchema", std::move(param)),
4045
m_parserCtx(NULL),
@@ -133,6 +138,7 @@ class ValidateSchema : public Operator {
133138
xmlSchemaPtr m_schema;
134139
std::string m_resource;
135140
std::string m_err;
141+
#endif
136142
};
137143

138144
} // namespace operators

src/request_body_processor/xml.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace modsecurity {
2424
namespace RequestBodyProcessor {
2525

26+
#ifdef WITH_LIBXML2
2627

2728
XML::XML(Transaction *transaction)
2829
: m_transaction(transaction) {
@@ -148,6 +149,7 @@ bool XML::complete(std::string *error) {
148149
return true;
149150
}
150151

152+
#endif
151153

152154
} // namespace RequestBodyProcessor
153155
} // namespace modsecurity

src/request_body_processor/xml.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
*
1414
*/
1515

16-
16+
#ifdef WITH_LIBXML2
1717
#include <libxml/xmlschemas.h>
1818
#include <libxml/xpath.h>
19+
#endif
1920

2021
#include <string>
2122
#include <iostream>
@@ -30,6 +31,7 @@
3031
namespace modsecurity {
3132
namespace RequestBodyProcessor {
3233

34+
#ifdef WITH_LIBXML2
3335

3436
struct xml_data {
3537
xmlSAXHandler *sax_handler;
@@ -63,6 +65,8 @@ class XML {
6365
std::string m_header;
6466
};
6567

68+
#endif
69+
6670
} // namespace RequestBodyProcessor
6771
} // namespace modsecurity
6872

src/transaction.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ Transaction::Transaction(ModSecurity *ms, Rules *rules, void *logCbData)
126126
#else
127127
m_json(NULL),
128128
#endif
129+
#ifdef WITH_LIBXML2
129130
m_xml(new RequestBodyProcessor::XML(this)),
131+
#else
132+
m_xml(NULL),
133+
#endif
130134
TransactionAnchoredVariables(this) {
131135
m_id = std::to_string(this->m_timeStamp) + \
132136
std::to_string(modsecurity::utils::generate_transaction_unique_id());
@@ -159,7 +163,9 @@ Transaction::~Transaction() {
159163
#ifdef WITH_YAJL
160164
delete m_json;
161165
#endif
166+
#ifdef WITH_LIBXML2
162167
delete m_xml;
168+
#endif
163169
}
164170

165171

@@ -666,6 +672,7 @@ int Transaction::processRequestBody() {
666672
*/
667673
std::unique_ptr<std::string> a = m_variableRequestHeaders.resolveFirst(
668674
"Content-Type");
675+
#ifdef WITH_LIBXML2
669676
if (m_requestBodyProcessor == XMLRequestBody) {
670677
std::string error;
671678
if (m_xml->init() == true) {
@@ -685,8 +692,13 @@ int Transaction::processRequestBody() {
685692
m_variableReqbodyError.set("0", m_variableOffset);
686693
m_variableReqbodyProcessorError.set("0", m_variableOffset);
687694
}
695+
#endif
688696
#if WITH_YAJL
697+
#ifdef WITH_LIBXML2
689698
} else if (m_requestBodyProcessor == JSONRequestBody) {
699+
#else
700+
if (m_requestBodyProcessor == JSONRequestBody) {
701+
#endif
690702
std::string error;
691703
if (m_json->init() == true) {
692704
m_json->processChunk(m_requestBody.str().c_str(),
@@ -706,7 +718,11 @@ int Transaction::processRequestBody() {
706718
m_variableReqbodyProcessorError.set("0", m_variableOffset);
707719
}
708720
#endif
721+
#if defined(WITH_LIBXML2) or defined(WITH_YAJL)
709722
} else if (m_requestBodyType == MultiPartRequestBody) {
723+
#else
724+
if (m_requestBodyType == MultiPartRequestBody) {
725+
#endif
710726
std::string error;
711727
if (a != NULL) {
712728
Multipart m(*a, this);

src/variables/xml.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
#include <sys/types.h>
2222
#include <sys/stat.h>
2323
#include <fcntl.h>
24+
#ifdef WITH_LIBXML2
2425
#include <libxml/xmlschemas.h>
2526
#include <libxml/xpath.h>
2627
#include <libxml/tree.h>
2728
#include <libxml/parser.h>
2829
#include <libxml/xpathInternals.h>
30+
#endif
2931

3032
#include <iostream>
3133
#include <string>
@@ -44,6 +46,12 @@
4446
namespace modsecurity {
4547
namespace Variables {
4648

49+
#ifndef WITH_LIBXML2
50+
void XML::evaluate(Transaction *t,
51+
Rule *rule,
52+
std::vector<const VariableValue *> *l) { }
53+
#else
54+
4755
void XML::evaluate(Transaction *t,
4856
Rule *rule,
4957
std::vector<const VariableValue *> *l) {
@@ -138,6 +146,7 @@ void XML::evaluate(Transaction *t,
138146
xmlXPathFreeContext(xpathCtx);
139147
}
140148

149+
#endif
141150

142151
} // namespace Variables
143152
} // namespace modsecurity

0 commit comments

Comments
 (0)