From 4adba5bd6666db9731c1485f6638354ed201931b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 12 Apr 2023 11:37:32 -0400 Subject: [PATCH] detect compressed records --- citadel/server/database.h | 17 ----------------- citadel/server/server.h | 19 ++++++++++++++++++- citadel/utils/ctdl3264.c | 7 ++++++- citadel/utils/ctdl3264_prep.sh | 4 +++- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/citadel/server/database.h b/citadel/server/database.h index b9b76b715..e55d9f7e6 100644 --- a/citadel/server/database.h +++ b/citadel/server/database.h @@ -37,23 +37,6 @@ void cdb_cull_logs(void); void cdb_compact(void); -/* - * Database records beginning with this magic number are assumed to - * be compressed. In the event that a database record actually begins with - * this magic number, we *must* compress it whether we want to or not, - * because the fetch function will try to uncompress it anyway. - * - * (No need to #ifdef this stuff; it compiles ok even if zlib is not present - * and doesn't declare anything so it won't bloat the code) - */ -#define COMPRESS_MAGIC 0xc0ffeeee - -struct CtdlCompressHeader { - int magic; - size_t uncompressed_len; - size_t compressed_len; -}; - int CheckIfAlreadySeen(StrBuf *guid); #endif /* DATABASE_H */ diff --git a/citadel/server/server.h b/citadel/server/server.h index 62a2e9c73..2e8fca38d 100644 --- a/citadel/server/server.h +++ b/citadel/server/server.h @@ -93,9 +93,9 @@ struct visit { // 1. Either their values may change at some point after initial save, or // 2. They are merely caches of data which exist somewhere else, for speed. // DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w -struct MetaData { // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/* +struct MetaData { long meta_msgnum; // Message number in *local* message base int meta_refcount; // Number of rooms pointing to this msg char meta_content_type[64]; // Cached MIME content-type @@ -194,4 +194,21 @@ struct floor { }; +// Database records beginning with this magic number are assumed to +// be compressed. In the event that a database record actually begins with +// this magic number, we *must* compress it whether we want to or not, +// because the fetch function will try to uncompress it anyway. +// +// (No need to #ifdef this stuff; it compiles ok even if zlib is not present +// and doesn't declare anything so it won't bloat the code) +#define COMPRESS_MAGIC 0xc0ffeeee + +struct CtdlCompressHeader { + int magic; + size_t uncompressed_len; + size_t compressed_len; +}; + + + #endif // SERVER_H diff --git a/citadel/utils/ctdl3264.c b/citadel/utils/ctdl3264.c index d7d1ba8ce..41d423176 100644 --- a/citadel/utils/ctdl3264.c +++ b/citadel/utils/ctdl3264.c @@ -357,7 +357,12 @@ void convert_table(int which_cdb) { // Walk through the database, calling convert functions as we go and clearing buffers before each call. while (out_key.size = 0, out_data.size = 0, (ret = dbcp->get(dbcp, &in_key, &in_data, DB_NEXT)) == 0) { - // FIXME handle compressed records here + // Do we need to decompress? + static int32_t magic = COMPRESS_MAGIC; + if ( (in_data.size >= sizeof(magic)) && (!memcmp(in_data.data, &magic, sizeof(magic))) ) { + printf("\033[31m\033[1m COMPRESSED \033[0m\n"); + // FIXME do the decompression + } // Call the convert function registered to this table convert_functions[which_cdb](which_cdb, &in_key, &in_data, &out_key, &out_data); diff --git a/citadel/utils/ctdl3264_prep.sh b/citadel/utils/ctdl3264_prep.sh index 11750e413..34c0d42dc 100755 --- a/citadel/utils/ctdl3264_prep.sh +++ b/citadel/utils/ctdl3264_prep.sh @@ -7,13 +7,14 @@ SERVER_H=server/server.h # Generate the "32-bit" versions of these structures. -# Note that this is specifically converting "32-bit to 64-bit" -- NOT "any-to-any" +# Note that this is specifically for converting "32-bit to 64-bit" -- NOT "any-to-any" convert_struct() { start_line=$(cat ${SERVER_H} | egrep -n "^struct $1 {" | cut -d: -f1) tail +${start_line} ${SERVER_H} | sed '/};/q' \ | sed s/"^struct $1 {"/"struct ${1}_32 {"/g \ | sed s/"long "/"int32_t "/g \ | sed s/"time_t "/"int32_t "/g \ + | sed s/"size_t "/"int32_t "/g \ | sed s/"struct ExpirePolicy "/"struct ExpirePolicy_32 "/g echo '' @@ -32,5 +33,6 @@ convert_struct() { convert_struct "floor" convert_struct "visit" convert_struct "MetaData" + convert_struct "CtdlCompressHeader" ) >utils/ctdl3264_structs.h -- 2.39.2