void
HttpHeader::putCc(const HttpHdrCc * cc)
{
- MemBuf mb;
- Packer p;
assert(cc);
/* remove old directives if any */
delById(HDR_CACHE_CONTROL);
/* pack into mb */
+ MemBuf mb;
mb.init();
- packerToMemInit(&p, &mb);
- cc->packInto(&p);
+ cc->packInto(&mb);
/* put */
addEntry(new HttpHeaderEntry(HDR_CACHE_CONTROL, NULL, mb.buf));
/* cleanup */
void
HttpHeader::putContRange(const HttpHdrContRange * cr)
{
- MemBuf mb;
- Packer p;
assert(cr);
/* remove old directives if any */
delById(HDR_CONTENT_RANGE);
/* pack into mb */
+ MemBuf mb;
mb.init();
- packerToMemInit(&p, &mb);
- httpHdrContRangePackInto(cr, &p);
+ httpHdrContRangePackInto(cr, &mb);
/* put */
addEntry(new HttpHeaderEntry(HDR_CONTENT_RANGE, NULL, mb.buf));
/* cleanup */
void
HttpHeader::putRange(const HttpHdrRange * range)
{
- MemBuf mb;
- Packer p;
assert(range);
/* remove old directives if any */
delById(HDR_RANGE);
/* pack into mb */
+ MemBuf mb;
mb.init();
- packerToMemInit(&p, &mb);
- range->packInto(&p);
+ range->packInto(&mb);
/* put */
addEntry(new HttpHeaderEntry(HDR_RANGE, NULL, mb.buf));
/* cleanup */
void
HttpHeader::putSc(HttpHdrSc *sc)
{
- MemBuf mb;
- Packer p;
assert(sc);
/* remove old directives if any */
delById(HDR_SURROGATE_CONTROL);
/* pack into mb */
+ MemBuf mb;
mb.init();
- packerToMemInit(&p, &mb);
- sc->packInto(&p);
+ sc->packInto(&mb);
/* put */
addEntry(new HttpHeaderEntry(HDR_SURROGATE_CONTROL, NULL, mb.buf));
/* cleanup */
*/
void HttpMsg::firstLineBuf(MemBuf& mb)
{
- Packer p;
- packerToMemInit(&p, &mb);
- packFirstLineInto(&p, true);
+ packFirstLineInto(&mb, true);
}
HttpReply::pack()
{
MemBuf *mb = new MemBuf;
- Packer p;
-
mb->init();
- packerToMemInit(&p, mb);
- packInto(&p);
+ packInto(mb);
return mb;
}
YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
+ tests/stub_cbdata.cc \
tests/stub_debug.cc \
tests/stub_HelperChildConfig.cc \
tools.h \
tests/stub_libmem.cc \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
+ tests/stub_cbdata.cc \
tests/stub_store.cc \
tests/stub_store_stats.cc \
tests/stub_tools.cc \
YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
+ tests/stub_cbdata.cc \
tests/stub_debug.cc \
tests/stub_HelperChildConfig.cc \
tools.h \
* calls memcpy, appends exactly size bytes,
* extends buffer or creates buffer if needed.
*/
-void MemBuf::append(const char *newContent, mb_size_t sz)
+void MemBuf::append(const char *newContent, int sz)
{
assert(sz >= 0);
assert(buf || (0==capacity && 0==size));
*space() = '\0';
}
-/* calls memBufVPrintf */
-void
-MemBuf::Printf(const char *fmt,...)
-{
- va_list args;
- va_start(args, fmt);
- vappendf(fmt, args);
- va_end(args);
-}
-
/**
* vappendf for other printf()'s to use; calls vsnprintf, extends buf if needed
*/
#ifndef SQUID_MEMBUF_H
#define SQUID_MEMBUF_H
+#include "base/Packable.h"
#include "cbdata.h"
-#include "Packer.h"
/**
- * Auto-growing memory-resident buffer with printf interface
+ * Auto-growing memory-resident buffer with Packable interface
* \deprecated Use SBuf instead.
*/
-class MemBuf
+class MemBuf : public Packable
{
CBDATA_CLASS(MemBuf);
capacity(0),
stolen(0)
{}
- ~MemBuf() {
+ virtual ~MemBuf() {
if (!stolen && buf)
clean();
}
void consume(mb_size_t sz); // removes sz bytes, moving content left
void consumeWhitespacePrefix(); ///< removes all prefix whitespace, moving content left
- void append(const char *c, mb_size_t sz); // grows if needed and possible
void appended(mb_size_t sz); // updates content size after external append
void truncate(mb_size_t sz); // removes sz last bytes
/** unfirtunate hack to test if the buffer has been Init()ialized */
int isNull();
- /**
- * calls snprintf, extends buffer if needed
- \note we use Printf instead of printf so the compiler won't
- * think we're calling the libc printf()
- */
- void Printf(const char *fmt,...) PRINTF_FORMAT_ARG2;
-
- /** vappendf for other printf()'s to use */
- void vappendf(const char *fmt, va_list ap);
-
/**
* freezes the object! and returns function to clear it up.
*
*/
FREE *freeFunc();
+ /* Packable API */
+ virtual void append(const char *c, int sz);
+ virtual void vappendf(const char *fmt, va_list ap);
+
private:
/**
* private copy constructor and assignment operator generates
/** returns free() function to be used, _freezes_ the object! */
void memBufReport(MemBuf * mb);
-/** pack content into a mem buf. */
-void packerToMemInit(Packer * p, MemBuf * mb);
#endif /* SQUID_MEMBUF_H */
/* DEBUG: section 60 Generic Data Packer */
#include "squid.h"
-#include "MemBuf.h"
+#include "Packer.h"
#include "Store.h"
/*
* warning (e.g., "warning: assignment from incompatible pointer type").
*/
-static void
-memBufAppend(MemBuf *mb, const char *buf, mb_size_t len)
-{
- mb->append(buf, len);
-}
-
-static void
-memBufVPrintf(MemBuf * mb, const char *fmt, va_list vargs)
-{
- mb->vappendf(fmt, vargs);
-}
-
static void
storeEntryAppend(StoreEntry *e, const char *buf, int len)
{
/* append()'s */
static void (*const store_append) (StoreEntry *, const char *, int) = &storeEntryAppend;
-static void (*const memBuf_append) (MemBuf *, const char *, mb_size_t) = &memBufAppend;
/* vprintf()'s */
static void (*const store_vprintf) (StoreEntry *, const char *, va_list ap) = &storeAppendVPrintf;
-static void (*const memBuf_vprintf) (MemBuf *, const char *, va_list ap) = &memBufVPrintf;
/* init/clean */
e->buffer();
}
-/* init with this to accumulate data in MemBuf */
-void
-packerToMemInit(Packer * p, MemBuf * mb)
-{
- assert(p && mb);
- p->append_ = (append_f) memBuf_append;
- p->packer_vprintf = (vprintf_f) memBuf_vprintf;
- p->real_handler = mb;
-}
-
Packer::~Packer()
{
if (append_ == (append_f) store_append && real_handler)
class Packer;
/* a common objPackInto interface; used by debugObj */
-typedef void (*ObjPackMethod) (void *obj, Packer * p);
+typedef void (*ObjPackMethod) (void *obj, Packable * p);
/* append/vprintf's for Packer */
typedef void (*append_f) (void *, const char *buf, int size);
{
MemBuf mb;
mb.init();
-
- Packer p;
- packerToMemInit(&p, &mb);
- theMessage.packInto(&p, true);
+ theMessage.packInto(&mb, true);
return Area::FromTempBuffer(mb.content(), mb.contentSize());
}
}
//don't set al.cache.objectSize because it hasn't exist yet
- Packer p;
MemBuf mb;
-
mb.init();
- packerToMemInit(&p, &mb);
-
- reply_->header.packInto(&p);
+ reply_->header.packInto(&mb);
al.headers.reply = xstrdup(mb.buf);
-
mb.clean();
}
prepareLogWithRequestDetails(adapted_request_, alep);
void Adaptation::Icap::ModXact::packHead(MemBuf &httpBuf, const HttpMsg *head)
{
- Packer p;
- packerToMemInit(&p, &httpBuf);
- head->packInto(&p, true);
+ head->packInto(&httpBuf, true);
}
// decides whether to offer a preview and calculates its size
if (Config.onoff.log_mime_hdrs) {
MemBuf mb;
mb.init();
- Packer pa;
- packerToMemInit(&pa, &mb);
- request->header.packInto(&pa);
+ request->header.packInto(&mb);
//This is the request after adaptation or redirection
aLogEntry->headers.adapted_request = xstrdup(mb.buf);
// the virgin request is saved to aLogEntry->request
if (aLogEntry->request) {
- Packer p;
mb.reset();
- packerToMemInit(&p, &mb);
- aLogEntry->request->header.packInto(&p);
+ aLogEntry->request->header.packInto(&mb);
aLogEntry->headers.request = xstrdup(mb.buf);
}
#if USE_ADAPTATION
const Adaptation::History::Pointer ah = request->adaptLogHistory();
if (ah != NULL) {
- Packer p;
mb.reset();
- packerToMemInit(&p, &mb);
- ah->lastMeta.packInto(&p);
+ ah->lastMeta.packInto(&mb);
aLogEntry->adapt.last_meta = xstrdup(mb.buf);
}
#endif
clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String boundary, MemBuf * mb)
{
HttpHeader hdr(hoReply);
- Packer p;
assert(rep);
assert(spec);
httpHeaderAddContRange(&hdr, *spec, rep->content_length);
- packerToMemInit(&p, mb);
-
- hdr.packInto(&p);
-
+ hdr.packInto(mb);
hdr.clean();
/* append <crlf> (we packed a header, not a reply) */
- mb->Printf("\r\n");
+ mb->append("\r\n", 2);
}
/**
str.Printf("HTTP Request:\r\n");
if (NULL != request) {
- Packer pck;
String urlpath_or_slash;
if (request->urlpath.size() != 0)
SQUIDSTRINGPRINT(urlpath_or_slash),
AnyP::ProtocolType_str[request->http_ver.protocol],
request->http_ver.major, request->http_ver.minor);
- packerToMemInit(&pck, &str);
- request->header.packInto(&pck);
+ request->header.packInto(&str);
}
str.Printf("\r\n");
break;
}
if (NULL != request) {
- Packer pck;
String urlpath_or_slash;
if (request->urlpath.size() != 0)
SQUIDSTRINGPRINT(urlpath_or_slash),
AnyP::ProtocolType_str[request->http_ver.protocol],
request->http_ver.major, request->http_ver.minor);
- packerToMemInit(&pck, &mb);
- request->header.packInto(&pck, true); //hide authorization data
+ request->header.packInto(&mb, true); //hide authorization data
} else if (request_hdrs) {
p = request_hdrs;
} else {
debugs(31, 3, "htcpTstReply: response = " << stuff.response);
if (spec) {
- MemBuf mb;
- mb.init();
- Packer p;
- packerToMemInit(&p, &mb);
stuff.S.method = spec->method;
stuff.S.uri = spec->uri;
stuff.S.version = spec->version;
hdr.putInt(HDR_AGE, (e->timestamp <= squid_curtime ? (squid_curtime - e->timestamp) : 0) );
else
hdr.putInt(HDR_AGE, 0);
- hdr.packInto(&p);
+ MemBuf mb;
+ mb.init();
+ hdr.packInto(&mb);
stuff.D.resp_hdrs = xstrdup(mb.buf);
stuff.D.respHdrsSz = mb.contentSize();
debugs(31, 3, "htcpTstReply: resp_hdrs = {" << stuff.D.resp_hdrs << "}");
if (e && e->lastmod > -1)
hdr.putTime(HDR_LAST_MODIFIED, e->lastmod);
- hdr.packInto(&p);
+ hdr.packInto(&mb);
stuff.D.entity_hdrs = xstrdup(mb.buf);
stuff.D.entityHdrsSz = mb.contentSize();
}
#endif /* USE_ICMP */
- hdr.packInto(&p);
+ hdr.packInto(&mb);
stuff.D.cache_hdrs = xstrdup(mb.buf);
stuff.D.cacheHdrsSz = mb.contentSize();
debugs(31, 3, "htcpTstReply: cache_hdrs = {" << stuff.D.cache_hdrs << "}");
HttpStateData::httpBuildRequestHeader(req, e, NULL, &hdr, flags);
MemBuf mb;
mb.init();
- Packer pa;
- packerToMemInit(&pa, &mb);
- hdr.packInto(&pa);
+ hdr.packInto(&mb);
hdr.clean();
stuff.S.req_hdrs = mb.buf;
pktlen = htcpBuildPacket(pkt, sizeof(pkt), &stuff);
if (reason != HTCP_CLR_INVALIDATION) {
HttpStateData::httpBuildRequestHeader(req, e, NULL, &hdr, flags);
mb.init();
- Packer pa;
- packerToMemInit(&pa, &mb);
- hdr.packInto(&pa);
+ hdr.packInto(&mb);
hdr.clean();
stuff.S.req_hdrs = mb.buf;
} else {
/* build and pack headers */
{
HttpHeader hdr(hoRequest);
- Packer p;
httpBuildRequestHeader(request, entry, fwd->al, &hdr, flags);
if (request->flags.pinned && request->flags.connectionAuth)
else if (hdr.has(HDR_AUTHORIZATION))
request->flags.authSent = true;
- packerToMemInit(&p, mb);
- hdr.packInto(&p);
+ hdr.packInto(mb);
hdr.clean();
}
/* append header terminator */
if (do_debug(9, 2)) {
MemBuf mb;
- Packer p;
mb.init();
- packerToMemInit(&p, &mb);
- request->pack(&p);
+ request->pack(&mb);
debugs(9, 2, "FTP Client " << clientConnection);
debugs(9, 2, "FTP Client REQUEST:\n---------\n" << mb.buf <<
mb_size_t MemBuf::spaceSize() const STUB_RETVAL(0)
mb_size_t MemBuf::potentialSpaceSize() const STUB_RETVAL(0)
void MemBuf::consume(mb_size_t sz) STUB
-void MemBuf::append(const char *c, mb_size_t sz) STUB
void MemBuf::appended(mb_size_t sz) STUB
void MemBuf::truncate(mb_size_t sz) STUB
void MemBuf::terminate() STUB
void MemBuf::clean() STUB
void MemBuf::reset() STUB
int MemBuf::isNull() STUB_RETVAL(1)
-void MemBuf::Printf(const char *fmt,...) STUB
-void MemBuf::vappendf(const char *fmt, va_list ap) STUB
FREE *MemBuf::freeFunc() STUB_RETVAL(NULL)
+void MemBuf::append(const char *, int) STUB
+void MemBuf::vappendf(const char *fmt, va_list ap) STUB
void memBufReport(MemBuf * mb) STUB
-void packerToMemInit(Packer * p, MemBuf * mb) STUB
#include "HttpHeader.h"
#include "HttpReply.h"
#include "MemObject.h"
+#include "Packer.h"
#include "RequestFlags.h"
#include "SquidConfig.h"
#include "Store.h"
#include "HttpHeader.h"
#include "HttpReply.h"
#include "MemObject.h"
+#include "Packer.h"
#include "RequestFlags.h"
#include "SquidConfig.h"
#include "Store.h"
void
debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm)
{
- MemBuf mb;
- Packer p;
assert(label && obj && pm);
+ MemBuf mb;
mb.init();
- packerToMemInit(&p, &mb);
- (*pm) (obj, &p);
+ (*pm) (obj, &mb);
debugs(section, level, "" << label << "" << mb.buf << "");
mb.clean();
}
TunnelStateData *tunnelState = (TunnelStateData *)data;
assert(!tunnelState->waitingForConnectExchange());
HttpHeader hdr_out(hoRequest);
- Packer p;
HttpStateFlags flags;
debugs(26, 3, HERE << srv << ", tunnelState=" << tunnelState);
memset(&flags, '\0', sizeof(flags));
tunnelState->al, /* AccessLogEntry */
&hdr_out,
flags); /* flags */
- packerToMemInit(&p, &mb);
- hdr_out.packInto(&p);
+ hdr_out.packInto(&mb);
hdr_out.clean();
mb.append("\r\n", 2);