4 * Citadel Dynamic Loading Module
5 * Written by Brian Costello <btx@calyx.net>
13 #include <sys/types.h>
20 #include "serv_extensions.h"
21 #include "sysdep_decls.h"
26 #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
33 struct CleanupFunctionHook *CleanupHookTable = NULL;
34 struct SessionFunctionHook *SessionHookTable = NULL;
35 struct UserFunctionHook *UserHookTable = NULL;
36 struct XmsgFunctionHook *XmsgHookTable = NULL;
37 struct MessageFunctionHook *MessageHookTable = NULL;
38 struct NetprocFunctionHook *NetprocHookTable = NULL;
39 struct DeleteFunctionHook *DeleteHookTable = NULL;
40 struct ServiceFunctionHook *ServiceHookTable = NULL;
41 struct FixedOutputHook *FixedOutputTable = NULL;
42 struct RoomFunctionHook *RoomHookTable = NULL;
43 struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL;
45 struct ProtoFunctionHook {
46 void (*handler) (char *cmdbuf);
49 struct ProtoFunctionHook *next;
50 } *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 static size_t nSizErrmsg = 0;
63 static 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. You should eventually remove "
79 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n";
82 void LogPrintMessages(long err)
84 char *List, *DetailList, *Short, *Where, *Hint, *Message;
85 int n = nSizPort + nSizErrmsg + 5;
87 Message = (char*) malloc(n * SIZ);
96 DetailList = errormessages;
107 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
109 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
110 if (errormessages!=NULL) free (errormessages);
111 errormessages = NULL;
112 if (portlist!=NULL) free (portlist);
119 void AppendString(char **target, char *append, size_t *len, size_t rate)
125 AddLen = strlen(append);
131 *target = (char*)malloc (*len * SIZ);
135 oLen = strlen(*target);
136 RelPtr = strlen(*target);
137 if (oLen + AddLen + 2 > *len * SIZ)
139 char *Buff = *target;
140 size_t NewSiz = *len + 10;
141 *target = malloc (NewSiz * SIZ);
142 memcpy (*target, Buff, NewSiz * SIZ);
146 memcpy (*target + oLen, append, AddLen);
147 (*target)[oLen + AddLen + 1] = '\n';
148 (*target)[oLen + AddLen + 2] = '\0';
151 void AddPortError(char *Port, char *ErrorMessage)
156 DetailErrorFlags |= ERR_PORT;
158 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
159 AppendString(&portlist, Port, &nSizPort, 2);
161 pos = strchr (portlist, ':');
162 if (pos != NULL) *pos = ';';
164 len = strlen (errormessages);
165 if (nSizErrmsg * SIZ > len + 3)
167 errormessages[len] = ';';
168 errormessages[len+1] = ' ';
169 errormessages[len+2] = '\0';
174 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
176 struct ProtoFunctionHook *p;
178 p = (struct ProtoFunctionHook *)
179 malloc(sizeof(struct ProtoFunctionHook));
182 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
185 p->handler = handler;
188 p->next = ProtoHookList;
190 lprintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
194 void CtdlUnregisterProtoHook(void (*handler) (char *), char *cmd)
196 struct ProtoFunctionHook *cur = NULL;
197 struct ProtoFunctionHook *p = NULL;
198 struct ProtoFunctionHook *lastcur = NULL;
200 for (cur = ProtoHookList;
202 cur = (cur != NULL)? cur->next: NULL) {
203 /* This will also remove duplicates if any */
204 while (cur != NULL &&
205 handler == cur->handler &&
206 !strcmp(cmd, cur->cmd)) {
207 lprintf(CTDL_INFO, "Unregistered server command %s (%s)\n",
210 if (cur == ProtoHookList) {
213 else if (lastcur != NULL)
224 void CtdlDestroyProtoHooks(void)
226 struct ProtoFunctionHook *cur, *p;
231 lprintf(CTDL_INFO, "Destroyed server command %s (%s)\n",
232 cur->cmd, cur->desc);
237 ProtoHookList = NULL;
241 int DLoader_Exec_Cmd(char *cmdbuf)
243 struct ProtoFunctionHook *p;
245 for (p = ProtoHookList; p; p = p->next) {
246 if (!strncasecmp(cmdbuf, p->cmd, 4)) {
247 p->handler(&cmdbuf[5]);
255 void initialize_server_extensions(void)
261 /*lprintf(CTDL_INFO, "%s\n", serv_bio_init());
262 lprintf(CTDL_INFO, "%s\n", serv_calendar_init());
263 lprintf(CTDL_INFO, "%s\n", serv_notes_init());
264 lprintf(CTDL_INFO, "%s\n", serv_ldap_init());
265 lprintf(CTDL_INFO, "%s\n", serv_chat_init());
266 lprintf(CTDL_INFO, "%s\n", serv_expire_init());
267 lprintf(CTDL_INFO, "%s\n", serv_imap_init());
268 lprintf(CTDL_INFO, "%s\n", serv_upgrade_init());
269 lprintf(CTDL_INFO, "%s\n", serv_inetcfg_init());
270 lprintf(CTDL_INFO, "%s\n", serv_listsub_init());
271 lprintf(CTDL_INFO, "%s\n", serv_mrtg_init());
272 lprintf(CTDL_INFO, "%s\n", serv_netfilter_init());
273 lprintf(CTDL_INFO, "%s\n", serv_network_init());
274 lprintf(CTDL_INFO, "%s\n", serv_newuser_init());
275 lprintf(CTDL_INFO, "%s\n", serv_pas2_init());
276 lprintf(CTDL_INFO, "%s\n", serv_smtp_init());
277 lprintf(CTDL_INFO, "%s\n", serv_pop3_init());
278 lprintf(CTDL_INFO, "%s\n", serv_rwho_init());
279 lprintf(CTDL_INFO, "%s\n", serv_spam_init());*/
280 /* lprintf(CTDL_INFO, "%s\n", serv_test_init()); */
281 /*lprintf(CTDL_INFO, "%s\n", serv_vandelay_init());
282 lprintf(CTDL_INFO, "%s\n", serv_vcard_init());
283 lprintf(CTDL_INFO, "%s\n", serv_fulltext_init());
284 lprintf(CTDL_INFO, "%s\n", serv_autocompletion_init());
285 lprintf(CTDL_INFO, "%s\n", serv_postfix_tcpdict());
286 lprintf(CTDL_INFO, "%s\n", serv_sieve_init());
287 lprintf(CTDL_INFO, "%s\n", serv_managesieve_init());
288 lprintf(CTDL_INFO, "%s\n", serv_funambol_init());*/
289 for (filter = 1; filter != 0; filter = filter << 1)
290 if ((filter & DetailErrorFlags) != 0)
291 LogPrintMessages(filter);
296 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
299 struct CleanupFunctionHook *newfcn;
301 newfcn = (struct CleanupFunctionHook *)
302 malloc(sizeof(struct CleanupFunctionHook));
303 newfcn->next = CleanupHookTable;
304 newfcn->h_function_pointer = fcn_ptr;
305 CleanupHookTable = newfcn;
307 lprintf(CTDL_INFO, "Registered a new cleanup function\n");
311 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
313 struct CleanupFunctionHook *cur, *p;
315 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
316 /* This will also remove duplicates if any */
317 while (cur != NULL &&
318 fcn_ptr == cur->h_function_pointer) {
319 lprintf(CTDL_INFO, "Unregistered cleanup function\n");
321 if (cur == CleanupHookTable) {
322 CleanupHookTable = p;
330 void CtdlDestroyCleanupHooks(void)
332 struct CleanupFunctionHook *cur, *p;
334 cur = CleanupHookTable;
337 lprintf(CTDL_INFO, "Destroyed cleanup function\n");
342 CleanupHookTable = NULL;
346 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
349 struct SessionFunctionHook *newfcn;
351 newfcn = (struct SessionFunctionHook *)
352 malloc(sizeof(struct SessionFunctionHook));
353 newfcn->next = SessionHookTable;
354 newfcn->h_function_pointer = fcn_ptr;
355 newfcn->eventtype = EventType;
356 SessionHookTable = newfcn;
358 lprintf(CTDL_INFO, "Registered a new session function (type %d)\n",
363 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
365 struct SessionFunctionHook *cur, *p;
367 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
368 /* This will also remove duplicates if any */
369 while (cur != NULL &&
370 fcn_ptr == cur->h_function_pointer &&
371 EventType == cur->eventtype) {
372 lprintf(CTDL_INFO, "Unregistered session function (type %d)\n",
375 if (cur == SessionHookTable) {
376 SessionHookTable = p;
384 void CtdlDestroySessionHooks(void)
386 struct SessionFunctionHook *cur, *p;
388 cur = SessionHookTable;
391 lprintf(CTDL_INFO, "Destroyed session function\n");
396 SessionHookTable = NULL;
400 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
403 struct UserFunctionHook *newfcn;
405 newfcn = (struct UserFunctionHook *)
406 malloc(sizeof(struct UserFunctionHook));
407 newfcn->next = UserHookTable;
408 newfcn->h_function_pointer = fcn_ptr;
409 newfcn->eventtype = EventType;
410 UserHookTable = newfcn;
412 lprintf(CTDL_INFO, "Registered a new user function (type %d)\n",
417 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
419 struct UserFunctionHook *cur, *p;
421 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
422 /* This will also remove duplicates if any */
423 while (cur != NULL &&
424 fcn_ptr == cur->h_function_pointer &&
425 EventType == cur->eventtype) {
426 lprintf(CTDL_INFO, "Unregistered user function (type %d)\n",
429 if (cur == UserHookTable) {
438 void CtdlDestroyUserHooks(void)
440 struct UserFunctionHook *cur, *p;
445 lprintf(CTDL_INFO, "Destroyed user function \n");
450 UserHookTable = NULL;
454 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
458 struct MessageFunctionHook *newfcn;
460 newfcn = (struct MessageFunctionHook *)
461 malloc(sizeof(struct MessageFunctionHook));
462 newfcn->next = MessageHookTable;
463 newfcn->h_function_pointer = handler;
464 newfcn->eventtype = EventType;
465 MessageHookTable = newfcn;
467 lprintf(CTDL_INFO, "Registered a new message function (type %d)\n",
472 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
475 struct MessageFunctionHook *cur, *p;
477 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
478 /* This will also remove duplicates if any */
479 while (cur != NULL &&
480 handler == cur->h_function_pointer &&
481 EventType == cur->eventtype) {
482 lprintf(CTDL_INFO, "Unregistered message function (type %d)\n",
485 if (cur == MessageHookTable) {
486 MessageHookTable = p;
494 void CtdlDestroyMessageHook(void)
496 struct MessageFunctionHook *cur, *p;
498 cur = MessageHookTable;
501 lprintf(CTDL_INFO, "Destroyed message function \n");
506 MessageHookTable = NULL;
510 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
512 struct RoomFunctionHook *newfcn;
514 newfcn = (struct RoomFunctionHook *)
515 malloc(sizeof(struct RoomFunctionHook));
516 newfcn->next = RoomHookTable;
517 newfcn->fcn_ptr = fcn_ptr;
518 RoomHookTable = newfcn;
520 lprintf(CTDL_INFO, "Registered a new room function\n");
524 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
526 struct RoomFunctionHook *cur, *p;
528 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
529 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
530 lprintf(CTDL_INFO, "Unregistered room function\n");
532 if (cur == RoomHookTable) {
542 void CtdlDestroyRoomHooks(void)
544 struct RoomFunctionHook *cur, *p;
549 lprintf(CTDL_INFO, "Unregistered room function\n");
554 RoomHookTable = NULL;
557 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
559 struct NetprocFunctionHook *newfcn;
561 newfcn = (struct NetprocFunctionHook *)
562 malloc(sizeof(struct NetprocFunctionHook));
563 newfcn->next = NetprocHookTable;
564 newfcn->h_function_pointer = handler;
565 NetprocHookTable = newfcn;
567 lprintf(CTDL_INFO, "Registered a new netproc function\n");
571 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
573 struct NetprocFunctionHook *cur, *p;
575 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
576 /* This will also remove duplicates if any */
577 while (cur != NULL &&
578 handler == cur->h_function_pointer ) {
579 lprintf(CTDL_INFO, "Unregistered netproc function\n");
581 if (cur == NetprocHookTable) {
582 NetprocHookTable = p;
590 void CtdlDestroyNetprocHooks(void)
592 struct NetprocFunctionHook *cur, *p;
594 cur = NetprocHookTable;
597 lprintf(CTDL_INFO, "Unregistered netproc function\n");
602 NetprocHookTable = NULL;
606 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
608 struct DeleteFunctionHook *newfcn;
610 newfcn = (struct DeleteFunctionHook *)
611 malloc(sizeof(struct DeleteFunctionHook));
612 newfcn->next = DeleteHookTable;
613 newfcn->h_function_pointer = handler;
614 DeleteHookTable = newfcn;
616 lprintf(CTDL_INFO, "Registered a new netproc function\n");
620 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
622 struct DeleteFunctionHook *cur, *p;
624 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
625 /* This will also remove duplicates if any */
626 while (cur != NULL &&
627 handler == cur->h_function_pointer ) {
628 lprintf(CTDL_INFO, "Unregistered netproc function\n");
630 if (cur == DeleteHookTable) {
638 void CtdlDestroyDeleteHooks(void)
640 struct DeleteFunctionHook *cur, *p;
642 cur = DeleteHookTable;
645 lprintf(CTDL_INFO, "Destroyed netproc function\n");
650 DeleteHookTable = NULL;
656 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
658 struct FixedOutputHook *newfcn;
660 newfcn = (struct FixedOutputHook *)
661 malloc(sizeof(struct FixedOutputHook));
662 newfcn->next = FixedOutputTable;
663 newfcn->h_function_pointer = handler;
664 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
665 FixedOutputTable = newfcn;
667 lprintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
671 void CtdlUnregisterFixedOutputHook(char *content_type)
673 struct FixedOutputHook *cur, *p;
675 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
676 /* This will also remove duplicates if any */
677 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
678 lprintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
680 if (cur == FixedOutputTable) {
681 FixedOutputTable = p;
689 void CtdlDestroyFixedOutputHooks(void)
691 struct FixedOutputHook *cur, *p;
693 cur = FixedOutputTable;
696 lprintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
702 FixedOutputTable = NULL;
705 /* returns nonzero if we found a hook and used it */
706 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
708 struct FixedOutputHook *fcn;
710 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
711 if (!strcasecmp(content_type, fcn->content_type)) {
712 (*fcn->h_function_pointer) (content, content_length);
723 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
726 struct XmsgFunctionHook *newfcn;
728 newfcn = (struct XmsgFunctionHook *)
729 malloc(sizeof(struct XmsgFunctionHook));
730 newfcn->next = XmsgHookTable;
731 newfcn->order = order;
732 newfcn->h_function_pointer = fcn_ptr;
733 XmsgHookTable = newfcn;
734 lprintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
738 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
740 struct XmsgFunctionHook *cur, *p;
742 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
743 /* This will also remove duplicates if any */
744 while (cur != NULL &&
745 fcn_ptr == cur->h_function_pointer &&
746 order == cur->order) {
747 lprintf(CTDL_INFO, "Unregistered x-msg function "
748 "(priority %d)\n", order);
750 if (cur == XmsgHookTable) {
759 void CtdlDestroyXmsgHooks(void)
761 struct XmsgFunctionHook *cur, *p;
766 lprintf(CTDL_INFO, "Destroyed x-msg function "
767 "(priority %d)\n", cur->order);
773 XmsgHookTable = NULL;
777 void CtdlRegisterServiceHook(int tcp_port,
779 void (*h_greeting_function) (void),
780 void (*h_command_function) (void),
781 void (*h_async_function) (void)
784 struct ServiceFunctionHook *newfcn;
789 newfcn = (struct ServiceFunctionHook *)
790 malloc(sizeof(struct ServiceFunctionHook));
791 message = (char*) malloc (SIZ);
793 newfcn->next = ServiceHookTable;
794 newfcn->tcp_port = tcp_port;
795 newfcn->sockpath = sockpath;
796 newfcn->h_greeting_function = h_greeting_function;
797 newfcn->h_command_function = h_command_function;
798 newfcn->h_async_function = h_async_function;
800 if (sockpath != NULL) {
801 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
802 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
804 else if (tcp_port <= 0) { /* port -1 to disable */
805 lprintf(CTDL_INFO, "Service has been manually disabled, skipping\n");
811 newfcn->msock = ig_tcp_server(config.c_ip_addr,
813 config.c_maxsessions,
815 snprintf(message, SIZ, "TCP port %s:%d: ",
816 config.c_ip_addr, tcp_port);
819 if (newfcn->msock > 0) {
820 ServiceHookTable = newfcn;
821 strcat(message, "registered.");
822 lprintf(CTDL_INFO, "%s\n", message);
825 AddPortError(message, error);
826 strcat(message, "FAILED.");
827 lprintf(CTDL_CRIT, "%s\n", message);
835 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
836 void (*h_greeting_function) (void),
837 void (*h_command_function) (void),
838 void (*h_async_function) (void)
841 struct ServiceFunctionHook *cur, *p;
843 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
844 /* This will also remove duplicates if any */
845 while (cur != NULL &&
846 !(sockpath && cur->sockpath &&
847 strcmp(sockpath, cur->sockpath)) &&
848 h_greeting_function == cur->h_greeting_function &&
849 h_command_function == cur->h_command_function &&
850 h_async_function == cur->h_async_function &&
851 tcp_port == cur->tcp_port) {
854 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
856 } else if (tcp_port) {
857 lprintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
859 lprintf(CTDL_INFO, "Unregistered unknown service\n");
862 if (cur == ServiceHookTable) {
863 ServiceHookTable = p;
871 void CtdlDestroyServiceHook(void)
873 struct ServiceFunctionHook *cur, *p;
875 cur = ServiceHookTable;
880 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
882 } else if (cur->tcp_port) {
883 lprintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
885 lprintf(CTDL_INFO, "Unregistered unknown service\n");
891 ServiceHookTable = NULL;
895 void PerformSessionHooks(int EventType)
897 struct SessionFunctionHook *fcn = NULL;
899 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
900 if (fcn->eventtype == EventType) {
901 (*fcn->h_function_pointer) ();
906 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
908 struct UserFunctionHook *fcn = NULL;
910 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
911 if (fcn->eventtype == EventType) {
912 (*fcn->h_function_pointer) (usbuf);
917 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
919 struct MessageFunctionHook *fcn = NULL;
920 int total_retval = 0;
922 /* Other code may elect to protect this message from server-side
923 * handlers; if this is the case, don't do anything.
924 lprintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
925 EventType, msg->cm_flags);
927 if (msg->cm_flags & CM_SKIP_HOOKS) {
928 lprintf(CTDL_DEBUG, "Skipping hooks\n");
932 /* Otherwise, run all the hooks appropriate to this event type.
934 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
935 if (fcn->eventtype == EventType) {
936 total_retval = total_retval +
937 (*fcn->h_function_pointer) (msg);
941 /* Return the sum of the return codes from the hook functions. If
942 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
943 * the save operation to abort.
949 int PerformRoomHooks(struct ctdlroom *target_room)
951 struct RoomFunctionHook *fcn;
952 int total_retval = 0;
954 lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
956 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
957 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
960 /* Return the sum of the return codes from the hook functions.
966 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
968 struct NetprocFunctionHook *fcn;
969 int total_retval = 0;
971 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
972 total_retval = total_retval +
973 (*fcn->h_function_pointer) (msg, target_room);
976 /* Return the sum of the return codes from the hook functions.
977 * A nonzero return code will cause the message to *not* be imported.
983 void PerformDeleteHooks(char *room, long msgnum)
985 struct DeleteFunctionHook *fcn;
987 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
988 (*fcn->h_function_pointer) (room, msgnum);
996 int PerformXmsgHooks(char *sender, char *recp, char *msg)
998 struct XmsgFunctionHook *fcn;
1002 for (p=0; p<MAX_XMSG_PRI; ++p) {
1003 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1004 if (fcn->order == p) {
1006 (*fcn->h_function_pointer)
1007 (sender, recp, msg);
1010 /* Break out of the loop if a higher-priority function
1011 * successfully delivered the message. This prevents duplicate
1012 * deliveries to local users simultaneously signed onto
1015 if (total_sent) break;
1020 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
1022 struct MaintenanceThreadHook *newfcn;
1024 newfcn = (struct MaintenanceThreadHook *)
1025 malloc(sizeof(struct MaintenanceThreadHook));
1026 newfcn->name = name;
1027 newfcn->next = MaintenanceThreadHookTable;
1028 newfcn->fcn_ptr = thread_proc;
1029 MaintenanceThreadHookTable = newfcn;
1031 lprintf(CTDL_INFO, "Registered a new maintenance thread function\n");
1036 * Dirty hack until we impliment a hook mechanism for this
1038 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1041 CtdlStartTLS (ok_response, nosup_response, error_response);