2 * Citadel Dynamic Loading Module
3 * Written by Brian Costello <btx@calyx.net>
5 * Copyright (c) 1987-2011 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
32 #include <libcitadel.h>
35 #include "serv_extensions.h"
36 #include "sysdep_decls.h"
40 #include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */
42 #include "ctdl_module.h"
49 struct CleanupFunctionHook *CleanupHookTable = NULL;
50 struct SessionFunctionHook *SessionHookTable = NULL;
51 struct UserFunctionHook *UserHookTable = NULL;
52 struct XmsgFunctionHook *XmsgHookTable = NULL;
53 struct MessageFunctionHook *MessageHookTable = NULL;
54 struct NetprocFunctionHook *NetprocHookTable = NULL;
55 struct DeleteFunctionHook *DeleteHookTable = NULL;
56 struct ServiceFunctionHook *ServiceHookTable = NULL;
57 struct FixedOutputHook *FixedOutputTable = NULL;
58 struct RoomFunctionHook *RoomHookTable = NULL;
59 struct SearchFunctionHook *SearchFunctionHookTable = NULL;
61 struct ProtoFunctionHook {
62 void (*handler) (char *cmdbuf);
67 HashList *ProtoHookList = NULL;
70 #define ERR_PORT (1 << 1)
73 static char *portlist = NULL;
74 static size_t nSizPort = 0;
76 static char *errormessages = NULL;
77 size_t nSizErrmsg = 0;
80 long DetailErrorFlags;
82 char *ErrSubject = "Startup Problems";
83 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"
84 "If you don't want citadel to provide these services, turn them off in WebCit via %s%s\n\n%s\n\n"
85 "To make both ways actualy take place restart the citserver with \"sendcommand down\"\n\n"
86 "The errors returned by the system were:\n%s\n"
87 "You can recheck the above if you follow this faq item:\n"
88 "http://www.citadel.org/doku.php/faq:mastering_your_os:net#netstat";
91 char *ErrPortShort = "We couldn't bind all ports you configured to be provided by citadel server.";
92 char *ErrPortWhere = "Admin->System Preferences->Network.\n\nThe failed ports and sockets are: ";
93 char *ErrPortHint = "If you want citadel to provide you with that functionality, "
94 "check the output of \"netstat -lnp\" on linux Servers or \"netstat -na\" on *BSD"
95 " and stop the programm, that binds these ports.\n You should eventually remove "
96 " their initscripts in /etc/init.d so that you won't get this trouble once more.\n"
97 " After that goto Administration -> Shutdown Citadel to make Citadel retry to bind this port.\n";
100 void LogPrintMessages(long err)
102 char *List, *DetailList, *Short, *Where, *Hint, *Message;
103 int n = nSizPort + nSizErrmsg + 5;
105 Message = (char*) malloc(n * SIZ);
107 DetailErrorFlags = DetailErrorFlags & ~err;
112 Short = ErrPortShort;
113 Where = ErrPortWhere;
116 DetailList = errormessages;
127 snprintf(Message, n * SIZ, ErrGeneral, Short, Where, List, Hint, DetailList);
129 syslog(LOG_EMERG, "%s", Message);
130 syslog(LOG_EMERG, "%s", ErrSubject);
131 quickie_message("Citadel", NULL, NULL, AIDEROOM, Message, FMT_FIXED, ErrSubject);
132 if (errormessages!=NULL) free (errormessages);
133 errormessages = NULL;
134 if (portlist!=NULL) free (portlist);
141 void AppendString(char **target, char *append, size_t *len, size_t rate)
147 AddLen = strlen(append);
153 *target = (char*)malloc (*len * SIZ);
157 oLen = strlen(*target);
158 RelPtr = strlen(*target);
159 if (oLen + AddLen + 2 > *len * SIZ)
161 char *Buff = *target;
162 size_t NewSiz = *len + 10;
163 *target = malloc (NewSiz * SIZ);
164 memcpy (*target, Buff, NewSiz * SIZ);
168 memcpy (*target + oLen, append, AddLen);
169 (*target)[oLen + AddLen + 1] = '\n';
170 (*target)[oLen + AddLen + 2] = '\0';
173 void AddPortError(char *Port, char *ErrorMessage)
178 DetailErrorFlags |= ERR_PORT;
180 AppendString(&errormessages, ErrorMessage, &nSizErrmsg, 10);
181 AppendString(&portlist, Port, &nSizPort, 2);
183 pos = strchr (portlist, ':');
184 if (pos != NULL) *pos = ';';
186 len = strlen (errormessages);
187 if (nSizErrmsg * SIZ > len + 3)
189 errormessages[len] = ';';
190 errormessages[len+1] = ' ';
191 errormessages[len+2] = '\0';
196 int DLoader_Exec_Cmd(char *cmdbuf)
199 struct ProtoFunctionHook *p;
201 if (GetHash(ProtoHookList, cmdbuf, 4, &vP) && (vP != NULL)) {
202 p = (struct ProtoFunctionHook*) vP;
203 p->handler(&cmdbuf[5]);
209 long FourHash(const char *key, long length)
213 const unsigned char *ptr = (const unsigned char*)key;
215 for (i = 0; i < 4; i++, ptr ++)
225 void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
227 struct ProtoFunctionHook *p;
229 if (ProtoHookList == NULL)
230 ProtoHookList = NewHash (1, FourHash);
233 p = (struct ProtoFunctionHook *)
234 malloc(sizeof(struct ProtoFunctionHook));
237 fprintf(stderr, "can't malloc new ProtoFunctionHook\n");
240 p->handler = handler;
244 Put(ProtoHookList, cmd, 4, p, NULL);
245 syslog(LOG_INFO, "Registered server command %s (%s)\n", cmd, desc);
248 void CtdlDestroyProtoHooks(void)
251 DeleteHash(&ProtoHookList);
255 void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
258 struct CleanupFunctionHook *newfcn;
260 newfcn = (struct CleanupFunctionHook *)
261 malloc(sizeof(struct CleanupFunctionHook));
262 newfcn->next = CleanupHookTable;
263 newfcn->h_function_pointer = fcn_ptr;
264 CleanupHookTable = newfcn;
266 syslog(LOG_INFO, "Registered a new cleanup function\n");
270 void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void))
272 struct CleanupFunctionHook *cur, *p;
274 for (cur = CleanupHookTable; cur != NULL; cur = cur->next) {
275 /* This will also remove duplicates if any */
276 while (cur != NULL &&
277 fcn_ptr == cur->h_function_pointer) {
278 syslog(LOG_INFO, "Unregistered cleanup function\n");
280 if (cur == CleanupHookTable) {
281 CleanupHookTable = p;
289 void CtdlDestroyCleanupHooks(void)
291 struct CleanupFunctionHook *cur, *p;
293 cur = CleanupHookTable;
296 syslog(LOG_INFO, "Destroyed cleanup function\n");
301 CleanupHookTable = NULL;
305 void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType)
308 struct SessionFunctionHook *newfcn;
310 newfcn = (struct SessionFunctionHook *)
311 malloc(sizeof(struct SessionFunctionHook));
312 newfcn->next = SessionHookTable;
313 newfcn->h_function_pointer = fcn_ptr;
314 newfcn->eventtype = EventType;
315 SessionHookTable = newfcn;
317 syslog(LOG_INFO, "Registered a new session function (type %d)\n",
322 void CtdlUnregisterSessionHook(void (*fcn_ptr) (void), int EventType)
324 struct SessionFunctionHook *cur, *p;
326 for (cur = SessionHookTable; cur != NULL; cur = cur->next) {
327 /* This will also remove duplicates if any */
328 while (cur != NULL &&
329 fcn_ptr == cur->h_function_pointer &&
330 EventType == cur->eventtype) {
331 syslog(LOG_INFO, "Unregistered session function (type %d)\n",
334 if (cur == SessionHookTable) {
335 SessionHookTable = p;
343 void CtdlDestroySessionHooks(void)
345 struct SessionFunctionHook *cur, *p;
347 cur = SessionHookTable;
350 syslog(LOG_INFO, "Destroyed session function\n");
355 SessionHookTable = NULL;
359 void CtdlRegisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
362 struct UserFunctionHook *newfcn;
364 newfcn = (struct UserFunctionHook *)
365 malloc(sizeof(struct UserFunctionHook));
366 newfcn->next = UserHookTable;
367 newfcn->h_function_pointer = fcn_ptr;
368 newfcn->eventtype = EventType;
369 UserHookTable = newfcn;
371 syslog(LOG_INFO, "Registered a new user function (type %d)\n",
376 void CtdlUnregisterUserHook(void (*fcn_ptr) (struct ctdluser *), int EventType)
378 struct UserFunctionHook *cur, *p;
380 for (cur = UserHookTable; cur != NULL; cur = cur->next) {
381 /* This will also remove duplicates if any */
382 while (cur != NULL &&
383 fcn_ptr == cur->h_function_pointer &&
384 EventType == cur->eventtype) {
385 syslog(LOG_INFO, "Unregistered user function (type %d)\n",
388 if (cur == UserHookTable) {
397 void CtdlDestroyUserHooks(void)
399 struct UserFunctionHook *cur, *p;
404 syslog(LOG_INFO, "Destroyed user function \n");
409 UserHookTable = NULL;
413 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
417 struct MessageFunctionHook *newfcn;
419 newfcn = (struct MessageFunctionHook *)
420 malloc(sizeof(struct MessageFunctionHook));
421 newfcn->next = MessageHookTable;
422 newfcn->h_function_pointer = handler;
423 newfcn->eventtype = EventType;
424 MessageHookTable = newfcn;
426 syslog(LOG_INFO, "Registered a new message function (type %d)\n",
431 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
434 struct MessageFunctionHook *cur, *p;
436 for (cur = MessageHookTable; cur != NULL; cur = cur->next) {
437 /* This will also remove duplicates if any */
438 while (cur != NULL &&
439 handler == cur->h_function_pointer &&
440 EventType == cur->eventtype) {
441 syslog(LOG_INFO, "Unregistered message function (type %d)\n",
444 if (cur == MessageHookTable) {
445 MessageHookTable = p;
453 void CtdlDestroyMessageHook(void)
455 struct MessageFunctionHook *cur, *p;
457 cur = MessageHookTable;
460 syslog(LOG_INFO, "Destroyed message function (type %d)\n", cur->eventtype);
465 MessageHookTable = NULL;
469 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
471 struct RoomFunctionHook *newfcn;
473 newfcn = (struct RoomFunctionHook *)
474 malloc(sizeof(struct RoomFunctionHook));
475 newfcn->next = RoomHookTable;
476 newfcn->fcn_ptr = fcn_ptr;
477 RoomHookTable = newfcn;
479 syslog(LOG_INFO, "Registered a new room function\n");
483 void CtdlUnregisterRoomHook(int (*fcn_ptr)(struct ctdlroom *))
485 struct RoomFunctionHook *cur, *p;
487 for (cur = RoomHookTable; cur != NULL; cur = cur->next) {
488 while (cur != NULL && fcn_ptr == cur->fcn_ptr) {
489 syslog(LOG_INFO, "Unregistered room function\n");
491 if (cur == RoomHookTable) {
501 void CtdlDestroyRoomHooks(void)
503 struct RoomFunctionHook *cur, *p;
508 syslog(LOG_INFO, "Destroyed room function\n");
513 RoomHookTable = NULL;
516 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
518 struct NetprocFunctionHook *newfcn;
520 newfcn = (struct NetprocFunctionHook *)
521 malloc(sizeof(struct NetprocFunctionHook));
522 newfcn->next = NetprocHookTable;
523 newfcn->h_function_pointer = handler;
524 NetprocHookTable = newfcn;
526 syslog(LOG_INFO, "Registered a new netproc function\n");
530 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) )
532 struct NetprocFunctionHook *cur, *p;
534 for (cur = NetprocHookTable; cur != NULL; cur = cur->next) {
535 /* This will also remove duplicates if any */
536 while (cur != NULL &&
537 handler == cur->h_function_pointer ) {
538 syslog(LOG_INFO, "Unregistered netproc function\n");
540 if (cur == NetprocHookTable) {
541 NetprocHookTable = p;
549 void CtdlDestroyNetprocHooks(void)
551 struct NetprocFunctionHook *cur, *p;
553 cur = NetprocHookTable;
556 syslog(LOG_INFO, "Destroyed netproc function\n");
561 NetprocHookTable = NULL;
565 void CtdlRegisterDeleteHook(void (*handler)(char *, long) )
567 struct DeleteFunctionHook *newfcn;
569 newfcn = (struct DeleteFunctionHook *)
570 malloc(sizeof(struct DeleteFunctionHook));
571 newfcn->next = DeleteHookTable;
572 newfcn->h_function_pointer = handler;
573 DeleteHookTable = newfcn;
575 syslog(LOG_INFO, "Registered a new delete function\n");
579 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
581 struct DeleteFunctionHook *cur, *p;
583 for (cur = DeleteHookTable; cur != NULL; cur = cur->next) {
584 /* This will also remove duplicates if any */
585 while (cur != NULL &&
586 handler == cur->h_function_pointer ) {
587 syslog(LOG_INFO, "Unregistered delete function\n");
589 if (cur == DeleteHookTable) {
597 void CtdlDestroyDeleteHooks(void)
599 struct DeleteFunctionHook *cur, *p;
601 cur = DeleteHookTable;
604 syslog(LOG_INFO, "Destroyed delete function\n");
609 DeleteHookTable = NULL;
615 void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
617 struct FixedOutputHook *newfcn;
619 newfcn = (struct FixedOutputHook *)
620 malloc(sizeof(struct FixedOutputHook));
621 newfcn->next = FixedOutputTable;
622 newfcn->h_function_pointer = handler;
623 safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
624 FixedOutputTable = newfcn;
626 syslog(LOG_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
630 void CtdlUnregisterFixedOutputHook(char *content_type)
632 struct FixedOutputHook *cur, *p;
634 for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
635 /* This will also remove duplicates if any */
636 while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
637 syslog(LOG_INFO, "Unregistered fixed output function for %s\n", content_type);
639 if (cur == FixedOutputTable) {
640 FixedOutputTable = p;
648 void CtdlDestroyFixedOutputHooks(void)
650 struct FixedOutputHook *cur, *p;
652 cur = FixedOutputTable;
655 syslog(LOG_INFO, "Destroyed fixed output function for %s\n", cur->content_type);
661 FixedOutputTable = NULL;
664 /* returns nonzero if we found a hook and used it */
665 int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
667 struct FixedOutputHook *fcn;
669 for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
670 if (!strcasecmp(content_type, fcn->content_type)) {
671 (*fcn->h_function_pointer) (content, content_length);
682 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
685 struct XmsgFunctionHook *newfcn;
687 newfcn = (struct XmsgFunctionHook *) malloc(sizeof(struct XmsgFunctionHook));
688 newfcn->next = XmsgHookTable;
689 newfcn->order = order;
690 newfcn->h_function_pointer = fcn_ptr;
691 XmsgHookTable = newfcn;
692 syslog(LOG_INFO, "Registered a new x-msg function (priority %d)\n", order);
696 void CtdlUnregisterXmsgHook(int (*fcn_ptr) (char *, char *, char *, char *), int order)
698 struct XmsgFunctionHook *cur, *p;
700 for (cur = XmsgHookTable; cur != NULL; cur = cur->next) {
701 /* This will also remove duplicates if any */
702 while (cur != NULL &&
703 fcn_ptr == cur->h_function_pointer &&
704 order == cur->order) {
705 syslog(LOG_INFO, "Unregistered x-msg function "
706 "(priority %d)\n", order);
708 if (cur == XmsgHookTable) {
717 void CtdlDestroyXmsgHooks(void)
719 struct XmsgFunctionHook *cur, *p;
724 syslog(LOG_INFO, "Destroyed x-msg function "
725 "(priority %d)\n", cur->order);
731 XmsgHookTable = NULL;
735 void CtdlRegisterServiceHook(int tcp_port,
737 void (*h_greeting_function) (void),
738 void (*h_command_function) (void),
739 void (*h_async_function) (void),
740 const char *ServiceName)
742 struct ServiceFunctionHook *newfcn;
747 newfcn = (struct ServiceFunctionHook *) malloc(sizeof(struct ServiceFunctionHook));
748 message = (char*) malloc (SIZ + 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 = ctdl_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 syslog(LOG_INFO, "Service %s has been manually disabled, skipping\n", ServiceName);
769 newfcn->msock = ctdl_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 syslog(LOG_INFO, "%s\n", message);
783 AddPortError(message, error);
784 strcat(message, "FAILED.");
785 syslog(LOG_CRIT, "%s\n", message);
792 void CtdlUnregisterServiceHook(int tcp_port, char *sockpath,
793 void (*h_greeting_function) (void),
794 void (*h_command_function) (void),
795 void (*h_async_function) (void)
798 struct ServiceFunctionHook *cur, *p;
800 cur = ServiceHookTable;
801 while (cur != NULL) {
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 syslog(LOG_INFO, "Closed UNIX domain socket %s\n",
814 } else if (tcp_port) {
815 syslog(LOG_INFO, "Closed TCP port %d\n", tcp_port);
817 syslog(LOG_INFO, "Unregistered service \"%s\"\n", cur->ServiceName);
820 if (cur == ServiceHookTable) {
821 ServiceHookTable = p;
830 void CtdlShutdownServiceHooks(void)
832 /* sort of a duplicate of close_masters() but called earlier */
833 struct ServiceFunctionHook *cur;
835 cur = ServiceHookTable;
838 if (cur->msock != -1)
842 if (cur->sockpath != NULL){
843 syslog(LOG_INFO, "[%s] Closed UNIX domain socket %s\n",
847 syslog(LOG_INFO, "[%s] closing service\n",
855 void CtdlDestroyServiceHook(void)
857 struct ServiceFunctionHook *cur, *p;
859 cur = ServiceHookTable;
864 syslog(LOG_INFO, "Closed UNIX domain socket %s\n",
866 } else if (cur->tcp_port) {
867 syslog(LOG_INFO, "Closed TCP port %d\n", cur->tcp_port);
869 syslog(LOG_INFO, "Destroyed service \"%s\"\n", cur->ServiceName);
875 ServiceHookTable = NULL;
878 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
880 struct SearchFunctionHook *newfcn;
882 if (!name || !fcn_ptr) {
886 newfcn = (struct SearchFunctionHook *)
887 malloc(sizeof(struct SearchFunctionHook));
888 newfcn->next = SearchFunctionHookTable;
890 newfcn->fcn_ptr = fcn_ptr;
891 SearchFunctionHookTable = newfcn;
893 syslog(LOG_INFO, "Registered a new search function (%s)\n", name);
896 void CtdlUnregisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name)
898 struct SearchFunctionHook *cur, *p;
900 for (cur = SearchFunctionHookTable; cur != NULL; cur = cur->next) {
901 while (fcn_ptr && (cur->fcn_ptr == fcn_ptr) && name && !strcmp(name, cur->name)) {
902 syslog(LOG_INFO, "Unregistered search function(%s)\n", name);
904 if (cur == SearchFunctionHookTable) {
905 SearchFunctionHookTable = p;
913 void CtdlDestroySearchHooks(void)
915 struct SearchFunctionHook *cur, *p;
917 cur = SearchFunctionHookTable;
918 SearchFunctionHookTable = NULL;
919 while (cur != NULL) {
926 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name)
928 struct SearchFunctionHook *fcn = NULL;
930 for (fcn = SearchFunctionHookTable; fcn != NULL; fcn = fcn->next) {
931 if (!func_name || !strcmp(func_name, fcn->name)) {
932 (*fcn->fcn_ptr) (num_msgs, search_msgs, search_string);
940 void PerformSessionHooks(int EventType)
942 struct SessionFunctionHook *fcn = NULL;
944 for (fcn = SessionHookTable; fcn != NULL; fcn = fcn->next) {
945 if (fcn->eventtype == EventType) {
946 if (EventType == EVT_TIMER) {
947 pthread_setspecific(MyConKey, NULL); /* for every hook */
949 (*fcn->h_function_pointer) ();
954 void PerformUserHooks(struct ctdluser *usbuf, int EventType)
956 struct UserFunctionHook *fcn = NULL;
958 for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) {
959 if (fcn->eventtype == EventType) {
960 (*fcn->h_function_pointer) (usbuf);
965 int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
967 struct MessageFunctionHook *fcn = NULL;
968 int total_retval = 0;
970 /* Other code may elect to protect this message from server-side
971 * handlers; if this is the case, don't do anything.
972 syslog(LOG_DEBUG, "** Event type is %d, flags are %d\n", EventType, msg->cm_flags);
974 if (msg->cm_flags & CM_SKIP_HOOKS) {
975 syslog(LOG_DEBUG, "Skipping hooks\n");
979 /* Otherwise, run all the hooks appropriate to this event type.
981 int num_hooks_processed = 0;
982 for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
983 if (fcn->eventtype == EventType) {
984 total_retval = total_retval + (*fcn->h_function_pointer) (msg);
985 syslog(LOG_DEBUG, "%d hooks completed, total_retval=%d",
986 ++num_hooks_processed, total_retval
991 /* Return the sum of the return codes from the hook functions. If
992 * this is an EVT_BEFORESAVE event, a nonzero return code will cause
993 * the save operation to abort.
999 int PerformRoomHooks(struct ctdlroom *target_room)
1001 struct RoomFunctionHook *fcn;
1002 int total_retval = 0;
1004 syslog(LOG_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname);
1006 for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) {
1007 total_retval = total_retval + (*fcn->fcn_ptr) (target_room);
1010 /* Return the sum of the return codes from the hook functions.
1012 return total_retval;
1016 int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room)
1018 struct NetprocFunctionHook *fcn;
1019 int total_retval = 0;
1021 for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) {
1022 total_retval = total_retval +
1023 (*fcn->h_function_pointer) (msg, target_room);
1026 /* Return the sum of the return codes from the hook functions.
1027 * A nonzero return code will cause the message to *not* be imported.
1029 return total_retval;
1033 void PerformDeleteHooks(char *room, long msgnum)
1035 struct DeleteFunctionHook *fcn;
1037 for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) {
1038 (*fcn->h_function_pointer) (room, msgnum);
1046 int PerformXmsgHooks(char *sender, char *sender_email, char *recp, char *msg)
1048 struct XmsgFunctionHook *fcn;
1052 for (p=0; p<MAX_XMSG_PRI; ++p) {
1053 for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
1054 if (fcn->order == p) {
1056 (*fcn->h_function_pointer)
1057 (sender, sender_email, recp, msg);
1060 /* Break out of the loop if a higher-priority function
1061 * successfully delivered the message. This prevents duplicate
1062 * deliveries to local users simultaneously signed onto
1065 if (total_sent) break;
1072 * Dirty hack until we impliment a hook mechanism for this
1074 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
1077 CtdlStartTLS (ok_response, nosup_response, error_response);