res_pjsip: Add support for building against pjproject with SIP transaction group...
authorJoshua Colp <jcolp@digium.com>
Sat, 16 Nov 2013 13:51:04 +0000 (13:51 +0000)
committerJoshua Colp <jcolp@digium.com>
Sat, 16 Nov 2013 13:51:04 +0000 (13:51 +0000)
SIP transaction group lock support has been backported into our pjproject. Since the code
now internally uses a group lock the code is now changed to unlock it if present. Note
that the act of finding the transaction is what actually returns it locked.

For further information about group locks check out the wiki page at:
http://trac.pjsip.org/repos/wiki/Group_Lock

(issue ASTERISK-22818)
Reported by: Matt Jordan
........

Merged revisions 402864 from http://svn.asterisk.org/svn/asterisk/branches/12

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402865 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configure
configure.ac
include/asterisk/autoconfig.h.in
res/res_pjsip/pjsip_distributor.c

index 0dca71f..9e414e1 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 400385 .
+# From configure.ac Revision: 400770 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for asterisk trunk.
 #
@@ -899,6 +899,10 @@ PBX_PORTAUDIO
 PORTAUDIO_DIR
 PORTAUDIO_INCLUDE
 PORTAUDIO_LIB
+PBX_PJ_TRANSACTION_GRP_LOCK
+PJ_TRANSACTION_GRP_LOCK_DIR
+PJ_TRANSACTION_GRP_LOCK_INCLUDE
+PJ_TRANSACTION_GRP_LOCK_LIB
 PBX_POPT
 POPT_DIR
 POPT_INCLUDE
 
 
 
+PJ_TRANSACTION_GRP_LOCK_DESCRIP="PJSIP Transaction Group Lock Support"
+
+PJ_TRANSACTION_GRP_LOCK_DIR=${pjsip_DIR}
+
+PBX_PJ_TRANSACTION_GRP_LOCK=0
+
+
+
+
+
+
+
     PORTAUDIO_DESCRIP="PortAudio"
     PORTAUDIO_OPTION="portaudio"
     PBX_PORTAUDIO=0
 
 
 
+if test "x${PBX_PJ_TRANSACTION_GRP_LOCK}" != "x1" -a "${USE_PJ_TRANSACTION_GRP_LOCK}" != "no"; then
+   pbxlibdir=""
+   # if --with-PJ_TRANSACTION_GRP_LOCK=DIR has been specified, use it.
+   if test "x${PJ_TRANSACTION_GRP_LOCK_DIR}" != "x"; then
+      if test -d ${PJ_TRANSACTION_GRP_LOCK_DIR}/lib; then
+         pbxlibdir="-L${PJ_TRANSACTION_GRP_LOCK_DIR}/lib"
+      else
+         pbxlibdir="-L${PJ_TRANSACTION_GRP_LOCK_DIR}"
+      fi
+   fi
+   pbxfuncname="pjsip_tsx_create_uac2"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_PJ_TRANSACTION_GRP_LOCK_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      as_ac_Lib=`$as_echo "ac_cv_lib_pjsip_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lpjsip" >&5
+$as_echo_n "checking for ${pbxfuncname} in -lpjsip... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpjsip ${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_PJ_TRANSACTION_GRP_LOCK_FOUND=yes
+else
+  AST_PJ_TRANSACTION_GRP_LOCK_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_PJ_TRANSACTION_GRP_LOCK_FOUND}" = "yes"; then
+      PJ_TRANSACTION_GRP_LOCK_LIB="${pbxlibdir} -lpjsip "
+      # if --with-PJ_TRANSACTION_GRP_LOCK=DIR has been specified, use it.
+      if test "x${PJ_TRANSACTION_GRP_LOCK_DIR}" != "x"; then
+         PJ_TRANSACTION_GRP_LOCK_INCLUDE="-I${PJ_TRANSACTION_GRP_LOCK_DIR}/include"
+      fi
+      PJ_TRANSACTION_GRP_LOCK_INCLUDE="${PJ_TRANSACTION_GRP_LOCK_INCLUDE} "
+      if test "xpjsip.h" = "x" ; then  # no header, assume found
+         PJ_TRANSACTION_GRP_LOCK_HEADER_FOUND="1"
+      else                             # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${PJ_TRANSACTION_GRP_LOCK_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "pjsip.h" "ac_cv_header_pjsip_h" "$ac_includes_default"
+if test "x$ac_cv_header_pjsip_h" = xyes; then :
+  PJ_TRANSACTION_GRP_LOCK_HEADER_FOUND=1
+else
+  PJ_TRANSACTION_GRP_LOCK_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${PJ_TRANSACTION_GRP_LOCK_HEADER_FOUND}" = "x0" ; then
+         PJ_TRANSACTION_GRP_LOCK_LIB=""
+         PJ_TRANSACTION_GRP_LOCK_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then                # only checking headers -> no library
+            PJ_TRANSACTION_GRP_LOCK_LIB=""
+         fi
+         PBX_PJ_TRANSACTION_GRP_LOCK=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_PJ_TRANSACTION_GRP_LOCK 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
+
 if test "x${PBX_POPT}" != "x1" -a "${USE_POPT}" != "no"; then
    pbxlibdir=""
    # if --with-POPT=DIR has been specified, use it.
index 4ba3b24..75b13fb 100644 (file)
@@ -433,6 +433,7 @@ AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
 AST_EXT_LIB_SETUP([PJPROJECT], [PJPROJECT], [pjproject])
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
+AST_EXT_LIB_SETUP_OPTIONAL([PJ_TRANSACTION_GRP_LOCK], [PJSIP Transaction Group Lock Support], [pjsip])
 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
 AST_EXT_LIB_SETUP_OPTIONAL([PRI_L2_PERSISTENCE], [ISDN Layer 2 persistence option], [PRI], [pri])
@@ -2015,6 +2016,8 @@ fi
 
 AST_PKG_CONFIG_CHECK([PJPROJECT], [libpjproject])
 
+AST_EXT_LIB_CHECK([PJ_TRANSACTION_GRP_LOCK], [pjsip], [pjsip_tsx_create_uac2], [pjsip.h])
+
 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
 
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
index a13df9e..31d8efc 100644 (file)
 /* Define if your system has the PJPROJECT libraries. */
 #undef HAVE_PJPROJECT
 
+/* Define to 1 if pjsip has the PJSIP Transaction Group Lock Support feature.
+   */
+#undef HAVE_PJ_TRANSACTION_GRP_LOCK
+
 /* Define to 1 if your system defines IP_PKTINFO. */
 #undef HAVE_PKTINFO
 
index 9fd6250..5e53cb0 100644 (file)
@@ -134,7 +134,12 @@ static pjsip_dialog *find_dialog(pjsip_rx_data *rdata)
        }
 
        dlg = pjsip_tsx_get_dlg(tsx);
+
+#ifdef HAVE_PJ_TRANSACTION_GRP_LOCK
+       pj_grp_lock_release(tsx->grp_lock);
+#else
        pj_mutex_unlock(tsx->mutex);
+#endif
 
        if (!dlg) {
                return NULL;