// 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;
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;
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;
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;
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;
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;
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;
else errormessages = NewStrBuf();
StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
-
len = StrLength(portlist);
if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
else portlist = NewStrBuf();
}
-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;
}
-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;
}
-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;
}
-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;
}
-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);
}
-/* 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) {
}
-void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
-{
+void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order) {
XmsgFunctionHook *newfcn;
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);
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);
}
}
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) ();
}
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;
}
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;
}
(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);