]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_swapmeta.cc
4360c02bc0ec98a76c412139feec758ed26756e0
2 * Copyright (C) 1996-2015 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 */
43 assert(e
->mem_obj
!= NULL
);
44 const int64_t objsize
= e
->mem_obj
->expectedReplySize();
45 assert(e
->swap_status
== SWAPOUT_WRITING
);
47 // e->mem_obj->request may be nil in this context
49 if (e
->mem_obj
->request
)
50 url
= e
->mem_obj
->request
->storeId();
54 debugs(20, 3, "storeSwapMetaBuild URL: " << url
);
56 tlv
*t
= StoreMeta::Factory (STORE_META_KEY
,SQUID_MD5_DIGEST_LENGTH
, e
->key
);
59 storeSwapTLVFree(TLV
);
63 T
= StoreMeta::Add(T
, t
);
64 t
= StoreMeta::Factory(STORE_META_STD_LFS
,STORE_HDR_METASIZE
,&e
->timestamp
);
67 storeSwapTLVFree(TLV
);
71 // XXX: do TLV without the c_str() termination. check readers first though
72 T
= StoreMeta::Add(T
, t
);
73 t
= StoreMeta::Factory(STORE_META_URL
, url
.length()+1, url
.c_str());
76 storeSwapTLVFree(TLV
);
81 T
= StoreMeta::Add(T
, t
);
82 t
= StoreMeta::Factory(STORE_META_OBJSIZE
, sizeof(objsize
), &objsize
);
85 storeSwapTLVFree(TLV
);
90 T
= StoreMeta::Add(T
, t
);
91 vary
= e
->mem_obj
->vary_headers
;
94 t
=StoreMeta::Factory(STORE_META_VARY_HEADERS
, strlen(vary
) + 1, vary
);
97 storeSwapTLVFree(TLV
);
101 StoreMeta::Add (T
, t
);
108 storeSwapMetaPack(tlv
* tlv_list
, int *length
)
114 assert(length
!= NULL
);
115 ++buflen
; /* STORE_META_OK */
116 buflen
+= sizeof(int); /* size of header to follow */
118 for (t
= tlv_list
; t
; t
= t
->next
)
119 buflen
+= sizeof(char) + sizeof(int) + t
->length
;
121 buf
= (char *)xmalloc(buflen
);
123 buf
[j
] = (char) STORE_META_OK
;
126 memcpy(&buf
[j
], &buflen
, sizeof(int));
130 for (t
= tlv_list
; t
; t
= t
->next
) {
131 buf
[j
] = t
->getType();
133 memcpy(&buf
[j
], &t
->length
, sizeof(int));
135 memcpy(&buf
[j
], t
->value
, t
->length
);
139 assert((int) j
== buflen
);