1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

Merge branch 'master' of supraverse.net:libpsyc

This commit is contained in:
Marenz 2011-05-08 22:20:16 +02:00
commit e8fb3d0b7f
5 changed files with 38 additions and 23 deletions

View file

@ -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

View file

@ -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';

View file

@ -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

View file

@ -4,8 +4,9 @@ use warnings;
use IO::Socket;
$| = 1;
print "Usage: splittest.pl <packet file> [<port> [<chunk length> [-v]]]\n" and exit unless @ARGV;
my $port = $ARGV[1] || 4440;
print "Usage: splittest.pl <packet file> [[<host>:]<port> [<chunk length> [-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 <FILE>;
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) {

View file

@ -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)