]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- changed internal structure of HttpBody to use MemBuf;
authorrousskov <>
Sat, 6 Jun 1998 03:21:16 +0000 (03:21 +0000)
committerrousskov <>
Sat, 6 Jun 1998 03:21:16 +0000 (03:21 +0000)
  no more inconsistencies with body.size
- removed HTML tags from mgr:http_headers dump

src/HttpBody.cc
src/HttpHeader.cc
src/MemBuf.cc
src/errorpage.cc
src/protos.h
src/structs.h

index 340817192a967350dc2ddd03cead76326e6b8532..47f4298c1923586b4e6ba2309be70d6190d3af9c 100644 (file)
@@ -2,7 +2,7 @@
 
 
 /*
- * $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
index 4feb615f7aa4322e955b34b0ae126ef9dd68d33e..d27ba9b71e1640226e6d90ccf19c2bcd3a018dd0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $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
@@ -969,9 +969,8 @@ httpHeaderFieldStatDumper(StoreEntry * sentry, int idx, double val, double size,
     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
@@ -990,16 +989,16 @@ httpHeaderStatDump(const HttpHeaderStat * hs, StoreEntry * e)
     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);
@@ -1026,8 +1025,8 @@ httpHeaderStoreReport(StoreEntry * e)
        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++) {
index c63690c4522210336a571be72c59662fc4f743bd..2771851849c50e3d37503216ed90885a1501f242 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $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
@@ -155,11 +155,9 @@ memBufReset(MemBuf * mb)
 {
     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);
@@ -167,6 +165,18 @@ memBufReset(MemBuf * mb)
     }
 }
 
+/* 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)
index 6da39703f564b3e788a897c3aaf5c6b767d3aefc..22f41136b748dc26f7c7b624703afdf5681b6244 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $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
@@ -527,8 +527,8 @@ errorBuildReply(ErrorState * err)
      */
     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;
 }
 
index 751c0e704702e5246adb8a98a746718a1f945b74..ed96fc715d301da58a7d28f8f4ad9c1734b35f94 100644 (file)
@@ -265,9 +265,8 @@ extern void httpBodyInit(HttpBody * body);
 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);
@@ -490,6 +489,8 @@ extern void memBufDefInit(MemBuf * mb);
 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 */
index 45e120822832f4cc73f4da9cbdedf882068f6e19..66962257e63f146b99bdd56fdb602539900853b4 100644 (file)
@@ -483,6 +483,27 @@ struct _hash_table {
     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 */
@@ -492,14 +513,12 @@ struct _HttpStatusLine {
 };
 
 /*
- * 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 */
@@ -998,28 +1017,6 @@ struct _iostats {
     } 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;