Revision
14845
Author
gmaruzz
Date
2009-09-14 13:02:05 -0500 (Mon, 14 Sep 2009)

Log Message

skypiax: fires a custom event when an incoming CHATMESSAGE arrives. In the headers are chatmessage id, chatname, from_handle, from_dispname. You want to answer to from_handle. In the body of the event is the chatmessage body. Heh

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14844 => 14845)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-09-14 15:19:53 UTC (rev 14844)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-09-14 18:02:05 UTC (rev 14845)
@@ -1410,6 +1410,11 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
+        if (switch_event_reserve_subclass(MY_EVENT_INCOMING_CHATMESSAGE) != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
+                return SWITCH_STATUS_GENERR;
+        }
+
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
 	skypiax_endpoint_interface->interface_name = "skypiax";
@@ -1501,6 +1506,8 @@
 		}
 
 	}
+        switch_event_free_subclass(MY_EVENT_INCOMING_CHATMESSAGE);
+
 	switch_safe_free(globals.dialplan);
 	switch_safe_free(globals.context);
 	switch_safe_free(globals.destination);
@@ -2145,6 +2152,31 @@
 	return 0;
 }
 
+int incoming_chatmessage(private_t * tech_pvt, int which)
+{
+        char event_info[512];
+        switch_event_t *event;
+
+        DEBUGA_SKYPE("received CHATMESSAGE on interface %s\n", SKYPIAX_P_LOG, tech_pvt->name);
+
+        switch_snprintf(event_info, sizeof(event_info), "incoming CHATMESSAGE on %s\n", tech_pvt->name);
+
+        if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_INCOMING_CHATMESSAGE) == SWITCH_STATUS_SUCCESS) {
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_info", event_info);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "interface_name", tech_pvt->name);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_handle", tech_pvt->chatmessages[which].from_handle);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_dispname", tech_pvt->chatmessages[which].from_dispname);
+                switch_event_add_body(event, "%s\n\n", tech_pvt->chatmessages[which].body);
+                switch_event_fire(&event);
+		memset(&tech_pvt->chatmessages[which], '\0', sizeof(&tech_pvt->chatmessages[which]) );
+        }
+
+        return 0;
+}
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h (14844 => 14845)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2009-09-14 15:19:53 UTC (rev 14844)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2009-09-14 18:02:05 UTC (rev 14845)
@@ -50,6 +50,8 @@
 #pragma warning(disable:4127)
 #endif
 
+#define MY_EVENT_INCOMING_CHATMESSAGE "skypiax::incoming_chatmessage"
+
 #define SAMPLERATE_SKYPIAX 16000
 #define SAMPLES_PER_FRAME SAMPLERATE_SKYPIAX/50
 
@@ -159,9 +161,19 @@
 	int api_connected;
 	switch_file_t *fdesc[2];
 };
-
 #endif //WIN32
 
+#define MAX_CHATMESSAGES 10
+
+struct chatmessage {
+	char id[256];
+	char type[256];
+	char chatname[256];
+	char from_handle[256];
+	char from_dispname[256];
+	char body[512];
+};
+typedef struct chatmessage chatmessage_t;
 struct private_object {
 	unsigned int flags;
 	switch_codec_t read_codec;
@@ -247,6 +259,8 @@
 	uint32_t ob_calls;
 	uint32_t ib_failed_calls;
 	uint32_t ob_failed_calls;
+
+	chatmessage_t chatmessages[MAX_CHATMESSAGES];
 };
 
 typedef struct private_object private_t;
@@ -293,3 +307,4 @@
 #else
 int skypiax_socket_create_and_bind(private_t * tech_pvt, unsigned short *which_port);
 #endif //WIN32
+int incoming_chatmessage(private_t * tech_pvt, int which);

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14844 => 14845)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-09-14 15:19:53 UTC (rev 14844)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-09-14 18:02:05 UTC (rev 14845)
@@ -222,6 +222,123 @@
 					skypiax_signaling_write(tech_pvt, msg_to_skype);
 				}
 			}
+			if (!strcasecmp(message, "CHATMESSAGE")) {
+				char msg_to_skype[256];
+				int i;
+				int found;
+
+				skypiax_strncpy(obj, where, sizeof(obj) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(id, where, sizeof(id) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(prop, where, sizeof(prop) - 1);
+				//where = strsep(stringp, " ");
+				skypiax_strncpy(value, *stringp, sizeof(value) - 1);
+				//where = strsep(stringp, " ");
+
+				//ERRORA ("Skype MSG, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n", SKYPIAX_P_LOG, obj, id, prop, value, where ? where : "NULL");
+
+				if (!strcasecmp(prop, "STATUS") && !strcasecmp(value, "RECEIVED")) {
+					NOTICA("RECEIVED CHATMESSAGE %s, let's see which type it is\n", SKYPIAX_P_LOG, id);
+					sprintf(msg_to_skype, "GET CHATMESSAGE %s TYPE", id);
+					skypiax_signaling_write(tech_pvt, msg_to_skype);
+				}
+
+				if (!strcasecmp(prop, "TYPE") && !strcasecmp(value, "SAID")) {
+					NOTICA("CHATMESSAGE %s is of type SAID, let's get the other infos\n", SKYPIAX_P_LOG, id);
+					found=0;
+					for(i=0; i<MAX_CHATMESSAGES; i++){
+						if(strlen(tech_pvt->chatmessages[i].id) == 0){
+							strncpy(tech_pvt->chatmessages[i].id, id, sizeof(tech_pvt->chatmessages[i].id));
+							strncpy(tech_pvt->chatmessages[i].type, value, sizeof(tech_pvt->chatmessages[i].type));
+							found=1;
+							break;
+						}
+					}
+					if(!found){
+						ERRORA("why we do not have a chatmessages slot free? we have more than %d chatmessages in parallel?\n", SKYPIAX_P_LOG, MAX_CHATMESSAGES);
+					} else {
+						NOTICA("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id);
+						sprintf(msg_to_skype, "GET CHATMESSAGE %s CHATNAME", id);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+						skypiax_sleep(100);
+						sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_HANDLE", id);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+						skypiax_sleep(100);
+						sprintf(msg_to_skype, "GET CHATMESSAGE %s FROM_DISPNAME", id);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+						skypiax_sleep(100);
+						sprintf(msg_to_skype, "GET CHATMESSAGE %s BODY", id);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+					}
+				}
+
+				if (!strcasecmp(prop, "CHATNAME")) {
+					NOTICA("CHATMESSAGE %s belongs to the CHAT %s\n", SKYPIAX_P_LOG, id, value);
+					found=0;
+					for(i=0; i<MAX_CHATMESSAGES; i++){
+						if(!strcmp(tech_pvt->chatmessages[i].id, id)){
+							strncpy(tech_pvt->chatmessages[i].chatname, value, sizeof(tech_pvt->chatmessages[i].chatname));
+							found=1;
+							break;
+						}
+					}
+					if(!found){
+						ERRORA("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
+					} 
+				}
+				if (!strcasecmp(prop, "FROM_HANDLE")) {
+					NOTICA("CHATMESSAGE %s was sent by FROM_HANDLE %s\n", SKYPIAX_P_LOG, id, value);
+					found=0;
+					for(i=0; i<MAX_CHATMESSAGES; i++){
+						if(!strcmp(tech_pvt->chatmessages[i].id, id)){
+							strncpy(tech_pvt->chatmessages[i].from_handle, value, sizeof(tech_pvt->chatmessages[i].from_handle));
+							found=1;
+							break;
+						}
+					}
+					if(!found){
+						ERRORA("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
+					} 
+
+				}
+				if (!strcasecmp(prop, "FROM_DISPNAME")) {
+					NOTICA("CHATMESSAGE %s was sent by FROM_DISPNAME %s\n", SKYPIAX_P_LOG, id, value);
+					found=0;
+					for(i=0; i<MAX_CHATMESSAGES; i++){
+						if(!strcmp(tech_pvt->chatmessages[i].id, id)){
+							strncpy(tech_pvt->chatmessages[i].from_dispname, value, sizeof(tech_pvt->chatmessages[i].from_dispname));
+							found=1;
+							break;
+						}
+					}
+					if(!found){
+						ERRORA("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
+					} 
+
+				}
+				if (!strcasecmp(prop, "BODY")) {
+					NOTICA("CHATMESSAGE %s has BODY %s\n", SKYPIAX_P_LOG, id, value);
+					found=0;
+					for(i=0; i<MAX_CHATMESSAGES; i++){
+						if(!strcmp(tech_pvt->chatmessages[i].id, id)){
+							strncpy(tech_pvt->chatmessages[i].body, value, sizeof(tech_pvt->chatmessages[i].body));
+							found=1;
+							break;
+						}
+					}
+					if(!found){
+						ERRORA("why chatmessage %s was not found in the chatmessages array??\n", SKYPIAX_P_LOG, id);
+					}else {
+						ERRORA("CHATMESSAGE %s is in position %d in the chatmessages array, type=%s, id=%s, chatname=%s, from_handle=%s, from_dispname=%s, body=%s\n", SKYPIAX_P_LOG, id, i, tech_pvt->chatmessages[i].type, tech_pvt->chatmessages[i].id, tech_pvt->chatmessages[i].chatname, tech_pvt->chatmessages[i].from_handle, tech_pvt->chatmessages[i].from_dispname, tech_pvt->chatmessages[i].body);
+						incoming_chatmessage(tech_pvt, i);
+					}
+
+				}
+
+			}
+
+
 			if (!strcasecmp(message, "CALL")) {
 				skypiax_strncpy(obj, where, sizeof(obj) - 1);
 				where = strsep(stringp, " ");
@@ -238,7 +355,6 @@
 
 				if (!strcasecmp(prop, "PARTNER_HANDLE")) {
 					if (tech_pvt->interface_state != SKYPIAX_STATE_SELECTED && (!strlen(tech_pvt->skype_call_id) || !strlen(tech_pvt->session_uuid_str))) {
-						//if (!strlen(tech_pvt->skype_call_id)) {
 						/* we are NOT inside an active call */
 						DEBUGA_SKYPE("Call %s TRY ANSWER\n", SKYPIAX_P_LOG, id);
 						skypiax_answer(tech_pvt, id, value);