From 13153634106771e049c71730f07e6b6b79a9ee65 Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Sat, 30 Apr 2011 17:07:01 +0200 Subject: [PATCH] parser: renamed flags, testServer: added routing only option --- include/psyc/parser.h | 6 +++--- src/parser.c | 8 ++++---- test/Makefile | 6 ++++++ test/testParser.c | 6 +++--- test/testServer.c | 9 +++++++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/psyc/parser.h b/include/psyc/parser.h index bcd4579..bc17948 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -22,9 +22,9 @@ typedef enum { /// Parse only the header - PSYC_PARSE_HEADER_ONLY = 1, - /// Expects only the content part of a packet. The length of the content must fit exactly in this case - PSYC_PARSE_BEGIN_AT_CONTENT = 2, + PSYC_PARSE_ROUTING_ONLY = 1, + /// Expects only the content part of a packet. The buffer should contain the whole content in this case. + PSYC_PARSE_START_AT_CONTENT = 2, } psycParseFlag; /** diff --git a/src/parser.c b/src/parser.c index 9157f3b..ffebd44 100644 --- a/src/parser.c +++ b/src/parser.c @@ -25,7 +25,7 @@ inline void psyc_initParseState2 (psycParseState* state, uint8_t flags) memset(state, 0, sizeof(psycParseState)); state->flags = flags; - if (flags & PSYC_PARSE_BEGIN_AT_CONTENT) + if (flags & PSYC_PARSE_START_AT_CONTENT) state->part = PSYC_PART_CONTENT; } @@ -36,7 +36,7 @@ inline void psyc_initParseListState (psycParseListState* state) inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf) { - if (state->flags & PSYC_PARSE_BEGIN_AT_CONTENT) + if (state->flags & PSYC_PARSE_START_AT_CONTENT) { state->contentLength = newBuf.length; state->contentLengthFound = PSYC_TRUE; @@ -231,7 +231,7 @@ inline psycParseRC psyc_parseModifier(psycParseState* state, char* oper, psycStr psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psycString* value) { #ifdef DEBUG - if (state->flags & PSYC_PARSE_HEADER_ONLY && state->flags & PSYC_PARSE_BEGIN_AT_CONTENT) + if (state->flags & PSYC_PARSE_ROUTING_ONLY && state->flags & PSYC_PARSE_START_AT_CONTENT) PP(("Invalid flag combination")) #endif @@ -301,7 +301,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc { // If we need to parse the header only and we know the content length, // then skip content parsing. - if (state->flags & PSYC_PARSE_HEADER_ONLY) + if (state->flags & PSYC_PARSE_ROUTING_ONLY) { state->part = PSYC_PART_DATA; if (++(state->cursor) >= state->buffer.length) diff --git a/test/Makefile b/test/Makefile index 482dd7e..c7d8813 100644 --- a/test/Makefile +++ b/test/Makefile @@ -27,9 +27,15 @@ test: ${TARGETS} netstart: ./testServer ${PORT} +netstartr: + ./testServer ${PORT} -r + netstartv: ./testServer ${PORT} -v +netstartrv: + ./testServer ${PORT} -r -v + nettest: for f in packets/full-*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | diff -u $$f -; done diff --git a/test/testParser.c b/test/testParser.c index 662ba77..c589851 100644 --- a/test/testParser.c +++ b/test/testParser.c @@ -7,7 +7,7 @@ int main(int argc, char **argv) { - int idx, ret, header_only = argc > 2, verbose = argc > 3; + int idx, ret, routing_only = argc > 2, verbose = argc > 3; char buffer[2048], oper; psycString name, value, elem; psycParseState state; @@ -23,8 +23,8 @@ int main(int argc, char **argv) write(1, buffer, idx); write(1, ">> PARSE\n", 9); } - if (header_only) - psyc_initParseState2(&state, PSYC_PARSE_HEADER_ONLY); + if (routing_only) + psyc_initParseState2(&state, PSYC_PARSE_ROUTING_ONLY); else psyc_initParseState(&state); psyc_nextParseBuffer(&state, psyc_newString(buffer, idx)); diff --git a/test/testServer.c b/test/testServer.c index 4cb9088..7c5dd8d 100644 --- a/test/testServer.c +++ b/test/testServer.c @@ -43,7 +43,7 @@ void *get_in_addr(struct sockaddr *sa) int main(int argc, char **argv) { char *port = argc > 1 ? argv[1] : "4440"; - uint8_t verbose = argc > 2; + uint8_t routing_only = argc > 2, verbose = argc > 3; fd_set master; // master file descriptor list fd_set read_fds; // temp file descriptor list for select() @@ -157,7 +157,10 @@ int main(int argc, char **argv) } // reset parser state & packet - psyc_initParseState(&parsers[newfd]); + if (routing_only) + psyc_initParseState2(&parsers[newfd], PSYC_PARSE_ROUTING_ONLY); + else + psyc_initParseState(&parsers[newfd]); memset(&packets[newfd], 0, sizeof(psycPacket)); memset(&routing[newfd], 0, sizeof(psycModifier) * ROUTING_LINES); memset(&entity[newfd], 0, sizeof(psycModifier) * ENTITY_LINES); @@ -193,6 +196,8 @@ int main(int argc, char **argv) do { ret = psyc_parse(&parsers[i], &oper, &name, &value); + if (verbose) + printf("# ret = %d\n", ret); switch (ret) { case PSYC_PARSE_ROUTING: assert(packets[i].routing.lines < ROUTING_LINES);