Add lookup table for message headers instead of doing rumpelstilskin lookup
[citadel.git] / citadel / serv_extensions.c
index 9f0bd25dcb365efe695ddff183519d3086f0caf9..9984e23cf23c2308610be2c7205f5e6448b4b240 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Citadel Dynamic Loading Module
+ * Citadel Extension Loader
  * Written by Brian Costello <btx@calyx.net>
  *
- * Copyright (c) 1987-2011 by the citadel.org team
+ * Copyright (c) 1987-2015 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 3.
  * GNU General Public License for more details.
  */
 
-#include "sysdep.h"
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-#include <limits.h>
-#include <ctype.h>
-#include <syslog.h>
 #include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "serv_extensions.h"
-#include "sysdep_decls.h"
-#include "msgbase.h"
-#include "config.h"
 
+#include "sysdep_decls.h"
 #include "modules/crypto/serv_crypto.h"        /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
 
+#include "serv_extensions.h"
 #include "ctdl_module.h"
+#include "config.h"
 
 
 int DebugModules = 0;
@@ -42,12 +30,6 @@ int DebugModules = 0;
  * Structure defentitions for hook tables
  */
 
-typedef struct __LogDebugEntry {
-       CtdlDbgFunction F;
-       const char *Name;
-       long Len;
-       const int *LogP;
-} LogDebugEntry;
 HashList *LogDebugEntryTable = NULL;
 
 typedef struct LogFunctionHook LogFunctionHook;
@@ -120,7 +102,7 @@ UserFunctionHook *UserHookTable = NULL;
 typedef struct MessageFunctionHook MessageFunctionHook;
 struct MessageFunctionHook {
        MessageFunctionHook *next;
-       int (*h_function_pointer) (struct CtdlMessage *msg);
+       int (*h_function_pointer) (struct CtdlMessage *msg, recptypes *recps);
        int eventtype;
 };
 MessageFunctionHook *MessageHookTable = NULL;
@@ -317,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;
@@ -392,52 +358,6 @@ void CtdlSetDebugLogFacilities(const char **Str, long n)
                DeleteHashPos(&Pos);
        }
 }
-void cmd_log_get(char *argbuf)
-{
-       long HKLen;
-       const char *ch;
-       HashPos *Pos;
-       void *vptr;
-
-       if (CtdlAccessCheck(ac_aide)) return;
-
-       cprintf("%d Log modules enabled:\n", LISTING_FOLLOWS);
-
-       Pos = GetNewHashPos(LogDebugEntryTable, 0);
-
-       while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) {
-               LogDebugEntry *E = (LogDebugEntry*)vptr;
-               cprintf("%s|%d\n", ch, *E->LogP);
-       }
-       
-       DeleteHashPos(&Pos);
-       cprintf("000\n");
-}
-void cmd_log_set(char *argbuf)
-{
-       void *vptr;
-       int lset;
-       int wlen;
-       char which[SIZ] = "";
-
-       if (CtdlAccessCheck(ac_aide)) return;
-
-       wlen = extract_token(which, argbuf, 0, '|', sizeof(which));
-       if (wlen < 0) wlen = 0;
-       lset = extract_int(argbuf, 1);
-       if (lset != 0) lset = 1;
-       if (GetHash(LogDebugEntryTable, which, wlen, &vptr) && 
-           (vptr != NULL))
-       {
-               LogDebugEntry *E = (LogDebugEntry*)vptr;
-               E->F(lset);
-               cprintf("%d %s|%d\n", CIT_OK, which, lset);
-       }
-       else {
-               cprintf("%d Log setting %s not known\n", 
-                       ERROR, which);
-       }
-}
 void CtdlDestroyDebugTable(void)
 {
 
@@ -795,7 +715,7 @@ void CtdlDestroyUserHooks(void)
 }
 
 
-void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
+void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *),
                                int EventType)
 {
 
@@ -813,7 +733,7 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
 }
 
 
-void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
+void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *),
                int EventType)
 {
        MessageFunctionHook *cur, *p, *last;
@@ -1196,7 +1116,7 @@ void CtdlRegisterServiceHook(int tcp_port,
        newfcn->ServiceName = ServiceName;
 
        if (sockpath != NULL) {
-               newfcn->msock = ctdl_uds_server(sockpath, config.c_maxsessions, error);
+               newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"), error);
                snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
        }
        else if (tcp_port <= 0) {       /* port -1 to disable */
@@ -1206,12 +1126,12 @@ void CtdlRegisterServiceHook(int tcp_port,
                return;
        }
        else {
-               newfcn->msock = ctdl_tcp_server(config.c_ip_addr,
+               newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"),
                                              tcp_port,
-                                             config.c_maxsessions
+                                             CtdlGetConfigInt("c_maxsessions")
                                              error);
                snprintf(message, SIZ, "TCP port %s:%d: (%s) ", 
-                        config.c_ip_addr, tcp_port, ServiceName);
+                        CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName);
        }
 
        if (newfcn->msock > 0) {
@@ -1444,7 +1364,7 @@ void PerformUserHooks(ctdluser *usbuf, int EventType)
        }
 }
 
-int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
+int PerformMessageHooks(struct CtdlMessage *msg, recptypes *recps, int EventType)
 {
        MessageFunctionHook *fcn = NULL;
        int total_retval = 0;
@@ -1462,7 +1382,7 @@ int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
         */
        for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
                if (fcn->eventtype == EventType) {
-                       total_retval = total_retval + (*fcn->h_function_pointer) (msg);
+                       total_retval = total_retval + (*fcn->h_function_pointer) (msg, recps);
                }
        }
 
@@ -1564,9 +1484,6 @@ CTDL_MODULE_INIT(modules)
 {
        if (!threading) {
                CtdlRegisterDebugFlagHook(HKEY("modules"), DebugModulesEnable, &DebugModules);
-
-               CtdlRegisterProtoHook(cmd_log_get, "LOGP", "Print Log-parameters");
-               CtdlRegisterProtoHook(cmd_log_set, "LOGS", "Set Log-parameters");
        }
        return "modules";
 }