From 90dadedc79efcff22df4b019550add03e31ec3a9 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Sun, 8 May 2011 16:49:24 +0200 Subject: [PATCH 1/5] makefile --- test/Makefile | 10 ++++++---- test/testServer.c | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Makefile b/test/Makefile index 0ead41e..e4965f5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,16 +2,18 @@ OPT = -O2 DEBUG = 2 CFLAGS = -I../include -Wall -std=c99 ${OPT} LDFLAGS = -L../lib +LOADLIBES = -lpsyc -lm +LOADLIBES_NET = ${LOADLIBES} TARGETS = testServer testParser testMatch testRender testText isRoutingVar getVarType WRAPPER = DIET = diet PORT = 4440 +NC = nc +DIFF = diff -LOADLIBES = -lpsyc -lm ifeq ($(shell uname),SunOS) - LOADLIBES_NET = ${LOADLIBES} -lsocket -lnsl -else - LOADLIBES_NET = ${LOADLIBES} + LOADLIBES_NET := ${LOADLIBES_NET} -lsocket -lnsl + DIFF = gdiff endif all: ${TARGETS} diff --git a/test/testServer.c b/test/testServer.c index 41b6da7..255d425 100644 --- a/test/testServer.c +++ b/test/testServer.c @@ -434,6 +434,10 @@ int main (int argc, char **argv) case PSYC_PARSE_ROUTING: case PSYC_PARSE_ENTITY: case PSYC_PARSE_ENTITY_END: + oper = 0; + name.length = 0; + value.length = 0; + if (pname->length >= 5 && memcmp(pname->ptr, "_list", 5) == 0) { if (verbose >= 2) From 00e319d8f433411a3141b8164a99e8378f3cff45 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Sun, 8 May 2011 16:50:14 +0200 Subject: [PATCH 2/5] makefile --- test/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index e4965f5..dc6767f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -47,10 +47,10 @@ nettest: srvstart pkt pktsplit srvkill nettestr: srvstartr pkt pktsplit srvkill pkt: - for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | diff -u $$f -; done + for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | ${DIFF} -u $$f -; done pktsplit: - for f in packets/[0-9]*; do echo ">> $$f"; ./splittest.pl $$f ${PORT} | diff -u $$f -; done + for f in packets/[0-9]*; do echo ">> $$f"; ./splittest.pl $$f ${PORT} | ${DIFF} -u $$f -; done pkterr: for f in packets/err-*; do echo ">> $$f"; cat $$f | nc localhost ${PORT}; done From 527eebe7f5f019270af6a9ccd40551d550b20711 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Sun, 8 May 2011 18:45:41 +0200 Subject: [PATCH 3/5] splittest fix --- test/splittest.pl | 8 ++++---- test/testServer.c | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/splittest.pl b/test/splittest.pl index 9794390..f467b67 100755 --- a/test/splittest.pl +++ b/test/splittest.pl @@ -4,8 +4,9 @@ use warnings; use IO::Socket; $| = 1; -print "Usage: splittest.pl [ [ [-v]]]\n" and exit unless @ARGV; -my $port = $ARGV[1] || 4440; +print "Usage: splittest.pl [[:] [ [-v]]]\n" and exit unless @ARGV; +my ($host, $port) = $ARGV[1] =~ /^(?:([a-z0-9.-]+):)?(\d+)$/i; +$host ||= 'localhost'; $port ||= 4440; my $length = int($ARGV[2] || 1); $length = 1 if $length < 1; my $verbose = $ARGV[3]; @@ -13,8 +14,7 @@ open FILE, '<', $ARGV[0] or die "$ARGV[0]: $!\n"; my $file = ''; $file .= $_ while ; close FILE; -my $s = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localhost", PeerPort => $port) or die "localhost:$port: $!\n"; -$s->autoflush(1); +my $s = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $host, PeerPort => $port) or die "$host:$port: $!\n"; my $c = 0; while ($c < length $file) { diff --git a/test/testServer.c b/test/testServer.c index 255d425..4d15d68 100644 --- a/test/testServer.c +++ b/test/testServer.c @@ -233,6 +233,11 @@ int main (int argc, char **argv) } else { + if (verbose >= 2) + printf("> %ld bytes\n", nbytes); + if (verbose >= 3) + printf("> [%.*s]", (int)nbytes, recvbuf); + // we got some data from a client parsebuf = recvbuf - contbytes; psyc_setParseBuffer2(&parsers[i], parsebuf, contbytes + nbytes); From a7b3b225300d4f16882376125e02c969c0f3b6e7 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Sun, 8 May 2011 20:17:56 +0200 Subject: [PATCH 4/5] test: makefile improvements --- Makefile | 4 +--- test/Makefile | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 5cb0938..c3343d6 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,7 @@ testdebug: debug ${MAKE} -C test debug test: all - ${MAKE} -C test test - ${MAKE} -C test nettest - ${MAKE} -C test nettestr + ${MAKE} -C test test nettest doc: doxygen diff --git a/test/Makefile b/test/Makefile index dc6767f..722ab38 100644 --- a/test/Makefile +++ b/test/Makefile @@ -37,29 +37,32 @@ test: ${TARGETS} ./testText ./isRoutingVar ./getVarType - for f in packets/[0-9]*; do echo ">> $$f"; ./testParser $$f; done - for f in packets/[0-9]*; do echo ">> $$f"; ./testParser $$f -r; done + x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testParser $$f; x=$$((x+$$?)); done; exit $$x + x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testParser $$f -r; x=$$((x+$$?)); done; exit $$x -# test packet parsing & rendering with the test server -nettest: srvstart pkt pktsplit srvkill +nettest: nettestfull nettestsplit -# same test but parse routing headers only -nettestr: srvstartr pkt pktsplit srvkill +nettestrun: srvstart pkt srvkill + +nettestfull: + ${MAKE} nettestrun + ${MAKE} nettestrun srv_args=r + +nettestsplit: + for n in 1 2 3 4 5; do ${MAKE} nettestrun srv_recvbuf=$$n && ${MAKE} nettestrun srv_args=r srv_recvbuf=$$n || exit $$?; done pkt: - for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | ${DIFF} -u $$f -; done + x=0; for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x pktsplit: - for f in packets/[0-9]*; do echo ">> $$f"; ./splittest.pl $$f ${PORT} | ${DIFF} -u $$f -; done + x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./splittest.pl $$f ${PORT} | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x pkterr: for f in packets/err-*; do echo ">> $$f"; cat $$f | nc localhost ${PORT}; done srvstart: - ./testServer ${PORT} & - -srvstartr: - ./testServer ${PORT} -r & + pkill -x testServer; exit 0 + ./testServer ${PORT} -${srv_args} ${srv_recvbuf} & srvkill: pkill -x testServer From 1bed39e5d6c8bf2ab9546d3653bd638e374e4049 Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Sun, 8 May 2011 22:08:48 +0200 Subject: [PATCH 5/5] parser: fix for partial content in routing-only mode --- src/parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/parser.c b/src/parser.c index 575a546..4e50dce 100644 --- a/src/parser.c +++ b/src/parser.c @@ -409,6 +409,9 @@ psycParseRC psyc_parse (psycParseState *state, char *oper, else // Search for the terminator. { size_t datac = state->cursor; // start of data + if (state->flags & PSYC_PARSE_ROUTING_ONLY) + state->startc = datac; // in routing-only mode restart from the start of data + while (1) { uint8_t nl = state->buffer.ptr[state->cursor] == '\n';