mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
refactoring - renamed functions
This commit is contained in:
parent
0a95b0a518
commit
260bba0c46
37 changed files with 570 additions and 691 deletions
|
@ -27,6 +27,8 @@
|
|||
#define PSYC_S2ARG(str) (str).ptr, (str).length
|
||||
#define PSYC_S2ARG2(str) (str).length, (str).ptr
|
||||
|
||||
#define PSYC_NUM_ELEM(a) (sizeof(a) / sizeof(*(a)))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_FALSE = 0,
|
||||
|
@ -99,22 +101,22 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
psycString name;
|
||||
psycString key;
|
||||
int value;
|
||||
} psycMatchVar;
|
||||
|
||||
/**
|
||||
* Shortcut for creating a psycString.
|
||||
*
|
||||
* @param memory Pointer to the buffer.
|
||||
* @param length Length of that buffer.
|
||||
* @param str Pointer to the buffer.
|
||||
* @param len Length of that buffer.
|
||||
*
|
||||
* @return An instance of the psycString struct.
|
||||
*/
|
||||
static inline
|
||||
psycString psyc_newString (const char *str, size_t slen)
|
||||
psycString psyc_string_new (char *str, size_t len)
|
||||
{
|
||||
psycString s = {slen, str};
|
||||
psycString s = {len, str};
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -124,81 +126,39 @@ unsigned int psyc_version ()
|
|||
return 1;
|
||||
}
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
extern const psycString psyc_routingVars[];
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
extern const psycMatchVar psyc_varTypes[];
|
||||
|
||||
extern const size_t psyc_routingVarsNum;
|
||||
extern const size_t psyc_varTypesNum;
|
||||
|
||||
/**
|
||||
* Is this a routing variable name?
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
psycBool psyc_isRoutingVar(psycString *name);
|
||||
/**
|
||||
* Is this a routing variable name?
|
||||
*/
|
||||
psycBool psyc_isRoutingVar2(const char *name, size_t len);
|
||||
int psyc_inherits (char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
* Checks if short keyword string matches long keyword string.
|
||||
*/
|
||||
psycType psyc_getVarType(psycString *name);
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
psycType psyc_getVarType2(const char *name, size_t len);
|
||||
int psyc_matches (char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Search for a variable name in an array.
|
||||
* Check if keyword is in array.
|
||||
*
|
||||
* @param array The array to search, should be ordered alphabetically.
|
||||
* @param size Size of array.
|
||||
* @param name Name of variable to look for.
|
||||
* @param namelen Length of name.
|
||||
* @param startswith If true, look for any variable starting with name,
|
||||
* @param kw Keyword to look for.
|
||||
* @param kwlen Length of keyword.
|
||||
* @param inherit If true, also look for anything inheriting from kw,
|
||||
otherwise only exact matches are returned.
|
||||
* @param matching A temporary array used for keeping track of results.
|
||||
* Should be the same size as the array we're searching.
|
||||
*
|
||||
* @return The value of the matched variable in the array.
|
||||
*/
|
||||
int psyc_findVar(const psycMatchVar *array, size_t size,
|
||||
const char *name, size_t namelen,
|
||||
uint8_t startswith, int8_t *matching);
|
||||
|
||||
/**
|
||||
* Is this a list variable name?
|
||||
*/
|
||||
static inline
|
||||
psycBool psyc_isListVar2(const char *name, size_t len)
|
||||
{
|
||||
return len < 5 || memcmp(name, "_list", 5) != 0 ||
|
||||
(len > 5 && name[5] != '_') ? PSYC_FALSE : PSYC_TRUE;
|
||||
}
|
||||
int psyc_in_array (const psycMatchVar *array, size_t size,
|
||||
const char *kw, size_t kwlen,
|
||||
psycBool inherit, int8_t *matching);
|
||||
|
||||
/**
|
||||
* Is this a list variable name?
|
||||
*/
|
||||
static inline
|
||||
psycBool psyc_isListVar(psycString *name)
|
||||
{
|
||||
return psyc_isListVar2(name->ptr, name->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if long keyword string inherits from short keyword string.
|
||||
*/
|
||||
int psyc_inherits(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Checks if short keyword string matches long keyword string.
|
||||
*/
|
||||
int psyc_matches(char *sho, size_t slen,
|
||||
char *lon, size_t llen);
|
||||
#include "psyc/variable.h"
|
||||
|
||||
#define PSYC_H
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <psyc.h>
|
||||
#include <psyc/syntax.h>
|
||||
#include <math.h>
|
||||
|
||||
/** Modifier flags. */
|
||||
typedef enum
|
||||
|
@ -78,7 +79,7 @@ typedef struct
|
|||
psycListFlag flag;
|
||||
} psycList;
|
||||
|
||||
/** intermediate struct for a PSYC packet */
|
||||
/** Intermediate struct for a PSYC packet */
|
||||
typedef struct
|
||||
{
|
||||
psycHeader routing; ///< Routing header.
|
||||
|
@ -92,12 +93,21 @@ typedef struct
|
|||
psycPacketFlag flag; ///< Packet flag.
|
||||
} psycPacket;
|
||||
|
||||
/**
|
||||
* Return the number of digits a number has in its base 10 representation.
|
||||
*/
|
||||
static inline
|
||||
size_t psyc_num_length (size_t n)
|
||||
{
|
||||
return n < 10 ? 1 : log10(n) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Check if a modifier needs length.
|
||||
*/
|
||||
static inline
|
||||
psycModifierFlag psyc_checkModifierLength (psycModifier *m)
|
||||
psycModifierFlag psyc_modifier_length_check (psycModifier *m)
|
||||
{
|
||||
psycModifierFlag flag;
|
||||
|
||||
|
@ -111,85 +121,64 @@ psycModifierFlag psyc_checkModifierLength (psycModifier *m)
|
|||
return flag;
|
||||
}
|
||||
|
||||
/** Create new modifier. */
|
||||
static inline
|
||||
psycModifier psyc_newModifier (char oper, psycString *name, psycString *value,
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
psycModifier m = {oper, *name, *value, flag};
|
||||
|
||||
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
||||
m.flag = psyc_checkModifierLength(&m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/** Create new modifier */
|
||||
static inline
|
||||
psycModifier psyc_newModifier2 (char oper,
|
||||
const char *name, size_t namelen,
|
||||
const char *value, size_t valuelen,
|
||||
psycModifierFlag flag)
|
||||
{
|
||||
psycString n = {namelen, name};
|
||||
psycString v = {valuelen, value};
|
||||
psycModifier psyc_modifier_new (char oper,
|
||||
char *name, size_t namelen,
|
||||
char *value, size_t valuelen,
|
||||
psycModifierFlag flag){
|
||||
|
||||
return psyc_newModifier(oper, &n, &v, 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);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Get the total length of a modifier when rendered.
|
||||
*/
|
||||
size_t psyc_getModifierLength (psycModifier *m);
|
||||
size_t psyc_modifier_length (psycModifier *m);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Check if a list needs length.
|
||||
*/
|
||||
psycListFlag psyc_checkListLength (psycList *list);
|
||||
psycListFlag psyc_list_length_check (psycList *list);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Get the total length of a list when rendered.
|
||||
*/
|
||||
psycListFlag psyc_getListLength (psycList *list);
|
||||
psycListFlag psyc_list_length (psycList *list);
|
||||
|
||||
/**
|
||||
* \internal
|
||||
* Check if a packet needs length.
|
||||
*/
|
||||
psycPacketFlag psyc_checkPacketLength (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_setPacketLength (psycPacket *p);
|
||||
size_t psyc_packet_length_set (psycPacket *p);
|
||||
|
||||
/** Create new list. */
|
||||
psycList psyc_newList (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_newPacket (psycHeader *routing,
|
||||
psycHeader *entity,
|
||||
psycString *method, psycString *data,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** Create new packet. */
|
||||
psycPacket psyc_newPacket2 (psycModifier *routing, size_t routinglen,
|
||||
psycPacket psyc_packet_new (psycModifier *routing, size_t routinglen,
|
||||
psycModifier *entity, size_t entitylen,
|
||||
const char *method, size_t methodlen,
|
||||
const char *data, size_t datalen,
|
||||
char *method, size_t methodlen,
|
||||
char *data, size_t datalen,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** Create new packet with raw content. */
|
||||
psycPacket psyc_newRawPacket (psycHeader *routing, psycString *content,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** Create new packet with raw content. */
|
||||
psycPacket psyc_newRawPacket2 (psycModifier *routing, size_t routinglen,
|
||||
const char *content, size_t contentlen,
|
||||
psycPacketFlag flag);
|
||||
psycPacket psyc_packet_new_raw (psycModifier *routing, size_t routinglen,
|
||||
char *content, size_t contentlen,
|
||||
psycPacketFlag flag);
|
||||
|
||||
/** @} */ // end of packet group
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
* @defgroup parse Parsing Functions
|
||||
*
|
||||
* This module contains packet and list parsing functions.
|
||||
* The parser adheres to the definition of a packet found at
|
||||
*
|
||||
* The parser adheres to the definition of a packet found at
|
||||
*
|
||||
* http://about.psyc.eu/Spec:Packet
|
||||
*
|
||||
* and the according terms are used throughout this documentation and in the
|
||||
|
@ -25,11 +25,10 @@
|
|||
*
|
||||
* @code
|
||||
* psycParseState state;
|
||||
*
|
||||
* psyc_initParseState(&state);
|
||||
* psyc_parse_state_init(&state, flags);
|
||||
* @endcode
|
||||
*
|
||||
* Note that there is also psyc_initParseState2 if you want to fine-tune what
|
||||
* With the flags parameter you can fine-tune what
|
||||
* part of the packet should be parsed. @see psycParseFlag
|
||||
*
|
||||
* Next, you have to tell the parser what it should parse. Assuming the variable
|
||||
|
@ -40,7 +39,7 @@
|
|||
* char* raw_data; // points to our (possibly incomplete) packet
|
||||
* size_t raw_len; // how many bytes of data
|
||||
*
|
||||
* psyc_setParseBuffer(&state, raw_data, raw_len); // state is our initialized state from before
|
||||
* psyc_parse_buffer_set(&state, raw_data, raw_len); // state is our initialized state from before
|
||||
* @endcode
|
||||
*
|
||||
* Now the the variables that will save the output of the parser need to be
|
||||
|
@ -77,7 +76,7 @@
|
|||
* case PSYC_PARSE_ENTITY: // it is a entity variable
|
||||
* // Name, value and operator of the variable can now be found in the
|
||||
* // respective variables:
|
||||
* printf("Variable: %.*s Value: %.*s Operator: %c\n",
|
||||
* printf("Variable: %.*s Value: %.*s Operator: %c\n",
|
||||
* name.length, name.ptr,
|
||||
* value.length, value.ptr,
|
||||
* oper);
|
||||
|
@ -86,7 +85,7 @@
|
|||
* // before passing it to the parser or you copy each variable now.
|
||||
* break;
|
||||
* case PSYC_PARSE_BODY: // it is the method and the body of the packet.
|
||||
* printf("Method Name: %.*s Body: %.*s\n",
|
||||
* printf("Method Name: %.*s Body: %.*s\n",
|
||||
* name.length, name.ptr, // name of the method
|
||||
* value.length, value.ptr); // value of the body
|
||||
* break;
|
||||
|
@ -94,11 +93,11 @@
|
|||
* // You can simply continue parsing till you get the
|
||||
* // PSYC_PARSE_INSUFFICIENT code which means the line is incomplete.
|
||||
* continue;
|
||||
* default: //
|
||||
* default: //
|
||||
* perror("Error %i happened :(\n", res);
|
||||
* return res;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* while (ret > 0)
|
||||
* @endcode
|
||||
*
|
||||
|
@ -193,7 +192,7 @@ typedef enum {
|
|||
|
||||
/**
|
||||
* The return value definitions for the list parsing function.
|
||||
* @see psyc_parseList()
|
||||
* @see psyc_parse_list()
|
||||
*/
|
||||
typedef enum {
|
||||
PSYC_PARSE_LIST_ERROR_DELIM = -4,
|
||||
|
@ -244,24 +243,11 @@ typedef struct {
|
|||
* Initializes the state struct.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initialized.
|
||||
* @see psyc_initParseState2
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseState (psycParseState *state)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the state struct with flags.
|
||||
*
|
||||
* @param state Pointer to the state struct that should be initialized.
|
||||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||
* @see psyc_initParseState
|
||||
* @see psycParseFlag
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseState2 (psycParseState *state, uint8_t flags)
|
||||
void psyc_parse_state_init (psycParseState *state, uint8_t flags)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseState));
|
||||
state->flags = flags;
|
||||
|
@ -277,46 +263,29 @@ void psyc_initParseState2 (psycParseState *state, uint8_t flags)
|
|||
* at the memory pointed to by buffer.
|
||||
*
|
||||
* @param state Pointer to the initialized state of the parser
|
||||
* @param buffer the buffer that should be parsed now
|
||||
* @param buffer pointer to the data that should be parsed
|
||||
* @param length length of the data in bytes
|
||||
* @see psycString
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseBuffer (psycParseState *state, psycString buffer)
|
||||
void psyc_parse_buffer_set (psycParseState *state, char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = buffer;
|
||||
state->buffer = (psycString) {length, buffer};
|
||||
state->cursor = 0;
|
||||
|
||||
if (state->flags & PSYC_PARSE_START_AT_CONTENT) {
|
||||
state->contentLength = buffer.length;
|
||||
state->contentLength = length;
|
||||
state->contentLengthFound = PSYC_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new buffer in the parser state struct with data to be parsed.
|
||||
*
|
||||
* This function does NOT copy the buffer. It will parse whatever is
|
||||
* at the memory pointed to by buffer.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseBuffer2 (psycParseState *state, const char *buffer, size_t length)
|
||||
{
|
||||
psycString buf = {length, buffer};
|
||||
psyc_setParseBuffer(state, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the list state struct.
|
||||
*
|
||||
* @param state Pointer to the list state struct that should be initialized.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initParseListState (psycParseListState *state)
|
||||
void psyc_parse_list_state_init (psycParseListState *state)
|
||||
{
|
||||
memset(state, 0, sizeof(psycParseListState));
|
||||
}
|
||||
|
@ -325,63 +294,56 @@ void psyc_initParseListState (psycParseListState *state)
|
|||
* Sets a new buffer in the list parser state struct with data to be parsed.
|
||||
*/
|
||||
static inline
|
||||
void psyc_setParseListBuffer (psycParseListState *state, psycString buffer)
|
||||
void psyc_parse_list_buffer_set (psycParseListState *state, char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = buffer;
|
||||
state->buffer = (psycString) {length, buffer};
|
||||
state->cursor = 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
void psyc_setParseListBuffer2 (psycParseListState *state, const char *buffer, size_t length)
|
||||
{
|
||||
psycString buf = {length, buffer};
|
||||
psyc_setParseListBuffer(state, buf);
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseContentLength (psycParseState *state)
|
||||
size_t psyc_parse_content_length (psycParseState *state)
|
||||
{
|
||||
return state->contentLength;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_isParseContentLengthFound (psycParseState *state)
|
||||
psycBool psyc_parse_content_length_found (psycParseState *state)
|
||||
{
|
||||
return state->contentLengthFound;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseValueLength (psycParseState *state)
|
||||
size_t psyc_parse_value_length (psycParseState *state)
|
||||
{
|
||||
return state->valueLength;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_isParseValueLengthFound (psycParseState *state)
|
||||
psycBool psyc_parse_value_length_found (psycParseState *state)
|
||||
{
|
||||
return state->valueLengthFound;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseCursor (psycParseState *state)
|
||||
size_t psyc_parse_cursor (psycParseState *state)
|
||||
{
|
||||
return state->cursor;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseBufferLength (psycParseState *state)
|
||||
size_t psyc_parse_buffer_length (psycParseState *state)
|
||||
{
|
||||
return state->buffer.length;
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getParseRemainingLength (psycParseState *state)
|
||||
size_t psyc_parse_remaining_length (psycParseState *state)
|
||||
{
|
||||
return state->buffer.length - state->cursor;
|
||||
}
|
||||
|
||||
static inline
|
||||
const char * psyc_getParseRemainingBuffer (psycParseState *state)
|
||||
const char * psyc_parse_remaining_buffer (psycParseState *state)
|
||||
{
|
||||
return state->buffer.ptr + state->cursor;
|
||||
}
|
||||
|
@ -422,10 +384,10 @@ psycParseRC psyc_parse (psycParseState *state, char *oper,
|
|||
#ifdef __INLINE_PSYC_PARSE
|
||||
static inline
|
||||
#endif
|
||||
psycParseListRC psyc_parseList (psycParseListState *state, psycString *elem);
|
||||
psycParseListRC psyc_parse_list (psycParseListState *state, psycString *elem);
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseNumber2 (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;
|
||||
|
@ -450,45 +412,27 @@ psycBool psyc_parseNumber2 (const char *value, size_t len, ssize_t *n)
|
|||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseNumber (psycString *value, ssize_t *n)
|
||||
psycBool psyc_parse_time (const char *value, size_t len, time_t *t)
|
||||
{
|
||||
return psyc_parseNumber2(value->ptr, value->length, n);
|
||||
return psyc_parse_number(value, len, t);
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseTime2 (const char *value, size_t len, time_t *t)
|
||||
psycBool psyc_parse_date (const char *value, size_t len, time_t *t)
|
||||
{
|
||||
return psyc_parseNumber2(value, len, t);
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseTime (psycString *value, time_t *t)
|
||||
{
|
||||
return psyc_parseNumber2(value->ptr, value->length, t);
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseDate2 (const char *value, size_t len, time_t *t)
|
||||
{
|
||||
if (psyc_parseNumber2(value, len, t)) {
|
||||
if (psyc_parse_number(value, len, t)) {
|
||||
*t += PSYC_EPOCH;
|
||||
return PSYC_TRUE;
|
||||
}
|
||||
return PSYC_FALSE;
|
||||
}
|
||||
|
||||
static inline
|
||||
psycBool psyc_parseDate (psycString *value, time_t *t)
|
||||
{
|
||||
return psyc_parseDate2(value->ptr, value->length, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is a glyph.
|
||||
* Glyphs are: : = + - ? !
|
||||
*/
|
||||
static inline
|
||||
char psyc_isGlyph (uint8_t g)
|
||||
char psyc_is_glyph (uint8_t g)
|
||||
{
|
||||
switch(g) {
|
||||
case ':':
|
||||
|
@ -507,7 +451,7 @@ char psyc_isGlyph (uint8_t g)
|
|||
* Determines if the argument is numeric.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isNumeric (uint8_t c)
|
||||
char psyc_is_numeric (uint8_t c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
@ -516,7 +460,7 @@ char psyc_isNumeric (uint8_t c)
|
|||
* Determines if the argument is alphabetic.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isAlpha (uint8_t c)
|
||||
char psyc_is_alpha (uint8_t c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
@ -525,9 +469,9 @@ char psyc_isAlpha (uint8_t c)
|
|||
* Determines if the argument is alphanumeric.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isAlphaNumeric (uint8_t c)
|
||||
char psyc_is_alpha_numeric (uint8_t c)
|
||||
{
|
||||
return psyc_isAlpha(c) || psyc_isNumeric(c);
|
||||
return psyc_is_alpha(c) || psyc_is_numeric(c);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,9 +479,9 @@ char psyc_isAlphaNumeric (uint8_t c)
|
|||
* Keyword characters are: alphanumeric and _
|
||||
*/
|
||||
static inline
|
||||
char psyc_isKwChar (uint8_t c)
|
||||
char psyc_is_kw_char (uint8_t c)
|
||||
{
|
||||
return psyc_isAlphaNumeric(c) || c == '_';
|
||||
return psyc_is_alpha_numeric(c) || c == '_';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -545,9 +489,9 @@ char psyc_isKwChar (uint8_t c)
|
|||
* Name characters are: see opaque_part in RFC 2396
|
||||
*/
|
||||
static inline
|
||||
char psyc_isNameChar (uint8_t c)
|
||||
char psyc_is_name_char (uint8_t c)
|
||||
{
|
||||
return psyc_isAlpha(c) || (c >= '$' && c <= ';') ||
|
||||
return psyc_is_alpha(c) || (c >= '$' && c <= ';') ||
|
||||
c == '_' || c == '!' || c == '?' || c == '=' || c == '@' || c == '~';
|
||||
}
|
||||
|
||||
|
@ -556,9 +500,9 @@ char psyc_isNameChar (uint8_t c)
|
|||
* Hostname characters are: alphanumeric and -
|
||||
*/
|
||||
static inline
|
||||
char psyc_isHostChar (uint8_t c)
|
||||
char psyc_is_host_char (uint8_t c)
|
||||
{
|
||||
return psyc_isAlphaNumeric(c) || c == '.' || c == '-';
|
||||
return psyc_is_alpha_numeric(c) || c == '.' || c == '-';
|
||||
}
|
||||
|
||||
/** @} */ // end of parse group
|
||||
|
|
|
@ -32,7 +32,7 @@ typedef enum
|
|||
} psycRenderRC;
|
||||
|
||||
/**
|
||||
* Return codes for psyc_renderList.
|
||||
* Return codes for psyc_render_list.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -48,15 +48,13 @@ typedef enum
|
|||
* The packet structure should contain the packet parts, either routing, entity,
|
||||
* method & data, or routing & content when rendering raw content.
|
||||
* It should also contain the contentLength & total length of the packet,
|
||||
* you can use psyc_setPacketLength() for calculating & setting these values.
|
||||
* you can use psyc_packet_length_set() for calculating & setting these values.
|
||||
* This function renders packet->length bytes to the buffer,
|
||||
* if buflen is less than that an error is returned.
|
||||
*
|
||||
* @see psyc_newPacket
|
||||
* @see psyc_newPacket2
|
||||
* @see psyc_newRawPacket
|
||||
* @see psyc_newRawPacket2
|
||||
* @see psyc_setPacketLength
|
||||
* @see psyc_packet_new
|
||||
* @see psyc_packet_new_raw
|
||||
* @see psyc_packet_length_set
|
||||
*/
|
||||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
|
@ -69,7 +67,7 @@ psycRenderRC psyc_render (psycPacket *packet, char *buffer, size_t buflen);
|
|||
#ifdef __INLINE_PSYC_RENDER
|
||||
static inline
|
||||
#endif
|
||||
psycRenderListRC psyc_renderList (psycList *list, char *buffer, size_t buflen);
|
||||
psycRenderListRC psyc_render_list (psycList *list, char *buffer, size_t buflen);
|
||||
|
||||
/** @} */ // end of render group
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *
|
|||
* @param buflen Length of output buffer.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initTextState (psycTextState *state,
|
||||
const char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen)
|
||||
void psyc_text_state_init (psycTextState *state,
|
||||
char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen)
|
||||
{
|
||||
state->cursor = 0;
|
||||
state->written = 0;
|
||||
|
@ -102,11 +102,11 @@ void psyc_initTextState (psycTextState *state,
|
|||
* @param closelen Length of closing brace.
|
||||
*/
|
||||
static inline
|
||||
void psyc_initTextState2 (psycTextState *state,
|
||||
const char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen,
|
||||
const char *open, size_t openlen,
|
||||
const char *close, size_t closelen)
|
||||
void psyc_text_state_init_custom (psycTextState *state,
|
||||
char *tmpl, size_t tmplen,
|
||||
char *buffer, size_t buflen,
|
||||
char *open, size_t openlen,
|
||||
char *close, size_t closelen)
|
||||
{
|
||||
state->cursor = 0;
|
||||
state->written = 0;
|
||||
|
@ -120,25 +120,15 @@ void psyc_initTextState2 (psycTextState *state,
|
|||
* Sets a new output buffer in the PSYC text state struct.
|
||||
*/
|
||||
static inline
|
||||
void psyc_setTextBuffer (psycTextState *state, psycString buffer)
|
||||
void psyc_text_buffer_set (psycTextState *state,
|
||||
char *buffer, size_t length)
|
||||
{
|
||||
state->buffer = buffer;
|
||||
state->buffer = (psycString){length, buffer};
|
||||
state->written = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new buffer in the PSYC text state struct.
|
||||
*/
|
||||
static inline
|
||||
void psyc_setTextBuffer2 (psycTextState *state,
|
||||
char *buffer, size_t length)
|
||||
{
|
||||
psycString buf = {length, buffer};
|
||||
psyc_setTextBuffer(state, buf);
|
||||
}
|
||||
|
||||
static inline
|
||||
size_t psyc_getTextBytesWritten (psycTextState *state)
|
||||
size_t psyc_text_bytes_written (psycTextState *state)
|
||||
{
|
||||
return state->written;
|
||||
}
|
||||
|
@ -151,10 +141,10 @@ size_t psyc_getTextBytesWritten (psycTextState *state)
|
|||
* string between these braces. Should the callback return
|
||||
* PSYC_TEXT_VALUE_NOT_FOUND, the original template text is copied as is.
|
||||
*
|
||||
* Before calling this function psyc_initTextState should be called to initialize
|
||||
* Before calling this function psyc_text_state_init should be called to initialize
|
||||
* the state struct. By default PSYC's "[" and "]" are used but you can provide
|
||||
* any other brace strings such as "${" and "}" or "<!--" and "-->" if you use
|
||||
* the psyc_initTextState2 variant.
|
||||
* the psyc_text_state_init_custom variant.
|
||||
*
|
||||
* @see http://about.psyc.eu/psyctext
|
||||
**/
|
||||
|
|
|
@ -73,9 +73,7 @@ typedef enum {
|
|||
PSYC_ENTITY_SERVICE = '$',
|
||||
} psycEntityType;
|
||||
|
||||
int psyc_parseUniform2(psycUniform *uni, const char *str, size_t length);
|
||||
|
||||
int psyc_parseUniform(psycUniform *uni, psycString *str);
|
||||
int psyc_uniform_parse (psycUniform *uni, char *str, size_t length);
|
||||
|
||||
#define PSYC_UNIFORM_H
|
||||
#endif
|
||||
|
|
37
include/psyc/variable.h
Normal file
37
include/psyc/variable.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef PSYC_VARIABLE_H
|
||||
|
||||
/**
|
||||
* @file psyc/variable.h
|
||||
*/
|
||||
|
||||
/// Routing variables in alphabetical order.
|
||||
extern const psycString psyc_routing_vars[];
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
extern const psycMatchVar psyc_var_types[];
|
||||
|
||||
extern const size_t psyc_routing_vars_num;
|
||||
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);
|
||||
|
||||
/**
|
||||
* Get the type of variable name.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
return len < 5 || memcmp(name, "_list", 5) != 0 ||
|
||||
(len > 5 && name[5] != '_') ? PSYC_FALSE : PSYC_TRUE;
|
||||
}
|
||||
|
||||
#define PSYC_VARIABLE_H
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue