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