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;
44 struct SearchFunctionHook *SearchFunctionHookTable = NULL;
46 struct ProtoFunctionHook {
47 void (*handler) (char *cmdbuf);
50 struct ProtoFunctionHook *next;
51 } *ProtoHookList = NULL;
54 #define ERR_PORT (1 << 1)
57 static char *portlist = NULL;
58 static size_t nSizPort = 0;
60 static char *errormessages = NULL;
61 static size_t nSizErrmsg = 0;
64 static long DetailErrorFlags;
66 char *ErrSubject = "Startup Problems";
67 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"
68 "If you don't want citadel to provide these services, turn them off in WebCit via %s%s\n\n%s\n\n"
69 "To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
70 "The errors returned by the system were:\n%s\n"
71 "You can recheck the above if you follow this faq item:\n"
72 "http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat";
75 char *ErrPortShort = "We couldn't bind all ports you configured to be provided by citadel server.";
76 char *ErrPortWhere = "Admin->System Preferences->Network.\n\nThe failed ports and sockets are: ";
77 char *ErrPortHint = "If you want citadel to provide you with that functionality, "
78 "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD"
79 " and stop the programm, that binds these ports. You should eventually remove "
80 " their initscripts in /etc/init.d so that you won't get this trouble once more.\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);
97 DetailList = errormessages;
108 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
110 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
111 if (errormessages!=NULL) free (errormessages);
112 errormessages = NULL;
113 if (portlist!=NULL) free (portlist);
120 void AppendString(char **target, char *append, size_t *len, size_t rate)
126 AddLen = strlen(append);
132 *target = (char*)malloc (*len * SIZ);
136 oLen = strlen(*target);
137 RelPtr = strlen(*target);
138 if (oLen + AddLen + 2 > *len * SIZ)
140 char *Buff = *target;
141 size_t NewSiz = *len + 10;
142 *target = malloc (NewSiz * SIZ);
143 memcpy (*target, Buff, NewSiz * SIZ);
147 memcpy (*target + oLen, append, AddLen);
148 (*target)[oLen + AddLen + 1] = '\n';
149 (*target)[oLen + AddLen + 2] = '\0';
152 void AddPortError(char *Port, char *ErrorMessage)
157 DetailErrorFlags |= ERR_PORT;
159 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
160 AppendString(&portlist, Port, &nSizPort, 2);
162 pos = strchr (portlist, ':');
163 if (pos != NULL) *pos = ';';
165 len = strlen (errormessages);
166 if (nSizErrmsg * SIZ > len + 3)
168 errormessages[len] = ';';
169 errormessages[len+1] = ' ';
170 errormessages[len+2] = '\0';
175 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
177 struct ProtoFunctionHook *p;
179 p = (struct ProtoFunctionHook *)
180 malloc(sizeof(struct ProtoFunctionHook));
183 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
186 p->handler = handler;
189 p->next = ProtoHookList;
191 lprintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
195 void CtdlUnregisterProtoHook(void (*handler) (char *), char *cmd)
197 struct ProtoFunctionHook *cur = NULL;
198 struct ProtoFunctionHook *p = NULL;
199 struct ProtoFunctionHook *lastcur = NULL;
201 for (cur = ProtoHookList;
203 cur = (cur != NULL)? cur->next: NULL) {
204 /* This will also remove duplicates if any */
205 while (cur != NULL &&
206 handler == cur->handler &&
207 !strcmp(cmd, cur->cmd)) {
208 lprintf(CTDL_INFO, "Unregistered server command %s (%s)\n",
211 if (cur == ProtoHookList) {
214 else if (lastcur != NULL)
225 void CtdlDestroyProtoHooks(void)
227 struct ProtoFunctionHook *cur, *p;
232 lprintf(CTDL_INFO, "Destroyed server command %s (%s)\n",
233 cur->cmd, cur->desc);
238 ProtoHookList = NULL;
242 int DLoader_Exec_Cmd(char *cmdbuf)
244 struct ProtoFunctionHook *p;
246 for (p = ProtoHookList; p; p = p->next) {
247 if (!strncasecmp(cmdbuf, p->cmd, 4)) {
248 p->handler(&cmdbuf[5]);
256 void initialize_server_extensions(void)
262 /*lprintf(CTDL_INFO, "%s\n", serv_bio_init());
263 lprintf(CTDL_INFO, "%s\n", serv_calendar_init());
264 lprintf(CTDL_INFO, "%s\n", serv_notes_init());
265 lprintf(CTDL_INFO, "%s\n", serv_ldap_init());
266 lprintf(CTDL_INFO, "%s\n", serv_chat_init());
267 lprintf(CTDL_INFO, "%s\n", serv_expire_init());
268 lprintf(CTDL_INFO, "%s\n", serv_imap_init());
269 lprintf(CTDL_INFO, "%s\n", serv_upgrade_init());
270 lprintf(CTDL_INFO, "%s\n", serv_inetcfg_init());
271 lprintf(CTDL_INFO, "%s\n", serv_listsub_init());
272 lprintf(CTDL_INFO, "%s\n", serv_mrtg_init());
273 lprintf(CTDL_INFO, "%s\n", serv_netfilter_init());
274 lprintf(CTDL_INFO, "%s\n", serv_network_init());
275 lprintf(CTDL_INFO, "%s\n", serv_newuser_init());
276 lprintf(CTDL_INFO, "%s\n", serv_pas2_init());
277 lprintf(CTDL_INFO, "%s\n", serv_smtp_init());
278 lprintf(CTDL_INFO, "%s\n", serv_pop3_init());
279 lprintf(CTDL_INFO, "%s\n", serv_rwho_init());
280 lprintf(CTDL_INFO, "%s\n", serv_spam_init());*/
281 /* lprintf(CTDL_INFO, "%s\n", serv_test_init()); */
282 /*lprintf(CTDL_INFO, "%s\n", serv_vandelay_init());
283 lprintf(CTDL_INFO, "%s\n", serv_vcard_init());
284 lprintf(CTDL_INFO, "%s\n", serv_fulltext_init());
285 lprintf(CTDL_INFO, "%s\n", serv_autocompletion_init());
286 lprintf(CTDL_INFO, "%s\n", serv_postfix_tcpdict());
287 lprintf(CTDL_INFO, "%s\n", serv_sieve_init());
288 lprintf(CTDL_INFO, "%s\n", serv_managesieve_init());
289 lprintf(CTDL_INFO, "%s\n", serv_funambol_init());*/
290 for (filter = 1; filter != 0; filter = filter << 1)
291 if ((filter & DetailErrorFlags) != 0)
292 LogPrintMessages(filter);
297 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
300 struct CleanupFunctionHook *newfcn;
302 newfcn = (struct CleanupFunctionHook *)
303 malloc(sizeof(struct CleanupFunctionHook));
304 newfcn->next = CleanupHookTable;
305 newfcn->h_function_pointer = fcn_ptr;
306 CleanupHookTable = newfcn;
308 lprintf(CTDL_INFO, "Registered a new cleanup function\n");
312 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
314 struct CleanupFunctionHook *cur, *p;
316 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
317 /* This will also remove duplicates if any */
318 while (cur != NULL &&
319 fcn_ptr == cur->h_function_pointer) {
320 lprintf(CTDL_INFO, "Unregistered cleanup function\n");
322 if (cur == CleanupHookTable) {
323 CleanupHookTable = p;
331 void CtdlDestroyCleanupHooks(void)
333 struct CleanupFunctionHook *cur, *p;
335 cur = CleanupHookTable;
338 lprintf(CTDL_INFO, "Destroyed cleanup function\n");
343 CleanupHookTable = NULL;
347 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
350 struct SessionFunctionHook *newfcn;
352 newfcn = (struct SessionFunctionHook *)
353 malloc(sizeof(struct SessionFunctionHook));
354 newfcn->next = SessionHookTable;
355 newfcn->h_function_pointer = fcn_ptr;
356 newfcn->eventtype = EventType;
357 SessionHookTable = newfcn;
359 lprintf(CTDL_INFO, "Registered a new session function (type %d)\n",
364 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
366 struct SessionFunctionHook *cur, *p;
368 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
369 /* This will also remove duplicates if any */
370 while (cur != NULL &&
371 fcn_ptr == cur->h_function_pointer &&
372 EventType == cur->eventtype) {
373 lprintf(CTDL_INFO, "Unregistered session function (type %d)\n",
376 if (cur == SessionHookTable) {
377 SessionHookTable = p;
385 void CtdlDestroySessionHooks(void)
387 struct SessionFunctionHook *cur, *p;
389 cur = SessionHookTable;
392 lprintf(CTDL_INFO, "Destroyed session function\n");
397 SessionHookTable = NULL;
401 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
404 struct UserFunctionHook *newfcn;
406 newfcn = (struct UserFunctionHook *)
407 malloc(sizeof(struct UserFunctionHook));
408 newfcn->next = UserHookTable;
409 newfcn->h_function_pointer = fcn_ptr;
410 newfcn->eventtype = EventType;
411 UserHookTable = newfcn;
413 lprintf(CTDL_INFO, "Registered a new user function (type %d)\n",
418 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
420 struct UserFunctionHook *cur, *p;
422 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
423 /* This will also remove duplicates if any */
424 while (cur != NULL &&
425 fcn_ptr == cur->h_function_pointer &&
426 EventType == cur->eventtype) {
427 lprintf(CTDL_INFO, "Unregistered user function (type %d)\n",
430 if (cur == UserHookTable) {
439 void CtdlDestroyUserHooks(void)
441 struct UserFunctionHook *cur, *p;
446 lprintf(CTDL_INFO, "Destroyed user function \n");
451 UserHookTable = NULL;
455 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
459 struct MessageFunctionHook *newfcn;
461 newfcn = (struct MessageFunctionHook *)
462 malloc(sizeof(struct MessageFunctionHook));
463 newfcn->next = MessageHookTable;
464 newfcn->h_function_pointer = handler;
465 newfcn->eventtype = EventType;
466 MessageHookTable = newfcn;
468 lprintf(CTDL_INFO, "Registered a new message function (type %d)\n",
473 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
476 struct MessageFunctionHook *cur, *p;
478 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
479 /* This will also remove duplicates if any */
480 while (cur != NULL &&
481 handler == cur->h_function_pointer &&
482 EventType == cur->eventtype) {
483 lprintf(CTDL_INFO, "Unregistered message function (type %d)\n",
486 if (cur == MessageHookTable) {
487 MessageHookTable = p;
495 void CtdlDestroyMessageHook(void)
497 struct MessageFunctionHook *cur, *p;
499 cur = MessageHookTable;
502 lprintf(CTDL_INFO, "Destroyed message function \n");
507 MessageHookTable = NULL;
511 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
513 struct RoomFunctionHook *newfcn;
515 newfcn = (struct RoomFunctionHook *)
516 malloc(sizeof(struct RoomFunctionHook));
517 newfcn->next = RoomHookTable;
518 newfcn->fcn_ptr = fcn_ptr;
519 RoomHookTable = newfcn;
521 lprintf(CTDL_INFO, "Registered a new room function\n");
525 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
527 struct RoomFunctionHook *cur, *p;
529 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
530 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
531 lprintf(CTDL_INFO, "Unregistered room function\n");
533 if (cur == RoomHookTable) {
543 void CtdlDestroyRoomHooks(void)
545 struct RoomFunctionHook *cur, *p;
550 lprintf(CTDL_INFO, "Unregistered room function\n");
555 RoomHookTable = NULL;
558 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
560 struct NetprocFunctionHook *newfcn;
562 newfcn = (struct NetprocFunctionHook *)
563 malloc(sizeof(struct NetprocFunctionHook));
564 newfcn->next = NetprocHookTable;
565 newfcn->h_function_pointer = handler;
566 NetprocHookTable = newfcn;
568 lprintf(CTDL_INFO, "Registered a new netproc function\n");
572 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
574 struct NetprocFunctionHook *cur, *p;
576 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
577 /* This will also remove duplicates if any */
578 while (cur != NULL &&
579 handler == cur->h_function_pointer ) {
580 lprintf(CTDL_INFO, "Unregistered netproc function\n");
582 if (cur == NetprocHookTable) {
583 NetprocHookTable = p;
591 void CtdlDestroyNetprocHooks(void)
593 struct NetprocFunctionHook *cur, *p;
595 cur = NetprocHookTable;
598 lprintf(CTDL_INFO, "Unregistered netproc function\n");
603 NetprocHookTable = NULL;
607 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
609 struct DeleteFunctionHook *newfcn;
611 newfcn = (struct DeleteFunctionHook *)
612 malloc(sizeof(struct DeleteFunctionHook));
613 newfcn->next = DeleteHookTable;
614 newfcn->h_function_pointer = handler;
615 DeleteHookTable = newfcn;
617 lprintf(CTDL_INFO, "Registered a new netproc function\n");
621 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
623 struct DeleteFunctionHook *cur, *p;
625 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
626 /* This will also remove duplicates if any */
627 while (cur != NULL &&
628 handler == cur->h_function_pointer ) {
629 lprintf(CTDL_INFO, "Unregistered netproc function\n");
631 if (cur == DeleteHookTable) {
639 void CtdlDestroyDeleteHooks(void)
641 struct DeleteFunctionHook *cur, *p;
643 cur = DeleteHookTable;
646 lprintf(CTDL_INFO, "Destroyed netproc function\n");
651 DeleteHookTable = NULL;
657 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
659 struct FixedOutputHook *newfcn;
661 newfcn = (struct FixedOutputHook *)
662 malloc(sizeof(struct FixedOutputHook));
663 newfcn->next = FixedOutputTable;
664 newfcn->h_function_pointer = handler;
665 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
666 FixedOutputTable = newfcn;
668 lprintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
672 void CtdlUnregisterFixedOutputHook(char *content_type)
674 struct FixedOutputHook *cur, *p;
676 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
677 /* This will also remove duplicates if any */
678 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
679 lprintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
681 if (cur == FixedOutputTable) {
682 FixedOutputTable = p;
690 void CtdlDestroyFixedOutputHooks(void)
692 struct FixedOutputHook *cur, *p;
694 cur = FixedOutputTable;
697 lprintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
703 FixedOutputTable = NULL;
706 /* returns nonzero if we found a hook and used it */
707 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
709 struct FixedOutputHook *fcn;
711 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
712 if (!strcasecmp(content_type, fcn->content_type)) {
713 (*fcn->h_function_pointer) (content, content_length);
724 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
727 struct XmsgFunctionHook *newfcn;
729 newfcn = (struct XmsgFunctionHook *)
730 malloc(sizeof(struct XmsgFunctionHook));
731 newfcn->next = XmsgHookTable;
732 newfcn->order = order;
733 newfcn->h_function_pointer = fcn_ptr;
734 XmsgHookTable = newfcn;
735 lprintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
739 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
741 struct XmsgFunctionHook *cur, *p;
743 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
744 /* This will also remove duplicates if any */
745 while (cur != NULL &&
746 fcn_ptr == cur->h_function_pointer &&
747 order == cur->order) {
748 lprintf(CTDL_INFO, "Unregistered x-msg function "
749 "(priority %d)\n", order);
751 if (cur == XmsgHookTable) {
760 void CtdlDestroyXmsgHooks(void)
762 struct XmsgFunctionHook *cur, *p;
767 lprintf(CTDL_INFO, "Destroyed x-msg function "
768 "(priority %d)\n", cur->order);
774 XmsgHookTable = NULL;
778 void CtdlRegisterServiceHook(int tcp_port,
780 void (*h_greeting_function) (void),
781 void (*h_command_function) (void),
782 void (*h_async_function) (void),
783 const char *ServiceName)
785 struct ServiceFunctionHook *newfcn;
790 newfcn = (struct ServiceFunctionHook *)
791 malloc(sizeof(struct ServiceFunctionHook));
792 message = (char*) malloc (SIZ);
794 newfcn->next = ServiceHookTable;
795 newfcn->tcp_port = tcp_port;
796 newfcn->sockpath = sockpath;
797 newfcn->h_greeting_function = h_greeting_function;
798 newfcn->h_command_function = h_command_function;
799 newfcn->h_async_function = h_async_function;
800 newfcn->ServiceName = ServiceName;
802 if (sockpath != NULL) {
803 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
804 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
806 else if (tcp_port <= 0) { /* port -1 to disable */
807 lprintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
813 newfcn->msock = ig_tcp_server(config.c_ip_addr,
815 config.c_maxsessions,
817 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
818 config.c_ip_addr, tcp_port, ServiceName);
821 if (newfcn->msock > 0) {
822 ServiceHookTable = newfcn;
823 strcat(message, "registered.");
824 lprintf(CTDL_INFO, "%s\n", message);
827 AddPortError(message, error);
828 strcat(message, "FAILED.");
829 lprintf(CTDL_CRIT, "%s\n", message);
837 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
838 void (*h_greeting_function) (void),
839 void (*h_command_function) (void),
840 void (*h_async_function) (void)
843 struct ServiceFunctionHook *cur, *p;
845 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
846 /* This will also remove duplicates if any */
847 while (cur != NULL &&
848 !(sockpath && cur->sockpath &&
849 strcmp(sockpath, cur->sockpath)) &&
850 h_greeting_function == cur->h_greeting_function &&
851 h_command_function == cur->h_command_function &&
852 h_async_function == cur->h_async_function &&
853 tcp_port == cur->tcp_port) {
856 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
858 } else if (tcp_port) {
859 lprintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
861 lprintf(CTDL_INFO, "Unregistered unknown service\n");
864 if (cur == ServiceHookTable) {
865 ServiceHookTable = p;
873 void CtdlDestroyServiceHook(void)
875 struct ServiceFunctionHook *cur, *p;
877 cur = ServiceHookTable;
882 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
884 } else if (cur->tcp_port) {
885 lprintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
887 lprintf(CTDL_INFO, "Unregistered unknown service\n");
893 ServiceHookTable = NULL;
896 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
898 struct SearchFunctionHook *newfcn;
900 if (!name || !fcn_ptr) {
904 newfcn = (struct SearchFunctionHook *)
905 malloc(sizeof(struct SearchFunctionHook));
906 newfcn->next = SearchFunctionHookTable;
908 newfcn->fcn_ptr = fcn_ptr;
909 SearchFunctionHookTable = newfcn;
911 lprintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
914 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
916 struct SearchFunctionHook *cur, *p;
918 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
919 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
920 lprintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
922 if (cur == SearchFunctionHookTable) {
923 SearchFunctionHookTable = p;
931 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
933 struct SearchFunctionHook *fcn = NULL;
935 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
936 if (!func_name || !strcmp(func_name, fcn->name)) {
937 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
945 void PerformSessionHooks(int EventType)
947 struct SessionFunctionHook *fcn = NULL;
949 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
950 if (fcn->eventtype == EventType) {
951 (*fcn->h_function_pointer) ();
956 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
958 struct UserFunctionHook *fcn = NULL;
960 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
961 if (fcn->eventtype == EventType) {
962 (*fcn->h_function_pointer) (usbuf);
967 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
969 struct MessageFunctionHook *fcn = NULL;
970 int total_retval = 0;
972 /* Other code may elect to protect this message from server-side
973 * handlers; if this is the case, don't do anything.
974 lprintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
975 EventType, msg->cm_flags);
977 if (msg->cm_flags & CM_SKIP_HOOKS) {
978 lprintf(CTDL_DEBUG, "Skipping hooks\n");
982 /* Otherwise, run all the hooks appropriate to this event type.
984 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
985 if (fcn->eventtype == EventType) {
986 total_retval = total_retval +
987 (*fcn->h_function_pointer) (msg);
991 /* Return the sum of the return codes from the hook functions. If
992 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
993 * the save operation to abort.
999 int PerformRoomHooks(struct ctdlroom *target_room)
1001 struct RoomFunctionHook *fcn;
1002 int total_retval = 0;
1004 lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
1006 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1007 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1010 /* Return the sum of the return codes from the hook functions.
1012 return total_retval;
1016 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
1018 struct NetprocFunctionHook *fcn;
1019 int total_retval = 0;
1021 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
1022 total_retval = total_retval +
1023 (*fcn->h_function_pointer) (msg, target_room);
1026 /* Return the sum of the return codes from the hook functions.
1027 * A nonzero return code will cause the message to *not* be imported.
1029 return total_retval;
1033 void PerformDeleteHooks(char *room, long msgnum)
1035 struct DeleteFunctionHook *fcn;
1037 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1038 (*fcn->h_function_pointer) (room, msgnum);
1046 int PerformXmsgHooks(char *sender, char *recp, char *msg)
1048 struct XmsgFunctionHook *fcn;
1052 for (p=0; p<MAX_XMSG_PRI; ++p) {
1053 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1054 if (fcn->order == p) {
1056 (*fcn->h_function_pointer)
1057 (sender, recp, msg);
1060 /* Break out of the loop if a higher-priority function
1061 * successfully delivered the message. This prevents duplicate
1062 * deliveries to local users simultaneously signed onto
1065 if (total_sent) break;
1070 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
1072 struct MaintenanceThreadHook *newfcn;
1074 newfcn = (struct MaintenanceThreadHook *)
1075 malloc(sizeof(struct MaintenanceThreadHook));
1076 newfcn->name = name;
1077 newfcn->next = MaintenanceThreadHookTable;
1078 newfcn->fcn_ptr = thread_proc;
1079 MaintenanceThreadHookTable = newfcn;
1081 lprintf(CTDL_INFO, "Registered a new maintenance thread function\n");
1086 * Dirty hack until we impliment a hook mechanism for this
1088 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1091 CtdlStartTLS (ok_response, nosup_response, error_response);