mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
parser: more detailed return codes for incomplete values
This commit is contained in:
parent
7a5d751477
commit
84ef512168
3 changed files with 40 additions and 18 deletions
|
@ -56,21 +56,27 @@ typedef enum
|
||||||
PSYC_PARSE_ENTITY = 3,
|
PSYC_PARSE_ENTITY = 3,
|
||||||
/// Entity modifier parsing is incomplete.
|
/// Entity modifier parsing is incomplete.
|
||||||
/// Operator & name are complete, value is incomplete.
|
/// Operator & name are complete, value is incomplete.
|
||||||
PSYC_PARSE_ENTITY_INCOMPLETE = 4,
|
PSYC_PARSE_ENTITY_START = 4,
|
||||||
|
PSYC_PARSE_ENTITY_CONT = 5,
|
||||||
|
PSYC_PARSE_ENTITY_END = 6,
|
||||||
/// Body parsing done, name contains method, value contains body.
|
/// Body parsing done, name contains method, value contains body.
|
||||||
PSYC_PARSE_BODY = 5,
|
PSYC_PARSE_BODY = 7,
|
||||||
/// Body parsing is incomplete, name contains method, value contains part of the body.
|
/// Body parsing is incomplete, name contains method, value contains part of the body.
|
||||||
PSYC_PARSE_BODY_INCOMPLETE = 6,
|
PSYC_PARSE_BODY_START = 8,
|
||||||
|
PSYC_PARSE_BODY_CONT = 9,
|
||||||
|
PSYC_PARSE_BODY_END = 10,
|
||||||
/// Content parsing done, value contains the whole content.
|
/// Content parsing done, value contains the whole content.
|
||||||
/// Used when PSYC_PARSE_ROUTING_ONLY is set.
|
/// Used when PSYC_PARSE_ROUTING_ONLY is set.
|
||||||
PSYC_PARSE_CONTENT = 5,
|
PSYC_PARSE_CONTENT = 7,
|
||||||
/// Content parsing is incomplete, value contains part of content.
|
/// Content parsing is incomplete, value contains part of content.
|
||||||
/// Used when PSYC_PARSE_ROUTING_ONLY is set.
|
/// Used when PSYC_PARSE_ROUTING_ONLY is set.
|
||||||
PSYC_PARSE_CONTENT_INCOMPLETE = 6,
|
PSYC_PARSE_CONTENT_START = 8,
|
||||||
|
PSYC_PARSE_CONTENT_CONT = 9,
|
||||||
|
PSYC_PARSE_CONTENT_END = 10,
|
||||||
/// Reached end of packet, parsing done.
|
/// Reached end of packet, parsing done.
|
||||||
PSYC_PARSE_COMPLETE = 7,
|
PSYC_PARSE_COMPLETE = 11,
|
||||||
/// Binary value parsing incomplete, used internally.
|
/// Binary value parsing incomplete, used internally.
|
||||||
PSYC_PARSE_INCOMPLETE = 8,
|
PSYC_PARSE_INCOMPLETE = 12,
|
||||||
} psycParseRC;
|
} psycParseRC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
10
src/parser.c
10
src/parser.c
|
@ -305,9 +305,9 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||||
state->contentParsed += value->length;
|
state->contentParsed += value->length;
|
||||||
|
|
||||||
if (ret == PSYC_PARSE_INCOMPLETE)
|
if (ret == PSYC_PARSE_INCOMPLETE)
|
||||||
return PSYC_PARSE_ENTITY_INCOMPLETE;
|
return PSYC_PARSE_ENTITY_CONT;
|
||||||
|
|
||||||
return PSYC_PARSE_ENTITY;
|
return PSYC_PARSE_ENTITY_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = state->cursor;
|
pos = state->cursor;
|
||||||
|
@ -330,7 +330,7 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||||
state->contentParsed += state->cursor - pos;
|
state->contentParsed += state->cursor - pos;
|
||||||
|
|
||||||
if (ret == PSYC_PARSE_INCOMPLETE)
|
if (ret == PSYC_PARSE_INCOMPLETE)
|
||||||
return PSYC_PARSE_ENTITY_INCOMPLETE;
|
return PSYC_PARSE_ENTITY_START;
|
||||||
else if (ret == PSYC_PARSE_SUCCESS)
|
else if (ret == PSYC_PARSE_SUCCESS)
|
||||||
return PSYC_PARSE_ENTITY;
|
return PSYC_PARSE_ENTITY;
|
||||||
|
|
||||||
|
@ -400,11 +400,11 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||||
state->contentParsed += value->length;
|
state->contentParsed += value->length;
|
||||||
|
|
||||||
if (ret == PSYC_PARSE_INCOMPLETE)
|
if (ret == PSYC_PARSE_INCOMPLETE)
|
||||||
return PSYC_PARSE_BODY_INCOMPLETE;
|
return state->valueParsed == value->length ? PSYC_PARSE_BODY_START : PSYC_PARSE_BODY_CONT;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->part = PSYC_PART_END;
|
state->part = PSYC_PART_END;
|
||||||
return PSYC_PARSE_BODY;
|
return state->valueLength == value->length ? PSYC_PARSE_BODY : PSYC_PARSE_BODY_END;
|
||||||
}
|
}
|
||||||
else // Search for the terminator.
|
else // Search for the terminator.
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,6 +103,7 @@ int main (int argc, char **argv)
|
||||||
psycString name, value, elem;
|
psycString name, value, elem;
|
||||||
psycString *pname = NULL, *pvalue = NULL;
|
psycString *pname = NULL, *pvalue = NULL;
|
||||||
psycParseListState listState;
|
psycParseListState listState;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
FD_ZERO(&master); // clear the master and temp sets
|
FD_ZERO(&master); // clear the master and temp sets
|
||||||
FD_ZERO(&read_fds);
|
FD_ZERO(&read_fds);
|
||||||
|
@ -256,14 +257,16 @@ int main (int argc, char **argv)
|
||||||
packets[i].routing.lines++;
|
packets[i].routing.lines++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSYC_PARSE_ENTITY_INCOMPLETE:
|
case PSYC_PARSE_ENTITY_START:
|
||||||
|
case PSYC_PARSE_ENTITY_CONT:
|
||||||
|
case PSYC_PARSE_ENTITY_END:
|
||||||
case PSYC_PARSE_ENTITY:
|
case PSYC_PARSE_ENTITY:
|
||||||
assert(packets[i].entity.lines < ENTITY_LINES);
|
assert(packets[i].entity.lines < ENTITY_LINES);
|
||||||
mod = &(packets[i].entity.modifiers[packets[i].entity.lines]);
|
mod = &(packets[i].entity.modifiers[packets[i].entity.lines]);
|
||||||
pname = &mod->name;
|
pname = &mod->name;
|
||||||
pvalue = &mod->value;
|
pvalue = &mod->value;
|
||||||
|
|
||||||
if (ret == PSYC_PARSE_ENTITY)
|
if (ret == PSYC_PARSE_ENTITY || ret == PSYC_PARSE_ENTITY_END)
|
||||||
{
|
{
|
||||||
packets[i].entity.lines++;
|
packets[i].entity.lines++;
|
||||||
mod->flag = psyc_isParseValueLengthFound(&parsers[i]) ?
|
mod->flag = psyc_isParseValueLengthFound(&parsers[i]) ?
|
||||||
|
@ -271,7 +274,9 @@ int main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSYC_PARSE_BODY_INCOMPLETE:
|
case PSYC_PARSE_BODY_START:
|
||||||
|
case PSYC_PARSE_BODY_CONT:
|
||||||
|
case PSYC_PARSE_BODY_END:
|
||||||
case PSYC_PARSE_BODY:
|
case PSYC_PARSE_BODY:
|
||||||
pname = &(packets[i].method);
|
pname = &(packets[i].method);
|
||||||
pvalue = &(packets[i].data);
|
pvalue = &(packets[i].data);
|
||||||
|
@ -363,12 +368,16 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
case PSYC_PARSE_ENTITY_INCOMPLETE:
|
case PSYC_PARSE_ENTITY_START:
|
||||||
case PSYC_PARSE_BODY_INCOMPLETE:
|
case PSYC_PARSE_ENTITY_CONT:
|
||||||
|
case PSYC_PARSE_BODY_START:
|
||||||
|
case PSYC_PARSE_BODY_CONT:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
case PSYC_PARSE_ENTITY:
|
case PSYC_PARSE_ENTITY:
|
||||||
|
case PSYC_PARSE_ENTITY_END:
|
||||||
case PSYC_PARSE_ROUTING:
|
case PSYC_PARSE_ROUTING:
|
||||||
case PSYC_PARSE_BODY:
|
case PSYC_PARSE_BODY:
|
||||||
|
case PSYC_PARSE_BODY_END:
|
||||||
if (oper)
|
if (oper)
|
||||||
{
|
{
|
||||||
mod->oper = oper;
|
mod->oper = oper;
|
||||||
|
@ -391,7 +400,13 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
if (value.length) {
|
if (value.length) {
|
||||||
if (!pvalue->length)
|
if (!pvalue->length)
|
||||||
pvalue->ptr = malloc(parsers[i].valueLength ? parsers[i].valueLength : value.length);
|
{
|
||||||
|
if (psyc_isParseValueLengthFound(&parsers[i]))
|
||||||
|
len = psyc_getParseValueLength(&parsers[i]);
|
||||||
|
else
|
||||||
|
len = value.length;
|
||||||
|
pvalue->ptr = malloc(len);
|
||||||
|
}
|
||||||
assert(pvalue->ptr != NULL);
|
assert(pvalue->ptr != NULL);
|
||||||
memcpy((void*)pvalue->ptr + pvalue->length, value.ptr, value.length);
|
memcpy((void*)pvalue->ptr + pvalue->length, value.ptr, value.length);
|
||||||
pvalue->length += value.length;
|
pvalue->length += value.length;
|
||||||
|
@ -418,6 +433,7 @@ int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
case PSYC_PARSE_ROUTING:
|
case PSYC_PARSE_ROUTING:
|
||||||
case PSYC_PARSE_ENTITY:
|
case PSYC_PARSE_ENTITY:
|
||||||
|
case PSYC_PARSE_ENTITY_END:
|
||||||
if (pname->length >= 5 && memcmp(pname->ptr, "_list", 5) == 0)
|
if (pname->length >= 5 && memcmp(pname->ptr, "_list", 5) == 0)
|
||||||
{
|
{
|
||||||
if (verbose >= 2)
|
if (verbose >= 2)
|
||||||
|
|
Loading…
Reference in a new issue