mod_musicindex  1.4.1
mod_musicindex.h
Go to the documentation of this file.
1 /*
2  * mod_musicindex.h
3  * mod_musicindex
4  *
5  * $Id: mod_musicindex.h 1013 2012-09-01 17:42:41Z varenet $
6  *
7  * Created by Thibaut VARENE on Thu Mar 20 2003.
8  * Copyright (c) 2003-2006 Regis BOUDIN
9  * Copyright (c) 2003-2012 Thibaut VARENE
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 2.1,
13  * as published by the Free Software Foundation.
14  *
15  */
16 
17 #ifndef MOD_MUSICINDEX_H
18 #define MOD_MUSICINDEX_H
19 
20 #include <httpd.h>
21 #include <http_config.h>
22 #include <http_request.h>
23 #include <http_protocol.h>
24 #include <http_log.h>
25 
26 /* AP24 bw compat 2.0/2.2 */
27 #ifdef APLOG_USE_MODULE
28 APLOG_USE_MODULE(musicindex);
29 #endif
30 
31 /* Define to the address where bug reports for this package should be sent. */
32 #undef PACKAGE_BUGREPORT
33 
34 /* Define to the full name of this package. */
35 #undef PACKAGE_NAME
36 
37 /* Define to the full name and version of this package. */
38 #undef PACKAGE_STRING
39 
40 /* Define to the one symbol short name of this package. */
41 #undef PACKAGE_TARNAME
42 
43 /* Define to the version of this package. */
44 #undef PACKAGE_VERSION
45 
46 #include "mod_musicindex_config.h"
47 
48 /*
49  * Current version number & authors
50  */
51 #define MUSIC_VERSION_STRING PACKAGE_VERSION
52 #define MUSIC_AUTHORS_STRING "R. Boudin & T. Varene"
53 #define MUSIC_HEADER_STRING "mod_musicindex/" MUSIC_VERSION_STRING
54 
55 /*
56  * Compile time configuration options
57  * Comment explains what happens when they are #define'd
58  * TODO some of these should be ./configure'able
59  */
60 #undef NO_TITLE_STRIP /* Disable title pretty printing for untagged files */
61 #undef NO_BR_NOMINAL /* Disable display of nominal bitrate when available */
62 #undef BE_INSECURE /* Enable insecure auth credential leaking in urls */
63 #undef DEBUG /* Enable debug output */
64 
65 /* these are not defined on BSD */
66 #ifndef FALSE
67  #define FALSE 0
68  #define TRUE !FALSE
69 #endif
70 
71 #ifndef C_HAS_ATTRIBUTE
72  #define __attribute__(x) /* NOTHING */
73 #endif
74 
75 #ifdef C_HAS_BUILTIN_EXPECT
76  #define likely(x) __builtin_expect(!!(x), 1)
77  #define unlikely(x) __builtin_expect(!!(x), 0)
78 #else
79  #define likely(x) (x)
80  #define unlikely(x) (x)
81 #endif
82 
83 #ifdef HAVE_SYS_TIME_H
84  #define STRUCTTV struct timeval
85  #if (!defined(HAVE_TIMERSUB) && !defined(timersub))
86  #define timersub(tvp, uvp, vvp) \
87  do { \
88  (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
89  (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
90  if ((vvp)->tv_usec < 0) { \
91  (vvp)->tv_sec--; \
92  (vvp)->tv_usec += 1000000; \
93  } \
94  } while (0)
95  #endif
96 #else
97  #define STRUCTTV int
98 #endif
99 
100 /* a very common macro */
101 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
102 
108 enum {
128 };
129 
130 
131 #define SB_DEFAULT SB_URI
133 /*
134  * Flags used in mu_config struct, fields "options" and "options_not".
135  * 16 bits max.
136  */
137 
138 /* First, the flags set by the configuration */
139 #define MI_ACTIVE (1 << 0)
141 #define MI_ALLOWSTREAM (1 << 1)
142 #define MI_ALLOWDWNLD (1 << 2)
143 #define MI_ALLOWSEARCH (1 << 3)
144 #define MI_ALLOWTARBALL (1 << 4)
147 #define MI_ALLOWFETCH (MI_ALLOWSTREAM | MI_ALLOWDWNLD | MI_ALLOWTARBALL)
148 
149 /* XXX TODO : move these flags to a different parameter in the structure */
150 /* The flags set on requests */
151 #define MI_STREAM (1 << 5)
152 #define MI_ALL (1 << 6)
153 #define MI_RECURSIVE (1 << 7)
154 #define MI_RSS (1 << 8)
155 #define MI_PODCAST (1 << 9)
156 #define MI_RANDOMDIR (1 << 10)
157 #define MI_TARBALL (1 << 11)
159 #define MI_STREAMLST (MI_STREAM)
160 #define MI_STREAMALL (MI_STREAM | MI_ALL)
161 #define MI_STREAMCOOKIE (MI_STREAM | MI_COOKIEOP)
162 #define MI_STREAMRQ (MI_STREAMLST | MI_STREAMALL | MI_STREAMCOOKIE)
163 
164 #define MI_DWNLDLST (MI_TARBALL)
165 #define MI_DWNLDALL (MI_TARBALL | MI_ALL)
166 #define MI_DWNLDCOOKIE (MI_TARBALL | MI_COOKIEOP)
167 #define MI_DWNLDRQ (MI_DWNLDLST | MI_DWNLDALL | MI_DWNLDCOOKIE)
168 
169 /* The cookie-related flags */
170 #define MI_COOKIEOP (1 << 12)
171 #define MI_COOKIEADD (1 << 13)
172 #define MI_COOKIEDEL (1 << 14)
174 #define MI_COOKIEADDLST (MI_COOKIEOP | MI_COOKIEADD)
175 #define MI_COOKIEDELLST (MI_COOKIEOP | MI_COOKIEDEL)
176 #define MI_COOKIEADDALL (MI_COOKIEOP | MI_COOKIEADD | MI_ALL)
177 #define MI_COOKIEPURGE (MI_COOKIEOP | MI_COOKIEDEL | MI_ALL)
178 #define MI_COOKIESTREAM (MI_COOKIEOP | MI_STREAM)
179 #define MI_COOKIEDWNLD (MI_COOKIEOP | MI_TARBALL)
180 
181 #define MI_ALLOPS (MI_COOKIEOP | \
182  MI_COOKIEADD | \
183  MI_COOKIEDEL | \
184  MI_STREAM | \
185  MI_TARBALL | \
186  MI_ALL)
187 
188 /* Flags for internal use */
189 #define MI_QUICKPL (1 << 15)
191 /* Extended options set: Flags not stored in config options but used directly.
192  These can exceed the 16bit boundary, with care. */
193 #define MI_CUSTOM (1 << 16)
194 #define MI_ALLOWRSS (1 << 17)
196 /*** End of mu_config flags ***/
197 
198 
199 /*
200  * Flags used in mu_ent struct, field "flags".
201  * 8 bits max.
202  */
203 
204 /* Following can be cached */
205 #define EF_VBR (1 << 0)
206 /* Following can *NOT* be cached and must be updated everytime */
207 #define EF_INCACHE (1 << 1)
208 #define EF_ALLOWSTREAM (1 << 2)
209 #define EF_ALLOWDWNLD (1 << 3)
210 #define EF_ALLOWTARBALL (1 << 4)
211 #define EF_ALLOWRSS (1 << 5)
214 #define EF_FLAGSTOSAVE (EF_VBR)
215 
216 /*** End of mu_ent flags ***/
217 
218 #define MAX_STRING 1024
219 #define MAX_GENRE 64
220 #define MAX_FNAME 255
221 #define MAX_PATHNAME 4096
223 #define MI_LOG_PREFIX "[mod_musicindex] "
225 #ifndef BUILD_FOR_APACHE2
226 
227  /* some things have to be redefined for apache 1.3 to use the same declaration
228  in both apache 1&2 versions of the program */
229  #define apr_pool_t pool
231  #define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \
232  { directive, func, mconfig, where, NO_ARGS, help }
233  #define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
234  { directive, func, mconfig, where, RAW_ARGS, help }
235  #define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
236  { directive, func, mconfig, where, TAKE1, help }
237  #define AP_INIT_FLAG(directive, func, mconfig, where, help) \
238  { directive, func, mconfig, where, FLAG, help }
239 
240  #define ap_is_directory(pool, name) ap_is_directory(name)
241  #define ap_set_content_type(r, string) (r->content_type = string)
242  #define apr_pool_create(child, parent) ((*(child)) = ap_make_sub_pool(parent))
243  #define ap_sub_req_lookup_uri(p, r, ptr) ap_sub_req_lookup_uri(p, r)
244  #define REQUEST_USER(rec) (rec->connection->user)
245 
246  #define apr_pool_destroy ap_destroy_pool
247 
248  #define apr_table_get ap_table_get
249  #define apr_table_set ap_table_set
250  #define apr_table_setn ap_table_setn
251  #define apr_palloc ap_palloc
252  #define apr_pcalloc ap_pcalloc
253  #define apr_pstrdup ap_pstrdup
254  #define apr_pstrndup ap_pstrndup
255  #define apr_pstrcat ap_pstrcat
256  #define apr_psprintf ap_psprintf
257  #define apr_base64_encode_len ap_base64encode_len
258  #define apr_base64_encode ap_base64encode
259  #define apr_base64_decode_len ap_base64decode_len
260  #define apr_base64_decode ap_base64decode
261 
262 #else
263 
264 
265  #if defined(AP20)
266  /* nada */
267  #elif defined(AP22)
268  #define ap_http_method ap_http_scheme
269  #elif defined(AP24)
270  #define ap_http_method ap_http_scheme
271  #define ap_get_server_name(r) ap_get_server_name_for_url(r)
272  #else
273  #error "unknown apache API"
274  #endif
275 
276  #include <apr_strings.h>
277  #include <apr_base64.h>
278  #include <ap_compat.h>
279 
280  #ifdef APLOG_ERR
281  #undef APLOG_ERR
282  #define APLOG_ERR LOG_ERR, 0
283  #endif
284  #ifdef APLOG_WARNING
285  #undef APLOG_WARNING
286  #define APLOG_WARNING LOG_WARNING, 0
287  #endif
288  #ifdef APLOG_NOTICE
289  #undef APLOG_NOTICE
290  #define APLOG_NOTICE LOG_NOTICE, 0
291  #endif
292  #ifdef APLOG_DEBUG
293  #undef APLOG_DEBUG
294  #define APLOG_DEBUG LOG_DEBUG, 0
295  #endif
296 
297  #define REQUEST_USER(rec) (rec->user)
298 
299 #endif /* ! __BUILD_FOR_APACHE2 */
300 
305 typedef struct mu_ent {
306  const struct mu_ent *next;
307  const char *file;
308  const char *filename;
309  const char *uri;
310  const char * restrict album;
311  const char * restrict artist;
312  const char * restrict title;
313  const char * restrict genre;
314  unsigned long bitrate;
315  unsigned long size;
316  unsigned long mtime;
317  unsigned short freq;
318  unsigned short length;
319  unsigned short date;
320  unsigned char flags;
321  unsigned char track;
322  unsigned char posn;
323  signed char filetype;
324 } /* __attribute__((packed)) */ mu_ent;
325 
331 typedef struct {
332  const mu_ent *head;
333  const mu_ent *fhead;
334  unsigned long filenb;
335  unsigned long fsize;
336  unsigned short dirnb;
337 } mu_pack;
338 
339 typedef struct mu_config mu_config;
340 
345 typedef struct {
352  void* (*opendir)(request_rec *r, mu_pack *const pack,
353  const char * const filename, const char * const uri, unsigned long soptions);
354 
363  const char* (*readdir)(void *dir);
364 
367  void (*closedir)(void *dir);
368 
370  mu_ent* (*make_entry)(request_rec *r, apr_pool_t *pool, FILE *const in,
371  const char *const filename);
372 
374  void (*write)(request_rec *r, const mu_ent *const entry,
375  const char * const name);
376 
379  void (*prologue)(request_rec *r);
380 
383  void (*epilogue)(request_rec *r);
384 } cache_backend;
385 
388 struct mu_config {
389  /* non settings, these are piggy-backed on the config struct */
390  char * restrict search;
391  const char * restrict custom_list;
393  /* actual settings */
394  const char * restrict title;
395  const char * restrict directory;
396  const char * restrict css;
397  const char * restrict iceserver;
399  const cache_backend * restrict cache;
400  void * restrict cache_setup;
402  signed short dir_per_line;
403  unsigned short cookie_life;
404  short rss_items;
406  unsigned short options;
407  unsigned short options_not;
409  unsigned short sets;
411  unsigned char order[SB_MAX+1];
412  unsigned char fields[SB_MAX+1];
413 };
414 
415 
416 /* i18n stuff */
417 #ifdef HAVE_GETTEXT
418  #include <libintl.h>
419  #define _(String) gettext(String)
420 #else
421  #define _(String) String
422 #endif /* HAVE_GETTEXT */
423 
424 #define mi_rerror(format, ...) \
425  ap_log_rerror(APLOG_MARK, APLOG_ERR, r, MI_LOG_PREFIX "(%s) " format, __func__, ## __VA_ARGS__)
426 #define mi_serror(format, ...) \
427  ap_log_error(APLOG_MARK, APLOG_ERR, s, MI_LOG_PREFIX "(%s) " format, __func__, ## __VA_ARGS__)
428 
429 /* this could arguably use APLOG_DEBUG but in most configurations this is never logged. Use it later ;-) */
430 #ifdef DEBUG
431  #define mi_rdebug(format, ...) \
432  ap_log_rerror(APLOG_MARK, APLOG_NOTICE, r, MI_LOG_PREFIX "(%s) " format, __func__, ## __VA_ARGS__)
433 #else
434  #define mi_rdebug(format, ...) /* nothing */
435 #endif
436 
437 extern module MODULE_VAR_EXPORT musicindex_module;
438 
439 #endif /* MOD_MUSICINDEX_H */