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 * NetprocFunctionHook extensions are used for hooks which implement handlers
86 * for incoming network messages.
88 typedef struct NetprocFunctionHook NetprocFunctionHook;
89 struct NetprocFunctionHook {
90 NetprocFunctionHook *next;
91 int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
93 NetprocFunctionHook *NetprocHookTable = NULL;
97 * DeleteFunctionHook extensions are used for hooks which get called when a
98 * message is about to be deleted.
100 typedef struct DeleteFunctionHook DeleteFunctionHook;
101 struct DeleteFunctionHook {
102 DeleteFunctionHook *next;
103 void (*h_function_pointer) (char *target_room, long msgnum);
105 DeleteFunctionHook *DeleteHookTable = NULL;
109 * ExpressMessageFunctionHook extensions are used for hooks which implement
110 * the sending of an instant message through various channels. Any function
111 * registered should return the number of recipients to whom the message was
112 * successfully transmitted.
114 typedef struct XmsgFunctionHook XmsgFunctionHook;
115 struct XmsgFunctionHook {
116 XmsgFunctionHook *next;
117 int (*h_function_pointer) (char *, char *, char *, char *);
120 XmsgFunctionHook *XmsgHookTable = NULL;
124 * RoomFunctionHook extensions are used for hooks which impliment room
125 * processing functions when new messages are added EG. SIEVE.
127 typedef struct RoomFunctionHook RoomFunctionHook;
128 struct RoomFunctionHook {
129 RoomFunctionHook *next;
130 int (*fcn_ptr) (struct ctdlroom *);
132 RoomFunctionHook *RoomHookTable = NULL;
135 typedef struct SearchFunctionHook SearchFunctionHook;
136 struct SearchFunctionHook {
137 SearchFunctionHook *next;
138 void (*fcn_ptr) (int *, long **, const char *);
141 SearchFunctionHook *SearchFunctionHookTable = NULL;
143 CleanupFunctionHook *CleanupHookTable = NULL;
144 CleanupFunctionHook *EVCleanupHookTable = NULL;
146 ServiceFunctionHook *ServiceHookTable = NULL;
148 typedef struct ProtoFunctionHook ProtoFunctionHook;
149 struct ProtoFunctionHook {
150 void (*handler) (char *cmdbuf);
155 HashList *ProtoHookList = NULL;
158 #define ERR_PORT (1 << 1)
161 static StrBuf *portlist = NULL;
163 static StrBuf *errormessages = NULL;
166 long DetailErrorFlags;
167 ConstStr Empty = {HKEY("")};
168 char *ErrSubject = "Startup Problems";
169 ConstStr ErrGeneral[] = {
170 {HKEY("Citadel had trouble on starting up. ")},
171 {HKEY(" This means, Citadel won't be the service provider for a specific service you configured it to.\n\n"
172 "If you don't want Citadel to provide these services, turn them off in WebCit via: ")},
173 {HKEY("To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
174 "The errors returned by the system were:\n")},
175 {HKEY("You can recheck the above if you follow this faq item:\n"
176 "http://www.citadel.org/doku.php?id=faq:mastering_your_os:net#netstat")}
179 ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by Citadel Server.\n")};
180 ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")};
181 ConstStr ErrPortHint = { HKEY("If you want Citadel to provide you with that functionality, "
182 "check the output of \"netstat -lnp\" on Linux, or \"netstat -na\" on BSD"
183 " and stop the program that binds these ports.\n You should eventually remove "
184 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
185 " After that goto \"Administration -> Shutdown Citadel\" to make Citadel restart & retry to bind this port.\n")};
188 void LogPrintMessages(long err)
191 StrBuf *List, *DetailList;
192 ConstStr *Short, *Where, *Hint;
195 Message = NewStrBufPlain(NULL, StrLength(portlist) + StrLength(errormessages));
197 DetailErrorFlags = DetailErrorFlags & ~err;
202 Short = &ErrPortShort;
203 Where = &ErrPortWhere;
206 DetailList = errormessages;
216 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[0]), 0);
217 StrBufAppendBufPlain(Message, CKEY(*Short), 0);
218 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[1]), 0);
219 StrBufAppendBufPlain(Message, CKEY(*Where), 0);
220 StrBufAppendBuf(Message, List, 0);
221 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
222 StrBufAppendBufPlain(Message, CKEY(*Hint), 0);
223 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
224 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[2]), 0);
225 StrBufAppendBuf(Message, DetailList, 0);
226 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
227 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[3]), 0);
229 syslog(LOG_EMERG, "extensions: %s", ChrPtr(Message));
230 syslog(LOG_EMERG, "extensions: %s", ErrSubject);
231 quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(Message), FMT_FIXED, ErrSubject);
233 FreeStrBuf(&Message);
235 FreeStrBuf(&DetailList);
239 void AddPortError(char *Port, char *ErrorMessage)
243 DetailErrorFlags |= ERR_PORT;
245 len = StrLength(errormessages);
246 if (len > 0) StrBufAppendBufPlain(errormessages, HKEY("; "), 0);
247 else errormessages = NewStrBuf();
248 StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
251 len = StrLength(portlist);
252 if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
253 else portlist = NewStrBuf();
254 StrBufAppendBufPlain(portlist, Port, -1, 0);
258 int DLoader_Exec_Cmd(char *cmdbuf)
261 ProtoFunctionHook *p;
263 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
264 p = (ProtoFunctionHook*) vP;
265 p->handler(&cmdbuf[5]);
272 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
274 ProtoFunctionHook *p;
276 if (ProtoHookList == NULL)
277 ProtoHookList = NewHash (1, FourHash);
280 p = (ProtoFunctionHook *)
281 malloc(sizeof(ProtoFunctionHook));
284 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
287 p->handler = handler;
291 Put(ProtoHookList, cmd, 4, p, NULL);
292 syslog(LOG_DEBUG, "extensions: registered server command %s (%s)", cmd, desc);
295 void CtdlDestroyProtoHooks(void)
298 DeleteHash(&ProtoHookList);
302 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
305 CleanupFunctionHook *newfcn;
307 newfcn = (CleanupFunctionHook *)
308 malloc(sizeof(CleanupFunctionHook));
309 newfcn->next = CleanupHookTable;
310 newfcn->h_function_pointer = fcn_ptr;
311 CleanupHookTable = newfcn;
313 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
317 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
319 CleanupFunctionHook *cur, *p, *last;
321 cur = CleanupHookTable;
324 if (fcn_ptr == cur->h_function_pointer)
326 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
335 CleanupHookTable = p;
346 void CtdlDestroyCleanupHooks(void)
348 CleanupFunctionHook *cur, *p;
350 cur = CleanupHookTable;
353 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
358 CleanupHookTable = NULL;
361 void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void))
364 CleanupFunctionHook *newfcn;
366 newfcn = (CleanupFunctionHook *)
367 malloc(sizeof(CleanupFunctionHook));
368 newfcn->next = EVCleanupHookTable;
369 newfcn->h_function_pointer = fcn_ptr;
370 EVCleanupHookTable = newfcn;
372 syslog(LOG_DEBUG, "extensions: registered a new cleanup function");
376 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void))
378 CleanupFunctionHook *cur, *p, *last;
380 cur = EVCleanupHookTable;
383 if (fcn_ptr == cur->h_function_pointer)
385 syslog(LOG_DEBUG, "extensions: unregistered cleanup function");
394 EVCleanupHookTable = p;
405 void CtdlDestroyEVCleanupHooks(void)
407 CleanupFunctionHook *cur, *p;
409 cur = EVCleanupHookTable;
412 syslog(LOG_DEBUG, "extensions: destroyed cleanup function");
414 cur->h_function_pointer();
418 EVCleanupHookTable = NULL;
424 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority)
426 SessionFunctionHook *newfcn;
428 newfcn = (SessionFunctionHook *)
429 malloc(sizeof(SessionFunctionHook));
430 newfcn->Priority = Priority;
431 newfcn->h_function_pointer = fcn_ptr;
432 newfcn->eventtype = EventType;
434 SessionFunctionHook **pfcn;
435 pfcn = &SessionHookTable;
436 while ((*pfcn != NULL) &&
437 ((*pfcn)->Priority < newfcn->Priority) &&
438 ((*pfcn)->next != NULL))
439 pfcn = &(*pfcn)->next;
441 newfcn->next = *pfcn;
444 syslog(LOG_DEBUG, "extensions: registered a new session function (type %d Priority %d)", EventType, Priority);
448 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
450 SessionFunctionHook *cur, *p, *last;
452 cur = SessionHookTable;
453 while (cur != NULL) {
454 if ((fcn_ptr == cur->h_function_pointer) &&
455 (EventType == cur->eventtype))
457 syslog(LOG_DEBUG, "extensions: unregistered session function (type %d)", EventType);
466 SessionHookTable = p;
476 void CtdlDestroySessionHooks(void)
478 SessionFunctionHook *cur, *p;
480 cur = SessionHookTable;
483 syslog(LOG_DEBUG, "extensions: destroyed session function");
488 SessionHookTable = NULL;
492 void CtdlRegisterUserHook(void (*fcn_ptr) (ctdluser *), int EventType)
495 UserFunctionHook *newfcn;
497 newfcn = (UserFunctionHook *)
498 malloc(sizeof(UserFunctionHook));
499 newfcn->next = UserHookTable;
500 newfcn->h_function_pointer = fcn_ptr;
501 newfcn->eventtype = EventType;
502 UserHookTable = newfcn;
504 syslog(LOG_DEBUG, "extensions: registered a new user function (type %d)",
509 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
511 UserFunctionHook *cur, *p, *last;
514 while (cur != NULL) {
515 if ((fcn_ptr == cur->h_function_pointer) &&
516 (EventType == cur->eventtype))
518 syslog(LOG_DEBUG, "extensions: unregistered user function (type %d)", EventType);
537 void CtdlDestroyUserHooks(void)
539 UserFunctionHook *cur, *p;
544 syslog(LOG_DEBUG, "extensions: destroyed user function");
549 UserHookTable = NULL;
553 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
556 MessageFunctionHook *newfcn;
558 newfcn = (MessageFunctionHook *)
559 malloc(sizeof(MessageFunctionHook));
560 newfcn->next = MessageHookTable;
561 newfcn->h_function_pointer = handler;
562 newfcn->eventtype = EventType;
563 MessageHookTable = newfcn;
565 syslog(LOG_DEBUG, "extensions: registered a new message function (type %d)", EventType);
569 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, recptypes *), int EventType)
571 MessageFunctionHook *cur, *p, *last;
573 cur = MessageHookTable;
574 while (cur != NULL) {
575 if ((handler == cur->h_function_pointer) &&
576 (EventType == cur->eventtype))
578 syslog(LOG_DEBUG, "extensions: unregistered message function (type %d)", EventType);
586 MessageHookTable = p;
596 void CtdlDestroyMessageHook(void)
598 MessageFunctionHook *cur, *p;
600 cur = MessageHookTable;
603 syslog(LOG_DEBUG, "extensions: destroyed message function (type %d)", cur->eventtype);
608 MessageHookTable = NULL;
612 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
614 RoomFunctionHook *newfcn;
616 newfcn = (RoomFunctionHook *)
617 malloc(sizeof(RoomFunctionHook));
618 newfcn->next = RoomHookTable;
619 newfcn->fcn_ptr = fcn_ptr;
620 RoomHookTable = newfcn;
622 syslog(LOG_DEBUG, "extensions: registered a new room function");
626 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
628 RoomFunctionHook *cur, *p, *last;
633 if (fcn_ptr == cur->fcn_ptr) {
634 syslog(LOG_DEBUG, "extensions: unregistered room function");
654 void CtdlDestroyRoomHooks(void)
656 RoomFunctionHook *cur, *p;
661 syslog(LOG_DEBUG, "extensions: destroyed room function");
666 RoomHookTable = NULL;
669 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
671 NetprocFunctionHook *newfcn;
673 newfcn = (NetprocFunctionHook *)
674 malloc(sizeof(NetprocFunctionHook));
675 newfcn->next = NetprocHookTable;
676 newfcn->h_function_pointer = handler;
677 NetprocHookTable = newfcn;
679 syslog(LOG_DEBUG, "extensions: registered a new netproc function");
683 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
685 NetprocFunctionHook *cur, *p, *last;
687 cur = NetprocHookTable;
690 while (cur != NULL) {
691 if (handler == cur->h_function_pointer)
693 syslog(LOG_DEBUG, "extensions: unregistered netproc function");
700 NetprocHookTable = p;
711 void CtdlDestroyNetprocHooks(void)
713 NetprocFunctionHook *cur, *p;
715 cur = NetprocHookTable;
718 syslog(LOG_DEBUG, "extensions: destroyed netproc function");
723 NetprocHookTable = NULL;
727 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
729 DeleteFunctionHook *newfcn;
731 newfcn = (DeleteFunctionHook *)
732 malloc(sizeof(DeleteFunctionHook));
733 newfcn->next = DeleteHookTable;
734 newfcn->h_function_pointer = handler;
735 DeleteHookTable = newfcn;
737 syslog(LOG_DEBUG, "extensions: registered a new delete function");
741 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
743 DeleteFunctionHook *cur, *p, *last;
746 cur = DeleteHookTable;
747 while (cur != NULL) {
748 if (handler == cur->h_function_pointer )
750 syslog(LOG_DEBUG, "extensions: unregistered delete function");
769 void CtdlDestroyDeleteHooks(void)
771 DeleteFunctionHook *cur, *p;
773 cur = DeleteHookTable;
776 syslog(LOG_DEBUG, "extensions: destroyed delete function");
781 DeleteHookTable = NULL;
785 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
787 FixedOutputHook *newfcn;
789 newfcn = (FixedOutputHook *)
790 malloc(sizeof(FixedOutputHook));
791 newfcn->next = FixedOutputTable;
792 newfcn->h_function_pointer = handler;
793 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
794 FixedOutputTable = newfcn;
796 syslog(LOG_DEBUG, "extensions: registered a new fixed output function for %s", newfcn->content_type);
800 void CtdlUnregisterFixedOutputHook(char *content_type)
802 FixedOutputHook *cur, *p, *last;
805 cur = FixedOutputTable;
806 while (cur != NULL) {
807 /* This will also remove duplicates if any */
808 if (!strcasecmp(content_type, cur->content_type)) {
809 syslog(LOG_DEBUG, "extensions: unregistered fixed output function for %s", content_type);
816 FixedOutputTable = p;
828 void CtdlDestroyFixedOutputHooks(void)
830 FixedOutputHook *cur, *p;
832 cur = FixedOutputTable;
835 syslog(LOG_DEBUG, "extensions: destroyed fixed output function for %s", cur->content_type);
841 FixedOutputTable = NULL;
844 /* returns nonzero if we found a hook and used it */
845 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
847 FixedOutputHook *fcn;
849 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
850 if (!strcasecmp(content_type, fcn->content_type)) {
851 (*fcn->h_function_pointer) (content, content_length);
859 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
862 XmsgFunctionHook *newfcn;
864 newfcn = (XmsgFunctionHook *) malloc(sizeof(XmsgFunctionHook));
865 newfcn->next = XmsgHookTable;
866 newfcn->order = order;
867 newfcn->h_function_pointer = fcn_ptr;
868 XmsgHookTable = newfcn;
869 syslog(LOG_DEBUG, "extensions: registered a new x-msg function (priority %d)", order);
873 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
875 XmsgFunctionHook *cur, *p, *last;
879 while (cur != NULL) {
880 /* This will also remove duplicates if any */
881 if (fcn_ptr == cur->h_function_pointer &&
882 order == cur->order) {
883 syslog(LOG_DEBUG, "extensions: unregistered x-msg function (priority %d)", order);
903 void CtdlDestroyXmsgHooks(void)
905 XmsgFunctionHook *cur, *p;
910 syslog(LOG_DEBUG, "extensions: destroyed x-msg function (priority %d)", cur->order);
915 XmsgHookTable = NULL;
919 void CtdlRegisterServiceHook(int tcp_port,
921 void (*h_greeting_function) (void),
922 void (*h_command_function) (void),
923 void (*h_async_function) (void),
924 const char *ServiceName)
926 ServiceFunctionHook *newfcn;
931 newfcn = (ServiceFunctionHook *) malloc(sizeof(ServiceFunctionHook));
932 message = (char*) malloc (SIZ + SIZ);
934 newfcn->next = ServiceHookTable;
935 newfcn->tcp_port = tcp_port;
936 newfcn->sockpath = sockpath;
937 newfcn->h_greeting_function = h_greeting_function;
938 newfcn->h_command_function = h_command_function;
939 newfcn->h_async_function = h_async_function;
940 newfcn->ServiceName = ServiceName;
942 if (sockpath != NULL) {
943 newfcn->msock = ctdl_uds_server(sockpath, CtdlGetConfigInt("c_maxsessions"), error);
944 snprintf(message, SIZ, "extensions: unix domain socket '%s': ", sockpath);
946 else if (tcp_port <= 0) { /* port -1 to disable */
947 syslog(LOG_INFO, "extensions: service %s has been manually disabled, skipping", ServiceName);
953 newfcn->msock = ctdl_tcp_server(CtdlGetConfigStr("c_ip_addr"),
955 CtdlGetConfigInt("c_maxsessions"),
957 snprintf(message, SIZ, "extensions: TCP port %s:%d: (%s) ",
958 CtdlGetConfigStr("c_ip_addr"), tcp_port, ServiceName);
961 if (newfcn->msock > 0) {
962 ServiceHookTable = newfcn;
963 strcat(message, "registered.");
964 syslog(LOG_INFO, "%s", message);
967 AddPortError(message, error);
968 strcat(message, "FAILED.");
969 syslog(LOG_ERR, "%s", message);
976 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
977 void (*h_greeting_function) (void),
978 void (*h_command_function) (void),
979 void (*h_async_function) (void)
982 ServiceFunctionHook *cur, *p, *last;
985 cur = ServiceHookTable;
986 while (cur != NULL) {
987 /* This will also remove duplicates if any */
988 if (h_greeting_function == cur->h_greeting_function &&
989 h_command_function == cur->h_command_function &&
990 h_async_function == cur->h_async_function &&
991 tcp_port == cur->tcp_port &&
992 !(sockpath && cur->sockpath && strcmp(sockpath, cur->sockpath)) )
997 syslog(LOG_INFO, "extensions: closed UNIX domain socket %s", sockpath);
999 } else if (tcp_port) {
1000 syslog(LOG_INFO, "extensions: closed TCP port %d", tcp_port);
1002 syslog(LOG_INFO, "extensions: unregistered service \"%s\"", cur->ServiceName);
1009 ServiceHookTable = p;
1020 void CtdlShutdownServiceHooks(void)
1022 /* sort of a duplicate of close_masters() but called earlier */
1023 ServiceFunctionHook *cur;
1025 cur = ServiceHookTable;
1028 if (cur->msock != -1)
1032 if (cur->sockpath != NULL){
1033 syslog(LOG_INFO, "extensions: [%s] Closed UNIX domain socket %s", cur->ServiceName, cur->sockpath);
1034 unlink(cur->sockpath);
1036 syslog(LOG_INFO, "extensions: [%s] closing service", cur->ServiceName);
1044 void CtdlDestroyServiceHook(void)
1047 ServiceFunctionHook *cur, *p;
1049 cur = ServiceHookTable;
1052 if (cur->msock != -1)
1059 Text = " Not closing again";
1062 if (cur->sockpath) {
1063 syslog(LOG_INFO, "extensions: %s UNIX domain socket %s", Text, cur->sockpath);
1064 unlink(cur->sockpath);
1065 } else if (cur->tcp_port) {
1066 syslog(LOG_INFO, "extensions: %s TCP port %d", Text, cur->tcp_port);
1068 syslog(LOG_INFO, "extensions: destroyed service \"%s\"", cur->ServiceName);
1074 ServiceHookTable = NULL;
1077 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1079 SearchFunctionHook *newfcn;
1081 if (!name || !fcn_ptr) {
1085 newfcn = (SearchFunctionHook *)
1086 malloc(sizeof(SearchFunctionHook));
1087 newfcn->next = SearchFunctionHookTable;
1088 newfcn->name = name;
1089 newfcn->fcn_ptr = fcn_ptr;
1090 SearchFunctionHookTable = newfcn;
1092 syslog(LOG_DEBUG, "extensions: registered a new search function (%s)", name);
1095 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
1097 SearchFunctionHook *cur, *p, *last;
1100 cur = SearchFunctionHookTable;
1101 while (cur != NULL) {
1103 (cur->fcn_ptr == fcn_ptr) &&
1104 name && !strcmp(name, cur->name))
1106 syslog(LOG_DEBUG, "extensions: unregistered search function(%s)", name);
1112 SearchFunctionHookTable = p;
1122 void CtdlDestroySearchHooks(void)
1124 SearchFunctionHook *cur, *p;
1126 cur = SearchFunctionHookTable;
1127 SearchFunctionHookTable = NULL;
1128 while (cur != NULL) {
1135 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
1137 SearchFunctionHook *fcn = NULL;
1139 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
1140 if (!func_name || !strcmp(func_name, fcn->name)) {
1141 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
1149 void PerformSessionHooks(int EventType)
1151 SessionFunctionHook *fcn = NULL;
1153 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
1154 if (fcn->eventtype == EventType) {
1155 if (EventType == EVT_TIMER) {
1156 pthread_setspecific(MyConKey, NULL); /* for every hook */
1158 (*fcn->h_function_pointer) ();
1163 void PerformUserHooks(ctdluser *usbuf, int EventType)
1165 UserFunctionHook *fcn = NULL;
1167 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
1168 if (fcn->eventtype == EventType) {
1169 (*fcn->h_function_pointer) (usbuf);
1174 int PerformMessageHooks(struct CtdlMessage *msg, recptypes *recps, int EventType)
1176 MessageFunctionHook *fcn = NULL;
1177 int total_retval = 0;
1179 /* Other code may elect to protect this message from server-side
1180 * handlers; if this is the case, don't do anything.
1182 if (msg->cm_flags & CM_SKIP_HOOKS) {
1186 /* Otherwise, run all the hooks appropriate to this event type.
1188 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
1189 if (fcn->eventtype == EventType) {
1190 total_retval = total_retval + (*fcn->h_function_pointer) (msg, recps);
1194 /* Return the sum of the return codes from the hook functions. If
1195 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
1196 * the save operation to abort.
1198 return total_retval;
1202 int PerformRoomHooks(struct ctdlroom *target_room)
1204 RoomFunctionHook *fcn;
1205 int total_retval = 0;
1207 syslog(LOG_DEBUG, "extensions: performing room hooks for <%s>", target_room->QRname);
1209 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1210 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1213 /* Return the sum of the return codes from the hook functions.
1215 return total_retval;
1219 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
1221 NetprocFunctionHook *fcn;
1222 int total_retval = 0;
1224 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
1225 total_retval = total_retval +
1226 (*fcn->h_function_pointer) (msg, target_room);
1229 /* Return the sum of the return codes from the hook functions.
1230 * A nonzero return code will cause the message to *not* be imported.
1232 return total_retval;
1236 void PerformDeleteHooks(char *room, long msgnum)
1238 DeleteFunctionHook *fcn;
1240 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1241 (*fcn->h_function_pointer) (room, msgnum);
1249 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1251 XmsgFunctionHook *fcn;
1255 for (p=0; p<MAX_XMSG_PRI; ++p) {
1256 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1257 if (fcn->order == p) {
1259 (*fcn->h_function_pointer)
1260 (sender, sender_email, recp, msg);
1263 /* Break out of the loop if a higher-priority function
1264 * successfully delivered the message. This prevents duplicate
1265 * deliveries to local users simultaneously signed onto
1268 if (total_sent) break;
1275 * Dirty hack until we impliment a hook mechanism for this
1277 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1280 CtdlStartTLS (ok_response, nosup_response, error_response);
1285 CTDL_MODULE_INIT(modules)