[asterisk-commits] file: branch file/gulp_transfer r388958 - in /team/file/gulp_transfer: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 17 11:10:06 CDT 2013


Author: file
Date: Fri May 17 11:10:04 2013
New Revision: 388958

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388958
Log:
Add a timer entry so that a session is automatically terminated if the remote endpoint does not play nice.

Modified:
    team/file/gulp_transfer/include/asterisk/res_sip_session.h
    team/file/gulp_transfer/res/res_sip_refer.c
    team/file/gulp_transfer/res/res_sip_session.c
    team/file/gulp_transfer/res/res_sip_session.exports.in

Modified: team/file/gulp_transfer/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_transfer/include/asterisk/res_sip_session.h?view=diff&rev=388958&r1=388957&r2=388958
==============================================================================
--- team/file/gulp_transfer/include/asterisk/res_sip_session.h (original)
+++ team/file/gulp_transfer/include/asterisk/res_sip_session.h Fri May 17 11:10:04 2013
@@ -95,6 +95,8 @@
 	AST_LIST_HEAD_NOLOCK(, ast_sip_session_delayed_request) delayed_requests;
 	/* When we need to reschedule a reinvite, we use this structure to do it */
 	pj_timer_entry rescheduled_reinvite;
+	/* When we need to forcefully end the session */
+	pj_timer_entry scheduled_termination;
 	/* Format capabilities pertaining to direct media */
 	struct ast_format_cap *direct_media_cap;
 	/* Identity of endpoint this session deals with */
@@ -291,6 +293,13 @@
 struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user, struct ast_format_cap *req_caps);
 
 /*!
+ * \brief Defer local termination of a session until remote side terminates, or an amount of time passes
+ *
+ * \param session The session to defer termination on
+ */
+void ast_sip_session_defer_termination(struct ast_sip_session *session);
+
+/*!
  * \brief Register an SDP handler
  *
  * An SDP handler is responsible for parsing incoming SDP streams and ensuring that

Modified: team/file/gulp_transfer/res/res_sip_refer.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_transfer/res/res_sip_refer.c?view=diff&rev=388958&r1=388957&r2=388958
==============================================================================
--- team/file/gulp_transfer/res/res_sip_refer.c (original)
+++ team/file/gulp_transfer/res/res_sip_refer.c Fri May 17 11:10:04 2013
@@ -379,7 +379,7 @@
 		break;
 	case AST_BRIDGE_TRANSFER_SUCCESS:
 		response = 200;
-		attended->transferer->defer_terminate = 1;
+		ast_sip_session_defer_termination(attended->transferer);
 		break;
 	}
 
@@ -551,7 +551,7 @@
 		case AST_BRIDGE_TRANSFER_FAIL:
 			return 500;
 		case AST_BRIDGE_TRANSFER_SUCCESS:
-			session->defer_terminate = 1;
+			ast_sip_session_defer_termination(session);
 			return 200;
 		}
 
@@ -593,7 +593,7 @@
 	case AST_BRIDGE_TRANSFER_FAIL:
 		return 500;
 	case AST_BRIDGE_TRANSFER_SUCCESS:
-		session->defer_terminate = 1;
+		ast_sip_session_defer_termination(session);
 		return 200;
 	}
 

Modified: team/file/gulp_transfer/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_transfer/res/res_sip_session.c?view=diff&rev=388958&r1=388957&r2=388958
==============================================================================
--- team/file/gulp_transfer/res/res_sip_session.c (original)
+++ team/file/gulp_transfer/res/res_sip_session.c Fri May 17 11:10:04 2013
@@ -1040,6 +1040,47 @@
 	return session;
 }
 
+static int session_termination_task(void *data)
+{
+	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
+	pjsip_tx_data *packet = NULL;
+
+	if (!session->inv_session) {
+		return 0;
+	}
+
+	if (pjsip_inv_end_session(session->inv_session, 603, NULL, &packet) == PJ_SUCCESS) {
+		ast_sip_session_send_request(session, packet);
+	}
+
+	return 0;
+}
+
+static void session_termination_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
+{
+	struct ast_sip_session *session = entry->user_data;
+
+	if (ast_sip_push_task(session->serializer, session_termination_task, session)) {
+		ao2_cleanup(session);
+	}
+}
+
+void ast_sip_session_defer_termination(struct ast_sip_session *session)
+{
+	pj_time_val delay = { .sec = 60, };
+
+	session->defer_terminate = 1;
+
+	session->scheduled_termination.id = 0;
+	ao2_ref(session, +1);
+	session->scheduled_termination.user_data = session;
+	session->scheduled_termination.cb = session_termination_cb;
+
+	if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &session->scheduled_termination, &delay) != PJ_SUCCESS) {
+		ao2_ref(session, -1);
+	}
+}
+
 struct ast_sip_session *ast_sip_dialog_get_session(pjsip_dialog *dlg)
 {
 	pjsip_inv_session *inv_session = pjsip_dlg_get_inv_session(dlg);
@@ -1472,6 +1513,11 @@
 static int session_end(struct ast_sip_session *session)
 {
 	struct ast_sip_session_supplement *iter;
+
+	/* Stop the scheduled termination */
+	if (pj_timer_heap_cancel(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()), &session->scheduled_termination)) {
+		ao2_ref(session, -1);
+	}
 
 	/* Session is dead. Let's get rid of the reference to the session */
 	AST_LIST_TRAVERSE(&session->supplements, iter, next) {

Modified: team/file/gulp_transfer/res/res_sip_session.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_transfer/res/res_sip_session.exports.in?view=diff&rev=388958&r1=388957&r2=388958
==============================================================================
--- team/file/gulp_transfer/res/res_sip_session.exports.in (original)
+++ team/file/gulp_transfer/res/res_sip_session.exports.in Fri May 17 11:10:04 2013
@@ -1,5 +1,6 @@
 {
 	global:
+		LINKER_SYMBOL_PREFIXast_sip_session_defer_termination;
 		LINKER_SYMBOL_PREFIXast_sip_session_register_sdp_handler;
 		LINKER_SYMBOL_PREFIXast_sip_session_unregister_sdp_handler;
 		LINKER_SYMBOL_PREFIXast_sip_session_register_supplement;




More information about the asterisk-commits mailing list