Implementation for path-based string data storage. More...
Go to the source code of this file.
Functions | |
void | datanode_copy (struct datanode *dest, struct datanode *src, int overwrite) |
Copies values at and beneath a source node to a destination, optionally overwriting. | |
void | datanode_destroy (struct datanode *node) |
Frees memory allocated for all node beneath a given node. | |
int | datanode_exists (struct datanode *node, const char *path) |
Tests whether any values exists at or beneath a node. | |
void | datanode_init (struct datanode *node, const char *key) |
Initializes a blank datanode. | |
struct datanode * | datanode_lookup (struct datanode *node, const char *path, int create) |
Obtains a node beneath a given node, pathing through child nodes as appropriate. | |
struct datanode * | datanode_lookup_expert (struct datanode *node, char *path, int create) |
The same as datanode_lookup, except that the input path is destructively modified (slashes replaced with ''). | |
void | datanode_read (struct datanode *node, FILE *stream, const char *type_char, int overwrite) |
Reads nodes from a file stream into a given node. | |
void | datanode_write (struct datanode *node, FILE *stream, const char *type_char) |
Prints all value-containing nodes beneath a given node in LRU (least recently used) order. |
Implementation for path-based string data storage.
Definition in file datanode.c.
Copies values at and beneath a source node to a destination, optionally overwriting.
The destination must already have been initialized via datanode_init or obtained via datanode_lookup.
This function also copies mod_type, val_type, and meta even from source nodes that do not have values, but only if overwiting or if the destination has no value. Further, this function does not copy val if val_type is negative (assumed to be non-string).
dest | the node to receive copied values | |
src | the node to be copied | |
overwrite | whether to overwite existing values |
Definition at line 192 of file datanode.c.
References datanode_lookup_expert(), datanode::first_child, datanode::key, datanode::meta, datanode::mod_type, datanode::next, datanode::val, and datanode::val_type.
Referenced by fx_copy_module().
void datanode_destroy | ( | struct datanode * | node | ) |
Frees memory allocated for all node beneath a given node.
node | the node to destruct |
Definition at line 66 of file datanode.c.
References datanode::first_child, datanode::key, datanode::next, and datanode::val.
Referenced by fx_done().
int datanode_exists | ( | struct datanode * | node, | |
const char * | path | |||
) |
Tests whether any values exists at or beneath a node.
This is a somewhat awkward definition of "exists", but reflects the fact that valueless node may be created for metadata purposes only. It is equivalent to asking whether a node's key will occur with a value or in a path when printing.
node | the containing node of the node to check for | |
path | the path of the node to chedk for |
Definition at line 185 of file datanode.c.
References datanode_lookup().
void datanode_init | ( | struct datanode * | node, | |
const char * | key | |||
) |
Initializes a blank datanode.
node | a freshly constructed datanode | |
key | the name of the datanode; e.g. "" for root |
Definition at line 60 of file datanode.c.
References datanode::key.
Obtains a node beneath a given node, pathing through child nodes as appropriate.
The key passed to this function may be a slash-delimited path as in UNIX. Child nodes are (optionally) created if they do not exist, and both found and created entries are moved to the ends of their containing lists. This causes nodes to be printed in LRU order.
It is never your responsibility to allocate or free memory for entire nodes, though when modifying a node's value, you must free the old value and provide a new one that may later be freed; i.e. do not use string constants, but instead strdup them first.
node | the containing node of the node to find | |
path | the path of the node to find | |
create | whether to create the node if it does not exist |
Definition at line 156 of file datanode.c.
References datanode_lookup_expert().
Referenced by datanode_exists().
The same as datanode_lookup, except that the input path is destructively modified (slashes replaced with '').
node | the containing node of the node to find | |
path | the path to the node to find; destructively modified | |
create | whether to create the node if it does not exist |
Definition at line 87 of file datanode.c.
References datanode::first_child, datanode::key, datanode::last_child, datanode::next, and datanode::parent.
Referenced by datanode_copy(), datanode_lookup(), and datanode_read().
void datanode_read | ( | struct datanode * | node, | |
FILE * | stream, | |||
const char * | type_char, | |||
int | overwrite | |||
) |
Reads nodes from a file stream into a given node.
Input format is identical to the output format for datanode_write. The ":type" segment is optional, with type set to 0 if emitted and left unchanged if type_chars is NULL (it still defaults to 0 for newly created nodes). Type is set via strchr(type_char, c)
.
node | the node to be filled | |
stream | the input stream | |
type_char | a string of characters indexed by node->type, or NULL if types should be ignored | |
overwrite | whether to overwerite existing values |
Definition at line 246 of file datanode.c.
References datanode_lookup_expert(), datanode::key, datanode::mod_type, unhex_in_place(), and datanode::val.
void datanode_write | ( | struct datanode * | node, | |
FILE * | stream, | |||
const char * | type_char | |||
) |
Prints all value-containing nodes beneath a given node in LRU (least recently used) order.
Node are printed in the format:
/path/from/root/key:type value
Type is given by character type_char
[node->type] if type_char is non-NULL; otherwise, it and its preceding colon are omitted. Nodes with negative val_type are not printed.
Due to conflicts with certain valid characters in keys and values (e.g. colons, spaces, and newlines), non-alphanumeric characters other than "_+,-.[]" are converted to 'XX', where XX is the hexadecimal ASCII value.
node | the node to print | |
stream | the output stream | |
type_char | a string of characters indexed by node->type, or NULL if types should not be printed |
Definition at line 226 of file datanode.c.
References datanode::first_child, hex_to_stream(), datanode::mod_type, datanode::next, datanode::val, and datanode::val_type.