void btreeDestroyNodeBlock(void *data) { BTreeNode *node = (BTreeNode *)data; uint8_t i; if (node == NULL) { return; } for (i = 0; i < node->keyCount; i++) { if (node->keys[i] != NULL) { /* dbg_log(SEC_0130_BTREE, 9)(LOGSTDOUT,"[DEBUG]btreeDestroyNodeBlock: %d# size %d, addr %lx, %.*s\n", i, node->keySizes[i], node->keys[i], node->keySizes[i], node->keys[i]); */ keyFree(node->keys[i], LOC_BTREE_0170); } } if (GDB_IS_DIRTY(node->block)) { dbg_log(SEC_0130_BTREE, 0)(LOGSTDOUT, "error:btreeDestroyNodeBlock: Dirty node at offset %d has not been written to disk.\n", node->block->offset); } SAFE_FREE(node->children, LOC_BTREE_0171); SAFE_FREE(node->keySizes, LOC_BTREE_0172); SAFE_FREE(node->keys, LOC_BTREE_0173); SAFE_FREE(node, LOC_BTREE_0174); }
// idea was to use now to do time based expirations, but for now just expiring all temps immediately int keyLoop(unsigned long now) { int i; if (!keytableLast) { return 0; } // free any tmp keys for (i=0; i<KEY_MAX; i++) { if (!keytableTmp[i]) { continue; } keyFree(i); } keytableLast = 0; return 1; }
/*comment: write BTree Node into buffer*/ void btreeWriteNodeBlock(GdbBlock *block, uint8_t **buffer, uint32_t *size) { BTreeNode *node; uint8_t i; uint32_t counter = 0; uint8_t ** newKeys; uint16_t * newKeySizes; node = (BTreeNode *)block->detail; #if (SWITCH_ON == COMPRESS_MODE) /* Compress the node. */ if (node->keyCount >= 2) { __compressNode(node, &newKeys, &newKeySizes); } else { newKeys = node->keys; newKeySizes = node->keySizes; } #endif/*(SWITCH_ON == COMPRESS_MODE)*/ #if (SWITCH_OFF == COMPRESS_MODE) newKeys = node->keys; newKeySizes = node->keySizes; #endif/*(SWITCH_OFF == COMPRESS_MODE)*/ *size = __getNodeSize(node, newKeySizes); MEM_CHECK(*buffer = (uint8_t *)SAFE_MALLOC(*size, LOC_BTREE_0162)); gdbPut8(*buffer, &counter, node->keyCount); for (i = 0; i < node->tree->order; i++) { gdbPutOffset(*buffer, &counter, node->children[i]); } for (i = 0; i < node->tree->order - 1; i++) { gdbPut16(*buffer, &counter, newKeySizes[i]); } for (i = 0; i < node->tree->order - 1; i++) { if (newKeySizes[i] > 0) { memcpy(*buffer + counter, newKeys[i], newKeySizes[i]); counter += newKeySizes[i]; } } #if (SWITCH_ON == COMPRESS_MODE) if (node->keyCount >= 2) { /* Free up the arrays. */ for (i = 0; i < node->keyCount; i++) { if (newKeys[i] != NULL) { keyFree(newKeys[i], LOC_BTREE_0163); } } SAFE_FREE(newKeys, LOC_BTREE_0164); SAFE_FREE(newKeySizes, LOC_BTREE_0165); } #endif/*(SWITCH_ON == COMPRESS_MODE)*/ }
/*comment: read BTree Node out of buffer*/ void * btreeReadNodeBlock(GdbBlock *block, const uint8_t *buffer, void *extra) { BTreeNode *node; uint8_t i; uint32_t counter = 0; node = (BTreeNode *)btreeCreateNodeBlock(block, extra); //comment: tree and block of the node were set in btreeCreateNodeBlock //node->tree = (BTree *)extra; //node->block = block; node->keyCount = gdbGet8(buffer, &counter); for (i = 0; i < node->tree->order; i++) { node->children[i] = gdbGetOffset(buffer, &counter); } for (i = 0; i < node->tree->order - 1; i++) { node->keySizes[i] = gdbGet16(buffer, &counter); } for (i = 0; i < node->tree->order - 1; i++) { if (node->keySizes[i] > 0) { MEM_CHECK(node->keys[i] = keyNew(node->keySizes[i], LOC_BTREE_0158)); memcpy(node->keys[i], buffer + counter, node->keySizes[i]); counter += node->keySizes[i]; } } #if (SWITCH_ON == COMPRESS_MODE) if (node->keyCount >= 2) { uint8_t **newKeys; uint16_t *newKeySizes; __uncompressNode(node, &newKeys, &newKeySizes); /* Free up the compressed keys. */ for (i = 0; i < node->keyCount; i++) { if (node->keys[i] != NULL) { keyFree(node->keys[i], LOC_BTREE_0159); } } SAFE_FREE(node->keys, LOC_BTREE_0160); SAFE_FREE(node->keySizes, LOC_BTREE_0161); /* Move over the new arrays. */ node->keys = newKeys; node->keySizes = newKeySizes; } #endif/*(SWITCH_ON == COMPRESS_MODE)*/ return node; }