CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Functions
clixon_qdb.h File Reference

Go to the source code of this file.

Data Structures

struct  db_pair
 

Functions

int db_init (char *file)
 
int db_delete (char *file)
 
int db_set (char *file, char *key, void *data, size_t datalen)
 
int db_get (char *file, char *key, void *data, size_t *datalen)
 
int db_get_alloc (char *file, char *key, void **data, size_t *datalen)
 
int db_del (char *file, char *key)
 
int db_exists (char *file, char *key)
 
int db_regexp (char *file, char *regexp, const char *label, struct db_pair **pairs, int noval)
 
char * db_sanitize (char *rx, const char *label)
 

Function Documentation

int db_del ( char *  file,
char *  key 
)

Delete database entry

Parameters
[in]filedatabase file
[in]keydatabase key
Return values
-1on failure,
0if key did not exist
1if successful.
int db_delete ( char *  file)

Remove database by removing file, if it exists *

Parameters
[in]filedatabase file
int db_exists ( char *  file,
char *  key 
)

Check if entry in database exists

Parameters
[in]filedatabase file
[in]keydatabase key
Return values
1if key exists in database
0key does not exist in database
-1error
int db_get ( char *  file,
char *  key,
void *  data,
size_t *  datalen 
)

Get data from database

Parameters
[in]filedatabase file
[in]keydatabase key
[out]dataPre-allocated buffer where data corresponding key is placed
[out]datalenLength of pre-allocated buffer
Return values
0if OK: value returned. If not found, zero string returned
-1on error
See Also
db_get_alloc Allocates memory
int db_get_alloc ( char *  file,
char *  key,
void **  data,
size_t *  datalen 
)

Get data from database and allocates memory Similar to db_get but returns a malloced pointer to the data instead of copying data to pre-allocated buffer. This is necessary if the length of the data is not known when calling the function.

Parameters
[in]filedatabase file
[in]keydatabase key
[out]dataAllocated buffer where data corresponding key is placed
[out]datalenLength of pre-allocated buffer
Return values
0if OK: value returned. If not found, zero string returned
-1on error
Note
: *data needs to be freed after use.
char *lvec = NULL;
size_t len = 0;
if (db_get-alloc(dbname, "a.0", &val, &vlen) == NULL)
return -1;
..do stuff..
if (val) free(val);
See Also
db_get Pre-allocates memory
int db_init ( char *  file)

Open database for reading and writing

Parameters
[in]filedatabase file
int db_regexp ( char *  file,
char *  regexp,
const char *  label,
struct db_pair **  pairs,
int  noval 
)

Return all entries in database that match a regular expression.

Parameters
[in]filedatabase file
[in]regexpregular expression for database keys
[in]labelfor memory/chunk allocation
[out]pairsVector of database keys and values
[in]novalIf set don't retreive values, just keys
Return values
-1on error
nNumber of pairs
struct db_pair *pairs;
int npairs;
if ((npairs = db_regexp(dbname, "^/test/kalle$", __FUNCTION__,
&pairs, 0)) < 0)
err;
char* db_sanitize ( char *  rx,
const char *  label 
)

Sanitize regexp string. Escape '\' etc.

int db_set ( char *  file,
char *  key,
void *  data,
size_t  datalen 
)

Write data to database

Parameters
[in]filedatabase file
[in]keydatabase key
[out]dataBuffer containing content
[out]datalenLength of buffer
Return values
0if OK: value returned. If not found, zero string returned
-1on error