2 * Citadel Extension Loader
3 * Originally written by Brian Costello <btx@calyx.net>
5 * Copyright (c) 1987-2020 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
20 #include <libcitadel.h>
21 #include "sysdep_decls.h"
22 #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
23 #include "serv_extensions.h"
24 #include "ctdl_module.h"
29 * Structure defentitions for hook tables
32 typedef struct FixedOutputHook FixedOutputHook;
33 struct FixedOutputHook {
34 FixedOutputHook *next;
35 char content_type[64];
36 void (*h_function_pointer) (char *, int);
38 FixedOutputHook *FixedOutputTable = NULL;
42 * SessionFunctionHook extensions are used for any type of hook for which
43 * the context in which it's being called (which is determined by the event
44 * type) will make it obvious for the hook function to know where to look for
47 typedef struct SessionFunctionHook SessionFunctionHook;
48 struct SessionFunctionHook {
49 SessionFunctionHook *next;
51 void (*h_function_pointer) (void);
54 SessionFunctionHook *SessionHookTable = NULL;
58 * UserFunctionHook extensions are used for any type of hook which implements
59 * an operation on a user or username (potentially) other than the one
60 * operating the current session.
62 typedef struct UserFunctionHook UserFunctionHook;
63 struct UserFunctionHook {
64 UserFunctionHook *next;
65 void (*h_function_pointer) (struct ctdluser *usbuf);
68 UserFunctionHook *UserHookTable = NULL;
72 * MessageFunctionHook extensions are used for hooks which implement handlers
73 * for various types of message operations (save, read, etc.)
75 typedef struct MessageFunctionHook MessageFunctionHook;
76 struct MessageFunctionHook {
77 MessageFunctionHook *next;
78 int (*h_function_pointer) (struct CtdlMessage *msg, recptypes *recps);
81 MessageFunctionHook *MessageHookTable = NULL;
85 * DeleteFunctionHook extensions are used for hooks which get called when a
86 * message is about to be deleted.
88 typedef struct DeleteFunctionHook DeleteFunctionHook;
89 struct DeleteFunctionHook {
90 DeleteFunctionHook *next;
91 void (*h_function_pointer) (char *target_room, long msgnum);
93 DeleteFunctionHook *DeleteHookTable = NULL;
97 * ExpressMessageFunctionHook extensions are used for hooks which implement
98 * the sending of an instant message through various channels. Any function
99 * registered should return the number of recipients to whom the message was
100 * successfully transmitted.
102 typedef struct XmsgFunctionHook XmsgFunctionHook;
103 struct XmsgFunctionHook {
104 XmsgFunctionHook *next;
105 int (*h_function_pointer) (char *, char *, char *, char *);
108 XmsgFunctionHook *XmsgHookTable = NULL;
112 * RoomFunctionHook extensions are used for hooks which impliment room
113 * processing functions when new messages are added.
115 typedef struct RoomFunctionHook RoomFunctionHook;
116 struct RoomFunctionHook {
117 RoomFunctionHook *next;
118 int (*fcn_ptr) (struct ctdlroom *);
120 RoomFunctionHook *RoomHookTable = NULL;
123 typedef struct SearchFunctionHook SearchFunctionHook;
124 struct SearchFunctionHook {
125 SearchFunctionHook *next;
126 void (*fcn_ptr) (int *, long **, const char *);
129 SearchFunctionHook *SearchFunctionHookTable = NULL;
131 CleanupFunctionHook *CleanupHookTable = NULL;
132 CleanupFunctionHook *EVCleanupHookTable = NULL;
134 ServiceFunctionHook *ServiceHookTable = NULL;
136 typedef struct ProtoFunctionHook ProtoFunctionHook;
137 struct ProtoFunctionHook {
138 void (*handler) (char *cmdbuf);
143 HashList *ProtoHookList = NULL;
146 #define ERR_PORT (1 << 1)
149 static StrBuf *portlist = NULL;
150 static StrBuf *errormessages = NULL;
153 long DetailErrorFlags;
154 ConstStr Empty = {HKEY("")};
155 char *ErrSubject = "Startup Problems";
156 ConstStr ErrGeneral[] = {
157 {HKEY("Citadel had trouble on starting up. ")},
158 {HKEY(" This means, Citadel won't be the service provider for a specific service you configured it to.\n\n"
159 "If you don't want Citadel to provide these services, turn them off in WebCit via: ")},
160 {HKEY("To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
161 "The errors returned by the system were:\n")},
162 {HKEY("You can recheck the above if you follow this faq item:\n"
163 "http://www.citadel.org/doku.php?id=faq:mastering_your_os:net#netstat")}
166 ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by Citadel Server.\n")};
167 ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")};
168 ConstStr ErrPortHint = { HKEY("If you want Citadel to provide you with that functionality, "
169 "check the output of \"netstat -lnp\" on Linux, or \"netstat -na\" on BSD"
170 " and disable the program that binds these ports.\n")};
173 void LogPrintMessages(long err)
176 StrBuf *List, *DetailList;
177 ConstStr *Short, *Where, *Hint;
180 Message = NewStrBufPlain(NULL, StrLength(portlist) + StrLength(errormessages));
182 DetailErrorFlags = DetailErrorFlags & ~err;
187 Short = &ErrPortShort;
188 Where = &ErrPortWhere;
191 DetailList = errormessages;
201 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[0]), 0);
202 StrBufAppendBufPlain(Message, CKEY(*Short), 0);
203 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[1]), 0);
204 StrBufAppendBufPlain(Message, CKEY(*Where), 0);
205 StrBufAppendBuf(Message, List, 0);
206 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
207 StrBufAppendBufPlain(Message, CKEY(*Hint), 0);
208 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
209 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[2]), 0);
210 StrBufAppendBuf(Message, DetailList, 0);
211 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
212 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[3]), 0);
214 syslog(LOG_EMERG, "extensions: %s", ChrPtr(Message));
215 syslog(LOG_EMERG, "extensions: %s", ErrSubject);
216 quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(Message), FMT_FIXED, ErrSubject);
218 FreeStrBuf(&Message);
220 FreeStrBuf(&DetailList);
224 void AddPortError(char *Port, char *ErrorMessage)
228 DetailErrorFlags |= ERR_PORT;
230 len = StrLength(errormessages);
231 if (len > 0) StrBufAppendBufPlain(errormessages, HKEY("; "), 0);
232 else errormessages = NewStrBuf();
233 StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
236 len = StrLength(portlist);
237 if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
238 else portlist = NewStrBuf();
239 StrBufAppendBufPlain(portlist, Port, -1, 0);
243 int DLoader_Exec_Cmd(char *cmdbuf)
246 ProtoFunctionHook *p;
248 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
249 p = (ProtoFunctionHook*) vP;
250 p->handler(&cmdbuf[5]);
257 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
259 ProtoFunctionHook *p;
261 if (ProtoHookList == NULL)
262 ProtoHookList = NewHash (1, FourHash);
265 p = (ProtoFunctionHook *)
266 malloc(sizeof(ProtoFunctionHook));
269 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
272 p->handler = handler;
276 Put(ProtoHookList, cmd, 4, p, NULL);
277 syslog(LOG_DEBUG, "extensions: registered server command %s (%s)", cmd, desc);
280 void CtdlDestroyProtoHooks(void)
283 DeleteHash(&ProtoHookList);
287 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
290 CleanupFunctionHook *newfcn;
292 newfcn = (CleanupFunctionHook *)
293 malloc(sizeof(CleanupFunctionHook));
294 newfcn->next = CleanupHookTable;
295 newfcn->h_function_pointer = fcn_ptr;
296 CleanupHookTable = newfcn;
298 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
302 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
304 CleanupFunctionHook *cur, *p, *last;
306 cur = CleanupHookTable;
309 if (fcn_ptr == cur->h_function_pointer)
311 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
320 CleanupHookTable = p;
331 void CtdlDestroyCleanupHooks(void)
333 CleanupFunctionHook *cur, *p;
335 cur = CleanupHookTable;
338 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
343 CleanupHookTable = NULL;
346 void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void))
349 CleanupFunctionHook *newfcn;
351 newfcn = (CleanupFunctionHook *)
352 malloc(sizeof(CleanupFunctionHook));
353 newfcn->next = EVCleanupHookTable;
354 newfcn->h_function_pointer = fcn_ptr;
355 EVCleanupHookTable = newfcn;
357 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
361 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void))
363 CleanupFunctionHook *cur, *p, *last;
365 cur = EVCleanupHookTable;
368 if (fcn_ptr == cur->h_function_pointer)
370 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
379 EVCleanupHookTable = p;
390 void CtdlDestroyEVCleanupHooks(void)
392 CleanupFunctionHook *cur, *p;
394 cur = EVCleanupHookTable;
397 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
399 cur->h_function_pointer();
403 EVCleanupHookTable = NULL;
409 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority)
411 SessionFunctionHook *newfcn;
413 newfcn = (SessionFunctionHook *)
414 malloc(sizeof(SessionFunctionHook));
415 newfcn->Priority = Priority;
416 newfcn->h_function_pointer = fcn_ptr;
417 newfcn->eventtype = EventType;
419 SessionFunctionHook **pfcn;
420 pfcn = &SessionHookTable;
421 while ((*pfcn != NULL) &&
422 ((*pfcn)->Priority < newfcn->Priority) &&
423 ((*pfcn)->next != NULL))
424 pfcn = &(*pfcn)->next;
426 newfcn->next = *pfcn;
429 syslog(LOG_DEBUG, "extensions: registered a new session function (type %d Priority %d)", EventType, Priority);
433 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
435 SessionFunctionHook *cur, *p, *last;
437 cur = SessionHookTable;
438 while (cur != NULL) {
439 if ((fcn_ptr == cur->h_function_pointer) &&
440 (EventType == cur->eventtype))
442 syslog(LOG_DEBUG, "extensions: unregistered session function (type %d)", EventType);
451 SessionHookTable = p;
461 void CtdlDestroySessionHooks(void)
463 SessionFunctionHook *cur, *p;
465 cur = SessionHookTable;
468 syslog(LOG_DEBUG, "extensions: destroyed session function");
473 SessionHookTable = NULL;
477 void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType)
480 UserFunctionHook *newfcn;
482 newfcn = (UserFunctionHook *)
483 malloc(sizeof(UserFunctionHook));
484 newfcn->next = UserHookTable;
485 newfcn->h_function_pointer = fcn_ptr;
486 newfcn->eventtype = EventType;
487 UserHookTable = newfcn;
489 syslog(LOG_DEBUG, "extensions: registered a new user function (type %d)",
494 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
496 UserFunctionHook *cur, *p, *last;
499 while (cur != NULL) {
500 if ((fcn_ptr == cur->h_function_pointer) &&
501 (EventType == cur->eventtype))
503 syslog(LOG_DEBUG, "extensions: unregistered user function (type %d)", EventType);
522 void CtdlDestroyUserHooks(void)
524 UserFunctionHook *cur, *p;
529 syslog(LOG_DEBUG, "extensions: destroyed user function");
534 UserHookTable = NULL;
538 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
541 MessageFunctionHook *newfcn;
543 newfcn = (MessageFunctionHook *)
544 malloc(sizeof(MessageFunctionHook));
545 newfcn->next = MessageHookTable;
546 newfcn->h_function_pointer = handler;
547 newfcn->eventtype = EventType;
548 MessageHookTable = newfcn;
550 syslog(LOG_DEBUG, "extensions: registered a new message function (type %d)", EventType);
554 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
556 MessageFunctionHook *cur, *p, *last;
558 cur = MessageHookTable;
559 while (cur != NULL) {
560 if ((handler == cur->h_function_pointer) &&
561 (EventType == cur->eventtype))
563 syslog(LOG_DEBUG, "extensions: unregistered message function (type %d)", EventType);
571 MessageHookTable = p;
581 void CtdlDestroyMessageHook(void)
583 MessageFunctionHook *cur, *p;
585 cur = MessageHookTable;
588 syslog(LOG_DEBUG, "extensions: destroyed message function (type %d)", cur->eventtype);
593 MessageHookTable = NULL;
597 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
599 RoomFunctionHook *newfcn;
601 newfcn = (RoomFunctionHook *)
602 malloc(sizeof(RoomFunctionHook));
603 newfcn->next = RoomHookTable;
604 newfcn->fcn_ptr = fcn_ptr;
605 RoomHookTable = newfcn;
607 syslog(LOG_DEBUG, "extensions: registered a new room function");
611 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
613 RoomFunctionHook *cur, *p, *last;
618 if (fcn_ptr == cur->fcn_ptr) {
619 syslog(LOG_DEBUG, "extensions: unregistered room function");
639 void CtdlDestroyRoomHooks(void)
641 RoomFunctionHook *cur, *p;
646 syslog(LOG_DEBUG, "extensions: destroyed room function");
651 RoomHookTable = NULL;
655 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
657 DeleteFunctionHook *newfcn;
659 newfcn = (DeleteFunctionHook *)
660 malloc(sizeof(DeleteFunctionHook));
661 newfcn->next = DeleteHookTable;
662 newfcn->h_function_pointer = handler;
663 DeleteHookTable = newfcn;
665 syslog(LOG_DEBUG, "extensions: registered a new delete function");
669 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
671 DeleteFunctionHook *cur, *p, *last;
674 cur = DeleteHookTable;
675 while (cur != NULL) {
676 if (handler == cur->h_function_pointer )
678 syslog(LOG_DEBUG, "extensions: unregistered delete function");
697 void CtdlDestroyDeleteHooks(void)
699 DeleteFunctionHook *cur, *p;
701 cur = DeleteHookTable;
704 syslog(LOG_DEBUG, "extensions: destroyed delete function");
709 DeleteHookTable = NULL;
713 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
715 FixedOutputHook *newfcn;
717 newfcn = (FixedOutputHook *)
718 malloc(sizeof(FixedOutputHook));
719 newfcn->next = FixedOutputTable;
720 newfcn->h_function_pointer = handler;
721 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
722 FixedOutputTable = newfcn;
724 syslog(LOG_DEBUG, "extensions: registered a new fixed output function for %s", newfcn->content_type);
728 void CtdlUnregisterFixedOutputHook(char *content_type)
730 FixedOutputHook *cur, *p, *last;
733 cur = FixedOutputTable;
734 while (cur != NULL) {
735 /* This will also remove duplicates if any */
736 if (!strcasecmp(content_type, cur->content_type)) {
737 syslog(LOG_DEBUG, "extensions: unregistered fixed output function for %s", content_type);
744 FixedOutputTable = p;
756 void CtdlDestroyFixedOutputHooks(void)
758 FixedOutputHook *cur, *p;
760 cur = FixedOutputTable;
763 syslog(LOG_DEBUG, "extensions: destroyed fixed output function for %s", cur->content_type);
769 FixedOutputTable = NULL;
772 /* returns nonzero if we found a hook and used it */
773 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
775 FixedOutputHook *fcn;
777 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
778 if (!strcasecmp(content_type, fcn->content_type)) {
779 (*fcn->h_function_pointer) (content, content_length);
787 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
790 XmsgFunctionHook *newfcn;
792 newfcn = (XmsgFunctionHook *) malloc(sizeof(XmsgFunctionHook));
793 newfcn->next = XmsgHookTable;
794 newfcn->order = order;
795 newfcn->h_function_pointer = fcn_ptr;
796 XmsgHookTable = newfcn;
797 syslog(LOG_DEBUG, "extensions: registered a new x-msg function (priority %d)", order);
801 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
803 XmsgFunctionHook *cur, *p, *last;
807 while (cur != NULL) {
808 /* This will also remove duplicates if any */
809 if (fcn_ptr == cur->h_function_pointer &&
810 order == cur->order) {
811 syslog(LOG_DEBUG, "extensions: unregistered x-msg function (priority %d)", order);
831 void CtdlDestroyXmsgHooks(void)
833 XmsgFunctionHook *cur, *p;
838 syslog(LOG_DEBUG, "extensions: destroyed x-msg function (priority %d)", cur->order);
843 XmsgHookTable = NULL;
847 void CtdlRegisterServiceHook(int tcp_port,
849 void (*h_greeting_function) (void),
850 void (*h_command_function) (void),
851 void (*h_async_function) (void),
852 const char *ServiceName)
854 ServiceFunctionHook *newfcn;
857 newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook));
858 message = (char*) malloc (SIZ + SIZ);
860 newfcn->next = ServiceHookTable;
861 newfcn->tcp_port = tcp_port;
862 newfcn->sockpath = sockpath;
863 newfcn->h_greeting_function = h_greeting_function;
864 newfcn->h_command_function = h_command_function;
865 newfcn->h_async_function = h_async_function;
866 newfcn->ServiceName = ServiceName;
868 if (sockpath != NULL) {
869 newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"));
870 snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath);
872 else if (tcp_port <= 0) { /* port -1 to disable */
873 syslog(LOG_INFO, "extensions: service %s has been manually disabled, skipping", ServiceName);
879 newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"), tcp_port, CtdlGetConfigInt("c_maxsessions"));
880 snprintf(message, SIZ, "extensions: TCP port %s:%d: (%s) ",
881 CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName);
884 if (newfcn->msock > 0) {
885 ServiceHookTable = newfcn;
886 strcat(message, "registered.");
887 syslog(LOG_INFO, "%s", message);
890 AddPortError(message, "failed");
891 strcat(message, "FAILED.");
892 syslog(LOG_ERR, "%s", message);
899 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
900 void (*h_greeting_function) (void),
901 void (*h_command_function) (void),
902 void (*h_async_function) (void)
905 ServiceFunctionHook *cur, *p, *last;
908 cur = ServiceHookTable;
909 while (cur != NULL) {
910 /* This will also remove duplicates if any */
911 if (h_greeting_function == cur->h_greeting_function &&
912 h_command_function == cur->h_command_function &&
913 h_async_function == cur->h_async_function &&
914 tcp_port == cur->tcp_port &&
915 !(sockpath && cur->sockpath && strcmp(sockpath, cur->sockpath)) )
920 syslog(LOG_INFO, "extensions: closed UNIX domain socket %s", sockpath);
922 } else if (tcp_port) {
923 syslog(LOG_INFO, "extensions: closed TCP port %d", tcp_port);
925 syslog(LOG_INFO, "extensions: unregistered service \"%s\"", cur->ServiceName);
932 ServiceHookTable = p;
943 void CtdlShutdownServiceHooks(void)
945 /* sort of a duplicate of close_masters() but called earlier */
946 ServiceFunctionHook *cur;
948 cur = ServiceHookTable;
951 if (cur->msock != -1)
955 if (cur->sockpath != NULL){
956 syslog(LOG_INFO, "extensions: [%s] Closed UNIX domain socket %s", cur->ServiceName, cur->sockpath);
957 unlink(cur->sockpath);
959 syslog(LOG_INFO, "extensions: [%s] closing service", cur->ServiceName);
967 void CtdlDestroyServiceHook(void)
970 ServiceFunctionHook *cur, *p;
972 cur = ServiceHookTable;
975 if (cur->msock != -1)
982 Text = " Not closing again";
986 syslog(LOG_INFO, "extensions: %s UNIX domain socket %s", Text, cur->sockpath);
987 unlink(cur->sockpath);
988 } else if (cur->tcp_port) {
989 syslog(LOG_INFO, "extensions: %s TCP port %d", Text, cur->tcp_port);
991 syslog(LOG_INFO, "extensions: destroyed service \"%s\"", cur->ServiceName);
997 ServiceHookTable = NULL;
1000 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1002 SearchFunctionHook *newfcn;
1004 if (!name || !fcn_ptr) {
1008 newfcn = (SearchFunctionHook *)
1009 malloc(sizeof(SearchFunctionHook));
1010 newfcn->next = SearchFunctionHookTable;
1011 newfcn->name = name;
1012 newfcn->fcn_ptr = fcn_ptr;
1013 SearchFunctionHookTable = newfcn;
1015 syslog(LOG_DEBUG, "extensions: registered a new search function (%s)", name);
1018 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1020 SearchFunctionHook *cur, *p, *last;
1023 cur = SearchFunctionHookTable;
1024 while (cur != NULL) {
1026 (cur->fcn_ptr == fcn_ptr) &&
1027 name && !strcmp(name, cur->name))
1029 syslog(LOG_DEBUG, "extensions: unregistered search function(%s)", name);
1035 SearchFunctionHookTable = p;
1045 void CtdlDestroySearchHooks(void)
1047 SearchFunctionHook *cur, *p;
1049 cur = SearchFunctionHookTable;
1050 SearchFunctionHookTable = NULL;
1051 while (cur != NULL) {
1058 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
1060 SearchFunctionHook *fcn = NULL;
1062 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
1063 if (!func_name || !strcmp(func_name, fcn->name)) {
1064 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
1072 void PerformSessionHooks(int EventType)
1074 SessionFunctionHook *fcn = NULL;
1076 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
1077 if (fcn->eventtype == EventType) {
1078 if (EventType == EVT_TIMER) {
1079 pthread_setspecific(MyConKey, NULL); /* for every hook */
1081 (*fcn->h_function_pointer) ();
1086 void PerformUserHooks(ctdluser *usbuf, int EventType)
1088 UserFunctionHook *fcn = NULL;
1090 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
1091 if (fcn->eventtype == EventType) {
1092 (*fcn->h_function_pointer) (usbuf);
1097 int PerformMessageHooks(struct CtdlMessage *msg, recptypes *recps, int EventType)
1099 MessageFunctionHook *fcn = NULL;
1100 int total_retval = 0;
1102 /* Other code may elect to protect this message from server-side
1103 * handlers; if this is the case, don't do anything.
1105 if (msg->cm_flags & CM_SKIP_HOOKS) {
1109 /* Otherwise, run all the hooks appropriate to this event type.
1111 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
1112 if (fcn->eventtype == EventType) {
1113 total_retval = total_retval + (*fcn->h_function_pointer) (msg, recps);
1117 /* Return the sum of the return codes from the hook functions. If
1118 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
1119 * the save operation to abort.
1121 return total_retval;
1125 int PerformRoomHooks(struct ctdlroom *target_room)
1127 RoomFunctionHook *fcn;
1128 int total_retval = 0;
1130 syslog(LOG_DEBUG, "extensions: performing room hooks for <%s>", target_room->QRname);
1132 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1133 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1136 /* Return the sum of the return codes from the hook functions.
1138 return total_retval;
1142 void PerformDeleteHooks(char *room, long msgnum)
1144 DeleteFunctionHook *fcn;
1146 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1147 (*fcn->h_function_pointer) (room, msgnum);
1152 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1154 XmsgFunctionHook *fcn;
1158 for (p=0; p<MAX_XMSG_PRI; ++p) {
1159 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1160 if (fcn->order == p) {
1162 (*fcn->h_function_pointer)
1163 (sender, sender_email, recp, msg);
1166 /* Break out of the loop if a higher-priority function
1167 * successfully delivered the message. This prevents duplicate
1168 * deliveries to local users simultaneously signed onto
1171 if (total_sent) break;
1178 * Dirty hack until we impliment a hook mechanism for this
1180 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1183 CtdlStartTLS (ok_response, nosup_response, error_response);
1188 CTDL_MODULE_INIT(modules)