]> code.citadel.org Git - citadel.git/commitdiff
* Finished off the message architecture stuff with a new class of hooks to
authorArt Cancro <ajc@citadel.org>
Sun, 19 Sep 1999 21:28:33 +0000 (21:28 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 19 Sep 1999 21:28:33 +0000 (21:28 +0000)
  enable future server-side handlers.

citadel/ChangeLog
citadel/citserver.c
citadel/dynloader.c
citadel/dynloader.h
citadel/msgbase.c
citadel/serv_chat.c
citadel/server.h

index 9548e46902928da5dd47624683565ec128cb5a87..de6e5b56a864fc622abb79a273aec8449f9fe57d 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.368  1999/09/19 21:28:33  ajc
+* Finished off the message architecture stuff with a new class of hooks to
+  enable future server-side handlers.
+
 Revision 1.367  1999/09/19 15:57:06  ajc
 * migrated cmd_ent3() to CtdlSaveMessage()
 
@@ -1256,3 +1260,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 71b05c36051c18b6424da0aa35a81c0d9c6b1ca4..b60557af76333b34ea0dc314ebb7ca84d1227d81 100644 (file)
@@ -28,8 +28,8 @@
 #include "housekeeping.h"
 #include "user_ops.h"
 #include "logging.h"
-#include "support.h"
 #include "msgbase.h"
+#include "support.h"
 #include "locate_host.h"
 #include "room_ops.h"
 #include "file_ops.h"
index bcf4aabc064bf9eeec82878a43d3d145f6f4c48d..f6da4d7b2dad619d57c3065ee05eace4282f1272 100644 (file)
 #endif
 #include <limits.h>
 #include <ctype.h>
-#include "dynloader.h"
 #include "citadel.h"
 #include "server.h"
+#include "dynloader.h"
 #include "sysdep_decls.h"
+#include "msgbase.h"
 #include "tools.h"
 
 #ifndef HAVE_SNPRINTF
@@ -38,6 +39,7 @@ struct CleanupFunctionHook *CleanupHookTable = NULL;
 struct SessionFunctionHook *SessionHookTable = NULL;
 struct UserFunctionHook *UserHookTable = NULL;
 struct XmsgFunctionHook *XmsgHookTable = NULL;
+struct MessageFunctionHook *MessageHookTable = NULL;
 
 struct ProtoFunctionHook {
        void (*handler) (char *cmdbuf);
@@ -194,6 +196,24 @@ void CtdlRegisterUserHook(void (*fcn_ptr) (char *, long), int EventType)
 }
 
 
+void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
+                               int EventType)
+{
+
+       struct MessageFunctionHook *newfcn;
+
+       newfcn = (struct MessageFunctionHook *)
+           mallok(sizeof(struct MessageFunctionHook));
+       newfcn->next = MessageHookTable;
+       newfcn->h_function_pointer = handler;
+       newfcn->eventtype = EventType;
+       MessageHookTable = newfcn;
+
+       lprintf(5, "Registered a new message function (type %d)\n",
+               EventType);
+}
+
+
 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
 {
 
@@ -242,6 +262,21 @@ void PerformUserHooks(char *username, long usernum, int EventType)
        }
 }
 
+int PerformMessageHooks(struct CtdlMessage *msg, int EventType)
+{
+       struct MessageFunctionHook *fcn;
+       int total_retval = 0;
+
+       for (fcn = MessageHookTable; fcn != NULL; fcn = fcn->next) {
+               if (fcn->eventtype == EventType) {
+                       total_retval = total_retval +
+                               (*fcn->h_function_pointer) (msg);
+               }
+       }
+
+       return total_retval;
+}
+
 int PerformXmsgHooks(char *sender, char *recp, char *msg)
 {
        struct XmsgFunctionHook *fcn;
index a3f19dbd2f7136762ec58e6e7333e562c2e9e928..4e9bb3726f9491acf69cfffb80ffebc48f1e02ee 100644 (file)
@@ -11,4 +11,6 @@ int PerformXmsgHooks(char *, char *, char *);
 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
 void CtdlRegisterUserHook(void (*fcn_ptr)(char*, long), int EventType);
 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *), int order);
+void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *), int EventType);
+int PerformMessageHooks(struct CtdlMessage *, int EventType);
 char *Dynamic_Module_Init(void);
index fc08f614bf6f6326508d97104546131ec7f4ce2b..b6255c01b859f450db838976d7880fa85310bf1b 100644 (file)
@@ -561,6 +561,13 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum)
        } while ((field_length > 0) && (field_header != 'M'));
 
        cdb_free(dmsgtext);
+
+       /* Perform "before read" hooks (aborting if any return nonzero) */
+       if (PerformMessageHooks(ret, EVT_BEFOREREAD) > 0) {
+               CtdlFreeMessage(ret);
+               return NULL;
+       }
+
        return (ret);
 }
 
@@ -1172,6 +1179,9 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
                }
        }
 
+       /* Perform "before save" hooks (aborting if any return nonzero) */
+       if (PerformMessageHooks(msg, EVT_BEFORESAVE) > 0) return;
+
        /* Network mail - send a copy to the network program. */
        if ((strlen(recipient) > 0) && (mailtype != MES_LOCAL)) {
                sprintf(aaa, "./network/spoolin/netmail.%04lx.%04x.%04x",
@@ -1267,6 +1277,9 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
        smi.smi_refcount = successful_local_recipients;
        safestrncpy(smi.smi_content_type, content_type, 64);
        PutSuppMsgInfo(&smi);
+
+       /* Perform "after save" hooks */
+       PerformMessageHooks(msg, EVT_AFTERSAVE);
 }
 
 
index 49d5ffa6cd5d21b9a54ab766f9d9842b0c166b2c..ad79093c3f1febc2ba0b4961368be45e1c489fb8 100644 (file)
@@ -42,6 +42,8 @@ int ChatLastMsg = 0;
 
 extern struct CitContext *ContextList;
 
+
+
 char *Dynamic_Module_Init(void)
 {
        CtdlRegisterProtoHook(cmd_chat, "CHAT", "Begin real-time chat");
index 02d650786882b7255ff253d4b6c5ed8107b62ffa..a538b3611b3162865d5fd453aff6b2b18079259e 100644 (file)
@@ -6,6 +6,7 @@ typedef pthread_t THREAD;
  */
 #define DEBUG_MEMORY_LEAKS
 
+struct CtdlMessage;
 
 /*
  * Generic per-session variable or data structure storage
@@ -246,6 +247,20 @@ extern struct UserFunctionHook *UserHookTable;
 #define EVT_OUTPUTMSG  101     /* Outputting a message */
 
 
+/*
+ * MessageFunctionHook extensions are used for hooks which implement handlers
+ * for various types of message operations (save, read, etc.)
+ */
+struct MessageFunctionHook {
+       struct MessageFunctionHook *next;
+       int (*h_function_pointer) (struct CtdlMessage *msg);
+       int eventtype;
+};
+extern struct MessageFunctionHook *MessageHookTable;
+
+#define EVT_BEFOREREAD 200
+#define EVT_BEFORESAVE 201
+#define EVT_AFTERSAVE  202
 
 
 /*