/*
- * $Id: HttpBody.cc,v 1.11 1998/05/27 22:51:39 rousskov Exp $
+ * $Id: HttpBody.cc,v 1.12 1998/06/05 21:21:16 rousskov Exp $
*
* DEBUG: section 56 HTTP Message Body
* AUTHOR: Alex Rousskov
#include "squid.h"
-/* local constants */
-
-/* local routines */
-
-
void
httpBodyInit(HttpBody * body)
{
- body->buf = NULL;
- body->size = 0;
- body->freefunc = NULL;
+ body->mb = MemBufNull;
}
void
httpBodyClean(HttpBody * body)
{
assert(body);
- if (body->buf) {
- assert(body->freefunc);
- (*body->freefunc) (body->buf);
- }
- body->buf = NULL;
- body->size = 0;
+ if (!memBufIsNull(&body->mb))
+ memBufClean(&body->mb);
}
-/* set body, if freefunc is NULL the content will be copied, otherwise not */
+/* set body by absorbing mb */
void
-httpBodySet(HttpBody * body, const char *buf, int size, FREE * freefunc)
+httpBodySet(HttpBody * body, MemBuf *mb)
{
assert(body);
- assert(!body->buf);
- assert(buf);
- assert(size);
- assert(buf[size - 1] == '\0'); /* paranoid */
- if (!freefunc) { /* they want us to make our own copy */
- body->buf = xmalloc(size);
- xmemcpy(body->buf, buf, size);
- freefunc = &xfree;
- } else {
- /* @?@ @?@ Fix this cast: we should probably have two httpBodySet()s */
- body->buf = (char *) buf;
- }
- body->freefunc = freefunc;
- body->size = size;
+ assert(memBufIsNull(&body->mb));
+ body->mb = *mb; /* absorb */
}
void
httpBodyPackInto(const HttpBody * body, Packer * p)
{
assert(body && p);
- /* assume it was a 0-terminated buffer */
- if (body->size)
- packerAppend(p, body->buf, body->size - 1);
+ if (body->mb.size)
+ packerAppend(p, body->mb.buf, body->mb.size);
}
+#if UNUSED_CODE
const char *
httpBodyPtr(const HttpBody * body)
{
- return body->buf ? body->buf : "";
+ return body->mb.buf ? body->mb.buf : "";
}
+#endif
/*
- * $Id: HttpHeader.cc,v 1.44 1998/06/05 19:45:17 rousskov Exp $
+ * $Id: HttpHeader.cc,v 1.45 1998/06/05 21:21:17 rousskov Exp $
*
* DEBUG: section 55 HTTP Header
* AUTHOR: Alex Rousskov
if (!visible && valid_id && dump_stat->owner_mask)
visible = CBIT_TEST(*dump_stat->owner_mask, id);
if (visible)
- storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\t %d\n",
- id, name, count, xdiv(count, dump_stat->busyDestroyedCount),
- visible);
+ storeAppendPrintf(sentry, "%2d\t %-20s\t %5d\t %6.2f\n",
+ id, name, count, xdiv(count, dump_stat->busyDestroyedCount));
}
static void
assert(hs && e);
dump_stat = hs;
- storeAppendPrintf(e, "\n<h3>Header Stats: %s</h3>\n", hs->label);
- storeAppendPrintf(e, "<h3>Field type distribution</h3>\n");
+ storeAppendPrintf(e, "\nHeader Stats: %s\n", hs->label);
+ storeAppendPrintf(e, "\nField type distribution\n");
storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
"id", "name", "count", "#/header");
statHistDump(&hs->fieldTypeDistr, e, httpHeaderFieldStatDumper);
- storeAppendPrintf(e, "<h3>Cache-control directives distribution</h3>\n");
+ storeAppendPrintf(e, "Cache-control directives distribution\n");
storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\n",
"id", "name", "count", "#/cc_field");
statHistDump(&hs->ccTypeDistr, e, httpHdrCcStatDumper);
- storeAppendPrintf(e, "<h3>Number of fields per header distribution</h3>\n");
+ storeAppendPrintf(e, "Number of fields per header distribution\n");
storeAppendPrintf(e, "%2s\t %-5s\t %5s\t %6s\n",
"id", "#flds", "count", "%total");
statHistDump(&hs->hdrUCountDistr, e, httpHeaderFldsPerHdrDumper);
httpHeaderStatDump(HttpHeaderStats + i, e);
storeAppendPrintf(e, "%s\n", "<br>");
}
- /* field stats */
- storeAppendPrintf(e, "<h3>Http Fields Stats (replies and requests)</h3>\n");
+ /* field stats for all messages */
+ storeAppendPrintf(e, "\nHttp Fields Stats (replies and requests)\n");
storeAppendPrintf(e, "%2s\t %-20s\t %5s\t %6s\t %6s\n",
"id", "name", "#alive", "%err", "%repeat");
for (ht = 0; ht < HDR_ENUM_END; ht++) {
/*
- * $Id: MemBuf.cc,v 1.14 1998/06/03 15:52:16 rousskov Exp $
+ * $Id: MemBuf.cc,v 1.15 1998/06/05 21:21:18 rousskov Exp $
*
* DEBUG: section 59 auto-growing Memory Buffer with printf
* AUTHOR: Alex Rousskov
{
assert(mb);
- if (!mb->buf && !mb->max_capacity && !mb->capacity && !mb->size) {
- /* Null */
+ if (memBufIsNull(mb)) {
memBufDefInit(mb);
} else {
- assert(mb->buf);
assert(mb->freefunc); /* not frozen */
/* reset */
memset(mb->buf, 0, mb->capacity);
}
}
+/* unfirtunate hack to test if the buffer has been Init()ialized */
+int
+memBufIsNull(MemBuf * mb)
+{
+ assert(mb);
+ if (!mb->buf && !mb->max_capacity && !mb->capacity && !mb->size)
+ return 1; /* null, not initialized */
+ assert(mb->buf && mb->max_capacity && mb->capacity); /* paranoid */
+ return 0;
+}
+
+
/* calls memcpy, appends exactly size bytes, extends buffer if needed */
void
memBufAppend(MemBuf * mb, const char *buf, mb_size_t sz)
/*
- * $Id: errorpage.cc,v 1.137 1998/06/02 21:50:21 rousskov Exp $
+ * $Id: errorpage.cc,v 1.138 1998/06/05 21:21:19 rousskov Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
*/
httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d",
err_type_str[err->page_id], err->xerrno);
- httpBodySet(&rep->body, content.buf, content.size + 1, NULL);
- memBufClean(&content);
+ httpBodySet(&rep->body, &content);
+ /* do not memBufClean() the content, it was absorbed by httpBody */
return rep;
}
extern void httpBodyClean(HttpBody * body);
/* get body ptr (always use this) */
extern const char *httpBodyPtr(const HttpBody * body);
-/* set body, if freefunc is NULL the content will be copied, otherwise not */
-extern void httpBodySet(HttpBody * body, const char *content, int size,
- FREE * freefunc);
+/* set body, does not clone mb so you should not reuse it */
+extern void httpBodySet(HttpBody * body, MemBuf *mb);
/* pack */
extern void httpBodyPackInto(const HttpBody * body, Packer * p);
extern void memBufClean(MemBuf * mb);
/* resets mb preserving (or initializing if needed) memory buffer */
extern void memBufReset(MemBuf * mb);
+/* unfirtunate hack to test if the buffer has been Init()ialized */
+extern int memBufIsNull(MemBuf * mb);
/* calls memcpy, appends exactly size bytes, extends buffer if needed */
extern void memBufAppend(MemBuf * mb, const char *buf, mb_size_t size);
/* calls snprintf, extends buffer if needed */
int count;
};
+/* auto-growing memory-resident buffer with printf interface */
+/* note: when updating this struct, update MemBufNULL #define */
+struct _MemBuf {
+ /* public, read-only */
+ char *buf;
+ mb_size_t size; /* used space, does not count 0-terminator */
+
+ /* private, stay away; use interface function instead */
+ mb_size_t max_capacity; /* when grows: assert(new_capacity <= max_capacity) */
+ mb_size_t capacity; /* allocated space */
+ FREE *freefunc; /* what to use to free the buffer, NULL after memBufFreeFunc() is called */
+};
+
+/* see Packer.c for description */
+struct _Packer {
+ /* protected, use interface functions instead */
+ append_f append;
+ vprintf_f vprintf;
+ void *real_handler; /* first parameter to real append and vprintf */
+};
+
/* http status line */
struct _HttpStatusLine {
/* public, read only */
};
/*
- * Note: HttpBody is used only for messages with a small text content that is
+ * Note: HttpBody is used only for messages with a small content that is
* known a priory (e.g., error messages).
*/
struct _HttpBody {
- /* private, never dereference these */
- char *buf; /* null terminated _text_ buffer, not for binary stuff */
- FREE *freefunc; /* used to free() .buf */
- int size;
+ /* private */
+ MemBuf mb;
};
/* http header extention field */
} Http, Ftp, Gopher, Wais;
};
-/* auto-growing memory-resident buffer with printf interface */
-/* note: when updating this struct, update MemBufNULL #define */
-struct _MemBuf {
- /* public, read-only */
- char *buf;
- mb_size_t size; /* used space, does not count 0-terminator */
-
- /* private, stay away; use interface function instead */
- mb_size_t max_capacity; /* when grows: assert(new_capacity <= max_capacity) */
- mb_size_t capacity; /* allocated space */
- FREE *freefunc; /* what to use to free the buffer, NULL after memBufFreeFunc() is called */
-};
-
-/* see Packer.c for description */
-struct _Packer {
- /* protected, use interface functions instead */
- append_f append;
- vprintf_f vprintf;
- void *real_handler; /* first parameter to real append and vprintf */
-};
-
-
struct _mem_node {
char *data;
int len;