]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
528b2c61 | 4 | * |
5 | * DEBUG: section 20 Storage Manager Swapfile Metadata | |
6 | * AUTHOR: Kostas Anagnostakis | |
7 | * | |
8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
9 | * ---------------------------------------------------------- | |
10 | * | |
11 | * Squid is the result of efforts by numerous individuals from | |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
19 | * | |
20 | * This program is free software; you can redistribute it and/or modify | |
21 | * it under the terms of the GNU General Public License as published by | |
22 | * the Free Software Foundation; either version 2 of the License, or | |
23 | * (at your option) any later version. | |
26ac0430 | 24 | * |
528b2c61 | 25 | * This program is distributed in the hope that it will be useful, |
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 | * GNU General Public License for more details. | |
26ac0430 | 29 | * |
528b2c61 | 30 | * You should have received a copy of the GNU General Public License |
31 | * along with this program; if not, write to the Free Software | |
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
33 | * | |
34 | */ | |
35 | ||
f7f3304a | 36 | #include "squid-old.h" |
528b2c61 | 37 | #include "StoreMeta.h" |
38 | #include "Store.h" | |
39 | #include "MemObject.h" | |
40 | #include "StoreMetaMD5.h" | |
41 | #include "StoreMetaURL.h" | |
42 | #include "StoreMetaSTD.h" | |
47f6e231 | 43 | #include "StoreMetaSTDLFS.h" |
528b2c61 | 44 | #include "StoreMetaVary.h" |
9e6e1d99 | 45 | #include "StoreMetaObjSize.h" |
528b2c61 | 46 | |
47 | bool | |
48 | StoreMeta::validType(char type) | |
49 | { | |
50 | /* VOID is reserved, and new types have to be added as classes */ | |
b7f7b5a3 | 51 | if (type <= STORE_META_VOID || type >= STORE_META_END + 10) { |
bf8fe701 | 52 | debugs(20, 0, "storeSwapMetaUnpack: bad type (" << type << ")!"); |
62e76326 | 53 | return false; |
528b2c61 | 54 | } |
62e76326 | 55 | |
b7f7b5a3 | 56 | /* Not yet implemented */ |
02f95cf0 | 57 | if (type >= STORE_META_END || |
26ac0430 AJ |
58 | type == STORE_META_STOREURL || |
59 | type == STORE_META_VARY_ID) { | |
b7f7b5a3 | 60 | debugs(20, 3, "storeSwapMetaUnpack: Not yet implemented (" << type << ") in disk metadata"); |
61 | return false; | |
62 | } | |
63 | ||
528b2c61 | 64 | /* Unused in any current squid code */ |
65 | if (type == STORE_META_KEY_URL || | |
62e76326 | 66 | type == STORE_META_KEY_SHA || |
67 | type == STORE_META_HITMETERING || | |
68 | type == STORE_META_VALID) { | |
bf8fe701 | 69 | debugs(20, 0, "Obsolete and unused type (" << type << ") in disk metadata"); |
62e76326 | 70 | return false; |
528b2c61 | 71 | } |
62e76326 | 72 | |
528b2c61 | 73 | return true; |
74 | } | |
75 | ||
62e76326 | 76 | class IntRange |
77 | { | |
78 | ||
528b2c61 | 79 | public: |
26ac0430 | 80 | IntRange (int minimum, int maximum) : _min (minimum), _max (maximum) { |
62e76326 | 81 | if (_min > _max) { |
82 | int temp = _min; | |
83 | _min = _max; | |
84 | _max = temp; | |
85 | } | |
86 | } | |
87 | ||
26ac0430 | 88 | bool includes (int anInt) const { |
62e76326 | 89 | if (anInt < _min || anInt > _max) |
90 | return false; | |
91 | ||
92 | return true; | |
93 | } | |
94 | ||
528b2c61 | 95 | private: |
96 | int _min; | |
97 | int _max; | |
98 | }; | |
99 | ||
100 | const int StoreMeta::MinimumTLVLength = 0; | |
101 | const int StoreMeta::MaximumTLVLength = 1 << 16; | |
102 | ||
103 | bool | |
e4ae841b | 104 | StoreMeta::validLength(int aLength) const |
528b2c61 | 105 | { |
e4ae841b FC |
106 | if (!IntRange (MinimumTLVLength, MaximumTLVLength).includes(aLength)) { |
107 | debugs(20, 0, "storeSwapMetaUnpack: insane length (" << aLength << ")!"); | |
62e76326 | 108 | return false; |
528b2c61 | 109 | } |
62e76326 | 110 | |
528b2c61 | 111 | return true; |
112 | } | |
113 | ||
114 | ||
115 | StoreMeta * | |
116 | StoreMeta::Factory (char type, size_t len, void const *value) | |
117 | { | |
118 | if (!validType(type)) | |
119 | return NULL; | |
62e76326 | 120 | |
528b2c61 | 121 | StoreMeta *result; |
62e76326 | 122 | |
528b2c61 | 123 | switch (type) { |
62e76326 | 124 | |
125 | case STORE_META_KEY: | |
126 | result = new StoreMetaMD5; | |
127 | break; | |
128 | ||
129 | case STORE_META_URL: | |
130 | result = new StoreMetaURL; | |
131 | break; | |
132 | ||
133 | case STORE_META_STD: | |
134 | result = new StoreMetaSTD; | |
135 | break; | |
136 | ||
47f6e231 | 137 | case STORE_META_STD_LFS: |
138 | result = new StoreMetaSTDLFS; | |
139 | break; | |
140 | ||
26ac0430 AJ |
141 | case STORE_META_OBJSIZE: |
142 | result = new StoreMetaObjSize; | |
9e6e1d99 | 143 | break; |
144 | ||
62e76326 | 145 | case STORE_META_VARY_HEADERS: |
146 | result = new StoreMetaVary; | |
147 | break; | |
148 | ||
149 | default: | |
bf8fe701 | 150 | debugs(20, 0, "Attempt to create unknown concrete StoreMeta"); |
62e76326 | 151 | return NULL; |
528b2c61 | 152 | } |
62e76326 | 153 | |
528b2c61 | 154 | if (!result->validLength(len)) { |
00d77d6b | 155 | delete result; |
62e76326 | 156 | return NULL; |
528b2c61 | 157 | } |
62e76326 | 158 | |
528b2c61 | 159 | result->length = len; |
160 | result->value = xmalloc(len); | |
41d00cd3 | 161 | memcpy(result->value, value, len); |
528b2c61 | 162 | return result; |
163 | } | |
164 | ||
165 | void | |
166 | StoreMeta::FreeList(StoreMeta **head) | |
167 | { | |
168 | StoreMeta *node; | |
62e76326 | 169 | |
528b2c61 | 170 | while ((node = *head) != NULL) { |
62e76326 | 171 | *head = node->next; |
172 | xfree(node->value); | |
00d77d6b | 173 | delete node; |
528b2c61 | 174 | } |
175 | } | |
176 | ||
177 | StoreMeta ** | |
178 | StoreMeta::Add(StoreMeta **tail, StoreMeta *aNode) | |
179 | { | |
180 | assert (*tail == NULL); | |
181 | *tail = aNode; | |
182 | return &aNode->next; /* return new tail pointer */ | |
183 | } | |
184 | ||
62e76326 | 185 | bool |
528b2c61 | 186 | StoreMeta::checkConsistency(StoreEntry *e) const |
187 | { | |
62e76326 | 188 | switch (getType()) { |
189 | ||
190 | case STORE_META_KEY: | |
191 | ||
192 | case STORE_META_URL: | |
193 | ||
194 | case STORE_META_VARY_HEADERS: | |
195 | assert(0); | |
196 | break; | |
197 | ||
198 | case STORE_META_STD: | |
199 | break; | |
200 | ||
47f6e231 | 201 | case STORE_META_STD_LFS: |
202 | break; | |
203 | ||
204 | case STORE_META_OBJSIZE: | |
26ac0430 | 205 | break; |
47f6e231 | 206 | |
62e76326 | 207 | default: |
bf8fe701 | 208 | debugs(20, 1, "WARNING: got unused STORE_META type " << getType()); |
62e76326 | 209 | break; |
210 | } | |
211 | ||
528b2c61 | 212 | return true; |
213 | } |