]> code.citadel.org Git - citadel.git/blob - citadel/serv_test.c
Added a new type of module hook for adding logging functions
[citadel.git] / citadel / serv_test.c
1 /* $Id$ */
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <signal.h>
7 #include <pwd.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <sys/time.h>
11 #include <sys/wait.h>
12 #include <string.h>
13 #include <limits.h>
14 #include <pthread.h>
15 #include "citadel.h"
16 #include "server.h"
17 #include <syslog.h>
18 #include <time.h>
19 #include "sysdep_decls.h"
20 #include "citserver.h"
21 #include "support.h"
22 #include "config.h"
23 #include "dynloader.h"
24 #include "room_ops.h"
25 #include "policy.h"
26 #include "database.h"
27 #include "msgbase.h"
28
29 extern struct CitContext *ContextList;
30
31 #define MODULE_NAME     "Dummy test module"
32 #define MODULE_AUTHOR   "Art Cancro"
33 #define MODULE_EMAIL    "ajc@uncnsrd.mt-kisco.ny.us"
34 #define MAJOR_VERSION   0
35 #define MINOR_VERSION   4
36
37 static struct DLModule_Info info = {
38         MODULE_NAME,
39         MODULE_AUTHOR,
40         MODULE_EMAIL,
41         MAJOR_VERSION,
42         MINOR_VERSION
43         };
44
45 void CleanupTest(void) {
46         lprintf(9, "--- test of adding an unload hook --- \n");
47         }
48
49 void NewRoomTest(void) {
50         lprintf(9, "--- test module was told we're now in %s ---\n",
51                 CC->cs_room);
52         }
53
54 void SessionStartTest(void) {
55         lprintf(9, "--- starting up session %d ---\n",
56                 CC->cs_pid);
57         }
58
59 void SessionStopTest(void) {
60         lprintf(9, "--- ending session %d ---\n", 
61                 CC->cs_pid);
62         }
63
64 void LoginTest(void) {
65         lprintf(9, "--- Hello, %s ---\n", CC->curr_user);
66         }
67
68
69 void Ygorl(char *username, long usernum) {
70         if (!strcasecmp(username, "Unsuspecting User")) {
71                 strcpy(username, "Flaming Asshole");
72                 }
73         }
74
75 void LogTest(char *buf) {
76         fprintf(stderr,"%c[1m%s%c[0m", 27, buf, 27);
77         fflush(stderr);
78         }
79
80
81 struct DLModule_Info *Dynamic_Module_Init(void)
82 {
83    CtdlRegisterCleanupHook(CleanupTest);
84    CtdlRegisterSessionHook(NewRoomTest, EVT_NEWROOM);
85    CtdlRegisterSessionHook(SessionStartTest, EVT_START);
86    CtdlRegisterSessionHook(SessionStopTest, EVT_STOP);
87    CtdlRegisterSessionHook(LoginTest, EVT_LOGIN);
88    CtdlRegisterUserHook(Ygorl, EVT_OUTPUTMSG);
89    CtdlRegisterLogHook(LogTest, 1);
90    return &info;
91 }