]> code.citadel.org Git - citadel.git/commitdiff
detect compressed records
authorArt Cancro <ajc@citadel.org>
Wed, 12 Apr 2023 15:37:32 +0000 (11:37 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 12 Apr 2023 15:37:32 +0000 (11:37 -0400)
citadel/server/database.h
citadel/server/server.h
citadel/utils/ctdl3264.c
citadel/utils/ctdl3264_prep.sh

index b9b76b715918992912c6ffab9937f52e1372ea53..e55d9f7e6024c856be592e2f55c1b9757de1ee4e 100644 (file)
@@ -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 */
index 62a2e9c7399e9033674891b9cc5ed03446abf437..2e8fca38de7f1b7ad8e6097a35eec904502838b2 100644 (file)
@@ -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
index d7d1ba8ce75d7d4feb8332d577900f57fd935b37..41d42317679296d77ecb296763935d3255650fd2 100644 (file)
@@ -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);
index 11750e41390c2eeb4749c8a33d81046cef9703a0..34c0d42dc95e732e7ac4d4a12c25c3f900283f72 100755 (executable)
@@ -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