2 * Citadel Dynamic Loading Module
3 * Written by Brian Costello <btx@calyx.net>
10 #include <sys/types.h>
15 #include <libcitadel.h>
18 #include "serv_extensions.h"
19 #include "sysdep_decls.h"
23 #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
25 #include "ctdl_module.h"
32 struct CleanupFunctionHook *CleanupHookTable = NULL;
33 struct SessionFunctionHook *SessionHookTable = NULL;
34 struct UserFunctionHook *UserHookTable = NULL;
35 struct XmsgFunctionHook *XmsgHookTable = NULL;
36 struct MessageFunctionHook *MessageHookTable = NULL;
37 struct NetprocFunctionHook *NetprocHookTable = NULL;
38 struct DeleteFunctionHook *DeleteHookTable = NULL;
39 struct ServiceFunctionHook *ServiceHookTable = NULL;
40 struct FixedOutputHook *FixedOutputTable = NULL;
41 struct RoomFunctionHook *RoomHookTable = NULL;
42 struct SearchFunctionHook *SearchFunctionHookTable = NULL;
44 struct ProtoFunctionHook {
45 void (*handler) (char *cmdbuf);
50 HashList *ProtoHookList = NULL;
53 #define ERR_PORT (1 << 1)
56 static char *portlist = NULL;
57 static size_t nSizPort = 0;
59 static char *errormessages = NULL;
60 size_t nSizErrmsg = 0;
63 long DetailErrorFlags;
65 char *ErrSubject = "Startup Problems";
66 char *ErrGeneral = "Citadel had trouble on starting up. %s This means, citadel won't be the service provider for a specific service you configured it to.\n\n"
67 "If you don't want citadel to provide these services, turn them off in WebCit via %s%s\n\n%s\n\n"
68 "To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
69 "The errors returned by the system were:\n%s\n"
70 "You can recheck the above if you follow this faq item:\n"
71 "http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat";
74 char *ErrPortShort = "We couldn't bind all ports you configured to be provided by citadel server.";
75 char *ErrPortWhere = "Admin->System Preferences->Network.\n\nThe failed ports and sockets are: ";
76 char *ErrPortHint = "If you want citadel to provide you with that functionality, "
77 "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD"
78 " and stop the programm, that binds these ports.\n You should eventually remove "
79 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
80 " After that goto Administration -> Shutdown Citadel to make Citadel retry to bind this port.\n";
83 void LogPrintMessages(long err)
85 char *List, *DetailList, *Short, *Where, *Hint, *Message;
86 int n = nSizPort + nSizErrmsg + 5;
88 Message = (char*) malloc(n * SIZ);
90 DetailErrorFlags = DetailErrorFlags & ~err;
99 DetailList = errormessages;
110 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
112 CtdlLogPrintf(0,Message);
113 CtdlLogPrintf(0,ErrSubject);
114 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
115 if (errormessages!=NULL) free (errormessages);
116 errormessages = NULL;
117 if (portlist!=NULL) free (portlist);
124 void AppendString(char **target, char *append, size_t *len, size_t rate)
130 AddLen = strlen(append);
136 *target = (char*)malloc (*len * SIZ);
140 oLen = strlen(*target);
141 RelPtr = strlen(*target);
142 if (oLen + AddLen + 2 > *len * SIZ)
144 char *Buff = *target;
145 size_t NewSiz = *len + 10;
146 *target = malloc (NewSiz * SIZ);
147 memcpy (*target, Buff, NewSiz * SIZ);
151 memcpy (*target + oLen, append, AddLen);
152 (*target)[oLen + AddLen + 1] = '\n';
153 (*target)[oLen + AddLen + 2] = '\0';
156 void AddPortError(char *Port, char *ErrorMessage)
161 DetailErrorFlags |= ERR_PORT;
163 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
164 AppendString(&portlist, Port, &nSizPort, 2);
166 pos = strchr (portlist, ':');
167 if (pos != NULL) *pos = ';';
169 len = strlen (errormessages);
170 if (nSizErrmsg * SIZ > len + 3)
172 errormessages[len] = ';';
173 errormessages[len+1] = ' ';
174 errormessages[len+2] = '\0';
179 int DLoader_Exec_Cmd(char *cmdbuf)
182 struct ProtoFunctionHook *p;
184 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
185 p = (struct ProtoFunctionHook*) vP;
186 p->handler(&cmdbuf[5]);
192 long FourHash(const char *key, long length)
196 const unsigned char *ptr = (const unsigned char*)key;
198 for (i = 0; i < 4; i++, ptr ++)
208 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
210 struct ProtoFunctionHook *p;
212 if (ProtoHookList == NULL)
213 ProtoHookList = NewHash (1, FourHash);
216 p = (struct ProtoFunctionHook *)
217 malloc(sizeof(struct ProtoFunctionHook));
220 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
223 p->handler = handler;
227 Put(ProtoHookList, cmd, 4, p, NULL);
228 CtdlLogPrintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
231 void CtdlDestroyProtoHooks(void)
234 DeleteHash(&ProtoHookList);
238 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
241 struct CleanupFunctionHook *newfcn;
243 newfcn = (struct CleanupFunctionHook *)
244 malloc(sizeof(struct CleanupFunctionHook));
245 newfcn->next = CleanupHookTable;
246 newfcn->h_function_pointer = fcn_ptr;
247 CleanupHookTable = newfcn;
249 CtdlLogPrintf(CTDL_INFO, "Registered a new cleanup function\n");
253 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
255 struct CleanupFunctionHook *cur, *p;
257 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
258 /* This will also remove duplicates if any */
259 while (cur != NULL &&
260 fcn_ptr == cur->h_function_pointer) {
261 CtdlLogPrintf(CTDL_INFO, "Unregistered cleanup function\n");
263 if (cur == CleanupHookTable) {
264 CleanupHookTable = p;
272 void CtdlDestroyCleanupHooks(void)
274 struct CleanupFunctionHook *cur, *p;
276 cur = CleanupHookTable;
279 CtdlLogPrintf(CTDL_INFO, "Destroyed cleanup function\n");
284 CleanupHookTable = NULL;
288 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
291 struct SessionFunctionHook *newfcn;
293 newfcn = (struct SessionFunctionHook *)
294 malloc(sizeof(struct SessionFunctionHook));
295 newfcn->next = SessionHookTable;
296 newfcn->h_function_pointer = fcn_ptr;
297 newfcn->eventtype = EventType;
298 SessionHookTable = newfcn;
300 CtdlLogPrintf(CTDL_INFO, "Registered a new session function (type %d)\n",
305 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
307 struct SessionFunctionHook *cur, *p;
309 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
310 /* This will also remove duplicates if any */
311 while (cur != NULL &&
312 fcn_ptr == cur->h_function_pointer &&
313 EventType == cur->eventtype) {
314 CtdlLogPrintf(CTDL_INFO, "Unregistered session function (type %d)\n",
317 if (cur == SessionHookTable) {
318 SessionHookTable = p;
326 void CtdlDestroySessionHooks(void)
328 struct SessionFunctionHook *cur, *p;
330 cur = SessionHookTable;
333 CtdlLogPrintf(CTDL_INFO, "Destroyed session function\n");
338 SessionHookTable = NULL;
342 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
345 struct UserFunctionHook *newfcn;
347 newfcn = (struct UserFunctionHook *)
348 malloc(sizeof(struct UserFunctionHook));
349 newfcn->next = UserHookTable;
350 newfcn->h_function_pointer = fcn_ptr;
351 newfcn->eventtype = EventType;
352 UserHookTable = newfcn;
354 CtdlLogPrintf(CTDL_INFO, "Registered a new user function (type %d)\n",
359 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
361 struct UserFunctionHook *cur, *p;
363 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
364 /* This will also remove duplicates if any */
365 while (cur != NULL &&
366 fcn_ptr == cur->h_function_pointer &&
367 EventType == cur->eventtype) {
368 CtdlLogPrintf(CTDL_INFO, "Unregistered user function (type %d)\n",
371 if (cur == UserHookTable) {
380 void CtdlDestroyUserHooks(void)
382 struct UserFunctionHook *cur, *p;
387 CtdlLogPrintf(CTDL_INFO, "Destroyed user function \n");
392 UserHookTable = NULL;
396 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
400 struct MessageFunctionHook *newfcn;
402 newfcn = (struct MessageFunctionHook *)
403 malloc(sizeof(struct MessageFunctionHook));
404 newfcn->next = MessageHookTable;
405 newfcn->h_function_pointer = handler;
406 newfcn->eventtype = EventType;
407 MessageHookTable = newfcn;
409 CtdlLogPrintf(CTDL_INFO, "Registered a new message function (type %d)\n",
414 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
417 struct MessageFunctionHook *cur, *p;
419 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
420 /* This will also remove duplicates if any */
421 while (cur != NULL &&
422 handler == cur->h_function_pointer &&
423 EventType == cur->eventtype) {
424 CtdlLogPrintf(CTDL_INFO, "Unregistered message function (type %d)\n",
427 if (cur == MessageHookTable) {
428 MessageHookTable = p;
436 void CtdlDestroyMessageHook(void)
438 struct MessageFunctionHook *cur, *p;
440 cur = MessageHookTable;
443 CtdlLogPrintf(CTDL_INFO, "Destroyed message function (type %d)\n", cur->eventtype);
448 MessageHookTable = NULL;
452 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
454 struct RoomFunctionHook *newfcn;
456 newfcn = (struct RoomFunctionHook *)
457 malloc(sizeof(struct RoomFunctionHook));
458 newfcn->next = RoomHookTable;
459 newfcn->fcn_ptr = fcn_ptr;
460 RoomHookTable = newfcn;
462 CtdlLogPrintf(CTDL_INFO, "Registered a new room function\n");
466 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
468 struct RoomFunctionHook *cur, *p;
470 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
471 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
472 CtdlLogPrintf(CTDL_INFO, "Unregistered room function\n");
474 if (cur == RoomHookTable) {
484 void CtdlDestroyRoomHooks(void)
486 struct RoomFunctionHook *cur, *p;
491 CtdlLogPrintf(CTDL_INFO, "Destroyed room function\n");
496 RoomHookTable = NULL;
499 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
501 struct NetprocFunctionHook *newfcn;
503 newfcn = (struct NetprocFunctionHook *)
504 malloc(sizeof(struct NetprocFunctionHook));
505 newfcn->next = NetprocHookTable;
506 newfcn->h_function_pointer = handler;
507 NetprocHookTable = newfcn;
509 CtdlLogPrintf(CTDL_INFO, "Registered a new netproc function\n");
513 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
515 struct NetprocFunctionHook *cur, *p;
517 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
518 /* This will also remove duplicates if any */
519 while (cur != NULL &&
520 handler == cur->h_function_pointer ) {
521 CtdlLogPrintf(CTDL_INFO, "Unregistered netproc function\n");
523 if (cur == NetprocHookTable) {
524 NetprocHookTable = p;
532 void CtdlDestroyNetprocHooks(void)
534 struct NetprocFunctionHook *cur, *p;
536 cur = NetprocHookTable;
539 CtdlLogPrintf(CTDL_INFO, "Destroyed netproc function\n");
544 NetprocHookTable = NULL;
548 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
550 struct DeleteFunctionHook *newfcn;
552 newfcn = (struct DeleteFunctionHook *)
553 malloc(sizeof(struct DeleteFunctionHook));
554 newfcn->next = DeleteHookTable;
555 newfcn->h_function_pointer = handler;
556 DeleteHookTable = newfcn;
558 CtdlLogPrintf(CTDL_INFO, "Registered a new delete function\n");
562 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
564 struct DeleteFunctionHook *cur, *p;
566 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
567 /* This will also remove duplicates if any */
568 while (cur != NULL &&
569 handler == cur->h_function_pointer ) {
570 CtdlLogPrintf(CTDL_INFO, "Unregistered delete function\n");
572 if (cur == DeleteHookTable) {
580 void CtdlDestroyDeleteHooks(void)
582 struct DeleteFunctionHook *cur, *p;
584 cur = DeleteHookTable;
587 CtdlLogPrintf(CTDL_INFO, "Destroyed delete function\n");
592 DeleteHookTable = NULL;
598 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
600 struct FixedOutputHook *newfcn;
602 newfcn = (struct FixedOutputHook *)
603 malloc(sizeof(struct FixedOutputHook));
604 newfcn->next = FixedOutputTable;
605 newfcn->h_function_pointer = handler;
606 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
607 FixedOutputTable = newfcn;
609 CtdlLogPrintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
613 void CtdlUnregisterFixedOutputHook(char *content_type)
615 struct FixedOutputHook *cur, *p;
617 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
618 /* This will also remove duplicates if any */
619 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
620 CtdlLogPrintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
622 if (cur == FixedOutputTable) {
623 FixedOutputTable = p;
631 void CtdlDestroyFixedOutputHooks(void)
633 struct FixedOutputHook *cur, *p;
635 cur = FixedOutputTable;
638 CtdlLogPrintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
644 FixedOutputTable = NULL;
647 /* returns nonzero if we found a hook and used it */
648 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
650 struct FixedOutputHook *fcn;
652 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
653 if (!strcasecmp(content_type, fcn->content_type)) {
654 (*fcn->h_function_pointer) (content, content_length);
665 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
668 struct XmsgFunctionHook *newfcn;
670 newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook));
671 newfcn->next = XmsgHookTable;
672 newfcn->order = order;
673 newfcn->h_function_pointer = fcn_ptr;
674 XmsgHookTable = newfcn;
675 CtdlLogPrintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
679 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
681 struct XmsgFunctionHook *cur, *p;
683 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
684 /* This will also remove duplicates if any */
685 while (cur != NULL &&
686 fcn_ptr == cur->h_function_pointer &&
687 order == cur->order) {
688 CtdlLogPrintf(CTDL_INFO, "Unregistered x-msg function "
689 "(priority %d)\n", order);
691 if (cur == XmsgHookTable) {
700 void CtdlDestroyXmsgHooks(void)
702 struct XmsgFunctionHook *cur, *p;
707 CtdlLogPrintf(CTDL_INFO, "Destroyed x-msg function "
708 "(priority %d)\n", cur->order);
714 XmsgHookTable = NULL;
718 void CtdlRegisterServiceHook(int tcp_port,
720 void (*h_greeting_function) (void),
721 void (*h_command_function) (void),
722 void (*h_async_function) (void),
723 const char *ServiceName)
725 struct ServiceFunctionHook *newfcn;
730 newfcn = (struct ServiceFunctionHook *) malloc(sizeof(struct ServiceFunctionHook));
731 message = (char*) malloc (SIZ + SIZ);
733 newfcn->next = ServiceHookTable;
734 newfcn->tcp_port = tcp_port;
735 newfcn->sockpath = sockpath;
736 newfcn->h_greeting_function = h_greeting_function;
737 newfcn->h_command_function = h_command_function;
738 newfcn->h_async_function = h_async_function;
739 newfcn->ServiceName = ServiceName;
741 if (sockpath != NULL) {
742 newfcn->msock = ctdl_uds_server(sockpath, config.c_maxsessions, error);
743 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
745 else if (tcp_port <= 0) { /* port -1 to disable */
746 CtdlLogPrintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
752 newfcn->msock = ctdl_tcp_server(config.c_ip_addr,
754 config.c_maxsessions,
756 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
757 config.c_ip_addr, tcp_port, ServiceName);
760 if (newfcn->msock > 0) {
761 ServiceHookTable = newfcn;
762 strcat(message, "registered.");
763 CtdlLogPrintf(CTDL_INFO, "%s\n", message);
766 AddPortError(message, error);
767 strcat(message, "FAILED.");
768 CtdlLogPrintf(CTDL_CRIT, "%s\n", message);
775 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
776 void (*h_greeting_function) (void),
777 void (*h_command_function) (void),
778 void (*h_async_function) (void)
781 struct ServiceFunctionHook *cur, *p;
783 cur = ServiceHookTable;
784 while (cur != NULL) {
785 /* This will also remove duplicates if any */
786 while (cur != NULL &&
787 !(sockpath && cur->sockpath &&
788 strcmp(sockpath, cur->sockpath)) &&
789 h_greeting_function == cur->h_greeting_function &&
790 h_command_function == cur->h_command_function &&
791 h_async_function == cur->h_async_function &&
792 tcp_port == cur->tcp_port) {
795 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
797 } else if (tcp_port) {
798 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
800 CtdlLogPrintf(CTDL_INFO, "Unregistered service \"%s\"\n", cur->ServiceName);
803 if (cur == ServiceHookTable) {
804 ServiceHookTable = p;
813 void CtdlShutdownServiceHooks(void)
815 /* sort of a duplicate of close_masters() but called earlier */
816 struct ServiceFunctionHook *cur;
818 cur = ServiceHookTable;
821 if (cur->msock != -1)
825 if (cur->sockpath != NULL){
826 CtdlLogPrintf(CTDL_INFO, "[%s] Closed UNIX domain socket %s\n",
830 CtdlLogPrintf(CTDL_INFO, "[%s] closing service\n",
838 void CtdlDestroyServiceHook(void)
840 struct ServiceFunctionHook *cur, *p;
842 cur = ServiceHookTable;
847 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
849 } else if (cur->tcp_port) {
850 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
852 CtdlLogPrintf(CTDL_INFO, "Destroyed service \"%s\"\n", cur->ServiceName);
858 ServiceHookTable = NULL;
861 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
863 struct SearchFunctionHook *newfcn;
865 if (!name || !fcn_ptr) {
869 newfcn = (struct SearchFunctionHook *)
870 malloc(sizeof(struct SearchFunctionHook));
871 newfcn->next = SearchFunctionHookTable;
873 newfcn->fcn_ptr = fcn_ptr;
874 SearchFunctionHookTable = newfcn;
876 CtdlLogPrintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
879 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
881 struct SearchFunctionHook *cur, *p;
883 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
884 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
885 CtdlLogPrintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
887 if (cur == SearchFunctionHookTable) {
888 SearchFunctionHookTable = p;
896 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
898 struct SearchFunctionHook *fcn = NULL;
900 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
901 if (!func_name || !strcmp(func_name, fcn->name)) {
902 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
910 void PerformSessionHooks(int EventType)
912 struct SessionFunctionHook *fcn = NULL;
914 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
915 if (fcn->eventtype == EventType) {
916 if (EventType == EVT_TIMER) {
917 citthread_setspecific(MyConKey, NULL); /* for every hook */
919 (*fcn->h_function_pointer) ();
924 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
926 struct UserFunctionHook *fcn = NULL;
928 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
929 if (fcn->eventtype == EventType) {
930 (*fcn->h_function_pointer) (usbuf);
935 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
937 struct MessageFunctionHook *fcn = NULL;
938 int total_retval = 0;
940 /* Other code may elect to protect this message from server-side
941 * handlers; if this is the case, don't do anything.
942 CtdlLogPrintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
943 EventType, msg->cm_flags);
945 if (msg->cm_flags & CM_SKIP_HOOKS) {
946 CtdlLogPrintf(CTDL_DEBUG, "Skipping hooks\n");
950 /* Otherwise, run all the hooks appropriate to this event type.
952 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
953 if (fcn->eventtype == EventType) {
954 total_retval = total_retval +
955 (*fcn->h_function_pointer) (msg);
959 /* Return the sum of the return codes from the hook functions. If
960 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
961 * the save operation to abort.
967 int PerformRoomHooks(struct ctdlroom *target_room)
969 struct RoomFunctionHook *fcn;
970 int total_retval = 0;
972 CtdlLogPrintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
974 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
975 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
978 /* Return the sum of the return codes from the hook functions.
984 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
986 struct NetprocFunctionHook *fcn;
987 int total_retval = 0;
989 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
990 total_retval = total_retval +
991 (*fcn->h_function_pointer) (msg, target_room);
994 /* Return the sum of the return codes from the hook functions.
995 * A nonzero return code will cause the message to *not* be imported.
1001 void PerformDeleteHooks(char *room, long msgnum)
1003 struct DeleteFunctionHook *fcn;
1005 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1006 (*fcn->h_function_pointer) (room, msgnum);
1014 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1016 struct XmsgFunctionHook *fcn;
1020 for (p=0; p<MAX_XMSG_PRI; ++p) {
1021 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1022 if (fcn->order == p) {
1024 (*fcn->h_function_pointer)
1025 (sender, sender_email, recp, msg);
1028 /* Break out of the loop if a higher-priority function
1029 * successfully delivered the message. This prevents duplicate
1030 * deliveries to local users simultaneously signed onto
1033 if (total_sent) break;
1040 * Dirty hack until we impliment a hook mechanism for this
1042 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1045 CtdlStartTLS (ok_response, nosup_response, error_response);