*/
#include "includes.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_TDB
+#include "lib/tdb/include/tdbutil.h"
+#include "system/time.h"
+#include "system/filesys.h"
+#include "db_wrap.h"
#define TIMEOUT_LEN 12
#define CACHE_DATA_FMT "%12u/%s"
-static TDB_CONTEXT *cache;
+static struct tdb_wrap *cache;
/**
* @file gencache.c
return False;
}
- cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
- O_RDWR|O_CREAT, 0644);
+ cache = tdb_wrap_open(NULL, cache_fname, 0, TDB_DEFAULT,
+ O_RDWR|O_CREAT, 0644);
SAFE_FREE(cache_fname);
if (!cache) {
BOOL gencache_shutdown(void)
{
- /* tdb_close routine returns -1 on error */
if (!cache) return False;
DEBUG(5, ("Closing cache file\n"));
- return tdb_close(cache) != -1;
+ talloc_free(cache);
+ return True;
}
= %s (%d seconds %s)\n", keybuf.dptr, value, ctime(&timeout),
(int)(timeout - time(NULL)), timeout > time(NULL) ? "ahead" : "in the past"));
- ret = tdb_store(cache, keybuf, databuf, 0);
+ ret = tdb_store(cache->tdb, keybuf, databuf, 0);
SAFE_FREE(valstr);
SAFE_FREE(keybuf.dptr);
SAFE_FREE(databuf.dptr);
timeout > time(NULL) ? "ahead" : "in the past"));
- ret = tdb_store(cache, keybuf, databuf, TDB_REPLACE);
+ ret = tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE);
SAFE_FREE(datastr);
SAFE_FREE(old_valstr);
keybuf.dptr = strdup(keystr);
keybuf.dsize = strlen(keystr)+1;
DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr));
- ret = tdb_delete(cache, keybuf);
+ ret = tdb_delete(cache->tdb, keybuf);
SAFE_FREE(keybuf.dptr);
return ret == 0;
keybuf.dptr = strdup(keystr);
keybuf.dsize = strlen(keystr)+1;
- databuf = tdb_fetch(cache, keybuf);
+ databuf = tdb_fetch(cache->tdb, keybuf);
SAFE_FREE(keybuf.dptr);
if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) {
time_t t;
unsigned i;
- v = (char*)malloc(sizeof(char) *
- (databuf.dsize - TIMEOUT_LEN));
+ v = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN);
SAFE_FREE(databuf.dptr);
sscanf(entry_buf, CACHE_DATA_FMT, (int*)&i, v);
if (!gencache_init()) return;
DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern));
- node = tdb_search_keys(cache, keystr_pattern);
+ node = tdb_search_keys(cache->tdb, keystr_pattern);
first_node = node;
while (node) {
* We don't use gencache_get function, because we need to iterate through
* all of the entries. Validity verification is up to fn routine.
*/
- databuf = tdb_fetch(cache, node->node_key);
+ databuf = tdb_fetch(cache->tdb, node->node_key);
if (!databuf.dptr || databuf.dsize <= TIMEOUT_LEN) {
SAFE_FREE(databuf.dptr);
SAFE_FREE(keystr);
}
entry = strndup(databuf.dptr, databuf.dsize);
SAFE_FREE(databuf.dptr);
- valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN));
+ valstr = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN);
sscanf(entry, CACHE_DATA_FMT, (int*)(&i), valstr);
timeout = i;
int gencache_lock_entry( const char *key )
{
- return tdb_lock_bystring(cache, key, 0);
+ return tdb_lock_bystring(cache->tdb, key);
}
/********************************************************************
void gencache_unlock_entry( const char *key )
{
- tdb_unlock_bystring(cache, key);
- return;
+ tdb_unlock_bystring(cache->tdb, key);
}