mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
new style: psyc_functions, psycTypes, PSYC_MACROS
This commit is contained in:
parent
7dc8effab6
commit
e48a6ab1eb
15 changed files with 204 additions and 203 deletions
|
@ -28,7 +28,7 @@ typedef enum
|
|||
{
|
||||
PSYC_FALSE = 0,
|
||||
PSYC_TRUE = 1,
|
||||
} PSYC_Bool;
|
||||
} psycBool;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
|
@ -42,7 +42,7 @@ typedef enum
|
|||
PSYC_PART_METHOD,
|
||||
PSYC_PART_DATA,
|
||||
PSYC_PART_END,
|
||||
} PSYC_Part;
|
||||
} psycPart;
|
||||
|
||||
/**
|
||||
* Different types that a variable can have.
|
||||
|
@ -67,7 +67,7 @@ typedef enum
|
|||
PSYC_TYPE_PAGE,
|
||||
PSYC_TYPE_UNIFORM,
|
||||
PSYC_TYPE_TIME,
|
||||
} PSYC_Type;
|
||||
} psycType;
|
||||
|
||||
/**
|
||||
* List types.
|
||||
|
@ -77,7 +77,7 @@ typedef enum
|
|||
{
|
||||
PSYC_LIST_TEXT = 1,
|
||||
PSYC_LIST_BINARY = 2,
|
||||
} PSYC_ListType;
|
||||
} psycListType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -85,30 +85,30 @@ typedef enum
|
|||
PSYC_MODIFIER_NEED_LENGTH = 1,
|
||||
PSYC_MODIFIER_NO_LENGTH = 2,
|
||||
PSYC_MODIFIER_ROUTING = 3,
|
||||
} PSYC_ModifierFlag;
|
||||
} psycModifierFlag;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_PACKET_CHECK_LENGTH = 0,
|
||||
PSYC_PACKET_NEED_LENGTH = 1,
|
||||
PSYC_PACKET_NO_LENGTH = 2,
|
||||
} PSYC_PacketFlag;
|
||||
} psycPacketFlag;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t length;
|
||||
const char *ptr;
|
||||
} PSYC_String;
|
||||
} psycString;
|
||||
|
||||
/**
|
||||
* Shortcut for creating a PSYC_String.
|
||||
* Shortcut for creating a psycString.
|
||||
*
|
||||
* @param memory Pointer to the buffer.
|
||||
* @param length Length of that buffer.
|
||||
*
|
||||
* @return An instance of the PSYC_String struct.
|
||||
* @return An instance of the psycString struct.
|
||||
*/
|
||||
inline PSYC_String PSYC_newString (const char *str, size_t strlen);
|
||||
inline psycString psyc_newString (const char *str, size_t strlen);
|
||||
|
||||
#define PSYC_C2STR(string) {sizeof(string)-1, string}
|
||||
#define PSYC_C2ARG(string) string, sizeof(string)-1
|
||||
|
@ -117,88 +117,88 @@ inline PSYC_String PSYC_newString (const char *str, size_t strlen);
|
|||
typedef struct
|
||||
{
|
||||
char oper; // not call it 'operator' as C++ may not like that..
|
||||
PSYC_String name;
|
||||
PSYC_String value;
|
||||
PSYC_ModifierFlag flag;
|
||||
} PSYC_Modifier;
|
||||
psycString name;
|
||||
psycString value;
|
||||
psycModifierFlag flag;
|
||||
} psycModifier;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t lines;
|
||||
PSYC_Modifier *modifiers;
|
||||
} PSYC_ModifierArray;
|
||||
psycModifier *modifiers;
|
||||
} psycModifierArray;
|
||||
|
||||
/* intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
PSYC_ModifierArray routing; ///< Routing header.
|
||||
PSYC_ModifierArray entity; ///< Entitiy header.
|
||||
PSYC_String method;
|
||||
PSYC_String data;
|
||||
psycModifierArray routing; ///< Routing header.
|
||||
psycModifierArray entity; ///< Entitiy header.
|
||||
psycString method;
|
||||
psycString data;
|
||||
size_t routingLength; ///< Length of routing part.
|
||||
size_t contentLength; ///< Length of content part.
|
||||
size_t length; ///< Total length of packet.
|
||||
PSYC_PacketFlag flag;
|
||||
} PSYC_Packet;
|
||||
psycPacketFlag flag;
|
||||
} psycPacket;
|
||||
|
||||
inline int PSYC_version();
|
||||
inline int psyc_version();
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier(char oper, PSYC_String *name, PSYC_String *value,
|
||||
PSYC_ModifierFlag flag);
|
||||
inline psycModifier psyc_newModifier(char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag);
|
||||
|
||||
inline PSYC_Modifier PSYC_newModifier2(char oper,
|
||||
inline psycModifier psyc_newModifier2(char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
PSYC_ModifierFlag flag);
|
||||
psycModifierFlag flag);
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket(PSYC_ModifierArray *routing,
|
||||
PSYC_ModifierArray *entity,
|
||||
PSYC_String *method, PSYC_String *data,
|
||||
PSYC_PacketFlag flag);
|
||||
inline psycPacket psyc_newPacket(psycModifierArray *routing,
|
||||
psycModifierArray *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag);
|
||||
|
||||
inline PSYC_Packet PSYC_newPacket2(PSYC_Modifier *routing, size_t routinglen,
|
||||
PSYC_Modifier *entity, size_t entitylen,
|
||||
inline psycPacket psyc_newPacket2(psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
const char *method, size_t methodlen,
|
||||
const char *data, size_t datalen,
|
||||
PSYC_PacketFlag flag);
|
||||
psycPacketFlag flag);
|
||||
|
||||
/// Routing vars in alphabetical order.
|
||||
extern const PSYC_String PSYC_routingVars[];
|
||||
extern const psycString PSYC_routingVars[];
|
||||
/// Number of routing vars.
|
||||
extern const size_t PSYC_routingVarsNum;
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Bool PSYC_isRoutingVar(const char *name, size_t len);
|
||||
psycBool psyc_isRoutingVar(const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
PSYC_Type PSYC_getVarType(char *name, size_t len);
|
||||
psycType psyc_getVarType(char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
int PSYC_inherits(char *sho, size_t slen,
|
||||
int psyc_inherits(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Checks if short keyword string matches long keyword string.
|
||||
*/
|
||||
int PSYC_matches(char *sho, size_t slen,
|
||||
int psyc_matches(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Callback for PSYC_text() that produces a value for a match.
|
||||
* Callback for psyc_text() that produces a value for a match.
|
||||
*
|
||||
* The application looks up a match such as _fruit from [_fruit] and
|
||||
* if found writes its current value from its variable store into the
|
||||
* outgoing buffer.. "Apple" for example. The template returns the
|
||||
* number of bytes written. 0 is a legal return value. Should the
|
||||
* callback return -1, PSYC_text leaves the original template text as is.
|
||||
* callback return -1, psyc_text leaves the original template text as is.
|
||||
*/
|
||||
typedef int (*PSYC_textCB)(uint8_t *match, size_t mlen,
|
||||
typedef int (*psyctextCB)(uint8_t *match, size_t mlen,
|
||||
uint8_t **buffer, size_t *blen);
|
||||
|
||||
/**
|
||||
|
@ -214,9 +214,9 @@ typedef int (*PSYC_textCB)(uint8_t *match, size_t mlen,
|
|||
*
|
||||
* See also http://about.psyc.eu/psyctext
|
||||
*/
|
||||
int PSYC_text(uint8_t *template, size_t tlen,
|
||||
int psyc_text(uint8_t *template, size_t tlen,
|
||||
uint8_t **buffer, size_t *blen,
|
||||
PSYC_textCB lookupValue,
|
||||
psyctextCB lookupValue,
|
||||
char *braceOpen, char *braceClose);
|
||||
|
||||
#endif // PSYC_H
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
typedef enum
|
||||
{
|
||||
PSYC_PARSE_HEADER_ONLY = 1,
|
||||
} PSYC_ParseFlag;
|
||||
} psycParseFlag;
|
||||
|
||||
/**
|
||||
* The return value definitions for the packet parsing function.
|
||||
* @see PSYC_parse()
|
||||
* @see psyc_parse()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -59,11 +59,11 @@ typedef enum
|
|||
PSYC_PARSE_COMPLETE = 7,
|
||||
/// Binary value parsing incomplete, used internally.
|
||||
PSYC_PARSE_INCOMPLETE = 8,
|
||||
} PSYC_ParseRC;
|
||||
} psycParseRC;
|
||||
|
||||
/**
|
||||
* The return value definitions for the list parsing function.
|
||||
* @see PSYC_parseList()
|
||||
* @see psyc_parseList()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ typedef enum
|
|||
PSYC_PARSE_LIST_END = 2,
|
||||
/// Binary list is incomplete.
|
||||
PSYC_PARSE_LIST_INCOMPLETE = 3,
|
||||
} PSYC_ParseListRC;
|
||||
} psycParseListRC;
|
||||
|
||||
/**
|
||||
* Struct for keeping parser state.
|
||||
|
@ -87,16 +87,16 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t startc; ///< position where the parsing would be resumed
|
||||
PSYC_String buffer; ///< buffer with data to be parsed
|
||||
uint8_t flags; ///< flags for the parser, see PSYC_ParseFlag
|
||||
PSYC_Part part; ///< part of the packet being parsed currently
|
||||
psycString buffer; ///< buffer with data to be parsed
|
||||
uint8_t flags; ///< flags for the parser, see psycParseFlag
|
||||
psycPart part; ///< part of the packet being parsed currently
|
||||
|
||||
size_t contentParsed; ///< number of bytes parsed from the content so far
|
||||
size_t contentLength; ///< expected length of the content
|
||||
PSYC_Bool contentLengthFound; ///< is there a length given for this packet?
|
||||
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
|
||||
} PSYC_ParseState;
|
||||
} psycParseState;
|
||||
|
||||
/**
|
||||
* Struct for keeping list parser state.
|
||||
|
@ -105,60 +105,60 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t startc; ///< line start position
|
||||
PSYC_String buffer;
|
||||
PSYC_ListType type; ///< list type
|
||||
psycString buffer;
|
||||
psycListType type; ///< list type
|
||||
|
||||
size_t elemParsed; ///< number of bytes parsed from the elem so far
|
||||
size_t elemLength; ///< expected length of the elem
|
||||
} PSYC_ParseListState;
|
||||
} psycParseListState;
|
||||
|
||||
/**
|
||||
* Initiates the state struct.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initParseState (PSYC_ParseState* state);
|
||||
inline void psyc_initParseState (psycParseState* state);
|
||||
|
||||
/**
|
||||
* Initiates the state struct with flags.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initiated.
|
||||
* @param flags Flags to be set for the parser, see PSYC_ParseFlag.
|
||||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||
*/
|
||||
inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags);
|
||||
inline void psyc_initParseState2 (psycParseState* state, uint8_t flags);
|
||||
|
||||
/**
|
||||
* Initiates the list state struct.
|
||||
*
|
||||
* @param state Pointer to the list state struct that should be initiated.
|
||||
*/
|
||||
inline void PSYC_initParseListState (PSYC_ParseListState* state);
|
||||
inline void psyc_initParseListState (psycParseListState* state);
|
||||
|
||||
inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_String newBuf);
|
||||
inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf);
|
||||
|
||||
inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_String newBuf);
|
||||
inline void psyc_nextParseListBuffer (psycParseListState* state, psycString newBuf);
|
||||
|
||||
inline size_t PSYC_getContentLength (PSYC_ParseState* s);
|
||||
inline size_t psyc_getContentLength (psycParseState* s);
|
||||
|
||||
/**
|
||||
* Parse PSYC packets.
|
||||
*
|
||||
* Generalized line-based packet parser.
|
||||
*
|
||||
* @param state An initialized PSYC_ParseState
|
||||
* @param state An initialized psycParseState
|
||||
* @param operator A pointer to a character. In case of a variable, it will
|
||||
* be set to the operator of that variable
|
||||
* @param name A pointer to a PSYC_String. It will point to the name of
|
||||
* @param name A pointer to a psycString. It will point to the name of
|
||||
* the variable or method and its length will be set accordingly
|
||||
* @param value A pointer to a PSYC_String. It will point to the
|
||||
* @param value A pointer to a psycString. It will point to the
|
||||
* value/body the variable/method and its length will be set accordingly
|
||||
*/
|
||||
PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_String* name, PSYC_String* value);
|
||||
psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psycString* value);
|
||||
|
||||
/**
|
||||
* List value parser.
|
||||
*/
|
||||
PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_String *name, PSYC_String* value, PSYC_String* elem);
|
||||
psycParseListRC psyc_parseList(psycParseListState* state, psycString *name, psycString* value, psycString* elem);
|
||||
|
||||
#endif // PSYC_PARSER_H
|
||||
|
||||
|
|
|
@ -17,19 +17,19 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Return codes for PSYC_render.
|
||||
* Return codes for psyc_render.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
//PSYC_RENDER_ERROR_ROUTING = -2,
|
||||
PSYC_RENDER_ERROR = -1,
|
||||
PSYC_RENDER_SUCCESS = 0,
|
||||
} PSYC_RenderRC;
|
||||
} psycRenderRC;
|
||||
|
||||
/**
|
||||
* Render a PSYC packet into a buffer.
|
||||
*/
|
||||
PSYC_RenderRC PSYC_render(PSYC_Packet *packet, char *buffer, size_t buflen);
|
||||
psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen);
|
||||
|
||||
/*
|
||||
typedef enum
|
||||
|
@ -38,7 +38,7 @@ typedef enum
|
|||
PSYC_RENDER_NEED_LENGTH = 1,
|
||||
PSYC_RENDER_NO_LENGTH = 2,
|
||||
PSYC_RENDER_ROUTING = 3,
|
||||
} PSYC_RenderFlag;
|
||||
} psycRenderFlag;
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -47,14 +47,14 @@ typedef enum
|
|||
/*
|
||||
typedef struct
|
||||
{
|
||||
PSYC_RenderFlag flag; ///< flags for the renderer
|
||||
PSYC_Part part; ///< part of the packet being rendered
|
||||
psycRenderFlag flag; ///< flags for the renderer
|
||||
psycPart part; ///< part of the packet being rendered
|
||||
size_t cursor; ///< current position in buffer
|
||||
size_t spot; ///< space for rendered length between the headers
|
||||
size_t contentLength; ///< length of the content part
|
||||
size_t length; ///< how big is the buffer we allocated
|
||||
char buffer[]; ///< OMG a C99 feature! variable size buffer!
|
||||
} PSYC_RenderState;
|
||||
} psycRenderState;
|
||||
*/
|
||||
/**
|
||||
* Initiates the state struct.
|
||||
|
@ -62,14 +62,14 @@ typedef struct
|
|||
* @param state Pointer to the state struct that should be initiated.
|
||||
*/
|
||||
/*
|
||||
inline void PSYC_initRenderState (PSYC_RenderState* state);
|
||||
inline void psyc_initRenderState (psycRenderState* state);
|
||||
|
||||
int PSYC_renderModifier(PSYC_RenderState* render,
|
||||
int psyc_renderModifier(psycRenderState* render,
|
||||
const char* name, size_t nlength,
|
||||
const char* value, size_t vlength,
|
||||
PSYC_RenderFlag flags, char oper);
|
||||
psycRenderFlag flags, char oper);
|
||||
|
||||
int PSYC_renderBody(PSYC_RenderState* render,
|
||||
int psyc_renderBody(psycRenderState* render,
|
||||
const char* method, size_t mlength,
|
||||
const char* data, size_t dlength);
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue