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. |
To use them:
#include <kdb.h>
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 513 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.
Definition at line 1064 of file key.c.
References KEY_NS_SYSTEM, KEY_NS_USER, 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.
Definition at line 1082 of file key.c.
References _Key::flags, KEY_NS_SYSTEM, KEY_NS_USER, KEY_SWITCH_ISSYSTEM, and KEY_SWITCH_ISUSER.
int keyIsSystem | ( | const Key * | key | ) |
Check whether a key is under the system
namespace or not.
system
, 0 otherwise Definition at line 1114 of file key.c.
References _Key::flags, and KEY_SWITCH_ISSYSTEM.
int keyIsUser | ( | const Key * | key | ) |
Check whether a key is under the user
namespace or not.
user
, 0 otherwise Definition at line 1144 of file key.c.
References _Key::flags, and KEY_SWITCH_ISUSER.
Referenced by keyGetFullName(), keyGetFullRootName(), keyGetFullRootNameSize(), keyGetRootNameSize(), keyToStreamBasename(), and ksLookupRE().
int keyIsLink | ( | const Key * | key | ) |
Check if a key is a link key.
The value of link keys is the key they point to.
Definition at line 1816 of file key.c.
References KEY_TYPE_LINK, and _Key::type.
int keyIsDir | ( | const Key * | key | ) |
Check if a key is folder key.
Folder keys have no value.
Definition at line 1831 of file key.c.
References _Key::access.
Referenced by kdbSetValue(), keyNew(), and keyToStreamBasename().
int keyIsBin | ( | const Key * | key | ) |
Check if a key is of some binary type.
Definition at line 1845 of file key.c.
References KEY_TYPE_STRING, and _Key::type.
Referenced by commandGet().
int keyIsString | ( | const Key * | key | ) |
Check if a key is of some string type.
Definition at line 1857 of file key.c.
References KEY_TYPE_STRING, and _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.
key
was changed in memory, 0 otherwise. Definition at line 1926 of file key.c.
References _Key::flags, and KEY_SWITCH_NEEDSYNC.
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 .
Key *key1, *key; uint32_t changes; // omited key1 and key2 initialization and manipulation changes=keyCompare(key1,key2); if (changes == 0) printf("key1 and key2 are identicall\n"); if (changes & KEY_SWITCH_VALUE) printf("key1 and key2 have different values\n"); if (changes & KEY_SWITCH_UID) printf("key1 and key2 have different UID\n");
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 2691 of file key.c.
References _Key::access, _Key::comment, _Key::data, _Key::dataSize, _Key::flags, _Key::gid, _Key::key, KEY_SWITCH_COMMENT, KEY_SWITCH_DOMAIN, KEY_SWITCH_FLAG, KEY_SWITCH_GID, KEY_SWITCH_MODE, KEY_SWITCH_NAME, KEY_SWITCH_NEEDSYNC, KEY_SWITCH_TYPE, KEY_SWITCH_UID, KEY_SWITCH_VALUE, _Key::type, _Key::uid, and _Key::userDomain.
Referenced by ksCompare().