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