]> code.citadel.org Git - citadel.git/blobdiff - citadel/dynloader.c
ICQ changes
[citadel.git] / citadel / dynloader.c
index 1f6dab1cd164c956ab981a0492d1775ad5346872..2fe4a9e52d47c8cd3d5dd1c303b1359a6f6d5851 100644 (file)
 #include <pthread.h>
 #endif
 #include <limits.h>
+#include <ctype.h>
 #include "dynloader.h"
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
+#include "tools.h"
 
 #ifndef HAVE_SNPRINTF
 #include <stdarg.h>
@@ -35,6 +37,7 @@ struct LogFunctionHook *LogHookTable = NULL;
 struct CleanupFunctionHook *CleanupHookTable = NULL;
 struct SessionFunctionHook *SessionHookTable = NULL;
 struct UserFunctionHook *UserHookTable = NULL;
+struct XmsgFunctionHook *XmsgHookTable = NULL;
 
 struct ProtoFunctionHook {
        void (*handler) (char *cmdbuf);
@@ -56,6 +59,7 @@ void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc)
        p->desc = desc;
        p->next = ProtoHookList;
        ProtoHookList = p;
+       lprintf(5, "Registered server command %s (%s)\n", cmd, desc);
 }
 
 int DLoader_Exec_Cmd(char *cmdbuf)
@@ -74,11 +78,12 @@ int DLoader_Exec_Cmd(char *cmdbuf)
 void DLoader_Init(char *pathname)
 {
        void *fcn_handle;
-       const char *dl_error;
+       char dl_error[256];
        DIR *dir;
+       int i;
        struct dirent *dptr;
-       struct DLModule_Info *(*h_init_fcn) (void);
-       struct DLModule_Info *dl_info;
+       char *(*h_init_fcn) (void);
+       char *dl_info;
 
        char pathbuf[PATH_MAX];
 
@@ -97,27 +102,29 @@ void DLoader_Init(char *pathname)
                if (!(fcn_handle = dlopen(pathbuf, DL_LAZY)))
 #endif
                {
-                       /* dl_error = dlerror(); */
-                       fprintf(stderr, "DLoader_Init dlopen failed\n");
+                       safestrncpy(dl_error, dlerror(), sizeof dl_error);
+                       for (i=0; i<strlen(dl_error); ++i)
+                               if (!isprint(dl_error[i]))
+                                       dl_error[i]='.';
+                       fprintf(stderr, "DLoader_Init dlopen failed: %s\n",
+                               dl_error);
                        continue;
                }
-               h_init_fcn = (struct DLModule_Info * (*)(void))
+               h_init_fcn = (char * (*)(void))
 #ifndef __OpenBSD__
                    dlsym(fcn_handle, "Dynamic_Module_Init");
 #else
                    dlsym(fcn_handle, "_Dynamic_Module_Init");
 #endif
 
-               if ((dl_error = dlerror()) != NULL) {
-                       fprintf(stderr, "DLoader_Init dlsym failed (%s)\n", dl_error);
+               if (dlerror() != NULL) {
+                       fprintf(stderr, "DLoader_Init dlsym failed\n");
                        continue;
                }
                dl_info = h_init_fcn();
 
-               printf("Loaded module: %s v%d.%d\nBy %s (%s)\n", dl_info->module_name,
-                      dl_info->major_version, dl_info->minor_version,
-                  dl_info->module_author, dl_info->module_author_email);
-       }                       /* While */
+               lprintf(3, "Loaded module: %s\n", dl_info);
+       }       /* While */
 }
 
 
@@ -187,6 +194,21 @@ void CtdlRegisterUserHook(void (*fcn_ptr) (char *, long), int EventType)
 }
 
 
+void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *) )
+{
+
+       struct XmsgFunctionHook *newfcn;
+
+       newfcn = (struct XmsgFunctionHook *)
+           mallok(sizeof(struct XmsgFunctionHook));
+       newfcn->next = XmsgHookTable;
+       newfcn->h_function_pointer = fcn_ptr;
+       XmsgHookTable = newfcn;
+
+       lprintf(5, "Registered a new x-msg function\n");
+}
+
+
 void PerformSessionHooks(int EventType)
 {
        struct SessionFunctionHook *fcn;
@@ -219,3 +241,15 @@ void PerformUserHooks(char *username, long usernum, int EventType)
                }
        }
 }
+
+int PerformXmsgHooks(char *sender, char *recp, char *msg)
+{
+       struct XmsgFunctionHook *fcn;
+       int total_sent = 0;
+
+       for (fcn = XmsgHookTable; fcn != NULL; fcn = fcn->next) {
+               total_sent +=
+                       (*fcn->h_function_pointer) (sender, recp, msg);
+       }
+       return total_sent;
+}