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

added flag for parsing header only

This commit is contained in:
Marenz 2011-04-17 12:56:24 +02:00
parent e197d7ee1d
commit 69ca100ed0
2 changed files with 23 additions and 6 deletions

View file

@ -1,13 +1,20 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
enum enum PSYC_Flags
{
PSYC_HEADER_ONLY = 1
};
enum PSYC_ReturnCodes
{ {
PSYC_SUCCESS = 0, PSYC_SUCCESS = 0,
PSYC_INSUFFICIENT = 1, PSYC_INSUFFICIENT = 1,
PSYC_ROUTING = 2, PSYC_ROUTING = 2,
PSYC_ENTITY = 3, PSYC_ENTITY = 3,
PSYC_COMPLETE = 4, PSYC_COMPLETE = 4,
PSYC_HEADER_COMPLETE = 5,
}; };
@ -36,6 +43,12 @@ inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length)
return arr; return arr;
} }
inline void PSYC_initState2 (PSYC_State* state, uint8_t flags )
{
memset(state, 0, sizeof(PSYC_State));
state->flags = flags;
}
inline void PSYC_initState (PSYC_State* state) inline void PSYC_initState (PSYC_State* state)
{ {
memset(state, 0, sizeof(PSYC_State)); memset(state, 0, sizeof(PSYC_State));

View file

@ -50,6 +50,7 @@ inline int PSYC_parse(
PSYC_Array* name, PSYC_Array* value, PSYC_Array* name, PSYC_Array* value,
uint8_t* modifier, unsigned long* expectedBytes) uint8_t* modifier, unsigned long* expectedBytes)
{ {
start:
/* first we test if we can access the first char */ /* first we test if we can access the first char */
if(state->buffer.length<=state->cursor) // cursor is not inside the length if(state->buffer.length<=state->cursor) // cursor is not inside the length
return PSYC_INSUFFICIENT; // return insufficient data. return PSYC_INSUFFICIENT; // return insufficient data.
@ -95,7 +96,10 @@ inline int PSYC_parse(
if(isAlphaNumeric(state->buffer.ptr[state->cursor])) if(isAlphaNumeric(state->buffer.ptr[state->cursor]))
{ {
state->inHeader = 0; state->inHeader = 0;
return 2; // return header finished if (state->flags & PSYC_HEADER_ONLY)
return PSYC_HEADER_COMPLETE; // return header finished
else
goto start;
} }
if(state->buffer.ptr[state->cursor] == '|') if(state->buffer.ptr[state->cursor] == '|')
@ -109,7 +113,7 @@ inline int PSYC_parse(
if(state->buffer.ptr[state->cursor]=='\n') if(state->buffer.ptr[state->cursor]=='\n')
{ {
++(state->cursor); ++(state->cursor);
return 3; // return packet finished return PSYC_COMPLETE; // return packet finished
} }
} }
return -6; // report error return -6; // report error
@ -150,7 +154,7 @@ inline int PSYC_parse(
if(state->buffer.ptr[state->cursor]=='\n') if(state->buffer.ptr[state->cursor]=='\n')
{ {
++(state->cursor); ++(state->cursor);
return 3; // return packet finished return PSYC_COMPLETE; // return packet finished
} }
} }
return -5; // report error return -5; // report error
@ -289,7 +293,7 @@ inline int PSYC_parse(
{ {
/* packet finishes here */ /* packet finishes here */
state->cursor+=3; state->cursor+=3;
return 3; return PSYC_COMPLETE;
} }
} }
@ -385,6 +389,6 @@ inline int PSYC_parse(
return -4; return -4;
state->cursor+=1; state->cursor+=1;
return 3; // packet is complete return PSYC_COMPLETE; // packet is complete
} }