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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 12 14:10:08 CDT 2013


Author: mmichelson
Date: Tue Mar 12 14:10:05 2013
New Revision: 382901

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382901
Log:
Make rescheduled reinvites use the same methods as other delayed requests.

Besides not repeating myself, it also allows for the same reinvite to be resent
when we reschedule due to a 491. So any custom headers added to the first reinvite
will be present in the rescheduled reinvite as well.


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=382901&r1=382900&r2=382901
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Tue Mar 12 14:10:05 2013
@@ -358,20 +358,27 @@
 	AST_LIST_ENTRY(ast_sip_session_delayed_request) next;
 };
 
-static int send_delayed_request(void *data)
-{
-	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
-	RAII_VAR(struct ast_sip_session_delayed_request *, delay, NULL, ast_free_ptr);
-
-	delay = AST_LIST_REMOVE_HEAD(&session->delayed_requests, next);
+static struct ast_sip_session_delayed_request *delayed_request_alloc(const char *method,
+		ast_sip_session_request_creation_cb on_request_creation,
+		ast_sip_session_response_cb on_response,
+		pjsip_tx_data *tdata)
+{
+	struct ast_sip_session_delayed_request *delay = ast_calloc(1, sizeof(*delay));
 	if (!delay) {
-		return 0;
-	}
-
+		return NULL;
+	}
+	ast_copy_string(delay->method, method, sizeof(delay->method));
+	delay->on_request_creation = on_request_creation;
+	delay->on_response = on_response;
+	delay->tdata = tdata;
+	return delay;
+}
+
+static int send_delayed_request(struct ast_sip_session *session, struct ast_sip_session_delayed_request *delay)
+{
 	ast_debug(3, "Sending delayed %s request to %s\n", delay->method, ast_sorcery_object_get_id(session->endpoint));
 
 	if (delay->tdata) {
-		/* Just re-send the request. Easy-peasy */
 		ast_sip_session_send_request_with_cb(session, delay->tdata, delay->on_response);
 		return 0;
 	}
@@ -389,6 +396,19 @@
 	return 0;
 }
 
+static int queued_delayed_request_send(void *data)
+{
+	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
+	RAII_VAR(struct ast_sip_session_delayed_request *, delay, NULL, ast_free_ptr);
+
+	delay = AST_LIST_REMOVE_HEAD(&session->delayed_requests, next);
+	if (!delay) {
+		return 0;
+	}
+
+	return send_delayed_request(session, delay);
+}
+
 static void queue_delayed_request(struct ast_sip_session *session)
 {
 	if (AST_LIST_EMPTY(&session->delayed_requests)) {
@@ -400,20 +420,19 @@
 			ast_sorcery_object_get_id(session->endpoint));
 
 	ao2_ref(session, +1);
-	ast_sip_push_task(session->serializer, send_delayed_request, session);
+	ast_sip_push_task(session->serializer, queued_delayed_request_send, session);
 }
 
 static int delay_request(struct ast_sip_session *session, ast_sip_session_request_creation_cb on_request,
 		ast_sip_session_response_cb on_response, const char *method, pjsip_tx_data *tdata)
 {
-	struct ast_sip_session_delayed_request *delay = ast_calloc(1, sizeof(*delay));
+	struct ast_sip_session_delayed_request *delay = delayed_request_alloc(method,
+			on_request, on_response, tdata);
+
 	if (!delay) {
 		return -1;
 	}
-	ast_copy_string(delay->method, method, sizeof(delay->method));
-	delay->on_request_creation = on_request;
-	delay->on_response = on_response;
-	delay->tdata = tdata;
+
 	AST_LIST_INSERT_TAIL(&session->delayed_requests, delay, next);
 	return 0;
 }
@@ -1009,10 +1028,11 @@
 
 struct reschedule_reinvite_data {
 	struct ast_sip_session *session;
-	ast_sip_session_response_cb on_response;
+	struct ast_sip_session_delayed_request *delay;
 };
 
-static struct reschedule_reinvite_data *reschedule_reinvite_data_alloc(struct ast_sip_session *session, ast_sip_session_response_cb on_response)
+static struct reschedule_reinvite_data *reschedule_reinvite_data_alloc(
+		struct ast_sip_session *session, struct ast_sip_session_delayed_request *delay)
 {
 	struct reschedule_reinvite_data *rrd = ast_malloc(sizeof(*rrd));
 	if (!rrd) {
@@ -1020,25 +1040,22 @@
 	}
 	ao2_ref(session, +1);
 	rrd->session = session;
-	rrd->on_response = on_response;
+	rrd->delay = delay;
 	return rrd;
 }
 
 static void reschedule_reinvite_data_destroy(struct reschedule_reinvite_data *rrd)
 {
 	ao2_cleanup(rrd->session);
+	ast_free(rrd->delay);
 	ast_free(rrd);
 }
 
 static int really_resend_reinvite(void *data)
 {
-	struct reschedule_reinvite_data *rrd = data;
-	struct ast_sip_session *session = rrd->session;
-	ast_sip_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;
+	RAII_VAR(struct reschedule_reinvite_data *, rrd, data, reschedule_reinvite_data_destroy);
+
+	return send_delayed_request(rrd->session, rrd->delay);
 }
 
 static void resend_reinvite(pj_timer_heap_t *timer, pj_timer_entry *entry)
@@ -1048,13 +1065,15 @@
 	ast_sip_push_task(rrd->session->serializer, really_resend_reinvite, entry->user_data);
 }
 
-static void reschedule_reinvite(struct ast_sip_session *session, ast_sip_session_response_cb on_response)
-{
+static void reschedule_reinvite(struct ast_sip_session *session, ast_sip_session_response_cb on_response, pjsip_tx_data *tdata)
+{
+	struct ast_sip_session_delayed_request *delay = delayed_request_alloc("INVITE",
+			NULL, on_response, tdata);
 	pjsip_inv_session *inv = session->inv_session;
-	struct reschedule_reinvite_data *rrd = reschedule_reinvite_data_alloc(session, on_response);
+	struct reschedule_reinvite_data *rrd = reschedule_reinvite_data_alloc(session, delay);
 	pj_time_val tv;
 	
-	if (!rrd) {
+	if (!rrd || !delay) {
 		return;
 	}
 
@@ -1277,7 +1296,7 @@
 			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, tsx->mod_data[session_module.id]);
+					reschedule_reinvite(session, tsx->mod_data[session_module.id], tsx->last_tx);
 					return;
 				} else {
 					/* Other failures result in destroying the session. */




More information about the asterisk-commits mailing list