caf9af73bb15a6e8ef16f7c4eb9c832b99c79480
[citadel.git] / citadel / serv_test.c
1 /*
2  * $Id$
3  *
4  * A skeleton module to test the dynamic loader.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <sys/types.h>
17
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
20 # include <time.h>
21 #else
22 # if HAVE_SYS_TIME_H
23 #  include <sys/time.h>
24 # else
25 #  include <time.h>
26 # endif
27 #endif
28
29 #include <sys/wait.h>
30 #include <string.h>
31 #include <limits.h>
32 #include "citadel.h"
33 #include "server.h"
34 #include "sysdep_decls.h"
35 #include "citserver.h"
36 #include "support.h"
37 #include "config.h"
38 #include "serv_extensions.h"
39 #include "room_ops.h"
40 #include "policy.h"
41 #include "database.h"
42 #include "msgbase.h"
43
44 extern struct CitContext *ContextList;
45
46 void CleanupTest(void) {
47         lprintf(9, "--- test of adding an unload hook --- \n");
48         }
49
50 void NewRoomTest(void) {
51         lprintf(9, "--- test module was told we're now in a new room ---\n");
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 char *serv_test_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 "$Id$";
91 }