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

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


Author: mmichelson
Date: Mon Mar 11 15:12:56 2013
New Revision: 382813

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382813
Log:
Implement a callback system for session responses.

Now when an entity calls for a request to be sent, they can have a callback
called when the final response for their request arrives.

In addition, the session refresh method has a callback that can be called
when the request is created. This allows for a caller to add custom headers
if there is a need to do so before sending the request.


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=382813&r1=382812&r2=382813
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Mon Mar 11 15:12:56 2013
@@ -464,35 +464,6 @@
 	return;
 }
 
-void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
-		response_cb on_response)
-{
-	pjsip_inv_session *inv_session = session->inv_session;
-
-	if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
-		/* Don't try to do anything with a hung-up call */
-		return;
-	}
-
-	if (inv_session->invite_tsx) {
-		/* We can't send a request yet, so delay it */
-		char method[15];
-		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, S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
-		delay_request(session, NULL, on_response, method);
-		return;
-	}
-	handle_outgoing_request(session, tdata);
-	pjsip_inv_send_msg(session->inv_session, tdata);
-	return;
-}
-
-void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
-{
-	ast_sip_session_send_request_with_cb(session, tdata, NULL);
-}
-
 static pj_status_t session_load(pjsip_endpoint *endpt);
 static pj_status_t session_start(void);
 static pj_status_t session_stop(void);
@@ -508,6 +479,37 @@
 	.stop = session_stop,
 	.on_rx_request = session_on_rx_request,
 };
+
+void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
+		response_cb on_response)
+{
+	pjsip_inv_session *inv_session = session->inv_session;
+
+	if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
+		/* Don't try to do anything with a hung-up call */
+		return;
+	}
+
+	if (inv_session->invite_tsx) {
+		/* We can't send a request yet, so delay it */
+		char method[15];
+		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, S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
+		delay_request(session, NULL, on_response, method);
+		return;
+	}
+
+	tdata->mod_data[session_module.id] = on_response;
+	handle_outgoing_request(session, tdata);
+	pjsip_inv_send_msg(session->inv_session, tdata);
+	return;
+}
+
+void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
+{
+	ast_sip_session_send_request_with_cb(session, tdata, NULL);
+}
 
 /*!
  * \brief Called when the PJSIP core loads us
@@ -1229,20 +1231,41 @@
 		 */
 		return;
 	}
-	if (tsx->method.id == PJSIP_INVITE_METHOD) {
+	switch (e->body.tsx_state.type) {
+	case PJSIP_EVENT_TX_MSG:
+		tsx->mod_data[session_module.id] = e->body.tsx_state.src.tdata->mod_data[session_module.id];
 		if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
 			queue_delayed_request(session);
-		} 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);
-			} else {
-				/* Other failures result in destroying the session. */
-				pjsip_tx_data *tdata;
-				pjsip_inv_end_session(inv, 500, NULL, &tdata);
-				ast_sip_session_send_request(session, tdata);
+		}
+		break;
+	case PJSIP_EVENT_RX_MSG:
+		if (tsx->method.id == PJSIP_INVITE_METHOD) {
+			if (tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+				queue_delayed_request(session);
+			} 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);
+					return;
+				} else {
+					/* Other failures result in destroying the session. */
+					pjsip_tx_data *tdata;
+					pjsip_inv_end_session(inv, 500, NULL, &tdata);
+					ast_sip_session_send_request(session, tdata);
+				}
 			}
 		}
+		if (tsx->mod_data[session_module.id]) {
+			response_cb cb = tsx->mod_data[session_module.id];
+			cb(session, e->body.tsx_state.src.rdata);
+		}
+	case PJSIP_EVENT_TRANSPORT_ERROR:
+	case PJSIP_EVENT_TIMER:
+	case PJSIP_EVENT_USER:
+	case PJSIP_EVENT_UNKNOWN:
+	case PJSIP_EVENT_TSX_STATE:
+		/* Inception? */
+		break;
 	}
 }
 




More information about the asterisk-commits mailing list