]>
Commit | Line | Data |
---|---|---|
9cef6668 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
9cef6668 | 3 | * |
bbc27441 AJ |
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. | |
9cef6668 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 20 Storage Manager Swapfile Metadata */ |
10 | ||
582c2af2 FC |
11 | #include "squid.h" |
12 | #include "md5.h" | |
528b2c61 | 13 | #include "MemObject.h" |
582c2af2 | 14 | #include "Store.h" |
528b2c61 | 15 | #include "StoreMeta.h" |
16 | #include "StoreMetaUnpacker.h" | |
f09f5b26 | 17 | |
582c2af2 FC |
18 | #if HAVE_SYS_WAIT_H |
19 | #include <sys/wait.h> | |
20 | #endif | |
21 | ||
69c01cd7 | 22 | void |
23 | storeSwapTLVFree(tlv * n) | |
f09f5b26 | 24 | { |
69c01cd7 | 25 | tlv *t; |
62e76326 | 26 | |
69c01cd7 | 27 | while ((t = n) != NULL) { |
62e76326 | 28 | n = t->next; |
29 | xfree(t->value); | |
00d77d6b | 30 | delete t; |
f09f5b26 | 31 | } |
f09f5b26 | 32 | } |
33 | ||
69c01cd7 | 34 | /* |
35 | * Build a TLV list for a StoreEntry | |
36 | */ | |
37 | tlv * | |
38 | storeSwapMetaBuild(StoreEntry * e) | |
f09f5b26 | 39 | { |
f53969cc | 40 | tlv *TLV = NULL; /* we'll return this */ |
69c01cd7 | 41 | tlv **T = &TLV; |
10602161 | 42 | assert(e->mem_obj != NULL); |
aa1a691e | 43 | const int64_t objsize = e->mem_obj->expectedReplySize(); |
a8a0b1c2 EC |
44 | |
45 | // e->mem_obj->request may be nil in this context | |
851feda6 | 46 | SBuf url; |
a8a0b1c2 EC |
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 | ||
c3031d67 | 54 | tlv *t = StoreMeta::Factory (STORE_META_KEY,SQUID_MD5_DIGEST_LENGTH, e->key); |
62e76326 | 55 | |
528b2c61 | 56 | if (!t) { |
62e76326 | 57 | storeSwapTLVFree(TLV); |
58 | return NULL; | |
528b2c61 | 59 | } |
62e76326 | 60 | |
528b2c61 | 61 | T = StoreMeta::Add(T, t); |
47f6e231 | 62 | t = StoreMeta::Factory(STORE_META_STD_LFS,STORE_HDR_METASIZE,&e->timestamp); |
62e76326 | 63 | |
528b2c61 | 64 | if (!t) { |
62e76326 | 65 | storeSwapTLVFree(TLV); |
66 | return NULL; | |
528b2c61 | 67 | } |
62e76326 | 68 | |
851feda6 | 69 | // XXX: do TLV without the c_str() termination. check readers first though |
528b2c61 | 70 | T = StoreMeta::Add(T, t); |
851feda6 | 71 | t = StoreMeta::Factory(STORE_META_URL, url.length()+1, url.c_str()); |
62e76326 | 72 | |
528b2c61 | 73 | if (!t) { |
62e76326 | 74 | storeSwapTLVFree(TLV); |
75 | return NULL; | |
528b2c61 | 76 | } |
62e76326 | 77 | |
ffcd6c5f | 78 | if (objsize >= 0) { |
15f1c218 A |
79 | T = StoreMeta::Add(T, t); |
80 | t = StoreMeta::Factory(STORE_META_OBJSIZE, sizeof(objsize), &objsize); | |
ffcd6c5f | 81 | |
15f1c218 A |
82 | if (!t) { |
83 | storeSwapTLVFree(TLV); | |
84 | return NULL; | |
85 | } | |
ffcd6c5f HN |
86 | } |
87 | ||
528b2c61 | 88 | T = StoreMeta::Add(T, t); |
90ab8f20 | 89 | SBuf vary(e->mem_obj->vary_headers); |
62e76326 | 90 | |
90ab8f20 | 91 | if (!vary.isEmpty()) { |
c9974e82 | 92 | t = StoreMeta::Factory(STORE_META_VARY_HEADERS, vary.length(), vary.c_str()); |
62e76326 | 93 | |
94 | if (!t) { | |
95 | storeSwapTLVFree(TLV); | |
96 | return NULL; | |
97 | } | |
98 | ||
99 | StoreMeta::Add (T, t); | |
528b2c61 | 100 | } |
62e76326 | 101 | |
69c01cd7 | 102 | return TLV; |
f09f5b26 | 103 | } |
104 | ||
69c01cd7 | 105 | char * |
106 | storeSwapMetaPack(tlv * tlv_list, int *length) | |
f09f5b26 | 107 | { |
e3ef2b09 | 108 | int buflen = 0; |
69c01cd7 | 109 | tlv *t; |
57d55dfa | 110 | int j = 0; |
69c01cd7 | 111 | char *buf; |
112 | assert(length != NULL); | |
f53969cc SM |
113 | ++buflen; /* STORE_META_OK */ |
114 | buflen += sizeof(int); /* size of header to follow */ | |
62e76326 | 115 | |
69c01cd7 | 116 | for (t = tlv_list; t; t = t->next) |
62e76326 | 117 | buflen += sizeof(char) + sizeof(int) + t->length; |
118 | ||
e6ccf245 | 119 | buf = (char *)xmalloc(buflen); |
62e76326 | 120 | |
5db6bf73 FC |
121 | buf[j] = (char) STORE_META_OK; |
122 | ++j; | |
62e76326 | 123 | |
41d00cd3 | 124 | memcpy(&buf[j], &buflen, sizeof(int)); |
62e76326 | 125 | |
e3ef2b09 | 126 | j += sizeof(int); |
62e76326 | 127 | |
69c01cd7 | 128 | for (t = tlv_list; t; t = t->next) { |
5db6bf73 FC |
129 | buf[j] = t->getType(); |
130 | ++j; | |
41d00cd3 | 131 | memcpy(&buf[j], &t->length, sizeof(int)); |
62e76326 | 132 | j += sizeof(int); |
41d00cd3 | 133 | memcpy(&buf[j], t->value, t->length); |
62e76326 | 134 | j += t->length; |
f09f5b26 | 135 | } |
62e76326 | 136 | |
e3ef2b09 | 137 | assert((int) j == buflen); |
138 | *length = buflen; | |
69c01cd7 | 139 | return buf; |
f09f5b26 | 140 | } |
f53969cc | 141 |