2 * Functions which manage expire policy for rooms
3 * Copyright (c) 1987-2015 by the citadel.org team
5 * This program is open source software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
26 # include <sys/time.h>
33 #include <libcitadel.h>
39 #include "sysdep_decls.h"
42 #include "citserver.h"
44 #include "ctdl_module.h"
48 * Retrieve the applicable expire policy for a specific room
50 void GetExpirePolicy(struct ExpirePolicy *epbuf, struct ctdlroom *qrbuf) {
53 /* If the room has its own policy, return it */
54 if (qrbuf->QRep.expire_mode != 0) {
55 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
59 /* (non-mailbox rooms)
60 * If the floor has its own policy, return it
62 if ( (qrbuf->QRflags & QR_MAILBOX) == 0) {
63 fl = CtdlGetCachedFloor(qrbuf->QRfloor);
64 if (fl->f_ep.expire_mode != 0) {
65 memcpy(epbuf, &fl->f_ep, sizeof(struct ExpirePolicy));
71 * If there is a default policy for mailbox rooms, return it
73 if (qrbuf->QRflags & QR_MAILBOX) {
74 if (config.c_mbxep.expire_mode != 0) {
75 memcpy(epbuf, &config.c_mbxep, sizeof(struct ExpirePolicy));
80 /* Otherwise, fall back on the system default */
81 memcpy(epbuf, &config.c_ep, sizeof(struct ExpirePolicy));
88 void cmd_gpex(char *argbuf) {
89 struct ExpirePolicy exp;
93 extract_token(which, argbuf, 0, '|', sizeof which);
94 if (!strcasecmp(which, strof(roompolicy))||
95 !strcasecmp(which, "room")) { /* Deprecated version */
96 memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
98 else if (!strcasecmp(which, strof(floorpolicy))||
99 !strcasecmp(which, "floor")) { /* Deprecated version */
100 fl = CtdlGetCachedFloor(CC->room.QRfloor);
101 memcpy(&exp, &fl->f_ep, sizeof(struct ExpirePolicy));
103 else if (!strcasecmp(which, strof(mailboxespolicy))||
104 !strcasecmp(which, "mailboxes")) {/* Deprecated version */
105 memcpy(&exp, &config.c_mbxep, sizeof(struct ExpirePolicy));
107 else if (!strcasecmp(which, strof(sitepolicy))||
108 !strcasecmp(which, "site")) {/* Deprecated version */
109 memcpy(&exp, &config.c_ep, sizeof(struct ExpirePolicy));
112 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
116 cprintf("%d %d|%d\n", CIT_OK, exp.expire_mode, exp.expire_value);
123 void cmd_spex(char *argbuf) {
124 struct ExpirePolicy exp;
128 memset(&exp, 0, sizeof(struct ExpirePolicy));
129 extract_token(which, argbuf, 0, '|', sizeof which);
130 exp.expire_mode = extract_int(argbuf, 1);
131 exp.expire_value = extract_int(argbuf, 2);
133 if ((exp.expire_mode < 0) || (exp.expire_mode > 3)) {
134 cprintf("%d Invalid policy.\n", ERROR + ILLEGAL_VALUE);
138 if ( (!strcasecmp(which, strof(roompolicy)))
139 || (!strcasecmp(which, "room"))
141 if (!is_room_aide()) {
142 cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
145 CtdlGetRoomLock(&CC->room, CC->room.QRname);
146 memcpy(&CC->room.QRep, &exp, sizeof(struct ExpirePolicy));
147 CtdlPutRoomLock(&CC->room);
148 cprintf("%d Room expire policy for '%s' has been updated.\n", CIT_OK, CC->room.QRname);
149 syslog(LOG_DEBUG, "Room: %s , Policy: %d , Value: %d",
157 if (CC->user.axlevel < AxAideU) {
158 cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
162 if ( (!strcasecmp(which, strof(floorpolicy)))
163 || (!strcasecmp(which, "floor"))
165 lgetfloor(&flbuf, CC->room.QRfloor);
166 memcpy(&flbuf.f_ep, &exp, sizeof(struct ExpirePolicy));
167 lputfloor(&flbuf, CC->room.QRfloor);
168 cprintf("%d Floor expire policy has been updated.\n", CIT_OK);
172 else if ( (!strcasecmp(which, strof(mailboxespolicy)))
173 || (!strcasecmp(which, "mailboxes"))
175 memcpy(&config.c_mbxep, &exp, sizeof(struct ExpirePolicy));
177 cprintf("%d Default expire policy for mailboxes set.\n", CIT_OK);
181 else if ( (!strcasecmp(which, strof(sitepolicy)))
182 || (!strcasecmp(which, "site"))
184 if (exp.expire_mode == EXPIRE_NEXTLEVEL) {
185 cprintf("%d Invalid policy (no higher level)\n",
186 ERROR + ILLEGAL_VALUE);
189 memcpy(&config.c_ep, &exp, sizeof(struct ExpirePolicy));
191 cprintf("%d Site expire policy has been updated.\n", CIT_OK);
195 cprintf("%d Invalid keyword '%s'\n", ERROR + ILLEGAL_VALUE, which);