2 * This file is part of DisOrder
3 * Copyright (C) 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file lib/rights.c
31 #include "configuration.h"
39 { RIGHT_READ
, "read" },
40 { RIGHT_PLAY
, "play" },
41 { RIGHT_MOVE_ANY
, "move any" },
42 { RIGHT_MOVE_MINE
, "move mine" },
43 { RIGHT_MOVE_RANDOM
, "move random" },
44 { RIGHT_REMOVE_ANY
, "remove any" },
45 { RIGHT_REMOVE_MINE
, "remove mine" },
46 { RIGHT_REMOVE_RANDOM
, "remove random" },
47 { RIGHT_SCRATCH_ANY
, "scratch any" },
48 { RIGHT_SCRATCH_MINE
, "scratch mine" },
49 { RIGHT_SCRATCH_RANDOM
, "scratch random" },
50 { RIGHT_VOLUME
, "volume" },
51 { RIGHT_ADMIN
, "admin" },
52 { RIGHT_RESCAN
, "rescan" },
53 { RIGHT_REGISTER
, "register" },
54 { RIGHT_USERINFO
, "userinfo" },
55 { RIGHT_PREFS
, "prefs" },
56 { RIGHT_GLOBAL_PREFS
, "global prefs" },
57 { RIGHT_PAUSE
, "pause" }
59 #define NRIGHTS (sizeof rights_names / sizeof *rights_names)
61 /** @brief Convert a rights word to a string */
62 char *rights_string(rights_type r
) {
67 for(n
= 0; n
< NRIGHTS
; ++n
) {
68 if(r
& rights_names
[n
].bit
) {
70 dynstr_append(d
, ',');
71 dynstr_append_string(d
, rights_names
[n
].name
);
78 /** @brief Parse a rights list
79 * @param s Rights list in string form
80 * @param rp Where to store rights, or NULL to just validate
81 * @param report Nonzero to log errors
82 * @return 0 on success, non-0 if @p s is not valid
84 int parse_rights(const char *s
, rights_type
*rp
, int report
) {
90 /* You can't have no rights */
92 error(0, "empty rights string");
100 if(l
== 3 && !strncmp(s
, "all", 3))
103 for(n
= 0; n
< NRIGHTS
; ++n
)
104 if(strlen(rights_names
[n
].name
) == l
105 && !strncmp(rights_names
[n
].name
, s
, l
))
109 error(0, "unknown user right '%.*s'", (int)l
, s
);
112 r
|= rights_names
[n
].bit
;