Data Structures | |
struct | _Key |
The private Key struct. More... | |
struct | _KeySet |
The private KeySet struct. More... | |
Enumerations | |
enum | KDBBackendMethod { KDB_BE_OPEN = 1, KDB_BE_CLOSE = 1<<1, KDB_BE_STATKEY = 1<<2, KDB_BE_GETKEY = 1<<3, KDB_BE_SETKEY = 1<<4, KDB_BE_SETKEYS = 1<<5, KDB_BE_RENAME = 1<<6, KDB_BE_REMOVEKEY = 1<<7, KDB_BE_GETCHILD = 1<<8, KDB_BE_MONITORKEY = 1<<9, KDB_BE_MONITORKEYS = 1<<10, KDB_BE_END = 0 } |
Switches to denote the backend methods. More... | |
Functions | |
ssize_t | unencode (char *encoded, void *returned) |
Unencodes a buffer of ASCII hexadecimal values into a byte stream. | |
int | kdbNeedsUTF8Conversion () |
Checks if UTF-8 conversion is needed in current context. | |
int | UTF8Engine (int direction, char **string, size_t *inputOutputByteSize) |
Converts string to (direction = UTF8_TO ) and from (direction = UTF8_FROM ) UTF-8. | |
ssize_t | encode (void *unencoded, size_t size, char *returned) |
Encodes a buffer of data onto hexadecimal ASCII. | |
int | kdbSetKeys_default (KeySet *ks) |
A high level, probably inefficient implementation for the kdbSetKeys() method. | |
uint32_t | kdbMonitorKeys_default (KeySet *interests, uint32_t diffMask, unsigned long iterations, unsigned sleeptime) |
A high level, probably inefficient, implementation for the kdbMonitorKeys() method. | |
uint32_t | kdbMonitorKey_default (Key *interest, uint32_t diffMask, unsigned long iterations, unsigned sleeptime) |
A high level, probably inefficient, implementation for the kdbMonitorKey() method. | |
KDBBackend * | kdbBackendExport (const char *backendName,...) |
This function must be called by a backend's kdbBackendFactory() to define the backend's methods that will be exported. | |
size_t | strblen (const char *s) |
Calculates the lenght in bytes of a string. | |
int | kdbOpen_backend () |
Initialize the backend. | |
int | kdbClose_backend () |
All finalization logic of the backend should go here. | |
int | kdbStatKey_backend (Key *key) |
Implementation for kdbStatKey() method. | |
int | kdbGetKey_backend (Key *key) |
Implementation for kdbGetKey() method. | |
int | kdbSetKey_backend (Key *key) |
Implementation for kdbSetKey() method. | |
int | kdbRename_backend (Key *key, const char *newName) |
Implementation for kdbRename() method. | |
int | kdbRemoveKey_backend (const Key *key) |
Implementation for kdbRemoveKey() method. | |
ssize_t | kdbGetKeyChildKeys_backend (const Key *parentKey, KeySet *returned, unsigned long options) |
Implementation for kdbGetKeyChildKeys() method. | |
int | kdbSetKeys_backend (KeySet *ks) |
Implementation for kdbSetKeys() method. | |
uint32_t | kdbMonitorKeys_backend (KeySet *interests, uint32_t diffMask, unsigned long iterations, unsigned sleep) |
The implementation of this method is optional. | |
uint32_t | kdbMonitorKey_backend (Key *interest, uint32_t diffMask, unsigned long iterations, unsigned sleep) |
The implementation of this method is optional. | |
KDBBackend * | kdbBackendFactory (void) |
All KeyDB methods implemented by the backend can have random names, except kdbBackendFactory(). |
Since version 0.4.9, Elektra can dynamically load different key storage backends. Fast jump to kdbBackendExport() to see an example of a backend implementation.
The methods of class KeyDB that are backend dependent are kdbOpen(), kdbClose(), kdbGetKey(), kdbSetKey(), kdbStatKey(), kdbGetKeyChildKeys(), kdbRemove(), kdbRename(). So a backend must reimplement these methods.
And methods that have a builtin default high-level inefficient implementation are kdbSetKeys(), kdbMonitorKey(), kdbMonitorKeys(). So it is suggested to reimplement them too, to make them more efficient.
The other KeyDB methods are higher level. They use the above methods to do their job, and generally don't have to be reimplemented for a different backend.
The backend must implement a method with name kdbBackendFactory() and no parameters, that is responsible of exporting the implementations of libelektra.so backend dependent methods.
The backend implementation must:
#include <kdb.h> #include <kdbbackend.h>
Better than that, a skeleton of a backend implementation is provided inside Elektra development package or source code tree, and should be used as a base for the implementation.
An elektrified program will use the backend defined by environment variable $KDB_BACKEND, The backend library is dynamically loaded when the program calls kdbOpen(), unless if the program is security/authentication/setuid related, in which it probably uses the more secure kdbOpenDefault() which completely ignores the $KDB_BACKEND environment and will use the "default"
named backend defined by the sysadmin. Look at /lib/libelektra-default
.so link to see the default backend for your system.
Elektra source code or development package provides a skeleton and Makefile to implement a backend, and we'll document this skeleton here.
A backend is defined by a single name, for example BACKENDNAME
, that causes libelektra.so look for its library as libelektra-BACKENDNAME
.so.
Elektra source code tree includes several backend implementations (http://germane-software.com/repositories/elektra/trunk/src/backends) that can also be used as a reference.
|
Switches to denote the backend methods. Used in calls to kdbBackendExport().
Definition at line 43 of file kdbbackend.h. |
|
Unencodes a buffer of ASCII hexadecimal values into a byte stream. The allowed format for the hexadecimal values is just a stream of pairs of plain hex-digits, all together or space-separated.
The
|
|
Checks if UTF-8 conversion is needed in current context. if nl_langinfo() is not available, no conversion is ever needed. If iconv usage is disabled there is no need to check if we need to convert. Furthermore, some systems have nl_langinfo(), but lacks ability to get CODESET through it. Look at the comments by the UTF8Engine() function for more information.
Definition at line 395 of file libkdb.c. Referenced by UTF8Engine(). |
|
Converts string to ( Since Elektra provides portability for key names and string values between different codesets, you should use this helper in your backend to convert to and from universal UTF-8 strings, when storing key names, values and comments. If iconv() or nl_langinfo() is not available on your system, or if iconv() usage is disabled (--disable-iconv on build time) simply return 0 immediately.
Definition at line 428 of file libkdb.c. References kdbNeedsUTF8Conversion(). |
|
Encodes a buffer of data onto hexadecimal ASCII. The resulting data is made up of pairs of ASCII hex-digits, space- and newline-separated. This is the counterpart of unencode().
The
Definition at line 504 of file libkdb.c. Referenced by keyToStreamBasename(). |
|
A high level, probably inefficient implementation for the kdbSetKeys() method.
If a backend doesn't want to reimplement this method, this implementation can be used, in which kdbSetKey() will be called for each Key object contained in
Definition at line 961 of file libkdb.c. References kdbSetKey(), keyNeedsSync(), ksCurrent(), and ksNext(). Referenced by kdbSetKeys(). |
|
A high level, probably inefficient, implementation for the kdbMonitorKeys() method. If a backend doesn't want to reimplement this method, this implementation can be used. Definition at line 1199 of file libkdb.c. References kdbMonitorKey(), ksCurrent(), ksNext(), and _KeySet::size. Referenced by kdbMonitorKeys(). |
|
A high level, probably inefficient, implementation for the kdbMonitorKey() method. If a backend doesn't want to reimplement this method, this implementation can be used. Definition at line 1298 of file libkdb.c. References KDB_RET_NOCRED, KDB_RET_NOTFOUND, kdbGetKey(), keyCompare(), keyDel(), keyDup(), keyGetNameSize(), and keyNew(). Referenced by kdbMonitorKey(). |
|
This function must be called by a backend's kdbBackendFactory() to define the backend's methods that will be exported. Its job is to organize a libelektra.so's table of virtual methods with pointers to backend dependent methods. The order and number of arguments are flexible (as keyNew()) to let libelektra.so evolve without breaking its ABI compatibility with backends. So for each method a backend must export, there is a flag defined by KDBBackendMethod. Each flag tells kdbBackendExport() which method comes next. A backend can have no implementation for a few methods that have default inefficient high-level implementations -- kdbSetKeys(), kdbMonitorKey(), kdbMonitorKeys() -- and to use these defaults, simply don't pass anything to kdbBackendExport() about them.
The last parameter must be
Definition at line 1425 of file libkdb.c. References KDB_BE_CLOSE, KDB_BE_GETCHILD, KDB_BE_GETKEY, KDB_BE_MONITORKEY, KDB_BE_MONITORKEYS, KDB_BE_OPEN, KDB_BE_REMOVEKEY, KDB_BE_RENAME, KDB_BE_SETKEY, KDB_BE_SETKEYS, KDB_BE_STATKEY, and strblen(). Referenced by kdbBackendFactory(). |
|
Calculates the lenght in bytes of a string. This function differs from strlen() because it is Unicode and multibyte chars safe. While strlen() counts characters and ignores the final NULL, strblen() count bytes including the ending NULL.
Definition at line 65 of file key.c. Referenced by commandSet(), kdbBackendExport(), kdbGetKeyByParent(), kdbGetKeyByParentKey(), kdbGetValueByParent(), kdbSetValueByParent(), keyAddBaseName(), keyGetBaseName(), keyGetComment(), keyGetCommentSize(), keyGetFullName(), keyGetFullNameSize(), keyGetFullRootNameSize(), keyGetName(), keyGetNameSize(), keyGetOwner(), keyGetOwnerSize(), keyGetParentNameSize(), keyNameGetBaseNameSize(), keySetBaseName(), keySetComment(), keySetLink(), keySetName(), keySetOwner(), keySetString(), keyToStreamBasename(), ksLookupByName(), ksLookupByValue(), ksToStream(), and parseCommandLine(). |
|
Initialize the backend. This is the first method kdbOpenBackend() calls after dynamically loading the backend library. This method is responsible of:
Definition at line 133 of file template.c. Referenced by kdbBackendFactory(). |
|
All finalization logic of the backend should go here. Called prior to unloading the backend dynamic module. Should ensure that no functions or static/global variables from the module will ever be accessed again. Should free any memory that the backend no longer needs. After this call, libelektra.so will unload the backend library, so this is the point to shutdown any affairs with the storage.
Definition at line 154 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbStatKey() method. This method is responsible of:
Definition at line 171 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbGetKey() method. This method is responsible of:
Definition at line 187 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbSetKey() method. This method is responsible of:
Definition at line 206 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbRename() method.
Definition at line 219 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbRemoveKey() method.
Definition at line 233 of file template.c. Referenced by kdbBackendFactory(). |
|
Implementation for kdbGetKeyChildKeys() method.
Definition at line 247 of file template.c. References _KeySet::size. Referenced by kdbBackendFactory(). |
|
Implementation for kdbSetKeys() method. The implementation of this method is optional, and a builtin, probablly inefficient implementation can be explicitly used when exporting the backend with kdbBackendExport(), using kdbSetKeys_default().
Definition at line 263 of file template.c. |
|
The implementation of this method is optional.
The builtin inefficient implementation will use kdbGetKey() for each key inside
Definition at line 277 of file template.c. Referenced by kdbBackendFactory(). |
|
The implementation of this method is optional.
The builtin inefficient implementation will use kdbGetKey() for
Definition at line 293 of file template.c. Referenced by kdbBackendFactory(). |
|
All KeyDB methods implemented by the backend can have random names, except kdbBackendFactory(). This is the single symbol that will be looked up when loading the backend, and the first method of the backend implementation that will be called. Its purpose is to "publish" the exported methods for libelektra.so. The implementation inside the provided skeleton is usually enough: simply call kdbBackendExport() with all methods that must be exported.
Definition at line 314 of file template.c. References KDB_BE_CLOSE, KDB_BE_END, KDB_BE_GETCHILD, KDB_BE_GETKEY, KDB_BE_MONITORKEY, KDB_BE_MONITORKEYS, KDB_BE_OPEN, KDB_BE_REMOVEKEY, KDB_BE_RENAME, KDB_BE_SETKEY, KDB_BE_STATKEY, kdbBackendExport(), kdbClose_backend(), kdbGetKey_backend(), kdbGetKeyChildKeys_backend(), kdbMonitorKey_backend(), kdbMonitorKeys_backend(), kdbOpen_backend(), kdbRemoveKey_backend(), kdbRename_backend(), kdbSetKey_backend(), and kdbStatKey_backend(). |