2 * Citadel Extension Loader
3 * Originally written by Brian Costello <btx@calyx.net>
5 * Copyright (c) 1987-2017 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 EG. SIEVE.
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;
151 static StrBuf *errormessages = NULL;
154 long DetailErrorFlags;
155 ConstStr Empty = {HKEY("")};
156 char *ErrSubject = "Startup Problems";
157 ConstStr ErrGeneral[] = {
158 {HKEY("Citadel had trouble on starting up. ")},
159 {HKEY(" This means, Citadel won't be the service provider for a specific service you configured it to.\n\n"
160 "If you don't want Citadel to provide these services, turn them off in WebCit via: ")},
161 {HKEY("To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
162 "The errors returned by the system were:\n")},
163 {HKEY("You can recheck the above if you follow this faq item:\n"
164 "http://www.citadel.org/doku.php?id=faq:mastering_your_os:net#netstat")}
167 ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by Citadel Server.\n")};
168 ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")};
169 ConstStr ErrPortHint = { HKEY("If you want Citadel to provide you with that functionality, "
170 "check the output of \"netstat -lnp\" on Linux, or \"netstat -na\" on BSD"
171 " and stop the program that binds these ports.\n You should eventually remove "
172 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
173 " After that goto \"Administration -> Shutdown Citadel\" to make Citadel restart & retry to bind this port.\n")};
176 void LogPrintMessages(long err)
179 StrBuf *List, *DetailList;
180 ConstStr *Short, *Where, *Hint;
183 Message = NewStrBufPlain(NULL, StrLength(portlist) + StrLength(errormessages));
185 DetailErrorFlags = DetailErrorFlags & ~err;
190 Short = &ErrPortShort;
191 Where = &ErrPortWhere;
194 DetailList = errormessages;
204 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[0]), 0);
205 StrBufAppendBufPlain(Message, CKEY(*Short), 0);
206 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[1]), 0);
207 StrBufAppendBufPlain(Message, CKEY(*Where), 0);
208 StrBufAppendBuf(Message, List, 0);
209 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
210 StrBufAppendBufPlain(Message, CKEY(*Hint), 0);
211 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
212 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[2]), 0);
213 StrBufAppendBuf(Message, DetailList, 0);
214 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
215 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[3]), 0);
217 syslog(LOG_EMERG, "extensions: %s", ChrPtr(Message));
218 syslog(LOG_EMERG, "extensions: %s", ErrSubject);
219 quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(Message), FMT_FIXED, ErrSubject);
221 FreeStrBuf(&Message);
223 FreeStrBuf(&DetailList);
227 void AddPortError(char *Port, char *ErrorMessage)
231 DetailErrorFlags |= ERR_PORT;
233 len = StrLength(errormessages);
234 if (len > 0) StrBufAppendBufPlain(errormessages, HKEY("; "), 0);
235 else errormessages = NewStrBuf();
236 StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
239 len = StrLength(portlist);
240 if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
241 else portlist = NewStrBuf();
242 StrBufAppendBufPlain(portlist, Port, -1, 0);
246 int DLoader_Exec_Cmd(char *cmdbuf)
249 ProtoFunctionHook *p;
251 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
252 p = (ProtoFunctionHook*) vP;
253 p->handler(&cmdbuf[5]);
260 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
262 ProtoFunctionHook *p;
264 if (ProtoHookList == NULL)
265 ProtoHookList = NewHash (1, FourHash);
268 p = (ProtoFunctionHook *)
269 malloc(sizeof(ProtoFunctionHook));
272 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
275 p->handler = handler;
279 Put(ProtoHookList, cmd, 4, p, NULL);
280 syslog(LOG_DEBUG, "extensions: registered server command %s (%s)", cmd, desc);
283 void CtdlDestroyProtoHooks(void)
286 DeleteHash(&ProtoHookList);
290 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
293 CleanupFunctionHook *newfcn;
295 newfcn = (CleanupFunctionHook *)
296 malloc(sizeof(CleanupFunctionHook));
297 newfcn->next = CleanupHookTable;
298 newfcn->h_function_pointer = fcn_ptr;
299 CleanupHookTable = newfcn;
301 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
305 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
307 CleanupFunctionHook *cur, *p, *last;
309 cur = CleanupHookTable;
312 if (fcn_ptr == cur->h_function_pointer)
314 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
323 CleanupHookTable = p;
334 void CtdlDestroyCleanupHooks(void)
336 CleanupFunctionHook *cur, *p;
338 cur = CleanupHookTable;
341 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
346 CleanupHookTable = NULL;
349 void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void))
352 CleanupFunctionHook *newfcn;
354 newfcn = (CleanupFunctionHook *)
355 malloc(sizeof(CleanupFunctionHook));
356 newfcn->next = EVCleanupHookTable;
357 newfcn->h_function_pointer = fcn_ptr;
358 EVCleanupHookTable = newfcn;
360 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
364 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void))
366 CleanupFunctionHook *cur, *p, *last;
368 cur = EVCleanupHookTable;
371 if (fcn_ptr == cur->h_function_pointer)
373 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
382 EVCleanupHookTable = p;
393 void CtdlDestroyEVCleanupHooks(void)
395 CleanupFunctionHook *cur, *p;
397 cur = EVCleanupHookTable;
400 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
402 cur->h_function_pointer();
406 EVCleanupHookTable = NULL;
412 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority)
414 SessionFunctionHook *newfcn;
416 newfcn = (SessionFunctionHook *)
417 malloc(sizeof(SessionFunctionHook));
418 newfcn->Priority = Priority;
419 newfcn->h_function_pointer = fcn_ptr;
420 newfcn->eventtype = EventType;
422 SessionFunctionHook **pfcn;
423 pfcn = &SessionHookTable;
424 while ((*pfcn != NULL) &&
425 ((*pfcn)->Priority < newfcn->Priority) &&
426 ((*pfcn)->next != NULL))
427 pfcn = &(*pfcn)->next;
429 newfcn->next = *pfcn;
432 syslog(LOG_DEBUG, "extensions: registered a new session function (type %d Priority %d)", EventType, Priority);
436 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
438 SessionFunctionHook *cur, *p, *last;
440 cur = SessionHookTable;
441 while (cur != NULL) {
442 if ((fcn_ptr == cur->h_function_pointer) &&
443 (EventType == cur->eventtype))
445 syslog(LOG_DEBUG, "extensions: unregistered session function (type %d)", EventType);
454 SessionHookTable = p;
464 void CtdlDestroySessionHooks(void)
466 SessionFunctionHook *cur, *p;
468 cur = SessionHookTable;
471 syslog(LOG_DEBUG, "extensions: destroyed session function");
476 SessionHookTable = NULL;
480 void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType)
483 UserFunctionHook *newfcn;
485 newfcn = (UserFunctionHook *)
486 malloc(sizeof(UserFunctionHook));
487 newfcn->next = UserHookTable;
488 newfcn->h_function_pointer = fcn_ptr;
489 newfcn->eventtype = EventType;
490 UserHookTable = newfcn;
492 syslog(LOG_DEBUG, "extensions: registered a new user function (type %d)",
497 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
499 UserFunctionHook *cur, *p, *last;
502 while (cur != NULL) {
503 if ((fcn_ptr == cur->h_function_pointer) &&
504 (EventType == cur->eventtype))
506 syslog(LOG_DEBUG, "extensions: unregistered user function (type %d)", EventType);
525 void CtdlDestroyUserHooks(void)
527 UserFunctionHook *cur, *p;
532 syslog(LOG_DEBUG, "extensions: destroyed user function");
537 UserHookTable = NULL;
541 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
544 MessageFunctionHook *newfcn;
546 newfcn = (MessageFunctionHook *)
547 malloc(sizeof(MessageFunctionHook));
548 newfcn->next = MessageHookTable;
549 newfcn->h_function_pointer = handler;
550 newfcn->eventtype = EventType;
551 MessageHookTable = newfcn;
553 syslog(LOG_DEBUG, "extensions: registered a new message function (type %d)", EventType);
557 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
559 MessageFunctionHook *cur, *p, *last;
561 cur = MessageHookTable;
562 while (cur != NULL) {
563 if ((handler == cur->h_function_pointer) &&
564 (EventType == cur->eventtype))
566 syslog(LOG_DEBUG, "extensions: unregistered message function (type %d)", EventType);
574 MessageHookTable = p;
584 void CtdlDestroyMessageHook(void)
586 MessageFunctionHook *cur, *p;
588 cur = MessageHookTable;
591 syslog(LOG_DEBUG, "extensions: destroyed message function (type %d)", cur->eventtype);
596 MessageHookTable = NULL;
600 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
602 RoomFunctionHook *newfcn;
604 newfcn = (RoomFunctionHook *)
605 malloc(sizeof(RoomFunctionHook));
606 newfcn->next = RoomHookTable;
607 newfcn->fcn_ptr = fcn_ptr;
608 RoomHookTable = newfcn;
610 syslog(LOG_DEBUG, "extensions: registered a new room function");
614 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
616 RoomFunctionHook *cur, *p, *last;
621 if (fcn_ptr == cur->fcn_ptr) {
622 syslog(LOG_DEBUG, "extensions: unregistered room function");
642 void CtdlDestroyRoomHooks(void)
644 RoomFunctionHook *cur, *p;
649 syslog(LOG_DEBUG, "extensions: destroyed room function");
654 RoomHookTable = NULL;
658 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
660 DeleteFunctionHook *newfcn;
662 newfcn = (DeleteFunctionHook *)
663 malloc(sizeof(DeleteFunctionHook));
664 newfcn->next = DeleteHookTable;
665 newfcn->h_function_pointer = handler;
666 DeleteHookTable = newfcn;
668 syslog(LOG_DEBUG, "extensions: registered a new delete function");
672 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
674 DeleteFunctionHook *cur, *p, *last;
677 cur = DeleteHookTable;
678 while (cur != NULL) {
679 if (handler == cur->h_function_pointer )
681 syslog(LOG_DEBUG, "extensions: unregistered delete function");
700 void CtdlDestroyDeleteHooks(void)
702 DeleteFunctionHook *cur, *p;
704 cur = DeleteHookTable;
707 syslog(LOG_DEBUG, "extensions: destroyed delete function");
712 DeleteHookTable = NULL;
716 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
718 FixedOutputHook *newfcn;
720 newfcn = (FixedOutputHook *)
721 malloc(sizeof(FixedOutputHook));
722 newfcn->next = FixedOutputTable;
723 newfcn->h_function_pointer = handler;
724 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
725 FixedOutputTable = newfcn;
727 syslog(LOG_DEBUG, "extensions: registered a new fixed output function for %s", newfcn->content_type);
731 void CtdlUnregisterFixedOutputHook(char *content_type)
733 FixedOutputHook *cur, *p, *last;
736 cur = FixedOutputTable;
737 while (cur != NULL) {
738 /* This will also remove duplicates if any */
739 if (!strcasecmp(content_type, cur->content_type)) {
740 syslog(LOG_DEBUG, "extensions: unregistered fixed output function for %s", content_type);
747 FixedOutputTable = p;
759 void CtdlDestroyFixedOutputHooks(void)
761 FixedOutputHook *cur, *p;
763 cur = FixedOutputTable;
766 syslog(LOG_DEBUG, "extensions: destroyed fixed output function for %s", cur->content_type);
772 FixedOutputTable = NULL;
775 /* returns nonzero if we found a hook and used it */
776 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
778 FixedOutputHook *fcn;
780 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
781 if (!strcasecmp(content_type, fcn->content_type)) {
782 (*fcn->h_function_pointer) (content, content_length);
790 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
793 XmsgFunctionHook *newfcn;
795 newfcn = (XmsgFunctionHook *) malloc(sizeof(XmsgFunctionHook));
796 newfcn->next = XmsgHookTable;
797 newfcn->order = order;
798 newfcn->h_function_pointer = fcn_ptr;
799 XmsgHookTable = newfcn;
800 syslog(LOG_DEBUG, "extensions: registered a new x-msg function (priority %d)", order);
804 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
806 XmsgFunctionHook *cur, *p, *last;
810 while (cur != NULL) {
811 /* This will also remove duplicates if any */
812 if (fcn_ptr == cur->h_function_pointer &&
813 order == cur->order) {
814 syslog(LOG_DEBUG, "extensions: unregistered x-msg function (priority %d)", order);
834 void CtdlDestroyXmsgHooks(void)
836 XmsgFunctionHook *cur, *p;
841 syslog(LOG_DEBUG, "extensions: destroyed x-msg function (priority %d)", cur->order);
846 XmsgHookTable = NULL;
850 void CtdlRegisterServiceHook(int tcp_port,
852 void (*h_greeting_function) (void),
853 void (*h_command_function) (void),
854 void (*h_async_function) (void),
855 const char *ServiceName)
857 ServiceFunctionHook *newfcn;
862 newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook));
863 message = (char*) malloc (SIZ + SIZ);
865 newfcn->next = ServiceHookTable;
866 newfcn->tcp_port = tcp_port;
867 newfcn->sockpath = sockpath;
868 newfcn->h_greeting_function = h_greeting_function;
869 newfcn->h_command_function = h_command_function;
870 newfcn->h_async_function = h_async_function;
871 newfcn->ServiceName = ServiceName;
873 if (sockpath != NULL) {
874 newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"), error);
875 snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath);
877 else if (tcp_port <= 0) { /* port -1 to disable */
878 syslog(LOG_INFO, "extensions: service %s has been manually disabled, skipping", ServiceName);
884 newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"),
886 CtdlGetConfigInt("c_maxsessions"),
888 snprintf(message, SIZ, "extensions: TCP port %s:%d: (%s) ",
889 CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName);
892 if (newfcn->msock > 0) {
893 ServiceHookTable = newfcn;
894 strcat(message, "registered.");
895 syslog(LOG_INFO, "%s", message);
898 AddPortError(message, error);
899 strcat(message, "FAILED.");
900 syslog(LOG_ERR, "%s", message);
907 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
908 void (*h_greeting_function) (void),
909 void (*h_command_function) (void),
910 void (*h_async_function) (void)
913 ServiceFunctionHook *cur, *p, *last;
916 cur = ServiceHookTable;
917 while (cur != NULL) {
918 /* This will also remove duplicates if any */
919 if (h_greeting_function == cur->h_greeting_function &&
920 h_command_function == cur->h_command_function &&
921 h_async_function == cur->h_async_function &&
922 tcp_port == cur->tcp_port &&
923 !(sockpath && cur->sockpath && strcmp(sockpath, cur->sockpath)) )
928 syslog(LOG_INFO, "extensions: closed UNIX domain socket %s", sockpath);
930 } else if (tcp_port) {
931 syslog(LOG_INFO, "extensions: closed TCP port %d", tcp_port);
933 syslog(LOG_INFO, "extensions: unregistered service \"%s\"", cur->ServiceName);
940 ServiceHookTable = p;
951 void CtdlShutdownServiceHooks(void)
953 /* sort of a duplicate of close_masters() but called earlier */
954 ServiceFunctionHook *cur;
956 cur = ServiceHookTable;
959 if (cur->msock != -1)
963 if (cur->sockpath != NULL){
964 syslog(LOG_INFO, "extensions: [%s] Closed UNIX domain socket %s", cur->ServiceName, cur->sockpath);
965 unlink(cur->sockpath);
967 syslog(LOG_INFO, "extensions: [%s] closing service", cur->ServiceName);
975 void CtdlDestroyServiceHook(void)
978 ServiceFunctionHook *cur, *p;
980 cur = ServiceHookTable;
983 if (cur->msock != -1)
990 Text = " Not closing again";
994 syslog(LOG_INFO, "extensions: %s UNIX domain socket %s", Text, cur->sockpath);
995 unlink(cur->sockpath);
996 } else if (cur->tcp_port) {
997 syslog(LOG_INFO, "extensions: %s TCP port %d", Text, cur->tcp_port);
999 syslog(LOG_INFO, "extensions: destroyed service \"%s\"", cur->ServiceName);
1005 ServiceHookTable = NULL;
1008 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1010 SearchFunctionHook *newfcn;
1012 if (!name || !fcn_ptr) {
1016 newfcn = (SearchFunctionHook *)
1017 malloc(sizeof(SearchFunctionHook));
1018 newfcn->next = SearchFunctionHookTable;
1019 newfcn->name = name;
1020 newfcn->fcn_ptr = fcn_ptr;
1021 SearchFunctionHookTable = newfcn;
1023 syslog(LOG_DEBUG, "extensions: registered a new search function (%s)", name);
1026 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1028 SearchFunctionHook *cur, *p, *last;
1031 cur = SearchFunctionHookTable;
1032 while (cur != NULL) {
1034 (cur->fcn_ptr == fcn_ptr) &&
1035 name && !strcmp(name, cur->name))
1037 syslog(LOG_DEBUG, "extensions: unregistered search function(%s)", name);
1043 SearchFunctionHookTable = p;
1053 void CtdlDestroySearchHooks(void)
1055 SearchFunctionHook *cur, *p;
1057 cur = SearchFunctionHookTable;
1058 SearchFunctionHookTable = NULL;
1059 while (cur != NULL) {
1066 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
1068 SearchFunctionHook *fcn = NULL;
1070 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
1071 if (!func_name || !strcmp(func_name, fcn->name)) {
1072 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
1080 void PerformSessionHooks(int EventType)
1082 SessionFunctionHook *fcn = NULL;
1084 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
1085 if (fcn->eventtype == EventType) {
1086 if (EventType == EVT_TIMER) {
1087 pthread_setspecific(MyConKey, NULL); /* for every hook */
1089 (*fcn->h_function_pointer) ();
1094 void PerformUserHooks(ctdluser *usbuf, int EventType)
1096 UserFunctionHook *fcn = NULL;
1098 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
1099 if (fcn->eventtype == EventType) {
1100 (*fcn->h_function_pointer) (usbuf);
1105 int PerformMessageHooks(struct CtdlMessage *msg, recptypes *recps, int EventType)
1107 MessageFunctionHook *fcn = NULL;
1108 int total_retval = 0;
1110 /* Other code may elect to protect this message from server-side
1111 * handlers; if this is the case, don't do anything.
1113 if (msg->cm_flags & CM_SKIP_HOOKS) {
1117 /* Otherwise, run all the hooks appropriate to this event type.
1119 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
1120 if (fcn->eventtype == EventType) {
1121 total_retval = total_retval + (*fcn->h_function_pointer) (msg, recps);
1125 /* Return the sum of the return codes from the hook functions. If
1126 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
1127 * the save operation to abort.
1129 return total_retval;
1133 int PerformRoomHooks(struct ctdlroom *target_room)
1135 RoomFunctionHook *fcn;
1136 int total_retval = 0;
1138 syslog(LOG_DEBUG, "extensions: performing room hooks for <%s>", target_room->QRname);
1140 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1141 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1144 /* Return the sum of the return codes from the hook functions.
1146 return total_retval;
1150 void PerformDeleteHooks(char *room, long msgnum)
1152 DeleteFunctionHook *fcn;
1154 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1155 (*fcn->h_function_pointer) (room, msgnum);
1160 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1162 XmsgFunctionHook *fcn;
1166 for (p=0; p<MAX_XMSG_PRI; ++p) {
1167 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1168 if (fcn->order == p) {
1170 (*fcn->h_function_pointer)
1171 (sender, sender_email, recp, msg);
1174 /* Break out of the loop if a higher-priority function
1175 * successfully delivered the message. This prevents duplicate
1176 * deliveries to local users simultaneously signed onto
1179 if (total_sent) break;
1186 * Dirty hack until we impliment a hook mechanism for this
1188 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1191 CtdlStartTLS (ok_response, nosup_response, error_response);
1196 CTDL_MODULE_INIT(modules)