summaryrefslogtreecommitdiffstats
path: root/tinyMSRP/src/session/tmsrp_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'tinyMSRP/src/session/tmsrp_data.c')
-rwxr-xr-xtinyMSRP/src/session/tmsrp_data.c324
1 files changed, 161 insertions, 163 deletions
diff --git a/tinyMSRP/src/session/tmsrp_data.c b/tinyMSRP/src/session/tmsrp_data.c
index e8c750e..d872da1 100755
--- a/tinyMSRP/src/session/tmsrp_data.c
+++ b/tinyMSRP/src/session/tmsrp_data.c
@@ -2,19 +2,19 @@
* 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.
*
@@ -43,38 +43,38 @@
tmsrp_data_in_t* tmsrp_data_in_create()
{
- return tsk_object_new(tmsrp_data_in_def_t);
+ 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);
+ 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);
+{
+ 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);
+ 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;
- }
+ if(!self) {
+ TSK_DEBUG_ERROR("Invalid parameter");
+ return -1;
+ }
- TSK_FREE(self->id);
- TSK_FREE(self->ctype);
- TSK_FREE(self->wctype);
+ TSK_FREE(self->id);
+ TSK_FREE(self->ctype);
+ TSK_FREE(self->wctype);
- return 0;
+ return 0;
}
@@ -87,45 +87,45 @@ static int tmsrp_data_deinit(tmsrp_data_t* self)
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;
+ 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;
+ 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(!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;
- }
+ 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;
+ return tsk_null;
}
@@ -133,38 +133,38 @@ tmsrp_message_t* tmsrp_data_in_get(tmsrp_data_in_t* self)
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 = (tsk_size_t)fread(ret->data, sizeof(uint8_t), toread, self->file)) == toread){
- self->size -= toread;
- }
- else{
- TSK_OBJECT_SAFE_FREE(ret);
- }
- }
-
-
- return ret;
+ 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 = (tsk_size_t)fread(ret->data, sizeof(uint8_t), toread, self->file)) == toread) {
+ self->size -= toread;
+ }
+ else {
+ TSK_OBJECT_SAFE_FREE(ret);
+ }
+ }
+
+
+ return ret;
}
@@ -179,30 +179,29 @@ tsk_buffer_t* tmsrp_data_out_get(tmsrp_data_out_t* self)
//
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;
+ 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;
+{
+ 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,
+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;
@@ -211,74 +210,73 @@ const tsk_object_def_t *tmsrp_data_in_def_t = &tmsrp_data_in_def_s;
//
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;
+ 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;
+{
+ 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,
+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;
OpenPOWER on IntegriCloud