1 .TH "Streaming" 3 "30 Jun 2009" "Elektra Projekt" \" -*- nroff -*-
5 Streaming \- Methods to output, generate and toXML Keys and Keysets.
12 .RI "enum \fBKDBStream\fP { \fBKDB_O_SHOWMETA\fP = 0xF0, \fBKDB_O_SHOWFLAGS\fP = 1<<14, \fBKDB_O_SHOWINDICES\fP = 1<<15, \fBKDB_O_CONDENSED\fP = 1<<16, \fBKDB_O_NUMBER\fP = 1<<17, \fBKDB_O_HEADER\fP = 1<<18, \fBKDB_O_FULLNAME\fP = 1<<19, \fBKDB_O_HIER\fP = 1<<20 }"
19 .RI "int \fBksFromXMLfile\fP (KeySet *ks, const char *filename)"
22 .RI "int \fBksFromXML\fP (KeySet *ks, int fd)"
25 .RI "ssize_t \fBkeyToStream\fP (const Key *key, FILE *stream, option_t options)"
28 .RI "ssize_t \fBkeyToStreamBasename\fP (const Key *key, FILE *stream, const char *parent, const size_t parentSize, option_t options)"
31 .RI "ssize_t \fBksToStream\fP (const KeySet *ks, FILE *stream, option_t options)"
34 .RI "int \fBkeyOutput\fP (const Key *k, FILE *stream, option_t options)"
37 .RI "int \fBksOutput\fP (const KeySet *ks, FILE *stream, option_t options)"
40 .RI "int \fBkeyGenerate\fP (const Key *key, FILE *stream, option_t options)"
43 .RI "int \fBksGenerate\fP (const KeySet *ks, FILE *stream, option_t options)"
46 .SH "Detailed Description"
48 Methods to output, generate and toXML Keys and Keysets.
50 Here are some functions that are in a separate library because they depend on non-basic libraries as libxml. Link against kdbtools library if your program won't be installed in /bin, or is not essential in early boot stages.
52 It is also possible to have a dynamic linkage, see the sourcecode from kdb-tool or testing framework how to achieve that.
54 Output prints keys line per line, meaned to be read by humans.
61 Generate prints keys and keysets as C-Structs, meaned to be read by a C-Compiler.
68 toXML prints keys and keysets as XML, meaned to be used as exchange format.
83 .SH "Enumeration Type Documentation"
85 .SS "enum \fBKDBStream\fP"
87 Options to change the default behavior of streaming.
89 On default the streaming options only output the names of the given keysets. If you want more information, header, metainfo, compressed output, full names, values or comments you will find the appropriate options here.
91 For full influence of value, comment and metadata shown, use these options together with keyswitch_t. All bits of meta-information ORed together are KDB_O_SHOWMETA.
93 For more information about the flags, consult the documentation of the streaming methods.
95 These options can be ORed. That is the |-Operator in C.
97 It uses the values defined in keyswitch_t too, so it starts with 14.
113 \fB\fIKDB_O_SHOWMETA \fP\fP
114 Show all metadata (type, uid, gid, mode)
116 \fB\fIKDB_O_SHOWFLAGS \fP\fP
119 \fB\fIKDB_O_SHOWINDICES \fP\fP
120 Show the indices for the entries
122 \fB\fIKDB_O_CONDENSED \fP\fP
123 Spare any whitespaces and do not group visually together.
125 \fB\fIKDB_O_NUMBER \fP\fP
126 Use a number intead of user and group name.
128 \fB\fIKDB_O_HEADER \fP\fP
129 Show also the header of the document.
131 \fB\fIKDB_O_FULLNAME \fP\fP
132 Export \fCuser\fP keys using full name.
134 \fB\fIKDB_O_HIER \fP\fP
135 Export to the new hierarchical XML representation using key basename. See \fBksToStream()\fP.
136 .SH "Function Documentation"
138 .SS "int keyGenerate (const Key * key, FILE * stream, option_t options)"
140 Generate a C-Style key and stream it.
142 This keyset can be used to include as c-code for applikations using elektra.
146 \fIkey\fP the key object to work with
148 \fIstream\fP the file pointer where to send the stream
150 \fIoptions\fP KDB_O_SHOWINDICES, KDB_O_IGNORE_COMMENT, KDB_O_SHOWINFO
159 .SS "int keyOutput (const Key * k, FILE * stream, option_t options)"
161 Output every information of a single key depending on options.
163 The format is not very strict and only intend to be read by human eyes for debugging purposes. Don't rely on the format in your applications.
167 \fIk\fP the key object to work with
169 \fIstream\fP the file pointer where to send the stream
171 \fIoptions\fP see text above
183 -1 on allocation errors
187 .SS "ssize_t keyToStream (const Key * key, FILE * stream, option_t options)"
189 Prints an XML representation of the key.
191 String generated is of the form:
195 <key name="system/sw/xorg/Monitor/Monitor0/Name"
196 type="string" uid="root" gid="root" mode="0660">
198 <value>Samsung TFT panel</value>
199 <comment>My monitor</comment>
207 <key parent="system/sw/xorg/Monitor/Monitor0" basename="Name"
208 type="string" uid="root" gid="root" mode="0660">
210 <value>Samsung TFT panel</value>
211 <comment>My monitor</comment>
217 \fIkey\fP the key object to work with
219 \fIstream\fP where to write output: a file or stdout
221 \fIoptions\fP Some option_t ORed:
223 \fCoption_t::KDB_O_NUMBERS\fP
225 Do not convert UID and GID into user and group names
227 \fC\fBoption_t::KDB_O_CONDENSED\fP\fP
229 Less human readable, more condensed output
231 \fC\fBoption_t::KDB_O_FULLNAME\fP\fP
233 The \fCuser\fP keys are exported with their full names (including user domains)
244 number of bytes written to output
248 .SS "ssize_t keyToStreamBasename (const Key * key, FILE * stream, const char * parent, const size_t parentSize, option_t options)"
250 Same as \fBkeyToStream()\fP but tries to strip \fCparentSize\fP bytes from \fCkey\fP name if it matches \fCparent\fP .
252 Taking the example from \fBkeyToStream()\fP, if \fCparent\fP is \fC'system/sw/xorg'\fP, the generated string is of the form:
256 <key basename="Monitor/Monitor0/Name"
257 type="string" uid="root" gid="root" mode="0660">
259 <value>Samsung TFT panel</value>
260 <comment>My monitor</comment>
265 It usefull to produce more human readable XML output of a key when it is being represented in a context that defines the parent key name. For example:
270 <keyset parent="user/sw">
271 <key basename="kdbedit"..../>
272 <key basename="phototools"..../>
273 <key basename="myapp"..../>
277 In the bove example, each \fC<key>\fP entry was generated by a call to \fBkeyToStreamBasename()\fP having \fC'user/sw'\fP as \fCparent\fP .
279 This method is used when \fBksToStream()\fP is called with \fBKDBOption::KDB_O_HIER\fP option.
283 \fIkey\fP the key object to work with
285 \fIstream\fP the FILE where to send the stream
287 \fIparentSize\fP the maximum size of \fCparent\fP that will be used. If 0, the entire \fCparent\fP will be used.
289 \fIparent\fP the string (or part of it, defined by \fCparentSize\fP ) that will be used to strip from the key name.
291 \fIoptions\fP Some option_t ORed:
293 \fCoption_t::KDB_O_NUMBERS\fP
295 Do not convert UID and GID into user and group names
297 \fC\fBoption_t::KDB_O_CONDENSED\fP\fP
299 Less human readable, more condensed output
301 \fC\fBoption_t::KDB_O_FULLNAME\fP\fP
303 The \fCuser\fP keys are exported with their full names (including user domains)
309 number of bytes written to output
313 .SS "int ksFromXML (KeySet * ks, int fd)"
315 FIXME: not working when fd is stdin Given a file descriptor (that can be \fCstdin\fP) for an XML file, validate schema, process nodes, convert and save it in the \fCks\fP KeySet.
321 \fIfd\fP Filedeskriptor?? should be FILE*
325 .SS "int ksFromXMLfile (KeySet * ks, const char * filename)"
327 Given an XML \fCfilename\fP, open it, validate schema, process nodes, convert and save it in the \fCks\fP KeySet.
329 Currently, the XML file can have many root \fC<keyset>\fP and \fC<key>\fP nodes. They will all be reduced to simple keys returned in \fCks\fP.
331 To check if the xml file is valid (best before you read from it):
335 char schemaPath[513];
337 ret=kdbGetString(handle, KDB_SCHEMA_PATH_KEY,schemaPath,sizeof(schemaPath));
339 if (ret==0) ret = isValidXML(filename,schemaPath);
340 else ret = isValidXML(filename,KDB_SCHEMA_PATH);
349 \fIfilename\fP the file to parse
353 .SS "int ksGenerate (const KeySet * ks, FILE * stream, option_t options)"
355 Generate a C-Style keyset and stream it.
357 This keyset can be used to include as c-code for applikations using elektra.
359 The options takes the same options as \fBkdbGet()\fP and \fBkdbSet()\fP.
363 \fIks\fP the keyset to work with
365 \fIstream\fP the file pointer where to send the stream
367 \fIoptions\fP which keys not to output
376 .SS "int ksOutput (const KeySet * ks, FILE * stream, option_t options)"
378 Output all information of a keyset.
380 The format is not very strict and only intend to be read by human eyes for debugging purposes. Don't rely on the format in your applications.
382 Keys are printed line per line with \fBkeyOutput()\fP.
384 The same options as \fBkeyOutput()\fP are taken and passed to them.
386 Additional KDB_O_HEADER will print the number of keys as first line.
390 \fIks\fP the keyset to work with
392 \fIstream\fP the file pointer where to send the stream
406 -1 on allocation errors
410 .SS "ssize_t ksToStream (const KeySet * ks, FILE * stream, option_t options)"
412 Writes to \fCstream\fP an XML version of the \fCks\fP object.
414 String generated is of the form:
419 <key name=...>...</key>
420 <key name=...>...</key>
421 <key name=...>...</key>
428 or if KDB_O_HIER is used, the form will be:
432 <keyset parent="user/smallest/parent/name">
434 <key basename=...>...</key>
435 <key name=...>...</key> <!-- a key thats not under this keyset's parent -->
436 <key basename=...>...</key>
443 KDB_O_HEADER will additionally generate a header like:
447 <?xml version="1.0" encoding="UTF-8"?>
448 <!-- Generated by Elektra API. Total of n keys. -->
449 <keyset xmlns="http://www.libelektra.org"
450 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
451 xsi:schemaLocation="http://www.libelektra.org elektra.xsd">
458 \fIks\fP the KeySet to serialize
460 \fIstream\fP where to write output: a file or stdout
462 \fIoptions\fP accepted option_t ORed:
464 \fCoption_t::KDB_O_NUMBERS\fP
466 Do not convert UID and GID into user and group names.
468 \fC\fBoption_t::KDB_O_FULLNAME\fP\fP
470 The \fCuser\fP keys are exported with their full names (including user domains)
472 \fC\fBoption_t::KDB_O_CONDENSED\fP\fP
474 Less human readable, more condensed output.
476 \fCoption_t::KDB_O_XMLHEADERS\fP
478 Exclude the correct XML headers in the output. If not used, the <?xml?> and schema info inside the <keyset> object will not be generated.
480 \fC\fBoption_t::KDB_O_HIER\fP\fP
482 Will generate a <keyset> node containing a \fCparent\fP attribute, and <key> nodes with a \fCbasename\fP relative to that \fCparent\fP. The \fCparent\fP is calculated by taking the smallest key name in the keyset, so it is a good idea to have only related keys on the keyset. Otherwise, a valid consistent XML document still will be generated with regular absolute \fCname\fP attribute for the <key> nodes, due to a clever \fBkeyToStreamBasename()\fP implementation.
490 commandList() for usage example
495 number of bytes written to output, or -1 if some error occurs
500 \fIks\fP The keyset to output
502 \fIstream\fP the file pointer where to send the stream
504 \fIoptions\fP see above text