chiark / gitweb /
--rcvbuf option; warn if -L is used
[disorder] / lib / configuration.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004, 2005, 2006, 2007 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 2 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, 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.
14  *
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
18  * USA
19  */
20
21 #ifndef CONFIGURATION_H
22 #define CONFIGURATION_H
23
24 #include <ao/ao.h>
25
26 struct real_pcre;
27
28 /* Configuration is kept in a @struct config@; the live configuration
29  * is always pointed to by @config@.  Values in @config@ are UTF-8 encoded.
30  */
31
32 /** @brief A list of strings */
33 struct stringlist {
34   /** @brief Number of strings */
35   int n;
36   /** @brief Array of strings */
37   char **s;
38 };
39
40 /** @brief A list of list of strings */
41 struct stringlistlist {
42   /** @brief Number of string lists */
43   int n;
44   /** @brief Array of string lists */
45   struct stringlist *s;
46 };
47
48 /** @brief A collection of tracks */
49 struct collection {
50   /** @brief Module that supports this collection */
51   char *module;
52   /** @brief Filename encoding */
53   char *encoding;
54   /** @brief Root directory */
55   char *root;
56 };
57
58 /** @brief A list of collections */
59 struct collectionlist {
60   /** @brief Number of collections */
61   int n;
62   /** @brief Array of collections */
63   struct collection *s;
64 };
65
66 struct namepart {
67   char *part;                           /* part */
68   struct real_pcre *re;                 /* regexp */
69   char *replace;                        /* replacement string */
70   char *context;                        /* context glob */
71   unsigned reflags;                     /* regexp flags */
72 };
73
74 struct namepartlist {
75   int n;
76   struct namepart *s;
77 };
78
79 struct transform {
80   char *type;                           /* track or dir */
81   char *context;                        /* sort or choose */
82   char *replace;                        /* substitution string */
83   struct real_pcre *re;                 /* compiled re */
84   unsigned flags;                       /* regexp flags */
85 };
86
87 struct transformlist {
88   int n;
89   struct transform *t;
90 };
91
92 /** @brief System configuration */
93 struct config {
94   /* server config */
95
96   /** @brief All players */
97   struct stringlistlist player;
98
99   /** @brief Allowed users */
100   struct stringlistlist allow;
101
102   /** @brief Scratch tracks */
103   struct stringlist scratch;
104
105   /** @brief Gap between tracks in seconds */
106   long gap;
107
108   /** @brief Maximum number of recent tracks to record in history */
109   long history;
110
111   /** @brief Trusted users */
112   struct stringlist trust;
113
114   /** @brief User for server to run as */
115   const char *user;
116
117   /** @brief Nice value for rescan subprocess */
118   long nice_rescan;
119
120   /** @brief Paths to search for plugins */
121   struct stringlist plugins;
122
123   /** @brief List of stopwords */
124   struct stringlist stopword;
125
126   /** @brief List of collections */
127   struct collectionlist collection;
128
129   /** @brief Database checkpoint byte limit */
130   long checkpoint_kbyte;
131
132   /** @brief Databsase checkpoint minimum */
133   long checkpoint_min;
134
135   /** @brief Path to mixer device */
136   char *mixer;
137
138   /** @brief Mixer channel to use */
139   char *channel;
140
141   long prefsync;                        /* preflog sync interval */
142
143   /** @brief Secondary listen address */
144   struct stringlist listen;
145
146   /** @brief Alias format string */
147   const char *alias;
148
149   /** @brief Enable server locking */
150   int lock;
151
152   /** @brief Nice value for server */
153   long nice_server;
154
155   /** @brief Nice value for speaker */
156   long nice_speaker;
157
158   /** @brief Command execute by speaker to play audio */
159   const char *speaker_command;
160
161   /** @brief Target sample format */
162   ao_sample_format sample_format;
163
164   /** @brief Sox syntax generation */
165   long sox_generation;
166
167   /** @brief Speaker backend
168    *
169    * Choices are @ref BACKEND_ALSA, @ref BACKEND_COMMAND or @ref
170    * BACKEND_NETWORK.
171    */
172   int speaker_backend;
173 #define BACKEND_ALSA 0                  /**< Use ALSA (Linux only) */
174 #define BACKEND_COMMAND 1               /**< Execute a command */
175 #define BACKEND_NETWORK 2               /**< Transmit RTP  */
176
177   /** @brief Home directory for state files */
178   const char *home;
179
180   /** @brief Login username */
181   const char *username;
182
183   /** @brief Login password */
184   const char *password;
185
186   /** @brief Address to connect to */
187   struct stringlist connect;
188
189   /** @brief Directories to search for web templates */
190   struct stringlist templates;
191
192   /** @brief Canonical URL of web interface */
193   const char *url;
194
195   /** @brief Maximum refresh interval for web interface (seconds) */
196   long refresh;
197
198   /** @brief Facilities restricted to trusted users
199    *
200    * A bitmap of @ref RESTRICT_SCRATCH, @ref RESTRICT_REMOVE and @ref
201    * RESTRICT_MOVE.
202    */
203   unsigned restrictions;                /* restrictions */
204 #define RESTRICT_SCRATCH 1              /**< Restrict scratching */
205 #define RESTRICT_REMOVE 2               /**< Restrict removal */
206 #define RESTRICT_MOVE 4                 /**< Restrict rearrangement */
207
208   /** @brief Target queue length */
209   long queue_pad;
210
211   struct namepartlist namepart;         /* transformations */
212
213   /** @brief Termination signal for subprocesses */
214   int signal;
215
216   /** @brief ALSA output device */
217   const char *device;
218   struct transformlist transform;       /* path name transformations */
219
220   struct stringlist broadcast;          /* audio broadcast address */
221   struct stringlist broadcast_from;     /* audio broadcast source address */
222
223   /* derived values: */
224   int nparts;                           /* number of distinct name parts */
225   char **parts;                         /* name part list  */
226 };
227
228 extern struct config *config;
229 /* the current configuration */
230
231 int config_read(void);
232 /* re-read config, return 0 on success or non-0 on error.
233  * Only updates @config@ if the new configuration is valid. */
234
235 char *config_get_file(const char *name);
236 /* get a filename within the home directory */
237
238 struct passwd;
239
240 char *config_userconf(const char *home, const struct passwd *pw);
241 /* get the user's own private conffile, assuming their home dir is
242  * @home@ if not null and using @pw@ otherwise */
243
244 char *config_usersysconf(const struct passwd *pw );
245 /* get the user's conffile in /etc */
246
247 char *config_private(void);
248 /* get the private config file */
249
250 extern char *configfile;
251
252 #endif /* CONFIGURATION_H */
253
254 /*
255 Local Variables:
256 c-basic-offset:2
257 comment-column:40
258 End:
259 */