serv_extensions.c: style cleanup from 30,000 feet
authorArt Cancro <ajc@citadel.org>
Mon, 27 Nov 2023 21:43:38 +0000 (11:43 -1000)
committerArt Cancro <ajc@citadel.org>
Mon, 27 Nov 2023 21:43:38 +0000 (11:43 -1000)
No, I'm not takin a broader view of the code.  I'm actually on an airplane.

citadel/server/serv_extensions.c

index 33796ac97bf433f8a4845239949f9054b89f899e..8787beae805027c94b5d7336cea1e755473ea8dc 100644 (file)
@@ -2,7 +2,7 @@
 // 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-2021 by the citadel.org team
+// 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 <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;
@@ -32,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;
@@ -48,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;
@@ -62,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;
@@ -75,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;
@@ -87,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;
@@ -102,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;
@@ -212,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();
@@ -256,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;
@@ -280,30 +262,25 @@ void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority
 }
 
 
-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);
+       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;
@@ -313,12 +290,10 @@ void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptyp
 }
 
 
-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;
@@ -327,12 +302,10 @@ void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
 }
 
 
-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;
@@ -341,12 +314,10 @@ void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
 }
 
 
-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);
@@ -356,9 +327,8 @@ void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int
 }
 
 
-/* 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) {
@@ -371,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;
 
@@ -410,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);
@@ -449,7 +418,8 @@ void CtdlShutdownServiceHooks(void) {
                        if (cur->sockpath != NULL){
                                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);
                        }
                }
@@ -464,7 +434,7 @@ void PerformSessionHooks(int EventType) {
        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) ();
                }
@@ -487,25 +457,22 @@ int PerformMessageHooks(struct CtdlMessage *msg, struct recptypes *recps, int Ev
        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;
 }
 
@@ -520,8 +487,7 @@ 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;
 }
 
@@ -548,20 +514,17 @@ 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;
 }
 
 
-/*
- * "Start TLS" function that is (hopefully) adaptable for any protocol
- */
+// "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);