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 ++)
215 ret = (ret << 8) | *ptr;
220 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
222 struct ProtoFunctionHook *p;
224 if (ProtoHookList == NULL)
225 ProtoHookList = NewHash (1, FourHash);
228 p = (struct ProtoFunctionHook *)
229 malloc(sizeof(struct ProtoFunctionHook));
232 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
235 p->handler = handler;
239 Put(ProtoHookList, cmd, 4, p, NULL);
240 CtdlLogPrintf(CTDL_INFO, "Registered server command %s (%s)\n", cmd, desc);
243 void CtdlDestroyProtoHooks(void)
246 DeleteHash(&ProtoHookList);
250 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
253 struct CleanupFunctionHook *newfcn;
255 newfcn = (struct CleanupFunctionHook *)
256 malloc(sizeof(struct CleanupFunctionHook));
257 newfcn->next = CleanupHookTable;
258 newfcn->h_function_pointer = fcn_ptr;
259 CleanupHookTable = newfcn;
261 CtdlLogPrintf(CTDL_INFO, "Registered a new cleanup function\n");
265 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
267 struct CleanupFunctionHook *cur, *p;
269 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
270 /* This will also remove duplicates if any */
271 while (cur != NULL &&
272 fcn_ptr == cur->h_function_pointer) {
273 CtdlLogPrintf(CTDL_INFO, "Unregistered cleanup function\n");
275 if (cur == CleanupHookTable) {
276 CleanupHookTable = p;
284 void CtdlDestroyCleanupHooks(void)
286 struct CleanupFunctionHook *cur, *p;
288 cur = CleanupHookTable;
291 CtdlLogPrintf(CTDL_INFO, "Destroyed cleanup function\n");
296 CleanupHookTable = NULL;
300 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
303 struct SessionFunctionHook *newfcn;
305 newfcn = (struct SessionFunctionHook *)
306 malloc(sizeof(struct SessionFunctionHook));
307 newfcn->next = SessionHookTable;
308 newfcn->h_function_pointer = fcn_ptr;
309 newfcn->eventtype = EventType;
310 SessionHookTable = newfcn;
312 CtdlLogPrintf(CTDL_INFO, "Registered a new session function (type %d)\n",
317 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
319 struct SessionFunctionHook *cur, *p;
321 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
322 /* This will also remove duplicates if any */
323 while (cur != NULL &&
324 fcn_ptr == cur->h_function_pointer &&
325 EventType == cur->eventtype) {
326 CtdlLogPrintf(CTDL_INFO, "Unregistered session function (type %d)\n",
329 if (cur == SessionHookTable) {
330 SessionHookTable = p;
338 void CtdlDestroySessionHooks(void)
340 struct SessionFunctionHook *cur, *p;
342 cur = SessionHookTable;
345 CtdlLogPrintf(CTDL_INFO, "Destroyed session function\n");
350 SessionHookTable = NULL;
354 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
357 struct UserFunctionHook *newfcn;
359 newfcn = (struct UserFunctionHook *)
360 malloc(sizeof(struct UserFunctionHook));
361 newfcn->next = UserHookTable;
362 newfcn->h_function_pointer = fcn_ptr;
363 newfcn->eventtype = EventType;
364 UserHookTable = newfcn;
366 CtdlLogPrintf(CTDL_INFO, "Registered a new user function (type %d)\n",
371 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
373 struct UserFunctionHook *cur, *p;
375 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
376 /* This will also remove duplicates if any */
377 while (cur != NULL &&
378 fcn_ptr == cur->h_function_pointer &&
379 EventType == cur->eventtype) {
380 CtdlLogPrintf(CTDL_INFO, "Unregistered user function (type %d)\n",
383 if (cur == UserHookTable) {
392 void CtdlDestroyUserHooks(void)
394 struct UserFunctionHook *cur, *p;
399 CtdlLogPrintf(CTDL_INFO, "Destroyed user function \n");
404 UserHookTable = NULL;
408 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
412 struct MessageFunctionHook *newfcn;
414 newfcn = (struct MessageFunctionHook *)
415 malloc(sizeof(struct MessageFunctionHook));
416 newfcn->next = MessageHookTable;
417 newfcn->h_function_pointer = handler;
418 newfcn->eventtype = EventType;
419 MessageHookTable = newfcn;
421 CtdlLogPrintf(CTDL_INFO, "Registered a new message function (type %d)\n",
426 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
429 struct MessageFunctionHook *cur, *p;
431 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
432 /* This will also remove duplicates if any */
433 while (cur != NULL &&
434 handler == cur->h_function_pointer &&
435 EventType == cur->eventtype) {
436 CtdlLogPrintf(CTDL_INFO, "Unregistered message function (type %d)\n",
439 if (cur == MessageHookTable) {
440 MessageHookTable = p;
448 void CtdlDestroyMessageHook(void)
450 struct MessageFunctionHook *cur, *p;
452 cur = MessageHookTable;
455 CtdlLogPrintf(CTDL_INFO, "Destroyed message function (type %d)\n", cur->eventtype);
460 MessageHookTable = NULL;
464 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
466 struct RoomFunctionHook *newfcn;
468 newfcn = (struct RoomFunctionHook *)
469 malloc(sizeof(struct RoomFunctionHook));
470 newfcn->next = RoomHookTable;
471 newfcn->fcn_ptr = fcn_ptr;
472 RoomHookTable = newfcn;
474 CtdlLogPrintf(CTDL_INFO, "Registered a new room function\n");
478 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
480 struct RoomFunctionHook *cur, *p;
482 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
483 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
484 CtdlLogPrintf(CTDL_INFO, "Unregistered room function\n");
486 if (cur == RoomHookTable) {
496 void CtdlDestroyRoomHooks(void)
498 struct RoomFunctionHook *cur, *p;
503 CtdlLogPrintf(CTDL_INFO, "Destroyed room function\n");
508 RoomHookTable = NULL;
511 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
513 struct NetprocFunctionHook *newfcn;
515 newfcn = (struct NetprocFunctionHook *)
516 malloc(sizeof(struct NetprocFunctionHook));
517 newfcn->next = NetprocHookTable;
518 newfcn->h_function_pointer = handler;
519 NetprocHookTable = newfcn;
521 CtdlLogPrintf(CTDL_INFO, "Registered a new netproc function\n");
525 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
527 struct NetprocFunctionHook *cur, *p;
529 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
530 /* This will also remove duplicates if any */
531 while (cur != NULL &&
532 handler == cur->h_function_pointer ) {
533 CtdlLogPrintf(CTDL_INFO, "Unregistered netproc function\n");
535 if (cur == NetprocHookTable) {
536 NetprocHookTable = p;
544 void CtdlDestroyNetprocHooks(void)
546 struct NetprocFunctionHook *cur, *p;
548 cur = NetprocHookTable;
551 CtdlLogPrintf(CTDL_INFO, "Destroyed netproc function\n");
556 NetprocHookTable = NULL;
560 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
562 struct DeleteFunctionHook *newfcn;
564 newfcn = (struct DeleteFunctionHook *)
565 malloc(sizeof(struct DeleteFunctionHook));
566 newfcn->next = DeleteHookTable;
567 newfcn->h_function_pointer = handler;
568 DeleteHookTable = newfcn;
570 CtdlLogPrintf(CTDL_INFO, "Registered a new delete function\n");
574 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
576 struct DeleteFunctionHook *cur, *p;
578 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
579 /* This will also remove duplicates if any */
580 while (cur != NULL &&
581 handler == cur->h_function_pointer ) {
582 CtdlLogPrintf(CTDL_INFO, "Unregistered delete function\n");
584 if (cur == DeleteHookTable) {
592 void CtdlDestroyDeleteHooks(void)
594 struct DeleteFunctionHook *cur, *p;
596 cur = DeleteHookTable;
599 CtdlLogPrintf(CTDL_INFO, "Destroyed delete function\n");
604 DeleteHookTable = NULL;
610 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
612 struct FixedOutputHook *newfcn;
614 newfcn = (struct FixedOutputHook *)
615 malloc(sizeof(struct FixedOutputHook));
616 newfcn->next = FixedOutputTable;
617 newfcn->h_function_pointer = handler;
618 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
619 FixedOutputTable = newfcn;
621 CtdlLogPrintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
625 void CtdlUnregisterFixedOutputHook(char *content_type)
627 struct FixedOutputHook *cur, *p;
629 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
630 /* This will also remove duplicates if any */
631 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
632 CtdlLogPrintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
634 if (cur == FixedOutputTable) {
635 FixedOutputTable = p;
643 void CtdlDestroyFixedOutputHooks(void)
645 struct FixedOutputHook *cur, *p;
647 cur = FixedOutputTable;
650 CtdlLogPrintf(CTDL_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
656 FixedOutputTable = NULL;
659 /* returns nonzero if we found a hook and used it */
660 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
662 struct FixedOutputHook *fcn;
664 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
665 if (!strcasecmp(content_type, fcn->content_type)) {
666 (*fcn->h_function_pointer) (content, content_length);
677 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
680 struct XmsgFunctionHook *newfcn;
682 newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook));
683 newfcn->next = XmsgHookTable;
684 newfcn->order = order;
685 newfcn->h_function_pointer = fcn_ptr;
686 XmsgHookTable = newfcn;
687 CtdlLogPrintf(CTDL_INFO, "Registered a new x-msg function (priority %d)\n", order);
691 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
693 struct XmsgFunctionHook *cur, *p;
695 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
696 /* This will also remove duplicates if any */
697 while (cur != NULL &&
698 fcn_ptr == cur->h_function_pointer &&
699 order == cur->order) {
700 CtdlLogPrintf(CTDL_INFO, "Unregistered x-msg function "
701 "(priority %d)\n", order);
703 if (cur == XmsgHookTable) {
712 void CtdlDestroyXmsgHooks(void)
714 struct XmsgFunctionHook *cur, *p;
719 CtdlLogPrintf(CTDL_INFO, "Destroyed x-msg function "
720 "(priority %d)\n", cur->order);
726 XmsgHookTable = NULL;
730 void CtdlRegisterServiceHook(int tcp_port,
732 void (*h_greeting_function) (void),
733 void (*h_command_function) (void),
734 void (*h_async_function) (void),
735 const char *ServiceName)
737 struct ServiceFunctionHook *newfcn;
742 newfcn = (struct ServiceFunctionHook *)
743 malloc(sizeof(struct ServiceFunctionHook));
744 message = (char*) malloc (SIZ);
746 newfcn->next = ServiceHookTable;
747 newfcn->tcp_port = tcp_port;
748 newfcn->sockpath = sockpath;
749 newfcn->h_greeting_function = h_greeting_function;
750 newfcn->h_command_function = h_command_function;
751 newfcn->h_async_function = h_async_function;
752 newfcn->ServiceName = ServiceName;
754 if (sockpath != NULL) {
755 newfcn->msock = ig_uds_server(sockpath, config.c_maxsessions, &error);
756 snprintf(message, SIZ, "Unix domain socket '%s': ", sockpath);
758 else if (tcp_port <= 0) { /* port -1 to disable */
759 CtdlLogPrintf(CTDL_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
765 newfcn->msock = ig_tcp_server(config.c_ip_addr,
767 config.c_maxsessions,
769 snprintf(message, SIZ, "TCP port %s:%d: (%s) ",
770 config.c_ip_addr, tcp_port, ServiceName);
773 if (newfcn->msock > 0) {
774 ServiceHookTable = newfcn;
775 strcat(message, "registered.");
776 CtdlLogPrintf(CTDL_INFO, "%s\n", message);
779 AddPortError(message, error);
780 strcat(message, "FAILED.");
781 CtdlLogPrintf(CTDL_CRIT, "%s\n", message);
789 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
790 void (*h_greeting_function) (void),
791 void (*h_command_function) (void),
792 void (*h_async_function) (void)
795 struct ServiceFunctionHook *cur, *p;
797 for (cur = ServiceHookTable; cur != NULL; cur = cur->next) {
798 /* This will also remove duplicates if any */
799 while (cur != NULL &&
800 !(sockpath && cur->sockpath &&
801 strcmp(sockpath, cur->sockpath)) &&
802 h_greeting_function == cur->h_greeting_function &&
803 h_command_function == cur->h_command_function &&
804 h_async_function == cur->h_async_function &&
805 tcp_port == cur->tcp_port) {
808 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
810 } else if (tcp_port) {
811 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", tcp_port);
813 CtdlLogPrintf(CTDL_INFO, "Unregistered service \"%s\"\n", cur->ServiceName);
816 if (cur == ServiceHookTable) {
817 ServiceHookTable = p;
825 void CtdlDestroyServiceHook(void)
827 struct ServiceFunctionHook *cur, *p;
829 cur = ServiceHookTable;
834 CtdlLogPrintf(CTDL_INFO, "Closed UNIX domain socket %s\n",
836 } else if (cur->tcp_port) {
837 CtdlLogPrintf(CTDL_INFO, "Closed TCP port %d\n", cur->tcp_port);
839 CtdlLogPrintf(CTDL_INFO, "Destroyed service \"%s\"\n", cur->ServiceName);
845 ServiceHookTable = NULL;
848 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
850 struct SearchFunctionHook *newfcn;
852 if (!name || !fcn_ptr) {
856 newfcn = (struct SearchFunctionHook *)
857 malloc(sizeof(struct SearchFunctionHook));
858 newfcn->next = SearchFunctionHookTable;
860 newfcn->fcn_ptr = fcn_ptr;
861 SearchFunctionHookTable = newfcn;
863 CtdlLogPrintf(CTDL_INFO, "Registered a new search function (%s)\n", name);
866 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name)
868 struct SearchFunctionHook *cur, *p;
870 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
871 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
872 CtdlLogPrintf(CTDL_INFO, "Unregistered search function(%s)\n", name);
874 if (cur == SearchFunctionHookTable) {
875 SearchFunctionHookTable = p;
883 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name)
885 struct SearchFunctionHook *fcn = NULL;
887 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
888 if (!func_name || !strcmp(func_name, fcn->name)) {
889 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
897 void PerformSessionHooks(int EventType)
899 struct SessionFunctionHook *fcn = NULL;
901 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
902 if (fcn->eventtype == EventType) {
903 (*fcn->h_function_pointer) ();
908 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
910 struct UserFunctionHook *fcn = NULL;
912 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
913 if (fcn->eventtype == EventType) {
914 (*fcn->h_function_pointer) (usbuf);
919 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
921 struct MessageFunctionHook *fcn = NULL;
922 int total_retval = 0;
924 /* Other code may elect to protect this message from server-side
925 * handlers; if this is the case, don't do anything.
926 CtdlLogPrintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n",
927 EventType, msg->cm_flags);
929 if (msg->cm_flags & CM_SKIP_HOOKS) {
930 CtdlLogPrintf(CTDL_DEBUG, "Skipping hooks\n");
934 /* Otherwise, run all the hooks appropriate to this event type.
936 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
937 if (fcn->eventtype == EventType) {
938 total_retval = total_retval +
939 (*fcn->h_function_pointer) (msg);
943 /* Return the sum of the return codes from the hook functions. If
944 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
945 * the save operation to abort.
951 int PerformRoomHooks(struct ctdlroom *target_room)
953 struct RoomFunctionHook *fcn;
954 int total_retval = 0;
956 CtdlLogPrintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
958 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
959 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
962 /* Return the sum of the return codes from the hook functions.
968 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
970 struct NetprocFunctionHook *fcn;
971 int total_retval = 0;
973 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
974 total_retval = total_retval +
975 (*fcn->h_function_pointer) (msg, target_room);
978 /* Return the sum of the return codes from the hook functions.
979 * A nonzero return code will cause the message to *not* be imported.
985 void PerformDeleteHooks(char *room, long msgnum)
987 struct DeleteFunctionHook *fcn;
989 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
990 (*fcn->h_function_pointer) (room, msgnum);
998 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1000 struct XmsgFunctionHook *fcn;
1004 for (p=0; p<MAX_XMSG_PRI; ++p) {
1005 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1006 if (fcn->order == p) {
1008 (*fcn->h_function_pointer)
1009 (sender, sender_email, recp, msg);
1012 /* Break out of the loop if a higher-priority function
1013 * successfully delivered the message. This prevents duplicate
1014 * deliveries to local users simultaneously signed onto
1017 if (total_sent) break;
1025 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module)
1027 struct DirectoryServiceHook *newfcn;
1029 newfcn = DirectoryServiceHookList;
1032 if (newfcn->cmd == cmd && !strcmp(newfcn->module, module))
1034 CtdlLogPrintf(CTDL_ERR, "Directory service function already handled by module %s\n", module);
1037 newfcn = newfcn->next;
1040 newfcn = (struct DirectoryServiceHook *) malloc (sizeof(struct DirectoryServiceHook));
1041 newfcn->handler = func;
1043 newfcn->module = module;
1044 newfcn->next = DirectoryServiceHookList;
1045 DirectoryServiceHookList = newfcn;
1047 CtdlLogPrintf(CTDL_INFO, "Registered a new directory service function from module %s\n", module);
1051 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd)
1053 struct DirectoryServiceHook *curfcn;
1054 struct DirectoryObject *our_object_list = NULL;
1055 struct DirectoryObject *newobject = NULL;
1056 struct DirectoryObject *oldobject = NULL;
1059 curfcn = DirectoryServiceHookList;
1061 our_object_list = (struct DirectoryObject *) *object;
1065 if (curfcn->cmd == cmd)
1069 if (cmd == DIRECTORY_CREATE_OBJECT)
1071 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1072 newobject->module = curfcn->module;
1073 newobject->object = NULL;
1074 newobject->next = our_object_list;
1075 our_object_list = newobject;
1077 if (our_object_list)
1079 for(newobject = our_object_list; newobject; newobject=newobject->next)
1081 if (!strcmp(newobject->module, curfcn->module))
1082 (void) curfcn->handler(cn, ou, &newobject->object);
1086 (void) curfcn->handler(cn, ou, NULL);
1092 if(!strcmp(curfcn->module, module))
1094 if (cmd == DIRECTORY_CREATE_OBJECT)
1096 newobject = (struct DirectoryObject*) malloc (sizeof(struct DirectoryObject));
1097 newobject->module = module;
1098 newobject->object = NULL;
1099 newobject->next = our_object_list;
1100 our_object_list = newobject;
1102 if (our_object_list)
1104 for(newobject = our_object_list; newobject; newobject=newobject->next)
1106 if (!strcmp(newobject->module, curfcn->module))
1107 (void) curfcn->handler(cn, ou, &newobject->object);
1111 (void) (curfcn->handler(cn, ou, NULL));
1117 curfcn=curfcn->next;
1119 if (our_object_list)
1121 *object = our_object_list;
1122 if (cmd == DIRECTORY_FREE_OBJECT)
1123 { // The objects pointed to by the list should have been freed by the module that created it
1124 for(newobject = our_object_list; newobject; )
1126 oldobject=newobject;
1127 newobject=newobject->next;
1136 void CtdlDestroyDirectoryServiceFuncs(void)
1138 struct DirectoryServiceHook *cur, *next;
1140 cur = DirectoryServiceHookList;
1141 DirectoryServiceHookList = NULL;
1145 CtdlLogPrintf(CTDL_INFO, "Destroyed directory service function for module %s.\n", cur->module);
1152 * Dirty hack until we impliment a hook mechanism for this
1154 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1157 CtdlStartTLS (ok_response, nosup_response, error_response);