* Fixed a multiselect bug in the mailbox view. Ctrl-click was selecting a message...
[citadel.git] / citadel / policy.c
blob226e985dc58e0eb61516af618a380c457f369062
1 /*
2 * $Id$
4 * Functions which manage policy for rooms (such as message expiry)
5 */
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <sys/stat.h>
12 #include <string.h>
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
16 # include <time.h>
17 #else
18 # if HAVE_SYS_TIME_H
19 # include <sys/time.h>
20 # else
21 # include <time.h>
22 # endif
23 #endif
25 #include <limits.h>
26 #include <libcitadel.h>
27 #include "citadel.h"
28 #include "server.h"
29 #include "database.h"
30 #include "config.h"
31 #include "room_ops.h"
32 #include "sysdep_decls.h"
33 #include "support.h"
34 #include "user_ops.h"
35 #include "msgbase.h"
36 #include "citserver.h"
40 * Retrieve the applicable expire policy for a specific room
42 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct ctdlroom *qrbuf) {
43 struct floor *fl;
45 /* If the room has its own policy, return it */
46 if (qrbuf->QRep.expire_mode != 0) {
47 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
48 return;
51 /* (non-mailbox rooms)
52 * If the floor has its own policy, return it
54 if ( (qrbuf->QRflags & QR_MAILBOX) == 0) {
55 fl = cgetfloor(qrbuf->QRfloor);
56 if (fl->f_ep.expire_mode != 0) {
57 memcpy(epbuf, &fl->f_ep, sizeof(struct ExpirePolicy));
58 return;
62 /* (Mailbox rooms)
63 * If there is a default policy for mailbox rooms, return it
65 if (qrbuf->QRflags & QR_MAILBOX) {
66 if (config.c_mbxep.expire_mode != 0) {
67 memcpy(epbuf, &config.c_mbxep,
68 sizeof(struct ExpirePolicy));
69 return;
73 /* Otherwise, fall back on the system default */
74 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
79 * Get Policy EXpire
81 void cmd_gpex(char *argbuf) {
82 struct ExpirePolicy exp;
83 struct floor *fl;
84 char which[128];
86 extract_token(which, argbuf, 0, '|', sizeof which);
87 if (!strcasecmp(which, "room")) {
88 memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
90 else if (!strcasecmp(which, "floor")) {
91 fl = cgetfloor(CC->room.QRfloor);
92 memcpy(&exp, &fl->f_ep, sizeof(struct ExpirePolicy));
94 else if (!strcasecmp(which, "mailboxes")) {
95 memcpy(&exp, &config.c_mbxep, sizeof(struct ExpirePolicy));
97 else if (!strcasecmp(which, "site")) {
98 memcpy(&exp, &config.c_ep, sizeof(struct ExpirePolicy));
100 else {
101 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
102 return;
105 cprintf("%d %d|%d\n", CIT_OK, exp.expire_mode, exp.expire_value);
110 * Set Policy EXpire
112 void cmd_spex(char *argbuf) {
113 struct ExpirePolicy exp;
114 struct floor flbuf;
115 char which[128];
117 memset(&exp, 0, sizeof(struct ExpirePolicy));
118 extract_token(which, argbuf, 0, '|', sizeof which);
119 exp.expire_mode = extract_int(argbuf, 1);
120 exp.expire_value = extract_int(argbuf, 2);
122 if ((exp.expire_mode < 0) || (exp.expire_mode > 3)) {
123 cprintf("%d Invalid policy.\n", ERROR + ILLEGAL_VALUE);
124 return;
127 if (!strcasecmp(which, "room")) {
128 if (!is_room_aide()) {
129 cprintf("%d Higher access required.\n",
130 ERROR + HIGHER_ACCESS_REQUIRED);
131 return;
133 lgetroom(&CC->room, CC->room.QRname);
134 memcpy(&CC->room.QRep, &exp, sizeof(struct ExpirePolicy));
135 lputroom(&CC->room);
136 cprintf("%d Room expire policy has been updated.\n", CIT_OK);
137 return;
140 if (CC->user.axlevel < 6) {
141 cprintf("%d Higher access required.\n",
142 ERROR + HIGHER_ACCESS_REQUIRED);
143 return;
146 if (!strcasecmp(which, "floor")) {
147 lgetfloor(&flbuf, CC->room.QRfloor);
148 memcpy(&flbuf.f_ep, &exp, sizeof(struct ExpirePolicy));
149 lputfloor(&flbuf, CC->room.QRfloor);
150 cprintf("%d Floor expire policy has been updated.\n", CIT_OK);
151 return;
154 else if (!strcasecmp(which, "mailboxes")) {
155 memcpy(&config.c_mbxep, &exp, sizeof(struct ExpirePolicy));
156 put_config();
157 cprintf("%d Default expire policy for mailboxes set.\n",
158 CIT_OK);
159 return;
162 else if (!strcasecmp(which, "site")) {
163 if (exp.expire_mode == EXPIRE_NEXTLEVEL) {
164 cprintf("%d Invalid policy (no higher level)\n",
165 ERROR + ILLEGAL_VALUE);
166 return;
168 memcpy(&config.c_ep, &exp, sizeof(struct ExpirePolicy));
169 put_config();
170 cprintf("%d Site expire policy has been updated.\n", CIT_OK);
171 return;
174 else {
175 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
176 return;