The encoding and decoding tables for Base64 are
authorArt Cancro <ajc@citadel.org>
Thu, 17 Jan 2008 20:29:27 +0000 (20:29 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 17 Jan 2008 20:29:27 +0000 (20:29 +0000)
no longer calculated at startup.  CtdlInitBase64Table() is removed.  The tables
are now hardcoded as 'const' arrays.  Not only will this eliminate the need to do
a startup calculation, but since it is now const we will get a nice clean segv if
some other code attempts to clobber them.

12 files changed:
citadel/citadel.c
citadel/citmail.c
citadel/getmail.c
citadel/sendcommand.c
citadel/server_main.c
citadel/setup.c
citadel/stress.c
citadel/userlist.c
citadel/whobbs.c
libcitadel/lib/libcitadel.h
libcitadel/lib/tools.c
webcit/webserver.c

index 700c732f21d00da4e9501855a282dd5d2a322ed9..4b12583689c1729ce810411a3e21361660726cfd 100644 (file)
@@ -1417,7 +1417,6 @@ int main(int argc, char **argv)
        eCrashParameters params;
 //     eCrashSymbolTable symbol_table;
 #endif
-       CtdlInitBase64Table();
        calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
 
 #ifdef HAVE_BACKTRACE
index f47d8f2ab3f43de5def3748793f3984b72acbf62..fea00e064c8f9c609ea1856d2cc4b80094f3501d 100644 (file)
@@ -184,8 +184,6 @@ int main(int argc, char **argv) {
        int read_recipients_from_headers = 0;
        char *add_these_recipients = NULL;
 
-       CtdlInitBase64Table();
-
        for (i=1; i<argc; ++i) {
                if (!strcmp(argv[i], "-d")) {
                        debug = 1;
index 664c81e08e20e8f9b37cf6145d0fa613ef951c5a..963a4f91552a86fd071617b4636a1b9f1764c8a0 100644 (file)
@@ -183,8 +183,6 @@ int main(int argc, char **argv)
        struct ctdlipcmessage *mret;
        char cret[SIZ];
 
-       CtdlInitBase64Table();
-
        strcpy(ctdl_home_directory, DEFAULT_PORT);
 
        /*
index 225b23a4c7a99ec989db0adf44e1428ba4dfbe95..3256a77be2c8694e1d7ebb09545d0fdaa8c55914 100644 (file)
@@ -179,8 +179,6 @@ int main(int argc, char **argv)
        int ret, err;
        int server_shutting_down = 0;
 
-       CtdlInitBase64Table();
-
        strcpy(ctdl_home_directory, DEFAULT_PORT);
 
        strcpy(cmd, "");
index a63564d17be70a6b0a63569bc6cb504c5dd8b28f..2be4109c57fdb124b2995844a123453d0a99306d 100644 (file)
@@ -99,7 +99,6 @@ int main(int argc, char **argv)
        /* initialise semaphores here. Patch by Matt and davew
         * its called here as they are needed by CtdlLogPrintf for thread safety
         */
-       CtdlInitBase64Table();
        InitialiseSemaphores();
        
        /* initialize the master context */
index fc64eb78e0586e1c998bc9075dc2a4a1100c5324..48df424963243ba4bbddb4103136c3012e7fbcca 100644 (file)
@@ -949,8 +949,6 @@ int main(int argc, char *argv[])
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
        
-       CtdlInitBase64Table();
-
        /* set an invalid setup type */
        setup_type = (-1);
 
index dfb98052ccf05a4101d29f4b470f3515257f83e5..d62ea3cb8dfcd11276857b8f42db9cddb9c4bbab 100644 (file)
@@ -299,8 +299,6 @@ int main(int argc, char** argv)
        int i;                  /* Counters */
        long runtime;           /* Run time for each thread */
 
-       CtdlInitBase64Table();
-
        /* Read argument list */
        for (i = 0; i < argc; i++) {
                if (!strcmp(argv[i], "-n")) {
index 388761b45249f85ee24b1786d19b2814fad0be24..33a0bc85fe27b290b6703cb40f16b5f796d5c89f 100644 (file)
@@ -77,7 +77,6 @@ int main(int argc, char **argv)
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
 
-       CtdlInitBase64Table();
        calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
 
        ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
index 9c0db8216e9383b22c8594b500fd23d46c297284..f4114bb55802da9686328108c23c7b765d6d2162 100644 (file)
@@ -75,8 +75,6 @@ int main(int argc, char **argv)
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
 
-       CtdlInitBase64Table();
-
        calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
 
        /* If this environment variable is set, we assume that the program
index d74e80afb2870668c857db2c2032d18885e83606..2e3fa460609944289277473518e944826d0b5a5a 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 
-#define LIBCITADEL_VERSION_NUMBER      101
+#define LIBCITADEL_VERSION_NUMBER      102
 
 /*
  * Here's a bunch of stupid magic to make the MIME parser portable.
index 61e49f0d089de8fc528fab6ee3e6e54e4c5a29d2..606449da1d6ae270244b6b005025b6498e4a5c21 100644 (file)
 #define FALSE 0
 
 typedef unsigned char byte;          /* Byte type */
-static byte dtable[256] = "\0";              /* base64 decode table */
-static byte etable[256] = "\0";              /* base64 encode table */
+
+/* Base64 encoding table */
+const byte etable[256] = {
+       65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
+       82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103,
+       104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
+       118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43,
+       47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* Base64 decoding table */
+const byte dtable[256] = {
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 62, 128, 128, 128, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+       128, 128, 128, 0, 128, 128, 128, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+       12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 128, 128, 128,
+       128, 128, 128, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+       40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
+       128, 128, 0
+};
+
 
 char *safestrncpy(char *dest, const char *src, size_t n)
 {
@@ -262,42 +300,6 @@ unsigned long extract_unsigned_long(const char *source, int parmnum)
 }
 
 
-
-void CtdlInitBase64Table(void)
-{
-       int i;
-       /*      Fill dtable with character encodings.  */
-       
-       /* Encoder Table */
-       for (i = 0; i < 26; i++) {
-               etable[i] = 'A' + i;
-               etable[26 + i] = 'a' + i;
-       }
-       for (i = 0; i < 10; i++) {
-               etable[52 + i] = '0' + i;
-       }
-       etable[62] = '+';
-       etable[63] = '/';
-       
-       /* Decoder Table */
-       for (i = 0; i < 255; i++) {
-               dtable[i] = 0x80;
-       }
-       for (i = 'A'; i <= 'Z'; i++) {
-               dtable[i] = 0 + (i - 'A');
-       }
-       for (i = 'a'; i <= 'z'; i++) {
-               dtable[i] = 26 + (i - 'a');
-       }
-       for (i = '0'; i <= '9'; i++) {
-               dtable[i] = 52 + (i - '0');
-       }
-       dtable['+'] = 62;
-       dtable['/'] = 63;
-       dtable['='] = 0;
-}
-
-
 /*
  * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by John Walker.
  */
index 0b47ce87200dcc33d240a055f2bd82166ffd5254..91dc4d12ee84bbf049598b6c7a81f57ae934b315 100644 (file)
@@ -822,7 +822,6 @@ int main(int argc, char **argv)
        if (chdir(webcitdir) != 0) {
                perror("chdir");
        }       
-       CtdlInitBase64Table();
        initialize_viewdefs();
        initialize_axdefs();