From c81067a9c169dff6dfaf789e726d1ef1bcd1121a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 11 Jul 2023 05:43:23 -0900 Subject: [PATCH] ctdldump: export floor records --- citadel/utils/ctdldump.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/citadel/utils/ctdldump.c b/citadel/utils/ctdldump.c index d3a3aa83a..d2d370d18 100644 --- a/citadel/utils/ctdldump.c +++ b/citadel/utils/ctdldump.c @@ -138,7 +138,7 @@ void close_dbenv(DB_ENV *dbenv) { } -// convert function for a message in msgmain +// export function for a message in msgmain void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data) { long in_msgnum; @@ -164,7 +164,7 @@ void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data) { } -// convert function for a user record +// export function for a user record void export_user(int which_cdb, DBT *in_key, DBT *in_data) { struct ctdluser *user = (struct ctdluser *)in_data->data; @@ -188,7 +188,7 @@ void export_user(int which_cdb, DBT *in_key, DBT *in_data) { } -// convert function for a room record +// export function for a room record void export_room(int which_cdb, DBT *in_key, DBT *in_data) { struct ctdlroom *room = (struct ctdlroom *)in_data->data; @@ -215,33 +215,27 @@ void export_room(int which_cdb, DBT *in_key, DBT *in_data) { } -#if 0 -// convert function for a floor record -void export_floors(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { +// export function for a floor record +void export_floor(int which_cdb, DBT *in_key, DBT *in_data) { - // the key is an "int", and "int" is 32-bits on both 32 and 64 bit platforms. - out_key->size = in_key->size; - out_key->data = realloc(out_key->data, out_key->size); - memcpy(out_key->data, in_key->data, in_key->size); + int floor_num; + memcpy(&floor_num, in_key->data, sizeof(int)); - // data - struct floor_32 *floor32 = (struct floor_32 *)in_data->data; - out_data->size = sizeof(struct floor); - out_data->data = realloc(out_data->data, out_data->size); - struct floor *floor64 = (struct floor *)out_data->data; - - // these are probably bit-for-bit identical, actually ... but we do it the "right" way anyway - floor64->f_flags = (unsigned short) floor32->f_flags; - strcpy(floor64->f_name, floor32->f_name); - floor64->f_ref_count = (int) floor32->f_ref_count; - floor64->f_ep.expire_mode = (int) floor32->f_ep.expire_mode; - floor64->f_ep.expire_value = (int) floor32->f_ep.expire_value; + struct floor *floor = (struct floor *)in_data->data; - // printf("\033[32m\033[1mFloor: %s\033[0m\n", floor64->f_name); + printf("floor|%d|%u|%s|%d|%d|%d\n", + floor_num, + floor->f_flags, + floor->f_name, + floor->f_ref_count, + floor->f_ep.expire_mode, + floor->f_ep.expire_value + ); } -// convert function for a msglist or a fulltext index record +#if 0 +// export function for a msglist or a fulltext index record // (both are indexed by a long and the data is arrays of longs) void export_msglists(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { int i; @@ -283,7 +277,7 @@ void export_msglists(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT } -// convert function for a visit record +// export function for a visit record void export_visits(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // data @@ -315,7 +309,7 @@ void export_visits(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT * } -// convert function for a directory record +// export function for a directory record void export_dir(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // the key is a string @@ -337,7 +331,7 @@ void export_dir(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out } -// convert function for a use table record +// export function for a use table record void export_usetable(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // the key is an int, which is the same size (32 bits) on both 32 and 64 bit systems @@ -360,7 +354,7 @@ void export_usetable(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT } -// convert function for large message texts +// export function for large message texts void export_bigmsgs(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // The key is a packed long @@ -387,7 +381,7 @@ void export_bigmsgs(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT } -// convert function for EUID Index records +// export function for EUID Index records void export_euidindex(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // The structure of an euidindex record *key* is: @@ -453,7 +447,7 @@ void export_usersbynumber(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key } -// convert function for a config record +// export function for a config record void export_config(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) { // the key is a string @@ -486,7 +480,7 @@ void (*export_functions[])(int which_cdb, DBT *in_key, DBT *in_data) = { export_msgmain, // CDB_MSGMAIN export_user, // CDB_USERS export_room, // CDB_ROOMS - zero_function, // CDB_FLOORTAB + export_floor, // CDB_FLOORTAB zero_function, // CDB_MSGLISTS zero_function, // CDB_VISIT zero_function, // CDB_DIRECTORY @@ -543,7 +537,7 @@ void export_table(int which_cdb, DB_ENV *src_dbenv) { memset(&in_data, 0, sizeof(DBT)); memset(&uncomp_data, 0, sizeof(DBT)); // decompressed input (the key doesn't change) - // Walk through the database, calling convert functions as we go and clearing buffers before each call. + // Walk through the database, calling export functions as we go and clearing buffers before each call. while (ret = src_dbcp->get(src_dbcp, &in_key, &in_data, DB_NEXT) == 0) { // If either the key or data are zero length, skip this record @@ -573,7 +567,7 @@ void export_table(int which_cdb, DB_ENV *src_dbenv) { } } - // Call the convert function registered to this table + // Call the export function registered to this table export_functions[which_cdb](which_cdb, &in_key, (compressed ? &uncomp_data : &in_data)); // Knowing the total number of rows isn't critical to the program. It's just for the user to know. -- 2.39.2