r17898@catbus: nickm | 2008-02-05 14:01:35 -0500

Add (and use) a MAP_DEL_CURRENT macro to augment a non-const variant of MAP_FOREACH.


svn:r13379
This commit is contained in:
Nick Mathewson 2008-02-05 19:40:17 +00:00
parent 2502359a5b
commit 3958d7b16f
2 changed files with 27 additions and 14 deletions

View File

@ -220,10 +220,33 @@ DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp); \
valvar = valvar##_voidp;
#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar) \
STMT_BEGIN \
prefix##iter_t *key##_iter; \
int keyvar##_del=0; \
for (key##_iter = prefix##iter_init(map); \
!prefix##iter_done(key##_iter); \
key##_iter = keyvar##_del ? \
prefix##iter_next_rmv(map, key##_iter) : \
prefix##iter_next(map, key##_iter)) { \
keytype keyvar; \
void *valvar##_voidp; \
valtype valvar; \
keyvar##_del=0; \
prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp); \
valvar = valvar##_voidp;
#define MAP_DEL_CURRENT(keyvar) \
STMT_BEGIN \
keyvar##_del = 1; \
STMT_END
#define MAP_FOREACH_END } STMT_END ;
#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar) \
MAP_FOREACH(digestmap_, map, const char *, keyvar, valtype, valvar)
#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
MAP_FOREACH_MODIFY(digestmap_, map, const char *, keyvar, valtype, valvar)
#define DIGESTMAP_FOREACH_END MAP_FOREACH_END
void* strmap_set_lc(strmap_t *map, const char *key, void *val);

View File

@ -1396,22 +1396,13 @@ dirserv_set_cached_networkstatus_v3(const char *networkstatus,
void
dirserv_clear_old_networkstatuses(time_t cutoff)
{
digestmap_iter_t *iter;
if (!cached_v2_networkstatus)
return;
for (iter = digestmap_iter_init(cached_v2_networkstatus);
!digestmap_iter_done(iter); ) {
const char *ident;
void *val;
cached_dir_t *dir;
digestmap_iter_get(iter, &ident, &val);
dir = val;
DIGESTMAP_FOREACH_MODIFY(cached_v2_networkstatus, id, cached_dir_t *, dir) {
if (dir->published < cutoff) {
char *fname;
iter = digestmap_iter_next_rmv(cached_v2_networkstatus, iter);
fname = networkstatus_get_cache_filename(ident);
fname = networkstatus_get_cache_filename(id);
if (file_status(fname) == FN_FILE) {
log_info(LD_DIR, "Removing too-old untrusted networkstatus in %s",
fname);
@ -1419,10 +1410,9 @@ dirserv_clear_old_networkstatuses(time_t cutoff)
}
tor_free(fname);
cached_dir_decref(dir);
} else {
iter = digestmap_iter_next(cached_v2_networkstatus, iter);
MAP_DEL_CURRENT(id);
}
}
} DIGESTMAP_FOREACH_END
}
/** Remove any v1 info from the directory cache that was published