Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

mod_musicindex.c

Go to the documentation of this file.
00001 /*
00002  *  mod_musicindex.c
00003  *  mod_musicindex
00004  *
00005  *  $Id: mod_musicindex.c,v 1.42 2003/10/28 20:50:11 boudinr Exp $
00006  *
00007  *  Created by Regis BOUDIN on Sat Dec 28 2002.
00008  *  Copyright (c) 2003 Regis BOUDIN
00009  *  Copyright (c) 2003 Thibaut VARENE
00010  * 
00011  *  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU Lesser General Public License as published by
00013  *  the Free Software Foundation; either version 2.1, or (at your option)
00014  *  any later version.
00015  *
00016  */
00017 
00018 
00040 #include "mod_musicindex.h"
00041 #include "playlist.h"
00042 #include "config.h"
00043 #include "html.h"
00044 #include "inf.h"
00045 
00046 static int handle_musicindex(request_rec * r)
00047 {
00048         char *ifile;
00049         /* Get the module configuration */
00050         mu_config *conf = (mu_config *)
00051                 ap_get_module_config(r->per_dir_config, &musicindex_module);
00052 
00053 #ifdef __BUILD_FOR_APACHE2
00054         /* This test is necessary for apache 2 */
00055         if(strcmp(r->handler,DIR_MAGIC_TYPE)) {
00056                 return DECLINED;
00057         }
00058 #endif
00059 
00060         r->allowed |= (1 << M_GET);
00061         /* if the request is not a GET and the module is not active, let the dir
00062         to another module */
00063         if ((r->method_number != M_GET) || (!(conf->options & MI_ACTIVE)))
00064                 return DECLINED;
00065 
00066         /* This part mostly comes from mod_autoindex. If the requested dir does
00067         not end with a '/', generate a new request with it */
00068         if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') {
00069                 if (r->args != NULL)
00070                         ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
00071                       "/", "?", r->args, NULL);
00072                 else
00073                         ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
00074                       "/", NULL);
00075 
00076                 ap_table_setn(r->headers_out, "Location",
00077                 ap_construct_url(r->pool, ifile, r));
00078                 return HTTP_MOVED_PERMANENTLY;
00079         }
00080 
00081         /* Depending on parameters from the HTTP request, call the adequate
00082         function to generate either a webpage or a m3u playlist */
00083         switch (treat_args(r, conf)) {
00084                 case 'A':
00085                         return musicindex_directory(r, conf);
00086                 case 'P':
00087                         return playlist_directory(r, conf);
00088                 case 'L':
00089                         return playlist_selected(r, conf);
00090                 default:
00091                         return 0;
00092         }
00093 
00094 }
00095 
00105 int handle_mp3(request_rec * r)
00106 {
00107         mu_config *conf = (mu_config *)
00108                 ap_get_module_config(r->per_dir_config, &musicindex_module);
00109 
00110 #ifdef __BUILD_FOR_APACHE2
00111         /* This test is necessary for apache 2 */
00112         if(strcmp(r->handler,"audio/mpeg")) {
00113                 return DECLINED;
00114         }
00115 #endif
00116 
00117         if (!(conf->options&(MI_ALLOWSTREAM|MI_ALLOWDWNLD)))
00118                 return HTTP_FORBIDDEN;
00119         return DECLINED;
00120 }
00121 
00131 int handle_ogg(request_rec *r)
00132 {
00133         mu_config *conf = (mu_config *)
00134                 ap_get_module_config(r->per_dir_config, &musicindex_module);
00135 
00136 #ifdef __BUILD_FOR_APACHE2
00137         /* This test is necessary for apache 2 */
00138         if((strcmp(r->handler,"application/ogg")) && (strcmp(r->handler,"audio/x-ogg"))) {
00139                 return DECLINED;
00140         }
00141 #endif
00142 
00143         if (!(conf->options&(MI_ALLOWSTREAM|MI_ALLOWDWNLD)))
00144                 return HTTP_FORBIDDEN;
00145         return DECLINED;
00146 }
00147 
00148 const command_rec musicindex_cmds[] = {
00149         {"MusicSortOrder", sort_order, NULL, OR_INDEXES, RAW_ARGS,
00150                 "can be : title album artist track disc length bitrate filetype genre"},
00151         {"MusicFields", set_fields, NULL, OR_INDEXES, RAW_ARGS,
00152                 "can be : title album artist track disc length bitrate filetype genre"},
00153         {"MusicAllowStream", allow_stream, NULL, OR_INDEXES, NO_ARGS,
00154                 "Enable streaming"},
00155         {"MusicAllowDownload", allow_download, NULL, OR_INDEXES, NO_ARGS,
00156                 "Enable download"},
00157         {"MusicAllowSearch", allow_search, NULL, OR_INDEXES, NO_ARGS,
00158                 "Enable searching (EXPERIMENTAL)"},
00159         {"MusicLister", music_lister, NULL, OR_INDEXES, NO_ARGS,
00160                 "Enable the Musicindex maker"},
00161         {"MusicCachePath", set_cache_path, NULL, OR_INDEXES, TAKE1,
00162                 "Set the cache absolute path, without trailing '/'."},
00163         {"MusicPageTitle", set_page_title, NULL, OR_INDEXES, TAKE1,
00164                 "Set the root title of the page."},
00165         {NULL}
00166 };
00167 
00168 #ifndef __BUILD_FOR_APACHE2
00169 
00170 const handler_rec musicindex_handlers[] = {
00171         {DIR_MAGIC_TYPE, handle_musicindex},
00172         {"audio/mpeg", handle_mp3},
00173         {"audio/x-ogg", handle_ogg},
00174         {"application/ogg", handle_ogg},
00175         {NULL}
00176 };
00177 
00178 module MODULE_VAR_EXPORT musicindex_module = {
00179         STANDARD_MODULE_STUFF,
00180         NULL,                           
00181         create_musicindex_config,       
00182         merge_musicindex_configs,       
00183         NULL,                           
00184         NULL,                           
00185         musicindex_cmds,                
00186         musicindex_handlers,            
00187         NULL,                           
00188         NULL,                           
00189         NULL,                           
00190         NULL,                           
00191         NULL,                           
00192         NULL,                           
00193         NULL,                           
00194         NULL,                           
00195         NULL,                           
00196         NULL,                           
00197         NULL                            
00198 };
00199 
00200 #else
00201 
00202 static void register_hooks(apr_pool_t *p)
00203 {
00204     ap_hook_handler(handle_musicindex,NULL,NULL,APR_HOOK_FIRST);
00205     ap_hook_handler(handle_mp3,NULL,NULL,APR_HOOK_FIRST);
00206     ap_hook_handler(handle_ogg,NULL,NULL,APR_HOOK_FIRST);
00207 }
00208 
00209 module AP_MODULE_DECLARE_DATA musicindex_module = {
00210     STANDARD20_MODULE_STUFF,
00211     create_musicindex_config,   /* create per-directory config structure */
00212     merge_musicindex_configs,   /* merge per-directory config structures */
00213     NULL,                       /* create per-server config structure */
00214     NULL,                       /* merge per-server config structures */
00215     musicindex_cmds,            /* command apr_table_t */
00216     register_hooks              /* register hooks */
00217 };
00218 
00219 #endif

Generated on Thu Oct 30 13:50:29 2003 for mod_musicindex by doxygen 1.3.4