mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
some typedef renames
This commit is contained in:
parent
2efca8dc96
commit
44950099a1
3 changed files with 24 additions and 24 deletions
|
@ -22,7 +22,7 @@
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
PSYC_HEADER_ONLY = 1,
|
PSYC_HEADER_ONLY = 1,
|
||||||
} PSYC_Flag;
|
} PSYC_ParserFlag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The return value definitions for the packet parsing function.
|
* The return value definitions for the packet parsing function.
|
||||||
|
@ -59,7 +59,7 @@ typedef enum
|
||||||
PSYC_COMPLETE = 7,
|
PSYC_COMPLETE = 7,
|
||||||
/// Binary value parsing incomplete, used internally.
|
/// Binary value parsing incomplete, used internally.
|
||||||
PSYC_INCOMPLETE = 8,
|
PSYC_INCOMPLETE = 8,
|
||||||
} PSYC_ReturnCode;
|
} PSYC_ParseRC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The return value definitions for the list parsing function.
|
* The return value definitions for the list parsing function.
|
||||||
|
@ -78,7 +78,7 @@ typedef enum
|
||||||
PSYC_LIST_END = 2,
|
PSYC_LIST_END = 2,
|
||||||
/// Binary list is incomplete.
|
/// Binary list is incomplete.
|
||||||
PSYC_LIST_INCOMPLETE = 3,
|
PSYC_LIST_INCOMPLETE = 3,
|
||||||
} PSYC_ListReturnCode;
|
} PSYC_ListRC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PSYC packet parts.
|
* PSYC packet parts.
|
||||||
|
@ -108,7 +108,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
size_t length;
|
size_t length;
|
||||||
const uint8_t * ptr; // just an unsigned char for opaque data
|
const uint8_t * ptr; // just an unsigned char for opaque data
|
||||||
} PSYC_Array;
|
} PSYC_Array; // to be renamed or solved differently..
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Struct for keeping parser state.
|
* Struct for keeping parser state.
|
||||||
|
@ -118,7 +118,7 @@ typedef struct
|
||||||
size_t cursor; ///< current position in buffer
|
size_t cursor; ///< current position in buffer
|
||||||
size_t startc; ///< position where the parsing would be resumed
|
size_t startc; ///< position where the parsing would be resumed
|
||||||
PSYC_Array buffer;
|
PSYC_Array buffer;
|
||||||
uint8_t flags; ///< flags for the parser, see PSYC_Flag
|
uint8_t flags; ///< flags for the parser, see PSYC_ParserFlag
|
||||||
PSYC_Part part; ///< part of the packet being parsed currently
|
PSYC_Part part; ///< part of the packet being parsed currently
|
||||||
|
|
||||||
size_t contentParsed; ///< number of bytes parsed from the content so far
|
size_t contentParsed; ///< number of bytes parsed from the content so far
|
||||||
|
@ -126,7 +126,7 @@ typedef struct
|
||||||
PSYC_Bool contentLengthFound; ///< is there a length given for this packet?
|
PSYC_Bool contentLengthFound; ///< is there a length given for this packet?
|
||||||
size_t valueParsed; ///< number of bytes parsed from the value so far
|
size_t valueParsed; ///< number of bytes parsed from the value so far
|
||||||
size_t valueLength; ///< expected length of the value
|
size_t valueLength; ///< expected length of the value
|
||||||
} PSYC_State;
|
} PSYC_ParserState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Struct for keeping list parser state.
|
* Struct for keeping list parser state.
|
||||||
|
@ -161,11 +161,11 @@ inline PSYC_Array PSYC_createArray (uint8_t* const memory, size_t length)
|
||||||
* Initiates the state struct with flags.
|
* Initiates the state struct with flags.
|
||||||
*
|
*
|
||||||
* @param state Pointer to the state struct that should be initiated.
|
* @param state Pointer to the state struct that should be initiated.
|
||||||
* @param flags Flags to be set for the parser, see PSYC_Flag.
|
* @param flags Flags to be set for the parser, see PSYC_ParserFlag.
|
||||||
*/
|
*/
|
||||||
inline void PSYC_initState2 (PSYC_State* state, uint8_t flags )
|
inline void PSYC_initState2 (PSYC_ParserState* state, uint8_t flags )
|
||||||
{
|
{
|
||||||
memset(state, 0, sizeof(PSYC_State));
|
memset(state, 0, sizeof(PSYC_ParserState));
|
||||||
state->flags = flags;
|
state->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,9 +174,9 @@ inline void PSYC_initState2 (PSYC_State* state, uint8_t flags )
|
||||||
*
|
*
|
||||||
* @param state Pointer to the state struct that should be initiated.
|
* @param state Pointer to the state struct that should be initiated.
|
||||||
*/
|
*/
|
||||||
inline void PSYC_initState (PSYC_State* state)
|
inline void PSYC_initState (PSYC_ParserState* state)
|
||||||
{
|
{
|
||||||
memset(state, 0, sizeof(PSYC_State));
|
memset(state, 0, sizeof(PSYC_ParserState));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +189,7 @@ inline void PSYC_initListState (PSYC_ListState* state)
|
||||||
memset(state, 0, sizeof(PSYC_ListState));
|
memset(state, 0, sizeof(PSYC_ListState));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PSYC_nextBuffer (PSYC_State* state, PSYC_Array newBuf)
|
inline void PSYC_nextBuffer (PSYC_ParserState* state, PSYC_Array newBuf)
|
||||||
{
|
{
|
||||||
state->buffer = newBuf;
|
state->buffer = newBuf;
|
||||||
state->cursor = 0;
|
state->cursor = 0;
|
||||||
|
@ -201,7 +201,7 @@ inline void PSYC_nextListBuffer (PSYC_ListState* state, PSYC_Array newBuf)
|
||||||
state->cursor = 0;
|
state->cursor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t PSYC_getContentLength (PSYC_State* s)
|
inline size_t PSYC_getContentLength (PSYC_ParserState* s)
|
||||||
{
|
{
|
||||||
return s->contentLength;
|
return s->contentLength;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ inline size_t PSYC_getContentLength (PSYC_State* s)
|
||||||
*
|
*
|
||||||
* Generalized line-based packet parser.
|
* Generalized line-based packet parser.
|
||||||
*
|
*
|
||||||
* @param state An initialized PSYC_State
|
* @param state An initialized PSYC_ParserState
|
||||||
* @param modifier A pointer to a character. In case of a variable, it will
|
* @param modifier A pointer to a character. In case of a variable, it will
|
||||||
* be set to the modifier of that variable
|
* be set to the modifier of that variable
|
||||||
* @param name A pointer to a PSYC_Array. It will point to the name of
|
* @param name A pointer to a PSYC_Array. It will point to the name of
|
||||||
|
@ -221,12 +221,12 @@ inline size_t PSYC_getContentLength (PSYC_State* s)
|
||||||
* @param value A pointer to a PSYC_Array. It will point to the
|
* @param value A pointer to a PSYC_Array. It will point to the
|
||||||
* value/body the variable/method and its length will be set accordingly
|
* value/body the variable/method and its length will be set accordingly
|
||||||
*/
|
*/
|
||||||
PSYC_ReturnCode PSYC_parse(PSYC_State* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
|
PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List value parser.
|
* List value parser.
|
||||||
*/
|
*/
|
||||||
PSYC_ListReturnCode PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
|
PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
|
||||||
|
|
||||||
#endif // PSYC_PARSER_H
|
#endif // PSYC_PARSER_H
|
||||||
|
|
||||||
|
|
14
src/parser.c
14
src/parser.c
|
@ -68,7 +68,7 @@ inline char isKwChar(uint8_t c)
|
||||||
* It should contain one or more keyword characters.
|
* It should contain one or more keyword characters.
|
||||||
* @return PSYC_ERROR or PSYC_SUCCESS
|
* @return PSYC_ERROR or PSYC_SUCCESS
|
||||||
*/
|
*/
|
||||||
inline PSYC_ReturnCode PSYC_parseName(PSYC_State* state, PSYC_Array* name)
|
inline PSYC_ParseRC PSYC_parseName(PSYC_ParserState* state, PSYC_Array* name)
|
||||||
{
|
{
|
||||||
name->ptr = state->buffer.ptr + state->cursor;
|
name->ptr = state->buffer.ptr + state->cursor;
|
||||||
name->length = 0;
|
name->length = 0;
|
||||||
|
@ -92,7 +92,7 @@ inline PSYC_ReturnCode PSYC_parseName(PSYC_State* state, PSYC_Array* name)
|
||||||
*
|
*
|
||||||
* @return PSYC_COMPLETE or PSYC_INCOMPLETE
|
* @return PSYC_COMPLETE or PSYC_INCOMPLETE
|
||||||
*/
|
*/
|
||||||
inline PSYC_ReturnCode PSYC_parseBinaryValue(PSYC_State* state, PSYC_Array* value, size_t* length, size_t* parsed)
|
inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParserState* state, PSYC_Array* value, size_t* length, size_t* parsed)
|
||||||
{
|
{
|
||||||
size_t remaining = *length - *parsed;
|
size_t remaining = *length - *parsed;
|
||||||
value->ptr = state->buffer.ptr + state->cursor;
|
value->ptr = state->buffer.ptr + state->cursor;
|
||||||
|
@ -115,7 +115,7 @@ inline PSYC_ReturnCode PSYC_parseBinaryValue(PSYC_State* state, PSYC_Array* valu
|
||||||
* Parse simple or binary variable.
|
* Parse simple or binary variable.
|
||||||
* @return PSYC_ERROR or PSYC_SUCCESS
|
* @return PSYC_ERROR or PSYC_SUCCESS
|
||||||
*/
|
*/
|
||||||
inline PSYC_ReturnCode PSYC_parseVar(PSYC_State* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
inline PSYC_ParseRC PSYC_parseVar(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||||
{
|
{
|
||||||
*modifier = *(state->buffer.ptr + state->cursor);
|
*modifier = *(state->buffer.ptr + state->cursor);
|
||||||
ADVANCE_CURSOR_OR_RETURN(PSYC_INSUFFICIENT);
|
ADVANCE_CURSOR_OR_RETURN(PSYC_INSUFFICIENT);
|
||||||
|
@ -179,7 +179,7 @@ inline PSYC_ReturnCode PSYC_parseVar(PSYC_State* state, uint8_t* modifier, PSYC_
|
||||||
* Parse PSYC packets.
|
* Parse PSYC packets.
|
||||||
* Generalized line-based parser.
|
* Generalized line-based parser.
|
||||||
*/
|
*/
|
||||||
PSYC_ReturnCode PSYC_parse(PSYC_State* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
|
||||||
{
|
{
|
||||||
int ret; // a return value
|
int ret; // a return value
|
||||||
size_t pos; // a cursor position
|
size_t pos; // a cursor position
|
||||||
|
@ -367,9 +367,9 @@ PSYC_ReturnCode PSYC_parse(PSYC_State* state, uint8_t* modifier, PSYC_Array* nam
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List value parser.
|
* List value parser.
|
||||||
* @return see PSYC_ListReturnCodes.
|
* @return see PSYC_ListRC.
|
||||||
*/
|
*/
|
||||||
PSYC_ListReturnCode PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
|
PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
|
||||||
{
|
{
|
||||||
if (state->cursor >= state->buffer.length)
|
if (state->cursor >= state->buffer.length)
|
||||||
return PSYC_LIST_INCOMPLETE;
|
return PSYC_LIST_INCOMPLETE;
|
||||||
|
@ -440,7 +440,7 @@ PSYC_ListReturnCode PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC
|
||||||
// Start or resume parsing the binary data
|
// Start or resume parsing the binary data
|
||||||
if (state->elemParsed < state->elemLength)
|
if (state->elemParsed < state->elemLength)
|
||||||
{
|
{
|
||||||
if (PSYC_parseBinaryValue((PSYC_State*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
|
if (PSYC_parseBinaryValue((PSYC_ParserState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
|
||||||
return PSYC_LIST_INCOMPLETE;
|
return PSYC_LIST_INCOMPLETE;
|
||||||
|
|
||||||
state->elemLength = 0;
|
state->elemLength = 0;
|
||||||
|
|
|
@ -8,7 +8,7 @@ int main(int argc, char** argv)
|
||||||
int index, ret;
|
int index, ret;
|
||||||
uint8_t buffer[2048], modifier;
|
uint8_t buffer[2048], modifier;
|
||||||
PSYC_Array name, value, elem;
|
PSYC_Array name, value, elem;
|
||||||
PSYC_State state;
|
PSYC_ParserState state;
|
||||||
PSYC_ListState listState;
|
PSYC_ListState listState;
|
||||||
|
|
||||||
int file = open(argv[1],O_RDONLY);
|
int file = open(argv[1],O_RDONLY);
|
||||||
|
|
Loading…
Reference in a new issue