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"
40 * Retrieve the applicable expire policy for a specific room
42 void GetExpirePolicy(struct ExpirePolicy
*epbuf
, struct ctdlroom
*qrbuf
) {
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
));
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
));
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
));
73 /* Otherwise, fall back on the system default */
74 memcpy(epbuf
, &config
.c_ep
, sizeof(struct ExpirePolicy
));
81 void cmd_gpex(char *argbuf
) {
82 struct ExpirePolicy exp
;
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
));
101 cprintf("%d Invalid keyword \"%s\"\n", ERROR
+ ILLEGAL_VALUE
, which
);
105 cprintf("%d %d|%d\n", CIT_OK
, exp
.expire_mode
, exp
.expire_value
);
112 void cmd_spex(char *argbuf
) {
113 struct ExpirePolicy exp
;
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
);
127 if (!strcasecmp(which
, "room")) {
128 if (!is_room_aide()) {
129 cprintf("%d Higher access required.\n",
130 ERROR
+ HIGHER_ACCESS_REQUIRED
);
133 lgetroom(&CC
->room
, CC
->room
.QRname
);
134 memcpy(&CC
->room
.QRep
, &exp
, sizeof(struct ExpirePolicy
));
136 cprintf("%d Room expire policy has been updated.\n", CIT_OK
);
140 if (CC
->user
.axlevel
< 6) {
141 cprintf("%d Higher access required.\n",
142 ERROR
+ HIGHER_ACCESS_REQUIRED
);
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
);
154 else if (!strcasecmp(which
, "mailboxes")) {
155 memcpy(&config
.c_mbxep
, &exp
, sizeof(struct ExpirePolicy
));
157 cprintf("%d Default expire policy for mailboxes set.\n",
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
);
168 memcpy(&config
.c_ep
, &exp
, sizeof(struct ExpirePolicy
));
170 cprintf("%d Site expire policy has been updated.\n", CIT_OK
);
175 cprintf("%d Invalid keyword \"%s\"\n", ERROR
+ ILLEGAL_VALUE
, which
);