2 * Copyright (c) 2013, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Confizery configuration tree
32 * This module defines a structure cfzy_conftree that stores the full
33 * configuration tree (composed of cfzy_confnode structures), and some
34 * meta data like the number of nodes in the tree, a hash table used
35 * to do a node lookup by its name, the path of the configuration tree
39 #ifndef _CFZY_CONFTREE_H_
40 #define _CFZY_CONFTREE_H_
42 #include "cfzy_confnode.h"
47 * Structure storing the config tree
49 struct cfzy_conftree {
50 char *path; /**< path of conftree file */
51 struct cfzy_confnode *root; /**< pointer to root node */
52 int count; /**< number of nodes */
53 struct cfzy_htable *nodes_htable; /**< htable of nodes, indexed by name */
54 struct cfzy_confnode_list prio_list; /**< ordered list of nodes */
58 * Create a new configuration tree
60 * Parse a configuration tree and allocate a new conftree
61 * structure. The structure must be freed with cfzy_conftree_free().
64 * name of the configuration tree file
66 * the allocated conftree structure, or NULL on error
68 struct cfzy_conftree *cfzy_conftree_new(const char *filename);
71 * Free a configuration tree structure
73 * Free a configuration tree structure previously allocated with
74 * cfzy_conftree_new().
77 * the configuration tree structure to be freed
79 void cfzy_conftree_free(struct cfzy_conftree *conftree);
82 * Dump a configuration tree structure in a file
85 * the configuration tree structure to be freed
87 * file where conf should be dumped
89 * 0 on success, negative on error
91 int cfzy_conftree_dump(const struct cfzy_conftree *conftree,
92 const char *filename);
95 * Evaluate a configuration tree structure
97 * Parse all nodes following priority list and set the effective_value
98 * field by calling cfzy_confnode_evaluate() which takes care of
99 * default values, user values, and dependencies.
102 * the configuration tree structure
104 * 0 on success, negative on error
106 int cfzy_conftree_evaluate(struct cfzy_conftree *conftree);
109 * Save values of configuration tree
111 * For each node, copy the effective_value field in
112 * old_effective_value and the user_value field in old_user_value.
113 * These values can be used later with cfzy_conftree_filter() to
114 * compare the old values with the new ones.
117 * the configuration tree structure
119 * 0 on success, negative on error
121 int cfzy_conftree_save_values(struct cfzy_conftree *conftree);
123 /* flags to be used with cfzy_conftree_filter() */
124 #define CFZY_FILTER_F_USR_UNSET 0x01
125 #define CFZY_FILTER_F_EFF_UNSET 0x02
126 #define CFZY_FILTER_F_USR_CHANGED 0x04
127 #define CFZY_FILTER_F_EFF_CHANGED 0x08
130 * Get a list of nodes matching conditions
132 * Return the list of nodes in configuration tree that match
133 * conditions. Example: cfzy_conftree_filter(contree,
134 * CFZY_FILTER_F_USR_UNSET) will return all nodes that have no user
135 * value (set to NULL).
138 * the configuration tree structure
140 * list of conditions (CFZY_FILTER_F_*)
142 * 0 on success, negative on error
144 struct cfzy_list_head *
145 cfzy_conftree_filter(struct cfzy_conftree *conftree, int flags);
147 #endif /* _CFZY_CONFTREE_H_ */