From a2aca6a698de965d8f19581fb3c9b04c6457f57c Mon Sep 17 00:00:00 2001 From: Marenz Date: Sat, 20 Feb 2010 23:06:33 +0100 Subject: [PATCH] proper handling of method and data --- src/parser.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/parser.c b/src/parser.c index e7bb231..72d398e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -289,16 +289,23 @@ inline int PSYC_parseElement( * for the method: after the \n data follows, * which is anything but \n|\n * + * but data is optional, so we first check + * here if data follows at all. + * * arg-data=*value. we set value here so it * points to a valid range and so we point * to the first potential arg-data byte. * If there is no arg-data, we still have * the length attribute on 0. */ - if(method == 0 && data[*cursor] == '\n') // emptyvar + if((method == 0 && data[*cursor] == '\n') /* emptyvar */ || + (method == 1 && *cursor+2 < dlength && + data[*cursor+1] == '|' && + data[*cursor+2] == '\n') /*no data */ ) { *value=data+*cursor; *vlength=0; - }else + } + else { *value=data+*cursor+1; if(1== complete) // we know the length of the packet @@ -318,23 +325,26 @@ inline int PSYC_parseElement( if(0 == method && data[*cursor] == '\n') break; - if(1 == method && data[*cursor] == '|') + if(1 == method && data[*cursor] == '\n') { - if(dlength<=++(*cursor)) // incremented cursor inside lenght? + if(dlength<=(*cursor)+2) // incremented cursor inside lenght? { *cursor=startc; // set to start value return 1; // return insufficient } - /* packet finishes here */ - if(data[*cursor] == '\n') - { - *cursor+=1; - return 3; - } + if(data[*cursor+1] == '|') + if(data[*cursor+2] == '\n') + { + /* packet finishes here */ + *cursor+=3; + return 3; + } + } ++(*vlength); - }} + } + } } }else if(inHeader == 0 && method==0 && data[*cursor] == ' ') // oi, its a binary var! { // after SP the length follows.