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