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

cache.c File Reference

Cache management subsystem. More...

#include "cache.h"
#include "playlist.h"

Go to the source code of this file.

Functions

void error_handler (request_rec *r, const char *caller)
 Handles error for the flat file cache subsystem.

short cache_make_dir (request_rec *r, char *dirpath)
 Creates cache subdirectories.

void cache_remove_dir (request_rec *r, DIR *cachedir, char *curdir)
 Removes cache subdirectories.

short cache_init (request_rec *r, mu_config *conf)
 Initializes flat file cache subsystem.

short cache_check_dir (request_rec *r, mu_config *conf, mu_cache_data *cachedata)
 Checks if a directory already exists in the cache.

short cache_check_file (request_rec *r, mu_config *conf, mu_cache_data *cachedata)
 Checks if a file already exists in the cache.

mu_entcache_read_file (request_rec *r, mu_ent *head, mu_config *conf, mu_cache_data *cachedata)
 Reads cache file information and fills mu_ent entry accordingly.

short cache_write_file (request_rec *r, mu_ent *p, mu_config *conf, mu_cache_data *cachedata)
 Creates and writes cache file information.


Detailed Description

Cache management subsystem.

Any cache implementation (regular files, SQL, or whatever backend) ought to provide the 4 mandatory interfaces:
short cache_check_dir(request_rec *, mu_config *, mu_cache_data *)
short cache_check_file(request_rec *, mu_config *, mu_cache_data *)
mu_ent *cache_read_file(request_rec *, mu_ent *, mu_config *, mu_cache_data *)
short cache_write_file(request_rec *, mu_ent *, mu_config *, mu_cache_data *)

Author:
Thibaut Varene
Version:
Revision
1.36
Date:
2003
Warning:
Under heavy development, not very well tested!

'errno' seems not to be seen as volatile by the compiler, therefore we cannot do "if(mkdir(foo) && errno == EEXIST)" for instance.

No flat file cache support for Solaris.

Bug:
We do rely on success of chdir() calls for the flat file implementation.

Todo:
Write SQL bits.

Solaris support (flat file).

Definition in file cache.c.


Function Documentation

short cache_check_dir request_rec *  r,
mu_config conf,
mu_cache_data cachedata
 

Checks if a directory already exists in the cache.

This function is called when the caller wants to know whether a given directory (as found in the cachedata struct) exists or not in the cache. If the directory exists, the function returns successfully, otherwise it tries to create it if possible and returns accordingly.

Parameters:
r Apache request_rec struct to handle log writings.
conf The config structure used to find out cache configuration.
cachedata A structure in which the full directory path can be found.
Returns:
0 on succes, CA_MISSARG if cachedata->name is missing, CA_FATAL otherwise.

Definition at line 285 of file cache.c.

References CA_FATAL, CA_MISSARG, cache_init(), cache_make_dir(), mu_config::cache_path, cache_remove_dir(), error_handler(), and mu_cache_data::name.

Referenced by make_music_entry().

short cache_check_file request_rec *  r,
mu_config conf,
mu_cache_data cachedata
 

Checks if a file already exists in the cache.

This function is called when the caller wants to know whether a given file (as found in the cachedata struct) exists or not in the cache. If the file exists, the function returns successfully, providing the FILE stream in cachedata->stream, otherwise it returns a specific error code.

Parameters:
r Apache request_rec struct to handle log writings.
conf The config structure used to find out cache configuration.
cachedata A structure in which the full file path can be found and in which the file stream will be set if needed.
Returns:
0 on succes, CA_CREATE if the file doesn't exist but can be created, CA_MISSARG if cachedata->name is missing, CA_FATAL otherwise.

Definition at line 346 of file cache.c.

References CA_CREATE, CA_FATAL, CA_MISSARG, cache_init(), mu_config::cache_path, error_handler(), mu_cache_data::name, and mu_cache_data::stream.

Referenced by make_music_entry().

short cache_init request_rec *  r,
mu_config conf
[static]
 

Initializes flat file cache subsystem.

Basically we do nothing more here than creating the root cache folder.

Parameters:
r Apache request_rec struct to handle log writings.
conf configuration structure in which the path to the cache root can be found.
Returns:
0 on succes, CA_FATAL otherwise.

Definition at line 258 of file cache.c.

References CA_FATAL, cache_make_dir(), mu_config::cache_path, and error_handler().

Referenced by cache_check_dir(), and cache_check_file().

short cache_make_dir request_rec *  r,
char *  dirpath
[static]
 

Creates cache subdirectories.

This subroutine takes care of creating all requested directories and subdirectories if they don't already exist and if possible.

Warning:
If dirpath begins with a "/" the function will return immediately.
Parameters:
r Apache request_rec struct to handle log writings.
dirpath A string representing a path to create.
Returns:
0 on succes, CA_FATAL otherwise.

Definition at line 168 of file cache.c.

References CA_FATAL, and error_handler().

Referenced by cache_check_dir(), and cache_init().

mu_ent* cache_read_file request_rec *  r,
mu_ent head,
mu_config conf,
mu_cache_data cachedata
 

Reads cache file information and fills mu_ent entry accordingly.

This function instanciates a new mu_ent entry and fills in its fields with data gathered from the cache file.

Bug:
Consummes 3*1k of RAM for each file read; we could probably shorten that to 3*256B, but the fields can be up to 1k long according to id3.org
Parameters:
r Apache request_rec struct to handle log writings.
conf The config structure used to find out cache configuration.
head The current mu_ent pointer.
cachedata A structure in which the cache file stream can be found.
Returns:
A new mu_ent entry, or head if failure.

Definition at line 396 of file cache.c.

References mu_ent::album, mu_ent::artist, mu_ent::bitrate, mu_ent::date, mu_ent::filetype, mu_ent::genre, mu_ent::length, MAX_STRING, new_ent(), mu_ent::posn, mu_ent::size, mu_cache_data::stream, mu_ent::title, and mu_ent::track.

Referenced by make_music_entry().

void cache_remove_dir request_rec *  r,
DIR *  cachedir,
char *  curdir
[static]
 

Removes cache subdirectories.

This subroutine takes care of removing any given directory and its content (recursively) if any, and if possible.

Parameters:
r Apache request_rec struct to handle log writings.
cachedir A DIR stream corresponding to the directory to remove.
curdir A string representing the absolute path of the corresponding parent directory on the "original" filesystem.

Definition at line 209 of file cache.c.

References error_handler().

Referenced by cache_check_dir().

short cache_write_file request_rec *  r,
mu_ent p,
mu_config conf,
mu_cache_data cachedata
 

Creates and writes cache file information.

This function creates a new cache file (using cachedata->name), and fills it with the data contained in the mu_ent p structure.

Parameters:
r Apache request_rec struct to handle log writings.
conf The config structure used to find out cache configuration.
p A mu_ent struct containing the data to store.
cachedata A structure in which the cache file name can be found.
Returns:
0 on success, CA_LOCKED if the file is locked already, CA_FATAL otherwise.

Definition at line 450 of file cache.c.

References mu_ent::album, mu_ent::artist, mu_ent::bitrate, CA_FATAL, CA_LOCKED, mu_config::cache_path, mu_ent::date, error_handler(), mu_ent::filetype, mu_ent::genre, mu_ent::length, mu_cache_data::name, mu_ent::posn, mu_ent::size, mu_cache_data::stream, mu_ent::title, and mu_ent::track.

Referenced by make_music_entry().

void error_handler request_rec *  r,
const char *  caller
[static]
 

Handles error for the flat file cache subsystem.

This function handles various errors depending on errno's value.

Parameters:
r Apache request_rec struct to handle log writings.
caller A string (eg. calling function name) used in messages sent.

Todo:
Many things.

Definition at line 87 of file cache.c.

Referenced by cache_check_dir(), cache_check_file(), cache_init(), cache_make_dir(), cache_remove_dir(), and cache_write_file().


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