51 static int32_t hash_files(
const void *data,
int key) {
54 const char *hashkey = (key) ? data : file->
filename;
56 ret =
jenhash(hashkey, strlen(hashkey), 0);
61 static int32_t hash_cats(
const void *data,
int key) {
64 const char *hashkey = (key) ? data : cat->
name;
66 ret =
jenhash(hashkey, strlen(hashkey), 0);
71 static void initconfigfiles(
void) {
84 static void free_config_entry(
void *data) {
88 free((
void *)entry->
item);
91 free((
void *)entry->
value);
98 if (!category || !category->
entries || !(newentry =
objalloc(
sizeof(*newentry), free_config_entry))) {
109 static void free_config_category(
void *data) {
113 free((
void *)cat->
name);
123 if (!(newcat =
objalloc(
sizeof(*newcat), free_config_category))) {
133 static void free_config_file(
void *data) {
150 if (!(newfile =
objalloc(
sizeof(*newfile), free_config_file))) {
161 static char *filterconf(
const char *str,
int minlen) {
168 if ((token = strrchr(tmp,
'#'))) {
176 if ((token = strchr(tmp,
'#')) && (token == tmp)) {
181 if ((token = strchr(tmp,
';')) && (token == tmp)) {
186 if (strlen(tmp) < minlen) {
204 char *tmp = (
char *)&line;
211 file = create_conf_file(configname, configfile);
214 if (!(config = fopen(file->
filepath,
"r"))) {
218 while(fgets(line,
sizeof(line) - 1, config)) {
219 if (!(tmp = filterconf(line, 3))) {
224 if ((token = strchr(tmp,
'[')) && (token == tmp)) {
226 token = strrchr(tmp,
']');
233 category = create_conf_category(tmp);
239 if (sscanf(tmp,
"%[^=] %*[=] %[^\n]", (
char *)&item, (
char *)&value) != 2) {
244 category = create_conf_category(
"default");
248 add_conf_entry(category,
trim(item),
trim(value));
327 strncpy(name, category->
name, len);
351 static void entry_callback(
void *data,
void *entry_cb) {
355 callback = *cb_entry;
369 static void category_callback(
void *data,
void *category_cb) {
387 static void file_callback(
void *data,
void *file_cb) {
391 cb_file = *cb_fileptr;
int strlenzero(const char *str)
Check if a string is zero length.
struct bucket_list * cat
Categories.
void * create_bucketlist(int bitmask, blisthash hash_function)
int objref(void *data)
Reference a object.
void config_entry_callback(struct bucket_list *entries, config_entrycb entry_cb)
Callback Wraper that iterates through all items calling a callback for each item. ...
void config_file_callback(config_filecb file_cb)
Callback wrapper to iterate over all configfiles calling a callback on each file. ...
const char * name
Category name.
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
struct config_entry * get_config_entry(struct bucket_list *categories, const char *item)
Find the entry in a config file.
Configuration category entry.
void unrefconfigfiles(void)
Empty out and unreference config files.
void * next_bucket_loop(struct bucket_loop *bloop)
Return a reference to the next item in the list this could be the first item.
DTS Application library API Include file.
char * trim(const char *str)
Trim whitesapce from the beggining and end of a string.
void(* config_filecb)(struct bucket_list *, const char *, const char *)
Calback used when processing config files.
struct bucket_list * entries
Entries in category.
const char * filepath
File path.
struct bucket_loop * get_category_loop(const char *configname)
Return a bucket loop to allow iterating over categories.
struct bucket_list * get_config_file(const char *configname)
Returns the catergories bucket for a config file.
struct bucket_list * get_category_next(struct bucket_loop *cloop, char *name, int len)
Iterate through categories returning the entries bucket.
void bucketlist_callback(struct bucket_list *blist, blist_cb callback, void *data2)
Run a callback function on all items in the list.
#define jenhash(key, length, initval)
Define jenhash as hashlittle on big endian it should be hashbig.
void(* config_entrycb)(const char *, const char *)
Callback used when processing a entry.
const char * filename
Filename.
void(* config_catcb)(struct bucket_list *, const char *)
Calback used when processing a category.
Configuration file category.
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
void config_cat_callback(struct bucket_list *categories, config_catcb cat_cb)
Callback wrapper that iterates through categories calling a callback on each category.
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
void * bucket_list_find_key(struct bucket_list *list, const void *key)
Find and return a reference to a item matching supplied key.
int objunref(void *data)
Drop reference held.
struct bucket_list * get_config_category(const char *configname, const char *category)
Return a single category.
int process_config(const char *configname, const char *configfile)
Process a configfile into buckets.
struct bucket_loop * init_bucket_loop(struct bucket_list *blist)
Create a bucket list iterator to safely iterate the list.
Bucket list, hold hashed objects in buckets.