$darkmode
Elektra 0.11.0
Macros | Typedefs | Functions
kdbprivate.h File Reference

Private declarations. More...

#include <elektra.h>
#include <elektra/error.h>
#include <kdb.h>
#include <kdbextension.h>
#include <kdbhelper.h>
#include <kdbio.h>
#include <kdbmacros.h>
#include <kdbnotificationinternal.h>
#include <kdbplugin.h>
#include <kdbtypes.h>
#include <limits.h>
Include dependency graph for kdbprivate.h:
This graph shows which files directly or indirectly include this file:

Macros

#define KEYSET_SIZE   16
 The minimal allocation size of a keyset inclusive NULL byte. More...
 
#define APPROXIMATE_NR_OF_BACKENDS   16
 Trie optimization.
 
#define KDB_MAX_UCHAR   (UCHAR_MAX + 1)
 The maximum value of unsigned char+1, needed for iteration over trie children/values: More...
 
#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. More...
 
#define KDB_CACHE_PREFIX   "system:/elektra/cache"
 All keys below this are used for cache metadata in the global keyset.
 
#define test_bit(var, bit)   (((unsigned long long) (var)) & ((unsigned long long) (bit)))
 Test a bit. More...
 
#define set_bit(var, bit)   ((var) |= ((unsigned long long) (bit)))
 Set a bit. More...
 
#define clear_bit(var, bit)   ((var) &= ~((unsigned long long) (bit)))
 Clear a bit. More...
 

Typedefs

typedef struct _BackendData BackendData
 Holds all data for one backend. More...
 

Functions

struct _ElektraDiff * elektraDiffNew (KeySet *addedKeys, KeySet *removedKeys, KeySet *modifiedKeys, KeySet *modifiedNewKeys, Key *parentKey)
 Create an ElektraDiff. More...
 
Plugin * elektraPluginOpen (const char *backendname, KeySet *modules, KeySet *config, Key *errorKey)
 Opens a plugin. More...
 
size_t elektraPluginGetFunction (Plugin *plugin, const char *name)
 Retrieves a function exported by a plugin. More...
 
int initHooks (KDB *kdb, const KeySet *config, KeySet *modules, const KeySet *contract, Key *errorKey)
 Initializes the hooks stored in the passed KDB handle. More...
 
void freeHooks (KDB *kdb, Key *errorKey)
 Uninitializes and frees all hooks in the passed KDB handle. More...
 
Plugin * elektraFindInternalNotificationPlugin (KDB *kdb)
 This method looks for the hook plugin 'internalnotification'. More...
 
int keyReplacePrefix (Key *key, const Key *oldPrefix, const Key *newPrefix)
 Replaces a prefix of the key name of key. More...
 
Key * elektraKsPopAtCursor (KeySet *ks, elektraCursor pos)
 Pop key at given cursor position. More...
 
KeySet * ksRenameKeys (KeySet *config, const char *name)
 Takes the first key and cuts off this common part for all other keys, instead name will be prepended. More...
 
ssize_t ksRename (KeySet *ks, const Key *root, const Key *newRoot)
 Moves all keys below root to below newRoot. More...
 
elektraCursor ksFindHierarchy (const KeySet *ks, const Key *root, elektraCursor *end)
 Searches for the start and optionally end of the key hierarchy rooted at root in ks. More...
 
KeySet * ksBelow (const KeySet *ks, const Key *root)
 Retrieves all Keys from KeySet ks that are below or at root. More...
 
ssize_t ksSubtract (KeySet *total, const KeySet *sub)
 Remove all the keys in sub from total. More...
 
ssize_t elektraMemcpy (Key **array1, Key **array2, size_t size)
 Internal Methods for Elektra. More...
 
ssize_t elektraMemmove (Key **array1, Key **array2, size_t size)
 Copies the key array2 into where array1 points. More...
 
bool elektraKeyNameValidate (const char *name, bool isComplete)
 Takes an escaped key name and validates it. More...
 
void elektraKeyNameCanonicalize (const char *name, char **canonicalName, size_t *canonicalSizePtr, size_t offset, size_t *usizePtr)
 Takes a valid (non-)canonical key name and produces its canonical form. More...
 
void elektraKeyNameUnescape (const char *name, char *unescapedName)
 Takes a canonical key name and unescapes it. More...
 
size_t elektraKeyNameEscapePart (const char *part, char **escapedPart)
 Takes a single key name part and produces its escaped form. More...
 
int elektraIsArrayPart (const char *namePart)
 Checks if the given key name part is an array part. More...
 
ElektraError * elektraErrorCreate (const char *code, const char *description, const char *module, const char *file, kdb_long_t line)
 Creates a new ElektraError using the provided values. More...
 
void elektraErrorAddWarning (ElektraError *error, ElektraError *warning)
 Adds a warning to an existing ElektraError struct. More...
 
ElektraError * elektraErrorFromKey (Key *key)
 Extracts the error and all warnings from the given key. More...
 
ElektraError * elektraErrorKeyNotFound (const char *keyname)
 Creates a "Key not found" error. More...
 
ElektraError * elektraErrorWrongType (const char *keyname, KDBType expectedType, KDBType actualType)
 Creates a "Wrong type" error. More...
 
ElektraError * elektraErrorNullError (const char *function)
 Creates a "Null error argument" error. More...
 

Detailed Description

Private declarations.

Macro Definition Documentation

◆ clear_bit

#define clear_bit (   var,
  bit 
)    ((var) &= ~((unsigned long long) (bit)))

Clear a bit.

See also
set_bit()

◆ KDB_MAX_UCHAR

#define KDB_MAX_UCHAR   (UCHAR_MAX + 1)

The maximum value of unsigned char+1, needed for iteration over trie children/values:

for (i=0; i<KDB_MAX_UCHAR; ++i)

◆ KDB_SYSTEM_ELEKTRA

#define KDB_SYSTEM_ELEKTRA   "system:/elektra"

Backend mounting information.

This key directory tells you where each backend is mounted to which mountpoint.

◆ KEYSET_SIZE

#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.

◆ set_bit

#define set_bit (   var,
  bit 
)    ((var) |= ((unsigned long long) (bit)))

Set a bit.

See also
clear_bit()

◆ test_bit

#define test_bit (   var,
  bit 
)    (((unsigned long long) (var)) & ((unsigned long long) (bit)))

Test a bit.

See also
set_bit(), clear_bit()

Typedef Documentation

◆ BackendData

typedef struct _BackendData BackendData

Holds all data for one backend.

This struct is used for the key values in _KDB.backends

Function Documentation

◆ elektraDiffNew()

struct _ElektraDiff* elektraDiffNew ( KeySet *  addedKeys,
KeySet *  removedKeys,
KeySet *  modifiedKeys,
KeySet *  modifiedNewKeys,
Key *  parentKey 
)

Create an ElektraDiff.

The returned ElektraDiff contains the same KeySets that are passed in, so be sure to ksIncRef them if you plan to use them after deleting the ElektraDiff.

Same goes for the parent key, please use keyIncRef if you plan to use it after deleting the ElektraDiff

Parameters
addedKeysthe added keys
removedKeysthe removed keys
modifiedKeysthe modified keys
modifiedNewKeysthe modified keys with the new values
parentKeythe parent key
Returns
ElektraDiff with the provided parameters

◆ elektraErrorAddWarning()

void elektraErrorAddWarning ( ElektraError *  error,
ElektraError *  warning 
)

Adds a warning to an existing ElektraError struct.

If you want to report a warning without an error, create a dummy error with elektraErrorPureWarning() and then add a warning to it.

Parameters
errorThe error to which warning shall be added.
warningThe warning to add. Once added it is owned by error. DO NOT call elektraErrorReset() on it afterwards.

◆ elektraErrorCreate()

ElektraError* elektraErrorCreate ( const char *  code,
const char *  description,
const char *  module,
const char *  file,
kdb_long_t  line 
)

Creates a new ElektraError using the provided values.

The returned value will be allocated with elektraCalloc().

Parameters
codeThe error code of the error. Will be copied and stored in the struct.
descriptionThe description of the error. Will be copied and stored in the struct.
moduleThe module that raised the error. Will be copied and stored in the struct.
fileThe file that raised the error. Will be copied and stored in the struct.
lineThe line in which the error was raised.
Returns
A newly allocated ElektraError (free with elektraErrorReset()).

◆ elektraErrorFromKey()

ElektraError* elektraErrorFromKey ( Key *  key)

Extracts the error and all warnings from the given key.

If no error exists, a pure warning error will be used.

See also
elektraErrorPureWarning
Note
Use the functions in src/libs/elektra/errors.c to add errors to a key.
Parameters
keyThe to extract error and warnings from.
Returns
A newly allocated ElektraError (free with elektraErrorReset()).

◆ elektraErrorKeyNotFound()

ElektraError* elektraErrorKeyNotFound ( const char *  keyname)

Creates a "Key not found" error.

Parameters
keynameThe name of the key that wasn't found.
Returns
A newly allocated ElektraError (free with elektraErrorReset()).

◆ elektraErrorNullError()

ElektraError* elektraErrorNullError ( const char *  function)

Creates a "Null error argument" error.

Parameters
functionThe name of the function that was called with a null pointer error argument.
Returns
A newly allocated ElektraError (free with elektraErrorReset()).

◆ elektraErrorWrongType()

ElektraError* elektraErrorWrongType ( const char *  keyname,
KDBType  expectedType,
KDBType  actualType 
)

Creates a "Wrong type" error.

Parameters
keynameThe name of the key that had the wrong type.
expectedTypeThe type that was expected.
actualTypeThe type that was actually found.
Returns
A newly allocated ElektraError (free with elektraErrorReset()).

◆ elektraFindInternalNotificationPlugin()

Plugin* elektraFindInternalNotificationPlugin ( KDB *  kdb)

This method looks for the hook plugin 'internalnotification'.

Parameters
kdbthe KDB instance in which to search
Returns
NULL if not loaded, pointer to the plugin otherwise

◆ elektraKsPopAtCursor()

Key* elektraKsPopAtCursor ( KeySet *  ks,
elektraCursor  pos 
)

Pop key at given cursor position.

Parameters
ksthe keyset to pop key from
cwhere to pop
Returns
the popped key
Return values
0if ks is 0

◆ elektraMemcpy()

ssize_t elektraMemcpy ( Key **  array1,
Key **  array2,
size_t  size 
)

Internal Methods for Elektra.

To use them:

#include <kdbinternal.h>
Includes most internal header files.

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
array1the destination
array2the source
sizehow many pointer to Keys to copy
Return values
-1on null pointers
0if nothing was done
Returns
size how many keys were copied

◆ elektraMemmove()

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
array1the destination
array2the source
sizehow many pointer to Keys to copy
Return values
-1on null pointers
0if nothing was done
Returns
size how many keys were copied

◆ elektraPluginGetFunction()

size_t elektraPluginGetFunction ( Plugin *  plugin,
const char *  name 
)

Retrieves a function exported by a plugin.

Parameters
pluginPlugin handle
nameFunction name. Must be a valid key name suffix. May not contain the sequence '..'
Returns
Pointer to function. NULL if function not found or not enough memory available

◆ elektraPluginOpen()

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
a pointer to a new created plugin or 0 on error

◆ freeHooks()

void freeHooks ( KDB *  kdb,
Key *  errorKey 
)

Uninitializes and frees all hooks in the passed KDB handle.

Parameters
kdbthe KDB handle where the hooks should be freed
errorKeythe key which holds errors and warnings which were issued

◆ initHooks()

int initHooks ( KDB *  kdb,
const KeySet *  config,
KeySet *  modules,
const KeySet *  contract,
Key *  errorKey 
)

Initializes the hooks stored in the passed KDB handle.

If the handle already contains initialized hooks, they will be reinitialized, including unloading and loading of their plugins. Parameters config and contract will be used to determine which hooks to populate.

Parameters
kdbthe KDB instance where the hooks should be initialized
configKeySet containing the current config in system:/elektra namespace
modulesthe current list of loaded modules
contractthe contract passed to kdbOpen
errorKeythe key which holds errors and warnings which were issued
Returns
0 on success, -1 on failure