mod_musicindex  1.4.1
playlist.c File Reference

Playlist management system. More...

#include "playlist.h"
#include "sort.h"
#include "playlist-flac.h"
#include "playlist-vorbis.h"
#include "playlist-mp3.h"
#include "playlist-mp4.h"
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  mu_dir
 Wrapper struct for the cache subsystem. More...

Typedefs

typedef struct mu_dir mu_dir
 Wrapper struct for the cache subsystem.

Functions

static mu_entmake_no_entry (request_rec *r, apr_pool_t *pool, FILE *const in, const char *const filename)
 Fallback function if the file could not be recognised.
static mu_entmake_cache_entry (request_rec *r, apr_pool_t *pool, FILE *const in, const char *const filename)
 Wrapper function to call the actual cache backend.
static void musicindex_opendir (request_rec *r, mu_dir *dir, mu_pack *const pack, const mu_ent_names *const names, unsigned long soptions)
 Custom directory opener.
static const char * musicindex_readdir (request_rec *r, mu_dir *dir)
 Get the string of the next filename to open.
static void musicindex_closedir (request_rec *r, mu_dir *dir)
 Close the open directory.
static short go_through_directory (request_rec *r, const unsigned short local_options)
 Check lots of details that could mean we shouldn't go through the directory.
void make_music_entry (request_rec *r, apr_pool_t *pool, mu_pack *const pack, mu_ent_names *names, unsigned long soptions)
 Add a file (and the content of the directory if requested) to the chain.
void build_custom_list (request_rec *r, mu_pack *const pack)
 Creates a link list based on the custom list.

Variables

struct ftype const filetype []
 Array of common strings widely used.
static const make_entry_ptr const make_entry []
 Function pointers array.

Detailed Description

Playlist management system.

Author
Regis Boudin
Thibaut Varene
Version
Revision:
1022
Date
2003-2009
2012

This is where the magic takes place. Here are the functions in charge of analyzing the content of the folders requested by the client, and of generating the structures and lists that will be used by the HTML subsystem to generate the pretty output.

Todo:
document the code path as best as possible (especiallly make_music_entry)

Definition in file playlist.c.

Typedef Documentation

typedef struct mu_dir mu_dir

Wrapper struct for the cache subsystem.

Function Documentation

void build_custom_list ( request_rec *  r,
mu_pack *const  pack 
)

Creates a link list based on the custom list.

This function generates a list containing all the files referenced in the conf->custom_list string. It handles parameters in a way so that it can handle indifferently strings for cookies or on-the-fly playlists.

Warning
This function uses a subrequest for each file. This has a significant performance impact, but OTOH this function isn't really in the 'performance path' of the module anyway.
Parameters
rApache request_rec struct
packA pack to which the generated list will be hooked
Returns
a list of mu_ent on success, NULL otherwise.

Definition at line 556 of file playlist.c.

References ap_sub_req_lookup_uri, apr_base64_decode, apr_base64_decode_len, mu_config::custom_list, mu_pack::fhead, mu_ent_names::filename, mu_pack::head, make_music_entry(), MI_ALLOWFETCH, MI_CUSTOM, musicindex_module, mu_ent::next, options, and mu_ent_names::uri.

Referenced by handle_musicindex().

static short go_through_directory ( request_rec *  r,
const unsigned short  local_options 
)
inlinestatic

Check lots of details that could mean we shouldn't go through the directory.

Parameters
rApache current request
local_optionsThis function can be called in subdirectories for which the configuration can differ from the current dir's one. This paramater allows the caller to specify the options to check against.
Returns
TRUE if directory descend is allowed, FALSE otherwise.

Definition at line 254 of file playlist.c.

References FALSE, MI_ACTIVE, MI_ALLOWSEARCH, MI_ALLOWSTREAM, MI_STREAMALL, musicindex_module, mu_config::options, mu_config::search, and TRUE.

Referenced by make_music_entry().

static mu_ent* make_cache_entry ( request_rec *  r,
apr_pool_t pool,
FILE *const  in,
const char *const  filename 
)
static

Wrapper function to call the actual cache backend.

Parameters
rApache request_rec struct
poolApache memory pool
infile to parse (closed on normal exit)
filenamecurrent filename
Returns
the cache data on success, head otherwise

Definition at line 100 of file playlist.c.

References mu_config::cache, EF_INCACHE, mu_ent::flags, likely, cache_backend::make_entry, and musicindex_module.

void make_music_entry ( request_rec *  r,
apr_pool_t pool,
mu_pack *const  pack,
mu_ent_names names,
unsigned long  soptions 
)

Add a file (and the content of the directory if requested) to the chain.

This function creates a new entry from a file. If the file is a directory and the recursive option is set, all its content is also added. Otherwise, if the file is "recognized", it is simply added.

Warning
If the filename is too long, it will be ignored.
Todo:
Find a way to not delegate file closing to subsystems (essentially hack vorbis)
Bug:
I'm afraid if we're asked to recurse into too many subdirs, we might end up with too many open fdesc.
Note
It'd be very nice to be able to make this function tail recursive, unfortunately it looks like it's going to be rather troublesome to do so.
This function will NOT and should NEVER muck with mu_pack.fhead. This should be taken care of by whoever calls it.
r->filename is the path to the file on the filesystem, while r->parsed_uri.path is the path to the file on the webserver, so no assertion can be made on their respective length
Parameters
poolPool
rApache request_rec struct to handle log writings (debugging)
packA pack of music entries to populate
namesNames
soptionsbitwise special options: these are made of the extended options flag set and are used to fiddle with the algorithms (regis please docu...)
Returns
When possible, struct mu_ent correctly set up

Definition at line 307 of file playlist.c.

References mu_ent::album, ap_is_directory, ap_sub_req_lookup_uri, apr_palloc, apr_pstrdup, apr_pstrndup, mu_ent::artist, mu_config::cache, mu_dir::dir, mu_config::dir_per_line, mu_pack::dirnb, EF_INCACHE, FALSE, mu_ent::file, mu_ent_names::filename, mu_ent::filename, mu_pack::filenb, mu_ent::filetype, mu_ent::flags, mu_pack::fsize, go_through_directory(), mu_pack::head, likely, make_entry, make_music_entry(), MAX_STRING, MI_ALLOWFETCH, MI_ALLOWRSS, MI_CUSTOM, MI_QUICKPL, MI_RECURSIVE, mi_rerror, MI_RSS, MI_STREAM, MI_TARBALL, musicindex_closedir(), musicindex_module, musicindex_opendir(), musicindex_readdir(), NEW_ENT, mu_ent::next, options, mu_config::options, P_FLAGS_OPTIONS, mu_config::search, mu_ent::size, mu_ent::title, unlikely, mu_ent_names::uri, mu_ent::uri, and cache_backend::write.

Referenced by build_custom_list(), cookie_addall(), handle_musicfile(), handle_musicindex(), and make_music_entry().

static mu_ent* make_no_entry ( request_rec *  r,
apr_pool_t pool,
FILE *const  in,
const char *const  filename 
)
inlinestatic

Fallback function if the file could not be recognised.

Parameters
rApache request_rec struct
poolPool
infile to parse (closed on normal exit)
filenamecurrent filename
Returns
head, whatever happens.

Definition at line 83 of file playlist.c.

static void musicindex_closedir ( request_rec *  r,
mu_dir dir 
)
inlinestatic

Close the open directory.

Parameters
rApache request_rec struct
dirAbstract pointer to our custom directory handler

Definition at line 231 of file playlist.c.

References mu_config::cache, cache_backend::closedir, mu_dir::dir, mu_dir::handled, and musicindex_module.

Referenced by make_music_entry().

static void musicindex_opendir ( request_rec *  r,
mu_dir dir,
mu_pack *const  pack,
const mu_ent_names *const  names,
unsigned long  soptions 
)
inlinestatic

Custom directory opener.

This is a first shot at the custom opendir function. At the end, This wraps around the various caches for directory management. Depending on what the cache back-end can do, it may add things to the entries list, and generate an internal list of files left to deal with. These files names will be retrieved with musicindex_readdir(). We mimic the opendir()/readdir()/closedir() scheme.

Parameters
rthe Apache request
dirAbstract pointer to our custom directory handler
packpack pointer
namesstructure containing the name of the directory
soptionsthe current extended options

Definition at line 172 of file playlist.c.

References mu_config::cache, mu_dir::dir, mu_ent_names::filename, mu_dir::handled, musicindex_module, cache_backend::opendir, and mu_ent_names::uri.

Referenced by make_music_entry().

static const char* musicindex_readdir ( request_rec *  r,
mu_dir dir 
)
inlinestatic

Get the string of the next filename to open.

Parameters
rApache request_rec struct
dirAbstract pointer to our custom directory handler
Returns
pointer to the string of the filename, without any trailing /, or NULL if there is nothing left to open.

Definition at line 203 of file playlist.c.

References mu_config::cache, mu_dir::dir, mu_dir::handled, musicindex_module, and cache_backend::readdir.

Referenced by make_music_entry().

Variable Documentation

struct ftype const filetype[]
Initial value:
{
{ "MP3", "audio/x-mp3" },
{ "Vorbis", "audio/x-ogg" },
{ "FLAC", "audio/flac" },
{ "MP4/AAC", "audio/mp4" }
}

Array of common strings widely used.

Warning
Must be kept in sync with the enum in playlist.h

http://filext.com/detaillist.php?extdetail=M3U http://filext.com/detaillist.php?extdetail=MP3 http://filext.com/detaillist.php?extdetail=OGG http://filext.com/detaillist.php?extdetail=FLAC http://filext.com/detaillist.php?extdetail=MP4

Definition at line 65 of file playlist.c.

Referenced by file_make_cache_entry(), list_songs(), and send_rss().

const make_entry_ptr const make_entry[]
static
Initial value:

Function pointers array.

Of course, as we defined function pointers, we will use them in a nice array. They will be called in a sequential manner.
make_cache_entry() MUST be called first.
Note : a make_dir_entry() function to handle directories has already been tried, unfortunately, it implies some bad side effects. Plus, it probably does not make things any quicker and increases the number of function calls. (that's a personnal NB to the developpers, to avoid repeating twice the same havoc as time goes by ;o)

Functions are ordered in what we believe is a top-down order of most frequent filetypes.

Definition at line 131 of file playlist.c.

Referenced by make_music_entry().