[asterisk-commits] mmichelson: branch mmichelson/direct_media r382846 - in /team/mmichelson/dire...

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


Author: mmichelson
Date: Tue Mar 12 10:44:34 2013
New Revision: 382846

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382846
Log:
Re-send created requests if possible when delaying requests.

This way, if someone has added custom headers to a request they
created, then we will re-send that same request instead of creating
a new one from scratch.


Modified:
    team/mmichelson/direct_media/include/asterisk/res_sip_session.h
    team/mmichelson/direct_media/res/res_sip_session.c
    team/mmichelson/direct_media/res/res_sip_session.exports.in

Modified: team/mmichelson/direct_media/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/include/asterisk/res_sip_session.h?view=diff&rev=382846&r1=382845&r2=382846
==============================================================================
--- team/mmichelson/direct_media/include/asterisk/res_sip_session.h (original)
+++ team/mmichelson/direct_media/include/asterisk/res_sip_session.h Tue Mar 12 10:44:34 2013
@@ -103,6 +103,7 @@
 	char method[15];
 	ast_sip_session_request_creation_cb on_request_creation;
 	ast_sip_session_response_cb on_response;
+	pjsip_tx_data *tdata;
 	AST_LIST_ENTRY(ast_sip_session_delayed_request) next;
 };
 

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=382846&r1=382845&r2=382846
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Tue Mar 12 10:44:34 2013
@@ -352,16 +352,21 @@
 
 static int send_delayed_request(void *data)
 {
-	struct ast_sip_session *session = data;
-	struct ast_sip_session_delayed_request *delay;
+	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) {
-		ao2_ref(session, -1);
 		return 0;
 	}
 
 	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;
+	}
 
 	if (!strcmp(delay->method, "INVITE")) {
 		ast_sip_session_refresh(session, delay->on_request_creation,
@@ -369,16 +374,10 @@
 	} else if (!strcmp(delay->method, "UPDATE")) {
 		ast_sip_session_refresh(session, delay->on_request_creation,
 				delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_UPDATE);
-	} else if (!strcmp(delay->method, "BYE")) {
-		pjsip_tx_data *tdata;
-		pjsip_inv_end_session(session->inv_session, 500, 0, &tdata);
-		if (delay->on_request_creation) {
-			delay->on_request_creation(session, tdata);
-		}
-		ast_sip_session_send_request(session, tdata);
-	}
-	ast_free(delay);
-	ao2_ref(session, -1);
+	} else {
+		ast_log(LOG_WARNING, "Unexpected delayed %s request with no existing request structure\n", delay->method);
+		return -1;
+	}
 	return 0;
 }
 
@@ -397,7 +396,7 @@
 }
 
 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)
+		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));
 	if (!delay) {
@@ -406,6 +405,7 @@
 	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;
 }
@@ -430,7 +430,7 @@
 		/* We can't send a reinvite yet, so delay it */
 		ast_debug(3, "Delaying sending reinvite to %s because of outstanding transaction...\n",
 				ast_sorcery_object_get_id(session->endpoint));
-		return delay_request(session, on_request_creation, on_response, "INVITE");
+		return delay_request(session, on_request_creation, on_response, "INVITE", NULL);
 	}
 
 	if (pjmedia_sdp_neg_was_answer_remote(inv_session->neg)) {
@@ -496,7 +496,7 @@
 		ast_copy_pj_str(method, &tdata->msg->line.req.method.name, sizeof(method));
 		ast_debug(3, "Delaying sending %s request to %s due to outstanding transaction\n",
 				method, ast_sorcery_object_get_id(session->endpoint));
-		delay_request(session, NULL, on_response, method);
+		delay_request(session, NULL, on_response, method, tdata);
 		return;
 	}
 

Modified: team/mmichelson/direct_media/res/res_sip_session.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/res/res_sip_session.exports.in?view=diff&rev=382846&r1=382845&r2=382846
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.exports.in (original)
+++ team/mmichelson/direct_media/res/res_sip_session.exports.in Tue Mar 12 10:44:34 2013
@@ -5,6 +5,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_session_register_supplement;
 		LINKER_SYMBOL_PREFIXast_sip_session_unregister_supplement;
 		LINKER_SYMBOL_PREFIXast_sip_session_alloc_datastore;
+		LINKER_SYMBOL_PREFIXast_sip_session_add_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_session_get_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_session_remove_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_session_get_identity;




More information about the asterisk-commits mailing list