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 */
28 #include "ctdl_module.h"
35 struct CleanupFunctionHook *CleanupHookTable = NULL;
36 struct SessionFunctionHook *SessionHookTable = NULL;
37 struct UserFunctionHook *UserHookTable = NULL;
38 struct XmsgFunctionHook *XmsgHookTable = NULL;
39 struct MessageFunctionHook *MessageHookTable = NULL;
40 struct NetprocFunctionHook *NetprocHookTable = NULL;
41 struct DeleteFunctionHook *DeleteHookTable = NULL;
42 struct ServiceFunctionHook *ServiceHookTable = NULL;
43 struct FixedOutputHook *FixedOutputTable = NULL;
44 struct RoomFunctionHook *RoomHookTable = NULL;
45 struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL;
46 struct SearchFunctionHook *SearchFunctionHookTable = NULL;
48 struct ProtoFunctionHook {
49 void (*handler) (char *cmdbuf);
52 struct ProtoFunctionHook *next;
53 } *ProtoHookList = NULL;
56 struct DirectoryServiceHook {
57 int (*handler) (char *cn, char *ou, void **object);
60 struct DirectoryServiceHook *next;
61 } *DirectoryServiceHookList = NULL;
63 struct DirectoryObject {
66 struct DirectoryObject *next;
69 #define ERR_PORT (1 << 1)
72 static char *portlist = NULL;
73 static size_t nSizPort = 0;
75 static char *errormessages = NULL;
76 size_t nSizErrmsg = 0;
79 long DetailErrorFlags;
81 char *ErrSubject = "Startup Problems";
82 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"
83 "If you don't want citadel to provide these services, turn them off in WebCit via %s%s\n\n%s\n\n"
84 "To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
85 "The errors returned by the system were:\n%s\n"
86 "You can recheck the above if you follow this faq item:\n"
87 "http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat";
90 char *ErrPortShort = "We couldn't bind all ports you configured to be provided by citadel server.";
91 char *ErrPortWhere = "Admin->System Preferences->Network.\n\nThe failed ports and sockets are: ";
92 char *ErrPortHint = "If you want citadel to provide you with that functionality, "
93 "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD"
94 " and stop the programm, that binds these ports. You should eventually remove "
95 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n";
98 void LogPrintMessages(long err)
100 char *List, *DetailList, *Short, *Where, *Hint, *Message;
101 int n = nSizPort + nSizErrmsg + 5;
103 Message = (char*) malloc(n * SIZ);
108 Short = ErrPortShort;
109 Where = ErrPortWhere;
112 DetailList = errormessages;
123 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
126 lprintf(0,ErrSubject);
127 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
128 if (errormessages!=NULL) free (errormessages);
129 errormessages = NULL;
130 if (portlist!=NULL) free (portlist);
137 void AppendString(char **target, char *append, size_t *len, size_t rate)
143 AddLen = strlen(append);
149 *target = (char*)malloc (*len * SIZ);
153 oLen = strlen(*target);
154 RelPtr = strlen(*target);
155 if (oLen + AddLen + 2 > *len * SIZ)
157 char *Buff = *target;
158 size_t NewSiz = *len + 10;
159 *target = malloc (NewSiz * SIZ);
160 memcpy (*target, Buff, NewSiz * SIZ);
164 memcpy (*target + oLen, append, AddLen);
165 (*target)[oLen + AddLen + 1] = '\n';
166 (*target)[oLen + AddLen + 2] = '\0';
169 void AddPortError(char *Port, char *ErrorMessage)
174 DetailErrorFlags |= ERR_PORT;
176 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
177 AppendString(&portlist, Port, &nSizPort, 2);
179 pos = strchr (portlist, ':');
180 if (pos != NULL) *pos = ';';
182 len = strlen (errormessages);
183 if (nSizErrmsg * SIZ > len + 3)
185 errormessages[len] = ';';
186 errormessages[len+1] = ' ';
187 errormessages[len+2] = '\0';
192 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
194 struct ProtoFunctionHook *p;
196 p = (struct ProtoFunctionHook *)
197 malloc(sizeof(struct ProtoFunctionHook));
200 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
203 p->handler = handler;
206 p->next = ProtoHookList;
208 lprintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
212 void CtdlUnregisterProtoHook(void (*handler) (char *), char *cmd)
214 struct ProtoFunctionHook *cur = NULL;
215 struct ProtoFunctionHook *p = NULL;
216 struct ProtoFunctionHook *lastcur = NULL;
218 for (cur = ProtoHookList;
220 cur = (cur != NULL)? cur->next: NULL) {
221 /* This will also remove duplicates if any */
222 while (cur != NULL &&
223 handler == cur->handler &&
224 !strcmp(cmd, cur->cmd)) {
225 lprintf(CTDL_INFO, "Unregistered server command %s (%s)\n",
228 if (cur == ProtoHookList) {
231 else if (lastcur != NULL)
242 void CtdlDestroyProtoHooks(void)
244 struct ProtoFunctionHook *cur, *p;
249 lprintf(CTDL_INFO, "Destroyed server command %s (%s)\n",
250 cur->cmd, cur->desc);
255 ProtoHookList = NULL;
259 int DLoader_Exec_Cmd(char *cmdbuf)
261 struct ProtoFunctionHook *p;
263 for (p = ProtoHookList; p; p = p->next) {
264 if (!strncasecmp(cmdbuf, p->cmd, 4)) {
265 p->handler(&cmdbuf[5]);
273 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
276 struct CleanupFunctionHook *newfcn;
278 newfcn = (struct CleanupFunctionHook *)
279 malloc(sizeof(struct CleanupFunctionHook));
280 newfcn->next = CleanupHookTable;
281 newfcn->h_function_pointer = fcn_ptr;
282 CleanupHookTable = newfcn;
284 lprintf(CTDL_INFO, "Registered a new cleanup function\n");
288 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
290 struct CleanupFunctionHook *cur, *p;
292 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
293 /* This will also remove duplicates if any */
294 while (cur != NULL &&
295 fcn_ptr == cur->h_function_pointer) {
296 lprintf(CTDL_INFO, "Unregistered cleanup function\n");
298 if (cur == CleanupHookTable) {
299 CleanupHookTable = p;
307 void CtdlDestroyCleanupHooks(void)
309 struct CleanupFunctionHook *cur, *p;
311 cur = CleanupHookTable;
314 lprintf(CTDL_INFO, "Destroyed cleanup function\n");
319 CleanupHookTable = NULL;
323 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
326 struct SessionFunctionHook *newfcn;
328 newfcn = (struct SessionFunctionHook *)
329 malloc(sizeof(struct SessionFunctionHook));
330 newfcn->next = SessionHookTable;
331 newfcn->h_function_pointer = fcn_ptr;
332 newfcn->eventtype = EventType;
333 SessionHookTable = newfcn;
335 lprintf(CTDL_INFO, "Registered a new session function (type %d)\n",
340 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
342 struct SessionFunctionHook *cur, *p;
344 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
345 /* This will also remove duplicates if any */
346 while (cur != NULL &&
347 fcn_ptr == cur->h_function_pointer &&
348 EventType == cur->eventtype) {
349 lprintf(CTDL_INFO, "Unregistered session function (type %d)\n",
352 if (cur == SessionHookTable) {
353 SessionHookTable = p;
361 void CtdlDestroySessionHooks(void)
363 struct SessionFunctionHook *cur, *p;
365 cur = SessionHookTable;
368 lprintf(CTDL_INFO, "Destroyed session function\n");
373 SessionHookTable = NULL;
377 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
380 struct UserFunctionHook *newfcn;
382 newfcn = (struct UserFunctionHook *)
383 malloc(sizeof(struct UserFunctionHook));
384 newfcn->next = UserHookTable;
385 newfcn->h_function_pointer = fcn_ptr;
386 newfcn->eventtype = EventType;
387 UserHookTable = newfcn;
389 lprintf(CTDL_INFO, "Registered a new user function (type %d)\n",
394 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
396 struct UserFunctionHook *cur, *p;
398 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
399 /* This will also remove duplicates if any */
400 while (cur != NULL &&
401 fcn_ptr == cur->h_function_pointer &&
402 EventType == cur->eventtype) {
403 lprintf(CTDL_INFO, "Unregistered user function (type %d)\n",
406 if (cur == UserHookTable) {
415 void CtdlDestroyUserHooks(void)
417 struct UserFunctionHook *cur, *p;
422 lprintf(CTDL_INFO, "Destroyed user function \n");
427 UserHookTable = NULL;
431 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
435 struct MessageFunctionHook *newfcn;
437 newfcn = (struct MessageFunctionHook *)
438 malloc(sizeof(struct MessageFunctionHook));
439 newfcn->next = MessageHookTable;
440 newfcn->h_function_pointer = handler;
441 newfcn->eventtype = EventType;
442 MessageHookTable = newfcn;
444 lprintf(CTDL_INFO, "Registered a new message function (type %d)\n",
449 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
452 struct MessageFunctionHook *cur, *p;
454 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
455 /* This will also remove duplicates if any */
456 while (cur != NULL &&
457 handler == cur->h_function_pointer &&
458 EventType == cur->eventtype) {
459 lprintf(CTDL_INFO, "Unregistered message function (type %d)\n",
462 if (cur == MessageHookTable) {
463 MessageHookTable = p;
471 void CtdlDestroyMessageHook(void)
473 struct MessageFunctionHook *cur, *p;
475 cur = MessageHookTable;
478 lprintf(CTDL_INFO, "Destroyed message function \n");
483 MessageHookTable = NULL;
487 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
489 struct RoomFunctionHook *newfcn;
491 newfcn = (struct RoomFunctionHook *)
492 malloc(sizeof(struct RoomFunctionHook));
493 newfcn->next = RoomHookTable;
494 newfcn->fcn_ptr = fcn_ptr;
495 RoomHookTable = newfcn;
497 lprintf(CTDL_INFO, "Registered a new room function\n");
501 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
503 struct RoomFunctionHook *cur, *p;
505 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
506 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
507 lprintf(CTDL_INFO, "Unregistered room function\n");
509 if (cur == RoomHookTable) {
519 void CtdlDestroyRoomHooks(void)
521 struct RoomFunctionHook *cur, *p;
526 lprintf(CTDL_INFO, "Unregistered room function\n");
531 RoomHookTable = NULL;
534 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
536 struct NetprocFunctionHook *newfcn;
538 newfcn = (struct NetprocFunctionHook *)
539 malloc(sizeof(struct NetprocFunctionHook));
540 newfcn->next = NetprocHookTable;
541 newfcn->h_function_pointer = handler;
542 NetprocHookTable = newfcn;
544 lprintf(CTDL_INFO, "Registered a new netproc function\n");
548 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
550 struct NetprocFunctionHook *cur, *p;
552 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
553 /* This will also remove duplicates if any */
554 while (cur != NULL &&
555 handler == cur->h_function_pointer ) {
556 lprintf(CTDL_INFO, "Unregistered netproc function\n");
558 if (cur == NetprocHookTable) {
559 NetprocHookTable = p;
567 void CtdlDestroyNetprocHooks(void)
569 struct NetprocFunctionHook *cur, *p;
571 cur = NetprocHookTable;
574 lprintf(CTDL_INFO, "Unregistered netproc function\n");
579 NetprocHookTable = NULL;
583 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
585 struct DeleteFunctionHook *newfcn;
587 newfcn = (struct DeleteFunctionHook *)
588 malloc(sizeof(struct DeleteFunctionHook));
589 newfcn->next = DeleteHookTable;
590 newfcn->h_function_pointer = handler;
591 DeleteHookTable = newfcn;
593 lprintf(CTDL_INFO, "Registered a new netproc function\n");
597 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
599 struct DeleteFunctionHook *cur, *p;
601 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
602 /* This will also remove duplicates if any */
603 while (cur != NULL &&
604 handler == cur->h_function_pointer ) {
605 lprintf(CTDL_INFO, "Unregistered netproc function\n");
607 if (cur == DeleteHookTable) {
615 void CtdlDestroyDeleteHooks(void)
617 struct DeleteFunctionHook *cur, *p;
619 cur = DeleteHookTable;
622 lprintf(CTDL_INFO, "Destroyed netproc function\n");
627 DeleteHookTable = NULL;
633 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
635 struct FixedOutputHook *newfcn;
637 newfcn = (struct FixedOutputHook *)
638 malloc(sizeof(struct FixedOutputHook));
639 newfcn->next = FixedOutputTable;
640 newfcn->h_function_pointer = handler;
641 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
642 FixedOutputTable = newfcn;
644 lprintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
648 void CtdlUnregisterFixedOutputHook(char *content_type)
650 struct FixedOutputHook *cur, *p;
652 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
653 /* This will also remove duplicates if any */
654 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
655 lprintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
657 if (cur == FixedOutputTable) {
658 FixedOutputTable = p;
666 void CtdlDestroyFixedOutputHooks(void)
668 struct FixedOutputHook *cur, *p;
670 cur = FixedOutputTable;
673 lprintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
679 FixedOutputTable = NULL;
682 /* returns nonzero if we found a hook and used it */
683 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
685 struct FixedOutputHook *fcn;
687 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
688 if (!strcasecmp(content_type, fcn->content_type)) {
689 (*fcn->h_function_pointer) (content, content_length);
700 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
703 struct XmsgFunctionHook *newfcn;
705 newfcn = (struct XmsgFunctionHook *)
706 malloc(sizeof(struct XmsgFunctionHook));
707 newfcn->next = XmsgHookTable;
708 newfcn->order = order;
709 newfcn->h_function_pointer = fcn_ptr;
710 XmsgHookTable = newfcn;
711 lprintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
715 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
717 struct XmsgFunctionHook *cur, *p;
719 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
720 /* This will also remove duplicates if any */
721 while (cur != NULL &&
722 fcn_ptr == cur->h_function_pointer &&
723 order == cur->order) {
724 lprintf(CTDL_INFO, "Unregistered x-msg function "
725 "(priority %d)\n", order);
727 if (cur == XmsgHookTable) {
736 void CtdlDestroyXmsgHooks(void)
738 struct XmsgFunctionHook *cur, *p;
743 lprintf(CTDL_INFO, "Destroyed x-msg function "
744 "(priority %d)\n", cur->order);
750 XmsgHookTable = NULL;
754 void CtdlRegisterServiceHook(int tcp_port,
756 void (*h_greeting_function) (void),
757 void (*h_command_function) (void),
758 void (*h_async_function) (void),
759 const char *ServiceName)
761 struct ServiceFunctionHook *newfcn;
766 newfcn = (struct ServiceFunctionHook *)
767 malloc(sizeof(struct ServiceFunctionHook));
768 message = (char*) malloc (SIZ);
770 newfcn->next = ServiceHookTable;
771 newfcn->tcp_port = tcp_port;
772 newfcn->sockpath = sockpath;
773 newfcn->h_greeting_function = h_greeting_function;
774 newfcn->h_command_function = h_command_function;
775 newfcn->h_async_function = h_async_function;
776 newfcn->ServiceName = ServiceName;
778 if (sockpath != NULL) {
779 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
780 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
782 else if (tcp_port <= 0) { /* port -1 to disable */
783 lprintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
789 newfcn->msock = ig_tcp_server(config.c_ip_addr,
791 config.c_maxsessions,
793 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
794 config.c_ip_addr, tcp_port, ServiceName);
797 if (newfcn->msock > 0) {
798 ServiceHookTable = newfcn;
799 strcat(message, "registered.");
800 lprintf(CTDL_INFO, "%s\n", message);
803 AddPortError(message, error);
804 strcat(message, "FAILED.");
805 lprintf(CTDL_CRIT, "%s\n", message);
813 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
814 void (*h_greeting_function) (void),
815 void (*h_command_function) (void),
816 void (*h_async_function) (void)
819 struct ServiceFunctionHook *cur, *p;
821 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
822 /* This will also remove duplicates if any */
823 while (cur != NULL &&
824 !(sockpath && cur->sockpath &&
825 strcmp(sockpath, cur->sockpath)) &&
826 h_greeting_function == cur->h_greeting_function &&
827 h_command_function == cur->h_command_function &&
828 h_async_function == cur->h_async_function &&
829 tcp_port == cur->tcp_port) {
832 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
834 } else if (tcp_port) {
835 lprintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
837 lprintf(CTDL_INFO, "Unregistered unknown service\n");
840 if (cur == ServiceHookTable) {
841 ServiceHookTable = p;
849 void CtdlDestroyServiceHook(void)
851 struct ServiceFunctionHook *cur, *p;
853 cur = ServiceHookTable;
858 lprintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
860 } else if (cur->tcp_port) {
861 lprintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
863 lprintf(CTDL_INFO, "Unregistered unknown service\n");
869 ServiceHookTable = NULL;
872 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
874 struct SearchFunctionHook *newfcn;
876 if (!name || !fcn_ptr) {
880 newfcn = (struct SearchFunctionHook *)
881 malloc(sizeof(struct SearchFunctionHook));
882 newfcn->next = SearchFunctionHookTable;
884 newfcn->fcn_ptr = fcn_ptr;
885 SearchFunctionHookTable = newfcn;
887 lprintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
890 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
892 struct SearchFunctionHook *cur, *p;
894 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
895 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
896 lprintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
898 if (cur == SearchFunctionHookTable) {
899 SearchFunctionHookTable = p;
907 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
909 struct SearchFunctionHook *fcn = NULL;
911 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
912 if (!func_name || !strcmp(func_name, fcn->name)) {
913 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
921 void PerformSessionHooks(int EventType)
923 struct SessionFunctionHook *fcn = NULL;
925 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
926 if (fcn->eventtype == EventType) {
927 (*fcn->h_function_pointer) ();
932 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
934 struct UserFunctionHook *fcn = NULL;
936 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
937 if (fcn->eventtype == EventType) {
938 (*fcn->h_function_pointer) (usbuf);
943 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
945 struct MessageFunctionHook *fcn = NULL;
946 int total_retval = 0;
948 /* Other code may elect to protect this message from server-side
949 * handlers; if this is the case, don't do anything.
950 lprintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
951 EventType, msg->cm_flags);
953 if (msg->cm_flags & CM_SKIP_HOOKS) {
954 lprintf(CTDL_DEBUG, "Skipping hooks\n");
958 /* Otherwise, run all the hooks appropriate to this event type.
960 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
961 if (fcn->eventtype == EventType) {
962 total_retval = total_retval +
963 (*fcn->h_function_pointer) (msg);
967 /* Return the sum of the return codes from the hook functions. If
968 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
969 * the save operation to abort.
975 int PerformRoomHooks(struct ctdlroom *target_room)
977 struct RoomFunctionHook *fcn;
978 int total_retval = 0;
980 lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
982 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
983 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
986 /* Return the sum of the return codes from the hook functions.
992 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
994 struct NetprocFunctionHook *fcn;
995 int total_retval = 0;
997 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
998 total_retval = total_retval +
999 (*fcn->h_function_pointer) (msg, target_room);
1002 /* Return the sum of the return codes from the hook functions.
1003 * A nonzero return code will cause the message to *not* be imported.
1005 return total_retval;
1009 void PerformDeleteHooks(char *room, long msgnum)
1011 struct DeleteFunctionHook *fcn;
1013 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1014 (*fcn->h_function_pointer) (room, msgnum);
1022 int PerformXmsgHooks(char *sender, char *recp, char *msg)
1024 struct XmsgFunctionHook *fcn;
1028 for (p=0; p<MAX_XMSG_PRI; ++p) {
1029 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1030 if (fcn->order == p) {
1032 (*fcn->h_function_pointer)
1033 (sender, recp, msg);
1036 /* Break out of the loop if a higher-priority function
1037 * successfully delivered the message. This prevents duplicate
1038 * deliveries to local users simultaneously signed onto
1041 if (total_sent) break;
1046 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
1048 struct MaintenanceThreadHook *newfcn;
1050 newfcn = (struct MaintenanceThreadHook *)
1051 malloc(sizeof(struct MaintenanceThreadHook));
1052 newfcn->name = name;
1053 newfcn->next = MaintenanceThreadHookTable;
1054 newfcn->fcn_ptr = thread_proc;
1055 MaintenanceThreadHookTable = newfcn;
1057 lprintf(CTDL_INFO, "Registered a new maintenance thread function\n");
1062 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module)
1064 struct DirectoryServiceHook *newfcn;
1066 newfcn = DirectoryServiceHookList;
1069 if (newfcn->cmd == cmd && !strcmp(newfcn->module, module))
1071 lprintf(CTDL_ERR, "Directory service function already handled by module %s\n", module);
1074 newfcn = newfcn->next;
1077 newfcn = (struct DirectoryServiceHook *) malloc (sizeof(struct DirectoryServiceHook));
1078 newfcn->handler = func;
1080 newfcn->module = module;
1081 newfcn->next = DirectoryServiceHookList;
1082 DirectoryServiceHookList = newfcn;
1084 lprintf(CTDL_INFO, "Registered a new directory service function from module %s\n", module);
1088 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd)
1090 struct DirectoryServiceHook *curfcn;
1091 struct DirectoryObject *our_object_list = NULL;
1092 struct DirectoryObject *newobject = NULL;
1093 struct DirectoryObject *oldobject = NULL;
1096 curfcn = DirectoryServiceHookList;
1098 our_object_list = (struct DirectoryObject *) *object;
1102 if (curfcn->cmd == cmd)
1106 if (cmd == DIRECTORY_CREATE_OBJECT)
1108 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1109 newobject->module = curfcn->module;
1110 newobject->object = NULL;
1111 newobject->next = our_object_list;
1112 our_object_list = newobject;
1114 if (our_object_list)
1116 for(newobject = our_object_list; newobject; newobject=newobject->next)
1118 if (!strcmp(newobject->module, curfcn->module))
1119 (void) curfcn->handler(cn, ou, &newobject->object);
1123 (void) curfcn->handler(cn, ou, NULL);
1129 if(!strcmp(curfcn->module, module))
1131 if (cmd == DIRECTORY_CREATE_OBJECT)
1133 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1134 newobject->module = module;
1135 newobject->object = NULL;
1136 newobject->next = our_object_list;
1137 our_object_list = newobject;
1139 if (our_object_list)
1141 for(newobject = our_object_list; newobject; newobject=newobject->next)
1143 if (!strcmp(newobject->module, curfcn->module))
1144 (void) curfcn->handler(cn, ou, &newobject->object);
1148 (void) (curfcn->handler(cn, ou, NULL));
1154 curfcn=curfcn->next;
1156 if (our_object_list)
1158 *object = our_object_list;
1159 if (cmd == DIRECTORY_FREE_OBJECT)
1160 { // The objects pointed to by the list should have been freed by the module that created it
1161 for(newobject = our_object_list; newobject; )
1163 oldobject=newobject;
1164 newobject=newobject->next;
1174 * Dirty hack until we impliment a hook mechanism for this
1176 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1179 CtdlStartTLS (ok_response, nosup_response, error_response);