Makes YAJL dependency to be optional

This commit is contained in:
Felipe Zimmerle 2015-11-24 16:03:33 -03:00
parent cf4377df70
commit fbf8ea74f3
5 changed files with 180 additions and 127 deletions

View File

@ -2,11 +2,16 @@
ACLOCAL_AMFLAGS = -I build
if WITH_YAJL
WITH_TESTS = tests
endif
SUBDIRS = \
src \
test \
doc \
examples
examples \
$(WITH_TESTS)
# make clean
CLEANFILES =

View File

@ -1,155 +1,176 @@
dnl Check for YAJL Libraries
dnl CHECK_YAJL(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
dnl Sets:
dnl YAJL_CFLAGS
dnl YAJL_LDADD
dnl YAJL_LDFLAGS
dnl YAJL_LIBS
dnl YAJL_VERSION
AC_DEFUN([PROG_YAJL],
[dnl
AC_DEFUN([PROG_YAJL], [
# Needed if pkg-config will be used.
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
YAJL_CONFIG=""
# Possible names for the yajl library/package (pkg-config)
YAJL_POSSIBLE_LIB_NAMES="yajl2 yajl"
# Possible extensions for the library
YAJL_POSSIBLE_EXTENSIONS="so la sl dll dylib"
# Possible paths (if pkg-config was not found, proceed with the file lookup)
YAJL_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/libyajl /usr/local/yajl /usr/local /opt/libyajl /opt/yajl /opt /usr"
# Variables to be set by this very own script.
YAJL_VERSION=""
YAJL_CFLAGS=""
YAJL_CPPFLAGS=""
YAJL_LDADD=""
YAJL_LDFLAGS=""
YAJL_CONFIG=${PKG_CONFIG}
YAJL_PKGNAMES="yajl2 yajl"
YAJL_SONAMES="so la sl dll dylib"
AC_ARG_WITH(
yajl,
[AC_HELP_STRING([--with-yajl=PATH],[Path to yajl prefix or config script])]
,, with_yajl=yes)
AC_HELP_STRING(
[--with-yajl=PATH],
[Path to yajl prefix or config script]
)
)
AS_CASE(["${with_yajl}"],
[no], [test_paths=],
[yes], [test_paths="/usr/lib /usr/local/lib /usr/local/libyajl /usr/local/yajl /usr/local /opt/libyajl /opt/yajl /opt /usr"],
[test_paths="${with_yajl}"])
AS_IF([test "x${test_paths}" != "x"], [
AC_MSG_CHECKING([for libyajl config script])
for x in ${test_paths}; do
dnl # Determine if the script was specified and use it directly
if test ! -d "$x" -a -e "$x"; then
YAJL_CONFIG=$x
break
if test "x${with_yajl}" == "xno"; then
AC_DEFINE(HAVE_GEOIP, 0, [Support for GeoIP was disabled by the utilization of --without-yajl or --with-yajl=no])
AC_MSG_NOTICE([Support for GeoIP was disabled by the utilization of --without-yajl or --with-yajl=no])
YAJL_DISABLED=yes
else
if test "x${with_yajl}" == "xyes"; then
YAJL_MANDATORY=yes
AC_MSG_NOTICE([GeoIP support was marked as mandatory by the utilization of --with-yajl=yes])
fi
# for x in ${YAJL_POSSIBLE_LIB_NAMES}; do
# CHECK_FOR_YAJL_AT(${x})
# if test -n "${YAJL_VERSION}"; then
# break
# fi
# done
dnl # Try known config script names/locations
for y in $YAJL_CONFIG; do
if test -e "${x}/bin/${y}"; then
YAJL_CONFIG="${x}/bin/${y}"
yajl_config="${YAJL_CONFIG}"
break
elif test -e "${x}/${y}"; then
YAJL_CONFIG="${x}/${y}"
yajl_config="${YAJL_CONFIG}"
break
# if test "x${with_yajl}" != "xyes" or test "x${with_yajl}" == "xyes"; then
if test "x${with_yajl}" == "x" || test "x${with_yajl}" == "xyes"; then
# Nothing about GeoIP was informed, using the pkg-config to figure things out.
if test -n "${PKG_CONFIG}"; then
YAJL_PKG_NAME=""
for x in ${YAJL_POSSIBLE_LIB_NAMES}; do
if ${PKG_CONFIG} --exists ${x}; then
YAJL_PKG_NAME="$x"
break
fi
done
fi
AC_MSG_NOTICE([Nothing about GeoIP was informed during the configure phase. Trying to detect it on the platform...])
if test -n "${YAJL_PKG_NAME}"; then
# Package was found using the pkg-config scripts
YAJL_VERSION="`${PKG_CONFIG} ${YAJL_PKG_NAME} --modversion`"
YAJL_CFLAGS="`${PKG_CONFIG} ${YAJL_PKG_NAME} --cflags`"
YAJL_LDADD="`${PKG_CONFIG} ${YAJL_PKG_NAME} --libs-only-l`"
YAJL_LDFLAGS="`${PKG_CONFIG} ${YAJL_PKG_NAME} --libs-only-L --libs-only-other`"
YAJL_DISPLAY="${YAJL_LDADD}, ${YAJL_CFLAGS}"
else
# If pkg-config did not find anything useful, go over file lookup.
for x in ${YAJL_POSSIBLE_LIB_NAMES}; do
CHECK_FOR_YAJL_AT(${x})
if test -n "${YAJL_VERSION}"; then
break
fi
done
fi
fi
done
if test -n "${yajl_config}"; then
break
fi
done
dnl # Try known package names
if test -n "${YAJL_CONFIG}"; then
YAJL_PKGNAME=""
for x in ${YAJL_PKGNAMES}; do
if ${YAJL_CONFIG} --exists ${x}; then
YAJL_PKGNAME="$x"
break
if test "x${with_yajl}" != "x"; then
# An specific path was informed, lets check.
YAJL_MANDATORY=yes
CHECK_FOR_YAJL_AT(${with_yajl})
fi
done
# fi
fi
if test -n "${YAJL_PKGNAME}"; then
AC_MSG_RESULT([${YAJL_CONFIG}])
YAJL_VERSION="`${YAJL_CONFIG} ${YAJL_PKGNAME} --modversion`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl VERSION: $YAJL_VERSION); fi
YAJL_CFLAGS="`${YAJL_CONFIG} ${YAJL_PKGNAME} --cflags`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl CFLAGS: $YAJL_CFLAGS); fi
YAJL_LDADD="`${YAJL_CONFIG} ${YAJL_PKGNAME} --libs-only-l`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl LDADD: $YAJL_LDADD); fi
YAJL_LDFLAGS="`${YAJL_CONFIG} ${YAJL_PKGNAME} --libs-only-L --libs-only-other`"
if test "$verbose_output" -eq 1; then AC_MSG_NOTICE(yajl LDFLAGS: $YAJL_LDFLAGS); fi
if test -z "${YAJL_CFLAGS}"; then
if test -z "${YAJL_MANDATORY}"; then
if test -z "${YAJL_DISABLED}"; then
AC_MSG_NOTICE([YAJL library was not found])
YAJL_FOUND=0
else
YAJL_FOUND=2
fi
else
AC_MSG_ERROR([YAJL was explicitly referenced but it was not found])
YAJL_FOUND=-1
fi
else
AC_MSG_RESULT([no])
YAJL_FOUND=1
AC_MSG_NOTICE([using YAJL v${YAJL_VERSION}])
YAJL_CFLAGS="-DWITH_YAJL ${YAJL_CFLAGS}"
YAJL_DISPLAY="${YAJL_LDADD}, ${YAJL_CFLAGS}"
AC_SUBST(YAJL_VERSION)
AC_SUBST(YAJL_LDADD)
AC_SUBST(YAJL_LIBS)
AC_SUBST(YAJL_LDFLAGS)
AC_SUBST(YAJL_CFLAGS)
AC_SUBST(YAJL_DISPLAY)
fi
dnl Hack to just try to find the lib and include
AC_MSG_CHECKING([for yajl install])
for x in ${test_paths}; do
for y in ${YAJL_SONAMES}; do
if test -e "${x}/libyajl.${y}"; then
yajl_lib_path="${x}/"
yajl_lib_name="yajl"
break
else
yajl_lib_path=""
yajl_lib_name=""
fi
done
if test -n "$yajl_lib_path"; then
break
fi
done
for x in ${test_paths}; do
if test -e "${x}/include/yajl_parse.h"; then
yajl_inc_path="${x}/include"
break
elif test -e "${x}/yajl_parse.h"; then
yajl_inc_path="${x}"
break
fi
dnl # Check some sub-paths as well
for yajl_pkg_name in ${yajl_lib_name} ${YAJL_PKGNAMES}; do
if test -e "${x}/include/${yajl_pkg_name}/yajl_parse.h"; then
yajl_inc_path="${x}/include"
break
elif test -e "${x}/${yajl_pkg_name}/yajl_parse.h"; then
yajl_inc_path="${x}"
break
else
yajl_inc_path=""
fi
done
if test -n "$yajl_inc_path"; then
break
fi
AC_SUBST(YAJL_FOUND)
]) # AC_DEFUN [PROG_YAJL]
AC_DEFUN([CHECK_FOR_YAJL_AT], [
path=$1
for y in ${YAJL_POSSIBLE_EXTENSIONS}; do
for z in ${YAJL_POSSIBLE_LIB_NAMES}; do
if test -e "${path}/${z}.${y}"; then
yajl_lib_path="${path}/"
yajl_lib_name="${z}"
yajl_lib_file="${yajl_lib_path}/${z}.${y}"
break
fi
if test -e "${path}/lib${z}.${y}"; then
yajl_lib_path="${path}/"
yajl_lib_name="${z}"
yajl_lib_file="${yajl_lib_path}/lib${z}.${y}"
break
fi
if test -e "${path}/lib/lib${z}.${y}"; then
yajl_lib_path="${path}/lib/"
yajl_lib_name="${z}"
yajl_lib_file="${yajl_lib_path}/lib${z}.${y}"
break
fi
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
yajl_lib_path="${path}/lib/x86_64-linux-gnu/"
yajl_lib_name="${z}"
yajl_lib_file="${yajl_lib_path}/lib${z}.${y}"
break
fi
done
if test -n "$yajl_lib_path"; then
break
fi
done
if test -e "${path}/include/yajl_parse.h"; then
yajl_inc_path="${path}/include"
elif test -e "${path}/yajl_parse.h"; then
yajl_inc_path="${path}"
elif test -e "${path}/include/yajl/yajl_parse.h"; then
yajl_inc_path="${path}/include"
fi
if test -n "${yajl_lib_path}"; then
AC_MSG_NOTICE([YAJL library found at: ${yajl_lib_file}])
fi
if test -n "${yajl_inc_path}"; then
AC_MSG_NOTICE([YAJL headers found at: ${yajl_inc_path}])
fi
if test -n "${yajl_lib_path}" -a -n "${yajl_inc_path}"; then
YAJL_CONFIG=""
AC_MSG_RESULT([${yajl_lib_path} ${yajl_inc_path}])
YAJL_VERSION="2"
# TODO: Compile a piece of code to check the version.
YAJL_CFLAGS="-I${yajl_inc_path}"
YAJL_LDADD="-l${yajl_lib_name}"
YAJL_LDFLAGS="-L${yajl_lib_path}"
else
YAJL_VERSION=""
AC_MSG_RESULT([no])
YAJL_DISPLAY="${yajl_lib_file}, ${yajl_inc_path}"
fi
fi
])
YAJL_LIBS=${YAJL_LDADD}
AC_SUBST(YAJL_CFLAGS)
AC_SUBST(YAJL_VERSION)
AC_SUBST(YAJL_LDADD)
AC_SUBST(YAJL_LIBS)
AC_SUBST(YAJL_LDFLAGS)
if test -z "${YAJL_VERSION}"; then
ifelse([$2], , AC_MSG_ERROR([*** yajl library not found]), $2)
else
AC_MSG_NOTICE([using yajl v${YAJL_VERSION}])
YAJL_CFLAGS="-DWITH_YAJL ${YAJL_CFLAGS}"
ifelse([$1], , , $1)
fi
])
]) # AC_DEFUN [CHECK_FOR_YAJL_AT]

View File

@ -190,6 +190,7 @@ AC_SUBST([MSC_GIT_VERSION])
# Files to be generated via autotools.
AM_CONDITIONAL([WITH_YAJL], [test "$want_test" = yes])
AC_CONFIG_FILES([\
Makefile \
doc/Makefile \
@ -268,4 +269,22 @@ if test "x$CURL_FOUND" = "x2"; then
echo " + LibCURL ....disabled"
fi
## YAJL
if test "x$YAJL_FOUND" = "x0"; then
echo " + YAJL ....not found"
fi
if test "x$YAJL_FOUND" = "x1"; then
echo -n " + YAJL ....found "
if ! test "x$YAJL_VERSION" = "x"; then
echo "v${YAJL_VERSION}"
else
echo ""
fi
echo " ${YAJL_DISPLAY}"
fi
if test "x$YAJL_FOUND" = "x2"; then
echo " + YAJL ....disabled"
fi
echo " "

View File

@ -15,8 +15,10 @@
#include "modsecurity/assay.h"
#ifdef WITH_YAJL
#include <yajl/yajl_tree.h>
#include <yajl/yajl_gen.h>
#endif
#include <stdio.h>
#include <string.h>
@ -1331,6 +1333,7 @@ std::string Assay::toOldAuditLogFormat(int parts, const std::string &trailer) {
std::string Assay::to_json(int parts) {
#ifdef WITH_YAJL
const unsigned char *buf;
size_t len;
yajl_gen g = NULL;
@ -1477,6 +1480,9 @@ std::string Assay::to_json(int parts) {
yajl_gen_free(g);
return log;
#else
return std::string("");
#endif
}

View File

@ -15,7 +15,9 @@
#include "common/modsecurity_test.h"
#ifdef WITH_YAJL
#include <yajl/yajl_tree.h>
#endif
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>