diff options
author | Mamadou DIOP <bossiel@yahoo.fr> | 2016-02-23 22:00:35 +0100 |
---|---|---|
committer | Mamadou DIOP <bossiel@yahoo.fr> | 2016-02-23 22:00:35 +0100 |
commit | 50dfb4359619563012997bc3ddafb7667741066c (patch) | |
tree | db234c1edc3240a653363b5735fc4077af4b8720 /tinyMEDIA/src/content | |
parent | 94b2219209038e05dd26395f6fb700be4d1062c0 (diff) | |
download | doubango-50dfb4359619563012997bc3ddafb7667741066c.zip doubango-50dfb4359619563012997bc3ddafb7667741066c.tar.gz |
Add new QoS implementation
Code formatting
Diffstat (limited to 'tinyMEDIA/src/content')
-rwxr-xr-x | tinyMEDIA/src/content/tmedia_content.c | 428 | ||||
-rwxr-xr-x | tinyMEDIA/src/content/tmedia_content_cpim.c | 722 |
2 files changed, 578 insertions, 572 deletions
diff --git a/tinyMEDIA/src/content/tmedia_content.c b/tinyMEDIA/src/content/tmedia_content.c index bcdf275..0e06d21 100755 --- a/tinyMEDIA/src/content/tmedia_content.c +++ b/tinyMEDIA/src/content/tmedia_content.c @@ -32,10 +32,9 @@ /**@defgroup tmedia_content_group Contents */ -typedef struct tmedia_content_plugin_entry_s -{ - const char* type; - const tmedia_content_plugin_def_t* plugin; +typedef struct tmedia_content_plugin_entry_s { + const char* type; + const tmedia_content_plugin_def_t* plugin; } tmedia_content_plugin_entry_t; @@ -45,156 +44,156 @@ tmedia_content_plugin_entry_t __tmedia_content_plugin_entries[TMEDIA_CONTENT_MAX int tmedia_content_plugin_register(const char* type, const tmedia_content_plugin_def_t* plugin) { - tsk_size_t i; - //-- int a = sizeof(__tmedia_content_plugin_entries); - if (!plugin || !plugin){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - /* add or replace the plugin */ - for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS; i++){ - if (!__tmedia_content_plugin_entries[i]->plugin || (__tmedia_content_plugin_entries[i]->plugin == plugin && tsk_striequals(type, __tmedia_content_plugin_entries[i]->type))){ - __tmedia_content_plugin_entries[i]->type = type; - __tmedia_content_plugin_entries[i]->plugin = plugin; - return 0; - } - } - - - TSK_DEBUG_ERROR("There are already %d plugins.", TMEDIA_CONTENT_MAX_PLUGINS); - return -2; + tsk_size_t i; + //-- int a = sizeof(__tmedia_content_plugin_entries); + if (!plugin || !plugin) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + + /* add or replace the plugin */ + for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS; i++) { + if (!__tmedia_content_plugin_entries[i]->plugin || (__tmedia_content_plugin_entries[i]->plugin == plugin && tsk_striequals(type, __tmedia_content_plugin_entries[i]->type))) { + __tmedia_content_plugin_entries[i]->type = type; + __tmedia_content_plugin_entries[i]->plugin = plugin; + return 0; + } + } + + + TSK_DEBUG_ERROR("There are already %d plugins.", TMEDIA_CONTENT_MAX_PLUGINS); + return -2; } int tmedia_content_plugin_unregister(const char* type, const tmedia_content_plugin_def_t* plugin) { - tsk_size_t i; - tsk_bool_t found = tsk_false; - if (!plugin){ - TSK_DEBUG_ERROR("Invalid Parameter"); - return -1; - } - - /* find the plugin to unregister */ - for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS && __tmedia_content_plugin_entries[i]->plugin; i++){ - if (__tmedia_content_plugin_entries[i]->plugin == plugin && tsk_striequals(type, __tmedia_content_plugin_entries[i]->type)){ - __tmedia_content_plugin_entries[i]->type = tsk_null, - __tmedia_content_plugin_entries[i]->plugin = tsk_null; - found = tsk_true; - break; - } - } - - /* compact */ - if (found){ - for (; i < (TMEDIA_CONTENT_MAX_PLUGINS - 1); i++){ - if (__tmedia_content_plugin_entries[i + 1]->plugin){ - __tmedia_content_plugin_entries[i]->type = __tmedia_content_plugin_entries[i + 1]->type, - __tmedia_content_plugin_entries[i]->plugin = __tmedia_content_plugin_entries[i + 1]->plugin; - } - else{ - break; - } - } - __tmedia_content_plugin_entries[i]->type = tsk_null, - __tmedia_content_plugin_entries[i]->plugin = tsk_null; - } - return (found ? 0 : -2); + tsk_size_t i; + tsk_bool_t found = tsk_false; + if (!plugin) { + TSK_DEBUG_ERROR("Invalid Parameter"); + return -1; + } + + /* find the plugin to unregister */ + for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS && __tmedia_content_plugin_entries[i]->plugin; i++) { + if (__tmedia_content_plugin_entries[i]->plugin == plugin && tsk_striequals(type, __tmedia_content_plugin_entries[i]->type)) { + __tmedia_content_plugin_entries[i]->type = tsk_null, + __tmedia_content_plugin_entries[i]->plugin = tsk_null; + found = tsk_true; + break; + } + } + + /* compact */ + if (found) { + for (; i < (TMEDIA_CONTENT_MAX_PLUGINS - 1); i++) { + if (__tmedia_content_plugin_entries[i + 1]->plugin) { + __tmedia_content_plugin_entries[i]->type = __tmedia_content_plugin_entries[i + 1]->type, + __tmedia_content_plugin_entries[i]->plugin = __tmedia_content_plugin_entries[i + 1]->plugin; + } + else { + break; + } + } + __tmedia_content_plugin_entries[i]->type = tsk_null, + __tmedia_content_plugin_entries[i]->plugin = tsk_null; + } + return (found ? 0 : -2); } int tmedia_content_plugin_unregister_all() { - tsk_size_t i; - for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS && __tmedia_content_plugin_entries[i]->plugin; i++){ - __tmedia_content_plugin_entries[i]->type = tsk_null, - __tmedia_content_plugin_entries[i]->plugin = tsk_null; - } - return 0; + tsk_size_t i; + for (i = 0; i < TMEDIA_CONTENT_MAX_PLUGINS && __tmedia_content_plugin_entries[i]->plugin; i++) { + __tmedia_content_plugin_entries[i]->type = tsk_null, + __tmedia_content_plugin_entries[i]->plugin = tsk_null; + } + return 0; } tmedia_content_t* tmedia_content_create(const char* type) { - tmedia_content_t* content = tsk_null; - const tmedia_content_plugin_entry_t* entry; - tsk_size_t i = 0; - - while (i < TMEDIA_CONTENT_MAX_PLUGINS){ - entry = __tmedia_content_plugin_entries[i]; - if (!entry->plugin || !entry->type){ - break; - } - if (entry->plugin->objdef && tsk_striequals(entry->type, type)){ - if ((content = tsk_object_new(entry->plugin->objdef))){ - content->plugin = entry->plugin; - content->type = entry->type; - return content; - } - } - ++i; - } - - TSK_DEBUG_WARN("Failed to find content type (%s) will be added as dummy", type); - if (tmedia_content_dummy_plugin_def_t){ - content = tsk_object_new(tmedia_content_dummy_plugin_def_t->objdef); - content->plugin = tmedia_content_dummy_plugin_def_t; - content->type = type; - } - - return content; + tmedia_content_t* content = tsk_null; + const tmedia_content_plugin_entry_t* entry; + tsk_size_t i = 0; + + while (i < TMEDIA_CONTENT_MAX_PLUGINS) { + entry = __tmedia_content_plugin_entries[i]; + if (!entry->plugin || !entry->type) { + break; + } + if (entry->plugin->objdef && tsk_striequals(entry->type, type)) { + if ((content = tsk_object_new(entry->plugin->objdef))) { + content->plugin = entry->plugin; + content->type = entry->type; + return content; + } + } + ++i; + } + + TSK_DEBUG_WARN("Failed to find content type (%s) will be added as dummy", type); + if (tmedia_content_dummy_plugin_def_t) { + content = tsk_object_new(tmedia_content_dummy_plugin_def_t->objdef); + content->plugin = tmedia_content_dummy_plugin_def_t; + content->type = type; + } + + return content; } tmedia_content_t* tmedia_content_parse(const void* data, tsk_size_t size, const char* type) { - tmedia_content_t* content = tmedia_content_create(type); - if (content){ - if (content->plugin->parse){ - int ret; - if ((ret = content->plugin->parse(content, data, size))){ - TSK_DEBUG_ERROR("Failed to parse the content(%d)", ret); - TSK_OBJECT_SAFE_FREE(content); - return tsk_null; - } - return content; - } - else{ - TSK_DEBUG_ERROR("No parser function for this content (%s)", type); - TSK_OBJECT_SAFE_FREE(content); - return tsk_null; - } - } - else{ - TSK_DEBUG_ERROR("Failed to to find content(%s)", type); - return tsk_null; - } + tmedia_content_t* content = tmedia_content_create(type); + if (content) { + if (content->plugin->parse) { + int ret; + if ((ret = content->plugin->parse(content, data, size))) { + TSK_DEBUG_ERROR("Failed to parse the content(%d)", ret); + TSK_OBJECT_SAFE_FREE(content); + return tsk_null; + } + return content; + } + else { + TSK_DEBUG_ERROR("No parser function for this content (%s)", type); + TSK_OBJECT_SAFE_FREE(content); + return tsk_null; + } + } + else { + TSK_DEBUG_ERROR("Failed to to find content(%s)", type); + return tsk_null; + } } int tmedia_content_init(tmedia_content_t* self) { - if (!self || !self->plugin){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } + if (!self || !self->plugin) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } - return 0; + return 0; } int tmedia_content_deinit(tmedia_content_t* self) { - if (!self || !self->plugin){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } + if (!self || !self->plugin) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } - return 0; + return 0; } tsk_buffer_t* tmedia_content_get_data(tmedia_content_t* self) { - if (!self || !self->plugin){ - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - return self->plugin->get_data(self); + if (!self || !self->plugin) { + TSK_DEBUG_ERROR("Invalid parameter"); + return tsk_null; + } + return self->plugin->get_data(self); } @@ -202,19 +201,19 @@ tsk_buffer_t* tmedia_content_get_data(tmedia_content_t* self) static int tmedia_content_dummy_parse(tmedia_content_t* self, const void* in_data, tsk_size_t in_size) { - tmedia_content_dummy_t *dummy = TMEDIA_CONTENT_DUMMY(self); - if (!dummy || dummy->data){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - dummy->data = tsk_buffer_create(in_data, in_size); - return 0; + tmedia_content_dummy_t *dummy = TMEDIA_CONTENT_DUMMY(self); + if (!dummy || dummy->data) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + + dummy->data = tsk_buffer_create(in_data, in_size); + return 0; } static tsk_buffer_t* tmedia_content_dummy_get_data(tmedia_content_t* self) { - return tsk_object_ref(TMEDIA_CONTENT_DUMMY(self)->data); + return tsk_object_ref(TMEDIA_CONTENT_DUMMY(self)->data); } @@ -228,42 +227,40 @@ static tsk_buffer_t* tmedia_content_dummy_get_data(tmedia_content_t* self) /* constructor */ static tsk_object_t* tmedia_content_dummy_ctor(tsk_object_t * self, va_list * app) { - tmedia_content_dummy_t *dummy = self; - if (dummy){ - /* init base: called by tmedia_content_create() */ - /* init self */ - } - return self; + tmedia_content_dummy_t *dummy = self; + if (dummy) { + /* init base: called by tmedia_content_create() */ + /* init self */ + } + return self; } /* destructor */ static tsk_object_t* tmedia_content_dummy_dtor(tsk_object_t * self) { - tmedia_content_dummy_t *dummy = self; - if (dummy){ - /* deinit base */ - tmedia_content_deinit(TMEDIA_CONTENT(dummy)); - /* deinit self */ - TSK_OBJECT_SAFE_FREE(dummy->data); - } - - return self; + tmedia_content_dummy_t *dummy = self; + if (dummy) { + /* deinit base */ + tmedia_content_deinit(TMEDIA_CONTENT(dummy)); + /* deinit self */ + TSK_OBJECT_SAFE_FREE(dummy->data); + } + + return self; } /* object definition */ -static const tsk_object_def_t tmedia_content_dummy_def_s = -{ - sizeof(tmedia_content_dummy_t), - tmedia_content_dummy_ctor, - tmedia_content_dummy_dtor, - tsk_null, +static const tsk_object_def_t tmedia_content_dummy_def_s = { + sizeof(tmedia_content_dummy_t), + tmedia_content_dummy_ctor, + tmedia_content_dummy_dtor, + tsk_null, }; /* plugin definition*/ -static const tmedia_content_plugin_def_t tmedia_content_dummy_plugin_def_s = -{ - &tmedia_content_dummy_def_s, +static const tmedia_content_plugin_def_t tmedia_content_dummy_plugin_def_s = { + &tmedia_content_dummy_def_s, - "dummy", - tmedia_content_dummy_parse, - tmedia_content_dummy_get_data + "dummy", + tmedia_content_dummy_parse, + tmedia_content_dummy_get_data }; const tmedia_content_plugin_def_t *tmedia_content_dummy_plugin_def_t = &tmedia_content_dummy_plugin_def_s; @@ -275,83 +272,82 @@ const tmedia_content_plugin_def_t *tmedia_content_dummy_plugin_def_t = &tmedia_c tmedia_content_header_t* tmedia_content_header_create(const char* name, const char* value) { - tmedia_content_header_t* header = tsk_object_new(tmedia_content_header_def_t); - const char* str; - - if (!header){ - TSK_DEBUG_ERROR("Failed to create new header object"); - return tsk_null; - } - header->name = tsk_strdup(name); - if (value && (str = strstr(value, ";"))){ - header->value = tsk_strndup(value, (tsk_size_t)(str - value)); - header->params = tsk_params_fromstring((str + 1), ";", tsk_true); - } - else{ - header->value = tsk_strdup(value); - } - - return header; + tmedia_content_header_t* header = tsk_object_new(tmedia_content_header_def_t); + const char* str; + + if (!header) { + TSK_DEBUG_ERROR("Failed to create new header object"); + return tsk_null; + } + header->name = tsk_strdup(name); + if (value && (str = strstr(value, ";"))) { + header->value = tsk_strndup(value, (tsk_size_t)(str - value)); + header->params = tsk_params_fromstring((str + 1), ";", tsk_true); + } + else { + header->value = tsk_strdup(value); + } + + return header; } int tmedia_content_header_deinit(tmedia_content_header_t* self) { - if (!self){ - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } + if (!self) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } - TSK_FREE(self->name); - TSK_FREE(self->value); - TSK_OBJECT_SAFE_FREE(self->params); + TSK_FREE(self->name); + TSK_FREE(self->value); + TSK_OBJECT_SAFE_FREE(self->params); - return 0; + return 0; } char* tmedia_content_header_tostring(const tmedia_content_header_t* self) { - char* string = tsk_null; - - if (!self){ - TSK_DEBUG_ERROR("Invalid parameter"); - return tsk_null; - } - - tsk_sprintf(&string, "%s: %s", self->name, self->value); - if (self->params){ - const tsk_list_item_t* item; - tsk_list_foreach(item, self->params){ - tsk_strcat_2(&string, ";%s=%s", TSK_PARAM(item->data)->name, TSK_PARAM(item->data)->value); - } - } - - return string; + char* string = tsk_null; + + if (!self) { + TSK_DEBUG_ERROR("Invalid parameter"); + return tsk_null; + } + + tsk_sprintf(&string, "%s: %s", self->name, self->value); + if (self->params) { + const tsk_list_item_t* item; + tsk_list_foreach(item, self->params) { + tsk_strcat_2(&string, ";%s=%s", TSK_PARAM(item->data)->name, TSK_PARAM(item->data)->value); + } + } + + return string; } /* constructor */ static tsk_object_t* tmedia_content_header_ctor(tsk_object_t * self, va_list * app) { - tmedia_content_header_t *header = self; - if (header){ - } - return self; + tmedia_content_header_t *header = self; + if (header) { + } + return self; } /* destructor */ static tsk_object_t* tmedia_content_header_dtor(tsk_object_t * self) { - tmedia_content_header_t *header = self; - if (header){ - tmedia_content_header_deinit(header); - } + tmedia_content_header_t *header = self; + if (header) { + tmedia_content_header_deinit(header); + } - return self; + return self; } /* object definition */ -static const tsk_object_def_t tmedia_content_header_def_s = -{ - sizeof(tmedia_content_header_t), - tmedia_content_header_ctor, - tmedia_content_header_dtor, - tsk_null, +static const tsk_object_def_t tmedia_content_header_def_s = { + sizeof(tmedia_content_header_t), + tmedia_content_header_ctor, + tmedia_content_header_dtor, + tsk_null, }; const tsk_object_def_t *tmedia_content_header_def_t = &tmedia_content_header_def_s; diff --git a/tinyMEDIA/src/content/tmedia_content_cpim.c b/tinyMEDIA/src/content/tmedia_content_cpim.c index 8b36727..6fb9f32 100755 --- a/tinyMEDIA/src/content/tmedia_content_cpim.c +++ b/tinyMEDIA/src/content/tmedia_content_cpim.c @@ -2,19 +2,19 @@ /* #line 1 "./ragel/tmedia_content_cpim.rl" */ /* * Copyright (C) 2010-2015 Mamadou DIOP. -* +* * 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. * @@ -67,337 +67,349 @@ A complete message looks something like this: static int tmedia_content_cpim_parse(tmedia_content_t* self, const void* in_data, tsk_size_t in_size) { - int cs = 0; - const char *p = in_data; - const char *pe = p + in_size; - const char *eof = pe; - - const char *tag_start = tsk_null; - - char* hname = tsk_null; - char* hvalue = tsk_null; - tsk_bool_t parsing_mime_headers = tsk_true; - - TSK_RAGEL_DISABLE_WARNINGS_BEGIN() - -/* #line 84 "./src/content/tmedia_content_cpim.c" */ -static const char _tmedia_machine_content_cpim_actions[] = { - 0, 1, 0, 1, 3, 1, 4, 1, - 5, 2, 0, 4, 2, 0, 5, 2, - 1, 0, 2, 2, 0 -}; - -static const char _tmedia_machine_content_cpim_key_offsets[] = { - 0, 0, 14, 30, 32, 34, 35, 36, - 51, 52, 66, 82, 84, 86, 87, 88, - 103, 104, 104 -}; - -static const char _tmedia_machine_content_cpim_trans_keys[] = { - 33, 37, 39, 126, 42, 43, 45, 46, - 48, 57, 65, 90, 95, 122, 32, 33, - 37, 39, 58, 126, 42, 43, 45, 46, - 48, 57, 65, 90, 95, 122, 32, 58, - 13, 32, 13, 10, 13, 33, 37, 39, - 126, 42, 43, 45, 46, 48, 57, 65, - 90, 95, 122, 10, 33, 37, 39, 126, - 42, 43, 45, 46, 48, 57, 65, 90, - 95, 122, 32, 33, 37, 39, 58, 126, - 42, 43, 45, 46, 48, 57, 65, 90, - 95, 122, 32, 58, 13, 32, 13, 10, - 13, 33, 37, 39, 126, 42, 43, 45, - 46, 48, 57, 65, 90, 95, 122, 10, - 0 -}; - -static const char _tmedia_machine_content_cpim_single_lengths[] = { - 0, 4, 6, 2, 2, 1, 1, 5, - 1, 4, 6, 2, 2, 1, 1, 5, - 1, 0, 0 -}; - -static const char _tmedia_machine_content_cpim_range_lengths[] = { - 0, 5, 5, 0, 0, 0, 0, 5, - 0, 5, 5, 0, 0, 0, 0, 5, - 0, 0, 0 -}; - -static const char _tmedia_machine_content_cpim_index_offsets[] = { - 0, 0, 10, 22, 25, 28, 30, 32, - 43, 45, 55, 67, 70, 73, 75, 77, - 88, 90, 91 -}; - -static const char _tmedia_machine_content_cpim_indicies[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 3, 3, 4, 3, - 3, 3, 3, 3, 3, 1, 5, 6, - 1, 8, 6, 7, 10, 9, 11, 1, - 12, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 1, 14, 1, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 1, 16, - 17, 17, 17, 18, 17, 17, 17, 17, - 17, 17, 1, 19, 20, 1, 22, 20, - 21, 24, 23, 25, 1, 26, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 1, - 28, 1, 29, 30, 0 -}; - -static const char _tmedia_machine_content_cpim_trans_targs[] = { - 2, 0, 3, 2, 4, 3, 4, 5, - 6, 5, 6, 7, 8, 2, 9, 10, - 11, 10, 12, 11, 12, 13, 14, 13, - 14, 15, 16, 10, 17, 18, 18 -}; - -static const char _tmedia_machine_content_cpim_trans_actions[] = { - 15, 0, 3, 0, 3, 0, 0, 1, - 9, 0, 5, 0, 0, 1, 0, 18, - 3, 0, 3, 0, 0, 1, 9, 0, - 5, 0, 0, 1, 0, 1, 0 -}; - -static const char _tmedia_machine_content_cpim_eof_actions[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 12, 7 -}; - -static const int tmedia_machine_content_cpim_start = 1; -static const int tmedia_machine_content_cpim_first_final = 17; -static const int tmedia_machine_content_cpim_error = 0; - -static const int tmedia_machine_content_cpim_en_main = 1; - - -/* #line 142 "./ragel/tmedia_content_cpim.rl" */ - (void)(eof); - (void)(tmedia_machine_content_cpim_first_final); - (void)(tmedia_machine_content_cpim_error); - (void)(tmedia_machine_content_cpim_en_main); - -/* #line 180 "./src/content/tmedia_content_cpim.c" */ - { - cs = tmedia_machine_content_cpim_start; - } - -/* #line 147 "./ragel/tmedia_content_cpim.rl" */ - -/* #line 187 "./src/content/tmedia_content_cpim.c" */ - { - int _klen; - unsigned int _trans; - const char *_acts; - unsigned int _nacts; - const char *_keys; - - if ( p == pe ) - goto _test_eof; - if ( cs == 0 ) - goto _out; + int cs = 0; + const char *p = in_data; + const char *pe = p + in_size; + const char *eof = pe; + + const char *tag_start = tsk_null; + + char* hname = tsk_null; + char* hvalue = tsk_null; + tsk_bool_t parsing_mime_headers = tsk_true; + + TSK_RAGEL_DISABLE_WARNINGS_BEGIN() + + /* #line 84 "./src/content/tmedia_content_cpim.c" */ + static const char _tmedia_machine_content_cpim_actions[] = { + 0, 1, 0, 1, 3, 1, 4, 1, + 5, 2, 0, 4, 2, 0, 5, 2, + 1, 0, 2, 2, 0 + }; + + static const char _tmedia_machine_content_cpim_key_offsets[] = { + 0, 0, 14, 30, 32, 34, 35, 36, + 51, 52, 66, 82, 84, 86, 87, 88, + 103, 104, 104 + }; + + static const char _tmedia_machine_content_cpim_trans_keys[] = { + 33, 37, 39, 126, 42, 43, 45, 46, + 48, 57, 65, 90, 95, 122, 32, 33, + 37, 39, 58, 126, 42, 43, 45, 46, + 48, 57, 65, 90, 95, 122, 32, 58, + 13, 32, 13, 10, 13, 33, 37, 39, + 126, 42, 43, 45, 46, 48, 57, 65, + 90, 95, 122, 10, 33, 37, 39, 126, + 42, 43, 45, 46, 48, 57, 65, 90, + 95, 122, 32, 33, 37, 39, 58, 126, + 42, 43, 45, 46, 48, 57, 65, 90, + 95, 122, 32, 58, 13, 32, 13, 10, + 13, 33, 37, 39, 126, 42, 43, 45, + 46, 48, 57, 65, 90, 95, 122, 10, + 0 + }; + + static const char _tmedia_machine_content_cpim_single_lengths[] = { + 0, 4, 6, 2, 2, 1, 1, 5, + 1, 4, 6, 2, 2, 1, 1, 5, + 1, 0, 0 + }; + + static const char _tmedia_machine_content_cpim_range_lengths[] = { + 0, 5, 5, 0, 0, 0, 0, 5, + 0, 5, 5, 0, 0, 0, 0, 5, + 0, 0, 0 + }; + + static const char _tmedia_machine_content_cpim_index_offsets[] = { + 0, 0, 10, 22, 25, 28, 30, 32, + 43, 45, 55, 67, 70, 73, 75, 77, + 88, 90, 91 + }; + + static const char _tmedia_machine_content_cpim_indicies[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 3, 3, 4, 3, + 3, 3, 3, 3, 3, 1, 5, 6, + 1, 8, 6, 7, 10, 9, 11, 1, + 12, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 1, 14, 1, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 1, 16, + 17, 17, 17, 18, 17, 17, 17, 17, + 17, 17, 1, 19, 20, 1, 22, 20, + 21, 24, 23, 25, 1, 26, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 1, + 28, 1, 29, 30, 0 + }; + + static const char _tmedia_machine_content_cpim_trans_targs[] = { + 2, 0, 3, 2, 4, 3, 4, 5, + 6, 5, 6, 7, 8, 2, 9, 10, + 11, 10, 12, 11, 12, 13, 14, 13, + 14, 15, 16, 10, 17, 18, 18 + }; + + static const char _tmedia_machine_content_cpim_trans_actions[] = { + 15, 0, 3, 0, 3, 0, 0, 1, + 9, 0, 5, 0, 0, 1, 0, 18, + 3, 0, 3, 0, 0, 1, 9, 0, + 5, 0, 0, 1, 0, 1, 0 + }; + + static const char _tmedia_machine_content_cpim_eof_actions[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 12, 7 + }; + + static const int tmedia_machine_content_cpim_start = 1; + static const int tmedia_machine_content_cpim_first_final = 17; + static const int tmedia_machine_content_cpim_error = 0; + + static const int tmedia_machine_content_cpim_en_main = 1; + + + /* #line 142 "./ragel/tmedia_content_cpim.rl" */ + (void)(eof); + (void)(tmedia_machine_content_cpim_first_final); + (void)(tmedia_machine_content_cpim_error); + (void)(tmedia_machine_content_cpim_en_main); + + /* #line 180 "./src/content/tmedia_content_cpim.c" */ + { + cs = tmedia_machine_content_cpim_start; + } + + /* #line 147 "./ragel/tmedia_content_cpim.rl" */ + + /* #line 187 "./src/content/tmedia_content_cpim.c" */ + { + int _klen; + unsigned int _trans; + const char *_acts; + unsigned int _nacts; + const char *_keys; + + if ( p == pe ) { + goto _test_eof; + } + if ( cs == 0 ) { + goto _out; + } _resume: - _keys = _tmedia_machine_content_cpim_trans_keys + _tmedia_machine_content_cpim_key_offsets[cs]; - _trans = _tmedia_machine_content_cpim_index_offsets[cs]; - - _klen = _tmedia_machine_content_cpim_single_lengths[cs]; - if ( _klen > 0 ) { - const char *_lower = _keys; - const char *_mid; - const char *_upper = _keys + _klen - 1; - while (1) { - if ( _upper < _lower ) - break; - - _mid = _lower + ((_upper-_lower) >> 1); - if ( (*p) < *_mid ) - _upper = _mid - 1; - else if ( (*p) > *_mid ) - _lower = _mid + 1; - else { - _trans += (_mid - _keys); - goto _match; - } - } - _keys += _klen; - _trans += _klen; - } - - _klen = _tmedia_machine_content_cpim_range_lengths[cs]; - if ( _klen > 0 ) { - const char *_lower = _keys; - const char *_mid; - const char *_upper = _keys + (_klen<<1) - 2; - while (1) { - if ( _upper < _lower ) - break; - - _mid = _lower + (((_upper-_lower) >> 1) & ~1); - if ( (*p) < _mid[0] ) - _upper = _mid - 2; - else if ( (*p) > _mid[1] ) - _lower = _mid + 2; - else { - _trans += ((_mid - _keys)>>1); - goto _match; - } - } - _trans += _klen; - } + _keys = _tmedia_machine_content_cpim_trans_keys + _tmedia_machine_content_cpim_key_offsets[cs]; + _trans = _tmedia_machine_content_cpim_index_offsets[cs]; + + _klen = _tmedia_machine_content_cpim_single_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + _klen - 1; + while (1) { + if ( _upper < _lower ) { + break; + } + + _mid = _lower + ((_upper-_lower) >> 1); + if ( (*p) < *_mid ) { + _upper = _mid - 1; + } + else if ( (*p) > *_mid ) { + _lower = _mid + 1; + } + else { + _trans += (_mid - _keys); + goto _match; + } + } + _keys += _klen; + _trans += _klen; + } + + _klen = _tmedia_machine_content_cpim_range_lengths[cs]; + if ( _klen > 0 ) { + const char *_lower = _keys; + const char *_mid; + const char *_upper = _keys + (_klen<<1) - 2; + while (1) { + if ( _upper < _lower ) { + break; + } + + _mid = _lower + (((_upper-_lower) >> 1) & ~1); + if ( (*p) < _mid[0] ) { + _upper = _mid - 2; + } + else if ( (*p) > _mid[1] ) { + _lower = _mid + 2; + } + else { + _trans += ((_mid - _keys)>>1); + goto _match; + } + } + _trans += _klen; + } _match: - _trans = _tmedia_machine_content_cpim_indicies[_trans]; - cs = _tmedia_machine_content_cpim_trans_targs[_trans]; - - if ( _tmedia_machine_content_cpim_trans_actions[_trans] == 0 ) - goto _again; - - _acts = _tmedia_machine_content_cpim_actions + _tmedia_machine_content_cpim_trans_actions[_trans]; - _nacts = (unsigned int) *_acts++; - while ( _nacts-- > 0 ) - { - switch ( *_acts++ ) - { - case 0: -/* #line 67 "./ragel/tmedia_content_cpim.rl" */ - { - tag_start = p; - } - break; - case 1: -/* #line 71 "./ragel/tmedia_content_cpim.rl" */ - { - parsing_mime_headers = tsk_true; - } - break; - case 2: -/* #line 75 "./ragel/tmedia_content_cpim.rl" */ - { - parsing_mime_headers = tsk_false; - } - break; - case 3: -/* #line 79 "./ragel/tmedia_content_cpim.rl" */ - { - TSK_PARSER_SET_STRING(hname); - } - break; - case 4: -/* #line 83 "./ragel/tmedia_content_cpim.rl" */ - { - tmedia_content_header_t* header; - TSK_PARSER_SET_STRING(hvalue); - header = tmedia_content_header_create(hname, hvalue); - TSK_FREE(hname); TSK_FREE(hvalue); - - if(parsing_mime_headers){ - if(!TMEDIA_CONTENT_CPIM(self)->m_headers){ - TMEDIA_CONTENT_CPIM(self)->m_headers = tsk_list_create(); - } - tsk_list_push_back_data(TMEDIA_CONTENT_CPIM(self)->m_headers, (void**)&header); - } - else{ - if(!TMEDIA_CONTENT_CPIM(self)->h_headers){ - TMEDIA_CONTENT_CPIM(self)->h_headers = tsk_list_create(); - } - tsk_list_push_back_data(TMEDIA_CONTENT_CPIM(self)->h_headers, (void**)&header); - } - } - break; -/* #line 307 "./src/content/tmedia_content_cpim.c" */ - } - } + _trans = _tmedia_machine_content_cpim_indicies[_trans]; + cs = _tmedia_machine_content_cpim_trans_targs[_trans]; + + if ( _tmedia_machine_content_cpim_trans_actions[_trans] == 0 ) { + goto _again; + } + + _acts = _tmedia_machine_content_cpim_actions + _tmedia_machine_content_cpim_trans_actions[_trans]; + _nacts = (unsigned int) *_acts++; + while ( _nacts-- > 0 ) { + switch ( *_acts++ ) { + case 0: + /* #line 67 "./ragel/tmedia_content_cpim.rl" */ + { + tag_start = p; + } + break; + case 1: + /* #line 71 "./ragel/tmedia_content_cpim.rl" */ + { + parsing_mime_headers = tsk_true; + } + break; + case 2: + /* #line 75 "./ragel/tmedia_content_cpim.rl" */ + { + parsing_mime_headers = tsk_false; + } + break; + case 3: + /* #line 79 "./ragel/tmedia_content_cpim.rl" */ + { + TSK_PARSER_SET_STRING(hname); + } + break; + case 4: + /* #line 83 "./ragel/tmedia_content_cpim.rl" */ + { + tmedia_content_header_t* header; + TSK_PARSER_SET_STRING(hvalue); + header = tmedia_content_header_create(hname, hvalue); + TSK_FREE(hname); + TSK_FREE(hvalue); + + if(parsing_mime_headers) { + if(!TMEDIA_CONTENT_CPIM(self)->m_headers) { + TMEDIA_CONTENT_CPIM(self)->m_headers = tsk_list_create(); + } + tsk_list_push_back_data(TMEDIA_CONTENT_CPIM(self)->m_headers, (void**)&header); + } + else { + if(!TMEDIA_CONTENT_CPIM(self)->h_headers) { + TMEDIA_CONTENT_CPIM(self)->h_headers = tsk_list_create(); + } + tsk_list_push_back_data(TMEDIA_CONTENT_CPIM(self)->h_headers, (void**)&header); + } + } + break; + /* #line 307 "./src/content/tmedia_content_cpim.c" */ + } + } _again: - if ( cs == 0 ) - goto _out; - if ( ++p != pe ) - goto _resume; - _test_eof: {} - if ( p == eof ) - { - const char *__acts = _tmedia_machine_content_cpim_actions + _tmedia_machine_content_cpim_eof_actions[cs]; - unsigned int __nacts = (unsigned int) *__acts++; - while ( __nacts-- > 0 ) { - switch ( *__acts++ ) { - case 0: -/* #line 67 "./ragel/tmedia_content_cpim.rl" */ - { - tag_start = p; - } - break; - case 5: -/* #line 103 "./ragel/tmedia_content_cpim.rl" */ - { - int len = (int)(p - tag_start); - if(len && tag_start){ - if(TMEDIA_CONTENT_CPIM(self)->e){ - TSK_OBJECT_SAFE_FREE(TMEDIA_CONTENT_CPIM(self)->e); \ - } - TMEDIA_CONTENT_CPIM(self)->e = tsk_buffer_create(tag_start, len); - } - } - break; -/* #line 341 "./src/content/tmedia_content_cpim.c" */ - } - } - } - - _out: {} - } - -/* #line 148 "./ragel/tmedia_content_cpim.rl" */ - TSK_RAGEL_DISABLE_WARNINGS_END() - - TSK_FREE(hname); - TSK_FREE(hvalue); - - if( cs < -/* #line 356 "./src/content/tmedia_content_cpim.c" */ -17 -/* #line 153 "./ragel/tmedia_content_cpim.rl" */ - ){ - TSK_DEBUG_ERROR("Failed to parse CPIM content"); - return -1; - } - - return 0; + if ( cs == 0 ) { + goto _out; + } + if ( ++p != pe ) { + goto _resume; + } +_test_eof: { + } + if ( p == eof ) { + const char *__acts = _tmedia_machine_content_cpim_actions + _tmedia_machine_content_cpim_eof_actions[cs]; + unsigned int __nacts = (unsigned int) *__acts++; + while ( __nacts-- > 0 ) { + switch ( *__acts++ ) { + case 0: + /* #line 67 "./ragel/tmedia_content_cpim.rl" */ + { + tag_start = p; + } + break; + case 5: + /* #line 103 "./ragel/tmedia_content_cpim.rl" */ + { + int len = (int)(p - tag_start); + if(len && tag_start) { + if(TMEDIA_CONTENT_CPIM(self)->e) { + TSK_OBJECT_SAFE_FREE(TMEDIA_CONTENT_CPIM(self)->e); + \ + } + TMEDIA_CONTENT_CPIM(self)->e = tsk_buffer_create(tag_start, len); + } + } + break; + /* #line 341 "./src/content/tmedia_content_cpim.c" */ + } + } + } + +_out: { + } + } + + /* #line 148 "./ragel/tmedia_content_cpim.rl" */ + TSK_RAGEL_DISABLE_WARNINGS_END() + + TSK_FREE(hname); + TSK_FREE(hvalue); + + if( cs < + /* #line 356 "./src/content/tmedia_content_cpim.c" */ + 17 + /* #line 153 "./ragel/tmedia_content_cpim.rl" */ + ) { + TSK_DEBUG_ERROR("Failed to parse CPIM content"); + return -1; + } + + return 0; } static tsk_buffer_t* tmedia_content_cpim_get_data(tmedia_content_t* self) { - tsk_buffer_t* data = tsk_buffer_create_null(); - tmedia_content_cpim_t *cpim = TMEDIA_CONTENT_CPIM(self); - const tsk_list_item_t* item; - /* - m: Content-type: Message/CPIM - s: - h: (message-metadata-headers) - s: - e: (encapsulated MIME message-body) - x: MIME security multipart message wrapper - */ - if(cpim->m_headers){ - tsk_list_foreach(item, cpim->m_headers){ - char* hstring = tmedia_content_header_tostring(TMEDIA_CONTENT_HEADER(item->data)); - tsk_buffer_append_2(data, TSK_LIST_IS_LAST(cpim->m_headers, item) ? "%s\r\n\r\n" : "%s\r\n", hstring); - TSK_FREE(hstring); - } - } - if(cpim->h_headers){ - tsk_list_foreach(item, cpim->h_headers){ - char* hstring = tmedia_content_header_tostring(TMEDIA_CONTENT_HEADER(item->data)); - tsk_buffer_append_2(data, TSK_LIST_IS_LAST(cpim->h_headers, item) ? "%s\r\n\r\n" : "%s\r\n", hstring); - TSK_FREE(hstring); - } - } - if(cpim->e){ - tsk_buffer_append(data, TSK_BUFFER_DATA(cpim->e), TSK_BUFFER_SIZE(cpim->e)); - } - if(cpim->x){ - tsk_buffer_append(data, TSK_BUFFER_DATA(cpim->x), TSK_BUFFER_SIZE(cpim->x)); - } - - return data; + tsk_buffer_t* data = tsk_buffer_create_null(); + tmedia_content_cpim_t *cpim = TMEDIA_CONTENT_CPIM(self); + const tsk_list_item_t* item; + /* + m: Content-type: Message/CPIM + s: + h: (message-metadata-headers) + s: + e: (encapsulated MIME message-body) + x: MIME security multipart message wrapper + */ + if(cpim->m_headers) { + tsk_list_foreach(item, cpim->m_headers) { + char* hstring = tmedia_content_header_tostring(TMEDIA_CONTENT_HEADER(item->data)); + tsk_buffer_append_2(data, TSK_LIST_IS_LAST(cpim->m_headers, item) ? "%s\r\n\r\n" : "%s\r\n", hstring); + TSK_FREE(hstring); + } + } + if(cpim->h_headers) { + tsk_list_foreach(item, cpim->h_headers) { + char* hstring = tmedia_content_header_tostring(TMEDIA_CONTENT_HEADER(item->data)); + tsk_buffer_append_2(data, TSK_LIST_IS_LAST(cpim->h_headers, item) ? "%s\r\n\r\n" : "%s\r\n", hstring); + TSK_FREE(hstring); + } + } + if(cpim->e) { + tsk_buffer_append(data, TSK_BUFFER_DATA(cpim->e), TSK_BUFFER_SIZE(cpim->e)); + } + if(cpim->x) { + tsk_buffer_append(data, TSK_BUFFER_DATA(cpim->x), TSK_BUFFER_SIZE(cpim->x)); + } + + return data; } //================================================================================================= @@ -406,44 +418,42 @@ static tsk_buffer_t* tmedia_content_cpim_get_data(tmedia_content_t* self) /* constructor */ static tsk_object_t* tmedia_content_cpim_ctor(tsk_object_t * self, va_list * app) { - tmedia_content_cpim_t *cpim = self; - if(cpim){ - /* init base: called by tmedia_content_create() */ - /* init self */ - } - return self; + tmedia_content_cpim_t *cpim = self; + if(cpim) { + /* init base: called by tmedia_content_create() */ + /* init self */ + } + return self; } /* destructor */ static tsk_object_t* tmedia_content_cpim_dtor(tsk_object_t * self) -{ - tmedia_content_cpim_t *cpim = self; - if(cpim){ - /* deinit base */ - tmedia_content_deinit(TMEDIA_CONTENT(cpim)); - /* deinit self */ - TSK_OBJECT_SAFE_FREE(cpim->m_headers); - TSK_OBJECT_SAFE_FREE(cpim->h_headers); - TSK_OBJECT_SAFE_FREE(cpim->e); - TSK_OBJECT_SAFE_FREE(cpim->x); - } - - return self; +{ + tmedia_content_cpim_t *cpim = self; + if(cpim) { + /* deinit base */ + tmedia_content_deinit(TMEDIA_CONTENT(cpim)); + /* deinit self */ + TSK_OBJECT_SAFE_FREE(cpim->m_headers); + TSK_OBJECT_SAFE_FREE(cpim->h_headers); + TSK_OBJECT_SAFE_FREE(cpim->e); + TSK_OBJECT_SAFE_FREE(cpim->x); + } + + return self; } /* object definition */ -static const tsk_object_def_t tmedia_content_cpim_def_s = -{ - sizeof(tmedia_content_cpim_t), - tmedia_content_cpim_ctor, - tmedia_content_cpim_dtor, - tsk_null, +static const tsk_object_def_t tmedia_content_cpim_def_s = { + sizeof(tmedia_content_cpim_t), + tmedia_content_cpim_ctor, + tmedia_content_cpim_dtor, + tsk_null, }; /* plugin definition*/ -static const tmedia_content_plugin_def_t tmedia_content_cpim_plugin_def_s = -{ - &tmedia_content_cpim_def_s, +static const tmedia_content_plugin_def_t tmedia_content_cpim_plugin_def_s = { + &tmedia_content_cpim_def_s, - TMEDIA_CONTENT_CPIM_TYPE, - tmedia_content_cpim_parse, - tmedia_content_cpim_get_data + TMEDIA_CONTENT_CPIM_TYPE, + tmedia_content_cpim_parse, + tmedia_content_cpim_get_data }; const tmedia_content_plugin_def_t *tmedia_content_cpim_plugin_def_t = &tmedia_content_cpim_plugin_def_s;
\ No newline at end of file |