Merge "core: Improve/simplify handling of required headers."
authorJoshua Colp <jcolp@digium.com>
Fri, 7 Apr 2017 19:48:36 +0000 (14:48 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Fri, 7 Apr 2017 19:48:36 +0000 (14:48 -0500)
16 files changed:
CHANGES
apps/app_queue.c
channels/chan_sip.c
configs/samples/pjsip.conf.sample
configure
configure.ac
include/asterisk/autoconfig.h.in
main/cdr.c
res/res_musiconhold.c
res/res_pjsip/pjsip_message_ip_updater.c
res/res_pjsip_sdp_rtp.c
res/res_pjsip_session.c
third-party/pjproject/configure.m4
third-party/pjproject/patches/0035-r5572-svn-backport-dialog-transaction-deadlock.patch [new file with mode: 0644]
third-party/pjproject/patches/0036-r5573-svn-backport-ua-pjsua-transaction-deadlock.patch [new file with mode: 0644]
third-party/pjproject/patches/0037-r5576-svn-backport-session-timer-crash.patch [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index f7f8505..9a82e1f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 --- Functionality changes from Asterisk 14 to Asterisk 15 --------------------
 ------------------------------------------------------------------------------
 
+app_queue
+------------------
+ * PAUSEALL/UNPAUSEALL now sets the pause reason in the queue_log if it has
+   been defined.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 14.4.0 to Asterisk 14.5.0 ------------
 ------------------------------------------------------------------------------
index 9bba676..ae2d645 100644 (file)
@@ -7332,7 +7332,7 @@ static int set_member_paused(const char *queuename, const char *interface, const
                                         * but since this affects all queues, we cannot.
                                         */
                                        ast_queue_log("NONE", "NONE", mem->membername,
-                                               (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", "");
+                                               (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", S_OR(reason, ""));
                                }
 
                                set_queue_member_pause(q, mem, reason, paused);
index f659a44..5419a1d 100644 (file)
@@ -25818,8 +25818,7 @@ static int handle_request_update(struct sip_pvt *p, struct sip_request *req)
  * \retval 0 ok
  * \retval -1 failure
  */
-static int handle_request_invite_st(struct sip_pvt *p, struct sip_request *req,
-               const char *required, int reinvite)
+static int handle_request_invite_st(struct sip_pvt *p, struct sip_request *req, int reinvite)
 {
        const char *p_uac_se_hdr;       /* UAC's Session-Expires header string                      */
        const char *p_uac_min_se;       /* UAC's requested Min-SE interval (char string)            */
@@ -25899,8 +25898,8 @@ static int handle_request_invite_st(struct sip_pvt *p, struct sip_request *req,
 
                case SESSION_TIMER_MODE_REFUSE:
                        if (p->reqsipoptions & SIP_OPT_TIMER) {
-                               transmit_response_with_unsupported(p, "420 Option Disabled", req, required);
-                               ast_log(LOG_WARNING, "Received SIP INVITE with supported but disabled option: %s\n", required);
+                               transmit_response_with_unsupported(p, "420 Option Disabled", req, "timer");
+                               ast_log(LOG_WARNING, "Received SIP INVITE with supported but disabled option: timer\n");
                                return -1;
                        }
                        break;
@@ -26006,7 +26005,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, str
         * then send a 420 with only those unsupported options listed */
        if (!ast_strlen_zero(unsupported)) {
                transmit_response_with_unsupported(p, "420 Bad extension (unsupported)", req, unsupported);
-               ast_log(LOG_WARNING, "Received SIP INVITE with unsupported required extension: required:%s unsupported:%s\n", required, unsupported);
+               ast_log(LOG_WARNING, "Received SIP INVITE with unsupported required extension: %s\n", unsupported);
                p->invitestate = INV_COMPLETED;
                if (!p->lastinvite) {
                        sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
@@ -26444,7 +26443,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, str
 
                        make_our_tag(p);
 
-                       if (handle_request_invite_st(p, req, required, reinvite)) {
+                       if (handle_request_invite_st(p, req, reinvite)) {
                                p->invitestate = INV_COMPLETED;
                                sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
                                res = INV_REQ_ERROR;
@@ -26486,7 +26485,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, str
                if (!req->ignore)
                        reinvite = 1;
 
-               if (handle_request_invite_st(p, req, required, reinvite)) {
+               if (handle_request_invite_st(p, req, reinvite)) {
                        p->invitestate = INV_COMPLETED;
                        if (!p->lastinvite) {
                                sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
index bb80768..612649e 100644 (file)
@@ -77,6 +77,8 @@
 ;   * Defines a permission list or references one stored in acl.conf
 ; * Registration "registration"
 ;   * Contains information about an outbound SIP registration
+; * Resource Lists
+;   * Contains information for configuring resource lists.
 ; * Phone Provisioning "phoneprov"
 ;   * Contains information needed by res_phoneprov for autoprovisioning
 
                 ; Common variables include LINE, LINEKEYS, etc.
                 ; See phoneprov.conf.sample for others.
 ;type=          ; Must be of type phoneprov (default: "")
+
+
+
+; MODULE PROVIDING BELOW SECTION(S): res_pjsip_outbound_publish
+;======================OUTBOUND_PUBLISHEN SECTION OPTIONS=====================
+; See https://wiki.asterisk.org/wiki/display/AST/Publishing+Extension+State
+; for more information.
+;[outbound-publish]
+;type=outbound-publish     ; Must be of type 'outbound-publish'.
+
+;expiration=3600           ; Expiration time for publications in seconds
+
+;outbound_auth=            ; Authentication object(s) to be used for outbound
+                           ; publishes.
+                           ; This is a comma-delimited list of auth    sections
+                           ; defined in pjsip.conf used to respond to outbound
+                           ; authentication challenges.
+                           ; Using the same auth section for inbound and
+                           ; outbound authentication is not recommended.  There
+                           ; is a difference in meaning for an empty realm
+                           ; setting between inbound and outbound authentication
+                           ; uses. See the auth realm description for details.
+
+;outbound_proxy=           ; SIP URI of the outbound proxy used to send
+                           ; publishes
+
+;server_uri=               ; SIP URI of the server and entity to publish to.
+                           ; This is the URI at which to find the entity and
+                           ; server to send the outbound PUBLISH to.
+                           ; This URI is used as the request URI of the outbound
+                           ; PUBLISH request from Asterisk.
+
+;from_uri=                 ; SIP URI to use in the From header.
+                           ; This is the URI that will be placed into the From
+                           ; header of outgoing PUBLISH messages. If no URI is
+                           ; specified then the URI provided in server_uri will
+                           ; be used.
+
+;to_uri=                   ; SIP URI to use in the To header.
+                           ; This is the URI that will be placed into the To
+                           ; header of outgoing PUBLISH messages. If no URI is
+                           ; specified then the URI provided in server_uri will
+                           ; be used.
+
+;event=                    ; Event type of the PUBLISH.
+
+;max_auth_attempts=        ; Maximum number of authentication attempts before
+                           ; stopping the pub.
+
+;transport=                ; Transport used for outbound publish.
+                           ; A transport configured in pjsip.conf. As with other
+                           ; res_pjsip modules, this will use the first
+                           ; available transport of the appropriate type if
+                           ; unconfigured.
+
+;multi_user=no             ; Enable multi-user support (Asterisk 14+ only)
+
+
+
+; MODULE PROVIDING BELOW SECTION(S): res_pjsip_pubsub
+;=============================RESOURCE-LIST===================================
+; See https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=30278158
+; for more information.
+;[resource_list]
+;type=resource_list        ; Must be of type 'resource_list'.
+
+;event=                    ; The SIP event package that the list resource.
+                           ; belongs to.  The SIP event package describes the
+                           ; types of resources that Asterisk reports the state
+                           ; of.
+
+;list_item=                ; The name of a resource to report state on.
+                           ; In general Asterisk looks up list items in the
+                           ; following way:
+                           ;  1. Check if the list item refers to another
+                           ;     configured resource list.
+                           ;  2. Pass the name of the resource off to
+                           ;     event-package-specific handlers to find the
+                           ;     specified resource.
+                           ; The second part means that the way the list item
+                           ; is specified depends on what type of list this is.
+                           ; For instance, if you have the event set to
+                           ; presence, then list items should be in the form of
+                           ; dialplan_extension@dialplan_context. For
+                           ; message-summary, mailbox names should be listed.
+
+;full_state=no             ; Indicates if the entire list's state should be
+                           ; sent out.
+                           ; If this option is enabled, and a resource changes
+                           ; state, then Asterisk will construct a notification
+                           ; that contains the state of all resources in the
+                           ; list. If the option is disabled, Asterisk will
+                           ; construct a notification that only contains the
+                           ; states of resources that have changed.
+                           ; NOTE: Even with this option disabled, there are
+                           ; certain situations where Asterisk is forced to send
+                           ; a notification with the states of all resources in
+                           ; the list. When a subscriber renews or terminates
+                           ; its subscription to the list, Asterisk MUST send
+                           ; a full state notification.
+
+;notification_batch_interval=0
+                           ; Time Asterisk should wait, in milliseconds,
+                           ; before sending notifications.
+
+;==========================INBOUND_PUBLICATION================================
+; See https://wiki.asterisk.org/wiki/display/AST/Exchanging+Device+and+Mailbox+State+Using+PJSIP
+; for more information.
+;[inbound-publication]
+;type=                     ; Must be of type 'inbound-publication'.
+
+;endpoint=                 ; Optional name of an endpoint that is only allowed
+                           ; to publish to this resource.
+
+
+; MODULE PROVIDING BELOW SECTION(S): res_pjsip_publish_asterisk
+;==========================ASTERISK_PUBLICATION===============================
+; See https://wiki.asterisk.org/wiki/display/AST/Exchanging+Device+and+Mailbox+State+Using+PJSIP
+; for more information.
+;[asterisk-publication]
+;type=asterisk-publication ; Must be of type 'asterisk-publication'.
+
+;devicestate_publish=      ; Optional name of a publish item that can be used
+                           ; to publish a req.
+
+;mailboxstate_publish=     ; Optional name of a publish item that can be used
+                           ; to publish a req.
+
+;device_state=no           ; Whether we should permit incoming device state
+                           ; events.
+
+;device_state_filter=      ; Optional regular expression used to filter what
+                           ; devices we accept events for.
+
+;mailbox_state=no          ; Whether we should permit incoming mailbox state
+                           ; events.
+
+;mailbox_state_filter=     ; Optional regular expression used to filter what
+                           ; mailboxes we accept events for.
index 3243323..dab7038 100755 (executable)
--- a/configure
+++ b/configure
@@ -945,6 +945,10 @@ PBX_POPT
 POPT_DIR
 POPT_INCLUDE
 POPT_LIB
+PBX_PJSIP_TSX_LAYER_FIND_TSX2
+PJSIP_TSX_LAYER_FIND_TSX2_DIR
+PJSIP_TSX_LAYER_FIND_TSX2_INCLUDE
+PJSIP_TSX_LAYER_FIND_TSX2_LIB
 PBX_PJSIP_EVSUB_SET_UAS_TIMEOUT
 PJSIP_EVSUB_SET_UAS_TIMEOUT_DIR
 PJSIP_EVSUB_SET_UAS_TIMEOUT_INCLUDE
@@ -7912,7 +7916,7 @@ fi
 
 if test "${WGET}" != ":" ; then
   DOWNLOAD=${WGET}
-  DOWNLOAD_TO_STDOUT="${WGET} -O-"
+  DOWNLOAD_TO_STDOUT="${WGET} -q -O-"
   DOWNLOAD_TIMEOUT='--timeout=$1'
 else if test "${CURL}" != ":" ; then
   DOWNLOAD="${CURL} -O --progress-bar -w \"%{url_effective}\n\""
@@ -9356,6 +9360,9 @@ $as_echo "#define HAVE_PJSIP_AUTH_CLT_DEINIT 1" >>confdefs.h
 $as_echo "#define HAVE_PJSIP_EVSUB_SET_UAS_TIMEOUT 1" >>confdefs.h
 
 
+$as_echo "#define HAVE_PJSIP_TSX_LAYER_FIND_TSX2 1" >>confdefs.h
+
+
 
 
 
@@ -11562,6 +11569,18 @@ PBX_PJSIP_EVSUB_SET_UAS_TIMEOUT=0
 
 
 
+
+PJSIP_TSX_LAYER_FIND_TSX2_DESCRIP="pjsip_tsx_layer_find_tsx2 support"
+PJSIP_TSX_LAYER_FIND_TSX2_OPTION=pjsip
+PJSIP_TSX_LAYER_FIND_TSX2_DIR=${PJPROJECT_DIR}
+
+PBX_PJSIP_TSX_LAYER_FIND_TSX2=0
+
+
+
+
+
+
 fi
 
 
@@ -26778,6 +26797,110 @@ _ACEOF
 fi
 
 
+
+if test "x${PBX_PJSIP_TSX_LAYER_FIND_TSX2}" != "x1" -a "${USE_PJSIP_TSX_LAYER_FIND_TSX2}" != "no"; then
+   pbxlibdir=""
+   # if --with-PJSIP_TSX_LAYER_FIND_TSX2=DIR has been specified, use it.
+   if test "x${PJSIP_TSX_LAYER_FIND_TSX2_DIR}" != "x"; then
+      if test -d ${PJSIP_TSX_LAYER_FIND_TSX2_DIR}/lib; then
+         pbxlibdir="-L${PJSIP_TSX_LAYER_FIND_TSX2_DIR}/lib"
+      else
+         pbxlibdir="-L${PJSIP_TSX_LAYER_FIND_TSX2_DIR}"
+      fi
+   fi
+   pbxfuncname="pjsip_tsx_layer_find_tsx2"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_PJSIP_TSX_LAYER_FIND_TSX2_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} $PJPROJECT_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} $PJPROJECT_LIB $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_PJSIP_TSX_LAYER_FIND_TSX2_FOUND=yes
+else
+  AST_PJSIP_TSX_LAYER_FIND_TSX2_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_PJSIP_TSX_LAYER_FIND_TSX2_FOUND}" = "yes"; then
+      PJSIP_TSX_LAYER_FIND_TSX2_LIB="${pbxlibdir} -lpjsip $PJPROJECT_LIB"
+      # if --with-PJSIP_TSX_LAYER_FIND_TSX2=DIR has been specified, use it.
+      if test "x${PJSIP_TSX_LAYER_FIND_TSX2_DIR}" != "x"; then
+         PJSIP_TSX_LAYER_FIND_TSX2_INCLUDE="-I${PJSIP_TSX_LAYER_FIND_TSX2_DIR}/include"
+      fi
+      PJSIP_TSX_LAYER_FIND_TSX2_INCLUDE="${PJSIP_TSX_LAYER_FIND_TSX2_INCLUDE} $PJPROJECT_CFLAGS"
+      if test "xpjsip.h" = "x" ; then  # no header, assume found
+         PJSIP_TSX_LAYER_FIND_TSX2_HEADER_FOUND="1"
+      else                             # check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${PJSIP_TSX_LAYER_FIND_TSX2_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 :
+  PJSIP_TSX_LAYER_FIND_TSX2_HEADER_FOUND=1
+else
+  PJSIP_TSX_LAYER_FIND_TSX2_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${PJSIP_TSX_LAYER_FIND_TSX2_HEADER_FOUND}" = "x0" ; then
+         PJSIP_TSX_LAYER_FIND_TSX2_LIB=""
+         PJSIP_TSX_LAYER_FIND_TSX2_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then                # only checking headers -> no library
+            PJSIP_TSX_LAYER_FIND_TSX2_LIB=""
+         fi
+         PBX_PJSIP_TSX_LAYER_FIND_TSX2=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_PJSIP_TSX_LAYER_FIND_TSX2 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
    fi
 fi
 
index a8e66bc..d8a567f 100644 (file)
@@ -293,7 +293,7 @@ AC_PATH_PROG([NM], [nm], :)
 
 if test "${WGET}" != ":" ; then
   DOWNLOAD=${WGET}
-  DOWNLOAD_TO_STDOUT="${WGET} -O-"
+  DOWNLOAD_TO_STDOUT="${WGET} -q -O-"
   DOWNLOAD_TIMEOUT='--timeout=$1'
 else if test "${CURL}" != ":" ; then
   DOWNLOAD="${CURL} -O --progress-bar -w \"%{url_effective}\n\""
@@ -519,6 +519,7 @@ AST_EXT_LIB_SETUP_OPTIONAL([PJSIP_EVSUB_GRP_LOCK], [PJSIP EVSUB Group Lock suppo
 AST_EXT_LIB_SETUP_OPTIONAL([PJSIP_INV_SESSION_REF], [PJSIP INVITE Session Reference Count support], [PJPROJECT], [pjsip])
 AST_EXT_LIB_SETUP_OPTIONAL([PJSIP_AUTH_CLT_DEINIT], [pjsip_auth_clt_deinit support], [PJPROJECT], [pjsip])
 AST_EXT_LIB_SETUP_OPTIONAL([PJSIP_EVSUB_SET_UAS_TIMEOUT], [PJSIP EVSUB Set UAS Timeout support], [PJPROJECT], [pjsip])
+AST_EXT_LIB_SETUP_OPTIONAL([PJSIP_TSX_LAYER_FIND_TSX2], [pjsip_tsx_layer_find_tsx2 support], [PJPROJECT], [pjsip])
 fi
 
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
@@ -2246,6 +2247,7 @@ if test "$USE_PJPROJECT" != "no" ; then
       AST_EXT_LIB_CHECK([PJSIP_INV_SESSION_REF], [pjsip], [pjsip_inv_add_ref], [pjsip.h], [$PJPROJECT_LIB], [$PJPROJECT_CFLAGS])
       AST_EXT_LIB_CHECK([PJSIP_AUTH_CLT_DEINIT], [pjsip], [pjsip_auth_clt_deinit], [pjsip.h], [$PJPROJECT_LIB], [$PJPROJECT_CFLAGS])
       AST_EXT_LIB_CHECK([PJSIP_EVSUB_SET_UAS_TIMEOUT], [pjsip], [pjsip_evsub_set_uas_timeout], [pjsip.h], [$PJPROJECT_LIB], [$PJPROJECT_CFLAGS])
+      AST_EXT_LIB_CHECK([PJSIP_TSX_LAYER_FIND_TSX2], [pjsip], [pjsip_tsx_layer_find_tsx2], [pjsip.h], [$PJPROJECT_LIB], [$PJPROJECT_CFLAGS])
    fi
 fi
 
index af1c90b..5f8a9d3 100644 (file)
 /* Define if your system has the PJSIP_TLS_TRANSPORT_PROTO headers. */
 #undef HAVE_PJSIP_TLS_TRANSPORT_PROTO
 
+/* Define to 1 if PJPROJECT has the pjsip_tsx_layer_find_tsx2 support feature.
+   */
+#undef HAVE_PJSIP_TSX_LAYER_FIND_TSX2
+
 /* Define to 1 if PJPROJECT has the pj_ssl_cert_load_from_files2 support
    feature. */
 #undef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2
index 363a2c6..214af2c 100644 (file)
@@ -3278,7 +3278,7 @@ void ast_cdr_setuserfield(const char *channel_name, const char *userfield)
                        if (it_cdr->fn_table == &finalized_state_fn_table && it_cdr->next != NULL) {
                                continue;
                        }
-                       strcpy(it_cdr->party_a.userfield, userfield);
+                       ast_copy_string(it_cdr->party_a.userfield, userfield, AST_MAX_USER_FIELD);
                }
                ao2_unlock(cdr);
        }
index 992737b..71f4691 100644 (file)
@@ -155,6 +155,7 @@ struct moh_files_state {
 
 /* Custom astobj2 flag */
 #define MOH_NOTDELETED          (1 << 30)       /*!< Find only records that aren't deleted? */
+#define MOH_REALTIME          (1 << 31)       /*!< Find only records that are realtime */
 
 static struct ast_flags global_flags[1] = {{0}};        /*!< global MOH_ flags */
 
@@ -1676,7 +1677,9 @@ static int moh_class_mark(void *obj, void *arg, int flags)
 {
        struct mohclass *class = obj;
 
-       class->delete = 1;
+       if ( ((flags & MOH_REALTIME) && class->realtime) || !(flags & MOH_REALTIME) ) {
+               class->delete = 1;
+       }
 
        return 0;
 }
@@ -1692,22 +1695,27 @@ static int load_moh_classes(int reload)
 {
        struct ast_config *cfg;
        struct ast_variable *var;
-       struct mohclass *class; 
+       struct mohclass *class;
        char *cat;
        int numclasses = 0;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
        cfg = ast_config_load("musiconhold.conf", config_flags);
 
-       if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
+       if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
                if (ast_check_realtime("musiconhold") && reload) {
-                       ao2_t_callback(mohclasses, OBJ_NODATA, moh_class_mark, NULL, "Mark deleted classes");
+                       ao2_t_callback(mohclasses, OBJ_NODATA | MOH_REALTIME, moh_class_mark, NULL, "Mark realtime classes for deletion");
                        ao2_t_callback(mohclasses, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, moh_classes_delete_marked, NULL, "Purge marked classes");
                }
+               moh_rescan_files();
                return 0;
        }
-       if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
-               moh_rescan_files();
+
+       if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
+               if (ast_check_realtime("musiconhold") && reload) {
+                       ao2_t_callback(mohclasses, OBJ_NODATA, moh_class_mark, NULL, "Mark deleted classes");
+                       ao2_t_callback(mohclasses, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, moh_classes_delete_marked, NULL, "Purge marked classes");
+               }
                return 0;
        }
 
index 864d898..2d07464 100644 (file)
@@ -339,8 +339,10 @@ static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata)
        transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id);
 
        if (!(transport && transport->symmetric_transport)) {
+               ao2_cleanup(transport);
                return PJ_FALSE;
        }
+       ao2_cleanup(transport);
 
        x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
        x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP);
index 21de440..701edc3 100644 (file)
@@ -198,8 +198,16 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
        struct ast_sockaddr *media_address =  &address_rtp;
 
        if (session->endpoint->media.bind_rtp_to_media_address && !ast_strlen_zero(session->endpoint->media.address)) {
-               ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0);
-               media_address = &temp_media_address;
+               if (ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0)) {
+                       ast_debug(1, "Endpoint %s: Binding RTP media to %s\n",
+                               ast_sorcery_object_get_id(session->endpoint),
+                               session->endpoint->media.address);
+                       media_address = &temp_media_address;
+               } else {
+                       ast_debug(1, "Endpoint %s: RTP media address invalid: %s\n",
+                               ast_sorcery_object_get_id(session->endpoint),
+                               session->endpoint->media.address);
+               }
        } else {
                struct ast_sip_transport *transport =
                        ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport",
@@ -209,9 +217,14 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
                        char hoststr[PJ_INET6_ADDRSTRLEN];
 
                        pj_sockaddr_print(&transport->state->host, hoststr, sizeof(hoststr), 0);
-                       ast_debug(1, "Transport: %s bound to host: %s, using this for media.\n",
-                                         session->endpoint->transport, hoststr);
-                       ast_sockaddr_parse(media_address, hoststr, 0);
+                       if (ast_sockaddr_parse(&temp_media_address, hoststr, 0)) {
+                               ast_debug(1, "Transport %s bound to %s: Using it for RTP media.\n",
+                                       session->endpoint->transport, hoststr);
+                               media_address = &temp_media_address;
+                       } else {
+                               ast_debug(1, "Transport %s bound to %s: Invalid for RTP media.\n",
+                                       session->endpoint->transport, hoststr);
+                       }
                }
                ao2_cleanup(transport);
        }
index 5f42dab..560b390 100644 (file)
@@ -1198,8 +1198,13 @@ void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip
 {
        pjsip_inv_session *inv_session = session->inv_session;
 
-       if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
-               /* Don't try to do anything with a hung-up call */
+       /* For every request except BYE we disallow sending of the message when
+        * the session has been disconnected. A BYE request is special though
+        * because it can be sent again after the session is disconnected except
+        * with credentials.
+        */
+       if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED &&
+               tdata->msg->line.req.method.id != PJSIP_BYE_METHOD) {
                return;
        }
 
index d5c8531..a5e9fca 100644 (file)
@@ -63,6 +63,7 @@ AC_DEFUN([_PJPROJECT_CONFIGURE],
        AC_DEFINE([HAVE_PJSIP_INV_SESSION_REF], 1, [Define if your system has PJSIP_INV_SESSION_REF])
        AC_DEFINE([HAVE_PJSIP_AUTH_CLT_DEINIT], 1, [Define if your system has pjsip_auth_clt_deinit declared.])
        AC_DEFINE([HAVE_PJSIP_EVSUB_SET_UAS_TIMEOUT], 1, [Define if your system has pjsip_evsub_set_uas_timeout declared.])
+       AC_DEFINE([HAVE_PJSIP_TSX_LAYER_FIND_TSX2], 1, [Define if your system has pjsip_tsx_layer_find_tsx2 declared.])
 
        AC_SUBST([PJPROJECT_BUNDLED])
        AC_SUBST([PJPROJECT_DIR])
diff --git a/third-party/pjproject/patches/0035-r5572-svn-backport-dialog-transaction-deadlock.patch b/third-party/pjproject/patches/0035-r5572-svn-backport-dialog-transaction-deadlock.patch
new file mode 100644 (file)
index 0000000..0c5e986
--- /dev/null
@@ -0,0 +1,32 @@
+Index: trunk/pjsip/src/pjsip/sip_transaction.c\r
+===================================================================\r
+--- a/pjsip/src/pjsip/sip_transaction.c        (revision 5244)\r
++++ b/pjsip/src/pjsip/sip_transaction.c        (revision 5572)\r
+@@ -1231,5 +1231,27 @@\r
+       PJSIP_EVENT_INIT_TSX_STATE(e, tsx, event_src_type, event_src,\r
+                                  prev_state);\r
++\r
++      /* For timer event, release lock to avoid deadlock.\r
++       * This should be safe because:\r
++       * 1. The tsx state just switches to TERMINATED or DESTROYED.\r
++       * 2. There should be no other processing taking place. All other\r
++       *    events, such as the ones handled by tsx_on_state_terminated()\r
++       *    should be ignored.\r
++         * 3. tsx_shutdown() hasn't been called.\r
++       * Refer to ticket #2001 (https://trac.pjsip.org/repos/ticket/2001).\r
++       */\r
++      if (event_src_type == PJSIP_EVENT_TIMER &&\r
++          (pj_timer_entry *)event_src == &tsx->timeout_timer)\r
++      {\r
++          pj_grp_lock_release(tsx->grp_lock);\r
++      }\r
++\r
+       (*tsx->tsx_user->on_tsx_state)(tsx, &e);\r
++\r
++      if (event_src_type == PJSIP_EVENT_TIMER &&\r
++          (pj_timer_entry *)event_src == &tsx->timeout_timer)\r
++      {\r
++          pj_grp_lock_acquire(tsx->grp_lock);\r
++      }\r
+     }\r
+     \r
diff --git a/third-party/pjproject/patches/0036-r5573-svn-backport-ua-pjsua-transaction-deadlock.patch b/third-party/pjproject/patches/0036-r5573-svn-backport-ua-pjsua-transaction-deadlock.patch
new file mode 100644 (file)
index 0000000..5887380
--- /dev/null
@@ -0,0 +1,119 @@
+Index: trunk/pjsip/include/pjsip/sip_transaction.h\r
+===================================================================\r
+--- a/pjsip/include/pjsip/sip_transaction.h    (revision 5572)\r
++++ b/pjsip/include/pjsip/sip_transaction.h    (revision 5573)\r
+@@ -180,4 +180,8 @@\r
+  * is created by calling #pjsip_tsx_create_key() from an incoming message.\r
+  *\r
++ * IMPORTANT: To prevent deadlock, application should use\r
++ * #pjsip_tsx_layer_find_tsx2() instead which only adds a reference to\r
++ * the transaction instead of locking it.\r
++ *\r
+  * @param key     The key string to find the transaction.\r
+  * @param lock            If non-zero, transaction will be locked before the\r
+@@ -190,4 +194,19 @@\r
+ PJ_DECL(pjsip_transaction*) pjsip_tsx_layer_find_tsx( const pj_str_t *key,\r
+                                                     pj_bool_t lock );\r
++\r
++/**\r
++ * Find a transaction with the specified key. The transaction key normally\r
++ * is created by calling #pjsip_tsx_create_key() from an incoming message.\r
++ *\r
++ * @param key     The key string to find the transaction.\r
++ * @param add_ref   If non-zero, transaction's reference will be added\r
++ *                by one before the function returns, to make sure that\r
++ *                it's not deleted by other threads.\r
++ *\r
++ * @return        The matching transaction instance, or NULL if transaction\r
++ *                can not be found.\r
++ */\r
++PJ_DECL(pjsip_transaction*) pjsip_tsx_layer_find_tsx2( const pj_str_t *key,\r
++                                                     pj_bool_t add_ref );\r
\r
+ /**\r
+Index: trunk/pjsip/src/pjsip/sip_transaction.c\r
+===================================================================\r
+--- a/pjsip/src/pjsip/sip_transaction.c        (revision 5572)\r
++++ b/pjsip/src/pjsip/sip_transaction.c        (revision 5573)\r
+@@ -642,6 +642,6 @@\r
+  * Find a transaction.\r
+  */\r
+-PJ_DEF(pjsip_transaction*) pjsip_tsx_layer_find_tsx( const pj_str_t *key,\r
+-                                                   pj_bool_t lock )\r
++static pjsip_transaction* find_tsx( const pj_str_t *key, pj_bool_t lock,\r
++                                  pj_bool_t add_ref )\r
+ {\r
+     pjsip_transaction *tsx;\r
+@@ -655,5 +655,5 @@\r
+     /* Prevent the transaction to get deleted before we have chance to lock it.\r
+      */\r
+-    if (tsx && lock)\r
++    if (tsx)\r
+         pj_grp_lock_add_ref(tsx->grp_lock);\r
+     \r
+@@ -667,10 +667,27 @@\r
+     PJ_RACE_ME(5);\r
\r
+-    if (tsx && lock) {\r
+-      pj_grp_lock_acquire(tsx->grp_lock);\r
+-        pj_grp_lock_dec_ref(tsx->grp_lock);\r
++    if (tsx) {\r
++      if (lock)\r
++          pj_grp_lock_acquire(tsx->grp_lock);\r
++\r
++        if (!add_ref)\r
++            pj_grp_lock_dec_ref(tsx->grp_lock);\r
+     }\r
\r
+     return tsx;\r
++}\r
++\r
++\r
++PJ_DEF(pjsip_transaction*) pjsip_tsx_layer_find_tsx( const pj_str_t *key,\r
++                                                   pj_bool_t lock )\r
++{\r
++    return find_tsx(key, lock, PJ_FALSE);\r
++}\r
++\r
++\r
++PJ_DEF(pjsip_transaction*) pjsip_tsx_layer_find_tsx2( const pj_str_t *key,\r
++                                                    pj_bool_t add_ref )\r
++{\r
++    return find_tsx(key, PJ_FALSE, add_ref);\r
+ }\r
\r
+Index: trunk/pjsip/src/pjsip/sip_ua_layer.c\r
+===================================================================\r
+--- a/pjsip/src/pjsip/sip_ua_layer.c   (revision 5572)\r
++++ b/pjsip/src/pjsip/sip_ua_layer.c   (revision 5573)\r
+@@ -552,10 +552,10 @@\r
\r
+       /* Lookup the INVITE transaction */\r
+-      tsx = pjsip_tsx_layer_find_tsx(&key, PJ_TRUE);\r
++      tsx = pjsip_tsx_layer_find_tsx2(&key, PJ_TRUE);\r
\r
+       /* We should find the dialog attached to the INVITE transaction */\r
+       if (tsx) {\r
+           dlg = (pjsip_dialog*) tsx->mod_data[mod_ua.mod.id];\r
+-          pj_grp_lock_release(tsx->grp_lock);\r
++          pj_grp_lock_dec_ref(tsx->grp_lock);\r
\r
+           /* Dlg may be NULL on some extreme condition\r
+Index: trunk/pjsip/src/pjsip-ua/sip_inv.c\r
+===================================================================\r
+--- a/pjsip/src/pjsip-ua/sip_inv.c     (revision 5572)\r
++++ b/pjsip/src/pjsip-ua/sip_inv.c     (revision 5573)\r
+@@ -3276,5 +3276,5 @@\r
+     pjsip_tsx_create_key(rdata->tp_info.pool, &key, PJSIP_ROLE_UAS,\r
+                        pjsip_get_invite_method(), rdata);\r
+-    invite_tsx = pjsip_tsx_layer_find_tsx(&key, PJ_TRUE);\r
++    invite_tsx = pjsip_tsx_layer_find_tsx2(&key, PJ_TRUE);\r
\r
+     if (invite_tsx == NULL) {\r
+@@ -3325,5 +3325,5 @@\r
\r
+     if (invite_tsx)\r
+-      pj_grp_lock_release(invite_tsx->grp_lock);\r
++      pj_grp_lock_dec_ref(invite_tsx->grp_lock);\r
+ }\r
\r
diff --git a/third-party/pjproject/patches/0037-r5576-svn-backport-session-timer-crash.patch b/third-party/pjproject/patches/0037-r5576-svn-backport-session-timer-crash.patch
new file mode 100644 (file)
index 0000000..098adcd
--- /dev/null
@@ -0,0 +1,72 @@
+Index: pjproject/trunk/pjsip/src/pjsip-ua/sip_timer.c
+===================================================================
+--- a/pjsip/src/pjsip-ua/sip_timer.c   (revision 5557)
++++ b/pjsip/src/pjsip-ua/sip_timer.c   (revision 5576)
+@@ -333,6 +333,8 @@
+     pjsip_tx_data *tdata = NULL;
+     pj_status_t status;
+     pj_bool_t as_refresher;
++    int entry_id;
++    char obj_name[PJ_MAX_OBJ_NAME];
+     pj_assert(inv);
+@@ -344,7 +346,10 @@
+     /* Check our role */
+     as_refresher =
+       (inv->timer->refresher == TR_UAC && inv->timer->role == PJSIP_ROLE_UAC) ||
+-      (inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS);    
++      (inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS);
++
++    entry_id = entry->id;
++    pj_ansi_strncpy(obj_name, inv->pool->obj_name, PJ_MAX_OBJ_NAME);
+     /* Do action based on role(refresher or refreshee). 
+      * As refresher:
+@@ -353,7 +358,7 @@
+      * As refreshee:
+      * - end session if there is no refresh request received.
+      */
+-    if (as_refresher && (entry->id != REFRESHER_EXPIRE_TIMER_ID)) {
++    if (as_refresher && (entry_id != REFRESHER_EXPIRE_TIMER_ID)) {
+       pj_time_val now;
+       /* As refresher, reshedule the refresh request on the following:
+@@ -414,7 +419,7 @@
+       }
+       pj_gettimeofday(&now);
+-      PJ_LOG(4, (inv->pool->obj_name,
++      PJ_LOG(4, (obj_name,
+                  "Refreshing session after %ds (expiration period=%ds)",
+                  (now.sec-inv->timer->last_refresh.sec),
+                  inv->timer->setting.sess_expires));
+@@ -432,7 +437,7 @@
+                                      NULL, &tdata);
+       pj_gettimeofday(&now);
+-      PJ_LOG(3, (inv->pool->obj_name, 
++      PJ_LOG(3, (obj_name,
+                  "No session %s received after %ds "
+                  "(expiration period=%ds), stopping session now!",
+                  (as_refresher?"refresh response":"refresh"),
+@@ -451,11 +456,16 @@
+       status = pjsip_inv_send_msg(inv, tdata);        
+     }
++    /*
++     * At this point, dialog might have already been destroyed,
++     * including its pool used by the invite session.
++     */
++
+     /* Print error message, if any */
+     if (status != PJ_SUCCESS) {
+-      PJ_PERROR(2, (inv->pool->obj_name, status,
++      PJ_PERROR(2, (obj_name, status,
+                    "Error in %s session timer",
+-                   ((as_refresher && entry->id != REFRESHER_EXPIRE_TIMER_ID)? 
++                   ((as_refresher && entry_id != REFRESHER_EXPIRE_TIMER_ID)?
+                      "refreshing" : "terminating")));
+     }
+ }
+