StoreMeta.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 20 Storage Manager Swapfile Metadata */
10 
11 #include "squid.h"
12 #include "base/Range.h"
13 #include "MemObject.h"
14 #include "Store.h"
15 #include "StoreMeta.h"
16 #include "StoreMetaMD5.h"
17 #include "StoreMetaObjSize.h"
18 #include "StoreMetaSTD.h"
19 #include "StoreMetaSTDLFS.h"
20 #include "StoreMetaURL.h"
21 #include "StoreMetaVary.h"
22 
23 bool
25 {
26  /* VOID is reserved, and new types have to be added as classes */
27  if (type <= STORE_META_VOID || type >= STORE_META_END + 10) {
28  debugs(20, DBG_CRITICAL, "storeSwapMetaUnpack: bad type (" << type << ")!");
29  return false;
30  }
31 
32  /* Not yet implemented */
33  if (type >= STORE_META_END ||
34  type == STORE_META_STOREURL ||
35  type == STORE_META_VARY_ID) {
36  debugs(20, 3, "storeSwapMetaUnpack: Not yet implemented (" << type << ") in disk metadata");
37  return false;
38  }
39 
40  /* Unused in any current squid code */
41  if (type == STORE_META_KEY_URL ||
42  type == STORE_META_KEY_SHA ||
43  type == STORE_META_HITMETERING ||
44  type == STORE_META_VALID) {
45  debugs(20, DBG_CRITICAL, "Obsolete and unused type (" << type << ") in disk metadata");
46  return false;
47  }
48 
49  return true;
50 }
51 
52 const int StoreMeta::MinimumTLVLength = 0;
53 const int StoreMeta::MaximumTLVLength = 1 << 16;
54 
55 bool
56 StoreMeta::validLength(int aLength) const
57 {
59  if (!TlvValidLengths.contains(aLength)) {
60  debugs(20, DBG_CRITICAL, MYNAME << ": insane length (" << aLength << ")!");
61  return false;
62  }
63 
64  return true;
65 }
66 
67 StoreMeta *
68 StoreMeta::Factory (char type, size_t len, void const *value)
69 {
70  if (!validType(type))
71  return NULL;
72 
73  StoreMeta *result;
74 
75  switch (type) {
76 
77  case STORE_META_KEY:
78  result = new StoreMetaMD5;
79  break;
80 
81  case STORE_META_URL:
82  result = new StoreMetaURL;
83  break;
84 
85  case STORE_META_STD:
86  result = new StoreMetaSTD;
87  break;
88 
89  case STORE_META_STD_LFS:
90  result = new StoreMetaSTDLFS;
91  break;
92 
93  case STORE_META_OBJSIZE:
94  result = new StoreMetaObjSize;
95  break;
96 
98  result = new StoreMetaVary;
99  break;
100 
101  default:
102  debugs(20, DBG_CRITICAL, "Attempt to create unknown concrete StoreMeta");
103  return NULL;
104  }
105 
106  if (!result->validLength(len)) {
107  delete result;
108  return NULL;
109  }
110 
111  result->length = len;
112  result->value = xmalloc(len);
113  memcpy(result->value, value, len);
114  return result;
115 }
116 
117 void
119 {
120  StoreMeta *node;
121 
122  while ((node = *head) != NULL) {
123  *head = node->next;
124  xfree(node->value);
125  delete node;
126  }
127 }
128 
129 StoreMeta **
131 {
132  assert (*tail == NULL);
133  *tail = aNode;
134  return &aNode->next; /* return new tail pointer */
135 }
136 
137 bool
139 {
140  switch (getType()) {
141 
142  case STORE_META_KEY:
143 
144  case STORE_META_URL:
145 
147  assert(0);
148  break;
149 
150  case STORE_META_STD:
151  break;
152 
153  case STORE_META_STD_LFS:
154  break;
155 
156  case STORE_META_OBJSIZE:
157  break;
158 
159  default:
160  debugs(20, DBG_IMPORTANT, "WARNING: got unused STORE_META type " << getType());
161  break;
162  }
163 
164  return true;
165 }
166 
168  length(s.length),
169  value(s.value),
170  next(s.next)
171 {}
172 
174 {
175  length=s.length;
176  value=s.value;
177  next=s.next;
178  return *this;
179 }
180 
tlv * next
Definition: StoreMeta.h:134
static StoreMeta ** Add(StoreMeta **tail, StoreMeta *aNode)
Definition: StoreMeta.cc:130
static void FreeList(StoreMeta **head)
Definition: StoreMeta.cc:118
#define assert(EX)
Definition: assert.h:17
int type
Definition: errorpage.cc:79
Definition: Range.h:18
static StoreMeta * Factory(char type, size_t len, void const *value)
Definition: StoreMeta.cc:68
void * value
Definition: StoreMeta.h:133
#define DBG_CRITICAL
Definition: Debug.h:44
Definition: parse.c:104
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define DBG_IMPORTANT
Definition: Debug.h:45
#define STORE_META_KEY
Definition: defines.h:165
virtual bool validLength(int) const
Definition: StoreMeta.cc:56
int length
Definition: StoreMeta.h:132
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
static int const MaximumTLVLength
Definition: StoreMeta.h:121
StoreMeta & operator=(const StoreMeta &)
Definition: StoreMeta.cc:173
#define MYNAME
Definition: Debug.h:160
virtual bool checkConsistency(StoreEntry *) const
Definition: StoreMeta.cc:138
virtual char getType() const =0
#define xmalloc
static bool validType(char)
Definition: StoreMeta.cc:24
static int const MinimumTLVLength
Definition: StoreMeta.h:122
#define xfree
bool contains(C const &) const
Definition: Range.h:54
squidaio_request_t * head
Definition: aiops.cc:127
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors