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