]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_swapmeta.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 20 Storage Manager Swapfile Metadata */
13 #include "MemObject.h"
15 #include "StoreMeta.h"
16 #include "StoreMetaUnpacker.h"
23 storeSwapTLVFree(tlv
* n
)
27 while ((t
= n
) != NULL
) {
35 * Build a TLV list for a StoreEntry
38 storeSwapMetaBuild(StoreEntry
* e
)
40 tlv
*TLV
= NULL
; /* we'll return this */
42 assert(e
->mem_obj
!= NULL
);
43 const int64_t objsize
= e
->mem_obj
->expectedReplySize();
45 // e->mem_obj->request may be nil in this context
47 if (e
->mem_obj
->request
)
48 url
= e
->mem_obj
->request
->storeId();
52 debugs(20, 3, "storeSwapMetaBuild URL: " << url
);
54 tlv
*t
= StoreMeta::Factory (STORE_META_KEY
,SQUID_MD5_DIGEST_LENGTH
, e
->key
);
57 storeSwapTLVFree(TLV
);
61 T
= StoreMeta::Add(T
, t
);
62 t
= StoreMeta::Factory(STORE_META_STD_LFS
,STORE_HDR_METASIZE
,&e
->timestamp
);
65 storeSwapTLVFree(TLV
);
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());
74 storeSwapTLVFree(TLV
);
79 T
= StoreMeta::Add(T
, t
);
80 t
= StoreMeta::Factory(STORE_META_OBJSIZE
, sizeof(objsize
), &objsize
);
83 storeSwapTLVFree(TLV
);
88 T
= StoreMeta::Add(T
, t
);
89 SBuf
vary(e
->mem_obj
->vary_headers
);
91 if (!vary
.isEmpty()) {
92 t
= StoreMeta::Factory(STORE_META_VARY_HEADERS
, vary
.length(), vary
.c_str());
95 storeSwapTLVFree(TLV
);
99 StoreMeta::Add (T
, t
);
106 storeSwapMetaPack(tlv
* tlv_list
, int *length
)
112 assert(length
!= NULL
);
113 ++buflen
; /* STORE_META_OK */
114 buflen
+= sizeof(int); /* size of header to follow */
116 for (t
= tlv_list
; t
; t
= t
->next
)
117 buflen
+= sizeof(char) + sizeof(int) + t
->length
;
119 buf
= (char *)xmalloc(buflen
);
121 buf
[j
] = (char) STORE_META_OK
;
124 memcpy(&buf
[j
], &buflen
, sizeof(int));
128 for (t
= tlv_list
; t
; t
= t
->next
) {
129 buf
[j
] = t
->getType();
131 memcpy(&buf
[j
], &t
->length
, sizeof(int));
133 memcpy(&buf
[j
], t
->value
, t
->length
);
137 assert((int) j
== buflen
);