Revision
14995
Author
gmaruzz
Date
2009-09-26 17:54:11 -0500 (Sat, 26 Sep 2009)

Log Message

celliax: incoming SMS now generates a correct event, with additional headers: proto, login, from, date, subject, during-call and a body containing the SMS body. Only the raw fields that are in ucs2 are decoded to utf8 (eg: sender and body)

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14994 => 14995)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-09-26 19:36:58 UTC (rev 14994)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-09-26 22:54:11 UTC (rev 14995)
@@ -398,6 +398,9 @@
 	int unread_sms_msg_id;
 	int reading_sms_msg;
 	char sms_message[4800];
+	char sms_sender[256];
+	char sms_date[256];
+	char sms_body[4800];
 	int sms_cnmi_not_supported;
 	char sms_receiving_program[256];
 

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14994 => 14995)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-09-26 19:36:58 UTC (rev 14994)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-09-26 22:54:11 UTC (rev 14995)
@@ -927,7 +927,7 @@
 								char *arg1[] = { tech_pvt->sms_receiving_program, (char *) NULL };
 								int i;
 
-								NOTICA("incoming SMS message:>>>%s<<<\n", CELLIAX_P_LOG, tech_pvt->sms_message);
+								DEBUGA_CELLIAX("incoming SMS message:>>>%s<<<\n", CELLIAX_P_LOG, tech_pvt->sms_message);
 								res=pipe(fd1);
 								pid1 = fork();
 
@@ -1321,7 +1321,7 @@
 			if (tech_pvt->reading_sms_msg > 1 && at_ack == -1) {
 				int c;
 				char sms_body[16000];
-				int err;
+				int err=0;
 
 				if (strncmp(tech_pvt->line_array.result[i], "+CMGR", 5) == 0) {	/* we are reading the "header" of an SMS */
 					char content[512];
@@ -1331,6 +1331,7 @@
 
 					int inside_comma = 0;
 					int inside_quote = 0;
+					int which_field = 0;
 					int d = 0;
 
 					for (c = 0; c < strlen(tech_pvt->line_array.result[i]); c++) {
@@ -1347,14 +1348,19 @@
 							if (inside_quote) {
 								inside_quote = 0;
 								//ERRORA("END_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", CELLIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
-								DEBUGA_CELLIAX("content=%s\n", CELLIAX_P_LOG, content);
+								DEBUGA_CELLIAX("%d content=%s\n", CELLIAX_P_LOG, which_field, content);
 
 								strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 								strncat(tech_pvt->sms_message, content, ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 								strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
 								memset(content2, '\0', sizeof(content2));
-								err = ucs2_to_utf8(tech_pvt, content, content2, sizeof(content2));
+								if(which_field==1){
+									err = ucs2_to_utf8(tech_pvt, content, content2, sizeof(content2));
+								} else {
+									err=0;
+									strncpy(content2, content, sizeof(content2));
+								}
 
 								strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 								if (!err)
@@ -1362,6 +1368,15 @@
 								strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 								memset(content, '\0', sizeof(content));
 								d = 0;
+								if(which_field==1){
+									strncpy(tech_pvt->sms_sender, content2, sizeof(tech_pvt->sms_sender));
+
+								} else if(which_field==2){
+									strncpy(tech_pvt->sms_date, content2, sizeof(tech_pvt->sms_date));
+								} else if(which_field > 2){
+								WARNINGA("WHY which_field is > 2 ? (which_field is %d)\n", CELLIAX_P_LOG, which_field);
+								}
+								which_field++;
 							} else {
 								inside_quote = 1;
 								//WARNINGA("START_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", CELLIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
@@ -1377,12 +1392,15 @@
 					}
 				}				//it was the +CMGR answer from the cellphone
 				else {
+					DEBUGA_CELLIAX("body=%s\n", CELLIAX_P_LOG, sms_body);
 					strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 					strncat(tech_pvt->sms_message, tech_pvt->line_array.result[i], ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 					strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
 					memset(sms_body, '\0', sizeof(sms_body));
 					err = ucs2_to_utf8(tech_pvt, tech_pvt->line_array.result[i], sms_body, sizeof(sms_body));
+					DEBUGA_CELLIAX("body=%s\n", CELLIAX_P_LOG, sms_body);
+					strncpy(tech_pvt->sms_body, sms_body, sizeof(tech_pvt->sms_body));
 
 					strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 					if (!err)
@@ -1390,7 +1408,6 @@
 					strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
 					DEBUGA_CELLIAX("sms_message=%s\n", CELLIAX_P_LOG, tech_pvt->sms_message);
-
 				}				//it was the UCS2 from cellphone
 
 			}					//we were reading the SMS

Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14994 => 14995)


--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-09-26 19:36:58 UTC (rev 14994)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-09-26 22:54:11 UTC (rev 14995)
@@ -2333,7 +2333,8 @@
 	switch_core_session_t *session = NULL;
 	int event_sent_to_esl = 0;
 
-	DEBUGA_CELLIAX("received SMS on interface %s\n", CELLIAX_P_LOG, tech_pvt->name);
+	DEBUGA_CELLIAX("received SMS on interface %s: %s\n", CELLIAX_P_LOG, tech_pvt->name, tech_pvt->sms_message);
+	DEBUGA_CELLIAX("received SMS on interface %s: DATE=%s, SENDER=%s, BODY=%s\n", CELLIAX_P_LOG, tech_pvt->name, tech_pvt->sms_date, tech_pvt->sms_sender, tech_pvt->sms_body);
 
 	if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
 		session = switch_core_session_locate(tech_pvt->session_uuid_str);
@@ -2342,11 +2343,12 @@
 		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", "333444555"); //FIXME
+		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", tech_pvt->sms_sender);
+		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "date", tech_pvt->sms_date); 
 		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->sms_message);
+		switch_event_add_body(event, "%s", tech_pvt->sms_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) {
@@ -2370,10 +2372,12 @@
 			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, "from", tech_pvt->sms_sender);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "date", tech_pvt->sms_date); 
 			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->sms_message);
+			switch_event_add_body(event, "%s", tech_pvt->sms_body);
 			if(session){
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "during-call", "true");
 			} else { //no session