Elektra
0.8.18
|
In Elektra multiple keys may refer to the same part of the configuration. A namespace is the part of the key that refers to the key's origin (like a unique path).
Possible sources are:
Having namespaces enables both admins and users to set specific parts of the application's configuration.
Let's say your app requires the following configuration data:
We now want to enter this configuration by using the kdb tool.
The security policy will most probably be set by your system administrator. So she enters
sudo kdb set "system/sw/org/myapp/policy" "super-high-secure"
The key system/app/policy will be stored in the system namespace (probably at /etc/kdb on a Linux/UNIX system).
Then the user sets his app directory by issuing:
kdb set "user/sw/org/myapp/default_dir" "/home/user/.myapp"
This key will be stored in the user namespace (at the home directory) and thus may vary from user to user. Elektra loads the value for the current user and passes it to the application.
You can also retrieve the values in the command line by using the kdb tool:
kdb get system/sw/org/maypp
Cascading keys are keys that start with **/** and are a way of making key lookups much easier. Let's say you want to load the configuration from the example above. You do not need to search every namespace by yourself. Just make a lookup for **/sw/org/myapp**, like this:
kdb get /sw/org/myapp/policy kdb get /sw/org/myapp/default_dir
When using cascading key the best key will be searched at runtime. If you are only interested in the system key, you would use:
kdb get system/sw/org/myapp/policy
The idea is to call kdbGet() to retrieve the root key for the application. Looking for a specific part of the configuration is done by ksLookup().
The documentation provides the following example to illustrate the intended usage. If you want to use a cascading key (starting with /), you use the ksLookup() or ksLookupByName() function (also see doxygen ):
if (kdbGet(handle, myConfig, p=keyNew("/sw/org/myapp", KEY_END)) == -1) errorHandler ("Could not get Keys", parentKey); if ((myKey = ksLookupByName (myConfig, "/sw/org/myapp/mykey", 0)) == NULL) errorHandler ("Could not Lookup Key");