From 6478b4f9cce3e238482d8637407b79755b3924f6 Mon Sep 17 00:00:00 2001 From: Aaron Hurt Date: Mon, 3 Aug 2015 16:58:21 -0500 Subject: [PATCH] applicable parts of #1174 backported for 3.0.x --- src/modules/rlm_couchbase/config.h.in | 6 + src/modules/rlm_couchbase/configure | 273 ++++++++++++++++++++-- src/modules/rlm_couchbase/configure.ac | 18 +- src/modules/rlm_couchbase/couchbase.c | 1 - src/modules/rlm_couchbase/couchbase.h | 3 +- src/modules/rlm_couchbase/jsonc_missing.h | 8 +- src/modules/rlm_couchbase/mod.c | 14 +- src/modules/rlm_couchbase/mod.h | 1 - src/modules/rlm_couchbase/rlm_couchbase.c | 1 - 9 files changed, 289 insertions(+), 36 deletions(-) diff --git a/src/modules/rlm_couchbase/config.h.in b/src/modules/rlm_couchbase/config.h.in index 6d5e1d1bcb..490c9ec43d 100644 --- a/src/modules/rlm_couchbase/config.h.in +++ b/src/modules/rlm_couchbase/config.h.in @@ -1,8 +1,14 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* json.h is at json-c/json.h relative to include dir */ +#undef HAVE_JSONMC_JSON_H + /* Define to 1 if you have the `json_c_version' function. */ #undef HAVE_JSON_C_VERSION +/* json.h is at json/json.h relative to include dir */ +#undef HAVE_JSON_JSON_H + /* Define to 1 if you have the `json_object_get_string_len' function. */ #undef HAVE_JSON_OBJECT_GET_STRING_LEN diff --git a/src/modules/rlm_couchbase/configure b/src/modules/rlm_couchbase/configure index d31392d32c..e567fb1134 100755 --- a/src/modules/rlm_couchbase/configure +++ b/src/modules/rlm_couchbase/configure @@ -2891,13 +2891,238 @@ fi have_json="yes" - - smart_prefix="json-c json" smart_try_dir="$jsonc_include_dir" -ac_safe=`echo "json.h" | sed 'y%./+-%__pm%'` +ac_safe=`echo "json/json.h" | sed 'y%./+-%__pm%'` +old_CPPFLAGS="$CPPFLAGS" +smart_include= +smart_include_dir="/usr/local/include /opt/include" + +_smart_try_dir= +_smart_include_dir= + +for _prefix in $smart_prefix ""; do + for _dir in $smart_try_dir; do + _smart_try_dir="${_smart_try_dir} ${_dir}/${_prefix}" + done + + for _dir in $smart_include_dir; do + _smart_include_dir="${_smart_include_dir} ${_dir}/${_prefix}" + done +done + +if test "x$_smart_try_dir" != "x"; then + for try in $_smart_try_dir; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json/json.h in $try" >&5 +$as_echo_n "checking for json/json.h in $try... " >&6; } + CPPFLAGS="-isystem $try $old_CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem $try" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done + CPPFLAGS="$old_CPPFLAGS" +fi + +if test "x$smart_include" = "x"; then + for _prefix in $smart_prefix; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/json/json.h" >&5 +$as_echo_n "checking for ${_prefix}/json/json.h... " >&6; } + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem ${_prefix}/" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +fi + +if test "x$smart_include" = "x"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json/json.h" >&5 +$as_echo_n "checking for json/json.h... " >&6; } + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include=" " + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +if test "x$smart_include" = "x"; then + + for prefix in $smart_prefix; do + + +if test "x$LOCATE" != "x"; then + DIRS= + file="${_prefix}/${1}" + + for x in `${LOCATE} $file 2>/dev/null`; do + base=`echo $x | sed "s%/${file}%%"` + if test "x$x" = "x$base"; then + continue; + fi + + dir=`${DIRNAME} $x 2>/dev/null` + exclude=`echo ${dir} | ${GREP} /home` + if test "x$exclude" != "x"; then + continue + fi + + already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}` + if test "x$already" = "x"; then + DIRS="$DIRS $dir" + fi + done +fi + +eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" + + done + + +if test "x$LOCATE" != "x"; then + DIRS= + file=json/json.h + + for x in `${LOCATE} $file 2>/dev/null`; do + base=`echo $x | sed "s%/${file}%%"` + if test "x$x" = "x$base"; then + continue; + fi + + dir=`${DIRNAME} $x 2>/dev/null` + exclude=`echo ${dir} | ${GREP} /home` + if test "x$exclude" != "x"; then + continue + fi + + already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}` + if test "x$already" = "x"; then + DIRS="$DIRS $dir" + fi + done +fi + +eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" + + + for try in $_smart_include_dir; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json/json.h in $try" >&5 +$as_echo_n "checking for json/json.h in $try... " >&6; } + CPPFLAGS="-isystem $try $old_CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem $try" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done + CPPFLAGS="$old_CPPFLAGS" +fi + +if test "x$smart_include" != "x"; then + eval "ac_cv_header_$ac_safe=yes" + CPPFLAGS="$smart_include $old_CPPFLAGS" + SMART_CPPFLAGS="$smart_include $SMART_CPPFLAGS" +fi + +smart_prefix= + + if test "x$ac_cv_header_json_json_h" != "xyes"; then + + +ac_safe=`echo "json-c/json.h" | sed 'y%./+-%__pm%'` old_CPPFLAGS="$CPPFLAGS" smart_include= smart_include_dir="/usr/local/include /opt/include" @@ -2917,13 +3142,13 @@ done if test "x$_smart_try_dir" != "x"; then for try in $_smart_try_dir; do - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json.h in $try" >&5 -$as_echo_n "checking for json.h in $try... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h in $try" >&5 +$as_echo_n "checking for json-c/json.h in $try... " >&6; } CPPFLAGS="-isystem $try $old_CPPFLAGS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { @@ -2953,13 +3178,13 @@ fi if test "x$smart_include" = "x"; then for _prefix in $smart_prefix; do - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/json.h" >&5 -$as_echo_n "checking for ${_prefix}/json.h... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/json-c/json.h" >&5 +$as_echo_n "checking for ${_prefix}/json-c/json.h... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { @@ -2987,13 +3212,13 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test "x$smart_include" = "x"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json.h" >&5 -$as_echo_n "checking for json.h... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h" >&5 +$as_echo_n "checking for json-c/json.h... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { @@ -3054,7 +3279,7 @@ eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" if test "x$LOCATE" != "x"; then DIRS= - file=json.h + file=json-c/json.h for x in `${LOCATE} $file 2>/dev/null`; do base=`echo $x | sed "s%/${file}%%"` @@ -3079,13 +3304,13 @@ eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" for try in $_smart_include_dir; do - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json.h in $try" >&5 -$as_echo_n "checking for json.h in $try... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h in $try" >&5 +$as_echo_n "checking for json-c/json.h in $try... " >&6; } CPPFLAGS="-isystem $try $old_CPPFLAGS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main () { @@ -3121,10 +3346,20 @@ fi smart_prefix= - if test "x$ac_cv_header_json_h" != "xyes"; then - have_json="no" - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&5 + if test "x$ac_cv_header_jsonmc_json_h" != "xyes"; then + have_json="no" + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&5 $as_echo "$as_me: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&2;} + fail="$fail json.h" + else + +$as_echo "#define HAVE_JSONMC_JSON_H 1" >>confdefs.h + + fi + else + +$as_echo "#define HAVE_JSON_JSON_H 1" >>confdefs.h + fi diff --git a/src/modules/rlm_couchbase/configure.ac b/src/modules/rlm_couchbase/configure.ac index c126e6e1d0..a43ee2fb18 100644 --- a/src/modules/rlm_couchbase/configure.ac +++ b/src/modules/rlm_couchbase/configure.ac @@ -70,13 +70,19 @@ if test x$with_[]modname != xno; then dnl ############################################################ have_json="yes" - - smart_prefix="json-c json" smart_try_dir="$jsonc_include_dir" - FR_SMART_CHECK_INCLUDE([json.h]) - if test "x$ac_cv_header_json_h" != "xyes"; then - have_json="no" - AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=.]) + FR_SMART_CHECK_INCLUDE([json/json.h]) + if test "x$ac_cv_header_json_json_h" != "xyes"; then + FR_SMART_CHECK_INCLUDE([json-c/json.h]) + if test "x$ac_cv_header_jsonmc_json_h" != "xyes"; then + have_json="no" + AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=.]) + fail="$fail json.h" + else + AC_DEFINE([HAVE_JSONMC_JSON_H],[1],[json.h is at json-c/json.h relative to include dir]) + fi + else + AC_DEFINE([HAVE_JSON_JSON_H],[1],[json.h is at json/json.h relative to include dir]) fi dnl ############################################################ diff --git a/src/modules/rlm_couchbase/couchbase.c b/src/modules/rlm_couchbase/couchbase.c index bfe4ec876c..a278dca5f8 100644 --- a/src/modules/rlm_couchbase/couchbase.c +++ b/src/modules/rlm_couchbase/couchbase.c @@ -29,7 +29,6 @@ RCSID("$Id$") #include #include -#include #include "couchbase.h" #include "jsonc_missing.h" diff --git a/src/modules/rlm_couchbase/couchbase.h b/src/modules/rlm_couchbase/couchbase.h index ad6cba579d..1e1ded49ec 100644 --- a/src/modules/rlm_couchbase/couchbase.h +++ b/src/modules/rlm_couchbase/couchbase.h @@ -30,7 +30,8 @@ RCSIDH(couchbase_h, "$Id$") #include -#include + +#include "jsonc_missing.h" /** Information relating to the parsing of Couchbase document payloads * diff --git a/src/modules/rlm_couchbase/jsonc_missing.h b/src/modules/rlm_couchbase/jsonc_missing.h index b248786bd6..5df68a89ec 100644 --- a/src/modules/rlm_couchbase/jsonc_missing.h +++ b/src/modules/rlm_couchbase/jsonc_missing.h @@ -29,10 +29,14 @@ RCSIDH(jsonc_missing_h, "$Id$") -#include - #include "config.h" +#if defined(HAVE_JSONMC_JSON_H) +# include +#elif defined(HAVE_JSON_JSON_H) +# include +#endif + #ifndef HAVE_JSON_C_VERSION const char *json_c_version(void); #endif diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c index 4d32e48499..9e1e6197e0 100644 --- a/src/modules/rlm_couchbase/mod.c +++ b/src/modules/rlm_couchbase/mod.c @@ -29,7 +29,6 @@ RCSID("$Id$") #include #include -#include #include "mod.h" #include "couchbase.h" @@ -121,9 +120,14 @@ int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance) CONF_PAIR *cp; /* conig pair */ const char *attribute, *element; /* attribute and element names */ - /* find map section */ - cs = cf_section_sub_find(conf, "map"); - if (!cs) cf_section_sub_find(conf, "update"); + /* find update section */ + cs = cf_section_sub_find(conf, "update"); + + /* backwards compatibility */ + if (!cs) { + cs = cf_section_sub_find(conf, "map"); + WARN("rlm_couchbase: found deprecated 'map' section - please change to 'update'"); + } /* check section */ if (!cs) { @@ -139,7 +143,7 @@ int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance) for (ci = cf_item_find_next(cs, NULL); ci != NULL; ci = cf_item_find_next(cs, ci)) { /* validate item */ if (!cf_item_is_pair(ci)) { - ERROR("rlm_couchbase: failed to parse invalid item in 'map' section"); + ERROR("rlm_couchbase: failed to parse invalid item in 'update' section"); /* free map */ if (inst->map) { json_object_put(inst->map); diff --git a/src/modules/rlm_couchbase/mod.h b/src/modules/rlm_couchbase/mod.h index 764c6f8e95..5f40db9c9f 100644 --- a/src/modules/rlm_couchbase/mod.h +++ b/src/modules/rlm_couchbase/mod.h @@ -32,7 +32,6 @@ RCSIDH(mod_h, "$Id$") #include #include -#include #include "jsonc_missing.h" diff --git a/src/modules/rlm_couchbase/rlm_couchbase.c b/src/modules/rlm_couchbase/rlm_couchbase.c index d45ee9c621..a5365ed24a 100644 --- a/src/modules/rlm_couchbase/rlm_couchbase.c +++ b/src/modules/rlm_couchbase/rlm_couchbase.c @@ -32,7 +32,6 @@ RCSID("$Id$") #include #include -#include #include "mod.h" #include "couchbase.h" -- 2.47.2