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

typedef struct xdbf_struct * xdbf


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:
p the memory pool we can use
spoolroot the root folder of the spool
host the 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:
h the xhash containing the cached content of xdb_file
key key in the hash (filename of the cached file)
data value in the hash (type is cacher)
arg pointer 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:
filename the filename
digit01 where to place the first two digits (size 3 chars!)
digit23 where 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:
spoolroot the 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:
arg the 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:
create true if the directory for the file should be generated
p pool that should be used for string operations
spl location for the spool root
host host of the xdb request (the 'spool folder')
file the basename of the xdb file
ext the extension for the xdb file
use_subdirs true 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:
host the host to load the file for (just for generating log messages)
fname the filename of the file, that should be loaded
cache a 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:
arg pointer 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().


Generated on Wed Sep 10 01:59:48 2008 for jabberd14 by  doxygen 1.5.5