mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
refactoring - renamed types
This commit is contained in:
parent
1713e08576
commit
baed20aed8
23 changed files with 257 additions and 257 deletions
|
@ -35,7 +35,7 @@ typedef enum
|
|||
PSYC_TRUE = 1,
|
||||
PSYC_NO = 0,
|
||||
PSYC_YES = 1,
|
||||
} psycBool;
|
||||
} PsycBool;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
|
@ -49,7 +49,7 @@ typedef enum
|
|||
PSYC_PART_METHOD = 3,
|
||||
PSYC_PART_DATA = 4,
|
||||
PSYC_PART_END = 5,
|
||||
} psycPart;
|
||||
} PsycPart;
|
||||
|
||||
/**
|
||||
* Different types that a variable can have.
|
||||
|
@ -74,7 +74,7 @@ typedef enum
|
|||
PSYC_TYPE_PAGE,
|
||||
PSYC_TYPE_UNIFORM,
|
||||
PSYC_TYPE_TIME,
|
||||
} psycType;
|
||||
} PsycType;
|
||||
|
||||
/**
|
||||
* List types.
|
||||
|
@ -84,7 +84,7 @@ typedef enum
|
|||
{
|
||||
PSYC_LIST_TEXT = 1,
|
||||
PSYC_LIST_BINARY = 2,
|
||||
} psycListType;
|
||||
} PsycListType;
|
||||
|
||||
/**
|
||||
* String struct.
|
||||
|
@ -97,26 +97,26 @@ typedef struct
|
|||
size_t length;
|
||||
/// pointer to the data
|
||||
char *ptr;
|
||||
} psycString;
|
||||
} PsycString;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
psycString key;
|
||||
PsycString key;
|
||||
int value;
|
||||
} psycMatchVar;
|
||||
} PsycMatchVar;
|
||||
|
||||
/**
|
||||
* Shortcut for creating a psycString.
|
||||
* Shortcut for creating a PsycString.
|
||||
*
|
||||
* @param str Pointer to the buffer.
|
||||
* @param len Length of that buffer.
|
||||
*
|
||||
* @return An instance of the psycString struct.
|
||||
* @return An instance of the PsycString struct.
|
||||
*/
|
||||
static inline
|
||||
psycString psyc_string_new (char *str, size_t len)
|
||||
PsycString psyc_string_new (char *str, size_t len)
|
||||
{
|
||||
psycString s = {len, str};
|
||||
PsycString s = {len, str};
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -154,9 +154,9 @@ int psyc_matches (char *sho, size_t slen,
|
|||
* @return The value of the matched variable in the array.
|
||||
*/
|
||||
|
||||
int psyc_in_array (const psycMatchVar *array, size_t size,
|
||||
int psyc_in_array (const PsycMatchVar *array, size_t size,
|
||||
const char *kw, size_t kwlen,
|
||||
psycBool inherit, int8_t *matching);
|
||||
PsycBool inherit, int8_t *matching);
|
||||
|
||||
#include "psyc/variable.h"
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ typedef enum
|
|||
PSYC_MODIFIER_NO_LENGTH = 2,
|
||||
/// Routing modifier, which implies that it doesn't need length.
|
||||
PSYC_MODIFIER_ROUTING = 3,
|
||||
} psycModifierFlag;
|
||||
} PsycModifierFlag;
|
||||
|
||||
/** List flags. */
|
||||
typedef enum
|
||||
|
@ -41,7 +41,7 @@ typedef enum
|
|||
PSYC_LIST_NEED_LENGTH = 1,
|
||||
/// List doesn't need length.
|
||||
PSYC_LIST_NO_LENGTH = 2,
|
||||
} psycListFlag;
|
||||
} PsycListFlag;
|
||||
|
||||
/** Packet flags. */
|
||||
typedef enum
|
||||
|
@ -52,46 +52,46 @@ typedef enum
|
|||
PSYC_PACKET_NEED_LENGTH = 1,
|
||||
/// Packet doesn't need content length.
|
||||
PSYC_PACKET_NO_LENGTH = 2,
|
||||
} psycPacketFlag;
|
||||
} PsycPacketFlag;
|
||||
|
||||
/** Structure for a modifier. */
|
||||
typedef struct
|
||||
{
|
||||
char oper;
|
||||
psycString name;
|
||||
psycString value;
|
||||
psycModifierFlag flag;
|
||||
} psycModifier;
|
||||
PsycString name;
|
||||
PsycString value;
|
||||
PsycModifierFlag flag;
|
||||
} PsycModifier;
|
||||
|
||||
/** Structure for an entity or routing header. */
|
||||
typedef struct
|
||||
{
|
||||
size_t lines;
|
||||
psycModifier *modifiers;
|
||||
} psycHeader;
|
||||
PsycModifier *modifiers;
|
||||
} PsycHeader;
|
||||
|
||||
/** Structure for a list. */
|
||||
typedef struct
|
||||
{
|
||||
size_t num_elems;
|
||||
psycString *elems;
|
||||
PsycString *elems;
|
||||
size_t length;
|
||||
psycListFlag flag;
|
||||
} psycList;
|
||||
PsycListFlag flag;
|
||||
} PsycList;
|
||||
|
||||
/** Intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
psycHeader routing; ///< Routing header.
|
||||
psycHeader entity; ///< Entity header.
|
||||
psycString method; ///< Contains the method.
|
||||
psycString data; ///< Contains the data.
|
||||
psycString content; ///< Contains the whole content.
|
||||
PsycHeader routing; ///< Routing header.
|
||||
PsycHeader entity; ///< Entity header.
|
||||
PsycString method; ///< Contains the method.
|
||||
PsycString data; ///< Contains the data.
|
||||
PsycString content; ///< Contains the whole content.
|
||||
size_t routingLength; ///< Length of routing part.
|
||||
size_t contentLength; ///< Length of content part.
|
||||
size_t length; ///< Total length of packet.
|
||||
psycPacketFlag flag; ///< Packet flag.
|
||||
} psycPacket;
|
||||
PsycPacketFlag flag; ///< Packet flag.
|
||||
} PsycPacket;
|
||||
|
||||
/**
|
||||
* Return the number of digits a number has in its base 10 representation.
|
||||
|
@ -107,9 +107,9 @@ size_t psyc_num_length (size_t n)
|
|||
* Check if a modifier needs length.
|
||||
*/
|
||||
static inline
|
||||
psycModifierFlag psyc_modifier_length_check (psycModifier *m)
|
||||
PsycModifierFlag psyc_modifier_length_check (PsycModifier *m)
|
||||
{
|
||||
psycModifierFlag flag;
|
||||
PsycModifierFlag flag;
|
||||
|
||||
if (m->value.length > PSYC_MODIFIER_SIZE_THRESHOLD)
|
||||
flag = PSYC_MODIFIER_NEED_LENGTH;
|
||||
|
@ -123,12 +123,12 @@ psycModifierFlag psyc_modifier_length_check (psycModifier *m)
|
|||
|
||||
/** Create new modifier */
|
||||
static inline
|
||||
psycModifier psyc_modifier_new (char oper,
|
||||
PsycModifier psyc_modifier_new (char oper,
|
||||
char *name, size_t namelen,
|
||||
char *value, size_t valuelen,
|
||||
psycModifierFlag flag){
|
||||
PsycModifierFlag flag){
|
||||
|
||||
psycModifier m = {oper, {namelen, name}, {valuelen, value}, flag};
|
||||
PsycModifier m = {oper, {namelen, name}, {valuelen, value}, flag};
|
||||
|
||||
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
||||
m.flag = psyc_modifier_length_check(&m);
|
||||
|
@ -140,45 +140,45 @@ psycModifier psyc_modifier_new (char oper,
|
|||
* \internal
|
||||
* Get the total length of a modifier when rendered.
|
||||
*/
|
||||
size_t psyc_modifier_length (psycModifier *m);
|
||||
size_t psyc_modifier_length (PsycModifier *m);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Check if a list needs length.
|
||||
*/
|
||||
psycListFlag psyc_list_length_check (psycList *list);
|
||||
PsycListFlag psyc_list_length_check (PsycList *list);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Get the total length of a list when rendered.
|
||||
*/
|
||||
psycListFlag psyc_list_length (psycList *list);
|
||||
PsycListFlag psyc_list_length (PsycList *list);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Check if a packet needs length.
|
||||
*/
|
||||
psycPacketFlag psyc_packet_length_check (psycPacket *p);
|
||||
PsycPacketFlag psyc_packet_length_check (PsycPacket *p);
|
||||
|
||||
/**
|
||||
* Calculate and set the rendered length of packet parts and total packet length.
|
||||
*/
|
||||
size_t psyc_packet_length_set (psycPacket *p);
|
||||
size_t psyc_packet_length_set (PsycPacket *p);
|
||||
|
||||
/** Create new list. */
|
||||
psycList psyc_list_new (psycString *elems, size_t num_elems, psycListFlag flag);
|
||||
PsycList psyc_list_new (PsycString *elems, size_t num_elems, PsycListFlag flag);
|
||||
|
||||
/** Create new packet. */
|
||||
psycPacket psyc_packet_new (psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
PsycPacket psyc_packet_new (PsycModifier *routing, size_t routinglen,
|
||||
PsycModifier *entity, size_t entitylen,
|
||||
char *method, size_t methodlen,
|
||||
char *data, size_t datalen,
|
||||
psycPacketFlag flag);
|
||||
PsycPacketFlag flag);
|
||||
|
||||
/** Create new packet with raw content. */
|
||||
psycPacket psyc_packet_new_raw (psycModifier *routing, size_t routinglen,
|
||||
PsycPacket psyc_packet_new_raw (PsycModifier *routing, size_t routinglen,
|
||||
char *content, size_t contentlen,
|
||||
psycPacketFlag flag);
|
||||
PsycPacketFlag flag);
|
||||
|
||||
/** @} */ // end of packet group
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
* To parse a packet you first have to initialize a state:
|
||||
*
|
||||
* @code
|
||||
* psycParseState state;
|
||||
* PsycParseState state;
|
||||
* psyc_parse_state_init(&state, flags);
|
||||
* @endcode
|
||||
*
|
||||
* With the flags parameter you can fine-tune what
|
||||
* part of the packet should be parsed. @see psycParseFlag
|
||||
* part of the packet should be parsed. @see PsycParseFlag
|
||||
*
|
||||
* Next, you have to tell the parser what it should parse. Assuming the variable
|
||||
* raw_data points to our packet and raw_len contains the length, you can pass
|
||||
|
@ -46,7 +46,7 @@
|
|||
* declared:
|
||||
*
|
||||
* @code
|
||||
* psycString name, // Name of the variable or method
|
||||
* PsycString name, // Name of the variable or method
|
||||
* value; // Value of the variable or body
|
||||
* char oper; // operator of the variable (if any)
|
||||
* @endcode
|
||||
|
@ -105,7 +105,7 @@
|
|||
* receive incomplete packets but still want to access the data. This code would
|
||||
* simply reject incomplete packets as error. A more detailed tutorial for
|
||||
* incomplete packets will follow. In the mean time, have look at the return
|
||||
* codes in psycParseRC and their explanations. @see psycParseRC
|
||||
* codes in PsycParseRC and their explanations. @see PsycParseRC
|
||||
*/
|
||||
|
||||
/** @{ */ // begin of parser group
|
||||
|
@ -122,7 +122,7 @@ typedef enum {
|
|||
/// Parse only the content.
|
||||
/// Parsing starts at the content and the content must be complete.
|
||||
PSYC_PARSE_START_AT_CONTENT = 2,
|
||||
} psycParseFlag;
|
||||
} PsycParseFlag;
|
||||
|
||||
/**
|
||||
* The return value definitions for the packet parsing function.
|
||||
|
@ -188,7 +188,7 @@ typedef enum {
|
|||
PSYC_PARSE_CONTENT = 10,
|
||||
/// Finished parsing packet.
|
||||
PSYC_PARSE_COMPLETE = 11,
|
||||
} psycParseRC;
|
||||
} PsycParseRC;
|
||||
|
||||
/**
|
||||
* The return value definitions for the list parsing function.
|
||||
|
@ -205,7 +205,7 @@ typedef enum {
|
|||
PSYC_PARSE_LIST_END = 2,
|
||||
/// Binary list is incomplete.
|
||||
PSYC_PARSE_LIST_INCOMPLETE = 3,
|
||||
} psycParseListRC;
|
||||
} PsycParseListRC;
|
||||
|
||||
/**
|
||||
* Struct for keeping parser state.
|
||||
|
@ -213,18 +213,18 @@ typedef enum {
|
|||
typedef struct {
|
||||
size_t cursor; ///< Current position in buffer.
|
||||
size_t startc; ///< Position where the parsing would be resumed.
|
||||
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.
|
||||
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 routingLength; ///< Length of routing part parsed so far.
|
||||
size_t contentParsed; ///< Number of bytes parsed from the content so far.
|
||||
size_t contentLength; ///< Expected length of the content.
|
||||
psycBool 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.
|
||||
psycBool valueLengthFound; ///< Is there a length given for this modifier?
|
||||
} psycParseState;
|
||||
PsycBool valueLengthFound; ///< Is there a length given for this modifier?
|
||||
} PsycParseState;
|
||||
|
||||
/**
|
||||
* Struct for keeping list parser state.
|
||||
|
@ -232,24 +232,24 @@ typedef struct {
|
|||
typedef struct {
|
||||
size_t cursor; ///< Current position in buffer.
|
||||
size_t startc; ///< Line start position.
|
||||
psycString buffer; ///< Buffer with data to be parsed.
|
||||
psycListType type; ///< List type.
|
||||
PsycString buffer; ///< Buffer with data to be parsed.
|
||||
PsycListType type; ///< List type.
|
||||
|
||||
size_t elemParsed; ///< Number of bytes parsed from the elem so far.
|
||||
size_t elemLength; ///< Expected length of the elem.
|
||||
} psycParseListState;
|
||||
} PsycParseListState;
|
||||
|
||||
/**
|
||||
* Initializes the state struct.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initialized.
|
||||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||
* @see psycParseFlag
|
||||
* @param flags Flags to be set for the parser, see PsycParseFlag.
|
||||
* @see PsycParseFlag
|
||||
*/
|
||||
static inline
|
||||
void psyc_parse_state_init (psycParseState *state, uint8_t flags)
|
||||
void psyc_parse_state_init (PsycParseState *state, uint8_t flags)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
memset(state, 0, sizeof(PsycParseState));
|
||||
state->flags = flags;
|
||||
|
||||
if (flags & PSYC_PARSE_START_AT_CONTENT)
|
||||
|
@ -265,12 +265,12 @@ void psyc_parse_state_init (psycParseState *state, uint8_t flags)
|
|||
* @param state Pointer to the initialized state of the parser
|
||||
* @param buffer pointer to the data that should be parsed
|
||||
* @param length length of the data in bytes
|
||||
* @see psycString
|
||||
* @see PsycString
|
||||
*/
|
||||
static inline
|
||||
void psyc_parse_buffer_set (psycParseState *state, char *buffer, size_t length)
|
||||
void psyc_parse_buffer_set (PsycParseState *state, char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = (psycString) {length, buffer};
|
||||
state->buffer = (PsycString) {length, buffer};
|
||||
state->cursor = 0;
|
||||
|
||||
if (state->flags & PSYC_PARSE_START_AT_CONTENT) {
|
||||
|
@ -285,65 +285,65 @@ void psyc_parse_buffer_set (psycParseState *state, char *buffer, size_t length)
|
|||
* @param state Pointer to the list state struct that should be initialized.
|
||||
*/
|
||||
static inline
|
||||
void psyc_parse_list_state_init (psycParseListState *state)
|
||||
void psyc_parse_list_state_init (PsycParseListState *state)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseListState));
|
||||
memset(state, 0, sizeof(PsycParseListState));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new buffer in the list parser state struct with data to be parsed.
|
||||
*/
|
||||
static inline
|
||||
void psyc_parse_list_buffer_set (psycParseListState *state, char *buffer, size_t length)
|
||||
void psyc_parse_list_buffer_set (PsycParseListState *state, char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = (psycString) {length, buffer};
|
||||
state->buffer = (PsycString) {length, buffer};
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_parse_content_length (psycParseState *state)
|
||||
size_t psyc_parse_content_length (PsycParseState *state)
|
||||
{
|
||||
return state->contentLength;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parse_content_length_found (psycParseState *state)
|
||||
PsycBool psyc_parse_content_length_found (PsycParseState *state)
|
||||
{
|
||||
return state->contentLengthFound;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_parse_value_length (psycParseState *state)
|
||||
size_t psyc_parse_value_length (PsycParseState *state)
|
||||
{
|
||||
return state->valueLength;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parse_value_length_found (psycParseState *state)
|
||||
PsycBool psyc_parse_value_length_found (PsycParseState *state)
|
||||
{
|
||||
return state->valueLengthFound;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_parse_cursor (psycParseState *state)
|
||||
size_t psyc_parse_cursor (PsycParseState *state)
|
||||
{
|
||||
return state->cursor;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_parse_buffer_length (psycParseState *state)
|
||||
size_t psyc_parse_buffer_length (PsycParseState *state)
|
||||
{
|
||||
return state->buffer.length;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_parse_remaining_length (psycParseState *state)
|
||||
size_t psyc_parse_remaining_length (PsycParseState *state)
|
||||
{
|
||||
return state->buffer.length - state->cursor;
|
||||
}
|
||||
|
||||
static inline
|
||||
const char * psyc_parse_remaining_buffer (psycParseState *state)
|
||||
const char * psyc_parse_remaining_buffer (PsycParseState *state)
|
||||
{
|
||||
return state->buffer.ptr + state->cursor;
|
||||
}
|
||||
|
@ -353,11 +353,11 @@ const char * psyc_parse_remaining_buffer (psycParseState *state)
|
|||
*
|
||||
* This function parses a full or partial PSYC packet while keeping parsing
|
||||
* state in a state variable that you have to pass in every time, and returns
|
||||
* whenever a modifier or the body is found. See psycParseRC for the possible
|
||||
* whenever a modifier or the body is found. See PsycParseRC for the possible
|
||||
* return codes. When it returns oper, name & value will point to the respective
|
||||
* parts of the buffer, no memory allocation is done.
|
||||
*
|
||||
* @param state An initialized psycParseState.
|
||||
* @param state An initialized PsycParseState.
|
||||
* @param oper In case of a modifier it will be set to the operator.
|
||||
* @param name In case of a modifier it will point to the name,
|
||||
* in case of the body it will point to the method.
|
||||
|
@ -367,8 +367,8 @@ const char * psyc_parse_remaining_buffer (psycParseState *state)
|
|||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||
psycString *name, psycString *value);
|
||||
PsycParseRC psyc_parse (PsycParseState *state, char *oper,
|
||||
PsycString *name, PsycString *value);
|
||||
|
||||
/**
|
||||
* List parser.
|
||||
|
@ -378,16 +378,16 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
|||
* every time. When it returns elem will point to the next element in value, no
|
||||
* memory allocation is done.
|
||||
*
|
||||
* @param state An initialized psycParseListState.
|
||||
* @param state An initialized PsycParseListState.
|
||||
* @param elem It will point to the next element in the list.
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseListRC psyc_parse_list (psycParseListState *state, psycString *elem);
|
||||
PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem);
|
||||
|
||||
static inline
|
||||
psycBool psyc_parse_number (const char *value, size_t len, ssize_t *n)
|
||||
PsycBool psyc_parse_number (const char *value, size_t len, ssize_t *n)
|
||||
{
|
||||
size_t c = 0;
|
||||
uint8_t neg = 0;
|
||||
|
@ -412,13 +412,13 @@ psycBool psyc_parse_number (const char *value, size_t len, ssize_t *n)
|
|||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parse_time (const char *value, size_t len, time_t *t)
|
||||
PsycBool psyc_parse_time (const char *value, size_t len, time_t *t)
|
||||
{
|
||||
return psyc_parse_number(value, len, t);
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parse_date (const char *value, size_t len, time_t *t)
|
||||
PsycBool psyc_parse_date (const char *value, size_t len, time_t *t)
|
||||
{
|
||||
if (psyc_parse_number(value, len, t)) {
|
||||
*t += PSYC_EPOCH;
|
||||
|
|
|
@ -29,7 +29,7 @@ typedef enum
|
|||
PSYC_RENDER_ERROR = -1,
|
||||
/// Packet is rendered successfully in the buffer.
|
||||
PSYC_RENDER_SUCCESS = 0,
|
||||
} psycRenderRC;
|
||||
} PsycRenderRC;
|
||||
|
||||
/**
|
||||
* Return codes for psyc_render_list.
|
||||
|
@ -40,7 +40,7 @@ typedef enum
|
|||
PSYC_RENDER_LIST_ERROR = -1,
|
||||
/// List is rendered successfully in the buffer.
|
||||
PSYC_RENDER_LIST_SUCCESS = 0,
|
||||
} psycRenderListRC;
|
||||
} PsycRenderListRC;
|
||||
|
||||
/**
|
||||
* Render a PSYC packet into a buffer.
|
||||
|
@ -59,7 +59,7 @@ typedef enum
|
|||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen);
|
||||
PsycRenderRC psyc_render (PsycPacket *packet, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Render a PSYC list into a buffer.
|
||||
|
@ -67,7 +67,7 @@ psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen);
|
|||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderListRC psyc_render_list (psycList *list, char *buffer, size_t buflen);
|
||||
PsycRenderListRC psyc_render_list (PsycList *list, char *buffer, size_t buflen);
|
||||
|
||||
/** @} */ // end of render group
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ typedef enum
|
|||
/// Text template parsing & rendering is incomplete, because the buffer was too small.
|
||||
/// Another call is required to this function after setting a new buffer.
|
||||
PSYC_TEXT_INCOMPLETE = 1,
|
||||
} psycTextRC;
|
||||
} PsycTextRC;
|
||||
|
||||
/**
|
||||
* Return values for psycTextCB.
|
||||
* Return values for PsycTextCB.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ typedef enum
|
|||
PSYC_TEXT_VALUE_NOT_FOUND = -1,
|
||||
/// Value found, substitute contents of the value variable.
|
||||
PSYC_TEXT_VALUE_FOUND = 0,
|
||||
} psycTextValueRC;
|
||||
} PsycTextValueRC;
|
||||
|
||||
/**
|
||||
* Struct for keeping PSYC text parser state.
|
||||
|
@ -48,11 +48,11 @@ typedef struct
|
|||
{
|
||||
size_t cursor; ///< current position in the template
|
||||
size_t written; ///< number of bytes written to buffer
|
||||
psycString tmpl; ///< input buffer with text template to parse
|
||||
psycString buffer; ///< output buffer for rendered text
|
||||
psycString open;
|
||||
psycString close;
|
||||
} psycTextState;
|
||||
PsycString tmpl; ///< input buffer with text template to parse
|
||||
PsycString buffer; ///< output buffer for rendered text
|
||||
PsycString open;
|
||||
PsycString close;
|
||||
} PsycTextState;
|
||||
|
||||
/**
|
||||
* Callback for psyc_text() that produces a value for a match.
|
||||
|
@ -64,7 +64,7 @@ typedef struct
|
|||
* PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
|
||||
* leaves the original template text as is.
|
||||
*/
|
||||
typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *value, void *extra);
|
||||
typedef PsycTextValueRC (*PsycTextCB)(const char *name, size_t len, PsycString *value, void *extra);
|
||||
|
||||
/**
|
||||
* Initializes the PSYC text state struct.
|
||||
|
@ -76,16 +76,16 @@ typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *
|
|||
* @param buflen Length of output buffer.
|
||||
*/
|
||||
static inline
|
||||
void psyc_text_state_init (psycTextState *state,
|
||||
void psyc_text_state_init (PsycTextState *state,
|
||||
char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen)
|
||||
{
|
||||
state->cursor = 0;
|
||||
state->written = 0;
|
||||
state->tmpl = (psycString) {tmplen, tmpl};
|
||||
state->buffer = (psycString) {buflen, buffer};
|
||||
state->open = (psycString) {1, "["};
|
||||
state->close = (psycString) {1, "]"};
|
||||
state->tmpl = (PsycString) {tmplen, tmpl};
|
||||
state->buffer = (PsycString) {buflen, buffer};
|
||||
state->open = (PsycString) {1, "["};
|
||||
state->close = (PsycString) {1, "]"};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,7 @@ void psyc_text_state_init (psycTextState *state,
|
|||
* @param closelen Length of closing brace.
|
||||
*/
|
||||
static inline
|
||||
void psyc_text_state_init_custom (psycTextState *state,
|
||||
void psyc_text_state_init_custom (PsycTextState *state,
|
||||
char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen,
|
||||
char *open, size_t openlen,
|
||||
|
@ -110,25 +110,25 @@ void psyc_text_state_init_custom (psycTextState *state,
|
|||
{
|
||||
state->cursor = 0;
|
||||
state->written = 0;
|
||||
state->tmpl = (psycString) {tmplen, tmpl};
|
||||
state->buffer = (psycString) {buflen, buffer};
|
||||
state->open = (psycString) {openlen, open};
|
||||
state->close = (psycString) {closelen, close};
|
||||
state->tmpl = (PsycString) {tmplen, tmpl};
|
||||
state->buffer = (PsycString) {buflen, buffer};
|
||||
state->open = (PsycString) {openlen, open};
|
||||
state->close = (PsycString) {closelen, close};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new output buffer in the PSYC text state struct.
|
||||
*/
|
||||
static inline
|
||||
void psyc_text_buffer_set (psycTextState *state,
|
||||
void psyc_text_buffer_set (PsycTextState *state,
|
||||
char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = (psycString){length, buffer};
|
||||
state->buffer = (PsycString){length, buffer};
|
||||
state->written = 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_text_bytes_written (psycTextState *state)
|
||||
size_t psyc_text_bytes_written (PsycTextState *state)
|
||||
{
|
||||
return state->written;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ size_t psyc_text_bytes_written (psycTextState *state)
|
|||
*
|
||||
* @see http://about.psyc.eu/psyctext
|
||||
**/
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue, void *extra);
|
||||
PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void *extra);
|
||||
|
||||
/** @} */ // end of text group
|
||||
|
||||
|
|
|
@ -11,31 +11,31 @@ typedef enum {
|
|||
PSYC_SCHEME_IRC = 1,
|
||||
PSYC_SCHEME_XMPP = 2,
|
||||
PSYC_SCHEME_SIP = 3,
|
||||
} psycScheme;
|
||||
} PsycScheme;
|
||||
|
||||
typedef struct {
|
||||
// essential parts
|
||||
uint8_t valid;
|
||||
psycScheme type;
|
||||
psycString scheme;
|
||||
psycString user;
|
||||
psycString pass;
|
||||
psycString host;
|
||||
psycString port;
|
||||
psycString transport;
|
||||
psycString resource;
|
||||
psycString query;
|
||||
psycString channel;
|
||||
PsycScheme type;
|
||||
PsycString scheme;
|
||||
PsycString user;
|
||||
PsycString pass;
|
||||
PsycString host;
|
||||
PsycString port;
|
||||
PsycString transport;
|
||||
PsycString resource;
|
||||
PsycString query;
|
||||
PsycString channel;
|
||||
|
||||
// convenient snippets of the URL
|
||||
psycString full; // the URL as such
|
||||
psycString body; // the URL without scheme and '//'
|
||||
psycString user_host; // mailto and xmpp style
|
||||
psycString host_port; // just host:port (and transport)
|
||||
psycString root; // root UNI of peer/server
|
||||
psycString slashes; // the // if the protocol has them
|
||||
psycString nick; // whatever works as a nickname
|
||||
} psycUniform;
|
||||
PsycString full; // the URL as such
|
||||
PsycString body; // the URL without scheme and '//'
|
||||
PsycString user_host; // mailto and xmpp style
|
||||
PsycString host_port; // just host:port (and transport)
|
||||
PsycString root; // root UNI of peer/server
|
||||
PsycString slashes; // the // if the protocol has them
|
||||
PsycString nick; // whatever works as a nickname
|
||||
} PsycUniform;
|
||||
|
||||
typedef enum {
|
||||
PSYC_UNIFORM_SCHEME = 0,
|
||||
|
@ -48,7 +48,7 @@ typedef enum {
|
|||
PSYC_UNIFORM_RESOURCE,
|
||||
PSYC_UNIFORM_QUERY,
|
||||
PSYC_UNIFORM_CHANNEL,
|
||||
} psycUniformPart;
|
||||
} PsycUniformPart;
|
||||
|
||||
typedef enum {
|
||||
PSYC_PARSE_UNIFORM_INVALID_SLASHES = -7,
|
||||
|
@ -58,22 +58,22 @@ typedef enum {
|
|||
PSYC_PARSE_UNIFORM_INVALID_PORT = -3,
|
||||
PSYC_PARSE_UNIFORM_INVALID_HOST = -2,
|
||||
PSYC_PARSE_UNIFORM_INVALID_SCHEME = -1,
|
||||
} psycParseUniformRC;
|
||||
} PsycParseUniformRC;
|
||||
|
||||
typedef enum {
|
||||
PSYC_TRANSPORT_TCP = 'c',
|
||||
PSYC_TRANSPORT_UDP = 'd',
|
||||
PSYC_TRANSPORT_TLS = 's',
|
||||
PSYC_TRANSPORT_GNUNET = 'g',
|
||||
} psycTransport;
|
||||
} PsycTransport;
|
||||
|
||||
typedef enum {
|
||||
PSYC_ENTITY_PERSON = '~',
|
||||
PSYC_ENTITY_PLACE = '@',
|
||||
PSYC_ENTITY_SERVICE = '$',
|
||||
} psycEntityType;
|
||||
} PsycEntityType;
|
||||
|
||||
int psyc_uniform_parse (psycUniform *uni, char *str, size_t length);
|
||||
int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length);
|
||||
|
||||
#define PSYC_UNIFORM_H
|
||||
#endif
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
extern const psycString psyc_routing_vars[];
|
||||
extern const PsycString psyc_routing_vars[];
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
extern const psycMatchVar psyc_var_types[];
|
||||
extern const PsycMatchVar psyc_var_types[];
|
||||
|
||||
extern const size_t psyc_routing_vars_num;
|
||||
extern const size_t psyc_var_types_num;
|
||||
|
@ -16,18 +16,18 @@ extern const size_t psyc_var_types_num;
|
|||
/**
|
||||
* Is this a routing variable name?
|
||||
*/
|
||||
psycBool psyc_var_is_routing (const char *name, size_t len);
|
||||
PsycBool psyc_var_is_routing (const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
psycType psyc_var_type (const char *name, size_t len);
|
||||
PsycType psyc_var_type (const char *name, size_t len);
|
||||
|
||||
/**
|
||||
* Is this a list variable name?
|
||||
*/
|
||||
static inline
|
||||
psycBool psyc_var_is_list (const char *name, size_t len)
|
||||
PsycBool psyc_var_is_list (const char *name, size_t len)
|
||||
{
|
||||
return len < 5 || memcmp(name, "_list", 5) != 0 ||
|
||||
(len > 5 && name[5] != '_') ? PSYC_FALSE : PSYC_TRUE;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
// psyctext helper
|
||||
psycTextValueRC lookup_value_mapping(const char *name, size_t len, psycString *value, void *extra)
|
||||
PsycTextValueRC lookup_value_mapping(const char *name, size_t len, PsycString *value, void *extra)
|
||||
{
|
||||
//printf("lookup_value_mapping called for %.*s\n", (int) len, name);
|
||||
struct pike_string *key = make_shared_binary_string(name, len);
|
||||
|
@ -68,8 +68,8 @@ psycTextValueRC lookup_value_mapping(const char *name, size_t len, psycString *v
|
|||
*! rendered string
|
||||
*/
|
||||
PIKEFUN string psyc_text(string template, mapping vars) {
|
||||
psycTextState state;
|
||||
psycTextRC ret;
|
||||
PsycTextState state;
|
||||
PsycTextRC ret;
|
||||
size_t len = 0;
|
||||
// FIXME:
|
||||
char buffer[512];
|
||||
|
@ -115,8 +115,8 @@ PIKEFUN int is_routingvar(string name) {
|
|||
*! serialized packet as a string
|
||||
*/
|
||||
PIKEFUN string render(mapping rvars, mapping evars, string method, string|void body) {
|
||||
psycPacket packet;
|
||||
psycHeader rheaders, eheaders;
|
||||
PsycPacket packet;
|
||||
PsycHeader rheaders, eheaders;
|
||||
|
||||
struct keypair *k; // for mappings
|
||||
INT32 e;
|
||||
|
@ -125,7 +125,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
|||
|
||||
// fill headers
|
||||
rheaders.lines = 0;
|
||||
rheaders.modifiers = malloc(sizeof(psycModifier) * rvars->data->size);
|
||||
rheaders.modifiers = malloc(sizeof(PsycModifier) * rvars->data->size);
|
||||
NEW_MAPPING_LOOP(rvars->data) {
|
||||
if (k->ind.type == PIKE_T_STRING) {
|
||||
switch(k->val.type) {
|
||||
|
@ -147,7 +147,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
|||
}
|
||||
|
||||
eheaders.lines = 0;
|
||||
eheaders.modifiers = malloc(sizeof(psycModifier) * evars->data->size);
|
||||
eheaders.modifiers = malloc(sizeof(PsycModifier) * evars->data->size);
|
||||
NEW_MAPPING_LOOP(evars->data) {
|
||||
if (k->ind.type == PIKE_T_STRING) {
|
||||
char *key;
|
||||
|
@ -183,14 +183,14 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
|||
*/
|
||||
case PIKE_T_ARRAY:
|
||||
do {
|
||||
psycString *elems = xcalloc(k->val.u.array->size, sizeof(psycString));
|
||||
psycList list;
|
||||
PsycString *elems = xcalloc(k->val.u.array->size, sizeof(PsycString));
|
||||
PsycList list;
|
||||
// FIXME: check for out of memory
|
||||
for(e = 0; e < k->val.u.array->size; e++) {
|
||||
struct svalue item = k->val.u.array->item[e];
|
||||
switch(item.type) {
|
||||
case PIKE_T_STRING:
|
||||
elems[e] = (psycString) { item.u.string->len, (char *) STR0(item.u.string) };
|
||||
elems[e] = (PsycString) { item.u.string->len, (char *) STR0(item.u.string) };
|
||||
break;
|
||||
default:
|
||||
// FIXME: xfree(elems) ?
|
||||
|
@ -245,7 +245,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
|||
}
|
||||
|
||||
PIKECLASS Parser {
|
||||
CVAR psycParseState parser;
|
||||
CVAR PsycParseState parser;
|
||||
CVAR struct pike_string *buffer;
|
||||
CVAR int handle_packet;
|
||||
CVAR int handle_error;
|
||||
|
@ -283,7 +283,7 @@ PIKECLASS Parser {
|
|||
|
||||
PIKEFUN void feed(string data) {
|
||||
char oper;
|
||||
psycString name, value;
|
||||
PsycString name, value;
|
||||
int ret;
|
||||
int err;
|
||||
|
||||
|
@ -379,8 +379,8 @@ PIKECLASS Parser {
|
|||
if (value.length > 0) {
|
||||
int retl;
|
||||
int count = 0;
|
||||
psycParseListState listState;
|
||||
psycString elem = (psycString) {0, 0};
|
||||
PsycParseListState listState;
|
||||
PsycString elem = (PsycString) {0, 0};
|
||||
|
||||
psyc_parse_list_state_init(&listState);
|
||||
psyc_parse_list_buffer_set(&listState, PSYC_S2ARG(value));
|
||||
|
|
|
@ -114,9 +114,9 @@ failed:
|
|||
*
|
||||
* @return The value of the matched variable in the array.
|
||||
*/
|
||||
int psyc_in_array (const psycMatchVar *array, size_t size,
|
||||
int psyc_in_array (const PsycMatchVar *array, size_t size,
|
||||
const char *kw, size_t kwlen,
|
||||
psycBool inherit, int8_t *matching)
|
||||
PsycBool inherit, int8_t *matching)
|
||||
{
|
||||
size_t cursor = 1;
|
||||
uint8_t i, m = 0;
|
||||
|
|
32
src/packet.c
32
src/packet.c
|
@ -3,14 +3,14 @@
|
|||
#include <psyc/packet.h>
|
||||
|
||||
inline
|
||||
psycListFlag psyc_list_length_check (psycList *list)
|
||||
PsycListFlag psyc_list_length_check (PsycList *list)
|
||||
{
|
||||
psycListFlag flag = PSYC_LIST_NO_LENGTH;
|
||||
PsycListFlag flag = PSYC_LIST_NO_LENGTH;
|
||||
size_t i, length = 0;
|
||||
|
||||
for (i = 0; i < list->num_elems; i++)
|
||||
{
|
||||
psycString *elem = &list->elems[i];
|
||||
PsycString *elem = &list->elems[i];
|
||||
length += 1 + elem->length; // |elem
|
||||
if (length > PSYC_MODIFIER_SIZE_THRESHOLD ||
|
||||
memchr(elem->ptr, (int)'|', elem->length) ||
|
||||
|
@ -25,7 +25,7 @@ psycListFlag psyc_list_length_check (psycList *list)
|
|||
}
|
||||
|
||||
inline
|
||||
psycListFlag psyc_list_length (psycList *list)
|
||||
PsycListFlag psyc_list_length (PsycList *list)
|
||||
{
|
||||
size_t i, length = 0;
|
||||
|
||||
|
@ -48,9 +48,9 @@ psycListFlag psyc_list_length (psycList *list)
|
|||
}
|
||||
|
||||
inline
|
||||
psycList psyc_list_new (psycString *elems, size_t num_elems, psycListFlag flag)
|
||||
PsycList psyc_list_new (PsycString *elems, size_t num_elems, PsycListFlag flag)
|
||||
{
|
||||
psycList list = {num_elems, elems, 0, flag};
|
||||
PsycList list = {num_elems, elems, 0, flag};
|
||||
|
||||
if (flag == PSYC_LIST_CHECK_LENGTH) // check if list elements need length
|
||||
list.flag = psyc_list_length_check(&list);
|
||||
|
@ -61,7 +61,7 @@ psycList psyc_list_new (psycString *elems, size_t num_elems, psycListFlag flag)
|
|||
|
||||
|
||||
inline
|
||||
size_t psyc_modifier_length (psycModifier *m)
|
||||
size_t psyc_modifier_length (PsycModifier *m)
|
||||
{
|
||||
size_t length = 1 + // oper
|
||||
m->name.length + 1 + // name\t
|
||||
|
@ -74,7 +74,7 @@ size_t psyc_modifier_length (psycModifier *m)
|
|||
}
|
||||
|
||||
inline
|
||||
psycPacketFlag psyc_packet_length_check (psycPacket *p)
|
||||
PsycPacketFlag psyc_packet_length_check (PsycPacket *p)
|
||||
{
|
||||
if (p->data.length == 1 && p->data.ptr[0] == C_GLYPH_PACKET_DELIMITER)
|
||||
return PSYC_PACKET_NEED_LENGTH;
|
||||
|
@ -96,7 +96,7 @@ psycPacketFlag psyc_packet_length_check (psycPacket *p)
|
|||
}
|
||||
|
||||
inline
|
||||
size_t psyc_packet_length_set (psycPacket *p)
|
||||
size_t psyc_packet_length_set (PsycPacket *p)
|
||||
{
|
||||
size_t i;
|
||||
p->routingLength = 0;
|
||||
|
@ -134,13 +134,13 @@ size_t psyc_packet_length_set (psycPacket *p)
|
|||
}
|
||||
|
||||
inline
|
||||
psycPacket psyc_packet_new (psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
PsycPacket psyc_packet_new (PsycModifier *routing, size_t routinglen,
|
||||
PsycModifier *entity, size_t entitylen,
|
||||
char *method, size_t methodlen,
|
||||
char *data, size_t datalen,
|
||||
psycPacketFlag flag)
|
||||
PsycPacketFlag flag)
|
||||
{
|
||||
psycPacket p = {{routinglen, routing}, {entitylen, entity},
|
||||
PsycPacket p = {{routinglen, routing}, {entitylen, entity},
|
||||
{methodlen, method}, {datalen, data}, {0,0}, 0, 0, flag};
|
||||
|
||||
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs a length
|
||||
|
@ -151,11 +151,11 @@ psycPacket psyc_packet_new (psycModifier *routing, size_t routinglen,
|
|||
}
|
||||
|
||||
inline
|
||||
psycPacket psyc_packet_new_raw (psycModifier *routing, size_t routinglen,
|
||||
PsycPacket psyc_packet_new_raw (PsycModifier *routing, size_t routinglen,
|
||||
char *content, size_t contentlen,
|
||||
psycPacketFlag flag)
|
||||
PsycPacketFlag flag)
|
||||
{
|
||||
psycPacket p = {{routinglen, routing}, {0,0}, {0,0}, {0,0},
|
||||
PsycPacket p = {{routinglen, routing}, {0,0}, {0,0}, {0,0},
|
||||
{contentlen, content}, 0, 0, flag};
|
||||
|
||||
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs a length
|
||||
|
|
16
src/parse.c
16
src/parse.c
|
@ -29,7 +29,7 @@ typedef enum {
|
|||
* @return PARSE_ERROR or PARSE_SUCCESS
|
||||
*/
|
||||
static inline
|
||||
parseRC psyc_parse_keyword (psycParseState *state, psycString *name)
|
||||
parseRC psyc_parse_keyword (PsycParseState *state, PsycString *name)
|
||||
{
|
||||
name->ptr = state->buffer.ptr + state->cursor;
|
||||
name->length = 0;
|
||||
|
@ -54,7 +54,7 @@ parseRC psyc_parse_keyword (psycParseState *state, psycString *name)
|
|||
* @return PARSE_COMPLETE or PARSE_INCOMPLETE
|
||||
*/
|
||||
static inline
|
||||
parseRC psyc_parse_binary_value (psycParseState *state, psycString *value,
|
||||
parseRC psyc_parse_binary_value (PsycParseState *state, PsycString *value,
|
||||
size_t *length, size_t *parsed)
|
||||
{
|
||||
size_t remaining = *length - *parsed;
|
||||
|
@ -81,8 +81,8 @@ parseRC psyc_parse_binary_value (psycParseState *state, psycString *value,
|
|||
* @return PARSE_ERROR or PARSE_SUCCESS
|
||||
*/
|
||||
static inline
|
||||
parseRC psyc_parse_modifier (psycParseState *state, char *oper,
|
||||
psycString *name, psycString *value)
|
||||
parseRC psyc_parse_modifier (PsycParseState *state, char *oper,
|
||||
PsycString *name, PsycString *value)
|
||||
{
|
||||
*oper = *(state->buffer.ptr + state->cursor);
|
||||
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
|
||||
|
@ -153,8 +153,8 @@ parseRC psyc_parse_modifier (psycParseState *state, char *oper,
|
|||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseRC psyc_parse (psycParseState *state, char *oper,
|
||||
psycString *name, psycString *value)
|
||||
PsycParseRC psyc_parse (PsycParseState *state, char *oper,
|
||||
PsycString *name, PsycString *value)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (state->flags & PSYC_PARSE_ROUTING_ONLY &&
|
||||
|
@ -437,7 +437,7 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
|||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseListRC psyc_parse_list (psycParseListState *state, psycString *elem)
|
||||
PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem)
|
||||
{
|
||||
if (state->cursor >= state->buffer.length)
|
||||
return PSYC_PARSE_LIST_INCOMPLETE;
|
||||
|
@ -504,7 +504,7 @@ psycParseListRC psyc_parse_list (psycParseListState *state, psycString *elem)
|
|||
// Start or resume parsing the binary data
|
||||
if (state->elemParsed < state->elemLength)
|
||||
{
|
||||
if (psyc_parse_binary_value((psycParseState*)state, elem,
|
||||
if (psyc_parse_binary_value((PsycParseState*)state, elem,
|
||||
&(state->elemLength), &(state->elemParsed)) == PARSE_INCOMPLETE)
|
||||
return PSYC_PARSE_LIST_INCOMPLETE;
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include <stdint.h>
|
||||
|
||||
struct psycParser;
|
||||
struct PsycParser;
|
||||
|
||||
/** @brief initialize a pstate struct
|
||||
*
|
||||
* @param pstate pointer to an allocated
|
||||
* psycParser struct.
|
||||
* PsycParser struct.
|
||||
*/
|
||||
void psyc_parse_state_init(struct psycParser* pstate);
|
||||
void psyc_parse_state_init(struct PsycParser* pstate);
|
||||
|
||||
|
||||
/** @brief parses a packet
|
||||
*
|
||||
* This function parses rawdata
|
||||
* and uses the callbacks in psycParser
|
||||
* and uses the callbacks in PsycParser
|
||||
* to communicate with the caller.
|
||||
*
|
||||
* First the header will be parsed,
|
||||
|
@ -43,10 +43,10 @@ void psyc_parse_state_init(struct psycParser* pstate);
|
|||
*
|
||||
*/
|
||||
void psyc_parse(const uint8_t* data, unsigned int length,
|
||||
struct psycParser* pstate);
|
||||
struct PsycParser* pstate);
|
||||
|
||||
/** @brief FlagMod */
|
||||
enum psycOperator
|
||||
enum PsycOperator
|
||||
{
|
||||
// modifier operators
|
||||
ASSIGN = 0x02,
|
||||
|
@ -56,7 +56,7 @@ enum psycOperator
|
|||
QUERY = 0x20,
|
||||
};
|
||||
|
||||
struct psycParser
|
||||
struct PsycParser
|
||||
{
|
||||
/** @brief Callback for the states
|
||||
*
|
||||
|
@ -76,10 +76,10 @@ struct psycParser
|
|||
* @param modifers modifer of the variable (see Modifer)
|
||||
* @param inEntity wether this variable is an entity
|
||||
* variable(true) or a routing variable(false) */
|
||||
void (*stateCallback)(struct psycParser* pstate,
|
||||
void (*stateCallback)(struct PsycParser* pstate,
|
||||
const uint8_t *name, const unsigned int nlength,
|
||||
const uint8_t *value, const unsigned int vlength,
|
||||
enum psycOperator oper, char inEntity);
|
||||
enum PsycOperator oper, char inEntity);
|
||||
|
||||
/** @brief gets called after the routing-header was parsed
|
||||
*
|
||||
|
@ -88,7 +88,7 @@ struct psycParser
|
|||
* when finished,
|
||||
* if not 0, parser will stop parsing and
|
||||
* calls contentCallback */
|
||||
char (*routingCallback)(struct psycParser* pstate);
|
||||
char (*routingCallback)(struct PsycParser* pstate);
|
||||
|
||||
/** @brief Body callback, gets called when the body was parsed
|
||||
*
|
||||
|
@ -102,7 +102,7 @@ struct psycParser
|
|||
* containing the data section
|
||||
* @param content not null terminated c-string
|
||||
* @param clength length of the content string */
|
||||
void (*bodyCallback)(struct psycParser* pstate,
|
||||
void (*bodyCallback)(struct PsycParser* pstate,
|
||||
const uint8_t* method, unsigned int mlength,
|
||||
const uint8_t* data, unsigned int dlength,
|
||||
const uint8_t* content, unsigned int clength);
|
||||
|
@ -123,7 +123,7 @@ struct psycParser
|
|||
*
|
||||
* Any previous state or body callbacks become
|
||||
* invalid and have to be purged.*/
|
||||
void (*errorCallback)(struct psycParser* pstate,
|
||||
void (*errorCallback)(struct PsycParser* pstate,
|
||||
const uint8_t *method, unsigned int mlength);
|
||||
|
||||
/** @brief error state callback
|
||||
|
@ -132,10 +132,10 @@ struct psycParser
|
|||
* The callback will be called once for each
|
||||
* state variable in the error report packet
|
||||
*/
|
||||
void (*errorStateCallback)(struct psycParser* pstate,
|
||||
void (*errorStateCallback)(struct PsycParser* pstate,
|
||||
const uint8_t *name, const unsigned int nlength,
|
||||
const uint8_t *value, const unsigned int vlength,
|
||||
enum psycOperator oper);
|
||||
enum PsycOperator oper);
|
||||
|
||||
|
||||
/*******************************************
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderListRC psyc_render_list (psycList *list, char *buffer, size_t buflen)
|
||||
PsycRenderListRC psyc_render_list (PsycList *list, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i, cur = 0;
|
||||
psycString *elem;
|
||||
PsycString *elem;
|
||||
|
||||
if (list->length > buflen) // return error if list doesn't fit in buffer
|
||||
return PSYC_RENDER_LIST_ERROR;
|
||||
|
@ -43,7 +43,7 @@ psycRenderListRC psyc_render_list (psycList *list, char *buffer, size_t buflen)
|
|||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_render_modifier (psycModifier *mod, char *buffer)
|
||||
size_t psyc_render_modifier (PsycModifier *mod, char *buffer)
|
||||
{
|
||||
size_t cur = 0;
|
||||
|
||||
|
@ -70,7 +70,7 @@ size_t psyc_render_modifier (psycModifier *mod, char *buffer)
|
|||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen)
|
||||
PsycRenderRC psyc_render (PsycPacket *packet, char *buffer, size_t buflen)
|
||||
{
|
||||
size_t i, cur = 0, len;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "lib.h"
|
||||
#include <psyc/text.h>
|
||||
|
||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue, void* extra)
|
||||
PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void* extra)
|
||||
{
|
||||
const char *start = state->tmpl.ptr, *end; // start & end of variable name
|
||||
const char *prev = state->tmpl.ptr + state->cursor;
|
||||
psycString value;
|
||||
PsycString value;
|
||||
int ret;
|
||||
size_t len;
|
||||
uint8_t no_subst = (state->cursor == 0); // whether we can return NO_SUBST
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include "psyc/uniform.h"
|
||||
#include "psyc/parse.h"
|
||||
|
||||
int psyc_uniform_parse (psycUniform *uni, char *str, size_t length)
|
||||
int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length)
|
||||
{
|
||||
char c;
|
||||
psycString *p;
|
||||
PsycString *p;
|
||||
size_t pos = 0, part = PSYC_UNIFORM_SCHEME;
|
||||
|
||||
uni->valid = 0;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
const psycString psyc_routing_vars[] =
|
||||
const PsycString psyc_routing_vars[] =
|
||||
{
|
||||
PSYC_C2STR("_amount_fragments"),
|
||||
PSYC_C2STR("_context"),
|
||||
|
@ -27,7 +27,7 @@ const psycString psyc_routing_vars[] =
|
|||
};
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
const psycMatchVar psyc_var_types[] =
|
||||
const PsycMatchVar psyc_var_types[] =
|
||||
{
|
||||
{PSYC_C2STR("_amount"), PSYC_TYPE_AMOUNT},
|
||||
{PSYC_C2STR("_color"), PSYC_TYPE_COLOR},
|
||||
|
@ -50,7 +50,7 @@ const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types);
|
|||
* Get the type of variable name.
|
||||
*/
|
||||
inline
|
||||
psycBool psyc_var_is_routing (const char *name, size_t len)
|
||||
PsycBool psyc_var_is_routing (const char *name, size_t len)
|
||||
{
|
||||
size_t cursor = 1;
|
||||
uint8_t i, m = 0;
|
||||
|
@ -91,7 +91,7 @@ psycBool psyc_var_is_routing (const char *name, size_t len)
|
|||
* Get the type of variable name.
|
||||
*/
|
||||
inline
|
||||
psycType psyc_var_type (const char *name, size_t len)
|
||||
PsycType psyc_var_type (const char *name, size_t len)
|
||||
{
|
||||
int8_t m[psyc_var_types_num];
|
||||
return psyc_in_array(psyc_var_types, psyc_var_types_num,
|
||||
|
|
|
@ -13,18 +13,18 @@ int main (int argc, char **argv) {
|
|||
uint8_t verbose = argc > 1;
|
||||
int i, k, n, ret;
|
||||
|
||||
psycParseListState listState;
|
||||
psycList list_text, list_bin;
|
||||
psycString elems_text[NELEMS], elems_bin[NELEMS], elem;
|
||||
PsycParseListState listState;
|
||||
PsycList list_text, list_bin;
|
||||
PsycString elems_text[NELEMS], elems_bin[NELEMS], elem;
|
||||
char buf_text[NELEMS * 200], buf_bin[NELEMS * 200], *elems[NELEMS], **elems2 = NULL;
|
||||
|
||||
struct timeval start, end;
|
||||
|
||||
for (i=0; i<NELEMS; i++)
|
||||
elems_text[i] = (psycString) PSYC_C2STR("1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890");
|
||||
elems_text[i] = (PsycString) PSYC_C2STR("1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890abcdefghijklmnopqrstuvwxyz-._ 1234567890");
|
||||
|
||||
for (i=0; i<NELEMS; i++)
|
||||
elems_bin[i] = (psycString) PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890");
|
||||
elems_bin[i] = (PsycString) PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890");
|
||||
|
||||
list_text = psyc_list_new(elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_NO_LENGTH);
|
||||
list_bin = psyc_list_new(elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
||||
|
|
|
@ -11,9 +11,9 @@ int main (int argc, char **argv)
|
|||
uint8_t verbose = argc > 2 && memchr(argv[2], (int)'v', strlen(argv[2]));
|
||||
int idx, ret;
|
||||
char buffer[2048], oper;
|
||||
psycString name, value, elem;
|
||||
psycParseState state;
|
||||
psycParseListState listState;
|
||||
PsycString name, value, elem;
|
||||
PsycParseState state;
|
||||
PsycParseListState listState;
|
||||
|
||||
if (argc < 2)
|
||||
return -1;
|
||||
|
|
|
@ -24,15 +24,15 @@ uint8_t verbose, stats;
|
|||
uint8_t multiple, single, routing_only, no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
psycParseState parsers[NUM_PARSERS];
|
||||
psycPacket packets[NUM_PARSERS];
|
||||
psycModifier routing[NUM_PARSERS][ROUTING_LINES];
|
||||
psycModifier entity[NUM_PARSERS][ENTITY_LINES];
|
||||
PsycParseState parsers[NUM_PARSERS];
|
||||
PsycPacket packets[NUM_PARSERS];
|
||||
PsycModifier routing[NUM_PARSERS][ROUTING_LINES];
|
||||
PsycModifier entity[NUM_PARSERS][ENTITY_LINES];
|
||||
|
||||
int contbytes, exit_code;
|
||||
|
||||
static inline
|
||||
void resetString (psycString *s, uint8_t freeptr);
|
||||
void resetString (PsycString *s, uint8_t freeptr);
|
||||
|
||||
// initialize parser & packet variables
|
||||
void test_init (int i) {
|
||||
|
@ -40,9 +40,9 @@ void test_init (int i) {
|
|||
psyc_parse_state_init(&parsers[i], routing_only ?
|
||||
PSYC_PARSE_ROUTING_ONLY : PSYC_PARSE_ALL);
|
||||
|
||||
memset(&packets[i], 0, sizeof(psycPacket));
|
||||
memset(&routing[i], 0, sizeof(psycModifier) * ROUTING_LINES);
|
||||
memset(&entity[i], 0, sizeof(psycModifier) * ENTITY_LINES);
|
||||
memset(&packets[i], 0, sizeof(PsycPacket));
|
||||
memset(&routing[i], 0, sizeof(PsycModifier) * ROUTING_LINES);
|
||||
memset(&entity[i], 0, sizeof(PsycModifier) * ENTITY_LINES);
|
||||
packets[i].routing.modifiers = routing[i];
|
||||
packets[i].entity.modifiers = entity[i];
|
||||
}
|
||||
|
@ -63,14 +63,14 @@ int test_input (int i, char *recvbuf, size_t nbytes) {
|
|||
* to this function together with the new data.
|
||||
*/
|
||||
|
||||
psycParseState *parser = &parsers[i];
|
||||
psycPacket *packet = &packets[i];
|
||||
PsycParseState *parser = &parsers[i];
|
||||
PsycPacket *packet = &packets[i];
|
||||
|
||||
char oper;
|
||||
psycString name, value, elem;
|
||||
psycString *pname = NULL, *pvalue = NULL;
|
||||
psycModifier *mod = NULL;
|
||||
psycParseListState listState;
|
||||
PsycString name, value, elem;
|
||||
PsycString *pname = NULL, *pvalue = NULL;
|
||||
PsycModifier *mod = NULL;
|
||||
PsycParseListState listState;
|
||||
size_t len;
|
||||
|
||||
// Set buffer with data for the parser.
|
||||
|
@ -308,7 +308,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) {
|
|||
}
|
||||
|
||||
static inline
|
||||
void resetString (psycString *s, uint8_t freeptr)
|
||||
void resetString (PsycString *s, uint8_t freeptr)
|
||||
{
|
||||
if (freeptr && s->length)
|
||||
free((void*)s->ptr);
|
||||
|
|
|
@ -23,7 +23,7 @@ uint8_t verbose, stats;
|
|||
uint8_t routing_only;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
psycParseState parser;
|
||||
PsycParseState parser;
|
||||
|
||||
void test_init (int i) {
|
||||
psyc_parse_state_init(&parser, routing_only ?
|
||||
|
@ -32,7 +32,7 @@ void test_init (int i) {
|
|||
|
||||
int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||
char oper;
|
||||
psycString name, value;
|
||||
PsycString name, value;
|
||||
int ret;
|
||||
|
||||
psyc_parse_buffer_set(&parser, recvbuf, nbytes);
|
||||
|
|
|
@ -11,12 +11,12 @@ int testPresence (const char *avail, int availlen,
|
|||
const char *desc, int desclen,
|
||||
const char *rendered, uint8_t verbose)
|
||||
{
|
||||
psycModifier routing[] = {
|
||||
PsycModifier routing[] = {
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
|
||||
PSYC_MODIFIER_ROUTING),
|
||||
};
|
||||
|
||||
psycModifier entity[] = {
|
||||
PsycModifier entity[] = {
|
||||
// presence is to be assigned permanently in distributed state
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_degree_availability"),
|
||||
avail, availlen, PSYC_MODIFIER_CHECK_LENGTH),
|
||||
|
@ -24,7 +24,7 @@ int testPresence (const char *avail, int availlen,
|
|||
desc, desclen, PSYC_MODIFIER_CHECK_LENGTH),
|
||||
};
|
||||
|
||||
psycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
||||
PsycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
||||
entity, PSYC_NUM_ELEM(entity),
|
||||
PSYC_C2ARG("_notice_presence"),
|
||||
NULL, 0,
|
||||
|
@ -39,26 +39,26 @@ int testPresence (const char *avail, int availlen,
|
|||
|
||||
int testList (const char *rendered, uint8_t verbose)
|
||||
{
|
||||
psycModifier routing[] = {
|
||||
PsycModifier routing[] = {
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
|
||||
PSYC_MODIFIER_ROUTING),
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
|
||||
PSYC_MODIFIER_ROUTING),
|
||||
};
|
||||
|
||||
psycString elems_text[] = {
|
||||
PsycString elems_text[] = {
|
||||
PSYC_C2STR("foo"),
|
||||
PSYC_C2STR("bar"),
|
||||
PSYC_C2STR("baz"),
|
||||
};
|
||||
|
||||
psycString elems_bin[] = {
|
||||
PsycString elems_bin[] = {
|
||||
PSYC_C2STR("foo"),
|
||||
PSYC_C2STR("b|r"),
|
||||
PSYC_C2STR("baz\nqux"),
|
||||
};
|
||||
|
||||
psycList list_text, list_bin;
|
||||
PsycList list_text, list_bin;
|
||||
list_text = psyc_list_new(elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_CHECK_LENGTH);
|
||||
list_bin = psyc_list_new(elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
||||
|
||||
|
@ -66,14 +66,14 @@ int testList (const char *rendered, uint8_t verbose)
|
|||
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
||||
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
||||
|
||||
psycModifier entity[] = {
|
||||
PsycModifier entity[] = {
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_list_text"),
|
||||
buf_text, list_text.length, list_text.flag),
|
||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_list_binary"),
|
||||
buf_bin, list_bin.length, list_bin.flag),
|
||||
};
|
||||
|
||||
psycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
||||
PsycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
||||
entity, PSYC_NUM_ELEM(entity),
|
||||
PSYC_C2ARG("_test_list"),
|
||||
PSYC_C2ARG("list test"),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
uint8_t verbose;
|
||||
|
||||
psycTextValueRC getValueFooBar (const char *name, size_t len, psycString *value, void *extra)
|
||||
PsycTextValueRC getValueFooBar (const char *name, size_t len, PsycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -16,7 +16,7 @@ psycTextValueRC getValueFooBar (const char *name, size_t len, psycString *value,
|
|||
return PSYC_TEXT_VALUE_FOUND;
|
||||
}
|
||||
|
||||
psycTextValueRC getValueEmpty (const char *name, size_t len, psycString *value, void *extra)
|
||||
PsycTextValueRC getValueEmpty (const char *name, size_t len, PsycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
|
@ -25,18 +25,18 @@ psycTextValueRC getValueEmpty (const char *name, size_t len, psycString *value,
|
|||
return PSYC_TEXT_VALUE_FOUND;
|
||||
}
|
||||
|
||||
psycTextValueRC getValueNotFound (const char *name, size_t len, psycString *value, void *extra)
|
||||
PsycTextValueRC getValueNotFound (const char *name, size_t len, PsycString *value, void *extra)
|
||||
{
|
||||
if (verbose)
|
||||
printf("> getValue: %.*s\n", (int)len, name);
|
||||
return PSYC_TEXT_VALUE_NOT_FOUND;
|
||||
}
|
||||
|
||||
int testText (char *template, size_t tmplen, char *buffer, size_t buflen, psycString *result, psycTextCB getValue)
|
||||
int testText (char *template, size_t tmplen, char *buffer, size_t buflen, PsycString *result, PsycTextCB getValue)
|
||||
{
|
||||
psycTextState state;
|
||||
PsycTextState state;
|
||||
size_t length = 0;
|
||||
psycTextRC ret;
|
||||
PsycTextRC ret;
|
||||
|
||||
psyc_text_state_init(&state, template, tmplen, buffer, buflen);
|
||||
do
|
||||
|
@ -71,7 +71,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
verbose = argc > 1;
|
||||
char buffer[BUFSIZE];
|
||||
psycString result;
|
||||
PsycString result;
|
||||
|
||||
char *str = "Hello [_foo] & [_bar]!";
|
||||
size_t len = strlen(str);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
void
|
||||
testUniform (char *str, int ret) {
|
||||
psycUniform *uni = malloc(sizeof(psycUniform));
|
||||
memset(uni, 0, sizeof(psycUniform));
|
||||
PsycUniform *uni = malloc(sizeof(PsycUniform));
|
||||
memset(uni, 0, sizeof(PsycUniform));
|
||||
printf("%s\n", str);
|
||||
int r = psyc_uniform_parse(uni, str, strlen(str));
|
||||
|
||||
|
|
Loading…
Reference in a new issue