mod_musicindex  1.4.1
html.c File Reference

HTML (and assimilated) code generation. More...

#include "html.h"
#include "playlist.h"
#include <http_core.h>
#include <time.h>

Go to the source code of this file.

Functions

static unsigned short list_songs (request_rec *r, const mu_pack *const pack, const int customlist)
 Formats the list of songs to be sent.
static void send_url (request_rec *r, const char *const restrict uri, const char *const restrict command, const short html)
 Formats a complete url string to be sent to client.
void send_head (request_rec *r)
 Sends HTML page headers and top of the page.
void send_directories (request_rec *r, const mu_pack *const pack)
 Sends directory listing for the current folder.
void send_tracks (request_rec *r, const mu_pack *const pack)
 Sends track listing for the current folder.
void send_customlist (request_rec *r, const mu_pack *const pack)
 Sends track listing for the current custom playlist.
void send_playlist (request_rec *r, const mu_pack *const pack)
 Sends playlist with url and EXTM3U info to the client.
void send_rss (request_rec *r, const mu_pack *const pack)
 Sends RSS feed.
void send_randomdir (request_rec *r)
 Sends a random directory location.
void send_foot (request_rec *r, const STRUCTTV *tvbegin, const STRUCTTV *tvprocess)
 Sends HTML page footers.

Variables

static const char const Gfavicon [] = "sound.png"
static const char const Gcd_icon [] = "general.png"
static const char const Gorigcss [] = "musicindex.css"
static const char *const Gcovericns []
 Cover icon names to look for in a directory.

Detailed Description

HTML (and assimilated) code generation.

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

That file groups all functions related to HTML and assimilated generation, that is to say functions that are used to send data to the client. It is mainly (X)HTML, but also playlist (in M3U format) and RSS.

Todo:

still some work on the custom table

Replace text with eye-candy icons wherever possible

reduce the size of this file & optimize functions

Fix search box collide on long path names

Definition in file html.c.

Function Documentation

static unsigned short list_songs ( request_rec *  r,
const mu_pack *const  pack,
const int  customlist 
)
static

Formats the list of songs to be sent.

This function formats a list of tracks (if any) to be sent to the client, as found in the pack passed in argument. Depending on config options, it allows streaming/shuffle etc.

Todo:

Sort option for recursive search?

Keep sort conf on userside (using cookie(s)).

We have the basis of doing per file permissions in the Select panel stuff which also needs to be rewritten and simplified

Parameters
rApache request_rec struct to handle connection details.
packpack of songs to display.
customlistWhether the list of entries p is a custom list or not
Returns
The total number of fields in a row.

Definition at line 93 of file html.c.

References _, mu_ent::album, apr_base64_encode, apr_base64_encode_len, mu_ent::artist, mu_ent::bitrate, mu_ent::date, EF_ALLOWDWNLD, EF_ALLOWSTREAM, EF_ALLOWTARBALL, EF_VBR, mu_pack::fhead, mu_config::fields, mu_ent::file, mu_ent::filename, filetype, mu_ent::filetype, mu_ent::flags, mu_ent::freq, mu_pack::fsize, FT_MAX, mu_ent::genre, mu_ent::length, MI_ALLOWDWNLD, MI_ALLOWSTREAM, MI_ALLOWTARBALL, MI_QUICKPL, MI_RECURSIVE, musicindex_module, ftype::nametype, mu_ent::next, mu_config::options, mu_ent::posn, SB_ALBUM, SB_ARTIST, SB_BITRATE, SB_DATE, SB_FILENAME, SB_FILETYPE, SB_FREQ, SB_GENRE, SB_LENGTH, SB_POSN, SB_SIZE, SB_TITLE, SB_TRACK, mu_config::search, mu_ent::size, mu_ent::title, mu_ent::track, and mu_ent::uri.

Referenced by send_customlist(), and send_tracks().

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

Sends track listing for the current custom playlist.

This function takes care of preparing and sending to the client the list (if any) of the available songs in the current custom pack list, retrieved from a cookie. Depending on config options, it allows streaming/shuffle etc.

Warning
Even though the buttons are here (Download All, Stream All...), custom playlists will always respect individual files permissions, meaning that one can end up with an empty playlist or tarball even though the list itself isn't empty.
Parameters
rApache request_rec struct to handle connection details.
packA pack of music entries.

Definition at line 873 of file html.c.

References _, mu_pack::fhead, mu_pack::filenb, and list_songs().

Referenced by handle_musicindex().

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

Sends directory listing for the current folder.

This function takes care of preparing and sending to the client the list (if any) of the available directories in the current folder. Depending on config options, it allows streaming/shuffle etc.

Remarks
I tried moving to purely semantic coding (using either div or li, none worked. It seems CSS/browsers can't render properly a list of element of fixed width but variable height in a variable "columns" context: if an element has a greater height than the one immediately after on the same "row", then the next row will start at the right of this longer element instead of starting back at the left of the page.
Parameters
rApache request_rec struct to handle connection details.
packA pack of music entries.

Definition at line 713 of file html.c.

References _, mu_config::dir_per_line, mu_pack::dirnb, EF_ALLOWRSS, EF_ALLOWSTREAM, EF_ALLOWTARBALL, mu_ent::file, mu_ent::filetype, mu_ent::flags, mu_pack::head, musicindex_module, mu_ent::next, and mu_ent::title.

Referenced by handle_musicindex().

void send_foot ( request_rec *  r,
const STRUCTTV tvbegin,
const STRUCTTV tvprocess 
)

Sends HTML page footers.

This function takes care of the formating of the HTML page footers. It sends the data that is common to all pages generated by the handler.

Parameters
rApache request_rec struct to handle connection details.
tvbeginwhen available, a timeval struct containing timing info for the beginning of the page generation.
tvprocesswhen available a timeval struct containing end of processing time

< Version string

< Version string

Definition at line 1143 of file html.c.

References _, ap_sub_req_lookup_uri, apr_pstrcat, mu_config::directory, MUSIC_AUTHORS_STRING, MUSIC_VERSION_STRING, and musicindex_module.

Referenced by handle_musicindex().

void send_head ( request_rec *  r)

Sends HTML page headers and top of the page.

This function takes care of the formating of the HTML page headers. It sends the data that is common to all pages generated by the handler.

Parameters
rApache request_rec struct to handle connection details.
Bug:
When we'll allow mu_config->directory to be modified, have to escape html/uri.

Definition at line 482 of file html.c.

References _, ap_sub_req_lookup_uri, apr_pstrcat, apr_pstrdup, mu_config::css, mu_config::directory, Gcd_icon, Gcovericns, Gfavicon, Gorigcss, MI_ACTIVE, MI_ALLOWSEARCH, MI_ALLOWSTREAM, MI_ALLOWTARBALL, MUSIC_HEADER_STRING, musicindex_module, mu_config::options, mu_config::rss_items, and mu_config::title.

Referenced by handle_musicindex().

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

Sends playlist with url and EXTM3U info to the client.

This function prepares an m3u playlist (with extra information where available: length, artist, title, album) and sends it to the client.

Parameters
rApache request_rec struct to handle connection details.
packA pack of music entries.

Definition at line 918 of file html.c.

References mu_ent::album, mu_ent::artist, EF_ALLOWSTREAM, mu_pack::fhead, mu_ent::flags, mu_ent::length, mu_ent::next, send_url(), mu_ent::title, and mu_ent::uri.

Referenced by handle_musicfile(), and handle_musicindex().

void send_randomdir ( request_rec *  r)

Sends a random directory location.

This function constructs a new URL relative to the current directory, corresponding to a random subdirectory. It might stop at an arbitrary sublevel, even at the current dir.

XXX A better (or at least different) implementation would only accounts for actual folders, and setup a random threshold level at which the function stops recursing.

Bug:
A forseable bug is that this function can send you to a directory which access may be denied by .htaccess
Parameters
rApache request_rec struct to handle connection details.

Definition at line 1067 of file html.c.

References ap_is_directory, apr_pstrcat, apr_pstrdup, and apr_table_setn.

Referenced by handle_musicindex().

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

Sends RSS feed.

see http://blogs.law.harvard.edu/tech/rss and http://feedvalidator.org/docs/rss2.html

Parameters
rApache request_rec struct to handle connection details.
packA pack of music entries.

Definition at line 953 of file html.c.

References _, EF_VBR, mu_pack::fhead, filetype, FT_MAX, MI_ALLOWDWNLD, MI_ALLOWSTREAM, MI_PODCAST, ftype::mimetype, MUSIC_HEADER_STRING, musicindex_module, ftype::nametype, mu_ent::next, mu_config::options, mu_config::rss_items, and send_url().

Referenced by handle_musicindex().

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

Sends track listing for the current folder.

This function takes care of preparing and sending to the client the list (if any) of the available songs in the current pack list. Depending on config options, it allows streaming/shuffle etc.

Parameters
rApache request_rec struct to handle connection details.
packA pack of music entries.

Definition at line 794 of file html.c.

References _, mu_pack::filenb, list_songs(), MI_ALLOWSTREAM, MI_ALLOWTARBALL, musicindex_module, mu_config::options, mu_config::order, SB_MAX, and mu_config::search.

Referenced by handle_musicindex().

static void send_url ( request_rec *  r,
const char *const restrict  uri,
const char *const restrict  command,
const short  html 
)
static

Formats a complete url string to be sent to client.

This function does all the URL formatting, in the form: http://[user:][passwd@]hostname[:port]/uri/

Bug:

If the admin sets a conf->iceserver too big (>MAX_PREFIX) the ices url will be truncated. If hostname+auth+etc is too long this function aborts... There's no user-modifiable data here, we assume admins know what they're doing.

It appears this function cannot deal with IPv6 numeric URLs for now. -> fixed with AP24

Note
Eventually, for the non-incecast case we should probably use ap_construct_url() which is safer and exists since 1.3. Its only drawback being it allocates memory (pstrcat/psprintf).
Parameters
rApache request_rec struct to handle connection details.
uriA string (basically a path) to be sent to form a complete url.
commandAn eventual command (like ?action=playall).
html1 ? html output : normally escaped URL output.

Definition at line 388 of file html.c.

References apr_base64_decode, apr_base64_decode_len, apr_table_get, mu_config::iceserver, MAX_PREFIX, mi_rerror, MI_RSS, musicindex_module, mu_config::options, REQUEST_USER, and unlikely.

Referenced by send_playlist(), and send_rss().

Variable Documentation

const char const Gcd_icon[] = "general.png"
static

Definition at line 61 of file html.c.

Referenced by send_head().

const char* const Gcovericns[]
static
Initial value:
{
"cover.jpg",
"cover.png",
"cover.gif",
"folder.jpg",
"folder.png",
"folder.gif",
NULL
}

Cover icon names to look for in a directory.

Definition at line 64 of file html.c.

Referenced by send_head().

const char const Gfavicon[] = "sound.png"
static

Definition at line 60 of file html.c.

Referenced by send_head().

const char const Gorigcss[] = "musicindex.css"
static

Definition at line 62 of file html.c.

Referenced by send_head().