[asterisk-commits] file: trunk r419766 - in /trunk: ./ res/res_pjsip_session.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 29 05:59:50 CDT 2014


Author: file
Date: Tue Jul 29 05:56:40 2014
New Revision: 419766

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419766
Log:
res_pjsip_session: Fix race condition where redirecting information may not be set.

Since the PJSIP INVITE session module is invoked before any session supplements it was
possible for it to handle a redirect before the res_pjsip_diversion module interpreted
and set redirecting information on the channel. This would cause the redirecting
information to get lost.

This patch ensures that session supplements are *always* invoked before a redirect occurs
by explicitly calling them in the redirect handler.

Review: https://reviewboard.asterisk.org/r/3850/
........

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

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip_session.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_session.c?view=diff&rev=419766&r1=419765&r2=419766
==============================================================================
--- trunk/res/res_pjsip_session.c (original)
+++ trunk/res/res_pjsip_session.c Tue Jul 29 05:56:40 2014
@@ -55,9 +55,9 @@
 static const pj_str_t *hostname;
 
 /* Some forward declarations */
-static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata);
-static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata);
-static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata);
+static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type);
+static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type);
+static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type);
 static void handle_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 static void handle_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata);
 static void handle_outgoing(struct ast_sip_session *session, pjsip_tx_data *tdata);
@@ -1571,7 +1571,7 @@
 	}
 	ast_sip_session_send_response(invite->session, tdata);
 
-	handle_incoming_request(invite->session, invite->rdata);
+	handle_incoming_request(invite->session, invite->rdata, PJSIP_EVENT_RX_MSG);
 
 	return 0;
 }
@@ -1782,7 +1782,7 @@
 
 #define print_debug_details(inv, tsx, e) __print_debug_details(__PRETTY_FUNCTION__, (inv), (tsx), (e))
 
-static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
+static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type)
 {
 	struct ast_sip_session_supplement *supplement;
 	struct pjsip_request_line req = rdata->msg_info.msg->line.req;
@@ -1797,10 +1797,15 @@
 	}
 }
 
-static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
+static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type)
 {
 	struct ast_sip_session_supplement *supplement;
 	struct pjsip_status_line status = rdata->msg_info.msg->line.status;
+
+	/* Squash all redirect transaction related responses as the supplements have already been invoked */
+	if (type == PJSIP_EVENT_TSX_STATE && PJSIP_IS_STATUS_IN_CLASS(status.code, 300)) {
+		return;
+	}
 
 	ast_debug(3, "Response is %d %.*s\n", status.code, (int) pj_strlen(&status.reason),
 			pj_strbuf(&status.reason));
@@ -1812,15 +1817,15 @@
 	}
 }
 
-static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata)
+static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type)
 {
 	ast_debug(3, "Received %s\n", rdata->msg_info.msg->type == PJSIP_REQUEST_MSG ?
 			"request" : "response");
 
 	if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) {
-		handle_incoming_request(session, rdata);
+		handle_incoming_request(session, rdata, type);
 	} else {
-		handle_incoming_response(session, rdata);
+		handle_incoming_response(session, rdata, type);
 	}
 
 	return 0;
@@ -1910,7 +1915,7 @@
 		handle_outgoing(session, e->body.tx_msg.tdata);
 		break;
 	case PJSIP_EVENT_RX_MSG:
-		handle_incoming(session, e->body.rx_msg.rdata);
+		handle_incoming(session, e->body.rx_msg.rdata, type);
 		break;
 	case PJSIP_EVENT_TSX_STATE:
 		ast_debug(3, "Source of transaction state change is %s\n", pjsip_event_str(e->body.tsx_state.type));
@@ -1920,7 +1925,7 @@
 			handle_outgoing(session, e->body.tsx_state.src.tdata);
 			break;
 		case PJSIP_EVENT_RX_MSG:
-			handle_incoming(session, e->body.tsx_state.src.rdata);
+			handle_incoming(session, e->body.tsx_state.src.rdata, type);
 			break;
 		case PJSIP_EVENT_TRANSPORT_ERROR:
 		case PJSIP_EVENT_TIMER:
@@ -2003,7 +2008,7 @@
 			}
 		} else {
 			if (tsx->role == PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING) {
-				handle_incoming_request(session, e->body.tsx_state.src.rdata);
+				handle_incoming_request(session, e->body.tsx_state.src.rdata, PJSIP_EVENT_TSX_STATE);
 			}
 		}
 		if ((cb = ast_sip_mod_data_get(tsx->mod_data, session_module.id,
@@ -2164,6 +2169,8 @@
 	if (!PJSIP_URI_SCHEME_IS_SIP(target) && !PJSIP_URI_SCHEME_IS_SIPS(target)) {
 		return PJSIP_REDIRECT_STOP;
 	}
+
+	handle_incoming(session, e->body.rx_msg.rdata, PJSIP_EVENT_RX_MSG);
 
 	uri = pjsip_uri_get_uri(target);
 




More information about the asterisk-commits mailing list