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