4 * Citadel Dynamic Loading Module
5 * Written by Brian Costello <btx@calyx.net>
13 #include <sys/types.h>
18 #include <libcitadel.h>
21 #include "serv_extensions.h"
22 #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 SearchFunctionHook *SearchFunctionHookTable = NULL;
47 struct ProtoFunctionHook {
48 void (*handler) (char *cmdbuf);
53 HashList *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"
96 " After that goto Administration -> Shutdown Citadel to make Citadel retry to bind this port.\n";
99 void LogPrintMessages(long err)
101 char *List, *DetailList, *Short, *Where, *Hint, *Message;
102 int n = nSizPort + nSizErrmsg + 5;
104 Message = (char*) malloc(n * SIZ);
106 DetailErrorFlags = DetailErrorFlags & ~err;
111 Short = ErrPortShort;
112 Where = ErrPortWhere;
115 DetailList = errormessages;
126 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
128 CtdlLogPrintf(0,Message);
129 CtdlLogPrintf(0,ErrSubject);
130 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
131 if (errormessages!=NULL) free (errormessages);
132 errormessages = NULL;
133 if (portlist!=NULL) free (portlist);
140 void AppendString(char **target, char *append, size_t *len, size_t rate)
146 AddLen = strlen(append);
152 *target = (char*)malloc (*len * SIZ);
156 oLen = strlen(*target);
157 RelPtr = strlen(*target);
158 if (oLen + AddLen + 2 > *len * SIZ)
160 char *Buff = *target;
161 size_t NewSiz = *len + 10;
162 *target = malloc (NewSiz * SIZ);
163 memcpy (*target, Buff, NewSiz * SIZ);
167 memcpy (*target + oLen, append, AddLen);
168 (*target)[oLen + AddLen + 1] = '\n';
169 (*target)[oLen + AddLen + 2] = '\0';
172 void AddPortError(char *Port, char *ErrorMessage)
177 DetailErrorFlags |= ERR_PORT;
179 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
180 AppendString(&portlist, Port, &nSizPort, 2);
182 pos = strchr (portlist, ':');
183 if (pos != NULL) *pos = ';';
185 len = strlen (errormessages);
186 if (nSizErrmsg * SIZ > len + 3)
188 errormessages[len] = ';';
189 errormessages[len+1] = ' ';
190 errormessages[len+2] = '\0';
195 int DLoader_Exec_Cmd(char *cmdbuf)
198 struct ProtoFunctionHook *p;
200 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
201 p = (struct ProtoFunctionHook*) vP;
202 p->handler(&cmdbuf[5]);
208 int FourHash(const char *key, long length)
212 const unsigned char *ptr = (const unsigned char*)key;
214 for (i = 0; i < 4; i++, ptr ++)
224 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
226 struct ProtoFunctionHook *p;
228 if (ProtoHookList == NULL)
229 ProtoHookList = NewHash (1, FourHash);
232 p = (struct ProtoFunctionHook *)
233 malloc(sizeof(struct ProtoFunctionHook));
236 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
239 p->handler = handler;
243 Put(ProtoHookList, cmd, 4, p, NULL);
244 CtdlLogPrintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
247 void CtdlDestroyProtoHooks(void)
250 DeleteHash(&ProtoHookList);
254 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
257 struct CleanupFunctionHook *newfcn;
259 newfcn = (struct CleanupFunctionHook *)
260 malloc(sizeof(struct CleanupFunctionHook));
261 newfcn->next = CleanupHookTable;
262 newfcn->h_function_pointer = fcn_ptr;
263 CleanupHookTable = newfcn;
265 CtdlLogPrintf(CTDL_INFO, "Registered a new cleanup function\n");
269 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
271 struct CleanupFunctionHook *cur, *p;
273 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
274 /* This will also remove duplicates if any */
275 while (cur != NULL &&
276 fcn_ptr == cur->h_function_pointer) {
277 CtdlLogPrintf(CTDL_INFO, "Unregistered cleanup function\n");
279 if (cur == CleanupHookTable) {
280 CleanupHookTable = p;
288 void CtdlDestroyCleanupHooks(void)
290 struct CleanupFunctionHook *cur, *p;
292 cur = CleanupHookTable;
295 CtdlLogPrintf(CTDL_INFO, "Destroyed cleanup function\n");
300 CleanupHookTable = NULL;
304 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
307 struct SessionFunctionHook *newfcn;
309 newfcn = (struct SessionFunctionHook *)
310 malloc(sizeof(struct SessionFunctionHook));
311 newfcn->next = SessionHookTable;
312 newfcn->h_function_pointer = fcn_ptr;
313 newfcn->eventtype = EventType;
314 SessionHookTable = newfcn;
316 CtdlLogPrintf(CTDL_INFO, "Registered a new session function (type %d)\n",
321 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
323 struct SessionFunctionHook *cur, *p;
325 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
326 /* This will also remove duplicates if any */
327 while (cur != NULL &&
328 fcn_ptr == cur->h_function_pointer &&
329 EventType == cur->eventtype) {
330 CtdlLogPrintf(CTDL_INFO, "Unregistered session function (type %d)\n",
333 if (cur == SessionHookTable) {
334 SessionHookTable = p;
342 void CtdlDestroySessionHooks(void)
344 struct SessionFunctionHook *cur, *p;
346 cur = SessionHookTable;
349 CtdlLogPrintf(CTDL_INFO, "Destroyed session function\n");
354 SessionHookTable = NULL;
358 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
361 struct UserFunctionHook *newfcn;
363 newfcn = (struct UserFunctionHook *)
364 malloc(sizeof(struct UserFunctionHook));
365 newfcn->next = UserHookTable;
366 newfcn->h_function_pointer = fcn_ptr;
367 newfcn->eventtype = EventType;
368 UserHookTable = newfcn;
370 CtdlLogPrintf(CTDL_INFO, "Registered a new user function (type %d)\n",
375 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
377 struct UserFunctionHook *cur, *p;
379 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
380 /* This will also remove duplicates if any */
381 while (cur != NULL &&
382 fcn_ptr == cur->h_function_pointer &&
383 EventType == cur->eventtype) {
384 CtdlLogPrintf(CTDL_INFO, "Unregistered user function (type %d)\n",
387 if (cur == UserHookTable) {
396 void CtdlDestroyUserHooks(void)
398 struct UserFunctionHook *cur, *p;
403 CtdlLogPrintf(CTDL_INFO, "Destroyed user function \n");
408 UserHookTable = NULL;
412 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
416 struct MessageFunctionHook *newfcn;
418 newfcn = (struct MessageFunctionHook *)
419 malloc(sizeof(struct MessageFunctionHook));
420 newfcn->next = MessageHookTable;
421 newfcn->h_function_pointer = handler;
422 newfcn->eventtype = EventType;
423 MessageHookTable = newfcn;
425 CtdlLogPrintf(CTDL_INFO, "Registered a new message function (type %d)\n",
430 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
433 struct MessageFunctionHook *cur, *p;
435 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
436 /* This will also remove duplicates if any */
437 while (cur != NULL &&
438 handler == cur->h_function_pointer &&
439 EventType == cur->eventtype) {
440 CtdlLogPrintf(CTDL_INFO, "Unregistered message function (type %d)\n",
443 if (cur == MessageHookTable) {
444 MessageHookTable = p;
452 void CtdlDestroyMessageHook(void)
454 struct MessageFunctionHook *cur, *p;
456 cur = MessageHookTable;
459 CtdlLogPrintf(CTDL_INFO, "Destroyed message function (type %d)\n", cur->eventtype);
464 MessageHookTable = NULL;
468 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
470 struct RoomFunctionHook *newfcn;
472 newfcn = (struct RoomFunctionHook *)
473 malloc(sizeof(struct RoomFunctionHook));
474 newfcn->next = RoomHookTable;
475 newfcn->fcn_ptr = fcn_ptr;
476 RoomHookTable = newfcn;
478 CtdlLogPrintf(CTDL_INFO, "Registered a new room function\n");
482 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
484 struct RoomFunctionHook *cur, *p;
486 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
487 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
488 CtdlLogPrintf(CTDL_INFO, "Unregistered room function\n");
490 if (cur == RoomHookTable) {
500 void CtdlDestroyRoomHooks(void)
502 struct RoomFunctionHook *cur, *p;
507 CtdlLogPrintf(CTDL_INFO, "Destroyed room function\n");
512 RoomHookTable = NULL;
515 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
517 struct NetprocFunctionHook *newfcn;
519 newfcn = (struct NetprocFunctionHook *)
520 malloc(sizeof(struct NetprocFunctionHook));
521 newfcn->next = NetprocHookTable;
522 newfcn->h_function_pointer = handler;
523 NetprocHookTable = newfcn;
525 CtdlLogPrintf(CTDL_INFO, "Registered a new netproc function\n");
529 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
531 struct NetprocFunctionHook *cur, *p;
533 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
534 /* This will also remove duplicates if any */
535 while (cur != NULL &&
536 handler == cur->h_function_pointer ) {
537 CtdlLogPrintf(CTDL_INFO, "Unregistered netproc function\n");
539 if (cur == NetprocHookTable) {
540 NetprocHookTable = p;
548 void CtdlDestroyNetprocHooks(void)
550 struct NetprocFunctionHook *cur, *p;
552 cur = NetprocHookTable;
555 CtdlLogPrintf(CTDL_INFO, "Destroyed netproc function\n");
560 NetprocHookTable = NULL;
564 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
566 struct DeleteFunctionHook *newfcn;
568 newfcn = (struct DeleteFunctionHook *)
569 malloc(sizeof(struct DeleteFunctionHook));
570 newfcn->next = DeleteHookTable;
571 newfcn->h_function_pointer = handler;
572 DeleteHookTable = newfcn;
574 CtdlLogPrintf(CTDL_INFO, "Registered a new delete function\n");
578 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
580 struct DeleteFunctionHook *cur, *p;
582 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
583 /* This will also remove duplicates if any */
584 while (cur != NULL &&
585 handler == cur->h_function_pointer ) {
586 CtdlLogPrintf(CTDL_INFO, "Unregistered delete function\n");
588 if (cur == DeleteHookTable) {
596 void CtdlDestroyDeleteHooks(void)
598 struct DeleteFunctionHook *cur, *p;
600 cur = DeleteHookTable;
603 CtdlLogPrintf(CTDL_INFO, "Destroyed delete function\n");
608 DeleteHookTable = NULL;
614 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
616 struct FixedOutputHook *newfcn;
618 newfcn = (struct FixedOutputHook *)
619 malloc(sizeof(struct FixedOutputHook));
620 newfcn->next = FixedOutputTable;
621 newfcn->h_function_pointer = handler;
622 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
623 FixedOutputTable = newfcn;
625 CtdlLogPrintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
629 void CtdlUnregisterFixedOutputHook(char *content_type)
631 struct FixedOutputHook *cur, *p;
633 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
634 /* This will also remove duplicates if any */
635 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
636 CtdlLogPrintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
638 if (cur == FixedOutputTable) {
639 FixedOutputTable = p;
647 void CtdlDestroyFixedOutputHooks(void)
649 struct FixedOutputHook *cur, *p;
651 cur = FixedOutputTable;
654 CtdlLogPrintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
660 FixedOutputTable = NULL;
663 /* returns nonzero if we found a hook and used it */
664 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
666 struct FixedOutputHook *fcn;
668 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
669 if (!strcasecmp(content_type, fcn->content_type)) {
670 (*fcn->h_function_pointer) (content, content_length);
681 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
684 struct XmsgFunctionHook *newfcn;
686 newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook));
687 newfcn->next = XmsgHookTable;
688 newfcn->order = order;
689 newfcn->h_function_pointer = fcn_ptr;
690 XmsgHookTable = newfcn;
691 CtdlLogPrintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
695 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
697 struct XmsgFunctionHook *cur, *p;
699 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
700 /* This will also remove duplicates if any */
701 while (cur != NULL &&
702 fcn_ptr == cur->h_function_pointer &&
703 order == cur->order) {
704 CtdlLogPrintf(CTDL_INFO, "Unregistered x-msg function "
705 "(priority %d)\n", order);
707 if (cur == XmsgHookTable) {
716 void CtdlDestroyXmsgHooks(void)
718 struct XmsgFunctionHook *cur, *p;
723 CtdlLogPrintf(CTDL_INFO, "Destroyed x-msg function "
724 "(priority %d)\n", cur->order);
730 XmsgHookTable = NULL;
734 void CtdlRegisterServiceHook(int tcp_port,
736 void (*h_greeting_function) (void),
737 void (*h_command_function) (void),
738 void (*h_async_function) (void),
739 const char *ServiceName)
741 struct ServiceFunctionHook *newfcn;
746 newfcn = (struct ServiceFunctionHook *)
747 malloc(sizeof(struct ServiceFunctionHook));
748 message = (char*) malloc (SIZ);
750 newfcn->next = ServiceHookTable;
751 newfcn->tcp_port = tcp_port;
752 newfcn->sockpath = sockpath;
753 newfcn->h_greeting_function = h_greeting_function;
754 newfcn->h_command_function = h_command_function;
755 newfcn->h_async_function = h_async_function;
756 newfcn->ServiceName = ServiceName;
758 if (sockpath != NULL) {
759 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
760 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
762 else if (tcp_port <= 0) { /* port -1 to disable */
763 CtdlLogPrintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
769 newfcn->msock = ig_tcp_server(config.c_ip_addr,
771 config.c_maxsessions,
773 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
774 config.c_ip_addr, tcp_port, ServiceName);
777 if (newfcn->msock > 0) {
778 ServiceHookTable = newfcn;
779 strcat(message, "registered.");
780 CtdlLogPrintf(CTDL_INFO, "%s\n", message);
783 AddPortError(message, error);
784 strcat(message, "FAILED.");
785 CtdlLogPrintf(CTDL_CRIT, "%s\n", message);
793 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
794 void (*h_greeting_function) (void),
795 void (*h_command_function) (void),
796 void (*h_async_function) (void)
799 struct ServiceFunctionHook *cur, *p;
801 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
802 /* This will also remove duplicates if any */
803 while (cur != NULL &&
804 !(sockpath && cur->sockpath &&
805 strcmp(sockpath, cur->sockpath)) &&
806 h_greeting_function == cur->h_greeting_function &&
807 h_command_function == cur->h_command_function &&
808 h_async_function == cur->h_async_function &&
809 tcp_port == cur->tcp_port) {
812 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
814 } else if (tcp_port) {
815 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
817 CtdlLogPrintf(CTDL_INFO, "Unregistered service \"%s\"\n", cur->ServiceName);
820 if (cur == ServiceHookTable) {
821 ServiceHookTable = p;
829 void CtdlDestroyServiceHook(void)
831 struct ServiceFunctionHook *cur, *p;
833 cur = ServiceHookTable;
838 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
840 } else if (cur->tcp_port) {
841 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
843 CtdlLogPrintf(CTDL_INFO, "Destroyed service \"%s\"\n", cur->ServiceName);
849 ServiceHookTable = NULL;
852 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
854 struct SearchFunctionHook *newfcn;
856 if (!name || !fcn_ptr) {
860 newfcn = (struct SearchFunctionHook *)
861 malloc(sizeof(struct SearchFunctionHook));
862 newfcn->next = SearchFunctionHookTable;
864 newfcn->fcn_ptr = fcn_ptr;
865 SearchFunctionHookTable = newfcn;
867 CtdlLogPrintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
870 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
872 struct SearchFunctionHook *cur, *p;
874 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
875 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
876 CtdlLogPrintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
878 if (cur == SearchFunctionHookTable) {
879 SearchFunctionHookTable = p;
887 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
889 struct SearchFunctionHook *fcn = NULL;
891 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
892 if (!func_name || !strcmp(func_name, fcn->name)) {
893 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
901 void PerformSessionHooks(int EventType)
903 struct SessionFunctionHook *fcn = NULL;
905 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
906 if (fcn->eventtype == EventType) {
907 (*fcn->h_function_pointer) ();
912 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
914 struct UserFunctionHook *fcn = NULL;
916 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
917 if (fcn->eventtype == EventType) {
918 (*fcn->h_function_pointer) (usbuf);
923 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
925 struct MessageFunctionHook *fcn = NULL;
926 int total_retval = 0;
928 /* Other code may elect to protect this message from server-side
929 * handlers; if this is the case, don't do anything.
930 CtdlLogPrintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
931 EventType, msg->cm_flags);
933 if (msg->cm_flags & CM_SKIP_HOOKS) {
934 CtdlLogPrintf(CTDL_DEBUG, "Skipping hooks\n");
938 /* Otherwise, run all the hooks appropriate to this event type.
940 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
941 if (fcn->eventtype == EventType) {
942 total_retval = total_retval +
943 (*fcn->h_function_pointer) (msg);
947 /* Return the sum of the return codes from the hook functions. If
948 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
949 * the save operation to abort.
955 int PerformRoomHooks(struct ctdlroom *target_room)
957 struct RoomFunctionHook *fcn;
958 int total_retval = 0;
960 CtdlLogPrintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
962 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
963 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
966 /* Return the sum of the return codes from the hook functions.
972 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
974 struct NetprocFunctionHook *fcn;
975 int total_retval = 0;
977 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
978 total_retval = total_retval +
979 (*fcn->h_function_pointer) (msg, target_room);
982 /* Return the sum of the return codes from the hook functions.
983 * A nonzero return code will cause the message to *not* be imported.
989 void PerformDeleteHooks(char *room, long msgnum)
991 struct DeleteFunctionHook *fcn;
993 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
994 (*fcn->h_function_pointer) (room, msgnum);
1002 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1004 struct XmsgFunctionHook *fcn;
1008 for (p=0; p<MAX_XMSG_PRI; ++p) {
1009 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1010 if (fcn->order == p) {
1012 (*fcn->h_function_pointer)
1013 (sender, sender_email, recp, msg);
1016 /* Break out of the loop if a higher-priority function
1017 * successfully delivered the message. This prevents duplicate
1018 * deliveries to local users simultaneously signed onto
1021 if (total_sent) break;
1029 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module)
1031 struct DirectoryServiceHook *newfcn;
1033 newfcn = DirectoryServiceHookList;
1036 if (newfcn->cmd == cmd && !strcmp(newfcn->module, module))
1038 CtdlLogPrintf(CTDL_ERR, "Directory service function already handled by module %s\n", module);
1041 newfcn = newfcn->next;
1044 newfcn = (struct DirectoryServiceHook *) malloc (sizeof(struct DirectoryServiceHook));
1045 newfcn->handler = func;
1047 newfcn->module = module;
1048 newfcn->next = DirectoryServiceHookList;
1049 DirectoryServiceHookList = newfcn;
1051 CtdlLogPrintf(CTDL_INFO, "Registered a new directory service function from module %s\n", module);
1055 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd)
1057 struct DirectoryServiceHook *curfcn;
1058 struct DirectoryObject *our_object_list = NULL;
1059 struct DirectoryObject *newobject = NULL;
1060 struct DirectoryObject *oldobject = NULL;
1063 curfcn = DirectoryServiceHookList;
1065 our_object_list = (struct DirectoryObject *) *object;
1069 if (curfcn->cmd == cmd)
1073 if (cmd == DIRECTORY_CREATE_OBJECT)
1075 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1076 newobject->module = curfcn->module;
1077 newobject->object = NULL;
1078 newobject->next = our_object_list;
1079 our_object_list = newobject;
1081 if (our_object_list)
1083 for(newobject = our_object_list; newobject; newobject=newobject->next)
1085 if (!strcmp(newobject->module, curfcn->module))
1086 (void) curfcn->handler(cn, ou, &newobject->object);
1090 (void) curfcn->handler(cn, ou, NULL);
1096 if(!strcmp(curfcn->module, module))
1098 if (cmd == DIRECTORY_CREATE_OBJECT)
1100 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1101 newobject->module = module;
1102 newobject->object = NULL;
1103 newobject->next = our_object_list;
1104 our_object_list = newobject;
1106 if (our_object_list)
1108 for(newobject = our_object_list; newobject; newobject=newobject->next)
1110 if (!strcmp(newobject->module, curfcn->module))
1111 (void) curfcn->handler(cn, ou, &newobject->object);
1115 (void) (curfcn->handler(cn, ou, NULL));
1121 curfcn=curfcn->next;
1123 if (our_object_list)
1125 *object = our_object_list;
1126 if (cmd == DIRECTORY_FREE_OBJECT)
1127 { // The objects pointed to by the list should have been freed by the module that created it
1128 for(newobject = our_object_list; newobject; )
1130 oldobject=newobject;
1131 newobject=newobject->next;
1140 void CtdlDestroyDirectoryServiceFuncs(void)
1142 struct DirectoryServiceHook *cur, *next;
1144 cur = DirectoryServiceHookList;
1145 DirectoryServiceHookList = NULL;
1149 CtdlLogPrintf(CTDL_INFO, "Destroyed directory service function for module %s.\n", cur->module);
1156 * Dirty hack until we impliment a hook mechanism for this
1158 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1161 CtdlStartTLS (ok_response, nosup_response, error_response);