check_wav: return error on premature end of file.
[paraslash.git] / db.h
1 /*
2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file db.h data structures common to all audio file selectors */
20
21 #include <sys/select.h>
22
23
24 int find_audio_files(const char *dirname, int (*f)(const char *, const char *));
25
26 /**
27 * describes one supported audio file selector
28 *
29 * There is one such struct for each supported selector. During the startup
30 * part of para_server the \a init() function of the activated selector gets
31 * called which fills in all other function pointers.
32 *
33 */
34 struct audio_file_selector {
35 /**
36 * name name of this selector
37 */
38 const char *name;
39 /**
40 * the init routine of the selector
41 *
42 * It should check its command line options and do all necessary initialization
43 * like connecting to a database server.
44 *
45 * A negative return value indicates an initialization error and means that
46 * this selector should be ignored for now (it may later be activated again via
47 * the chs command).
48 *
49 * If \a init() returns success (non-negative return value), it must have
50 * initialized in all non-optional function pointers of the given selector
51 * struct. Moreover, \a cmd_list must point to a NULL-terminated array which
52 * holds the list of all commands that are supported by this selector.
53 */
54 int (*init)(struct audio_file_selector *self);
55 /**
56 * list of commands supported by this selector
57 */
58 struct server_command *cmd_list;
59 /**
60 * pointer to function returning list of at most \a num audio files to be
61 * streamed next
62 *
63 * \a get_audio_file_list() must return a pointer to a array of at most \a num
64 * char* pointers (terminated by a NULL pointer), or NULL on errors. Both the
65 * array and its contents must be dynamically allocated and are freed by the
66 * caller.
67 *
68 */
69 char **(*get_audio_file_list)(unsigned int num);
70 /**
71 *
72 * the update hook
73 *
74 * The \a update_audio_file pointer is optional and need not be supplied. In this
75 * case it is not neccessary to init this pointer from within init(). If
76 * \a update_audio_file is non-NULL, the function it points to gets called
77 * whenever a new audio file was successfully loaded and is going to be
78 * streamed by any of paraslash's senders. The full path of the audio file is
79 * passed \a update_audio_file().
80 *
81 */
82 void (*update_audio_file)(char *audio_file);
83 /**
84 *
85 * shutdown this selector and free all resources
86 *
87 * This gets called whenever the audio file selector changes. The reason for
88 * this change might be that some user sent the chs command, that para_server
89 * receives the HUP signal, or that para_server shuts down. It is assumed to
90 * succeed.
91 */
92 void (*shutdown)(void);
93 /**
94 *
95 * add file descriptors to fd_sets
96 *
97 * The pre_select function of the activated selector gets called just before
98 * para_server enters its main select loop. The selector may add its own file
99 * descriptors to the \a rfds or the \a wfds set.
100 *
101 * \return The highest-numbered file descriptor which was added to either of
102 * the two fd sets (or -1 if no file descriptors were added).
103 *
104 * \sa select(2)
105 */
106 int (*pre_select)(fd_set *rfds, fd_set *wfds);
107 /**
108 * handle the file descriptors which are ready for I/O
109 *
110 * If the pre_select hook added one ore more file descriptors to the read or write
111 * set, this is the hook to check the result and do any I/O on those descriptors
112 * which are ready for reading/writing.
113 */
114 void (*post_select)(fd_set *rfds, fd_set *wfds);
115 /**
116 * each selector has its private data pointer */
117 void *private_data;
118 };
119
120 int mysql_selector_init(struct audio_file_selector*);
121 int playlist_selector_init(struct audio_file_selector*);
122 int random_selector_init(struct audio_file_selector*);
123