]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ufsdump.cc
Merged from trunk
[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 "config.h"
36 #include "StoreMeta.h"
37 #include "StoreMetaUnpacker.h"
38 #include "Store.h"
39 #include "Generic.h"
40 #undef malloc
41 #undef free
42
43 #if HAVE_STDEXCEPT
44 #include <stdexcept>
45 #endif
46 #if HAVE_IOSTREAM
47 #include <iostream>
48 #endif
49 #if HAVE_CASSERT
50 #include <cassert>
51 #endif
52
53 /* stub functions for parts of squid not factored to be dynamic yet */
54 void
55 eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
56 {}
57
58 // required by storeKeyPublicByRequest*
59 // XXX: what pulls in storeKeyPublicByRequest?
60 const char *urlCanonical(HttpRequest *) { assert(false); return NULL; }
61
62 void
63 storeAppendPrintf(StoreEntry * e, const char *fmt,...)
64 {
65 va_list args;
66 va_start(args, fmt);
67
68 assert(false);
69
70 va_end(args);
71 }
72
73 #include "CacheManager.h"
74 CacheManager*
75 CacheManager::GetInstance()
76 {
77 assert(false);
78 return NULL;
79 }
80
81 void
82 CacheManager::registerAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic) {}
83
84 /* MinGW needs also a stub of death() */
85 void
86 death(int sig)
87 {
88 std::cout << "Fatal: Signal " << sig;
89 exit(1);
90 }
91
92 void
93 fatal(const char *message)
94 {
95 fprintf(stderr, "FATAL: %s\n", message);
96 exit(1);
97 }
98
99 /* end stub functions */
100
101 struct MetaStd {
102 time_t timestamp;
103 time_t lastref;
104 time_t expires;
105 time_t lastmod;
106 size_t swap_file_sz;
107 u_short refcount;
108 u_short flags;
109 };
110
111 struct MetaStdLfs {
112 time_t timestamp;
113 time_t lastref;
114 time_t expires;
115 time_t lastmod;
116 uint64_t swap_file_sz;
117 u_short refcount;
118 u_short flags;
119 };
120
121 struct DumpStoreMeta : public unary_function<StoreMeta, void> {
122 DumpStoreMeta() {}
123
124 void operator()(StoreMeta const &x) {
125 switch (x.getType()) {
126
127 case STORE_META_KEY:
128 std::cout << "MD5: " << storeKeyText((const cache_key *)x.value) << std::endl;
129 break;
130
131 case STORE_META_STD:
132 std::cout << "STD, Size:" << ((struct MetaStd*)x.value)->swap_file_sz <<
133 " Flags: 0x" << std::hex << ((struct MetaStd*)x.value)->flags << std::dec <<
134 " Refcount: " << ((struct MetaStd*)x.value)->refcount <<
135 std::endl;
136 break;
137
138 case STORE_META_STD_LFS:
139 std::cout << "STD_LFS, Size: " << ((struct MetaStdLfs*)x.value)->swap_file_sz <<
140 " Flags: 0x" << std::hex << ((struct MetaStdLfs*)x.value)->flags << std::dec <<
141 " Refcount: " << ((struct MetaStdLfs*)x.value)->refcount <<
142 std::endl;
143 break;
144
145 case STORE_META_URL:
146 assert (((char *)x.value)[x.length - 1] == 0);
147 std::cout << "URL: " << (char *)x.value << std::endl;
148 break;
149
150 default:
151 std::cout << "Unknown store meta type: " << (int)x.getType() <<
152 " of length " << x.length << std::endl;
153 break;
154 }
155 }
156 };
157
158 int
159 main(int argc, char *argv[])
160 {
161 int fd = -1;
162 StoreMeta *metadata = NULL;
163
164 try {
165 if (argc != 2)
166 throw std::runtime_error("No filename provided");
167
168 fd = open (argv[1], O_RDONLY | O_BINARY);
169
170 if (fd < 0)
171 throw std::runtime_error("Could not open file.");
172
173 char tempbuf[SM_PAGE_SIZE];
174
175 int len = read(fd, tempbuf, SM_PAGE_SIZE);
176
177 if (len < 0)
178 throw std::runtime_error("Could not read header into memory.");
179
180 close (fd);
181
182 fd = -1;
183
184 int hdr_len;
185
186 StoreMetaUnpacker aBuilder(tempbuf, len, &hdr_len);
187
188 metadata = aBuilder.createStoreMeta ();
189
190 cache_key key[SQUID_MD5_DIGEST_LENGTH];
191
192 memset(key, '\0', SQUID_MD5_DIGEST_LENGTH);
193
194 DumpStoreMeta dumper;
195
196 for_each(*metadata, dumper);
197
198
199 return 0;
200 } catch (std::runtime_error error) {
201 std::cout << "Failed : " << error.what() << std::endl;
202
203 if (fd >= 0)
204 close(fd);
205
206 if (metadata)
207 StoreMeta::FreeList(&metadata);
208
209 return 1;
210 }
211 }