2 * Citadel Dynamic Loading Module
3 * Written by Brian Costello <btx@calyx.net>
5 * Copyright (c) 1987-2011 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 as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
32 #include <libcitadel.h>
35 #include "serv_extensions.h"
36 #include "sysdep_decls.h"
40 #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
42 #include "ctdl_module.h"
49 struct CleanupFunctionHook *CleanupHookTable = NULL;
50 struct SessionFunctionHook *SessionHookTable = NULL;
51 struct UserFunctionHook *UserHookTable = NULL;
52 struct XmsgFunctionHook *XmsgHookTable = NULL;
53 struct MessageFunctionHook *MessageHookTable = NULL;
54 struct NetprocFunctionHook *NetprocHookTable = NULL;
55 struct DeleteFunctionHook *DeleteHookTable = NULL;
56 struct ServiceFunctionHook *ServiceHookTable = NULL;
57 struct FixedOutputHook *FixedOutputTable = NULL;
58 struct RoomFunctionHook *RoomHookTable = NULL;
59 struct SearchFunctionHook *SearchFunctionHookTable = NULL;
61 struct ProtoFunctionHook {
62 void (*handler) (char *cmdbuf);
67 HashList *ProtoHookList = NULL;
70 #define ERR_PORT (1 << 1)
73 static StrBuf *portlist = NULL;
75 static StrBuf *errormessages = NULL;
78 long DetailErrorFlags;
79 ConstStr Empty = {HKEY("")};
80 char *ErrSubject = "Startup Problems";
81 ConstStr ErrGeneral[] = {
82 {HKEY("Citadel had trouble on starting up. ")},
83 {HKEY(" This means, citadel won't be the service provider for a specific service you configured it to.\n\n"
84 "If you don't want citadel to provide these services, turn them off in WebCit via: ")},
85 {HKEY("To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
86 "The errors returned by the system were:\n")},
87 {HKEY("You can recheck the above if you follow this faq item:\n"
88 "http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat")}
91 ConstStr ErrPortShort = { HKEY("We couldn't bind all ports you configured to be provided by citadel server.\n")};
92 ConstStr ErrPortWhere = { HKEY("\"Admin->System Preferences->Network\".\n\nThe failed ports and sockets are: ")};
93 ConstStr ErrPortHint = { HKEY("If you want citadel to provide you with that functionality, "
94 "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD"
95 " and stop the program that binds these ports.\n You should eventually remove "
96 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
97 " After that goto \"Administration -> Shutdown Citadel\" to make Citadel restart & retry to bind this port.\n")};
100 void LogPrintMessages(long err)
103 StrBuf *List, *DetailList;
104 ConstStr *Short, *Where, *Hint;
107 Message = NewStrBufPlain(NULL,
108 StrLength(portlist) + StrLength(errormessages));
110 DetailErrorFlags = DetailErrorFlags & ~err;
115 Short = &ErrPortShort;
116 Where = &ErrPortWhere;
119 DetailList = errormessages;
129 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[0]), 0);
130 StrBufAppendBufPlain(Message, CKEY(*Short), 0);
131 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[1]), 0);
132 StrBufAppendBufPlain(Message, CKEY(*Where), 0);
133 StrBufAppendBuf(Message, List, 0);
134 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
135 StrBufAppendBufPlain(Message, CKEY(*Hint), 0);
136 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
137 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[2]), 0);
138 StrBufAppendBuf(Message, DetailList, 0);
139 StrBufAppendBufPlain(Message, HKEY("\n\n"), 0);
140 StrBufAppendBufPlain(Message, CKEY(ErrGeneral[3]), 0);
142 syslog(LOG_EMERG, "%s", ChrPtr(Message));
143 syslog(LOG_EMERG, "%s", ErrSubject);
144 quickie_message("Citadel", NULL, NULL, AIDEROOM, ChrPtr(Message), FMT_FIXED, ErrSubject);
146 FreeStrBuf(&Message);
148 FreeStrBuf(&DetailList);
152 void AddPortError(char *Port, char *ErrorMessage)
156 DetailErrorFlags |= ERR_PORT;
158 len = StrLength(errormessages);
159 if (len > 0) StrBufAppendBufPlain(errormessages, HKEY("; "), 0);
160 else errormessages = NewStrBuf();
161 StrBufAppendBufPlain(errormessages, ErrorMessage, -1, 0);
164 len = StrLength(portlist);
165 if (len > 0) StrBufAppendBufPlain(portlist, HKEY(";"), 0);
166 else portlist = NewStrBuf();
167 StrBufAppendBufPlain(portlist, Port, -1, 0);
171 int DLoader_Exec_Cmd(char *cmdbuf)
174 struct ProtoFunctionHook *p;
176 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
177 p = (struct ProtoFunctionHook*) vP;
178 p->handler(&cmdbuf[5]);
184 long FourHash(const char *key, long length)
188 const unsigned char *ptr = (const unsigned char*)key;
190 for (i = 0; i < 4; i++, ptr ++)
200 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
202 struct ProtoFunctionHook *p;
204 if (ProtoHookList == NULL)
205 ProtoHookList = NewHash (1, FourHash);
208 p = (struct ProtoFunctionHook *)
209 malloc(sizeof(struct ProtoFunctionHook));
212 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
215 p->handler = handler;
219 Put(ProtoHookList, cmd, 4, p, NULL);
220 syslog(LOG_INFO, "Registered server command %s (%s)\n", cmd, desc);
223 void CtdlDestroyProtoHooks(void)
226 DeleteHash(&ProtoHookList);
230 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
233 struct CleanupFunctionHook *newfcn;
235 newfcn = (struct CleanupFunctionHook *)
236 malloc(sizeof(struct CleanupFunctionHook));
237 newfcn->next = CleanupHookTable;
238 newfcn->h_function_pointer = fcn_ptr;
239 CleanupHookTable = newfcn;
241 syslog(LOG_INFO, "Registered a new cleanup function\n");
245 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
247 struct CleanupFunctionHook *cur, *p;
249 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
250 /* This will also remove duplicates if any */
251 while (cur != NULL &&
252 fcn_ptr == cur->h_function_pointer) {
253 syslog(LOG_INFO, "Unregistered cleanup function\n");
255 if (cur == CleanupHookTable) {
256 CleanupHookTable = p;
264 void CtdlDestroyCleanupHooks(void)
266 struct CleanupFunctionHook *cur, *p;
268 cur = CleanupHookTable;
271 syslog(LOG_INFO, "Destroyed cleanup function\n");
276 CleanupHookTable = NULL;
280 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
283 struct SessionFunctionHook *newfcn;
285 newfcn = (struct SessionFunctionHook *)
286 malloc(sizeof(struct SessionFunctionHook));
287 newfcn->next = SessionHookTable;
288 newfcn->h_function_pointer = fcn_ptr;
289 newfcn->eventtype = EventType;
290 SessionHookTable = newfcn;
292 syslog(LOG_INFO, "Registered a new session function (type %d)\n",
297 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
299 struct SessionFunctionHook *cur, *p;
301 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
302 /* This will also remove duplicates if any */
303 while (cur != NULL &&
304 fcn_ptr == cur->h_function_pointer &&
305 EventType == cur->eventtype) {
306 syslog(LOG_INFO, "Unregistered session function (type %d)\n",
309 if (cur == SessionHookTable) {
310 SessionHookTable = p;
318 void CtdlDestroySessionHooks(void)
320 struct SessionFunctionHook *cur, *p;
322 cur = SessionHookTable;
325 syslog(LOG_INFO, "Destroyed session function\n");
330 SessionHookTable = NULL;
334 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
337 struct UserFunctionHook *newfcn;
339 newfcn = (struct UserFunctionHook *)
340 malloc(sizeof(struct UserFunctionHook));
341 newfcn->next = UserHookTable;
342 newfcn->h_function_pointer = fcn_ptr;
343 newfcn->eventtype = EventType;
344 UserHookTable = newfcn;
346 syslog(LOG_INFO, "Registered a new user function (type %d)\n",
351 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
353 struct UserFunctionHook *cur, *p;
355 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
356 /* This will also remove duplicates if any */
357 while (cur != NULL &&
358 fcn_ptr == cur->h_function_pointer &&
359 EventType == cur->eventtype) {
360 syslog(LOG_INFO, "Unregistered user function (type %d)\n",
363 if (cur == UserHookTable) {
372 void CtdlDestroyUserHooks(void)
374 struct UserFunctionHook *cur, *p;
379 syslog(LOG_INFO, "Destroyed user function \n");
384 UserHookTable = NULL;
388 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
392 struct MessageFunctionHook *newfcn;
394 newfcn = (struct MessageFunctionHook *)
395 malloc(sizeof(struct MessageFunctionHook));
396 newfcn->next = MessageHookTable;
397 newfcn->h_function_pointer = handler;
398 newfcn->eventtype = EventType;
399 MessageHookTable = newfcn;
401 syslog(LOG_INFO, "Registered a new message function (type %d)\n",
406 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
409 struct MessageFunctionHook *cur, *p;
411 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
412 /* This will also remove duplicates if any */
413 while (cur != NULL &&
414 handler == cur->h_function_pointer &&
415 EventType == cur->eventtype) {
416 syslog(LOG_INFO, "Unregistered message function (type %d)\n",
419 if (cur == MessageHookTable) {
420 MessageHookTable = p;
428 void CtdlDestroyMessageHook(void)
430 struct MessageFunctionHook *cur, *p;
432 cur = MessageHookTable;
435 syslog(LOG_INFO, "Destroyed message function (type %d)\n", cur->eventtype);
440 MessageHookTable = NULL;
444 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
446 struct RoomFunctionHook *newfcn;
448 newfcn = (struct RoomFunctionHook *)
449 malloc(sizeof(struct RoomFunctionHook));
450 newfcn->next = RoomHookTable;
451 newfcn->fcn_ptr = fcn_ptr;
452 RoomHookTable = newfcn;
454 syslog(LOG_INFO, "Registered a new room function\n");
458 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
460 struct RoomFunctionHook *cur, *p;
462 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
463 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
464 syslog(LOG_INFO, "Unregistered room function\n");
466 if (cur == RoomHookTable) {
476 void CtdlDestroyRoomHooks(void)
478 struct RoomFunctionHook *cur, *p;
483 syslog(LOG_INFO, "Destroyed room function\n");
488 RoomHookTable = NULL;
491 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
493 struct NetprocFunctionHook *newfcn;
495 newfcn = (struct NetprocFunctionHook *)
496 malloc(sizeof(struct NetprocFunctionHook));
497 newfcn->next = NetprocHookTable;
498 newfcn->h_function_pointer = handler;
499 NetprocHookTable = newfcn;
501 syslog(LOG_INFO, "Registered a new netproc function\n");
505 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
507 struct NetprocFunctionHook *cur, *p;
509 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
510 /* This will also remove duplicates if any */
511 while (cur != NULL &&
512 handler == cur->h_function_pointer ) {
513 syslog(LOG_INFO, "Unregistered netproc function\n");
515 if (cur == NetprocHookTable) {
516 NetprocHookTable = p;
524 void CtdlDestroyNetprocHooks(void)
526 struct NetprocFunctionHook *cur, *p;
528 cur = NetprocHookTable;
531 syslog(LOG_INFO, "Destroyed netproc function\n");
536 NetprocHookTable = NULL;
540 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
542 struct DeleteFunctionHook *newfcn;
544 newfcn = (struct DeleteFunctionHook *)
545 malloc(sizeof(struct DeleteFunctionHook));
546 newfcn->next = DeleteHookTable;
547 newfcn->h_function_pointer = handler;
548 DeleteHookTable = newfcn;
550 syslog(LOG_INFO, "Registered a new delete function\n");
554 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
556 struct DeleteFunctionHook *cur, *p;
558 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
559 /* This will also remove duplicates if any */
560 while (cur != NULL &&
561 handler == cur->h_function_pointer ) {
562 syslog(LOG_INFO, "Unregistered delete function\n");
564 if (cur == DeleteHookTable) {
572 void CtdlDestroyDeleteHooks(void)
574 struct DeleteFunctionHook *cur, *p;
576 cur = DeleteHookTable;
579 syslog(LOG_INFO, "Destroyed delete function\n");
584 DeleteHookTable = NULL;
590 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
592 struct FixedOutputHook *newfcn;
594 newfcn = (struct FixedOutputHook *)
595 malloc(sizeof(struct FixedOutputHook));
596 newfcn->next = FixedOutputTable;
597 newfcn->h_function_pointer = handler;
598 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
599 FixedOutputTable = newfcn;
601 syslog(LOG_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
605 void CtdlUnregisterFixedOutputHook(char *content_type)
607 struct FixedOutputHook *cur, *p;
609 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
610 /* This will also remove duplicates if any */
611 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
612 syslog(LOG_INFO, "Unregistered fixed output function for %s\n", content_type);
614 if (cur == FixedOutputTable) {
615 FixedOutputTable = p;
623 void CtdlDestroyFixedOutputHooks(void)
625 struct FixedOutputHook *cur, *p;
627 cur = FixedOutputTable;
630 syslog(LOG_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
636 FixedOutputTable = NULL;
639 /* returns nonzero if we found a hook and used it */
640 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
642 struct FixedOutputHook *fcn;
644 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
645 if (!strcasecmp(content_type, fcn->content_type)) {
646 (*fcn->h_function_pointer) (content, content_length);
657 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
660 struct XmsgFunctionHook *newfcn;
662 newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook));
663 newfcn->next = XmsgHookTable;
664 newfcn->order = order;
665 newfcn->h_function_pointer = fcn_ptr;
666 XmsgHookTable = newfcn;
667 syslog(LOG_INFO, "Registered a new x-msg function (priority %d)\n", order);
671 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
673 struct XmsgFunctionHook *cur, *p;
675 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
676 /* This will also remove duplicates if any */
677 while (cur != NULL &&
678 fcn_ptr == cur->h_function_pointer &&
679 order == cur->order) {
680 syslog(LOG_INFO, "Unregistered x-msg function "
681 "(priority %d)\n", order);
683 if (cur == XmsgHookTable) {
692 void CtdlDestroyXmsgHooks(void)
694 struct XmsgFunctionHook *cur, *p;
699 syslog(LOG_INFO, "Destroyed x-msg function "
700 "(priority %d)\n", cur->order);
706 XmsgHookTable = NULL;
710 void CtdlRegisterServiceHook(int tcp_port,
712 void (*h_greeting_function) (void),
713 void (*h_command_function) (void),
714 void (*h_async_function) (void),
715 const char *ServiceName)
717 struct ServiceFunctionHook *newfcn;
722 newfcn = (struct ServiceFunctionHook *) malloc(sizeof(struct ServiceFunctionHook));
723 message = (char*) malloc (SIZ + SIZ);
725 newfcn->next = ServiceHookTable;
726 newfcn->tcp_port = tcp_port;
727 newfcn->sockpath = sockpath;
728 newfcn->h_greeting_function = h_greeting_function;
729 newfcn->h_command_function = h_command_function;
730 newfcn->h_async_function = h_async_function;
731 newfcn->ServiceName = ServiceName;
733 if (sockpath != NULL) {
734 newfcn->msock = ctdl_uds_server(sockpath, config.c_maxsessions, error);
735 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
737 else if (tcp_port <= 0) { /* port -1 to disable */
738 syslog(LOG_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
744 newfcn->msock = ctdl_tcp_server(config.c_ip_addr,
746 config.c_maxsessions,
748 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
749 config.c_ip_addr, tcp_port, ServiceName);
752 if (newfcn->msock > 0) {
753 ServiceHookTable = newfcn;
754 strcat(message, "registered.");
755 syslog(LOG_INFO, "%s\n", message);
758 AddPortError(message, error);
759 strcat(message, "FAILED.");
760 syslog(LOG_CRIT, "%s\n", message);
767 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
768 void (*h_greeting_function) (void),
769 void (*h_command_function) (void),
770 void (*h_async_function) (void)
773 struct ServiceFunctionHook *cur, *p;
775 cur = ServiceHookTable;
776 while (cur != NULL) {
777 /* This will also remove duplicates if any */
778 while (cur != NULL &&
779 !(sockpath && cur->sockpath &&
780 strcmp(sockpath, cur->sockpath)) &&
781 h_greeting_function == cur->h_greeting_function &&
782 h_command_function == cur->h_command_function &&
783 h_async_function == cur->h_async_function &&
784 tcp_port == cur->tcp_port) {
787 syslog(LOG_INFO, "Closed UNIX domain socket %s\n",
789 } else if (tcp_port) {
790 syslog(LOG_INFO, "Closed TCP port %d\n", tcp_port);
792 syslog(LOG_INFO, "Unregistered service \"%s\"\n", cur->ServiceName);
795 if (cur == ServiceHookTable) {
796 ServiceHookTable = p;
805 void CtdlShutdownServiceHooks(void)
807 /* sort of a duplicate of close_masters() but called earlier */
808 struct ServiceFunctionHook *cur;
810 cur = ServiceHookTable;
813 if (cur->msock != -1)
817 if (cur->sockpath != NULL){
818 syslog(LOG_INFO, "[%s] Closed UNIX domain socket %s\n",
822 syslog(LOG_INFO, "[%s] closing service\n",
830 void CtdlDestroyServiceHook(void)
832 struct ServiceFunctionHook *cur, *p;
834 cur = ServiceHookTable;
839 syslog(LOG_INFO, "Closed UNIX domain socket %s\n",
841 } else if (cur->tcp_port) {
842 syslog(LOG_INFO, "Closed TCP port %d\n", cur->tcp_port);
844 syslog(LOG_INFO, "Destroyed service \"%s\"\n", cur->ServiceName);
850 ServiceHookTable = NULL;
853 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
855 struct SearchFunctionHook *newfcn;
857 if (!name || !fcn_ptr) {
861 newfcn = (struct SearchFunctionHook *)
862 malloc(sizeof(struct SearchFunctionHook));
863 newfcn->next = SearchFunctionHookTable;
865 newfcn->fcn_ptr = fcn_ptr;
866 SearchFunctionHookTable = newfcn;
868 syslog(LOG_INFO, "Registered a new search function (%s)\n", name);
871 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
873 struct SearchFunctionHook *cur, *p;
875 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
876 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
877 syslog(LOG_INFO, "Unregistered search function(%s)\n", name);
879 if (cur == SearchFunctionHookTable) {
880 SearchFunctionHookTable = p;
888 void CtdlDestroySearchHooks(void)
890 struct SearchFunctionHook *cur, *p;
892 cur = SearchFunctionHookTable;
893 SearchFunctionHookTable = NULL;
894 while (cur != NULL) {
901 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
903 struct SearchFunctionHook *fcn = NULL;
905 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
906 if (!func_name || !strcmp(func_name, fcn->name)) {
907 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
915 void PerformSessionHooks(int EventType)
917 struct SessionFunctionHook *fcn = NULL;
919 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
920 if (fcn->eventtype == EventType) {
921 if (EventType == EVT_TIMER) {
922 pthread_setspecific(MyConKey, NULL); /* for every hook */
924 (*fcn->h_function_pointer) ();
929 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
931 struct UserFunctionHook *fcn = NULL;
933 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
934 if (fcn->eventtype == EventType) {
935 (*fcn->h_function_pointer) (usbuf);
940 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
942 struct MessageFunctionHook *fcn = NULL;
943 int total_retval = 0;
945 /* Other code may elect to protect this message from server-side
946 * handlers; if this is the case, don't do anything.
947 syslog(LOG_DEBUG, "** Event type is %d, flags are %d\n", EventType, msg->cm_flags);
949 if (msg->cm_flags & CM_SKIP_HOOKS) {
950 syslog(LOG_DEBUG, "Skipping hooks\n");
954 /* Otherwise, run all the hooks appropriate to this event type.
956 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
957 if (fcn->eventtype == EventType) {
958 total_retval = total_retval + (*fcn->h_function_pointer) (msg);
962 /* Return the sum of the return codes from the hook functions. If
963 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
964 * the save operation to abort.
970 int PerformRoomHooks(struct ctdlroom *target_room)
972 struct RoomFunctionHook *fcn;
973 int total_retval = 0;
975 syslog(LOG_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
977 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
978 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
981 /* Return the sum of the return codes from the hook functions.
987 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
989 struct NetprocFunctionHook *fcn;
990 int total_retval = 0;
992 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
993 total_retval = total_retval +
994 (*fcn->h_function_pointer) (msg, target_room);
997 /* Return the sum of the return codes from the hook functions.
998 * A nonzero return code will cause the message to *not* be imported.
1000 return total_retval;
1004 void PerformDeleteHooks(char *room, long msgnum)
1006 struct DeleteFunctionHook *fcn;
1008 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1009 (*fcn->h_function_pointer) (room, msgnum);
1017 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1019 struct XmsgFunctionHook *fcn;
1023 for (p=0; p<MAX_XMSG_PRI; ++p) {
1024 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1025 if (fcn->order == p) {
1027 (*fcn->h_function_pointer)
1028 (sender, sender_email, recp, msg);
1031 /* Break out of the loop if a higher-priority function
1032 * successfully delivered the message. This prevents duplicate
1033 * deliveries to local users simultaneously signed onto
1036 if (total_sent) break;
1043 * Dirty hack until we impliment a hook mechanism for this
1045 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1048 CtdlStartTLS (ok_response, nosup_response, error_response);