bool gencache_del(const char *keystr);
bool gencache_get(const char *keystr, char **valstr, time_t *timeout);
bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob,
- time_t *timeout);
+ time_t *timeout, bool *was_expired);
bool gencache_stabilize(void);
bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob, time_t timeout);
void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr),
**/
bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob,
- time_t *timeout)
+ time_t *timeout, bool *was_expired)
{
TDB_DATA databuf;
time_t t;
char *endptr;
+ bool expired = false;
if (keystr == NULL) {
- return false;
+ goto fail;
}
if (tdb_data_cmp(string_term_tdb_data(keystr),
last_stabilize_key()) == 0) {
DEBUG(10, ("Can't get %s as a key\n", keystr));
- return false;
+ goto fail;
}
if (!gencache_init()) {
- return False;
+ goto fail;
}
databuf = tdb_fetch_bystring(cache_notrans, keystr);
if (databuf.dptr == NULL) {
DEBUG(10, ("Cache entry with key = %s couldn't be found \n",
keystr));
- return False;
+ goto fail;
}
if (!gencache_pull_timeout((char *)databuf.dptr, &t, &endptr)) {
SAFE_FREE(databuf.dptr);
- return False;
+ goto fail;
}
DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, "
if (t == 0) {
/* Deleted */
SAFE_FREE(databuf.dptr);
- return False;
+ goto fail;
}
if (t <= time(NULL)) {
gencache_set(keystr, "", 0);
SAFE_FREE(databuf.dptr);
- return False;
+
+ expired = true;
+ goto fail;
}
if (blob != NULL) {
if (blob->data == NULL) {
SAFE_FREE(databuf.dptr);
DEBUG(0, ("memdup failed\n"));
- return False;
+ goto fail;
}
}
}
return True;
+
+fail:
+ if (was_expired != NULL) {
+ *was_expired = expired;
+ }
+ return false;
}
struct stabilize_state {
DATA_BLOB blob;
bool ret = False;
- ret = gencache_get_data_blob(keystr, &blob, ptimeout);
+ ret = gencache_get_data_blob(keystr, &blob, ptimeout, NULL);
if (!ret) {
return false;
}
return NT_STATUS_NO_MEMORY;
}
- if (!gencache_get_data_blob(key, &blob, NULL)) {
+ if (!gencache_get_data_blob(key, &blob, NULL, NULL)) {
return NT_STATUS_NOT_FOUND;
}
return False;
}
- if (!gencache_get_data_blob("foo", &blob, NULL)) {
+ if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
d_printf("%s: gencache_get_data_blob() failed\n", __location__);
return False;
}
return False;
}
- if (gencache_get_data_blob("foo", &blob, NULL)) {
+ if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
d_printf("%s: gencache_get_data_blob() on deleted entry "
"succeeded\n", __location__);
return False;