]> code.citadel.org Git - citadel.git/blob - citadel/serv_test.c
policy
[citadel.git] / citadel / serv_test.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include <signal.h>
6 #include <pwd.h>
7 #include <errno.h>
8 #include <sys/types.h>
9 #include <sys/time.h>
10 #include <sys/wait.h>
11 #include <string.h>
12 #include <limits.h>
13 #include <pthread.h>
14 #include "citadel.h"
15 #include "server.h"
16 #include <syslog.h>
17 #include "sysdep_decls.h"
18 #include "citserver.h"
19 #include "support.h"
20 #include "config.h"
21 #include "dynloader.h"
22 #include "room_ops.h"
23 #include "policy.h"
24 #include "database.h"
25
26 extern struct CitContext *ContextList;
27
28 #define MODULE_NAME     "Dummy test module"
29 #define MODULE_AUTHOR   "Art Cancro"
30 #define MODULE_EMAIL    "ajc@uncnsrd.mt-kisco.ny.us"
31 #define MAJOR_VERSION   0
32 #define MINOR_VERSION   3
33
34 static struct DLModule_Info info = {
35         MODULE_NAME,
36         MODULE_AUTHOR,
37         MODULE_EMAIL,
38         MAJOR_VERSION,
39         MINOR_VERSION
40         };
41
42 void CleanupTest(void) {
43         lprintf(9, "--- test of adding an unload hook --- \n");
44         }
45
46 void NewRoomTest(void) {
47         lprintf(9, "--- test module was told we're now in %s ---\n",
48                 CC->cs_room);
49         }
50
51 void SessionStartTest(void) {
52         lprintf(9, "--- starting up session %d ---\n",
53                 CC->cs_pid);
54         }
55
56 void SessionStopTest(void) {
57         lprintf(9, "--- ending session %d ---\n", 
58                 CC->cs_pid);
59         }
60
61 void LoginTest(void) {
62         lprintf(9, "--- Hello, %s ---\n", CC->curr_user);
63         }
64
65
66 void Ygorl(char *username, long usernum) {
67         if (!strcasecmp(username, "Hexslinger")) {
68                 strcpy(username, "Flaming Asshole");
69                 }
70         }
71
72
73
74 void DoPurgeMessages(struct quickroom *qrbuf) {
75         struct ExpirePolicy epbuf;
76         long delnum;
77
78         GetExpirePolicy(&epbuf, qrbuf);
79         
80         lprintf(9, "ExpirePolicy for <%s> is <%d> <%d>\n",
81                 qrbuf->QRname, epbuf.expire_mode, epbuf.expire_value);
82
83         /* If the room is set to never expire messages ... do nothing */
84         if (epbuf.expire_mode == EXPIRE_NEXTLEVEL) return;
85         if (epbuf.expire_mode == EXPIRE_MANUAL) return;
86
87         get_msglist(qrbuf);
88         
89         /* Nothing to do if there aren't any messages */
90         if (CC->num_msgs == 0) return;
91
92         /* If the room is set to expire by count, do that */
93         if (epbuf.expire_mode == EXPIRE_NUMMSGS) {
94                 while (CC->num_msgs > epbuf.expire_value) {
95                         delnum = MessageFromList(0);
96                         lprintf(5, "Expiring message %ld\n", delnum);
97                         cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long));
98                         memcpy(&CC->msglist[0], &CC->msglist[1],
99                                 (sizeof(long)*(CC->num_msgs - 1)));
100                         CC->num_msgs = CC->num_msgs - 1;
101                         }
102                 }
103
104         /* If the room is set to expire by age...  FIX (write this!!) */
105         if (epbuf.expire_mode == EXPIRE_AGE) {
106                 }
107
108         put_msglist(qrbuf);
109         }
110
111 void PurgeMessages(void) {
112         ForEachRoom(DoPurgeMessages);
113         }
114
115 struct DLModule_Info *Dynamic_Module_Init(void)
116 {
117    CtdlRegisterCleanupHook(CleanupTest);
118    CtdlRegisterCleanupHook(PurgeMessages);
119    CtdlRegisterSessionHook(NewRoomTest, EVT_NEWROOM);
120    CtdlRegisterSessionHook(SessionStartTest, EVT_START);
121    CtdlRegisterSessionHook(SessionStopTest, EVT_STOP);
122    CtdlRegisterSessionHook(LoginTest, EVT_LOGIN);
123    CtdlRegisterUserHook(Ygorl, EVT_OUTPUTMSG);
124    return &info;
125 }