Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
config-lookup.c File Reference

Implementation draft for a configuration system (2008). More...

Go to the source code of this file.

Description

Implementation draft for a configuration system (2008).

Implementation of the lookup of configuration keys

Todo:
as of 2016 this code is unused and likely to be replaced by a different approach.

Definition in file config-lookup.c.

#include "include/logging.h"
#include "lib/safeclib.h"
#include "lib/tmpbuf.h"
#include "common/config-lookup.h"
#include "common/config.h"

Functions

 LUMIERA_ERROR_DEFINE (CONFIG_LOOKUP, "config lookup failure")
 
static int cmp_fn (const void *a, const void *b)
 
static void delete_fn (PSplaynode node)
 
static const void * key_fn (const PSplaynode node)
 
LumieraConfigLookup lumiera_config_lookup_init (LumieraConfigLookup self)
 Initialise a lookup structure.
 
LumieraConfigLookup lumiera_config_lookup_destroy (LumieraConfigLookup self)
 Destroy a lookup structure.
 
LumieraConfigLookupentry lumiera_config_lookup_insert (LumieraConfigLookup self, LumieraConfigitem item)
 Add a config item to a lookup structure.
 
LumieraConfigLookupentry lumiera_config_lookup_insert_default (LumieraConfigLookup self, LumieraConfigitem item)
 
LumieraConfigitem lumiera_config_lookup_remove (LumieraConfigLookup self, LumieraConfigitem item)
 Remove a config item from a lookup structure.
 
LumieraConfigLookupentry lumiera_config_lookup_find (LumieraConfigLookup self, const char *key)
 Find a hashtable entry in the lookup structure.
 
LumieraConfigitem lumiera_config_lookup_item_find (LumieraConfigLookup self, const char *key)
 Find a the topmost config item stored to a given key.
 
LumieraConfigitem lumiera_config_lookup_item_tail_find (LumieraConfigLookup self, const char *key)
 Find a the bottom most config item stored to a given key.
 
LumieraConfigLookupentry lumiera_config_lookupentry_init (LumieraConfigLookupentry self, const char *key)
 
LumieraConfigLookupentry lumiera_config_lookupentry_new (const char *key)
 
LumieraConfigLookupentry lumiera_config_lookupentry_destroy (LumieraConfigLookupentry self)
 
void lumiera_config_lookupentry_delete (LumieraConfigLookupentry self)
 

Function Documentation

◆ LUMIERA_ERROR_DEFINE()

LUMIERA_ERROR_DEFINE ( CONFIG_LOOKUP  ,
"config lookup failure"   
)

◆ cmp_fn()

static int cmp_fn ( const void *  a,
const void *  b 
)
static

Definition at line 217 of file config-lookup.c.

Referenced by lumiera_config_lookup_init().

+ Here is the caller graph for this function:

◆ delete_fn()

static void delete_fn ( PSplaynode  node)
static

Definition at line 223 of file config-lookup.c.

References lumiera_config_lookupentry_delete().

Referenced by lumiera_config_lookup_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ key_fn()

static const void * key_fn ( const PSplaynode  node)
static

Definition at line 230 of file config-lookup.c.

Referenced by lumiera_config_lookup_init().

+ Here is the caller graph for this function:

◆ lumiera_config_lookup_init()

LumieraConfigLookup lumiera_config_lookup_init ( LumieraConfigLookup  self)

Initialise a lookup structure.

Parameters
selflookup structure to be initialised
Returns
self on success else NULL

Definition at line 50 of file config-lookup.c.

References cmp_fn(), delete_fn(), key_fn(), and psplay_init().

Referenced by lumiera_config_init(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_destroy()

LumieraConfigLookup lumiera_config_lookup_destroy ( LumieraConfigLookup  self)

Destroy a lookup structure.

Parameters
selflookup structure to be destroyed
Returns
self

Definition at line 59 of file config-lookup.c.

References psplay_destroy().

Referenced by lumiera_config_destroy(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_insert()

LumieraConfigLookupentry lumiera_config_lookup_insert ( LumieraConfigLookup  self,
LumieraConfigitem  item 
)

Add a config item to a lookup structure.

Config items are stored under their key and stacked in insertion order.

Parameters
selflookup structure where the item shall be added
itemconfig item to add to the lookup structure
Returns
opaque pointer to a hashtable entry

Definition at line 69 of file config-lookup.c.

References llist_insert_head, lumiera_config_lookupentry_new(), lumiera_tmpbuf_strcat3(), NULL, psplay_find(), and psplay_insert().

Referenced by lumiera_config_set(), lumiera_config_setdefault(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_insert_default()

LumieraConfigLookupentry lumiera_config_lookup_insert_default ( LumieraConfigLookup  self,
LumieraConfigitem  item 
)

Add a default config item to a lookup structure. The item must contain a full key and not part of any 'section' and is inserted as tail of the lookup list.

Parameters
selflookup structure where the item shall be added
itemconfig item to add to the lookup structure
Returns
opaque pointer to a hashtable entry

Definition at line 91 of file config-lookup.c.

References llist_insert_tail, lumiera_config_lookupentry_new(), lumiera_tmpbuf_snprintf(), psplay_find(), and psplay_insert().

+ Here is the call graph for this function:

◆ lumiera_config_lookup_remove()

LumieraConfigitem lumiera_config_lookup_remove ( LumieraConfigLookup  self,
LumieraConfigitem  item 
)

Remove a config item from a lookup structure.

Config must be removed from the lookup when they are not used anymore. Removing a config item unlinks it from the stack of all config items with the same key. When this was the last config item under that key, the lookup entry is cleaned up.

Parameters
selflookup structure where the item shall be removed
itemconfig item to be removed from the lookup
Returns
item

Definition at line 113 of file config-lookup.c.

References LLIST_TO_STRUCTP, and psplay_delete_node().

Referenced by lumiera_configitem_destroy(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_find()

LumieraConfigLookupentry lumiera_config_lookup_find ( LumieraConfigLookup  self,
const char *  key 
)

Find a hashtable entry in the lookup structure.

Internal function, can be used to check if at least one item is available for a given key.

Parameters
selflookup structure where the key shall be searched
keystring to be looked up
Returns
NULL if nothing is found, otherwise a opaque pointer to a hash table entry

Definition at line 136 of file config-lookup.c.

References psplay_find().

Referenced by lumiera_config_lookup_item_find(), and lumiera_config_lookup_item_tail_find().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_item_find()

LumieraConfigitem lumiera_config_lookup_item_find ( LumieraConfigLookup  self,
const char *  key 
)

Find a the topmost config item stored to a given key.

Parameters
selflookup structure where the key shall be searched
keystring to be looked up
Returns
the config item which was last stored under the given key or NULL when nothing was found

Definition at line 144 of file config-lookup.c.

References llist_head, LLIST_TO_STRUCTP, lumiera_config_lookup_find(), and NULL.

Referenced by lumiera_config_get(), lumiera_config_set(), lumiera_config_setdefault(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookup_item_tail_find()

LumieraConfigitem lumiera_config_lookup_item_tail_find ( LumieraConfigLookup  self,
const char *  key 
)

Find a the bottom most config item stored to a given key.

defaults sits at the bottom if exists

Parameters
selflookup structure where the key shall be searched
keystring to be looked up

Definition at line 159 of file config-lookup.c.

References llist_tail, LLIST_TO_STRUCTP, lumiera_config_lookup_find(), and NULL.

Referenced by lumiera_config_get_default().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookupentry_init()

LumieraConfigLookupentry lumiera_config_lookupentry_init ( LumieraConfigLookupentry  self,
const char *  key 
)

Definition at line 177 of file config-lookup.c.

References lumiera_strndup(), and psplaynode_init().

Referenced by lumiera_config_lookupentry_new().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookupentry_new()

LumieraConfigLookupentry lumiera_config_lookupentry_new ( const char *  key)

Definition at line 191 of file config-lookup.c.

References lumiera_config_lookupentry_init(), and lumiera_malloc().

Referenced by lumiera_config_lookup_insert(), and lumiera_config_lookup_insert_default().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookupentry_destroy()

LumieraConfigLookupentry lumiera_config_lookupentry_destroy ( LumieraConfigLookupentry  self)

Definition at line 198 of file config-lookup.c.

References lumiera_free().

Referenced by lumiera_config_lookupentry_delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_config_lookupentry_delete()

void lumiera_config_lookupentry_delete ( LumieraConfigLookupentry  self)

Definition at line 211 of file config-lookup.c.

References lumiera_config_lookupentry_destroy(), and lumiera_free().

Referenced by delete_fn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: