[Freeswitch-branches] [commit] r11204 - freeswitch/branches/ctrix/mod_airpe

FreeSWITCH SVN ctrix at freeswitch.org
Wed Jan 14 13:05:23 PST 2009


Author: ctrix
Date: Wed Jan 14 15:05:23 2009
New Revision: 11204

Log:
Reworked all the call logic.
Big cleanups of unused code.
Should be almost working 100%!



Modified:
   freeswitch/branches/ctrix/mod_airpe/airpe_api.c
   freeswitch/branches/ctrix/mod_airpe/airpe_if_common.c
   freeswitch/branches/ctrix/mod_airpe/mod_airpe.c
   freeswitch/branches/ctrix/mod_airpe/mod_airpe.h

Modified: freeswitch/branches/ctrix/mod_airpe/airpe_api.c
==============================================================================
--- freeswitch/branches/ctrix/mod_airpe/airpe_api.c	(original)
+++ freeswitch/branches/ctrix/mod_airpe/airpe_api.c	Wed Jan 14 15:05:23 2009
@@ -30,6 +30,13 @@
 
 #include "mod_airpe.h"
 
+/* 
+    TODO
+	block / authorize users
+	add / remove users from contact list
+*/
+
+
 #define AIRPE_MOODTEXT_SYNTAX "airpe_moodtext <clientname> <text>"
 SWITCH_STANDARD_API(airpe_moodtext_command)
 {

Modified: freeswitch/branches/ctrix/mod_airpe/airpe_if_common.c
==============================================================================
--- freeswitch/branches/ctrix/mod_airpe/airpe_if_common.c	(original)
+++ freeswitch/branches/ctrix/mod_airpe/airpe_if_common.c	Wed Jan 14 15:05:23 2009
@@ -146,10 +146,36 @@
     return SWITCH_STATUS_SUCCESS;
 }
 
+void airpe_clear_call_id(airpe_interface_t *airpe) {
+
+    airpe->active_call_id = 0;
+    switch_safe_free(airpe->active_session_uuid);
+    airpe->active_session_uuid = NULL;
+}
+
+switch_status_t	airpe_set_call_id(airpe_interface_t *airpe, int sk_id, char *fs_uuid) {
+    assert(airpe);
+
+    airpe->active_call_id = sk_id;
+
+    if ( fs_uuid ) {
+	switch_safe_free(airpe->active_session_uuid);
+	airpe->active_session_uuid = strdup(fs_uuid);
+    }
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+/* ************************************************************************* */
+
 switch_status_t airpe_cmd_write(airpe_interface_t *airpe, char *msg) {
+    switch_status_t status;
+
     if ( airpe->debug )
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "msg to airpe client %s: %s\n", airpe->name, msg);
-    return airpe_skype_send_message(airpe->skype_window, msg);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "msg to airpe client %s: > %s\n", airpe->name, msg);
+
+    status = airpe_skype_send_message(airpe->skype_window, msg);
+    return status;
 }
 
 switch_status_t airpe_originate(airpe_interface_t *airpe, char *dest) {
@@ -161,7 +187,7 @@
     airpe_cmd_write(p, "SET AGC OFF");
     airpe_cmd_write(p, "SET AEC OFF");
     */
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "airpe client %s: Originating to %s\n", airpe->name, dest);
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "airpe client %s: Originating to client %s\n", airpe->name, dest);
 
     snprintf(msg, sizeof(msg), "CALL %s", dest);
 
@@ -182,17 +208,14 @@
     return SWITCH_STATUS_FALSE;
 }
 
-
-
 /*****************************************************************************
     SKYPE AUDIO
  *****************************************************************************/
 
-switch_status_t airpe_hangup( private_object_t *pvt ) {
+switch_status_t airpe_call_shutdown( private_object_t *pvt ) {
     airpe_interface_t *airpe;
 
     assert(pvt);
-    assert(pvt->session);
     assert(pvt->airpe);
     
     airpe = pvt->airpe;
@@ -225,10 +248,14 @@
     assert(pvt);
     assert(pvt->session);
     assert(pvt->airpe);
-    
+
+    if ( !switch_test_flag(pvt, TFLAG_IO) )
+	return SWITCH_STATUS_SUCCESS;
+
     airpe = pvt->airpe;
     pool = switch_core_session_get_pool(pvt->session);
 
+
     if ( !airpe->audio_in_active_socket ) {
 	rv = switch_socket_accept(&inbound_socket, airpe->audio_in_socket, pool);
         if ( rv == SWITCH_STATUS_SUCCESS ) {
@@ -262,6 +289,9 @@
     airpe = pvt->airpe;
     pool = switch_core_session_get_pool(pvt->session);
 
+    if ( !switch_test_flag(pvt, TFLAG_IO) )
+	return SWITCH_STATUS_SUCCESS;
+
     if ( !airpe->audio_out_active_socket ) {
 	rv = switch_socket_accept(&inbound_socket, airpe->audio_out_socket, pool);
         if ( rv == SWITCH_STATUS_SUCCESS ) {
@@ -269,7 +299,7 @@
 	    switch_sleep(100000);
 	}
 	else {
-	    return SWITCH_STATUS_FALSE;
+	    return SWITCH_STATUS_SUCCESS;
 	}
     }
 
@@ -281,9 +311,6 @@
     if ( (rv==SWITCH_STATUS_SUCCESS) ) {
 	    pvt->read_frame.datalen = mlen;
     }
-//    if ( mlen == 0 )
-//	return SWITCH_STATUS_SUCCESS;
-
     return rv;
 }
 
@@ -320,7 +347,7 @@
     }
     tech_pvt->airpe = airpe;
 
-    switch_snprintf(chan_name, sizeof(chan_name), MODNAME"/%s", airpe->name);
+    switch_snprintf(chan_name, sizeof(chan_name), MODNAME"/%s/%s", airpe->name, airpe->destination);
     switch_channel_set_name(channel, chan_name);
 
     tech_pvt->caller_profile = switch_caller_profile_new( switch_core_session_get_pool(new_session),
@@ -346,11 +373,12 @@
 
 
     switch_set_flag(tech_pvt, TFLAG_INBOUND);
-    airpe->active_call_id = callid;
+    airpe_set_call_id(airpe, callid, switch_core_session_get_uuid(new_session) );
+
     switch_channel_set_state(channel, CS_INIT);
 
     if ( switch_core_session_thread_launch(new_session) != SWITCH_STATUS_SUCCESS ) {
-	airpe->active_call_id = 0;
+	airpe_clear_call_id(airpe);
     	switch_core_session_destroy(&new_session);
 	return SWITCH_STATUS_FALSE;
     }
@@ -363,8 +391,23 @@
     switch_core_session_t *session = NULL;
     switch_channel_t *channel = NULL;
 
+    if ( airpe->active_session_uuid ) {
+	session = switch_core_session_locate(airpe->active_session_uuid);
+	if ( session )
+	    channel = switch_core_session_get_channel(session);
+    }
+
+/*
+ADEBUG("MANAGING: %s - %d - %d - INB: %d - OUTB %d\n", 
+    (airpe->active_session_uuid) ? airpe->active_session_uuid : "NO SESSION UUID",
+    (session) ? 1 : 0,
+    (channel) ? 1 : 0,
+    (airpe->tech_pvt) ? switch_test_flag(airpe->tech_pvt, TFLAG_INBOUND) : -1,
+    (airpe->tech_pvt) ? switch_test_flag(airpe->tech_pvt, TFLAG_OUTBOUND): -1
+);
+*/
+
     if ( airpe->active_call_id && airpe->active_call_id != callid ) {
-ADEBUG("CASE 1 - different call\n");
 	if      ( !strncmp(status, "UNPLACED", strlen("UNPLACED")) ) {	    
 	    snprintf(buf, sizeof(buf), "SET CALL %d STATUS FINISHED", callid);
 	    airpe_cmd_write(airpe, buf);
@@ -375,102 +418,88 @@
 
     }
     else if ( airpe->active_call_id && airpe->active_call_id == callid ) {
-ADEBUG("CASE 2 - my call\n");
-	if ( airpe->tech_pvt ) {
-	    assert(airpe->tech_pvt);
-	    session = airpe->tech_pvt->session;
-	    assert(session);
-
-	    channel = switch_core_session_get_channel(session);
-    	    assert(channel);
-	}
-
 	if ( !strncmp(status, "ROUTING", strlen("ROUTING")) ) {
 	}
 	else if ( !strncmp(status, "RINGING", strlen("RINGING")) ) {
-	    //if ( switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ) {
-		//switch_channel_set_state(channel, CS_RINGING);
-	    switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
-	    switch_channel_mark_ring_ready(channel);
-	    //}
-
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d SET_INPUT PORT=\"%d\"", callid, airpe->audio_in_port);
-	    airpe_cmd_write(airpe, buf);
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d SET_OUTPUT PORT=\"%d\"", callid, airpe->audio_out_port);
-	    airpe_cmd_write(airpe, buf);
-
-
-
-	    switch_channel_set_state(channel, CS_ROUTING);
-
-	}
-	else if ( !strncmp(status, "INPROGRESS", strlen("INPROGRESS")) ) {
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d STOP_VIDEO_SEND", callid );
-	    airpe_cmd_write(airpe, buf);
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d STOP_VIDEO_RECEIVE", callid );
-	    airpe_cmd_write(airpe, buf);
-
-	    if ( channel ) {
-	        switch_channel_mark_answered(channel);
+	    if ( session && channel ) {
+		switch_channel_mark_ring_ready(channel);
 	    }
 	    else {
 		if ( airpe_manage_incoming_call(airpe, callid) != SWITCH_STATUS_SUCCESS ) {
 		    snprintf(buf, sizeof(buf), "ALTER CALL %d END HANGUP", callid );
 		    airpe_cmd_write(airpe, buf);
-		    airpe->active_call_id = 0;
+		    airpe_clear_call_id(airpe);
 		}
 	    }
 	}
+	else if ( !strncmp(status, "INPROGRESS", strlen("INPROGRESS")) ) {
+
+	    if ( channel && switch_test_flag(airpe->tech_pvt, TFLAG_OUTBOUND) ) {
+		snprintf(buf, sizeof(buf), "ALTER CALL %d SET_INPUT PORT=\"%d\"", callid, airpe->audio_in_port);
+		airpe_cmd_write(airpe, buf);
+		airpe_cmd_write(airpe, "PING");
+		snprintf(buf, sizeof(buf), "ALTER CALL %d SET_OUTPUT PORT=\"%d\"", callid, airpe->audio_out_port);
+		airpe_cmd_write(airpe, buf);
+		airpe_cmd_write(airpe, "PING");
+	        switch_set_flag(airpe->tech_pvt, TFLAG_IO);
+
+		snprintf(buf, sizeof(buf), "ALTER CALL %d STOP_VIDEO_SEND", callid );
+		airpe_cmd_write(airpe, buf);
+		snprintf(buf, sizeof(buf), "ALTER CALL %d STOP_VIDEO_RECEIVE", callid );
+		airpe_cmd_write(airpe, buf);
+
+	        switch_channel_answer(channel);
+	    }
+
+	}
 	else if ( !strncmp(status, "FINISHED", strlen("FINISHED")) ) {
 	    if ( channel )
 	        switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-	    airpe->active_call_id = 0;
+	    airpe_clear_call_id(airpe);
 	}
 	else if ( !strncmp(status, "FAILED", strlen("FAILED")) ) {
 	    if ( channel )
 	        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-	    airpe->active_call_id = 0;
+	    airpe_clear_call_id(airpe);
 	}
 	else if ( !strncmp(status, "CANCELLED", strlen("CANCELLED")) ) {
 	    if ( channel )
 	        switch_channel_hangup(channel, SWITCH_CAUSE_ORIGINATOR_CANCEL);
-	    airpe->active_call_id = 0;
+	    airpe_clear_call_id(airpe);
 	}
 	else if ( !strncmp(status, "REFUSED", strlen("REFUSED")) ) {
 	    if ( channel )
 	        switch_channel_hangup(channel, SWITCH_CAUSE_CALL_REJECTED);
-	    airpe->active_call_id = 0;
+	    airpe_clear_call_id(airpe);
 	}
 	else if ( !strncmp(status, "MISSED", strlen("MISSED")) ) {
 	    if ( channel )
 	        switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
-	    airpe->active_call_id = 0;
+	    airpe_clear_call_id(airpe);
 	}
 	else if ( !strncmp(status, "UNPLACED", strlen("UNPLACED")) ) {
 	}
 	else {
-ADEBUG("Unmanaged status \n");
+	    ADEBUG("Unmanaged status \n");
 	}
     }
     else {
-ADEBUG("CASE 3 - no calls online\n");
-	if      ( !strncmp(status, "UNPLACED", strlen("UNPLACED")) ) {	    
-	    airpe->active_call_id = callid;
-	}
-	else if ( !strncmp(status, "RINGING", strlen("RINGING")) ) {
-	    airpe->active_call_id = callid;
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d ANSWER", callid );
-	    airpe_cmd_write(airpe, buf);
+	if      ( !strncmp(status, "UNPLACED", strlen("UNPLACED")) ) {
+	    airpe_set_call_id(airpe, callid, NULL);
 	}
 	else {
 	    ADEBUG("--- (%d/%d) Unmanaged status %s\n", airpe->active_call_id, callid, status);
 	}
     }
 
+    if ( session ) 
+	switch_core_session_rwunlock(session);
+
     return SWITCH_STATUS_SUCCESS;
 }
 
 switch_status_t airpe_manage_skype_msg( airpe_interface_t *airpe, const char *msg ) {
+    switch_core_session_t *session = NULL;
     char *buf = NULL;
     int argc = 0;
     char *argv[9] = { 0 };
@@ -479,13 +508,16 @@
     assert(msg);
 
     if ( airpe->debug )
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "airpe client %s: %s\n", airpe->name, msg);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "airpe client %s: < %s\n", airpe->name, msg);
+
+    if ( airpe->active_session_uuid )
+	session = switch_core_session_locate(airpe->active_session_uuid);
 
     buf = strdup(msg);
     argc = switch_separate_string(buf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
-    if ( argc == 0 ) {
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "airpe client %s: %s - Message without arguments? uh?\n", airpe->name, msg);
+    if ( argc == 0  ) {
+	/* Empty message. Shit happens (TM) */
 	free(buf);
 	return  SWITCH_STATUS_FALSE;
     }
@@ -516,8 +548,14 @@
 	/* The connection status of the client (ex: ONLINE) */
 	airpe->conn_status = skype_conn_status( argv[1] );
     }
-    else if ( !strncmp( buf, "USER", strlen("USER")) ) {
-	/* Updates about the users of our list - ignored */
+    else if ( !strncmp( buf, "USER", strlen("USER")) && argc >= 2 ) {
+	/* Updates about the users of our list or new auth requests */
+	if ( !strncmp(argv[2], "RECEIVEDAUTHREQUEST", strlen("RECEIVEDAUTHREQUEST") ) ) {
+	    /* TODO add option to ignore such requests */
+	    char buf[SKYPE_MSG_LEN] = "";
+	    snprintf(buf, sizeof(buf), "SET USER %s ISAUTHORIZED TRUE", argv[1]);
+	    airpe_cmd_write(airpe, buf);
+	}
     }
     else if ( !strncmp( buf, "GROUP", strlen("GROUP")) ) {
 	/* Updates about the groups of our list - ignored */
@@ -531,7 +569,6 @@
     else if ( !strncmp( buf, "AUTOAWAY", strlen("AUTOAWAY")) ) {
 	/* Autoaway - ignored */
     }
-//TODO: RECEIVEDAUTHREQUEST - Add a config option to authorize or forget about it.
     else if ( !strncmp( buf, "MUTE", strlen("MUTE")) && argc >= 2 ) {
 	if ( !strncmp(argv[1], "ON", 2) ) { 
 	    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "airpe client %s: I don't like to be muted...\n", airpe->name);
@@ -598,11 +635,10 @@
 
 		snprintf(buf, sizeof(buf), "GET CALL %d PARTNER_DISPNAME", callid);
 		airpe_cmd_write(airpe, buf);
-
 		snprintf(buf, sizeof(buf), "GET CALL %d PARTNER_HANDLE", callid);
 		airpe_cmd_write(airpe, buf);
 
-		airpe_cmd_write(airpe, "PING");
+		airpe_set_call_id(airpe, callid, NULL);
 	    }
 	    else {
 		snprintf(buf, sizeof(buf), "ALTER CALL %d END HANGUP", callid );
@@ -614,30 +650,28 @@
 	}
 	else if ( !strncmp(cmd, "DTMF", strlen("DTMF")) ) {
 	    /* This is an incoming DTMF */
-	    switch_core_session_t *session;
-	    switch_channel_t *channel;
-	    switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
-	    const char *signal_ptr;
-	    int tmp;
-
-	    assert(airpe->tech_pvt);
-    	    session = airpe->tech_pvt->session;
-	    assert(session);
-	    channel = switch_core_session_get_channel(session);
-	    assert(channel);
-
-	    signal_ptr = argv[3];
+	    if ( session ) {
+	        switch_channel_t *channel;
+		switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
+	        const char *signal_ptr;
+		int tmp;
+
+    	        channel = switch_core_session_get_channel(session);
+		assert(channel);
+
+	        signal_ptr = argv[3];
+
+		if (*signal_ptr && (*signal_ptr == '*' || *signal_ptr == '#' || *signal_ptr == 'A' || *signal_ptr == 'B' || *signal_ptr == 'C' || *signal_ptr == 'D')) {
+		    dtmf.digit = *signal_ptr;
+	        } else {
+	    	    tmp = atoi(signal_ptr);
+	    	    dtmf.digit = switch_rfc2833_to_char(tmp);
+		}
 
-	    if (*signal_ptr && (*signal_ptr == '*' || *signal_ptr == '#' || *signal_ptr == 'A' || *signal_ptr == 'B' || *signal_ptr == 'C' || *signal_ptr == 'D')) {
-		dtmf.digit = *signal_ptr;
-	    } else {
-		tmp = atoi(signal_ptr);
-		dtmf.digit = switch_rfc2833_to_char(tmp);
+		switch_mutex_lock(airpe->tech_pvt->flag_mutex);
+	        switch_channel_queue_dtmf(channel, &dtmf);
+		switch_mutex_unlock(airpe->tech_pvt->flag_mutex);
 	    }
-
-	    switch_mutex_lock(airpe->tech_pvt->flag_mutex);
-	    switch_channel_queue_dtmf(channel, &dtmf);
-	    switch_mutex_unlock(airpe->tech_pvt->flag_mutex);
 	}
 	else if ( !strncmp(cmd, "FAILUREREASON", strlen("FAILUREREASON")) && argc >=2 ) {
 	    airpe->last_fail_reason = atoi(argv[1]);
@@ -706,6 +740,9 @@
 
     switch_safe_free(buf);
 
+    if ( session ) 
+	switch_core_session_rwunlock(session);
+
     return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/ctrix/mod_airpe/mod_airpe.c
==============================================================================
--- freeswitch/branches/ctrix/mod_airpe/mod_airpe.c	(original)
+++ freeswitch/branches/ctrix/mod_airpe/mod_airpe.c	Wed Jan 14 15:05:23 2009
@@ -196,7 +196,6 @@
     airpe_audio_sockets_create(airpe);
 
     switch_threadattr_create(&attr_skype, airpe_module_pool);
-    //switch_threadattr_detach_set(attr_skype, 1);
     switch_threadattr_stacksize_set(attr_skype, SWITCH_THREAD_STACKSIZE);
 
     switch_thread_create(&airpe->airpe_thread_skype, 
@@ -230,6 +229,7 @@
     airpe_set_mood_text(airpe, NULL);
     airpe_set_partner_displayname(airpe, NULL);
     airpe_set_partner_handle(airpe, NULL);
+    airpe_set_call_id(airpe, 0, NULL);
 
     return SWITCH_STATUS_SUCCESS;
 }
@@ -263,21 +263,12 @@
 	// TODO if fail switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
     }
 
-    if ( switch_test_flag(tech_pvt, TFLAG_INBOUND) ) {
-	char buf[SKYPE_MSG_LEN];
-	snprintf(buf, sizeof(buf), "ALTER CALL %d SET_INPUT PORT=\"%d\"", tech_pvt->airpe->active_call_id, tech_pvt->airpe->audio_in_port);
-	airpe_cmd_write(tech_pvt->airpe, buf);
-	snprintf(buf, sizeof(buf), "ALTER CALL %d SET_OUTPUT PORT=\"%d\"", tech_pvt->airpe->active_call_id, tech_pvt->airpe->audio_out_port);
-	airpe_cmd_write(tech_pvt->airpe, buf);
-
-        switch_channel_set_state(channel, CS_ROUTING);
-    }
+    switch_channel_set_state(channel, CS_ROUTING);
 
     return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t channel_on_routing(switch_core_session_t * session) {
-    char buf[SKYPE_MSG_LEN];
     switch_channel_t *channel = NULL;
     private_object_t *tech_pvt = NULL;
 
@@ -287,11 +278,6 @@
     tech_pvt = switch_core_session_get_private(session);
     assert(tech_pvt);
 
-    if ( switch_test_flag(tech_pvt, TFLAG_INBOUND) ) {
-        snprintf(buf, sizeof(buf), "ALTER CALL %d ANSWER", tech_pvt->airpe->active_call_id);
-        airpe_cmd_write(tech_pvt->airpe, buf);
-    }
-
     return SWITCH_STATUS_SUCCESS;
 }
 
@@ -313,7 +299,6 @@
     switch_channel_t *channel = NULL;
     private_object_t *tech_pvt = NULL;
     airpe_interface_t *airpe = NULL;
-    char msg[SKYPE_MSG_LEN];
 
     channel = switch_core_session_get_channel(session);
     assert(channel);
@@ -325,13 +310,11 @@
     assert(airpe);
 
     if ( airpe->active_call_id ) {
-	snprintf(msg, sizeof(msg), "ALTER CALL %d HANGUP", airpe->active_call_id);
-	airpe_cmd_write(airpe, msg);
-//	airpe->active_call_id = 0;
-//	airpe->tech_pvt = NULL;
+	char buf[SKYPE_MSG_LEN];
+	snprintf(buf, sizeof(buf), "ALTER CALL %d HANGUP", airpe->active_call_id);
+	airpe_cmd_write(airpe, buf);
     }
-
-    airpe_hangup( tech_pvt );
+    airpe_call_shutdown( tech_pvt );
 
     if (tech_pvt->read_codec.implementation) {
 	switch_core_codec_destroy(&tech_pvt->read_codec);
@@ -351,6 +334,7 @@
 /*****************************************************************************
     CHANNEL IO INTERFACE / ROUTINES
  *****************************************************************************/
+
 static switch_call_cause_t channel_outgoing_channel(
 		    switch_core_session_t 	*session,
                     switch_event_t 		*var_event,
@@ -422,9 +406,9 @@
 	    switch_core_session_destroy(new_session);
     	    return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	}
-
-	switch_channel_set_flag(channel, CF_OUTBOUND);	
-	switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
+	airpe_set_call_id(tech_pvt->airpe, 0, switch_core_session_get_uuid(*new_session) );
+	switch_channel_set_flag(channel, CF_OUTBOUND);
+	switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
 	switch_channel_set_state(channel, CS_INIT);
 	return SWITCH_CAUSE_SUCCESS;
     }
@@ -453,7 +437,10 @@
     *frame = NULL;
 
     if ( airpe_audio_read(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-	ADEBUG("airpe_audio_read ERROR\n");
+/*
+	if ( tech_pvt->airpe->debug )
+	    ADEBUG("airpe_audio_read ERROR\n");
+*/
 	return SWITCH_STATUS_FALSE;
     }
 
@@ -492,12 +479,19 @@
     assert(tech_pvt);
 
     if ( !tech_pvt->airpe ) {
+	ADEBUG("airpe_audio_write ERROR: no client\n");
 	return SWITCH_STATUS_FALSE;
     }
 
     airpe = tech_pvt->airpe;
 
     rv = airpe_audio_write(tech_pvt, frame);
+
+    if ( rv != SWITCH_STATUS_SUCCESS ) {
+	ADEBUG("airpe_audio_write ERROR\n");
+	return SWITCH_STATUS_FALSE;
+    }
+
     return rv;
 }
 
@@ -546,6 +540,7 @@
 {
     switch_channel_t *channel;
     private_object_t *tech_pvt;
+    airpe_interface_t *airpe;
 
     channel = switch_core_session_get_channel(session);
     assert(channel);
@@ -553,30 +548,57 @@
     tech_pvt = (private_object_t *) switch_core_session_get_private(session);
     assert(tech_pvt);
 
+    airpe = tech_pvt->airpe;
+    assert(airpe);
+
     switch (msg->message_id) {
 	case SWITCH_MESSAGE_INDICATE_ANSWER:
-	    ADEBUG("received message indicate answer...\n");
 /*
-    	    //switch_answer_channel(session);
-	    char buf[SKYPE_MSG_LEN];
-	    snprintf(buf, sizeof(buf), "ALTER CALL %d ANSWER", tech_pvt->airpe->active_call_id );
-	    airpe_cmd_write(tech_pvt->airpe, buf);
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate answer...\n");
 */
+	    if ( switch_test_flag(tech_pvt, TFLAG_INBOUND) ) {
+	        char buf[SKYPE_MSG_LEN];
+	        snprintf(buf, sizeof(buf), "ALTER CALL %d ANSWER\n", tech_pvt->airpe->active_call_id );
+		airpe_cmd_write(tech_pvt->airpe, buf);
+		snprintf(buf, sizeof(buf), "ALTER CALL %d SET_INPUT PORT=\"%d\"", tech_pvt->airpe->active_call_id, tech_pvt->airpe->audio_in_port);
+		airpe_cmd_write(tech_pvt->airpe, buf);
+		snprintf(buf, sizeof(buf), "ALTER CALL %d SET_OUTPUT PORT=\"%d\"", tech_pvt->airpe->active_call_id, tech_pvt->airpe->audio_out_port);
+		airpe_cmd_write(tech_pvt->airpe, buf);
+	        switch_set_flag(tech_pvt, TFLAG_IO);
+	    }
+	    break;
+/*
+	case SWITCH_MESSAGE_INDICATE_PROGRESS:
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate progress...\n");
+	    break;
+	case SWITCH_MESSAGE_INDICATE_BRIDGE:
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate bridge...\n");
 	    break;
 	case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
-	    ADEBUG("received message indicate unbridge...\n");
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate unbridge...\n");
 	    break;
 	case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
-	    ADEBUG("received message indicate transcode necessary...\n");
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate transcode necessary...\n");
 	    break;
 	case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
-	    ADEBUG("received message indicate audio sync...\n");
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate audio sync...\n");
 	    break;
 	case SWITCH_MESSAGE_INDICATE_TRANSFER:
-	    ADEBUG("received message indicate transfer...\n");
+	    if ( airpe->debug ) 
+		ADEBUG("received message indicate transfer...\n");
 	    break;
+*/
 	default:
-	    ADEBUG("Unmanaged received message... %d\n", msg->message_id);
+/*
+	    if ( airpe->debug ) 
+		ADEBUG("Unmanaged received message... %d\n", msg->message_id);
+*/
 	    break;
     }
 
@@ -596,7 +618,6 @@
     assert(tech_pvt);
 
     body = switch_event_get_body(event);
-
     if (!body) {
 	body = "";
     }

Modified: freeswitch/branches/ctrix/mod_airpe/mod_airpe.h
==============================================================================
--- freeswitch/branches/ctrix/mod_airpe/mod_airpe.h	(original)
+++ freeswitch/branches/ctrix/mod_airpe/mod_airpe.h	Wed Jan 14 15:05:23 2009
@@ -112,15 +112,15 @@
 typedef enum {
   TFLAG_INBOUND 	= (1 << 1),
   TFLAG_OUTBOUND	= (1 << 2),
+  TFLAG_IO 		= (1 << 3),
 /*
-  TFLAG_IO 		= (1 << 0),
-  TFLAG_DTMF 		= (1 << 3),
   TFLAG_VOICE 		= (1 << 4),
-  TFLAG_HANGUP 		= (1 << 5),
-  TFLAG_LINEAR 		= (1 << 6),
-  TFLAG_CODEC 		= (1 << 7),
-  TFLAG_BREAK 		= (1 << 8),
-  TFLAG_ANSWER 		= (1 << 9)
+  TFLAG_DTMF 		= (1 << 5),
+  TFLAG_HANGUP 		= (1 << 6),
+  TFLAG_LINEAR 		= (1 << 7),
+  TFLAG_CODEC 		= (1 << 8),
+  TFLAG_BREAK 		= (1 << 9),
+  TFLAG_ANSWER 		= (1 <<10)
 */
 } TFLAGS;
 
@@ -157,6 +157,7 @@
     char			*skype_version;
     char			*mood_text;
     int 			active_call_id;
+    char 			*active_session_uuid;
     int				last_fail_reason;
     int				running;
     private_object_t		*tech_pvt;
@@ -202,8 +203,9 @@
 switch_status_t	airpe_set_mood_text(airpe_interface_t *airpe, char *string);
 switch_status_t	airpe_set_partner_displayname(airpe_interface_t *airpe, char *string);
 switch_status_t	airpe_set_partner_handle(airpe_interface_t *airpe, char *string);
+switch_status_t	airpe_set_call_id(airpe_interface_t *airpe, int sk_id, char *fs_uuid);
 
-switch_status_t airpe_hangup( private_object_t *pvt );
+switch_status_t airpe_call_shutdown( private_object_t *pvt );
 switch_status_t airpe_audio_read( private_object_t *pvt );
 switch_status_t airpe_audio_write( private_object_t *pvt, switch_frame_t *frame );
 



More information about the Freeswitch-branches mailing list