]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ufsdump.cc
protos.h refactoring, part one.
[thirdparty/squid.git] / src / ufsdump.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 00 UFS Store Dump Tool
5 * AUTHOR: Robert Collins
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #include "squid.h"
36 #include "StoreMeta.h"
37 #include "StoreMetaUnpacker.h"
38 #include "Store.h"
39 #include "store_key_md5.h"
40 #include "Generic.h"
41 #include "mgr/Registration.h"
42
43 #undef malloc
44 #undef free
45
46 #if HAVE_STDEXCEPT
47 #include <stdexcept>
48 #endif
49 #if HAVE_IOSTREAM
50 #include <iostream>
51 #endif
52 #if HAVE_CASSERT
53 #include <cassert>
54 #endif
55
56 /* stub functions for parts of squid not factored to be dynamic yet */
57 void
58 eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
59 {}
60
61 // required by storeKeyPublicByRequest*
62 // XXX: what pulls in storeKeyPublicByRequest?
63 const char *urlCanonical(HttpRequest *) { assert(false); return NULL; }
64
65 void
66 storeAppendPrintf(StoreEntry * e, const char *fmt,...)
67 {
68 va_list args;
69 va_start(args, fmt);
70
71 assert(false);
72
73 va_end(args);
74 }
75
76 void
77 Mgr::RegisterAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {}
78
79 /* MinGW needs also a stub of death() */
80 void
81 death(int sig)
82 {
83 std::cout << "Fatal: Signal " << sig;
84 exit(1);
85 }
86
87 void
88 fatal(const char *message)
89 {
90 fprintf(stderr, "FATAL: %s\n", message);
91 exit(1);
92 }
93
94 /* end stub functions */
95
96 struct MetaStd {
97 time_t timestamp;
98 time_t lastref;
99 time_t expires;
100 time_t lastmod;
101 size_t swap_file_sz;
102 uint16_t refcount;
103 uint16_t flags;
104 };
105
106 struct MetaStdLfs {
107 time_t timestamp;
108 time_t lastref;
109 time_t expires;
110 time_t lastmod;
111 uint64_t swap_file_sz;
112 uint16_t refcount;
113 uint16_t flags;
114 };
115
116 struct DumpStoreMeta : public unary_function<StoreMeta, void> {
117 DumpStoreMeta() {}
118
119 void operator()(StoreMeta const &x) {
120 switch (x.getType()) {
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:
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;
131 break;
132
133 case STORE_META_STD_LFS:
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;
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;
143 break;
144
145 default:
146 std::cout << "Unknown store meta type: " << (int)x.getType() <<
147 " of length " << x.length << std::endl;
148 break;
149 }
150 }
151 };
152
153 int
154 main(int argc, char *argv[])
155 {
156 int fd = -1;
157 StoreMeta *metadata = NULL;
158
159 try {
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
185 cache_key key[SQUID_MD5_DIGEST_LENGTH];
186
187 memset(key, '\0', SQUID_MD5_DIGEST_LENGTH);
188
189 DumpStoreMeta dumper;
190
191 for_each(*metadata, dumper);
192
193 return 0;
194 } catch (std::runtime_error error) {
195 std::cout << "Failed : " << error.what() << std::endl;
196
197 if (fd >= 0)
198 close(fd);
199
200 if (metadata)
201 StoreMeta::FreeList(&metadata);
202
203 return 1;
204 }
205 }