00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KDB_H
00024 #define KDB_H
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef WIN32
00035 #include <windows.h>
00036 typedef unsigned char uint8_t;
00037 typedef unsigned short uint16_t;
00038 typedef unsigned int uint32_t;
00039 #define ssize_t int
00040 #define strcasecmp stricmp
00041 #define snprintf _snprintf
00042 #else
00043
00044 #include <inttypes.h>
00045 #endif
00046
00047 #include <sys/types.h>
00048 #include <errno.h>
00049 #include <stdio.h>
00050
00051
00052
00053
00054 #ifndef NO_REGEX_H
00055 #include <regex.h>
00056 #else
00057 #define regex_t void
00058 #endif
00059
00060 #define RG_KEY_DELIM '/'
00061
00062
00063
00064 #define RG_KEY_FORMAT_VERSION 2
00065 #define RG_KEY_FORMAT "RG002"
00066
00067
00090 enum KeyType {
00091 KEY_TYPE_UNDEFINED=0,
00092 KEY_TYPE_DIR=1,
00093 KEY_TYPE_LINK=2,
00096 KEY_TYPE_BINARY=20,
00100 KEY_TYPE_STRING=40
00101 };
00102
00103
00104
00105
00106
00107
00113 enum KeyNamespace {
00114 KEY_NS_SYSTEM=1,
00115 KEY_NS_USER=2
00116 };
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00153 enum KeySwitch {
00154 KEY_SWITCH_TYPE=1,
00155 KEY_SWITCH_NAME=1<<1,
00156 KEY_SWITCH_VALUE=1<<2,
00157 KEY_SWITCH_OWNER=1<<5,
00158 KEY_SWITCH_DOMAIN=KEY_SWITCH_OWNER,
00159 KEY_SWITCH_COMMENT=1<<6,
00160 KEY_SWITCH_UID=1<<7,
00161 KEY_SWITCH_GID=1<<8,
00162 KEY_SWITCH_MODE=1<<10,
00163 KEY_SWITCH_TIME=1<<11,
00164 KEY_SWITCH_NEEDSYNC=1<<12,
00165 KEY_SWITCH_ACTIVE=1<<14,
00166 KEY_SWITCH_ISSYSTEM=1<<23,
00167 KEY_SWITCH_ISUSER=1<<24,
00168 KEY_SWITCH_FLAG=1<<31,
00170 KEY_SWITCH_END=0,
00173 KEY_SWITCH_INITIALIZED=0x10042008,
00174 KEY_SWITCH_INITMASK=0x18442218
00175 };
00176
00177
00178
00179
00180
00181
00182
00183
00184 enum KeyFlags {
00185 KEY_FLAG_HASTYPE = KEY_SWITCH_TYPE,
00186 KEY_FLAG_HASKEY = KEY_SWITCH_NAME,
00187 KEY_FLAG_HASDATA = KEY_SWITCH_VALUE,
00188 KEY_FLAG_HASDOMAIN = KEY_SWITCH_DOMAIN,
00189 KEY_FLAG_HASCOMMENT = KEY_SWITCH_COMMENT,
00190 KEY_FLAG_HASUID = KEY_SWITCH_UID,
00191 KEY_FLAG_HASGID = KEY_SWITCH_GID,
00192 KEY_FLAG_HASPRM = KEY_SWITCH_MODE,
00193 KEY_FLAG_HASTIME = KEY_SWITCH_TIME,
00194 KEY_FLAG_NEEDSYNC = KEY_SWITCH_NEEDSYNC,
00195 KEY_FLAG_FLAG = KEY_SWITCH_FLAG,
00196 KEY_FLAG_INITIALIZED = KEY_SWITCH_INITIALIZED,
00197 KEY_FLAG_INITMASK = KEY_SWITCH_INITMASK
00198 };
00199
00200
00201
00219 enum KDBErr {
00220 KDB_RET_OK=0,
00223
00224 KDB_RET_NULLKEY=EINVAL,
00225 KDB_RET_UNINITIALIZED=EINVAL,
00227
00228 KDB_RET_NOTFOUND=ENOENT,
00229 KDB_RET_INVALIDKEY=ESRCH,
00232
00233 KDB_RET_NOKEY=ENXIO,
00234 KDB_RET_NODATA=ENODEV,
00235 KDB_RET_NODESC=ENOTDIR,
00236 KDB_RET_NODOMAIN=EDOM,
00237 KDB_RET_NOGROUP=ECHILD,
00238 KDB_RET_NOTIME=ENOTTY,
00241
00242 KDB_RET_NOCRED=EACCES,
00243 KDB_RET_TRUNC=ERANGE,
00244 KDB_RET_NOMEM=ENOMEM,
00245 KDB_RET_TYPEMISMATCH=EBADF,
00248
00249 KDB_RET_NOSYS=ENOSYS,
00250 KDB_RET_EBACKEND=EIO
00251 };
00252
00253
00263 enum KDBOptions {
00264 KDB_O_RECURSIVE=1,
00265 KDB_O_DIR=1<<1,
00266 KDB_O_DIRONLY=1<<2,
00267 KDB_O_NOEMPTY=1<<3,
00268 KDB_O_STATONLY=1<<4,
00269 KDB_O_INACTIVE=1<<5,
00271 KDB_O_SORT=1<<6,
00272 KDB_O_NFOLLOWLINK=1<<7,
00274
00275 KDB_O_CONDENSED=1<<8,
00276 KDB_O_NUMBERS=1<<9,
00277 KDB_O_XMLHEADERS=1<<10,
00278 KDB_O_FULLNAME=1<<11,
00280 KDB_O_FULLUGID=1<<12,
00283 KDB_O_HIER=1<<13,
00287
00288 KDB_O_NOCASE=1<<15,
00289 KDB_O_NOSPANPARENT=1<<16,
00292
00293 KDB_O_NOVALUE=KDB_O_DIRONLY
00294
00295 };
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 typedef struct _Key Key;
00318 typedef struct _KeySet KeySet;
00319
00320
00332 typedef struct _KDBInfo {
00333
00334
00335 char *version;
00336 char *backendName;
00337 uint8_t backendIsOpen;
00338 } KDBInfo;
00339
00340
00341
00342
00343 #ifdef __cplusplus
00344 extern "C" {
00345 #endif
00346
00347
00348
00349
00350
00351
00352
00353
00354 int kdbOpen();
00355 int kdbOpenDefault();
00356 int kdbOpenBackend(char *backendName);
00357 int kdbClose();
00358
00359 int kdbGetValue(const char *keyname, char *returned,size_t maxSize);
00360 int kdbGetKeyByParent(const char *parentName, const char *baseName, Key *returned);
00361 int kdbGetKeyByParentKey(const Key *parent, const char *baseName, Key *returned);
00362 int kdbGetValueByParent(const char *parentName, const char *baseName, char *returned,
00363 size_t maxSize);
00364
00365 int kdbSetValue(const char *keyname, const char *value);
00366 int kdbSetValueByParent(const char *parentName, const char *baseName, const char *value);
00367
00368 int kdbRename(Key *key, const char *newName);
00369 int kdbRemove(const char *keyName);
00370 int kdbRemoveKey(const Key *key);
00371 int kdbLink(const char *oldPath, const char *newKeyName);
00372
00373 int kdbGetKeyByParent(const char *parentName, const char *baseName, Key *returned);
00374 int kdbGetKeyByParentKey(const Key *parent, const char *basename, Key *returned);
00375 int kdbGetValueByParent(const char *parentName, const char *baseName, char *returned,
00376 size_t maxSize);
00377
00378
00379
00380
00381
00382 int kdbStatKey(Key *key);
00383 int kdbGetKey(Key *key);
00384 int kdbSetKey(Key *key);
00385
00386 ssize_t kdbGetKeyChildKeys(const Key *parentName, KeySet *returned, unsigned long options);
00387 ssize_t kdbGetChildKeys(const char *parentName, KeySet *returned, unsigned long options);
00388 ssize_t kdbGetRootKeys(KeySet *returned);
00389
00390 int kdbSetKeys(KeySet *ks);
00391
00392 uint32_t kdbMonitorKey(Key *interest, uint32_t diffMask,
00393 unsigned long iterations, unsigned usleep);
00394 uint32_t kdbMonitorKeys(KeySet *interests, uint32_t diffMask,
00395 unsigned long iterations, unsigned sleep);
00396
00397 KDBInfo *kdbGetInfo(void);
00398 void kdbFreeInfo(KDBInfo *info);
00399 int kdbInfoToString(KDBInfo *info,char *string,size_t maxSize);
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 int keyInit(Key *key);
00410 int keyClose(Key *key);
00411
00412 Key *keyNew(const char *keyName, ...);
00413 int keyDel(Key *key);
00414 #define keyFree(x) keyDel(x)
00415
00416 int keyIsInitialized(const Key *key);
00417 int keyNeedsSync(const Key *key);
00418 int keyDup(const Key *source,Key *dest);
00419
00420
00421
00422
00423
00424 uint8_t keyGetType(const Key *key);
00425 uint8_t keySetType(Key *key,uint8_t type);
00426
00427 int keySetFlag(Key *key);
00428 int keyClearFlag(Key *key);
00429 int keyGetFlag(const Key *key);
00430
00431 ssize_t keyGetRecordSize(const Key *key);
00432 ssize_t keyGetNameSize(const Key *key);
00433 ssize_t keyGetFullNameSize(const Key *key);
00434
00435 ssize_t keyGetName(const Key *key, char *returnedName, size_t maxSize);
00436 char *keyStealName(const Key *key);
00437 ssize_t keySetName(Key *key, const char *newName);
00438
00439 ssize_t keyGetFullName(const Key *key, char *returnedName, size_t maxSize);
00440 ssize_t keyGetRootName(const Key *key, char *returned, size_t maxSize);
00441 ssize_t keyGetFullRootName(const Key *key, char *returned, size_t maxSize);
00442
00443 ssize_t keyGetBaseName(const Key *key, char *returned, size_t maxSize);
00444 char *keyStealBaseName(const Key *key);
00445 ssize_t keyNameGetBaseNameSize(const char *keyName);
00446 ssize_t keyGetBaseNameSize(const Key *key);
00447 ssize_t keyAddBaseName(Key *key,const char *baseName);
00448 ssize_t keySetBaseName(Key *key,const char *baseName);
00449
00450 ssize_t keyGetParentName(const Key *key, char *returned, size_t maxSize);
00451 ssize_t keyGetParentNameSize(const Key *key);
00452
00453 ssize_t keyNameGetRootNameSize(const char *keyName);
00454 ssize_t keyGetRootNameSize(const Key *key);
00455 ssize_t keyGetFullRootNameSize(const Key *key);
00456
00457
00458 ssize_t keyGetCommentSize(const Key *key);
00459 ssize_t keyGetComment(const Key *key, char *returnedDesc, size_t maxSize);
00460 char *keyStealComment(const Key *key);
00461 ssize_t keySetComment(Key *key, const char *newDesc);
00462
00463 uid_t keyGetUID(const Key *key);
00464 int keySetUID(Key *key, uid_t uid);
00465
00466 gid_t keyGetGID(const Key *key);
00467 int keySetGID(Key *key, gid_t gid);
00468
00469 mode_t keyGetAccess(const Key *key);
00470 int keySetAccess(Key *key, mode_t mode);
00471
00472 ssize_t keyGetOwnerSize(const Key *key);
00473 ssize_t keyGetOwner(const Key *key, char *returned, size_t maxSize);
00474 char *keyStealOwner(const Key *key);
00475 ssize_t keySetOwner(Key *key, const char *userDomain);
00476
00477
00478 ssize_t keyGetValueSize(const Key *key);
00479 ssize_t keyGetDataSize(const Key *key);
00480
00481 ssize_t keyGetString(const Key *key, char *returnedString, size_t maxSize);
00482 ssize_t keySetString(Key *key, const char *newString);
00483 void *keyStealValue(const Key *key);
00484
00485 ssize_t keyGetBinary(const Key *key, void *returnedBinary, size_t maxSize);
00486 ssize_t keySetBinary(Key *key, const void *newBinary, size_t dataSize);
00487
00488 ssize_t keySetRaw(Key *key, const void *newBinary, size_t dataSize);
00489
00490 ssize_t keyGetLink(const Key *key, char *returnedTarget, size_t maxSize);
00491 ssize_t keySetLink(Key *key, const char *target);
00492
00493 time_t keyGetMTime(const Key *key);
00494 time_t keyGetATime(const Key *key);
00495 time_t keyGetCTime(const Key *key);
00496
00497 int keyIsSystem(const Key *key);
00498 int keyNameIsSystem(const char *keyName);
00499
00500 int keyIsUser(const Key *key);
00501 int keyNameIsUser(const char *keyName);
00502
00503 int keyGetNamespace(const Key *key);
00504 int keyNameGetNamespace(const char *keyName);
00505
00506 int keyIsDir(const Key *key);
00507 int keyIsLink(const Key *key);
00508 int keyIsBin(const Key *key);
00509 int keyIsString(const Key *key);
00510
00511 Key *keyNext(Key *key);
00512
00513 uint32_t keyCompare(const Key *key1, const Key *key2);
00514
00515 ssize_t keyToStream(const Key *key, FILE* stream, unsigned long options);
00516 ssize_t keyToStreamBasename(const Key *key, FILE* stream,
00517 const char *parent, const size_t parentSize, unsigned long options);
00518
00519
00520
00521
00522
00523
00524
00525
00526 KeySet *ksNew();
00527 int ksDel(KeySet *ks);
00528 #define ksFree(x) ksDel(x)
00529
00530 int ksInit(KeySet *ks);
00531 int ksClose(KeySet *ks);
00532 ssize_t ksGetSize(KeySet *ks);
00533
00534 ssize_t ksInsert(KeySet *ks, Key *toInsert);
00535 ssize_t ksAppend(KeySet *ks, Key *toAppend);
00536 Key *ksPop(KeySet *ks);
00537 Key *ksPopLast(KeySet *ks);
00538
00539 ssize_t ksInsertKeys(KeySet *ks, KeySet *toInsert);
00540 ssize_t ksAppendKeys(KeySet *ks, KeySet *toAppend);
00541
00542 ssize_t ksToStream(const KeySet *ks, FILE* stream, unsigned long options);
00543 int ksCompare(KeySet *ks1, KeySet *ks2, KeySet *removed);
00544 void ksSort(KeySet *ks);
00545
00546 Key *ksLookupByName(KeySet *ks, const char *name,unsigned long options);
00547 Key *ksLookupByValue(KeySet *ks, const char *value,unsigned long options);
00548 Key *ksLookupByBinaryValue(KeySet *ks, void *value, size_t size,
00549 unsigned long options);
00550 uint32_t ksLookupRE(KeySet *ks, uint32_t where,
00551 const regex_t *regexp, unsigned long options);
00552
00553 int ksRewind(KeySet *ks);
00554 Key *ksNext(KeySet *ks);
00555 Key *ksCurrent(const KeySet *ks);
00556
00557 Key *ksHead(KeySet *ks);
00558 Key *ksTail(KeySet *ks);
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 size_t strblen(const char *s);
00575
00576 #ifdef __cplusplus
00577 }
00578 #endif
00579
00580
00581 #endif