diff options
author | Gerald Carter <jerry@samba.org> | 2003-01-24 21:25:12 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2003-01-24 21:25:12 +0000 |
commit | f911f03a7db94635bf78d2c9b4748700af757bb5 (patch) | |
tree | 2f12efc920c48c777161605860a54cc594dd8ac5 /source3 | |
parent | 7cc3cf9410dedcf242254ff017c28cabb86276c6 (diff) | |
download | samba-f911f03a7db94635bf78d2c9b4748700af757bb5.tar.gz samba-f911f03a7db94635bf78d2c9b4748700af757bb5.tar.bz2 samba-f911f03a7db94635bf78d2c9b4748700af757bb5.zip |
sync with tpot's change to gencache_get() in HEAD
(This used to be commit 305f167db2a34cdf3dd6378954e815ce34111232)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/gencache.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 3ff67b9918..a844d8c014 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -233,9 +233,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) TDB_DATA keybuf, databuf; /* fail completely if get null pointers passed */ -#if 0 /* JERRY */ - SMB_ASSERT(keystr && valstr && timeout); -#endif + SMB_ASSERT(keystr); if (!gencache_init()) return False; @@ -244,32 +242,44 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) keybuf.dsize = strlen(keystr); databuf = tdb_fetch(cache, keybuf); - /* special case for tpot */ - if ( !valstr && !timeout ) { - BOOL result = False; - - result = (databuf.dptr == NULL); - SAFE_FREE(databuf.dptr); - return result; - } - if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { char* entry_buf = strndup(databuf.dptr, databuf.dsize); - *valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN)); + char *v; + time_t t; + + v = (char*)malloc(sizeof(char) * + (databuf.dsize - TIMEOUT_LEN)); SAFE_FREE(databuf.dptr); - sscanf(entry_buf, CACHE_DATA_FMT, (int*)timeout, *valstr); + sscanf(entry_buf, CACHE_DATA_FMT, (int*)&t, v); SAFE_FREE(entry_buf); - DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, timeout = %s\n", - *timeout > time(NULL) ? "valid" : "expired", keystr, *valstr, - ctime(timeout))); - return *timeout > time(NULL); + 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); - *valstr = NULL; - timeout = NULL; - DEBUG(10, ("Cache entry with key = %s couldn't be found\n", keystr)); + + if (valstr) + *valstr = NULL; + + if (timeout) + timeout = NULL; + + DEBUG(10, ("Cache entry with key = %s couldn't be found\n", + keystr)); + return False; } } @@ -333,4 +343,3 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time tdb_search_list_free(first_node); } - |