diff options
author | Volker Lendecke <vl@samba.org> | 2010-11-27 11:36:52 +0100 |
---|---|---|
committer | Volker Lendecke <vlendec@samba.org> | 2010-11-28 14:19:19 +0100 |
commit | 62afdb9cc056da4ba7a873e6bce00b4f2c32f4a4 (patch) | |
tree | 4191e4a8a06c6b934cc1a2a2ecfa7d89fada0d34 | |
parent | 9843103b7d2a13b1b8a45b3a1d958700bbf1bcfc (diff) | |
download | samba-62afdb9cc056da4ba7a873e6bce00b4f2c32f4a4.tar.gz samba-62afdb9cc056da4ba7a873e6bce00b4f2c32f4a4.tar.bz2 samba-62afdb9cc056da4ba7a873e6bce00b4f2c32f4a4.zip |
s3: Convert gencache_get_data_blob to gencache_parse
-rw-r--r-- | source3/lib/gencache.c | 97 |
1 files changed, 38 insertions, 59 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index fa8dcb02f9..89df3f9e80 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -348,6 +348,37 @@ bool gencache_parse(const char *keystr, return (ret != -1); } +struct gencache_get_data_blob_state { + DATA_BLOB *blob; + time_t timeout; + bool result; +}; + +static void gencache_get_data_blob_parser(time_t timeout, DATA_BLOB blob, + void *private_data) +{ + struct gencache_get_data_blob_state *state = + (struct gencache_get_data_blob_state *)private_data; + + if (timeout == 0) { + state->result = false; + return; + } + state->timeout = timeout; + + if (state->blob == NULL) { + state->result = true; + return; + } + + *state->blob = data_blob(blob.data, blob.length); + if (state->blob->data == NULL) { + state->result = false; + return; + } + state->result = true; +} + /** * Get existing entry from the cache file. * @@ -363,54 +394,19 @@ bool gencache_parse(const char *keystr, bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob, time_t *timeout, bool *was_expired) { - TDB_DATA databuf; - time_t t; - char *endptr; + struct gencache_get_data_blob_state state; bool expired = false; - if (keystr == NULL) { - 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)); - goto fail; - } - - if (!gencache_init()) { - goto fail; - } - - databuf = tdb_fetch_bystring(cache_notrans, keystr); + state.result = false; + state.blob = blob; - if (databuf.dptr == NULL) { - databuf = tdb_fetch_bystring(cache, keystr); - } - - if (databuf.dptr == NULL) { - DEBUG(10, ("Cache entry with key = %s couldn't be found \n", - keystr)); + if (!gencache_parse(keystr, gencache_get_data_blob_parser, &state)) { goto fail; } - - if (!gencache_pull_timeout((char *)databuf.dptr, &t, &endptr)) { - SAFE_FREE(databuf.dptr); + if (!state.result) { goto fail; } - - DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, " - "timeout = %s", t > time(NULL) ? "valid" : - "expired", keystr, endptr+1, ctime(&t))); - - if (t == 0) { - /* Deleted */ - SAFE_FREE(databuf.dptr); - goto fail; - } - - if (t <= time(NULL)) { - + if (state.timeout <= time(NULL)) { /* * We're expired, delete the entry. We can't use gencache_del * here, because that uses gencache_get_data_blob for checking @@ -418,28 +414,11 @@ bool gencache_get_data_blob(const char *keystr, DATA_BLOB *blob, * directly store an empty value with 0 timeout. */ gencache_set(keystr, "", 0); - - SAFE_FREE(databuf.dptr); - expired = true; goto fail; } - - if (blob != NULL) { - *blob = data_blob( - endptr+1, - databuf.dsize - PTR_DIFF(endptr+1, databuf.dptr)); - if (blob->data == NULL) { - SAFE_FREE(databuf.dptr); - DEBUG(0, ("memdup failed\n")); - goto fail; - } - } - - SAFE_FREE(databuf.dptr); - if (timeout) { - *timeout = t; + *timeout = state.timeout; } return True; |