]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/serv_extensions.c
serv_extensions.c: style cleanup from 30,000 feet
[citadel.git] / citadel / server / serv_extensions.c
index 6197d2880563869a7d5dce70dd2f2ef5aa0affa3..8787beae805027c94b5d7336cea1e755473ea8dc 100644 (file)
@@ -1,17 +1,11 @@
-/*
- * Citadel Extension Loader
- * Originally written by Brian Costello <btx@calyx.net>
- *
- * Copyright (c) 1987-2021 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
+// This began as a framework written by Brian Costello (btx) that loaded server extensions as dynamic modules.
+// We don't do it that way anymore but the concept lives on as a high degree of modularity in the server.
+// The functions in this file handle registration and execution of the server hooks used by static linked modules.
+//
+// Copyright (c) 1987-2023 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.
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <libcitadel.h>
 #include "sysdep_decls.h"
-#include "modules/crypto/serv_crypto.h"        /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
+#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"
 
 
-/*
- * Structure defentitions for hook tables
- */
-
+// Structure defentitions for hook tables
 typedef struct FixedOutputHook FixedOutputHook;
 struct FixedOutputHook {
        FixedOutputHook *next;
@@ -38,12 +29,10 @@ struct FixedOutputHook {
 FixedOutputHook *FixedOutputTable = NULL;
 
 
-/*
- * SessionFunctionHook extensions are used for any type of hook for which
- * the context in which it's being called (which is determined by the event
- * type) will make it obvious for the hook function to know where to look for
- * pertinent data.
- */
+// SessionFunctionHook extensions are used for any type of hook for which
+// the context in which it's being called (which is determined by the event
+// type) will make it obvious for the hook function to know where to look for
+// pertinent data.
 typedef struct SessionFunctionHook SessionFunctionHook;
 struct SessionFunctionHook {
        SessionFunctionHook *next;
@@ -54,11 +43,9 @@ struct SessionFunctionHook {
 SessionFunctionHook *SessionHookTable = NULL;
 
 
-/*
- * UserFunctionHook extensions are used for any type of hook which implements
- * an operation on a user or username (potentially) other than the one
- * operating the current session.
- */
+// UserFunctionHook extensions are used for any type of hook which implements
+// an operation on a user or username (potentially) other than the one
+// operating the current session.
 typedef struct UserFunctionHook UserFunctionHook;
 struct UserFunctionHook {
        UserFunctionHook *next;
@@ -68,10 +55,8 @@ struct UserFunctionHook {
 UserFunctionHook *UserHookTable = NULL;
 
 
-/*
- * MessageFunctionHook extensions are used for hooks which implement handlers
- * for various types of message operations (save, read, etc.)
- */
+// MessageFunctionHook extensions are used for hooks which implement handlers
+// for various types of message operations (save, read, etc.)
 typedef struct MessageFunctionHook MessageFunctionHook;
 struct MessageFunctionHook {
        MessageFunctionHook *next;
@@ -81,10 +66,8 @@ struct MessageFunctionHook {
 MessageFunctionHook *MessageHookTable = NULL;
 
 
-/*
- * DeleteFunctionHook extensions are used for hooks which get called when a
- * message is about to be deleted.
- */
+// DeleteFunctionHook extensions are used for hooks which get called when a
+// message is about to be deleted.
 typedef struct DeleteFunctionHook DeleteFunctionHook;
 struct DeleteFunctionHook {
        DeleteFunctionHook *next;
@@ -93,12 +76,10 @@ struct DeleteFunctionHook {
 DeleteFunctionHook *DeleteHookTable = NULL;
 
 
-/*
- * ExpressMessageFunctionHook extensions are used for hooks which implement
- * the sending of an instant message through various channels.  Any function
- * registered should return the number of recipients to whom the message was
- * successfully transmitted.
- */
+// ExpressMessageFunctionHook extensions are used for hooks which implement
+// the sending of an instant message through various channels.  Any function
+// registered should return the number of recipients to whom the message was
+// successfully transmitted.
 typedef struct XmsgFunctionHook XmsgFunctionHook;
 struct XmsgFunctionHook {
        XmsgFunctionHook *next;
@@ -108,10 +89,8 @@ struct XmsgFunctionHook {
 XmsgFunctionHook *XmsgHookTable = NULL;
 
 
-/*
- * RoomFunctionHook extensions are used for hooks which impliment room
- * processing functions when new messages are added.
- */
+// RoomFunctionHook extensions are used for hooks which implement room
+// processing functions when new messages are added.
 typedef struct RoomFunctionHook RoomFunctionHook;
 struct RoomFunctionHook {
        RoomFunctionHook *next;
@@ -119,15 +98,6 @@ struct RoomFunctionHook {
 };
 RoomFunctionHook *RoomHookTable = NULL;
 
-
-typedef struct SearchFunctionHook SearchFunctionHook;
-struct SearchFunctionHook {
-       SearchFunctionHook *next;
-       void (*fcn_ptr) (int *, long **, const char *);
-       char *name;
-};
-SearchFunctionHook *SearchFunctionHookTable = NULL;
-
 ServiceFunctionHook *ServiceHookTable = NULL;
 
 typedef struct ProtoFunctionHook ProtoFunctionHook;
@@ -167,8 +137,7 @@ ConstStr ErrPortHint  = { HKEY("If you want Citadel to provide you with that fun
                               " and disable the program that binds these ports.\n")};
 
 
-void LogPrintMessages(long err)
-{
+void LogPrintMessages(long err) {
        StrBuf *Message;
        StrBuf *List, *DetailList;
        ConstStr *Short, *Where, *Hint; 
@@ -218,8 +187,7 @@ void LogPrintMessages(long err)
 }
 
 
-void AddPortError(char *Port, char *ErrorMessage)
-{
+void AddPortError(char *Port, char *ErrorMessage) {
        long len;
 
        DetailErrorFlags |= ERR_PORT;
@@ -229,7 +197,6 @@ void AddPortError(char *Port, char *ErrorMessage)
        else errormessages = NewStrBuf();
        StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
 
-
        len = StrLength(portlist);
        if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
        else portlist = NewStrBuf();
@@ -237,8 +204,7 @@ void AddPortError(char *Port, char *ErrorMessage)
 }
 
 
-int DLoader_Exec_Cmd(char *cmdbuf)
-{
+int DLoader_Exec_Cmd(char *cmdbuf) {
        void *vP;
        ProtoFunctionHook *p;
 
@@ -251,8 +217,7 @@ int DLoader_Exec_Cmd(char *cmdbuf)
 }
 
 
-void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
-{
+void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc) {
        ProtoFunctionHook *p;
 
        if (ProtoHookList == NULL)
@@ -275,12 +240,10 @@ void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
 }
 
 
-void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority)
-{
+void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority) {
        SessionFunctionHook *newfcn;
 
-       newfcn = (SessionFunctionHook *)
-           malloc(sizeof(SessionFunctionHook));
+       newfcn = (SessionFunctionHook *) malloc(sizeof(SessionFunctionHook));
        newfcn->Priority = Priority;
        newfcn->h_function_pointer = fcn_ptr;
        newfcn->eventtype = EventType;
@@ -299,88 +262,25 @@ void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority
 }
 
 
-void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
-{
-       SessionFunctionHook *cur, *p, *last;
-       last = NULL;
-       cur = SessionHookTable;
-       while  (cur != NULL) {
-               if ((fcn_ptr == cur->h_function_pointer) &&
-                   (EventType == cur->eventtype))
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered session function (type %d)", EventType);
-                       p = cur->next;
-
-                       free(cur);
-                       cur = NULL;
-
-                       if (last != NULL)
-                               last->next = p;
-                       else 
-                               SessionHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType)
-{
+void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType) {
 
        UserFunctionHook *newfcn;
 
-       newfcn = (UserFunctionHook *)
-           malloc(sizeof(UserFunctionHook));
+       newfcn = (UserFunctionHook *) malloc(sizeof(UserFunctionHook));
        newfcn->next = UserHookTable;
        newfcn->h_function_pointer = fcn_ptr;
        newfcn->eventtype = EventType;
        UserHookTable = newfcn;
 
-       syslog(LOG_DEBUG, "extensions: registered a new user function (type %d)",
-                  EventType);
-}
-
-
-void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
-{
-       UserFunctionHook *cur, *p, *last;
-       last = NULL;
-       cur = UserHookTable;
-       while (cur != NULL) {
-               if ((fcn_ptr == cur->h_function_pointer) &&
-                   (EventType == cur->eventtype))
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered user function (type %d)", EventType);
-                       p = cur->next;
-
-                       free(cur);
-                       cur = NULL;
-
-                       if (last != NULL)
-                               last->next = p;
-                       else 
-                               UserHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
+       syslog(LOG_DEBUG, "extensions: registered a new user function (type %d)", EventType);
 }
 
 
-void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType)
-{
+void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType) {
 
        MessageFunctionHook *newfcn;
 
-       newfcn = (MessageFunctionHook *)
-           malloc(sizeof(MessageFunctionHook));
+       newfcn = (MessageFunctionHook *) malloc(sizeof(MessageFunctionHook));
        newfcn->next = MessageHookTable;
        newfcn->h_function_pointer = handler;
        newfcn->eventtype = EventType;
@@ -390,40 +290,10 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptyp
 }
 
 
-void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType)
-{
-       MessageFunctionHook *cur, *p, *last;
-       last = NULL;
-       cur = MessageHookTable;
-       while (cur != NULL) {
-               if ((handler == cur->h_function_pointer) &&
-                   (EventType == cur->eventtype))
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered message function (type %d)", EventType);
-                       p = cur->next;
-                       free(cur);
-                       cur = NULL;
-
-                       if (last != NULL)
-                               last->next = p;
-                       else 
-                               MessageHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
-{
+void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *)) {
        RoomFunctionHook *newfcn;
 
-       newfcn = (RoomFunctionHook *)
-           malloc(sizeof(RoomFunctionHook));
+       newfcn = (RoomFunctionHook *) malloc(sizeof(RoomFunctionHook));
        newfcn->next = RoomHookTable;
        newfcn->fcn_ptr = fcn_ptr;
        RoomHookTable = newfcn;
@@ -432,40 +302,10 @@ void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
 }
 
 
-void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
-{
-       RoomFunctionHook *cur, *p, *last;
-       last = NULL;
-       cur = RoomHookTable;
-       while (cur != NULL)
-       {
-               if (fcn_ptr == cur->fcn_ptr) {
-                       syslog(LOG_DEBUG, "extensions: unregistered room function");
-                       p = cur->next;
-
-                       free(cur);
-                       cur = NULL;
-
-                       if (last != NULL)
-                               last->next = p;
-                       else 
-                               RoomHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
-{
+void CtdlRegisterDeleteHook(void (*handler)(char *, long) ) {
        DeleteFunctionHook *newfcn;
 
-       newfcn = (DeleteFunctionHook *)
-           malloc(sizeof(DeleteFunctionHook));
+       newfcn = (DeleteFunctionHook *) malloc(sizeof(DeleteFunctionHook));
        newfcn->next = DeleteHookTable;
        newfcn->h_function_pointer = handler;
        DeleteHookTable = newfcn;
@@ -474,40 +314,10 @@ void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
 }
 
 
-void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
-{
-       DeleteFunctionHook *cur, *p, *last;
-
-       last = NULL;
-       cur = DeleteHookTable;
-       while (cur != NULL) {
-               if (handler == cur->h_function_pointer )
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered delete function");
-                       p = cur->next;
-                       free(cur);
-
-                       if (last != NULL)
-                               last->next = p;
-                       else
-                               DeleteHookTable = p;
-
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
-{
+void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) ) {
        FixedOutputHook *newfcn;
 
-       newfcn = (FixedOutputHook *)
-           malloc(sizeof(FixedOutputHook));
+       newfcn = (FixedOutputHook *) malloc(sizeof(FixedOutputHook));
        newfcn->next = FixedOutputTable;
        newfcn->h_function_pointer = handler;
        safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
@@ -517,38 +327,8 @@ void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int
 }
 
 
-void CtdlUnregisterFixedOutputHook(char *content_type)
-{
-       FixedOutputHook *cur, *p, *last;
-
-       last = NULL;
-       cur = FixedOutputTable;
-       while (cur != NULL) {
-               /* This will also remove duplicates if any */
-               if (!strcasecmp(content_type, cur->content_type)) {
-                       syslog(LOG_DEBUG, "extensions: unregistered fixed output function for %s", content_type);
-                       p = cur->next;
-                       free(cur);
-
-                       if (last != NULL)
-                               last->next = p;
-                       else
-                               FixedOutputTable = p;
-                       
-                       cur = p;
-               }
-               else
-               {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-/* returns nonzero if we found a hook and used it */
-int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
-{
+// returns nonzero if we found a hook and used it
+int PerformFixedOutputHooks(char *content_type, char *content, int content_length) {
        FixedOutputHook *fcn;
 
        for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
@@ -561,8 +341,7 @@ int PerformFixedOutputHooks(char *content_type, char *content, int content_lengt
 }
 
 
-void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
-{
+void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order) {
 
        XmsgFunctionHook *newfcn;
 
@@ -575,36 +354,6 @@ void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int o
 }
 
 
-void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
-{
-       XmsgFunctionHook *cur, *p, *last;
-
-       last = NULL;
-       cur = XmsgHookTable;
-       while (cur != NULL) {
-               /* This will also remove duplicates if any */
-               if (fcn_ptr == cur->h_function_pointer &&
-                   order == cur->order) {
-                       syslog(LOG_DEBUG, "extensions: unregistered x-msg function (priority %d)", order);
-                       p = cur->next;
-                       free(cur);
-
-                       if (last != NULL) {
-                               last->next = p;
-                       }
-                       else {
-                               XmsgHookTable = p;
-                       }
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
 void CtdlRegisterServiceHook(int tcp_port,
                             char *sockpath,
                             void (*h_greeting_function) (void),
@@ -630,7 +379,7 @@ void CtdlRegisterServiceHook(int tcp_port,
                newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"));
                snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath);
        }
-       else if (tcp_port <= 0) {       /* port -1 to disable */
+       else if (tcp_port <= 0) {       // port -1 to disable
                syslog(LOG_INFO, "extensions: service %s has been manually disabled, skipping", ServiceName);
                free (message);
                free(newfcn);
@@ -657,66 +406,20 @@ void CtdlRegisterServiceHook(int tcp_port,
 }
 
 
-void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
-                       void (*h_greeting_function) (void),
-                       void (*h_command_function) (void),
-                       void (*h_async_function) (void)
-                       )
-{
-       ServiceFunctionHook *cur, *p, *last;
-
-       last = NULL;
-       cur = ServiceHookTable;
-       while (cur != NULL) {
-               /* This will also remove duplicates if any */
-               if (h_greeting_function == cur->h_greeting_function &&
-                   h_command_function == cur->h_command_function &&
-                   h_async_function == cur->h_async_function &&
-                   tcp_port == cur->tcp_port && 
-                   !(sockpath && cur->sockpath && strcmp(sockpath, cur->sockpath)) )
-               {
-                       if (cur->msock > 0)
-                               close(cur->msock);
-                       if (sockpath) {
-                               syslog(LOG_INFO, "extensions: closed UNIX domain socket %s", sockpath);
-                               unlink(sockpath);
-                       } else if (tcp_port) {
-                               syslog(LOG_INFO, "extensions: closed TCP port %d", tcp_port);
-                       } else {
-                               syslog(LOG_INFO, "extensions: unregistered service \"%s\"", cur->ServiceName);
-                       }
-                       p = cur->next;
-                       free(cur);
-                       if (last != NULL)
-                               last->next = p;
-                       else
-                               ServiceHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlShutdownServiceHooks(void)
-{
-       /* sort of a duplicate of close_masters() but called earlier */
+// During shutdown we can close all of the listening sockets.
+void CtdlShutdownServiceHooks(void) {
        ServiceFunctionHook *cur;
 
        cur = ServiceHookTable;
-       while (cur != NULL) 
-       {
-               if (cur->msock != -1)
-               {
+       while (cur != NULL) {
+               if (cur->msock != -1) {
                        close(cur->msock);
                        cur->msock = -1;
                        if (cur->sockpath != NULL){
-                               syslog(LOG_INFO, "extensions: [%s] Closed UNIX domain socket %s", cur->ServiceName, cur->sockpath);
+                               syslog(LOG_INFO, "extensions: [%s] closed unix domain socket %s", cur->ServiceName, cur->sockpath);
                                unlink(cur->sockpath);
-                       } else {
+                       }
+                       else {
                                syslog(LOG_INFO, "extensions: [%s] closing service", cur->ServiceName);
                        }
                }
@@ -725,82 +428,21 @@ void CtdlShutdownServiceHooks(void)
 }
 
 
-void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
-{
-       SearchFunctionHook *newfcn;
-
-       if (!name || !fcn_ptr) {
-               return;
-       }
-       
-       newfcn = (SearchFunctionHook *)
-           malloc(sizeof(SearchFunctionHook));
-       newfcn->next = SearchFunctionHookTable;
-       newfcn->name = name;
-       newfcn->fcn_ptr = fcn_ptr;
-       SearchFunctionHookTable = newfcn;
-
-       syslog(LOG_DEBUG, "extensions: registered a new search function (%s)", name);
-}
-
-void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
-{
-       SearchFunctionHook *cur, *p, *last;
-       
-       last = NULL;
-       cur = SearchFunctionHookTable;
-       while (cur != NULL) {
-               if (fcn_ptr &&
-                   (cur->fcn_ptr == fcn_ptr) &&
-                   name && !strcmp(name, cur->name))
-               {
-                       syslog(LOG_DEBUG, "extensions: unregistered search function(%s)", name);
-                       p = cur->next;
-                       free (cur);
-                       if (last != NULL)
-                               last->next = p;
-                       else
-                               SearchFunctionHookTable = p;
-                       cur = p;
-               }
-               else {
-                       last = cur;
-                       cur = cur->next;
-               }
-       }
-}
-
-
-void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
-{
-       SearchFunctionHook *fcn = NULL;
-
-       for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
-               if (!func_name || !strcmp(func_name, fcn->name)) {
-                       (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
-                       return;
-               }
-       }
-       *num_msgs = 0;
-}
-
-
-void PerformSessionHooks(int EventType)
-{
+void PerformSessionHooks(int EventType) {
        SessionFunctionHook *fcn = NULL;
 
        for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
                if (fcn->eventtype == EventType) {
                        if (EventType == EVT_TIMER) {
-                               pthread_setspecific(MyConKey, NULL);    /* for every hook */
+                               pthread_setspecific(MyConKey, NULL);    // for every hook
                        }
                        (*fcn->h_function_pointer) ();
                }
        }
 }
 
-void PerformUserHooks(ctdluser *usbuf, int EventType)
-{
+
+void PerformUserHooks(ctdluser *usbuf, int EventType) {
        UserFunctionHook *fcn = NULL;
 
        for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
@@ -810,36 +452,32 @@ void PerformUserHooks(ctdluser *usbuf, int EventType)
        }
 }
 
-int PerformMessageHooks(struct CtdlMessage *msg, struct recptypes *recps, int EventType)
-{
+
+int PerformMessageHooks(struct CtdlMessage *msg, struct recptypes *recps, int EventType) {
        MessageFunctionHook *fcn = NULL;
        int total_retval = 0;
 
-       /* Other code may elect to protect this message from server-side
-        * handlers; if this is the case, don't do anything.
-        */
+       // Other code may elect to protect this message from server-side
+       // handlers; if this is the case, don't do anything.
        if (msg->cm_flags & CM_SKIP_HOOKS) {
                return(0);
        }
 
-       /* Otherwise, run all the hooks appropriate to this event type.
-        */
+       // Otherwise, run all the hooks appropriate to this event type.
        for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
                if (fcn->eventtype == EventType) {
                        total_retval = total_retval + (*fcn->h_function_pointer) (msg, recps);
                }
        }
 
-       /* Return the sum of the return codes from the hook functions.  If
-        * this is an EVT_BEFORESAVE event, a nonzero return code will cause
-        * the save operation to abort.
-        */
+       // Return the sum of the return codes from the hook functions.  If
+       // this is an EVT_BEFORESAVE event, a nonzero return code will cause
+       // the save operation to abort.
        return total_retval;
 }
 
 
-int PerformRoomHooks(struct ctdlroom *target_room)
-{
+int PerformRoomHooks(struct ctdlroom *target_room) {
        RoomFunctionHook *fcn;
        int total_retval = 0;
 
@@ -849,14 +487,12 @@ int PerformRoomHooks(struct ctdlroom *target_room)
                total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
        }
 
-       /* Return the sum of the return codes from the hook functions.
-        */
+       // Return the sum of the return codes from the hook functions.
        return total_retval;
 }
 
 
-void PerformDeleteHooks(char *room, long msgnum)
-{
+void PerformDeleteHooks(char *room, long msgnum) {
        DeleteFunctionHook *fcn;
 
        for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
@@ -865,8 +501,7 @@ void PerformDeleteHooks(char *room, long msgnum)
 }
 
 
-int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
-{
+int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg) {
        XmsgFunctionHook *fcn;
        int total_sent = 0;
        int p;
@@ -879,31 +514,24 @@ int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
                                                (sender, sender_email, recp, msg);
                        }
                }
-               /* Break out of the loop if a higher-priority function
-                * successfully delivered the message.  This prevents duplicate
-                * deliveries to local users simultaneously signed onto
-                * remote services.
-                */
+               // Break out of the loop if a higher-priority function
+               // successfully delivered the message.  This prevents duplicate
+               // deliveries to local users simultaneously signed onto
+               // remote services.
                if (total_sent) break;
        }
        return total_sent;
 }
 
 
-/*
- * Dirty hack until we impliment a hook mechanism for this
- */
-void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
-{
+// "Start TLS" function that is (hopefully) adaptable for any protocol
+void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response) {
 #ifdef HAVE_OPENSSL
        CtdlStartTLS (ok_response, nosup_response, error_response);
 #endif
 }
 
 
-CTDL_MODULE_INIT(modules)
-{
-       if (!threading) {
-       }
+CTDL_MODULE_INIT(modules) {
        return "modules";
 }