mod_musicindex  1.4.1
http.c File Reference

HTTP features handling. More...

#include "http.h"
#include "sort.h"
#include "playlist.h"

Go to the source code of this file.

Functions

void treat_get_args (request_rec *r)
 Treats the GET arguments.
void treat_post_args (request_rec *r)
 Treats the POST arguments.
static const char * find_playlist (request_rec *r, apr_pool_t *subpool)
static const char * find_or_create_playlist (request_rec *r, apr_pool_t *subpool)
static const char * cookie_add (request_rec *r, apr_pool_t *subpool)
 Adds file(s) to the cookie holding the custom playlist.
static const char * cookie_addall (request_rec *r, apr_pool_t *subpool)
 Adds all files in a directory to the cookie holding the custom playlist.
static const char * cookie_remove (request_rec *r, apr_pool_t *subpool)
 Removes file(s) from the cookie holding the custom playlist.
void cookie_and_stream_work (request_rec *r)

Detailed Description

HTTP features handling.

Author
Regis Boudin
Thibaut Varene
Version
Revision:
1003
Date
2004-2007

This file is here to deal with HTTP related features which are not directly handled by Apache. It includes parsing of arguments received via GET or POST requests and cookie management for cross-directories playlists.

Cookies

We're gonna base64 encode all strings stored to the cookie. base64 uses only the following characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" so we should be perfectly fine dealing with '&' and friends.

We store in the cookie file identifier as follows: base64_encoded_uri&" We store the unescaped base64 string in the cookie.

Also note that according to: http://www.15seconds.com/faq/Cookies/388.htm
According to the draft specification issued by Netscape Communications, the limits regarding the size of cookie and space occupied by all cookies is:

  • 4 KB per cookie maximum
  • 300 total cookies, for a total of 1.2 Mbytes maximum
  • 20 cookies accepted from a particular server or domain

Which means that we don't have infinite space, and can't store big custom lists. Reports shows that ~50 songs is a max, but if depends on the length of the path anyway.

Todo:

Test, test, test.

Use cookie for session identifer, and store custom lists on the server.

Bug:
Beware of "big lists"
Todo:
Store custom list locally, and store only a session reference in the cookie.

Definition in file http.c.

Function Documentation

static const char* cookie_add ( request_rec *  r,
apr_pool_t subpool 
)
static

Adds file(s) to the cookie holding the custom playlist.

This function takes a list of files to add to the custom playlist cookie in the form of base64 encoded uris stored in the conf->custom_list field, comming from the POST arguments.

Parameters
rthe apache request
subpoolthe current subpool to use for mem allocations
Returns
a string to store in the cookie

Definition at line 335 of file http.c.

References apr_pstrcat, mu_config::custom_list, find_or_create_playlist(), and musicindex_module.

Referenced by cookie_and_stream_work().

static const char* cookie_addall ( request_rec *  r,
apr_pool_t subpool 
)
static

Adds all files in a directory to the cookie holding the custom playlist.

This function runs a make_music_entry on the local folder and adds to the cookie all the files in this directory, and stores their absolute unescaped URI base64 encoded.

Parameters
rthe apache request
subpoolthe current subpool to use for mem allocations
Returns
a string to store in the cookie

Definition at line 369 of file http.c.

References apr_base64_encode, apr_base64_encode_len, apr_pstrcat, mu_pack::fhead, find_or_create_playlist(), mu_pack::head, listsort(), make_music_entry(), MI_RECURSIVE, musicindex_module, mu_ent::next, mu_config::order, and mu_ent::uri.

Referenced by cookie_and_stream_work().

static const char* cookie_remove ( request_rec *  r,
apr_pool_t subpool 
)
static

Removes file(s) from the cookie holding the custom playlist.

This function takes a list of files to remove to the custom playlist cookie in the form of base64 uris stored in the conf->custom_list field, comming from the POST arguments. It then copies the old base64 encoded URIs from the existing cookie into a new one only if it can't find a match based on the custom_list.

Parameters
rthe apache request
subpoolthe current subpool to use for mem allocations
Returns
the new cookie string deprived of matching files

Definition at line 415 of file http.c.

References apr_pstrcat, apr_pstrdup, mu_config::custom_list, find_playlist(), and musicindex_module.

Referenced by cookie_and_stream_work().

static const char* find_or_create_playlist ( request_rec *  r,
apr_pool_t subpool 
)
static

Definition at line 313 of file http.c.

References apr_pstrdup, and find_playlist().

Referenced by cookie_add(), and cookie_addall().

static const char* find_playlist ( request_rec *  r,
apr_pool_t subpool 
)
static

Definition at line 299 of file http.c.

References apr_table_get.

Referenced by cookie_and_stream_work(), cookie_remove(), and find_or_create_playlist().

void treat_get_args ( request_rec *  r)

Treats the GET arguments.

This function searches for keywords passed as URL arguments (with "?xxx") and sets the handler options accordingly.

Parameters
rApache request_rec struct to handle connection details.

Definition at line 75 of file http.c.

References mu_config::custom_list, MI_ALLOWSTREAM, MI_ALLOWTARBALL, MI_DWNLDALL, MI_PODCAST, MI_QUICKPL, MI_RANDOMDIR, MI_RECURSIVE, MI_RSS, MI_STREAMALL, musicindex_module, mu_config::options, mu_config::order, mu_config::rss_items, SB_DEFAULT, SB_DIR, SB_MAX, SB_MTIME, SB_RANDOM, and SB_URI.

Referenced by handle_musicindex().

void treat_post_args ( request_rec *  r)

Treats the POST arguments.

This function searches for keywords in arguments sent in a POST request. It only sets option flags and the search string when they are needed.

Warning
This function is fairly inefficient as-is. It does a lot of useless checks and string comparisons, because it will only deal with 1 action at a time, so as soon as we have one hit, we could give up. We could add 'return's everywhere but it's pretty ugly as well.
Parameters
rApache request_rec struct to handle connection details.

Definition at line 170 of file http.c.

References apr_pstrcat, apr_pstrdup, mu_config::cache, mu_config::custom_list, MAX_STRING, MI_ALLOWSEARCH, MI_ALLOWSTREAM, MI_ALLOWTARBALL, MI_COOKIEADDALL, MI_COOKIEADDLST, MI_COOKIEDELLST, MI_COOKIEDWNLD, MI_COOKIEOP, MI_COOKIEPURGE, MI_COOKIESTREAM, MI_DWNLDALL, MI_DWNLDLST, MI_QUICKPL, MI_RECURSIVE, MI_STREAMALL, MI_STREAMLST, musicindex_module, mu_config::options, mu_config::order, SB_DEFAULT, SB_DIR, SB_MAX, SB_RANDOM, SB_URI, and mu_config::search.

Referenced by handle_musicindex().