Add support for building RADIUS with radcli
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>
Sat, 12 Nov 2016 18:15:12 +0000 (20:15 +0200)
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>
Mon, 14 Nov 2016 17:40:03 +0000 (19:40 +0200)
Radcli is yet another RADIUS client library, generally compatible with
freeradius and radiusclient-ng.

This commit adds autoconf option for detecting it as well and changes
cdr_radius and cel_radius to use its header file in that case.

ASTERISK-26540 #close

Change-Id: I271f0715406334874865ffbce0b354b3a2ca148f

CHANGES
cdr/cdr_radius.c
cel/cel_radius.c
configure
configure.ac
include/asterisk/autoconfig.h.in

diff --git a/CHANGES b/CHANGES
index a57ed88..96851af 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,10 @@ Build System
    Asterisk built with LOW_MEMORY can now successfully load binary modules
    built without LOW_MEMORY and vice versa.
 
+ * RADIUS backends for CEL and CDR can now also be built using the radcli
+   client library, in addition to the existing support for building them
+   using either freeradius or radiusclient-ng.
+
 Core
 ------------------
  * ASTERISK_REGISTER_FILE was no longer useful and has been removed.  Sources
index af434f6..f6b311d 100644 (file)
 
 #include "asterisk.h"
 
-#ifdef FREERADIUS_CLIENT
-#include <freeradius-client.h>
-#else
-#include <radiusclient-ng.h>
-#endif
+#include RADIUS_HEADER_STR
 
 #include "asterisk/channel.h"
 #include "asterisk/cdr.h"
index e31cb5e..250d6a7 100644 (file)
 
 #include "asterisk.h"
 
-#ifdef FREERADIUS_CLIENT
-#include <freeradius-client.h>
-#else
-#include <radiusclient-ng.h>
-#endif
+#include RADIUS_HEADER_STR
 
 #include "asterisk/channel.h"
 #include "asterisk/cel.h"
index 5d21730..eeda932 100755 (executable)
--- a/configure
+++ b/configure
@@ -30902,7 +30902,7 @@ fi
 
 if test "x${PBX_RADIUS}" = "x1"; then
 
-$as_echo "#define FREERADIUS_CLIENT /**/" >>confdefs.h
+$as_echo "#define RADIUS_HEADER_STR <freeradius-client.h>" >>confdefs.h
 
 else
 
@@ -31009,6 +31009,121 @@ _ACEOF
 fi
 
 
+       if test "x${PBX_RADIUS}" = "x1"; then
+
+$as_echo "#define RADIUS_HEADER_STR <radiusclient-ng.h>" >>confdefs.h
+
+       else
+
+if test "x${PBX_RADIUS}" != "x1" -a "${USE_RADIUS}" != "no"; then
+   pbxlibdir=""
+   # if --with-RADIUS=DIR has been specified, use it.
+   if test "x${RADIUS_DIR}" != "x"; then
+      if test -d ${RADIUS_DIR}/lib; then
+         pbxlibdir="-L${RADIUS_DIR}/lib"
+      else
+         pbxlibdir="-L${RADIUS_DIR}"
+      fi
+   fi
+   pbxfuncname="rc_read_config"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_RADIUS_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      as_ac_Lib=`$as_echo "ac_cv_lib_radcli_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lradcli" >&5
+$as_echo_n "checking for ${pbxfuncname} in -lradcli... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lradcli ${pbxlibdir}  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+eval ac_res=\$$as_ac_Lib
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
+  AST_RADIUS_FOUND=yes
+else
+  AST_RADIUS_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_RADIUS_FOUND}" = "yes"; then
+      RADIUS_LIB="${pbxlibdir} -lradcli "
+      # if --with-RADIUS=DIR has been specified, use it.
+      if test "x${RADIUS_DIR}" != "x"; then
+         RADIUS_INCLUDE="-I${RADIUS_DIR}/include"
+      fi
+      RADIUS_INCLUDE="${RADIUS_INCLUDE} "
+      if test "xradcli/radcli.h" = "x" ; then  # no header, assume found
+         RADIUS_HEADER_FOUND="1"
+      else                             # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${RADIUS_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "radcli/radcli.h" "ac_cv_header_radcli_radcli_h" "$ac_includes_default"
+if test "x$ac_cv_header_radcli_radcli_h" = xyes; then :
+  RADIUS_HEADER_FOUND=1
+else
+  RADIUS_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${RADIUS_HEADER_FOUND}" = "x0" ; then
+         RADIUS_LIB=""
+         RADIUS_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then                # only checking headers -> no library
+            RADIUS_LIB=""
+         fi
+         PBX_RADIUS=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_RADIUS 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+               if test "x${PBX_RADIUS}" = "x1"; then
+
+$as_echo "#define RADIUS_HEADER_STR <radcli/radcli.h>" >>confdefs.h
+
+               fi
+       fi
 fi
 
 
index ea55df4..3bdf140 100644 (file)
@@ -2364,9 +2364,17 @@ AST_EXT_LIB_CHECK([LUA], [lua], [luaL_openlib], [lua.h], [-lm])
 # just different header filenames and different SONAMEs
 AST_EXT_LIB_CHECK([RADIUS], [freeradius-client], [rc_read_config], [freeradius-client.h])
 if test "x${PBX_RADIUS}" = "x1"; then
-       AC_DEFINE(FREERADIUS_CLIENT, [], [Use the FreeRADIUS-client library])
+       AC_DEFINE(RADIUS_HEADER_STR, [<freeradius-client.h>], [Name of RADIUS library include header])
 else
        AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
+       if test "x${PBX_RADIUS}" = "x1"; then
+               AC_DEFINE(RADIUS_HEADER_STR, [<radiusclient-ng.h>], [Name of RADIUS library include header])
+       else
+               AST_EXT_LIB_CHECK([RADIUS], [radcli], [rc_read_config], [radcli/radcli.h])
+               if test "x${PBX_RADIUS}" = "x1"; then
+                       AC_DEFINE(RADIUS_HEADER_STR, [<radcli/radcli.h>], [Name of RADIUS library include header])
+               fi
+       fi
 fi
 
 AST_EXT_LIB_CHECK([CODEC2], [codec2], [codec2_create], [codec2/codec2.h])
index 706798c..45bc800 100644 (file)
@@ -28,9 +28,6 @@
 /* Define to 1 if using `alloca.c'. */
 #undef C_ALLOCA
 
-/* Use the FreeRADIUS-client library */
-#undef FREERADIUS_CLIENT
-
 /* Define to 1 if anonymous semaphores work. */
 #undef HAS_WORKING_SEMAPHORE
 
 /* Define if your system needs braces around PTHREAD_ONCE_INIT */
 #undef PTHREAD_ONCE_INIT_NEEDS_BRACES
 
+/* Name of RADIUS library include header */
+#undef RADIUS_HEADER_STR
+
 /* Define to the type of arg 1 for `select'. */
 #undef SELECT_TYPE_ARG1