fdbfile.c File Reference

fdb - database using text files as the backend. More...

#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "boris.h"
#include "plugin.h"

Include dependency graph for fdbfile.c:

Go to the source code of this file.

Data Structures

struct  fdb_iterator
 handle used for iteration of all records of a particular domain. More...
struct  fdb_read_handle
 handle used for reading a record. More...
struct  fdb_write_handle
 handle used for writing. More...
struct  plugin_fdb_class
 class definition. More...

Defines

#define FDB_VALUE_MAX   4096
#define MKDIR(d)   mkdir(d, 0777)
#define PERROR(m)   perror(m)
#define VERBOSE   printf

Functions

static char * fdb_basepath (const char *domain)
 generate the directory used for a domain.
static int fdb_domain_init (const char *domain)
 initializes a domain.
static int fdb_istempname (const char *filename)
 checks to see if filename is a temp filename.
static struct fdb_iteratorfdb_iterator_begin (const char *domain)
 get an iterator that lists all records in domain.
static void fdb_iterator_end (struct fdb_iterator *it)
 finish the iterator.
static const char * fdb_iterator_next (struct fdb_iterator *it)
 get id of record.
static char * fdb_makepath (const char *domain, const char *id)
 creates a filename name.
static char * fdb_makepath_tmp (const char *domain, const char *id)
 creates a temporary name.
static int fdb_parse_line (char *line, const char **name, const char **value)
 modifies line and points name and value to the correct positions.
static struct fdb_read_handlefdb_read_begin (const char *domain, const char *id)
 start reading.
static struct fdb_read_handlefdb_read_begin_uint (const char *domain, unsigned id)
static int fdb_read_end (struct fdb_read_handle *h)
 end reading process, close the file and free the handle.
static void fdb_read_handle_free (struct fdb_read_handle *h)
 frees a read handle.
static int fdb_read_next (struct fdb_read_handle *h, const char **name, const char **value)
 read a line of data from the file.
static void fdb_write_abort (struct fdb_write_handle *h)
 terminate the creation of this record.
static struct fdb_write_handlefdb_write_begin (const char *domain, const char *id)
 open the file and start writing to it.
static struct fdb_write_handlefdb_write_begin_uint (const char *domain, unsigned id)
 same as fdb_write_begin() but takes a uint.
static int fdb_write_end (struct fdb_write_handle *h)
 move the temp file over the real file then close it.
static int fdb_write_format (struct fdb_write_handle *h, const char *name, const char *value_fmt,...)
 write a string to an open record.
static void fdb_write_handle_free (struct fdb_write_handle *h)
 frees a write handle.
static int fdb_write_pair (struct fdb_write_handle *h, const char *name, const char *value_str)
 write a string to an open record.
static int initialize (void)
static int ishex (const char code[2])
 return true if 2 characters are valid hexidecimal.
static int shutdown (void)
static void unescape (char *str)
 process XX escapes in-place.
static unsigned unhex (const char code[2])
 verify with ishex() before calling.

Variables

struct plugin_fdb_class plugin_class


Detailed Description

fdb - database using text files as the backend.

Author:
Jon Mayo <jon.mayo@gmail.com>
Date:
2009 Dec 27
Copyright 2009 Jon Mayo Ms-RL : See COPYING.txt for complete license text.

Definition in file fdbfile.c.


Define Documentation

#define FDB_VALUE_MAX   4096

Definition at line 32 of file fdbfile.c.

#define MKDIR (  )     mkdir(d, 0777)

Definition at line 28 of file fdbfile.c.

#define PERROR (  )     perror(m)

Definition at line 29 of file fdbfile.c.

#define VERBOSE   printf

Definition at line 30 of file fdbfile.c.


Function Documentation

static char* fdb_basepath ( const char *  domain  )  [static]

generate the directory used for a domain.

Definition at line 132 of file fdbfile.c.

Here is the caller graph for this function:

static int fdb_domain_init ( const char *  domain  )  [static]

initializes a domain.

(creates a directory to hold files)

Definition at line 223 of file fdbfile.c.

Here is the call graph for this function:

static int fdb_istempname ( const char *  filename  )  [static]

checks to see if filename is a temp filename.

must work with or without a path part.

Definition at line 160 of file fdbfile.c.

Here is the caller graph for this function:

static struct fdb_iterator* fdb_iterator_begin ( const char *  domain  )  [static, read]

get an iterator that lists all records in domain.

Definition at line 495 of file fdbfile.c.

Here is the call graph for this function:

static void fdb_iterator_end ( struct fdb_iterator it  )  [static]

finish the iterator.

Definition at line 571 of file fdbfile.c.

static const char* fdb_iterator_next ( struct fdb_iterator it  )  [static]

get id of record.

return NULL if no more ids.

Definition at line 529 of file fdbfile.c.

Here is the call graph for this function:

static char* fdb_makepath ( const char *  domain,
const char *  id 
) [static]

creates a filename name.

Definition at line 141 of file fdbfile.c.

Here is the caller graph for this function:

static char* fdb_makepath_tmp ( const char *  domain,
const char *  id 
) [static]

creates a temporary name.

Definition at line 150 of file fdbfile.c.

Here is the caller graph for this function:

static int fdb_parse_line ( char *  line,
const char **  name,
const char **  value 
) [static]

modifies line and points name and value to the correct positions.

dequotes the value portion.

Definition at line 192 of file fdbfile.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static struct fdb_read_handle* fdb_read_begin ( const char *  domain,
const char *  id 
) [static, read]

start reading.

Definition at line 398 of file fdbfile.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static struct fdb_read_handle* fdb_read_begin_uint ( const char *  domain,
unsigned  id 
) [static, read]

Definition at line 422 of file fdbfile.c.

Here is the call graph for this function:

static int fdb_read_end ( struct fdb_read_handle h  )  [static]

end reading process, close the file and free the handle.

Definition at line 476 of file fdbfile.c.

Here is the call graph for this function:

static void fdb_read_handle_free ( struct fdb_read_handle h  )  [static]

frees a read handle.

assumes f has already been closed.

Definition at line 182 of file fdbfile.c.

Here is the caller graph for this function:

static int fdb_read_next ( struct fdb_read_handle h,
const char **  name,
const char **  value 
) [static]

read a line of data from the file.

Definition at line 431 of file fdbfile.c.

Here is the call graph for this function:

static void fdb_write_abort ( struct fdb_write_handle h  )  [static]

terminate the creation of this record.

it is still necessary to call fdb_write_end()

Definition at line 391 of file fdbfile.c.

static struct fdb_write_handle* fdb_write_begin ( const char *  domain,
const char *  id 
) [static, read]

open the file and start writing to it.

Definition at line 237 of file fdbfile.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static struct fdb_write_handle* fdb_write_begin_uint ( const char *  domain,
unsigned  id 
) [static, read]

same as fdb_write_begin() but takes a uint.

Definition at line 263 of file fdbfile.c.

Here is the call graph for this function:

static int fdb_write_end ( struct fdb_write_handle h  )  [static]

move the temp file over the real file then close it.

Definition at line 341 of file fdbfile.c.

Here is the call graph for this function:

static int fdb_write_format ( struct fdb_write_handle h,
const char *  name,
const char *  value_fmt,
  ... 
) [static]

write a string to an open record.

this interface is limited to FDB_VALUE_MAX. you can only use a name once per transaction (begin/end)

Todo:
make this interface not limit the value.

< holds the largest possible value.

Definition at line 326 of file fdbfile.c.

Here is the call graph for this function:

static void fdb_write_handle_free ( struct fdb_write_handle h  )  [static]

frees a write handle.

assumes f has already been closed.

Definition at line 172 of file fdbfile.c.

Here is the caller graph for this function:

static int fdb_write_pair ( struct fdb_write_handle h,
const char *  name,
const char *  value_str 
) [static]

write a string to an open record.

you can only use a name once per transaction (begin/end)

Definition at line 273 of file fdbfile.c.

Here is the caller graph for this function:

static int initialize ( void   )  [static]

Definition at line 649 of file fdbfile.c.

Here is the call graph for this function:

static int ishex ( const char  code[2]  )  [static]

return true if 2 characters are valid hexidecimal.

Definition at line 82 of file fdbfile.c.

Here is the caller graph for this function:

static int shutdown ( void   )  [static]

Definition at line 656 of file fdbfile.c.

Here is the call graph for this function:

static void unescape ( char *  str  )  [static]

process XX escapes in-place.

removes trailing whitespace too.

Definition at line 103 of file fdbfile.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned unhex ( const char  code[2]  )  [static]

verify with ishex() before calling.

Definition at line 89 of file fdbfile.c.

Here is the caller graph for this function:


Variable Documentation


Generated on Mon Dec 28 09:03:34 2009 for boris by  doxygen 1.5.8