mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
parser: fixes for header only parsing
This commit is contained in:
parent
6107757c2e
commit
357f0f6de4
3 changed files with 19 additions and 8 deletions
|
@ -24,7 +24,7 @@ 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_BEGIN_AT_CONTENT = 2,
|
||||
} psycParseFlag;
|
||||
|
||||
/**
|
||||
|
|
12
src/parser.c
12
src/parser.c
|
@ -136,10 +136,6 @@ inline psycParseRC psyc_parseName(psycParseState* state, psycString* name)
|
|||
*/
|
||||
inline psycParseRC psyc_parseBinaryValue(psycParseState* state, psycString* value, size_t* length, size_t* parsed)
|
||||
{
|
||||
if (state->flags & PSYC_PARSE_HEADER_ONLY &&
|
||||
state->flags & PSYC_PARSE_BEGIN_AT_CONTENT)
|
||||
return PSYC_PARSE_ERROR_INVALID_FLAGS;
|
||||
|
||||
size_t remaining = *length - *parsed;
|
||||
value->ptr = state->buffer.ptr + state->cursor;
|
||||
|
||||
|
@ -300,8 +296,13 @@ 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 && state->contentLengthFound)
|
||||
if (state->flags & PSYC_PARSE_HEADER_ONLY)
|
||||
{
|
||||
state->part = PSYC_PART_DATA;
|
||||
if (++(state->cursor) >= state->buffer.length)
|
||||
return PSYC_PARSE_INSUFFICIENT;
|
||||
goto PSYC_PART_DATA;
|
||||
}
|
||||
else
|
||||
state->part = PSYC_PART_CONTENT;
|
||||
}
|
||||
|
@ -397,6 +398,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
|
|||
}
|
||||
|
||||
case PSYC_PART_DATA:
|
||||
PSYC_PART_DATA:
|
||||
value->ptr = state->buffer.ptr + state->cursor;
|
||||
value->length = 0;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int idx, ret, verbose = argc > 2;
|
||||
int idx, ret, header_only = argc > 2, verbose = argc > 3;
|
||||
char buffer[2048], oper;
|
||||
psycString name, value, elem;
|
||||
psycParseState state;
|
||||
|
@ -23,14 +23,23 @@ int main(int argc, char **argv)
|
|||
write(1, buffer, idx);
|
||||
write(1, ">> PARSE\n", 9);
|
||||
}
|
||||
psyc_initParseState(&state);
|
||||
if (header_only)
|
||||
psyc_initParseState2(&state, PSYC_PARSE_HEADER_ONLY);
|
||||
else
|
||||
psyc_initParseState(&state);
|
||||
psyc_nextParseBuffer(&state, psyc_newString(buffer, idx));
|
||||
|
||||
// try parsing that now
|
||||
// while ((ret = psyc_parse(&state, &oper, &name, &value)))
|
||||
// {
|
||||
do {
|
||||
oper = 0;
|
||||
name.length = 0;
|
||||
value.length = 0;
|
||||
|
||||
ret = psyc_parse(&state, &oper, &name, &value);
|
||||
if (verbose)
|
||||
printf(">> ret = %d\n", ret);
|
||||
switch (ret)
|
||||
{
|
||||
case PSYC_PARSE_ROUTING:
|
||||
|
|
Loading…
Reference in a new issue