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