[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Sep 22 15:22:22 CDT 2010


branch "master" has been updated
       via  642bb8372c6aaea16e9b8833c6bd26ea24f86edc (commit)
      from  521b4891fec9f3dab6a9da7284c1254ef52ce47c (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |   45 +++++++++++++++++++++----------------------
 1 files changed, 22 insertions(+), 23 deletions(-)


- Log -----------------------------------------------------------------
commit 642bb8372c6aaea16e9b8833c6bd26ea24f86edc
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Sep 22 15:22:51 2010 -0500

    Clean up INVITE handling some by handling failure cases properly.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 6c2e25f..d065cf5 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -330,43 +330,44 @@ static void handle_new_invite(pjsip_rx_data *rdata)
 	//handle the request. For now, just plunge forward.
 	
 	pjsip_dialog *dlg;
+	pjsip_module *module = pjsip_ua_instance();
+
 	//XXX The NULL parameter should be replaced with
 	//An appropriate Contact header. Leaving it NULL makes
 	//PJSIP create the contact header for responses based
 	//on the To header of the incoming Invite.
-	pjsip_module *module = pjsip_ua_instance();
-	pj_status_t status = pjsip_dlg_create_uas(module, rdata, NULL, &dlg);
-	PJSipDialogModInfo *dlg_mod_info = new PJSipDialogModInfo(dlg);
-
-	if (status != PJ_SUCCESS)
+	if (pjsip_dlg_create_uas(module, rdata, NULL, &dlg) != PJ_SUCCESS)
 	{
 		std::cerr << "[WARNING] Unable to create UAS dialog on incoming INVITE" << std::endl;
+		return;
 	}
 
+	PJSipDialogModInfo *dlg_mod_info = new PJSipDialogModInfo(dlg);
+
 	//XXX The sdp argument is NULL for now, but can be changed if we
 	//know what has been configured for this particular caller.
-	
 	pjsip_inv_session *inv_session;
-	status = pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session);
-
-	if (status != PJ_SUCCESS)
+	if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS)
 	{
 		std::cerr << "[WARNING] Unable to create INVITE session" << std::endl;
+		//Since the inv_session was not created, we need to access the base dialog
+		//directly instead. Other failure cases will use pjsip_inv_terminate instead.
+		pjsip_dlg_terminate(dlg);
+		return;
 	}
 
 	pjsip_tx_data *tdata;
-	status = pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata);
-
-	if (status != PJ_SUCCESS)
+	if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
 	{
 		std::cerr << "[WARNING] Failed to create 100 Trying response" << std::endl;
+		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+		return;
 	}
 
-	status = pjsip_inv_send_msg(inv_session, tdata);
-
-	if (status != PJ_SUCCESS)
+	if (pjsip_inv_send_msg(inv_session, tdata) != PJ_SUCCESS)
 	{
 		std::cerr << "[WARNING] Failed to send 100 Trying response" << std::endl;
+		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
 	}
 
 	SipChannelServiceDataModel &dataModel = SipChannelServiceDataModel::getInstance();
@@ -381,15 +382,13 @@ static void handle_new_invite(pjsip_rx_data *rdata)
 	SipEndpointPtr caller = factory->findByName(callerName);
 	if (caller == 0)
 	{
-		pjsip_inv_answer(inv_session, 404, NULL, NULL, &tdata);
-		pjsip_inv_send_msg(inv_session, tdata);
+		pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
 		return;
 	}
 	SipEndpointConfig &config = caller->getConfig();
 	if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
 	{
-		pjsip_inv_answer(inv_session, 403, NULL, NULL, &tdata);
-		pjsip_inv_send_msg(inv_session, tdata);
+		pjsip_inv_end_session(inv_session, 403, NULL, &tdata);
 		return;
 	}
 
@@ -421,14 +420,14 @@ static void handle_new_invite(pjsip_rx_data *rdata)
 	catch (AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
 	{
 	   // Destination not found is special since we can actually map it to a good response code, 404
-	   pjsip_inv_answer(inv_session, 404, NULL, NULL, &tdata);
-	   pjsip_inv_send_msg(inv_session, tdata);
+	   pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
+	   return;
 	}
 	catch (...)
 	{
 	   // Everything else doesn't really map so they just become internal server errors
-	   pjsip_inv_answer(inv_session, 500, NULL, NULL, &tdata);
-	   pjsip_inv_send_msg(inv_session, tdata);
+	   pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
+	   return;
 	}
 	// All the actual call routing is taken care of, so let's tell the state replicator
 	// what all we learned.

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list