]>
Commit | Line | Data |
---|---|---|
9cef6668 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 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; |
42 | const char *url; | |
f66a9ef4 | 43 | const char *vary; |
10602161 | 44 | assert(e->mem_obj != NULL); |
aa1a691e | 45 | const int64_t objsize = e->mem_obj->expectedReplySize(); |
69c01cd7 | 46 | assert(e->swap_status == SWAPOUT_WRITING); |
a8a0b1c2 EC |
47 | |
48 | // e->mem_obj->request may be nil in this context | |
49 | if (e->mem_obj->request) | |
50 | url = e->mem_obj->request->storeId(); | |
51 | else | |
52 | url = e->url(); | |
53 | ||
54 | debugs(20, 3, "storeSwapMetaBuild URL: " << url); | |
55 | ||
c3031d67 | 56 | tlv *t = StoreMeta::Factory (STORE_META_KEY,SQUID_MD5_DIGEST_LENGTH, e->key); |
62e76326 | 57 | |
528b2c61 | 58 | if (!t) { |
62e76326 | 59 | storeSwapTLVFree(TLV); |
60 | return NULL; | |
528b2c61 | 61 | } |
62e76326 | 62 | |
528b2c61 | 63 | T = StoreMeta::Add(T, t); |
47f6e231 | 64 | t = StoreMeta::Factory(STORE_META_STD_LFS,STORE_HDR_METASIZE,&e->timestamp); |
62e76326 | 65 | |
528b2c61 | 66 | if (!t) { |
62e76326 | 67 | storeSwapTLVFree(TLV); |
68 | return NULL; | |
528b2c61 | 69 | } |
62e76326 | 70 | |
528b2c61 | 71 | T = StoreMeta::Add(T, t); |
72 | t = StoreMeta::Factory(STORE_META_URL, strlen(url) + 1, url); | |
62e76326 | 73 | |
528b2c61 | 74 | if (!t) { |
62e76326 | 75 | storeSwapTLVFree(TLV); |
76 | return NULL; | |
528b2c61 | 77 | } |
62e76326 | 78 | |
ffcd6c5f | 79 | if (objsize >= 0) { |
15f1c218 A |
80 | T = StoreMeta::Add(T, t); |
81 | t = StoreMeta::Factory(STORE_META_OBJSIZE, sizeof(objsize), &objsize); | |
ffcd6c5f | 82 | |
15f1c218 A |
83 | if (!t) { |
84 | storeSwapTLVFree(TLV); | |
85 | return NULL; | |
86 | } | |
ffcd6c5f HN |
87 | } |
88 | ||
528b2c61 | 89 | T = StoreMeta::Add(T, t); |
f66a9ef4 | 90 | vary = e->mem_obj->vary_headers; |
62e76326 | 91 | |
528b2c61 | 92 | if (vary) { |
62e76326 | 93 | t =StoreMeta::Factory(STORE_META_VARY_HEADERS, strlen(vary) + 1, vary); |
94 | ||
95 | if (!t) { | |
96 | storeSwapTLVFree(TLV); | |
97 | return NULL; | |
98 | } | |
99 | ||
100 | StoreMeta::Add (T, t); | |
528b2c61 | 101 | } |
62e76326 | 102 | |
69c01cd7 | 103 | return TLV; |
f09f5b26 | 104 | } |
105 | ||
69c01cd7 | 106 | char * |
107 | storeSwapMetaPack(tlv * tlv_list, int *length) | |
f09f5b26 | 108 | { |
e3ef2b09 | 109 | int buflen = 0; |
69c01cd7 | 110 | tlv *t; |
57d55dfa | 111 | int j = 0; |
69c01cd7 | 112 | char *buf; |
113 | assert(length != NULL); | |
f53969cc SM |
114 | ++buflen; /* STORE_META_OK */ |
115 | buflen += sizeof(int); /* size of header to follow */ | |
62e76326 | 116 | |
69c01cd7 | 117 | for (t = tlv_list; t; t = t->next) |
62e76326 | 118 | buflen += sizeof(char) + sizeof(int) + t->length; |
119 | ||
e6ccf245 | 120 | buf = (char *)xmalloc(buflen); |
62e76326 | 121 | |
5db6bf73 FC |
122 | buf[j] = (char) STORE_META_OK; |
123 | ++j; | |
62e76326 | 124 | |
41d00cd3 | 125 | memcpy(&buf[j], &buflen, sizeof(int)); |
62e76326 | 126 | |
e3ef2b09 | 127 | j += sizeof(int); |
62e76326 | 128 | |
69c01cd7 | 129 | for (t = tlv_list; t; t = t->next) { |
5db6bf73 FC |
130 | buf[j] = t->getType(); |
131 | ++j; | |
41d00cd3 | 132 | memcpy(&buf[j], &t->length, sizeof(int)); |
62e76326 | 133 | j += sizeof(int); |
41d00cd3 | 134 | memcpy(&buf[j], t->value, t->length); |
62e76326 | 135 | j += t->length; |
f09f5b26 | 136 | } |
62e76326 | 137 | |
e3ef2b09 | 138 | assert((int) j == buflen); |
139 | *length = buflen; | |
69c01cd7 | 140 | return buf; |
f09f5b26 | 141 | } |
f53969cc | 142 |