[Asterisk-code-review] autoconf: Check for srtp get version string() before using it (asterisk[15])

Sean Bright asteriskteam at digium.com
Mon Sep 17 10:47:49 CDT 2018


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/10164


Change subject: autoconf: Check for srtp_get_version_string() before using it
......................................................................

autoconf: Check for srtp_get_version_string() before using it

Change-Id: Id2a916ff9448706090e72ff2c7fb3f5ba24a05df
---
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M menuselect/configure
M res/res_srtp.c
5 files changed, 251 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/10164/1

diff --git a/configure b/configure
index 4ec8bcf..37a48e2 100755
--- a/configure
+++ b/configure
@@ -772,6 +772,10 @@
 OPENSSL_DIR
 OPENSSL_INCLUDE
 OPENSSL_LIB
+PBX_SRTP_GET_VERSION
+SRTP_GET_VERSION_DIR
+SRTP_GET_VERSION_INCLUDE
+SRTP_GET_VERSION_LIB
 PBX_SRTP_SHUTDOWN
 SRTP_SHUTDOWN_DIR
 SRTP_SHUTDOWN_INCLUDE
@@ -1343,6 +1347,7 @@
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -1533,6 +1538,7 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1785,6 +1791,15 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1922,7 +1937,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -2075,6 +2090,7 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -12469,6 +12485,18 @@
 
 
 
+SRTP_GET_VERSION_DESCRIP="SRTP Library Version Function"
+SRTP_GET_VERSION_OPTION=srtp
+SRTP_GET_VERSION_DIR=${SRTP_DIR}
+
+PBX_SRTP_GET_VERSION=0
+
+
+
+
+
+
+
     OPENSSL_DESCRIP="OpenSSL Secure Sockets Layer"
     OPENSSL_OPTION="ssl"
     PBX_OPENSSL=0
@@ -15288,7 +15316,7 @@
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
@@ -15334,7 +15362,7 @@
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
@@ -15358,7 +15386,7 @@
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
@@ -15403,7 +15431,7 @@
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
@@ -15427,7 +15455,7 @@
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 		       && LARGE_OFF_T % 2147483647 == 1)
 		      ? 1 : -1];
@@ -16727,6 +16755,8 @@
     if (*(data + i) != *(data3 + i))
       return 14;
   close (fd);
+  free (data);
+  free (data3);
   return 0;
 }
 _ACEOF
@@ -31877,6 +31907,102 @@
 
 
 
+if test "x${PBX_SRTP_GET_VERSION}" != "x1" -a "${USE_SRTP_GET_VERSION}" != "no"; then
+   pbxlibdir=""
+   # if --with-SRTP_GET_VERSION=DIR has been specified, use it.
+   if test "x${SRTP_GET_VERSION_DIR}" != "x"; then
+      if test -d ${SRTP_GET_VERSION_DIR}/lib; then
+         pbxlibdir="-L${SRTP_GET_VERSION_DIR}/lib"
+      else
+         pbxlibdir="-L${SRTP_GET_VERSION_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_get_version_string in -lsrtp2" >&5
+$as_echo_n "checking for srtp_get_version_string in -lsrtp2... " >&6; }
+if ${ac_cv_lib_srtp2_srtp_get_version_string+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsrtp2 ${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 srtp_get_version_string ();
+int
+main ()
+{
+return srtp_get_version_string ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_srtp2_srtp_get_version_string=yes
+else
+  ac_cv_lib_srtp2_srtp_get_version_string=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_srtp2_srtp_get_version_string" >&5
+$as_echo "$ac_cv_lib_srtp2_srtp_get_version_string" >&6; }
+if test "x$ac_cv_lib_srtp2_srtp_get_version_string" = xyes; then :
+  AST_SRTP_GET_VERSION_FOUND=yes
+else
+  AST_SRTP_GET_VERSION_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_SRTP_GET_VERSION_FOUND}" = "yes"; then
+      SRTP_GET_VERSION_LIB="${pbxlibdir} -lsrtp2 "
+      # if --with-SRTP_GET_VERSION=DIR has been specified, use it.
+      if test "x${SRTP_GET_VERSION_DIR}" != "x"; then
+         SRTP_GET_VERSION_INCLUDE="-I${SRTP_GET_VERSION_DIR}/include"
+      fi
+      SRTP_GET_VERSION_INCLUDE="${SRTP_GET_VERSION_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${SRTP_GET_VERSION_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "srtp2/srtp.h" "ac_cv_header_srtp2_srtp_h" "$ac_includes_default"
+if test "x$ac_cv_header_srtp2_srtp_h" = xyes; then :
+  SRTP_GET_VERSION_HEADER_FOUND=1
+else
+  SRTP_GET_VERSION_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${SRTP_GET_VERSION_HEADER_FOUND}" = "x0" ; then
+         SRTP_GET_VERSION_LIB=""
+         SRTP_GET_VERSION_INCLUDE=""
+      else
+
+         PBX_SRTP_GET_VERSION=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP_GET_VERSION 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
     # libsrtp2 removed support for PRNG, so we require OpenSSL
     if test "x$PBX_OPENSSL" != x1;
     then
@@ -32416,6 +32542,102 @@
 fi
 
 
+
+if test "x${PBX_SRTP_GET_VERSION}" != "x1" -a "${USE_SRTP_GET_VERSION}" != "no"; then
+   pbxlibdir=""
+   # if --with-SRTP_GET_VERSION=DIR has been specified, use it.
+   if test "x${SRTP_GET_VERSION_DIR}" != "x"; then
+      if test -d ${SRTP_GET_VERSION_DIR}/lib; then
+         pbxlibdir="-L${SRTP_GET_VERSION_DIR}/lib"
+      else
+         pbxlibdir="-L${SRTP_GET_VERSION_DIR}"
+      fi
+   fi
+
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for srtp_get_version_string in -lsrtp" >&5
+$as_echo_n "checking for srtp_get_version_string in -lsrtp... " >&6; }
+if ${ac_cv_lib_srtp_srtp_get_version_string+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsrtp ${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 srtp_get_version_string ();
+int
+main ()
+{
+return srtp_get_version_string ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_srtp_srtp_get_version_string=yes
+else
+  ac_cv_lib_srtp_srtp_get_version_string=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_srtp_srtp_get_version_string" >&5
+$as_echo "$ac_cv_lib_srtp_srtp_get_version_string" >&6; }
+if test "x$ac_cv_lib_srtp_srtp_get_version_string" = xyes; then :
+  AST_SRTP_GET_VERSION_FOUND=yes
+else
+  AST_SRTP_GET_VERSION_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+
+
+   # now check for the header.
+   if test "${AST_SRTP_GET_VERSION_FOUND}" = "yes"; then
+      SRTP_GET_VERSION_LIB="${pbxlibdir} -lsrtp "
+      # if --with-SRTP_GET_VERSION=DIR has been specified, use it.
+      if test "x${SRTP_GET_VERSION_DIR}" != "x"; then
+         SRTP_GET_VERSION_INCLUDE="-I${SRTP_GET_VERSION_DIR}/include"
+      fi
+      SRTP_GET_VERSION_INCLUDE="${SRTP_GET_VERSION_INCLUDE} "
+
+         # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${SRTP_GET_VERSION_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "srtp/srtp.h" "ac_cv_header_srtp_srtp_h" "$ac_includes_default"
+if test "x$ac_cv_header_srtp_srtp_h" = xyes; then :
+  SRTP_GET_VERSION_HEADER_FOUND=1
+else
+  SRTP_GET_VERSION_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+
+      if test "x${SRTP_GET_VERSION_HEADER_FOUND}" = "x0" ; then
+         SRTP_GET_VERSION_LIB=""
+         SRTP_GET_VERSION_INCLUDE=""
+      else
+
+         PBX_SRTP_GET_VERSION=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP_GET_VERSION 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
     fi
 fi
 
diff --git a/configure.ac b/configure.ac
index 2822251..4172c14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -585,6 +585,7 @@
 AST_EXT_LIB_SETUP_OPTIONAL([SRTP_192], [SRTP Library AES-192 (ICM)], [SRTP], [srtp])
 AST_EXT_LIB_SETUP_OPTIONAL([SRTP_GCM], [SRTP Library AES-128 (GCM) and AES-256 (GCM)], [SRTP], [srtp])
 AST_EXT_LIB_SETUP_OPTIONAL([SRTP_SHUTDOWN], [SRTP Library Shutdown Function], [SRTP], [srtp])
+AST_EXT_LIB_SETUP_OPTIONAL([SRTP_GET_VERSION], [SRTP Library Version Function], [SRTP], [srtp])
 AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL Secure Sockets Layer], [ssl])
 AST_EXT_LIB_SETUP_OPTIONAL([RT], [Realtime functions], [rt])
 AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
@@ -2606,6 +2607,7 @@
     AST_EXT_LIB_CHECK([SRTP_192], [srtp2], [srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80])
     AST_EXT_LIB_CHECK([SRTP_GCM], [srtp2], [srtp_crypto_policy_set_aes_gcm_128_8_auth])
     AST_EXT_LIB_CHECK([SRTP_SHUTDOWN], [srtp2], [srtp_shutdown], [srtp2/srtp.h])
+    AST_EXT_LIB_CHECK([SRTP_GET_VERSION], [srtp2], [srtp_get_version_string], [srtp2/srtp.h])
 
     # libsrtp2 removed support for PRNG, so we require OpenSSL
     if test "x$PBX_OPENSSL" != x1;
@@ -2640,6 +2642,7 @@
         AST_EXT_LIB_CHECK([SRTP_192], [srtp], [crypto_policy_set_aes_cm_192_hmac_sha1_80])
         AST_EXT_LIB_CHECK([SRTP_GCM], [srtp], [crypto_policy_set_aes_gcm_128_8_auth])
         AST_EXT_LIB_CHECK([SRTP_SHUTDOWN], [srtp], [srtp_shutdown], [srtp/srtp.h])
+        AST_EXT_LIB_CHECK([SRTP_GET_VERSION], [srtp], [srtp_get_version_string], [srtp/srtp.h])
     fi
 fi
 
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 03e4e21..b5c4b59 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -908,6 +908,9 @@
    feature. */
 #undef HAVE_SRTP_GCM
 
+/* Define to 1 if SRTP has the SRTP Library Version Function feature. */
+#undef HAVE_SRTP_GET_VERSION
+
 /* Define to 1 if SRTP has the SRTP Library Shutdown Function feature. */
 #undef HAVE_SRTP_SHUTDOWN
 
diff --git a/menuselect/configure b/menuselect/configure
index 8efb637..fd7d24b 100755
--- a/menuselect/configure
+++ b/menuselect/configure
@@ -692,6 +692,7 @@
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -772,6 +773,7 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE}'
@@ -1024,6 +1026,15 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1161,7 +1172,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1314,6 +1325,7 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
diff --git a/res/res_srtp.c b/res/res_srtp.c
index ad3ea2e..bebcbe6 100644
--- a/res/res_srtp.c
+++ b/res/res_srtp.c
@@ -1212,7 +1212,11 @@
 		return -1;
 	}
 
+#ifdef HAVE_SRTP_GET_VERSION
 	ast_verb(2, "%s initialized\n", srtp_get_version_string());
+#else
+	ast_verb(2, "libsrtp initialized\n");
+#endif
 
 	g_initialized = 1;
 	return 0;

-- 
To view, visit https://gerrit.asterisk.org/10164
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id2a916ff9448706090e72ff2c7fb3f5ba24a05df
Gerrit-Change-Number: 10164
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180917/82519d9b/attachment-0001.html>


More information about the asterisk-code-review mailing list