chiark / gitweb /
Merge from disorder.dev.
[disorder] / lib / queue-rights.c
CommitLineData
938d8157 1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2007 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
938d8157 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
938d8157 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
938d8157 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
938d8157 17 */
18/** @file lib/queue-rights.c
19 * @brief Various rights-checking operations
20 */
21
05b75f8d 22#include "common.h"
938d8157 23
24#include "queue.h"
25#include "rights.h"
26
27/** @brief Test for scratchability
28 * @param rights User rights
29 * @param who Username
30 * @param q Queue entry or NULL
31 * @return non-0 if scratchable, else 0
32 */
33int right_scratchable(rights_type rights, const char *who,
34 const struct queue_entry *q) {
35 rights_type r;
36
37 if(!q)
38 return 0;
39 if(q->submitter)
40 if(!strcmp(q->submitter, who))
41 r = RIGHT_SCRATCH_MINE|RIGHT_SCRATCH_ANY;
42 else
43 r = RIGHT_SCRATCH_ANY;
44 else
45 r = RIGHT_SCRATCH_RANDOM|RIGHT_SCRATCH_ANY;
46 return !!(rights & r);
47}
48
49/** @brief Test for movability
50 * @param rights User rights
51 * @param who Username
52 * @param q Queue entry or NULL
53 * @return non-0 if movable, else 0
54 */
55int right_movable(rights_type rights, const char *who,
56 const struct queue_entry *q) {
57 rights_type r;
58
59 if(!q)
60 return 0;
61 if(q->submitter)
62 if(!strcmp(q->submitter, who))
63 r = RIGHT_MOVE_MINE|RIGHT_MOVE_ANY;
64 else
65 r = RIGHT_MOVE_ANY;
66 else
67 r = RIGHT_MOVE_RANDOM|RIGHT_MOVE_ANY;
68 return !!(rights & r);
69}
70
71/** @brief Test for removability
72 * @param rights User rights
73 * @param who Username
74 * @param q Queue entry or NULL
75 * @return non-0 if removable, else 0
76 */
77int right_removable(rights_type rights, const char *who,
78 const struct queue_entry *q) {
79 rights_type r;
80
81 if(!q)
82 return 0;
83 if(q->submitter)
84 if(!strcmp(q->submitter, who))
85 r = RIGHT_REMOVE_MINE|RIGHT_REMOVE_ANY;
86 else
87 r = RIGHT_REMOVE_ANY;
88 else
89 r = RIGHT_REMOVE_RANDOM|RIGHT_REMOVE_ANY;
90 return !!(rights & r);
91}
92
93/*
94Local Variables:
95c-basic-offset:2
96comment-column:40
97fill-column:79
98indent-tabs-mode:nil
99End:
100*/