diff --git a/include/psyc/parser.h b/include/psyc/parser.h index bff444d..984ae84 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -21,6 +21,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, @@ -32,6 +33,8 @@ typedef enum */ typedef enum { + /// Invalid combination of flags + PSYC_PARSE_ERROR_INVALID_FLAGS = -10, PSYC_PARSE_ERROR_END = -9, PSYC_PARSE_ERROR_BODY = -8, PSYC_PARSE_ERROR_METHOD = -7, diff --git a/src/parser.c b/src/parser.c index bb92526..6e84964 100644 --- a/src/parser.c +++ b/src/parser.c @@ -136,6 +136,10 @@ 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;