/*
- * $Id: HttpBody.cc,v 1.20 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpBody.cc,v 1.21 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 56 HTTP Message Body
* AUTHOR: Alex Rousskov
void
httpBodyInit(HttpBody * body)
{
- body->mb = MemBufNull;
+ body->mb = new MemBuf;
}
void
{
assert(body);
- if (!memBufIsNull(&body->mb))
- memBufClean(&body->mb);
+ if (!memBufIsNull(body->mb))
+ memBufClean(body->mb);
}
/* set body by absorbing mb */
httpBodySet(HttpBody * body, MemBuf * mb)
{
assert(body);
- assert(memBufIsNull(&body->mb));
- body->mb = *mb; /* absorb */
+ assert(memBufIsNull(body->mb));
+ body->mb = mb; /* absorb */
}
void
{
assert(body && p);
- if (body->mb.size)
- packerAppend(p, body->mb.buf, body->mb.size);
+ if (body->mb->contentSize())
+ packerAppend(p, body->mb->content(), body->mb->contentSize());
}
#if UNUSED_CODE
const char *
httpBodyPtr(const HttpBody * body)
{
- return body->mb.buf ? body->mb.buf : "";
+ return body->mb->content() ? body->mb->content() : "";
}
#endif
/*
- * $Id: HttpReply.cc,v 1.71 2005/05/01 08:11:47 serassio Exp $
+ * $Id: HttpReply.cc,v 1.72 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
* becuase somebody may feed a non NULL-terminated buffer to
* us.
*/
- MemBuf mb = MemBufNull;
+ MemBuf mb;
int success;
/* reset current state, because we are not used in incremental fashion */
httpReplyReset(rep);
}
/* create memBuf, create mem-based packer, pack, destroy packer, return MemBuf */
-MemBuf
+MemBuf *
httpReplyPack(const HttpReply * rep)
{
- MemBuf mb;
+ MemBuf *mb = new MemBuf;
Packer p;
assert(rep);
- memBufDefInit(&mb);
- packerToMemInit(&p, &mb);
+ memBufDefInit(mb);
+ packerToMemInit(&p, mb);
httpReplyPackInto(rep, &p);
packerClean(&p);
return mb;
storeEntryReplaceObject(e, rep);
}
-MemBuf
+MemBuf *
httpPackedReply(HttpVersion ver, http_status status, const char *ctype,
int clen, time_t lmt, time_t expires)
{
HttpReply *rep = httpReplyCreate();
- MemBuf mb;
httpReplySetHeaders(rep, ver, status, ctype, NULL, clen, lmt, expires);
- mb = httpReplyPack(rep);
+ MemBuf *mb = httpReplyPack(rep);
httpReplyDestroy(rep);
return mb;
}
return rv;
}
-MemBuf
+MemBuf *
httpPacked304Reply(const HttpReply * rep)
{
/* Not as efficient as skipping the header duplication,
* but easier to maintain
*/
HttpReply *temp;
- MemBuf rv;
assert (rep);
temp = httpReplyMake304 (rep);
- rv = httpReplyPack(temp);
+ MemBuf *rv = httpReplyPack(temp);
httpReplyDestroy (temp);
return rv;
}
/*
- * $Id: HttpReply.h,v 1.7 2004/08/30 05:12:31 robertc Exp $
+ * $Id: HttpReply.h,v 1.8 2005/08/31 19:15:35 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
extern void httpReplyPackInto(const HttpReply * rep, Packer * p);
/* ez-routines */
/* mem-pack: returns a ready to use mem buffer with a packed reply */
-extern MemBuf httpReplyPack(const HttpReply * rep);
+extern MemBuf *httpReplyPack(const HttpReply * rep);
/* swap: create swap-based packer, pack, destroy packer */
extern void httpReplySwapOut(HttpReply * rep, StoreEntry * e);
/* set commonly used info with one call */
extern void httpReplySetHeaders(HttpReply * rep, HttpVersion ver, http_status status,
const char *reason, const char *ctype, int clen, time_t lmt, time_t expires);
/* do everything in one call: init, set, pack, clean, return MemBuf */
-extern MemBuf httpPackedReply(HttpVersion ver, http_status status, const char *ctype,
- int clen, time_t lmt, time_t expires);
+extern MemBuf *httpPackedReply(HttpVersion ver, http_status status, const char *ctype,
+ int clen, time_t lmt, time_t expires);
/* construct 304 reply and pack it into MemBuf, return MemBuf */
-extern MemBuf httpPacked304Reply(const HttpReply * rep);
+extern MemBuf *httpPacked304Reply(const HttpReply * rep);
/* construct a 304 reply and return it */
extern HttpReply *httpReplyMake304(const HttpReply *rep);
/* update when 304 reply is received for a cached object */
/*
- * $Id: MemBuf.cc,v 1.37 2004/12/21 17:52:53 robertc Exp $
+ * $Id: MemBuf.cc,v 1.38 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 59 auto-growing Memory Buffer with printf
* AUTHOR: Alex Rousskov
memBufClean(MemBuf * mb)
{
assert(mb);
- assert(mb->buf);
- assert(!mb->stolen); /* not frozen */
- memFreeBuf(mb->capacity, mb->buf);
- mb->buf = NULL;
- mb->size = mb->capacity = mb->max_capacity = 0;
+ if (memBufIsNull(mb)) {
+ // nothing to do
+ } else {
+ assert(mb->buf);
+ assert(!mb->stolen); /* not frozen */
+
+ memFreeBuf(mb->capacity, mb->buf);
+ mb->buf = NULL;
+ mb->size = mb->capacity = mb->max_capacity = 0;
+ }
}
/* cleans the buffer without changing its capacity
return 0;
}
+mb_size_t MemBuf::spaceSize() const
+{
+ const mb_size_t terminatedSize = size + 1;
+ return (terminatedSize < capacity) ? capacity - terminatedSize : 0;
+}
-/* calls memcpy, appends exactly size bytes, extends buffer if needed */
-void
-memBufAppend(MemBuf * mb, const char *buf, mb_size_t sz)
+mb_size_t MemBuf::potentialSpaceSize() const
{
- assert(mb && buf && sz >= 0);
- assert(mb->buf);
- assert(!mb->stolen); /* not frozen */
+ const mb_size_t terminatedSize = size + 1;
+ return (terminatedSize < max_capacity) ? max_capacity - terminatedSize : 0;
+}
- if (sz > 0) {
- if (mb->size + sz + 1 > mb->capacity)
- memBufGrow(mb, mb->size + sz + 1);
+// removes sz bytes and "packs" by moving content left
+void MemBuf::consume(mb_size_t shiftSize)
+{
+ const mb_size_t cSize = contentSize();
+ assert(0 <= shiftSize && shiftSize <= cSize);
+ assert(!stolen); /* not frozen */
- assert(mb->size + sz <= mb->capacity); /* paranoid */
+ if (shiftSize > 0) {
+ if (shiftSize < cSize)
+ xmemmove(buf, buf + shiftSize, cSize - shiftSize);
- xmemcpy(mb->buf + mb->size, buf, sz);
+ size -= shiftSize;
- mb->size += sz;
+ terminate();
+ }
+}
- mb->buf[mb->size] = '\0'; /* \0 terminate in case we are used as a string. Not counted in the size */
+// calls memcpy, appends exactly size bytes, extends buffer if needed
+void MemBuf::append(const char *newContent, mb_size_t sz)
+{
+ assert(sz >= 0);
+ assert(buf);
+ assert(!stolen); /* not frozen */
+
+ if (sz > 0) {
+ if (size + sz + 1 > capacity)
+ memBufGrow(this, size + sz + 1);
+
+ assert(size + sz <= capacity); /* paranoid */
+
+ xmemcpy(space(), newContent, sz);
+
+ appended(sz);
}
}
+// updates content size after external append
+void MemBuf::appended(mb_size_t sz)
+{
+ assert(size + sz <= capacity);
+ size += sz;
+ terminate();
+}
+
+// 0-terminate in case we are used as a string.
+// Extra octet is not counted in the content size (or space size)
+// XXX: but the extra octet is counted when growth decisions are made!
+// This will cause the buffer to grow when spaceSize() == 1 on append,
+// which will assert() if the buffer cannot grow any more.
+void MemBuf::terminate()
+{
+ assert(size < capacity);
+ *space() = '\0';
+}
+
+void
+memBufAppend(MemBuf * mb, const char *buf, mb_size_t sz)
+{
+ assert(mb);
+ mb->append(buf, sz);
+}
+
/* calls memBufVPrintf */
#if STDC_HEADERS
void
/*
- * $Id: MemBuf.cci,v 1.1 2003/01/23 00:37:14 robertc Exp $
+ * $Id: MemBuf.cci,v 1.2 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 59 auto-growing Memory Buffer with printf
* AUTHOR: Robert Collins
*/
MemBuf::MemBuf() : buf (NULL), size (0), max_capacity (0), capacity(0), stolen(0)
+{}
+
+MemBuf::~MemBuf()
{
+ if (!stolen)
+ assert(NULL == buf);
}
-
/*
- * $Id: MemBuf.h,v 1.2 2003/02/21 22:50:06 robertc Exp $
+ * $Id: MemBuf.h,v 1.3 2005/08/31 19:15:35 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
public:
_SQUID_INLINE_ MemBuf();
- /* public, read-only */
- char *buf;
- mb_size_t size; /* used space, does not count 0-terminator */
+ _SQUID_INLINE_ ~MemBuf();
+
+ /* use methods instead of deprecated buf and size members */
+
+ char *content() { return buf; } // start of the added data
+
+ mb_size_t contentSize() const { return size; } // available data size
+
+ bool hasContent() const { return size > 0; }
+
+ // these space-related methods assume no growth and allow 0-termination
+ char *space() { return buf + size; } // space to add data
+
+ mb_size_t spaceSize() const;
+ bool hasSpace() const { return size+1 < capacity; }
+
+ mb_size_t potentialSpaceSize() const; // accounts for possible growth
+ bool hasPotentialSpace() const { return potentialSpaceSize() > 0; }
+
+ // there is currently no stretch() method to grow without appending
+
+ void consume(mb_size_t sz); // removes sz bytes, 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
+
+ // XXX: convert global memBuf*() functions into methods
+
+ void terminate(); // zero-terminates the buffer w/o increasing contentSize
+
+private:
+ /*
+ * private copy constructor and assignment operator generates
+ * compiler errors if someone tries to copy/assign a MemBuf
+ */
+ MemBuf(const MemBuf& m) {assert(false);};
+
+ MemBuf& operator= (const MemBuf& m) {assert(false); return *this;};
+
+public:
+ /* public, read-only, depricated in favor of space*() and content*() */
+ // XXX: hide these members completely and remove 0-termination
+ // so that consume() does not need to memmove all the time
+ char *buf; // available content
+ mb_size_t size; // used space, does not count 0-terminator
/* private, stay away; use interface function instead */
+ // XXX: make these private after converting memBuf*() functions to methods
mb_size_t max_capacity; /* when grows: assert(new_capacity <= max_capacity) */
mb_size_t capacity; /* allocated space */
1; /* the buffer has been stolen for use by someone else */
};
-/* to initialize static variables (see also MemBufNull) */
-#define MemBufNULL MemBuf();
-
#ifdef _USE_INLINE_
#include "MemBuf.cci"
#endif
/* puts report on MemBuf _module_ usage into mb */
SQUIDCEXTERN void memBufReport(MemBuf * mb);
-#define MemBufNull MemBuf();
-
#endif /* SQUID_MEM_H */
/*
- * $Id: access_log.cc,v 1.101 2004/12/26 11:31:11 serassio Exp $
+ * $Id: access_log.cc,v 1.102 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 46 Access Log
* AUTHOR: Duane Wessels
logformat *lf;
Logfile *logfile;
logformat_token *fmt;
- static MemBuf mb = MemBufNULL;
+ static MemBuf mb;
char tmp[1024];
String sb;
/*
- * $Id: client_side.cc,v 1.689 2005/08/31 17:21:58 wessels Exp $
+ * $Id: client_side.cc,v 1.690 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
memBufDefInit(&mb);
packRange(bodyData, &mb);
- if (mb.size)
+ if (mb.contentSize())
/* write */
- comm_old_write_mbuf(fd(), mb, clientWriteComplete, this);
+ comm_old_write_mbuf(fd(), &mb, clientWriteComplete, this);
else
writeComplete(fd(), NULL, 0, COMM_OK);
}
ClientSocketContext::sendStartOfMessage(HttpReply * rep, StoreIOBuffer bodyData)
{
prepareReply(rep);
- /* init mb; put status line and headers if any */
assert (rep);
- MemBuf mb = httpReplyPack(rep);
+ MemBuf *mb = httpReplyPack(rep);
/* Save length of headers for persistent conn checks */
- http->out.headers_sz = mb.size;
+ http->out.headers_sz = mb->contentSize();
#if HEADERS_LOG
headersLog(0, 0, http->request->method, rep);
size_t length = lengthToSend(bodyData.range());
noteSentBodyBytes (length);
- memBufAppend(&mb, bodyData.data, length);
+ memBufAppend(mb, bodyData.data, length);
} else {
- packRange(bodyData, &mb);
+ packRange(bodyData, mb);
}
}
/* write */
comm_old_write_mbuf(fd(), mb, clientWriteComplete, this);
- /* if we don't do it, who will? */
+ delete mb;
}
/*
/*
- * $Id: comm.cc,v 1.408 2005/08/27 18:40:20 serassio Exp $
+ * $Id: comm.cc,v 1.409 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
/* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */
void
-comm_old_write_mbuf(int fd, MemBuf mb, CWCB * handler, void *handler_data) {
- comm_old_write(fd, mb.buf, mb.size, handler, handler_data, memBufFreeFunc(&mb));
+comm_old_write_mbuf(int fd, MemBuf *mb, CWCB * handler, void *handler_data) {
+ comm_old_write(fd, mb->buf, mb->size, handler, handler_data, memBufFreeFunc(mb));
}
/*
- * $Id: dns_internal.cc,v 1.79 2005/08/28 08:55:21 serassio Exp $
+ * $Id: dns_internal.cc,v 1.80 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c
* AUTHOR: Duane Wessels
int fd;
unsigned short msglen;
int read_msglen;
- MemBuf msg;
- MemBuf queue;
+ MemBuf *msg;
+ MemBuf *queue;
bool busy;
};
if (vc->busy)
return;
- if (vc->queue.size == 0)
+ if (vc->queue->contentSize() == 0)
return;
- MemBuf mb = vc->queue;
+ MemBuf *mb = vc->queue;
- vc->queue = MemBufNULL;
+ vc->queue = new MemBuf;
vc->busy = 1;
commSetTimeout(vc->fd, Config.Timeout.idns_query, NULL, NULL);
comm_old_write_mbuf(vc->fd, mb, idnsSentQueryVC, vc);
+
+ delete mb;
}
static void
idnsVCClosed(int fd, void *data)
{
nsvc * vc = (nsvc *)data;
+ delete vc->queue;
+ delete vc->msg;
+ // XXX need to free and/or cbdataReferenceDone(vc) ?
nameservers[vc->ns].vc = NULL;
}
else
addr = Config.Addrs.udp_incoming;
- vc->queue = MemBufNULL;
+ vc->queue = new MemBuf;
- vc->msg = MemBufNULL;
+ vc->msg = new MemBuf;
vc->fd = comm_open(SOCK_STREAM,
IPPROTO_TCP,
nsvc *vc = nameservers[ns].vc;
- if (memBufIsNull(&vc->queue))
- memBufDefInit(&vc->queue);
+ memBufReset(vc->queue);
short head = htons(q->sz);
- memBufAppend(&vc->queue, (char *)&head, 2);
+ memBufAppend(vc->queue, (char *)&head, 2);
- memBufAppend(&vc->queue, q->buf, q->sz);
+ memBufAppend(vc->queue, q->buf, q->sz);
idnsDoSendQueryVC(vc);
}
return;
}
- vc->msg.size += len;
+ vc->msg->size += len; // XXX should not access -> size directly
- if (vc->msg.size < vc->msglen) {
- comm_read(fd, buf + len, vc->msglen - vc->msg.size, idnsReadVC, vc);
+ if (vc->msg->contentSize() < vc->msglen) {
+ comm_read(fd, buf + len, vc->msglen - vc->msg->contentSize(), idnsReadVC, vc);
return;
}
debug(78, 3) ("idnsReadVC: FD %d: received %d bytes via tcp from %s.\n",
fd,
- (int) vc->msg.size,
+ (int) vc->msg->contentSize(),
inet_ntoa(nameservers[vc->ns].S.sin_addr));
- idnsGrokReply(vc->msg.buf, vc->msg.size);
- memBufClean(&vc->msg);
+ idnsGrokReply(vc->msg->buf, vc->msg->contentSize());
+ memBufClean(vc->msg);
comm_read(fd, (char *)&vc->msglen, 2 , idnsReadVCHeader, vc);
}
vc->msglen = ntohs(vc->msglen);
- memBufInit(&vc->msg, vc->msglen, vc->msglen);
- comm_read(fd, vc->msg.buf, vc->msglen, idnsReadVC, vc);
+ memBufInit(vc->msg, vc->msglen, vc->msglen);
+ comm_read(fd, vc->msg->buf, vc->msglen, idnsReadVC, vc);
}
/*
/*
- * $Id: errorpage.cc,v 1.201 2005/05/01 08:11:48 serassio Exp $
+ * $Id: errorpage.cc,v 1.202 2005/08/31 19:15:35 wessels Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
static const char *errorFindHardText(err_type type);
static ErrorDynamicPageInfo *errorDynamicPageInfoCreate(int id, const char *page_name);
static void errorDynamicPageInfoDestroy(ErrorDynamicPageInfo * info);
-static MemBuf errorBuildContent(ErrorState * err);
+static MemBuf *errorBuildContent(ErrorState * err);
static int errorDump(ErrorState * err, MemBuf * mb);
static const char *errorConvert(char token, ErrorState * err);
static CWCB errorSendComplete;
errorDump(ErrorState * err, MemBuf * mb)
{
HttpRequest *r = err->request;
- MemBuf str = MemBufNULL;
+ MemBuf str;
const char *p = NULL; /* takes priority over mb if set */
memBufReset(&str);
/* email subject line */
errorConvert(char token, ErrorState * err)
{
HttpRequest *r = err->request;
- static MemBuf mb = MemBufNULL;
+ static MemBuf mb;
const char *p = NULL; /* takes priority over mb if set */
int do_quote = 1;
if (err->page_id != ERR_SQUID_SIGNATURE) {
const int saved_id = err->page_id;
- MemBuf sign_mb;
err->page_id = ERR_SQUID_SIGNATURE;
- sign_mb = errorBuildContent(err);
- memBufPrintf(&mb, "%s", sign_mb.buf);
- memBufClean(&sign_mb);
+ MemBuf *sign_mb = errorBuildContent(err);
+ memBufPrintf(&mb, "%s", sign_mb->content());
+ memBufClean(sign_mb);
+ delete sign_mb;
err->page_id = saved_id;
do_quote = 0;
} else {
httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%d %s\n", err->httpStatus, "Access Denied");
} else {
- MemBuf content = errorBuildContent(err);
- httpReplySetHeaders(rep, version, err->httpStatus, NULL, "text/html", content.size, 0, squid_curtime);
+ MemBuf *content = errorBuildContent(err);
+ httpReplySetHeaders(rep, version, err->httpStatus, NULL, "text/html", content->contentSize(), 0, squid_curtime);
/*
* include some information for downstream caches. Implicit
* replaceable content. This isn't quite sufficient. xerrno is not
*/
httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d",
name, err->xerrno);
- httpBodySet(&rep->body, &content);
- /* do not memBufClean() the content, it was absorbed by httpBody */
+ httpBodySet(&rep->body, content);
+ /* do not memBufClean() or delete the content, it was absorbed by httpBody */
}
return rep;
}
-static MemBuf
+static MemBuf *
errorBuildContent(ErrorState * err)
{
- MemBuf content;
+ MemBuf *content = new MemBuf;
const char *m;
const char *p;
const char *t;
assert(err != NULL);
assert(err->page_id > ERR_NONE && err->page_id < error_page_count);
- memBufDefInit(&content);
+ memBufDefInit(content);
m = error_text[err->page_id];
assert(m);
while ((p = strchr(m, '%'))) {
- memBufAppend(&content, m, p - m); /* copy */
+ memBufAppend(content, m, p - m); /* copy */
t = errorConvert(*++p, err); /* convert */
- memBufPrintf(&content, "%s", t); /* copy */
+ memBufPrintf(content, "%s", t); /* copy */
m = p + 1; /* advance */
}
if (*m)
- memBufPrintf(&content, "%s", m); /* copy tail */
+ memBufPrintf(content, "%s", m); /* copy tail */
- assert((size_t)content.size == strlen(content.buf));
+ assert((size_t)content->contentSize() == strlen(content->content()));
return content;
}
/*
- * $Id: external_acl.cc,v 1.63 2005/05/06 01:57:55 hno Exp $
+ * $Id: external_acl.cc,v 1.64 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 82 External ACL
* AUTHOR: Henrik Nordstrom, MARA Systems AB
static char *
makeExternalAclKey(ACLChecklist * ch, external_acl_data * acl_data)
{
- static MemBuf mb = MemBufNULL;
+ static MemBuf mb;
char buf[256];
int first = 1;
wordlist *arg;
/*
- * $Id: helper.cc,v 1.65 2005/01/27 19:57:09 serassio Exp $
+ * $Id: helper.cc,v 1.66 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 84 Helper process maintenance
* AUTHOR: Harvest Derived?
srv->rbuf = NULL;
}
- if (!memBufIsNull(&srv->wqueue))
- memBufClean(&srv->wqueue);
+ memBufClean(srv->wqueue);
+ delete srv->wqueue;
+
+ if (srv->writebuf) {
+ memBufClean(srv->writebuf);
+ delete srv->writebuf;
+ srv->writebuf = NULL;
+ }
for (i = 0; i < concurrency; i++) {
if ((r = srv->requests[i])) {
}
#if 0
- if (!memBufIsNull(&srv->wqueue))
- memBufClean(&srv->wqueue);
+ memBufClean(srv->wqueue);
+
+ delete srv->wqueue;
#endif
{
helper_server *srv = (helper_server *)data;
- memBufClean(&srv->writebuf);
+ memBufClean(srv->writebuf);
+ delete srv->writebuf;
+ srv->writebuf = NULL;
srv->flags.writing = 0;
if (flag != COMM_OK) {
return;
}
- if (!memBufIsNull(&srv->wqueue)) {
+ if (!memBufIsNull(srv->wqueue)) {
srv->writebuf = srv->wqueue;
- srv->wqueue = MemBufNull;
+ srv->wqueue = new MemBuf;
srv->flags.writing = 1;
comm_write(srv->wfd,
- srv->writebuf.buf,
- srv->writebuf.size,
+ srv->writebuf->content(),
+ srv->writebuf->contentSize(),
helperDispatchWriteDone, /* Handler */
srv); /* Handler-data */
}
srv->stats.pending += 1;
r->dispatch_time = current_time;
- if (memBufIsNull(&srv->wqueue))
- memBufDefInit(&srv->wqueue);
+ if (memBufIsNull(srv->wqueue))
+ memBufDefInit(srv->wqueue);
if (hlp->concurrency)
- memBufPrintf(&srv->wqueue, "%d %s", slot, r->buf);
+ memBufPrintf(srv->wqueue, "%d %s", slot, r->buf);
else
- memBufAppend(&srv->wqueue, r->buf, strlen(r->buf));
+ memBufAppend(srv->wqueue, r->buf, strlen(r->buf));
if (!srv->flags.writing) {
+ assert(NULL == srv->writebuf);
srv->writebuf = srv->wqueue;
- srv->wqueue = MemBufNull;
+ srv->wqueue = new MemBuf;
srv->flags.writing = 1;
comm_write(srv->wfd,
- srv->writebuf.buf,
- srv->writebuf.size,
+ srv->writebuf->content(),
+ srv->writebuf->contentSize(),
helperDispatchWriteDone, /* Handler */
srv); /* Handler-data */
}
/*
- * $Id: http.cc,v 1.454 2005/08/19 17:03:28 wessels Exp $
+ * $Id: http.cc,v 1.455 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
&mb,
httpState->flags);
debug(11, 6) ("httpSendRequest: FD %d:\n%s\n", fd, mb.buf);
- comm_old_write_mbuf(fd, mb, sendHeaderDone, httpState);
+ comm_old_write_mbuf(fd, &mb, sendHeaderDone, httpState);
}
void
/*
- * $Id: ident.cc,v 1.69 2003/03/04 01:40:28 robertc Exp $
+ * $Id: ident.cc,v 1.70 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 30 Ident (RFC 931)
* AUTHOR: Duane Wessels
{
IdentStateData *state = (IdentStateData *)data;
IdentClient *c;
- MemBuf mb;
if (status != COMM_OK) {
/* Failed to connect */
return;
}
+ MemBuf mb;
memBufDefInit(&mb);
memBufPrintf(&mb, "%d, %d\r\n",
ntohs(state->my_peer.sin_port),
ntohs(state->me.sin_port));
- comm_old_write_mbuf(fd, mb, NULL, state);
+ comm_old_write_mbuf(fd, &mb, NULL, state);
comm_read(fd, state->buf, BUFSIZ, identReadReply, state);
commSetTimeout(fd, Config.Timeout.ident, identTimeout, state);
}
/*
- * $Id: internal.cc,v 1.30 2003/09/01 03:49:39 robertc Exp $
+ * $Id: internal.cc,v 1.31 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 76 Internal Squid Object handling
* AUTHOR: Duane, Alex, Henrik
char *
internalRemoteUri(const char *host, u_short port, const char *dir, const char *name)
{
- static MemBuf mb = MemBufNULL;
static char lc_host[SQUIDHOSTNAMELEN];
assert(host && name);
/* convert host name to lower case */
strlen(lc_host) - 1);
/* build uri in mb */
+ static MemBuf mb;
+
memBufReset(&mb);
memBufPrintf(&mb, "http://%s", lc_host);
/*
- * $Id: mime.cc,v 1.116 2005/03/06 14:46:30 serassio Exp $
+ * $Id: mime.cc,v 1.117 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 25 MIME Parsing
* AUTHOR: Harvest Derived
const char *
mimeGetIconURL(const char *fn)
{
- static MemBuf mb = MemBufNULL;
char const *icon = mimeGetIcon(fn);
if (icon == NULL)
return null_string;
if (Config.icons.use_short_names) {
+ static MemBuf mb;
memBufReset(&mb);
memBufPrintf(&mb, "/squid-internal-static/icons/%s", icon);
- return mb.buf;
+ return mb.content();
} else {
return internalLocalUri("/squid-internal-static/icons/", icon);
}
/*
- * $Id: protos.h,v 1.507 2005/08/27 19:36:36 serassio Exp $
+ * $Id: protos.h,v 1.508 2005/08/31 19:15:36 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
CWCB * handler,
void *handler_data,
FREE *);
-SQUIDCEXTERN void comm_old_write_mbuf(int fd, MemBuf mb, CWCB * handler, void *handler_data);
+SQUIDCEXTERN void comm_old_write_mbuf(int fd, MemBuf *mb, CWCB * handler, void *handler_data);
SQUIDCEXTERN void commCallCloseHandlers(int fd);
SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *);
SQUIDCEXTERN int ignoreErrno(int);
/*
- * $Id: structs.h,v 1.523 2005/08/19 17:03:28 wessels Exp $
+ * $Id: structs.h,v 1.524 2005/08/31 19:15:36 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
struct _HttpBody
{
/* private */
- MemBuf mb;
+ MemBuf *mb;
};
#include "SquidString.h"
int pid;
int rfd;
int wfd;
- MemBuf wqueue;
- MemBuf writebuf;
+ MemBuf *wqueue;
+ MemBuf *writebuf;
char *rbuf;
size_t rbuf_sz;
off_t roffset;
/*
- * $Id: tunnel.cc,v 1.150 2005/06/09 16:04:30 serassio Exp $
+ * $Id: tunnel.cc,v 1.151 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
sslProxyConnected(int fd, void *data)
{
SslStateData *sslState = (SslStateData *)data;
- MemBuf mb;
HttpHeader hdr_out(hoRequest);
Packer p;
http_state_flags flags;
debug(26, 3) ("sslProxyConnected: FD %d sslState=%p\n", fd, sslState);
memset(&flags, '\0', sizeof(flags));
flags.proxying = sslState->request->flags.proxying;
+ MemBuf mb;
memBufDefInit(&mb);
memBufPrintf(&mb, "CONNECT %s HTTP/1.0\r\n", sslState->url);
httpBuildRequestHeader(sslState->request,
packerClean(&p);
memBufAppend(&mb, "\r\n", 2);
- comm_old_write_mbuf(sslState->server.fd(), mb, sslProxyConnectedWriteDone, sslState);
+ comm_old_write_mbuf(sslState->server.fd(), &mb, sslProxyConnectedWriteDone, sslState);
commSetTimeout(sslState->server.fd(),
Config.Timeout.read,
/*
- * $Id: urn.cc,v 1.86 2003/09/01 03:49:40 robertc Exp $
+ * $Id: urn.cc,v 1.87 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 52 URN Parsing
* AUTHOR: Kostas Anagnostakis
url_entry *urls;
url_entry *u;
url_entry *min_u;
- MemBuf mb;
+ MemBuf *mb = NULL;
ErrorState *err;
int i;
int urlcnt = 0;
min_u = urnFindMinRtt(urls, urnState->request->method, NULL);
qsort(urls, urlcnt, sizeof(*urls), url_entry_sort);
storeBuffer(e);
- memBufDefInit(&mb);
- memBufPrintf(&mb,
+ mb = new MemBuf;
+ memBufDefInit(mb);
+ memBufPrintf(mb,
"<TITLE>Select URL for %s</TITLE>\n"
"<STYLE type=\"text/css\"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}--></STYLE>\n"
"<H2>Select URL for %s</H2>\n"
for (i = 0; i < urlcnt; i++) {
u = &urls[i];
debug(52, 3) ("URL {%s}\n", u->url);
- memBufPrintf(&mb,
+ memBufPrintf(mb,
"<TR><TD><A HREF=\"%s\">%s</A></TD>", u->url, u->url);
if (urls[i].rtt > 0)
- memBufPrintf(&mb,
+ memBufPrintf(mb,
"<TD align=\"right\">%4d <it>ms</it></TD>", u->rtt);
else
- memBufPrintf(&mb, "<TD align=\"right\">Unknown</TD>");
+ memBufPrintf(mb, "<TD align=\"right\">Unknown</TD>");
- memBufPrintf(&mb,
+ memBufPrintf(mb,
"<TD>%s</TD></TR>\n", u->flags.cached ? " [cached]" : " ");
}
- memBufPrintf(&mb,
+ memBufPrintf(mb,
"</TABLE>"
"<HR noshade size=\"1px\">\n"
"<ADDRESS>\n"
full_appname_string, getMyHostname());
rep = httpReplyCreate();
httpReplySetHeaders(rep, version, HTTP_MOVED_TEMPORARILY, NULL,
- "text/html", mb.size, 0, squid_curtime);
+ "text/html", mb->contentSize(), 0, squid_curtime);
if (urnState->flags.force_menu) {
debug(51, 3) ("urnHandleReply: forcing menu\n");
httpHeaderPutStr(&rep->header, HDR_LOCATION, min_u->url);
}
- httpBodySet(&rep->body, &mb);
+ httpBodySet(&rep->body, mb);
+ /* don't clean or delete mb; rep->body owns it now */
httpReplySwapOut(rep, e);
e->complete();
/*
- * $Id: wais.cc,v 1.150 2003/08/10 11:00:45 robertc Exp $
+ * $Id: wais.cc,v 1.151 2005/08/31 19:15:36 wessels Exp $
*
* DEBUG: section 24 WAIS Relay
* AUTHOR: Harvest Derived
memBufPrintf(&mb, "\r\n");
debug(24, 6) ("waisSendRequest: buf: %s\n", mb.buf);
- comm_old_write_mbuf(fd, mb, waisSendComplete, waisState);
+ comm_old_write_mbuf(fd, &mb, waisSendComplete, waisState);
if (EBIT_TEST(waisState->entry->flags, ENTRY_CACHABLE))
storeSetPublicKey(waisState->entry); /* Make it public */