llconf 0.0.2
entry.h File Reference

Data Structures

struct  cnfresult
 A structure to hold the results of cnf_find_entry. More...
 

Functions

struct cnfresultcreate_cnfresult (struct cnfnode *cn, const char *path)
 Create a cnfresult structure.
 
void destroy_cnfresult (struct cnfresult *cr)
 Free a single cnfresult element.
 
void destroy_cnfresult_list (struct cnfresult *cr_list)
 Free a cnfresult structure list by calling destroy_cnfresult() for all list members.
 
struct cnfresultcnf_find_entry (struct cnfnode *cn_root, const char *path)
 Find all matching entries in a tree.
 
struct cnfnodecnf_add_branch (struct cnfnode *cn_root, const char *path, int do_merge)
 Add a branch to a tree.
 
int cnf_del_branch (struct cnfnode *cn_root, const char *path, int del_empty)
 Delete a branch of the tree.
 
int cnf_set_entry (struct cnfnode *cn_root, const char *path, const char *val, int do_create)
 Set the value of a single entry in the tree.
 
const char * cnf_get_entry (struct cnfnode *cn_root, const char *path)
 Get the value of a single entry in the tree.
 
struct cnfnodecnf_get_node (struct cnfnode *cn_root, const char *path)
 Get a pointer to a single node in the tree.
 
void strip_cnftree (struct cnfnode *cn_root)
 Strip comments and empty lines from the tree.
 

Function Documentation

◆ cnf_add_branch()

struct cnfnode * cnf_add_branch ( struct cnfnode * cn_root,
const char * path,
int do_merge )

Add a branch to a tree.

Add a branch to an existing tree of nodes. If part of the tree already exists, and do_merge==1, the remainder will be created. For example, if path is "iface/eth0/address", and "iface/eth0" already exists and do_merge==1, just "address" will be appended to "iface/eth0". If do_merge==0, a whole new subtree, starting with "iface" will be appended.

Parameters
[in]cn_rootpointer to the root of the tree
[in]paththe path to append to
[in]do_mergeflag as described above
Returns
pointer to the last newly created node

◆ cnf_del_branch()

int cnf_del_branch ( struct cnfnode * cn_root,
const char * path,
int del_empty )

Delete a branch of the tree.

Deletes a subtree pointed to by path. If more than one matching entry exists, the first one will be deleted. If del_empty==1, and by removing the parent tree becomes empty, the parents will be removed recursively. If del_empty==0, an empty subtree may be left behind. In any case, memory of the subtree and deleted parents will be freed.

Parameters
[in]cn_rootpointer to the root of the tree
[in]paththe path of the tree to be deleted
[in]del_emptyset to 1 if empty parents shall be removed.

◆ cnf_find_entry()

struct cnfresult * cnf_find_entry ( struct cnfnode * cn_root,
const char * path )

Find all matching entries in a tree.

Search in the cnfnode tree for entries matching the given path specification.

Parameters
[in]cn_rootThe root of the cnfnode tree
[in]pathA string specifying the path to be sought.
Returns
A cnfresult with a list of matching results.

◆ cnf_get_entry()

const char * cnf_get_entry ( struct cnfnode * cn_root,
const char * path )

Get the value of a single entry in the tree.

Get the value of an entry pointed to by path.

Parameters
[in]cn_rootA pointer to the root of the tree.
[in]paththe path of the entry.
Returns
A pointer to the string value of the requested node, or NULL if the node doesn't exist or doesn't have a value.
See also
cnf_find_entry

◆ cnf_get_node()

struct cnfnode * cnf_get_node ( struct cnfnode * cn_root,
const char * path )

Get a pointer to a single node in the tree.

Get the node of an entry pointed to by path. If more than one matching entry exists, the first one will be returned.

Parameters
[in]cn_rootA pointer to the root of the tree.
[in]pathThe path to seek.
Returns
A pointer to the node on success, or NULL if the node is not found.
See also
cnf_find_entry

◆ cnf_set_entry()

int cnf_set_entry ( struct cnfnode * cn_root,
const char * path,
const char * val,
int do_create )

Set the value of a single entry in the tree.

Set the value of an entry pointed to by path. If more than one matching entry exists, the first one will be set. If do_create==1, a new node (or subtree) will be created, if the entry does not exist. if do_create==0, -1 will be returned, and errno will be set to ENOENT.

Parameters
[in]cn_rootpointer to the root of the tree
[in]paththe path of the entry
[in]valthe (new) value of the entry
[in]do_createflag as described above
Returns
0 on success, and -1 on error.

◆ create_cnfresult()

struct cnfresult * create_cnfresult ( struct cnfnode * cn,
const char * path )

Create a cnfresult structure.

Parameters
[in]cnThe cnfnode to be represented by the new cnfresult.
[in]pathThe (optional) fully-qualified path to the node.
Returns
The pointer to the newly allocated cnfresult.

◆ destroy_cnfresult()

void destroy_cnfresult ( struct cnfresult * cr)

Free a single cnfresult element.

Parameters
[in]crThe structure to free.

◆ destroy_cnfresult_list()

void destroy_cnfresult_list ( struct cnfresult * cr_list)

Free a cnfresult structure list by calling destroy_cnfresult() for all list members.

Parameters
[in]cr_listpointer to the cnfresult list to destroy.

◆ strip_cnftree()

void strip_cnftree ( struct cnfnode * cn_root)

Strip comments and empty lines from the tree.

In particular, all nodes with names starting with a dot are removed from the tree. This will include any .comment, .empty or .unparsed nodes, for example.

Parameters
[in]cn_rootA pointer to the root of the tree which is to be stripped.