From 85b0e1b9c985b0969fc9debe43bdf0705f5048a0 Mon Sep 17 00:00:00 2001
From: Mathieu Parent <math.parent@gmail.com>
Date: Mon, 27 Sep 2010 18:49:11 +0200
Subject: [PATCH] Skinny: Adds unimplemented send_data(), correct formats

- send_data() (only defined in .h-file - never implemented)
- Adds correct formats when adding message body.

Thanks to Peter Olsson for spotting this in FS-2737
---
 src/mod/endpoints/mod_skinny/skinny_api.c     |  2 +-
 .../endpoints/mod_skinny/skinny_protocol.c    | 26 +++++++++++++++++++
 src/mod/endpoints/mod_skinny/skinny_server.c  |  4 +--
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/mod/endpoints/mod_skinny/skinny_api.c b/src/mod/endpoints/mod_skinny/skinny_api.c
index 9f527f544c..7bbb27afd3 100644
--- a/src/mod/endpoints/mod_skinny/skinny_api.c
+++ b/src/mod/endpoints/mod_skinny/skinny_api.c
@@ -408,7 +408,7 @@ static switch_status_t skinny_api_cmd_profile_device_send_data(const char *profi
 					*/
 				}
 			}
-			switch_event_add_body(event, body);
+			switch_event_add_body(event, "%s", body);
 			switch_event_fire(&event);
 			stream->write_function(stream, "+OK\n");
 	    } else {
diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c
index 5486f0833d..743514d98c 100644
--- a/src/mod/endpoints/mod_skinny/skinny_protocol.c
+++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c
@@ -902,6 +902,32 @@ switch_status_t send_reset(listener_t *listener, uint32_t reset_type)
 	return skinny_send_reply(listener, message);
 }
 
+switch_status_t send_data(listener_t *listener, uint32_t message_type,
+	uint32_t application_id,
+	uint32_t line_instance,
+	uint32_t call_id,
+	uint32_t transaction_id,
+	uint32_t data_length,
+	const char *data)
+{
+	skinny_message_t *message;
+	switch_assert(data_length == strlen(data));
+	/* data_length should be a multiple of 4 */
+	if ((data_length % 4) != 0) {
+		data_length = (data_length / 4 + 1) * 4;
+	}
+	message = switch_core_alloc(listener->pool, 12+sizeof(message->data.data)+data_length-1);
+	message->type = message_type;
+	message->length = 4 + sizeof(message->data.data)+data_length-1;
+	message->data.data.application_id = application_id;
+	message->data.data.line_instance = line_instance;
+	message->data.data.call_id = call_id;
+	message->data.data.transaction_id = transaction_id;
+	message->data.data.data_length = data_length;
+	strncpy(message->data.data.data, data, data_length);
+	return skinny_send_reply(listener, message);
+}
+
 switch_status_t send_extended_data(listener_t *listener, uint32_t message_type,
 	uint32_t application_id,
 	uint32_t line_instance,
diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c
index bd2d6795e5..cfafea6f01 100644
--- a/src/mod/endpoints/mod_skinny/skinny_server.c
+++ b/src/mod/endpoints/mod_skinny/skinny_server.c
@@ -1884,7 +1884,7 @@ switch_status_t skinny_handle_data_message(listener_t *listener, skinny_message_
 	tmp = malloc(request->data.data.data_length + 1);
 	memcpy(tmp, request->data.data.data, request->data.data.data_length);
 	tmp[request->data.data.data_length] = '\0';
-	switch_event_add_body(event, tmp);
+	switch_event_add_body(event, "%s", tmp);
 	switch_safe_free(tmp);
 	switch_event_fire(&event);
 
@@ -1956,7 +1956,7 @@ switch_status_t skinny_handle_extended_data_message(listener_t *listener, skinny
 	tmp = malloc(request->data.data.data_length + 1);
 	memcpy(tmp, request->data.data.data, request->data.data.data_length);
 	tmp[request->data.data.data_length] = '\0';
-	switch_event_add_body(event, tmp);
+	switch_event_add_body(event, "%s", tmp);
 	switch_safe_free(tmp);
 	switch_event_fire(&event);