Key :: Miscelaneous

Methods to do various things. More...

Functions

KeykeyNext (Key *key)
 Return a pointer to the next key, if key is member of a KeySet.
ssize_t keyToStream (const Key *key, FILE *stream, unsigned long options)
 Prints an XML representation of the key.
ssize_t keyToStreamBasename (const Key *key, FILE *stream, const char *parent, const size_t parentSize, unsigned long options)
 Same as keyToStream() but tries to strip parentSize bytes from key name if it matches parent .
void * keySerialize (Key *key)
 Return a block of memory with the entire key serialized, including metainfo, value, comment and full name.
KeykeyUnserialize (const void *serialized)
 Given a membory block created by keySerialize(), unserialize it into a Key structure and return it.

Detailed Description

Methods to do various things.

To use them:

#include <kdb.h>

Function Documentation

Key* keyNext ( Key key  ) 

Return a pointer to the next key, if key is member of a KeySet.

Different from ksNext(), this call does not affect the KeySet internal cursor .

Definition at line 2544 of file key.c.

References _Key::next.

ssize_t keyToStream ( const Key key,
FILE *  stream,
unsigned long  options 
)

Prints an XML representation of the key.

String generated is of the form:

	<key name="system/sw/xorg/Monitor/Monitor0/Name"
		type="string" uid="root" gid="root" mode="0660">

		<value>Samsung TFT panel</value>
		<comment>My monitor</comment>
	</key>

	<key parent="system/sw/xorg/Monitor/Monitor0" basename="Name"
		type="string" uid="root" gid="root" mode="0660">

		<value>Samsung TFT panel</value>
		<comment>My monitor</comment>
	</key>

Parameters:
stream where to write output: a file or stdout
options Some KDBOptions ORed:
See also:
ksToStream()
Returns:
number of bytes written to output

Definition at line 2786 of file key.c.

References keyToStreamBasename().

Referenced by ksToStream().

ssize_t keyToStreamBasename ( const Key key,
FILE *  stream,
const char *  parent,
const size_t  parentSize,
unsigned long  options 
)

Same as keyToStream() but tries to strip parentSize bytes from key name if it matches parent .

Taking the example from keyToStream(), if parent is "system/sw/xorg", the generated string is of the form:

	<key basename="Monitor/Monitor0/Name"
		type="string" uid="root" gid="root" mode="0660">

		<value>Samsung TFT panel</value>
		<comment>My monitor</comment>
	</key>

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:

	<keyset parent="user/sw">
		<key basename="kdbedit"..../>
		<key basename="phototools"..../>
		<key basename="myapp"..../>
	</keyset>

In the bove example, each <key> entry was generated by a call to keyToStreamBasename() having "user/sw" as parent .

This method is used when ksToStream() is called with KDBOption::KDB_O_HIER option.

Parameters:
parentSize the maximum size of parent that will be used. If 0, the entire parent will be used.
parent the string (or part of it, defined by parentSize ) that will be used to strip from the key name.
Returns:
number of bytes written to output

Definition at line 2832 of file key.c.

References _Key::access, _Key::comment, _Key::data, _Key::dataSize, encode(), _Key::gid, KDB_O_CONDENSED, KDB_O_FULLNAME, KDB_O_FULLUGID, KDB_O_NUMBERS, _Key::key, KEY_TYPE_BINARY, KEY_TYPE_LINK, KEY_TYPE_STRING, KEY_TYPE_UNDEFINED, keyGetFullName(), keyIsDir(), keyIsUser(), strblen(), _Key::type, _Key::uid, and _Key::userDomain.

Referenced by keyToStream(), and ksToStream().

void* keySerialize ( Key key  ) 

Return a block of memory with the entire key serialized, including metainfo, value, comment and full name.

Deallocate it with a simple free().

See also:
keyUnserialize()

Definition at line 3236 of file key.c.

References _Key::comment, _Key::commentSize, _Key::data, _Key::dataSize, KEY_METAINFO_SIZE, keyGetFullName(), keyGetFullNameSize(), and _Key::recordSize.

Key* keyUnserialize ( const void *  serialized  ) 

Given a membory block created by keySerialize(), unserialize it into a Key structure and return it.

The serialized can be freed after this call, because memory will be allocated for all elements of the new key;

See also:
keySerialize()

Definition at line 3279 of file key.c.

References _Key::comment, _Key::commentSize, _Key::data, _Key::dataSize, KEY_METAINFO_SIZE, KEY_SWITCH_END, keyNew(), and keySetName().


Generated on Tue May 22 04:09:28 2007 for Elektra Project by  doxygen 1.5.2