├── README.md ├── tests ├── a00014.vtc ├── a00012.vtc ├── a02004.vtc ├── a02003.vtc ├── a02013.vtc ├── a00010.vtc ├── a00018.vtc ├── a02019.vtc ├── a02017.vtc ├── a02018.vtc ├── a00021.vtc ├── a00007.vtc ├── a02022.vtc ├── a02002.vtc ├── a02011.vtc ├── a00011.vtc ├── a00015.vtc ├── a02000.vtc ├── a02010.vtc ├── a02024.vtc ├── a02016.vtc ├── a02005.vtc ├── a02023.vtc ├── a02006.vtc ├── a02020.vtc ├── a02021.vtc ├── a00002.vtc ├── a02015.vtc ├── a00008.vtc ├── a02012.vtc ├── a00006.vtc ├── a00013.vtc ├── a02014.vtc ├── a00019.vtc ├── a00004.vtc ├── a00005.vtc ├── a00003.vtc ├── a02007.vtc ├── a02009.vtc ├── a02001.vtc ├── a02008.vtc └── a00000.vtc ├── src ├── config.h ├── vtc_log.h ├── tbl │ ├── vsig_list.h │ ├── h2_stream.h │ ├── h2_settings.h │ ├── h2_error.h │ └── h2_frames.h ├── vtc_h2_priv.h ├── cmds.h ├── huffman_gen.py ├── vtc_http.h ├── hpack.h ├── teken_scs.h ├── vtc_h2_stattbl.h ├── vtc_proxy.c ├── teken_subr_compat.h ├── vtc_sess.c ├── sequences ├── gensequences └── teken_wcwidth.h ├── diff.sh ├── a00020.vtc ├── LICENSE ├── lib ├── vfl.h ├── vsub.h ├── vus.h ├── vpf.h ├── vrnd.h ├── vre_pcre2.h ├── vav.h ├── vtim.h ├── vlu.h ├── vsig.h ├── vss.h ├── vfil.h ├── vnum.h ├── miniobj.h ├── vev.h ├── vjsn.h ├── vcli.h ├── vre.h ├── vbh.h ├── vtcp.h ├── vas.c ├── vsa.h ├── vend.h ├── vfl.c ├── vlu.c ├── vus.c ├── vas.h ├── vsb.h ├── vpf.c ├── vct.h ├── vsub.c └── vrnd.c └── Makefile /README.md: -------------------------------------------------------------------------------- 1 | # VTest 2 | 3 | VTest is now archived. Please use https://github.com/vtest/VTest2 in place. 4 | 5 | *EOF* 6 | -------------------------------------------------------------------------------- /tests/a00014.vtc: -------------------------------------------------------------------------------- 1 | vtest "Custom feature verification" 2 | 3 | feature cmd true 4 | feature cmd false 5 | 6 | this is an invalid vtest command 7 | -------------------------------------------------------------------------------- /tests/a00012.vtc: -------------------------------------------------------------------------------- 1 | vtest "Ensure that we can test non-existence of headers (#1062)" 2 | 3 | server s1 { 4 | rxreq 5 | txresp 6 | } -start 7 | 8 | client c1 -connect ${s1_sock} { 9 | txreq 10 | rxresp 11 | expect resp.http.X-Test == 12 | } -run 13 | 14 | -------------------------------------------------------------------------------- /tests/a02004.vtc: -------------------------------------------------------------------------------- 1 | vtest "Simple request with body" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -body "bob" 7 | } -run 8 | } -start 9 | 10 | client c1 -connect ${s1_sock} { 11 | stream 1 { 12 | txreq 13 | rxresp 14 | expect resp.bodylen == 3 15 | } -run 16 | } -run 17 | -------------------------------------------------------------------------------- /tests/a02003.vtc: -------------------------------------------------------------------------------- 1 | vtest "Check bodylen" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | expect req.bodylen == 3 7 | txresp -bodylen 7 8 | } -run 9 | } -start 10 | 11 | client c1 -connect ${s1_sock} { 12 | stream 1 { 13 | txreq -bodylen 3 14 | rxresp 15 | expect resp.bodylen == 7 16 | } -run 17 | } -run 18 | -------------------------------------------------------------------------------- /tests/a02013.vtc: -------------------------------------------------------------------------------- 1 | vtest "H/2 state after sending/receiving preface" 2 | 3 | server s1 { 4 | expect h2.state == false 5 | rxpri 6 | expect h2.state == true 7 | } -start 8 | 9 | client c1 -connect ${s1_sock} { 10 | expect h2.state == false 11 | txpri 12 | expect h2.state == true 13 | } -start 14 | 15 | server s1 -wait 16 | -------------------------------------------------------------------------------- /tests/a00010.vtc: -------------------------------------------------------------------------------- 1 | vtest "simply test that the framework support \0" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.url == "/" 6 | txresp -body {a\0bc} 7 | } 8 | 9 | server s1 -start 10 | 11 | client c1 -connect ${s1_sock} { 12 | 13 | txreq 14 | rxresp 15 | expect resp.bodylen == 4 16 | } 17 | 18 | client c1 -run 19 | 20 | server s1 -wait 21 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | 2 | #define HAVE_CLOCK_GETTIME 1 3 | #define HAVE_NANOSLEEP 1 4 | 5 | #ifdef __linux__ 6 | # define _GNU_SOURCE 1 7 | # define HAVE_SYS_VFS_H 1 8 | # define HAVE_FALLOCATE 1 9 | #else 10 | # define HAVE_STATVFS_H 1 11 | # define HAVE_SYS_MOUNT_H 1 12 | #endif 13 | 14 | #ifdef __FreeBSD__ 15 | # define HAVE_CLOSEFROM 1 16 | #endif 17 | -------------------------------------------------------------------------------- /tests/a00018.vtc: -------------------------------------------------------------------------------- 1 | vtest "feature ignore_unknown_macro" 2 | 3 | feature ignore_unknown_macro 4 | 5 | server s1 { 6 | rxreq 7 | expect req.http.Foo == "${foo}" 8 | txresp -hdr "Bar: ${bar}" 9 | } -start 10 | 11 | client c1 -connect ${s1_sock} { 12 | txreq -hdr "Foo: ${foo}" 13 | rxresp 14 | expect resp.status == 200 15 | expect resp.http.Bar == "${bar}" 16 | } -run 17 | -------------------------------------------------------------------------------- /tests/a02019.vtc: -------------------------------------------------------------------------------- 1 | vtest "Static table encoding" 2 | server s1 { 3 | stream 1 { 4 | rxreq 5 | expect req.http.:path == "/index.html" 6 | txresp 7 | } -run 8 | 9 | } -start 10 | 11 | client c1 -connect ${s1_sock} { 12 | stream 1 { 13 | 14 | txreq -idxHdr 2 \ 15 | -idxHdr 6 \ 16 | -idxHdr 5 17 | rxresp 18 | } -run 19 | 20 | 21 | } -run 22 | 23 | server s1 -wait 24 | -------------------------------------------------------------------------------- /tests/a02017.vtc: -------------------------------------------------------------------------------- 1 | vtest "Push promise" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txpush -promised 2 -url "/hereyougo" 7 | txresp 8 | } -run 9 | } -start 10 | 11 | client c1 -connect ${s1_sock} { 12 | stream 1 { 13 | txreq 14 | rxpush 15 | expect push.id == 2 16 | expect req.url == "/hereyougo" 17 | expect req.method == "GET" 18 | rxresp 19 | } -run 20 | } -run 21 | 22 | server s1 -wait 23 | -------------------------------------------------------------------------------- /tests/a02018.vtc: -------------------------------------------------------------------------------- 1 | vtest "H/2 state after sending/receiving preface" 2 | 3 | server s1 { 4 | expect h2.state == "false" 5 | stream 1 { 6 | rxreq 7 | txresp 8 | } -run 9 | expect h2.state == "true" 10 | } -start 11 | 12 | client c1 -connect ${s1_sock} { 13 | expect h2.state == "false" 14 | stream 1 { 15 | txreq 16 | rxresp 17 | } -run 18 | expect h2.state == "true" 19 | } -start 20 | 21 | server s1 -wait 22 | -------------------------------------------------------------------------------- /diff.sh: -------------------------------------------------------------------------------- 1 | 2 | VT=/home/phk/Varnish/trunk/varnish-cache 3 | 4 | for i in `find lib src -type f -print` 5 | do 6 | b=`basename $i` 7 | d=false 8 | for j in \ 9 | ${VT}/include/$b \ 10 | ${VT}/include/tbl/$b \ 11 | ${VT}/lib/libvarnish/$b \ 12 | ${VT}/bin/varnishtest/$b 13 | do 14 | if [ -f $j ] ; then 15 | diff -u $i $j 16 | d=true 17 | break 18 | fi 19 | done 20 | if ! $d ; then 21 | echo "MISSING $i" 22 | fi 23 | done 24 | -------------------------------------------------------------------------------- /tests/a00021.vtc: -------------------------------------------------------------------------------- 1 | varnishtest "Test VTC includes" 2 | 3 | shell { 4 | cat >${tmpdir}/f1 <<-EOF 5 | rxreq 6 | EOF 7 | } 8 | 9 | shell { 10 | cat >${tmpdir}/f2 <<-EOF 11 | txresp 12 | EOF 13 | } 14 | 15 | shell { 16 | cat >${tmpdir}/f3 <<-EOF 17 | server s1 { 18 | include "${tmpdir}/f1" "${tmpdir}/f2" 19 | } -start 20 | EOF 21 | } 22 | 23 | include "${tmpdir}/f3" 24 | 25 | client c1 -connect "${s1_sock}" { 26 | txreq 27 | rxresp 28 | } -run 29 | -------------------------------------------------------------------------------- /tests/a00007.vtc: -------------------------------------------------------------------------------- 1 | vtest "TCP reuse" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.url == "/1" 6 | txresp -body "123456789\n" 7 | rxreq 8 | expect req.url == "/2" 9 | txresp -body "987654321\n" 10 | } 11 | 12 | server s1 -start 13 | 14 | client c1 -connect ${s1_sock} { 15 | txreq -url "/1" -req "POST" -body "abcdefghi\n" 16 | rxresp 17 | txreq -url "/2" -req "POST" -body "ihgfedcba\n" 18 | rxresp 19 | } 20 | 21 | client c1 -run 22 | 23 | server s1 -wait 24 | -------------------------------------------------------------------------------- /tests/a02022.vtc: -------------------------------------------------------------------------------- 1 | vtest "H/1 -> H/2 upgrade" 2 | 3 | feature cmd "nghttp --version | grep -q 'nghttp2/[1-9]'" 4 | 5 | server s1 { 6 | rxreq 7 | upgrade 8 | 9 | stream 3 { rxprio } -run 10 | stream 5 { rxprio } -run 11 | stream 7 { rxprio } -run 12 | stream 9 { rxprio } -run 13 | stream 11 { rxprio } -run 14 | 15 | stream 1 { 16 | rxprio 17 | txresp 18 | } -start 19 | 20 | } -start 21 | 22 | 23 | shell { nghttp http://${s1_addr}:${s1_port} -nu } 24 | -------------------------------------------------------------------------------- /tests/a02002.vtc: -------------------------------------------------------------------------------- 1 | vtest "Trigger a compression error via bad index" 2 | 3 | server s1 { 4 | non_fatal 5 | stream 1 { 6 | rxreq 7 | expect req.http.foo == 8 | txgoaway -laststream 0 -err 9 -debug "compression_error" 9 | } -run 10 | } -start 11 | 12 | client c1 -connect ${s1_sock} { 13 | stream 1 { 14 | txreq -idxHdr 100 -litHdr inc plain "foo" plain "bar" 15 | rxgoaway 16 | expect goaway.err == 9 17 | expect goaway.laststream == 0 18 | expect goaway.debug == "compression_error" 19 | } -run 20 | } -run 21 | -------------------------------------------------------------------------------- /tests/a02011.vtc: -------------------------------------------------------------------------------- 1 | vtest "overflow" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -hdr long-header-original1 original1 \ 7 | -hdr long-header-original2 original2 \ 8 | -hdr long-header-original3 original3 \ 9 | -hdr long-header-original4 original4 10 | } -run 11 | } -start 12 | 13 | client c1 -connect ${s1_sock} { 14 | stream 1 { 15 | txreq -req GET \ 16 | -url / \ 17 | -hdr :scheme http \ 18 | -hdr :authority localhost 19 | rxresp 20 | expect resp.http.:status == 200 21 | } -run 22 | } -run 23 | -------------------------------------------------------------------------------- /tests/a00011.vtc: -------------------------------------------------------------------------------- 1 | vtest "test vtc gzip support" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.http.content-length == "26" 6 | expect req.bodylen == "26" 7 | gunzip 8 | expect req.bodylen == "3" 9 | expect req.http.content-encoding == "gzip" 10 | txresp -gzipbody FOO 11 | } -start 12 | 13 | client c1 -connect ${s1_sock} { 14 | txreq -gzipbody FOO 15 | rxresp 16 | expect resp.http.content-length == "26" 17 | expect resp.bodylen == "26" 18 | gunzip 19 | expect resp.bodylen == "3" 20 | expect resp.http.content-encoding == "gzip" 21 | } -run 22 | -------------------------------------------------------------------------------- /tests/a00015.vtc: -------------------------------------------------------------------------------- 1 | vtest "Write a body to a file" 2 | 3 | server s1 { 4 | # First, HTTP checks 5 | rxreq 6 | expect req.http.Content-Type == "text/plain" 7 | 8 | # Then, payload checks 9 | write_body req.txt 10 | shell {grep -q request req.txt} 11 | 12 | txresp -hdr "Content-Type: text/plain" -body response 13 | } -start 14 | 15 | client c1 -connect ${s1_sock} { 16 | txreq -req POST -hdr "Content-Type: text/plain" -body request 17 | 18 | # First, HTTP checks 19 | rxresp 20 | expect resp.http.Content-Type == "text/plain" 21 | 22 | # Then, payload checks 23 | write_body resp.txt 24 | shell {grep -q response resp.txt} 25 | } -run 26 | -------------------------------------------------------------------------------- /tests/a02000.vtc: -------------------------------------------------------------------------------- 1 | vtest "Close/accept after H/2 upgrade" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp 7 | } -run 8 | 9 | expect_close 10 | accept 11 | 12 | rxreq 13 | txresp 14 | 15 | close 16 | accept 17 | 18 | rxreq 19 | txresp 20 | 21 | stream 1 { 22 | rxreq 23 | txresp 24 | } -run 25 | } -start 26 | 27 | client c1 -connect ${s1_sock} { 28 | stream 1 { 29 | txreq 30 | rxresp 31 | } -run 32 | } -run 33 | 34 | client c1 -connect ${s1_sock} { 35 | txreq 36 | rxresp 37 | 38 | } -run 39 | 40 | client c1 -connect ${s1_sock} { 41 | txreq 42 | rxresp 43 | 44 | stream 1 { 45 | txreq 46 | rxresp 47 | } -run 48 | } -run 49 | 50 | server s1 -wait 51 | -------------------------------------------------------------------------------- /tests/a02010.vtc: -------------------------------------------------------------------------------- 1 | vtest "Verify the initial window size" 2 | 3 | server s1 { 4 | stream 0 { 5 | rxsettings 6 | txsettings -ack 7 | } -run 8 | stream 1 { 9 | rxreq 10 | txresp -bodylen 100 11 | } -run 12 | stream 0 { 13 | rxsettings 14 | txsettings -ack 15 | } -run 16 | } -start 17 | 18 | client c1 -connect ${s1_sock} { 19 | stream 0 { 20 | txsettings -winsize 128 21 | rxsettings 22 | } -run 23 | stream 1 { 24 | txreq 25 | rxresp 26 | expect resp.bodylen == 100 27 | expect stream.window == 28 28 | } -run 29 | stream 0 { 30 | txsettings -winsize 64 31 | rxsettings 32 | 33 | expect stream.window == 65435 34 | } -run 35 | stream 1 { 36 | expect stream.window == -36 37 | } -run 38 | } -run 39 | 40 | server s1 -wait 41 | -------------------------------------------------------------------------------- /a00020.vtc: -------------------------------------------------------------------------------- 1 | varnishtest "Test HAproxy CLI facility" 2 | 3 | #REQUIRE_VERSION=1.9 4 | 5 | feature ignore_unknown_macro 6 | feature cmd {haproxy --version 2>&1 | grep -q 'HA-Proxy version'} 7 | 8 | # Do nothing. Is there only to create s1_* macros 9 | server s1 { 10 | } -start 11 | 12 | haproxy h1 -W -S -conf { 13 | global 14 | nbproc 4 15 | defaults 16 | mode http 17 | # ${no-htx} option http-use-htx 18 | timeout connect 1s 19 | timeout client 1s 20 | timeout server 1s 21 | 22 | frontend myfrontend 23 | bind "fd@${my_fe}" 24 | default_backend test 25 | 26 | backend test 27 | server www1 ${s1_addr}:${s1_port} 28 | } -start 29 | 30 | haproxy h1 -mcli { 31 | send "@3 show info" 32 | expect ~ ".*\nProcess_num: 3\n.*" 33 | } -wait 34 | -------------------------------------------------------------------------------- /tests/a02024.vtc: -------------------------------------------------------------------------------- 1 | vtest "Write a body to a file" 2 | 3 | server s1 { 4 | fatal 5 | stream 1 { 6 | # First, HTTP checks 7 | rxreq 8 | expect req.http.Content-Type == "text/plain" 9 | 10 | # Then, payload checks 11 | write_body req.txt 12 | shell {grep -q request req.txt} 13 | 14 | txresp -hdr Content-Type text/plain -body response 15 | } -run 16 | 17 | } -start 18 | 19 | client c1 -connect ${s1_sock} { 20 | fatal 21 | stream 1 { 22 | txreq -req POST -hdr Content-Type text/plain -body request 23 | 24 | # First, HTTP checks 25 | rxresp 26 | expect resp.http.Content-Type == "text/plain" 27 | 28 | # Then, payload checks 29 | write_body resp.txt 30 | shell {grep -q response resp.txt} 31 | } -run 32 | } -run 33 | 34 | server s1 -wait 35 | -------------------------------------------------------------------------------- /tests/a02016.vtc: -------------------------------------------------------------------------------- 1 | vtest "Test pseudo-headers inspection" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | 7 | expect req.url == "/foo" 8 | expect req.http.:path == "/foo" 9 | 10 | expect req.method == "NOTGET" 11 | expect req.http.:method == "NOTGET" 12 | 13 | expect req.authority == "bar" 14 | expect req.http.:authority == "bar" 15 | 16 | expect req.scheme == "baz" 17 | expect req.http.:scheme == "baz" 18 | 19 | txresp -status 123 20 | } -run 21 | } -start 22 | 23 | client c1 -connect ${s1_sock} { 24 | stream 1 { 25 | txreq -url "/foo" \ 26 | -req "NOTGET" \ 27 | -hdr ":authority" "bar" \ 28 | -scheme "baz" 29 | 30 | rxresp 31 | 32 | expect resp.status == 123 33 | expect resp.http.:status == 123 34 | } -run 35 | } -start 36 | 37 | server s1 -wait 38 | -------------------------------------------------------------------------------- /tests/a02005.vtc: -------------------------------------------------------------------------------- 1 | vtest "Continuation frames" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -nohdrend 7 | txcont -nohdrend -hdr "foo" "bar" 8 | txcont -hdr "baz" "qux" 9 | } -run 10 | stream 3 { 11 | rxreq 12 | txresp -nohdrend 13 | txcont -nohdrend -hdr "foo2" "bar2" 14 | txcont -hdr "baz2" "qux2" 15 | } -run 16 | } -start 17 | 18 | client c1 -connect ${s1_sock} { 19 | stream 1 { 20 | txreq 21 | rxhdrs -all 22 | expect resp.http.foo == "bar" 23 | expect resp.http.baz == "qux" 24 | } -run 25 | stream 3 { 26 | txreq 27 | rxhdrs -some 2 28 | expect resp.http.foo2 == 29 | expect resp.http.baz2 == 30 | rxcont 31 | expect resp.http.foo2 == "bar2" 32 | expect resp.http.baz2 == "qux2" 33 | } -run 34 | } -run 35 | 36 | server s1 -wait 37 | -------------------------------------------------------------------------------- /tests/a02023.vtc: -------------------------------------------------------------------------------- 1 | vtest "Window update" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -body "bob" 7 | } -run 8 | stream 3 { 9 | rxreq 10 | txresp -nohdrend 11 | txcont -nohdrend -hdr "foo" "bar" 12 | txcont -hdr "baz" "qux" 13 | txdata -data "foo" 14 | txdata -data "bar" 15 | } -run 16 | 17 | } -start 18 | 19 | client c1 -connect ${s1_sock} { 20 | stream 1 { 21 | txreq 22 | rxresp 23 | expect resp.bodylen == 3 24 | } -run 25 | stream 3 { 26 | txreq 27 | rxhdrs 28 | rxcont 29 | rxcont 30 | expect resp.http.:status == "200" 31 | expect resp.http.foo == "bar" 32 | expect stream.window == 65535 33 | 34 | rxdata 35 | expect stream.window == 65532 36 | 37 | rxdata 38 | expect stream.window == 65529 39 | expect resp.body == "foobar" 40 | expect resp.http.baz == "qux" 41 | } -run 42 | } -run 43 | 44 | server s1 -wait 45 | -------------------------------------------------------------------------------- /tests/a02006.vtc: -------------------------------------------------------------------------------- 1 | vtest "Keep track of window credits" 2 | 3 | server s1 { 4 | stream 2 { 5 | rxreq 6 | txresp -nohdrend 7 | txcont -nohdrend -hdr "foo" "bar" 8 | txcont -hdr "baz" "qux" 9 | txdata -data "foo" 10 | txdata -data "bar" 11 | } -run 12 | 13 | } -start 14 | 15 | client c1 -connect ${s1_sock} { 16 | stream 0 { 17 | expect stream.window == 65535 18 | } -run 19 | stream 2 { 20 | expect stream.window == 65535 21 | txreq 22 | rxhdrs 23 | rxcont 24 | rxcont 25 | expect resp.http.:status == "200" 26 | expect resp.http.foo == "bar" 27 | expect stream.window == 65535 28 | rxdata 29 | expect stream.window == 65532 30 | rxdata 31 | expect stream.window == 65529 32 | expect resp.body == "foobar" 33 | expect resp.http.baz == "qux" 34 | } -run 35 | stream 0 { 36 | expect stream.window == 65529 37 | } -run 38 | } -run 39 | 40 | server s1 -wait 41 | -------------------------------------------------------------------------------- /tests/a02020.vtc: -------------------------------------------------------------------------------- 1 | vtest "Reduce dynamic table while incoming headers are flying" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -litHdr inc plain hoge plain fuga 7 | expect tbl.enc[1].key == "hoge" 8 | expect tbl.enc[1].value == "fuga" 9 | expect tbl.enc.size == 40 10 | 11 | } -run 12 | 13 | 14 | stream 3 { 15 | rxreq 16 | txresp -idxHdr 62 -litHdr inc plain "foo" plain "bar" 17 | } -run 18 | 19 | stream 0 { rxsettings } -run 20 | } -start 21 | 22 | client c1 -connect ${s1_sock} { 23 | stream 1 { 24 | txreq 25 | rxresp 26 | expect tbl.dec[1].key == "hoge" 27 | expect tbl.dec[1].value == "fuga" 28 | expect tbl.dec.size == 40 29 | expect tbl.dec.length == 1 30 | } -run 31 | 32 | stream 3 { txreq } -run 33 | stream 0 { txsettings -hdrtbl 0 } -run 34 | 35 | non_fatal 36 | stream 3 { 37 | rxresp 38 | expect resp.http.foo == 39 | } -run 40 | 41 | } -run 42 | -------------------------------------------------------------------------------- /tests/a02021.vtc: -------------------------------------------------------------------------------- 1 | vtest "Reduce dynamic table size" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp -litHdr inc plain hoge plain fuga 7 | expect tbl.dec.size == 57 8 | expect tbl.enc.size == 40 9 | } -run 10 | 11 | stream 0 { 12 | rxsettings 13 | txsettings -ack 14 | } -run 15 | 16 | stream 3 { 17 | rxreq 18 | expect tbl.dec.size == 110 19 | expect tbl.enc.size == 0 20 | txresp 21 | } -run 22 | } -start 23 | 24 | client c1 -connect ${s1_sock} { 25 | stream 1 { 26 | txreq -idxHdr 2 \ 27 | -idxHdr 6 \ 28 | -idxHdr 4 \ 29 | -litIdxHdr inc 1 huf "www.example.com" 30 | rxresp 31 | expect tbl.dec.size == 40 32 | expect tbl.enc.size == 57 33 | } -run 34 | 35 | stream 0 { 36 | txsettings -hdrtbl 0 37 | rxsettings 38 | } -run 39 | 40 | stream 3 { 41 | txreq -idxHdr 2 \ 42 | -idxHdr 6 \ 43 | -idxHdr 4 \ 44 | -idxHdr 62 \ 45 | -litIdxHdr inc 24 huf no-cache 46 | expect tbl.enc.size == 110 47 | expect tbl.dec.size == 0 48 | rxresp 49 | } -run 50 | } -run 51 | 52 | server s1 -wait 53 | -------------------------------------------------------------------------------- /tests/a00002.vtc: -------------------------------------------------------------------------------- 1 | vtest "basic default HTTP transactions with expect and options" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.method == PUT 6 | expect req.proto == HTTP/1.0 7 | expect req.url == "/foo" 8 | txresp -proto HTTP/1.2 -status 201 -reason Foo 9 | } 10 | 11 | server s1 -start 12 | 13 | client c1 -connect ${s1_sock} { 14 | txreq -req PUT -proto HTTP/1.0 -url /foo 15 | rxresp 16 | expect resp.proto == HTTP/1.2 17 | expect resp.status == 201 18 | expect resp.reason == Foo 19 | } 20 | 21 | client c1 -run 22 | 23 | server s1 -wait 24 | 25 | # The same tests with unix domain sockets 26 | server s2 -listen "${tmpdir}/s2.sock" { 27 | rxreq 28 | expect req.method == PUT 29 | expect req.proto == HTTP/1.0 30 | expect req.url == "/foo" 31 | txresp -proto HTTP/1.2 -status 201 -reason Foo 32 | } -start 33 | 34 | client c2 -connect ${s2_sock} { 35 | txreq -req PUT -proto HTTP/1.0 -url /foo 36 | rxresp 37 | expect resp.proto == HTTP/1.2 38 | expect resp.status == 201 39 | expect resp.reason == Foo 40 | } 41 | 42 | client c2 -run 43 | 44 | server s2 -wait 45 | -------------------------------------------------------------------------------- /tests/a02015.vtc: -------------------------------------------------------------------------------- 1 | vtest "exclusive dependency" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp 7 | } -run 8 | stream 3 { 9 | rxreq 10 | txresp 11 | } -run 12 | stream 5 { 13 | rxreq 14 | txresp 15 | expect stream.dependency == 0 16 | } -run 17 | 18 | stream 1 { 19 | expect stream.dependency == 5 20 | } -run 21 | stream 3 { 22 | expect stream.dependency == 5 23 | } -run 24 | 25 | stream 1 { 26 | rxprio 27 | } -run 28 | stream 5 { 29 | expect stream.dependency == 1 30 | } -run 31 | 32 | } -start 33 | client c1 -connect ${s1_sock} { 34 | stream 1 { 35 | txreq 36 | rxresp 37 | } -run 38 | stream 3 { 39 | txreq 40 | rxresp 41 | } -run 42 | stream 5 { 43 | txreq -req GET -ex 44 | expect stream.dependency == 0 45 | rxresp 46 | } -run 47 | 48 | stream 1 { 49 | expect stream.dependency == 5 50 | } -run 51 | stream 3 { 52 | expect stream.dependency == 5 53 | } -run 54 | 55 | stream 1 { 56 | txprio -stream 0 -ex 57 | } -run 58 | stream 5 { 59 | expect stream.dependency == 1 60 | } -run 61 | } -run 62 | 63 | server s1 -wait 64 | -------------------------------------------------------------------------------- /tests/a00008.vtc: -------------------------------------------------------------------------------- 1 | vtest "Barrier operations" 2 | 3 | # bs -> server, bc -> client, bb -> both 4 | barrier bs cond 4 5 | barrier bc cond 4 6 | barrier bb cond 4 -cyclic 7 | 8 | server s1 { 9 | rxreq 10 | barrier bs sync 11 | barrier bb sync 12 | delay .9 13 | txresp 14 | } -start 15 | 16 | server s2 { 17 | rxreq 18 | barrier bs sync 19 | barrier bb sync 20 | delay .6 21 | txresp 22 | } -start 23 | 24 | server s3 { 25 | rxreq 26 | barrier bs sync 27 | barrier bb sync 28 | delay .2 29 | txresp 30 | } -start 31 | 32 | client c1 -connect ${s1_sock} { 33 | delay .2 34 | txreq 35 | rxresp 36 | barrier bc sync 37 | barrier bb sync 38 | } -start 39 | 40 | client c2 -connect ${s2_sock} { 41 | delay .6 42 | txreq 43 | rxresp 44 | barrier bc sync 45 | barrier bb sync 46 | } -start 47 | 48 | client c3 -connect ${s3_sock} { 49 | delay .9 50 | txreq 51 | rxresp 52 | barrier bc sync 53 | barrier bb sync 54 | } -start 55 | 56 | # Wait for all servers to have received requests 57 | barrier bs sync 58 | barrier bb sync 59 | 60 | # Wait for all clients to have received responses 61 | barrier bc sync 62 | barrier bb sync 63 | -------------------------------------------------------------------------------- /tests/a02012.vtc: -------------------------------------------------------------------------------- 1 | vtest "padded DATA frames" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | # HDR indexed ":status: 200" + 2 padding bytes 7 | sendhex "00 00 04 01 0c 00 00 00 01 02 88 12 34" 8 | # DATA "foo" + 4 padding bytes 9 | sendhex "00 00 08 00 09 00 00 00 01 04 66 6f 6f 6e 6e 6e 6e" 10 | 11 | } -run 12 | 13 | stream 3 { 14 | rxreq 15 | txresp -nostrend 16 | txdata -data "bull" -pad "frog" -nostrend 17 | txdata -data "terrier" -padlen 17 18 | txdata -datalen 4 -padlen 2 19 | } -run 20 | 21 | stream 5 { 22 | rxreq 23 | txresp -pad "pwepew" 24 | } -run 25 | } -start 26 | 27 | client c1 -connect ${s1_sock} { 28 | stream 1 { 29 | txreq 30 | rxresp 31 | expect resp.bodylen == 3 32 | expect resp.body == "foo" 33 | } -run 34 | 35 | stream 3 { 36 | txreq 37 | rxhdrs 38 | 39 | rxdata 40 | expect frame.size == 9 41 | expect resp.body == "bull" 42 | 43 | rxdata 44 | expect frame.size == 25 45 | expect resp.body == "bullterrier" 46 | 47 | rxdata 48 | expect frame.size == 7 49 | } -run 50 | 51 | stream 5 { 52 | txreq 53 | rxresp 54 | expect frame.padding == 6 55 | } -run 56 | } -run 57 | -------------------------------------------------------------------------------- /tests/a00006.vtc: -------------------------------------------------------------------------------- 1 | vtest "bidirectional message bodies" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.method == PUT 6 | expect req.proto == HTTP/1.0 7 | expect req.url == "/foo" 8 | txresp -proto HTTP/1.2 -status 201 -reason Foo \ 9 | -body "987654321\n" 10 | } 11 | 12 | server s1 -start 13 | 14 | client c1 -connect ${s1_sock} { 15 | txreq -req PUT -proto HTTP/1.0 -url /foo \ 16 | -body "123456789\n" 17 | rxresp 18 | expect resp.proto == HTTP/1.2 19 | expect resp.status == 201 20 | expect resp.reason == Foo 21 | } 22 | 23 | client c1 -run 24 | 25 | server s1 -wait 26 | 27 | # The same tests with Unix domain sockets 28 | server s2 -listen "${tmpdir}/s2.sock" { 29 | rxreq 30 | expect req.method == PUT 31 | expect req.proto == HTTP/1.0 32 | expect req.url == "/foo" 33 | txresp -proto HTTP/1.2 -status 201 -reason Foo \ 34 | -body "987654321\n" 35 | } 36 | 37 | server s2 -start 38 | 39 | client c2 -connect ${s2_sock} { 40 | txreq -req PUT -proto HTTP/1.0 -url /foo \ 41 | -body "123456789\n" 42 | rxresp 43 | expect resp.proto == HTTP/1.2 44 | expect resp.status == 201 45 | expect resp.reason == Foo 46 | } 47 | 48 | client c2 -run 49 | 50 | server s2 -wait 51 | -------------------------------------------------------------------------------- /tests/a00013.vtc: -------------------------------------------------------------------------------- 1 | vtest "Barrier operations" 2 | 3 | # same as a00008.vtc, with socket barriers instead 4 | 5 | # bs -> server, bc -> client, bb -> both 6 | barrier bs sock 4 7 | barrier bc sock 4 8 | barrier bb sock 4 -cyclic 9 | 10 | server s1 { 11 | rxreq 12 | barrier bs sync 13 | barrier bb sync 14 | delay .9 15 | txresp 16 | } -start 17 | 18 | server s2 { 19 | rxreq 20 | barrier bs sync 21 | barrier bb sync 22 | delay .6 23 | txresp 24 | } -start 25 | 26 | server s3 { 27 | rxreq 28 | barrier bs sync 29 | barrier bb sync 30 | delay .2 31 | txresp 32 | } -start 33 | 34 | client c1 -connect ${s1_sock} { 35 | delay .2 36 | txreq 37 | rxresp 38 | barrier bc sync 39 | barrier bb sync 40 | } -start 41 | 42 | client c2 -connect ${s2_sock} { 43 | delay .6 44 | txreq 45 | rxresp 46 | barrier bc sync 47 | barrier bb sync 48 | } -start 49 | 50 | client c3 -connect ${s3_sock} { 51 | delay .9 52 | txreq 53 | rxresp 54 | barrier bc sync 55 | barrier bb sync 56 | } -start 57 | 58 | # Wait for all servers to have received requests 59 | barrier bs sync 60 | barrier bb sync 61 | 62 | # Wait for all clients to have received responses 63 | barrier bc sync 64 | barrier bb sync 65 | -------------------------------------------------------------------------------- /tests/a02014.vtc: -------------------------------------------------------------------------------- 1 | vtest "priority" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | txresp 7 | expect stream.weight == 16 8 | expect stream.dependency == 0 9 | } -run 10 | stream 3 { 11 | rxreq 12 | txresp 13 | expect stream.weight == 123 14 | expect stream.dependency == 5 15 | 16 | rxprio 17 | expect prio.weight == 10 18 | expect prio.stream == 7 19 | expect stream.weight == 10 20 | expect stream.dependency == 7 21 | } -run 22 | } -start 23 | client c1 -connect ${s1_sock} { 24 | stream 1 { 25 | txreq -req GET -url /1 \ 26 | -hdr :scheme http -hdr :authority localhost 27 | rxresp 28 | expect stream.weight == 16 29 | expect stream.dependency == 0 30 | } -run 31 | stream 3 { 32 | txreq -req GET -url /3 \ 33 | -hdr :scheme http -hdr :authority localhost \ 34 | -weight 123 -ex -dep 5 35 | rxresp 36 | expect stream.weight == 123 37 | expect stream.dependency == 5 38 | 39 | txprio -weight 10 -stream 7 40 | expect stream.weight == 10 41 | expect stream.dependency == 7 42 | } -run 43 | stream 5 { 44 | expect stream.weight == 16 45 | expect stream.dependency == 0 46 | } -run 47 | stream 0 { 48 | expect stream.weight == 49 | expect stream.dependency == 50 | } -run 51 | } -run 52 | server s1 -wait 53 | -------------------------------------------------------------------------------- /tests/a00019.vtc: -------------------------------------------------------------------------------- 1 | varnishtest "Check rxrespbody -max" 2 | 3 | server s1 { 4 | rxreq 5 | txresp -bodylen 65536 6 | rxreq 7 | txresp 8 | } -start 9 | 10 | server s2 { 11 | rxreq 12 | txresp -nolen -hdr "Transfer-Encoding: chunked" 13 | chunkedlen 8192 14 | chunkedlen 4096 15 | chunkedlen 4096 16 | chunkedlen 16384 17 | chunkedlen 16384 18 | chunkedlen 16384 19 | chunkedlen 0 20 | rxreq 21 | txresp 22 | } -start 23 | 24 | server s3 { 25 | rxreq 26 | txresp -nolen -bodylen 65536 27 | } -start 28 | 29 | client c1 -connect ${s1_sock} { 30 | txreq 31 | rxresphdrs 32 | rxrespbody -max 8192 33 | expect resp.bodylen == 8192 34 | rxrespbody -max 8192 35 | expect resp.bodylen == 16384 36 | rxrespbody 37 | expect resp.bodylen == 65536 38 | txreq 39 | rxresp 40 | } -run 41 | 42 | client c2 -connect ${s2_sock} { 43 | txreq 44 | rxresphdrs 45 | rxrespbody -max 8192 46 | expect resp.bodylen == 8192 47 | rxrespbody -max 8192 48 | expect resp.bodylen == 16384 49 | rxrespbody 50 | expect resp.bodylen == 65536 51 | txreq 52 | rxresp 53 | } -run 54 | 55 | client c3 -connect ${s3_sock} { 56 | txreq 57 | rxresphdrs 58 | rxrespbody -max 8192 59 | expect resp.bodylen == 8192 60 | rxrespbody -max 8192 61 | expect resp.bodylen == 16384 62 | rxrespbody 63 | expect resp.bodylen == 65536 64 | } -run 65 | -------------------------------------------------------------------------------- /tests/a00004.vtc: -------------------------------------------------------------------------------- 1 | vtest "dual shared server HTTP transactions" 2 | 3 | server s1 -repeat 2 { 4 | rxreq 5 | expect req.method == PUT 6 | expect req.proto == HTTP/1.0 7 | expect req.url == "/foo" 8 | txresp -proto HTTP/1.2 -status 201 -reason Foo 9 | } 10 | 11 | server s1 -start 12 | 13 | client c1 -connect ${s1_sock} { 14 | txreq -req PUT -proto HTTP/1.0 -url /foo 15 | rxresp 16 | expect resp.proto == HTTP/1.2 17 | expect resp.status == 201 18 | expect resp.reason == Foo 19 | } 20 | 21 | client c2 -connect ${s1_sock} { 22 | txreq -req PUT -proto HTTP/1.0 -url /foo 23 | rxresp 24 | expect resp.proto == HTTP/1.2 25 | expect resp.status == 201 26 | expect resp.reason == Foo 27 | } 28 | 29 | client c1 -start 30 | client c2 -start 31 | 32 | client c1 -wait 33 | client c2 -wait 34 | 35 | server s1 -wait 36 | 37 | # The same tests with Unix domain sockets 38 | server s2 -repeat 2 -listen "${tmpdir}/s2.sock" { 39 | rxreq 40 | expect req.method == PUT 41 | expect req.proto == HTTP/1.0 42 | expect req.url == "/foo" 43 | txresp -proto HTTP/1.2 -status 201 -reason Foo 44 | } 45 | 46 | server s2 -start 47 | 48 | client c3 -connect ${s2_sock} { 49 | txreq -req PUT -proto HTTP/1.0 -url /foo 50 | rxresp 51 | expect resp.proto == HTTP/1.2 52 | expect resp.status == 201 53 | expect resp.reason == Foo 54 | } 55 | 56 | client c4 -connect ${s2_sock} { 57 | txreq -req PUT -proto HTTP/1.0 -url /foo 58 | rxresp 59 | expect resp.proto == HTTP/1.2 60 | expect resp.status == 201 61 | expect resp.reason == Foo 62 | } 63 | 64 | client c3 -start 65 | client c4 -start 66 | 67 | client c3 -wait 68 | client c4 -wait 69 | 70 | server s2 -wait 71 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # Collection Copyright 2 | 3 | BSD 2-Clause License 4 | 5 | Copyright (c) 2018, Vtest project 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | # File Copyrights 30 | 31 | All files have some variant of BSD 2-Clause License, except: 32 | 33 | * lib/vqueue.h - BSD 3-Clause License 34 | * src/huffman_input - BSD 3-Clause License 35 | * src/vtc_h2_enctbl.h - BSD 3-Clause License 36 | * src/vtc_h2_stattbl.h - BSD 3-Clause License 37 | 38 | -------------------------------------------------------------------------------- /src/vtc_log.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2011 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | 32 | struct vtclog { 33 | unsigned magic; 34 | #define VTCLOG_MAGIC 0x82731202 35 | char *id; 36 | struct vsb *vsb; 37 | pthread_mutex_t mtx; 38 | int act; 39 | const struct cmds *cmds; 40 | }; 41 | -------------------------------------------------------------------------------- /lib/vfl.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer 12 | * in this position and unchanged. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * Derived from: 30 | * $FreeBSD: src/lib/libutil/libutil.h,v 1.44 2007/05/10 15:01:42 des Exp $ 31 | */ 32 | 33 | #ifndef VFL_H_INCLUDED 34 | #define VFL_H_INCLUDED 35 | 36 | int VFL_Open(const char *, int, ...); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/vsub.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* from libvarnish/subproc.c */ 34 | typedef void vsub_func_f(void*); 35 | 36 | unsigned VSUB_run(struct vsb *, vsub_func_f *, void *priv, const char *name, 37 | int maxlines); 38 | 39 | void VSUB_closefrom(int fd); 40 | -------------------------------------------------------------------------------- /src/tbl/vsig_list.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2018 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * NB: Changing the list of signals requires updating libvarnishapi.map 31 | * 32 | */ 33 | 34 | /*lint -save -e525 -e539 */ 35 | 36 | VSIG_SIGNAL(INT, int) 37 | VSIG_SIGNAL(HUP, hup) 38 | VSIG_SIGNAL(TERM, term) 39 | VSIG_SIGNAL(USR1, usr1) 40 | #undef VSIG_SIGNAL 41 | 42 | /*lint -restore */ 43 | -------------------------------------------------------------------------------- /tests/a00005.vtc: -------------------------------------------------------------------------------- 1 | vtest "dual shared client HTTP transactions" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.method == PUT 6 | expect req.proto == HTTP/1.0 7 | expect req.url == "/foo" 8 | txresp -proto HTTP/1.2 -status 201 -reason Foo 9 | } 10 | 11 | server s2 { 12 | rxreq 13 | expect req.method == GET 14 | expect req.proto == HTTP/1.1 15 | expect req.url == "/" 16 | txresp 17 | } 18 | 19 | server s1 -start 20 | server s2 -start 21 | 22 | client c1 -connect ${s1_sock} { 23 | txreq -req PUT -proto HTTP/1.0 -url /foo 24 | rxresp 25 | expect resp.proto == HTTP/1.2 26 | expect resp.status == 201 27 | expect resp.reason == Foo 28 | } 29 | 30 | client c1 -run 31 | 32 | client c1 -connect ${s2_sock} { 33 | txreq 34 | rxresp 35 | expect resp.proto == HTTP/1.1 36 | expect resp.status == 200 37 | expect resp.reason == OK 38 | } 39 | 40 | client c1 -run 41 | 42 | server s1 -wait 43 | server s2 -wait 44 | 45 | # The same tests with unix domain sockets 46 | server s3 -listen "${tmpdir}/s3.sock" { 47 | rxreq 48 | expect req.method == PUT 49 | expect req.proto == HTTP/1.0 50 | expect req.url == "/foo" 51 | txresp -proto HTTP/1.2 -status 201 -reason Foo 52 | } 53 | 54 | server s4 -listen "${tmpdir}/s4.sock" { 55 | rxreq 56 | expect req.method == GET 57 | expect req.proto == HTTP/1.1 58 | expect req.url == "/" 59 | txresp 60 | } 61 | 62 | server s3 -start 63 | server s4 -start 64 | 65 | client c2 -connect ${s3_sock} { 66 | txreq -req PUT -proto HTTP/1.0 -url /foo 67 | rxresp 68 | expect resp.proto == HTTP/1.2 69 | expect resp.status == 201 70 | expect resp.reason == Foo 71 | } 72 | 73 | client c2 -run 74 | 75 | client c2 -connect ${s4_sock} { 76 | txreq 77 | rxresp 78 | expect resp.proto == HTTP/1.1 79 | expect resp.status == 200 80 | expect resp.reason == OK 81 | } 82 | 83 | client c2 -run 84 | 85 | server s3 -wait 86 | server s4 -wait 87 | -------------------------------------------------------------------------------- /lib/vus.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2018 UPLEX - Nils Goroll Systemoptimierung 3 | * All rights reserved. 4 | * 5 | * Author: Geoffrey Simmons 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | struct sockaddr_un; 33 | 34 | typedef int vus_resolved_f(void *priv, const struct sockaddr_un *); 35 | int VUS_resolver(const char *path, vus_resolved_f *func, void *priv, 36 | const char **err); 37 | int VUS_bind(const struct sockaddr_un *uds, const char **errp); 38 | int VUS_connect(const char *path, int msec); 39 | -------------------------------------------------------------------------------- /lib/vpf.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 2005 Pawel Jakub Dawidek 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * Derived from: 29 | * $FreeBSD: src/lib/libutil/libutil.h,v 1.41 2005/08/24 17:21:38 pjd Exp $ 30 | */ 31 | 32 | #ifndef VPF_H_INCLUDED 33 | #define VPF_H_INCLUDED 34 | 35 | struct vpf_fh; 36 | 37 | struct vpf_fh *VPF_Open(const char *path, mode_t mode, pid_t *pidptr); 38 | int VPF_Read(const char *path, pid_t *); 39 | void VPF_Write(const struct vpf_fh *pfh); 40 | void VPF_Remove(struct vpf_fh *pfh); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/vrnd.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * Random functions 31 | */ 32 | 33 | typedef void vrnd_lock_f(void); 34 | 35 | extern vrnd_lock_f *VRND_Lock; 36 | extern vrnd_lock_f *VRND_Unlock; 37 | 38 | int VRND_RandomCrypto(void *, size_t); 39 | 40 | long VRND_RandomTestable(void); 41 | double VRND_RandomTestableDouble(void); 42 | void VRND_SeedTestable(unsigned int); 43 | void VRND_SeedAll(void); /* Seed random(3) properly */ 44 | 45 | -------------------------------------------------------------------------------- /tests/a00003.vtc: -------------------------------------------------------------------------------- 1 | vtest "dual independent HTTP transactions" 2 | 3 | server s1 { 4 | rxreq 5 | expect req.method == PUT 6 | expect req.proto == HTTP/1.0 7 | expect req.url == "/foo" 8 | txresp -proto HTTP/1.2 -status 201 -reason Foo 9 | } 10 | 11 | server s2 { 12 | rxreq 13 | expect req.method == GET 14 | expect req.proto == HTTP/1.1 15 | expect req.url == "/" 16 | txresp 17 | } 18 | 19 | server s1 -start 20 | server s2 -start 21 | 22 | client c1 -connect ${s1_sock} { 23 | txreq -req PUT -proto HTTP/1.0 -url /foo 24 | rxresp 25 | expect resp.proto == HTTP/1.2 26 | expect resp.status == 201 27 | expect resp.reason == Foo 28 | } 29 | 30 | client c2 -connect ${s2_sock} { 31 | txreq 32 | rxresp 33 | expect resp.proto == HTTP/1.1 34 | expect resp.status == 200 35 | expect resp.reason == OK 36 | } 37 | 38 | client c1 -start 39 | client c2 -start 40 | 41 | client c1 -wait 42 | client c2 -wait 43 | 44 | server s1 -wait 45 | server s2 -wait 46 | 47 | # The same tests with Unix domain sockets 48 | server s3 -listen "${tmpdir}/s3.sock" { 49 | rxreq 50 | expect req.method == PUT 51 | expect req.proto == HTTP/1.0 52 | expect req.url == "/foo" 53 | txresp -proto HTTP/1.2 -status 201 -reason Foo 54 | } 55 | 56 | server s4 -listen "${tmpdir}/s4.sock" { 57 | rxreq 58 | expect req.method == GET 59 | expect req.proto == HTTP/1.1 60 | expect req.url == "/" 61 | txresp 62 | } 63 | 64 | server s3 -start 65 | server s4 -start 66 | 67 | client c3 -connect ${s3_sock} { 68 | txreq -req PUT -proto HTTP/1.0 -url /foo 69 | rxresp 70 | expect resp.proto == HTTP/1.2 71 | expect resp.status == 201 72 | expect resp.reason == Foo 73 | } 74 | 75 | client c4 -connect ${s4_sock} { 76 | txreq 77 | rxresp 78 | expect resp.proto == HTTP/1.1 79 | expect resp.status == 200 80 | expect resp.reason == OK 81 | } 82 | 83 | client c3 -start 84 | client c4 -start 85 | 86 | client c3 -wait 87 | client c4 -wait 88 | 89 | server s3 -wait 90 | server s4 -wait 91 | -------------------------------------------------------------------------------- /lib/vre_pcre2.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2021 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Dridi Boukelmoune 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * Access to the PCRE2 backend in VRE 31 | * 32 | */ 33 | 34 | #ifndef VRE_H_INCLUDED 35 | #error Include vre.h before vre_pcre2.h 36 | #endif 37 | 38 | #ifndef VRE_PCRE2_H_INCLUDED 39 | #define VRE_PCRE2_H_INCLUDED 40 | 41 | #define PCRE2_CODE_UNIT_WIDTH 8 42 | 43 | #include 44 | 45 | pcre2_code *VRE_unpack(const vre_t *code); 46 | 47 | #endif /* VRE_PCRE2_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /lib/vav.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | void VAV_Free(char **argv); 34 | char **VAV_ParseTxt(const char *b, const char *e, int *argc, int flag); 35 | char **VAV_Parse(const char *s, int *argc, int flag); 36 | char *VAV_BackSlashDecode(const char *s, const char *e); 37 | int VAV_BackSlash(const char *s, char *res); 38 | #define ARGV_COMMENT (1 << 0) 39 | #define ARGV_COMMA (1 << 1) 40 | #define ARGV_NOESC (1 << 2) 41 | -------------------------------------------------------------------------------- /lib/vtim.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* from libvarnish/vtim.c */ 34 | extern unsigned VTIM_postel; 35 | #define VTIM_FORMAT_SIZE 30 36 | void VTIM_format(vtim_real t, char *p); 37 | vtim_real VTIM_parse(const char *p); 38 | vtim_mono VTIM_mono(void); 39 | vtim_real VTIM_real(void); 40 | void VTIM_sleep(vtim_dur t); 41 | struct timespec VTIM_timespec(vtim_dur t); 42 | struct timeval VTIM_timeval(vtim_dur t); 43 | -------------------------------------------------------------------------------- /src/tbl/h2_stream.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2016 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * RFC7540 section 11.4 31 | */ 32 | 33 | /*lint -save -e525 -e539 */ 34 | 35 | H2_STREAM(IDLE, "idle", "idle") 36 | H2_STREAM(RESV_LOC, "r-loc", "reserved (local)") 37 | H2_STREAM(RESV_REM, "r-rem", "reserved (remote)") 38 | H2_STREAM(OPEN, "open", "open") 39 | H2_STREAM(CLOS_LOC, "c-loc", "half closed (local)") 40 | H2_STREAM(CLOS_REM, "c-rem", "half closed (remote)") 41 | H2_STREAM(CLOSED, "closed", "closed") 42 | #undef H2_STREAM 43 | 44 | /*lint -restore */ 45 | -------------------------------------------------------------------------------- /lib/vlu.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2005-2008 Poul-Henning Kamp 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-2-Clause 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * Functions for assembling a bytestream into text-lines and calling 29 | * a function on each. 30 | */ 31 | 32 | #ifdef VLU_H_INCLUDED 33 | # error "vlu.h included multiple times" 34 | #endif 35 | #define VLU_H_INCLUDED 36 | 37 | typedef int (vlu_f)(void *, const char *); 38 | struct vlu *VLU_New(vlu_f *, void *, unsigned); 39 | void VLU_Reset(struct vlu *); 40 | int VLU_Fd(struct vlu *, int); 41 | void VLU_Destroy(struct vlu **); 42 | int VLU_File(int, vlu_f *, void *, unsigned); 43 | int VLU_Feed(struct vlu *, const char*, int); 44 | -------------------------------------------------------------------------------- /lib/vsig.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2018 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #ifndef VAPI_VSIG_H_INCLUDED 33 | #define VAPI_VSIG_H_INCLUDED 34 | 35 | #include 36 | #include 37 | 38 | #define VSIG_SIGNAL(UPPER, lower) \ 39 | extern sig_atomic_t VSIG_##lower; \ 40 | void VSIG_Got_##lower(int sig); \ 41 | void VSIG_Arm_##lower(void); 42 | 43 | #include "tbl/vsig_list.h" 44 | 45 | #ifndef WCOREDUMP 46 | # ifdef WIFCORED 47 | # define WCOREDUMP(s) WIFCORED(s) 48 | # else 49 | # define WCOREDUMP(s) (-1) 50 | # endif 51 | #endif 52 | 53 | #endif /* VAPI_VSC_H_INCLUDED */ 54 | -------------------------------------------------------------------------------- /tests/a02007.vtc: -------------------------------------------------------------------------------- 1 | vtest "HPACK test" 2 | 3 | server s1 { 4 | stream 1 { 5 | rxreq 6 | expect tbl.dec.size == 57 7 | expect tbl.dec[1].key == ":authority" 8 | expect tbl.dec[1].value == "www.example.com" 9 | txresp 10 | } -run 11 | 12 | stream 3 { 13 | rxreq 14 | expect tbl.dec[1].key == "cache-control" 15 | expect tbl.dec[1].value == "no-cache" 16 | expect tbl.dec[2].key == ":authority" 17 | expect tbl.dec[2].value == "www.example.com" 18 | expect tbl.dec.size == 110 19 | txresp 20 | } -run 21 | 22 | stream 5 { 23 | rxreq 24 | expect tbl.dec[1].key == "custom-key" 25 | expect tbl.dec[1].value == "custom-value" 26 | expect tbl.dec[2].key == "cache-control" 27 | expect tbl.dec[2].value == "no-cache" 28 | expect tbl.dec[3].key == ":authority" 29 | expect tbl.dec[3].value == "www.example.com" 30 | expect tbl.dec.size == 164 31 | txresp 32 | } -run 33 | } -start 34 | 35 | client c1 -connect ${s1_sock} { 36 | stream 1 { 37 | 38 | txreq -idxHdr 2 \ 39 | -idxHdr 6 \ 40 | -idxHdr 4 \ 41 | -litIdxHdr inc 1 huf "www.example.com" 42 | expect tbl.enc[1].key == ":authority" 43 | expect tbl.enc[1].value == "www.example.com" 44 | rxresp 45 | } -run 46 | 47 | stream 3 { 48 | txreq -idxHdr 2 \ 49 | -idxHdr 6 \ 50 | -idxHdr 4 \ 51 | -idxHdr 62 \ 52 | -litIdxHdr inc 24 huf no-cache 53 | expect tbl.enc[1].key == "cache-control" 54 | expect tbl.enc[1].value == "no-cache" 55 | expect tbl.enc[2].key == ":authority" 56 | expect tbl.enc[2].value == "www.example.com" 57 | expect tbl.enc.size == 110 58 | rxresp 59 | } -run 60 | 61 | stream 5 { 62 | txreq -idxHdr 2 \ 63 | -idxHdr 7 \ 64 | -idxHdr 5 \ 65 | -idxHdr 63 \ 66 | -litHdr inc huf "custom-key" huf "custom-value" 67 | expect tbl.enc[1].key == "custom-key" 68 | expect tbl.enc[1].value == "custom-value" 69 | expect tbl.enc[2].key == "cache-control" 70 | expect tbl.enc[2].value == "no-cache" 71 | expect tbl.enc[3].key == ":authority" 72 | expect tbl.enc[3].value == "www.example.com" 73 | expect tbl.enc.size == 164 74 | rxresp 75 | } -run 76 | 77 | } -run 78 | 79 | server s1 -wait 80 | -------------------------------------------------------------------------------- /tests/a02009.vtc: -------------------------------------------------------------------------------- 1 | vtest "More HPACK tests" 2 | server s1 { 3 | stream 1 { 4 | rxreq 5 | expect tbl.dec.size == 57 6 | expect tbl.dec[1].key == ":authority" 7 | expect tbl.dec[1].value == "www.example.com" 8 | txresp 9 | } -run 10 | 11 | stream 3 { 12 | rxreq 13 | expect tbl.dec[1].key == "cache-control" 14 | expect tbl.dec[1].value == "no-cache" 15 | expect tbl.dec[2].key == ":authority" 16 | expect tbl.dec[2].value == "www.example.com" 17 | expect tbl.dec.size == 110 18 | txresp 19 | } -run 20 | 21 | stream 5 { 22 | rxreq 23 | expect tbl.dec[1].key == "custom-key" 24 | expect tbl.dec[1].value == "custom-value" 25 | expect tbl.dec[2].key == "cache-control" 26 | expect tbl.dec[2].value == "no-cache" 27 | expect tbl.dec[3].key == ":authority" 28 | expect tbl.dec[3].value == "www.example.com" 29 | expect tbl.dec.size == 164 30 | txresp 31 | } -run 32 | } -start 33 | 34 | client c1 -connect ${s1_sock} { 35 | stream 1 { 36 | 37 | txreq -idxHdr 2 \ 38 | -idxHdr 6 \ 39 | -idxHdr 4 \ 40 | -litIdxHdr inc 1 huf "www.example.com" 41 | expect tbl.enc[1].key == ":authority" 42 | expect tbl.enc[1].value == "www.example.com" 43 | rxresp 44 | } -run 45 | 46 | stream 3 { 47 | txreq -idxHdr 2 \ 48 | -idxHdr 6 \ 49 | -idxHdr 4 \ 50 | -idxHdr 62 \ 51 | -litIdxHdr inc 24 huf no-cache 52 | expect tbl.enc[1].key == "cache-control" 53 | expect tbl.enc[1].value == "no-cache" 54 | expect tbl.enc[2].key == ":authority" 55 | expect tbl.enc[2].value == "www.example.com" 56 | expect tbl.enc.size == 110 57 | rxresp 58 | } -run 59 | 60 | stream 5 { 61 | txreq -idxHdr 2 \ 62 | -idxHdr 7 \ 63 | -idxHdr 5 \ 64 | -idxHdr 63 \ 65 | -litHdr inc huf "custom-key" huf "custom-value" 66 | expect tbl.enc[1].key == "custom-key" 67 | expect tbl.enc[1].value == "custom-value" 68 | expect tbl.enc[2].key == "cache-control" 69 | expect tbl.enc[2].value == "no-cache" 70 | expect tbl.enc[3].key == ":authority" 71 | expect tbl.enc[3].value == "www.example.com" 72 | expect tbl.enc.size == 164 73 | rxresp 74 | } -run 75 | 76 | } -run 77 | 78 | server s1 -wait 79 | -------------------------------------------------------------------------------- /tests/a02001.vtc: -------------------------------------------------------------------------------- 1 | vtest "Quickly test all frames" 2 | 3 | server s1 { 4 | rxpri 5 | stream 0 { 6 | # PRIO 7 | txprio -stream 23456 -weight 123 8 | 9 | # RST 10 | txrst -err 2 11 | 12 | # SETTINGS 13 | txsettings -push true -hdrtbl 11111111 -maxstreams 222222 -winsize 333333 -framesize 444444 -hdrsize 555555 14 | txsettings -ack 15 | 16 | # PING 17 | txping -data "01234567" 18 | txping -data "abcdefgh" -ack 19 | 20 | # GOAWAY 21 | txgoaway -laststream 17432423 -err 12 -debug "kangaroo" 22 | 23 | # WINUP 24 | txwinup -size 500 25 | 26 | 27 | # FRAME 28 | txresp -body "floubidou" 29 | 30 | 31 | # FRAME 32 | txresp -body "tata" 33 | } -run 34 | } -start 35 | 36 | client c1 -connect ${s1_sock} { 37 | txpri 38 | stream 0 { 39 | # PRIO 40 | rxprio 41 | expect prio.stream == 23456 42 | expect prio.weight == 123 43 | 44 | # RST 45 | rxrst 46 | expect rst.err >= 2 47 | expect rst.err < 3 48 | 49 | # SETTINGS 50 | rxsettings 51 | expect settings.hdrtbl == 11111111 52 | expect settings.maxstreams == 222222 53 | expect settings.winsize == 333333 54 | expect settings.framesize == 444444 55 | expect settings.hdrsize == 555555 56 | 57 | rxsettings 58 | expect settings.ack == true 59 | expect settings.hdrtbl == 60 | expect settings.maxstreams == 61 | expect settings.winsize == 62 | expect settings.framesize == 63 | expect settings.hdrsize == 64 | 65 | # PING 66 | rxping 67 | expect ping.ack == "false" 68 | expect ping.data == "01234567" 69 | expect ping.data != "O1234567" 70 | rxping 71 | expect ping.ack == "true" 72 | expect ping.data == "abcdefgh" 73 | expect ping.data != "abcdefgt" 74 | 75 | # GOAWAY 76 | rxgoaway 77 | expect goaway.err == 12 78 | expect goaway.laststream == 17432423 79 | expect goaway.debug == "kangaroo" 80 | 81 | # WINUP 82 | rxwinup 83 | expect winup.size == 500 84 | 85 | # FRAME 86 | rxhdrs 87 | rxdata 88 | expect frame.data == "floubidou" 89 | expect frame.type == 0 90 | expect frame.size == 9 91 | expect frame.stream == 0 92 | 93 | rxresp 94 | expect resp.body == "floubidoutata" 95 | } -run 96 | } -run 97 | -------------------------------------------------------------------------------- /src/vtc_h2_priv.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2016 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Guillaume Quintard 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #define ITER_DONE(iter) (iter->buf == iter->end ? hpk_done : hpk_more) 32 | 33 | struct dynhdr { 34 | struct hpk_hdr header; 35 | VTAILQ_ENTRY(dynhdr) list; 36 | }; 37 | 38 | VTAILQ_HEAD(dynamic_table,dynhdr); 39 | 40 | struct hpk_iter { 41 | struct hpk_ctx *ctx; 42 | uint8_t *orig; 43 | uint8_t *buf; 44 | uint8_t *end; 45 | }; 46 | 47 | const struct hpk_txt * tbl_get_key(const struct hpk_ctx *ctx, uint32_t index); 48 | 49 | const struct hpk_txt * tbl_get_value(const struct hpk_ctx *ctx, uint32_t index); 50 | void push_header (struct hpk_ctx *ctx, const struct hpk_hdr *h); 51 | -------------------------------------------------------------------------------- /lib/vss.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2009 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * SPDX-License-Identifier: BSD-2-Clause 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | */ 30 | 31 | /* vss.c */ 32 | struct suckaddr; 33 | 34 | typedef int vss_resolved_f(void *priv, const struct suckaddr *); 35 | int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, 36 | void *priv, const char **err); 37 | int VSS_resolver_socktype(const char *addr, const char *def_port, 38 | vss_resolved_f *func, void *priv, const char **err, int socktype); 39 | struct suckaddr *VSS_ResolveOne(void *dst, 40 | const char *addr, const char *port, 41 | int family, int socktype, int flags); 42 | struct suckaddr *VSS_ResolveFirst(void *dst, 43 | const char *addr, const char *port, 44 | int family, int socktype, int flags); 45 | -------------------------------------------------------------------------------- /src/cmds.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2018 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | /*lint -save -e525 -e539 */ 33 | 34 | #ifndef CMD_GLOBAL 35 | #define CMD_GLOBAL(x) 36 | #endif 37 | CMD_GLOBAL(barrier) 38 | CMD_GLOBAL(delay) 39 | CMD_GLOBAL(shell) 40 | CMD_GLOBAL(include) 41 | #undef CMD_GLOBAL 42 | 43 | #ifndef CMD_TOP 44 | #define CMD_TOP(x) 45 | #endif 46 | CMD_TOP(client) 47 | CMD_TOP(feature) 48 | CMD_TOP(filewrite) 49 | CMD_TOP(haproxy) 50 | #ifdef VTEST_WITH_VTC_LOGEXPECT 51 | CMD_TOP(logexpect) 52 | #endif 53 | CMD_TOP(process) 54 | CMD_TOP(server) 55 | CMD_TOP(setenv) 56 | CMD_TOP(syslog) 57 | CMD_TOP(tunnel) 58 | #ifdef VTEST_WITH_VTC_VARNISH 59 | CMD_TOP(varnish) 60 | #endif 61 | CMD_TOP(varnishtest) 62 | CMD_TOP(vtest) 63 | #undef CMD_TOP 64 | 65 | /*lint -restore */ 66 | -------------------------------------------------------------------------------- /lib/vfil.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | struct vfil_path; 34 | 35 | /* from libvarnish/vfil.c */ 36 | 37 | void VFIL_null_fd(int); 38 | 39 | char *VFIL_readfile(const char *pfx, const char *fn, ssize_t *sz); 40 | int VFIL_writefile(const char *pfx, const char *fn, const char *buf, size_t sz); 41 | int VFIL_nonblocking(int fd); 42 | int VFIL_fsinfo(int fd, unsigned *pbs, uintmax_t *size, uintmax_t *space); 43 | int VFIL_allocate(int fd, uintmax_t size, int insist); 44 | void VFIL_setpath(struct vfil_path**, const char *path); 45 | typedef int vfil_path_func_f(void *priv, const char *fn); 46 | int VFIL_searchpath(const struct vfil_path *, vfil_path_func_f *func, 47 | void *priv, const char *fni, char **fno); 48 | 49 | -------------------------------------------------------------------------------- /lib/vnum.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* from libvarnish/vnum.c */ 34 | #define VNUM_EPSILON (1e-9) 35 | double VNUM(const char *p); 36 | vtim_dur VNUM_duration_unit(vtim_dur r, const char *b, const char *e); 37 | vtim_dur VNUM_duration(const char *p); 38 | int64_t VNUM_bytes_unit(double r, const char *b, const char *e, uintmax_t rel, 39 | const char **errtxt); 40 | const char *VNUM_2bytes(const char *p, uintmax_t *r, uintmax_t rel); 41 | ssize_t VNUM_uint(const char *b, const char *e, const char **p); 42 | ssize_t VNUM_hex(const char *b, const char *e, const char **p); 43 | 44 | int64_t SF_Parse_Integer(const char **ipp, const char **errtxt); 45 | double SF_Parse_Decimal(const char **ipp, int strict, const char **errtxt); 46 | double SF_Parse_Number(const char **ipp, int strict, const char **errtxt); 47 | 48 | #define VNUM_LEGAL_DURATION \ 49 | "Legal duration units are 'ms', 's', 'm', 'h', 'd', 'w' and 'y'" 50 | -------------------------------------------------------------------------------- /lib/miniobj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Poul-Henning Kamp 3 | * 4 | * This file is in the public domain. 5 | * 6 | */ 7 | 8 | #define ZERO_OBJ(to, sz) \ 9 | do { \ 10 | void *(*volatile z_obj)(void *, int, size_t) = memset; \ 11 | (void)z_obj(to, 0, sz); \ 12 | } while (0) 13 | 14 | #define INIT_OBJ(to, type_magic) \ 15 | do { \ 16 | (void)memset(to, 0, sizeof *(to)); \ 17 | (to)->magic = (type_magic); \ 18 | } while (0) 19 | 20 | #define FINI_OBJ(to) \ 21 | do { \ 22 | ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \ 23 | to = NULL; \ 24 | } while (0) 25 | 26 | #define ALLOC_OBJ(to, type_magic) \ 27 | do { \ 28 | (to) = calloc(1, sizeof *(to)); \ 29 | if ((to) != NULL) \ 30 | (to)->magic = (type_magic); \ 31 | } while (0) 32 | 33 | #define FREE_OBJ(to) \ 34 | do { \ 35 | ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \ 36 | free(to); \ 37 | to = NULL; \ 38 | } while (0) 39 | 40 | #define VALID_OBJ(ptr, type_magic) \ 41 | ((ptr) != NULL && (ptr)->magic == (type_magic)) 42 | 43 | #define CHECK_OBJ(ptr, type_magic) \ 44 | do { \ 45 | assert((ptr)->magic == type_magic); \ 46 | } while (0) 47 | 48 | #define CHECK_OBJ_NOTNULL(ptr, type_magic) \ 49 | do { \ 50 | assert((ptr) != NULL); \ 51 | assert((ptr)->magic == type_magic); \ 52 | } while (0) 53 | 54 | #define CHECK_OBJ_ORNULL(ptr, type_magic) \ 55 | do { \ 56 | if ((ptr) != NULL) \ 57 | assert((ptr)->magic == type_magic); \ 58 | } while (0) 59 | 60 | #define CAST_OBJ(to, from, type_magic) \ 61 | do { \ 62 | (to) = (from); \ 63 | if ((to) != NULL) \ 64 | CHECK_OBJ((to), (type_magic)); \ 65 | } while (0) 66 | 67 | #define CAST_OBJ_NOTNULL(to, from, type_magic) \ 68 | do { \ 69 | (to) = (from); \ 70 | AN((to)); \ 71 | CHECK_OBJ((to), (type_magic)); \ 72 | } while (0) 73 | 74 | #define TAKE_OBJ_NOTNULL(to, pfrom, type_magic) \ 75 | do { \ 76 | AN((pfrom)); \ 77 | (to) = *(pfrom); \ 78 | *(pfrom) = NULL; \ 79 | CHECK_OBJ_NOTNULL((to), (type_magic)); \ 80 | } while (0) 81 | 82 | #define REPLACE(ptr, val) \ 83 | do { \ 84 | const char *_vreplace = (val); \ 85 | free(ptr); \ 86 | if (_vreplace != NULL) { \ 87 | ptr = strdup(_vreplace); \ 88 | AN((ptr)); \ 89 | } else { \ 90 | ptr = NULL; \ 91 | } \ 92 | } while (0) 93 | -------------------------------------------------------------------------------- /lib/vev.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2009 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | struct vev; 34 | struct vev_root; 35 | 36 | typedef int vev_cb_f(const struct vev *, int what); 37 | 38 | struct vev { 39 | unsigned magic; 40 | #define VEV_MAGIC 0x46bbd419 41 | 42 | /* pub */ 43 | const char *name; 44 | int fd; 45 | unsigned fd_flags; 46 | unsigned fd_events; 47 | #define VEV__RD POLLIN 48 | #define VEV__WR POLLOUT 49 | #define VEV__ERR POLLERR 50 | #define VEV__HUP POLLHUP 51 | #define VEV__SIG -1 52 | int sig; 53 | unsigned sig_flags; 54 | double timeout; 55 | vev_cb_f *callback; 56 | void *priv; 57 | 58 | /* priv */ 59 | double __when; 60 | unsigned __binheap_idx; 61 | unsigned __privflags; 62 | struct vev_root *__vevb; 63 | }; 64 | 65 | struct vev_root *VEV_New(void); 66 | void VEV_Destroy(struct vev_root **); 67 | 68 | struct vev *VEV_Alloc(void); 69 | 70 | int VEV_Start(struct vev_root *, struct vev *); 71 | void VEV_Stop(struct vev_root *, struct vev *); 72 | 73 | int VEV_Once(struct vev_root *); 74 | int VEV_Loop(struct vev_root *); 75 | -------------------------------------------------------------------------------- /src/huffman_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import sys 5 | 6 | #HPH(0x30, 0x00000000, 5) 7 | regex = re.compile("^HPH\((.{4}), (.{10}), +(.{1,3})\)") 8 | 9 | if len(sys.argv) != 2: 10 | print("{} takes one and only one argument".format(sys.argv[0])) 11 | sys.exit(2) 12 | 13 | class sym: 14 | def __init__(self, bigval, bigvall, chr=0, esc=None): 15 | self.vall = bigvall % 8 if bigvall % 8 else 8 16 | self.val = bigval & ((1 << self.vall) - 1) 17 | self.pfx = (bigval >> self.vall)# & 0xff 18 | self.chr = chr 19 | self.esc = esc 20 | 21 | tbls = {} 22 | msl = {} # max sym length 23 | 24 | f = open(sys.argv[1]) 25 | for l in f: 26 | grp = 1 27 | match = regex.match(l) 28 | if not match: 29 | continue 30 | 31 | char = int(match.group(grp), 16) 32 | grp += 1 33 | 34 | val = int(match.group(grp), 16) 35 | grp += 1 36 | 37 | vall = int(match.group(grp)) 38 | 39 | s = sym(val, vall, char) 40 | if s.pfx not in tbls: 41 | tbls[s.pfx] = {} 42 | 43 | if s.val in tbls[s.pfx]: 44 | assert tbls[s.pfx][s.val].e 45 | tbls[s.pfx][s.val] = s 46 | 47 | # add the escape entry in the "previous" table 48 | if s.pfx: 49 | pp = s.pfx >> 8 50 | pv = s.pfx & 0xff 51 | if pp not in tbls: 52 | tbls[pp] = {} 53 | tbls[pp][pv] = sym(pv, 8, 0, "&tbl_{:x}".format(s.pfx)) 54 | f.close() 55 | 56 | # add the EOS case 57 | s = sym(63, 6, 0) 58 | tbls[0xffffff][63] = s 59 | 60 | print('''/* NB: This file is machine generated, DO NOT EDIT! 61 | * edit 'huffman_input' instead 62 | */ 63 | 64 | struct stbl; 65 | 66 | struct ssym { 67 | uint8_t csm; /* bits consumed */ 68 | uint8_t chr; /* character */ 69 | struct stbl *nxt; /* next table */ 70 | }; 71 | 72 | struct stbl { 73 | unsigned msk; 74 | struct ssym *syms; 75 | }; 76 | ''') 77 | 78 | for pfx in sorted(tbls.keys(), reverse=True): 79 | msl = max([x.vall for x in tbls[pfx].values()]) 80 | for s in tbls[pfx].values(): 81 | s.val = s.val << (msl - s.vall) 82 | 83 | tbl = sorted(tbls[pfx].values(), key=lambda x: x.val) 84 | print("\nstatic struct ssym sym_{:x}_array[] = {{".format(pfx)) 85 | for s in tbl: 86 | for j in range(2 ** (msl - s.vall)): 87 | print("{} {{{}, {:3d}, {}}},".format( 88 | "\t " if j else "/* idx {:3d} */".format(s.val + j), 89 | s.vall, s.chr % 256, 90 | s.esc if s.esc else "NULL")) 91 | print('''}}; 92 | 93 | static struct stbl tbl_{:x} = {{ 94 | {}, 95 | sym_{:x}_array 96 | }};'''.format(pfx, msl, pfx)) 97 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | 3 | PYTHON3 ?= python3 4 | PYTHON ?= python 5 | 6 | VARNISH_SRC ?= /home/phk/Varnish/trunk/varnish-cache 7 | 8 | AWK ?= awk 9 | 10 | SRCS= src/*.c \ 11 | lib/*.c 12 | 13 | OBJS= src/*.o \ 14 | lib/*.o 15 | 16 | DEPS= lib/*.h \ 17 | src/*.h \ 18 | src/tbl/*.h \ 19 | src/teken_state.h \ 20 | src/vtc_h2_dectbl.h 21 | 22 | FLAGS= -O2 -Wall -Werror 23 | 24 | CFLAGS= ${FLAGS} 25 | LDFLAGS= ${FLAGS} -s 26 | DEFINES= 27 | 28 | INCS= -Isrc \ 29 | -Ilib \ 30 | -I/usr/local/include \ 31 | -pthread 32 | 33 | LIBS= -L/usr/local/lib \ 34 | -lm \ 35 | -lpcre2-8 \ 36 | -lz 37 | 38 | ####################################################################### 39 | # If you want to build vtest without varnish support, use this part: 40 | 41 | vtest: ${DEPS} ${SRCS} 42 | ${MAKE} \ 43 | DEFINES= \ 44 | `for s in $(SRCS); do echo $${s%.c}.o;done` 45 | 46 | ${CC} \ 47 | ${LDFLAGS} \ 48 | -o vtest \ 49 | ${INCS} \ 50 | ${OBJS} \ 51 | ${LIBS} 52 | 53 | test: vtest 54 | env PATH=`pwd`:${PATH} vtest tests/*.vtc 55 | 56 | ####################################################################### 57 | # ... other point to varnish source tree and use this part: 58 | 59 | varnishtest: ${DEPS} ${SRCS} 60 | ${MAKE} \ 61 | DEFINES="-DVTEST_WITH_VTC_VARNISH -DVTEST_WITH_VTC_LOGEXPECT" \ 62 | `for s in $(SRCS); do echo $${s%.c}.o;done` 63 | 64 | ${CC} \ 65 | ${LDFLAGS} \ 66 | -o varnishtest \ 67 | ${OBJS} \ 68 | ${LIBS} \ 69 | -L${VARNISH_SRC}/lib/libvarnishapi/.libs \ 70 | -Wl,--rpath,${VARNISH_SRC}/lib/libvarnishapi/.libs \ 71 | -lvarnishapi 72 | 73 | ####################################################################### 74 | # Implicit rule used in a sub-process by the rules above, and makes use 75 | # of ${DEFINES} for extra arguments : 76 | .c.o: 77 | ${CC} \ 78 | ${CFLAGS} \ 79 | ${DEFINES} \ 80 | ${INCS} \ 81 | -I${VARNISH_SRC}/include \ 82 | -o $@ -c $< 83 | 84 | ####################################################################### 85 | 86 | src/vtc_h2_dectbl.h: src/huffman_gen.py src/tbl/vhp_huffman.h 87 | @( echo trying python3 && \ 88 | ${PYTHON3} src/huffman_gen.py src/tbl/vhp_huffman.h > $@ ) || \ 89 | ( rm -f $@; echo trying python instead && \ 90 | ${PYTHON} src/huffman_gen.py src/tbl/vhp_huffman.h > $@ ) || \ 91 | ( rm -f $@; echo failed && exit 1 ) 92 | 93 | ####################################################################### 94 | 95 | src/teken_state.h: src/gensequences src/sequences 96 | ${AWK} -f src/gensequences src/sequences > src/teken_state.h 97 | 98 | ####################################################################### 99 | 100 | clean: 101 | rm -f vtest varnishtest 102 | rm -f src/teken_state.h 103 | rm -f src/vtc_h2_dectbl.h 104 | rm -f ${OBJS} 105 | -------------------------------------------------------------------------------- /lib/vjsn.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2017 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #define VJSN_TYPES \ 32 | VJSN_TYPE_MACRO(OBJECT, object) \ 33 | VJSN_TYPE_MACRO(ARRAY, array) \ 34 | VJSN_TYPE_MACRO(NUMBER, number) \ 35 | VJSN_TYPE_MACRO(STRING, string) \ 36 | VJSN_TYPE_MACRO(TRUE, true) \ 37 | VJSN_TYPE_MACRO(FALSE, false) \ 38 | VJSN_TYPE_MACRO(NULL, null) 39 | 40 | struct vjsn_val { 41 | unsigned magic; 42 | #define VJSN_VAL_MAGIC 0x08a06b80 43 | const char *type; 44 | const char *name; 45 | const char *name_e; 46 | VTAILQ_ENTRY(vjsn_val) list; 47 | VTAILQ_HEAD(,vjsn_val) children; 48 | char *value; 49 | char *value_e; 50 | }; 51 | 52 | struct vjsn { 53 | unsigned magic; 54 | #define VJSN_MAGIC 0x86a7f02b 55 | 56 | char *raw; 57 | char *ptr; 58 | struct vjsn_val *value; 59 | const char *err; 60 | }; 61 | 62 | struct vjsn *vjsn_parse_end(const char *, const char *, const char **); 63 | struct vjsn *vjsn_parse(const char *, const char **); 64 | void vjsn_delete(struct vjsn **); 65 | void vjsn_dump(const struct vjsn *js, FILE *fo); 66 | void vjsn_dump_val(const struct vjsn_val *jsv, FILE *fo); 67 | struct vjsn_val *vjsn_child(const struct vjsn_val *, const char *); 68 | 69 | #define VJSN_TYPE_MACRO(UPPER, lower) \ 70 | int vjsn_is_##lower(const struct vjsn_val *jsv); 71 | VJSN_TYPES 72 | #undef VJSN_TYPE_MACRO 73 | -------------------------------------------------------------------------------- /lib/vcli.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * Public definition of the CLI protocol, part of the published Varnish-API. 32 | * 33 | * The overall structure of the protocol is a command-line like 34 | * "command+arguments" request and a IETF style "number + string" response. 35 | * 36 | * Arguments can contain arbitrary sequences of bytes which are encoded 37 | * in back-slash notation in double-quoted, if necessary. 38 | */ 39 | 40 | /* 41 | * Status/return codes in the CLI protocol 42 | */ 43 | 44 | enum VCLI_status_e { 45 | CLIS_SYNTAX = 100, 46 | CLIS_UNKNOWN = 101, 47 | CLIS_UNIMPL = 102, 48 | CLIS_TOOFEW = 104, 49 | CLIS_TOOMANY = 105, 50 | CLIS_PARAM = 106, 51 | CLIS_AUTH = 107, 52 | CLIS_OK = 200, 53 | CLIS_TRUNCATED = 201, 54 | CLIS_CANT = 300, 55 | CLIS_COMMS = 400, 56 | CLIS_CLOSE = 500 57 | }; 58 | 59 | /* Length of first line of response */ 60 | #define CLI_LINE0_LEN 13 61 | #define CLI_AUTH_RESPONSE_LEN 64 /* 64 hex + NUL */ 62 | 63 | #if !defined(VCLI_PROTOCOL_ONLY) 64 | /* Convenience functions exported in libvarnishapi */ 65 | int VCLI_WriteResult(int fd, unsigned status, const char *result); 66 | int VCLI_ReadResult(int fd, unsigned *status, char **ptr, double tmo); 67 | void VCLI_AuthResponse(int S_fd, const char *challenge, 68 | char response[CLI_AUTH_RESPONSE_LEN + 1]); 69 | #endif 70 | -------------------------------------------------------------------------------- /src/vtc_http.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2015 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #define MAX_HDR 64 32 | 33 | struct vtc_sess { 34 | unsigned magic; 35 | #define VTC_SESS_MAGIC 0x932bd565 36 | struct vtclog *vl; 37 | char *name; 38 | int repeat; 39 | int keepalive; 40 | int fd; 41 | 42 | ssize_t rcvbuf; 43 | }; 44 | 45 | struct http { 46 | unsigned magic; 47 | #define HTTP_MAGIC 0x2f02169c 48 | int *sfd; 49 | struct vtc_sess *sess; 50 | int timeout; 51 | struct vtclog *vl; 52 | 53 | struct vsb *vsb; 54 | 55 | int rcvbuf; 56 | int nrxbuf; 57 | char *rx_b; 58 | char *rx_p; 59 | char *rx_e; 60 | char *rem_ip; 61 | char *rem_port; 62 | char *rem_path; 63 | char *body; 64 | long bodyl; 65 | char bodylen[20]; 66 | char chunklen[20]; 67 | 68 | char *req[MAX_HDR]; 69 | char *resp[MAX_HDR]; 70 | 71 | int gziplevel; 72 | int gzipresidual; 73 | 74 | int head_method; 75 | 76 | int fatal; 77 | 78 | /* H/2 */ 79 | unsigned h2; 80 | int wf; 81 | 82 | pthread_t tp; 83 | VTAILQ_HEAD(, stream) streams; 84 | pthread_mutex_t mtx; 85 | pthread_cond_t cond; 86 | struct hpk_ctx *encctx; 87 | struct hpk_ctx *decctx; 88 | uint64_t iws; 89 | int64_t ws; 90 | }; 91 | 92 | int http_process(struct vtclog *vl, struct vtc_sess *vsp, const char *spec, 93 | int sock, int *sfd, const char *addr, int rcvbuf); 94 | 95 | -------------------------------------------------------------------------------- /lib/vre.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2009 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Tollef Fog Heen 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * Regular expression support 31 | * 32 | * We wrap PCRE2 in VRE to make to make it feasible to use something else 33 | * without hunting down stuff through out the Varnish source code. 34 | * 35 | */ 36 | 37 | #ifndef VRE_H_INCLUDED 38 | #define VRE_H_INCLUDED 39 | 40 | #define VRE_ERROR_LEN 128 41 | 42 | struct vre; 43 | struct vsb; 44 | 45 | struct vre_limits { 46 | unsigned match; 47 | unsigned depth; 48 | }; 49 | 50 | typedef struct vre vre_t; 51 | 52 | /* This maps to PCRE2 error codes */ 53 | extern const int VRE_ERROR_NOMATCH; 54 | 55 | /* And those to PCRE2 compilation options */ 56 | extern const unsigned VRE_CASELESS; 57 | 58 | vre_t *VRE_compile(const char *, unsigned, int *, int *, unsigned); 59 | vre_t *VRE_export(const vre_t *, size_t *); 60 | int VRE_error(struct vsb *, int err); 61 | int VRE_match(const vre_t *code, const char *subject, size_t length, 62 | int options, const volatile struct vre_limits *lim); 63 | int VRE_capture(const vre_t *code, const char *subject, size_t length, 64 | int options, txt *groups, size_t count, 65 | const volatile struct vre_limits *lim); 66 | int VRE_sub(const vre_t *code, const char *subject, const char *replacement, 67 | struct vsb *vsb, const volatile struct vre_limits *lim, int all); 68 | void VRE_free(vre_t **); 69 | void VRE_quote(struct vsb *, const char *); 70 | 71 | #endif /* VRE_H_INCLUDED */ 72 | -------------------------------------------------------------------------------- /src/hpack.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2016 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Guillaume Quintard 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | 33 | enum hpk_result{ 34 | hpk_more = 0, 35 | hpk_done, 36 | hpk_err, 37 | }; 38 | 39 | enum hpk_indexed { 40 | hpk_unset = 0, 41 | hpk_idx, 42 | hpk_inc, 43 | hpk_not, 44 | hpk_never, 45 | }; 46 | 47 | struct hpk_txt { 48 | char *ptr; 49 | int len; 50 | int huff; 51 | }; 52 | 53 | struct hpk_hdr { 54 | struct hpk_txt key; 55 | struct hpk_txt value; 56 | enum hpk_indexed t; 57 | unsigned i; 58 | }; 59 | 60 | struct hpk_ctx; 61 | struct hpk_iter; 62 | 63 | struct hpk_ctx * HPK_NewCtx(uint32_t tblsize); 64 | void HPK_FreeCtx(struct hpk_ctx *ctx); 65 | 66 | struct hpk_iter * HPK_NewIter(struct hpk_ctx *ctx, void *buf, int size); 67 | void HPK_FreeIter(struct hpk_iter *iter); 68 | 69 | enum hpk_result HPK_DecHdr(struct hpk_iter *iter, struct hpk_hdr *header); 70 | enum hpk_result HPK_EncHdr(struct hpk_iter *iter, const struct hpk_hdr *header); 71 | 72 | int gethpk_iterLen(const struct hpk_iter *iter); 73 | 74 | enum hpk_result HPK_ResizeTbl(struct hpk_ctx *ctx, uint32_t num); 75 | 76 | const struct hpk_hdr * HPK_GetHdr(const struct hpk_ctx *ctx, uint32_t index); 77 | 78 | uint32_t HPK_GetTblSize(const struct hpk_ctx *ctx); 79 | uint32_t HPK_GetTblMaxSize(const struct hpk_ctx *ctx); 80 | uint32_t HPK_GetTblLength(const struct hpk_ctx *ctx); 81 | 82 | #if 0 83 | /* DEBUG */ 84 | void dump_dyn_tbl(const struct hpk_ctx *ctx); 85 | #endif 86 | -------------------------------------------------------------------------------- /lib/vbh.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2009 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * Binary Heap API (see: http://en.wikipedia.org/wiki/Binary_heap) 32 | * 33 | * XXX: doesn't scale back the array of pointers when items are deleted. 34 | */ 35 | 36 | /* Public Interface --------------------------------------------------*/ 37 | 38 | struct vbh; 39 | 40 | typedef int vbh_cmp_t(void *priv, const void *a, const void *b); 41 | /* 42 | * Comparison function. 43 | * Should return true if item 'a' should be closer to the root 44 | * than item 'b' 45 | */ 46 | 47 | typedef void vbh_update_t(void *priv, void *a, unsigned newidx); 48 | /* 49 | * Update function (optional) 50 | * When items move in the tree, this function gets called to 51 | * notify the item of its new index. 52 | * Only needed if deleting non-root items. 53 | */ 54 | 55 | struct vbh *VBH_new(void *priv, vbh_cmp_t, vbh_update_t); 56 | /* 57 | * Create Binary tree 58 | * 'priv' is passed to cmp and update functions. 59 | */ 60 | 61 | void VBH_destroy(struct vbh **); 62 | /* 63 | * Destroy an empty Binary tree 64 | */ 65 | 66 | void VBH_insert(struct vbh *, void *); 67 | /* 68 | * Insert an item 69 | */ 70 | 71 | void VBH_reorder(const struct vbh *, unsigned idx); 72 | /* 73 | * Move an order after changing its key value. 74 | */ 75 | 76 | void VBH_delete(struct vbh *, unsigned idx); 77 | /* 78 | * Delete an item 79 | * The root item has 'idx' zero 80 | */ 81 | 82 | void *VBH_root(const struct vbh *); 83 | /* 84 | * Return the root item 85 | */ 86 | 87 | #define VBH_NOIDX 0 88 | -------------------------------------------------------------------------------- /lib/vtcp.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | struct suckaddr; 34 | 35 | /* from libvarnish/tcp.c */ 36 | /* NI_MAXHOST and NI_MAXSERV are ridiculously long for numeric format */ 37 | #define VTCP_ADDRBUFSIZE 64 38 | #define VTCP_PORTBUFSIZE 16 39 | 40 | int VTCP_Check(ssize_t a); 41 | #define VTCP_Assert(a) assert(VTCP_Check(a)) 42 | 43 | struct suckaddr *VTCP_my_suckaddr(int sock); 44 | void VTCP_myname(int sock, char *abuf, unsigned alen, 45 | char *pbuf, unsigned plen); 46 | void VTCP_hisname(int sock, char *abuf, unsigned alen, 47 | char *pbuf, unsigned plen); 48 | int VTCP_filter_http(int sock); 49 | int VTCP_fastopen(int sock, int depth); 50 | void VTCP_blocking(int sock); 51 | void VTCP_nonblocking(int sock); 52 | int VTCP_linger(int sock, int linger); 53 | int VTCP_check_hup(int sock); 54 | 55 | // #ifdef SOL_SOCKET 56 | void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen, 57 | char *pbuf, unsigned plen); 58 | int VTCP_connected(int s); 59 | int VTCP_connect(const struct suckaddr *name, int msec); 60 | int VTCP_open(const char *addr, const char *def_port, vtim_dur timeout, 61 | const char **err); 62 | void VTCP_close(int *s); 63 | int VTCP_bind(const struct suckaddr *addr, const char **errp); 64 | int VTCP_listen(const struct suckaddr *addr, int depth, const char **errp); 65 | int VTCP_listen_on(const char *addr, const char *def_port, int depth, 66 | const char **errp); 67 | void VTCP_set_read_timeout(int s, vtim_dur seconds); 68 | int VTCP_read(int fd, void *ptr, size_t len, vtim_dur tmo); 69 | // #endif 70 | -------------------------------------------------------------------------------- /src/tbl/h2_settings.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2016 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * RFC7540 section 11.3 31 | * 32 | * Upper 33 | * lower 34 | * tag 35 | * default 36 | * min 37 | * max 38 | * range_error 39 | */ 40 | 41 | /*lint -save -e525 -e539 */ 42 | 43 | H2_SETTING( // rfc7540,l,2097,2103 44 | HEADER_TABLE_SIZE, 45 | header_table_size, 46 | 0x1, 47 | 4096, // rfc7540,l,4224,4224 48 | 0, 49 | 0xffffffff, 50 | 0 51 | ) 52 | 53 | #ifndef H2_SETTINGS_PARAM_ONLY 54 | H2_SETTING( // rfc7540,l,2105,2114 55 | ENABLE_PUSH, 56 | enable_push, 57 | 0x2, 58 | 1, // rfc7540,l,4225,4225 59 | 0, 60 | 1, 61 | H2CE_PROTOCOL_ERROR 62 | ) 63 | #endif 64 | 65 | H2_SETTING( // rfc7540,l,2116,2121 66 | MAX_CONCURRENT_STREAMS, 67 | max_concurrent_streams, 68 | 0x3, 69 | 0xffffffff, // rfc7540,l,4226,4226 70 | 0, 71 | 0xffffffff, 72 | 0 73 | ) 74 | 75 | H2_SETTING( // rfc7540,l,2139,2148 76 | INITIAL_WINDOW_SIZE, 77 | initial_window_size, 78 | 0x4, 79 | 65535, // rfc7540,l,4227,4227 80 | 0, 81 | 0x7fffffff, 82 | H2CE_FLOW_CONTROL_ERROR 83 | ) 84 | 85 | H2_SETTING( // rfc7540,l,2150,2157 86 | MAX_FRAME_SIZE, 87 | max_frame_size, 88 | 0x5, 89 | 16384, // rfc7540,l,4228,4228 90 | 16384, 91 | 0x00ffffff, 92 | H2CE_PROTOCOL_ERROR 93 | ) 94 | 95 | H2_SETTING( // rfc7540,l,2159,2167 96 | MAX_HEADER_LIST_SIZE, 97 | max_header_list_size, 98 | 0x6, 99 | 0x7fffffff, // rfc7540,l,4229,4229 100 | 0, 101 | 0xffffffff, 102 | 0 103 | ) 104 | #undef H2_SETTING 105 | 106 | /*lint -restore */ 107 | -------------------------------------------------------------------------------- /src/teken_scs.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2009 Ed Schouten 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * $FreeBSD: head/sys/teken/teken_scs.h 332297 2018-04-08 19:23:50Z phk $ 29 | */ 30 | 31 | static inline teken_char_t 32 | teken_scs_process(const teken_t *t, teken_char_t c) 33 | { 34 | 35 | return (t->t_scs[t->t_curscs](t, c)); 36 | } 37 | 38 | /* Unicode points for VT100 box drawing. */ 39 | static const uint16_t teken_boxdrawing_unicode[31] = { 40 | 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, 41 | 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, 42 | 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, 43 | 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7 44 | }; 45 | 46 | /* ASCII points for VT100 box drawing. */ 47 | static const uint8_t teken_boxdrawing_8bit[31] = { 48 | '?', '?', 'H', 'F', 'C', 'L', '?', '?', 49 | 'N', 'V', '+', '+', '+', '+', '+', '-', 50 | '-', '-', '-', '-', '+', '+', '+', '+', 51 | '|', '?', '?', '?', '?', '?', '?', 52 | }; 53 | 54 | static teken_char_t 55 | teken_scs_special_graphics(const teken_t *t, teken_char_t c) 56 | { 57 | 58 | /* Box drawing. */ 59 | if (c >= '`' && c <= '~') 60 | return (t->t_stateflags & TS_8BIT ? 61 | teken_boxdrawing_8bit[c - '`'] : 62 | teken_boxdrawing_unicode[c - '`']); 63 | return (c); 64 | } 65 | 66 | static teken_char_t 67 | teken_scs_uk_national(const teken_t *t, teken_char_t c) 68 | { 69 | 70 | /* Pound sign. */ 71 | if (c == '#') 72 | return (t->t_stateflags & TS_8BIT ? 0x9c : 0xa3); 73 | return (c); 74 | } 75 | 76 | static teken_char_t 77 | teken_scs_us_ascii(const teken_t *t, teken_char_t c) 78 | { 79 | 80 | /* No processing. */ 81 | (void)t; 82 | return (c); 83 | } 84 | -------------------------------------------------------------------------------- /lib/vas.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2016 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * This is the default backend function for libvarnish' assert facilities. 32 | */ 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "vdef.h" 41 | 42 | #include "vas.h" 43 | 44 | const char * 45 | VAS_errtxt(int e) 46 | { 47 | const char *p; 48 | int oerrno = errno; 49 | 50 | p = strerror(e); 51 | if (p != NULL) 52 | return (p); 53 | 54 | errno = oerrno; 55 | return ("strerror(3) returned NULL"); 56 | } 57 | 58 | vas_f *VAS_Fail_Func v_noreturn_; 59 | 60 | void v_noreturn_ 61 | VAS_Fail(const char *func, const char *file, int line, 62 | const char *cond, enum vas_e kind) 63 | { 64 | int err = errno; 65 | 66 | if (VAS_Fail_Func != NULL) { 67 | VAS_Fail_Func(func, file, line, cond, kind); 68 | } else { 69 | if (kind == VAS_MISSING) { 70 | fprintf(stderr, 71 | "Missing error handling code in %s(), %s line %d:\n" 72 | " Condition(%s) not true.\n", 73 | func, file, line, cond); 74 | } else if (kind == VAS_INCOMPLETE) { 75 | fprintf(stderr, 76 | "Incomplete code in %s(), %s line %d:\n", 77 | func, file, line); 78 | } else if (kind == VAS_WRONG) { 79 | fprintf(stderr, 80 | "Wrong turn in %s(), %s line %d: %s\n", 81 | func, file, line, cond); 82 | } else { 83 | fprintf(stderr, 84 | "Assert error in %s(), %s line %d:\n" 85 | " Condition(%s) not true.\n", 86 | func, file, line, cond); 87 | } 88 | if (err) 89 | fprintf(stderr, 90 | " errno = %d (%s)\n", err, strerror(err)); 91 | } 92 | abort(); 93 | } 94 | -------------------------------------------------------------------------------- /lib/vsa.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013-2015 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #ifndef VSA_H_INCLUDED 33 | #define VSA_H_INCLUDED 34 | 35 | struct suckaddr; 36 | extern const size_t vsa_suckaddr_len; 37 | extern const struct suckaddr *bogo_ip; 38 | extern const struct suckaddr *bogo_ip6; 39 | 40 | void VSA_Init(void); 41 | int VSA_Sane(const struct suckaddr *); 42 | unsigned VSA_Port(const struct suckaddr *); 43 | int VSA_Compare(const struct suckaddr *, const struct suckaddr *); 44 | int VSA_Compare_IP(const struct suckaddr *, const struct suckaddr *); 45 | struct suckaddr *VSA_Clone(const struct suckaddr *sua); 46 | struct suckaddr *VSA_getsockname(int, void *, size_t); 47 | struct suckaddr *VSA_getpeername(int, void *, size_t); 48 | 49 | const void *VSA_Get_Sockaddr(const struct suckaddr *, socklen_t *sl); 50 | int VSA_Get_Proto(const struct suckaddr *); 51 | 52 | /* 53 | * 's' is a sockaddr of some kind, 'sal' is its length 54 | */ 55 | struct suckaddr *VSA_Malloc(const void *s, unsigned sal); 56 | 57 | /* 58 | * 'd' SHALL point to vsa_suckaddr_len aligned bytes of storage, 59 | * 's' is a sockaddr of some kind, 'sal' is its length. 60 | */ 61 | struct suckaddr *VSA_Build(void *d, const void *s, unsigned sal); 62 | 63 | /* 'd' SHALL point to vsa_suckaddr_len aligned bytes of storage 64 | * 65 | * fam: address family 66 | * a / al : address and length 67 | * p / pl : port and length 68 | * 69 | * NULL or 0 length argument are ignored. 70 | * argument of the wrong length are an error (NULL return value, EINVAL) 71 | */ 72 | struct suckaddr * VSA_BuildFAP(void *d, sa_family_t fam, 73 | const void *a, unsigned al, const void *p, unsigned pl); 74 | 75 | /* 76 | * This VRT interface is for the VCC generated ACL code, which needs 77 | * to know the address family and a pointer to the actual address. 78 | */ 79 | 80 | int VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/vtc_h2_stattbl.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * For Copyright information see RFC7541 [BSD3] 3 | */ 4 | 5 | STAT_HDRS(1, ":authority", "") 6 | STAT_HDRS(2, ":method", "GET") 7 | STAT_HDRS(3, ":method", "POST") 8 | STAT_HDRS(4, ":path", "/") 9 | STAT_HDRS(5, ":path", "/index.html") 10 | STAT_HDRS(6, ":scheme", "http") 11 | STAT_HDRS(7, ":scheme", "https") 12 | STAT_HDRS(8, ":status", "200") 13 | STAT_HDRS(9, ":status", "204") 14 | STAT_HDRS(10, ":status", "206") 15 | STAT_HDRS(11, ":status", "304") 16 | STAT_HDRS(12, ":status", "400") 17 | STAT_HDRS(13, ":status", "404") 18 | STAT_HDRS(14, ":status", "500") 19 | STAT_HDRS(15, "accept-charset", "") 20 | STAT_HDRS(16, "accept-encoding", "gzip,deflate") 21 | STAT_HDRS(17, "accept-language", "") 22 | STAT_HDRS(18, "accept-ranges", "") 23 | STAT_HDRS(19, "accept", "") 24 | STAT_HDRS(20, "access-control-allow-origin", "") 25 | STAT_HDRS(21, "age", "") 26 | STAT_HDRS(22, "allow", "") 27 | STAT_HDRS(23, "authorization", "") 28 | STAT_HDRS(24, "cache-control", "") 29 | STAT_HDRS(25, "content-disposition", "") 30 | STAT_HDRS(26, "content-encoding", "") 31 | STAT_HDRS(27, "content-language", "") 32 | STAT_HDRS(28, "content-length", "") 33 | STAT_HDRS(29, "content-location", "") 34 | STAT_HDRS(30, "content-range", "") 35 | STAT_HDRS(31, "content-type", "") 36 | STAT_HDRS(32, "cookie", "") 37 | STAT_HDRS(33, "date", "") 38 | STAT_HDRS(34, "etag", "") 39 | STAT_HDRS(35, "expect", "") 40 | STAT_HDRS(36, "expires", "") 41 | STAT_HDRS(37, "from", "") 42 | STAT_HDRS(38, "host", "") 43 | STAT_HDRS(39, "if-match", "") 44 | STAT_HDRS(40, "if-modified-since", "") 45 | STAT_HDRS(41, "if-none-match", "") 46 | STAT_HDRS(42, "if-range", "") 47 | STAT_HDRS(43, "if-unmodified-since", "") 48 | STAT_HDRS(44, "last-modified", "") 49 | STAT_HDRS(45, "link", "") 50 | STAT_HDRS(46, "location", "") 51 | STAT_HDRS(47, "max-forwards", "") 52 | STAT_HDRS(48, "proxy-authenticate", "") 53 | STAT_HDRS(49, "proxy-authorization", "") 54 | STAT_HDRS(50, "range", "") 55 | STAT_HDRS(51, "referer", "") 56 | STAT_HDRS(52, "refresh", "") 57 | STAT_HDRS(53, "retry-after", "") 58 | STAT_HDRS(54, "server", "") 59 | STAT_HDRS(55, "set-cookie", "") 60 | STAT_HDRS(56, "strict-transport-security", "") 61 | STAT_HDRS(57, "transfer-encoding", "") 62 | STAT_HDRS(58, "user-agent", "") 63 | STAT_HDRS(59, "vary", "") 64 | STAT_HDRS(60, "via", "") 65 | STAT_HDRS(61, "www-authenticate", "") 66 | -------------------------------------------------------------------------------- /tests/a02008.vtc: -------------------------------------------------------------------------------- 1 | vtest "HPACK test" 2 | 3 | server s1 { 4 | stream 0 { 5 | txsettings -hdrtbl 256 6 | rxsettings 7 | txsettings -ack 8 | rxsettings 9 | expect settings.ack == true 10 | } -run 11 | 12 | stream 1 { 13 | rxreq 14 | expect tbl.dec[1].key == "location" 15 | expect tbl.dec[1].value == "https://www.example.com" 16 | expect tbl.dec[2].key == "date" 17 | expect tbl.dec[2].value == "Mon, 21 Oct 2013 20:13:21 GMT" 18 | expect tbl.dec[3].key == "cache-control" 19 | expect tbl.dec[3].value == "private" 20 | expect tbl.dec[4].key == ":status" 21 | expect tbl.dec[4].value == "302" 22 | expect tbl.dec.size == 222 23 | txresp 24 | } -run 25 | 26 | stream 3 { 27 | rxreq 28 | expect tbl.dec[1].key == ":status" 29 | expect tbl.dec[1].value == "307" 30 | expect tbl.dec[2].key == "location" 31 | expect tbl.dec[2].value == "https://www.example.com" 32 | expect tbl.dec[3].key == "date" 33 | expect tbl.dec[3].value == "Mon, 21 Oct 2013 20:13:21 GMT" 34 | expect tbl.dec[4].key == "cache-control" 35 | expect tbl.dec[4].value == "private" 36 | expect tbl.dec.size == 222 37 | txresp 38 | } -run 39 | 40 | stream 5 { 41 | rxreq 42 | expect tbl.dec[1].key == "set-cookie" 43 | expect tbl.dec[1].value == "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" 44 | expect tbl.dec[2].key == "content-encoding" 45 | expect tbl.dec[2].value == "gzip" 46 | expect tbl.dec[3].key == "date" 47 | expect tbl.dec[3].value == "Mon, 21 Oct 2013 20:13:22 GMT" 48 | expect tbl.dec.size == 215 49 | txresp 50 | } -run 51 | } -start 52 | 53 | client c1 -connect ${s1_sock} { 54 | stream 0 { 55 | txsettings -hdrtbl 256 56 | rxsettings 57 | txsettings -ack 58 | rxsettings 59 | expect settings.ack == true 60 | } -run 61 | 62 | stream 1 { 63 | 64 | txreq \ 65 | -litIdxHdr inc 8 plain "302" \ 66 | -litIdxHdr inc 24 plain "private" \ 67 | -litIdxHdr inc 33 plain "Mon, 21 Oct 2013 20:13:21 GMT" \ 68 | -litIdxHdr inc 46 plain "https://www.example.com" 69 | expect tbl.enc[1].key == "location" 70 | expect tbl.enc[1].value == "https://www.example.com" 71 | expect tbl.enc[2].key == "date" 72 | expect tbl.enc[2].value == "Mon, 21 Oct 2013 20:13:21 GMT" 73 | expect tbl.enc[3].key == "cache-control" 74 | expect tbl.enc[3].value == "private" 75 | expect tbl.enc[4].key == ":status" 76 | expect tbl.enc[4].value == "302" 77 | expect tbl.enc.size == 222 78 | rxresp 79 | } -run 80 | 81 | stream 3 { 82 | txreq \ 83 | -litIdxHdr inc 8 huf "307" \ 84 | -idxHdr 65 \ 85 | -idxHdr 64 \ 86 | -idxHdr 63 87 | expect tbl.enc[1].key == ":status" 88 | expect tbl.enc[1].value == "307" 89 | expect tbl.enc[2].key == "location" 90 | expect tbl.enc[2].value == "https://www.example.com" 91 | expect tbl.enc[3].key == "date" 92 | expect tbl.enc[3].value == "Mon, 21 Oct 2013 20:13:21 GMT" 93 | expect tbl.enc[4].key == "cache-control" 94 | expect tbl.enc[4].value == "private" 95 | expect tbl.enc.size == 222 96 | rxresp 97 | } -run 98 | 99 | stream 5 { 100 | txreq -idxHdr 8 \ 101 | -idxHdr 65 \ 102 | -litIdxHdr inc 33 plain "Mon, 21 Oct 2013 20:13:22 GMT" \ 103 | -idxHdr 64 \ 104 | -litIdxHdr inc 26 plain "gzip" \ 105 | -litIdxHdr inc 55 plain "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" 106 | expect tbl.enc[1].key == "set-cookie" 107 | expect tbl.enc[1].value == "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" 108 | expect tbl.enc[2].key == "content-encoding" 109 | expect tbl.enc[2].value == "gzip" 110 | expect tbl.enc[3].key == "date" 111 | expect tbl.enc[3].value == "Mon, 21 Oct 2013 20:13:22 GMT" 112 | expect tbl.enc.size == 215 113 | rxresp 114 | } -run 115 | 116 | } -run 117 | 118 | server s1 -wait 119 | -------------------------------------------------------------------------------- /src/tbl/h2_error.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2016-2021 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * RFC7540 section 11.4 31 | * 32 | * Types: conn=1|stream=2 33 | * Reason: stream_close_t 34 | */ 35 | 36 | /*lint -save -e525 -e539 */ 37 | 38 | H2_ERROR( 39 | /* name */ NO_ERROR, 40 | /* val */ 0, 41 | /* types */ 3, 42 | /* reason */ SC_REM_CLOSE, 43 | /* descr */ "Graceful shutdown" 44 | ) 45 | 46 | H2_ERROR( 47 | /* name */ PROTOCOL_ERROR, 48 | /* val */ 1, 49 | /* types */ 3, 50 | /* reason */ SC_RX_JUNK, 51 | /* descr */ "Protocol error detected" 52 | ) 53 | 54 | H2_ERROR( 55 | /* name */ INTERNAL_ERROR, 56 | /* val */ 2, 57 | /* types */ 3, 58 | /* reason */ SC_VCL_FAILURE, 59 | /* descr */ "Implementation fault" 60 | ) 61 | 62 | H2_ERROR( 63 | /* name */ FLOW_CONTROL_ERROR, 64 | /* val */ 3, 65 | /* types */ 3, 66 | /* reason */ SC_OVERLOAD, 67 | /* descr */ "Flow-control limits exceeded" 68 | ) 69 | 70 | H2_ERROR( 71 | /* name */ SETTINGS_TIMEOUT, 72 | /* val */ 4, 73 | /* types */ 1, 74 | /* reason */ SC_RX_TIMEOUT, 75 | /* descr */ "Settings not acknowledged" 76 | ) 77 | 78 | H2_ERROR( 79 | /* name */ STREAM_CLOSED, 80 | /* val */ 5, 81 | /* types */ 2, 82 | /* reason */ SC_NULL, 83 | /* descr */ "Frame received for closed stream" 84 | ) 85 | 86 | H2_ERROR( 87 | /* name */ FRAME_SIZE_ERROR, 88 | /* val */ 6, 89 | /* types */ 3, 90 | /* reason */ SC_RX_JUNK, 91 | /* descr */ "Frame size incorrect" 92 | ) 93 | 94 | H2_ERROR( 95 | /* name */ REFUSED_STREAM, 96 | /* val */ 7, 97 | /* types */ 2, 98 | /* reason */ SC_NULL, 99 | /* descr */ "Stream not processed" 100 | ) 101 | 102 | H2_ERROR( 103 | /* name */ CANCEL, 104 | /* val */ 8, 105 | /* types */ 2, 106 | /* reason */ SC_NULL, 107 | /* descr */ "Stream cancelled" 108 | ) 109 | 110 | H2_ERROR( 111 | /* name */ COMPRESSION_ERROR, 112 | /* val */ 9, 113 | /* types */ 1, 114 | /* reason */ SC_RX_JUNK, 115 | /* descr */ "Compression state not updated" 116 | ) 117 | 118 | H2_ERROR( 119 | /* name */ CONNECT_ERROR, 120 | /* val */ 10, 121 | /* types */ 2, 122 | /* reason */ SC_NULL, 123 | /* descr */ "TCP connection error for CONNECT method" 124 | ) 125 | 126 | H2_ERROR( 127 | /* name */ ENHANCE_YOUR_CALM, 128 | /* val */ 11, 129 | /* types */ 3, 130 | /* reason */ SC_OVERLOAD, 131 | /* descr */ "Processing capacity exceeded" 132 | ) 133 | 134 | H2_ERROR( 135 | /* name */ INADEQUATE_SECURITY, 136 | /* val */ 12, 137 | /* types */ 1, 138 | /* reason */ SC_RX_JUNK, 139 | /* descr */ "Negotiated TLS parameters not acceptable" 140 | ) 141 | 142 | H2_ERROR( 143 | /* name */ HTTP_1_1_REQUIRED, 144 | /* val */ 13, 145 | /* types */ 1, 146 | /* reason */ SC_REQ_HTTP20, 147 | /* descr */ "Use HTTP/1.1 for the request" 148 | ) 149 | 150 | #undef H2_ERROR 151 | /*lint -restore */ 152 | -------------------------------------------------------------------------------- /lib/vend.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2003,2010 Poul-Henning Kamp 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * From: 29 | * $FreeBSD: head/sys/sys/endian.h 121122 2003-10-15 20:05:57Z obrien $ 30 | * 31 | * Endian conversion functions 32 | */ 33 | 34 | #ifndef VEND_H_INCLUDED 35 | #define VEND_H_INCLUDED 36 | 37 | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ 38 | 39 | static __inline uint16_t 40 | vbe16dec(const void *pp) 41 | { 42 | uint8_t const *p = (uint8_t const *)pp; 43 | 44 | return ((p[0] << 8) | p[1]); 45 | } 46 | 47 | static __inline uint32_t 48 | vbe32dec(const void *pp) 49 | { 50 | uint8_t const *p = (uint8_t const *)pp; 51 | 52 | return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 53 | } 54 | 55 | static __inline uint64_t 56 | vbe64dec(const void *pp) 57 | { 58 | uint8_t const *p = (uint8_t const *)pp; 59 | 60 | return (((uint64_t)vbe32dec(p) << 32) | vbe32dec(p + 4)); 61 | } 62 | 63 | #if 0 64 | static __inline uint16_t 65 | vle16dec(const void *pp) 66 | { 67 | uint8_t const *p = (uint8_t const *)pp; 68 | 69 | return ((p[1] << 8) | p[0]); 70 | } 71 | #endif 72 | 73 | static __inline uint32_t 74 | vle32dec(const void *pp) 75 | { 76 | uint8_t const *p = (uint8_t const *)pp; 77 | 78 | return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); 79 | } 80 | 81 | #if 0 82 | static __inline uint64_t 83 | vle64dec(const void *pp) 84 | { 85 | uint8_t const *p = (uint8_t const *)pp; 86 | 87 | return (((uint64_t)vle32dec(p + 4) << 32) | vle32dec(p)); 88 | } 89 | #endif 90 | 91 | static __inline void 92 | vbe16enc(void *pp, uint16_t u) 93 | { 94 | uint8_t *p = (uint8_t *)pp; 95 | 96 | p[0] = (u >> 8) & 0xff; 97 | p[1] = u & 0xff; 98 | } 99 | 100 | static __inline void 101 | vbe32enc(void *pp, uint32_t u) 102 | { 103 | uint8_t *p = (uint8_t *)pp; 104 | 105 | p[0] = (u >> 24) & 0xff; 106 | p[1] = (u >> 16) & 0xff; 107 | p[2] = (u >> 8) & 0xff; 108 | p[3] = u & 0xff; 109 | } 110 | 111 | static __inline void 112 | vbe64enc(void *pp, uint64_t u) 113 | { 114 | uint8_t *p = (uint8_t *)pp; 115 | 116 | vbe32enc(p, (uint32_t)(u >> 32)); 117 | vbe32enc(p + 4, (uint32_t)(u & 0xffffffffU)); 118 | } 119 | 120 | static __inline void 121 | vle16enc(void *pp, uint16_t u) 122 | { 123 | uint8_t *p = (uint8_t *)pp; 124 | 125 | p[0] = u & 0xff; 126 | p[1] = (u >> 8) & 0xff; 127 | } 128 | 129 | static __inline void 130 | vle32enc(void *pp, uint32_t u) 131 | { 132 | uint8_t *p = (uint8_t *)pp; 133 | 134 | p[0] = u & 0xff; 135 | p[1] = (u >> 8) & 0xff; 136 | p[2] = (u >> 16) & 0xff; 137 | p[3] = (u >> 24) & 0xff; 138 | } 139 | 140 | #if 0 141 | static __inline void 142 | vle64enc(void *pp, uint64_t u) 143 | { 144 | uint8_t *p = (uint8_t *)pp; 145 | 146 | vle32enc(p, (uint32_t)(u & 0xffffffffU)); 147 | vle32enc(p + 4, (uint32_t)(u >> 32)); 148 | } 149 | #endif 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /lib/vfl.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2007-2009 Dag-Erling Coïdan Smørgrav 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer 12 | * in this position and unchanged. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * Derived from: 29 | * $FreeBSD: head/lib/libutil/flopen.c 326219 2017-11-26 02:00:33Z pfg $ 30 | */ 31 | 32 | #include "config.h" 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "vfl.h" 44 | 45 | /* 46 | * Reliably open and lock a file. 47 | * 48 | * Please do not modify this code without first reading the revision history 49 | * and discussing your changes with . Don't be fooled by the 50 | * code's apparent simplicity; there would be no need for this function if it 51 | * was easy to get right. 52 | */ 53 | static int 54 | vflopenat(int dirfd, const char *path, int flags, va_list ap) 55 | { 56 | int fd, operation, serrno, trunc; 57 | struct stat sb, fsb; 58 | mode_t mode; 59 | 60 | #ifdef O_EXLOCK 61 | flags &= ~O_EXLOCK; 62 | #endif 63 | 64 | mode = 0; 65 | if (flags & O_CREAT) { 66 | mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */ 67 | } 68 | 69 | operation = LOCK_EX; 70 | if (flags & O_NONBLOCK) 71 | operation |= LOCK_NB; 72 | 73 | trunc = (flags & O_TRUNC); 74 | flags &= ~O_TRUNC; 75 | 76 | for (;;) { 77 | if ((fd = openat(dirfd, path, flags, mode)) == -1) 78 | /* non-existent or no access */ 79 | return (-1); 80 | if (flock(fd, operation) == -1) { 81 | /* unsupported or interrupted */ 82 | serrno = errno; 83 | (void)close(fd); 84 | errno = serrno; 85 | return (-1); 86 | } 87 | if (fstatat(dirfd, path, &sb, 0) == -1) { 88 | /* disappeared from under our feet */ 89 | (void)close(fd); 90 | continue; 91 | } 92 | if (fstat(fd, &fsb) == -1) { 93 | /* can't happen [tm] */ 94 | serrno = errno; 95 | (void)close(fd); 96 | errno = serrno; 97 | return (-1); 98 | } 99 | if (sb.st_dev != fsb.st_dev || 100 | sb.st_ino != fsb.st_ino) { 101 | /* changed under our feet */ 102 | (void)close(fd); 103 | continue; 104 | } 105 | if (trunc && ftruncate(fd, 0) != 0) { 106 | /* can't happen [tm] */ 107 | serrno = errno; 108 | (void)close(fd); 109 | errno = serrno; 110 | return (-1); 111 | } 112 | /* 113 | * The following change is provided as a specific example to 114 | * avoid. 115 | */ 116 | #if 0 117 | if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { 118 | serrno = errno; 119 | (void)close(fd); 120 | errno = serrno; 121 | return (-1); 122 | } 123 | #endif 124 | return (fd); 125 | } 126 | } 127 | 128 | int 129 | VFL_Open(const char *path, int flags, ...) 130 | { 131 | va_list ap; 132 | int ret; 133 | 134 | va_start(ap, flags); 135 | ret = vflopenat(AT_FDCWD, path, flags, ap); 136 | va_end(ap); 137 | return (ret); 138 | } 139 | -------------------------------------------------------------------------------- /src/vtc_proxy.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2015 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include "config.h" 32 | 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | 39 | #include "vtc.h" 40 | 41 | #include "vend.h" 42 | #include "vsa.h" 43 | #include "vtcp.h" 44 | 45 | static const char vpx1_sig[] = {'P', 'R', 'O', 'X', 'Y'}; 46 | static const char vpx2_sig[] = { 47 | '\r', '\n', '\r', '\n', '\0', '\r', '\n', 48 | 'Q', 'U', 'I', 'T', '\n', 49 | }; 50 | 51 | static void 52 | vpx_enc_addr(struct vsb *vsb, int proto, const struct suckaddr *s) 53 | { 54 | const struct sockaddr_in *sin4; 55 | const struct sockaddr_in6 *sin6; 56 | socklen_t sl; 57 | 58 | if (proto == PF_INET6) { 59 | sin6 = VSA_Get_Sockaddr(s, &sl); //lint !e826 60 | AN(sin6); 61 | assert(sl >= sizeof(*sin6)); 62 | VSB_bcat(vsb, &sin6->sin6_addr, sizeof(sin6->sin6_addr)); 63 | } else { 64 | sin4 = VSA_Get_Sockaddr(s, &sl); //lint !e826 65 | AN(sin4); 66 | assert(sl >= sizeof(*sin4)); 67 | VSB_bcat(vsb, &sin4->sin_addr, sizeof(sin4->sin_addr)); 68 | } 69 | } 70 | 71 | static void 72 | vpx_enc_port(struct vsb *vsb, const struct suckaddr *s) 73 | { 74 | uint8_t b[2]; 75 | 76 | vbe16enc(b, (uint16_t)VSA_Port(s)); 77 | VSB_bcat(vsb, b, sizeof(b)); 78 | } 79 | 80 | int 81 | vtc_send_proxy(int fd, int version, const struct suckaddr *sac, 82 | const struct suckaddr *sas) 83 | { 84 | struct vsb *vsb; 85 | char hc[VTCP_ADDRBUFSIZE]; 86 | char pc[VTCP_PORTBUFSIZE]; 87 | char hs[VTCP_ADDRBUFSIZE]; 88 | char ps[VTCP_PORTBUFSIZE]; 89 | int i; 90 | int proto; 91 | 92 | AN(sac); 93 | AN(sas); 94 | 95 | assert(version == 1 || version == 2); 96 | vsb = VSB_new_auto(); 97 | AN(vsb); 98 | 99 | proto = VSA_Get_Proto(sas); 100 | assert(proto == PF_INET6 || proto == PF_INET); 101 | 102 | if (version == 1) { 103 | VSB_bcat(vsb, vpx1_sig, sizeof(vpx1_sig)); 104 | if (proto == PF_INET6) 105 | VSB_cat(vsb, " TCP6 "); 106 | else if (proto == PF_INET) 107 | VSB_cat(vsb, " TCP4 "); 108 | VTCP_name(sac, hc, sizeof(hc), pc, sizeof(pc)); 109 | VTCP_name(sas, hs, sizeof(hs), ps, sizeof(ps)); 110 | VSB_printf(vsb, "%s %s %s %s\r\n", hc, hs, pc, ps); 111 | } else if (version == 2) { 112 | VSB_bcat(vsb, vpx2_sig, sizeof(vpx2_sig)); 113 | VSB_putc(vsb, 0x21); 114 | if (proto == PF_INET6) { 115 | VSB_putc(vsb, 0x21); 116 | VSB_putc(vsb, 0x00); 117 | VSB_putc(vsb, 0x24); 118 | } else if (proto == PF_INET) { 119 | VSB_putc(vsb, 0x11); 120 | VSB_putc(vsb, 0x00); 121 | VSB_putc(vsb, 0x0c); 122 | } 123 | vpx_enc_addr(vsb, proto, sac); 124 | vpx_enc_addr(vsb, proto, sas); 125 | vpx_enc_port(vsb, sac); 126 | vpx_enc_port(vsb, sas); 127 | } else 128 | WRONG("Wrong proxy version"); 129 | 130 | AZ(VSB_finish(vsb)); 131 | i = VSB_tofile(vsb, fd); 132 | VSB_destroy(&vsb); 133 | return (i); 134 | } 135 | -------------------------------------------------------------------------------- /lib/vlu.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2005-2008 Poul-Henning Kamp 3 | * All rights reserved. 4 | * 5 | * SPDX-License-Identifier: BSD-2-Clause 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * Functions for assembling a bytestream into text-lines and calling 29 | * a function on each. 30 | */ 31 | 32 | #include "config.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "vdef.h" 40 | 41 | #include "vas.h" // XXX Flexelint "not used" - but req'ed for assert() 42 | #include "miniobj.h" 43 | 44 | #include "vlu.h" 45 | 46 | struct vlu { 47 | unsigned magic; 48 | #define LINEUP_MAGIC 0x08286661 49 | char *buf; 50 | unsigned bufl; 51 | unsigned bufp; 52 | void *priv; 53 | vlu_f *func; 54 | }; 55 | 56 | struct vlu * 57 | VLU_New(vlu_f *func, void *priv, unsigned bufsize) 58 | { 59 | struct vlu *l; 60 | 61 | if (bufsize == 0) 62 | bufsize = BUFSIZ; 63 | ALLOC_OBJ(l, LINEUP_MAGIC); 64 | if (l != NULL) { 65 | l->func = func; 66 | l->priv = priv; 67 | l->bufl = bufsize - 1; 68 | l->buf = malloc(l->bufl + 1L); 69 | if (l->buf == NULL) 70 | FREE_OBJ(l); 71 | } 72 | return (l); 73 | } 74 | 75 | void 76 | VLU_Reset(struct vlu *l) 77 | { 78 | CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC); 79 | l->bufp = 0; 80 | } 81 | 82 | void 83 | VLU_Destroy(struct vlu **lp) 84 | { 85 | struct vlu *l; 86 | 87 | TAKE_OBJ_NOTNULL(l, lp, LINEUP_MAGIC); 88 | free(l->buf); 89 | FREE_OBJ(l); 90 | } 91 | 92 | static int 93 | LineUpProcess(struct vlu *l) 94 | { 95 | char *p, *q; 96 | int i; 97 | 98 | l->buf[l->bufp] = '\0'; 99 | for (p = l->buf; *p != '\0'; p = q) { 100 | /* Find first CR or NL */ 101 | for (q = p; *q != '\0'; q++) { 102 | if (*q == '\n' || *q == '\r') 103 | break; 104 | } 105 | if (*q == '\0') 106 | break; 107 | *q++ = '\0'; 108 | i = l->func(l->priv, p); 109 | if (i != 0) 110 | return (i); 111 | } 112 | if (*p != '\0') { 113 | q = strchr(p, '\0'); 114 | assert(q != NULL); 115 | l->bufp = (unsigned)(q - p); 116 | memmove(l->buf, p, l->bufp); 117 | l->buf[l->bufp] = '\0'; 118 | } else 119 | l->bufp = 0; 120 | return (0); 121 | } 122 | 123 | int 124 | VLU_Fd(struct vlu *l, int fd) 125 | { 126 | int i; 127 | 128 | CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC); 129 | i = read(fd, l->buf + l->bufp, l->bufl - l->bufp); 130 | if (i == 0) 131 | return (-2); 132 | if (i < 0) 133 | return (-1); 134 | l->bufp += i; 135 | return (LineUpProcess(l)); 136 | } 137 | 138 | int 139 | VLU_File(int fd, vlu_f *func, void *priv, unsigned bufsize) 140 | { 141 | struct vlu *vlu; 142 | int i; 143 | 144 | vlu = VLU_New(func, priv, bufsize); 145 | AN(vlu); 146 | do { 147 | i = VLU_Fd(vlu, fd); 148 | } while (i == 0); 149 | VLU_Destroy(&vlu); 150 | return (i); 151 | } 152 | 153 | int 154 | VLU_Feed(struct vlu *l, const char *ptr, int len) 155 | { 156 | int i = 0; 157 | unsigned u; 158 | 159 | CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC); 160 | AN(ptr); 161 | assert(len > 0); 162 | while (len > 0) { 163 | u = len; 164 | if (u > l->bufl - l->bufp) 165 | u = l->bufl - l->bufp; 166 | memcpy(l->buf + l->bufp, ptr, u); 167 | len -= u; 168 | ptr += u; 169 | l->bufp += u; 170 | i = LineUpProcess(l); 171 | if (i) 172 | return (i); 173 | } 174 | return (i); 175 | } 176 | -------------------------------------------------------------------------------- /lib/vus.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2018 UPLEX - Nils Goroll Systemoptimierung 3 | * All rights reserved. 4 | * 5 | * Author: Geoffrey Simmons 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "vdef.h" 40 | #include "vas.h" 41 | #include "vus.h" 42 | #include "vtcp.h" 43 | 44 | static int 45 | sun_init(struct sockaddr_un *uds, const char *path, const char **err) 46 | { 47 | AN(uds); 48 | AN(path); 49 | assert(*path == '/'); 50 | 51 | if (err) 52 | *err = NULL; 53 | 54 | if (strlen(path) + 1 > sizeof(uds->sun_path)) { 55 | errno = ENAMETOOLONG; 56 | if (err) 57 | *err = "Path too long for a Unix domain socket"; 58 | return (-1); 59 | } 60 | memset(uds->sun_path, 0, sizeof(uds->sun_path)); 61 | bprintf(uds->sun_path, "%s", path); 62 | uds->sun_family = PF_UNIX; 63 | return (0); 64 | } 65 | 66 | int 67 | VUS_resolver(const char *path, vus_resolved_f *func, void *priv, 68 | const char **err) 69 | { 70 | struct sockaddr_un uds; 71 | int ret; 72 | 73 | AN(err); 74 | 75 | ret = sun_init(&uds, path, err); 76 | if (ret) 77 | return (ret); 78 | 79 | if (func != NULL) 80 | ret = func(priv, &uds); 81 | return (ret); 82 | } 83 | 84 | int 85 | VUS_bind(const struct sockaddr_un *uds, const char **errp) 86 | { 87 | int sd, e; 88 | socklen_t sl = sizeof(*uds); 89 | 90 | if (errp != NULL) 91 | *errp = NULL; 92 | 93 | sd = socket(PF_UNIX, SOCK_STREAM, 0); 94 | if (sd < 0) { 95 | if (errp != NULL) 96 | *errp = "socket(2)"; 97 | return (-1); 98 | } 99 | 100 | if (unlink(uds->sun_path) != 0 && errno != ENOENT) { 101 | if (errp != NULL) 102 | *errp = "unlink(2)"; 103 | e = errno; 104 | closefd(&sd); 105 | errno = e; 106 | return (-1); 107 | } 108 | 109 | if (bind(sd, (const void*)uds, sl) != 0) { 110 | if (errp != NULL) 111 | *errp = "bind(2)"; 112 | e = errno; 113 | closefd(&sd); 114 | errno = e; 115 | return (-1); 116 | } 117 | return (sd); 118 | } 119 | 120 | int 121 | VUS_connect(const char *path, int msec) 122 | { 123 | int s, i; 124 | struct pollfd fds[1]; 125 | struct sockaddr_un uds; 126 | socklen_t sl = (socklen_t) sizeof(uds); 127 | 128 | if (path == NULL) 129 | return (-1); 130 | i = sun_init(&uds, path, NULL); 131 | if (i) 132 | return (i); 133 | AN(sl); 134 | 135 | s = socket(PF_UNIX, SOCK_STREAM, 0); 136 | if (s < 0) 137 | return (s); 138 | 139 | /* Set the socket non-blocking */ 140 | if (msec != 0) 141 | VTCP_nonblocking(s); 142 | 143 | i = connect(s, (const void*)&uds, sl); 144 | if (i == 0) 145 | return (s); 146 | if (errno != EINPROGRESS) { 147 | closefd(&s); 148 | return (-1); 149 | } 150 | 151 | if (msec < 0) { 152 | /* 153 | * Caller is responsible for waiting and 154 | * calling VTCP_connected 155 | */ 156 | return (s); 157 | } 158 | 159 | assert(msec > 0); 160 | /* Exercise our patience, polling for write */ 161 | fds[0].fd = s; 162 | fds[0].events = POLLWRNORM; 163 | fds[0].revents = 0; 164 | i = poll(fds, 1, msec); 165 | 166 | if (i == 0) { 167 | /* Timeout, close and give up */ 168 | closefd(&s); 169 | errno = ETIMEDOUT; 170 | return (-1); 171 | } 172 | 173 | return (VTCP_connected(s)); 174 | } 175 | -------------------------------------------------------------------------------- /lib/vas.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * assert(), AN() and AZ() are static checks that should not happen. 32 | * In general asserts should be cheap, such as checking return 33 | * values and similar. 34 | * diagnostic() are asserts which are so expensive that we may want 35 | * to compile them out for performance at a later date. 36 | * xxxassert(), XXXAN() and XXXAZ() marks conditions we ought to 37 | * handle gracefully, such as malloc failure. 38 | */ 39 | 40 | #ifndef VAS_H_INCLUDED 41 | #define VAS_H_INCLUDED 42 | 43 | 44 | #include 45 | #include // size_t 46 | 47 | const char * VAS_errtxt(int e); 48 | 49 | enum vas_e { 50 | VAS_WRONG, 51 | VAS_MISSING, 52 | VAS_ASSERT, 53 | VAS_INCOMPLETE, 54 | VAS_VCL, 55 | }; 56 | 57 | typedef void vas_f(const char *, const char *, int, const char *, enum vas_e); 58 | 59 | extern vas_f *VAS_Fail_Func v_noreturn_; 60 | extern vas_f VAS_Fail v_noreturn_; 61 | 62 | #ifdef WITHOUT_ASSERTS 63 | #define assert(e) ((void)(e)) 64 | #else /* WITH_ASSERTS */ 65 | #define assert(e) \ 66 | do { \ 67 | if (!(e)) { \ 68 | VAS_Fail(__func__, __FILE__, __LINE__, \ 69 | #e, VAS_ASSERT); \ 70 | } \ 71 | } while (0) 72 | #endif 73 | 74 | #define xxxassert(e) \ 75 | do { \ 76 | if (!(e)) { \ 77 | VAS_Fail(__func__, __FILE__, __LINE__, \ 78 | #e, VAS_MISSING); \ 79 | } \ 80 | } while (0) 81 | 82 | /* Assert zero return value */ 83 | #define AZ(foo) do { assert((foo) == 0); } while (0) 84 | #define AN(foo) do { assert((foo) != 0); } while (0) 85 | #define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0) 86 | #define XXXAN(foo) do { xxxassert((foo) != 0); } while (0) 87 | #define diagnostic(foo) assert(foo) 88 | #define WRONG(expl) \ 89 | do { \ 90 | VAS_Fail(__func__, __FILE__, __LINE__, expl, VAS_WRONG); \ 91 | } while (0) 92 | 93 | #define INCOMPL() \ 94 | do { \ 95 | VAS_Fail(__func__, __FILE__, __LINE__, \ 96 | "", VAS_INCOMPLETE); \ 97 | } while (0) 98 | 99 | /* 100 | * Most of this nightmare is stolen from FreeBSD's 101 | */ 102 | #ifndef __has_extension 103 | # define __has_extension(x) 0 104 | #endif 105 | 106 | #if __has_extension(c_static_assert) 107 | # define v_static_assert _Static_assert 108 | #elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) 109 | # define v_static_assert _Static_assert 110 | #else 111 | # if defined(__COUNTER__) 112 | # define v_static_assert(x, y) __v_static_assert(x, __COUNTER__) 113 | # else 114 | # define v_static_assert(x, y) __v_static_assert(x, __LINE__) 115 | # endif 116 | # define __v_static_assert(x, y) ___v_static_assert(x, y) 117 | # define ___v_static_assert(x, y) \ 118 | typedef char __vassert_## y[(x) ? 1 : -1] v_unused_ 119 | #endif 120 | 121 | /* 122 | * A normal pointer difference is signed, but when we don't want a negative 123 | * value this little tool will make sure we don't get that. 124 | */ 125 | 126 | static inline size_t 127 | pdiff(const void *b, const void *e) 128 | { 129 | 130 | AN(b); 131 | AN(e); 132 | assert(b <= e); 133 | return ((size_t)((const char *)e - (const char *)b)); 134 | } 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /src/tbl/h2_frames.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2016 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * RFC7540 section 11.2 31 | */ 32 | 33 | /*lint -save -e525 -e539 */ 34 | 35 | #ifdef H2_FRAME 36 | /* lower, upper, type, flags 37 | * rx_stream-zero 38 | * rx_stream-nonzero 39 | * rx_stream-idle 40 | * tx_flow-control // rfc7540,l,1265,1270 41 | * tx_continuation 42 | * tx_final-flags 43 | * overhead 44 | */ 45 | H2_FRAME(data, DATA, 0x0, 0x09, 46 | H2CE_PROTOCOL_ERROR, // rfc7540,l,1758,1761 47 | 0, 48 | H2CE_PROTOCOL_ERROR, 49 | 1, 50 | H2_F_DATA, 51 | 0x01, // rfc7540,l,1750,1753 52 | 0 53 | ) 54 | H2_FRAME(headers, HEADERS, 0x1, 0x2d, 55 | H2CE_PROTOCOL_ERROR, // rfc7540,l,1876,1879 56 | 0, 57 | 0, // rfc7540,l,938,940 58 | 0, 59 | H2_F_CONTINUATION, 60 | 0x04, // rfc7540,l,1855,1857 61 | 0 62 | ) 63 | H2_FRAME(priority, PRIORITY, 0x2, 0x00, 64 | H2CE_PROTOCOL_ERROR, // rfc7540,l,1933,1936 65 | 0, 66 | 0, // rfc7540,l,938,940 67 | 0, 68 | 0, 69 | 0, 70 | 1 71 | ) 72 | H2_FRAME(rst_stream, RST_STREAM, 0x3, 0x00, 73 | H2CE_PROTOCOL_ERROR, // rfc7540,l,1993,1996 74 | 0, 75 | H2CE_PROTOCOL_ERROR, 76 | 0, 77 | 0, 78 | 0, 79 | 1 80 | ) 81 | H2_FRAME(settings, SETTINGS, 0x4, 0x01, 82 | 0, 83 | H2CE_PROTOCOL_ERROR, // rfc7540,l,2052,2056 84 | H2CE_PROTOCOL_ERROR, 85 | 0, 86 | 0, 87 | 0, 88 | 1 89 | ) 90 | H2_FRAME(push_promise, PUSH_PROMISE, 0x5, 0x0c, 91 | H2CE_PROTOCOL_ERROR, // rfc7540,l,2262,2263 92 | 0, 93 | H2CE_PROTOCOL_ERROR, 94 | 0, 95 | H2_F_CONTINUATION, 96 | 0x04, // rfc7540,l,2249,2251 97 | 2 98 | ) 99 | H2_FRAME(ping, PING, 0x6, 0x01, 100 | 0, 101 | H2CE_PROTOCOL_ERROR, // rfc7540,l,2359,2362 102 | H2CE_PROTOCOL_ERROR, 103 | 0, 104 | 0, 105 | 0, 106 | 1 107 | ) 108 | H2_FRAME(goaway, GOAWAY, 0x7, 0x00, 109 | 0, 110 | H2CE_PROTOCOL_ERROR, // rfc7540,l,2432,2435 111 | H2CE_PROTOCOL_ERROR, 112 | 0, 113 | 0, 114 | 0, 115 | 1 116 | ) 117 | H2_FRAME(window_update, WINDOW_UPDATE, 0x8, 0x00, 118 | 0, 119 | 0, 120 | H2CE_PROTOCOL_ERROR, 121 | 0, 122 | 0, 123 | 0, 124 | 1 125 | ) 126 | H2_FRAME(continuation, CONTINUATION, 0x9, 0x04, 127 | H2CE_PROTOCOL_ERROR, // rfc7540,l,2764,2767 128 | 0, 129 | H2CE_PROTOCOL_ERROR, 130 | 0, 131 | H2_F_CONTINUATION, 132 | 0x04, // rfc7540,l,2753,2754 133 | 0 134 | ) 135 | #undef H2_FRAME 136 | #endif 137 | 138 | #ifdef H2_FRAME_FLAGS 139 | /* lower, upper, flag */ 140 | H2_FRAME_FLAGS(none, NONE, 0x00) 141 | H2_FRAME_FLAGS(data_end_stream, DATA_END_STREAM, 0x01) 142 | H2_FRAME_FLAGS(data_padded, DATA_PADDED, 0x08) 143 | H2_FRAME_FLAGS(headers_end_stream, HEADERS_END_STREAM, 0x01) 144 | H2_FRAME_FLAGS(headers_end_headers, HEADERS_END_HEADERS, 0x04) 145 | H2_FRAME_FLAGS(headers_padded, HEADERS_PADDED, 0x08) 146 | H2_FRAME_FLAGS(headers_priority, HEADERS_PRIORITY, 0x20) 147 | H2_FRAME_FLAGS(settings_ack, SETTINGS_ACK, 0x01) 148 | H2_FRAME_FLAGS(push_promise_end_headers,PUSH_PROMISE_END_HEADERS, 0x04) 149 | H2_FRAME_FLAGS(push_promise_padded, PUSH_PROMISE_PADDED, 0x08) 150 | H2_FRAME_FLAGS(ping_ack, PING_ACK, 0x01) 151 | H2_FRAME_FLAGS(continuation_end_headers,CONTINUATION_END_HEADERS, 0x04) 152 | #undef H2_FRAME_FLAGS 153 | #endif 154 | 155 | /*lint -restore */ 156 | -------------------------------------------------------------------------------- /lib/vsb.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2000-2011 Poul-Henning Kamp 5 | * Copyright (c) 2000-2008 Dag-Erling Coïdan Smørgrav 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer 13 | * in this position and unchanged. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * $FreeBSD: head/sys/sys/vsb.h 221993 2011-05-16 16:18:40Z phk $ 31 | */ 32 | 33 | #ifndef VSB_H_INCLUDED 34 | #define VSB_H_INCLUDED 35 | 36 | /* 37 | * Structure definition 38 | */ 39 | struct vsb { 40 | unsigned magic; 41 | #define VSB_MAGIC 0x4a82dd8a 42 | int s_error; /* current error code */ 43 | char *s_buf; /* storage buffer */ 44 | ssize_t s_size; /* size of storage buffer */ 45 | ssize_t s_len; /* current length of string */ 46 | #define VSB_FIXEDLEN 0x00000000 /* fixed length buffer (default) */ 47 | #define VSB_AUTOEXTEND 0x00000001 /* automatically extend buffer */ 48 | #define VSB_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */ 49 | #define VSB_DYNAMIC 0x00010000 /* s_buf must be freed */ 50 | #define VSB_FINISHED 0x00020000 /* set by VSB_finish() */ 51 | #define VSB_DYNSTRUCT 0x00080000 /* vsb must be freed */ 52 | int s_flags; /* flags */ 53 | int s_indent; /* Ident level */ 54 | }; 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | /* 60 | * API functions 61 | */ 62 | struct vsb *VSB_init(struct vsb *, void *, ssize_t); 63 | struct vsb *VSB_new_auto(void); 64 | void VSB_clear(struct vsb *); 65 | int VSB_bcat(struct vsb *, const void *, ssize_t); 66 | int VSB_cat(struct vsb *, const char *); 67 | int VSB_printf(struct vsb *, const char *, ...) 68 | v_printflike_(2, 3); 69 | #ifdef va_start 70 | int VSB_vprintf(struct vsb *, const char *, va_list) 71 | v_printflike_(2, 0); 72 | #endif 73 | int VSB_putc(struct vsb *, int); 74 | int VSB_error(const struct vsb *); 75 | int VSB_finish(struct vsb *); 76 | char *VSB_data(const struct vsb *); 77 | ssize_t VSB_len(const struct vsb *); 78 | void VSB_fini(struct vsb *); 79 | void VSB_destroy(struct vsb **); 80 | 81 | /* 82 | * VSB_quote[_pfx] has four major modes, and two modifiers 83 | */ 84 | 85 | #define VSB_QUOTE_PLAIN 0 86 | /* 87 | * Basic "show me the string" mode 88 | * All output is a single line 89 | */ 90 | #define VSB_QUOTE_JSON 2 91 | /* 92 | * Output suitable for inclusion between "..." in JSON 93 | * Uses JSON \u%04x quoting. 94 | * Anything above 0x7e had better be UTF-8 95 | */ 96 | #define VSB_QUOTE_HEX 4 97 | /* 98 | * Hex dump, single line. 99 | * All zero data is compressed to "0x0...0" 100 | */ 101 | #define VSB_QUOTE_CSTR 8 102 | /* 103 | * C lanuage source code literal string(s) 104 | * Breaks strings at \n (expecting string concatenation) 105 | */ 106 | #define VSB_QUOTE_UNSAFE 16 107 | /* 108 | * For general display applications 109 | * " and \ are not quoted 110 | * Splits output to new line at '\n' 111 | * Implies VSB_QUOTE_NONL 112 | */ 113 | 114 | #define VSB_QUOTE_NONL 1 115 | /* 116 | * If the output does not end in \n, append \n 117 | * Can be combined with all other modes. 118 | */ 119 | 120 | #define VSB_QUOTE_ESCHEX 32 121 | /* 122 | * Use \x%02x instead of \%03o 123 | * Not valid with VSB_QUOTE_JSON and VSB_QUOTE_HEX 124 | */ 125 | 126 | void VSB_quote_pfx(struct vsb *, const char*, const void *, 127 | int len, int how); 128 | void VSB_quote(struct vsb *, const void *, int len, int how); 129 | void VSB_indent(struct vsb *, int); 130 | int VSB_tofile(const struct vsb *, int fd); 131 | #ifdef __cplusplus 132 | }; 133 | #endif 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /lib/vpf.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2005 Pawel Jakub Dawidek 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * Derived from: 28 | * $FreeBSD: head/lib/libutil/pidfile.c 184091 2008-10-20 17:41:08Z des $ 29 | */ 30 | 31 | #include "config.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "vdef.h" 45 | 46 | #include "vas.h" // XXX Flexelint "not used" - but req'ed for assert() 47 | #include "vfl.h" 48 | #include "vpf.h" 49 | 50 | struct vpf_fh { 51 | int pf_fd; 52 | char *pf_path; 53 | dev_t pf_dev; 54 | ino_t pf_ino; 55 | }; 56 | 57 | static int 58 | vpf_verify(const struct vpf_fh *pfh) 59 | { 60 | struct stat sb; 61 | 62 | if (pfh == NULL || pfh->pf_fd == -1) 63 | return (EINVAL); 64 | /* 65 | * Check remembered descriptor. 66 | */ 67 | if (fstat(pfh->pf_fd, &sb) == -1) 68 | return (errno); 69 | if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino) 70 | return (EINVAL); 71 | return (0); 72 | } 73 | 74 | int 75 | VPF_Read(const char *path, pid_t *pidptr) 76 | { 77 | char buf[16], *endptr; 78 | int error, fd, i; 79 | 80 | fd = open(path, O_RDONLY | O_CLOEXEC); 81 | if (fd == -1) 82 | return (errno); 83 | 84 | i = read(fd, buf, sizeof(buf) - 1); 85 | error = errno; 86 | closefd(&fd); 87 | if (i == -1) 88 | return (error); 89 | else if (i == 0) 90 | return (EAGAIN); 91 | if (i > 0 && buf[i - 1] == '\n') 92 | i--; 93 | buf[i] = '\0'; 94 | 95 | *pidptr = strtol(buf, &endptr, 10); 96 | if (endptr != &buf[i]) 97 | return (EINVAL); 98 | 99 | return (0); 100 | } 101 | 102 | struct vpf_fh * 103 | VPF_Open(const char *path, mode_t mode, pid_t *pidptr) 104 | { 105 | struct vpf_fh *pfh; 106 | struct stat sb; 107 | int fd; 108 | 109 | /* 110 | * Open the PID file and obtain exclusive lock. 111 | * We truncate PID file here only to remove old PID immediately, 112 | * PID file will be truncated again in VPF_Write(), so 113 | * VPF_Write() can be called multiple times. 114 | */ 115 | fd = VFL_Open(path, 116 | O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); 117 | if (fd == -1) { 118 | if (errno == EWOULDBLOCK && pidptr != NULL) { 119 | errno = VPF_Read(path, pidptr); 120 | if (errno == 0) 121 | errno = EEXIST; 122 | } 123 | return (NULL); 124 | } 125 | 126 | /* 127 | * Remember file information, so in VPF_Write() we are sure we write 128 | * to the proper descriptor. 129 | */ 130 | AZ(fstat(fd, &sb)); 131 | 132 | pfh = malloc(sizeof(*pfh)); 133 | AN(pfh); 134 | pfh->pf_path = strdup(path); 135 | AN(pfh->pf_path); 136 | 137 | pfh->pf_fd = fd; 138 | pfh->pf_dev = sb.st_dev; 139 | pfh->pf_ino = sb.st_ino; 140 | 141 | return (pfh); 142 | } 143 | 144 | void 145 | VPF_Write(const struct vpf_fh *pfh) 146 | { 147 | char pidstr[16]; 148 | 149 | /* 150 | * Check remembered descriptor, so we don't overwrite some other 151 | * file if pidfile was closed and descriptor reused. 152 | */ 153 | if (vpf_verify(pfh) != 0) 154 | return; 155 | 156 | /* 157 | * Truncate PID file, so multiple calls of VPF_Write() are allowed. 158 | */ 159 | AZ(ftruncate(pfh->pf_fd, 0)); 160 | 161 | bprintf(pidstr, "%jd", (intmax_t)getpid()); 162 | assert(pwrite(pfh->pf_fd, pidstr, strlen(pidstr), 0) == 163 | (ssize_t)strlen(pidstr)); 164 | } 165 | 166 | void 167 | VPF_Remove(struct vpf_fh *pfh) 168 | { 169 | if (vpf_verify(pfh) == 0) { 170 | (void)unlink(pfh->pf_path); 171 | closefd(&pfh->pf_fd); 172 | } 173 | free(pfh->pf_path); 174 | free(pfh); 175 | } 176 | -------------------------------------------------------------------------------- /src/teken_subr_compat.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 | * 4 | * Copyright (c) 2008-2009 Ed Schouten 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * $FreeBSD: head/sys/teken/teken_subr_compat.h 332297 2018-04-08 19:23:50Z phk $ 29 | */ 30 | 31 | static void 32 | teken_subr_cons25_set_border(const teken_t *t, unsigned int c) 33 | { 34 | 35 | teken_funcs_param(t, TP_SETBORDER, c); 36 | } 37 | 38 | static void 39 | teken_subr_cons25_set_global_cursor_shape(const teken_t *t, unsigned int ncmds, 40 | const unsigned int cmds[]) 41 | { 42 | unsigned int code, i; 43 | 44 | /* 45 | * Pack the args to work around API deficiencies. This requires 46 | * knowing too much about the low level to be fully compatible. 47 | * Returning when ncmds > 3 is necessary and happens to be 48 | * compatible. Discarding high bits is necessary and happens to 49 | * be incompatible only for invalid args when ncmds == 3. 50 | */ 51 | if (ncmds > 3) 52 | return; 53 | code = 0; 54 | for (i = ncmds; i > 0; i--) 55 | code = (code << 8) | (cmds[i - 1] & 0xff); 56 | code = (code << 8) | ncmds; 57 | teken_funcs_param(t, TP_SETGLOBALCURSOR, code); 58 | } 59 | 60 | static void 61 | teken_subr_cons25_set_local_cursor_type(const teken_t *t, unsigned int type) 62 | { 63 | 64 | teken_funcs_param(t, TP_SETLOCALCURSOR, type); 65 | } 66 | 67 | static const teken_color_t cons25_colors[8] = { TC_BLACK, TC_BLUE, 68 | TC_GREEN, TC_CYAN, TC_RED, TC_MAGENTA, TC_BROWN, TC_WHITE }; 69 | 70 | static void 71 | teken_subr_cons25_set_default_background(teken_t *t, unsigned int c) 72 | { 73 | 74 | t->t_defattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8); 75 | t->t_curattr.ta_bgcolor = cons25_colors[c % 8] | (c & 8); 76 | } 77 | 78 | static void 79 | teken_subr_cons25_set_default_foreground(teken_t *t, unsigned int c) 80 | { 81 | 82 | t->t_defattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8); 83 | t->t_curattr.ta_fgcolor = cons25_colors[c % 8] | (c & 8); 84 | } 85 | 86 | static const teken_color_t cons25_revcolors[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; 87 | 88 | void 89 | teken_get_defattr_cons25(const teken_t *t, int *fg, int *bg) 90 | { 91 | 92 | *fg = cons25_revcolors[teken_256to8(t->t_defattr.ta_fgcolor)]; 93 | if (t->t_defattr.ta_format & TF_BOLD) 94 | *fg += 8; 95 | *bg = cons25_revcolors[teken_256to8(t->t_defattr.ta_bgcolor)]; 96 | } 97 | 98 | static void 99 | teken_subr_cons25_switch_virtual_terminal(const teken_t *t, unsigned int vt) 100 | { 101 | 102 | teken_funcs_param(t, TP_SWITCHVT, vt); 103 | } 104 | 105 | static void 106 | teken_subr_cons25_set_bell_pitch_duration(const teken_t *t, unsigned int pitch, 107 | unsigned int duration) 108 | { 109 | 110 | teken_funcs_param(t, TP_SETBELLPD, (pitch << 16) | 111 | (duration & 0xffff)); 112 | } 113 | 114 | static void 115 | teken_subr_cons25_set_graphic_rendition(teken_t *t, unsigned int cmd, 116 | unsigned int param) 117 | { 118 | 119 | (void)param; 120 | switch (cmd) { 121 | case 0: /* Reset. */ 122 | t->t_curattr = t->t_defattr; 123 | break; 124 | default: 125 | teken_printf("unsupported attribute %u\n", cmd); 126 | } 127 | } 128 | 129 | static void 130 | teken_subr_cons25_set_terminal_mode(teken_t *t, unsigned int mode) 131 | { 132 | 133 | switch (mode) { 134 | case 0: /* Switch terminal to xterm. */ 135 | t->t_stateflags &= ~TS_CONS25; 136 | break; 137 | case 1: /* Switch terminal to cons25. */ 138 | t->t_stateflags |= TS_CONS25; 139 | break; 140 | default: 141 | break; 142 | } 143 | } 144 | 145 | #if 0 146 | static void 147 | teken_subr_vt52_decid(teken_t *t) 148 | { 149 | const char response[] = "\x1B/Z"; 150 | 151 | teken_funcs_respond(t, response, sizeof response - 1); 152 | } 153 | #endif 154 | -------------------------------------------------------------------------------- /lib/vct.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2009 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* from libvarnish/vct.c */ 34 | 35 | #include "vas.h" 36 | 37 | #define VCT_OWS (1<<0) 38 | #define VCT_CRLF (1<<1) 39 | #define VCT_LWS (VCT_CRLF | VCT_OWS) 40 | #define VCT_CTL (1<<2) 41 | #define VCT_ALPHA (1<<3) 42 | #define VCT_SEPARATOR (1<<4) 43 | #define VCT_DIGIT (1<<5) 44 | #define VCT_HEX (1<<6) 45 | #define VCT_XMLNAMESTART (1<<7) 46 | #define VCT_XMLNAME (1<<8) 47 | #define VCT_TCHAR (1<<9) 48 | #define VCT_ID (1<<10) 49 | #define VCT_IDENT (VCT_ALPHA | VCT_DIGIT | VCT_ID) 50 | #define VCT_BASE64 (1<<11) 51 | #define VCT_VT (1<<12) 52 | #define VCT_SPACE (VCT_LWS | VCT_VT) 53 | #define VCT_UPPER (1<<13) 54 | #define VCT_LOWER (1<<14) 55 | 56 | extern const uint16_t vct_typtab[256]; 57 | extern const uint8_t vct_lowertab[256]; 58 | 59 | const char *VCT_invalid_name(const char *b, const char *e); 60 | 61 | static inline int 62 | vct_is(int x, uint16_t y) 63 | { 64 | 65 | x &= 0xff; 66 | return (vct_typtab[x] & (y)); 67 | } 68 | 69 | #define vct_isows(x) vct_is(x, VCT_OWS) 70 | #define vct_issp(x) vct_is(x, VCT_OWS) 71 | #define vct_ishex(x) vct_is(x, VCT_HEX) 72 | #define vct_islws(x) vct_is(x, VCT_LWS) 73 | #define vct_isctl(x) vct_is(x, VCT_CTL) 74 | #define vct_isspace(x) vct_is(x, VCT_SPACE) 75 | #define vct_isdigit(x) vct_is(x, VCT_DIGIT) 76 | #define vct_isalpha(x) vct_is(x, VCT_ALPHA) 77 | #define vct_islower(x) vct_is(x, VCT_LOWER) 78 | #define vct_isupper(x) vct_is(x, VCT_UPPER) 79 | #define vct_isalnum(x) vct_is(x, VCT_ALPHA | VCT_DIGIT) 80 | #define vct_isbase64(x) vct_is(x, VCT_BASE64) 81 | #define vct_issep(x) vct_is(x, VCT_SEPARATOR) 82 | #define vct_issepctl(x) vct_is(x, VCT_SEPARATOR | VCT_CTL) 83 | #define vct_isident1(x) vct_isalpha(x) 84 | #define vct_isident(x) vct_is(x, VCT_IDENT) 85 | #define vct_isxmlnamestart(x) vct_is(x, VCT_XMLNAMESTART) 86 | #define vct_isxmlname(x) vct_is(x, VCT_XMLNAMESTART | VCT_XMLNAME) 87 | #define vct_istchar(x) vct_is(x, VCT_ALPHA | VCT_DIGIT | VCT_TCHAR) 88 | #define vct_ishdrval(x) \ 89 | (((uint8_t)(x) >= 0x20 && (uint8_t)(x) != 0x7f) ||(uint8_t)(x) == 0x09) 90 | 91 | static inline int 92 | vct_iscrlf(const char* p, const char* end) 93 | { 94 | assert(p <= end); 95 | if (p == end) 96 | return (0); 97 | if ((p[0] == 0x0d && (p+1 < end) && p[1] == 0x0a)) // CR LF 98 | return (2); 99 | if (p[0] == 0x0a) // LF 100 | return (1); 101 | return (0); 102 | } 103 | 104 | /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */ 105 | static inline char* 106 | vct_skipcrlf(char* p, const char* end) 107 | { 108 | return (p + vct_iscrlf(p, end)); 109 | } 110 | 111 | static inline int 112 | vct_casecmp(const void *a, const void *b) 113 | { 114 | const uint8_t *aa = a; 115 | const uint8_t *bb = b; 116 | 117 | while (*aa && vct_lowertab[*aa] == vct_lowertab[*bb]) { 118 | aa++; 119 | bb++; 120 | } 121 | if (!*aa && !*bb) 122 | return (0); 123 | if (!*aa) 124 | return (-1); 125 | if (!*bb) 126 | return (1); 127 | return ((int)vct_lowertab[*aa] - (int)vct_lowertab[*bb]); 128 | } 129 | 130 | static inline int 131 | vct_caselencmp(const void *a, const void *b, ssize_t sz) 132 | { 133 | const uint8_t *aa = a; 134 | const uint8_t *bb = b; 135 | 136 | assert(sz >= 0); 137 | while (sz > 0 && *aa && vct_lowertab[*aa] == vct_lowertab[*bb]) { 138 | aa++; 139 | bb++; 140 | sz--; 141 | } 142 | if (!sz || (!*aa && !*bb)) 143 | return (0); 144 | if (!*aa) 145 | return (-1); 146 | if (!*bb) 147 | return (1); 148 | return ((int)vct_lowertab[*aa] - (int)vct_lowertab[*bb]); 149 | } 150 | -------------------------------------------------------------------------------- /src/vtc_sess.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2020 Varnish Software AS 3 | * All rights reserved. 4 | * 5 | * Author: Poul-Henning Kamp 6 | * 7 | * SPDX-License-Identifier: BSD-2-Clause 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | */ 31 | 32 | #include "config.h" 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "vtc.h" 40 | #include "vtc_http.h" 41 | 42 | struct thread_arg { 43 | unsigned magic; 44 | #define THREAD_ARG_MAGIC 0xd5dc5f1c 45 | void *priv; 46 | sess_conn_f *conn_f; 47 | sess_disc_f *disc_f; 48 | const char *listen_addr; 49 | struct vtc_sess *vsp; 50 | int *asocket; 51 | const char *spec; 52 | }; 53 | 54 | struct vtc_sess * 55 | Sess_New(struct vtclog *vl, const char *name) 56 | { 57 | struct vtc_sess *vsp; 58 | 59 | ALLOC_OBJ(vsp, VTC_SESS_MAGIC); 60 | AN(vsp); 61 | vsp->vl = vl; 62 | REPLACE(vsp->name, name); 63 | vsp->repeat = 1; 64 | return (vsp); 65 | } 66 | 67 | void 68 | Sess_Destroy(struct vtc_sess **vspp) 69 | { 70 | struct vtc_sess *vsp; 71 | 72 | TAKE_OBJ_NOTNULL(vsp, vspp, VTC_SESS_MAGIC); 73 | REPLACE(vsp->name, NULL); 74 | FREE_OBJ(vsp); 75 | } 76 | 77 | int 78 | Sess_GetOpt(struct vtc_sess *vsp, char * const **avp) 79 | { 80 | char * const *av; 81 | int rv = 0; 82 | 83 | CHECK_OBJ_NOTNULL(vsp, VTC_SESS_MAGIC); 84 | AN(avp); 85 | av = *avp; 86 | AN(*av); 87 | if (!strcmp(*av, "-rcvbuf")) { 88 | AN(av[1]); 89 | vsp->rcvbuf = atoi(av[1]); 90 | av += 1; 91 | rv = 1; 92 | } else if (!strcmp(*av, "-repeat")) { 93 | AN(av[1]); 94 | vsp->repeat = atoi(av[1]); 95 | av += 1; 96 | rv = 1; 97 | } else if (!strcmp(*av, "-keepalive")) { 98 | vsp->keepalive = 1; 99 | rv = 1; 100 | } 101 | *avp = av; 102 | return (rv); 103 | } 104 | 105 | int 106 | sess_process(struct vtclog *vl, struct vtc_sess *vsp, 107 | const char *spec, int sock, int *sfd, const char *addr) 108 | { 109 | int rv; 110 | 111 | CHECK_OBJ_NOTNULL(vsp, VTC_SESS_MAGIC); 112 | 113 | rv = http_process(vl, vsp, spec, sock, sfd, addr, vsp->rcvbuf); 114 | return (rv); 115 | } 116 | 117 | static void * 118 | sess_thread(void *priv) 119 | { 120 | struct vtclog *vl; 121 | struct vtc_sess *vsp; 122 | struct thread_arg ta, *tap; 123 | int i, fd = -1; 124 | 125 | CAST_OBJ_NOTNULL(tap, priv, THREAD_ARG_MAGIC); 126 | ta = *tap; 127 | FREE_OBJ(tap); 128 | 129 | vsp = ta.vsp; 130 | CHECK_OBJ_NOTNULL(vsp, VTC_SESS_MAGIC); 131 | vl = vtc_logopen("%s", vsp->name); 132 | pthread_cleanup_push(vtc_logclose, vl); 133 | 134 | assert(vsp->repeat > 0); 135 | vtc_log(vl, 2, "Started on %s (%u iterations%s)", ta.listen_addr, 136 | vsp->repeat, vsp->keepalive ? " using keepalive" : ""); 137 | for (i = 0; i < vsp->repeat; i++) { 138 | if (fd < 0) 139 | fd = ta.conn_f(ta.priv, vl); 140 | fd = sess_process(vl, ta.vsp, ta.spec, fd, 141 | ta.asocket, ta.listen_addr); 142 | if (! vsp->keepalive) 143 | ta.disc_f(ta.priv, vl, &fd); 144 | } 145 | if (vsp->keepalive) 146 | ta.disc_f(ta.priv, vl, &fd); 147 | vtc_log(vl, 2, "Ending"); 148 | pthread_cleanup_pop(0); 149 | vtc_logclose(vl); 150 | return (NULL); 151 | } 152 | 153 | pthread_t 154 | Sess_Start_Thread( 155 | void *priv, 156 | struct vtc_sess *vsp, 157 | sess_conn_f *conn, 158 | sess_disc_f *disc, 159 | const char *listen_addr, 160 | int *asocket, 161 | const char *spec 162 | ) 163 | { 164 | struct thread_arg *ta; 165 | pthread_t pt; 166 | 167 | AN(priv); 168 | CHECK_OBJ_NOTNULL(vsp, VTC_SESS_MAGIC); 169 | AN(conn); 170 | AN(disc); 171 | AN(listen_addr); 172 | ALLOC_OBJ(ta, THREAD_ARG_MAGIC); 173 | AN(ta); 174 | ta->priv = priv; 175 | ta->vsp = vsp; 176 | 177 | ta->conn_f = conn; 178 | ta->disc_f = disc; 179 | ta->listen_addr = listen_addr; 180 | ta->asocket = asocket; 181 | ta->spec = spec; 182 | AZ(pthread_create(&pt, NULL, sess_thread, ta)); 183 | return (pt); 184 | } 185 | -------------------------------------------------------------------------------- /src/sequences: -------------------------------------------------------------------------------- 1 | #- 2 | # Copyright (c) 2008-2009 Ed Schouten 3 | # All rights reserved. 4 | # 5 | # SPDX-License-Identifier: BSD-2-Clause 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | # SUCH DAMAGE. 27 | # 28 | # $FreeBSD: head/sys/teken/sequences 334316 2018-05-29 08:41:44Z dumbbell $ 29 | 30 | # File format is as follows: 31 | # Abbr Abbreviation of sequence name 32 | # Name Sequence name (will be converted to C function name) 33 | # Sequence Bytes that form the sequence 34 | # Args Standard value of arguments passed to this sequence 35 | # - `n' non-zero number (0 gets converted to 1) 36 | # - `r' regular numeric argument 37 | # - `v' means a variable number of arguments 38 | 39 | # Abbr Name Sequence Args 40 | CBT Cursor Backward Tabulation ^[ [ Z n 41 | CHT Cursor Forward Tabulation ^[ [ I n 42 | CNL Cursor Next Line ^[ [ E n 43 | CPL Cursor Previous Line ^[ [ F n 44 | CPR Cursor Position Report ^[ [ n r 45 | CUB Cursor Backward ^[ [ D n 46 | CUD Cursor Down ^[ [ B n 47 | CUD Cursor Down ^[ [ e n 48 | CUF Cursor Forward ^[ [ C n 49 | CUF Cursor Forward ^[ [ a n 50 | CUP Cursor Position ^[ [ H n n 51 | CUP Cursor Position ^[ [ f n n 52 | CUU Cursor Up ^[ [ A n 53 | DA1 Primary Device Attributes ^[ [ c r 54 | DA2 Secondary Device Attributes ^[ [ > c r 55 | DC Delete character ^[ [ P n 56 | DCS Device Control String ^[ P 57 | DECALN Alignment test ^[ # 8 58 | DECDHL Double Height Double Width Line Top ^[ # 3 59 | DECDHL Double Height Double Width Line Bottom ^[ # 4 60 | DECDWL Single Height Double Width Line ^[ # 6 61 | DECKPAM Keypad application mode ^[ = 62 | DECKPNM Keypad numeric mode ^[ > 63 | DECRC Restore cursor ^[ 8 64 | DECRC Restore cursor ^[ [ u 65 | DECRM Reset DEC mode ^[ [ ? l r 66 | DECSC Save cursor ^[ 7 67 | DECSC Save cursor ^[ [ s 68 | DECSCUSR Set Cursor Style ^[ [ SP q r 69 | DECSM Set DEC mode ^[ [ ? h r 70 | DECSTBM Set top and bottom margins ^[ [ r r r 71 | DECSWL Single Height Single Width Line ^[ # 5 72 | DL Delete line ^[ [ M n 73 | DSR Device Status Report ^[ [ ? n r 74 | ECH Erase character ^[ [ X n 75 | ED Erase display ^[ [ J r 76 | EL Erase line ^[ [ K r 77 | G0SCS0 G0 SCS Special Graphics ^[ ( 0 78 | G0SCS1 G0 SCS US ASCII ^[ ( 1 79 | G0SCS2 G0 SCS Special Graphics ^[ ( 2 80 | G0SCSA G0 SCS UK National ^[ ( A 81 | G0SCSB G0 SCS US ASCII ^[ ( B 82 | G1SCS0 G1 SCS Special Graphics ^[ ) 0 83 | G1SCS1 G1 SCS US ASCII ^[ ) 1 84 | G1SCS2 G1 SCS Special Graphics ^[ ) 2 85 | G1SCSA G1 SCS UK National ^[ ) A 86 | G1SCSB G1 SCS US ASCII ^[ ) B 87 | HPA Horizontal Position Absolute ^[ [ G n 88 | HPA Horizontal Position Absolute ^[ [ ` n 89 | HTS Horizontal Tab Set ^[ H 90 | ICH Insert character ^[ [ @ n 91 | IL Insert line ^[ [ L n 92 | IND Index ^[ D 93 | NEL Next line ^[ E 94 | OSC Operating System Command ^[ ] 95 | RI Reverse index ^[ M 96 | RIS Reset to Initial State ^[ c 97 | RM Reset Mode ^[ [ l r 98 | SD Pan Up ^[ [ T n 99 | SGR Set Graphic Rendition ^[ [ m v 100 | SM Set Mode ^[ [ h r 101 | ST String Terminator ^[ \\ 102 | SU Pan Down ^[ [ S n 103 | TBC Tab Clear ^[ [ g r 104 | VPA Vertical Position Absolute ^[ [ d n 105 | 106 | # Cons25 compatibility sequences 107 | C25BLPD Cons25 set bell pitch duration ^[ [ = B r r 108 | C25BORD Cons25 set border ^[ [ = A r 109 | C25DBG Cons25 set default background ^[ [ = G r 110 | C25DFG Cons25 set default foreground ^[ [ = F r 111 | C25GCS Cons25 set global cursor shape ^[ [ = C v 112 | C25LCT Cons25 set local cursor type ^[ [ = S r 113 | C25MODE Cons25 set terminal mode ^[ [ = T r 114 | C25SGR Cons25 set graphic rendition ^[ [ x r r 115 | C25VTSW Cons25 switch virtual terminal ^[ [ z r 116 | 117 | # VT52 compatibility 118 | #DECID VT52 DECID ^[ Z 119 | 120 | # ECMA-48 121 | REP Repeat last graphic char ^[ [ b n 122 | -------------------------------------------------------------------------------- /src/gensequences: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | 3 | #- 4 | # Copyright (c) 2008-2009 Ed Schouten 5 | # All rights reserved. 6 | # 7 | # SPDX-License-Identifier: BSD-2-Clause 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions 11 | # are met: 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | # SUCH DAMAGE. 29 | # 30 | # $FreeBSD: head/sys/teken/gensequences 333925 2018-05-20 14:21:20Z dumbbell $ 31 | 32 | function die(msg) { 33 | print msg; 34 | exit 1; 35 | } 36 | 37 | function cchar(str) { 38 | if (str == "^[") 39 | return "\\x1B"; 40 | if (str == "SP") 41 | return " "; 42 | 43 | return str; 44 | } 45 | 46 | function csequence(str) { 47 | if (str == "SP") 48 | return " "; 49 | 50 | return str; 51 | } 52 | 53 | BEGIN { 54 | FS = "\t+" 55 | 56 | while (getline > 0) { 57 | if (NF == 0 || $1 ~ /^#/) 58 | continue; 59 | 60 | if (NF != 3 && NF != 4) 61 | die("Invalid line layout: " NF " columns"); 62 | 63 | split($3, sequence, " +"); 64 | nsequences = 0; 65 | for (s in sequence) 66 | nsequences++; 67 | 68 | prefix = ""; 69 | l_prefix_name[""] = "teken_state_init"; 70 | for (i = 1; i < nsequences; i++) { 71 | n = prefix csequence(sequence[i]); 72 | l_prefix_parent[n] = prefix; 73 | l_prefix_suffix[n] = sequence[i]; 74 | if (!l_prefix_name[n]) 75 | l_prefix_name[n] = "teken_state_" "" ++npr; 76 | prefix = n; 77 | } 78 | 79 | suffix = sequence[nsequences]; 80 | cmd = prefix suffix; 81 | 82 | # Fill lists 83 | if (l_cmd_name[cmd] != "") 84 | die(cmd " already exists"); 85 | l_cmd_prefix[cmd] = prefix; 86 | l_cmd_suffix[cmd] = suffix; 87 | l_cmd_args[cmd] = $4; 88 | l_cmd_abbr[cmd] = $1; 89 | l_cmd_name[cmd] = $2; 90 | l_cmd_c_name[cmd] = "teken_subr_" tolower($2); 91 | gsub(" ", "_", l_cmd_c_name[cmd]); 92 | 93 | if ($4 != "") 94 | l_prefix_numbercmds[prefix]++; 95 | } 96 | 97 | print "/* Generated file. Do not edit. */"; 98 | print ""; 99 | 100 | for (p in l_prefix_name) { 101 | if (l_prefix_name[p] != "teken_state_init") 102 | print "static teken_state_t " l_prefix_name[p] ";"; 103 | } 104 | 105 | for (p in l_prefix_name) { 106 | print ""; 107 | print "/* '" p "' */"; 108 | print "static void"; 109 | print l_prefix_name[p] "(teken_t *t, teken_char_t c)"; 110 | print "{"; 111 | 112 | if (l_prefix_numbercmds[p] > 0) { 113 | print ""; 114 | print "\tif (teken_state_numbers(t, c))"; 115 | print "\t\treturn;"; 116 | } 117 | 118 | print ""; 119 | print "\tswitch (c) {"; 120 | for (c in l_cmd_prefix) { 121 | if (l_cmd_prefix[c] != p) 122 | continue; 123 | 124 | print "\tcase '" cchar(l_cmd_suffix[c]) "': /* " l_cmd_abbr[c] ": " l_cmd_name[c] " */"; 125 | 126 | if (l_cmd_args[c] == "v") { 127 | print "\t\t" l_cmd_c_name[c] "(t, t->t_curnum, t->t_nums);"; 128 | } else { 129 | printf "\t\t%s(t", l_cmd_c_name[c]; 130 | split(l_cmd_args[c], args, " "); 131 | for (a = 1; args[a] != ""; a++) { 132 | if (args[a] == "n") 133 | printf ", (t->t_curnum < %d || t->t_nums[%d] == 0) ? 1 : t->t_nums[%d]", a, (a - 1), (a - 1); 134 | else if (args[a] == "r") 135 | printf ", t->t_curnum < %d ? 0 : t->t_nums[%d]", a, (a - 1); 136 | else 137 | die("Invalid argument type: " args[a]); 138 | } 139 | print ");"; 140 | } 141 | print "\t\tbreak;"; 142 | } 143 | for (pc in l_prefix_parent) { 144 | if (l_prefix_parent[pc] != p) 145 | continue; 146 | print "\tcase '" cchar(l_prefix_suffix[pc]) "':"; 147 | print "\t\tteken_state_switch(t, " l_prefix_name[pc] ");"; 148 | print "\t\treturn;"; 149 | } 150 | 151 | print "\tdefault:"; 152 | if (l_prefix_name[p] == "teken_state_init") { 153 | print "\t\tteken_subr_regular_character(t, c);"; 154 | } else { 155 | print "\t\tteken_printf(\"Unsupported sequence in " l_prefix_name[p] ": %u\\n\", (unsigned int)c);"; 156 | } 157 | print "\t\tbreak;"; 158 | 159 | print "\t}"; 160 | 161 | if (l_prefix_name[p] != "teken_state_init") { 162 | print ""; 163 | print "\tt->t_last = 0;"; 164 | print "\tteken_state_switch(t, teken_state_init);"; 165 | } 166 | print "}"; 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /lib/vsub.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * All rights reserved. 5 | * 6 | * Author: Poul-Henning Kamp 7 | * 8 | * SPDX-License-Identifier: BSD-2-Clause 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * Run stuff in a child process 32 | */ 33 | 34 | #include "config.h" 35 | 36 | #include 37 | #include 38 | #include // Solaris closefrom(3c) 39 | #include 40 | #include 41 | #ifndef HAVE_CLOSEFROM 42 | # include 43 | #endif 44 | 45 | #include "vdef.h" 46 | 47 | #include "vsig.h" 48 | 49 | #include "vas.h" 50 | #include "vfil.h" 51 | #include "vlu.h" 52 | #include "vsb.h" 53 | #include "vsub.h" 54 | 55 | struct vsub_priv { 56 | const char *name; 57 | struct vsb *sb; 58 | int lines; 59 | int maxlines; 60 | }; 61 | 62 | void 63 | VSUB_closefrom(int fd) 64 | { 65 | 66 | assert(fd >= 0); 67 | 68 | #ifdef HAVE_CLOSEFROM 69 | closefrom(fd); 70 | return; 71 | #else 72 | char buf[128]; 73 | int i, maxfd = 0; 74 | DIR *d; 75 | struct dirent *de; 76 | char *p; 77 | 78 | bprintf(buf, "/proc/%d/fd/", getpid()); 79 | d = opendir(buf); 80 | if (d != NULL) { 81 | while (1) { 82 | de = readdir(d); 83 | if (de == NULL) 84 | break; 85 | i = strtoul(de->d_name, &p, 10); 86 | if (*p != '\0') 87 | continue; 88 | if (i > maxfd) 89 | maxfd = i; 90 | } 91 | AZ(closedir(d)); 92 | } 93 | 94 | if (maxfd == 0) 95 | maxfd = sysconf(_SC_OPEN_MAX); 96 | assert(maxfd > 0); 97 | for (; maxfd > fd; maxfd--) 98 | (void)close(maxfd); 99 | #endif 100 | } 101 | 102 | static int 103 | vsub_vlu(void *priv, const char *str) 104 | { 105 | struct vsub_priv *sp; 106 | 107 | sp = priv; 108 | if (!sp->lines++) 109 | VSB_printf(sp->sb, "Message from %s:\n", sp->name); 110 | if (sp->maxlines < 0 || sp->lines <= sp->maxlines) 111 | VSB_printf(sp->sb, "%s\n", str); 112 | return (0); 113 | } 114 | 115 | /* returns an exit code */ 116 | unsigned 117 | VSUB_run(struct vsb *sb, vsub_func_f *func, void *priv, const char *name, 118 | int maxlines) 119 | { 120 | int rv, p[2], status; 121 | pid_t pid; 122 | struct vsub_priv sp; 123 | 124 | sp.sb = sb; 125 | sp.name = name; 126 | sp.lines = 0; 127 | sp.maxlines = maxlines; 128 | 129 | if (pipe(p) < 0) { 130 | VSB_printf(sb, "Starting %s: pipe() failed: %s", 131 | name, strerror(errno)); 132 | return (1); 133 | } 134 | assert(p[0] > STDERR_FILENO); 135 | assert(p[1] > STDERR_FILENO); 136 | if ((pid = fork()) < 0) { 137 | VSB_printf(sb, "Starting %s: fork() failed: %s", 138 | name, strerror(errno)); 139 | closefd(&p[0]); 140 | closefd(&p[1]); 141 | return (1); 142 | } 143 | if (pid == 0) { 144 | VFIL_null_fd(STDIN_FILENO); 145 | assert(dup2(p[1], STDOUT_FILENO) == STDOUT_FILENO); 146 | assert(dup2(p[1], STDERR_FILENO) == STDERR_FILENO); 147 | /* Close all other fds */ 148 | VSUB_closefrom(STDERR_FILENO + 1); 149 | func(priv); 150 | /* 151 | * func should either exec or exit, so getting here should be 152 | * treated like an assertion failure - except that we don't know 153 | * if it's safe to trigger an actual assertion 154 | */ 155 | _exit(4); 156 | } 157 | closefd(&p[1]); 158 | (void)VLU_File(p[0], vsub_vlu, &sp, 0); 159 | closefd(&p[0]); 160 | if (sp.maxlines >= 0 && sp.lines > sp.maxlines) 161 | VSB_printf(sb, "[%d lines truncated]\n", 162 | sp.lines - sp.maxlines); 163 | do { 164 | rv = waitpid(pid, &status, 0); 165 | if (rv < 0 && errno != EINTR) { 166 | VSB_printf(sb, "Running %s: waitpid() failed: %s\n", 167 | name, strerror(errno)); 168 | return (1); 169 | } 170 | } while (rv < 0); 171 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { 172 | rv = -1; 173 | VSB_printf(sb, "Running %s failed", name); 174 | if (WIFEXITED(status)) { 175 | rv = WEXITSTATUS(status); 176 | VSB_printf(sb, ", exited with %d", rv); 177 | } 178 | if (WIFSIGNALED(status)) { 179 | rv = 2; 180 | VSB_printf(sb, ", signal %d", WTERMSIG(status)); 181 | } 182 | if (WCOREDUMP(status)) 183 | VSB_cat(sb, ", core dumped"); 184 | VSB_cat(sb, "\n"); 185 | assert(rv != -1); 186 | return (rv); 187 | } 188 | return (0); 189 | } 190 | -------------------------------------------------------------------------------- /tests/a00000.vtc: -------------------------------------------------------------------------------- 1 | vtest "Test vtest itself" 2 | 3 | shell -exit 1 -expect {vtest [options]} {vtest -h} 4 | 5 | shell -exit 1 -match {-D.*Define macro} {vtest -h} 6 | 7 | shell { 8 | pwd 9 | echo 'notvtest foo bar' > _.vtc 10 | echo 'shell "exit 9"' >> _.vtc 11 | } 12 | 13 | shell -exit 2 -expect {doesn't start with 'vtest' or 'varnishtes} { 14 | vtest -v _.vtc 15 | } 16 | 17 | shell -exit 77 -expect {0 tests failed, 1 tests skipped, 0 tests passed} { 18 | unset TMPDIR 19 | vtest -k _.vtc 20 | } 21 | 22 | # Test external macro-def with a a two-turtle test 23 | shell -expect {__=barf} { 24 | echo vtest foo > _.vtc 25 | printf 'shell {echo %c{foobar} > ${tmpdir}/__}' '$' >> _.vtc 26 | vtest -q -Dfoobar=barf _.vtc 27 | echo __=`cat __` 28 | } 29 | 30 | # Test a test failure 31 | shell -exit 2 -expect {TEST _.vtc FAILED} { 32 | echo vtest foo > _.vtc 33 | echo 'shell {false}' >> _.vtc 34 | exec vtest -v _.vtc || true 35 | } 36 | 37 | # Test a test skip 38 | shell -exit 77 -expect {TEST _.vtc skipped} { 39 | echo vtest foo > _.vtc 40 | echo 'feature cmd false' >> _.vtc 41 | exec vtest -v _.vtc || true 42 | } 43 | 44 | # Simple process tests 45 | 46 | process p1 "cat" -start 47 | process p1 -writeln "foo" 48 | process p1 -expect-text 2 1 foo 49 | process p1 -stop 50 | process p1 -wait 51 | shell "grep -q foo ${p1_out}" 52 | shell "test -f ${p1_err} -a ! -s ${p1_err}" 53 | 54 | process p2 -log "cat" -start 55 | process p2 -writeln "bar" 56 | process p2 -expect-text 2 1 bar 57 | process p2 -write "\x04" 58 | process p2 -wait 59 | shell "grep -q bar ${p2_out}" 60 | shell "test -f ${p2_err} -a ! -s ${p2_err}" 61 | 62 | process p3 -dump "cat" -start 63 | process p3 -writeln "baz" 64 | process p3 -expect-text 2 1 baz 65 | process p3 -kill KILL 66 | process p3 -wait 67 | shell "grep -q baz ${p3_out}" 68 | shell "test -f ${p3_err} -a ! -s ${p3_err}" 69 | 70 | process p4 -hexdump "cat" -start 71 | process p4 -writeln "b\001z" 72 | process p4 -expect-text 2 1 "b" 73 | process p4 -kill TERM 74 | process p4 -wait -screen_dump 75 | 76 | # Curses process tests 77 | 78 | process p5 "ps -lw | grep '[p][s]' ; tty ; echo @" -start 79 | process p5 -expect-text 0 0 {@} -screen_dump -wait 80 | 81 | process p6 "stty -a ; echo '*'" -start 82 | process p6 -expect-text 0 0 {*} -screen_dump -wait 83 | 84 | process p7 -hexdump {stty raw -echo; stty -a ; echo "*" ; cat} -start 85 | process p7 -expect-text 0 0 "*" -screen_dump 86 | 87 | process p7 -write "\x1b[H\x1b[2Jzzzzzzz" 88 | process p7 -write "\x0c1\x1b[79C2\x08>\x1b[25;1H3\x1b[25;80H" 89 | process p7 -write "\x1b[H\x1b[2J1\x1b[79C2\x08>\x1b[25;1H3\x1b[25;80H" 90 | process p7 -write "4\x08>\x1b[A\x1b[Cv\x1b[22A^\x1b[79D^\x1b[;2H<\n\n\n\n" 91 | process p7 -write "\n\n\n\n\n\n\n\n\x1b[B\x1b[11B\x08<\x1b[24;Hv\x1b[12;1H" 92 | process p7 -write "111111112222222333333\x0d\x0a111111112" 93 | process p7 -write "222222333333\x0d\x0a111111112222222333333 UTF8: " 94 | process p7 -writehex {c2 a2 20} 95 | process p7 -writehex {e2 82 ac 20} 96 | process p7 -writehex {f0 90 80 80 20} 97 | process p7 -writehex {f0 9f 90 b0 20} 98 | process p7 -writehex {f0 a0 80 80 20} 99 | process p7 -writehex {f0 b0 80 80 20} 100 | process p7 -write "\x1b[22;24;25;27;30;47;49;97;107m" 101 | process p7 -write "\x1b[22;24;25;27;30m" 102 | process p7 -write "\x1b[47;49;97;107m" 103 | process p7 -write "\x0d\x0a111111112222222333333\x0d\x0a\x1b[12" 104 | process p7 -write ";12H\x1b[K\x1b[13;12H\x1b[0K\x1b[14;12H\x1b[1K\x1b" 105 | process p7 -write "[15;12H\x1b[2K\x1b[3;1Hline3 <\x0d\x0a" 106 | 107 | process p7 -need-bytes 310 -expect-text 3 1 "line3 <" 108 | process p7 -expect-cursor 4 1 109 | process p7 -expect-cursor 4 0 110 | process p7 -expect-cursor 0 1 111 | process p7 -screen-dump 112 | 113 | # Also exercise CONS25 mode 114 | process p7 -write "\x1b[=1T" 115 | process p7 -write "\x1b[=2T" 116 | process p7 -write "\x1b[8z" 117 | process p7 -write "\x1b[0x" 118 | process p7 -write "\x1b[=1A" 119 | process p7 -write "\x1b[=1;2B" 120 | process p7 -write "\x1b[=1;2;3C" 121 | process p7 -write "\x1b[=1;2;3;4C" 122 | process p7 -write "\x1b[=1F" 123 | process p7 -write "\x1b[=1G" 124 | process p7 -write "\x1b[=1S" 125 | process p7 -writehex {0c 08 40 0d 0a 08} 126 | 127 | process p7 -expect-text 1 1 "@" 128 | process p7 -expect-cursor 1 80 129 | process p7 -writehex "0c 41 0e 42 0f" 130 | process p7 -expect-text 1 1 "A" 131 | process p7 -expect-text 0 0 "B" 132 | process p7 -write "\x1b[=0T" 133 | 134 | process p7 -writehex "0c 0a 0d 43 0a 08 08 0e 44 0f" 135 | 136 | process p7 -expect-text 3 1 "C" 137 | process p7 -expect-text 4 1 "D" 138 | process p7 -write "\x1b[2T" 139 | process p7 -expect-text 5 1 "C" 140 | process p7 -expect-text 6 1 "D" 141 | process p7 -write "\x1b[3S" 142 | process p7 -expect-text 3 1 "D" 143 | 144 | process p7 -write "\x1b[4;200H%" 145 | process p7 -expect-text 4 80 "%" 146 | 147 | process p7 -write "\x1b[7;7H\x09X\x09Y\x09Z\x1b[2ZW\x1b[2Ew\x1b[F*" 148 | 149 | process p7 -expect-text 7 17 "W" 150 | process p7 -expect-text 9 1 "w" 151 | process p7 -expect-text 8 1 "*" 152 | 153 | process p7 -write "\x1b[10;4HABCDEFGHIJKLMN\x1b(A#$%\x1b)A" 154 | process p7 -write "\x1b[8G\x1b[2X>" 155 | process p7 -expect-text 10 8 ">" 156 | process p7 -screen-dump 157 | 158 | # Test responses 159 | process p7 -write "\x1b[3;1HA\x1b[5n" 160 | process p7 -write "\x1b[4;1HB\x1b[6n" 161 | process p7 -write "\x1b[5;1HC\x1b[15n" 162 | process p7 -write "\x1b[6;1HD\x1b[25n" 163 | process p7 -write "\x1b[7;1HE\x1b[26n" 164 | process p7 -write "\x1b[8;1HF\x1b[?26n" 165 | process p7 -write "\x1b[9;1HG\x1bPfutfutfut\x01" 166 | process p7 -write "\x1b[10;1HH\x1b]futfutfut\x01" 167 | process p7 -write "\x1b[11;1HI\x1b[>c" 168 | process p7 -write "\x1b[24;1HW" 169 | process p7 -expect-text 24 1 "W" 170 | process p7 -screen-dump 171 | -------------------------------------------------------------------------------- /src/teken_wcwidth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Markus Kuhn -- 2007-05-26 (Unicode 5.0) 3 | * 4 | * Permission to use, copy, modify, and distribute this software 5 | * for any purpose and without fee is hereby granted. The author 6 | * disclaims all warranties with regard to this software. 7 | * 8 | * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c 9 | * 10 | * $FreeBSD: head/sys/teken/teken_wcwidth.h 332297 2018-04-08 19:23:50Z phk $ 11 | */ 12 | 13 | struct interval { 14 | teken_char_t first; 15 | teken_char_t last; 16 | }; 17 | 18 | /* auxiliary function for binary search in interval table */ 19 | static int bisearch(teken_char_t ucs, const struct interval *table, int max) { 20 | int min = 0; 21 | int mid; 22 | 23 | if (ucs < table[0].first || ucs > table[max].last) 24 | return 0; 25 | while (max >= min) { 26 | mid = (min + max) / 2; 27 | if (ucs > table[mid].last) 28 | min = mid + 1; 29 | else if (ucs < table[mid].first) 30 | max = mid - 1; 31 | else 32 | return 1; 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | static int teken_wcwidth(teken_char_t ucs) 39 | { 40 | /* sorted list of non-overlapping intervals of non-spacing characters */ 41 | /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ 42 | static const struct interval combining[] = { 43 | { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 }, 44 | { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, 45 | { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 }, 46 | { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 }, 47 | { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, 48 | { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, 49 | { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 }, 50 | { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D }, 51 | { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, 52 | { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, 53 | { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, 54 | { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, 55 | { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, 56 | { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, 57 | { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, 58 | { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D }, 59 | { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 }, 60 | { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 }, 61 | { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC }, 62 | { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, 63 | { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, 64 | { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, 65 | { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, 66 | { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, 67 | { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, 68 | { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, 69 | { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, 70 | { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, 71 | { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, 72 | { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F }, 73 | { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, 74 | { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, 75 | { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, 76 | { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, 77 | { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B }, 78 | { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 }, 79 | { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 }, 80 | { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF }, 81 | { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 }, 82 | { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F }, 83 | { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, 84 | { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, 85 | { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, 86 | { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F }, 87 | { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 }, 88 | { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, 89 | { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, 90 | { 0xE0100, 0xE01EF } 91 | }; 92 | 93 | /* test for 8-bit control characters */ 94 | if (ucs == 0) 95 | return 0; 96 | if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) 97 | return -1; 98 | 99 | /* binary search in table of non-spacing characters */ 100 | if (bisearch(ucs, combining, 101 | sizeof(combining) / sizeof(struct interval) - 1)) 102 | return 0; 103 | 104 | /* if we arrive here, ucs is not a combining or C0/C1 control character */ 105 | 106 | return 1 + 107 | (int)(ucs >= 0x1100 && 108 | (ucs <= 0x115f || /* Hangul Jamo init. consonants */ 109 | ucs == 0x2329 || ucs == 0x232a || 110 | (ucs >= 0x2e80 && ucs <= 0xa4cf && 111 | ucs != 0x303f) || /* CJK ... Yi */ 112 | (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ 113 | (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ 114 | (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ 115 | (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ 116 | (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ 117 | (ucs >= 0xffe0 && ucs <= 0xffe6) || 118 | (ucs >= 0x20000 && ucs <= 0x2fffd) || 119 | (ucs >= 0x30000 && ucs <= 0x3fffd))); 120 | } 121 | -------------------------------------------------------------------------------- /lib/vrnd.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2006 Verdens Gang AS 3 | * Copyright (c) 2006-2011 Varnish Software AS 4 | * Copyright (c) 1983, 1993 The Regents of the University of California. 5 | * All rights reserved. 6 | * 7 | * Author: Dag-Erling Smørgrav 8 | * 9 | * SPDX-License-Identifier: BSD-2-Clause 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * Partially from: $FreeBSD: head/lib/libc/stdlib/random.c 303342 33 | * 34 | */ 35 | 36 | #include "config.h" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "vdef.h" 46 | 47 | #include "vas.h" 48 | #include "vrnd.h" 49 | 50 | 51 | vrnd_lock_f *VRND_Lock; 52 | vrnd_lock_f *VRND_Unlock; 53 | 54 | /********************************************************************** 55 | * Stripped down random(3) implementation from FreeBSD, to provide 56 | * predictable "random" numbers of testing purposes. 57 | */ 58 | 59 | #define TYPE_3 3 /* x**31 + x**3 + 1 */ 60 | #define DEG_3 31 61 | #define SEP_3 3 62 | 63 | static uint32_t randtbl[DEG_3 + 1] = { 64 | TYPE_3, 65 | 0x2cf41758, 0x27bb3711, 0x4916d4d1, 0x7b02f59f, 0x9b8e28eb, 0xc0e80269, 66 | 0x696f5c16, 0x878f1ff5, 0x52d9c07f, 0x916a06cd, 0xb50b3a20, 0x2776970a, 67 | 0xee4eb2a6, 0xe94640ec, 0xb1d65612, 0x9d1ed968, 0x1043f6b7, 0xa3432a76, 68 | 0x17eacbb9, 0x3c09e2eb, 0x4f8c2b3, 0x708a1f57, 0xee341814, 0x95d0e4d2, 69 | 0xb06f216c, 0x8bd2e72e, 0x8f7c38d7, 0xcfc6a8fc, 0x2a59495, 0xa20d2a69, 70 | 0xe29d12d1 71 | }; 72 | 73 | static uint32_t *fptr = &randtbl[SEP_3 + 1]; 74 | static uint32_t *rptr = &randtbl[1]; 75 | 76 | static uint32_t * const state = &randtbl[1]; 77 | static const int rand_deg = DEG_3; 78 | static const int rand_sep = SEP_3; 79 | static const uint32_t * const end_ptr = &randtbl[DEG_3 + 1]; 80 | 81 | static inline uint32_t 82 | good_rand(uint32_t ctx) 83 | { 84 | /* 85 | * Compute x = (7^5 * x) mod (2^31 - 1) 86 | * without overflowing 31 bits: 87 | * (2^31 - 1) = 127773 * (7^5) + 2836 88 | * From "Random number generators: good ones are hard to find", 89 | * Park and Miller, Communications of the ACM, vol. 31, no. 10, 90 | * October 1988, p. 1195. 91 | */ 92 | int32_t hi, lo, x; 93 | 94 | /* Transform to [1, 0x7ffffffe] range. */ 95 | x = (ctx % 0x7ffffffe) + 1; 96 | hi = x / 127773; 97 | lo = x % 127773; 98 | x = 16807 * lo - 2836 * hi; 99 | if (x < 0) 100 | x += 0x7fffffff; 101 | /* Transform to [0, 0x7ffffffd] range. */ 102 | return (x - 1); 103 | } 104 | 105 | static long 106 | vrnd_RandomTestable(void) 107 | { 108 | uint32_t i; 109 | uint32_t *f, *r; 110 | 111 | /* 112 | * Use local variables rather than static variables for speed. 113 | */ 114 | f = fptr; r = rptr; 115 | *f += *r; 116 | i = *f >> 1; /* chucking least random bit */ 117 | if (++f >= end_ptr) { 118 | f = state; 119 | ++r; 120 | } 121 | else if (++r >= end_ptr) { 122 | r = state; 123 | } 124 | 125 | fptr = f; rptr = r; 126 | return ((long)i); 127 | } 128 | 129 | 130 | void 131 | VRND_SeedTestable(unsigned int x) 132 | { 133 | int i, lim; 134 | 135 | state[0] = (uint32_t)x; 136 | for (i = 1; i < rand_deg; i++) 137 | state[i] = good_rand(state[i - 1]); 138 | fptr = &state[rand_sep]; 139 | rptr = &state[0]; 140 | lim = 10 * rand_deg; 141 | for (i = 0; i < lim; i++) 142 | (void)vrnd_RandomTestable(); 143 | } 144 | 145 | long 146 | VRND_RandomTestable(void) 147 | { 148 | long l; 149 | 150 | AN(VRND_Lock); 151 | VRND_Lock(); 152 | l = vrnd_RandomTestable(); 153 | AN(VRND_Unlock); 154 | VRND_Unlock(); 155 | return (l); 156 | } 157 | 158 | double 159 | VRND_RandomTestableDouble(void) 160 | { 161 | return ( 162 | ldexp((double)VRND_RandomTestable(), -31) + 163 | ldexp((double)VRND_RandomTestable(), -62) 164 | ); 165 | } 166 | 167 | int 168 | VRND_RandomCrypto(void *ptr, size_t len) 169 | { 170 | int fd; 171 | char *p = ptr; 172 | ssize_t l; 173 | 174 | AN(ptr); 175 | fd = open("/dev/urandom", O_RDONLY); 176 | if (fd < 0) 177 | return (-1); 178 | while (len > 0) { 179 | l = read(fd, p, len); 180 | if (l < 0) 181 | break; 182 | p += l; 183 | len -= l; 184 | } 185 | closefd(&fd); 186 | return (len == 0 ? 0 : -1); 187 | } 188 | 189 | void 190 | VRND_SeedAll(void) 191 | { 192 | unsigned long seed; 193 | 194 | AZ(VRND_RandomCrypto(&seed, sizeof seed)); 195 | srandom(seed); 196 | AZ(VRND_RandomCrypto(&seed, sizeof seed)); 197 | VRND_SeedTestable(seed); 198 | AZ(VRND_RandomCrypto(&seed, sizeof seed)); 199 | srand48(seed); 200 | } 201 | --------------------------------------------------------------------------------