mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
parser: renamed flags, testServer: added routing only option
This commit is contained in:
parent
8488c39ce1
commit
1315363410
5 changed files with 23 additions and 12 deletions
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue