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

revert changes in parse.c

This commit is contained in:
lurchi 2016-09-05 11:53:54 +02:00
parent 48b9e626ed
commit 2614da4953

View file

@ -119,7 +119,7 @@ psyc_parse_remaining_buffer (PsycParseState *state);
* *
* @return PARSE_ERROR or PARSE_SUCCESS * @return PARSE_ERROR or PARSE_SUCCESS
*/ */
inline ParseRC static inline ParseRC
parse_keyword (ParseState *state, PsycString *name) parse_keyword (ParseState *state, PsycString *name)
{ {
name->data = state->buffer.data + state->cursor; name->data = state->buffer.data + state->cursor;
@ -138,7 +138,7 @@ parse_keyword (ParseState *state, PsycString *name)
* *
* @return PARSE_SUCCESS, PARSE_ERROR or PARSE_INSUFFICIENT * @return PARSE_SUCCESS, PARSE_ERROR or PARSE_INSUFFICIENT
*/ */
inline ParseRC static inline ParseRC
parse_length (ParseState *state, size_t *len) parse_length (ParseState *state, size_t *len)
{ {
ParseRC ret = PARSE_ERROR; ParseRC ret = PARSE_ERROR;
@ -165,7 +165,7 @@ parse_length (ParseState *state, size_t *len)
* *
* @return PARSE_SUCCESS or PARSE_INCOMPLETE * @return PARSE_SUCCESS or PARSE_INCOMPLETE
*/ */
inline ParseRC static inline ParseRC
parse_binary (ParseState *state, size_t length, PsycString *value, size_t *parsed) parse_binary (ParseState *state, size_t length, PsycString *value, size_t *parsed)
{ {
size_t remaining = length - *parsed; size_t remaining = length - *parsed;
@ -197,7 +197,7 @@ parse_binary (ParseState *state, size_t length, PsycString *value, size_t *parse
* *
* @return PARSE_SUCCESS or PARSE_INSUFFICIENT * @return PARSE_SUCCESS or PARSE_INSUFFICIENT
*/ */
inline ParseRC static inline ParseRC
parse_until (ParseState *state, const char end, PsycString *value) parse_until (ParseState *state, const char end, PsycString *value)
{ {
value->data = state->buffer.data + state->cursor; value->data = state->buffer.data + state->cursor;
@ -282,7 +282,7 @@ psyc_parse_modifier (PsycParseState *state, char *oper,
/** Parse PSYC packets. */ /** Parse PSYC packets. */
#ifdef __INLINE_PSYC_PARSE #ifdef __INLINE_PSYC_PARSE
extern inline static inline
#endif #endif
PsycParseRC PsycParseRC
psyc_parse (PsycParseState *state, char *oper, psyc_parse (PsycParseState *state, char *oper,
@ -573,9 +573,8 @@ psyc_parse_list (PsycParseListState *state, PsycString *type, PsycString *elem)
{ {
ParseRC ret; ParseRC ret;
if (state->cursor >= state->buffer.length) { if (state->cursor >= state->buffer.length)
return PSYC_PARSE_LIST_END; return PSYC_PARSE_LIST_END;
}
state->startc = state->cursor; state->startc = state->cursor;
@ -640,7 +639,6 @@ psyc_parse_list (PsycParseListState *state, PsycString *type, PsycString *elem)
} }
break; break;
case PARSE_INSUFFICIENT: // end of buffer case PARSE_INSUFFICIENT: // end of buffer
state->cursor = state->buffer.length;
return PSYC_PARSE_LIST_ELEM_LAST; return PSYC_PARSE_LIST_ELEM_LAST;
case PARSE_ERROR: case PARSE_ERROR:
return PSYC_PARSE_LIST_ERROR_ELEM_TYPE; return PSYC_PARSE_LIST_ERROR_ELEM_TYPE;
@ -685,14 +683,12 @@ psyc_parse_list (PsycParseListState *state, PsycString *type, PsycString *elem)
switch (parse_binary((ParseState*)state, state->elemlen, elem, switch (parse_binary((ParseState*)state, state->elemlen, elem,
&state->elem_parsed)) { &state->elem_parsed)) {
case PARSE_SUCCESS: case PARSE_SUCCESS:
state->part = PSYC_LIST_PART_ELEM_START;
if (elem->length == state->elem_parsed) if (elem->length == state->elem_parsed)
ret = PSYC_PARSE_LIST_ELEM; ret = PSYC_PARSE_LIST_ELEM;
else else
ret = PSYC_PARSE_LIST_ELEM_END; ret = PSYC_PARSE_LIST_ELEM_END;
break; break;
case PARSE_INCOMPLETE: case PARSE_INCOMPLETE:
state->part = PSYC_LIST_PART_ELEM;
if (elem->length == state->elem_parsed) if (elem->length == state->elem_parsed)
ret = PSYC_PARSE_LIST_ELEM_START; ret = PSYC_PARSE_LIST_ELEM_START;
else else
@ -704,17 +700,16 @@ psyc_parse_list (PsycParseListState *state, PsycString *type, PsycString *elem)
} else { } else {
switch (parse_until((ParseState*)state, '|', elem)) { switch (parse_until((ParseState*)state, '|', elem)) {
case PARSE_SUCCESS: case PARSE_SUCCESS:
state->part = PSYC_LIST_PART_ELEM_START;
ret = PSYC_PARSE_LIST_ELEM; ret = PSYC_PARSE_LIST_ELEM;
break; break;
case PARSE_INSUFFICIENT: case PARSE_INSUFFICIENT:
state->cursor = state->buffer.length;
return PSYC_PARSE_LIST_ELEM_LAST; return PSYC_PARSE_LIST_ELEM_LAST;
default: // should not be reached default: // should not be reached
return PSYC_PARSE_LIST_ERROR; return PSYC_PARSE_LIST_ERROR;
} }
} }
state->part = PSYC_LIST_PART_ELEM_START;
state->startc = state->cursor; state->startc = state->cursor;
return ret; return ret;
} }
@ -878,7 +873,6 @@ psyc_parse_dict (PsycParseDictState *state, PsycString *type, PsycString *elem)
} }
break; break;
case PARSE_INSUFFICIENT: // end of buffer case PARSE_INSUFFICIENT: // end of buffer
//state->cursor = state->buffer.length;
return PSYC_PARSE_DICT_VALUE_LAST; return PSYC_PARSE_DICT_VALUE_LAST;
case PARSE_ERROR: case PARSE_ERROR:
return PSYC_PARSE_DICT_ERROR_VALUE_TYPE; return PSYC_PARSE_DICT_ERROR_VALUE_TYPE;
@ -923,7 +917,6 @@ psyc_parse_dict (PsycParseDictState *state, PsycString *type, PsycString *elem)
switch (parse_binary((ParseState*)state, state->elemlen, elem, switch (parse_binary((ParseState*)state, state->elemlen, elem,
&state->elem_parsed)) { &state->elem_parsed)) {
case PARSE_SUCCESS: case PARSE_SUCCESS:
state->part = PSYC_DICT_PART_KEY_START;
if (elem->length == state->elem_parsed) if (elem->length == state->elem_parsed)
ret = PSYC_PARSE_DICT_VALUE; ret = PSYC_PARSE_DICT_VALUE;
else else
@ -941,17 +934,16 @@ psyc_parse_dict (PsycParseDictState *state, PsycString *type, PsycString *elem)
} else { } else {
switch (parse_until((ParseState*)state, '{', elem)) { switch (parse_until((ParseState*)state, '{', elem)) {
case PARSE_SUCCESS: case PARSE_SUCCESS:
state->part = PSYC_DICT_PART_KEY_START;
ret = PSYC_PARSE_DICT_VALUE; ret = PSYC_PARSE_DICT_VALUE;
break; break;
case PARSE_INSUFFICIENT: case PARSE_INSUFFICIENT:
state->cursor = state->buffer.length;
return PSYC_PARSE_DICT_VALUE_LAST; return PSYC_PARSE_DICT_VALUE_LAST;
default: // should not be reached default: // should not be reached
return PSYC_PARSE_DICT_ERROR; return PSYC_PARSE_DICT_ERROR;
} }
} }
state->part = PSYC_DICT_PART_KEY_START;
return ret; return ret;
} }
@ -1094,9 +1086,8 @@ psyc_parse_update (PsycParseUpdateState *state, char *oper, PsycString *value)
{ {
PsycParseIndexRC ret; PsycParseIndexRC ret;
if (state->cursor >= state->buffer.length) { if (state->cursor >= state->buffer.length)
return PSYC_PARSE_UPDATE_END; return PSYC_PARSE_UPDATE_END;
}
state->startc = state->cursor; state->startc = state->cursor;