Commit | Line | Data |
---|---|---|
05b75f8d RK |
1 | /* |
2 | * This file is part of DisOrder | |
8a886602 | 3 | * Copyright (C) 2008-2012 Richard Kettlewell |
05b75f8d | 4 | * |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
05b75f8d | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
05b75f8d RK |
8 | * (at your option) any later version. |
9 | * | |
e7eb3a27 RK |
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 | * | |
05b75f8d | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
05b75f8d | 17 | */ |
132a5a4a RK |
18 | /** @file server/disorder-server.h |
19 | * @brief Definitions for server and allied utilities | |
20 | */ | |
05b75f8d RK |
21 | |
22 | #ifndef DISORDER_SERVER_H | |
23 | #define DISORDER_SERVER_H | |
24 | ||
25 | #include "common.h" | |
26 | ||
27 | #include <db.h> | |
28 | #include <errno.h> | |
29 | #include <fcntl.h> | |
30 | #include <fnmatch.h> | |
31 | #include <gcrypt.h> | |
32 | #include <getopt.h> | |
33 | #include <grp.h> | |
34 | #include <locale.h> | |
35 | #include <netinet/in.h> | |
05b75f8d RK |
36 | #include <pwd.h> |
37 | #include <signal.h> | |
38 | #include <stddef.h> | |
39 | #include <sys/socket.h> | |
40 | #include <sys/stat.h> | |
41 | #include <sys/time.h> | |
42 | #include <sys/types.h> | |
43 | #include <sys/un.h> | |
31e2a93e | 44 | #include <sys/resource.h> |
05b75f8d RK |
45 | #include <syslog.h> |
46 | #include <time.h> | |
47 | #include <unistd.h> | |
48 | ||
49 | #include "addr.h" | |
50 | #include "authhash.h" | |
51 | #include "base64.h" | |
52 | #include "cache.h" | |
53 | #include "charset.h" | |
54 | #include "configuration.h" | |
55 | #include "cookies.h" | |
56 | #include "defs.h" | |
57 | #include "disorder.h" | |
58 | #include "event.h" | |
59 | #include "eventlog.h" | |
60 | #include "eventlog.h" | |
61 | #include "hash.h" | |
62 | #include "hex.h" | |
63 | #include "inputline.h" | |
64 | #include "kvp.h" | |
65 | #include "log.h" | |
66 | #include "logfd.h" | |
67 | #include "mem.h" | |
68 | #include "mime.h" | |
05b75f8d RK |
69 | #include "printf.h" |
70 | #include "queue.h" | |
71 | #include "random.h" | |
72 | #include "rights.h" | |
73 | #include "sendmail.h" | |
74 | #include "sink.h" | |
75 | #include "speaker-protocol.h" | |
76 | #include "split.h" | |
77 | #include "syscalls.h" | |
78 | #include "table.h" | |
79 | #include "trackdb-int.h" | |
80 | #include "trackdb.h" | |
81 | #include "trackname.h" | |
b50cfb8a | 82 | #include "uaudio.h" |
05b75f8d RK |
83 | #include "unicode.h" |
84 | #include "user.h" | |
85 | #include "vector.h" | |
86 | #include "version.h" | |
87 | #include "wstat.h" | |
88 | ||
b50cfb8a RK |
89 | extern const struct uaudio *api; |
90 | ||
05b75f8d RK |
91 | void daemonize(const char *tag, int fac, const char *pidfile); |
92 | /* Go into background. Send stdout/stderr to syslog. | |
93 | * If @pri@ is non-null, it should be "facility.level" | |
94 | * If @tag@ is non-null, it is used as a tag to each message | |
95 | * If @pidfile@ is non-null, the PID is written to that file. | |
96 | */ | |
97 | ||
98 | void quit(ev_source *ev) attribute((noreturn)); | |
99 | /* terminate the daemon */ | |
100 | ||
37f29ce9 RK |
101 | int reconfigure(ev_source *ev, unsigned flags); |
102 | /* reconfigure */ | |
103 | ||
104 | void reset_sockets(ev_source *ev); | |
105 | ||
106 | /** @brief Set when starting server */ | |
107 | #define RECONFIGURE_FIRST 0x0001 | |
108 | ||
109 | /** @brief Set when reloading after SIGHUP etc */ | |
110 | #define RECONFIGURE_RELOADING 0x0002 | |
05b75f8d | 111 | |
74f77840 RK |
112 | void dbparams_check(void); |
113 | ||
05b75f8d RK |
114 | extern struct queue_entry qhead; |
115 | /* queue of things yet to be played. the head will be played | |
116 | * soonest. */ | |
117 | ||
118 | extern struct queue_entry phead; | |
119 | /* things that have been played in the past. the head is the oldest. */ | |
120 | ||
121 | extern long pcount; | |
122 | ||
123 | void queue_read(void); | |
124 | /* read the queue in. Calls @fatal@ on error. */ | |
125 | ||
126 | void queue_write(void); | |
127 | /* write the queue out. Calls @fatal@ on error. */ | |
128 | ||
129 | void recent_read(void); | |
130 | /* read the recently played list in. Calls @fatal@ on error. */ | |
131 | ||
132 | void recent_write(void); | |
133 | /* write the recently played list out. Calls @fatal@ on error. */ | |
134 | ||
135 | struct queue_entry *queue_add(const char *track, const char *submitter, | |
7a853280 RK |
136 | int where, const char *target, |
137 | enum track_origin origin); | |
05b75f8d RK |
138 | #define WHERE_START 0 /* Add to head of queue */ |
139 | #define WHERE_END 1 /* Add to end of queue */ | |
140 | #define WHERE_BEFORE_RANDOM 2 /* End, or before random track */ | |
7a853280 | 141 | #define WHERE_AFTER 3 /* After the target */ |
4857234e | 142 | #define WHERE_NOWHERE 4 /* Don't add to queue at all */ |
05b75f8d RK |
143 | /* add an entry to the queue. Return a pointer to the new entry. */ |
144 | ||
145 | void queue_remove(struct queue_entry *q, const char *who); | |
146 | /* remove an from the queue */ | |
147 | ||
148 | struct queue_entry *queue_find(const char *key); | |
149 | /* find a track in the queue by name or ID */ | |
150 | ||
151 | void queue_played(struct queue_entry *q); | |
152 | /* add @q@ to the played list */ | |
153 | ||
154 | int queue_move(struct queue_entry *q, int delta, const char *who); | |
155 | /* move element @q@ in the queue towards the front (@delta@ > 0) or towards the | |
156 | * back (@delta@ < 0). The return value is the leftover delta once we've hit | |
157 | * the end in whichever direction we were going. */ | |
158 | ||
159 | void queue_moveafter(struct queue_entry *target, | |
160 | int nqs, struct queue_entry **qs, const char *who); | |
161 | /* Move all the elements QS to just after TARGET, or to the head if | |
162 | * TARGET=0. */ | |
163 | ||
164 | void queue_fix_sofar(struct queue_entry *q); | |
165 | /* Fix up the sofar field for standalone players */ | |
166 | ||
167 | void schedule_init(ev_source *ev); | |
168 | const char *schedule_add(ev_source *ev, | |
169 | struct kvp *actiondata); | |
170 | int schedule_del(const char *id); | |
171 | struct kvp *schedule_get(const char *id); | |
172 | char **schedule_list(int *neventsp); | |
173 | ||
174 | extern struct queue_entry *playing; /* playing track or 0 */ | |
175 | extern int paused; /* non-0 if paused */ | |
176 | ||
177 | void play(ev_source *ev); | |
178 | /* try to play something, if playing is enabled and nothing is playing | |
179 | * already */ | |
180 | ||
9439cdab RK |
181 | /** @brief Return true if @p represents a true flag */ |
182 | int flag_enabled(const char *s); | |
183 | ||
05b75f8d RK |
184 | int playing_is_enabled(void); |
185 | /* return true iff playing is enabled */ | |
186 | ||
187 | void enable_playing(const char *who, ev_source *ev); | |
188 | /* enable playing */ | |
189 | ||
9439cdab | 190 | void disable_playing(const char *who, ev_source *ev); |
05b75f8d RK |
191 | /* disable playing. */ |
192 | ||
193 | int random_is_enabled(void); | |
194 | /* return true iff random play is enabled */ | |
195 | ||
196 | void enable_random(const char *who, ev_source *ev); | |
197 | /* enable random play */ | |
198 | ||
9439cdab | 199 | void disable_random(const char *who, ev_source *ev); |
05b75f8d RK |
200 | /* disable random play */ |
201 | ||
202 | void scratch(const char *who, const char *id); | |
203 | /* scratch the playing track. @who@ identifies the scratcher. @id@ is | |
204 | * the ID or a null pointer. */ | |
205 | ||
206 | void quitting(ev_source *ev); | |
207 | /* called to terminate current track and shut down speaker process | |
208 | * when quitting */ | |
209 | ||
210 | void speaker_setup(ev_source *ev); | |
211 | /* set up the speaker subprocess */ | |
212 | ||
213 | void speaker_reload(void); | |
214 | /* Tell the speaker process to reload its configuration. */ | |
215 | ||
216 | int pause_playing(const char *who); | |
217 | /* Pause the current track. Return 0 on success, -1 on error. WHO | |
218 | * can be 0. */ | |
219 | ||
220 | void resume_playing(const char *who); | |
221 | /* Resume after a pause. WHO can be 0. */ | |
222 | ||
223 | int prepare(ev_source *ev, | |
224 | struct queue_entry *q); | |
225 | /* Prepare to play Q */ | |
226 | ||
227 | void abandon(ev_source *ev, | |
228 | struct queue_entry *q); | |
229 | /* Abandon a possibly-prepared track. */ | |
230 | ||
231 | void add_random_track(ev_source *ev); | |
232 | /* If random play is enabled then try to add a track to the queue. */ | |
233 | ||
234 | int server_start(ev_source *ev, int pf, | |
235 | size_t socklen, const struct sockaddr *sa, | |
de37b640 RK |
236 | const char *name, |
237 | int privileged); | |
05b75f8d RK |
238 | /* start listening. Return the fd. */ |
239 | ||
240 | int server_stop(ev_source *ev, int fd); | |
241 | /* Stop listening on @fd@ */ | |
242 | ||
b0116b5c RK |
243 | void rtp_request(const struct sockaddr_storage *sa); |
244 | void rtp_request_cancel(const struct sockaddr_storage *sa); | |
245 | ||
05b75f8d RK |
246 | extern int volume_left, volume_right; /* last known volume */ |
247 | ||
248 | extern int wideopen; /* blindly accept all logins */ | |
249 | ||
250 | /* plugins */ | |
251 | ||
252 | struct plugin; | |
253 | ||
254 | typedef void *plugin_handle; | |
255 | typedef void function_t(void); | |
256 | ||
257 | const struct plugin *open_plugin(const char *name, | |
258 | unsigned flags); | |
259 | #define PLUGIN_FATAL 0x0001 /* fatal() on error */ | |
260 | /* Open a plugin. Returns a null pointer on error or a handle to it | |
261 | * on success. */ | |
262 | ||
263 | function_t *get_plugin_function(const struct plugin *handle, | |
264 | const char *symbol); | |
265 | const void *get_plugin_object(const struct plugin *handle, | |
266 | const char *symbol); | |
267 | /* Look up a function or an object in a plugin */ | |
268 | ||
269 | /* track length computation ***************************************************/ | |
270 | ||
271 | long tracklength(const char *plugin, const char *track, const char *path); | |
272 | ||
273 | /* collection interface *******************************************************/ | |
274 | ||
275 | void scan(const char *module, const char *root); | |
276 | /* write a list of path names below @root@ to standard output. */ | |
277 | ||
278 | int check(const char *module, const char *root, const char *path); | |
279 | /* Recheck a track, given its root and path name. Return 1 if it | |
280 | * exists, 0 if it does not exist and -1 if an error occurred. */ | |
281 | ||
282 | /* notification interface *****************************************************/ | |
283 | ||
284 | void notify_play(const char *track, | |
285 | const char *submitter); | |
286 | /* we're going to play @track@. It was submitted by @submitter@ | |
287 | * (might be a null pointer) */ | |
288 | ||
289 | void notify_scratch(const char *track, | |
290 | const char *submitter, | |
291 | const char *scratcher, | |
292 | int seconds); | |
293 | /* @scratcher@ scratched @track@ after @seconds@. It was submitted by | |
294 | * @submitter@ (might be a null pointer) */ | |
295 | ||
296 | void notify_not_scratched(const char *track, | |
297 | const char *submitter); | |
298 | /* @track@ (submitted by @submitter@, which might be a null pointer) | |
299 | * was not scratched. */ | |
300 | ||
301 | void notify_queue(const char *track, | |
302 | const char *submitter); | |
303 | /* @track@ was queued by @submitter@ */ | |
304 | ||
305 | void notify_queue_remove(const char *track, | |
306 | const char *remover); | |
307 | /* @track@ removed from the queue by @remover@ (never a null pointer) */ | |
308 | ||
309 | void notify_queue_move(const char *track, | |
310 | const char *mover); | |
311 | /* @track@ moved in the queue by @mover@ (never a null pointer) */ | |
312 | ||
313 | void notify_pause(const char *track, | |
314 | const char *pauser); | |
315 | /* TRACK was paused by PAUSER (might be a null pointer) */ | |
316 | ||
317 | void notify_resume(const char *track, | |
318 | const char *resumer); | |
319 | /* TRACK was resumed by PAUSER (might be a null pointer) */ | |
320 | ||
321 | /* track playing **************************************************************/ | |
322 | ||
323 | unsigned long play_get_type(const struct plugin *pl); | |
324 | /* Get the type word for this plugin */ | |
325 | ||
326 | void *play_prefork(const struct plugin *pl, | |
327 | const char *track); | |
328 | /* Call the prefork function for PL and return the user data */ | |
329 | ||
330 | void play_track(const struct plugin *pl, | |
331 | const char *const *parameters, | |
332 | int nparameters, | |
333 | const char *path, | |
334 | const char *track); | |
335 | /* play a track. Called inside a fork. */ | |
336 | ||
337 | void play_cleanup(const struct plugin *pl, void *data); | |
338 | /* Call the cleanup function for PL if necessary */ | |
339 | ||
340 | int play_pause(const struct plugin *pl, long *playedp, void *data); | |
341 | /* Pause track. */ | |
342 | ||
343 | void play_resume(const struct plugin *pl, void *data); | |
344 | /* Resume track. */ | |
345 | ||
5bac5b78 RK |
346 | /* background process support *************************************************/ |
347 | ||
348 | /** @brief Child process parameters */ | |
349 | struct pbgc_params { | |
350 | /** @brief Length of player command */ | |
351 | int argc; | |
352 | /** @brief Player command */ | |
353 | const char **argv; | |
5bac5b78 RK |
354 | /** @brief Raw track name */ |
355 | const char *rawpath; | |
356 | }; | |
357 | ||
358 | /** @brief Callback to play or prepare a track | |
359 | * @param q Track to play or decode | |
360 | * @param bgdata User data pointer | |
361 | * @return Exit code | |
362 | */ | |
363 | typedef int play_background_child_fn(struct queue_entry *q, | |
364 | const struct pbgc_params *params, | |
365 | void *bgdata); | |
366 | ||
367 | int play_background(ev_source *ev, | |
368 | const struct stringlist *player, | |
369 | struct queue_entry *q, | |
370 | play_background_child_fn *child, | |
371 | void *bgdata); | |
372 | ||
373 | /* Return values from start(), prepare() and play_background() */ | |
374 | ||
375 | #define START_OK 0 /**< @brief Succeeded. */ | |
376 | #define START_HARDFAIL 1 /**< @brief Track is broken. */ | |
377 | #define START_SOFTFAIL 2 /**< @brief Track OK, system (temporarily?) broken */ | |
378 | ||
18f94073 RK |
379 | void periodic_mount_check(ev_source *ev_); |
380 | ||
8138da17 RK |
381 | /** @brief How often to check for new (or old) filesystems */ |
382 | # define MOUNT_CHECK_INTERVAL 5 /* seconds */ | |
18f94073 | 383 | |
05b75f8d RK |
384 | #endif /* DISORDER_SERVER_H */ |
385 | ||
386 | /* | |
387 | Local Variables: | |
388 | c-basic-offset:2 | |
389 | comment-column:40 | |
390 | fill-column:79 | |
391 | indent-tabs-mode:nil | |
392 | End: | |
393 | */ |