summaryrefslogtreecommitdiffstats
path: root/tinySIGCOMP/src/tcomp_deflatedata.ghost.c
diff options
context:
space:
mode:
Diffstat (limited to 'tinySIGCOMP/src/tcomp_deflatedata.ghost.c')
-rwxr-xr-xtinySIGCOMP/src/tcomp_deflatedata.ghost.c263
1 files changed, 132 insertions, 131 deletions
diff --git a/tinySIGCOMP/src/tcomp_deflatedata.ghost.c b/tinySIGCOMP/src/tcomp_deflatedata.ghost.c
index bfcb927..2446b6e 100755
--- a/tinySIGCOMP/src/tcomp_deflatedata.ghost.c
+++ b/tinySIGCOMP/src/tcomp_deflatedata.ghost.c
@@ -2,19 +2,19 @@
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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.
*
@@ -77,26 +77,25 @@ I suppose we would like to compress this message "libsigcomp":
#define GHOST_BYTECODE1_SIZE (GHOST_VERSION_INDEX + 1)
-static const char* DeflateData_deflate_bytecode1_ghost =
-{
- "\xff\xff" // Circular buffer Size (CBS)
- "\xff\xff" // State Memory Size (DMS)
- "\x00\x05" // See 'libsigcomp/asm/deflate.asm'
- "\xff\xff" // (CBS + strlen(input))
-
- "\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00"
- "\x00\x0a\x00\x01\x00\x0b\x00\x01\x00\x0d\x00\x01\x00\x0f\x00\x01\x00\x11\x00\x02\x00\x13\x00\x02\x00\x17\x00\x02\x00\x1b"
- "\x00\x02\x00\x1f\x00\x03\x00\x23\x00\x03\x00\x2b\x00\x03\x00\x33\x00\x03\x00\x3b\x00\x04\x00\x43\x00\x04\x00\x53\x00\x04"
- "\x00\x63\x00\x04\x00\x73\x00\x05\x00\x83\x00\x05\x00\xa3\x00\x05\x00\xc3\x00\x05\x00\xe3\x00\x00\x01\x02\x00\x00\x00\x01"
- "\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x01\x00\x05\x00\x01\x00\x07\x00\x02\x00\x09\x00\x02\x00\x0d\x00\x03"
- "\x00\x11\x00\x03\x00\x19\x00\x04\x00\x21\x00\x04\x00\x31\x00\x05\x00\x41\x00\x05\x00\x61\x00\x06\x00\x81\x00\x06\x00\xc1"
- "\x00\x07\x01\x01\x00\x07\x01\x81\x00\x08\x02\x01\x00\x08\x03\x01\x00\x09\x04\x01\x00\x09\x06\x01\x00\x0a\x08\x01\x00\x0a"
- "\x0c\x01\x00\x0b\x10\x01\x00\x0b\x18\x01\x00\x0c\x20\x01\x00\x0c\x30\x01\x00\x0d\x40\x01\x00\x0d\x60\x01"
-
- "\xff\xff" // HASH_LEN
- "\xff\xff" // SMS
- "\xff" // [CPB+DMS+SMS]
- "\xff" // SigComp Version
+static const char* DeflateData_deflate_bytecode1_ghost = {
+ "\xff\xff" // Circular buffer Size (CBS)
+ "\xff\xff" // State Memory Size (DMS)
+ "\x00\x05" // See 'libsigcomp/asm/deflate.asm'
+ "\xff\xff" // (CBS + strlen(input))
+
+ "\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00"
+ "\x00\x0a\x00\x01\x00\x0b\x00\x01\x00\x0d\x00\x01\x00\x0f\x00\x01\x00\x11\x00\x02\x00\x13\x00\x02\x00\x17\x00\x02\x00\x1b"
+ "\x00\x02\x00\x1f\x00\x03\x00\x23\x00\x03\x00\x2b\x00\x03\x00\x33\x00\x03\x00\x3b\x00\x04\x00\x43\x00\x04\x00\x53\x00\x04"
+ "\x00\x63\x00\x04\x00\x73\x00\x05\x00\x83\x00\x05\x00\xa3\x00\x05\x00\xc3\x00\x05\x00\xe3\x00\x00\x01\x02\x00\x00\x00\x01"
+ "\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x01\x00\x05\x00\x01\x00\x07\x00\x02\x00\x09\x00\x02\x00\x0d\x00\x03"
+ "\x00\x11\x00\x03\x00\x19\x00\x04\x00\x21\x00\x04\x00\x31\x00\x05\x00\x41\x00\x05\x00\x61\x00\x06\x00\x81\x00\x06\x00\xc1"
+ "\x00\x07\x01\x01\x00\x07\x01\x81\x00\x08\x02\x01\x00\x08\x03\x01\x00\x09\x04\x01\x00\x09\x06\x01\x00\x0a\x08\x01\x00\x0a"
+ "\x0c\x01\x00\x0b\x10\x01\x00\x0b\x18\x01\x00\x0c\x20\x01\x00\x0c\x30\x01\x00\x0d\x40\x01\x00\x0d\x60\x01"
+
+ "\xff\xff" // HASH_LEN
+ "\xff\xff" // SMS
+ "\xff" // [CPB+DMS+SMS]
+ "\xff" // SigComp Version
};
@@ -109,36 +108,36 @@ static const char* DeflateData_deflate_bytecode1_ghost =
*/
void tcomp_deflatedata_createGhost(tcomp_deflatedata_t *deflatedata, uint32_t state_length, tcomp_params_t *params)
{
- uint8_t *ghostvalue_ptr = 0;
+ uint8_t *ghostvalue_ptr = 0;
#define GHOSTVALUE_AT(position) (ghostvalue_ptr + position)
- if(!deflatedata){
- TSK_DEBUG_ERROR("NULL defalte data.");
- return;
- }
-
- if(deflatedata->ghostState){
- TSK_DEBUG_ERROR("The defalte data already have a ghost state. This MUST never happen.");
- return;
- }
-
- tsk_safeobj_lock(deflatedata);
-
- deflatedata->ghostState = tcomp_state_create(state_length, GHOST_STATE_ADDRESS, GHOST_STATE_INSTRUCTION, GHOST_STATE_MIN_ACCESS_LEN, GHOST_STATE_RETENTION_PRIORITY);
- tcomp_buffer_allocBuff(deflatedata->ghostState->value, state_length);
- ghostvalue_ptr = tcomp_buffer_getBuffer(deflatedata->ghostState->value);
-
- memcpy(ghostvalue_ptr, DeflateData_deflate_bytecode1_ghost, GHOST_BYTECODE1_SIZE);
-
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_START_INDEX), DEFLATE_UDVM_CIRCULAR_START_INDEX );
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_DMS_INDEX), state_length+GHOST_STATE_ADDRESS );
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_END_INDEX), (DEFLATE_UDVM_CIRCULAR_START_INDEX + 0/*input_size*/) );
- // ......
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_HASH_LEN_INDEX), (state_length+8) );
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_SMS_INDEX), state_length );
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CPB_DMS_SMS_INDEX), tcomp_params_getParameters(params) ); // [cpb+dms+sms]+[version]
-
- // ------------------------------------------------------------
+ if(!deflatedata) {
+ TSK_DEBUG_ERROR("NULL defalte data.");
+ return;
+ }
+
+ if(deflatedata->ghostState) {
+ TSK_DEBUG_ERROR("The defalte data already have a ghost state. This MUST never happen.");
+ return;
+ }
+
+ tsk_safeobj_lock(deflatedata);
+
+ deflatedata->ghostState = tcomp_state_create(state_length, GHOST_STATE_ADDRESS, GHOST_STATE_INSTRUCTION, GHOST_STATE_MIN_ACCESS_LEN, GHOST_STATE_RETENTION_PRIORITY);
+ tcomp_buffer_allocBuff(deflatedata->ghostState->value, state_length);
+ ghostvalue_ptr = tcomp_buffer_getBuffer(deflatedata->ghostState->value);
+
+ memcpy(ghostvalue_ptr, DeflateData_deflate_bytecode1_ghost, GHOST_BYTECODE1_SIZE);
+
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_START_INDEX), DEFLATE_UDVM_CIRCULAR_START_INDEX );
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_DMS_INDEX), state_length+GHOST_STATE_ADDRESS );
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_END_INDEX), (DEFLATE_UDVM_CIRCULAR_START_INDEX + 0/*input_size*/) );
+ // ......
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_HASH_LEN_INDEX), (state_length+8) );
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_SMS_INDEX), state_length );
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CPB_DMS_SMS_INDEX), tcomp_params_getParameters(params) ); // [cpb+dms+sms]+[version]
+
+ // ------------------------------------------------------------
#define GHOST_DICT_CODE_INDEX (GHOST_BYTECODE1_SIZE)
#define GHOST_DICT_WORDS_INDEX (GHOST_DICT_CODE_INDEX + 2)
@@ -148,23 +147,25 @@ void tcomp_deflatedata_createGhost(tcomp_deflatedata_t *deflatedata, uint32_t st
# define GHOST_FIXME2_INDEX (GHOST_DICT_WORDS_INDEX + 0)
#endif
#define GHOST_DEFLATE_BYTECODE_INDEX (GHOST_FIXME2_INDEX + 4)
-#define GHOST_INPUT_INDEX (GHOST_DEFLATE_BYTECODE_INDEX + DEFLATE_BYTECODE_LEN)
+#define GHOST_INPUT_INDEX (GHOST_DEFLATE_BYTECODE_INDEX + DEFLATE_BYTECODE_LEN)
#if USE_DICTS_FOR_COMPRESSION
- BINARY_SET_2BYTES( ghostState->getStateValue()->getBuffer(GHOST_DICT_CODE_INDEX), DEFLATE_FIXME_DICT );
- if( DEFLATE_FIXME_DICT == DEFLATE_NO_DICT ){
- // Nothing to append
- }else{
- if(DEFLATE_FIXME_DICT == DEFLATE_SIP_DICT_ONLY){
- ::memmove( ghostState->getStateValue()->getBuffer(GHOST_DICT_WORDS_INDEX), RFC3485_DICTIONARY_SIP_IDENTIFIER, 4 );
- }else{
- assert(1==0);
- }
- }
+ BINARY_SET_2BYTES( ghostState->getStateValue()->getBuffer(GHOST_DICT_CODE_INDEX), DEFLATE_FIXME_DICT );
+ if( DEFLATE_FIXME_DICT == DEFLATE_NO_DICT ) {
+ // Nothing to append
+ }
+ else {
+ if(DEFLATE_FIXME_DICT == DEFLATE_SIP_DICT_ONLY) {
+ ::memmove( ghostState->getStateValue()->getBuffer(GHOST_DICT_WORDS_INDEX), RFC3485_DICTIONARY_SIP_IDENTIFIER, 4 );
+ }
+ else {
+ assert(1==0);
+ }
+ }
#endif
- memcpy( GHOSTVALUE_AT(GHOST_DEFLATE_BYTECODE_INDEX), (const char*)DEFLATEDATA_DEFLATE_BYTECODE, DEFLATE_BYTECODE_LEN );
+ memcpy( GHOSTVALUE_AT(GHOST_DEFLATE_BYTECODE_INDEX), (const char*)DEFLATEDATA_DEFLATE_BYTECODE, DEFLATE_BYTECODE_LEN );
- tsk_safeobj_unlock(deflatedata);
+ tsk_safeobj_unlock(deflatedata);
#undef GHOSTVALUE_AT
}
@@ -173,78 +174,78 @@ void tcomp_deflatedata_createGhost(tcomp_deflatedata_t *deflatedata, uint32_t st
*/
void tcomp_deflatedata_ackGhost(tcomp_compressordata_t *data, const tcomp_buffer_handle_t *stateid)
{
- tcomp_deflatedata_t *deflatedata = data;
- if(!deflatedata){
- TSK_DEBUG_ERROR("NULL defalte data.");
- return;
- }
-
- tsk_safeobj_lock(deflatedata);
-
- if(deflatedata->ghostState){
- /* Update ghost */
- if(tcomp_buffer_startsWith(deflatedata->ghostState->identifier, stateid)){
- /* END() + COPY() */
- tcomp_deflateStream_end(&(deflatedata->stream_acked));
- tcomp_deflateStream_copy(&(deflatedata->stream_acked), &(deflatedata->stream_1));
- deflatedata->stream_acked.stateful = 1;
- deflatedata->stream_acked.dataWaitingAck = 0;
- TSK_DEBUG_INFO("SigComp - ACKed State id=");
- tcomp_buffer_print(stateid);
- }
- }
-
- tsk_safeobj_unlock(deflatedata);
+ tcomp_deflatedata_t *deflatedata = data;
+ if(!deflatedata) {
+ TSK_DEBUG_ERROR("NULL defalte data.");
+ return;
+ }
+
+ tsk_safeobj_lock(deflatedata);
+
+ if(deflatedata->ghostState) {
+ /* Update ghost */
+ if(tcomp_buffer_startsWith(deflatedata->ghostState->identifier, stateid)) {
+ /* END() + COPY() */
+ tcomp_deflateStream_end(&(deflatedata->stream_acked));
+ tcomp_deflateStream_copy(&(deflatedata->stream_acked), &(deflatedata->stream_1));
+ deflatedata->stream_acked.stateful = 1;
+ deflatedata->stream_acked.dataWaitingAck = 0;
+ TSK_DEBUG_INFO("SigComp - ACKed State id=");
+ tcomp_buffer_print(stateid);
+ }
+ }
+
+ tsk_safeobj_unlock(deflatedata);
}
/**Updates a Ghost state.
*/
void tcomp_deflatedata_updateGhost(tcomp_deflatedata_t *deflatedata, const uint8_t *input_ptr, tsk_size_t input_size)
{
- uint32_t i;
- uint8_t *ghostvalue_ptr = 0;
+ uint32_t i;
+ uint8_t *ghostvalue_ptr = 0;
#define GHOSTVALUE_AT(position) (ghostvalue_ptr + position)
-
- if(!deflatedata){
- TSK_DEBUG_ERROR("NULL defalte data.");
- return;
- }
- if(!deflatedata->ghostState){
- TSK_DEBUG_ERROR("NULL ghost state.");
- return;
- }
+ if(!deflatedata) {
+ TSK_DEBUG_ERROR("NULL defalte data.");
+ return;
+ }
- tsk_safeobj_lock(deflatedata);
+ if(!deflatedata->ghostState) {
+ TSK_DEBUG_ERROR("NULL ghost state.");
+ return;
+ }
- ghostvalue_ptr = tcomp_buffer_getBuffer(deflatedata->ghostState->value);
+ tsk_safeobj_lock(deflatedata);
+
+ ghostvalue_ptr = tcomp_buffer_getBuffer(deflatedata->ghostState->value);
#define ZBUFF_LEN (0x0001 << deflatedata->zWindowBits)
- for(i = 0; i < input_size; i++){
+ for(i = 0; i < input_size; i++) {
#if 0
- *GHOSTVALUE_AT(GHOST_INPUT_INDEX + ghost_copy_offset) = 0x00;
+ *GHOSTVALUE_AT(GHOST_INPUT_INDEX + ghost_copy_offset) = 0x00;
#else
- *GHOSTVALUE_AT(GHOST_INPUT_INDEX + deflatedata->ghost_copy_offset) = input_ptr[i];
+ *GHOSTVALUE_AT(GHOST_INPUT_INDEX + deflatedata->ghost_copy_offset) = input_ptr[i];
#endif
- deflatedata->ghost_copy_offset = (deflatedata->ghost_copy_offset + 1) % ZBUFF_LEN;
- }
-
- /* Update Circular Buffer Index */
- TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_END_INDEX), (DEFLATE_UDVM_CIRCULAR_START_INDEX + deflatedata->ghost_copy_offset) );
-
- /* Compute State Identifier (20 bytes) */
- tcomp_state_makeValid(deflatedata->ghostState);
- // new state identifer not acked yet
- if(deflatedata->useOnlyACKedStates){
- deflatedata->stream_acked.stateful = 0;
- deflatedata->stream_acked.dataWaitingAck = 1;
- }
-
- TSK_DEBUG_INFO("SigComp - Making Ghost state valid with id = ");
- tcomp_buffer_print(deflatedata->ghostState->identifier);
-
- tsk_safeobj_unlock(deflatedata);
+ deflatedata->ghost_copy_offset = (deflatedata->ghost_copy_offset + 1) % ZBUFF_LEN;
+ }
+
+ /* Update Circular Buffer Index */
+ TSK_BINARY_SET_2BYTES( GHOSTVALUE_AT(GHOST_CB_END_INDEX), (DEFLATE_UDVM_CIRCULAR_START_INDEX + deflatedata->ghost_copy_offset) );
+
+ /* Compute State Identifier (20 bytes) */
+ tcomp_state_makeValid(deflatedata->ghostState);
+ // new state identifer not acked yet
+ if(deflatedata->useOnlyACKedStates) {
+ deflatedata->stream_acked.stateful = 0;
+ deflatedata->stream_acked.dataWaitingAck = 1;
+ }
+
+ TSK_DEBUG_INFO("SigComp - Making Ghost state valid with id = ");
+ tcomp_buffer_print(deflatedata->ghostState->identifier);
+
+ tsk_safeobj_unlock(deflatedata);
#undef GHOSTVALUE_AT
}
@@ -252,21 +253,21 @@ void tcomp_deflatedata_updateGhost(tcomp_deflatedata_t *deflatedata, const uint8
uint32_t* tcomp_deflatedata_getGhostCopyOffset(tcomp_deflatedata_t *deflatedata)
{
- if(!deflatedata){
- TSK_DEBUG_ERROR("NULL defalte data.");
- return 0;
- }
+ if(!deflatedata) {
+ TSK_DEBUG_ERROR("NULL defalte data.");
+ return 0;
+ }
- return &(deflatedata->ghost_copy_offset);
+ return &(deflatedata->ghost_copy_offset);
}
void tcomp_deflatedata_freeGhostState(tcomp_compressordata_t *data)
{
- tcomp_deflatedata_t *deflatedata = data;
- if(!deflatedata){
- TSK_DEBUG_ERROR("NULL defalte data.");
- return;
- }
+ tcomp_deflatedata_t *deflatedata = data;
+ if(!deflatedata) {
+ TSK_DEBUG_ERROR("NULL defalte data.");
+ return;
+ }
- TSK_OBJECT_SAFE_FREE(deflatedata->ghostState);
+ TSK_OBJECT_SAFE_FREE(deflatedata->ghostState);
}
OpenPOWER on IntegriCloud