From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/gencache/gencache.c | 375 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 375 insertions(+) create mode 100644 source4/lib/gencache/gencache.c (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c new file mode 100644 index 0000000000..de8c47ada5 --- /dev/null +++ b/source4/lib/gencache/gencache.c @@ -0,0 +1,375 @@ +/* + Unix SMB/CIFS implementation. + + Generic, persistent and shared between processes cache mechanism for use + by various parts of the Samba code + + Copyright (C) Rafal Szczesniak 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#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 struct tdb_wrap *cache; + +/** + * @file gencache.c + * @brief Generic, persistent and shared between processes cache mechanism + * for use by various parts of the Samba code + * + **/ + + +/** + * Cache initialisation function. Opens cache tdb file or creates + * it if does not exist. + * + * @return true on successful initialisation of the cache or + * false on failure + **/ + +BOOL gencache_init(void) +{ + char* cache_fname = NULL; + + /* skip file open if it's already opened */ + if (cache) return True; + + asprintf(&cache_fname, "%s/%s", lp_lockdir(), "gencache.tdb"); + if (cache_fname) + DEBUG(5, ("Opening cache file at %s\n", cache_fname)); + else { + DEBUG(0, ("Filename allocation failed.\n")); + return False; + } + + cache = tdb_wrap_open(NULL, cache_fname, 0, TDB_DEFAULT, + O_RDWR|O_CREAT, 0644); + + SAFE_FREE(cache_fname); + if (!cache) { + DEBUG(5, ("Attempt to open gencache.tdb has failed.\n")); + return False; + } + return True; +} + + +/** + * Cache shutdown function. Closes opened cache tdb file. + * + * @return true on successful closing the cache or + * false on failure during cache shutdown + **/ + +BOOL gencache_shutdown(void) +{ + if (!cache) return False; + DEBUG(5, ("Closing cache file\n")); + talloc_free(cache); + return True; +} + + +/** + * Set an entry in the cache file. If there's no such + * one, then add it. + * + * @param keystr string that represents a key of this entry + * @param value text representation value being cached + * @param timeout time when the value is expired + * + * @retval true when entry is successfuly stored + * @retval false on failure + **/ + +BOOL gencache_set(const char *keystr, const char *value, time_t timeout) +{ + int ret; + TDB_DATA keybuf, databuf; + char* valstr = NULL; + + /* fail completely if get null pointers passed */ + SMB_ASSERT(keystr && value); + + if (!gencache_init()) return False; + + asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value); + if (!valstr) + return False; + + keybuf.dptr = strdup(keystr); + keybuf.dsize = strlen(keystr)+1; + databuf.dptr = strdup(valstr); + databuf.dsize = strlen(valstr)+1; + DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout \ + = %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->tdb, keybuf, databuf, 0); + SAFE_FREE(valstr); + SAFE_FREE(keybuf.dptr); + SAFE_FREE(databuf.dptr); + + return ret == 0; +} + + +/** + * Set existing entry to the cache file. + * + * @param keystr string that represents a key of this entry + * @param valstr text representation value being cached + * @param timeout time when the value is expired + * + * @retval true when entry is successfuly set + * @retval false on failure + **/ + +BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) +{ + int ret = -1; + TDB_DATA keybuf, databuf; + char *old_valstr, *datastr; + time_t old_timeout; + + /* fail completely if get null pointers passed */ + SMB_ASSERT(keystr && valstr); + + if (!gencache_init()) return False; + + /* + * Check whether entry exists in the cache + * Don't verify gencache_get exit code, since the entry may be expired + */ + gencache_get(keystr, &old_valstr, &old_timeout); + + if (!(old_valstr && old_timeout)) return False; + + DEBUG(10, ("Setting cache entry with key = %s; old value = %s and old timeout \ + = %s\n", keystr, old_valstr, ctime(&old_timeout))); + + asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr); + keybuf.dptr = strdup(keystr); + keybuf.dsize = strlen(keystr)+1; + databuf.dptr = strdup(datastr); + databuf.dsize = strlen(datastr)+1; + DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr, + ctime(&timeout), (int)(timeout - time(NULL)), + timeout > time(NULL) ? "ahead" : "in the past")); + + + ret = tdb_store(cache->tdb, keybuf, databuf, TDB_REPLACE); + + SAFE_FREE(datastr); + SAFE_FREE(old_valstr); + SAFE_FREE(keybuf.dptr); + SAFE_FREE(databuf.dptr); + + return ret == 0; +} + + +/** + * Delete one entry from the cache file. + * + * @param keystr string that represents a key of this entry + * + * @retval true upon successful deletion + * @retval false in case of failure + **/ + +BOOL gencache_del(const char *keystr) +{ + int ret; + TDB_DATA keybuf; + + /* fail completely if get null pointers passed */ + SMB_ASSERT(keystr); + + if (!gencache_init()) return False; + + keybuf.dptr = strdup(keystr); + keybuf.dsize = strlen(keystr)+1; + DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr)); + ret = tdb_delete(cache->tdb, keybuf); + + SAFE_FREE(keybuf.dptr); + return ret == 0; +} + + +/** + * Get existing entry from the cache file. + * + * @param keystr string that represents a key of this entry + * @param valstr buffer that is allocated and filled with the entry value + * buffer's disposing must be done outside + * @param timeout pointer to a time_t that is filled with entry's + * timeout + * + * @retval true when entry is successfuly fetched + * @retval False for failure + **/ + +BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) +{ + TDB_DATA keybuf, databuf; + + /* fail completely if get null pointers passed */ + SMB_ASSERT(keystr); + + if (!gencache_init()) + return False; + + keybuf.dptr = strdup(keystr); + keybuf.dsize = strlen(keystr)+1; + databuf = tdb_fetch(cache->tdb, keybuf); + SAFE_FREE(keybuf.dptr); + + if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { + char* entry_buf = strndup(databuf.dptr, databuf.dsize); + char *v; + time_t t; + unsigned i; + + v = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN); + + SAFE_FREE(databuf.dptr); + sscanf(entry_buf, CACHE_DATA_FMT, (int*)&i, v); + SAFE_FREE(entry_buf); + t = i; + + DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, " + "timeout = %s\n", t > time(NULL) ? "valid" : + "expired", keystr, v, ctime(&t))); + + if (valstr) + *valstr = v; + else + SAFE_FREE(v); + + if (timeout) + *timeout = t; + + return t > time(NULL); + + } else { + SAFE_FREE(databuf.dptr); + + if (valstr) + *valstr = NULL; + + if (timeout) + timeout = NULL; + + DEBUG(10, ("Cache entry with key = %s couldn't be found\n", + keystr)); + + return False; + } +} + + +/** + * Iterate through all entries which key matches to specified pattern + * + * @param fn pointer to the function that will be supplied with each single + * matching cache entry (key, value and timeout) as an arguments + * @param data void pointer to an arbitrary data that is passed directly to the fn + * function on each call + * @param keystr_pattern pattern the existing entries' keys are matched to + * + **/ + +void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr), + void* data, const char* keystr_pattern) +{ + TDB_LIST_NODE *node, *first_node; + TDB_DATA databuf; + char *keystr = NULL, *valstr = NULL, *entry = NULL; + time_t timeout = 0; + unsigned i; + + /* fail completely if get null pointers passed */ + SMB_ASSERT(fn && keystr_pattern); + + if (!gencache_init()) return; + + DEBUG(5, ("Searching cache keys with pattern %s\n", keystr_pattern)); + node = tdb_search_keys(cache->tdb, keystr_pattern); + first_node = node; + + while (node) { + /* ensure null termination of the key string */ + keystr = strndup(node->node_key.dptr, node->node_key.dsize); + + /* + * 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->tdb, node->node_key); + if (!databuf.dptr || databuf.dsize <= TIMEOUT_LEN) { + SAFE_FREE(databuf.dptr); + SAFE_FREE(keystr); + node = node->next; + continue; + } + entry = strndup(databuf.dptr, databuf.dsize); + SAFE_FREE(databuf.dptr); + valstr = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN); + sscanf(entry, CACHE_DATA_FMT, (int*)(&i), valstr); + timeout = i; + + DEBUG(10, ("Calling function with arguments (key = %s, value = %s, timeout = %s)\n", + keystr, valstr, ctime(&timeout))); + fn(keystr, valstr, timeout, data); + + SAFE_FREE(valstr); + SAFE_FREE(entry); + SAFE_FREE(keystr); + node = node->next; + } + + tdb_search_list_free(first_node); +} + +/******************************************************************** + lock a key +********************************************************************/ + +int gencache_lock_entry( const char *key ) +{ + return tdb_lock_bystring(cache->tdb, key); +} + +/******************************************************************** + unlock a key +********************************************************************/ + +void gencache_unlock_entry( const char *key ) +{ + tdb_unlock_bystring(cache->tdb, key); +} + + -- cgit From c42923a4e3769b5a259d3461714944f77047cc64 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 14:48:04 +0000 Subject: r14996: Fix compilation of gencache (This used to be commit 6782214c44fbf69c0d4b65a75fb4430cb21b2e1c) --- source4/lib/gencache/gencache.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index de8c47ada5..05530b7702 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -26,6 +26,7 @@ #include "system/time.h" #include "system/filesys.h" #include "db_wrap.h" +#include "lib/gencache/gencache.h" #define TIMEOUT_LEN 12 #define CACHE_DATA_FMT "%12u/%s" -- cgit From 6e62c6beac456c07d651db9ea351debe8c60c301 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 29 Apr 2006 16:12:01 +0000 Subject: r15325: Fix compiler warnings (This used to be commit 5d51047fe3187863a18b2a976ba3bf831cb3c765) --- source4/lib/gencache/gencache.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index 05530b7702..4c60d76095 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -119,9 +119,9 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) if (!valstr) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; - databuf.dptr = strdup(valstr); + databuf.dptr = (uint8_t *)strdup(valstr); databuf.dsize = strlen(valstr)+1; DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout \ = %s (%d seconds %s)\n", keybuf.dptr, value, ctime(&timeout), @@ -171,9 +171,9 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) = %s\n", keystr, old_valstr, ctime(&old_timeout))); asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr); - keybuf.dptr = strdup(keystr); + keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; - databuf.dptr = strdup(datastr); + databuf.dptr = (uint8_t *)strdup(datastr); databuf.dsize = strlen(datastr)+1; DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr, ctime(&timeout), (int)(timeout - time(NULL)), @@ -210,7 +210,7 @@ BOOL gencache_del(const char *keystr) if (!gencache_init()) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr)); ret = tdb_delete(cache->tdb, keybuf); @@ -243,13 +243,13 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) if (!gencache_init()) return False; - keybuf.dptr = strdup(keystr); + keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; databuf = tdb_fetch(cache->tdb, keybuf); SAFE_FREE(keybuf.dptr); if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { - char* entry_buf = strndup(databuf.dptr, databuf.dsize); + char* entry_buf = strndup((char *)databuf.dptr, databuf.dsize); char *v; time_t t; unsigned i; @@ -323,7 +323,7 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time while (node) { /* ensure null termination of the key string */ - keystr = strndup(node->node_key.dptr, node->node_key.dsize); + keystr = strndup((char *)node->node_key.dptr, node->node_key.dsize); /* * We don't use gencache_get function, because we need to iterate through @@ -336,7 +336,7 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time node = node->next; continue; } - entry = strndup(databuf.dptr, databuf.dsize); + entry = strndup((char *)databuf.dptr, databuf.dsize); SAFE_FREE(databuf.dptr); valstr = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN); sscanf(entry, CACHE_DATA_FMT, (int*)(&i), valstr); -- cgit From af870da6194b47c6cd09445c1e03832d00e951bb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 20 Oct 2006 23:32:23 +0000 Subject: r19428: moved tdbutil.c from lib/tdb/common/ to lib/util/util_tdb.c tdbutil.c is Samba specific, so should not be part of the generic tdb library (This used to be commit 979dd24f5e44605fc1603b690913b8c31be7478f) --- source4/lib/gencache/gencache.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index 4c60d76095..dff67054d4 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -22,7 +22,6 @@ */ #include "includes.h" -#include "lib/tdb/include/tdbutil.h" #include "system/time.h" #include "system/filesys.h" #include "db_wrap.h" -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/gencache/gencache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index dff67054d4..a30f09fefa 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From bd5a802a26f427779663a3de5f6d49f352b7c473 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 11:47:03 +0000 Subject: r24992: Remove some uses of lp_*(). (This used to be commit a5a1a5540510cdb1bfbb3e89b84f4ba5b2812c55) --- source4/lib/gencache/gencache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index a30f09fefa..08ff55b211 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -50,22 +50,23 @@ static struct tdb_wrap *cache; BOOL gencache_init(void) { char* cache_fname = NULL; + TALLOC_CTX *mem_ctx = talloc_autofree_context(); /* skip file open if it's already opened */ if (cache) return True; - asprintf(&cache_fname, "%s/%s", lp_lockdir(), "gencache.tdb"); - if (cache_fname) + cache_fname = lock_path(mem_ctx, "gencache.tdb"); + if (cache_fname != NULL) { DEBUG(5, ("Opening cache file at %s\n", cache_fname)); - else { + } else { DEBUG(0, ("Filename allocation failed.\n")); - return False; + return false; } - cache = tdb_wrap_open(NULL, cache_fname, 0, TDB_DEFAULT, + cache = tdb_wrap_open(mem_ctx, cache_fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644); - SAFE_FREE(cache_fname); + talloc_free(cache_fname); if (!cache) { DEBUG(5, ("Attempt to open gencache.tdb has failed.\n")); return False; -- cgit From 2f3551ca7cee59d4d053cceb87abdf1da1b3a1ad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 Oct 2007 18:52:55 +0000 Subject: r25446: Merge some changes I made on the way home from SFO: 2007-09-29 More higher-level passing around of lp_ctx. 2007-09-29 Fix warning. 2007-09-29 Pass loadparm contexts on a higher level. 2007-09-29 Avoid using global loadparm context. (This used to be commit 3468952e771ab31f90b6c374ade01c5550810f42) --- source4/lib/gencache/gencache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index 08ff55b211..30bb1d86ed 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -55,7 +55,7 @@ BOOL gencache_init(void) /* skip file open if it's already opened */ if (cache) return True; - cache_fname = lock_path(mem_ctx, "gencache.tdb"); + cache_fname = lock_path(mem_ctx, global_loadparm, "gencache.tdb"); if (cache_fname != NULL) { DEBUG(5, ("Opening cache file at %s\n", cache_fname)); } else { -- cgit From 863a1dd1555e25903d9a41664ca5c7d398e242d7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Oct 2007 14:19:35 +0000 Subject: r25577: BOOL -> bool metze (This used to be commit 6f665a12789b839c3d49ea8307f78bec77730c94) --- source4/lib/gencache/gencache.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index 30bb1d86ed..949b16cb3b 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -47,13 +47,13 @@ static struct tdb_wrap *cache; * false on failure **/ -BOOL gencache_init(void) +bool gencache_init(void) { char* cache_fname = NULL; TALLOC_CTX *mem_ctx = talloc_autofree_context(); /* skip file open if it's already opened */ - if (cache) return True; + if (cache) return true; cache_fname = lock_path(mem_ctx, global_loadparm, "gencache.tdb"); if (cache_fname != NULL) { @@ -69,9 +69,9 @@ BOOL gencache_init(void) talloc_free(cache_fname); if (!cache) { DEBUG(5, ("Attempt to open gencache.tdb has failed.\n")); - return False; + return false; } - return True; + return true; } @@ -82,12 +82,12 @@ BOOL gencache_init(void) * false on failure during cache shutdown **/ -BOOL gencache_shutdown(void) +bool gencache_shutdown(void) { - if (!cache) return False; + if (!cache) return false; DEBUG(5, ("Closing cache file\n")); talloc_free(cache); - return True; + return true; } @@ -103,7 +103,7 @@ BOOL gencache_shutdown(void) * @retval false on failure **/ -BOOL gencache_set(const char *keystr, const char *value, time_t timeout) +bool gencache_set(const char *keystr, const char *value, time_t timeout) { int ret; TDB_DATA keybuf, databuf; @@ -112,11 +112,11 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) /* fail completely if get null pointers passed */ SMB_ASSERT(keystr && value); - if (!gencache_init()) return False; + if (!gencache_init()) return false; asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value); if (!valstr) - return False; + return false; keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; @@ -146,7 +146,7 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) * @retval false on failure **/ -BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) +bool gencache_set_only(const char *keystr, const char *valstr, time_t timeout) { int ret = -1; TDB_DATA keybuf, databuf; @@ -156,7 +156,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) /* fail completely if get null pointers passed */ SMB_ASSERT(keystr && valstr); - if (!gencache_init()) return False; + if (!gencache_init()) return false; /* * Check whether entry exists in the cache @@ -164,7 +164,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) */ gencache_get(keystr, &old_valstr, &old_timeout); - if (!(old_valstr && old_timeout)) return False; + if (!(old_valstr && old_timeout)) return false; DEBUG(10, ("Setting cache entry with key = %s; old value = %s and old timeout \ = %s\n", keystr, old_valstr, ctime(&old_timeout))); @@ -199,7 +199,7 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) * @retval false in case of failure **/ -BOOL gencache_del(const char *keystr) +bool gencache_del(const char *keystr) { int ret; TDB_DATA keybuf; @@ -207,7 +207,7 @@ BOOL gencache_del(const char *keystr) /* fail completely if get null pointers passed */ SMB_ASSERT(keystr); - if (!gencache_init()) return False; + if (!gencache_init()) return false; keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; @@ -229,10 +229,10 @@ BOOL gencache_del(const char *keystr) * timeout * * @retval true when entry is successfuly fetched - * @retval False for failure + * @retval false for failure **/ -BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) +bool gencache_get(const char *keystr, char **valstr, time_t *timeout) { TDB_DATA keybuf, databuf; @@ -240,7 +240,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) SMB_ASSERT(keystr); if (!gencache_init()) - return False; + return false; keybuf.dptr = (uint8_t *)strdup(keystr); keybuf.dsize = strlen(keystr)+1; @@ -286,7 +286,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) DEBUG(10, ("Cache entry with key = %s couldn't be found\n", keystr)); - return False; + return false; } } -- cgit From 7f3b941976e00455c4768731bb923267f717b39e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 17 Nov 2007 22:46:39 +0100 Subject: r26017: db_wrap.h doesn't exist anymore and we now need tdb_wrap.h metze (This used to be commit 88f11a88f32a0a5fe2702d24f1879881a5865365) --- source4/lib/gencache/gencache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index 949b16cb3b..ea80a93624 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -23,7 +23,7 @@ #include "includes.h" #include "system/time.h" #include "system/filesys.h" -#include "db_wrap.h" +#include "tdb_wrap.h" #include "lib/gencache/gencache.h" #define TIMEOUT_LEN 12 -- cgit From 51db4c3f3d81d1ed03beae6426786c843ac59807 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 2 Dec 2007 17:56:09 +0100 Subject: r26228: Store loadparm context in auth context, move more loadparm_contexts up the call stack. (This used to be commit ba75f1613a9aac69dd5df94dd8a2b37820acd166) --- source4/lib/gencache/gencache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/gencache/gencache.c') diff --git a/source4/lib/gencache/gencache.c b/source4/lib/gencache/gencache.c index ea80a93624..aaaa40eea8 100644 --- a/source4/lib/gencache/gencache.c +++ b/source4/lib/gencache/gencache.c @@ -47,7 +47,7 @@ static struct tdb_wrap *cache; * false on failure **/ -bool gencache_init(void) +bool gencache_init(struct loadparm_context *lp_ctx) { char* cache_fname = NULL; TALLOC_CTX *mem_ctx = talloc_autofree_context(); @@ -55,7 +55,7 @@ bool gencache_init(void) /* skip file open if it's already opened */ if (cache) return true; - cache_fname = lock_path(mem_ctx, global_loadparm, "gencache.tdb"); + cache_fname = lock_path(mem_ctx, lp_ctx, "gencache.tdb"); if (cache_fname != NULL) { DEBUG(5, ("Opening cache file at %s\n", cache_fname)); } else { -- cgit