[master] 7ce0d47 Rename source files to their VTLA names
Poul-Henning Kamp
phk at varnish-cache.org
Sun Oct 9 20:20:29 CEST 2011
commit 7ce0d474d5b36e4feaf38df30594611060397e0f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Oct 9 18:20:10 2011 +0000
Rename source files to their VTLA names
diff --git a/bin/varnishadm/Makefile.am b/bin/varnishadm/Makefile.am
index 93997b9..201a361 100644
--- a/bin/varnishadm/Makefile.am
+++ b/bin/varnishadm/Makefile.am
@@ -8,8 +8,8 @@ dist_man_MANS = varnishadm.1
varnishadm_SOURCES = \
varnishadm.c \
- $(top_builddir)/lib/libvarnish/assert.c \
- $(top_builddir)/lib/libvarnish/tcp.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
+ $(top_builddir)/lib/libvarnish/vtcp.c \
$(top_builddir)/lib/libvarnish/vss.c
varnishadm_CFLAGS = @LIBEDIT_CFLAGS@
diff --git a/bin/varnishhist/Makefile.am b/bin/varnishhist/Makefile.am
index 8f19313..8aafa2d 100644
--- a/bin/varnishhist/Makefile.am
+++ b/bin/varnishhist/Makefile.am
@@ -7,7 +7,7 @@ bin_PROGRAMS = varnishhist
dist_man_MANS = varnishhist.1
varnishhist_SOURCES = varnishhist.c \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/version.c
varnishhist_LDADD = \
diff --git a/bin/varnishlog/Makefile.am b/bin/varnishlog/Makefile.am
index 79bf2ad..e21ee35 100644
--- a/bin/varnishlog/Makefile.am
+++ b/bin/varnishlog/Makefile.am
@@ -8,7 +8,7 @@ dist_man_MANS = varnishlog.1
varnishlog_SOURCES = \
varnishlog.c \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/flopen.c \
$(top_builddir)/lib/libvarnish/version.c \
$(top_builddir)/lib/libvarnish/vsb.c \
diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am
index 9b652da..8b3f617 100644
--- a/bin/varnishncsa/Makefile.am
+++ b/bin/varnishncsa/Makefile.am
@@ -10,7 +10,7 @@ varnishncsa_SOURCES = \
varnishncsa.c \
base64.c \
base64.h \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/flopen.c \
$(top_builddir)/lib/libvarnish/version.c \
$(top_builddir)/lib/libvarnish/vsb.c \
diff --git a/bin/varnishreplay/Makefile.am b/bin/varnishreplay/Makefile.am
index 553dfda..2be20f7 100644
--- a/bin/varnishreplay/Makefile.am
+++ b/bin/varnishreplay/Makefile.am
@@ -8,8 +8,8 @@ dist_man_MANS = varnishreplay.1
varnishreplay_SOURCES = \
varnishreplay.c \
- $(top_builddir)/lib/libvarnish/assert.c \
- $(top_builddir)/lib/libvarnish/tcp.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
+ $(top_builddir)/lib/libvarnish/vtcp.c \
$(top_builddir)/lib/libvarnish/vss.c
varnishreplay_LDADD = \
diff --git a/bin/varnishsizes/Makefile.am b/bin/varnishsizes/Makefile.am
index a25b280..8029741 100644
--- a/bin/varnishsizes/Makefile.am
+++ b/bin/varnishsizes/Makefile.am
@@ -7,7 +7,7 @@ bin_PROGRAMS = varnishsizes
dist_man_MANS = varnishsizes.1
varnishsizes_SOURCES = varnishsizes.c \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/version.c
varnishsizes_LDADD = \
diff --git a/bin/varnishstat/Makefile.am b/bin/varnishstat/Makefile.am
index 8407eb2..83588c9 100644
--- a/bin/varnishstat/Makefile.am
+++ b/bin/varnishstat/Makefile.am
@@ -11,7 +11,7 @@ varnishstat_SOURCES = \
\
varnishstat.c \
varnishstat_curses.c \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/version.c
varnishstat_LDADD = \
diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am
index dab412f..630fbf7 100644
--- a/bin/varnishtop/Makefile.am
+++ b/bin/varnishtop/Makefile.am
@@ -7,7 +7,7 @@ bin_PROGRAMS = varnishtop
dist_man_MANS = varnishtop.1
varnishtop_SOURCES = varnishtop.c \
- $(top_builddir)/lib/libvarnish/assert.c \
+ $(top_builddir)/lib/libvarnish/vas.c \
$(top_builddir)/lib/libvarnish/version.c
varnishtop_LDADD = \
diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index 21a9d98..b8651cc 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -5,8 +5,8 @@ pkglib_LTLIBRARIES = libvarnish.la
libvarnish_la_LDFLAGS = -avoid-version
libvarnish_la_SOURCES = \
- argv.c \
- assert.c \
+ vav.c \
+ vas.c \
binary_heap.c \
subproc.c \
cli_auth.c \
@@ -15,7 +15,7 @@ libvarnish_la_SOURCES = \
flopen.c \
num.c \
time.c \
- tcp.c \
+ vtcp.c \
vct.c \
version.c \
vev.c \
diff --git a/lib/libvarnish/argv.c b/lib/libvarnish/argv.c
deleted file mode 100644
index a0c57bb..0000000
--- a/lib/libvarnish/argv.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 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.
- *
- * const char **VAV_Parse(const char *s, int comment)
- * Parse a command like line into an argv[]
- * Index zero contains NULL or an error message
- * "double quotes" and backslash substitution is handled.
- *
- * void VAV_Free(const char **argv)
- * Free the result of VAV_Parse()
- *
- */
-
-#include "config.h"
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "vas.h"
-#include "vav.h"
-
-int
-VAV_BackSlash(const char *s, char *res)
-{
- int r;
- char c;
- unsigned u;
-
- assert(*s == '\\');
- r = c = 0;
- switch(s[1]) {
- case 'n':
- c = '\n';
- r = 2;
- break;
- case 'r':
- c = '\r';
- r = 2;
- break;
- case 't':
- c = '\t';
- r = 2;
- break;
- case '"':
- c = '"';
- r = 2;
- break;
- case '\\':
- c = '\\';
- r = 2;
- break;
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- for (r = 1; r < 4; r++) {
- if (!isdigit(s[r]))
- break;
- if (s[r] - '0' > 7)
- break;
- c <<= 3; /*lint !e701 signed left shift */
- c |= s[r] - '0';
- }
- break;
- case 'x':
- if (1 == sscanf(s + 1, "x%02x", &u)) {
- assert(!(u & ~0xff));
- c = u; /*lint !e734 loss of precision */
- r = 4;
- }
- break;
- default:
- break;
- }
- if (res != NULL)
- *res = c;
- return (r);
-}
-
-char *
-VAV_BackSlashDecode(const char *s, const char *e)
-{
- const char *q;
- char *p, *r;
- int i;
-
- if (e == NULL)
- e = strchr(s, '\0');
- assert(e != NULL);
- p = calloc((e - s) + 1, 1);
- if (p == NULL)
- return (p);
- for (r = p, q = s; q < e; ) {
- if (*q != '\\') {
- *r++ = *q++;
- continue;
- }
- i = VAV_BackSlash(q, r);
- q += i;
- r++;
- }
- *r = '\0';
- return (p);
-}
-
-static char err_invalid_backslash[] = "Invalid backslash sequence";
-static char err_missing_quote[] = "Missing '\"'";
-
-char **
-VAV_Parse(const char *s, int *argc, int flag)
-{
- char **argv;
- const char *p;
- int nargv, largv;
- int i, quote;
-
- assert(s != NULL);
- nargv = 1;
- largv = 16;
- argv = calloc(sizeof *argv, largv);
- if (argv == NULL)
- return (NULL);
-
- for (;;) {
- if (*s == '\0')
- break;
- if (isspace(*s)) {
- s++;
- continue;
- }
- if ((flag & ARGV_COMMENT) && *s == '#')
- break;
- if (*s == '"' && !(flag & ARGV_NOESC)) {
- p = ++s;
- quote = 1;
- } else {
- p = s;
- quote = 0;
- }
- while (1) {
- if (*s == '\\' && !(flag & ARGV_NOESC)) {
- i = VAV_BackSlash(s, NULL);
- if (i == 0) {
- argv[0] = err_invalid_backslash;
- return (argv);
- }
- s += i;
- continue;
- }
- if (!quote) {
- if (*s == '\0' || isspace(*s))
- break;
- if ((flag & ARGV_COMMA) && *s == ',')
- break;
- s++;
- continue;
- }
- if (*s == '"' && !(flag & ARGV_NOESC))
- break;
- if (*s == '\0') {
- argv[0] = err_missing_quote;
- return (argv);
- }
- s++;
- }
- if (nargv + 1 >= largv) {
- argv = realloc(argv, sizeof (*argv) * (largv += largv));
- assert(argv != NULL);
- }
- if (flag & ARGV_NOESC) {
- argv[nargv] = malloc(1 + (s - p));
- assert(argv[nargv] != NULL);
- memcpy(argv[nargv], p, s - p);
- argv[nargv][s - p] = '\0';
- nargv++;
- } else {
- argv[nargv++] = VAV_BackSlashDecode(p, s);
- }
- if (*s != '\0')
- s++;
- }
- argv[nargv] = NULL;
- if (argc != NULL)
- *argc = nargv;
- return (argv);
-}
-
-void
-VAV_Free(char **argv)
-{
- int i;
-
- for (i = 1; argv[i] != NULL; i++)
- free(argv[i]);
- free(argv);
-}
-
-#ifdef TESTPROG
-
-#include <printf.h>
-
-static void
-VAV_Print(char **argv)
-{
- int i;
-
- printf("---- %p\n", argv);
- if (argv[0] != NULL)
- printf("err %V\n", argv[0]);
- for (i = 1; argv[i] != NULL; i++)
- printf("%3d %V\n", i, argv[i]);
-}
-
-static void
-Test(const char *str)
-{
- char **av;
-
- printf("Test: <%V>\n", str);
- av = VAV_Parse(str, 0);
- VAV_Print(av);
-}
-
-int
-main(int argc, char **argv)
-{
- char buf[BUFSIZ];
-
- (void)argc;
- (void)argv;
-
- register_printf_render_std("V");
-
- while (fgets(buf, sizeof buf, stdin))
- Test(buf);
-
- return (0);
-}
-#endif
diff --git a/lib/libvarnish/assert.c b/lib/libvarnish/assert.c
deleted file mode 100644
index 82351ce..0000000
--- a/lib/libvarnish/assert.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 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.
- *
- * This is the default backend function for libvarnish' assert facilities.
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "libvarnish.h"
-
-static void
-VAS_Fail_default(const char *func, const char *file, int line,
- const char *cond, int err, int xxx)
-{
-
- if (xxx) {
- fprintf(stderr,
- "Missing errorhandling code in %s(), %s line %d:\n"
- " Condition(%s) not true.\n",
- func, file, line, cond);
- } else {
- fprintf(stderr,
- "Assert error in %s(), %s line %d:\n"
- " Condition(%s) not true.\n",
- func, file, line, cond);
- }
- if (err)
- fprintf(stderr,
- " errno = %d (%s)\n", err, strerror(err));
- abort();
-}
-
-vas_f *VAS_Fail = VAS_Fail_default;
diff --git a/lib/libvarnish/tcp.c b/lib/libvarnish/tcp.c
deleted file mode 100644
index e8932e8..0000000
--- a/lib/libvarnish/tcp.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 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.
- */
-
-#include "config.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-
-#ifdef __linux
-#include <netinet/tcp.h>
-#endif
-
-#include <errno.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
-#endif
-#include <netdb.h>
-#include <poll.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <math.h>
-
-#include "vtcp.h"
-#include "libvarnish.h"
-
-/*--------------------------------------------------------------------*/
-
-int
-VTCP_port(const struct sockaddr_storage *addr)
-{
-
- if (addr->ss_family == AF_INET) {
- const struct sockaddr_in *ain = (const void *)addr;
- return ntohs((ain->sin_port));
- }
- if (addr->ss_family == AF_INET6) {
- const struct sockaddr_in6 *ain = (const void *)addr;
- return ntohs((ain->sin6_port));
- }
- return (-1);
-}
-
-
-/*--------------------------------------------------------------------*/
-
-void
-VTCP_name(const struct sockaddr_storage *addr, unsigned l,
- char *abuf, unsigned alen, char *pbuf, unsigned plen)
-{
- int i;
-
- i = getnameinfo((const void *)addr, l, abuf, alen, pbuf, plen,
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (i) {
- /*
- * XXX this printf is shitty, but we may not have space
- * for the gai_strerror in the bufffer :-(
- */
- printf("getnameinfo = %d %s\n", i, gai_strerror(i));
- (void)snprintf(abuf, alen, "Conversion");
- (void)snprintf(pbuf, plen, "Failed");
- return;
- }
- /* XXX dirty hack for v4-to-v6 mapped addresses */
- if (strncmp(abuf, "::ffff:", 7) == 0) {
- for (i = 0; abuf[i + 7]; ++i)
- abuf[i] = abuf[i + 7];
- abuf[i] = '\0';
- }
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VTCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
-{
- struct sockaddr_storage addr_s;
- socklen_t l;
-
- l = sizeof addr_s;
- AZ(getsockname(sock, (void *)&addr_s, &l));
- VTCP_name(&addr_s, l, abuf, alen, pbuf, plen);
-}
-/*--------------------------------------------------------------------*/
-
-void
-VTCP_hisname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
-{
- struct sockaddr_storage addr_s;
- socklen_t l;
-
- l = sizeof addr_s;
- if (!getpeername(sock, (void*)&addr_s, &l))
- VTCP_name(&addr_s, l, abuf, alen, pbuf, plen);
- else {
- (void)snprintf(abuf, alen, "<none>");
- (void)snprintf(pbuf, plen, "<none>");
- }
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VTCP_filter_http(int sock)
-{
-#ifdef HAVE_ACCEPT_FILTERS
- struct accept_filter_arg afa;
- int i;
-
- memset(&afa, 0, sizeof(afa));
- strcpy(afa.af_name, "httpready");
- errno = 0;
- i = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER,
- &afa, sizeof(afa));
- /* XXX ugly */
- if (i)
- printf("Acceptfilter(%d, httpready): %d %s\n",
- sock, i, strerror(errno));
- return (i);
-#elif defined(__linux)
- int defer = 1;
- setsockopt(sock, SOL_TCP,TCP_DEFER_ACCEPT,(char *) &defer, sizeof(int));
- return (0);
-#else
- (void)sock;
- return (0);
-#endif
-}
-
-/*--------------------------------------------------------------------
- * Functions for controlling NONBLOCK mode.
- *
- * We use FIONBIO because it is cheaper than fcntl(2), which requires
- * us to do two syscalls, one to get and one to set, the latter of
- * which mucks about a bit before it ends up calling ioctl(FIONBIO),
- * at least on FreeBSD.
- */
-
-int
-VTCP_blocking(int sock)
-{
- int i, j;
-
- i = 0;
- j = ioctl(sock, FIONBIO, &i);
- VTCP_Assert(j);
- return (j);
-}
-
-int
-VTCP_nonblocking(int sock)
-{
- int i, j;
-
- i = 1;
- j = ioctl(sock, FIONBIO, &i);
- VTCP_Assert(j);
- return (j);
-}
-
-/*--------------------------------------------------------------------
- * On TCP a connect(2) can block for a looong time, and we don't want that.
- * Unfortunately, the SocketWizards back in those days were happy to wait
- * any amount of time for a connection, so the connect(2) syscall does not
- * take an argument for patience.
- *
- * There is a little used work-around, and we employ it at our peril.
- *
- */
-
-int
-VTCP_connect(int s, const struct sockaddr_storage *name, socklen_t namelen, int msec)
-{
- int i, k;
- socklen_t l;
- struct pollfd fds[1];
-
- assert(s >= 0);
-
- /* Set the socket non-blocking */
- if (msec > 0)
- (void)VTCP_nonblocking(s);
-
- /* Attempt the connect */
- i = connect(s, (const void *)name, namelen);
- if (i == 0 || errno != EINPROGRESS)
- return (i);
-
- assert(msec > 0);
- /* Exercise our patience, polling for write */
- fds[0].fd = s;
- fds[0].events = POLLWRNORM;
- fds[0].revents = 0;
- i = poll(fds, 1, msec);
-
- if (i == 0) {
- /* Timeout, close and give up */
- errno = ETIMEDOUT;
- return (-1);
- }
-
- /* Find out if we got a connection */
- l = sizeof k;
- AZ(getsockopt(s, SOL_SOCKET, SO_ERROR, &k, &l));
-
- /* An error means no connection established */
- errno = k;
- if (k)
- return (-1);
-
- (void)VTCP_blocking(s);
- return (0);
-}
-
-/*--------------------------------------------------------------------
- * When closing a TCP connection, a couple of errno's are legit, we
- * can't be held responsible for the other end wanting to talk to us.
- */
-
-void
-VTCP_close(int *s)
-{
- int i;
-
- i = close(*s);
-
- assert (VTCP_Check(i));
- *s = -1;
-}
-
-void
-VTCP_set_read_timeout(int s, double seconds)
-{
- struct timeval timeout;
- timeout.tv_sec = (int)floor(seconds);
- timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec));
-#ifdef SO_RCVTIMEO_WORKS
- AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout));
-#else
- (void)s;
-#endif
-}
-
-/*--------------------------------------------------------------------
- * Set or reset SO_LINGER flag
- */
-
-int
-VTCP_linger(int sock, int linger)
-{
- struct linger lin;
- int i;
-
- memset(&lin, 0, sizeof lin);
- lin.l_onoff = linger;
- i = setsockopt(sock, SOL_SOCKET, SO_LINGER, &lin, sizeof lin);
- VTCP_Assert(i);
- return (i);
-}
diff --git a/lib/libvarnish/vas.c b/lib/libvarnish/vas.c
new file mode 100644
index 0000000..82351ce
--- /dev/null
+++ b/lib/libvarnish/vas.c
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 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.
+ *
+ * This is the default backend function for libvarnish' assert facilities.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libvarnish.h"
+
+static void
+VAS_Fail_default(const char *func, const char *file, int line,
+ const char *cond, int err, int xxx)
+{
+
+ if (xxx) {
+ fprintf(stderr,
+ "Missing errorhandling code in %s(), %s line %d:\n"
+ " Condition(%s) not true.\n",
+ func, file, line, cond);
+ } else {
+ fprintf(stderr,
+ "Assert error in %s(), %s line %d:\n"
+ " Condition(%s) not true.\n",
+ func, file, line, cond);
+ }
+ if (err)
+ fprintf(stderr,
+ " errno = %d (%s)\n", err, strerror(err));
+ abort();
+}
+
+vas_f *VAS_Fail = VAS_Fail_default;
diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c
new file mode 100644
index 0000000..a0c57bb
--- /dev/null
+++ b/lib/libvarnish/vav.c
@@ -0,0 +1,264 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 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.
+ *
+ * const char **VAV_Parse(const char *s, int comment)
+ * Parse a command like line into an argv[]
+ * Index zero contains NULL or an error message
+ * "double quotes" and backslash substitution is handled.
+ *
+ * void VAV_Free(const char **argv)
+ * Free the result of VAV_Parse()
+ *
+ */
+
+#include "config.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "vas.h"
+#include "vav.h"
+
+int
+VAV_BackSlash(const char *s, char *res)
+{
+ int r;
+ char c;
+ unsigned u;
+
+ assert(*s == '\\');
+ r = c = 0;
+ switch(s[1]) {
+ case 'n':
+ c = '\n';
+ r = 2;
+ break;
+ case 'r':
+ c = '\r';
+ r = 2;
+ break;
+ case 't':
+ c = '\t';
+ r = 2;
+ break;
+ case '"':
+ c = '"';
+ r = 2;
+ break;
+ case '\\':
+ c = '\\';
+ r = 2;
+ break;
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ for (r = 1; r < 4; r++) {
+ if (!isdigit(s[r]))
+ break;
+ if (s[r] - '0' > 7)
+ break;
+ c <<= 3; /*lint !e701 signed left shift */
+ c |= s[r] - '0';
+ }
+ break;
+ case 'x':
+ if (1 == sscanf(s + 1, "x%02x", &u)) {
+ assert(!(u & ~0xff));
+ c = u; /*lint !e734 loss of precision */
+ r = 4;
+ }
+ break;
+ default:
+ break;
+ }
+ if (res != NULL)
+ *res = c;
+ return (r);
+}
+
+char *
+VAV_BackSlashDecode(const char *s, const char *e)
+{
+ const char *q;
+ char *p, *r;
+ int i;
+
+ if (e == NULL)
+ e = strchr(s, '\0');
+ assert(e != NULL);
+ p = calloc((e - s) + 1, 1);
+ if (p == NULL)
+ return (p);
+ for (r = p, q = s; q < e; ) {
+ if (*q != '\\') {
+ *r++ = *q++;
+ continue;
+ }
+ i = VAV_BackSlash(q, r);
+ q += i;
+ r++;
+ }
+ *r = '\0';
+ return (p);
+}
+
+static char err_invalid_backslash[] = "Invalid backslash sequence";
+static char err_missing_quote[] = "Missing '\"'";
+
+char **
+VAV_Parse(const char *s, int *argc, int flag)
+{
+ char **argv;
+ const char *p;
+ int nargv, largv;
+ int i, quote;
+
+ assert(s != NULL);
+ nargv = 1;
+ largv = 16;
+ argv = calloc(sizeof *argv, largv);
+ if (argv == NULL)
+ return (NULL);
+
+ for (;;) {
+ if (*s == '\0')
+ break;
+ if (isspace(*s)) {
+ s++;
+ continue;
+ }
+ if ((flag & ARGV_COMMENT) && *s == '#')
+ break;
+ if (*s == '"' && !(flag & ARGV_NOESC)) {
+ p = ++s;
+ quote = 1;
+ } else {
+ p = s;
+ quote = 0;
+ }
+ while (1) {
+ if (*s == '\\' && !(flag & ARGV_NOESC)) {
+ i = VAV_BackSlash(s, NULL);
+ if (i == 0) {
+ argv[0] = err_invalid_backslash;
+ return (argv);
+ }
+ s += i;
+ continue;
+ }
+ if (!quote) {
+ if (*s == '\0' || isspace(*s))
+ break;
+ if ((flag & ARGV_COMMA) && *s == ',')
+ break;
+ s++;
+ continue;
+ }
+ if (*s == '"' && !(flag & ARGV_NOESC))
+ break;
+ if (*s == '\0') {
+ argv[0] = err_missing_quote;
+ return (argv);
+ }
+ s++;
+ }
+ if (nargv + 1 >= largv) {
+ argv = realloc(argv, sizeof (*argv) * (largv += largv));
+ assert(argv != NULL);
+ }
+ if (flag & ARGV_NOESC) {
+ argv[nargv] = malloc(1 + (s - p));
+ assert(argv[nargv] != NULL);
+ memcpy(argv[nargv], p, s - p);
+ argv[nargv][s - p] = '\0';
+ nargv++;
+ } else {
+ argv[nargv++] = VAV_BackSlashDecode(p, s);
+ }
+ if (*s != '\0')
+ s++;
+ }
+ argv[nargv] = NULL;
+ if (argc != NULL)
+ *argc = nargv;
+ return (argv);
+}
+
+void
+VAV_Free(char **argv)
+{
+ int i;
+
+ for (i = 1; argv[i] != NULL; i++)
+ free(argv[i]);
+ free(argv);
+}
+
+#ifdef TESTPROG
+
+#include <printf.h>
+
+static void
+VAV_Print(char **argv)
+{
+ int i;
+
+ printf("---- %p\n", argv);
+ if (argv[0] != NULL)
+ printf("err %V\n", argv[0]);
+ for (i = 1; argv[i] != NULL; i++)
+ printf("%3d %V\n", i, argv[i]);
+}
+
+static void
+Test(const char *str)
+{
+ char **av;
+
+ printf("Test: <%V>\n", str);
+ av = VAV_Parse(str, 0);
+ VAV_Print(av);
+}
+
+int
+main(int argc, char **argv)
+{
+ char buf[BUFSIZ];
+
+ (void)argc;
+ (void)argv;
+
+ register_printf_render_std("V");
+
+ while (fgets(buf, sizeof buf, stdin))
+ Test(buf);
+
+ return (0);
+}
+#endif
diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
new file mode 100644
index 0000000..e8932e8
--- /dev/null
+++ b/lib/libvarnish/vtcp.c
@@ -0,0 +1,290 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 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.
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#ifdef __linux
+#include <netinet/tcp.h>
+#endif
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+#include <netdb.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+
+#include "vtcp.h"
+#include "libvarnish.h"
+
+/*--------------------------------------------------------------------*/
+
+int
+VTCP_port(const struct sockaddr_storage *addr)
+{
+
+ if (addr->ss_family == AF_INET) {
+ const struct sockaddr_in *ain = (const void *)addr;
+ return ntohs((ain->sin_port));
+ }
+ if (addr->ss_family == AF_INET6) {
+ const struct sockaddr_in6 *ain = (const void *)addr;
+ return ntohs((ain->sin6_port));
+ }
+ return (-1);
+}
+
+
+/*--------------------------------------------------------------------*/
+
+void
+VTCP_name(const struct sockaddr_storage *addr, unsigned l,
+ char *abuf, unsigned alen, char *pbuf, unsigned plen)
+{
+ int i;
+
+ i = getnameinfo((const void *)addr, l, abuf, alen, pbuf, plen,
+ NI_NUMERICHOST | NI_NUMERICSERV);
+ if (i) {
+ /*
+ * XXX this printf is shitty, but we may not have space
+ * for the gai_strerror in the bufffer :-(
+ */
+ printf("getnameinfo = %d %s\n", i, gai_strerror(i));
+ (void)snprintf(abuf, alen, "Conversion");
+ (void)snprintf(pbuf, plen, "Failed");
+ return;
+ }
+ /* XXX dirty hack for v4-to-v6 mapped addresses */
+ if (strncmp(abuf, "::ffff:", 7) == 0) {
+ for (i = 0; abuf[i + 7]; ++i)
+ abuf[i] = abuf[i + 7];
+ abuf[i] = '\0';
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VTCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
+{
+ struct sockaddr_storage addr_s;
+ socklen_t l;
+
+ l = sizeof addr_s;
+ AZ(getsockname(sock, (void *)&addr_s, &l));
+ VTCP_name(&addr_s, l, abuf, alen, pbuf, plen);
+}
+/*--------------------------------------------------------------------*/
+
+void
+VTCP_hisname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen)
+{
+ struct sockaddr_storage addr_s;
+ socklen_t l;
+
+ l = sizeof addr_s;
+ if (!getpeername(sock, (void*)&addr_s, &l))
+ VTCP_name(&addr_s, l, abuf, alen, pbuf, plen);
+ else {
+ (void)snprintf(abuf, alen, "<none>");
+ (void)snprintf(pbuf, plen, "<none>");
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VTCP_filter_http(int sock)
+{
+#ifdef HAVE_ACCEPT_FILTERS
+ struct accept_filter_arg afa;
+ int i;
+
+ memset(&afa, 0, sizeof(afa));
+ strcpy(afa.af_name, "httpready");
+ errno = 0;
+ i = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER,
+ &afa, sizeof(afa));
+ /* XXX ugly */
+ if (i)
+ printf("Acceptfilter(%d, httpready): %d %s\n",
+ sock, i, strerror(errno));
+ return (i);
+#elif defined(__linux)
+ int defer = 1;
+ setsockopt(sock, SOL_TCP,TCP_DEFER_ACCEPT,(char *) &defer, sizeof(int));
+ return (0);
+#else
+ (void)sock;
+ return (0);
+#endif
+}
+
+/*--------------------------------------------------------------------
+ * Functions for controlling NONBLOCK mode.
+ *
+ * We use FIONBIO because it is cheaper than fcntl(2), which requires
+ * us to do two syscalls, one to get and one to set, the latter of
+ * which mucks about a bit before it ends up calling ioctl(FIONBIO),
+ * at least on FreeBSD.
+ */
+
+int
+VTCP_blocking(int sock)
+{
+ int i, j;
+
+ i = 0;
+ j = ioctl(sock, FIONBIO, &i);
+ VTCP_Assert(j);
+ return (j);
+}
+
+int
+VTCP_nonblocking(int sock)
+{
+ int i, j;
+
+ i = 1;
+ j = ioctl(sock, FIONBIO, &i);
+ VTCP_Assert(j);
+ return (j);
+}
+
+/*--------------------------------------------------------------------
+ * On TCP a connect(2) can block for a looong time, and we don't want that.
+ * Unfortunately, the SocketWizards back in those days were happy to wait
+ * any amount of time for a connection, so the connect(2) syscall does not
+ * take an argument for patience.
+ *
+ * There is a little used work-around, and we employ it at our peril.
+ *
+ */
+
+int
+VTCP_connect(int s, const struct sockaddr_storage *name, socklen_t namelen, int msec)
+{
+ int i, k;
+ socklen_t l;
+ struct pollfd fds[1];
+
+ assert(s >= 0);
+
+ /* Set the socket non-blocking */
+ if (msec > 0)
+ (void)VTCP_nonblocking(s);
+
+ /* Attempt the connect */
+ i = connect(s, (const void *)name, namelen);
+ if (i == 0 || errno != EINPROGRESS)
+ return (i);
+
+ assert(msec > 0);
+ /* Exercise our patience, polling for write */
+ fds[0].fd = s;
+ fds[0].events = POLLWRNORM;
+ fds[0].revents = 0;
+ i = poll(fds, 1, msec);
+
+ if (i == 0) {
+ /* Timeout, close and give up */
+ errno = ETIMEDOUT;
+ return (-1);
+ }
+
+ /* Find out if we got a connection */
+ l = sizeof k;
+ AZ(getsockopt(s, SOL_SOCKET, SO_ERROR, &k, &l));
+
+ /* An error means no connection established */
+ errno = k;
+ if (k)
+ return (-1);
+
+ (void)VTCP_blocking(s);
+ return (0);
+}
+
+/*--------------------------------------------------------------------
+ * When closing a TCP connection, a couple of errno's are legit, we
+ * can't be held responsible for the other end wanting to talk to us.
+ */
+
+void
+VTCP_close(int *s)
+{
+ int i;
+
+ i = close(*s);
+
+ assert (VTCP_Check(i));
+ *s = -1;
+}
+
+void
+VTCP_set_read_timeout(int s, double seconds)
+{
+ struct timeval timeout;
+ timeout.tv_sec = (int)floor(seconds);
+ timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec));
+#ifdef SO_RCVTIMEO_WORKS
+ AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout));
+#else
+ (void)s;
+#endif
+}
+
+/*--------------------------------------------------------------------
+ * Set or reset SO_LINGER flag
+ */
+
+int
+VTCP_linger(int sock, int linger)
+{
+ struct linger lin;
+ int i;
+
+ memset(&lin, 0, sizeof lin);
+ lin.l_onoff = linger;
+ i = setsockopt(sock, SOL_SOCKET, SO_LINGER, &lin, sizeof lin);
+ VTCP_Assert(i);
+ return (i);
+}
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index f88d748..492b10d 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -10,8 +10,8 @@ libvarnishapi_la_SOURCES = \
vsm_api.h \
vsl_api.h \
\
- ../libvarnish/assert.c \
- ../libvarnish/argv.c \
+ ../libvarnish/vas.c \
+ ../libvarnish/vav.c \
../../include/vcs_version.h \
../libvarnish/version.c \
../libvarnish/cli_common.c \
More information about the varnish-commit
mailing list