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