ctdldump: convert binary to base64 instead of hex
authorArt Cancro <ajc@citadel.org>
Wed, 12 Jul 2023 02:29:58 +0000 (17:29 -0900)
committerArt Cancro <ajc@citadel.org>
Wed, 12 Jul 2023 02:29:58 +0000 (17:29 -0900)
citadel/utils/ctdldump.c

index a5c64274fb8f3385a75623f77e5376caca650155..222545092fe189d2b0ca9b4afdcacef7ed7ddd2e 100644 (file)
@@ -40,8 +40,8 @@ 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) {
+// convert a binary blob to base64 (non-reentrant!)
+char *b64out(void *data, size_t len) {
        static char *outbuf = NULL;
        static size_t outlen = 0;
        int i;
@@ -52,12 +52,7 @@ char *hexout(void *data, size_t len) {
                outlen = len * 2;
        }
 
-        for (i=0; i<len; ++i) {
-                ch = 0;
-                memcpy(&ch, data+i, 1);
-                sprintf((outbuf + (i * 2)), "%02X", (int) ch);
-        }
-
+       CtdlEncodeBase64(outbuf, data, len, 0);
        return(outbuf);
 }
 
@@ -157,7 +152,7 @@ void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data) {
 
        // If the msgnum is positive, we are looking at a MESSAGE
        else if (in_msgnum > 0) {
-               printf("msgtext|%ld|%s|\n", in_msgnum, hexout(in_data->data, in_data->size));
+               printf("msgtext|%ld|%s|\n", in_msgnum, b64out(in_data->data, in_data->size));
        }
 
        // If the msgnum is 0 it's probably not a valid record.
@@ -181,7 +176,7 @@ void export_user(int which_cdb, DBT *in_key, DBT *in_data) {
                user->fullname,
                user->msgnum_bio,
                user->msgnum_pic,
-               hexout(user->emailaddrs, strlen(user->emailaddrs)),
+               b64out(user->emailaddrs, strlen(user->emailaddrs)),
                user->msgnum_inboxrules,
                user->lastproc_inboxrules
        );
@@ -298,7 +293,7 @@ void export_bigmsg(int which_cdb, DBT *in_key, DBT *in_data) {
        long msgnum;
 
        memcpy(&msgnum, in_key->data, sizeof(msgnum));
-       printf("bigmsg|%ld|%s|\n", msgnum, hexout(in_data->data, in_data->size));
+       printf("bigmsg|%ld|%s|\n", msgnum, b64out(in_data->data, in_data->size));
 }