[Freeswitch-svn] [commit] r11208 - freeswitch/branches/ctrix/mod_airpe

FreeSWITCH SVN ctrix at freeswitch.org
Wed Jan 14 17:09:36 PST 2009


Author: ctrix
Date: Wed Jan 14 19:09:35 2009
New Revision: 11208

Log:
An application, some events and some channel variables.



Modified:
   freeswitch/branches/ctrix/mod_airpe/airpe_api.c
   freeswitch/branches/ctrix/mod_airpe/airpe_apps.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 19:09:35 2009
@@ -37,7 +37,7 @@
 */
 
 
-#define AIRPE_MOODTEXT_SYNTAX "airpe_moodtext <clientname> <text>"
+#define AIRPE_MOODTEXT_SYNTAX "airpe_moodtext <clientname> [text]"
 SWITCH_STANDARD_API(airpe_moodtext_command)
 {
     int argc = 0;
@@ -67,11 +67,10 @@
     } 
 
     if ( argc == 1 ) {
-        stream->write_function(stream, "+OK: ");
 	if ( airpe->mood_text )
 	    stream->write_function(stream, airpe->mood_text);
 	else
-	    stream->write_function(stream, "UNKNOWN");
+	    stream->write_function(stream, "[UNKNOWN]");
 	stream->write_function(stream, "\n");
     }
     else {
@@ -91,7 +90,7 @@
     return SWITCH_STATUS_SUCCESS;
 }
 
-#define AIRPE_INFO_SYNTAX "airpe_status <clientname>"
+#define AIRPE_INFO_SYNTAX "airpe_info <clientname>"
 SWITCH_STANDARD_API(airpe_info_command)
 {
     int argc = 0;
@@ -161,7 +160,7 @@
     return SWITCH_STATUS_SUCCESS;
 }
 
-#define AIRPE_STATUS_SYNTAX "airpe_status <clientname> <status>"
+#define AIRPE_STATUS_SYNTAX "airpe_status <clientname> [status]"
 SWITCH_STANDARD_API(airpe_status_command)
 {
     int argc = 0;
@@ -197,7 +196,6 @@
     if ( !cstatus ) {
 	const char *str_status = NULL;
 	str_status = skype_user_status_string( airpe->user_status );
-	stream->write_function(stream, "+OK status is ");
 	if ( str_status )
 	    stream->write_function(stream, str_status);
 	else
@@ -251,13 +249,13 @@
     switch_api_interface_t *api;
 
     switch_console_set_complete("add airpe_moodtext ");
-    SWITCH_ADD_API(api, "airpe_moodtext", "sets the mood text of an airpe client", airpe_moodtext_command, AIRPE_MOODTEXT_SYNTAX);
+    SWITCH_ADD_API(api, "airpe_moodtext", "gets/sets the mood text of an airpe client", airpe_moodtext_command, AIRPE_MOODTEXT_SYNTAX);
 
     switch_console_set_complete("add airpe_info ");
     SWITCH_ADD_API(api, "airpe_info", "shows the status of an airpe client", airpe_info_command, AIRPE_INFO_SYNTAX);
 
     switch_console_set_complete("add airpe_status ");
-    SWITCH_ADD_API(api, "airpe_status", "sets the status of an airpe client", airpe_status_command, AIRPE_STATUS_SYNTAX);
+    SWITCH_ADD_API(api, "airpe_status", "gets/sets the status of an airpe client", airpe_status_command, AIRPE_STATUS_SYNTAX);
 
     return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/branches/ctrix/mod_airpe/airpe_apps.c
==============================================================================
--- freeswitch/branches/ctrix/mod_airpe/airpe_apps.c	(original)
+++ freeswitch/branches/ctrix/mod_airpe/airpe_apps.c	Wed Jan 14 19:09:35 2009
@@ -30,15 +30,67 @@
 
 #include "mod_airpe.h"
 
-SWITCH_STANDARD_APP(airpe_app_test) 
+#define AIRPE_SET_STATUS_SYNTAX "<client> <unknown|online|offline|skyoeme|away|na|dnd|invisible|loggedout>"
+SWITCH_STANDARD_APP(airpe_set_status)
 {
+    airpe_interface_t *airpe = NULL;
+    const char *str_status = NULL;
+    char buf[SKYPE_MSG_LEN];
+    char *client = NULL;
+    char *text = NULL;
+
+    client = (char *) data;
+    if ( (text = strchr(client,' ')) ) {
+	*text++ = '\0';
+    }
+
+    if ( switch_strlen_zero(client) ) {
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No client specified.\n");
+	return;
+    }
+
+    airpe = airpe_find_interface(client);
+
+    if ( !airpe ) {
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No airpe client matching name '%s' found.\n", client);
+	return;
+    }
+
+    if ( !switch_strlen_zero(text) ) {
+
+	if      ( !strncasecmp(text, "unknown", sizeof("unknown") ) )
+	    str_status = skype_user_status_string(USER_STATUS_UNKNOWN);
+	else if ( !strncasecmp(text, "online", sizeof("online") ) )
+	    str_status = skype_user_status_string(USER_STATUS_ONLINE);
+	else if ( !strncasecmp(text, "offline", sizeof("offline") ) )
+	    str_status = skype_user_status_string(USER_STATUS_OFFLINE);
+	else if ( !strncasecmp(text, "skypeme", sizeof("skypeme") ) )
+	    str_status = skype_user_status_string(USER_STATUS_SKYPEME);
+	else if ( !strncasecmp(text, "away", sizeof("away") ) )
+	    str_status = skype_user_status_string(USER_STATUS_AWAY);
+	else if ( !strncasecmp(text, "na", sizeof("na") ) )
+	    str_status = skype_user_status_string(USER_STATUS_NA);
+	else if ( !strncasecmp(text, "dnd", sizeof("dnd") ) )
+	    str_status = skype_user_status_string(USER_STATUS_DND);
+	else if ( !strncasecmp(text, "invisible", sizeof("invisible") ) )
+	    str_status = skype_user_status_string(USER_STATUS_INVISIBLE);
+	else if ( !strncasecmp(text, "loggedout", sizeof("loggedout") ) )
+	    str_status = skype_user_status_string(USER_STATUS_LOGGEDOUT);
+
+	if ( str_status ) {
+	    snprintf(buf, SKYPE_MSG_LEN, "SET USERSTATUS %s", str_status );
+	    airpe_cmd_write(airpe, buf);
+	}
+
+    }
+
 }
 
 
 switch_status_t airpe_register_apps( switch_loadable_module_interface_t **module_interface ) {
     switch_application_interface_t *app_interface;
 
-    SWITCH_ADD_APP(app_interface, "airpe_test", "test text", "test text", airpe_app_test, "", SAF_SUPPORT_NOMEDIA);
+    SWITCH_ADD_APP(app_interface, "airpe_set_status", "Sets the status of an airpe client", "Sets the status of an airpe client", airpe_set_status, AIRPE_SET_STATUS_SYNTAX, SAF_SUPPORT_NOMEDIA);
 
     return SWITCH_STATUS_SUCCESS;
 }

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 19:09:35 2009
@@ -373,6 +373,8 @@
     else
 	switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 
+    switch_channel_set_variable(channel, "airpe_client", airpe->name);
+    switch_channel_set_variable(channel, "airpe_user_status", skype_user_status_string(airpe->user_status) );
 
     switch_set_flag(tech_pvt, TFLAG_INBOUND);
     airpe_set_call_id(airpe, callid, switch_core_session_get_uuid(new_session) );
@@ -502,6 +504,8 @@
 
 switch_status_t airpe_manage_skype_msg( airpe_interface_t *airpe, const char *msg ) {
     switch_core_session_t *session = NULL;
+    switch_channel_t *channel = NULL;
+    switch_event_t *s_event = NULL;
     char *buf = NULL;
     int argc = 0;
     char *argv[9] = { 0 };
@@ -512,8 +516,11 @@
     if ( airpe->debug )
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "airpe client %s: < %s\n", airpe->name, msg);
 
-    if ( airpe->active_session_uuid )
+    if ( airpe->active_session_uuid ) {
 	session = switch_core_session_locate(airpe->active_session_uuid);
+	if ( session )
+	    channel = switch_core_session_get_channel(session);
+    }
 
     buf = strdup(msg);
     argc = switch_separate_string(buf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -524,8 +531,6 @@
 	return  SWITCH_STATUS_FALSE;
     }
 
-
-
     if      ( !strncmp( buf, "CURRENTUSERHANDLE", strlen("CURRENTUSERHANDLE")) ) {
 	/* The username that the client is using. */
 	// TODO ... if the user handle mismatches, disconnect the channel or simply disable
@@ -553,9 +558,16 @@
     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") ) ) {
+	    if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, AIRPE_EVENT_AUTHREQUEST) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "client-name", airpe->name);
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "auth_user", argv[1]);
+		switch_event_fire(&s_event);
+	    }
 	    if ( airpe->auto_auth ) {
 		snprintf(buf, sizeof(buf), "SET USER %s ISAUTHORIZED TRUE", argv[1]);
 		airpe_cmd_write(airpe, buf);
+
+
 	    }
 	}
     }
@@ -627,6 +639,11 @@
 	else if ( !strncmp(cmd, "STATUS", strlen("STATUS")) && argc >=4 ) {
 	    char *callstatus = argv[3];
 	    airpe_manage_call_status( airpe, callid, callstatus );
+	    if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, AIRPE_EVENT_STATUSCHANGE) == SWITCH_STATUS_SUCCESS) {
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "client-name", airpe->name);
+		switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", callstatus);
+		switch_event_fire(&s_event);
+	    }
 	}
 	else if ( !strncmp(cmd, "CONF_ID", strlen("CONF_ID")) ) {
 	    char buf[SKYPE_MSG_LEN];
@@ -652,15 +669,11 @@
 	}
 	else if ( !strncmp(cmd, "DTMF", strlen("DTMF")) ) {
 	    /* This is an incoming DTMF */
-	    if ( session ) {
-	        switch_channel_t *channel;
+	    if ( session && 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')) {
@@ -670,9 +683,7 @@
 	    	    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);
 	    }
 	}
 	else if ( !strncmp(cmd, "FAILUREREASON", strlen("FAILUREREASON")) && argc >=2 ) {
@@ -698,6 +709,8 @@
 		if ( data ) {
 		    data += strlen("PARTNER_DISPNAME ");
 		    airpe_set_partner_displayname(airpe, data);
+		    if ( channel )
+		        switch_channel_set_variable(channel, "airpe_partner_dispname", data);
 		}
 	    }
 	    switch_safe_free(tmp);
@@ -710,6 +723,8 @@
 		if ( data ) {
 		    data += strlen("PARTNER_HANDLE ");
 		    airpe_set_partner_handle(airpe, data);
+		    if ( channel )
+		        switch_channel_set_variable(channel, "airpe_partner_handle", data);
 		}
 		switch_safe_free(tmp);
 	    }
@@ -735,10 +750,13 @@
     }
     else if ( !strncmp( buf, "ERROR", strlen("ERROR")) ) {
 	/* If we are in the middle of a call, hangup */
+	/*
 	if ( airpe->active_call_id ) {
+	    char buf[SKYPE_MSG_LEN] = "";
 	    snprintf(buf, sizeof(buf), "ALTER CALL %d END HANGUP", airpe->active_call_id );
 	    airpe_cmd_write(airpe, buf);
 	}
+	*/
     }
     else {
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unmanaged message\n");

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 19:09:35 2009
@@ -408,6 +408,10 @@
 	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_variable(channel, "airpe_client", tech_pvt->airpe->name);
+	switch_channel_set_variable(channel, "airpe_user_status", skype_user_status_string(tech_pvt->airpe->user_status) );
+
 	switch_channel_set_state(channel, CS_INIT);
 	return SWITCH_CAUSE_SUCCESS;
     }

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 19:09:35 2009
@@ -33,6 +33,9 @@
 
 #define MODNAME "airpe"
 
+#define AIRPE_EVENT_AUTHREQUEST "airpe::authrequest"
+#define AIRPE_EVENT_STATUSCHANGE "airpe::statuschange"
+
 #define SKYPE_MSG_LEN	1024
 
 #define CODEC_SAMPLE_RATE	16000



More information about the Freeswitch-svn mailing list