r712 - in trunk/varnish-cache: . bin/varnishd bin/varnishlog bin/varnishncsa bin/varnishtop include lib lib/libvarnish lib/libvcl
des at projects.linpro.no
des at projects.linpro.no
Mon Aug 7 13:09:30 CEST 2006
Author: des
Date: 2006-08-07 13:09:30 +0200 (Mon, 07 Aug 2006)
New Revision: 712
Added:
trunk/varnish-cache/include/vsb.h
trunk/varnish-cache/lib/libvarnish/vsb.3
trunk/varnish-cache/lib/libvarnish/vsb.c
Removed:
trunk/varnish-cache/include/sbuf.h
trunk/varnish-cache/lib/libsbuf/
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_cli.c
trunk/varnish-cache/bin/varnishd/cache_response.c
trunk/varnish-cache/bin/varnishd/cache_vrt_re.c
trunk/varnish-cache/bin/varnishd/flint.lnt
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/bin/varnishd/mgt_vcc.c
trunk/varnish-cache/bin/varnishd/varnishd.c
trunk/varnish-cache/bin/varnishlog/Makefile.am
trunk/varnish-cache/bin/varnishlog/varnishlog.c
trunk/varnish-cache/bin/varnishncsa/Makefile.am
trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
trunk/varnish-cache/bin/varnishtop/Makefile.am
trunk/varnish-cache/bin/varnishtop/varnishtop.c
trunk/varnish-cache/configure.ac
trunk/varnish-cache/include/Makefile.am
trunk/varnish-cache/include/cli_common.h
trunk/varnish-cache/include/libvcl.h
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/Makefile.am
trunk/varnish-cache/lib/libvarnish/Makefile.am
trunk/varnish-cache/lib/libvarnish/cli_common.c
trunk/varnish-cache/lib/libvcl/vcc_acl.c
trunk/varnish-cache/lib/libvcl/vcc_compile.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
trunk/varnish-cache/lib/libvcl/vcc_token.c
Log:
Fold libsbuf into libvarnish, with s/sbuf/vsb/g.
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -56,7 +56,6 @@
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 \
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -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;
Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 = &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 @@
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 @@
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)
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -18,9 +18,9 @@
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 @@
}
}
- 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 @@
"<!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);
}
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
}
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 @@
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);
}
Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt 2006-08-07 11:09:30 UTC (rev 712)
@@ -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
Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
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 @@
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 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
{
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 @@
} 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 @@
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 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -17,7 +17,7 @@
#include <time.h>
#include <unistd.h>
-#include "sbuf.h"
+#include "vsb.h"
#include "libvarnish.h"
#include "cli.h"
Modified: trunk/varnish-cache/bin/varnishlog/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishlog/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishlog/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -11,5 +11,5 @@
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
Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
/* Ordering-----------------------------------------------------------*/
-static struct sbuf *ob[65536];
+static struct vsb *ob[65536];
static int hc[65536];
static int xrf[65536];
@@ -43,10 +43,10 @@
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 @@
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 @@
;
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 @@
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 @@
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;
Modified: trunk/varnish-cache/bin/varnishncsa/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishncsa/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -11,5 +11,5 @@
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
Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
};
-/* 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 @@
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 @@
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);
}
Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishtop/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishtop/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -11,6 +11,6 @@
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
Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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"
Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/configure.ac 2006-08-07 11:09:30 UTC (rev 712)
@@ -75,7 +75,6 @@
include/Makefile
lib/Makefile
lib/libcompat/Makefile
- lib/libsbuf/Makefile
lib/libvarnish/Makefile
lib/libvarnishapi/Makefile
lib/libvcl/Makefile
Modified: trunk/varnish-cache/include/Makefile.am
===================================================================
--- trunk/varnish-cache/include/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/include/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -12,7 +12,7 @@
libvcl.h \
miniobj.h \
queue.h \
- sbuf.h \
+ vsb.h \
shmlog.h \
shmlog_tags.h \
stat_field.h \
Modified: trunk/varnish-cache/include/cli_common.h
===================================================================
--- trunk/varnish-cache/include/cli_common.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/include/cli_common.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -3,7 +3,7 @@
*/
struct cli {
- struct sbuf *sb;
+ struct vsb *sb;
enum cli_status_e result;
};
Modified: trunk/varnish-cache/include/libvcl.h
===================================================================
--- trunk/varnish-cache/include/libvcl.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/include/libvcl.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -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);
Deleted: trunk/varnish-cache/include/sbuf.h
===================================================================
--- trunk/varnish-cache/include/sbuf.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/include/sbuf.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -1,78 +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/sys/sbuf.h,v 1.14 2004/07/09 11:35:30 des Exp $
- */
-
-#ifndef SBUF_H_INCLUDED
-#define SBUF_H_INCLUDED
-
-/*
- * Structure definition
- */
-struct sbuf {
- 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 */
- int s_flags; /* flags */
-};
-
-__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) */;
-#ifdef va_start
-int sbuf_vprintf(struct sbuf *, 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 *);
-__END_DECLS
-
-#endif
Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/include/vrt.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -8,7 +8,7 @@
*/
struct sess;
-struct sbuf;
+struct vsb;
struct backend;
struct VCL_conf;
@@ -38,7 +38,7 @@
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 *);
Copied: trunk/varnish-cache/include/vsb.h (from rev 710, trunk/varnish-cache/include/sbuf.h)
===================================================================
--- trunk/varnish-cache/include/sbuf.h 2006-08-07 10:40:19 UTC (rev 710)
+++ trunk/varnish-cache/include/vsb.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -0,0 +1,78 @@
+/*-
+ * 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/sys/vsb.h,v 1.14 2004/07/09 11:35:30 des Exp $
+ */
+
+#ifndef VSB_H_INCLUDED
+#define VSB_H_INCLUDED
+
+/*
+ * Structure definition
+ */
+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 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 */
+};
+
+__BEGIN_DECLS
+/*
+ * API functions
+ */
+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 vsb_vprintf(struct vsb *, const char *, va_list) /* __printflike(2, 0) */;
+#endif
+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
Modified: trunk/varnish-cache/lib/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -2,7 +2,6 @@
SUBDIRS = \
libcompat \
- libsbuf \
libvarnish \
libvarnishapi \
libvcl
Modified: trunk/varnish-cache/lib/libvarnish/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnish/Makefile.am 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvarnish/Makefile.am 2006-08-07 11:09:30 UTC (rev 712)
@@ -9,6 +9,7 @@
binary_heap.c \
cli.c \
cli_common.c \
- time.c
+ time.c \
+ vsb.c
libvarnish_la_CFLAGS = -include config.h
Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli_common.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
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 @@
*/
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);
Copied: trunk/varnish-cache/lib/libvarnish/vsb.3 (from rev 710, trunk/varnish-cache/lib/libsbuf/sbuf.3)
===================================================================
--- trunk/varnish-cache/lib/libsbuf/sbuf.3 2006-08-07 10:40:19 UTC (rev 710)
+++ trunk/varnish-cache/lib/libvarnish/vsb.3 2006-08-07 11:09:30 UTC (rev 712)
@@ -0,0 +1,338 @@
+.\"-
+.\" 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.
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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/share/man/man9/vsb.9,v 1.25 2005/12/23 11:49:52 phk Exp $
+.\"
+.Dd March 14, 2006
+.Dt VSB 3
+.Os
+.Sh NAME
+.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 libvarnish
+.Sh SYNOPSIS
+.In vsb.h
+.Ft struct vsb *
+.Fn vsb_new "struct vsb *s" "char *buf" "int length" "int flags"
+.Ft void
+.Fn vsb_clear "struct vsb *s"
+.Ft int
+.Fn vsb_setpos "struct vsb *s" "int pos"
+.Ft int
+.Fn vsb_bcat "struct vsb *s" "const void *buf" "size_t len"
+.Ft int
+.Fn vsb_bcpy "struct vsb *s" "const void *buf" "size_t len"
+.Ft int
+.Fn vsb_cat "struct vsb *s" "const char *str"
+.Ft int
+.Fn vsb_cpy "struct vsb *s" "const char *str"
+.Ft int
+.Fn vsb_printf "struct vsb *s" "const char *fmt" "..."
+.Ft int
+.Fn vsb_vprintf "struct vsb *s" "const char *fmt" "va_list ap"
+.Ft int
+.Fn vsb_putc "struct vsb *s" "int c"
+.Ft int
+.Fn vsb_trim "struct vsb *s"
+.Ft int
+.Fn vsb_overflowed "struct vsb *s"
+.Ft void
+.Fn vsb_finish "struct vsb *s"
+.Ft char *
+.Fn vsb_data "struct vsb *s"
+.Ft int
+.Fn vsb_len "struct vsb *s"
+.Ft int
+.Fn vsb_done "struct vsb *s"
+.Ft void
+.Fn vsb_delete "struct vsb *s"
+.Sh DESCRIPTION
+The
+.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 vsbs ,
+defined in
+.In sys/vsb.h .
+.Pp
+The
+.Fn vsb_new
+function initializes the
+.Fa vsb
+pointed to by its first argument.
+If that pointer is
+.Dv NULL ,
+.Fn vsb_new
+allocates a
+.Vt struct vsb
+using
+.Xr malloc 9 .
+The
+.Fa buf
+argument is a pointer to a buffer in which to store the actual string;
+if it is
+.Dv NULL ,
+.Fn vsb_new
+will allocate one using
+.Xr malloc 9 .
+The
+.Fa length
+is the initial size of the storage buffer.
+The fourth argument,
+.Fa flags ,
+may be comprised of the following flags:
+.Bl -tag -width ".Dv VSB_AUTOEXTEND"
+.It Dv VSB_FIXEDLEN
+The storage buffer is fixed at its initial size.
+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
+.Pp
+Note that if
+.Fa buf
+is not
+.Dv NULL ,
+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
+vsb is undefined.
+.Pp
+The
+.Fn vsb_delete
+function clears the
+.Fa vsb
+and frees any memory allocated for it.
+There must be a call to
+.Fn vsb_delete
+for every call to
+.Fn vsb_new .
+Any attempt to access the vsb after it has been deleted will fail.
+.Pp
+The
+.Fn vsb_clear
+function invalidates the contents of the
+.Fa vsb
+and resets its position to zero.
+.Pp
+The
+.Fn vsb_setpos
+function sets the
+.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 vsb at the new position.
+.Pp
+The
+.Fn vsb_bcat
+function appends the first
+.Fa len
+bytes from the buffer
+.Fa buf
+to the
+.Fa vsb .
+.Pp
+The
+.Fn vsb_bcpy
+function replaces the contents of the
+.Fa vsb
+with the first
+.Fa len
+bytes from the buffer
+.Fa buf .
+.Pp
+The
+.Fn vsb_cat
+function appends the NUL-terminated string
+.Fa str
+to the
+.Fa vsb
+at the current position.
+.Pp
+The
+.Fn vsb_cpy
+function replaces the contents of the
+.Fa vsb
+with those of the NUL-terminated string
+.Fa str .
+This is equivalent to calling
+.Fn vsb_cat
+with a fresh
+.Fa vsb
+or one which position has been reset to zero with
+.Fn vsb_clear
+or
+.Fn vsb_setpos .
+.Pp
+The
+.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 vsb
+at the current position.
+.Pp
+The
+.Fn vsb_vprintf
+function behaves the same as
+.Fn vsb_printf
+except that the arguments are obtained from the variable-length argument list
+.Fa ap .
+.Pp
+The
+.Fn vsb_putc
+function appends the character
+.Fa c
+to the
+.Fa vsb
+at the current position.
+.Pp
+The
+.Fn vsb_trim
+function removes trailing whitespace from the
+.Fa vsb .
+.Pp
+The
+.Fn vsb_overflowed
+function returns a non-zero value if the
+.Fa vsb
+overflowed.
+.Pp
+The
+.Fn vsb_finish
+function null-terminates the
+.Fa vsb
+and marks it as finished, which means that it may no longer be
+modified using
+.Fn vsb_setpos ,
+.Fn vsb_cat ,
+.Fn vsb_cpy ,
+.Fn vsb_printf
+or
+.Fn vsb_putc .
+.Pp
+The
+.Fn vsb_data
+and
+.Fn vsb_len
+functions return the actual string and its length, respectively;
+.Fn vsb_data
+only works on a finished
+.Fa vsb .
+.Fn vsb_done
+returns non-zero if the vsb is finished.
+.Sh NOTES
+If an operation caused an
+.Fa vsb
+to overflow, most subsequent operations on it will fail until the
+.Fa vsb
+is finished using
+.Fn vsb_finish
+or reset using
+.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 vsb_setpos ,
+or it is reinitialized to a sufficiently short string using
+.Fn vsb_cpy .
+.Sh RETURN VALUES
+.Fn vsb_new
+returns
+.Dv NULL
+if it failed to allocate a storage buffer, and a pointer to the new
+.Fa vsb
+otherwise.
+.Pp
+.Fn vsb_setpos
+returns \-1 if
+.Fa pos
+was invalid, and zero otherwise.
+.Pp
+.Fn vsb_cat ,
+.Fn vsb_cpy ,
+.Fn vsb_printf ,
+.Fn vsb_putc ,
+and
+.Fn vsb_trim
+all return \-1 if the buffer overflowed, and zero otherwise.
+.Pp
+.Fn vsb_overflowed
+returns a non-zero value if the buffer overflowed, and zero otherwise.
+.Pp
+.Fn vsb_data
+and
+.Fn vsb_len
+return
+.Dv NULL
+and \-1, respectively, if the buffer overflowed.
+.Sh SEE ALSO
+.Xr printf 3 ,
+.Xr strcat 3 ,
+.Xr strcpy 3
+.Sh HISTORY
+The
+.Nm vsb
+family of functions first appeared in
+.Fx 4.4 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm vsb
+family of functions was designed by
+.An Poul-Henning Kamp Aq phk at FreeBSD.org
+and implemented by
+.An Dag-Erling Sm\(/orgrav Aq des at FreeBSD.org .
+Additional improvements were suggested by
+.An Justin T. Gibbs Aq gibbs at FreeBSD.org .
+Auto-extend support added by
+.An Kelly Yancey Aq kbyanc at FreeBSD.org .
+.Pp
+This manual page was written by
+.An Dag-Erling Sm\(/orgrav Aq des at FreeBSD.org .
Copied: trunk/varnish-cache/lib/libvarnish/vsb.c (from rev 710, trunk/varnish-cache/lib/libsbuf/sbuf.c)
===================================================================
--- trunk/varnish-cache/lib/libsbuf/sbuf.c 2006-08-07 10:40:19 UTC (rev 710)
+++ trunk/varnish-cache/lib/libvarnish/vsb.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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));
+}
Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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_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;
}
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
} while (0)
/*--------------------------------------------------------------------
- * Printf output to the two sbufs, possibly indented
+ * Printf output to the two vsbs, possibly indented
*/
void
@@ -97,9 +97,9 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
{
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 @@
/*--------------------------------------------------------------------*/
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 @@
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 @@
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 @@
/*--------------------------------------------------------------------*/
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 @@
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);
}
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2006-08-07 11:09:30 UTC (rev 712)
@@ -22,9 +22,9 @@
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;
Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -476,7 +476,7 @@
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 @@
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);
Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_token.c 2006-08-07 10:46:59 UTC (rev 711)
+++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2006-08-07 11:09:30 UTC (rev 712)
@@ -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 @@
{
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 @@
} 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 @@
} 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 @@
{
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 @@
{
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 @@
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;
}
More information about the varnish-commit
mailing list