4 * Functions which manage policy for rooms (such as message expiry)
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
19 # include <sys/time.h>
26 #include <libcitadel.h>
32 #include "sysdep_decls.h"
35 #include "citserver.h"
37 #include "ctdl_module.h"
41 * Retrieve the applicable expire policy for a specific room
43 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct ctdlroom *qrbuf) {
46 /* If the room has its own policy, return it */
47 if (qrbuf->QRep.expire_mode != 0) {
48 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
52 /* (non-mailbox rooms)
53 * If the floor has its own policy, return it
55 if ( (qrbuf->QRflags & QR_MAILBOX) == 0) {
56 fl = CtdlGetCachedFloor(qrbuf->QRfloor);
57 if (fl->f_ep.expire_mode != 0) {
58 memcpy(epbuf, &fl->f_ep, sizeof(struct ExpirePolicy));
64 * If there is a default policy for mailbox rooms, return it
66 if (qrbuf->QRflags & QR_MAILBOX) {
67 if (config.c_mbxep.expire_mode != 0) {
68 memcpy(epbuf, &config.c_mbxep,
69 sizeof(struct ExpirePolicy));
74 /* Otherwise, fall back on the system default */
75 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
82 void cmd_gpex(char *argbuf) {
83 struct ExpirePolicy exp;
87 extract_token(which, argbuf, 0, '|', sizeof which);
88 if (!strcasecmp(which, strof(room))) {
89 memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
91 else if (!strcasecmp(which, strof(floorpolicy))||
92 !strcasecmp(which, "floor")) { /* Deprecated version */
93 fl = CtdlGetCachedFloor(CC->room.QRfloor);
94 memcpy(&exp, &fl->f_ep, sizeof(struct ExpirePolicy));
96 else if (!strcasecmp(which, strof(mailboxespolicy))||
97 !strcasecmp(which, "mailboxes")) {/* Deprecated version */
98 memcpy(&exp, &config.c_mbxep, sizeof(struct ExpirePolicy));
100 else if (!strcasecmp(which, strof(sitepolicy))||
101 !strcasecmp(which, "site")) {/* Deprecated version */
102 memcpy(&exp, &config.c_ep, sizeof(struct ExpirePolicy));
105 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
109 cprintf("%d %d|%d\n", CIT_OK, exp.expire_mode, exp.expire_value);
116 void cmd_spex(char *argbuf) {
117 struct ExpirePolicy exp;
121 memset(&exp, 0, sizeof(struct ExpirePolicy));
122 extract_token(which, argbuf, 0, '|', sizeof which);
123 exp.expire_mode = extract_int(argbuf, 1);
124 exp.expire_value = extract_int(argbuf, 2);
126 if ((exp.expire_mode < 0) || (exp.expire_mode > 3)) {
127 cprintf("%d Invalid policy.\n", ERROR + ILLEGAL_VALUE);
131 if (!strcasecmp(which, "room")) {
132 if (!is_room_aide()) {
133 cprintf("%d Higher access required.\n",
134 ERROR + HIGHER_ACCESS_REQUIRED);
137 CtdlGetRoomLock(&CC->room, CC->room.QRname);
138 memcpy(&CC->room.QRep, &exp, sizeof(struct ExpirePolicy));
139 CtdlPutRoomLock(&CC->room);
140 cprintf("%d Room expire policy has been updated.\n", CIT_OK);
144 if (CC->user.axlevel < AxAideU) {
145 cprintf("%d Higher access required.\n",
146 ERROR + HIGHER_ACCESS_REQUIRED);
150 if (!strcasecmp(which, strof(floorpolicy))||
151 !strcasecmp(which, "floor")) { /* deprecated version */
152 lgetfloor(&flbuf, CC->room.QRfloor);
153 memcpy(&flbuf.f_ep, &exp, sizeof(struct ExpirePolicy));
154 lputfloor(&flbuf, CC->room.QRfloor);
155 cprintf("%d Floor expire policy has been updated.\n", CIT_OK);
159 else if (!strcasecmp(which, strof(mailboxespolicy))||
160 !strcasecmp(which, "mailboxes")) {
161 memcpy(&config.c_mbxep, &exp, sizeof(struct ExpirePolicy));
163 cprintf("%d Default expire policy for mailboxes set.\n",
168 else if (!strcasecmp(which, strof(sitepolicy))||
169 !strcasecmp(which, "site")) {/* deprecated version */
170 if (exp.expire_mode == EXPIRE_NEXTLEVEL) {
171 cprintf("%d Invalid policy (no higher level)\n",
172 ERROR + ILLEGAL_VALUE);
175 memcpy(&config.c_ep, &exp, sizeof(struct ExpirePolicy));
177 cprintf("%d Site expire policy has been updated.\n", CIT_OK);
182 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);