Wrote the first of 14 export functions (msgmain)
authorArt Cancro <ajc@citadel.org>
Tue, 11 Jul 2023 02:57:06 +0000 (17:57 -0900)
committerArt Cancro <ajc@citadel.org>
Tue, 11 Jul 2023 02:57:06 +0000 (17:57 -0900)
citadel/Makefile
citadel/utils/ctdldump.c

index 65a1e90c3fafb945a66db3e977d5b00afcc9cebc..5c5277a947173df323d11feff04de46b2eecf950 100644 (file)
@@ -10,7 +10,7 @@
 # config.mk is generated by ./configure
 include config.mk
 
-all := citserver setup ctdlmigrate sendcommand citmail chkpw chkpwd
+all := citserver setup ctdlmigrate sendcommand citmail chkpw chkpwd ctdldump
 all: $(all)
 
 SRCDIRS := $(wildcard server server/modules/*)
index cc18b44c3ff740215fe989379eb2128b22247e56..387dab2e55f6ecdc52f0a2aab95b3e8480840e27 100644 (file)
@@ -40,6 +40,28 @@ void *reallok(void *ptr, size_t size) {
 #define realloc reallok
 
 
+// convert a binary blob to hex (non-reentrant!!!)
+char *hexout(void *data, size_t len) {
+       static char *outbuf = NULL;
+       static size_t outlen = 0;
+       int i;
+       char ch;
+
+       if ((outbuf == NULL) || (outlen < (len * 2))) {
+               outbuf = reallok(outbuf, (len * 2));
+               outlen = len * 2;
+       }
+
+        for (i=0; i<len; ++i) {
+                ch = 0;
+                memcpy(&ch, data+i, 1);
+                sprintf((outbuf + (i * 2)), "%02X", (int) ch);
+        }
+
+       return(outbuf);
+}
+
+
 // Open a database environment
 DB_ENV *open_dbenv(char *dirname) {
 
@@ -116,61 +138,32 @@ void close_dbenv(DB_ENV *dbenv) {
 }
 
 
-
-#if 0
-
-
 // convert function for a message in msgmain
-void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
-       int32_t in_msgnum;
-       long out_msgnum;
-       memcpy(&in_msgnum, in_key->data, sizeof(in_msgnum));
-       out_msgnum = (long)in_msgnum;
+void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data) {
+       long in_msgnum;
 
-       if (in_key->size != 4) {
-               fprintf(stderr, "\033[31m\033[1m *** SOURCE DATABASE IS NOT 32-BIT *** ABORTING *** \033[0m\n");
+       if (in_key->size != sizeof(long)) {
+               fprintf(stderr, "\033[31m\033[1m *** BAD DATA *** ABORTING *** \033[0m\n");
                abort();
        }
 
+       memcpy(&in_msgnum, in_key->data, sizeof(in_msgnum));
+
        // If the msgnum is negative, we are looking at METADATA
        if (in_msgnum < 0) {
-               struct MetaData_32 *meta32 = (struct MetaData_32 *)in_data->data;
-
-               // fprintf(stderr, "\033[32m\033[1mMetadata: msgnum=%d , refcount=%d , content_type=\"%s\" , rfc822len=%d\033[0m\n", meta32->meta_msgnum, meta32->meta_refcount, meta32->meta_content_type, meta32->meta_rfc822_length);
-
-               out_key->size = sizeof(long);
-               out_key->data = realloc(out_key->data, out_key->size);
-               memcpy(out_key->data, &out_msgnum, sizeof(long));
-
-               out_data->size = sizeof(struct MetaData);
-               out_data->data = realloc(out_data->data, out_data->size);
-               struct MetaData *meta64 = (struct MetaData *)out_data->data;
-               memset(meta64, 0, sizeof(struct MetaData));
-               meta64->meta_msgnum             = (long)        meta32->meta_msgnum;
-               meta64->meta_refcount           = (int)         meta32->meta_refcount;
-               strcpy(meta64->meta_content_type,               meta32->meta_content_type);
-               meta64->meta_rfc822_length      = (long)        meta32->meta_rfc822_length;
+               struct MetaData *meta = (struct MetaData *)in_data->data;
+               printf("msgmeta|%ld|%d|%s|%ld\n", meta->meta_msgnum, meta->meta_refcount, meta->meta_content_type, meta->meta_rfc822_length);
        }
 
        // If the msgnum is positive, we are looking at a MESSAGE
        else if (in_msgnum > 0) {
-               out_key->size = sizeof(long);
-               out_key->data = realloc(out_key->data, out_key->size);
-               memcpy(out_key->data, &out_msgnum, sizeof(long));
-
-               // copy the message verbatim
-               out_data->size = in_data->size;
-               out_data->data = realloc(out_data->data, out_data->size);
-               memcpy(out_data->data, in_data->data, out_data->size);
-               // printf("\033[32m\033[1mMessage: %ld\033[0m\n", out_msgnum);
+               printf("msgtext|%s\n", hexout(in_data->data, in_data->size));
        }
 
        // If the msgnum is 0 it's probably not a valid record.
-       else {
-               // printf("\033[31mmsgmain: message number 0 is impossible, skipping this record\033[0m\n");
-       }
 }
 
+#if 0
 
 // convert function for a user record
 void export_users(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
@@ -447,44 +440,6 @@ void export_euidindex(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DB
        memcpy(out_data->data, &out_msgnum, sizeof(out_msgnum));
        memcpy(out_data->data+sizeof(out_msgnum), &out_roomnum, sizeof(out_roomnum));
        strcpy(out_data->data+sizeof(out_msgnum)+sizeof(out_roomnum), euid);
-
-
-       //int i;
-       //char ch;
-//
-       //printf("  in_key:             ");
-       //for (i=0; i<in_key->size; ++i) {
-               //ch = 0;
-               //memcpy(&ch, in_key->data+i, 1);
-               //printf("%02X ", (int) ch);
-       //}
-       //printf("\n");
-//
-       //printf(" out_key: ");
-       //for (i=0; i<out_key->size; ++i) {
-               //ch = 0;
-               //memcpy(&ch, out_key->data+i, 1);
-               //printf("%02X ", (int) ch);
-       //}
-       //printf("\n");
-//
-       //printf(" in_data:                         ");
-       //for (i=0; i<in_data->size; ++i) {
-               //ch = 0;
-               //memcpy(&ch, in_data->data+i, 1);
-       //      printf("%02X ", (int) ch);
-       //}
-       //printf("\n");
-//
-       //printf("out_data: ");
-       //for (i=0; i<out_data->size; ++i) {
-               //ch = 0;
-               //memcpy(&ch, out_data->data+i, 1);
-               //printf("%02X ", (int) ch);
-       //}
-       //printf("\n");
-
-
 }
 
 
@@ -541,12 +496,12 @@ void export_config(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *
 
 // For obsolete databases, zero all the output
 void zero_function(int which_cdb, DBT *in_key, DBT *in_data) {
-       printf("%d: \n", which_cdb);
+       //printf("Table %02x, keylen=%d, datalen=%d\n", which_cdb, in_key->size, in_data->size);
 }
 
 
 void (*export_functions[])(int which_cdb, DBT *in_key, DBT *in_data) = {
-       zero_function,          // CDB_MSGMAIN
+       export_msgmain,         // CDB_MSGMAIN
        zero_function,          // CDB_USERS
        zero_function,          // CDB_ROOMS
        zero_function,          // CDB_FLOORTAB