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 size_t nSizErrmsg = 0;
64 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);
111 lprintf(0,ErrSubject);
112 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
113 if (errormessages!=NULL) free (errormessages);
114 errormessages = NULL;
115 if (portlist!=NULL) free (portlist);
122 void AppendString(char **target, char *append, size_t *len, size_t rate)
128 AddLen = strlen(append);
134 *target = (char*)malloc (*len * SIZ);
138 oLen = strlen(*target);
139 RelPtr = strlen(*target);
140 if (oLen + AddLen + 2 > *len * SIZ)
142 char *Buff = *target;
143 size_t NewSiz = *len + 10;
144 *target = malloc (NewSiz * SIZ);
145 memcpy (*target, Buff, NewSiz * SIZ);
149 memcpy (*target + oLen, append, AddLen);
150 (*target)[oLen + AddLen + 1] = '\n';
151 (*target)[oLen + AddLen + 2] = '\0';
154 void AddPortError(char *Port, char *ErrorMessage)
159 DetailErrorFlags |= ERR_PORT;
161 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
162 AppendString(&portlist, Port, &nSizPort, 2);
164 pos = strchr (portlist, ':');
165 if (pos != NULL) *pos = ';';
167 len = strlen (errormessages);
168 if (nSizErrmsg * SIZ > len + 3)
170 errormessages[len] = ';';
171 errormessages[len+1] = ' ';
172 errormessages[len+2] = '\0';
177 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
179 struct ProtoFunctionHook *p;
181 p = (struct ProtoFunctionHook *)
182 malloc(sizeof(struct ProtoFunctionHook));
185 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
188 p->handler = handler;
191 p->next = ProtoHookList;
193 lprintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
197 void CtdlUnregisterProtoHook(void (*handler) (char *), char *cmd)
199 struct ProtoFunctionHook *cur = NULL;
200 struct ProtoFunctionHook *p = NULL;
201 struct ProtoFunctionHook *lastcur = NULL;
203 for (cur = ProtoHookList;
205 cur = (cur != NULL)? cur->next: NULL) {
206 /* This will also remove duplicates if any */
207 while (cur != NULL &&
208 handler == cur->handler &&
209 !strcmp(cmd, cur->cmd)) {
210 lprintf(CTDL_INFO, "Unregistered server command %s (%s)\n",
213 if (cur == ProtoHookList) {
216 else if (lastcur != NULL)
227 void CtdlDestroyProtoHooks(void)
229 struct ProtoFunctionHook *cur, *p;
234 lprintf(CTDL_INFO, "Destroyed server command %s (%s)\n",
235 cur->cmd, cur->desc);
240 ProtoHookList = NULL;
244 int DLoader_Exec_Cmd(char *cmdbuf)
246 struct ProtoFunctionHook *p;
248 for (p = ProtoHookList; p; p = p->next) {
249 if (!strncasecmp(cmdbuf, p->cmd, 4)) {
250 p->handler(&cmdbuf[5]);
258 void initialize_server_extensions(void)
264 /*lprintf(CTDL_INFO, "%s\n", serv_bio_init());
265 lprintf(CTDL_INFO, "%s\n", serv_calendar_init());
266 lprintf(CTDL_INFO, "%s\n", serv_notes_init());
267 lprintf(CTDL_INFO, "%s\n", serv_ldap_init());
268 lprintf(CTDL_INFO, "%s\n", serv_chat_init());
269 lprintf(CTDL_INFO, "%s\n", serv_expire_init());
270 lprintf(CTDL_INFO, "%s\n", serv_imap_init());
271 lprintf(CTDL_INFO, "%s\n", serv_upgrade_init());
272 lprintf(CTDL_INFO, "%s\n", serv_inetcfg_init());
273 lprintf(CTDL_INFO, "%s\n", serv_listsub_init());
274 lprintf(CTDL_INFO, "%s\n", serv_mrtg_init());
275 lprintf(CTDL_INFO, "%s\n", serv_netfilter_init());
276 lprintf(CTDL_INFO, "%s\n", serv_network_init());
277 lprintf(CTDL_INFO, "%s\n", serv_newuser_init());
278 lprintf(CTDL_INFO, "%s\n", serv_pas2_init());
279 lprintf(CTDL_INFO, "%s\n", serv_smtp_init());
280 lprintf(CTDL_INFO, "%s\n", serv_pop3_init());
281 lprintf(CTDL_INFO, "%s\n", serv_rwho_init());
282 lprintf(CTDL_INFO, "%s\n", serv_spam_init());*/
283 /* lprintf(CTDL_INFO, "%s\n", serv_test_init()); */
284 /*lprintf(CTDL_INFO, "%s\n", serv_vandelay_init());
285 lprintf(CTDL_INFO, "%s\n", serv_vcard_init());
286 lprintf(CTDL_INFO, "%s\n", serv_fulltext_init());
287 lprintf(CTDL_INFO, "%s\n", serv_autocompletion_init());
288 lprintf(CTDL_INFO, "%s\n", serv_postfix_tcpdict());
289 lprintf(CTDL_INFO, "%s\n", serv_sieve_init());
290 lprintf(CTDL_INFO, "%s\n", serv_managesieve_init());
291 lprintf(CTDL_INFO, "%s\n", serv_funambol_init());*/
292 for (filter = 1; filter != 0; filter = filter << 1)
293 if ((filter & DetailErrorFlags) != 0)
294 LogPrintMessages(filter);
299 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
302 struct CleanupFunctionHook *newfcn;
304 newfcn = (struct CleanupFunctionHook *)
305 malloc(sizeof(struct CleanupFunctionHook));
306 newfcn->next = CleanupHookTable;
307 newfcn->h_function_pointer = fcn_ptr;
308 CleanupHookTable = newfcn;
310 lprintf(CTDL_INFO, "Registered a new cleanup function\n");
314 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
316 struct CleanupFunctionHook *cur, *p;
318 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
319 /* This will also remove duplicates if any */
320 while (cur != NULL &&
321 fcn_ptr == cur->h_function_pointer) {
322 lprintf(CTDL_INFO, "Unregistered cleanup function\n");
324 if (cur == CleanupHookTable) {
325 CleanupHookTable = p;
333 void CtdlDestroyCleanupHooks(void)
335 struct CleanupFunctionHook *cur, *p;
337 cur = CleanupHookTable;
340 lprintf(CTDL_INFO, "Destroyed cleanup function\n");
345 CleanupHookTable = NULL;
349 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
352 struct SessionFunctionHook *newfcn;
354 newfcn = (struct SessionFunctionHook *)
355 malloc(sizeof(struct SessionFunctionHook));
356 newfcn->next = SessionHookTable;
357 newfcn->h_function_pointer = fcn_ptr;
358 newfcn->eventtype = EventType;
359 SessionHookTable = newfcn;
361 lprintf(CTDL_INFO, "Registered a new session function (type %d)\n",
366 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
368 struct SessionFunctionHook *cur, *p;
370 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
371 /* This will also remove duplicates if any */
372 while (cur != NULL &&
373 fcn_ptr == cur->h_function_pointer &&
374 EventType == cur->eventtype) {
375 lprintf(CTDL_INFO, "Unregistered session function (type %d)\n",
378 if (cur == SessionHookTable) {
379 SessionHookTable = p;
387 void CtdlDestroySessionHooks(void)
389 struct SessionFunctionHook *cur, *p;
391 cur = SessionHookTable;
394 lprintf(CTDL_INFO, "Destroyed session function\n");
399 SessionHookTable = NULL;
403 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
406 struct UserFunctionHook *newfcn;
408 newfcn = (struct UserFunctionHook *)
409 malloc(sizeof(struct UserFunctionHook));
410 newfcn->next = UserHookTable;
411 newfcn->h_function_pointer = fcn_ptr;
412 newfcn->eventtype = EventType;
413 UserHookTable = newfcn;
415 lprintf(CTDL_INFO, "Registered a new user function (type %d)\n",
420 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
422 struct UserFunctionHook *cur, *p;
424 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
425 /* This will also remove duplicates if any */
426 while (cur != NULL &&
427 fcn_ptr == cur->h_function_pointer &&
428 EventType == cur->eventtype) {
429 lprintf(CTDL_INFO, "Unregistered user function (type %d)\n",
432 if (cur == UserHookTable) {
441 void CtdlDestroyUserHooks(void)
443 struct UserFunctionHook *cur, *p;
448 lprintf(CTDL_INFO, "Destroyed user function \n");
453 UserHookTable = NULL;
457 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
461 struct MessageFunctionHook *newfcn;
463 newfcn = (struct MessageFunctionHook *)
464 malloc(sizeof(struct MessageFunctionHook));
465 newfcn->next = MessageHookTable;
466 newfcn->h_function_pointer = handler;
467 newfcn->eventtype = EventType;
468 MessageHookTable = newfcn;
470 lprintf(CTDL_INFO, "Registered a new message function (type %d)\n",
475 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
478 struct MessageFunctionHook *cur, *p;
480 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
481 /* This will also remove duplicates if any */
482 while (cur != NULL &&
483 handler == cur->h_function_pointer &&
484 EventType == cur->eventtype) {
485 lprintf(CTDL_INFO, "Unregistered message function (type %d)\n",
488 if (cur == MessageHookTable) {
489 MessageHookTable = p;
497 void CtdlDestroyMessageHook(void)
499 struct MessageFunctionHook *cur, *p;
501 cur = MessageHookTable;
504 lprintf(CTDL_INFO, "Destroyed message function \n");
509 MessageHookTable = NULL;
513 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
515 struct RoomFunctionHook *newfcn;
517 newfcn = (struct RoomFunctionHook *)
518 malloc(sizeof(struct RoomFunctionHook));
519 newfcn->next = RoomHookTable;
520 newfcn->fcn_ptr = fcn_ptr;
521 RoomHookTable = newfcn;
523 lprintf(CTDL_INFO, "Registered a new room function\n");
527 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
529 struct RoomFunctionHook *cur, *p;
531 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
532 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
533 lprintf(CTDL_INFO, "Unregistered room function\n");
535 if (cur == RoomHookTable) {
545 void CtdlDestroyRoomHooks(void)
547 struct RoomFunctionHook *cur, *p;
552 lprintf(CTDL_INFO, "Unregistered room function\n");
557 RoomHookTable = NULL;
560 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
562 struct NetprocFunctionHook *newfcn;
564 newfcn = (struct NetprocFunctionHook *)
565 malloc(sizeof(struct NetprocFunctionHook));
566 newfcn->next = NetprocHookTable;
567 newfcn->h_function_pointer = handler;
568 NetprocHookTable = newfcn;
570 lprintf(CTDL_INFO, "Registered a new netproc function\n");
574 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
576 struct NetprocFunctionHook *cur, *p;
578 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
579 /* This will also remove duplicates if any */
580 while (cur != NULL &&
581 handler == cur->h_function_pointer ) {
582 lprintf(CTDL_INFO, "Unregistered netproc function\n");
584 if (cur == NetprocHookTable) {
585 NetprocHookTable = p;
593 void CtdlDestroyNetprocHooks(void)
595 struct NetprocFunctionHook *cur, *p;
597 cur = NetprocHookTable;
600 lprintf(CTDL_INFO, "Unregistered netproc function\n");
605 NetprocHookTable = NULL;
609 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
611 struct DeleteFunctionHook *newfcn;
613 newfcn = (struct DeleteFunctionHook *)
614 malloc(sizeof(struct DeleteFunctionHook));
615 newfcn->next = DeleteHookTable;
616 newfcn->h_function_pointer = handler;
617 DeleteHookTable = newfcn;
619 lprintf(CTDL_INFO, "Registered a new netproc function\n");
623 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
625 struct DeleteFunctionHook *cur, *p;
627 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
628 /* This will also remove duplicates if any */
629 while (cur != NULL &&
630 handler == cur->h_function_pointer ) {
631 lprintf(CTDL_INFO, "Unregistered netproc function\n");
633 if (cur == DeleteHookTable) {
641 void CtdlDestroyDeleteHooks(void)
643 struct DeleteFunctionHook *cur, *p;
645 cur = DeleteHookTable;
648 lprintf(CTDL_INFO, "Destroyed netproc function\n");
653 DeleteHookTable = NULL;
659 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
661 struct FixedOutputHook *newfcn;
663 newfcn = (struct FixedOutputHook *)
664 malloc(sizeof(struct FixedOutputHook));
665 newfcn->next = FixedOutputTable;
666 newfcn->h_function_pointer = handler;
667 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
668 FixedOutputTable = newfcn;
670 lprintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
674 void CtdlUnregisterFixedOutputHook(char *content_type)
676 struct FixedOutputHook *cur, *p;
678 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
679 /* This will also remove duplicates if any */
680 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
681 lprintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
683 if (cur == FixedOutputTable) {
684 FixedOutputTable = p;
692 void CtdlDestroyFixedOutputHooks(void)
694 struct FixedOutputHook *cur, *p;
696 cur = FixedOutputTable;
699 lprintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
705 FixedOutputTable = NULL;
708 /* returns nonzero if we found a hook and used it */
709 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
711 struct FixedOutputHook *fcn;
713 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
714 if (!strcasecmp(content_type, fcn->content_type)) {
715 (*fcn->h_function_pointer) (content, content_length);
726 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
729 struct XmsgFunctionHook *newfcn;
731 newfcn = (struct XmsgFunctionHook *)
732 malloc(sizeof(struct XmsgFunctionHook));
733 newfcn->next = XmsgHookTable;
734 newfcn->order = order;
735 newfcn->h_function_pointer = fcn_ptr;
736 XmsgHookTable = newfcn;
737 lprintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
741 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
743 struct XmsgFunctionHook *cur, *p;
745 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
746 /* This will also remove duplicates if any */
747 while (cur != NULL &&
748 fcn_ptr == cur->h_function_pointer &&
749 order == cur->order) {
750 lprintf(CTDL_INFO, "Unregistered x-msg function "
751 "(priority %d)\n", order);
753 if (cur == XmsgHookTable) {
762 void CtdlDestroyXmsgHooks(void)
764 struct XmsgFunctionHook *cur, *p;
769 lprintf(CTDL_INFO, "Destroyed x-msg function "
770 "(priority %d)\n", cur->order);
776 XmsgHookTable = NULL;
780 void CtdlRegisterServiceHook(int tcp_port,
782 void (*h_greeting_function) (void),
783 void (*h_command_function) (void),
784 void (*h_async_function) (void),
785 const char *ServiceName)
787 struct ServiceFunctionHook *newfcn;
792 newfcn = (struct ServiceFunctionHook *)
793 malloc(sizeof(struct ServiceFunctionHook));
794 message = (char*) malloc (SIZ);
796 newfcn->next = ServiceHookTable;
797 newfcn->tcp_port = tcp_port;
798 newfcn->sockpath = sockpath;
799 newfcn->h_greeting_function = h_greeting_function;
800 newfcn->h_command_function = h_command_function;
801 newfcn->h_async_function = h_async_function;
802 newfcn->ServiceName = ServiceName;
804 if (sockpath != NULL) {
805 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
806 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
808 else if (tcp_port <= 0) { /* port -1 to disable */
809 lprintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
815 newfcn->msock = ig_tcp_server(config.c_ip_addr,
817 config.c_maxsessions,
819 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
820 config.c_ip_addr, tcp_port, ServiceName);
823 if (newfcn->msock > 0) {
824 ServiceHookTable = newfcn;
825 strcat(message, "registered.");
826 lprintf(CTDL_INFO, "%s\n", message);
829 AddPortError(message, error);
830 strcat(message, "FAILED.");
831 lprintf(CTDL_CRIT, "%s\n", message);
839 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
840 void (*h_greeting_function) (void),
841 void (*h_command_function) (void),
842 void (*h_async_function) (void)
845 struct ServiceFunctionHook *cur, *p;
847 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
848 /* This will also remove duplicates if any */
849 while (cur != NULL &&
850 !(sockpath && cur->sockpath &&
851 strcmp(sockpath, cur->sockpath)) &&
852 h_greeting_function == cur->h_greeting_function &&
853 h_command_function == cur->h_command_function &&
854 h_async_function == cur->h_async_function &&
855 tcp_port == cur->tcp_port) {
858 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
860 } else if (tcp_port) {
861 lprintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
863 lprintf(CTDL_INFO, "Unregistered unknown service\n");
866 if (cur == ServiceHookTable) {
867 ServiceHookTable = p;
875 void CtdlDestroyServiceHook(void)
877 struct ServiceFunctionHook *cur, *p;
879 cur = ServiceHookTable;
884 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
886 } else if (cur->tcp_port) {
887 lprintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
889 lprintf(CTDL_INFO, "Unregistered unknown service\n");
895 ServiceHookTable = NULL;
898 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
900 struct SearchFunctionHook *newfcn;
902 if (!name || !fcn_ptr) {
906 newfcn = (struct SearchFunctionHook *)
907 malloc(sizeof(struct SearchFunctionHook));
908 newfcn->next = SearchFunctionHookTable;
910 newfcn->fcn_ptr = fcn_ptr;
911 SearchFunctionHookTable = newfcn;
913 lprintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
916 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
918 struct SearchFunctionHook *cur, *p;
920 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
921 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
922 lprintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
924 if (cur == SearchFunctionHookTable) {
925 SearchFunctionHookTable = p;
933 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
935 struct SearchFunctionHook *fcn = NULL;
937 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
938 if (!func_name || !strcmp(func_name, fcn->name)) {
939 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
947 void PerformSessionHooks(int EventType)
949 struct SessionFunctionHook *fcn = NULL;
951 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
952 if (fcn->eventtype == EventType) {
953 (*fcn->h_function_pointer) ();
958 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
960 struct UserFunctionHook *fcn = NULL;
962 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
963 if (fcn->eventtype == EventType) {
964 (*fcn->h_function_pointer) (usbuf);
969 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
971 struct MessageFunctionHook *fcn = NULL;
972 int total_retval = 0;
974 /* Other code may elect to protect this message from server-side
975 * handlers; if this is the case, don't do anything.
976 lprintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
977 EventType, msg->cm_flags);
979 if (msg->cm_flags & CM_SKIP_HOOKS) {
980 lprintf(CTDL_DEBUG, "Skipping hooks\n");
984 /* Otherwise, run all the hooks appropriate to this event type.
986 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
987 if (fcn->eventtype == EventType) {
988 total_retval = total_retval +
989 (*fcn->h_function_pointer) (msg);
993 /* Return the sum of the return codes from the hook functions. If
994 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
995 * the save operation to abort.
1001 int PerformRoomHooks(struct ctdlroom *target_room)
1003 struct RoomFunctionHook *fcn;
1004 int total_retval = 0;
1006 lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
1008 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1009 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1012 /* Return the sum of the return codes from the hook functions.
1014 return total_retval;
1018 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
1020 struct NetprocFunctionHook *fcn;
1021 int total_retval = 0;
1023 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
1024 total_retval = total_retval +
1025 (*fcn->h_function_pointer) (msg, target_room);
1028 /* Return the sum of the return codes from the hook functions.
1029 * A nonzero return code will cause the message to *not* be imported.
1031 return total_retval;
1035 void PerformDeleteHooks(char *room, long msgnum)
1037 struct DeleteFunctionHook *fcn;
1039 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1040 (*fcn->h_function_pointer) (room, msgnum);
1048 int PerformXmsgHooks(char *sender, char *recp, char *msg)
1050 struct XmsgFunctionHook *fcn;
1054 for (p=0; p<MAX_XMSG_PRI; ++p) {
1055 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1056 if (fcn->order == p) {
1058 (*fcn->h_function_pointer)
1059 (sender, recp, msg);
1062 /* Break out of the loop if a higher-priority function
1063 * successfully delivered the message. This prevents duplicate
1064 * deliveries to local users simultaneously signed onto
1067 if (total_sent) break;
1072 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
1074 struct MaintenanceThreadHook *newfcn;
1076 newfcn = (struct MaintenanceThreadHook *)
1077 malloc(sizeof(struct MaintenanceThreadHook));
1078 newfcn->name = name;
1079 newfcn->next = MaintenanceThreadHookTable;
1080 newfcn->fcn_ptr = thread_proc;
1081 MaintenanceThreadHookTable = newfcn;
1083 lprintf(CTDL_INFO, "Registered a new maintenance thread function\n");
1088 * Dirty hack until we impliment a hook mechanism for this
1090 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1093 CtdlStartTLS (ok_response, nosup_response, error_response);