mod_musicindex
1.4.1
|
Flat file cache management subsystem. More...
#include "playlist.h"
#include "cache-file.h"
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <sys/file.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | mi_data_buffer |
struct type used to reduce memory usage More... |
Macros | |
#define | CACHE_VERS 12 |
#define | CACHE_NF 15 |
#define | CA_OK 0 |
#define | CA_FATAL 10 |
#define | CA_MISSARG 20 |
#define | CA_CREATE 30 |
#define | CA_LOCKED 40 |
#define | ISDOT(x) ( (x)[0] == '.' && (!(x)[1] || ((x)[1] == '.' && !(x)[2])) ) |
test for "." and ".." dir entries. | |
#define | BLANKSTR(x) ( !(x) ? "#" : (x) ) |
if char *x is NULL, print a printable ascii char (white space would be trashed by fscanf alas) | |
#define | ISBLANK(x) ( ((x)[0] == '#') && ((x)[1] == '\0') ) |
Detection of our "home made" encoding of NULL strings. |
Functions | |
static void | error_handler (request_rec *r, const char *const caller) |
Handles error for the flat file cache subsystem. | |
static short | file_cache_make_dir (request_rec *r, const char *const dirpath) |
Creates cache subdirectories. | |
static void | file_cache_remove_dir (request_rec *r, DIR *cachedir, const char *const curdir) |
Removes cache subdirectories. | |
static void * | cache_file_opendir (request_rec *r, mu_pack *const pack, const char *const filename, const char *uri, unsigned long soptions) |
Checks if a directory already exists in the cache. | |
static mu_ent * | file_make_cache_entry (request_rec *r, apr_pool_t *pool, FILE *const in, const char *const filename) |
Fills in the information fields about a music file from the cache. | |
static void | cache_file_write (request_rec *r, const mu_ent *const p, const char *const filename) |
Creates and writes cache file information. | |
int | cache_file_setup (cmd_parms *cmd, const char *const setup_string, mu_config *const conf) |
Variables | |
static const cache_backend | cache_backend_file |
Flat file cache management subsystem.
Definition in file cache-file.c.
#define BLANKSTR | ( | x | ) | ( !(x) ? "#" : (x) ) |
if char *x is NULL, print a printable ascii char (white space would be trashed by fscanf alas)
Definition at line 68 of file cache-file.c.
Referenced by cache_file_write().
#define CA_CREATE 30 |
Definition at line 62 of file cache-file.c.
#define CA_FATAL 10 |
Definition at line 60 of file cache-file.c.
Referenced by file_cache_make_dir().
#define CA_LOCKED 40 |
Definition at line 63 of file cache-file.c.
#define CA_MISSARG 20 |
Definition at line 61 of file cache-file.c.
#define CA_OK 0 |
Definition at line 59 of file cache-file.c.
Referenced by file_cache_make_dir().
#define CACHE_NF 15 |
Definition at line 57 of file cache-file.c.
Referenced by file_make_cache_entry().
#define CACHE_VERS 12 |
Definition at line 56 of file cache-file.c.
Referenced by cache_file_write(), and file_make_cache_entry().
#define ISBLANK | ( | x | ) | ( ((x)[0] == '#') && ((x)[1] == '\0') ) |
Detection of our "home made" encoding of NULL strings.
Definition at line 70 of file cache-file.c.
Referenced by file_make_cache_entry().
#define ISDOT | ( | x | ) | ( (x)[0] == '.' && (!(x)[1] || ((x)[1] == '.' && !(x)[2])) ) |
test for "." and ".." dir entries.
x is a char *
Definition at line 66 of file cache-file.c.
Referenced by file_cache_remove_dir().
|
static |
Checks if a directory already exists in the cache.
This function takes advantage of the standard behaviour of the cache backend in musicindex: this function is called when the caller wants to know whether the backend handles a given directory. We always return NULL, pretending we don't, as "handling" means being able to provide a full listing straight out of cache, which we don't in this particular incarnation, but we take the opportunity to do our own cooking with our cache data, creating the directory in cache if need be, and checking for cache data sanity.
r | Apache request_rec struct. |
pack | Ignored |
filename | current directory path |
uri | server-side uri (unused) |
soptions | Flags to use for created entries. Ignored. |
Definition at line 280 of file cache-file.c.
References mu_config::cache_setup, error_handler(), file_cache_make_dir(), file_cache_remove_dir(), musicindex_module, and unlikely.
int cache_file_setup | ( | cmd_parms * | cmd, |
const char *const | setup_string, | ||
mu_config *const | conf | ||
) |
Definition at line 513 of file cache-file.c.
References apr_pstrdup, mu_config::cache, cache_backend_file, mu_config::cache_setup, and mi_serror.
|
static |
Creates and writes cache file information.
This function creates a new cache file (for #filename), and fills it with the data contained in the mu_ent p structure.
r | Apache request_rec struct to handle log writings. |
p | A mu_ent struct containing the data to store. |
filename | current filename of the file to cache. |
Definition at line 451 of file cache-file.c.
References mu_ent::album, mu_ent::artist, mu_ent::bitrate, BLANKSTR, mu_config::cache_setup, CACHE_VERS, mu_ent::date, EF_FLAGSTOSAVE, error_handler(), mu_ent::filetype, mu_ent::flags, mu_ent::freq, mu_ent::genre, mu_ent::length, mu_ent::mtime, musicindex_module, mu_ent::posn, mu_ent::size, mu_ent::title, and mu_ent::track.
|
static |
Handles error for the flat file cache subsystem.
This function handles various errors depending on errno's value.
r | Apache request_rec struct to handle log writings. |
caller | A string (eg. calling function name) used in messages sent. |
Definition at line 82 of file cache-file.c.
References mi_rerror.
Referenced by cache_file_opendir(), cache_file_write(), file_cache_make_dir(), file_cache_remove_dir(), and file_make_cache_entry().
|
static |
Creates cache subdirectories.
This subroutine takes care of creating all requested directories and subdirectories if they don't already exist and if possible.
r | Apache request_rec struct to handle log writings. |
dirpath | A string representing a path to create. |
Definition at line 167 of file cache-file.c.
References CA_FATAL, CA_OK, and error_handler().
Referenced by cache_file_opendir().
|
static |
Removes cache subdirectories.
This subroutine takes care of removing any given directory and its content (recursively) if any, and if possible.
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 216 of file cache-file.c.
References apr_pstrcat, error_handler(), ISDOT, and unlikely.
Referenced by cache_file_opendir().
|
static |
Fills in the information fields about a music file from the cache.
This function reads the tags from the cache file and fills in the struct mu_ent fields accordingly.
r | Apache request_rec struct to handle log writings. |
pool | Apache pool |
in | Not used (except for closing). |
filename | current filename. |
Definition at line 345 of file cache-file.c.
References mu_ent::album, mi_data_buffer::album, apr_pstrdup, mu_ent::artist, mi_data_buffer::artist, mu_ent::bitrate, CACHE_NF, mu_config::cache_setup, CACHE_VERS, mu_ent::date, error_handler(), filetype, mu_ent::filetype, mu_ent::flags, mu_ent::freq, mu_ent::genre, mi_data_buffer::genre, ISBLANK, mu_ent::length, likely, mu_ent::mtime, musicindex_module, NEW_ENT, mu_ent::posn, mu_ent::size, mu_ent::title, mi_data_buffer::title, mu_ent::track, and unlikely.
|
static |
Definition at line 503 of file cache-file.c.
Referenced by cache_file_setup().