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

parser: fixes for partial packets

This commit is contained in:
tg(x) 2011-04-29 16:00:48 +02:00
parent 508661cc55
commit 8abc3c85e9

View file

@ -189,7 +189,8 @@ inline psycParseRC psyc_parseModifier(psycParseState* state, char* oper, psycStr
if (state->buffer.ptr[state->cursor] != '\t') if (state->buffer.ptr[state->cursor] != '\t')
return PSYC_PARSE_ERROR_MOD_TAB; return PSYC_PARSE_ERROR_MOD_TAB;
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INCOMPLETE); if (++(state->cursor) >= state->buffer.length)
return PSYC_PARSE_INCOMPLETE;
ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)); ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
if (ret == PSYC_PARSE_INCOMPLETE) if (ret == PSYC_PARSE_INCOMPLETE)
@ -264,6 +265,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
else // not a glyph else // not a glyph
{ {
state->part = PSYC_PART_LENGTH; state->part = PSYC_PART_LENGTH;
state->startc = state->cursor;
// fall thru // fall thru
} }
@ -300,8 +302,8 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
goto PSYC_PART_END; goto PSYC_PART_END;
} }
state->startc = state->cursor + 1;
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
state->startc = state->cursor;
// fall thru // fall thru
case PSYC_PART_CONTENT: case PSYC_PART_CONTENT:
@ -365,12 +367,12 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
{ // if length was found set start position to the beginning of data { // if length was found set start position to the beginning of data
state->cursor++; state->cursor++;
state->startc = state->cursor; state->startc = state->cursor;
state->contentParsed += state->cursor - pos;
state->part = PSYC_PART_DATA; state->part = PSYC_PART_DATA;
} }
else // otherwise keep it at the beginning of method else // otherwise keep it at the beginning of method
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
state->contentParsed += state->cursor - pos;
// fall thru // fall thru
} }
else // No method, which means the packet should end now. else // No method, which means the packet should end now.
@ -418,6 +420,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
if (state->buffer.ptr[state->cursor+nl] == '|' && if (state->buffer.ptr[state->cursor+nl] == '|' &&
state->buffer.ptr[state->cursor+1+nl] == '\n') // packet ends here state->buffer.ptr[state->cursor+1+nl] == '\n') // packet ends here
{ {
state->contentParsed += state->cursor - pos;
state->cursor += nl; state->cursor += nl;
state->part = PSYC_PART_END; state->part = PSYC_PART_END;
return PSYC_PARSE_BODY; return PSYC_PARSE_BODY;