fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / serv_moderate.c
1 /*
2  * $Id$
3  *
4  * Server-side functions which handle message moderation.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <sys/types.h>
17
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
20 # include <time.h>
21 #else
22 # if HAVE_SYS_TIME_H
23 #  include <sys/time.h>
24 # else
25 #  include <time.h>
26 # endif
27 #endif
28
29 #include <sys/wait.h>
30 #include <string.h>
31 #include <limits.h>
32 #include "citadel.h"
33 #include "server.h"
34 #include "sysdep_decls.h"
35 #include "citserver.h"
36 #include "support.h"
37 #include "config.h"
38 #include "control.h"
39 #include "dynloader.h"
40 #include "room_ops.h"
41 #include "user_ops.h"
42 #include "policy.h"
43 #include "database.h"
44 #include "msgbase.h"
45 #include "tools.h"
46
47
48
49 /*
50  * moderate a message
51  */
52 void cmd_mmod(char *argbuf) {
53         long msgnum;
54         int newlevel;
55         struct SuppMsgInfo smi;
56         int is_message_in_room;
57
58         /* user must be at least a Room Aide to moderate */
59         if (CtdlAccessCheck(ac_room_aide)) return;
60
61         msgnum = extract_long(argbuf, 0);
62         newlevel = extract_int(argbuf, 1);
63
64         if ( (newlevel < (-63)) || (newlevel > (+63)) ) {
65                 cprintf("%d %d is not a valid moderation level.\n",
66                         ERROR+ILLEGAL_VALUE, newlevel);
67                 return;
68         }
69
70         is_message_in_room = CtdlForEachMessage(MSGS_EQ, msgnum, (-127),
71                                 NULL, NULL, NULL, NULL);
72         if (!is_message_in_room) {
73                 cprintf("%d Message %ld is not in this room.\n",
74                         ERROR+ILLEGAL_VALUE, msgnum);
75                 return;
76         }
77
78         GetSuppMsgInfo(&smi, msgnum);
79         smi.smi_mod = newlevel;
80         PutSuppMsgInfo(&smi);
81
82         cprintf("%d Message %ld is moderated to %d\n", OK, msgnum, newlevel);
83 }
84
85
86 char *Dynamic_Module_Init(void)
87 {
88         CtdlRegisterProtoHook(cmd_mmod, "MMOD", "Moderate a message");
89         return "$Id$";
90 }