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