summaryrefslogtreecommitdiffstats
path: root/tinyMSRP/src/session
diff options
context:
space:
mode:
Diffstat (limited to 'tinyMSRP/src/session')
-rw-r--r--tinyMSRP/src/session/tmsrp_config.c82
-rw-r--r--tinyMSRP/src/session/tmsrp_data.c284
-rw-r--r--tinyMSRP/src/session/tmsrp_receiver.c203
-rw-r--r--tinyMSRP/src/session/tmsrp_sender.c286
4 files changed, 855 insertions, 0 deletions
diff --git a/tinyMSRP/src/session/tmsrp_config.c b/tinyMSRP/src/session/tmsrp_config.c
new file mode 100644
index 0000000..18b857c
--- /dev/null
+++ b/tinyMSRP/src/session/tmsrp_config.c
@@ -0,0 +1,82 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file tmsrp_media.c
+ * @brief MSRP Session config.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+ * @date Created: Sat Nov 8 16:54:58 2009 mdiop
+ */
+#include "tinymsrp/session/tmsrp_config.h"
+
+#include "tsk_memory.h"
+
+
+TINYMSRP_API tmsrp_config_t* tmsrp_config_create()
+{
+ return tsk_object_new(tmsrp_config_def_t);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+//=================================================================================================
+// MSRP Session config object definition
+//
+static void* tmsrp_config_ctor(tsk_object_t * self, va_list * app)
+{
+ tmsrp_config_t *config = self;
+ if(config){
+ config->Failure_Report = tsk_true;
+ }
+ return self;
+}
+
+static void* tmsrp_config_dtor(tsk_object_t * self)
+{
+ tmsrp_config_t *config = self;
+ if(config){
+ TSK_OBJECT_SAFE_FREE(config->From_Path);
+ TSK_OBJECT_SAFE_FREE(config->To_Path);
+ }
+
+ return self;
+}
+
+static const tsk_object_def_t tmsrp_config_def_s =
+{
+ sizeof(tmsrp_config_t),
+ tmsrp_config_ctor,
+ tmsrp_config_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *tmsrp_config_def_t = &tmsrp_config_def_s;
+
diff --git a/tinyMSRP/src/session/tmsrp_data.c b/tinyMSRP/src/session/tmsrp_data.c
new file mode 100644
index 0000000..b12fff1
--- /dev/null
+++ b/tinyMSRP/src/session/tmsrp_data.c
@@ -0,0 +1,284 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file tmsrp_data.c
+ * @brief MSRP input/output data.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+ * @date Created: Sat Nov 8 16:54:58 2009 mdiop
+ */
+#include "tinymsrp/session/tmsrp_data.h"
+
+#include "tinymsrp/session/tmsrp_config.h"
+
+#include "tinymsrp/parsers/tmsrp_parser_message.h"
+
+#include "tsk_string.h"
+#include "tsk_memory.h"
+#include "tsk_debug.h"
+
+#include <stdio.h> /* fopen, fclose ... */
+
+#define TMSRP_DATA_IN_MAX_BUFFER 0xFFFFFF
+
+tmsrp_data_in_t* tmsrp_data_in_create()
+{
+ return tsk_object_new(tmsrp_data_in_def_t);
+}
+
+tmsrp_data_out_t* _tmsrp_data_out_create(const void* pdata, tsk_size_t size, tsk_bool_t isfilepath)
+{
+ return tsk_object_new(tmsrp_data_out_def_t, pdata, size, isfilepath);
+}
+
+tmsrp_data_out_t* tmsrp_data_out_create(const void* pdata, tsk_size_t size)
+{
+ return _tmsrp_data_out_create(pdata, size, tsk_false);
+}
+
+tmsrp_data_out_t* tmsrp_data_out_file_create(const char* filepath)
+{
+ return _tmsrp_data_out_create(filepath, tsk_strlen(filepath), tsk_true);
+}
+
+
+/* =========================== Common ============================= */
+static int tmsrp_data_deinit(tmsrp_data_t* self)
+{
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ TSK_FREE(self->id);
+ TSK_FREE(self->ctype);
+ TSK_FREE(self->wctype);
+
+ return 0;
+}
+
+
+
+
+
+
+
+/* =========================== Incoming ============================= */
+
+int tmsrp_data_in_put(tmsrp_data_in_t* self, const void* pdata, tsk_size_t size)
+{
+ int ret = -1;
+
+ if(!self || !self->buffer || !pdata || !size){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return ret;
+ }
+
+ if((ret = tsk_buffer_append(self->buffer, pdata, size))){
+ TSK_DEBUG_ERROR("Failed to append data");
+ tsk_buffer_cleanup(self->buffer);
+ return ret;
+ }
+ else{
+ if(TSK_BUFFER_SIZE(self->buffer) > TMSRP_DATA_IN_MAX_BUFFER){
+ tsk_buffer_cleanup(self->buffer);
+ TSK_DEBUG_ERROR("Too many bytes are waiting.");
+ return -3;
+ }
+ }
+
+ return ret;
+}
+
+tmsrp_message_t* tmsrp_data_in_get(tmsrp_data_in_t* self)
+{
+ tmsrp_message_t* ret;
+ tsk_size_t msg_size;
+
+ if(!self || !self->buffer || !TSK_BUFFER_DATA(self->buffer) || !TSK_BUFFER_SIZE(self->buffer)){
+ //...this is not an error
+ return tsk_null;
+ }
+
+ if((ret = tmsrp_message_parse_2(self->buffer->data, self->buffer->size, &msg_size))){
+ tsk_buffer_remove(self->buffer, 0, msg_size);
+ return ret;
+ }
+
+ return tsk_null;
+}
+
+
+/* =========================== Outgoing ============================= */
+
+tsk_buffer_t* tmsrp_data_out_get(tmsrp_data_out_t* self)
+{
+ tsk_buffer_t* ret = tsk_null;
+ tsk_size_t toread;
+
+ if(!self){
+ return tsk_null;
+ }
+
+ if(!(toread = self->size > TMSRP_MAX_CHUNK_SIZE ? TMSRP_MAX_CHUNK_SIZE : self->size)){
+ return tsk_null;
+ }
+
+ if(self->message){
+ ret = tsk_buffer_create(TSK_BUFFER_DATA(self->message), toread);
+ tsk_buffer_remove(self->message, 0, toread);
+ self->size = self->message->size;
+ }
+ else if(self->file){
+ // Buffer hack
+ tsk_size_t read;
+ ret = tsk_buffer_create_null();
+ ret->data = tsk_calloc(toread, sizeof(uint8_t));
+ ret->size = toread;
+ if((read = fread(ret->data, sizeof(uint8_t), toread, self->file)) == toread){
+ self->size -= toread;
+ }
+ else{
+ TSK_OBJECT_SAFE_FREE(ret);
+ }
+ }
+
+
+ return ret;
+}
+
+
+
+
+
+
+
+
+//=================================================================================================
+// MSRP incoming data object definition
+//
+static void* tmsrp_data_in_ctor(tsk_object_t * self, va_list * app)
+{
+ tmsrp_data_in_t *data_in = self;
+ if(data_in){
+ data_in->buffer = tsk_buffer_create_null();
+ }
+ return self;
+}
+
+static void* tmsrp_data_in_dtor(tsk_object_t * self)
+{
+ tmsrp_data_in_t *data_in = self;
+ if(data_in){
+ tmsrp_data_deinit(TMSRP_DATA(data_in));
+ TSK_OBJECT_SAFE_FREE(data_in->buffer);
+ }
+
+ return self;
+}
+
+static const tsk_object_def_t tmsrp_data_in_def_s =
+{
+ sizeof(tmsrp_data_in_t),
+ tmsrp_data_in_ctor,
+ tmsrp_data_in_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *tmsrp_data_in_def_t = &tmsrp_data_in_def_s;
+
+//=================================================================================================
+// MSRP outgoing data object definition
+//
+static void* tmsrp_data_out_ctor(tsk_object_t * self, va_list * app)
+{
+ tmsrp_data_out_t *data_out = self;
+ if(data_out){
+ tsk_istr_t id;
+ const void* pdata = va_arg(*app, const void*);
+ tsk_size_t size = va_arg(*app, tsk_size_t);
+ tsk_bool_t isfilepath = va_arg(*app, tsk_bool_t);
+
+ if(isfilepath){
+ if((data_out->file = fopen((const char*)pdata, "rb"))){
+ int ret;
+ if((ret = fseek(data_out->file, 0L, SEEK_END))){
+ TSK_DEBUG_ERROR("fseek for file:[%s] failed with error code %d.", (const char*)pdata, ret);
+ TMSRP_DATA(data_out)->isOK = tsk_false;
+ }
+ else{
+ data_out->size = ftell(data_out->file);
+ if((ret = fseek(data_out->file, 0L, SEEK_SET))){
+ TSK_DEBUG_ERROR("fseek for file:[%s] failed with error code %d.", (const char*)pdata, ret);
+ TMSRP_DATA(data_out)->isOK = tsk_false;
+ }
+ else{
+ TMSRP_DATA(data_out)->isOK = tsk_true;
+ }
+ }
+ }
+ else{
+ TSK_DEBUG_ERROR("Failed to open(rb) this file:[%s]", (const char*)pdata);
+ TMSRP_DATA(data_out)->isOK = tsk_false;
+ }
+ }
+ else{
+ if((data_out->message = tsk_buffer_create(pdata, size))){
+ TMSRP_DATA(data_out)->isOK = (data_out->message->size == size);
+ data_out->size = data_out->message->size;
+ }
+ }
+
+ // content type
+ TMSRP_DATA(data_out)->ctype = tsk_strdup("application/octet-stream");
+ TMSRP_DATA(data_out)->wctype = tsk_strdup("text/plain");
+ // random id
+ tsk_strrandom(&id);
+ TMSRP_DATA(data_out)->id = tsk_strdup(id);
+ }
+ return self;
+}
+
+static void* tmsrp_data_out_dtor(tsk_object_t * self)
+{
+ tmsrp_data_out_t *data_out = self;
+ if(data_out){
+ tmsrp_data_deinit(TMSRP_DATA(data_out));
+ TSK_OBJECT_SAFE_FREE(data_out->message);
+
+ if(data_out->file){
+ fclose(data_out->file);
+ data_out->file = tsk_null;
+ }
+ }
+
+ return self;
+}
+
+static const tsk_object_def_t tmsrp_data_out_def_s =
+{
+ sizeof(tmsrp_data_out_t),
+ tmsrp_data_out_ctor,
+ tmsrp_data_out_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *tmsrp_data_out_def_t = &tmsrp_data_out_def_s;
diff --git a/tinyMSRP/src/session/tmsrp_receiver.c b/tinyMSRP/src/session/tmsrp_receiver.c
new file mode 100644
index 0000000..bd41d37
--- /dev/null
+++ b/tinyMSRP/src/session/tmsrp_receiver.c
@@ -0,0 +1,203 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file tmsrp_receiver.c
+ * @brief MSRP receiver.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+ * @date Created: Sat Nov 8 16:54:58 2009 mdiop
+ */
+#include "tinymsrp/session/tmsrp_receiver.h"
+
+#include "tmsrp.h"
+
+#include "tnet_utils.h"
+
+#include "tsk_memory.h"
+#include "tsk_string.h"
+#include "tsk_debug.h"
+
+static void _tmsrp_receiver_alert_user(tmsrp_receiver_t* self, tsk_bool_t outgoing, tmsrp_message_t* message)
+{
+ if(self->callback.func){
+ tmsrp_event_t* _event = tmsrp_event_create(self->callback.data, outgoing, tmsrp_event_type_message, message);
+ self->callback.func(_event);
+ TSK_OBJECT_SAFE_FREE(_event);
+ }
+}
+
+tmsrp_receiver_t* tmsrp_receiver_create(tmsrp_config_t* config, tnet_fd_t fd)
+{
+ return tsk_object_new(tmsrp_receiver_def_t, config, fd);
+}
+
+int tmsrp_receiver_set_fd(tmsrp_receiver_t* self, tnet_fd_t fd)
+{
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ self->fd = fd;
+ return 0;
+}
+
+int tmsrp_receiver_start(tmsrp_receiver_t* self, const void* callback_data, tmsrp_event_cb_f func)
+{
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ self->callback.data = callback_data;
+ self->callback.func = func;
+
+ return 0;
+}
+
+int tmsrp_receiver_stop(tmsrp_receiver_t* self)
+{
+ return 0;
+}
+
+int tmsrp_receiver_recv(tmsrp_receiver_t* self, const void* data, tsk_size_t size)
+{
+ tmsrp_message_t* message;
+
+ if(!self || !data || !size){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ // put the data
+ tmsrp_data_in_put(self->data_in, data, size);
+ // get msrp messages
+ while((message = tmsrp_data_in_get(self->data_in))){
+
+ /* alert that we have received a message (Request or Response) */
+ _tmsrp_receiver_alert_user(self, tsk_false, message);
+
+ //
+ // REQUEST
+ //
+ if(TMSRP_MESSAGE_IS_REQUEST(message)){
+ /* ============= SEND =============== */
+ if(TMSRP_REQUEST_IS_SEND(message)){
+ tmsrp_response_t* r2xx;
+ tmsrp_request_t* REPORT;
+
+ // send 200 OK
+ if((r2xx = tmsrp_create_response(message, 200, "OK"))){
+ if(tmsrp_message_serialize(r2xx, self->buffer) == 0 && self->buffer->data){
+ tnet_sockfd_send(self->fd, self->buffer->data, self->buffer->size, 0);
+ }
+
+ tsk_buffer_cleanup(self->buffer);
+ TSK_OBJECT_SAFE_FREE(r2xx);
+ }
+ // send REPORT
+ if(tmsrp_isReportRequired(message, tsk_false)){
+ if((REPORT = tmsrp_create_report(message, 200, "OK"))){
+ if(tmsrp_message_serialize(REPORT, self->buffer) == 0 && self->buffer->data){
+ tnet_sockfd_send(self->fd, self->buffer->data, self->buffer->size, 0);
+ }
+ tsk_buffer_cleanup(self->buffer);
+ TSK_OBJECT_SAFE_FREE(REPORT);
+ }
+ }
+ }
+ /* ============= REPORT =============== */
+ if(TMSRP_REQUEST_IS_REPORT(message)){
+ tmsrp_response_t* r2xx;
+
+ // send 200 OK
+ if((r2xx = tmsrp_create_response(message, 200, "Report received"))){
+ if(tmsrp_message_serialize(r2xx, self->buffer) == 0 && self->buffer->data){
+ tnet_sockfd_send(self->fd, self->buffer->data, self->buffer->size, 0);
+ }
+
+ tsk_buffer_cleanup(self->buffer);
+ TSK_OBJECT_SAFE_FREE(r2xx);
+ }
+ }
+
+ /* ============= AUTH =============== */
+ /* ============= METHOD =============== */
+ }
+ //
+ // RESPONSE
+ //
+ else{
+ //short code = TMSRP_RESPONSE_CODE(message);
+ //TSK_DEBUG_INFO("code=%u, tid=%s, phrase=%s", code, message->tid, TMSRP_RESPONSE_PHRASE(message));
+ }
+
+
+ // alert user layer
+
+ TSK_OBJECT_SAFE_FREE(message);
+ }
+
+ return 0;
+}
+
+
+//=================================================================================================
+// MSRP receiver object definition
+//
+static void* tmsrp_receiver_ctor(tsk_object_t * self, va_list *app)
+{
+ tmsrp_receiver_t *receiver = self;
+ if(receiver){
+ receiver->config = tsk_object_ref(va_arg(*app, tmsrp_config_t*));
+ receiver->fd = va_arg(*app, tnet_fd_t);
+
+ receiver->data_in = tmsrp_data_in_create();
+ receiver->buffer = tsk_buffer_create_null();
+ }
+ return self;
+}
+
+static void* tmsrp_receiver_dtor(tsk_object_t * self)
+{
+ tmsrp_receiver_t *receiver = self;
+ if(receiver){
+ /* Stop */
+ tmsrp_receiver_stop(receiver);
+
+ TSK_OBJECT_SAFE_FREE(receiver->config);
+ TSK_OBJECT_SAFE_FREE(receiver->data_in);
+ TSK_OBJECT_SAFE_FREE(receiver->buffer);
+ // the FD is owned by the transport ...do not close it
+ }
+ return self;
+}
+
+static const tsk_object_def_t tmsrp_receiver_def_s =
+{
+ sizeof(tmsrp_receiver_t),
+ tmsrp_receiver_ctor,
+ tmsrp_receiver_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *tmsrp_receiver_def_t = &tmsrp_receiver_def_s;
+
diff --git a/tinyMSRP/src/session/tmsrp_sender.c b/tinyMSRP/src/session/tmsrp_sender.c
new file mode 100644
index 0000000..f43c94a
--- /dev/null
+++ b/tinyMSRP/src/session/tmsrp_sender.c
@@ -0,0 +1,286 @@
+/*
+* Copyright (C) 2009 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* DOUBANGO is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with DOUBANGO.
+*
+*/
+
+/**@file tmsrp_sender.c
+ * @brief MSRP sender.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+ * @date Created: Sat Nov 8 16:54:58 2009 mdiop
+ */
+#include "tinymsrp/session/tmsrp_sender.h"
+
+#include "tnet_utils.h"
+
+#include "tsk_thread.h"
+#include "tsk_memory.h"
+#include "tsk_string.h"
+#include "tsk_time.h"
+#include "tsk_debug.h"
+
+
+static void *run(void* self);
+
+
+tmsrp_sender_t* tmsrp_sender_create(tmsrp_config_t* config, tnet_fd_t fd)
+{
+ return tsk_object_new(tmsrp_sender_def_t, config, fd);
+}
+
+int tmsrp_sender_set_fd(tmsrp_sender_t* self, tnet_fd_t fd)
+{
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+ self->fd = fd;
+ return 0;
+}
+
+int tmsrp_sender_start(tmsrp_sender_t* self)
+{
+ int ret = -1;
+
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ goto bail;
+ }
+
+ TSK_RUNNABLE(self)->run = run;
+ if((ret = tsk_runnable_start(TSK_RUNNABLE(self), tmsrp_data_out_def_t))){
+ goto bail;
+ }
+
+bail:
+ return ret;
+}
+
+int tsmrp_sender_send_data(tmsrp_sender_t* self, const void* pdata, tsk_size_t size, const char* ctype, const char* wctype)
+{
+ tmsrp_data_out_t* data_out;
+
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ if((data_out = tmsrp_data_out_create(pdata, size))){
+ if(ctype){
+ tsk_strupdate(&TMSRP_DATA(data_out)->ctype, ctype);
+ }
+ if(wctype){
+ tsk_strupdate(&TMSRP_DATA(data_out)->wctype, wctype);
+ }
+ TSK_RUNNABLE_ENQUEUE_OBJECT(self, data_out);
+ return 0;
+ }
+ return -2;
+}
+
+int tsmrp_sender_send_file(tmsrp_sender_t* self, const char* filepath)
+{
+ tmsrp_data_out_t* data_out;
+
+ if(!self || !filepath){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
+
+ if((data_out = tmsrp_data_out_file_create(filepath))){
+ if(TMSRP_DATA(data_out)->isOK){
+ TSK_RUNNABLE_ENQUEUE_OBJECT(self, data_out);
+ return 0;
+ }
+ else{
+ TSK_OBJECT_SAFE_FREE(data_out);
+ return -3;
+ }
+ }
+ return -2;
+}
+
+int tmsrp_sender_stop(tmsrp_sender_t* self)
+{
+ int ret = -1;
+
+ if(!self){
+ TSK_DEBUG_ERROR("Invalid parameter");
+ goto bail;
+ }
+
+ if((ret = tsk_runnable_stop(TSK_RUNNABLE(self)))){
+ goto bail;
+ }
+
+bail:
+ return ret;
+}
+
+
+
+
+void *run(void* self)
+{
+ tsk_list_item_t *curr;
+ tmsrp_sender_t *sender = self;
+ tmsrp_data_out_t *data_out;
+ tsk_buffer_t* chunck, *message = tsk_buffer_create_null();
+ tsk_size_t start;
+ tsk_size_t end;
+ tsk_size_t total;
+ tsk_istr_t tid;
+ int64_t __now = (int64_t)tsk_time_epoch();
+ tsk_bool_t error = tsk_false;
+
+ TSK_DEBUG_INFO("MSRP SENDER::run -- START");
+
+ TSK_RUNNABLE_RUN_BEGIN(sender);
+
+ if((curr = TSK_RUNNABLE_POP_FIRST(sender))){
+ if(!(data_out = (tmsrp_data_out_t*)curr->data)){
+ continue;
+ }
+
+ error = tsk_false;
+ start = 1;
+ total = data_out->size;
+
+ while(TSK_RUNNABLE(self)->running && !error && (chunck = tmsrp_data_out_get(data_out))){
+ tmsrp_request_t* SEND;
+ // set end
+ end = (start + chunck->size) - 1;
+ // compute new transaction id
+ tsk_itoa(++__now, &tid);
+ // create SEND request
+ SEND = tmsrp_request_create(tid, "SEND");
+ // T-Path and From-Path (because of otherURIs)
+ SEND->To = tsk_object_ref(sender->config->To_Path);
+ SEND->From = tsk_object_ref(sender->config->From_Path);
+ // add other headers
+ tmsrp_message_add_headers(SEND,
+ TMSRP_HEADER_MESSAGE_ID_VA_ARGS(TMSRP_DATA(data_out)->id),
+ // TMSRP_HEADER_BYTE_RANGE_VA_ARGS(start, end, total), => See below
+ TMSRP_HEADER_FAILURE_REPORT_VA_ARGS(sender->config->Failure_Report ? freport_yes : freport_no),
+ TMSRP_HEADER_SUCCESS_REPORT_VA_ARGS(sender->config->Success_Report),
+
+ tsk_null);
+ // add data
+ if(start == 1 && chunck->size && tsk_striequals(TMSRP_DATA(data_out)->ctype, "message/CPIM")){
+ tsk_buffer_t* content_cpim = tsk_buffer_create_null();
+ if(content_cpim){
+ tsk_buffer_append_2(content_cpim, "Subject: %s\r\n\r\nContent-Type: %s\r\n\r\n",
+ "test", TMSRP_DATA(data_out)->wctype);
+ end += content_cpim->size;
+ total += content_cpim->size;
+ tsk_buffer_append(content_cpim, chunck->data, chunck->size);
+ tmsrp_message_add_content(SEND, TMSRP_DATA(data_out)->ctype, content_cpim->data, content_cpim->size);
+ TSK_OBJECT_SAFE_FREE(content_cpim);
+ }
+ else{
+ TSK_DEBUG_ERROR("Failed to allocate new buffer");
+ }
+ }
+ else{
+ tmsrp_message_add_content(SEND, TMSRP_DATA(data_out)->ctype, chunck->data, chunck->size);
+ }
+ // add byte range here not before: think about message/cpim
+ tmsrp_message_add_headers(SEND,
+ TMSRP_HEADER_BYTE_RANGE_VA_ARGS(start, end, total),
+
+ tsk_null);
+
+
+ // set continuation flag
+ SEND->end_line.cflag = (end == total) ? '$' : '+';
+ // serialize and send
+ if(!(tmsrp_message_serialize(SEND, message))){
+ if(tnet_sockfd_send(sender->fd, message->data, message->size, 0) == 0){
+ error = tsk_true;
+ // abort
+ }
+ }
+ tsk_buffer_cleanup(message);
+
+ // set start
+ start = (end + 1);
+ // cleanup
+ TSK_OBJECT_SAFE_FREE(chunck);
+ TSK_OBJECT_SAFE_FREE(SEND);
+
+ /* wait */
+ if(sender->chunck_duration){
+ tsk_thread_sleep(sender->chunck_duration);
+ }
+ }
+
+
+ tsk_object_unref(curr);
+ }
+
+ TSK_RUNNABLE_RUN_END(self);
+
+ TSK_OBJECT_SAFE_FREE(message);
+
+ TSK_DEBUG_INFO("MSRP SENDER::run -- STOP");
+
+ return 0;
+}
+
+
+
+//=================================================================================================
+// MSRP sender object definition
+//
+static void* tmsrp_sender_ctor(tsk_object_t * self, va_list *app)
+{
+ tmsrp_sender_t *sender = self;
+ if(sender){
+ sender->config = tsk_object_ref(va_arg(*app, tmsrp_config_t*));
+ sender->fd = va_arg(*app, tnet_fd_t);
+
+ sender->outgoingList = tsk_list_create();
+ }
+ return self;
+}
+
+static void* tmsrp_sender_dtor(tsk_object_t * self)
+{
+ tmsrp_sender_t *sender = self;
+ if(sender){
+ /* Stop */
+ tmsrp_sender_stop(sender);
+
+ TSK_OBJECT_SAFE_FREE(sender->config);
+ TSK_OBJECT_SAFE_FREE(sender->outgoingList);
+ // the FD is owned by the transport ...do not close it
+ }
+ return self;
+}
+
+static const tsk_object_def_t tmsrp_sender_def_s =
+{
+ sizeof(tmsrp_sender_t),
+ tmsrp_sender_ctor,
+ tmsrp_sender_dtor,
+ tsk_null,
+};
+const tsk_object_def_t *tmsrp_sender_def_t = &tmsrp_sender_def_s;
OpenPOWER on IntegriCloud