1 .TH "KDB Backends :: Backend Helper for Elektra" 3 "30 Jun 2009" "Elektra Projekt" \" -*- nroff -*-
5 KDB Backends :: Backend Helper for Elektra \- Backend helper Methods for Elektra and Backends.
12 .RI "int \fBkdbbWriteLock\fP (FILE *f)"
15 .RI "int \fBkdbbReadLock\fP (FILE *f)"
18 .RI "int \fBkdbbUnlock\fP (FILE *f)"
21 .RI "ssize_t \fBkdbbEncode\fP (void *kdbbDecoded, size_t size, char *returned)"
24 .RI "ssize_t \fBkdbbDecode\fP (char *kdbbEncoded, void *returned)"
27 .RI "int \fBkdbbNeedsUTF8Conversion\fP ()"
30 .RI "int \fBkdbbUTF8Engine\fP (int direction, char **string, size_t *inputOutputByteSize)"
33 .RI "int \fBkdbbEncodeChar\fP (char c, char *buffer, size_t bufSize)"
36 .RI "int \fBkdbbDecodeChar\fP (const char *from, char *into)"
39 .RI "int \fBkdbbFilenameToKeyName\fP (const char *string, char *buffer, int bufSize)"
42 .RI "ssize_t \fBkdbbGetFullKeyName\fP (KDB *handle, const char *forFilename, const Key *parentKey, Key *returned)"
45 .RI "int \fBkdbbKeyNameToRelativeFilename\fP (const char *string, char *buffer, size_t bufSize)"
48 .RI "ssize_t \fBkdbbKeyCalcRelativeFilename\fP (const Key *key, char *relativeFilename, size_t maxSize)"
51 .RI "ssize_t \fBkdbbGetFullFilename\fP (KDB *handle, const Key *forKey, char *returned, size_t maxSize)"
54 .SH "Detailed Description"
56 Backend helper Methods for Elektra and Backends.
61 #include <kdbbackend.h>
66 These backend helper methods provide functionality commonly used by backends to make backend development easier and to provide the same behaviour between backends.
67 .SH "Function Documentation"
69 .SS "ssize_t kdbbDecode (char * kdbbEncoded, void * returned)"
71 UnkdbbEncodes a buffer of ASCII hexadecimal values into a byte stream.
73 The allowed format for the hexadecimal values is just a stream of pairs of plain hex-digits, all together or space-separated.
75 The \fCreturned\fP data won't be bigger than half the size of the source \fCkdbbEncoded\fP data.
79 \fIkdbbEncoded\fP the source of ASCII hexadecimal digits.
81 \fIreturned\fP preallocated destination for the kdbbDecoded data.
86 the amount of bytes kdbbDecoded
97 .SS "int kdbbDecodeChar (const char * from, char * into)"
101 Decode one char from 25, 2B, 2F, 2C following RFC 2396 or copy char untouched if different.
105 \fIfrom\fP String containing sequence to decode
107 \fIinto\fP Decoded char
112 : Positive size of byte read from 'from' for decoding the sequence if sucess or -1 if error (into untouched)
120 NOTE: No '\\0' is added at the end of buffer.
121 .SS "ssize_t kdbbEncode (void * kdbbDecoded, size_t size, char * returned)"
123 Encodes a buffer of data onto hexadecimal ASCII.
125 The resulting data is made up of pairs of ASCII hex-digits, space- and newline-separated. This is the counterpart of \fBkdbbDecode()\fP.
127 The \fCreturned\fP must allocated prior you call this function and won't be bigger than 3 times the size of the source \fCkdbbDecoded\fP + 1 byte.
131 \fIkdbbDecoded\fP the source buffer.
133 \fIsize\fP the size of the source buffer in bytes.
135 \fIreturned\fP the preallocated destination for the ASCII-kdbbEncoded data.
140 the amount of bytes used in the resulting kdbbEncoded buffer.
149 .SS "int kdbbEncodeChar (char c, char * buffer, size_t bufSize)"
153 Encode '/', '\\', '', '+', ' ' char following RFC 2396 or copy char untouched if different.
157 \fIc\fP Char to kdbbEncode
159 \fIbuffer\fP string wich will contain kdbbEncoded char
161 \fIbufSize\fP Size of the buffer
166 : Size of the kdbbEncoded string if success or -1 if error * (then buffer is untouched)
174 NOTE: No '\\0' is added at the end of buffer.
175 .SS "int kdbbFilenameToKeyName (const char * string, char * buffer, int bufSize)"
177 Translate a relative file name to a key name applying decoding.
181 \fIstring\fP Filename
183 \fIbuffer\fP decoded keyName
185 \fIbufSize\fP Size of buffer
197 \fBkdbbKeyNameToRelativeFilename\fP
201 .SS "ssize_t kdbbGetFullFilename (KDB * handle, const Key * forKey, char * returned, size_t maxSize)"
203 Calculate the real file name for a key.
205 system/ keys will get the prefix KDB_DB_SYSTEM
207 For the user/ keys the algorithm works as follow: 1.) When the override environment KDB_HOME exists the configuration will be searched below KDB_HOME/KDB_DB_USER 2.) When the owner of the key exists in the elektra user database steps a.) and b.) will be tested: a.) The specific value for configuration storage of the user below system/users/<owner>/kdb b.) The home variable in system/users/<owner>/home will be merged together with KDB_DB_USER 3.) When the environment HOME exists the configuration will be searched below HOME/KDB_DB_USER 4.) Otherwise the KDB_DB_HOME/<owner>/KDB_DB_USER will be used
211 \fIforKey\fP the key object to work with
213 \fIhandle\fP the kdb handle to work with
215 \fIreturned\fP the buffer to return the calculated filename
217 \fImaxSize\fP maximum number of bytes that fit the buffer
222 kdbCalcRelativeFilename()
227 number of bytes written to the buffer, or 0 on error
229 length of returned string on success
235 .SS "ssize_t kdbbGetFullKeyName (KDB * handle, const char * forFilename, const Key * parentKey, Key * returned)"
237 Calculates the keyname out of a relative filename.
241 \fIhandle\fP The kdb handle to work with
243 \fIforFilename\fP needs to be the a null terminated string containing the relative filename
245 \fIparentKey\fP is the key above the key which will be returned
247 \fIreturned\fP The proper keyname and owner will be stored in returned. A valid key must be passed.
252 number of bytes written to the buffer, or 0 on error
254 length of returned string on success
261 \fBkdbbKeyNameToRelativeFilename()\fP
265 .SS "ssize_t kdbbKeyCalcRelativeFilename (const Key * key, char * relativeFilename, size_t maxSize)"
267 This is a helper to kdbGetFullFilename()
271 \fIkey\fP has the relevant name for the relative filename
273 \fIrelativeFilename\fP the buffer to return the calculated filename
275 \fImaxSize\fP maximum number of bytes that fit the buffer
285 number of bytes written to the buffer
291 .SS "int kdbbKeyNameToRelativeFilename (const char * string, char * buffer, size_t bufSize)"
293 Translate a key name to a relative file name applying encoding.
299 \fIbuffer\fP kdbbEncoded filename
301 \fIbufSize\fP Size of buffer
306 Number of byte written in buffer on success,
313 \fBkdbbKeyNameToRelativeFilename\fP
317 .SS "int kdbbNeedsUTF8Conversion (void)"
319 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 \fBkdbbUTF8Engine()\fP function for more information.
325 anything else if needed
329 .SS "int kdbbReadLock (FILE * f)"
331 Locks file for read mode.
333 Other processes and threads are allowed to read the file too simultaneous.
337 \fIf\fP is a valid filedescriptor
349 sets KDB_ERR_NOLOCK when locking failed
353 .SS "int kdbbUnlock (FILE * f)"
359 \fIf\fP is a valid filedescriptor
371 sets KDB_ERR_NOLOCK when locking failed
375 .SS "int kdbbUTF8Engine (int direction, char ** string, size_t * inputOutputByteSize)"
377 Converts string to (\fCdirection\fP = \fCUTF8_TO\fP) and from (\fCdirection\fP = \fCUTF8_FROM\fP) UTF-8.
379 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.
381 Broken locales in applications can cause problems too. Make sure to load the environment locales in your application using
384 setlocale (LC_ALL, '');
389 Otherwise kdbbUTF8Engine will quit with -1 leading that backends return with error when non-ascii characters appear. Binary values are not effected.
391 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.
395 \fIdirection\fP must be \fCUTF8_TO\fP (convert from current non-UTF-8 to UTF-8) or \fCUTF8_FROM\fP (convert from UTF-8 to current non-UTF-8)
397 \fIstring\fP before the call: the string to be converted; after the call: reallocated to carry the converted string
399 \fIinputOutputByteSize\fP before the call: the size of the string including leading NULL; after the call: the size of the converted string including leading NULL
410 .SS "int kdbbWriteLock (FILE * f)"
412 Locks file for exclusive write mode.
414 This function will block until all reader and writer have left the file.
418 \fIf\fP is a valid filedescriptor
430 sets KDB_ERR_NOLOCK when locking failed