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