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