citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

expire_policy.c
Go to the documentation of this file.
1/*
2 * Functions which manage expire policy for rooms
3 * Copyright (c) 1987-2015 by the citadel.org team
4 *
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.
7 *
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.
12 */
13
14#include "sysdep.h"
15#include <stdlib.h>
16#include <unistd.h>
17#include <stdio.h>
18#include <sys/stat.h>
19#include <string.h>
20
21#include <time.h>
22#include <limits.h>
23#include <libcitadel.h>
24#include "citadel.h"
25#include "server.h"
26#include "database.h"
27#include "config.h"
28#include "room_ops.h"
29#include "sysdep_decls.h"
30#include "support.h"
31#include "msgbase.h"
32#include "citserver.h"
33#include "ctdl_module.h"
34#include "user_ops.h"
35
36/*
37 * Retrieve the applicable expire policy for a specific room
38 */
39void GetExpirePolicy(struct ExpirePolicy *epbuf, struct ctdlroom *qrbuf) {
40 struct floor *fl;
41
42 /* If the room has its own policy, return it */
43 if (qrbuf->QRep.expire_mode != 0) {
44 memcpy(epbuf, &qrbuf->QRep, sizeof(struct ExpirePolicy));
45 return;
46 }
47
48 /* (non-mailbox rooms)
49 * If the floor has its own policy, return it
50 */
51 if ( (qrbuf->QRflags & QR_MAILBOX) == 0) {
53 if (fl->f_ep.expire_mode != 0) {
54 memcpy(epbuf, &fl->f_ep, sizeof(struct ExpirePolicy));
55 return;
56 }
57 }
58
59 /* (Mailbox rooms)
60 * If there is a default policy for mailbox rooms, return it
61 */
62 if (qrbuf->QRflags & QR_MAILBOX) {
63 if (CtdlGetConfigInt("c_mbxep_mode") != 0) {
64 epbuf->expire_mode = CtdlGetConfigInt("c_mbxep_mode");
65 epbuf->expire_value = CtdlGetConfigInt("c_mbxep_value");
66 return;
67 }
68 }
69
70 /* Otherwise, fall back on the system default */
71 epbuf->expire_mode = CtdlGetConfigInt("c_ep_mode");
72 epbuf->expire_value = CtdlGetConfigInt("c_ep_value");
73}
74
75
76/*
77 * Get Policy EXpire
78 */
79void cmd_gpex(char *argbuf) {
80 struct ExpirePolicy exp;
81 struct floor *fl;
82 char which[128];
83
84 memset(&exp, 0, sizeof(struct ExpirePolicy));
85 extract_token(which, argbuf, 0, '|', sizeof which);
86 if (!strcasecmp(which, strof(roompolicy)) || !strcasecmp(which, "room")) {
87 memcpy(&exp, &CC->room.QRep, sizeof(struct ExpirePolicy));
88 }
89 else if (!strcasecmp(which, strof(floorpolicy)) || !strcasecmp(which, "floor")) {
90 fl = CtdlGetCachedFloor(CC->room.QRfloor);
91 memcpy(&exp, &fl->f_ep, sizeof(struct ExpirePolicy));
92 }
93 else if (!strcasecmp(which, strof(mailboxespolicy)) || !strcasecmp(which, "mailboxes")) {
94 exp.expire_mode = CtdlGetConfigInt("c_mbxep_mode");
95 exp.expire_value = CtdlGetConfigInt("c_mbxep_value");
96 }
97 else if (!strcasecmp(which, strof(sitepolicy)) || !strcasecmp(which, "site")) {
98 exp.expire_mode = CtdlGetConfigInt("c_ep_mode");
99 exp.expire_value = CtdlGetConfigInt("c_ep_value");
100 }
101 else {
102 cprintf("%d Invalid keyword \"%s\"\n", ERROR + ILLEGAL_VALUE, which);
103 return;
104 }
105
106 cprintf("%d %d|%d\n", CIT_OK, exp.expire_mode, exp.expire_value);
107}
108
109
110/*
111 * Set Policy EXpire
112 */
113void cmd_spex(char *argbuf) {
114 struct ExpirePolicy exp;
115 struct floor flbuf;
116 char which[128];
117
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);
122
123 if ((exp.expire_mode < 0) || (exp.expire_mode > 3)) {
124 cprintf("%d Invalid policy.\n", ERROR + ILLEGAL_VALUE);
125 return;
126 }
127
128 if ((!strcasecmp(which, strof(roompolicy))) || (!strcasecmp(which, "room")))
129 {
130 if (!is_room_aide()) {
131 cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
132 return;
133 }
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 for '%s' has been updated.\n", CIT_OK, CC->room.QRname);
138 syslog(LOG_DEBUG, "Room: %s , Policy: %d , Value: %d",
139 CC->room.QRname,
140 exp.expire_mode,
141 exp.expire_value
142 );
143 return;
144 }
145
146 if (CC->user.axlevel < AxAideU) {
147 cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
148 return;
149 }
150
151 if ((!strcasecmp(which, strof(floorpolicy))) || (!strcasecmp(which, "floor")))
152 {
153 lgetfloor(&flbuf, CC->room.QRfloor);
154 memcpy(&flbuf.f_ep, &exp, sizeof(struct ExpirePolicy));
155 lputfloor(&flbuf, CC->room.QRfloor);
156 cprintf("%d Floor expire policy has been updated.\n", CIT_OK);
157 return;
158 }
159
160 else if ((!strcasecmp(which, strof(mailboxespolicy))) || (!strcasecmp(which, "mailboxes")))
161 {
162 CtdlSetConfigInt("c_mbxep_mode", exp.expire_mode);
163 CtdlSetConfigInt("c_mbxep_value", exp.expire_value);
164 cprintf("%d Default expire policy for mailboxes set.\n", CIT_OK);
165 return;
166 }
167
168 else if ((!strcasecmp(which, strof(sitepolicy))) || (!strcasecmp(which, "site")))
169 {
170 if (exp.expire_mode == EXPIRE_NEXTLEVEL) {
171 cprintf("%d Invalid policy (no higher level)\n", ERROR + ILLEGAL_VALUE);
172 return;
173 }
174 CtdlSetConfigInt("c_ep_mode", exp.expire_mode);
175 CtdlSetConfigInt("c_ep_value", exp.expire_value);
176 cprintf("%d Site expire policy has been updated.\n", CIT_OK);
177 return;
178 }
179
180 cprintf("%d Invalid keyword '%s'\n", ERROR + ILLEGAL_VALUE, which);
181}
#define EXPIRE_NEXTLEVEL
Definition: citadel.h:69
int CtdlGetConfigInt(char *key)
Definition: config.c:426
void CtdlSetConfigInt(char *key, int value)
Definition: config.c:359
#define CC
Definition: context.h:140
struct floor * CtdlGetCachedFloor(int floor_num)
Definition: room_ops.c:535
int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:387
void CtdlPutRoomLock(struct ctdlroom *qrbuf)
Definition: room_ops.c:444
void cmd_gpex(char *argbuf)
Definition: expire_policy.c:79
void cmd_spex(char *argbuf)
void GetExpirePolicy(struct ExpirePolicy *epbuf, struct ctdlroom *qrbuf)
Definition: expire_policy.c:39
#define CIT_OK
Definition: ipcdef.h:6
#define ILLEGAL_VALUE
Definition: ipcdef.h:16
#define HIGHER_ACCESS_REQUIRED
Definition: ipcdef.h:23
#define QR_MAILBOX
Definition: ipcdef.h:53
#define ERROR
Definition: ipcdef.h:9
void lgetfloor(struct floor *flbuf, int floor_num)
Definition: room_ops.c:524
void lputfloor(struct floor *flbuf, int floor_num)
Definition: room_ops.c:599
struct floor flbuf
Definition: serv_migrate.c:501
struct ctdlroom qrbuf
Definition: serv_migrate.c:497
int expire_mode
Definition: citadel.h:65
int expire_value
Definition: citadel.h:66
char QRfloor
Definition: citadel.h:116
struct ExpirePolicy QRep
Definition: citadel.h:118
unsigned QRflags
Definition: citadel.h:113
Definition: citadel.h:145
struct ExpirePolicy f_ep
Definition: citadel.h:149
void cprintf(const char *format,...)
Definition: sysdep.c:381
int is_room_aide(void)
Definition: user_ops.c:441