00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <eyedbconfig.h>
00025
00026 #include "kern_p.h"
00027
00028 #define ROOT_ENTRY_BEGIN_SCAN(dbr) \
00029 {\
00030 DbHeader _dbh(DBSADDR(dbh)); \
00031 for (int j = 0; j < MAX_ROOT_ENTRIES; j++) { \
00032 DbRootEntry _dbr = _dbh.vre(j); \
00033 DbRootEntry *dbr = &_dbr; \
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #define ROOT_ENTRY_END_SCAN(dbr) \
00045 } \
00046 }
00047
00048 namespace eyedbsm {
00049
00050 Status
00051 ESM_rootEntrySet(DbHandle const *dbh, char const *const key,
00052 void const *const data, unsigned int size, Boolean create)
00053 {
00054 #undef PR
00055 #define PR "rootEntrySet: "
00056 if (!check_dbh(dbh))
00057 return statusMake(INVALID_DB_HANDLE, PR IDBH);
00058 else if (!key)
00059 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "null key given");
00060 else if (strlen(key) >= (size_t)MAX_ROOT_KEY)
00061 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "maximum key size exceeded: `%d' (maximum is `%d'", strlen(key), MAX_ROOT_KEY);
00062 else if (size < 0)
00063 return statusMake(INVALID_ROOT_ENTRY_SIZE, PR "invalid negative size given: `%d'", size);
00064 else if (size > MAX_ROOT_DATA)
00065 return statusMake(INVALID_ROOT_ENTRY_SIZE, PR "maximum data size exceeeded: `%d' (maximum is `%d'", size, MAX_ROOT_DATA);
00066 else
00067 {
00068 ROOT_ENTRY_BEGIN_SCAN(dbr)
00069 if (!strcmp(dbr->key(), key))
00070 {
00071 if (create)
00072 return statusMake(ROOT_ENTRY_EXISTS, PR "root entry already exists: '%s'", key);
00073 memcpy(dbr->data(), data, size);
00074 return Success;
00075 }
00076
00077 ROOT_ENTRY_END_SCAN(dbr)
00078
00079 ROOT_ENTRY_BEGIN_SCAN(dbr)
00080 if (!dbr->key()[0])
00081 {
00082 strcpy(dbr->key(), key);
00083 memcpy(dbr->data(), data, size);
00084 return Success;
00085 }
00086 ROOT_ENTRY_END_SCAN(dbr)
00087
00088 return statusMake(TOO_MANY_ROOT_ENTRIES, PR "too many root entries: `%d'", MAX_ROOT_ENTRIES);
00089 }
00090 }
00091
00092 Status
00093 ESM_rootEntryGet(DbHandle const *dbh, char const *const key,
00094 void *data, int maxsize)
00095 {
00096 #undef PR
00097 #define PR "rootEntryGet: "
00098 if (!check_dbh(dbh))
00099 return statusMake(INVALID_DB_HANDLE, PR IDBH);
00100 else if (!key)
00101 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "null key given");
00102 else if (strlen(key) >= (size_t)MAX_ROOT_KEY)
00103 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "maximum key size exceeded: `%d' (maximum is `%d'", strlen(key), MAX_ROOT_KEY);
00104 else if (maxsize < 0)
00105 return statusMake(INVALID_ROOT_ENTRY_SIZE, PR "negative maximum size given: `%d'", maxsize);
00106 else
00107 {
00108 ROOT_ENTRY_BEGIN_SCAN(dbr)
00109 if (strcmp(dbr->key(), key) == 0)
00110 {
00111 memcpy(data, dbr->data(), MIN(maxsize, MAX_ROOT_DATA));
00112 return Success;
00113 }
00114 ROOT_ENTRY_END_SCAN(dbr)
00115 return statusMake(ROOT_ENTRY_NOT_FOUND, PR "root entry not found: '%s'", key);
00116 }
00117 }
00118
00119 Status
00120 ESM_rootEntryDelete(DbHandle const *dbh, char const *const key)
00121 {
00122 #undef PR
00123 #define PR "rootEntryDelete: "
00124 if (!check_dbh(dbh))
00125 return statusMake(INVALID_DB_HANDLE, PR IDBH);
00126 else if (!key)
00127 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "null key given");
00128 else if (strlen(key) >= (size_t)MAX_ROOT_KEY)
00129 return statusMake(INVALID_ROOT_ENTRY_KEY, PR "maximum key size exceeded: `%d' (maximum is `%d'", strlen(key), MAX_ROOT_KEY);
00130 else
00131 {
00132 ROOT_ENTRY_BEGIN_SCAN(dbr)
00133 if (strcmp(dbr->key(), key) == 0)
00134 {
00135 dbr->key()[0] = 0;
00136 return Success;
00137 }
00138 ROOT_ENTRY_END_SCAN(dbr)
00139 return statusMake(ROOT_ENTRY_NOT_FOUND, PR "root entry not found: '%s'", key);
00140 }
00141 }
00142
00143 }