]> err.no Git - varnish/commitdiff
Bring in FreeBSD's version of vis(3), strvis(3) and strvisx(3).
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Aug 2006 12:31:19 +0000 (12:31 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Aug 2006 12:31:19 +0000 (12:31 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@767 d4fa192b-c00b-0410-8231-f00ffab90ce4

12 files changed:
varnish-cache/bin/varnishlog/Makefile.am
varnish-cache/bin/varnishlog/varnishlog.c
varnish-cache/bin/varnishncsa/Makefile.am
varnish-cache/bin/varnishncsa/varnishncsa.c
varnish-cache/bin/varnishstat/Makefile.am
varnish-cache/bin/varnishtop/Makefile.am
varnish-cache/bin/varnishtop/varnishtop.c
varnish-cache/configure.ac
varnish-cache/include/Makefile.am
varnish-cache/include/compat/vis.h [new file with mode: 0644]
varnish-cache/lib/libcompat/Makefile.am
varnish-cache/lib/libcompat/vis.c [new file with mode: 0644]

index 2d0ceffcacf3d968f16117fb0026bd9c4618a18a..c739b31c27563f82be989cda7549fa61f9e62605 100644 (file)
@@ -11,5 +11,6 @@ varnishlog_SOURCES = varnishlog.c
 varnishlog_CFLAGS = -include config.h
 
 varnishlog_LDADD = \
+       $(top_builddir)/lib/libcompat/libcompat.a \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvarnishapi/libvarnishapi.la
index 3a07ae00402865f2fe0b3a7b30e0e6cba068724c..9694d18d07e83496ae6be4b73227c07265b5a1df 100644 (file)
@@ -9,7 +9,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <vis.h>
+
+#include "compat/vis.h"
 
 #include "vsb.h"
 
index 667a9eb65113a4b4955bde090508e12b2054d992..660a4613e16a55b0195ee878813b70d3c4993230 100644 (file)
@@ -11,6 +11,7 @@ varnishncsa_SOURCES = varnishncsa.c
 varnishncsa_CFLAGS = -include config.h
 
 varnishncsa_LDADD = \
+       $(top_builddir)/lib/libcompat/libcompat.a \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvarnishapi/libvarnishapi.la
 
index 738644f7d96a050ffb069529b7037d335ad50e60..7a1133c16c1c9c66b4a8ff1e594dd5dd37d487e7 100644 (file)
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <vis.h>
 #include <time.h>
 
+#include "compat/vis.h"
+
 #include "vsb.h"
 
 #include "libvarnish.h"
index fcd0f6f037826f47c2582ce54a90eb2bfb709ef9..97cd6461fe55dd3064349a67938334e5b68720ac 100644 (file)
@@ -11,6 +11,7 @@ varnishstat_SOURCES = varnishstat.c
 varnishstat_CFLAGS = -include config.h
 
 varnishstat_LDADD = \
+       $(top_builddir)/lib/libcompat/libcompat.a \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvarnishapi/libvarnishapi.la  \
        -lcurses
index b333c189c89debcaba5c57b1b0c94b06f439838e..3750f2ebcdb6ac1c82ddc8d28c872d5d45307bfe 100644 (file)
@@ -11,6 +11,7 @@ varnishtop_SOURCES = varnishtop.c
 varnishtop_CFLAGS = -include config.h
 
 varnishtop_LDADD = \
+       $(top_builddir)/lib/libcompat/libcompat.a \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
        -lcurses
index 050836b40370fc405bb0ed62c874f1558d673dc5..77bd666a148ee95777508cf3fddbc58de75912d6 100644 (file)
@@ -4,14 +4,15 @@
  * Log tailer for Varnish
  */
 
-#include <stdio.h>
 #include <ctype.h>
+#include <curses.h>
 #include <errno.h>
-#include <string.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <curses.h>
-#include <vis.h>
+
+#include "compat/vis.h"
 
 #include "vsb.h"
 
index a6364955d855f687f7d09fb7c7cea4640de911aa..321f40a9bca5d1783a7f24d6e91b65753a7dea96 100644 (file)
@@ -61,9 +61,12 @@ AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([strerror])
 AC_FUNC_STRERROR_R
 AC_CHECK_FUNCS([socket])
+
+# These functions are provided by libcompat on platforms where they
+# are not available
 AC_CHECK_FUNCS([srandomdev])
-AC_CHECK_FUNCS([strlcat])
-AC_CHECK_FUNCS([strlcpy])
+AC_CHECK_FUNCS([strlcat strlcpy])
+AC_CHECK_FUNCS([vis strvis strvisx])
 
 # asprintf() and vasprintf() are tricky, because on some systems, they
 # are present in the C library, but their prototypes are hidden behind
index 7c4f909e316a8fa3ce1428b38902a4b60772d2d0..943b3fb26ea6a1e7cdc24b300ba0fbbc04134cf0 100644 (file)
@@ -10,6 +10,7 @@ noinst_HEADERS = \
        compat/strlcat.h \
        compat/strlcpy.h \
        compat/vasprintf.h \
+       compat/vis.h \
        hash.h \
        http_headers.h \
        libvarnish.h \
diff --git a/varnish-cache/include/compat/vis.h b/varnish-cache/include/compat/vis.h
new file mode 100644 (file)
index 0000000..6b257f0
--- /dev/null
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *     @(#)vis.h       8.1 (Berkeley) 6/2/93
+ * $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $
+ * $Id$
+ */
+
+#ifndef _VIS_H_
+#define        _VIS_H_
+
+/*
+ * to select alternate encoding format
+ */
+#define        VIS_OCTAL       0x01    /* use octal \ddd format */
+#define        VIS_CSTYLE      0x02    /* use \[nrft0..] where appropriate */
+
+/*
+ * to alter set of characters encoded (default is to encode all
+ * non-graphic except space, tab, and newline).
+ */
+#define        VIS_SP          0x04    /* also encode space */
+#define        VIS_TAB         0x08    /* also encode tab */
+#define        VIS_NL          0x10    /* also encode newline */
+#define        VIS_WHITE       (VIS_SP | VIS_TAB | VIS_NL)
+#define        VIS_SAFE        0x20    /* only encode "unsafe" characters */
+
+/*
+ * other
+ */
+#define        VIS_NOSLASH     0x40    /* inhibit printing '\' */
+#define        VIS_HTTPSTYLE   0x80    /* http-style escape % HEX HEX */
+#define        VIS_GLOB        0x100   /* encode glob(3) magics */
+
+/*
+ * unvis return codes
+ */
+#define        UNVIS_VALID      1      /* character valid */
+#define        UNVIS_VALIDPUSH  2      /* character valid, push back passed char */
+#define        UNVIS_NOCHAR     3      /* valid sequence, no character produced */
+#define        UNVIS_SYNBAD    -1      /* unrecognized escape sequence */
+#define        UNVIS_ERROR     -2      /* decoder in unknown state (unrecoverable) */
+
+/*
+ * unvis flags
+ */
+#define        UNVIS_END       1       /* no more characters */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char   *vis(char *, int, int, int);
+int    strvis(char *, const char *, int);
+int    strvisx(char *, const char *, size_t, int);
+int    strunvis(char *, const char *);
+int    strunvisx(char *, const char *, int);
+int    unvis(char *, int, int *, int);
+__END_DECLS
+
+#endif /* !_VIS_H_ */
index dcddb0b566708656fdb10d836ad68fa505e5b14f..472ae7050273d14365648cb66aad3653f6093425 100644 (file)
@@ -9,6 +9,7 @@ libcompat_a_SOURCES = \
        vasprintf.c \
        srandomdev.c \
        strlcat.c \
-       strlcpy.c
+       strlcpy.c \
+       vis.c
 
 libcompat_a_CFLAGS = -include config.h
diff --git a/varnish-cache/lib/libcompat/vis.c b/varnish-cache/lib/libcompat/vis.c
new file mode 100644 (file)
index 0000000..5496519
--- /dev/null
@@ -0,0 +1,214 @@
+/*-
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * @(#)vis.c   8.1 (Berkeley) 7/19/93
+ * $FreeBSD: src/lib/libc/gen/vis.c,v 1.13 2003/10/30 12:41:50 phk Exp $
+ * $Id$
+ */
+
+#if !defined(HAVE_VIS) || !defined(HAVE_STRVIS) || !defined(HAVE_STRVISX)
+
+#include <sys/types.h>
+#include <limits.h>
+#include <ctype.h>
+#include <stdio.h>
+
+#include "compat/vis.h"
+
+#define        isoctal(c)      (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+
+/*
+ * vis - visually encode characters
+ */
+#ifndef HAVE_VIS
+char *
+vis(dst, c, flag, nextc)
+       char *dst;
+       int c, nextc;
+       int flag;
+{
+       c = (unsigned char)c;
+
+       if (flag & VIS_HTTPSTYLE) {
+               /* Described in RFC 1808 */
+               if (!(isalnum(c) /* alpha-numeric */
+                   /* safe */
+                   || c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
+                   /* extra */
+                   || c == '!' || c == '*' || c == '\'' || c == '('
+                   || c == ')' || c == ',')) {
+                       *dst++ = '%';
+                       snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c);
+                       dst += 2;
+                       goto done;
+               }
+       }
+
+       if ((flag & VIS_GLOB) &&
+           (c == '*' || c == '?' || c == '[' || c == '#'))
+               ;
+       else if (isgraph(c) ||
+          ((flag & VIS_SP) == 0 && c == ' ') ||
+          ((flag & VIS_TAB) == 0 && c == '\t') ||
+          ((flag & VIS_NL) == 0 && c == '\n') ||
+          ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) {
+               *dst++ = c;
+               if (c == '\\' && (flag & VIS_NOSLASH) == 0)
+                       *dst++ = '\\';
+               *dst = '\0';
+               return (dst);
+       }
+
+       if (flag & VIS_CSTYLE) {
+               switch(c) {
+               case '\n':
+                       *dst++ = '\\';
+                       *dst++ = 'n';
+                       goto done;
+               case '\r':
+                       *dst++ = '\\';
+                       *dst++ = 'r';
+                       goto done;
+               case '\b':
+                       *dst++ = '\\';
+                       *dst++ = 'b';
+                       goto done;
+               case '\a':
+                       *dst++ = '\\';
+                       *dst++ = 'a';
+                       goto done;
+               case '\v':
+                       *dst++ = '\\';
+                       *dst++ = 'v';
+                       goto done;
+               case '\t':
+                       *dst++ = '\\';
+                       *dst++ = 't';
+                       goto done;
+               case '\f':
+                       *dst++ = '\\';
+                       *dst++ = 'f';
+                       goto done;
+               case ' ':
+                       *dst++ = '\\';
+                       *dst++ = 's';
+                       goto done;
+               case '\0':
+                       *dst++ = '\\';
+                       *dst++ = '0';
+                       if (isoctal(nextc)) {
+                               *dst++ = '0';
+                               *dst++ = '0';
+                       }
+                       goto done;
+               }
+       }
+       if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
+               *dst++ = '\\';
+               *dst++ = ((u_char)c >> 6 & 07) + '0';
+               *dst++ = ((u_char)c >> 3 & 07) + '0';
+               *dst++ = ((u_char)c & 07) + '0';
+               goto done;
+       }
+       if ((flag & VIS_NOSLASH) == 0)
+               *dst++ = '\\';
+       if (c & 0200) {
+               c &= 0177;
+               *dst++ = 'M';
+       }
+       if (iscntrl(c)) {
+               *dst++ = '^';
+               if (c == 0177)
+                       *dst++ = '?';
+               else
+                       *dst++ = c + '@';
+       } else {
+               *dst++ = '-';
+               *dst++ = c;
+       }
+done:
+       *dst = '\0';
+       return (dst);
+}
+#endif
+
+/*
+ * strvis, strvisx - visually encode characters from src into dst
+ *
+ *     Dst must be 4 times the size of src to account for possible
+ *     expansion.  The length of dst, not including the trailing NUL,
+ *     is returned.
+ *
+ *     Strvisx encodes exactly len bytes from src into dst.
+ *     This is useful for encoding a block of data.
+ */
+#ifndef HAVE_STRVIS
+int
+strvis(dst, src, flag)
+       char *dst;
+       const char *src;
+       int flag;
+{
+       char c;
+       char *start;
+
+       for (start = dst; (c = *src); )
+               dst = vis(dst, c, flag, *++src);
+       *dst = '\0';
+       return (dst - start);
+}
+#endif
+
+#ifndef HAVE_STRVISX
+int
+strvisx(dst, src, len, flag)
+       char *dst;
+       const char *src;
+       size_t len;
+       int flag;
+{
+       int c;
+       char *start;
+
+       for (start = dst; len > 1; len--) {
+               c = *src;
+               dst = vis(dst, c, flag, *++src);
+       }
+       if (len)
+               dst = vis(dst, *src, flag, '\0');
+       *dst = '\0';
+
+       return (dst - start);
+}
+#endif
+
+#endif