Main Page | Modules | Data Structures | File List | Data Fields

Key :: Methods for Making Tests

Methods to do various tests on Keys. More...

Functions

int keyIsInitialized (const Key *key)
 Test if key is initialized.
int keyNameGetNamespace (const char *keyName)
 Return the namespace of a key name.
int keyGetNamespace (const Key *key)
 Return the namespace of a key.
int keyIsSystem (const Key *key)
 Check whether a key is under the system namespace or not.
int keyIsUser (const Key *key)
 Check whether a key is under the user namespace or not.
int keyIsLink (const Key *key)
 Check if a key is a link key.
int keyIsDir (const Key *key)
 Check if a key is folder key.
int keyIsBin (const Key *key)
 Check if a key is of some binary type.
int keyIsString (const Key *key)
 Check if a key is of some string type.
int keyNeedsSync (const Key *key)
 Test if the in-memory key object was changed after retrieved from disk.
uint32_t keyCompare (const Key *key1, const Key *key2)
 Compare 2 keys.

Detailed Description

Methods to do various tests on Keys.

To use them:

#include <kdb.h>

Function Documentation

int keyIsInitialized const Key key  ) 
 

Test if key is initialized.

This function is more or less reliable. You'd better guarantee your code is robust enough using keyNew(), keyInit(), keyDel() and keyClose() everytime.

Definition at line 466 of file key.c.

References _Key::flags.

int keyNameGetNamespace const char *  keyName  ) 
 

Return the namespace of a key name.

Currently valid namespaces are KeyNamespace::KEY_NS_SYSTEM and KeyNamespace::KEY_NS_USER.

Returns:
KeyNamespace::KEY_NS_SYSTEM, KeyNamespace::KEY_NS_USER or 0
See also:
keyGetNamespace(), keyIsUser(), keyIsSystem()

KeyNamespace

Definition at line 894 of file key.c.

References keyNameIsSystem(), and keyNameIsUser().

int keyGetNamespace const Key key  ) 
 

Return the namespace of a key.

Currently valid namespaces are KeyNamespace::KEY_NS_SYSTEM and KeyNamespace::KEY_NS_USER.

Returns:
KeyNamespace::KEY_NS_SYSTEM, KeyNamespace::KEY_NS_USER or 0
See also:
keyNameGetNamespace(), keyIsUser(), keyIsSystem()

Definition at line 912 of file key.c.

References _Key::flags.

int keyIsSystem const Key key  ) 
 

Check whether a key is under the system namespace or not.

Returns:
1 if key name begins with system, 0 otherwise
See also:
keyNameIsSystem(), keyIsUser(), keyNameIsUser()

Definition at line 950 of file key.c.

References _Key::flags.

int keyIsUser const Key key  ) 
 

Check whether a key is under the user namespace or not.

Returns:
1 if key name begins with user, 0 otherwise
See also:
keyNameIsSystem(), keyIsSystem(), keyNameIsUser()

Definition at line 986 of file key.c.

References _Key::flags.

Referenced by keyGetFullRootName(), keyGetFullRootNameSize(), keyToStreamBasename(), ksLookupRE(), and ksToStream().

int keyIsLink const Key key  ) 
 

Check if a key is a link key.

The value of link keys is the key they point to.

Returns:
1 if key is a link, 0 otherwise
See also:
keyIsDir(), keyGetType()

Definition at line 1625 of file key.c.

References _Key::type.

int keyIsDir const Key key  ) 
 

Check if a key is folder key.

Folder keys have no value.

Returns:
1 if key is a folder, 0 otherwise
See also:
keyIsLink(), keyGetType()

Definition at line 1644 of file key.c.

References _Key::type.

int keyIsBin const Key key  ) 
 

Check if a key is of some binary type.

Returns:
1 if KEY_TYPE_BINARY <= type < KEY_TYPE_STRING , 0 otherwise
See also:
keyGetBinary(), keySetBinary()

Definition at line 1660 of file key.c.

References KEY_TYPE_BINARY, and _Key::type.

Referenced by commandGet().

int keyIsString const Key key  ) 
 

Check if a key is of some string type.

Returns:
1 if type >= KEY_TYPE_STRING , 0 otherwise
See also:
keyGetString(), keySetString()

Definition at line 1675 of file key.c.

References _Key::type.

int keyNeedsSync const Key key  ) 
 

Test if the in-memory key object was changed after retrieved from disk.

All library methods that change Key properties take care of setting a 'key is dirty' internal flag, that is checked by this method.

Returns:
1 if key was changed in memory, 0 otherwise.

Definition at line 1753 of file key.c.

References _Key::flags.

Referenced by kdbSetKeys_default().

uint32_t keyCompare const Key key1,
const Key key2
 

Compare 2 keys.

The returned flags bit array has 1s (differ) or 0s (equal) for each key meta info compared, that can be logically ORed using KeySwitch flags. The flags you can use are KEY_SWITCH_TYPE , KEY_SWITCH_NAME , KEY_SWITCH_VALUE , KEY_SWITCH_OWNER , KEY_SWITCH_COMMENT , KEY_SWITCH_UID , KEY_SWITCH_GID , KEY_SWITCH_MODE , KEY_SWITCH_NEEDSYNC and KEY_SWITCH_FLAG .

Returns:
a bit array poiting the differences
See also:
ksCompare() for examples and more detailed description

KeySwitch

Example of very powerfull specific Key lookup in a KeySet:
KeySet *ks=ksNew();
Key *base;
Key *current;
uint32_t match;
uint32_t interests;


kdbGetChildKeys(ks,"usr/sw/MyApp",KDB_O_RECURSIVE);

// assemble a key we'll use to compare our KeySet to
base=keyNew("user/sw/MyApp/some/deep/key",
    KEY_SWITCH_TYPE,KEY_TYPE_LINK,
    KEY_SWITCH_VALUE,"system/mtp/x",
    KEY_SWITCH_MODE,0654,
    KEY_SWITCH_END));

// we are interested only in key type and access permissions
interests=(KEY_SWITCH_TYPE | KEY_SWITCH_MODE);
    
ksRewind(ks);   // put cursor in the begining
while ((curren=ksNext(ks))) {
    match=keyCompare(current,base);
    
    if ((~match & interests) == interests)
        printf("Key %s has same type and permissions of base key",keyStealName(current));

    // continue walking in the KeySet....
}

// now we want same name and/or value and/or sync status
interests=(KEY_SWITCH_NAME | KEY_SWITCH_VALUE | KEY_SWITCH_NEEDSYNC);

// we don't really need ksRewind(), since previous loop achieved end of KeySet
ksRewind(ks);
while ((current=ksNext(ks))) {
    match=keyCompare(current,base);
    
    if ((~match & interests) == interests) {
        printf("Key %s has same name, value, and sync status
            of base key",keyStealName(current));
    }
    // continue walking in the KeySet....
}

keyDel(base);
ksDel(ks);

Definition at line 2513 of file key.c.

References _Key::access, _Key::comment, _Key::data, _Key::dataSize, _Key::flags, _Key::gid, _Key::key, KEY_SWITCH_FLAG, _Key::type, _Key::uid, and _Key::userDomain.

Referenced by kdbMonitorKey_default(), and ksCompare().


Generated on Sun Feb 19 10:05:37 2006 for Elektra Project by  doxygen 1.3.9.1