]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
skypiax: now incoming CHATMESSAGE is transformed into a MESSAGE event, and sent to...
authorGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 15 Sep 2009 19:41:22 +0000 (19:41 +0000)
committerGiovanni Maruzzelli <gmaruzz@gmail.com>
Tue, 15 Sep 2009 19:41:22 +0000 (19:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14876 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_skypiax/skypiax_protocol.c

index 25aecf1248957c644efbbdf3ec2d725eae0e8cf8..249b33d028b1bca95d39d635e5db48f214a9165d 100644 (file)
@@ -35,6 +35,7 @@
  */
 
 #include "skypiax.h"
+#define MDL_CHAT_PROTO "skype"
 
 #ifdef WIN32
 /***************/
@@ -2236,26 +2237,67 @@ int skypiax_transfer(private_t * tech_pvt, char *id, char *value)
 
 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]) );
-        }
+       switch_event_t *event;
+       switch_core_session_t *session = NULL;
+       int event_sent_to_esl = 0;
+
+       DEBUGA_SKYPE("received CHATMESSAGE on interface %s\n", SKYPIAX_P_LOG, tech_pvt->name);
+
+       if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
+               session = switch_core_session_locate(tech_pvt->session_uuid_str);
+       }
+       if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", tech_pvt->name);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->chatmessages[which].from_dispname);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->chatmessages[which].from_handle);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);
+               switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body);
+               if(session){
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true");
+                       if (switch_core_session_queue_event(session, &event) != SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
+                               switch_event_fire(&event);
+                       }
+               } else { //no session
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false");
+                       switch_event_fire(&event);
+                       event_sent_to_esl=1;
+               }
+
+       }else{
+               ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name);
+       }
+
+       if(!event_sent_to_esl){
+
+               if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", tech_pvt->name);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->chatmessages[which].from_dispname);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->chatmessages[which].from_handle);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "chatname", tech_pvt->chatmessages[which].chatname);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "id", tech_pvt->chatmessages[which].id);
+                       switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body);
+                       if(session){
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true");
+                       } else { //no session
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "false");
+                       }
+                       switch_event_fire(&event);
+               } else{
+                       ERRORA("cannot create event on interface %s. WHY?????\n", SKYPIAX_P_LOG, tech_pvt->name);
+               }
+       }
 
-        return 0;
+       if(session){
+               switch_core_session_rwunlock(session);
+       }
+       memset(&tech_pvt->chatmessages[which], '\0', sizeof(&tech_pvt->chatmessages[which]) );
+       return 0;
 }
 
 
index 7ac3b466d948e7e43074b16c6ab08e68944c7ade..d7da86e88b6f57a1f4420f4e7e9cbf38eeac9f86 100644 (file)
@@ -365,7 +365,7 @@ int skypiax_signaling_read(private_t * tech_pvt)
                                        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);
+                                               DEBUGA_SKYPE("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);
                                        }