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/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'; diff --git a/test/Makefile b/test/Makefile index 0ead41e..722ab38 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} @@ -35,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 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 41b6da7..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); @@ -434,6 +439,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)