\subsection*{Definition}

In Elektra multiple keys may refer to the same part of the configuration. A {\itshape namespace} is the part of the key that refers to the key's origin (like a unique path).

Possible sources are\+:


\begin{DoxyItemize}
\item {\bfseries spec/something} for specification of other keys
\item {\bfseries proc/something} for in-\/memory keys (e.\+g. command-\/line)
\item {\bfseries dir/something} for dir keys in current working directory
\item {\bfseries system/something} for system keys in /etc or /
\item {\bfseries user/something} for user keys in home directory
\item $\ast$$\ast$/something$\ast$$\ast$ for cascading keys (actually refers to one of the above)
\end{DoxyItemize}

Having namespaces enables both admins and users to set specific parts of the application's configuration.

\subsection*{How it works on the command line (kdb)}

Let's say your app requires the following configuration data\+:


\begin{DoxyItemize}
\item {\bfseries sw/org/myapp/policy} -\/ a security policy to be applied
\item {\bfseries sw/org/myapp/default\+\_\+dir} -\/ a place where the application stores its data per default
\end{DoxyItemize}

We now want to enter this configuration by using the {\bfseries kdb} tool.

The security policy will most probably be set by your system administrator. So she enters \begin{DoxyVerb}    sudo kdb set "system/sw/org/myapp/policy" "super-high-secure"
\end{DoxyVerb}


The key {\bfseries system/app/policy} will be stored in the system namespace (probably at /etc/kdb on a Linux/\+U\+N\+I\+X system).

Then the user sets his app directory by issuing\+: \begin{DoxyVerb}    kdb set "user/sw/org/myapp/default_dir" "/home/user/.myapp"
\end{DoxyVerb}


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 {\bfseries kdb} tool\+: \begin{DoxyVerb}    kdb get system/sw/org/maypp
\end{DoxyVerb}


{\itshape Cascading keys} are keys that start with $\ast$$\ast$/$\ast$$\ast$ 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 $\ast$$\ast$/sw/org/myapp$\ast$$\ast$, like this\+: \begin{DoxyVerb}    kdb get /sw/org/myapp/policy
    kdb get /sw/org/myapp/default_dir
\end{DoxyVerb}


When using cascading key the best key will be searched at runtime. If you are only interested in the system key, you would use\+: \begin{DoxyVerb}    kdb get system/sw/org/myapp/policy
\end{DoxyVerb}


\subsection*{How it works in C}

The idea is to call {\bfseries \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} to retrieve the root key for the application. Looking for a specific part of the configuration is done by {\bfseries \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}}.

The documentation provides the following example to illustrate the intended usage. If you want to use a {\itshape cascading key} (starting with /), you use the {\bfseries \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ks\+Lookup()}} or {\bfseries \hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ks\+Lookup\+By\+Name()}} function (also see \href{http://doc.libelektra.org/api/current/html/group__keyset.html#gaa34fc43a081e6b01e4120daa6c112004}{\tt doxygen} )\+: \begin{DoxyVerb}    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");\end{DoxyVerb}
 