00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00050 mu_config *conf = (mu_config *)
00051 ap_get_module_config(r->per_dir_config, &musicindex_module);
00052
00053 #ifdef __BUILD_FOR_APACHE2
00054
00055 if(strcmp(r->handler,DIR_MAGIC_TYPE)) {
00056 return DECLINED;
00057 }
00058 #endif
00059
00060 r->allowed |= (1 << M_GET);
00061
00062
00063 if ((r->method_number != M_GET) || (!(conf->options & MI_ACTIVE)))
00064 return DECLINED;
00065
00066
00067
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
00082
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
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
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,
00212 merge_musicindex_configs,
00213 NULL,
00214 NULL,
00215 musicindex_cmds,
00216 register_hooks
00217 };
00218
00219 #endif