store_swapmeta.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 "md5.h"
13 #include "MemObject.h"
14 #include "Store.h"
15 #include "StoreMeta.h"
16 #include "StoreMetaUnpacker.h"
17 
18 #if HAVE_SYS_WAIT_H
19 #include <sys/wait.h>
20 #endif
21 
22 void
24 {
25  tlv *t;
26 
27  while ((t = n) != NULL) {
28  n = t->next;
29  xfree(t->value);
30  delete t;
31  }
32 }
33 
34 /*
35  * Build a TLV list for a StoreEntry
36  */
37 tlv *
39 {
40  tlv *TLV = NULL; /* we'll return this */
41  tlv **T = &TLV;
42  assert(e->mem_obj != NULL);
43  const int64_t objsize = e->mem_obj->expectedReplySize();
44 
45  // e->mem_obj->request may be nil in this context
46  SBuf url;
47  if (e->mem_obj->request)
48  url = e->mem_obj->request->storeId();
49  else
50  url = e->url();
51 
52  debugs(20, 3, "storeSwapMetaBuild URL: " << url);
53 
55 
56  if (!t) {
57  storeSwapTLVFree(TLV);
58  return NULL;
59  }
60 
61  T = StoreMeta::Add(T, t);
63 
64  if (!t) {
65  storeSwapTLVFree(TLV);
66  return NULL;
67  }
68 
69  // XXX: do TLV without the c_str() termination. check readers first though
70  T = StoreMeta::Add(T, t);
71  t = StoreMeta::Factory(STORE_META_URL, url.length()+1, url.c_str());
72 
73  if (!t) {
74  storeSwapTLVFree(TLV);
75  return NULL;
76  }
77 
78  if (objsize >= 0) {
79  T = StoreMeta::Add(T, t);
80  t = StoreMeta::Factory(STORE_META_OBJSIZE, sizeof(objsize), &objsize);
81 
82  if (!t) {
83  storeSwapTLVFree(TLV);
84  return NULL;
85  }
86  }
87 
88  T = StoreMeta::Add(T, t);
89  SBuf vary(e->mem_obj->vary_headers);
90 
91  if (!vary.isEmpty()) {
93 
94  if (!t) {
95  storeSwapTLVFree(TLV);
96  return NULL;
97  }
98 
99  StoreMeta::Add (T, t);
100  }
101 
102  return TLV;
103 }
104 
105 char *
106 storeSwapMetaPack(tlv * tlv_list, int *length)
107 {
108  int buflen = 0;
109  tlv *t;
110  int j = 0;
111  char *buf;
112  assert(length != NULL);
113  ++buflen; /* STORE_META_OK */
114  buflen += sizeof(int); /* size of header to follow */
115 
116  for (t = tlv_list; t; t = t->next)
117  buflen += sizeof(char) + sizeof(int) + t->length;
118 
119  buf = (char *)xmalloc(buflen);
120 
121  buf[j] = (char) STORE_META_OK;
122  ++j;
123 
124  memcpy(&buf[j], &buflen, sizeof(int));
125 
126  j += sizeof(int);
127 
128  for (t = tlv_list; t; t = t->next) {
129  buf[j] = t->getType();
130  ++j;
131  memcpy(&buf[j], &t->length, sizeof(int));
132  j += sizeof(int);
133  memcpy(&buf[j], t->value, t->length);
134  j += t->length;
135  }
136 
137  assert((int) j == buflen);
138  *length = buflen;
139  return buf;
140 }
141 
#define STORE_META_OK
Definition: defines.h:141
static StoreMeta ** Add(StoreMeta **tail, StoreMeta *aNode)
Definition: StoreMeta.cc:130
#define STORE_HDR_METASIZE
Definition: defines.h:172
#define assert(EX)
Definition: assert.h:17
Definition: SBuf.h:87
static StoreMeta * Factory(char type, size_t len, void const *value)
Definition: StoreMeta.cc:68
bool isEmpty() const
Definition: SBuf.h:422
const SBuf storeId()
Definition: HttpRequest.cc:662
time_t timestamp
Definition: Store.h:165
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:405
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define STORE_META_KEY
Definition: defines.h:165
#define SQUID_MD5_DIGEST_LENGTH
Definition: md5.h:66
tlv * storeSwapMetaBuild(StoreEntry *e)
const char * c_str()
Definition: SBuf.cc:546
class StoreMeta tlv
Definition: StoreMeta.h:15
MemObject * mem_obj
Definition: Store.h:162
void storeSwapTLVFree(tlv *n)
const char * url() const
Definition: store.cc:1672
void const char * buf
Definition: stub_helper.cc:16
bool SIGHDLR int STUB void int
Definition: stub_tools.cc:68
SBuf vary_headers
Definition: MemObject.h:176
char * storeSwapMetaPack(tlv *tlv_list, int *length)
#define xmalloc
#define xfree
HttpRequestPointer request
Definition: MemObject.h:157
#define NULL
Definition: types.h:166
int64_t expectedReplySize() const
Definition: MemObject.cc:256

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors