Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > 1f68756f2311732dff7a7e2ea2a48123 > files > 30

elektra-devel-0.7.0-3.fc13.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Elektra Projekt: KDB :: Low Level Methods</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>KDB :: Low Level Methods</h1>
<p>General methods to access the Key database.  
<a href="#_details">More...</a></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#ga40e35f26cc69bd43ef1b2207f4fa121b">kdbMount</a> (KDB *handle, const Key *mountpoint, const KeySet *config)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#ga400ca66a9bdc04ecadb66d84dc06bd55">kdbUnmount</a> (KDB *handle, const Key *mountpoint)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">Key *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#gaa3717146f45e5a9665377c7f5b71e39b">kdbGetMountpoint</a> (KDB *handle, const Key *where)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">KDB *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose</a> (KDB *handle)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">ssize_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet</a> (KDB *handle, KeySet *returned, Key *parentKey, option_t options)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">ssize_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet</a> (KDB *handle, KeySet *ks, Key *parentKey, option_t options)</td></tr>
</table>
<hr/><a name="_details"></a><h2>Detailed Description</h2>
<p>General methods to access the Key database. </p>
<p>To use them: </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;kdb.h&gt;</span>
</pre></div><p>The kdb*() class of methods are used to access the storage, to get and set <a class="el" href="group__key.html">Keys </a> or <a class="el" href="group__keyset.html">KeySets </a>.</p>
<p>The most important functions are:</p>
<ul>
<li><a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen()</a></li>
<li><a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a></li>
<li><a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a></li>
<li><a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a></li>
</ul>
<p>The two essential functions for dynamic information about backends are:</p>
<ul>
<li><a class="el" href="group__kdb.html#gaa3717146f45e5a9665377c7f5b71e39b">kdbGetMountpoint()</a></li>
<li>kdbGetCapability()</li>
</ul>
<p>They use some backend implementation to know the details about how to access the storage. Currently we have this backends:</p>
<ul>
<li><code>berkeleydb:</code> the keys are stored in a Berkeley DB database, providing very small footprint, speed, and other advantages.</li>
<li><code>filesys:</code> the key hierarchy and data are saved as plain text files in the filesystem.</li>
<li><code>ini:</code> the key hierarchy are saved into configuration files. <dl class="see"><dt><b>See also:</b></dt><dd><a href="http://www.libelektra.org/Ini">http://www.libelektra.org/Ini</a></dd></dl>
</li>
<li><code>fstab:</code> a reference backend used to interpret the <code>/etc/fstab</code> file as a set of keys under <code>system/filesystems</code> .</li>
<li><code>gconf:</code> makes Elektra use the GConf daemon to access keys. Only the <code>user/</code> tree is available since GConf is not system wide.</li>
</ul>
<p>Backends are physically a library named <code>/lib/libelektra-{NAME}</code>.so.</p>
<p>See <a class="el" href="group__backend.html">writing a new backend </a> for information about how to write a backend.</p>
<p>Language binding writers should follow the same rules:</p>
<ul>
<li>You must relay completely on the backend-dependent methods.</li>
<li>You may use or reimplement the second set of methods.</li>
<li>You should completely reimplement in your language the higher lever methods.</li>
<li>Many methods are just for comfort in C. These methods are marked and need not to be implemented if the binding language has e.g. string operators which can do the operation easily. </li>
</ul>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="gad9bb8bd3f1296bfa77cc9a1b41b7a859"></a><!-- doxytag: member="kdb.c::kdbClose" ref="gad9bb8bd3f1296bfa77cc9a1b41b7a859" args="(KDB *handle)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int kdbClose </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Closes the session with the Key database.</p>
<p>You should call this method when you finished your affairs with the key database. You can manipulate Key and KeySet objects also after <a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a>. You must not use any kdb* call afterwards. You can implement <a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a> in the atexit() handler.</p>
<p>This is the counterpart of <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen()</a>.</p>
<p>The <code>handle</code> parameter will be finalized and all resources associated to it will be freed. After a <a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a>, this <code>handle</code> can't be used anymore, unless it gets initialized again with another call to <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen()</a>.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen()</a> </dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>contains internal information of <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">opened </a> key database </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>0 on success </dd>
<dd>
-1 on NULL pointer </dd></dl>

</div>
</div>
<a class="anchor" id="ga37b44bda1b83bc0144916bf21a86c1b5"></a><!-- doxytag: member="kdb.c::kdbGet" ref="ga37b44bda1b83bc0144916bf21a86c1b5" args="(KDB *handle, KeySet *returned, Key *parentKey, option_t options)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ssize_t kdbGet </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">KeySet *&nbsp;</td>
          <td class="paramname"> <em>returned</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Key *&nbsp;</td>
          <td class="paramname"> <em>parentKey</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">option_t&nbsp;</td>
          <td class="paramname"> <em>options</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Retrieve keys in an atomic and universal way, all other kdbGet Functions rely on that one.</p>
<p>The <code>returned</code> KeySet must be initialized or may already contain some keys. The new retrieved keys will be appended using <a class="el" href="group__keyset.html#gaa5a1d467a4d71041edce68ea7748ce45">ksAppendKey()</a>.</p>
<p>In default behaviour (<code>options</code> = 0) it will fully retrieve all keys under the <code>parentKey</code> folder, with all subfolders and their children but not inactive keys or folders.</p>
<p>The keyset will not be sorted at first place, but will be marked dirty and sorted afterwards when needed. That could be a subsequent <a class="el" href="group__keyset.html#gaa34fc43a081e6b01e4120daa6c112004">ksLookup()</a>, <a class="el" href="group__keyset.html#gad2e30fb6d4739d917c5abb2ac2f9c1a1">ksLookupByName()</a> or <a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a>. See <a class="el" href="group__keyset.html#ga023554d395ccf2319a3807b8b5d2530c">ksSort()</a> on that issue.</p>
<p>The behaviour can be fine-tuned with options in various ways to make <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> more comfortable.</p>
<h2><a class="anchor" id="kdbgetoption">
Options</a></h2>
<p>The <code>option</code> is an array of the following ORed flags:</p>
<ul>
<li><code>option_t::KDB_O_DEL</code> <br/>
 Its often useful to <a class="el" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel()</a> the parentKey in the line after <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a>. Using this flag, you can just pass a key allocated with <a class="el" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew()</a>, <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> will free it for you in the end.</li>
<li><code>option_t::KDB_O_POP</code> <br/>
 The <code>parentKey</code> itself will always be added to <code>returned</code>. If you only want the children of the parentKey in <code>returned</code>, but not the parentKey itself, use this flag. This is only valid for the first parentKey, the one you passed. The other recursive parentKeys will stay in the keyset. To get only the leaves of the tree, without any parentKey, see option_t::KDB_O_NODIR below.</li>
<li><code>option_t::KDB_O_NODIR</code> <br/>
 Don't include folders in the <code>returned</code> KeySet, so only keys without subkeys. You can picture it best that you only get the leaves of the tree of keys.</li>
<li><code>option_t::KDB_O_DIRONLY</code> <br/>
 Put in <code>returned</code> only the folder keys. The resulting KeySet will be only the skeleton of the tree. This option must not be ORed together with KDB_O_DIR.</li>
<li><code>option_t::KDB_O_NOSTAT</code> <br/>
 Don't stat they keys, whatever <a class="el" href="group__keytest.html#ga3908b6511648a950f37cd0005bfea5d5">keyNeedStat()</a> says. That means that also the key value and comment will be retrieved. The flag will result in that all keys in <code>returned</code> don't have <a class="el" href="group__keytest.html#ga3908b6511648a950f37cd0005bfea5d5">keyNeedStat()</a> set.</li>
<li><code>option_t::KDB_O_STATONLY</code> <br/>
 Only stat the keys. It means that key value and comment will not be retrieved. The resulting keys will contain only meta info such as user and group IDs, owner, mode permissions and modification times. You don't need that flag if the keys already have <a class="el" href="group__keytest.html#ga3908b6511648a950f37cd0005bfea5d5">keyNeedStat()</a> set. The flag will result in that all keys in <code>returned</code> have <a class="el" href="group__keytest.html#ga3908b6511648a950f37cd0005bfea5d5">keyNeedStat()</a> set.</li>
<li><code>option_t::KDB_O_INACTIVE</code> <br/>
 Will make it not ignore inactive keys, so <code>returned</code> will contain also inactive keys. Inactive keys are those that have names begining with '.' (dot). Please be sure that you know what you are doing, inactive keys must not have any semantics to the application. This flag should only be set in key browsers after explicit user request. You might also get inactive keys when you plan to remove a whole hierarchy.</li>
<li><code>option_t::KDB_O_SORT</code> <br/>
 Force <code>returned</code> to be <a class="el" href="group__keyset.html#ga023554d395ccf2319a3807b8b5d2530c">ksSort()</a>ed. Normally you don't want that the <code>returned</code> is sorted immediately because you might add other keys or go for another <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a>. Sorting will take place automatically when needed by <a class="el" href="group__keyset.html#gaa34fc43a081e6b01e4120daa6c112004">ksLookup()</a> or <a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a>, also without this option set. But you need to sort the keyset for yourself, when you just iterate over it. If you want to do that, pass this flag at the last <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a>.</li>
<li><code>option_t::KDB_O_NORECURSIVE</code> <br/>
 Dont get the keys recursive. Only receive keys from one folder. This might not work if the backend does not support it. Be prepared for more keys and use <a class="el" href="group__keyset.html#gaa34fc43a081e6b01e4120daa6c112004">ksLookup()</a> and avoid static assumptions on how many keys you get.</li>
</ul>
<dl class="user"><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment">KDB *handle;
KeySet *myConfig;
Key *key;

myConfig=<a class="code" href="group__keyset.html#ga671e1aaee3ae9dc13b4834a4ddbd2c3c">ksNew</a>(0);

handle = <a class="code" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen</a>();

key=<a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a>(<span class="stringliteral">&quot;system/sw/MyApp&quot;</span>,KEY_END);
rc=<a class="code" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet</a>(handle,key, myConfig, 0);
<a class="code" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel</a>(key);

key=<a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a>(<span class="stringliteral">&quot;user/sw/MyApp&quot;</span>,KEY_END);
rc=<a class="code" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet</a>(handle,key, myConfig, 0);
<a class="code" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel</a>(key);

<span class="comment">// will sort keyset here</span>
key=<a class="code" href="group__keyset.html#gad2e30fb6d4739d917c5abb2ac2f9c1a1">ksLookupByName</a>(myConfig,<span class="stringliteral">&quot;/sw/MyApp/key&quot;</span>, 0);
<span class="comment">// check if key is not 0 and work with it...</span>

<a class="code" href="group__keyset.html#ga27e5c16473b02a422238c8d970db7ac8">ksDel</a> (myConfig); <span class="comment">// delete the in-memory configuration</span>


<span class="comment">// maybe you want kdbSet() myConfig here</span>

<a class="code" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose</a>(handle); <span class="comment">// no more affairs with the key database.</span>
</pre></div></dd></dl>
<h2><a class="anchor" id="kdbgetdetail">
Details</a></h2>
<p>When no backend could be found (e.g. no backend mounted) the default backend will be used.</p>
<p>If you pass a NULL pointer as handle and/or returned <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> will return -1 and do nothing but <a class="el" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel()</a> the parentKey when requested and not a NULL pointer.</p>
<p>If you pass NULL as parentKey the root keys of all namespaces will be appended to returned.</p>
<p>For every directory key (<a class="el" href="group__keytest.html#gac0a10c602d52a35f81347e8a32312017">keyIsDir()</a>) the appropriate backend will be chosen and keys in it will be requested.</p>
<p>If any backend reports an failure the recursive getting of keys will be stopped. Backends only report failure when they are not able to get keys for any problems.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>contains internal information of <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">opened </a> key database </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>parentKey</em>&nbsp;</td><td>parent key or NULL to get the root keys </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>returned</em>&nbsp;</td><td>the (pre-initialized) KeySet returned with all keys found </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>options</em>&nbsp;</td><td>ORed options to control approaches </td></tr>
  </table>
  </dd>
</dl>
<dl class="see"><dt><b>See also:</b></dt><dd>option_t </dd>
<dd>
<a class="el" href="group__kdbhighlevel.html">kdb higher level Methods </a> that rely on <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> </dd>
<dd>
<a class="el" href="group__keyset.html#gad2e30fb6d4739d917c5abb2ac2f9c1a1">ksLookupByName()</a>, ksLookupByString() for powerful lookups after the KeySet was retrieved </dd>
<dd>
commandList() code in <a class="el" href="group__kdb.html" title="General methods to access the Key database.">KDB :: Low Level Methods</a> command for usage example </dd>
<dd>
commandEdit() code in <a class="el" href="group__kdb.html" title="General methods to access the Key database.">KDB :: Low Level Methods</a> command for usage example </dd>
<dd>
commandExport() code in <a class="el" href="group__kdb.html" title="General methods to access the Key database.">KDB :: Low Level Methods</a> command for usage example </dd></dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>number of keys contained by <code>returned</code> </dd>
<dd>
-1 on failure </dd></dl>

</div>
</div>
<a class="anchor" id="gaa3717146f45e5a9665377c7f5b71e39b"></a><!-- doxytag: member="kdb.c::kdbGetMountpoint" ref="gaa3717146f45e5a9665377c7f5b71e39b" args="(KDB *handle, const Key *where)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Key* kdbGetMountpoint </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const Key *&nbsp;</td>
          <td class="paramname"> <em>where</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Lookup a mountpoint in a handle for a specific key.</p>
<p>Will return a key representing the mountpoint or null if there is no appropriate mountpoint e.g. its the root mountpoint.</p>
<p>Together with kdbGetCapability() the two essential informations about mounted backends.</p>
<dl class="user"><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment">Key * key = <a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a> (<span class="stringliteral">&quot;system/template&quot;</span>);
KDB * handle = <a class="code" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen</a>();
Key *mountpoint=0;
mountpoint=<a class="code" href="group__kdb.html#gaa3717146f45e5a9665377c7f5b71e39b">kdbGetMountpoint</a>(handle, key);

printf(<span class="stringliteral">&quot;The library I am using is %s mounted in %s\n&quot;</span>,
        <a class="code" href="group__keyvalue.html#ga6f29609c5da53c6dc26a98678d5752af">keyValue</a>(mountpoint),
        <a class="code" href="group__keyname.html#ga8e805c726a60da921d3736cda7813513">keyName</a>(mountpoint));
<a class="code" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose</a> (handle);
<a class="code" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel</a> (key);
</pre></div></dd></dl>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>is the data structure, where the mounted directories are saved. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>where</em>&nbsp;</td><td>the key, that should be looked up. </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>the mountpoint associated with the key </dd></dl>

</div>
</div>
<a class="anchor" id="ga40e35f26cc69bd43ef1b2207f4fa121b"></a><!-- doxytag: member="kdb.c::kdbMount" ref="ga40e35f26cc69bd43ef1b2207f4fa121b" args="(KDB *handle, const Key *mountpoint, const KeySet *config)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int kdbMount </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const Key *&nbsp;</td>
          <td class="paramname"> <em>mountpoint</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const KeySet *&nbsp;</td>
          <td class="paramname"> <em>config</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Dynamically mount a single backend.</p>
<p>Maps the mountpoint, defined through its name and value, into the global elektra hierachy. If successfull, under the mountpoint another backend will reside.</p>
<p>This only works for a single KDB, that means a single thread in a single process. You may want statically mounting by editing system/elektra/mountpoints.</p>
<p>If you allocated mountpoint and config first, make sure that you free it! It is ok to free it immediately afterwards.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>handle to the kdb data structure </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>mountpoint</em>&nbsp;</td><td>the <a class="el" href="group__keyname.html#ga8e805c726a60da921d3736cda7813513">keyName()</a> of this key is the mountpoint, <a class="el" href="group__keyvalue.html#ga6f29609c5da53c6dc26a98678d5752af">keyValue()</a> the backend </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>config</em>&nbsp;</td><td>the configuration passed for that backend </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>0 on success, -1 if an error occurred </dd></dl>

</div>
</div>
<a class="anchor" id="gab7be60c387892d2235907836c5060e1f"></a><!-- doxytag: member="kdb.c::kdbOpen" ref="gab7be60c387892d2235907836c5060e1f" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">KDB* kdbOpen </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname"></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Opens the session with the Key database.</p>
<p>The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the <code>KDB</code> datastructure will be initialized.</p>
<p>You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to <a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a>. You can use the atexit () handler for it.</p>
<p>The pointer to the <code>KDB</code> structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.</p>
<p>Get a <code>KDB</code> handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it: </p>
<div class="fragment"><pre class="fragment">thread1 {
        KDB * h;
        h = <a class="code" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen</a>();
        <span class="comment">// fetch keys and work with them</span>
        <a class="code" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose</a>(h);
}
thread2 {
        KDB * h;
        h = <a class="code" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen</a>();
        <span class="comment">// fetch keys and work with them</span>
        <a class="code" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose</a>(h);
}
</pre></div><p>You don't need to use the <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">kdbOpen()</a> if you only want to manipulate plain in-memory Key or KeySet objects without any affairs with the backend key database,</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__kdb.html#gad9bb8bd3f1296bfa77cc9a1b41b7a859">kdbClose()</a> to end all affairs to the <a class="el" href="group__key.html" title="Key construction and initialization methods.">Key :: Basic Methods</a> database. </dd></dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>a KDB pointer on success </dd>
<dd>
NULL on failure </dd></dl>

</div>
</div>
<a class="anchor" id="ga953cf29721e6000c2516cd6b5d36f571"></a><!-- doxytag: member="kdb.c::kdbSet" ref="ga953cf29721e6000c2516cd6b5d36f571" args="(KDB *handle, KeySet *ks, Key *parentKey, option_t options)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">ssize_t kdbSet </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">KeySet *&nbsp;</td>
          <td class="paramname"> <em>ks</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Key *&nbsp;</td>
          <td class="paramname"> <em>parentKey</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">option_t&nbsp;</td>
          <td class="paramname"> <em>options</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Set keys in an atomic and universal way, all other kdbSet Functions rely on that one.</p>
<p>The given handle and keyset are the objects to work with.</p>
<p>With parentKey you can only store a part of the given keyset. Otherwise pass a null pointer or a parentKey without a name.</p>
<div class="fragment"><pre class="fragment">KeySet *ks = <a class="code" href="group__keyset.html#ga671e1aaee3ae9dc13b4834a4ddbd2c3c">ksNew</a>(0);
<a class="code" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet</a> (h, ks, <a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a>(<span class="stringliteral">&quot;system/myapp&quot;</span>,0), KDB_O_DEL);
<a class="code" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet</a> (h, ks, <a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a>(<span class="stringliteral">&quot;user/myapp&quot;</span>,0), KDB_O_DEL);

<span class="comment">//now only set everything below user, because you can&apos;t write to system</span>
<a class="code" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet</a> (h, ks, <a class="code" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew</a>(<span class="stringliteral">&quot;user/myapp&quot;</span>,0), KDB_O_DEL);

<a class="code" href="group__keyset.html#ga27e5c16473b02a422238c8d970db7ac8">ksDel</a> (ks);
</pre></div><p>Each key is checked with <a class="el" href="group__keytest.html#gaf247df0de7aca04b32ef80e39ef12950">keyNeedSync()</a> before being actually committed. So only changed keys are updated. If no key of a backend needs to be synced the <a class="el" href="group__backend.html#ga2d86ff43b693d59d4b82b597756e9e23">kdbSet_backend()</a> will be omitted.</p>
<p>If some error occurs, <a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a> will stop. In this situation the KeySet internal cursor will be set on the key that generated the error. This specific key and all behind it were not set. To be failsafe jump over it and try to set the rest, but report the error to the user.</p>
<dl class="user"><dt><b>Example of how this method can be used:</b></dt><dd><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> i;
KeySet *ks;  <span class="comment">// the KeySet I want to set</span>
<span class="comment">// fill ks with some keys</span>
<span class="keywordflow">for</span> (i=0; i&lt; 10; i++) <span class="comment">// limit to 10 tries</span>
{
        ret=<a class="code" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet</a>(handle,ks, 0, 0);
        <span class="keywordflow">if</span> (ret == -1)
        {
                <span class="comment">// We got an error. Warn user.</span>
                Key *problem;
                problem=<a class="code" href="group__keyset.html#ga4287b9416912c5f2ab9c195cb74fb094">ksCurrent</a>(ks);
                <span class="keywordflow">if</span> (problem)
                {
                        <span class="keywordtype">char</span> keyname[300]=<span class="stringliteral">&quot;&quot;</span>;
                        <a class="code" href="group__keyname.html#gaaba1494a5ffc976e0e56c43f4334a23c">keyGetFullName</a>(problem,keyname,<span class="keyword">sizeof</span>(keyname));
                        fprintf(stderr,<span class="stringliteral">&quot;kdb import: while importing %s&quot;</span>, keyname);
                } <span class="keywordflow">else</span> <span class="keywordflow">break</span>;
                <span class="comment">// And try to set keys again starting from the next key,</span>
                <span class="comment">// unless we reached the end of KeySet</span>
                <span class="keywordflow">if</span> (<a class="code" href="group__keyset.html#ga317321c9065b5a4b3e33fe1c399bcec9">ksNext</a>(ks) == 0) <span class="keywordflow">break</span>;
        }
}
</pre></div></dd></dl>
<h2><a class="anchor" id="kdbsetoption">
Options</a></h2>
<p>There are some options changing the behaviour of <a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a>:</p>
<ul>
<li><code>option_t::KDB_O_DEL</code> <br/>
 Its often useful to <a class="el" href="group__key.html#ga3df95bbc2494e3e6703ece5639be5bb1">keyDel()</a> the parentKey in the line after <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a>. Using this flag, you can just pass a key allocated with <a class="el" href="group__key.html#gaf6893c038b3ebee90c73a9ea8356bebf">keyNew()</a>, <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> will free it for you in the end.</li>
<li><code>option_t::KDB_O_SYNC</code> <br/>
 Will force to save all keys, independent of their sync state.</li>
<li><code>option_t::KDB_O_NOREMOVE</code> <br/>
 Don't remove any key from disk, even if <a class="el" href="group__keymeta.html#ga6e14e5f1de26e1318100631a149f2984">keyRemove()</a> was set. With that flag removing keys can't happen unintentional. The flag will result in that all keys in <code>returned</code> don't have <a class="el" href="group__keytest.html#gaae91159815480fbb3b3d9d7fa85e77b9">keyNeedRemove()</a> set.</li>
<li><code>option_t::KDB_O_REMOVEONLY</code> <br/>
 Remove all keys instead of setting them. All keys in <code>returned</code> will have <a class="el" href="group__keytest.html#gaae91159815480fbb3b3d9d7fa85e77b9">keyNeedRemove()</a> set, but not <a class="el" href="group__keytest.html#ga3908b6511648a950f37cd0005bfea5d5">keyNeedStat()</a> saying to you that the key was deleted permanently. This option implicit also activates <code>option_t::KDB_O_SYNC</code> because the sync state will be changed when they are marked remove. You might need option_t::KDB_O_INACTIVE set for the previous call of <a class="el" href="group__kdb.html#ga37b44bda1b83bc0144916bf21a86c1b5">kdbGet()</a> if there are any. Otherwise the recursive remove will fail, because removing directories is only possible when all subkeys are removed.</li>
</ul>
<h2><a class="anchor" id="kdbsetdetail">
Details</a></h2>
<p>When you dont have a parentKey or its name empty, then all keys will be set.</p>
<p>You can remove some keys instead of setting them by marking them with <a class="el" href="group__keymeta.html#ga6e14e5f1de26e1318100631a149f2984">keyRemove()</a>. The <a class="el" href="group__keytest.html#gaf247df0de7aca04b32ef80e39ef12950">keyNeedSync()</a> flag will be unset after successful removing. But the <a class="el" href="group__keytest.html#gaae91159815480fbb3b3d9d7fa85e77b9">keyNeedRemove()</a> flag will stay, but its safe to delete the key.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>contains internal information of <a class="el" href="group__kdb.html#gab7be60c387892d2235907836c5060e1f">opened </a> key database </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>ks</em>&nbsp;</td><td>a KeySet which should contain changed keys, otherwise nothing is done </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>parentKey</em>&nbsp;</td><td>holds the information below which key keys should be set </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>options</em>&nbsp;</td><td>see in <a class="el" href="group__kdb.html#ga953cf29721e6000c2516cd6b5d36f571">kdbSet()</a> documentation </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>0 on success </dd>
<dd>
-1 on failure </dd></dl>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="group__keytest.html#gaf247df0de7aca04b32ef80e39ef12950">keyNeedSync()</a>, <a class="el" href="group__keyset.html#ga317321c9065b5a4b3e33fe1c399bcec9">ksNext()</a>, <a class="el" href="group__keyset.html#ga4287b9416912c5f2ab9c195cb74fb094">ksCurrent()</a> </dd>
<dd>
<a class="el" href="group__keymeta.html#ga6e14e5f1de26e1318100631a149f2984">keyRemove()</a>, <a class="el" href="group__keytest.html#gaae91159815480fbb3b3d9d7fa85e77b9">keyNeedRemove()</a> </dd>
<dd>
commandEdit(), commandImport() code in <a class="el" href="group__kdb.html" title="General methods to access the Key database.">KDB :: Low Level Methods</a> command for usage and error handling example </dd></dl>

</div>
</div>
<a class="anchor" id="ga400ca66a9bdc04ecadb66d84dc06bd55"></a><!-- doxytag: member="kdb.c::kdbUnmount" ref="ga400ca66a9bdc04ecadb66d84dc06bd55" args="(KDB *handle, const Key *mountpoint)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int kdbUnmount </td>
          <td>(</td>
          <td class="paramtype">KDB *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const Key *&nbsp;</td>
          <td class="paramname"> <em>mountpoint</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Dynamically unmount a single backend.</p>
<p>Unmount a backend that was mounted with <a class="el" href="group__kdb.html#ga40e35f26cc69bd43ef1b2207f4fa121b">kdbMount()</a> before.</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>handle to the kdb data structure </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>mountpoint</em>&nbsp;</td><td>directory where backend is mounted to, that should be unmounted </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>0 on success, -1 if an error ocurred. </dd></dl>

</div>
</div>
</div>
<hr size="1"/><address style="text-align: right;"><small>Generated on 8 Nov 2009 for Elektra Projekt by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>