Add lookup table for message headers instead of doing rumpelstilskin lookup
authorWilfried Goesgens <willi@arangodb.com>
Sun, 20 Dec 2015 21:18:29 +0000 (22:18 +0100)
committerWilfried Goesgens <willi@arangodb.com>
Sun, 20 Dec 2015 21:18:29 +0000 (22:18 +0100)
citadel/modules/ctdlproto/serv_messages.c
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_extensions.c

index ef1d70a7a4ef27de66fbe868fd98294f9ef880cd..88a893c494c8c000bd50e1a715db7c986fee3c28 100644 (file)
@@ -92,7 +92,6 @@ void cmd_msgs(char *cmdbuf)
        char tfield[256];
        char tvalue[256];
        int cm_ref = 0;
-       int i;
        int with_template = 0;
        struct CtdlMessage *template = NULL;
        char search_string[1024];
@@ -153,15 +152,21 @@ void cmd_msgs(char *cmdbuf)
                template->cm_anon_type = MES_NORMAL;
 
                while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
+                       eMsgField f;
+
                        long tValueLen;
-                       extract_token(tfield, buf, 0, '|', sizeof tfield);
-                       tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue);
-                       if (tValueLen >= 0) {
-                               for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) {
-                                               if (!strcasecmp(tfield, msgkeys[i])) {
-                                                       CM_SetField(template, i, tvalue, tValueLen);
-                                               }
+                       tValueLen = extract_token(tfield, buf, 0, '|', sizeof tfield);
+                       if ((tValueLen == 4) && GetFieldFromMnemonic(&f, tfield))
+                       {
+                               if (with_template == 1) {
+                                       tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue);
+                                       if (tValueLen >= 0) {
+                                               CM_SetField(template, f, tvalue, tValueLen);
                                        }
+                               }
+                               else {
+
+                               }
                        }
                }
                buffer_output();
index 0d91873c5c21212de8f2557daec582012f4f721f..93c673faa3c1a245962136cd48c36ebdcdb5757d 100644 (file)
@@ -45,7 +45,7 @@ int MessageDebugEnabled = 0;
  * These are the four-character field headers we use when outputting
  * messages in Citadel format (as opposed to RFC822 format).
  */
-char *msgkeys[] = {
+char *msgkeys[91] = {
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
@@ -80,8 +80,33 @@ char *msgkeys[] = {
        "wefw", /* W -> eWeferences   */
        NULL,   /* X */
        "cccc", /* Y -> eCarbonCopY   */
-       NULL    /* Z */
+       NULL   /* Z */
+
 };
+HashList *msgKeyLookup = NULL;
+
+int GetFieldFromMnemonic(eMsgField *f, const char* c)
+{
+       void *v = NULL;
+       if (GetHash(msgKeyLookup, c, 4, &v)) {
+               *f = (eMsgField) v;
+               return 1;
+       }
+       return 0;
+}
+
+void FillMsgKeyLookupTable(void)
+{
+       long i;
+
+       msgKeyLookup = NewHash (1, FourHash);
+
+       for (i=0; i < 91; i++) {
+               if (msgkeys[i] != NULL) {
+                       Put(msgKeyLookup, msgkeys[i], 4, (void*)i, reference_free_handler);
+               }
+       }
+}
 
 eMsgField FieldOrder[]  = {
 /* Important fields */
@@ -4120,6 +4145,7 @@ void SetMessageDebugEnabled(const int n)
 CTDL_MODULE_INIT(msgbase)
 {
        if (!threading) {
+               FillMsgKeyLookupTable();
                CtdlRegisterDebugFlagHook(HKEY("messages"), SetMessageDebugEnabled, &MessageDebugEnabled);
        }
 
index 4b53032eb75157e727d2b9bfcdcef85c9246f23b..34b5ec599a0f9463dbf44ebe2cfe7e467609432e 100644 (file)
@@ -73,6 +73,9 @@ struct addresses_to_be_filed {
 
 extern struct addresses_to_be_filed *atbf;
 
+int GetFieldFromMnemonic(eMsgField *f, const char* c);
+
+
 void memfmout (char *mptr, const char *nl);
 void output_mime_parts(char *);
 long send_message (struct CtdlMessage *);
index 568d9a3ae0275032f977296793b288dabe8aa912..9984e23cf23c2308610be2c7205f5e6448b4b240 100644 (file)
@@ -299,22 +299,6 @@ int DLoader_Exec_Cmd(char *cmdbuf)
        return 0;
 }
 
-long FourHash(const char *key, long length) 
-{
-       int i;
-       int ret = 0;
-       const unsigned char *ptr = (const unsigned char*)key;
-
-       for (i = 0; i < 4; i++, ptr ++) 
-               ret = (ret << 8) | 
-                       ( ((*ptr >= 'a') &&
-                          (*ptr <= 'z'))? 
-                         *ptr - 'a' + 'A': 
-                         *ptr);
-
-       return ret;
-}
-
 void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F, const int *LogP)
 {
        LogDebugEntry *E;