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

tests & fix for 0 length modifier value

This commit is contained in:
tg(x) 2011-05-04 17:59:51 +02:00
parent e7a4df6180
commit c4340bae9f
6 changed files with 25 additions and 2 deletions

View file

@ -109,6 +109,7 @@ typedef struct
psycBool contentLengthFound; ///< is there a length given for this packet?
size_t valueParsed; ///< number of bytes parsed from the value so far
size_t valueLength; ///< expected length of the value
psycBool valueLengthFound; ///< is there a length given for this modifier?
} psycParseState;
/**
@ -231,6 +232,12 @@ size_t psyc_getParseValueLength (psycParseState *state)
return state->valueLength;
}
static inline
psycBool psyc_isParseValueLengthFound (psycParseState *state)
{
return state->valueLengthFound;
}
static inline
size_t psyc_getParseCursor (psycParseState *state)
{

View file

@ -75,7 +75,7 @@ size_t psyc_getModifierLength (psycModifier *m)
m->name.length + 1 + // name\t
m->value.length + 1; // value\n
if (m->flag == PSYC_MODIFIER_NEED_LENGTH && m->value.length) // add length of length if needed
if (m->flag == PSYC_MODIFIER_NEED_LENGTH) // add length of length if needed
length += psyc_getNumLength(m->value.length) + 1; // SP length
return length;

View file

@ -140,6 +140,7 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
size_t length = 0;
value->length = 0;
state->valueLength = 0;
state->valueLengthFound = 0;
state->valueParsed = 0;
// Parse the value.
@ -150,6 +151,7 @@ psycParseRC psyc_parseModifier (psycParseState *state, char *oper,
if (isNumeric(state->buffer.ptr[state->cursor]))
{
state->valueLengthFound = 1;
do
{
length = 10 * length + state->buffer.ptr[state->cursor] - '0';

View file

@ -0,0 +1,7 @@
:_source psyc://foo.example.com/
:_target psyc://bar.example.com/
:_foo 0
_message_private
OHAI
|

7
test/packets/00-no-value Normal file
View file

@ -0,0 +1,7 @@
:_source psyc://foo.example.com/
:_target psyc://bar.example.com/
:_foo
_message_private
OHAI
|

View file

@ -234,7 +234,7 @@ int main (int argc, char **argv)
if (ret == PSYC_PARSE_ENTITY)
{
packets[i].entity.lines++;
mod->flag = psyc_getParseValueLength(&parsers[i]) ?
mod->flag = psyc_isParseValueLengthFound(&parsers[i]) ?
PSYC_MODIFIER_NEED_LENGTH : PSYC_MODIFIER_NO_LENGTH;
}
break;