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"
36 #include "citserver.h"
38 #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, "room")) {
89 memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
91 else if (!strcasecmp(which, "floor")) {
92 fl = CtdlGetCachedFloor(CC->room.QRfloor);
93 memcpy(&exp, &fl->f_ep, sizeof(struct ExpirePolicy));
95 else if (!strcasecmp(which, "mailboxes")) {
96 memcpy(&exp, &config.c_mbxep, sizeof(struct ExpirePolicy));
98 else if (!strcasecmp(which, "site")) {
99 memcpy(&exp, &config.c_ep, sizeof(struct ExpirePolicy));
102 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
106 cprintf("%d %d|%d\n", CIT_OK, exp.expire_mode, exp.expire_value);
113 void cmd_spex(char *argbuf) {
114 struct ExpirePolicy exp;
118 memset(&exp, 0, sizeof(struct ExpirePolicy));
119 extract_token(which, argbuf, 0, '|', sizeof which);
120 exp.expire_mode = extract_int(argbuf, 1);
121 exp.expire_value = extract_int(argbuf, 2);
123 if ((exp.expire_mode < 0) || (exp.expire_mode > 3)) {
124 cprintf("%d Invalid policy.\n", ERROR + ILLEGAL_VALUE);
128 if (!strcasecmp(which, "room")) {
129 if (!is_room_aide()) {
130 cprintf("%d Higher access required.\n",
131 ERROR + HIGHER_ACCESS_REQUIRED);
134 CtdlGetRoomLock(&CC->room, CC->room.QRname);
135 memcpy(&CC->room.QRep, &exp, sizeof(struct ExpirePolicy));
136 CtdlPutRoomLock(&CC->room);
137 cprintf("%d Room expire policy has been updated.\n", CIT_OK);
141 if (CC->user.axlevel < AxAideU) {
142 cprintf("%d Higher access required.\n",
143 ERROR + HIGHER_ACCESS_REQUIRED);
147 if (!strcasecmp(which, "floor")) {
148 lgetfloor(&flbuf, CC->room.QRfloor);
149 memcpy(&flbuf.f_ep, &exp, sizeof(struct ExpirePolicy));
150 lputfloor(&flbuf, CC->room.QRfloor);
151 cprintf("%d Floor expire policy has been updated.\n", CIT_OK);
155 else if (!strcasecmp(which, "mailboxes")) {
156 memcpy(&config.c_mbxep, &exp, sizeof(struct ExpirePolicy));
158 cprintf("%d Default expire policy for mailboxes set.\n",
163 else if (!strcasecmp(which, "site")) {
164 if (exp.expire_mode == EXPIRE_NEXTLEVEL) {
165 cprintf("%d Invalid policy (no higher level)\n",
166 ERROR + ILLEGAL_VALUE);
169 memcpy(&config.c_ep, &exp, sizeof(struct ExpirePolicy));
171 cprintf("%d Site expire policy has been updated.\n", CIT_OK);
176 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
182 /*****************************************************************************/
183 /* MODULE INITIALIZATION STUFF */
184 /*****************************************************************************/
186 CTDL_MODULE_INIT(policy)
189 CtdlRegisterProtoHook(cmd_gpex, "GPEX", "Autoconverted. TODO: document me.");
190 CtdlRegisterProtoHook(cmd_spex, "SPEX", "Autoconverted. TODO: document me.");
192 /* return our Subversion id for the Log */