[Freeswitch-svn] [commit] r1986 - freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip

Freeswitch SVN anthm at freeswitch.org
Wed Jul 19 14:01:40 EDT 2006


Author: anthm
Date: Wed Jul 19 14:01:40 2006
New Revision: 1986

Modified:
   freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c

Log:
trying to stop race 

Modified: freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c
==============================================================================
--- freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c	(original)
+++ freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c	Wed Jul 19 14:01:40 2006
@@ -247,18 +247,18 @@
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initial SDP created\n" );
 
 		/* create INVITE session */
-		status = pjsip_inv_create_uac( tech_pvt->sip_dialog, sdp, 0, &tech_pvt->sip_invite );
-		if ( status != PJ_SUCCESS ) {
+		if ((status = pjsip_inv_create_uac( tech_pvt->sip_dialog, sdp, 0, &tech_pvt->sip_invite ) != PJ_SUCCESS )) {
 			switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new INVITE session for call %s\n" );
 			pjsip_dlg_terminate( tech_pvt->sip_dialog );
 			return SWITCH_STATUS_GENERR;
 		}
 
-		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invite UAC created\n" );
 
 		/* attach private object to pjsip session data */
 		tech_pvt->sip_invite->mod_data[globals.mod_app.id] = tech_pvt;
 
+		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invite UAC created\n" );
+
 		/* create invite request */
 		status = pjsip_inv_invite( tech_pvt->sip_invite, &txdata );
 		if ( status != PJ_SUCCESS ) {
@@ -528,9 +528,10 @@
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new private object for call\n" );
 		goto err;
 	}
+	tech_pvt->session = *new_session;
 	switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 	tech_pvt->profile = profile;
-	tech_pvt->session = *new_session;
+
 	switch_core_session_set_private( *new_session, tech_pvt );
 	channel = switch_core_session_get_channel( *new_session );
 
@@ -768,15 +769,15 @@
 			return;
 		}
 
+		switch_core_session_set_private( session, tech_pvt );
+		tech_pvt->session = session;
+
 		switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 
 		/* need the invite data in pjsip_on_init */
 		tech_pvt->sip_ua = pjsip_ua_instance();
 		tech_pvt->profile = profile;
 		
-		switch_core_session_set_private( session, tech_pvt );
-		tech_pvt->session = session;
-
 		/* give the new session a name */
 		pj_strdup_with_null( pjsip_pool, &tmp, &((pjsip_sip_uri *)rxdata->msg_info.from->uri)->host );
 		snprintf( name, sizeof(name), "pjsip/%s/%s-%04x", profile->name, tmp.ptr, rand() & 0xffff );
@@ -804,10 +805,11 @@
 		
 		/* Create our initial sdp */
 		create_sdp( dialog->pool, tech_pvt, &sdp, NULL );
+		tech_pvt->sip_dialog = dialog;
 
+		
 		/* Create UAS invite session */
-		status = pjsip_inv_create_uas( dialog, rxdata, sdp, 0, &tech_pvt->sip_invite );
-		if( status != PJ_SUCCESS ) {
+		if ((status = pjsip_inv_create_uas( dialog, rxdata, sdp, 0, &tech_pvt->sip_invite ) != PJ_SUCCESS )) {
 			pjsip_dlg_create_response( dialog, rxdata, 500, NULL, &txdata );
 			pjsip_dlg_send_response( dialog, pjsip_rdata_get_tsx( rxdata ), txdata );
 
@@ -816,6 +818,10 @@
 			return;
 		}
 
+
+		tech_pvt->sip_invite->mod_data[globals.mod_app.id] = tech_pvt;
+		tech_pvt->profile = profile;
+
 		pj_strdup_with_null( pjsip_pool, &username, &((pjsip_sip_uri *)rxdata->msg_info.from->uri)->user );
 		pj_strdup_with_null( pjsip_pool, &host, &((pjsip_sip_uri *)rxdata->msg_info.from->uri)->host );
 		pj_strdup_with_null( pjsip_pool, &destination, &((pjsip_sip_uri *)rxdata->msg_info.to->uri)->host );
@@ -834,12 +840,7 @@
 													destination.ptr)) != 0 ) {
 			switch_channel_set_caller_profile( channel, tech_pvt->caller_profile );
 		}
-
-		/* assign vars */
-		tech_pvt->sip_invite->mod_data[globals.mod_app.id] = tech_pvt;
-		tech_pvt->sip_dialog = dialog;
-		tech_pvt->profile = profile;
-
+		
 		/* set call id */
 		pjsip_strncpy( tech_pvt->call_id, &dialog->call_id->id, sizeof( tech_pvt->call_id ) );
 
@@ -949,11 +950,11 @@
 	tech_pvt = inv->mod_data[globals.mod_app.id];
 	assert( tech_pvt != NULL );
 
+	session = tech_pvt->session;
+	assert ( session != NULL );
+
 	profile = tech_pvt->profile;
 	assert( profile != NULL );
-
-	session = tech_pvt->session;
-	assert( session != NULL );
 
 	channel = switch_core_session_get_channel( session );
 	assert( channel != NULL );



More information about the Freeswitch-svn mailing list