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