Data Structures | |
struct | _treeconf_ctx_s |
Treeconf context structure. More... | |
struct | _treeconf_node_s |
Treeconf node structure. More... | |
struct | _treeconf_str_s |
Treeconf string structure. More... | |
struct | _treeconf_subst_s |
Treeconf substitution structure. More... | |
Defines | |
#define | TREECONF_CTX_MAGIC |
Treeconf context magic number. | |
#define | TREECONF_CTX_INIT |
Configuration context initializer. | |
#define | tx_verify(ctx) |
Context verification macro. | |
#define | tx_config(ctx) |
Context configuration node pointer. | |
#define | tx_count(ctx) |
Context configuration node count. | |
#define | tc_init(ctx) |
Configuration context dynamic initializer. | |
#define | TREECONF_NODE_MAGIC |
Treeconf node magic number. | |
#define | tn_verify(node) |
Configuration node verification macro. | |
#define | tn_context(node) |
Configuration node context. | |
#define | tn_type(node) |
Configuration node type. | |
#define | tn_next(node) |
Next configuration node. | |
#define | tn_down(node) |
Child configuration node. | |
#define | tn_parent(node) |
Parent configuration node. | |
#define | tn_nodown(node) |
Implicit registration callback function. | |
#define | tn_change(node) |
Value change callback function. | |
#define | tn_value(node) |
Variable value. | |
#define | tn_default(node) |
Variable default value. | |
#define | tn_assoc(node) |
Association data. | |
#define | tn_name(node) |
Node name. | |
#define | tn_isdef(node) |
Node value is default? | |
#define | ts_string(strs, n) |
String pointer. | |
#define | ts_length(strs, n) |
String length. | |
#define | TC_SUBST_INSECURE |
Insecure substitution flag. | |
#define | TC_SUBST_IGNORE |
Ignore substitution flag. | |
#define | TC_SUBST_INIT(chr, str, flags) |
Substitution static initializer. | |
#define | tu_char(sub) |
Substitution rule character. | |
#define | tu_value(sub) |
Substitution value. | |
#define | tu_flags(sub) |
Substitution flags. | |
#define | TC_PATH_SECURE |
Prohibit insecure substitutions. | |
#define | TC_PATH_ALL |
Search all files in the path. | |
Typedefs | |
typedef _treeconf_ctx_s | treeconf_ctx_t |
Configuration context. | |
typedef _treeconf_node_s | treeconf_node_t |
Configuration node. | |
typedef _treeconf_str_s | treeconf_str_t |
Configuration strings. | |
typedef _treeconf_subst_s | treeconf_subst_t |
Path substitutions. | |
typedef int(* | treeconf_nodown_t )(treeconf_ctx_t *ctx, treeconf_node_t *parent, treeconf_str_t *name, int elements) |
Unregistered variable callback. | |
typedef void(* | treeconf_change_t )(treeconf_ctx_t *ctx, treeconf_node_t *node) |
Variable change callback. | |
typedef unsigned int(* | treeconf_file_t )(const char *file, void *data) |
Path callback. | |
Enumerations | |
enum | treeconf_type_t { TC_NODETYPE_VARIABLE, TC_NODETYPE_NODE, TC_NODETYPE_IMPLICIT, TC_NODETYPE_MASK } |
Node type. More... | |
Functions | |
unsigned int | tc_break (treeconf_str_t **str_p, int *cnt_p, const char *name, const char *delims) |
Break a string into an array of components. | |
unsigned int | tc_path (const char *path, const char *def, treeconf_subst_t substs[], int s_cnt, unsigned int flags, treeconf_file_t call, void *call_data) |
Search a path-like string for readable files. | |
unsigned int | tc_destroy (treeconf_ctx_t *ctx) |
Destroy a context. | |
unsigned int | tc_register (treeconf_ctx_t *ctx, const char *name, const char *def, treeconf_node_t *parent, treeconf_nodown_t nodown, treeconf_change_t change, void *assoc) |
Register a configuration variable. | |
unsigned int | tc_set (treeconf_ctx_t *ctx, const char *name, const char *value, treeconf_node_t *parent) |
Set a variable to a given value. | |
unsigned int | tc_get (treeconf_ctx_t *ctx, const char *name, const char **value, treeconf_node_t *parent) |
Get the value of a variable. | |
unsigned int | tc_find (treeconf_ctx_t *ctx, const char *name, treeconf_node_t **node, treeconf_node_t *parent) |
Obtain a pointer to a given node. | |
unsigned int | tc_load (const char *file, void *ctx) |
Load a configuration file. |
|
This macro simply initializes a dynamically allocated treeconf_ctx_t.
Definition at line 267 of file treeconf.h. |
|
Normally, tc_path() searches for the first readable file and calls the callback for that file. However, some applications may wish to read all files in a given path. This flag may be used to force tc_path() to behave in that fashion. Definition at line 701 of file treeconf.h. Referenced by _subst(). |
|
This flag, when passed to the tc_path() function, prohibits any and all insecure substitutions---tilde expansion for the current user and any caller-specific substitutions flagged as insecure. Definition at line 692 of file treeconf.h. Referenced by tc_path(). |
|
Some substitutions may not be available under certain circumstances. This flag will cause the given substitution to be ignored. Definition at line 543 of file treeconf.h. |
|
This static initializer may be used for statically creating an array of substitutions. The values of the given substitutions may be filled in just prior to the call to tc_path().
Definition at line 555 of file treeconf.h. |
|
Some substitutions may be insecure when used by a setuid program. This flag may be used to mark a particular substitution as insecure. Definition at line 535 of file treeconf.h. |
|
This macro retrieves a pointer to the association data associated with the given
Definition at line 452 of file treeconf.h. |
|
Some applications may need to know when the value of a particular variable changes. They may do this by setting the
Definition at line 408 of file treeconf.h. |
|
This macro returns a pointer to the configuration context a given
Definition at line 324 of file treeconf.h. |
|
This macro retrieves a pointer to the string representing the default value of the given
Definition at line 438 of file treeconf.h. |
|
This macro is used when traversing the configuration tree. It returns the first child node of the current
Definition at line 363 of file treeconf.h. |
|
This macro checks to see if the given
Definition at line 483 of file treeconf.h. |
|
This macro retrieves a pointer to the name of the given
Definition at line 471 of file treeconf.h. Referenced by _tc_lookup_node(). |
|
This macro is used when traversing the configuration tree. It returns the next node at the same level as the current
Definition at line 350 of file treeconf.h. |
|
When the application sets a variable that has not yet been registered, but has nodes that have, the
Definition at line 392 of file treeconf.h. Referenced by main(). |
|
This macro is used to retrieve the parent node of a given
Definition at line 375 of file treeconf.h. |
|
This macro is used to determine the type of the given
Definition at line 338 of file treeconf.h. Referenced by _tc_lookup_node(), and main(). |
|
This macro retrieves a pointer to the string representing the current value of the given
Definition at line 423 of file treeconf.h. Referenced by main(). |
|
This macro verifies that a given pointer actually does point to a configuration node.
Definition at line 312 of file treeconf.h. Referenced by tc_find(), tc_get(), tc_register(), and tc_set(). |
|
This is a static initialier for objects of type treeconf_ctx_t. Definition at line 219 of file treeconf.h. |
|
This is the magic number used for the treeconf context structure. Definition at line 213 of file treeconf.h. |
|
This is the magic number used for the treeconf node structure. Definition at line 298 of file treeconf.h. |
|
This macro returns the length of the string designated by
Definition at line 517 of file treeconf.h. Referenced by main(). |
|
This macro returns a pointer to the beginning of the string designated by
Definition at line 505 of file treeconf.h. Referenced by main(). |
|
The substitutions provided by tc_path() are introduced by a % character followed by another single character, as defined in a treeconf_subst_t structure. This macro, given
Definition at line 570 of file treeconf.h. |
|
This macro, given a
Definition at line 594 of file treeconf.h. |
|
This macro, given a
Definition at line 582 of file treeconf.h. Referenced by _subst(). |
|
The tx_config() macro returns a pointer to the first configuration node at the root level. The entire configuration tree may then be traversed.
Definition at line 246 of file treeconf.h. Referenced by _tc_lookup_node(), and main(). |
|
The tx_count() macro merely returns an integer indicating the number of configuration nodes allocated for this configuration.
Definition at line 258 of file treeconf.h. Referenced by main(). |
|
This macro verifies that a given pointer actually does point to a configuration context.
Definition at line 233 of file treeconf.h. Referenced by main(), tc_destroy(), tc_find(), tc_get(), tc_load(), tc_register(), and tc_set(). |
|
When a variable is registered, the application may set a callback so that it may be informed of that change. This type represents a pointer to that callback function.
Definition at line 180 of file treeconf.h. |
|
Almost all of the treeconf functions operate within a context defined by this structure. All of the various configuration settings and variable registrations are tied directly to this context, and so the context itself represents the exact configuration.
Definition at line 89 of file treeconf.h. Referenced by _tc_create_node(), _tc_lookup_node(), load_results(), main(), nodown_false(), nodown_true(), t_change(), tc_destroy(), tc_find(), tc_get(), tc_load(), tc_register(), and tc_set(). |
|
This type represents a pointer to a callback function used by tc_path() when a file in the path list exists and is readable. A non-zero return value will terminate the path search and will be returned by tc_path().
Definition at line 196 of file treeconf.h. |
|
Each configuration variable is represented as a node of a generalized tree. This structure represents each node of the tree, and will contain the actual value assigned to a specific configuration variable, as well as any references to callback functions.
Definition at line 102 of file treeconf.h. Referenced by _tc_create_node(), _tc_lookup_node(), _tc_release_children(), _tc_set(), main(), nodown_false(), nodown_true(), t_change(), tc_destroy(), tc_find(), tc_get(), tc_load(), tc_register(), and tc_set(). |
|
If an attempt is made to set an unregistered variable, the library will call a callback with a pointer to the last registered node in the line. If that callback returns a true value, then the unregistered variable will be implicitly registered. This type represents a pointer to that callback function.
Definition at line 167 of file treeconf.h. |
|
One fundamental operation in the Tree-based Configuration Management Library is breaking up variable names into lists of variable node names. This must be done without modifying the string, as some strings may be statically allocated in read-only memory. This is done by associating a length with each string. This structure is simply a means for grouping a length with a string pointer, and is only used by tc_break() and one callback function. Definition at line 115 of file treeconf.h. Referenced by _add_string(), _subst(), main(), nodown_false(), nodown_true(), tc_break(), and tc_path(). |
|
The library provides a helper function, tc_path(), for locating file(s) in a colon-separated list of file paths. Occasionally, substitutions may be desired---for instance, a path containing "~/.tconf" should always refer to the ".tconf" in the current user's home directory. This tilde expansion is performed automatically by tc_path(), but other substitutions may be permitted by the application. This structure provides a means of specifying the desired substitutions to tc_path(). Definition at line 128 of file treeconf.h. |
|
Each node in the configuration tree may be a variable node, meaning that it has an associated value, or a tree node, meaning that the node has no associated value but that it does have other nodes, possibly variable nodes, as descendants. This enumeration is used to indicate the type of node. It also contains a flag to indicate whether the node has been implicitly registered.
Definition at line 140 of file treeconf.h. Referenced by tc_register(). |
|
The tc_break() function is similar to strtok(), in that it splits a string up in components based on the delimiters in the
Definition at line 92 of file tc_break.c. References _add_string(), stringbuf::sb_comps, stringbuf::sb_count, and treeconf_str_t. Referenced by _tc_lookup_node(), main(), and tc_path(). |
Here is the call graph for this function:
|
This function is used to clean up the library. Every configuration variable is destroyed and the memory returned to the system. The context is unusable after calling this function; it must be reinitialized by calling tc_init().
Definition at line 34 of file tc_destroy.c. References _tc_release_node, _treeconf_node_s::tn_next, treeconf_ctx_t, treeconf_node_t, _treeconf_ctx_s::tx_config, _treeconf_ctx_s::tx_count, _treeconf_ctx_s::tx_magic, and tx_verify. Referenced by main(). |
|
The tc_find() function simply looks up the node named by
Definition at line 36 of file tc_find.c. References _tc_create_node(), _tc_doerror, _tc_lookup_node(), _tn_call_nodown, result::r_comps, result::r_count, result::r_node, result::r_startnew, TC_NODETYPE_IMPLICIT, TC_NODETYPE_NODE, TC_NODETYPE_VARIABLE, _treeconf_node_s::tn_change, _treeconf_node_s::tn_context, _treeconf_node_s::tn_nodown, tn_verify, treeconf_ctx_t, treeconf_node_t, _treeconf_str_s::ts_length, _treeconf_str_s::ts_string, and tx_verify. |
Here is the call graph for this function:
|
The tc_get() function obtains the value of the variable named by the
Definition at line 36 of file tc_get.c. References _tc_lookup_node(), result::r_comps, result::r_count, result::r_node, result::r_startnew, _treeconf_node_s::tn_context, _treeconf_node_s::tn_type, _treeconf_node_s::tn_value, tn_verify, treeconf_ctx_t, treeconf_node_t, and tx_verify. Referenced by main(). |
Here is the call graph for this function:
|
This is a convenience function for loading a configuration from a file or a set of files. Its signature matches that of the treeconf_file_t callback function so that it may be used with the tc_path() function.
The configuration file format is loosely based on the Windows INI format. Basically, it consists of a number of key-equals-value pairs, with each such pair terminated by a semicolon (' The tc_load() function may return any of the errors specified for tc_find(), tc_set(), open(), or read().
Definition at line 203 of file tc_load.c. References _tc_doerror, accum, clear, cunget, finish, Q_O, Q_S, Q_X, quoted, tc_find(), tc_set(), treeconf_ctx_t, treeconf_node_t, tx_verify, and xlate. Referenced by main(). |
Here is the call graph for this function:
|
The tc_path() function is a helper function designed to find one or more readable files in a colon-separated list of files. It performs a variety of substitutions, including inserting a default search string if the given path contains an empty field; expansion of user home directories via the ~ mechanism; and arbitrary, caller-defined substitutions of the form %c, where
For the first readable file in the path (or for all readable files, if the TC_PATH_ALL flag was used), the function specified by the function pointer
For more information about substitutions, see the documentation for treeconf_subst_t and the TC_SUBST_INSECURE, TC_SUBST_INIT(), tu_char(), tu_value(), and tu_flags() macros. For more information on the callback function, see the documentation for treeconf_file_t. For the possible
Definition at line 349 of file tc_path.c. References _subst(), buf::str, substs, tc_break(), TC_PATH_SECURE, treeconf_str_t, treeconf_subst_t, and _treeconf_str_s::ts_length. |
Here is the call graph for this function:
|
The tc_register() function registers a configuration node with the library. A given configuration node may be either a variable node, which may have a value, or a tree node, which may have children. A variable node may not have children, and a tree node may not have a value. Variable nodes are created by passing a non-
The name of the node to register is given by the constant string
Finally, the
Definition at line 36 of file tc_register.c. References _tc_create_node(), _tc_doerror, _tc_lookup_node(), _tc_release_children(), _tn_call_change, result::r_comps, result::r_count, result::r_node, result::r_startnew, TC_NODETYPE_NODE, TC_NODETYPE_VARIABLE, _treeconf_node_s::tn_assoc, _treeconf_node_s::tn_change, _treeconf_node_s::tn_context, _treeconf_node_s::tn_default, _treeconf_node_s::tn_down, _treeconf_node_s::tn_nodown, _treeconf_node_s::tn_parent, _treeconf_node_s::tn_type, _treeconf_node_s::tn_value, tn_verify, treeconf_ctx_t, treeconf_node_t, treeconf_type_t, _treeconf_str_s::ts_length, _treeconf_str_s::ts_string, and tx_verify. Referenced by load_results(), and main(). |
Here is the call graph for this function:
|
The tc_set() function sets the variable named by
Definition at line 76 of file tc_set.c. References _tc_create_node(), _tc_doerror, _tc_lookup_node(), _tc_release_children(), _tc_set(), _tn_call_nodown, result::r_comps, result::r_count, result::r_node, result::r_startnew, TC_NODETYPE_IMPLICIT, TC_NODETYPE_NODE, TC_NODETYPE_VARIABLE, _treeconf_node_s::tn_change, _treeconf_node_s::tn_context, _treeconf_node_s::tn_nodown, _treeconf_node_s::tn_type, tn_verify, treeconf_ctx_t, treeconf_node_t, _treeconf_str_s::ts_length, _treeconf_str_s::ts_string, and tx_verify. |
Here is the call graph for this function: