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