jabberd14 1.6.2
Data Structures | Defines | Typedefs | Functions
xdb_file.cc File Reference

implements storage in XML files More...

#include <jabberd.h>
#include <dirent.h>

Data Structures

struct  cacher_struct
struct  xdbf_struct

Defines

#define FILES_PRIME   509

Typedefs

typedef struct cacher_structcacher
typedef struct cacher_struct _cacher
typedef struct xdbf_structxdbf
typedef struct xdbf_struct _xdbf

Functions

void _xdb_file_purge (xht h, const char *key, void *data, void *arg)
result xdb_file_purge (void *arg)
xmlnode xdb_file_load (char *host, char *fname, xht cache)
void _xdb_get_hashes (const char *filename, char digit01[3], char digit23[3])
char * xdb_file_full (int create, pool p, const char *spl, char const *host, const char *file, char const *ext, int use_subdirs)
result xdb_file_phandler (instance i, dpacket p, void *arg)
void xdb_file_cleanup (void *arg)
void _xdb_convert_hostspool (pool p, const char *spoolroot, char *host)
void xdb_convert_spool (const char *spoolroot)
void xdb_file (instance i, xmlnode x)

Detailed Description

implements storage in XML files

Todo:
the xdbns attribute in the spool files should be contained in its own namespace

The xdb_file module can be used to store XML in files - one per user. It is the traditional storage module of the jabberd14 server.


Define Documentation

#define FILES_PRIME   509

Referenced by xdb_file().


Typedef Documentation

typedef struct cacher_struct _cacher
typedef struct xdbf_struct _xdbf
typedef struct cacher_struct * cacher

an item in the hash of cached data

typedef struct xdbf_struct * xdbf

xdb_file internal data

created for each instance of xdb_file


Function Documentation

void _xdb_convert_hostspool ( pool  p,
const char *  spoolroot,
char *  host 
)

convert a spool directory for a given host from the old format to the new one which distributes the files over several subdirs

Parameters:
pthe memory pool we can use
spoolrootthe root folder of the spool
hostthe host for which we should try to convert

References _xdb_get_hashes(), j_strcmp(), log_error, and log_notice().

Referenced by xdb_convert_spool().

void _xdb_file_purge ( xht  h,
const char *  key,
void *  data,
void *  arg 
)

xhash_walker function. Called for each cached content. Decides if it has to be expired.

Parameters:
hthe xhash containing the cached content of xdb_file
keykey in the hash (filename of the cached file)
datavalue in the hash (type is cacher)
argpointer to the xdb_file internal component instance data

References xdbf_struct::cache, cacher_struct::file, cacher_struct::fname, cacher_struct::lastset, log_debug2, LOGT_STORAGE, xdbf_struct::timeout, xhash_zap(), xmlnode_free(), and ZONE.

Referenced by xdb_file_purge().

void _xdb_get_hashes ( const char *  filename,
char  digit01[3],
char  digit23[3] 
)

calculate the left-most four digits of the SHA-1 hash over a filename

Parameters:
filenamethe filename
digit01where to place the first two digits (size 3 chars!)
digit23where to place the next two digits (size 3 chars!)

References crc32_r(), log_debug2, LOGT_STORAGE, and ZONE.

Referenced by _xdb_convert_hostspool(), and xdb_file_full().

void xdb_convert_spool ( const char *  spoolroot)

convert a spool directory from the old format to the new one which distributes the files over several subdirs

Parameters:
spoolrootthe root folder of the spool

References _xdb_convert_hostspool(), log_debug2, LOGT_STORAGE, pool_free(), pool_new, and ZONE.

void xdb_file ( instance  i,
xmlnode  x 
)
void xdb_file_cleanup ( void *  arg)

cleanup xdb_file on server shutdown

Parameters:
argthe instance configuration of this component

References xdbf_struct::cache, and xhash_free().

Referenced by xdb_file().

char* xdb_file_full ( int  create,
pool  p,
const char *  spl,
char const *  host,
const char *  file,
char const *  ext,
int  use_subdirs 
)

utility that generates the filename for a spool file

Parameters:
createtrue if the directory for the file should be generated
ppool that should be used for string operations
spllocation for the spool root
hosthost of the xdb request (the 'spool folder')
filethe basename of the xdb file
extthe extension for the xdb file
use_subdirstrue if file should be located in subdirectories
Returns:
concatenated string of the form spl+"/"+somehashes+"/"+file+"."+ext

References _xdb_get_hashes(), log_error, and pstrdup().

xmlnode xdb_file_load ( char *  host,
char *  fname,
xht  cache 
)

load an XML file

Parameters:
hostthe host to load the file for (just for generating log messages)
fnamethe filename of the file, that should be loaded
cachea hash containing the cached files, that do not need to get loaded and parsed again
Returns:
the loaded (or cached) xmlnode

References cacher_struct::file, cacher_struct::fname, j_strcmp(), cacher_struct::lastset, log_debug2, log_warn(), LOGT_STORAGE, NS_JABBERD_XDB, NS_SERVER, pmalloco(), pstrdup(), xhash_get(), xhash_put(), xmlnode_change_namespace(), xmlnode_file(), xmlnode_get_namespace(), xmlnode_new_tag_ns(), xmlnode_pool(), and ZONE.

result xdb_file_phandler ( instance  i,
dpacket  p,
void *  arg 
)
result xdb_file_purge ( void *  arg)

check for cached content, that has expired

This function gets called regulary as a function, that is registered with heartbeat. It removes expired content from the caching hash.

Parameters:
argpointer to xdb_local component instance data (type is xdbf)
Returns:
always r_DONE

References _xdb_file_purge(), xdbf_struct::cache, log_debug2, LOGT_STORAGE, r_DONE, xhash_walk(), and ZONE.

Referenced by xdb_file().