From c64813f4fde4f5b99d8ee7cd22a3b1e17206babe Mon Sep 17 00:00:00 2001
From: Giovanni Maruzzelli <gmaruzz@gmail.com>
Date: Fri, 4 May 2012 16:31:17 +0200
Subject: [PATCH] skypopen: mod_sms hookup, is flawed, because it needs to CHAT
 CREATE, then read back the DIALOG. It will have to be spun as a separate
 thread, but is here as a proof of concept. I disable it right now

---
 src/mod/endpoints/mod_skypopen/mod_skypopen.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c
index 159840f5e4..4e6fec15f7 100644
--- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c
+++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c
@@ -1957,6 +1957,7 @@ static switch_status_t chat_send(switch_event_t *message_event)
 
 		while (!found) {
 			for (i = 0; i < MAX_CHATS; i++) {
+				//DEBUGA_SKYPE("tech_pvt->chats[i].dialog_partner='%s' to='%s'\n", SKYPOPEN_P_LOG, tech_pvt->chats[i].dialog_partner, to);
 				if (!strcmp(tech_pvt->chats[i].dialog_partner, to)) {
 					snprintf(skype_msg, sizeof(skype_msg), "CHATMESSAGE %s %s", tech_pvt->chats[i].chatname, body);
 					skypopen_signaling_write(tech_pvt, skype_msg);
@@ -1969,7 +1970,7 @@ static switch_status_t chat_send(switch_event_t *message_event)
 			}
 			tried++;
 			if (tried > 20) {
-				ERRORA("No chat with dialog_partner='%s' was found\n", SKYPOPEN_P_LOG, to);
+				ERRORA("No chat with dialog_partner='%s' was found. (If you're using mod_sms this is a bug of mod_skypopen when using mod_sms, from next incoming message it will probably work...)\n", SKYPOPEN_P_LOG, to);
 				break;
 			}
 			switch_sleep(50000);
@@ -2966,12 +2967,24 @@ int incoming_chatmessage(private_t *tech_pvt, int which)
 	if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SKYPE_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, "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);
+/* mod_sms begin */
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", tech_pvt->skype_user);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", tech_pvt->name);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_proto", SKYPE_CHAT_PROTO);
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", tech_pvt->chatmessages[which].from_handle);
+                //switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", "from_host");
+                //switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_full", "from_full");
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_user", tech_pvt->name);
+                //switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_host", "to_host");
+/* mod_sms end */
+
 		switch_event_add_body(event, "%s", tech_pvt->chatmessages[which].body);
+                switch_core_chat_send("GLOBAL", event); /* mod_sms */
 		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) {