-
/*
- * $Id$
- *
- * AUTHOR: Alex Rousskov
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
/*
* Test-suite for playing with cache digests
*/
-#include "squid-old.h"
+#include "squid.h"
+#include "CacheDigest.h"
+#include "store_key_md5.h"
+
+#include <cerrno>
typedef struct {
int query_count;
CacheDigest *digest;
Cache *peer;
CacheQueryStats qstats;
- int count; /* #currently cached entries */
- int req_count; /* #requests to this cache */
- int bad_add_count; /* #duplicate adds */
- int bad_del_count; /* #dels with no prior add */
+ int count; /* #currently cached entries */
+ int req_count; /* #requests to this cache */
+ int bad_add_count; /* #duplicate adds */
+ int bad_del_count; /* #dels with no prior add */
};
-
typedef struct _CacheEntry {
const cache_key *key;
typedef struct {
cache_key key[SQUID_MD5_DIGEST_LENGTH];
time_t timestamp;
- short int use_icp; /* true/false */
+ short int use_icp; /* true/false */
} RawAccessLogEntry;
typedef enum {
struct _FileIterator {
const char *fname;
FILE *file;
- time_t inner_time; /* timestamp of the current entry */
- time_t time_offset; /* to adjust time set by reader */
- int line_count; /* number of lines scanned */
- int bad_line_count; /* number of parsing errors */
- int time_warp_count; /* number of out-of-order entries in the file */
- FI_READER reader; /* reads next entry and updates inner_time */
- void *entry; /* buffer for the current entry, freed with xfree() */
+ time_t inner_time; /* timestamp of the current entry */
+ time_t time_offset; /* to adjust time set by reader */
+ int line_count; /* number of lines scanned */
+ int bad_line_count; /* number of parsing errors */
+ int time_warp_count; /* number of out-of-order entries in the file */
+ FI_READER reader; /* reads next entry and updates inner_time */
+ void *entry; /* buffer for the current entry, freed with xfree() */
};
/* globals */
-static time_t cur_time = -1; /* timestamp of the current log entry */
-
-/* copied from url.c */
-const char *RequestMethodStr[] = {
- "NONE",
- "GET",
- "POST",
- "PUT",
- "HEAD",
- "CONNECT",
- "TRACE",
- "PURGE"
-};
+static time_t cur_time = -1; /* timestamp of the current log entry */
/* copied from url.c */
static HttpRequestMethod
xfree(e);
}
-
/* Cache */
static Cache *
/* destroy the hash table itself */
hashFreeMemory(hash);
- if (cache->digest)
- cacheDigestDestroy(cache->digest);
-
+ delete cache->digest;
xfree(cache);
}
assert(cache);
fprintf(stderr, "%s: init-ing digest with %d entries\n", cache->name, cache->count);
- if (cache->digest)
- cacheDigestDestroy(cache->digest);
-
hash = cache->hash;
- cache->digest = cacheDigestCreate(cache->count + 1, 6);
+ delete cache->digest;
+ cache->digest = new CacheDigest(cache->count + 1, 6);
if (!cache->count)
return;
hash_first(hash);
while ((e = (CacheEntry *)hash_next(hash))) {
- cacheDigestAdd(cache->digest, e->key);
+ cache->digest->add(e->key);
}
gettimeofday(&t_end, NULL);
cacheQueryPeer(Cache * cache, const cache_key * key)
{
const int peer_has_it = hash_lookup(cache->peer->hash, key) != NULL;
- const int we_think_we_have_it = cacheDigestTest(cache->digest, key);
+ const int we_think_we_have_it = cache->digest->test(key);
++ cache->qstats.query_count;
entry = (RawAccessLogEntry*)fi->entry;
if (!fgets(buf, sizeof(buf), fi->file))
- return frEof; /* eof */
+ return frEof; /* eof */
entry->timestamp = fi->inner_time = (time_t) atoi(buf);
return frOk;
}
-
static void
cachePurge(Cache * cache, storeSwapLogData * s, int update_digest)
{
hash_remove_link(cache->hash, (hash_link *) olde);
if (update_digest)
- cacheDigestDel(cache->digest, s->key);
+ cache->digest->remove(s->key);
cacheEntryDestroy(olde);
++ cache->count;
if (update_digest)
- cacheDigestAdd(cache->digest, e->key);
+ cache->digest->add(e->key);
}
}
{
fprintf(stderr, "usage: %s <access_log> <swap_state> ...\n",
prg_name);
- return -1;
+ return EXIT_FAILURE;
}
int
/* digest peer cache content */
cacheResetDigest(them);
- us->digest = cacheDigestClone(them->digest); /* @netw@ */
+ us->digest = them->digest->clone();
/* shift the time in access log to match ready_time */
fileIteratorSetCurTime(fis[0], ready_time);
xfree(fis);
cacheDestroy(them);
cacheDestroy(us);
- return 0;
+ return EXIT_SUCCESS;
}
+