]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ufsdump.cc
Fix alias linker dist/install
[thirdparty/squid.git] / src / ufsdump.cc
CommitLineData
528b2c61 1
2/*
262a0e14 3 * $Id$
528b2c61 4 *
5 * DEBUG: section 0 UFS Store Dump
6 * AUTHOR: Robert Collins
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
26ac0430 24 *
528b2c61 25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
26ac0430 29 *
528b2c61 30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
85944c1c 36#include "config.h"
528b2c61 37#include "StoreMeta.h"
38#include "StoreMetaUnpacker.h"
39#include "Store.h"
40#include "Generic.h"
528b2c61 41#undef malloc
42#undef free
27e059d4
AJ
43
44#if HAVE_STDEXCEPT
528b2c61 45#include <stdexcept>
27e059d4
AJ
46#endif
47#if HAVE_IOSTREAM
528b2c61 48#include <iostream>
27e059d4
AJ
49#endif
50#if HAVE_CASSERT
7a6dc83d 51#include <cassert>
27e059d4 52#endif
528b2c61 53
c21ad0f5 54/* stub functions for parts of squid not factored to be dynamic yet */
74544ee3
AR
55void
56eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
528b2c61 57{}
58
74544ee3
AR
59// required by storeKeyPublicByRequest*
60// XXX: what pulls in storeKeyPublicByRequest?
61const char *urlCanonical(HttpRequest *) { assert(false); return NULL; }
62
757a2291 63void
74544ee3
AR
64storeAppendPrintf(StoreEntry * e, const char *fmt,...)
65{
66 va_list args;
67 va_start(args, fmt);
68
af6a12ee 69 assert(false);
74544ee3
AR
70
71 va_end(args);
72}
73
74#include "CacheManager.h"
75CacheManager*
76CacheManager::GetInstance()
77{
af6a12ee 78 assert(false);
74544ee3
AR
79 return NULL;
80}
757a2291 81
c21ad0f5 82void
74544ee3
AR
83CacheManager::registerAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {}
84
f3f3e961
GS
85/* MinGW needs also a stub of death() */
86void
87death(int sig)
88{
89 std::cout << "Fatal: Signal " << sig;
90 exit (1);
91}
92
c21ad0f5 93
c21ad0f5 94/* end stub functions */
528b2c61 95
26ac0430 96struct MetaStd {
47f6e231 97 time_t timestamp;
26ac0430
AJ
98 time_t lastref;
99 time_t expires;
100 time_t lastmod;
101 size_t swap_file_sz;
102 u_short refcount;
103 u_short flags;
47f6e231 104};
105
26ac0430
AJ
106struct MetaStdLfs {
107 time_t timestamp;
108 time_t lastref;
109 time_t expires;
110 time_t lastmod;
111 uint64_t swap_file_sz;
112 u_short refcount;
113 u_short flags;
47f6e231 114};
115
26ac0430
AJ
116struct DumpStoreMeta : public unary_function<StoreMeta, void> {
117 DumpStoreMeta() {}
528b2c61 118
26ac0430 119 void operator()(StoreMeta const &x) {
528b2c61 120 switch (x.getType()) {
62e76326 121
122 case STORE_META_KEY:
123 std::cout << "MD5: " << storeKeyText((const cache_key *)x.value) << std::endl;
124 break;
125
126 case STORE_META_STD:
26ac0430
AJ
127 std::cout << "STD, Size:" << ((struct MetaStd*)x.value)->swap_file_sz <<
128 " Flags: 0x" << std::hex << ((struct MetaStd*)x.value)->flags << std::dec <<
129 " Refcount: " << ((struct MetaStd*)x.value)->refcount <<
130 std::endl;
47f6e231 131 break;
132
133 case STORE_META_STD_LFS:
26ac0430
AJ
134 std::cout << "STD_LFS, Size: " << ((struct MetaStdLfs*)x.value)->swap_file_sz <<
135 " Flags: 0x" << std::hex << ((struct MetaStdLfs*)x.value)->flags << std::dec <<
136 " Refcount: " << ((struct MetaStdLfs*)x.value)->refcount <<
137 std::endl;
62e76326 138 break;
139
140 case STORE_META_URL:
141 assert (((char *)x.value)[x.length - 1] == 0);
142 std::cout << "URL: " << (char *)x.value << std::endl;
47f6e231 143 break;
62e76326 144
145 default:
26ac0430
AJ
146 std::cout << "Unknown store meta type: " << (int)x.getType() <<
147 " of length " << x.length << std::endl;
62e76326 148 break;
149 }
528b2c61 150 }
151};
152
153int
154main(int argc, char *argv[])
155{
156 int fd = -1;
157 StoreMeta *metadata = NULL;
158
26ac0430 159 try {
528b2c61 160 if (argc != 2)
161 throw std::runtime_error("No filename provided");
162
163 fd = open (argv[1], O_RDONLY | O_BINARY);
164
165 if (fd < 0)
166 throw std::runtime_error("Could not open file.");
167
168 char tempbuf[SM_PAGE_SIZE];
169
170 int len = read(fd, tempbuf, SM_PAGE_SIZE);
171
172 if (len < 0)
173 throw std::runtime_error("Could not read header into memory.");
174
175 close (fd);
176
177 fd = -1;
178
179 int hdr_len;
180
181 StoreMetaUnpacker aBuilder(tempbuf, len, &hdr_len);
182
183 metadata = aBuilder.createStoreMeta ();
184
c3031d67 185 cache_key key[SQUID_MD5_DIGEST_LENGTH];
528b2c61 186
c3031d67 187 memset(key, '\0', SQUID_MD5_DIGEST_LENGTH);
528b2c61 188
62e76326 189 DumpStoreMeta dumper;
190
191 for_each(*metadata, dumper);
528b2c61 192
193
194 return 0;
26ac0430 195 } catch (std::runtime_error error) {
528b2c61 196 std::cout << "Failed : " << error.what() << std::endl;
197
198 if (fd >= 0)
199 close(fd);
200
201 if (metadata)
202 StoreMeta::FreeList(&metadata);
203
204 return 1;
205 }
206}