]> err.no Git - varnish/commitdiff
Fold libsbuf into libvarnish, with s/sbuf/vsb/g.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 11:09:30 +0000 (11:09 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 11:09:30 +0000 (11:09 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@712 d4fa192b-c00b-0410-8231-f00ffab90ce4

33 files changed:
varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_cli.c
varnish-cache/bin/varnishd/cache_response.c
varnish-cache/bin/varnishd/cache_vrt_re.c
varnish-cache/bin/varnishd/flint.lnt
varnish-cache/bin/varnishd/mgt_cli.c
varnish-cache/bin/varnishd/mgt_vcc.c
varnish-cache/bin/varnishd/varnishd.c
varnish-cache/bin/varnishlog/Makefile.am
varnish-cache/bin/varnishlog/varnishlog.c
varnish-cache/bin/varnishncsa/Makefile.am
varnish-cache/bin/varnishncsa/varnishncsa.c
varnish-cache/bin/varnishtop/Makefile.am
varnish-cache/bin/varnishtop/varnishtop.c
varnish-cache/configure.ac
varnish-cache/include/Makefile.am
varnish-cache/include/cli_common.h
varnish-cache/include/libvcl.h
varnish-cache/include/vrt.h
varnish-cache/include/vsb.h [moved from varnish-cache/include/sbuf.h with 58% similarity]
varnish-cache/lib/Makefile.am
varnish-cache/lib/libsbuf/Makefile.am [deleted file]
varnish-cache/lib/libsbuf/sbuf.c [deleted file]
varnish-cache/lib/libvarnish/Makefile.am
varnish-cache/lib/libvarnish/cli_common.c
varnish-cache/lib/libvarnish/vsb.3 [moved from varnish-cache/lib/libsbuf/sbuf.3 with 68% similarity]
varnish-cache/lib/libvarnish/vsb.c [new file with mode: 0644]
varnish-cache/lib/libvcl/vcc_acl.c
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_token.c

index 2764eba93c24f5231aae660e76de9b926f1d3d85..a15bd3053a873df3c6d87eb219d5f600ca670067 100644 (file)
@@ -56,7 +56,6 @@ varnishd_LDFLAGS = -export-dynamic
 
 varnishd_LDADD = \
        $(top_builddir)/lib/libcompat/libcompat.a \
-       $(top_builddir)/lib/libsbuf/libsbuf.a \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvcl/libvcl.la \
        -lpthread \
index e560c68a67e911f1bb7aaf1e2404900b4081090e..2eca601dcd9e59db8ca2bf0dba7dfbd7497b3bbd 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/time.h>
 
 #include "queue.h"
-#include "sbuf.h"
+#include "vsb.h"
 
 #include "vcl_returns.h"
 #include "common.h"
@@ -26,7 +26,7 @@
 #define HTTP_HDR_FIRST         5
 
 struct cli;
-struct sbuf;
+struct vsb;
 struct sess;
 struct object;
 struct objhead;
index 0db9917c4f3124b465c4798c3ba3e2eea1c8da9b..d244c5fcdc5f41bcefa0120ae7283b999eed0465 100644 (file)
@@ -14,7 +14,7 @@
 #include "cli_priv.h"
 #include "cli_common.h"
 #include "cache.h"
-#include "sbuf.h"
+#include "vsb.h"
 #include "heritage.h"
 
 /*--------------------------------------------------------------------*/
@@ -64,7 +64,7 @@ CLI_Init(void)
        cli = &clis;
        memset(cli, 0, sizeof *cli);
        
-       cli->sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(cli->sb != NULL);
        lbuf = 4096;
        buf = malloc(lbuf);
@@ -93,9 +93,9 @@ CLI_Init(void)
                        continue;
                *p = '\0';
                VSL(SLT_CLI, 0, "Rd %s", buf);
-               sbuf_clear(cli->sb);
+               vsb_clear(cli->sb);
                cli_dispatch(cli, CLI_cmds, buf);
-               sbuf_finish(cli->sb);
+               vsb_finish(cli->sb);
                i = cli_writeres(heritage.fds[1], cli);
                if (i) {
                        VSL(SLT_Error, 0, "CLI write failed (errno=%d)", errno);
@@ -103,7 +103,7 @@ CLI_Init(void)
                        return;
                }
                VSL(SLT_CLI, 0, "Wr %d %d %s",
-                   i, cli->result, sbuf_data(cli->sb));
+                   i, cli->result, vsb_data(cli->sb));
                i = ++p - buf; 
                assert(i <= nbuf);
                if (i < nbuf)
index d4ccf5239cf5717298c82ff5cbc847bd582d3a0d..0c03c6303b9410b0e54750d8088cb2a4bc2b5a41 100644 (file)
@@ -18,9 +18,9 @@ void
 RES_Error(struct sess *sp, int error, const char *msg)
 {
        char buf[40];
-       struct sbuf *sb;
+       struct vsb *sb;
 
-       sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(sb != NULL);
 
        if (msg == NULL) {
@@ -31,11 +31,11 @@ RES_Error(struct sess *sp, int error, const char *msg)
                }
        }
 
-       sbuf_clear(sb);
-       sbuf_printf(sb, "HTTP/1.1 %03d %s\r\n", error, msg);
+       vsb_clear(sb);
+       vsb_printf(sb, "HTTP/1.1 %03d %s\r\n", error, msg);
        TIM_format(sp->t_req.tv_sec, buf);
-       sbuf_printf(sb, "Date: %s\r\n", buf);
-       sbuf_cat(sb,
+       vsb_printf(sb, "Date: %s\r\n", buf);
+       vsb_cat(sb,
                "Server: Varnish\r\n"
                "Connection: close\r\n"
                "content-Type: text/html; charset=iso-8859-1\r\n"
@@ -43,33 +43,33 @@ RES_Error(struct sess *sp, int error, const char *msg)
                "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
                "<HTML>\r\n"
                "  <HEAD>\r\n");
-       sbuf_printf(sb, "    <TITLE>%03d %s</TITLE>\r\n", error, msg);
-       sbuf_cat(sb,
+       vsb_printf(sb, "    <TITLE>%03d %s</TITLE>\r\n", error, msg);
+       vsb_cat(sb,
                "  </HEAD>\r\n"
                "  <BODY>\r\n");
-       sbuf_printf(sb, "    <H1>Error %03d %s</H1>\r\n", error, msg);
+       vsb_printf(sb, "    <H1>Error %03d %s</H1>\r\n", error, msg);
        switch(error) {
        case 400:
-               sbuf_cat(sb,
+               vsb_cat(sb,
                    "    Your HTTP protocol request did not make sense.\r\n");
                break;
        case 500:
        default:
-               sbuf_cat(sb,
+               vsb_cat(sb,
                    "    Something unexpected happened.\r\n");
                break;
        }
-       sbuf_cat(sb,
+       vsb_cat(sb,
                "    <P>\r\n"
                "    <I>\r\n"
                "    <A href=\"http://varnish.linpro.no/\">Varnish</A>\r\n"
                "  </BODY>\r\n"
                "</HTML>\r\n");
-       sbuf_finish(sb);
-       WRK_Write(sp->wrk, sbuf_data(sb), sbuf_len(sb));
+       vsb_finish(sb);
+       WRK_Write(sp->wrk, vsb_data(sb), vsb_len(sb));
        WRK_Flush(sp->wrk);
        vca_close_session(sp, msg);
-       sbuf_delete(sb);
+       vsb_delete(sb);
 }
 
 
index d83ba47ea8d75fea72e04df917d2a6a71e70c8b6..c50460e738f5c4b8f4bc6c4acb4e9a1b3e362bc3 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "shmlog.h"
 #include "vrt.h"
-#include "sbuf.h"
+#include "vsb.h"
 #include "vcl.h"
 #include "cache.h"
 
@@ -52,7 +52,7 @@ VRT_re_match(const char *s, void *re)
 }
 
 int
-VRT_re_test(struct sbuf *sb, const char *re)
+VRT_re_test(struct vsb *sb, const char *re)
 {
        int i;
        regex_t t;      
@@ -65,7 +65,7 @@ VRT_re_test(struct sbuf *sb, const char *re)
                return (0);
        }
        (void)regerror(i, &t, buf, sizeof buf);
-       sbuf_printf(sb, "Regexp compilation error:\n\n%s\n\n", buf);
+       vsb_printf(sb, "Regexp compilation error:\n\n%s\n\n", buf);
        regfree(&t);
        return (1);
 }
index 020c06f38f12761ee50e29c688d0fec16510324b..8ebea6847e696535e142b4d430d663b3abda684e 100644 (file)
@@ -24,8 +24,8 @@
 -esym(534, memcpy)     // Ignoring return value of function
 -esym(534, memmove)    // Ignoring return value of function
 -esym(534, strcpy)     // Ignoring return value of function
--esym(534, sbuf_printf)        // Ignoring return value of function
--esym(534, sbuf_cat)   // Ignoring return value of function
+-esym(534, vsb_printf) // Ignoring return value of function
+-esym(534, vsb_cat)    // Ignoring return value of function
 
 // cache.h
 -emacro(506, INCOMPL) // Constant value Boolean
index 3afc805bd66f6e908d2691b8014097409bddaa9a..aac03ae39ed5f5b3814811b34b2d386868ecf04d 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "cli_priv.h"
 #include "cli.h"
-#include "sbuf.h"
+#include "vsb.h"
 #include "cli_common.h"
 #include "mgt.h"
 #include "mgt_cli.h"
@@ -258,9 +258,9 @@ mgt_cli_callback(struct ev *e, int what)
                        return (0);
                *p = '\0';
 fprintf(stderr, "CLI <%s>\n", cp->buf);
-               sbuf_clear(cp->cli->sb);
+               vsb_clear(cp->cli->sb);
                cli_dispatch(cp->cli, cli_proto, cp->buf);
-               sbuf_finish(cp->cli->sb);
+               vsb_finish(cp->cli->sb);
                /* XXX: cp->verbose */
                if (cli_writeres(cp->fdo, cp->cli))
                        break;
@@ -271,7 +271,7 @@ fprintf(stderr, "CLI <%s>\n", cp->buf);
                cp->nbuf -= i;
                return (0);
        }
-       sbuf_delete(cp->cli->sb);
+       vsb_delete(cp->cli->sb);
        free(cp->buf);
        close(cp->fdi);
        close(cp->fdo);
@@ -298,7 +298,7 @@ mgt_cli_setup(int fdi, int fdo, int verbose)
        cp->buf = malloc(cp->lbuf);
        assert(cp->buf != NULL);
 
-       cp->cli->sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       cp->cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(cp->cli->sb != NULL);
 
        cp->ev = calloc(sizeof *cp->ev, 1);
index 9800915473f863ae07cf7cd0eccb0f246d821099..717057ff2d6188bebde13d439a07dd274dc6edbe 100644 (file)
@@ -11,7 +11,7 @@
 #include <assert.h>
 #include <sys/types.h>
 
-#include "sbuf.h"
+#include "vsb.h"
 #include "queue.h"
 
 #include "libvarnish.h"
@@ -120,10 +120,10 @@ mgt_vcc_default(const char *bflag, const char *fflag)
 {
        char *buf, *vf;
        const char *p, *q;
-       struct sbuf *sb;
+       struct vsb *sb;
        struct vclprog *vp;
 
-       sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(sb != NULL);
        if (bflag != NULL) {
                /*
@@ -155,13 +155,13 @@ mgt_vcc_default(const char *bflag, const char *fflag)
        } else {
                vf = VCC_CompileFile(sb, fflag);
        }
-       sbuf_finish(sb);
-       if (sbuf_len(sb) > 0) {
-               fprintf(stderr, "%s", sbuf_data(sb));
-               sbuf_delete(sb);
+       vsb_finish(sb);
+       if (vsb_len(sb) > 0) {
+               fprintf(stderr, "%s", vsb_data(sb));
+               vsb_delete(sb);
                return (1);
        }
-       sbuf_delete(sb);
+       vsb_delete(sb);
        vp = mgt_vcc_add("boot", vf);
        vp->active = 1;
        return (0);
@@ -224,22 +224,22 @@ void
 mcf_config_inline(struct cli *cli, char **av, void *priv)
 {
        char *vf, *p;
-       struct sbuf *sb;
+       struct vsb *sb;
        unsigned status;
 
        (void)priv;
 
-       sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(sb != NULL);
        vf = VCC_Compile(sb, av[3], NULL);
-       sbuf_finish(sb);
-       if (sbuf_len(sb) > 0) {
-               cli_out(cli, "%s", sbuf_data(sb));
-               sbuf_delete(sb);
+       vsb_finish(sb);
+       if (vsb_len(sb) > 0) {
+               cli_out(cli, "%s", vsb_data(sb));
+               vsb_delete(sb);
                cli_result(cli, CLIS_PARAM);
                return;
        }
-       sbuf_delete(sb);
+       vsb_delete(sb);
        if (child_pid >= 0 &&
            mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) {
                cli_result(cli, status);
@@ -254,23 +254,23 @@ void
 mcf_config_load(struct cli *cli, char **av, void *priv)
 {
        char *vf;
-       struct sbuf *sb;
+       struct vsb *sb;
        unsigned status;
        char *p;
 
        (void)priv;
 
-       sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(sb != NULL);
        vf = VCC_CompileFile(sb, av[3]);
-       sbuf_finish(sb);
-       if (sbuf_len(sb) > 0) {
-               cli_out(cli, "%s", sbuf_data(sb));
-               sbuf_delete(sb);
+       vsb_finish(sb);
+       if (vsb_len(sb) > 0) {
+               cli_out(cli, "%s", vsb_data(sb));
+               vsb_delete(sb);
                cli_result(cli, CLIS_PARAM);
                return;
        }
-       sbuf_delete(sb);
+       vsb_delete(sb);
        if (child_pid >= 0 &&
            mgt_cli_askchild(&status, &p, "config.load %s %s\n", av[2], vf)) {
                cli_result(cli, status);
index cd9d916867310bf67dfc0913a3e3ee45cd1c7e85..a39a7db8e87db1b8d00319ee82dbb806db3fc979 100644 (file)
@@ -17,7 +17,7 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "sbuf.h"
+#include "vsb.h"
 
 #include "libvarnish.h"
 #include "cli.h"
index 5aed3f673d33c6a86d4153ef2959507efdd91054..2d0ceffcacf3d968f16117fb0026bd9c4618a18a 100644 (file)
@@ -11,5 +11,5 @@ varnishlog_SOURCES = varnishlog.c
 varnishlog_CFLAGS = -include config.h
 
 varnishlog_LDADD = \
-       $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
-       $(top_builddir)/lib/libsbuf/libsbuf.a 
+       $(top_builddir)/lib/libvarnish/libvarnish.la \
+       $(top_builddir)/lib/libvarnishapi/libvarnishapi.la
index 31d19d53dfc86a9255169d8794ddf381e382a0b1..67fa138994c409347498b5c711da19129bbeae45 100644 (file)
@@ -10,7 +10,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <vis.h>
 
 #include "shmlog.h"
@@ -31,7 +31,7 @@ vis_it(unsigned char *p)
 
 /* Ordering-----------------------------------------------------------*/
 
-static struct sbuf     *ob[65536];
+static struct vsb      *ob[65536];
 static int             hc[65536];
 static int             xrf[65536];
 
@@ -43,10 +43,10 @@ clean_order(void)
        for (u = 0; u < 65536; u++) {
                if (ob[u] == NULL)
                        continue;
-               sbuf_finish(ob[u]);
-               if (sbuf_len(ob[u]))
-                       printf("%s\n", sbuf_data(ob[u]));
-               sbuf_clear(ob[u]);
+               vsb_finish(ob[u]);
+               if (vsb_len(ob[u]))
+                       printf("%s\n", vsb_data(ob[u]));
+               vsb_clear(ob[u]);
        }
 }
 
@@ -57,32 +57,32 @@ order(unsigned char *p, int h_opt)
 
        u = (p[2] << 8) | p[3];
        if (ob[u] == NULL) {
-               ob[u] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+               ob[u] = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
                assert(ob[u] != NULL);
        }
        v = 0;
        switch (p[0]) {
        case SLT_VCL_call:
-               sbuf_printf(ob[u], "%02x %3d %4d %-12s",
+               vsb_printf(ob[u], "%02x %3d %4d %-12s",
                    p[0], p[1], u, VSL_tags[p[0]]);
                if (p[1] > 0) {
-                       sbuf_cat(ob[u], " <");
-                       sbuf_bcat(ob[u], p + 4, p[1]);
+                       vsb_cat(ob[u], " <");
+                       vsb_bcat(ob[u], p + 4, p[1]);
                }
                if (h_opt && p[1] == 3 && !memcmp(p + 4, "hit", 3))
                        hc[u]++;
                break;
        case SLT_VCL_trace:
                if (p[1] > 0) {
-                       sbuf_cat(ob[u], " ");
-                       sbuf_bcat(ob[u], p + 4, p[1]);
+                       vsb_cat(ob[u], " ");
+                       vsb_bcat(ob[u], p + 4, p[1]);
                }
                break;
        case SLT_VCL_return:
                if (p[1] > 0) {
-                       sbuf_cat(ob[u], " ");
-                       sbuf_bcat(ob[u], p + 4, p[1]);
-                       sbuf_cat(ob[u], ">\n");
+                       vsb_cat(ob[u], " ");
+                       vsb_bcat(ob[u], p + 4, p[1]);
+                       vsb_cat(ob[u], ">\n");
                }
                if (h_opt && p[1] == 7 && !memcmp(p + 4, "deliver", 7))
                        hc[u]++;
@@ -100,11 +100,11 @@ order(unsigned char *p, int h_opt)
                        ;
                else if (p[1] > 4 && !memcmp(p + 4, "TTD:", 4))
                        break;
-               sbuf_printf(ob[u], "%02x %3d %4d %-12s",
+               vsb_printf(ob[u], "%02x %3d %4d %-12s",
                    p[0], p[1], u, VSL_tags[p[0]]);
                if (p[1] > 0)
-                       sbuf_cat(ob[u], vis_it(p));
-               sbuf_cat(ob[u], "\n");
+                       vsb_cat(ob[u], vis_it(p));
+               vsb_cat(ob[u], "\n");
                break;
        case SLT_HttpError:
                if (!h_opt) 
@@ -147,19 +147,19 @@ order(unsigned char *p, int h_opt)
                break;
        }
        if (v) {
-               sbuf_printf(ob[u], "%02x %3d %4d %-12s",
+               vsb_printf(ob[u], "%02x %3d %4d %-12s",
                    p[0], p[1], u, VSL_tags[p[0]]);
                if (p[1] > 0) {
-                       sbuf_cat(ob[u], " <");
-                       sbuf_bcat(ob[u], p + 4, p[1]);
-                       sbuf_cat(ob[u], ">");
+                       vsb_cat(ob[u], " <");
+                       vsb_bcat(ob[u], p + 4, p[1]);
+                       vsb_cat(ob[u], ">");
                }
-               sbuf_cat(ob[u], "\n");
+               vsb_cat(ob[u], "\n");
        }
        if (u == 0) {
-               sbuf_finish(ob[u]);
-               printf("%s", sbuf_data(ob[u]));
-               sbuf_clear(ob[u]);
+               vsb_finish(ob[u]);
+               printf("%s", vsb_data(ob[u]));
+               vsb_clear(ob[u]);
                return;
        }
        switch (p[0]) {
@@ -167,10 +167,10 @@ order(unsigned char *p, int h_opt)
        case SLT_SessionReuse:
        case SLT_BackendClose:
        case SLT_BackendReuse:
-               sbuf_finish(ob[u]);
-               if ((hc[u] != 4 || h_opt == 0) && sbuf_len(ob[u]) > 1)
-                       printf("%s\n", sbuf_data(ob[u]));
-               sbuf_clear(ob[u]);
+               vsb_finish(ob[u]);
+               if ((hc[u] != 4 || h_opt == 0) && vsb_len(ob[u]) > 1)
+                       printf("%s\n", vsb_data(ob[u]));
+               vsb_clear(ob[u]);
                hc[u] = 0;
                xrf[u] = 0;
                break;
index d72dd7ed65202cf0f30a8dd7994a4dc15d6359dd..707dad110dfaf1866de3e5e0824af9a5214a28fa 100644 (file)
@@ -11,5 +11,5 @@ varnishncsa_SOURCES = varnishncsa.c
 varnishncsa_CFLAGS = -include config.h
 
 varnishncsa_LDADD = \
-       $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
-       $(top_builddir)/lib/libsbuf/libsbuf.a 
+       $(top_builddir)/lib/libvarnish/libvarnish.la \
+       $(top_builddir)/lib/libvarnishapi/libvarnishapi.la
index c205a70d70be42f79f2d1cc8c06f466584c289e3..f52804080ba83c2ee2ad5ee5827742a2d7201f05 100644 (file)
@@ -18,7 +18,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <assert.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <vis.h>
 #include <time.h>
 
@@ -39,13 +39,13 @@ struct logline {
 
 };
 
-/* We make a array of pointers to sbuf's. Sbuf is a string buffer.
+/* We make a array of pointers to vsb's. Sbuf is a string buffer.
  * * The buffer can be made/extended/cleared etc. through a API.
  * * The array is 65536 long because we will use sessionid as key.
  * *
  * */
 
-static struct sbuf      *ob[65536];
+static struct vsb      *ob[65536];
 static struct logline  ll[65536];
 
 
@@ -64,8 +64,8 @@ clean_order(void)
        for (u = 0; u < 65536; u++) {
                if (ob[u] == NULL)
                        continue;
-               sbuf_finish(ob[u]);
-               sbuf_clear(ob[u]);
+               vsb_finish(ob[u]);
+               vsb_clear(ob[u]);
        }
 }
 
@@ -80,7 +80,7 @@ extended_log_format(unsigned char *p, char *w_opt)
 
        u = (p[2] << 8) | p[3];
        if (ob[u] == NULL) {
-               ob[u] = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+               ob[u] = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
                assert(ob[u] != NULL);
        }
        
index 680d758456aea4bad68e2d3d60f38e6fb72866f9..b333c189c89debcaba5c57b1b0c94b06f439838e 100644 (file)
@@ -11,6 +11,6 @@ varnishtop_SOURCES = varnishtop.c
 varnishtop_CFLAGS = -include config.h
 
 varnishtop_LDADD = \
+       $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
-       $(top_builddir)/lib/libsbuf/libsbuf.a \
        -lcurses
index 4e9c5d61919defda3ab889c1c3cadc8ca2961a12..89d0d147f599606691287157c7c2242162952650 100644 (file)
@@ -12,7 +12,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include <curses.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <vis.h>
 
 #include "shmlog.h"
index 59aa819054d2d16b115fa52c661b4afd386a3691..d2adc25f3c56c2adb135b5bbf14b4b2018dab9dc 100644 (file)
@@ -75,7 +75,6 @@ AC_CONFIG_FILES([
     include/Makefile
     lib/Makefile
     lib/libcompat/Makefile
-    lib/libsbuf/Makefile
     lib/libvarnish/Makefile
     lib/libvarnishapi/Makefile
     lib/libvcl/Makefile
index a77d1209ab54ec927e79ab3eb2ddc5de738f4f23..2cfcef96a14bc5b96b6fc8a6a67e35dd861f38e6 100644 (file)
@@ -12,7 +12,7 @@ noinst_HEADERS = \
        libvcl.h \
        miniobj.h \
        queue.h \
-       sbuf.h \
+       vsb.h \
        shmlog.h \
        shmlog_tags.h \
        stat_field.h \
index 12d19d4ff3f1ac2ecf3c234f729f01ca2d5c78ab..b1bc8840a17dbfa7bec3c005ceb1bec680345795 100644 (file)
@@ -3,7 +3,7 @@
  */
 
 struct cli {
-       struct sbuf             *sb;
+       struct vsb              *sb;
        enum cli_status_e       result;
 };
 
index 3c17e3a1cf668e117d802a18885cc033e3f21321..c477ba4a98ca4a53e8e8a82eecc8c52d837d1616 100644 (file)
@@ -2,8 +2,8 @@
  * $Id$
  */
 
-char *VCC_Compile(struct sbuf *sb, const char *b, const char *e);
-char *VCC_CompileFile(struct sbuf *sb, const char *fn);
+char *VCC_Compile(struct vsb *sb, const char *b, const char *e);
+char *VCC_CompileFile(struct vsb *sb, const char *fn);
 void VCC_InitCompile(const char *default_vcl);
 
 
index 71a32838f80498bc39139aaf6ee004aa8a094ca8..1915a0df47bd875d79b6921e411cc5d5e31f48cd 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 struct sess;
-struct sbuf;
+struct vsb;
 struct backend;
 struct VCL_conf;
 
@@ -38,7 +38,7 @@ void VRT_acl_fini(struct vrt_acl *);
 void VRT_re_init(void **, const char *);
 void VRT_re_fini(void *);
 int VRT_re_match(const char *, void *re);
-int VRT_re_test(struct sbuf *, const char *);
+int VRT_re_test(struct vsb *, const char *);
 
 void VRT_count(struct sess *, unsigned);
 int VRT_rewrite(const char *, const char *);
similarity index 58%
rename from varnish-cache/include/sbuf.h
rename to varnish-cache/include/vsb.h
index b60f8c7fd47f75bafbb5327d249fe4f0a0f95f73..a8c095168a35336bd6ff256e5c81a10322da79ca 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $Id$
- * $FreeBSD: src/sys/sys/sbuf.h,v 1.14 2004/07/09 11:35:30 des Exp $
+ * $FreeBSD: src/sys/sys/vsb.h,v 1.14 2004/07/09 11:35:30 des Exp $
  */
 
-#ifndef SBUF_H_INCLUDED
-#define SBUF_H_INCLUDED
+#ifndef VSB_H_INCLUDED
+#define VSB_H_INCLUDED
 
 /*
  * Structure definition
  */
-struct sbuf {
+struct vsb {
        char            *s_buf;         /* storage buffer */
        void            *s_unused;      /* binary compatibility. */
        int              s_size;        /* size of storage buffer */
        int              s_len;         /* current length of string */
-#define        SBUF_FIXEDLEN   0x00000000      /* fixed length buffer (default) */
-#define        SBUF_AUTOEXTEND 0x00000001      /* automatically extend buffer */
-#define        SBUF_USRFLAGMSK 0x0000ffff      /* mask of flags the user may specify */
-#define        SBUF_DYNAMIC    0x00010000      /* s_buf must be freed */
-#define        SBUF_FINISHED   0x00020000      /* set by sbuf_finish() */
-#define        SBUF_OVERFLOWED 0x00040000      /* sbuf overflowed */
-#define        SBUF_DYNSTRUCT  0x00080000      /* sbuf must be freed */
+#define        VSB_FIXEDLEN    0x00000000      /* fixed length buffer (default) */
+#define        VSB_AUTOEXTEND  0x00000001      /* automatically extend buffer */
+#define        VSB_USRFLAGMSK 0x0000ffff       /* mask of flags the user may specify */
+#define        VSB_DYNAMIC     0x00010000      /* s_buf must be freed */
+#define        VSB_FINISHED    0x00020000      /* set by vsb_finish() */
+#define        VSB_OVERFLOWED  0x00040000      /* vsb overflowed */
+#define        VSB_DYNSTRUCT   0x00080000      /* vsb must be freed */
        int              s_flags;       /* flags */
 };
 
@@ -54,25 +54,25 @@ __BEGIN_DECLS
 /*
  * API functions
  */
-struct sbuf    *sbuf_new(struct sbuf *, char *, int, int);
-void            sbuf_clear(struct sbuf *);
-int             sbuf_setpos(struct sbuf *, int);
-int             sbuf_bcat(struct sbuf *, const void *, size_t);
-int             sbuf_bcpy(struct sbuf *, const void *, size_t);
-int             sbuf_cat(struct sbuf *, const char *);
-int             sbuf_cpy(struct sbuf *, const char *);
-int             sbuf_printf(struct sbuf *, const char *, ...) /* __printflike(2, 3) */;
+struct vsb     *vsb_new(struct vsb *, char *, int, int);
+void            vsb_clear(struct vsb *);
+int             vsb_setpos(struct vsb *, int);
+int             vsb_bcat(struct vsb *, const void *, size_t);
+int             vsb_bcpy(struct vsb *, const void *, size_t);
+int             vsb_cat(struct vsb *, const char *);
+int             vsb_cpy(struct vsb *, const char *);
+int             vsb_printf(struct vsb *, const char *, ...) /* __printflike(2, 3) */;
 #ifdef va_start
-int             sbuf_vprintf(struct sbuf *, const char *, va_list) /* __printflike(2, 0) */;
+int             vsb_vprintf(struct vsb *, const char *, va_list) /* __printflike(2, 0) */;
 #endif
-int             sbuf_putc(struct sbuf *, int);
-int             sbuf_trim(struct sbuf *);
-int             sbuf_overflowed(struct sbuf *);
-void            sbuf_finish(struct sbuf *);
-char           *sbuf_data(struct sbuf *);
-int             sbuf_len(struct sbuf *);
-int             sbuf_done(struct sbuf *);
-void            sbuf_delete(struct sbuf *);
+int             vsb_putc(struct vsb *, int);
+int             vsb_trim(struct vsb *);
+int             vsb_overflowed(struct vsb *);
+void            vsb_finish(struct vsb *);
+char           *vsb_data(struct vsb *);
+int             vsb_len(struct vsb *);
+int             vsb_done(struct vsb *);
+void            vsb_delete(struct vsb *);
 __END_DECLS
 
 #endif
index cf13ceb93baa5a55e0e8f09e2aca5e099c96e0e6..40e3174c77b358fa556a824e9c17d79497395cf2 100644 (file)
@@ -2,7 +2,6 @@
 
 SUBDIRS = \
        libcompat \
-       libsbuf \
        libvarnish \
        libvarnishapi \
        libvcl
diff --git a/varnish-cache/lib/libsbuf/Makefile.am b/varnish-cache/lib/libsbuf/Makefile.am
deleted file mode 100644 (file)
index a6fed39..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# $Id$
-
-INCLUDES = -I$(top_srcdir)/include
-
-lib_LIBRARIES = libsbuf.a
-
-libsbuf_a_SOURCES = \
-       sbuf.c
-
-libsbuf_a_CFLAGS = -include config.h
diff --git a/varnish-cache/lib/libsbuf/sbuf.c b/varnish-cache/lib/libsbuf/sbuf.c
deleted file mode 100644 (file)
index d8460b8..0000000
+++ /dev/null
@@ -1,468 +0,0 @@
-/*-
- * Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Coïdan Smørgrav
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer
- *    in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id$
- * $FreeBSD: src/sys/kern/subr_sbuf.c,v 1.30 2005/12/23 11:49:53 phk Exp $
- */
-
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "sbuf.h"
-
-#define        KASSERT(e, m)
-#define        SBMALLOC(size)          malloc(size)
-#define        SBFREE(buf)             free(buf)
-#define        min(x,y)                (x < y ? x : y)
-
-/*
- * Predicates
- */
-#define        SBUF_ISDYNAMIC(s)       ((s)->s_flags & SBUF_DYNAMIC)
-#define        SBUF_ISDYNSTRUCT(s)     ((s)->s_flags & SBUF_DYNSTRUCT)
-#define        SBUF_ISFINISHED(s)      ((s)->s_flags & SBUF_FINISHED)
-#define        SBUF_HASOVERFLOWED(s)   ((s)->s_flags & SBUF_OVERFLOWED)
-#define        SBUF_HASROOM(s)         ((s)->s_len < (s)->s_size - 1)
-#define        SBUF_FREESPACE(s)       ((s)->s_size - (s)->s_len - 1)
-#define        SBUF_CANEXTEND(s)       ((s)->s_flags & SBUF_AUTOEXTEND)
-
-/*
- * Set / clear flags
- */
-#define        SBUF_SETFLAG(s, f)      do { (s)->s_flags |= (f); } while (0)
-#define        SBUF_CLEARFLAG(s, f)    do { (s)->s_flags &= ~(f); } while (0)
-
-#define        SBUF_MINEXTENDSIZE      16              /* Should be power of 2. */
-#define        SBUF_MAXEXTENDSIZE      4096
-#define        SBUF_MAXEXTENDINCR      4096
-
-/*
- * Debugging support
- */
-#if !defined(NDEBUG)
-static void
-_assert_sbuf_integrity(const char *fun, struct sbuf *s)
-{
-       KASSERT(s != NULL,
-           ("%s called with a NULL sbuf pointer", fun));
-       KASSERT(s->s_buf != NULL,
-           ("%s called with uninitialized or corrupt sbuf", fun));
-       KASSERT(s->s_len < s->s_size,
-           ("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));
-}
-
-static void
-_assert_sbuf_state(const char *fun, struct sbuf *s, int state)
-{
-       KASSERT((s->s_flags & SBUF_FINISHED) == state,
-           ("%s called with %sfinished or corrupt sbuf", fun,
-           (state ? "un" : "")));
-}
-#define        assert_sbuf_integrity(s) _assert_sbuf_integrity(__func__, (s))
-#define        assert_sbuf_state(s, i)  _assert_sbuf_state(__func__, (s), (i))
-#else
-#define        assert_sbuf_integrity(s) do { } while (0)
-#define        assert_sbuf_state(s, i)  do { } while (0)
-#endif
-
-static int
-sbuf_extendsize(int size)
-{
-       int newsize;
-
-       newsize = SBUF_MINEXTENDSIZE;
-       while (newsize < size) {
-               if (newsize < (int)SBUF_MAXEXTENDSIZE)
-                       newsize *= 2;
-               else
-                       newsize += SBUF_MAXEXTENDINCR;
-       }
-
-       return (newsize);
-}
-
-
-/*
- * Extend an sbuf.
- */
-static int
-sbuf_extend(struct sbuf *s, int addlen)
-{
-       char *newbuf;
-       int newsize;
-
-       if (!SBUF_CANEXTEND(s))
-               return (-1);
-
-       newsize = sbuf_extendsize(s->s_size + addlen);
-       newbuf = (char *)SBMALLOC(newsize);
-       if (newbuf == NULL)
-               return (-1);
-       bcopy(s->s_buf, newbuf, s->s_size);
-       if (SBUF_ISDYNAMIC(s))
-               SBFREE(s->s_buf);
-       else
-               SBUF_SETFLAG(s, SBUF_DYNAMIC);
-       s->s_buf = newbuf;
-       s->s_size = newsize;
-       return (0);
-}
-
-/*
- * Initialize an sbuf.
- * If buf is non-NULL, it points to a static or already-allocated string
- * big enough to hold at least length characters.
- */
-struct sbuf *
-sbuf_new(struct sbuf *s, char *buf, int length, int flags)
-{
-       KASSERT(length >= 0,
-           ("attempt to create an sbuf of negative length (%d)", length));
-       KASSERT((flags & ~SBUF_USRFLAGMSK) == 0,
-           ("%s called with invalid flags", __func__));
-
-       flags &= SBUF_USRFLAGMSK;
-       if (s == NULL) {
-               s = (struct sbuf *)SBMALLOC(sizeof *s);
-               if (s == NULL)
-                       return (NULL);
-               bzero(s, sizeof *s);
-               s->s_flags = flags;
-               SBUF_SETFLAG(s, SBUF_DYNSTRUCT);
-       } else {
-               bzero(s, sizeof *s);
-               s->s_flags = flags;
-       }
-       s->s_size = length;
-       if (buf) {
-               s->s_buf = buf;
-               return (s);
-       }
-       if (flags & SBUF_AUTOEXTEND)
-               s->s_size = sbuf_extendsize(s->s_size);
-       s->s_buf = (char *)SBMALLOC(s->s_size);
-       if (s->s_buf == NULL) {
-               if (SBUF_ISDYNSTRUCT(s))
-                       SBFREE(s);
-               return (NULL);
-       }
-       SBUF_SETFLAG(s, SBUF_DYNAMIC);
-       return (s);
-}
-
-/*
- * Clear an sbuf and reset its position.
- */
-void
-sbuf_clear(struct sbuf *s)
-{
-       assert_sbuf_integrity(s);
-       /* don't care if it's finished or not */
-
-       SBUF_CLEARFLAG(s, SBUF_FINISHED);
-       SBUF_CLEARFLAG(s, SBUF_OVERFLOWED);
-       s->s_len = 0;
-}
-
-/*
- * Set the sbuf's end position to an arbitrary value.
- * Effectively truncates the sbuf at the new position.
- */
-int
-sbuf_setpos(struct sbuf *s, int pos)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       KASSERT(pos >= 0,
-           ("attempt to seek to a negative position (%d)", pos));
-       KASSERT(pos < s->s_size,
-           ("attempt to seek past end of sbuf (%d >= %d)", pos, s->s_size));
-
-       if (pos < 0 || pos > s->s_len)
-               return (-1);
-       s->s_len = pos;
-       return (0);
-}
-
-/*
- * Append a byte string to an sbuf.
- */
-int
-sbuf_bcat(struct sbuf *s, const void *buf, size_t len)
-{
-       const char *str = buf;
-
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-
-       for (; len; len--) {
-               if (!SBUF_HASROOM(s) && sbuf_extend(s, len) < 0)
-                       break;
-               s->s_buf[s->s_len++] = *str++;
-       }
-       if (len) {
-               SBUF_SETFLAG(s, SBUF_OVERFLOWED);
-               return (-1);
-       }
-       return (0);
-}
-
-/*
- * Copy a byte string into an sbuf.
- */
-int
-sbuf_bcpy(struct sbuf *s, const void *buf, size_t len)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       sbuf_clear(s);
-       return (sbuf_bcat(s, buf, len));
-}
-
-/*
- * Append a string to an sbuf.
- */
-int
-sbuf_cat(struct sbuf *s, const char *str)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-
-       while (*str) {
-               if (!SBUF_HASROOM(s) && sbuf_extend(s, strlen(str)) < 0)
-                       break;
-               s->s_buf[s->s_len++] = *str++;
-       }
-       if (*str) {
-               SBUF_SETFLAG(s, SBUF_OVERFLOWED);
-               return (-1);
-       }
-       return (0);
-}
-
-/*
- * Copy a string into an sbuf.
- */
-int
-sbuf_cpy(struct sbuf *s, const char *str)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       sbuf_clear(s);
-       return (sbuf_cat(s, str));
-}
-
-/*
- * Format the given argument list and append the resulting string to an sbuf.
- */
-int
-sbuf_vprintf(struct sbuf *s, const char *fmt, va_list ap)
-{
-       va_list ap_copy;
-       int len;
-
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       KASSERT(fmt != NULL,
-           ("%s called with a NULL format string", __func__));
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-
-       do {
-               va_copy(ap_copy, ap);
-               len = vsnprintf(&s->s_buf[s->s_len], SBUF_FREESPACE(s) + 1,
-                   fmt, ap_copy);
-               va_end(ap_copy);
-       } while (len > SBUF_FREESPACE(s) &&
-           sbuf_extend(s, len - SBUF_FREESPACE(s)) == 0);
-
-       /*
-        * s->s_len is the length of the string, without the terminating nul.
-        * When updating s->s_len, we must subtract 1 from the length that
-        * we passed into vsnprintf() because that length includes the
-        * terminating nul.
-        *
-        * vsnprintf() returns the amount that would have been copied,
-        * given sufficient space, hence the min() calculation below.
-        */
-       s->s_len += min(len, SBUF_FREESPACE(s));
-       if (!SBUF_HASROOM(s) && !SBUF_CANEXTEND(s))
-               SBUF_SETFLAG(s, SBUF_OVERFLOWED);
-
-       KASSERT(s->s_len < s->s_size,
-           ("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-       return (0);
-}
-
-/*
- * Format the given arguments and append the resulting string to an sbuf.
- */
-int
-sbuf_printf(struct sbuf *s, const char *fmt, ...)
-{
-       va_list ap;
-       int result;
-
-       va_start(ap, fmt);
-       result = sbuf_vprintf(s, fmt, ap);
-       va_end(ap);
-       return(result);
-}
-
-/*
- * Append a character to an sbuf.
- */
-int
-sbuf_putc(struct sbuf *s, int c)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-
-       if (!SBUF_HASROOM(s) && sbuf_extend(s, 1) < 0) {
-               SBUF_SETFLAG(s, SBUF_OVERFLOWED);
-               return (-1);
-       }
-       if (c != '\0')
-           s->s_buf[s->s_len++] = c;
-       return (0);
-}
-
-/*
- * Trim whitespace characters from end of an sbuf.
- */
-int
-sbuf_trim(struct sbuf *s)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-
-       while (s->s_len && isspace(s->s_buf[s->s_len-1]))
-               --s->s_len;
-
-       return (0);
-}
-
-/*
- * Check if an sbuf overflowed
- */
-int
-sbuf_overflowed(struct sbuf *s)
-{
-    return SBUF_HASOVERFLOWED(s);
-}
-
-/*
- * Finish off an sbuf.
- */
-void
-sbuf_finish(struct sbuf *s)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, 0);
-
-       s->s_buf[s->s_len] = '\0';
-       SBUF_CLEARFLAG(s, SBUF_OVERFLOWED);
-       SBUF_SETFLAG(s, SBUF_FINISHED);
-}
-
-/*
- * Return a pointer to the sbuf data.
- */
-char *
-sbuf_data(struct sbuf *s)
-{
-       assert_sbuf_integrity(s);
-       assert_sbuf_state(s, SBUF_FINISHED);
-
-       return s->s_buf;
-}
-
-/*
- * Return the length of the sbuf data.
- */
-int
-sbuf_len(struct sbuf *s)
-{
-       assert_sbuf_integrity(s);
-       /* don't care if it's finished or not */
-
-       if (SBUF_HASOVERFLOWED(s))
-               return (-1);
-       return s->s_len;
-}
-
-/*
- * Clear an sbuf, free its buffer if necessary.
- */
-void
-sbuf_delete(struct sbuf *s)
-{
-       int isdyn;
-
-       assert_sbuf_integrity(s);
-       /* don't care if it's finished or not */
-
-       if (SBUF_ISDYNAMIC(s))
-               SBFREE(s->s_buf);
-       isdyn = SBUF_ISDYNSTRUCT(s);
-       bzero(s, sizeof *s);
-       if (isdyn)
-               SBFREE(s);
-}
-
-/*
- * Check if an sbuf has been finished.
- */
-int
-sbuf_done(struct sbuf *s)
-{
-
-       return(SBUF_ISFINISHED(s));
-}
index fbd6c6e6385bf1570b95a8e80ee49dd1d00fd58f..2e331b1d6be6df2675ffa33d11defc3dce91a483 100644 (file)
@@ -9,6 +9,7 @@ libvarnish_la_SOURCES = \
        binary_heap.c \
        cli.c \
        cli_common.c \
-       time.c
+       time.c \
+       vsb.c
 
 libvarnish_la_CFLAGS = -include config.h
index 14aa3cf2911e68e2661708df0d4f41d818a57efc..b0b12ec4526249e1bb832723ea3e1e4a32b76d80 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <sys/wait.h>
 
-#include "sbuf.h"
+#include "vsb.h"
 
 #include "cli.h"
 #include "cli_priv.h"
@@ -29,7 +29,7 @@ cli_out(struct cli *cli, const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       sbuf_vprintf(cli->sb, fmt, ap);
+       vsb_vprintf(cli->sb, fmt, ap);
        va_end(ap);
 }
 
@@ -59,10 +59,10 @@ cli_writeres(int fd, struct cli *cli)
                                         */
 
        i = snprintf(res, sizeof res,
-           "%-3d %-8d\n", cli->result, sbuf_len(cli->sb));
+           "%-3d %-8d\n", cli->result, vsb_len(cli->sb));
        assert(i == CLI_LINE0_LEN);
        iov[0].iov_base = (void*)(uintptr_t)res;
-       iov[1].iov_base = (void*)(uintptr_t)sbuf_data(cli->sb);
+       iov[1].iov_base = (void*)(uintptr_t)vsb_data(cli->sb);
        iov[2].iov_base = (void*)(uintptr_t)"\n";
        for (l = i = 0; i < 3; i++) {
                iov[i].iov_len = strlen(iov[i].iov_base);
similarity index 68%
rename from varnish-cache/lib/libsbuf/sbuf.3
rename to varnish-cache/lib/libvarnish/vsb.3
index f0ceb680df4dbdb5d6f517377267ea6fd25da34e..fede1d09b62dfb510c5899bf83a0a6ad6acb38bc 100644 (file)
 .\" SUCH DAMAGE.
 .\"
 .\" $Id$
-.\" $FreeBSD: src/share/man/man9/sbuf.9,v 1.25 2005/12/23 11:49:52 phk Exp $
+.\" $FreeBSD: src/share/man/man9/vsb.9,v 1.25 2005/12/23 11:49:52 phk Exp $
 .\"
 .Dd March 14, 2006
-.Dt SBUF 3
+.Dt VSB 3
 .Os
 .Sh NAME
-.Nm sbuf_new ,
-.Nm sbuf_clear ,
-.Nm sbuf_setpos ,
-.Nm sbuf_bcat ,
-.Nm sbuf_bcpy ,
-.Nm sbuf_cat ,
-.Nm sbuf_cpy ,
-.Nm sbuf_printf ,
-.Nm sbuf_vprintf ,
-.Nm sbuf_putc ,
-.Nm sbuf_trim ,
-.Nm sbuf_overflowed ,
-.Nm sbuf_finish ,
-.Nm sbuf_data ,
-.Nm sbuf_len ,
-.Nm sbuf_done ,
-.Nm sbuf_delete
+.Nm vsb_new ,
+.Nm vsb_clear ,
+.Nm vsb_setpos ,
+.Nm vsb_bcat ,
+.Nm vsb_bcpy ,
+.Nm vsb_cat ,
+.Nm vsb_cpy ,
+.Nm vsb_printf ,
+.Nm vsb_vprintf ,
+.Nm vsb_putc ,
+.Nm vsb_trim ,
+.Nm vsb_overflowed ,
+.Nm vsb_finish ,
+.Nm vsb_data ,
+.Nm vsb_len ,
+.Nm vsb_done ,
+.Nm vsb_delete
 .Nd safe string formatting
 .Sh LIBRARY
-.Lb libsbuf
+.Lb libvarnish
 .Sh SYNOPSIS
-.In sbuf.h
-.Ft struct sbuf *
-.Fn sbuf_new "struct sbuf *s" "char *buf" "int length" "int flags"
+.In vsb.h
+.Ft struct vsb *
+.Fn vsb_new "struct vsb *s" "char *buf" "int length" "int flags"
 .Ft void
-.Fn sbuf_clear "struct sbuf *s"
+.Fn vsb_clear "struct vsb *s"
 .Ft int
-.Fn sbuf_setpos "struct sbuf *s" "int pos"
+.Fn vsb_setpos "struct vsb *s" "int pos"
 .Ft int
-.Fn sbuf_bcat "struct sbuf *s" "const void *buf" "size_t len"
+.Fn vsb_bcat "struct vsb *s" "const void *buf" "size_t len"
 .Ft int
-.Fn sbuf_bcpy "struct sbuf *s" "const void *buf" "size_t len"
+.Fn vsb_bcpy "struct vsb *s" "const void *buf" "size_t len"
 .Ft int
-.Fn sbuf_cat "struct sbuf *s" "const char *str"
+.Fn vsb_cat "struct vsb *s" "const char *str"
 .Ft int
-.Fn sbuf_cpy "struct sbuf *s" "const char *str"
+.Fn vsb_cpy "struct vsb *s" "const char *str"
 .Ft int
-.Fn sbuf_printf "struct sbuf *s" "const char *fmt" "..."
+.Fn vsb_printf "struct vsb *s" "const char *fmt" "..."
 .Ft int
-.Fn sbuf_vprintf "struct sbuf *s" "const char *fmt" "va_list ap"
+.Fn vsb_vprintf "struct vsb *s" "const char *fmt" "va_list ap"
 .Ft int
-.Fn sbuf_putc "struct sbuf *s" "int c"
+.Fn vsb_putc "struct vsb *s" "int c"
 .Ft int
-.Fn sbuf_trim "struct sbuf *s"
+.Fn vsb_trim "struct vsb *s"
 .Ft int
-.Fn sbuf_overflowed "struct sbuf *s"
+.Fn vsb_overflowed "struct vsb *s"
 .Ft void
-.Fn sbuf_finish "struct sbuf *s"
+.Fn vsb_finish "struct vsb *s"
 .Ft char *
-.Fn sbuf_data "struct sbuf *s"
+.Fn vsb_data "struct vsb *s"
 .Ft int
-.Fn sbuf_len "struct sbuf *s"
+.Fn vsb_len "struct vsb *s"
 .Ft int
-.Fn sbuf_done "struct sbuf *s"
+.Fn vsb_done "struct vsb *s"
 .Ft void
-.Fn sbuf_delete "struct sbuf *s"
+.Fn vsb_delete "struct vsb *s"
 .Sh DESCRIPTION
 The
-.Nm sbuf
+.Nm vsb
 family of functions allows one to safely allocate, construct and
 release bounded null-terminated strings in kernel space.
 Instead of arrays of characters, these functions operate on structures
 called
-.Fa sbufs ,
+.Fa vsbs ,
 defined in
-.In sys/sbuf.h .
+.In sys/vsb.h .
 .Pp
 The
-.Fn sbuf_new
+.Fn vsb_new
 function initializes the
-.Fa sbuf
+.Fa vsb
 pointed to by its first argument.
 If that pointer is
 .Dv NULL ,
-.Fn sbuf_new
+.Fn vsb_new
 allocates a
-.Vt struct sbuf
+.Vt struct vsb
 using
 .Xr malloc 9 .
 The
@@ -114,7 +114,7 @@ The
 argument is a pointer to a buffer in which to store the actual string;
 if it is
 .Dv NULL ,
-.Fn sbuf_new
+.Fn vsb_new
 will allocate one using
 .Xr malloc 9 .
 The
@@ -123,11 +123,11 @@ is the initial size of the storage buffer.
 The fourth argument,
 .Fa flags ,
 may be comprised of the following flags:
-.Bl -tag -width ".Dv SBUF_AUTOEXTEND"
-.It Dv SBUF_FIXEDLEN
+.Bl -tag -width ".Dv VSB_AUTOEXTEND"
+.It Dv VSB_FIXEDLEN
 The storage buffer is fixed at its initial size.
-Attempting to extend the sbuf beyond this size results in an overflow condition.
-.It Dv SBUF_AUTOEXTEND
+Attempting to extend the vsb beyond this size results in an overflow condition.
+.It Dv VSB_AUTOEXTEND
 This indicates that the storage buffer may be extended as necessary, so long
 as resources allow, to hold additional data.
 .El
@@ -140,175 +140,175 @@ it must point to an array of at least
 .Fa length
 characters.
 The result of accessing that array directly while it is in use by the
-sbuf is undefined.
+vsb is undefined.
 .Pp
 The
-.Fn sbuf_delete
+.Fn vsb_delete
 function clears the
-.Fa sbuf
+.Fa vsb
 and frees any memory allocated for it.
 There must be a call to
-.Fn sbuf_delete
+.Fn vsb_delete
 for every call to
-.Fn sbuf_new .
-Any attempt to access the sbuf after it has been deleted will fail.
+.Fn vsb_new .
+Any attempt to access the vsb after it has been deleted will fail.
 .Pp
 The
-.Fn sbuf_clear
+.Fn vsb_clear
 function invalidates the contents of the
-.Fa sbuf
+.Fa vsb
 and resets its position to zero.
 .Pp
 The
-.Fn sbuf_setpos
+.Fn vsb_setpos
 function sets the
-.Fa sbuf Ns 's
+.Fa vsb Ns 's
 end position to
 .Fa pos ,
 which is a value between zero and one less than the size of the
 storage buffer.
-This effectively truncates the sbuf at the new position.
+This effectively truncates the vsb at the new position.
 .Pp
 The
-.Fn sbuf_bcat
+.Fn vsb_bcat
 function appends the first
 .Fa len
 bytes from the buffer
 .Fa buf
 to the
-.Fa sbuf .
+.Fa vsb .
 .Pp
 The
-.Fn sbuf_bcpy
+.Fn vsb_bcpy
 function replaces the contents of the
-.Fa sbuf
+.Fa vsb
 with the first
 .Fa len
 bytes from the buffer
 .Fa buf .
 .Pp
 The
-.Fn sbuf_cat
+.Fn vsb_cat
 function appends the NUL-terminated string
 .Fa str
 to the
-.Fa sbuf
+.Fa vsb
 at the current position.
 .Pp
 The
-.Fn sbuf_cpy
+.Fn vsb_cpy
 function replaces the contents of the
-.Fa sbuf
+.Fa vsb
 with those of the NUL-terminated string
 .Fa str .
 This is equivalent to calling
-.Fn sbuf_cat
+.Fn vsb_cat
 with a fresh
-.Fa sbuf
+.Fa vsb
 or one which position has been reset to zero with
-.Fn sbuf_clear
+.Fn vsb_clear
 or
-.Fn sbuf_setpos .
+.Fn vsb_setpos .
 .Pp
 The
-.Fn sbuf_printf
+.Fn vsb_printf
 function formats its arguments according to the format string pointed
 to by
 .Fa fmt
 and appends the resulting string to the
-.Fa sbuf
+.Fa vsb
 at the current position.
 .Pp
 The
-.Fn sbuf_vprintf
+.Fn vsb_vprintf
 function behaves the same as
-.Fn sbuf_printf
+.Fn vsb_printf
 except that the arguments are obtained from the variable-length argument list
 .Fa ap .
 .Pp
 The
-.Fn sbuf_putc
+.Fn vsb_putc
 function appends the character
 .Fa c
 to the
-.Fa sbuf
+.Fa vsb
 at the current position.
 .Pp
 The
-.Fn sbuf_trim
+.Fn vsb_trim
 function removes trailing whitespace from the
-.Fa sbuf .
+.Fa vsb .
 .Pp
 The
-.Fn sbuf_overflowed
+.Fn vsb_overflowed
 function returns a non-zero value if the
-.Fa sbuf
+.Fa vsb
 overflowed.
 .Pp
 The
-.Fn sbuf_finish
+.Fn vsb_finish
 function null-terminates the
-.Fa sbuf
+.Fa vsb
 and marks it as finished, which means that it may no longer be
 modified using
-.Fn sbuf_setpos ,
-.Fn sbuf_cat ,
-.Fn sbuf_cpy ,
-.Fn sbuf_printf
+.Fn vsb_setpos ,
+.Fn vsb_cat ,
+.Fn vsb_cpy ,
+.Fn vsb_printf
 or
-.Fn sbuf_putc .
+.Fn vsb_putc .
 .Pp
 The
-.Fn sbuf_data
+.Fn vsb_data
 and
-.Fn sbuf_len
+.Fn vsb_len
 functions return the actual string and its length, respectively;
-.Fn sbuf_data
+.Fn vsb_data
 only works on a finished
-.Fa sbuf .
-.Fn sbuf_done
-returns non-zero if the sbuf is finished.
+.Fa vsb .
+.Fn vsb_done
+returns non-zero if the vsb is finished.
 .Sh NOTES
 If an operation caused an
-.Fa sbuf
+.Fa vsb
 to overflow, most subsequent operations on it will fail until the
-.Fa sbuf
+.Fa vsb
 is finished using
-.Fn sbuf_finish
+.Fn vsb_finish
 or reset using
-.Fn sbuf_clear ,
+.Fn vsb_clear ,
 or its position is reset to a value between 0 and one less than the
 size of its storage buffer using
-.Fn sbuf_setpos ,
+.Fn vsb_setpos ,
 or it is reinitialized to a sufficiently short string using
-.Fn sbuf_cpy .
+.Fn vsb_cpy .
 .Sh RETURN VALUES
-.Fn sbuf_new
+.Fn vsb_new
 returns
 .Dv NULL
 if it failed to allocate a storage buffer, and a pointer to the new
-.Fa sbuf
+.Fa vsb
 otherwise.
 .Pp
-.Fn sbuf_setpos
+.Fn vsb_setpos
 returns \-1 if
 .Fa pos
 was invalid, and zero otherwise.
 .Pp
-.Fn sbuf_cat ,
-.Fn sbuf_cpy ,
-.Fn sbuf_printf ,
-.Fn sbuf_putc ,
+.Fn vsb_cat ,
+.Fn vsb_cpy ,
+.Fn vsb_printf ,
+.Fn vsb_putc ,
 and
-.Fn sbuf_trim
+.Fn vsb_trim
 all return \-1 if the buffer overflowed, and zero otherwise.
 .Pp
-.Fn sbuf_overflowed
+.Fn vsb_overflowed
 returns a non-zero value if the buffer overflowed, and zero otherwise.
 .Pp
-.Fn sbuf_data
+.Fn vsb_data
 and
-.Fn sbuf_len
+.Fn vsb_len
 return
 .Dv NULL
 and \-1, respectively, if the buffer overflowed.
@@ -318,13 +318,13 @@ and \-1, respectively, if the buffer overflowed.
 .Xr strcpy 3
 .Sh HISTORY
 The
-.Nm sbuf
+.Nm vsb
 family of functions first appeared in
 .Fx 4.4 .
 .Sh AUTHORS
 .An -nosplit
 The
-.Nm sbuf
+.Nm vsb
 family of functions was designed by
 .An Poul-Henning Kamp Aq phk@FreeBSD.org
 and implemented by
diff --git a/varnish-cache/lib/libvarnish/vsb.c b/varnish-cache/lib/libvarnish/vsb.c
new file mode 100644 (file)
index 0000000..03aace7
--- /dev/null
@@ -0,0 +1,468 @@
+/*-
+ * Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Coïdan Smørgrav
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ * $FreeBSD: src/sys/kern/subr_sbuf.c,v 1.30 2005/12/23 11:49:53 phk Exp $
+ */
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "vsb.h"
+
+#define        KASSERT(e, m)
+#define        SBMALLOC(size)          malloc(size)
+#define        SBFREE(buf)             free(buf)
+#define        min(x,y)                (x < y ? x : y)
+
+/*
+ * Predicates
+ */
+#define        VSB_ISDYNAMIC(s)        ((s)->s_flags & VSB_DYNAMIC)
+#define        VSB_ISDYNSTRUCT(s)      ((s)->s_flags & VSB_DYNSTRUCT)
+#define        VSB_ISFINISHED(s)       ((s)->s_flags & VSB_FINISHED)
+#define        VSB_HASOVERFLOWED(s)    ((s)->s_flags & VSB_OVERFLOWED)
+#define        VSB_HASROOM(s)          ((s)->s_len < (s)->s_size - 1)
+#define        VSB_FREESPACE(s)        ((s)->s_size - (s)->s_len - 1)
+#define        VSB_CANEXTEND(s)        ((s)->s_flags & VSB_AUTOEXTEND)
+
+/*
+ * Set / clear flags
+ */
+#define        VSB_SETFLAG(s, f)       do { (s)->s_flags |= (f); } while (0)
+#define        VSB_CLEARFLAG(s, f)     do { (s)->s_flags &= ~(f); } while (0)
+
+#define        VSB_MINEXTENDSIZE       16              /* Should be power of 2. */
+#define        VSB_MAXEXTENDSIZE       4096
+#define        VSB_MAXEXTENDINCR       4096
+
+/*
+ * Debugging support
+ */
+#if !defined(NDEBUG)
+static void
+_vsb_assert_integrity(const char *fun, struct vsb *s)
+{
+       KASSERT(s != NULL,
+           ("%s called with a NULL vsb pointer", fun));
+       KASSERT(s->s_buf != NULL,
+           ("%s called with uninitialized or corrupt vsb", fun));
+       KASSERT(s->s_len < s->s_size,
+           ("wrote past end of vsb (%d >= %d)", s->s_len, s->s_size));
+}
+
+static void
+_vsb_assert_state(const char *fun, struct vsb *s, int state)
+{
+       KASSERT((s->s_flags & VSB_FINISHED) == state,
+           ("%s called with %sfinished or corrupt vsb", fun,
+           (state ? "un" : "")));
+}
+#define        vsb_assert_integrity(s) _vsb_assert_integrity(__func__, (s))
+#define        vsb_assert_state(s, i)   _vsb_assert_state(__func__, (s), (i))
+#else
+#define        vsb_assert_integrity(s) do { } while (0)
+#define        vsb_assert_state(s, i)   do { } while (0)
+#endif
+
+static int
+vsb_extendsize(int size)
+{
+       int newsize;
+
+       newsize = VSB_MINEXTENDSIZE;
+       while (newsize < size) {
+               if (newsize < (int)VSB_MAXEXTENDSIZE)
+                       newsize *= 2;
+               else
+                       newsize += VSB_MAXEXTENDINCR;
+       }
+
+       return (newsize);
+}
+
+
+/*
+ * Extend an vsb.
+ */
+static int
+vsb_extend(struct vsb *s, int addlen)
+{
+       char *newbuf;
+       int newsize;
+
+       if (!VSB_CANEXTEND(s))
+               return (-1);
+
+       newsize = vsb_extendsize(s->s_size + addlen);
+       newbuf = (char *)SBMALLOC(newsize);
+       if (newbuf == NULL)
+               return (-1);
+       bcopy(s->s_buf, newbuf, s->s_size);
+       if (VSB_ISDYNAMIC(s))
+               SBFREE(s->s_buf);
+       else
+               VSB_SETFLAG(s, VSB_DYNAMIC);
+       s->s_buf = newbuf;
+       s->s_size = newsize;
+       return (0);
+}
+
+/*
+ * Initialize an vsb.
+ * If buf is non-NULL, it points to a static or already-allocated string
+ * big enough to hold at least length characters.
+ */
+struct vsb *
+vsb_new(struct vsb *s, char *buf, int length, int flags)
+{
+       KASSERT(length >= 0,
+           ("attempt to create an vsb of negative length (%d)", length));
+       KASSERT((flags & ~VSB_USRFLAGMSK) == 0,
+           ("%s called with invalid flags", __func__));
+
+       flags &= VSB_USRFLAGMSK;
+       if (s == NULL) {
+               s = (struct vsb *)SBMALLOC(sizeof *s);
+               if (s == NULL)
+                       return (NULL);
+               bzero(s, sizeof *s);
+               s->s_flags = flags;
+               VSB_SETFLAG(s, VSB_DYNSTRUCT);
+       } else {
+               bzero(s, sizeof *s);
+               s->s_flags = flags;
+       }
+       s->s_size = length;
+       if (buf) {
+               s->s_buf = buf;
+               return (s);
+       }
+       if (flags & VSB_AUTOEXTEND)
+               s->s_size = vsb_extendsize(s->s_size);
+       s->s_buf = (char *)SBMALLOC(s->s_size);
+       if (s->s_buf == NULL) {
+               if (VSB_ISDYNSTRUCT(s))
+                       SBFREE(s);
+               return (NULL);
+       }
+       VSB_SETFLAG(s, VSB_DYNAMIC);
+       return (s);
+}
+
+/*
+ * Clear an vsb and reset its position.
+ */
+void
+vsb_clear(struct vsb *s)
+{
+       vsb_assert_integrity(s);
+       /* don't care if it's finished or not */
+
+       VSB_CLEARFLAG(s, VSB_FINISHED);
+       VSB_CLEARFLAG(s, VSB_OVERFLOWED);
+       s->s_len = 0;
+}
+
+/*
+ * Set the vsb's end position to an arbitrary value.
+ * Effectively truncates the vsb at the new position.
+ */
+int
+vsb_setpos(struct vsb *s, int pos)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       KASSERT(pos >= 0,
+           ("attempt to seek to a negative position (%d)", pos));
+       KASSERT(pos < s->s_size,
+           ("attempt to seek past end of vsb (%d >= %d)", pos, s->s_size));
+
+       if (pos < 0 || pos > s->s_len)
+               return (-1);
+       s->s_len = pos;
+       return (0);
+}
+
+/*
+ * Append a byte string to an vsb.
+ */
+int
+vsb_bcat(struct vsb *s, const void *buf, size_t len)
+{
+       const char *str = buf;
+
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+
+       for (; len; len--) {
+               if (!VSB_HASROOM(s) && vsb_extend(s, len) < 0)
+                       break;
+               s->s_buf[s->s_len++] = *str++;
+       }
+       if (len) {
+               VSB_SETFLAG(s, VSB_OVERFLOWED);
+               return (-1);
+       }
+       return (0);
+}
+
+/*
+ * Copy a byte string into an vsb.
+ */
+int
+vsb_bcpy(struct vsb *s, const void *buf, size_t len)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       vsb_clear(s);
+       return (vsb_bcat(s, buf, len));
+}
+
+/*
+ * Append a string to an vsb.
+ */
+int
+vsb_cat(struct vsb *s, const char *str)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+
+       while (*str) {
+               if (!VSB_HASROOM(s) && vsb_extend(s, strlen(str)) < 0)
+                       break;
+               s->s_buf[s->s_len++] = *str++;
+       }
+       if (*str) {
+               VSB_SETFLAG(s, VSB_OVERFLOWED);
+               return (-1);
+       }
+       return (0);
+}
+
+/*
+ * Copy a string into an vsb.
+ */
+int
+vsb_cpy(struct vsb *s, const char *str)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       vsb_clear(s);
+       return (vsb_cat(s, str));
+}
+
+/*
+ * Format the given argument list and append the resulting string to an vsb.
+ */
+int
+vsb_vprintf(struct vsb *s, const char *fmt, va_list ap)
+{
+       va_list ap_copy;
+       int len;
+
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       KASSERT(fmt != NULL,
+           ("%s called with a NULL format string", __func__));
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+
+       do {
+               va_copy(ap_copy, ap);
+               len = vsnprintf(&s->s_buf[s->s_len], VSB_FREESPACE(s) + 1,
+                   fmt, ap_copy);
+               va_end(ap_copy);
+       } while (len > VSB_FREESPACE(s) &&
+           vsb_extend(s, len - VSB_FREESPACE(s)) == 0);
+
+       /*
+        * s->s_len is the length of the string, without the terminating nul.
+        * When updating s->s_len, we must subtract 1 from the length that
+        * we passed into vsnprintf() because that length includes the
+        * terminating nul.
+        *
+        * vsnprintf() returns the amount that would have been copied,
+        * given sufficient space, hence the min() calculation below.
+        */
+       s->s_len += min(len, VSB_FREESPACE(s));
+       if (!VSB_HASROOM(s) && !VSB_CANEXTEND(s))
+               VSB_SETFLAG(s, VSB_OVERFLOWED);
+
+       KASSERT(s->s_len < s->s_size,
+           ("wrote past end of vsb (%d >= %d)", s->s_len, s->s_size));
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+       return (0);
+}
+
+/*
+ * Format the given arguments and append the resulting string to an vsb.
+ */
+int
+vsb_printf(struct vsb *s, const char *fmt, ...)
+{
+       va_list ap;
+       int result;
+
+       va_start(ap, fmt);
+       result = vsb_vprintf(s, fmt, ap);
+       va_end(ap);
+       return(result);
+}
+
+/*
+ * Append a character to an vsb.
+ */
+int
+vsb_putc(struct vsb *s, int c)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+
+       if (!VSB_HASROOM(s) && vsb_extend(s, 1) < 0) {
+               VSB_SETFLAG(s, VSB_OVERFLOWED);
+               return (-1);
+       }
+       if (c != '\0')
+           s->s_buf[s->s_len++] = c;
+       return (0);
+}
+
+/*
+ * Trim whitespace characters from end of an vsb.
+ */
+int
+vsb_trim(struct vsb *s)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+
+       while (s->s_len && isspace(s->s_buf[s->s_len-1]))
+               --s->s_len;
+
+       return (0);
+}
+
+/*
+ * Check if an vsb overflowed
+ */
+int
+vsb_overflowed(struct vsb *s)
+{
+    return VSB_HASOVERFLOWED(s);
+}
+
+/*
+ * Finish off an vsb.
+ */
+void
+vsb_finish(struct vsb *s)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, 0);
+
+       s->s_buf[s->s_len] = '\0';
+       VSB_CLEARFLAG(s, VSB_OVERFLOWED);
+       VSB_SETFLAG(s, VSB_FINISHED);
+}
+
+/*
+ * Return a pointer to the vsb data.
+ */
+char *
+vsb_data(struct vsb *s)
+{
+       vsb_assert_integrity(s);
+       vsb_assert_state(s, VSB_FINISHED);
+
+       return s->s_buf;
+}
+
+/*
+ * Return the length of the vsb data.
+ */
+int
+vsb_len(struct vsb *s)
+{
+       vsb_assert_integrity(s);
+       /* don't care if it's finished or not */
+
+       if (VSB_HASOVERFLOWED(s))
+               return (-1);
+       return s->s_len;
+}
+
+/*
+ * Clear an vsb, free its buffer if necessary.
+ */
+void
+vsb_delete(struct vsb *s)
+{
+       int isdyn;
+
+       vsb_assert_integrity(s);
+       /* don't care if it's finished or not */
+
+       if (VSB_ISDYNAMIC(s))
+               SBFREE(s->s_buf);
+       isdyn = VSB_ISDYNSTRUCT(s);
+       bzero(s, sizeof *s);
+       if (isdyn)
+               SBFREE(s);
+}
+
+/*
+ * Check if an vsb has been finished.
+ */
+int
+vsb_done(struct vsb *s)
+{
+
+       return(VSB_ISFINISHED(s));
+}
index 13ba8fe16b294e82b14cb8106061b0e97f40b485..5e0a52a8b57b6d6749de379dc63de29878bf24b9 100644 (file)
@@ -12,7 +12,7 @@
 #include <netdb.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -37,10 +37,10 @@ vcc_Cond_Ip(struct var *vp, struct tokenlist *tl)
                vcc_NextToken(tl);
                break;
        default:
-               sbuf_printf(tl->sb, "Illegal condition ");
+               vsb_printf(tl->sb, "Illegal condition ");
                vcc_ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, " on IP number variable\n");
-               sbuf_printf(tl->sb, "  only '==', '!=' and '~' are legal\n");
+               vsb_printf(tl->sb, " on IP number variable\n");
+               vsb_printf(tl->sb, "  only '==', '!=' and '~' are legal\n");
                vcc_ErrWhere(tl, tl->t);
                break;
        }
index 2fca8e96cb1114c86354df1c5726df660d4936d2..576ea6b1b7484c8f8cba15d23ece248f455e56d2 100644 (file)
@@ -45,7 +45,7 @@
 #include <stdio.h>
 #include <printf.h>
 #include <stdarg.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <stdlib.h>
 #include <string.h>
 #include <queue.h>
@@ -88,7 +88,7 @@ const char *vcc_default_vcl_b, *vcc_default_vcl_e;
 } while (0)
        
 /*--------------------------------------------------------------------
- * Printf output to the two sbufs, possibly indented
+ * Printf output to the two vsbs, possibly indented
  */
 
 void
@@ -97,9 +97,9 @@ Fh(struct tokenlist *tl, int indent, const char *fmt, ...)
        va_list ap;
 
        if (indent)
-               sbuf_printf(tl->fh, "%*.*s", tl->indent, tl->indent, "");
+               vsb_printf(tl->fh, "%*.*s", tl->indent, tl->indent, "");
        va_start(ap, fmt);
-       sbuf_vprintf(tl->fh, fmt, ap);
+       vsb_vprintf(tl->fh, fmt, ap);
        va_end(ap);
 }
 
@@ -109,9 +109,9 @@ Fc(struct tokenlist *tl, int indent, const char *fmt, ...)
        va_list ap;
 
        if (indent)
-               sbuf_printf(tl->fc, "%*.*s", tl->indent, tl->indent, "");
+               vsb_printf(tl->fc, "%*.*s", tl->indent, tl->indent, "");
        va_start(ap, fmt);
-       sbuf_vprintf(tl->fc, fmt, ap);
+       vsb_vprintf(tl->fc, fmt, ap);
        va_end(ap);
 }
 
@@ -121,9 +121,9 @@ Fi(struct tokenlist *tl, int indent, const char *fmt, ...)
        va_list ap;
 
        if (indent)
-               sbuf_printf(tl->fi, "%*.*s", tl->indent, tl->indent, "");
+               vsb_printf(tl->fi, "%*.*s", tl->indent, tl->indent, "");
        va_start(ap, fmt);
-       sbuf_vprintf(tl->fi, fmt, ap);
+       vsb_vprintf(tl->fi, fmt, ap);
        va_end(ap);
 }
 
@@ -133,9 +133,9 @@ Ff(struct tokenlist *tl, int indent, const char *fmt, ...)
        va_list ap;
 
        if (indent)
-               sbuf_printf(tl->ff, "%*.*s", tl->indent, tl->indent, "");
+               vsb_printf(tl->ff, "%*.*s", tl->indent, tl->indent, "");
        va_start(ap, fmt);
-       sbuf_vprintf(tl->ff, fmt, ap);
+       vsb_vprintf(tl->ff, fmt, ap);
        va_end(ap);
 }
 
@@ -294,9 +294,9 @@ TimeUnit(struct tokenlist *tl)
        else if (vcc_IdIs(tl->t, "d"))
                sc = 60.0 * 60.0 * 24.0;
        else {
-               sbuf_printf(tl->sb, "Unknown time unit ");
+               vsb_printf(tl->sb, "Unknown time unit ");
                vcc_ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, ".  Legal are 's', 'm', 'h' and 'd'\n");
+               vsb_printf(tl->sb, ".  Legal are 's', 'm', 'h' and 'd'\n");
                vcc_ErrWhere(tl, tl->t);
                return (1.0);
        }
@@ -323,9 +323,9 @@ SizeUnit(struct tokenlist *tl)
        else if (vcc_IdIs(tl->t, "gb") || vcc_IdIs(tl->t, "Gb"))
                sc = 1024.0 * 1024.0 * 1024.0;
        else {
-               sbuf_printf(tl->sb, "Unknown size unit ");
+               vsb_printf(tl->sb, "Unknown size unit ");
                vcc_ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, ".  Legal are 'kb', 'mb' and 'gb'\n");
+               vsb_printf(tl->sb, ".  Legal are 'kb', 'mb' and 'gb'\n");
                vcc_ErrWhere(tl, tl->t);
                return (1.0);
        }
@@ -441,9 +441,9 @@ FindVar(struct tokenlist *tl, struct token *t, struct var *vl)
                        return (v);
                return (HeaderVar(tl, t, v));
        }
-       sbuf_printf(tl->sb, "Unknown variable ");
+       vsb_printf(tl->sb, "Unknown variable ");
        vcc_ErrToken(tl, t);
-       sbuf_cat(tl->sb, "\nAt: ");
+       vsb_cat(tl->sb, "\nAt: ");
        vcc_ErrWhere(tl, t);
        return (NULL);
 }
@@ -561,7 +561,7 @@ Cond_Int(struct var *vp, struct tokenlist *tl)
                        SizeVal(tl);
                        break;
                default:
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "No conditions available for variable '%s'\n",
                            vp->name);
                        vcc_ErrWhere(tl, tl->t);
@@ -570,10 +570,10 @@ Cond_Int(struct var *vp, struct tokenlist *tl)
                Fc(tl, 0, "\n");
                break;
        default:
-               sbuf_printf(tl->sb, "Illegal condition ");
+               vsb_printf(tl->sb, "Illegal condition ");
                vcc_ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, " on integer variable\n");
-               sbuf_printf(tl->sb,
+               vsb_printf(tl->sb, " on integer variable\n");
+               vsb_printf(tl->sb,
                    "  only '==', '!=', '<', '>', '<=' and '>=' are legal\n");
                vcc_ErrWhere(tl, tl->t);
                break;
@@ -618,7 +618,7 @@ Cond_2(struct tokenlist *tl)
                case TIME:      L(tl, Cond_Int(vp, tl)); break;
                /* XXX backend == */
                default:        
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "Variable '%s'"
                            " has no conditions that can be checked\n",
                            vp->name);
@@ -626,11 +626,11 @@ Cond_2(struct tokenlist *tl)
                        return;
                }
        } else {
-               sbuf_printf(tl->sb,
+               vsb_printf(tl->sb,
                    "Syntax error in condition, expected '(', '!' or"
                    " variable name, found ");
                vcc_ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, "\n");
+               vsb_printf(tl->sb, "\n");
                vcc_ErrWhere(tl, tl->t);
                return;
        }
@@ -820,9 +820,9 @@ Action(struct tokenlist *tl)
                                    u & 0xff);
                                break;
                        }
-                       sbuf_printf(tl->sb, "Illegal assignment operator ");
+                       vsb_printf(tl->sb, "Illegal assignment operator ");
                        vcc_ErrToken(tl, tl->t);
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            " only '=' is legal for IP numbers\n");
                        vcc_ErrWhere(tl, tl->t);
                        return;
@@ -835,21 +835,21 @@ Action(struct tokenlist *tl)
                                vcc_NextToken(tl);
                                break;
                        }
-                       sbuf_printf(tl->sb, "Illegal assignment operator ");
+                       vsb_printf(tl->sb, "Illegal assignment operator ");
                        vcc_ErrToken(tl, tl->t);
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            " only '=' is legal for backend\n");
                        vcc_ErrWhere(tl, tl->t);
                        return;
                default:
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "Assignments not possible for '%s'\n", vp->name);
                        vcc_ErrWhere(tl, tl->t);
                        return;
                }
                return;
        default:
-               sbuf_printf(tl->sb, "Expected action, 'if' or '}'\n");
+               vsb_printf(tl->sb, "Expected action, 'if' or '}'\n");
                vcc_ErrWhere(tl, at);
                return;
        }
@@ -881,7 +881,7 @@ Compound(struct tokenlist *tl)
                        Fc(tl, 1, "}\n");
                        return;
                case EOI:
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "End of input while in compound statement\n");
                        tl->err = 1;
                        return;
@@ -968,7 +968,7 @@ Backend(struct tokenlist *tl)
                        vcc_NextToken(tl);
                        break;
                default:
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "Assignments not possible for '%s'\n", vp->name);
                        vcc_ErrWhere(tl, tl->t);
                        return;
@@ -978,14 +978,14 @@ Backend(struct tokenlist *tl)
        }
        ExpectErr(tl, '}');
        if (t_host == NULL) {
-               sbuf_printf(tl->sb, "Backend '%T' has no hostname\n", t_be);
+               vsb_printf(tl->sb, "Backend '%T' has no hostname\n", t_be);
                vcc_ErrWhere(tl, tl->t);
                return;
        }
        host = EncString(t_host);
        ep = CheckHostPort(host, "80");
        if (ep != NULL) {
-               sbuf_printf(tl->sb, "Backend '%T': %s\n", t_be, ep);
+               vsb_printf(tl->sb, "Backend '%T': %s\n", t_be, ep);
                vcc_ErrWhere(tl, t_host);
                return;
        }
@@ -993,7 +993,7 @@ Backend(struct tokenlist *tl)
                port = EncString(t_port);
                ep = CheckHostPort(host, port);
                if (ep != NULL) {
-                       sbuf_printf(tl->sb, "Backend '%T': %s\n", t_be, ep);
+                       vsb_printf(tl->sb, "Backend '%T': %s\n", t_be, ep);
                        vcc_ErrWhere(tl, t_port);
                        return;
                }
@@ -1061,10 +1061,10 @@ Parse(struct tokenlist *tl)
                case EOI:
                        break;
                default:
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "Expected 'acl', 'sub' or 'backend', found ");
                        vcc_ErrToken(tl, tl->t);
-                       sbuf_printf(tl->sb, " at\n");
+                       vsb_printf(tl->sb, " at\n");
                        vcc_ErrWhere(tl, tl->t);
                        return;
                }
@@ -1120,11 +1120,11 @@ Consist_Decend(struct tokenlist *tl, struct proc *p, unsigned returns)
        struct proccall *pc;
 
        if (!p->exists) {
-               sbuf_printf(tl->sb, "Function %T does not exist\n", p->name);
+               vsb_printf(tl->sb, "Function %T does not exist\n", p->name);
                return (1);
        }
        if (p->active) {
-               sbuf_printf(tl->sb, "Function recurses on\n");
+               vsb_printf(tl->sb, "Function recurses on\n");
                vcc_ErrWhere(tl, p->name);
                return (1);
        }
@@ -1132,21 +1132,21 @@ Consist_Decend(struct tokenlist *tl, struct proc *p, unsigned returns)
        if (u) {
 #define VCL_RET_MAC(a, b, c, d) \
                if (u & VCL_RET_##b) { \
-                       sbuf_printf(tl->sb, "Illegal return for method\n"); \
+                       vsb_printf(tl->sb, "Illegal return for method\n"); \
                        vcc_ErrWhere(tl, p->returnt[d]); \
                } 
 #include "vcl_returns.h"
 #undef VCL_RET_MAC
-               sbuf_printf(tl->sb, "In function\n");
+               vsb_printf(tl->sb, "In function\n");
                vcc_ErrWhere(tl, p->name);
                return (1);
        }
        p->active = 1;
        TAILQ_FOREACH(pc, &p->calls, list) {
                if (Consist_Decend(tl, pc->p, returns)) {
-                       sbuf_printf(tl->sb, "\nCalled from\n");
+                       vsb_printf(tl->sb, "\nCalled from\n");
                        vcc_ErrWhere(tl, p->name);
-                       sbuf_printf(tl->sb, "at\n");
+                       vsb_printf(tl->sb, "at\n");
                        vcc_ErrWhere(tl, pc->t);
                        return (1);
                }
@@ -1172,7 +1172,7 @@ Consistency(struct tokenlist *tl)
                if (m->name == NULL) 
                        continue;
                if (Consist_Decend(tl, p, m->returns)) {
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "\nwhich is a %s method\n", m->name);
                        return (1);
                }
@@ -1180,7 +1180,7 @@ Consistency(struct tokenlist *tl)
        TAILQ_FOREACH(p, &tl->procs, list) {
                if (p->called)
                        continue;
-               sbuf_printf(tl->sb, "Function unused\n");
+               vsb_printf(tl->sb, "Function unused\n");
                vcc_ErrWhere(tl, p->name);
                return (1);
        }
@@ -1213,27 +1213,27 @@ CheckRefs(struct tokenlist *tl)
                        break;
                default:
                        ErrInternal(tl);
-                       sbuf_printf(tl->sb, "Ref ");
+                       vsb_printf(tl->sb, "Ref ");
                        vcc_ErrToken(tl, r->name);
-                       sbuf_printf(tl->sb, " has unknown type %d\n",
+                       vsb_printf(tl->sb, " has unknown type %d\n",
                            r->type);
                        continue;
                }
                if (r->defcnt == 0 && r->name->tok == METHOD) {
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "No definition for method %T\n", r->name);
                        continue;
                }
 
                if (r->defcnt == 0) {
-                       sbuf_printf(tl->sb,
+                       vsb_printf(tl->sb,
                            "Undefined %s %T, first reference:\n",
                            type, r->name);
                        vcc_ErrWhere(tl, r->name);
                        continue;
                } 
 
-               sbuf_printf(tl->sb, "Unused %s %T, defined:\n", type, r->name);
+               vsb_printf(tl->sb, "Unused %s %T, defined:\n", type, r->name);
                vcc_ErrWhere(tl, r->name);
        }
        return (nerr);
@@ -1289,8 +1289,8 @@ EmitInitFunc(struct tokenlist *tl)
 {
 
        Fc(tl, 0, "\nstatic void\nVGC_Init(void)\n{\n\n");
-       sbuf_finish(tl->fi);
-       sbuf_cat(tl->fc, sbuf_data(tl->fi));
+       vsb_finish(tl->fi);
+       vsb_cat(tl->fc, vsb_data(tl->fi));
        Fc(tl, 0, "}\n");
 }
 
@@ -1299,8 +1299,8 @@ EmitFiniFunc(struct tokenlist *tl)
 {
 
        Fc(tl, 0, "\nstatic void\nVGC_Fini(void)\n{\n\n");
-       sbuf_finish(tl->ff);
-       sbuf_cat(tl->fc, sbuf_data(tl->ff));
+       vsb_finish(tl->ff);
+       vsb_cat(tl->fc, vsb_data(tl->ff));
        Fc(tl, 0, "}\n");
 }
 
@@ -1335,7 +1335,7 @@ EmitStruct(struct tokenlist *tl)
 /*--------------------------------------------------------------------*/
 
 char *
-VCC_Compile(struct sbuf *sb, const char *b, const char *e)
+VCC_Compile(struct vsb *sb, const char *b, const char *e)
 {
        struct tokenlist tokens;
        struct ref *r;
@@ -1351,16 +1351,16 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e)
        TAILQ_INIT(&tokens.procs);
        tokens.sb = sb;
 
-       tokens.fc = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       tokens.fc = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(tokens.fc != NULL);
 
-       tokens.fh = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       tokens.fh = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(tokens.fh != NULL);
 
-       tokens.fi = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       tokens.fi = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(tokens.fi != NULL);
 
-       tokens.ff = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
+       tokens.ff = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
        assert(tokens.ff != NULL);
 
        Fh(&tokens, 0, "extern struct VCL_conf VCL_conf;\n");
@@ -1411,18 +1411,18 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e)
        vcl_output_lang_h(fo);
        fputs(vrt_obj_h, fo);
 
-       sbuf_finish(tokens.fh);
-       fputs(sbuf_data(tokens.fh), fo);
-       sbuf_delete(tokens.fh);
+       vsb_finish(tokens.fh);
+       fputs(vsb_data(tokens.fh), fo);
+       vsb_delete(tokens.fh);
 
-       sbuf_finish(tokens.fc);
-       fputs(sbuf_data(tokens.fc), fo);
-       sbuf_delete(tokens.fc);
+       vsb_finish(tokens.fc);
+       fputs(vsb_data(tokens.fc), fo);
+       vsb_delete(tokens.fc);
 
        i = pclose(fo);
        fprintf(stderr, "pclose=%d\n", i);
        if (i) {
-               sbuf_printf(sb, "Internal error: GCC returned 0x%04x\n", i);
+               vsb_printf(sb, "Internal error: GCC returned 0x%04x\n", i);
                unlink(of);
                free(of);
                return (NULL);
@@ -1448,7 +1448,7 @@ done:
 /*--------------------------------------------------------------------*/
 
 char *
-VCC_CompileFile(struct sbuf *sb, const char *fn)
+VCC_CompileFile(struct vsb *sb, const char *fn)
 {
        char *f, *r;
        int fd, i;
@@ -1456,7 +1456,7 @@ VCC_CompileFile(struct sbuf *sb, const char *fn)
 
        fd = open(fn, O_RDONLY);
        if (fd < 0) {
-               sbuf_printf(sb, "Cannot open file '%s': %s",
+               vsb_printf(sb, "Cannot open file '%s': %s",
                    fn, strerror(errno));
                return (NULL);
        }
index db5302589b188ccf004a6f75c959e71b90997b53..c13f92ff8424b4768fd1dac6e1c88432ed663462 100644 (file)
@@ -22,9 +22,9 @@ struct tokenlist {
        struct token            *t;
        int                     indent;
        unsigned                cnt;
-       struct sbuf             *fc, *fh, *fi, *ff;
+       struct vsb              *fc, *fh, *fi, *ff;
        TAILQ_HEAD(, ref)       refs;
-       struct sbuf             *sb;
+       struct vsb              *sb;
        int                     err;
        int                     nbackend;
        TAILQ_HEAD(, proc)      procs;
index 1777c6e8801be35501bc86eb263af1cc2b49ab97..721dad3513bfb538b9338c71f3798fceb95df707 100644 (file)
@@ -476,7 +476,7 @@ vcl_output_lang_h(FILE *f)
        fputs(" */\n", f);
        fputs("\n", f);
        fputs("struct sess;\n", f);
-       fputs("struct sbuf;\n", f);
+       fputs("struct vsb;\n", f);
        fputs("struct backend;\n", f);
        fputs("struct VCL_conf;\n", f);
        fputs("\n", f);
@@ -506,7 +506,7 @@ vcl_output_lang_h(FILE *f)
        fputs("void VRT_re_init(void **, const char *);\n", f);
        fputs("void VRT_re_fini(void *);\n", f);
        fputs("int VRT_re_match(const char *, void *re);\n", f);
-       fputs("int VRT_re_test(struct sbuf *, const char *);\n", f);
+       fputs("int VRT_re_test(struct vsb *, const char *);\n", f);
        fputs("\n", f);
        fputs("void VRT_count(struct sess *, unsigned);\n", f);
        fputs("int VRT_rewrite(const char *, const char *);\n", f);
index 6934bb0e4fd41d1badd4f34068afaa8fb28acfe7..4b2be1129aabdf2bb475a357a95aad616b1aa898 100644 (file)
@@ -14,7 +14,7 @@
 #include <stdio.h>
 #include <printf.h>
 #include <stdarg.h>
-#include <sbuf.h>
+#include <vsb.h>
 #include <stdlib.h>
 #include <string.h>
 #include <queue.h>
@@ -33,16 +33,16 @@ vcc_ErrToken(struct tokenlist *tl, struct token *t)
 {
 
        if (t->tok == EOI)
-               sbuf_printf(tl->sb, "end of input");
+               vsb_printf(tl->sb, "end of input");
        else
-               sbuf_printf(tl->sb, "'%T'", t);
+               vsb_printf(tl->sb, "'%T'", t);
 }
 
 void
 vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line)
 {
 
-       sbuf_printf(tl->sb, "VCL compiler internal error at %s():%u\n",
+       vsb_printf(tl->sb, "VCL compiler internal error at %s():%u\n",
            func, line);
        tl->err = 1;
 }
@@ -77,27 +77,27 @@ vcc_ErrWhere(struct tokenlist *tl, struct token *t)
                } else
                        pos++;
        }
-       sbuf_printf(tl->sb, "In %s Line %d Pos %d\n", f, lin, pos);
+       vsb_printf(tl->sb, "In %s Line %d Pos %d\n", f, lin, pos);
        x = y = 0;
        for (p = l; p < e && *p != '\n'; p++) {
                if (*p == '\t') {
                        y &= ~7;
                        y += 8;
                        while (x < y) {
-                               sbuf_bcat(tl->sb, " ", 1);
+                               vsb_bcat(tl->sb, " ", 1);
                                x++;
                        }
                } else {
                        x++;
                        y++;
-                       sbuf_bcat(tl->sb, p, 1);
+                       vsb_bcat(tl->sb, p, 1);
                }
        }
-       sbuf_cat(tl->sb, "\n");
+       vsb_cat(tl->sb, "\n");
        x = y = 0;
        for (p = l; p < e && *p != '\n'; p++) {
                if (p >= t->b && p < t->e) {
-                       sbuf_bcat(tl->sb, "#", 1);
+                       vsb_bcat(tl->sb, "#", 1);
                        x++;
                        y++;
                        continue;
@@ -108,11 +108,11 @@ vcc_ErrWhere(struct tokenlist *tl, struct token *t)
                } else
                        y++;
                while (x < y) {
-                       sbuf_bcat(tl->sb, "-", 1);
+                       vsb_bcat(tl->sb, "-", 1);
                        x++;
                }
        }
-       sbuf_cat(tl->sb, "\n");
+       vsb_cat(tl->sb, "\n");
        tl->err = 1;
 }
 
@@ -123,7 +123,7 @@ vcc_NextToken(struct tokenlist *tl)
 {
        tl->t = TAILQ_NEXT(tl->t, list);
        if (tl->t == NULL) {
-               sbuf_printf(tl->sb,
+               vsb_printf(tl->sb,
                    "Ran out of input, something is missing or"
                    " maybe unbalanced (...) or {...}\n");
                tl->err = 1;
@@ -136,9 +136,9 @@ vcc__Expect(struct tokenlist *tl, unsigned tok, int line)
 {
        if (tl->t->tok == tok)
                return;
-       sbuf_printf(tl->sb, "Expected %s got ", vcl_tnames[tok]);
+       vsb_printf(tl->sb, "Expected %s got ", vcl_tnames[tok]);
        vcc_ErrToken(tl, tl->t);
-       sbuf_printf(tl->sb, "\n(program line %u), at\n", line);
+       vsb_printf(tl->sb, "\n(program line %u), at\n", line);
        vcc_ErrWhere(tl, tl->t);
 }
 
@@ -286,7 +286,7 @@ vcc_Lexer(struct tokenlist *tl, const char *b, const char *e)
                        continue;
                }
                vcc_AddToken(tl, EOI, p, p + 1);
-               sbuf_printf(tl->sb, "Syntax error at\n");
+               vsb_printf(tl->sb, "Syntax error at\n");
                vcc_ErrWhere(tl, tl->t);
                return;
        }