| kdbprivate.h(3elektra) | Elektra | kdbprivate.h(3elektra) |
NAME¶
kdbprivate.h - Private declarations.
SYNOPSIS¶
#include <kdb.h>
#include <kdbconfig.h>
#include <kdbextension.h>
#include <kdbhelper.h>
#include <kdbmacros.h>
#include <kdbplugin.h>
#include <kdbproposal.h>
#include <kdbtypes.h>
#include <kdbglobal.h>
#include <limits.h>
Macros¶
#define KEYSET_SIZE 16
The minimal allocation size of a keyset inclusive NULL byte. #define
NR_OF_PLUGINS 10
How many plugins can exist in an backend. #define COMMIT_PLUGIN 7
The index of the commit plugin. #define STORAGE_PLUGIN 5
The index of the storage plugin. #define RESOLVER_PLUGIN 0
The index of the resolver plugin. #define APPROXIMATE_NR_OF_BACKENDS 16
Trie optimization. #define MAX_LEN_INT 31
The maximum of how many characters an integer needs as decimal number. #define
KDB_SYSTEM_ELEKTRA 'system/elektra'
Backend mounting information. #define test_bit(var, bit) ((var) &
(bit))
Test a bit. #define set_bit(var, bit) ((var) |= (bit))
Set a bit. #define clear_bit(var, bit) ((var) &= ~(bit))
Clear a bit.
Enumerations¶
enum keyflag_t { KEY_FLAG_SYNC = 1,
KEY_FLAG_RO_NAME = 1 << 1, KEY_FLAG_RO_VALUE = 1
<< 2, KEY_FLAG_RO_META = 1 << 3 }
Key Flags. enum ksflag_t { KS_FLAG_SYNC = 1 }
Ks Flags. enum splitflag_t { SPLIT_FLAG_SYNC = 1,
SPLIT_FLAG_CASCADING = 1 << 1 }
Functions¶
Split * splitNew (void)
Allocates a new split object. void splitDel (Split *keysets)
Delete a split object. void splitRemove (Split *split, size_t where)
Remove one part of split. ssize_t splitAppend (Split *split, Backend
*backend, Key *parentKey, int syncbits)
Increases the size of split and appends a new empty keyset. int
splitBuildup (Split *split, KDB *handle, Key *parentKey)
Walks through kdb->split and adds all backends below parentKey to split.
void splitUpdateFileName (Split *split, KDB *handle, Key *key)
Update the (configuration) file name for the parent key. int
splitAppoint (Split *split, KDB *handle, KeySet *ks)
Appoints all keys from ks to yet unsynced splits. int splitGet (Split
*split, Key *warningKey, KDB *handle)
Does some work after getting of backends is finished. int splitMerge
(Split *split, KeySet *dest)
Merges together all parts of split into dest. int splitDivide (Split
*split, KDB *handle, KeySet *ks)
Splits up the keysets and search for a sync bit in every key. int
splitSync (Split *split)
Add sync bits everywhere keys were removed/added. void splitPrepare
(Split *split)
Prepares for kdbSet() mainloop afterwards. int splitUpdateSize
(Split *split)
Also update sizes after kdbSet() to recognize multiple kdbSet()
attempts. Backend * backendOpen (KeySet *elektra_config, KeySet
*modules, Key *errorKey)
Builds a backend out of the configuration supplied from: Backend *
backendOpenDefault (KeySet *modules, const char *file, Key *errorKey)
Opens a default backend using the plugin named KDB_RESOLVER and KDB_STORAGE.
Backend * backendOpenModules (KeySet *modules, Key *errorKey)
Backend * backendOpenVersion (Key *errorKey)
Opens the internal version backend. int backendUpdateSize (Backend
*backend, Key *parent, int size)
Update internal size in backend. Plugin * elektraPluginOpen (const char
*backendname, KeySet *modules, KeySet *config, Key *errorKey)
Opens a plugin. int elektraProcessPlugin (Key *cur, int *pluginNumber,
char **pluginName, char **referenceName, Key *errorKey)
int elektraProcessPlugins (Plugin **plugins, KeySet *modules, KeySet
*referencePlugins, KeySet *config, KeySet *systemConfig, Key *errorKey)
Load a plugin. int trieClose (Trie *trie, Key *errorKey)
Closes the trie and all opened backends within. Backend * trieLookup
(Trie *trie, const Key *key)
The Trie structure. Trie * trieInsert (Trie *trie, const char *name,
Backend *value)
Insert into trie. int mountOpen (KDB *kdb, KeySet *config, KeySet
*modules, Key *errorKey)
Creates a trie from a given configuration. int mountDefault (KDB *kdb,
KeySet *modules, int inFallback, Key *errorKey)
Reopens the default backend and mounts the default backend if needed. int
mountModules (KDB *kdb, KeySet *modules, Key *errorKey)
Mount all module configurations. int mountVersion (KDB *kdb, Key
*errorKey)
Mount the version backend. int mountBackend (KDB *kdb, Backend
*backend, Key *errorKey)
Mounts a backend into the trie. Key * mountGetMountpoint (KDB *handle,
const Key *where)
Lookup a mountpoint in a handle for a specific key. " Backend *
mountGetBackend (KDB *handle, const Key *key)
Lookup a backend handle for a specific key. Key * elektraKsPrev (KeySet
*ks)
Returns the previous Key in a KeySet. Key * elektraKsPopAtCursor
(KeySet *ks, cursor_t pos)
Pop key at given cursor position. int elektraKeyLock (Key *key, enum
elektraLockOptions what)
Permanently locks a part of the key. ssize_t ksSearchInternal (const
KeySet *ks, const Key *toAppend)
" ssize_t elektraMemcpy (Key **array1, Key **array2, size_t size)
Internal Methods for Elektra. ssize_t elektraMemmove (Key **array1, Key
**array2, size_t size)
Copies the key array2 into where array1 points. int
elektraValidateKeyName (const char *name, size_t size)
Validates whether the supplied keyname is valid. KeySet *
elektraRenameKeys (KeySet *config, const char *name)
Takes the first key and cuts off this common part for all other keys, instead
name will be prepended.
Detailed Description¶
Private declarations.
Copyright:
Macro Definition Documentation¶
#define clear_bit(var, bit) ((var) &= ~(bit))¶
Clear a bit.
See also:
#define KDB_SYSTEM_ELEKTRA 'system/elektra'¶
Backend mounting information. This key directory tells you where each backend is mounted to which mountpoint.
#define KEYSET_SIZE 16¶
The minimal allocation size of a keyset inclusive NULL byte. ksGetAlloc() will return one less because it says how much can actually be stored.
#define MAX_LEN_INT 31¶
The maximum of how many characters an integer needs as decimal number.
#define NR_OF_PLUGINS 10¶
How many plugins can exist in an backend.
#define set_bit(var, bit) ((var) |= (bit))¶
Set a bit.
See also:
#define test_bit(var, bit) ((var) & (bit))¶
Test a bit.
See also:
Enumeration Type Documentation¶
enum keyflag_t¶
Key Flags. Store a synchronizer state so that the Elektra knows if something has changed or not.
Enumerator
- KEY_FLAG_SYNC
- Key need sync. If name, value or metadata are changed this flag will be set, so that the backend will sync the key to database.
- KEY_FLAG_RO_NAME
- Read only flag for name. Key name is read only and not allowed to be changed. All attempts to change the name will lead to an error. Needed for metakeys and keys that are in a data structure that depends on name ordering.
- KEY_FLAG_RO_VALUE
- Read only flag for value. Key value is read only and not allowed to be changed. All attempts to change the value will lead to an error. Needed for metakeys
- KEY_FLAG_RO_META
- Read only flag for meta. Key meta is read only and not allowed to be changed. All attempts to change the value will lead to an error. Needed for metakeys.
enum ksflag_t¶
Ks Flags. Store a synchronizer state so that the Elektra knows if something has changed or not.
Enumerator
- KS_FLAG_SYNC
- KeySet need sync. If keys were popped from the Keyset this flag will be set, so that the backend will sync the keys to database.
enum splitflag_t¶
Enumerator
- SPLIT_FLAG_SYNC
- KeySet in Split need sync. Is there any key in there which need to be synced? If keys were popped from the Keyset this flag will be set, so that the backend will sync the keys to database.
- SPLIT_FLAG_CASCADING
- Do we need relative checks? Is this a cascading backend?
Function Documentation¶
Backend* backendOpen (KeySet * elektraConfig, KeySet * modules, Key * errorKey)¶
Builds a backend out of the configuration supplied from:
system/elektra/mountpoints/<name>
The root key must be like the above example. You do not need to rewind the keyset. But every key must be below the root key.
The internal consistency will be checked in this function. If necessary parts are missing, like no plugins, they cant be loaded or similar 0 will be returned.
ksCut() is perfectly suitable for cutting out the configuration like needed.
Note:
Parameters:
modules used to load new modules or get references to existing one
errorKey the key where an error and warnings are added
Returns:
Return values:
Backend* backendOpenDefault (KeySet * modules, const char * file, Key * errorKey)¶
Opens a default backend using the plugin named KDB_RESOLVER and KDB_STORAGE.
Parameters:
errorKey the key to issue warnings and errors to
Returns:
Backend* backendOpenModules (KeySet * modules, Key * errorKey)¶
Returns:
Parameters:
errorKey the key to issue warnings and errors to
Backend* backendOpenVersion (Key * errorKey)¶
Opens the internal version backend.
Parameters:
Returns:
int backendUpdateSize (Backend * backend, Key * parent, int size)¶
Update internal size in backend.
Parameters:
parent for parent
size to update (-1 default, 0 empty, >0 otherwise)
Precondition:
Return values:
0 on success
int elektraKeyLock (Key * key, enum elektraLockOptions what)¶
Permanently locks a part of the key. This can be:
- KEY_FLAG_LOCK_NAME to lock the name
- KEY_FLAG_LOCK_VALUE to lock the value
- KEY_FLAG_LOCK_META to lock the metadata
To unlock the key, duplicate it.
It is also possible to lock when the key is created with keyNew().
Some data structures need to lock the key (most likely its name), so that the ordering does not get confused.
Parameters:
See also:
Return values:
0 if everything was locked before
-1 if it could not be locked (nullpointer)
Key* elektraKsPopAtCursor (KeySet * ks, cursor_t pos)¶
Pop key at given cursor position.
Parameters:
c where to pop
The internal cursor will be rewinded using ksRewind(). You can use ksGetCursor() and ksSetCursor() jump back to the previous position. e.g. to pop at current position within ksNext() loop:
cursor_t c = ksGetCursor(ks); keyDel (ksPopAtCursor(ks, c)); ksSetCursor(ks, c); ksPrev(ks); // to have correct key after next ksNext()
Warning:
Returns:
Return values:
Key* elektraKsPrev (KeySet * ks)¶
Returns the previous Key in a KeySet. KeySets have an internal cursor that can be reset with ksRewind(). Every time ksPrev() is called the cursor is decremented and the new current Key is returned.
You'll get a NULL pointer if the key before begin of the KeySet was reached.
Don't delete the key, use ksPop() if you want to delete it.
Returns:
See also:
ssize_t elektraMemcpy (Key ** array1, Key ** array2, size_t size)¶
Internal Methods for Elektra. To use them:
#include <kdbinternal.h>
There are some areas where libraries have to reimplement some basic functions to archive support for non-standard systems, for testing purposes or to provide a little more convenience. Copies the key array2 into where array1 points. It copies size elements.
Overlapping is prohibited, use elektraMemmove() instead.
Parameters:
array2 the source
size how many pointer to Keys to copy
Return values:
0 if nothing was done
Returns:
ssize_t elektraMemmove (Key ** array1, Key ** array2, size_t size)¶
Copies the key array2 into where array1 points. It copies size elements.
Overlapping is ok. If they do not overlap consider elektraMemcpy() instead.
Parameters:
array2 the source
size how many pointer to Keys to copy
Return values:
0 if nothing was done
Returns:
Plugin* elektraPluginOpen (const char * name, KeySet * modules, KeySet * config, Key * errorKey)¶
Opens a plugin. The config will be used as is. So be sure to transfer ownership of the config to it, with e.g. ksDup(). elektraPluginClose() will delete the config.
Returns:
int elektraProcessPlugin (Key * cur, int * pluginNumber, char ** pluginName, char ** referenceName, Key * errorKey)¶
Return values:
2 and an allocated string of the referenceName if an old plugin should be used
3 and both if a new plugin should be created and made available for later back referencing.
-1 on error
int elektraProcessPlugins (Plugin ** plugins, KeySet * modules, KeySet * referencePlugins, KeySet * config, KeySet * systemConfig, Key * errorKey)¶
Load a plugin. The array of plugins must be set to 0. Its length is NR_OF_PLUGINS.
systemConfig will only be used, not deleted.
Parameters:
systemConfig the shared (system) config for the plugins. Every plugin additional get this config.
Return values:
KeySet* elektraRenameKeys (KeySet * config, const char * name)¶
Takes the first key and cuts off this common part for all other keys, instead name will be prepended.
Returns:
The first key is removed in the resulting keyset.
int elektraValidateKeyName (const char * name, size_t size)¶
Validates whether the supplied keyname is valid. The function looks for tangling escape characters in the end and for a minimum length.
Does not check for valid namespaces
Precondition:
Parameters:
size a elektraStrLen of the key name
Return values:
false if its invalid
int mountBackend (KDB * kdb, Backend * backend, Key * errorKey)¶
Mounts a backend into the trie.
Precondition:
Postcondition:
Warning:
Parameters:
backend the backend to mount
errorKey the key used to report warnings
Return values:
1 on success
int mountDefault (KDB * kdb, KeySet * modules, int inFallback, Key * errorKey)¶
Reopens the default backend and mounts the default backend if needed.
Precondition:
Parameters:
modules the current list of loaded modules
errorKey the key used to report warnings
Return values:
0 on success
Backend* mountGetBackend (KDB * handle, const Key * key)¶
Lookup a backend handle for a specific key. The required canonical name is ensured by using a key as parameter, which will transform the key to canonical representation.
Will return handle when no more specific KDB could be found.
If key is 0 or invalid the default backend will be returned.
Parameters:
key the key, that should be looked up.
Returns:
Key* mountGetMountpoint (KDB * handle, const Key * where)¶
Lookup a mountpoint in a handle for a specific key. Will return a key representing the mountpoint or null if there is no appropriate mountpoint e.g. its the root mountpoint.
Example:
Key * key = keyNew ("system/template");
KDB * handle = kdbOpen();
Key *mountpoint=0;
mountpoint=kdbGetMountpoint(handle, key);
printf("The backend I am using is %s mounted in %s0,
keyValue(mountpoint),
keyName(mountpoint));
kdbClose (handle);
keyDel (key);
Parameters:
where the key, that should be looked up.
Returns:
int mountModules (KDB * kdb, KeySet * modules, Key * errorKey)¶
Mount all module configurations.
Parameters:
modules the current list of loaded modules
errorKey the key used to report warnings
Return values:
0 otherwise
int mountOpen (KDB * kdb, KeySet * config, KeySet * modules, Key * errorKey)¶
Creates a trie from a given configuration. The config will be deleted within this function.
is not allowed to be executed before
Parameters:
modules the current list of loaded modules
config the configuration which should be used to build up the trie.
errorKey the key used to report warnings
Return values:
0 on success
int mountVersion (KDB * kdb, Key * errorKey)¶
Mount the version backend.
Parameters:
errorKey the key used to report warnings
Return values:
ssize_t splitAppend (Split * split, Backend * backend, Key * parentKey, int syncbits)¶
Increases the size of split and appends a new empty keyset. Initializes the element with the given parameters at size-1 to be used.
Will automatically resize split if needed.
Parameters:
backend the backend which should be appended
parentKey the parentKey which should be appended
syncbits the initial syncstate which should be appended
Return values:
Returns:
int splitAppoint (Split * split, KDB * handle, KeySet * ks)¶
Appoints all keys from ks to yet unsynced splits.
Precondition:
Parameters:
handle to determine to which backend a key belongs
ks the keyset to appoint to split
Return values:
-1 if no backend was found for a key
int splitBuildup (Split * split, KDB * kdb, Key * parentKey)¶
Walks through kdb->split and adds all backends below parentKey to split. Sets syncbits to 2 if it is a default or root backend (which needs splitting). The information is copied from kdb->split.
Precondition:
there needs to be a valid defaultBackend but its ok not to have a trie inside KDB.
parentKey must be a valid key! (could be implemented more generally, but that would require splitting up of keysets of the same backend)
Parameters:
kdb the handle to get information about backends
parentKey the information below which key the backends are from interest
Return values:
void splitDel (Split * keysets)¶
Delete a split object. Will free all allocated resources of a split keyset.
Parameters:
int splitDivide (Split * split, KDB * handle, KeySet * ks)¶
Splits up the keysets and search for a sync bit in every key. It does not check if there were removed keys, see splitSync() for the next step.
It does not create new backends, this has to be done by buildup before.
Precondition:
Parameters:
handle to get information where the individual keys belong
ks the keyset to divide
Return values:
1 if there were sync bits
-1 if no backend was found for any key
int splitGet (Split * split, Key * warningKey, KDB * handle)¶
Does some work after getting of backends is finished.
- Update sizes
- Removal of wrong keys
Precondition:
- check if keys are in correct backend
- remove syncbits
- update sizes in the backends
Parameters:
warningKey postcondition violations are reported here
handle the handle to preprocess the keys
Return values:
-1 if no backend was found for a key or split->parents has invalid namespace
int splitMerge (Split * split, KeySet * dest)¶
Merges together all parts of split into dest.
Parameters:
dest the destination keyset where all keysets are appended.
Return values:
Split* splitNew (void)¶
Allocates a new split object. Splits up a keyset into multiple keysets where each of them will passed to the correct kdbSet().
Initially the size is 0 and alloc is APPROXIMATE_NR_OF_BACKENDS.
Returns:
See also:
void splitPrepare (Split * split)¶
Prepares for kdbSet() mainloop afterwards. All splits which do not need sync are removed and a deep copy of the remaining keysets is done.
Parameters:
void splitRemove (Split * split, size_t where)¶
Remove one part of split.
Parameters:
where the position to cut away
Precondition:
Postcondition:
int splitSync (Split * split)¶
Add sync bits everywhere keys were removed/added.
- checks if the size of a previous kdbGet() is unchanged.
- checks if in correct state (kdbGet() needs to be executed before)
Only splitDivide() together with this function can really decide if sync is needed or not.
Precondition:
Return values:
1 if kdbSet() is needed
-1 on wrong keys (also has assert, should not happen)
-2 wrong spec state: kdbGet() was not executed before
-3 wrong dir state: kdbGet() was not executed before
-4 wrong user state: kdbGet() was not executed before
-5 wrong system state: kdbGet() was not executed before
Precondition:
Parameters:
void splitUpdateFileName (Split * split, KDB * handle, Key * key)¶
Update the (configuration) file name for the parent key.
Parameters:
handle the handle to work with
key the parentKey that should be updated (name must be correct)
int splitUpdateSize (Split * split)¶
Also update sizes after kdbSet() to recognize multiple kdbSet() attempts.
Warning:
int trieClose (Trie * trie, Key * errorKey)¶
Closes the trie and all opened backends within.
Parameters:
errorKey the key used to report warnings
Return values:
Trie* trieInsert (Trie * trie, const char * name, Backend * value)¶
Insert into trie.
Parameters:
name the key's name to insert
value the value to insert
Return values:
Backend* trieLookup (Trie * trie, const Key * key)¶
The Trie structure. Lookups a backend inside the trie.
Returns:
0 otherwise
Parameters:
key the name of this key will be looked up
Author¶
Generated automatically by Doxygen for Elektra from the source code.
| Mon Jan 15 2018 | Version 0.8.20 |