chiark / gitweb /
Build fixes for FreeBSD
[disorder] / lib / configuration.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004-2009 Richard Kettlewell
4  *
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 3 of the License, or
8  * (at your option) any later version.
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  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /** @file lib/configuration.h
19  * @brief Configuration file support
20  */
21
22 #ifndef CONFIGURATION_H
23 #define CONFIGURATION_H
24
25 #include <pcre.h>
26
27 #include "speaker-protocol.h"
28 #include "rights.h"
29
30 struct uaudio;
31
32 /* Configuration is kept in a @struct config@; the live configuration
33  * is always pointed to by @config@.  Values in @config@ are UTF-8 encoded.
34  */
35
36 /** @brief A list of strings */
37 struct stringlist {
38   /** @brief Number of strings */
39   int n;
40   /** @brief Array of strings */
41   char **s;
42 };
43
44 /** @brief A list of list of strings */
45 struct stringlistlist {
46   /** @brief Number of string lists */
47   int n;
48   /** @brief Array of string lists */
49   struct stringlist *s;
50 };
51
52 /** @brief A collection of tracks */
53 struct collection {
54   /** @brief Module that supports this collection */
55   char *module;
56   /** @brief Filename encoding */
57   char *encoding;
58   /** @brief Root directory */
59   char *root;
60 };
61
62 /** @brief A list of collections */
63 struct collectionlist {
64   /** @brief Number of collections */
65   int n;
66   /** @brief Array of collections */
67   struct collection *s;
68 };
69
70 struct namepart {
71   char *part;                           /* part */
72   pcre *re;                             /* regexp */
73   char *replace;                        /* replacement string */
74   char *context;                        /* context glob */
75   unsigned reflags;                     /* regexp flags */
76 };
77
78 struct namepartlist {
79   int n;
80   struct namepart *s;
81 };
82
83 struct transform {
84   char *type;                           /* track or dir */
85   char *context;                        /* sort or choose */
86   char *replace;                        /* substitution string */
87   pcre *re;                             /* compiled re */
88   unsigned flags;                       /* regexp flags */
89 };
90
91 struct transformlist {
92   int n;
93   struct transform *t;
94 };
95
96 /** @brief System configuration */
97 struct config {
98   /* server config */
99
100   /** @brief Authorization algorithm */
101   char *authorization_algorithm;
102   
103   /** @brief All players */
104   struct stringlistlist player;
105
106   /** @brief All tracklength plugins */
107   struct stringlistlist tracklength;
108
109   /** @brief Allowed users */
110   struct stringlistlist allow;
111
112   /** @brief Scratch tracks */
113   struct stringlist scratch;
114
115   /** @brief Gap between tracks in seconds */
116   long gap;
117
118   /** @brief Maximum number of recent tracks to record in history */
119   long history;
120
121   /** @brief Expiry limit for noticed.db */
122   long noticed_history;
123   
124   /** @brief Trusted users */
125   struct stringlist trust;
126
127   /** @brief User for server to run as */
128   const char *user;
129
130   /** @brief Nice value for rescan subprocess */
131   long nice_rescan;
132
133   /** @brief Paths to search for plugins */
134   struct stringlist plugins;
135
136   /** @brief List of stopwords */
137   struct stringlist stopword;
138
139   /** @brief List of collections */
140   struct collectionlist collection;
141
142   /** @brief Database checkpoint byte limit */
143   long checkpoint_kbyte;
144
145   /** @brief Databsase checkpoint minimum */
146   long checkpoint_min;
147
148   /** @brief Path to mixer device */
149   char *mixer;
150
151   /** @brief Mixer channel to use */
152   char *channel;
153
154   long prefsync;                        /* preflog sync interval */
155
156   /** @brief Secondary listen address */
157   struct stringlist listen;
158
159   /** @brief Alias format string */
160   const char *alias;
161
162   /** @brief Enable server locking */
163   int lock;
164
165   /** @brief Nice value for server */
166   long nice_server;
167
168   /** @brief Nice value for speaker */
169   long nice_speaker;
170
171   /** @brief Command execute by speaker to play audio */
172   const char *speaker_command;
173
174   /** @brief Target sample format */
175   struct stream_header sample_format;
176
177   /** @brief Sox syntax generation */
178   long sox_generation;
179
180   /** @brief API used to play sound */
181   const char *api;
182
183   /** @brief Home directory for state files */
184   const char *home;
185
186   /** @brief Login username */
187   const char *username;
188
189   /** @brief Login password */
190   const char *password;
191
192   /** @brief Address to connect to */
193   struct stringlist connect;
194
195   /** @brief Directories to search for web templates */
196   struct stringlist templates;
197
198   /** @brief Canonical URL of web interface */
199   char *url;
200
201   /** @brief Short display limit */
202   long short_display;
203
204   /** @brief Maximum refresh interval for web interface (seconds) */
205   long refresh;
206
207   /** @brief Facilities restricted to trusted users
208    *
209    * A bitmap of @ref RESTRICT_SCRATCH, @ref RESTRICT_REMOVE and @ref
210    * RESTRICT_MOVE.
211    */
212   unsigned restrictions;                /* restrictions */
213 #define RESTRICT_SCRATCH 1              /**< Restrict scratching */
214 #define RESTRICT_REMOVE 2               /**< Restrict removal */
215 #define RESTRICT_MOVE 4                 /**< Restrict rearrangement */
216
217   /** @brief Target queue length */
218   long queue_pad;
219
220   /** @brief Minimum time between a track being played again */
221   long replay_min;
222   
223   struct namepartlist namepart;         /* transformations */
224
225   /** @brief Termination signal for subprocesses */
226   int signal;
227
228   /** @brief ALSA output device */
229   const char *device;
230   struct transformlist transform;       /* path name transformations */
231
232   /** @brief Address to send audio data to */
233   struct stringlist broadcast;
234
235   /** @brief Source address for network audio transmission */
236   struct stringlist broadcast_from;
237
238   /** @brief TTL for multicast packets */
239   long multicast_ttl;
240
241   /** @brief Whether to loop back multicast packets */
242   int multicast_loop;
243
244   /** @brief Login lifetime in seconds */
245   long cookie_login_lifetime;
246
247   /** @brief Signing key lifetime in seconds */
248   long cookie_key_lifetime;
249
250   /** @brief Default rights for a new user */
251   char *default_rights;
252
253   /** @brief Path to sendmail executable */
254   char *sendmail;
255
256   /** @brief SMTP server for sending mail */
257   char *smtp_server;
258
259   /** @brief Origin address for outbound mail */
260   char *mail_sender;
261
262   /** @brief Maximum number of tracks in response to 'new' */
263   long new_max;
264
265   /** @brief Minimum interval between password reminder emails */
266   long reminder_interval;
267
268   /** @brief Whether to allow user management over TCP */
269   int remote_userman;
270
271   /** @brief Maximum age of biased-up tracks */
272   long new_bias_age;
273
274   /** @brief Maximum bias */
275   long new_bias;
276   
277   /* derived values: */
278   int nparts;                           /* number of distinct name parts */
279   char **parts;                         /* name part list  */
280
281   /* undocumented, for testing only */
282   long dbversion;
283 };
284
285 extern struct config *config;
286 /* the current configuration */
287
288 int config_read(int server);
289 /* re-read config, return 0 on success or non-0 on error.
290  * Only updates @config@ if the new configuration is valid. */
291
292 char *config_get_file2(struct config *c, const char *name);
293 char *config_get_file(const char *name);
294 /* get a filename within the home directory */
295
296 struct passwd;
297
298 char *config_userconf(const char *home, const struct passwd *pw);
299 /* get the user's own private conffile, assuming their home dir is
300  * @home@ if not null and using @pw@ otherwise */
301
302 char *config_usersysconf(const struct passwd *pw );
303 /* get the user's conffile in /etc */
304
305 char *config_private(void);
306 /* get the private config file */
307
308 extern char *configfile;
309 extern int config_per_user;
310
311 extern const struct uaudio *const *config_uaudio_apis;
312
313 #endif /* CONFIGURATION_H */
314
315 /*
316 Local Variables:
317 c-basic-offset:2
318 comment-column:40
319 End:
320 */