[asterisk-commits] mmichelson: branch mmichelson/direct_media r382814 - /team/mmichelson/direct_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 11 15:43:37 CDT 2013


Author: mmichelson
Date: Mon Mar 11 15:43:34 2013
New Revision: 382814

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382814
Log:
Make it so rescheduled reinvites due to a 491 get the response callback
called.


Modified:
    team/mmichelson/direct_media/res/res_sip_session.c

Modified: team/mmichelson/direct_media/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/res/res_sip_session.c?view=diff&rev=382814&r1=382813&r2=382814
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Mon Mar 11 15:43:34 2013
@@ -999,27 +999,57 @@
 	return handled;
 }
 
+struct reschedule_reinvite_data {
+	struct ast_sip_session *session;
+	response_cb on_response;
+};
+
+static struct reschedule_reinvite_data *reschedule_reinvite_data_alloc(struct ast_sip_session *session, response_cb on_response)
+{
+	struct reschedule_reinvite_data *rrd = ast_malloc(sizeof(*rrd));
+	if (!rrd) {
+		return NULL;
+	}
+	ao2_ref(session, +1);
+	rrd->session = session;
+	rrd->on_response = on_response;
+	return rrd;
+}
+
+static void reschedule_reinvite_data_destroy(struct reschedule_reinvite_data *rrd)
+{
+	ao2_cleanup(rrd->session);
+	ast_free(rrd);
+}
+
 static int really_resend_reinvite(void *data)
 {
-	struct ast_sip_session *session = data;
-
-	/* XXX Address the callbacks here!! */
-	ast_sip_session_refresh(session, NULL, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
-	ao2_ref(session, -1);
+	struct reschedule_reinvite_data *rrd = data;
+	struct ast_sip_session *session = rrd->session;
+	response_cb on_response = rrd->on_response;
+
+	ast_sip_session_refresh(session, NULL, on_response, AST_SIP_SESSION_REFRESH_METHOD_INVITE);
+	reschedule_reinvite_data_destroy(rrd);
 	return 0;
 }
 
 static void resend_reinvite(pj_timer_heap_t *timer, pj_timer_entry *entry)
 {
-	struct ast_sip_session *session = entry->user_data;
-
-	ast_sip_push_task(session->serializer, really_resend_reinvite, session);
-}
-
-static void reschedule_reinvite(struct ast_sip_session *session)
+	struct reschedule_reinvite_data *rrd = entry->user_data;
+
+	ast_sip_push_task(rrd->session->serializer, really_resend_reinvite, entry->user_data);
+}
+
+static void reschedule_reinvite(struct ast_sip_session *session, response_cb on_response)
 {
 	pjsip_inv_session *inv = session->inv_session;
+	struct reschedule_reinvite_data *rrd = reschedule_reinvite_data_alloc(session, on_response);
 	pj_time_val tv;
+	
+	if (!rrd) {
+		return;
+	}
+
 	tv.sec = 0;
 	if (inv->role == PJSIP_ROLE_UAC) {
 		tv.msec = 2100 + ast_random() % 2000;
@@ -1027,9 +1057,8 @@
 		tv.msec = ast_random() % 2000;
 	}
 
-	pj_timer_entry_init(&session->rescheduled_reinvite, 0, session, resend_reinvite);
-
-	ao2_ref(session, +1);
+	pj_timer_entry_init(&session->rescheduled_reinvite, 0, rrd, resend_reinvite);
+
 	pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &session->rescheduled_reinvite, &tv);
 }
 
@@ -1245,7 +1274,7 @@
 			} else if (tsx->role == PJSIP_ROLE_UAC && tsx->state == PJSIP_TSX_STATE_COMPLETED) {
 				/* This means we got a non 2XX final response to our outgoing INVITE */
 				if (tsx->status_code == PJSIP_SC_REQUEST_PENDING) {
-					reschedule_reinvite(session);
+					reschedule_reinvite(session, tsx->mod_data[session_module.id]);
 					return;
 				} else {
 					/* Other failures result in destroying the session. */




More information about the asterisk-commits mailing list