]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Return timed out entries from gencache_get if timeout param != NULL
authorVolker Lendecke <vl@samba.org>
Thu, 3 Jul 2008 13:58:37 +0000 (15:58 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 3 Jul 2008 13:59:19 +0000 (15:59 +0200)
net cache get was the only one interested in the timeout. That single caller
can take care of the timeout itself then.

With this API change idmap_cache.c can be converted to gencache.

source/lib/gencache.c
source/utils/net_cache.c

index b773f83c58125302b0153456664226f62119543b..1b4342a62bb44af072f317fa96625aa38465e216 100644 (file)
@@ -166,15 +166,16 @@ bool gencache_del(const char *keystr)
  *
  * @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
+ *               buffer's disposing must be done outside
+ * @param timeout If == NULL, the caller is not interested in timed out
+ *                entries. If != NULL, return the timeout timestamp, the
+ *                caller must figure out itself if this entry is timed out.
  *
  * @retval true when entry is successfuly fetched
  * @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 *ptimeout)
 {
        TDB_DATA databuf;
        time_t t;
@@ -207,9 +208,13 @@ bool gencache_get(const char *keystr, char **valstr, time_t *timeout)
                   "timeout = %s", t > time(NULL) ? "valid" :
                   "expired", keystr, endptr+1, ctime(&t)));
 
-       if (t <= time(NULL)) {
+       if ((t <= time(NULL)) && (ptimeout == NULL)) {
+
+               /*
+                * The entry is expired, and the caller isn't interested in
+                * timed out ones. Delete it.
+                */
 
-               /* We're expired, delete the entry */
                tdb_delete_bystring(cache, keystr);
 
                SAFE_FREE(databuf.dptr);
@@ -224,15 +229,15 @@ bool gencache_get(const char *keystr, char **valstr, time_t *timeout)
                        return False;
                }
        }
-       
+
        SAFE_FREE(databuf.dptr);
 
-       if (timeout) {
-               *timeout = t;
+       if (ptimeout) {
+               *ptimeout = t;
        }
 
        return True;
-} 
+}
 
 /**
  * Get existing entry from the cache file.
index 4e9ae18c0d9a6f8a738871aba547fdcf7a093e93..21fcc9155d1fa75ae05e619cf55d265faf52e947 100644 (file)
@@ -225,7 +225,8 @@ static int net_cache_get(struct net_context *c, int argc, const char **argv)
                return -1;
        }
 
-       if (gencache_get(keystr, &valuestr, &timeout)) {
+       if (gencache_get(keystr, &valuestr, &timeout)
+           && (timeout > time(NULL))) {
                print_cache_entry(keystr, valuestr, timeout, NULL);
                return 0;
        }