Makes the build system to look for yajl using a macro file

Now searching for yajl using find_yajl.m4 macro file instead
of using pkg-config directly. If YAJL was not found or if it
was disabled in the configure phase, the code will be compiled
without JSON support.
This commit is contained in:
Felipe Zimmerle
2013-12-03 13:41:08 -08:00
committed by Felipe Zimmerle
parent e90874a694
commit 8d4c3e4f5c
10 changed files with 242 additions and 26 deletions

View File

@@ -38,7 +38,8 @@ mod_security2_la_CFLAGS = @APR_CFLAGS@ \
@LIBXML2_CFLAGS@ \
@LUA_CFLAGS@ \
@MODSEC_EXTRA_CFLAGS@ \
@PCRE_CFLAGS@
@PCRE_CFLAGS@ \
@YAJL_CFLAGS@
mod_security2_la_CPPFLAGS = @APR_CPPFLAGS@ \
@@ -49,7 +50,8 @@ mod_security2_la_LIBADD = @APR_LDADD@ \
@APU_LDADD@ \
@LIBXML2_LDADD@ \
@LUA_LDADD@ \
@PCRE_LDADD@
@PCRE_LDADD@ \
@YAJL_LDADD@
if AIX
mod_security2_la_LDFLAGS = -module -avoid-version \
@@ -58,7 +60,8 @@ mod_security2_la_LDFLAGS = -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if HPUX
@@ -68,7 +71,8 @@ mod_security2_la_LDFLAGS = -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if MACOSX
@@ -78,7 +82,8 @@ mod_security2_la_LDFLAGS = -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if SOLARIS
@@ -88,7 +93,8 @@ mod_security2_la_LDFLAGS = -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if LINUX
@@ -98,7 +104,8 @@ mod_security2_la_LDFLAGS = -no-undefined -module -avoid-version -R @PCRE_LD_PATH
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if FREEBSD
@@ -108,7 +115,8 @@ mod_security2_la_LDFLAGS = -no-undefined -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if OPENBSD
@@ -118,7 +126,8 @@ mod_security2_la_LDFLAGS = -no-undefined -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if NETBSD
@@ -128,7 +137,8 @@ mod_security2_la_LDFLAGS = -no-undefined -module -avoid-version \
@APXS_LDFLAGS@ \
@LIBXML2_LDFLAGS@ \
@LUA_LDFLAGS@ \
@PCRE_LDFLAGS@
@PCRE_LDFLAGS@ \
@YAJL_LDFLAGS@
endif
if LINUX

View File

@@ -256,8 +256,10 @@ static apr_status_t modsecurity_tx_cleanup(void *data) {
/* XML processor cleanup. */
if (msr->xml != NULL) xml_cleanup(msr);
#ifdef WITH_YAJL
/* JSON processor cleanup. */
if (msr->json != NULL) json_cleanup(msr);
#endif
// TODO: Why do we ignore return code here?
modsecurity_request_body_clear(msr, &my_error_msg);

View File

@@ -59,7 +59,6 @@ typedef struct msc_parm msc_parm;
#include "msc_lua.h"
#endif
#define PHASE_REQUEST_HEADERS 1
#define PHASE_REQUEST_BODY 2
#define PHASE_RESPONSE_HEADERS 3
@@ -369,7 +368,9 @@ struct modsec_rec {
multipart_data *mpd; /* MULTIPART processor data structure */
xml_data *xml; /* XML processor data structure */
#ifdef WITH_YAJL
json_data *json; /* JSON processor data structure */
#endif
/* audit logging */
char *new_auditlog_boundary;

View File

@@ -14,6 +14,8 @@
#include "msc_json.h"
#ifdef WITH_YAJL
int json_add_argument(modsec_rec *msr, const char *value, unsigned length)
{
msc_arg *arg = (msc_arg *) NULL;
@@ -311,3 +313,4 @@ apr_status_t json_cleanup(modsec_rec *msr) {
return 1;
}
#endif

View File

@@ -14,11 +14,19 @@
#ifndef _MSC_JSON_H_
#define _MSC_JSON_H_
#ifdef WITH_YAJL
typedef struct json_data json_data;
#include "modsecurity.h"
#include <yajl/yajl_parse.h>
//#ifdef WITH_YAJL
//#else
#include "modsecurity.h"
/* Structures */
struct json_data {
@@ -46,3 +54,4 @@ int DSOLOCAL json_complete(modsec_rec *msr, char **error_msg);
apr_status_t DSOLOCAL json_cleanup(modsec_rec *msr);
#endif
#endif

View File

@@ -128,12 +128,19 @@ apr_status_t modsecurity_request_body_start(modsec_rec *msr, char **error_msg) {
}
}
else if (strcmp(msr->msc_reqbody_processor, "JSON") == 0) {
#ifdef WITH_YAJL
if (json_init(msr, &my_error_msg) < 0) {
*error_msg = apr_psprintf(msr->mp, "JSON parsing error (init): %s", my_error_msg);
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = my_error_msg;
msr_log(msr, 2, "%s", *error_msg);
}
#else
*error_msg = apr_psprintf(msr->mp, "JSON support was not enabled");
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = my_error_msg;
msr_log(msr, 2, "%s", *error_msg);
#endif
}
else if (strcmp(msr->msc_reqbody_processor, "URLENCODED") == 0) {
/* Do nothing, URLENCODED processor does not support streaming yet. */
@@ -356,13 +363,20 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
/* Increase per-request data length counter. */
msr->msc_reqbody_no_files_length += length;
/* Process data as XML. */
/* Process data as JSON. */
#ifdef WITH_YAJL
if (json_process_chunk(msr, data, length, &my_error_msg) < 0) {
*error_msg = apr_psprintf(msr->mp, "JSON parsing error: %s", my_error_msg);
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
}
#else
*error_msg = apr_psprintf(msr->mp, "JSON support was not enabled");
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
#endif
}
else if (strcmp(msr->msc_reqbody_processor, "URLENCODED") == 0) {
/* Increase per-request data length counter. */
@@ -622,6 +636,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
}
}
else if (strcmp(msr->msc_reqbody_processor, "JSON") == 0) {
#ifdef WITH_YAJL
if (json_complete(msr, &my_error_msg) < 0) {
*error_msg = apr_psprintf(msr->mp, "JSON parser error: %s", my_error_msg);
msr->msc_reqbody_error = 1;
@@ -629,6 +644,14 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
msr_log(msr, 2, "%s", *error_msg);
return -1;
}
#else
*error_msg = apr_psprintf(msr->mp, "JSON support was not enabled");
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
return -1;
#endif
}
else if (strcmp(msr->msc_reqbody_processor, "URLENCODED") == 0) {
return modsecurity_request_body_end_urlencoded(msr, error_msg);