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