1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

added @ op & _table type; number, index & keyword parsing

This commit is contained in:
tg(x) 2011-11-21 16:00:46 +01:00
parent 42c2709378
commit 2e242d4f47
7 changed files with 165 additions and 135 deletions

View file

@ -70,6 +70,7 @@ typedef enum {
PSYC_TYPE_UNKNOWN, PSYC_TYPE_UNKNOWN,
PSYC_TYPE_AMOUNT, PSYC_TYPE_AMOUNT,
PSYC_TYPE_COLOR, PSYC_TYPE_COLOR,
PSYC_TYPE_COUNTER,
PSYC_TYPE_DATE, PSYC_TYPE_DATE,
PSYC_TYPE_DEGREE, PSYC_TYPE_DEGREE,
PSYC_TYPE_ENTITY, PSYC_TYPE_ENTITY,
@ -78,8 +79,9 @@ typedef enum {
PSYC_TYPE_LIST, PSYC_TYPE_LIST,
PSYC_TYPE_NICK, PSYC_TYPE_NICK,
PSYC_TYPE_PAGE, PSYC_TYPE_PAGE,
PSYC_TYPE_UNIFORM, PSYC_TYPE_TABLE,
PSYC_TYPE_TIME, PSYC_TYPE_TIME,
PSYC_TYPE_UNIFORM,
} PsycType; } PsycType;
/** /**

View file

@ -57,6 +57,7 @@ typedef enum {
PSYC_OPERATOR_ASSIGN = '=', PSYC_OPERATOR_ASSIGN = '=',
PSYC_OPERATOR_AUGMENT = '+', PSYC_OPERATOR_AUGMENT = '+',
PSYC_OPERATOR_DIMINISH = '-', PSYC_OPERATOR_DIMINISH = '-',
PSYC_OPERATOR_UPDATE = '@',
PSYC_OPERATOR_QUERY = '?', PSYC_OPERATOR_QUERY = '?',
} PsycOperator; } PsycOperator;
@ -92,13 +93,13 @@ typedef struct {
typedef struct { typedef struct {
PsycHeader routing; ///< Routing header. PsycHeader routing; ///< Routing header.
PsycHeader entity; ///< Entity header. PsycHeader entity; ///< Entity header.
char stateop; ///< State operation. @see PsycStateOp
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 routinglen; ///< Length of routing part.
size_t contentLength; ///< Length of content part. size_t contentlen; ///< Length of content part.
size_t length; ///< Total length of packet. size_t length; ///< Total length of packet.
PsycStateOp stateop; ///< State operation. @see PsycStateOp
PsycPacketFlag flag; ///< Packet flag. PsycPacketFlag flag; ///< Packet flag.
} PsycPacket; } PsycPacket;

View file

@ -260,13 +260,13 @@ typedef struct {
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 routinglen; ///< Length of routing part parsed so far.
size_t contentParsed; ///< Number of bytes parsed from the content so far. size_t content_parsed; ///< Number of bytes parsed from the content so far.
size_t contentLength; ///< Expected length of the content. size_t contentlen; ///< Expected length of the content.
PsycBool contentLengthFound;///< Is there a length given for this packet? PsycBool contentlen_found; ///< Is there a length given for this packet?
size_t valueParsed; ///< Number of bytes parsed from the value so far. size_t value_parsed; ///< Number of bytes parsed from the value so far.
size_t valueLength; ///< Expected length of the value. size_t valuelen; ///< Expected length of the value.
PsycBool valueLengthFound; ///< Is there a length given for this modifier? PsycBool valuelen_found; ///< Is there a length given for this modifier?
} PsycParseState; } PsycParseState;
/** /**
@ -280,8 +280,8 @@ typedef struct {
char term; ///< Terminator character at the end. char term; ///< Terminator character at the end.
uint8_t term_set; ///< Look for terminator. uint8_t term_set; ///< Look for terminator.
size_t elemParsed; ///< Number of bytes parsed from the elem so far. size_t elem_parsed; ///< Number of bytes parsed from the elem so far.
size_t elemLength; ///< Expected length of the elem. size_t elemlen; ///< Expected length of the elem.
} PsycParseListState; } PsycParseListState;
/** /**
@ -326,14 +326,14 @@ psyc_parse_state_init (PsycParseState *state, uint8_t flags)
* @see PsycString * @see PsycString
*/ */
static inline void static inline void
psyc_parse_buffer_set (PsycParseState *state, const char *buffer, size_t length) 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) {
state->contentLength = length; state->contentlen = length;
state->contentLengthFound = PSYC_TRUE; state->contentlen_found = PSYC_TRUE;
} }
} }
@ -385,25 +385,25 @@ psyc_parse_table_buffer_set (PsycParseTableState *state, char *buffer, size_t le
static inline size_t static inline size_t
psyc_parse_content_length (PsycParseState *state) psyc_parse_content_length (PsycParseState *state)
{ {
return state->contentLength; return state->contentlen;
} }
static inline PsycBool static inline PsycBool
psyc_parse_content_length_found (PsycParseState *state) psyc_parse_content_length_found (PsycParseState *state)
{ {
return state->contentLengthFound; return state->contentlen_found;
} }
static inline size_t static inline size_t
psyc_parse_value_length (PsycParseState *state) psyc_parse_value_length (PsycParseState *state)
{ {
return state->valueLength; return state->valuelen;
} }
static inline PsycBool static inline PsycBool
psyc_parse_value_length_found (PsycParseState *state) psyc_parse_value_length_found (PsycParseState *state)
{ {
return state->valueLengthFound; return state->valuelen_found;
} }
static inline size_t static inline size_t
@ -473,14 +473,14 @@ psyc_parse_list (PsycParseListState *state, PsycString *elem);
PsycParseTableRC PsycParseTableRC
psyc_parse_table (PsycParseTableState *state, PsycString *elem); psyc_parse_table (PsycParseTableState *state, PsycString *elem);
static inline PsycRC static inline size_t
psyc_parse_number (const char *value, size_t len, int64_t *n) psyc_parse_int (const char *value, size_t len, int64_t *n)
{ {
size_t c = 0; size_t c = 0;
uint8_t neg = 0; uint8_t neg = 0;
if (!value) if (!value)
return PSYC_ERROR; return c;
if (value[0] == '-') if (value[0] == '-')
neg = ++c; neg = ++c;
@ -490,61 +490,54 @@ psyc_parse_number (const char *value, size_t len, int64_t *n)
*n = 10 * *n + (value[c++] - '0'); *n = 10 * *n + (value[c++] - '0');
if (c != len) if (c != len)
return PSYC_ERROR; return c;
if (neg) if (neg)
*n = 0 - *n; *n = 0 - *n;
return PSYC_OK; return c;
} }
static inline PsycRC static inline size_t
psyc_parse_number_unsigned (const char *value, size_t len, uint64_t *n) psyc_parse_uint (const char *value, size_t len, uint64_t *n)
{ {
size_t c = 0; size_t c = 0;
if (!value) if (!value)
return PSYC_ERROR; return c;
*n = 0; *n = 0;
while (c < len && value[c] >= '0' && value[c] <= '9') while (c < len && value[c] >= '0' && value[c] <= '9')
*n = 10 * *n + (value[c++] - '0'); *n = 10 * *n + (value[c++] - '0');
return c == len ? PSYC_OK : PSYC_ERROR; return c;
} }
static inline PsycRC static inline size_t
psyc_parse_time (const char *value, size_t len, time_t *t) psyc_parse_index (const char *value, size_t len, int64_t *n)
{ {
return psyc_parse_number(value, len, t); if (!value || len == 0 || value[0] != '#')
} return 0;
return psyc_parse_int(value + 1, len, n) + 1;
static inline PsycRC
psyc_parse_date (const char *value, size_t len, time_t *t)
{
if (psyc_parse_number(value, len, t)) {
*t += PSYC_EPOCH;
return PSYC_OK;
}
return PSYC_ERROR;
} }
/** /**
* Determines if the argument is a glyph. * Determines if the argument is a glyph.
* Glyphs are: : = + - ? ! * Glyphs are: : = + - ? !
*/ */
static inline char static inline PsycBool
psyc_is_glyph (uint8_t g) psyc_is_glyph (char g)
{ {
switch (g) { switch (g) {
case ':': case ':':
case '=': case '=':
case '+': case '+':
case '-': case '-':
case '@':
case '?': case '?':
case '!': case '!':
return 1; return PSYC_TRUE;
default: default:
return 0; return PSYC_FALSE;
} }
} }
@ -552,7 +545,7 @@ psyc_is_glyph (uint8_t g)
* Determines if the argument is numeric. * Determines if the argument is numeric.
*/ */
static inline char static inline char
psyc_is_numeric (uint8_t c) psyc_is_numeric (char c)
{ {
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
@ -561,7 +554,7 @@ psyc_is_numeric (uint8_t c)
* Determines if the argument is alphabetic. * Determines if the argument is alphabetic.
*/ */
static inline char static inline char
psyc_is_alpha (uint8_t c) psyc_is_alpha (char c)
{ {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
} }
@ -570,7 +563,7 @@ psyc_is_alpha (uint8_t c)
* Determines if the argument is alphanumeric. * Determines if the argument is alphanumeric.
*/ */
static inline char static inline char
psyc_is_alpha_numeric (uint8_t c) psyc_is_alpha_numeric (char c)
{ {
return psyc_is_alpha(c) || psyc_is_numeric(c); return psyc_is_alpha(c) || psyc_is_numeric(c);
} }
@ -580,7 +573,7 @@ psyc_is_alpha_numeric (uint8_t c)
* Keyword characters are: alphanumeric and _ * Keyword characters are: alphanumeric and _
*/ */
static inline char static inline char
psyc_is_kw_char (uint8_t c) psyc_is_kw_char (char c)
{ {
return psyc_is_alpha_numeric(c) || c == '_'; return psyc_is_alpha_numeric(c) || c == '_';
} }
@ -590,7 +583,7 @@ psyc_is_kw_char (uint8_t c)
* Name characters are: see opaque_part in RFC 2396 * Name characters are: see opaque_part in RFC 2396
*/ */
static inline char static inline char
psyc_is_name_char (uint8_t c) psyc_is_name_char (char c)
{ {
return psyc_is_alpha(c) || (c >= '$' && c <= ';') return psyc_is_alpha(c) || (c >= '$' && c <= ';')
|| c == '_' || c == '!' || c == '?' || c == '=' || c == '@' || c == '~'; || c == '_' || c == '!' || c == '?' || c == '=' || c == '@' || c == '~';
@ -601,11 +594,24 @@ psyc_is_name_char (uint8_t c)
* Hostname characters are: alphanumeric and - * Hostname characters are: alphanumeric and -
*/ */
static inline char static inline char
psyc_is_host_char (uint8_t c) psyc_is_host_char (char c)
{ {
return psyc_is_alpha_numeric(c) || c == '.' || c == '-'; return psyc_is_alpha_numeric(c) || c == '.' || c == '-';
} }
/**
* Parse variable name or method name.
* It should contain one or more keyword characters.
* @return Number of characters parsed.
*/
static inline size_t
psyc_parse_keyword (const char *data, size_t len)
{
size_t c = 0;
while (c < len && psyc_is_kw_char(data[c++]));
return c > 0 ? c - 1 : 0;
}
/** @} */ // end of parse group /** @} */ // end of parse group
#endif #endif

View file

@ -95,39 +95,39 @@ inline size_t
psyc_packet_length_set (PsycPacket * p) psyc_packet_length_set (PsycPacket * p)
{ {
size_t i; size_t i;
p->routingLength = 0; p->routinglen = 0;
p->contentLength = 0; p->contentlen = 0;
// add routing header length // add routing header length
for (i = 0; i < p->routing.lines; i++) for (i = 0; i < p->routing.lines; i++)
p->routingLength += psyc_modifier_length(&(p->routing.modifiers[i])); p->routinglen += psyc_modifier_length(&(p->routing.modifiers[i]));
if (p->content.length) if (p->content.length)
p->contentLength = p->content.length; p->contentlen = p->content.length;
else { else {
// add state operation // add state operation
if (p->stateop != PSYC_STATE_NOOP) if (p->stateop != PSYC_STATE_NOOP)
p->contentLength += 2; // op\n p->contentlen += 2; // op\n
// add entity header length // add entity header length
for (i = 0; i < p->entity.lines; i++) for (i = 0; i < p->entity.lines; i++)
p->contentLength += psyc_modifier_length(&(p->entity.modifiers[i])); p->contentlen += psyc_modifier_length(&(p->entity.modifiers[i]));
// add length of method, data & delimiter // add length of method, data & delimiter
if (p->method.length) if (p->method.length)
p->contentLength += p->method.length + 1; // method\n p->contentlen += p->method.length + 1; // method\n
if (p->data.length) if (p->data.length)
p->contentLength += p->data.length + 1; // data\n p->contentlen += p->data.length + 1; // data\n
} }
// set total length: routing-header content |\n // set total length: routing-header content |\n
p->length = p->routingLength + p->contentLength + 2; p->length = p->routinglen + p->contentlen + 2;
if (p->contentLength > 0 || p->flag == PSYC_PACKET_NEED_LENGTH) if (p->contentlen > 0 || p->flag == PSYC_PACKET_NEED_LENGTH)
p->length++; // add \n at the start of the content part p->length++; // add \n at the start of the content part
if (p->flag == PSYC_PACKET_NEED_LENGTH) // add length of length if needed if (p->flag == PSYC_PACKET_NEED_LENGTH) // add length of length if needed
p->length += psyc_num_length(p->contentLength); p->length += psyc_num_length(p->contentlen);
return p->length; return p->length;
} }
@ -140,8 +140,18 @@ psyc_packet_init (PsycPacket * p,
char *data, size_t datalen, char *data, size_t datalen,
char stateop, PsycPacketFlag flag) char stateop, PsycPacketFlag flag)
{ {
*p = (PsycPacket) {{routinglen, routing}, {entitylen, entity}, stateop, *p = (PsycPacket) {
{methodlen, method}, {datalen, data}, {0, 0}, 0, 0, flag}; .routing = {routinglen, routing},
.entity = {entitylen, entity},
.method = {methodlen, method},
.data = {datalen, data},
.content = {0, 0},
.routinglen = 0,
.contentlen = 0,
.length = 0,
.stateop = stateop,
.flag = flag,
};
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length
p->flag = psyc_packet_length_check(p); p->flag = psyc_packet_length_check(p);
@ -155,8 +165,18 @@ psyc_packet_init_raw (PsycPacket * p,
char *content, size_t contentlen, char *content, size_t contentlen,
PsycPacketFlag flag) PsycPacketFlag flag)
{ {
*p = (PsycPacket) {{routinglen, routing}, {0, 0}, 0, {0, 0}, {0, 0}, *p = (PsycPacket) {
{contentlen, content}, 0, 0, flag}; .routing = {routinglen, routing},
.entity = {0, 0},
.method = {0, 0},
.data = {0, 0},
.content = {contentlen, content},
.routinglen = 0,
.contentlen = 0,
.length = 0,
.stateop = 0,
.flag = flag,
};
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length
p->flag = psyc_packet_length_check(p); p->flag = psyc_packet_length_check(p);

View file

@ -29,7 +29,7 @@ typedef enum {
* @return PARSE_ERROR or PARSE_SUCCESS * @return PARSE_ERROR or PARSE_SUCCESS
*/ */
static inline ParseRC static inline ParseRC
psyc_parse_keyword (PsycParseState *state, PsycString *name) parse_keyword (PsycParseState *state, PsycString *name)
{ {
name->data = state->buffer.data + state->cursor; name->data = state->buffer.data + state->cursor;
name->length = 0; name->length = 0;
@ -86,7 +86,7 @@ psyc_parse_modifier (PsycParseState *state, char *oper,
*oper = *(state->buffer.data + state->cursor); *oper = *(state->buffer.data + state->cursor);
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
ParseRC ret = psyc_parse_keyword(state, name); ParseRC ret = parse_keyword(state, name);
if (ret == PARSE_ERROR) if (ret == PARSE_ERROR)
return PSYC_PARSE_ERROR_MOD_NAME; return PSYC_PARSE_ERROR_MOD_NAME;
else if (ret != PARSE_SUCCESS) else if (ret != PARSE_SUCCESS)
@ -94,9 +94,9 @@ psyc_parse_modifier (PsycParseState *state, char *oper,
size_t length = 0; size_t length = 0;
value->length = 0; value->length = 0;
state->valueLength = 0; state->valuelen = 0;
state->valueLengthFound = 0; state->valuelen_found = 0;
state->valueParsed = 0; state->value_parsed = 0;
// Parse the value. // Parse the value.
// If we're in the content part check if it's a binary var. // If we're in the content part check if it's a binary var.
@ -106,13 +106,13 @@ psyc_parse_modifier (PsycParseState *state, char *oper,
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
if (psyc_is_numeric(state->buffer.data[state->cursor])) { if (psyc_is_numeric(state->buffer.data[state->cursor])) {
state->valueLengthFound = 1; state->valuelen_found = 1;
do { do {
length = 10 * length + state->buffer.data[state->cursor] - '0'; length = 10 * length + state->buffer.data[state->cursor] - '0';
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
} }
while (psyc_is_numeric(state->buffer.data[state->cursor])); while (psyc_is_numeric(state->buffer.data[state->cursor]));
state->valueLength = length; state->valuelen = length;
} else } else
return PSYC_PARSE_ERROR_MOD_LEN; return PSYC_PARSE_ERROR_MOD_LEN;
@ -124,8 +124,8 @@ psyc_parse_modifier (PsycParseState *state, char *oper,
return length ? PARSE_INCOMPLETE : PARSE_SUCCESS; // if length=0 we're done return length ? PARSE_INCOMPLETE : PARSE_SUCCESS; // if length=0 we're done
ret = ret =
psyc_parse_binary_value(state, value, &(state->valueLength), psyc_parse_binary_value(state, value, &(state->valuelen),
&(state->valueParsed)); &(state->value_parsed));
if (ret == PARSE_INCOMPLETE) if (ret == PARSE_INCOMPLETE)
return ret; return ret;
@ -170,18 +170,18 @@ psyc_parse (PsycParseState *state, char *oper,
switch (state->part) { switch (state->part) {
case PSYC_PART_RESET: // New packet starts here, reset state. case PSYC_PART_RESET: // New packet starts here, reset state.
state->valueParsed = 0; state->value_parsed = 0;
state->valueLength = 0; state->valuelen = 0;
state->valueLengthFound = 0; state->valuelen_found = 0;
state->routingLength = 0; state->routinglen = 0;
state->contentParsed = 0; state->content_parsed = 0;
state->contentLength = 0; state->contentlen = 0;
state->contentLengthFound = 0; state->contentlen_found = 0;
state->part = PSYC_PART_ROUTING; state->part = PSYC_PART_ROUTING;
// fall thru // fall thru
case PSYC_PART_ROUTING: case PSYC_PART_ROUTING:
if (state->routingLength > 0) { if (state->routinglen > 0) {
if (state->buffer.data[state->cursor] != '\n') if (state->buffer.data[state->cursor] != '\n')
return PSYC_PARSE_ERROR_MOD_NL; return PSYC_PARSE_ERROR_MOD_NL;
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
@ -192,7 +192,7 @@ psyc_parse (PsycParseState *state, char *oper,
if (psyc_is_glyph(state->buffer.data[state->cursor])) { if (psyc_is_glyph(state->buffer.data[state->cursor])) {
// it is a glyph, so a variable starts here // it is a glyph, so a variable starts here
ret = psyc_parse_modifier(state, oper, name, value); ret = psyc_parse_modifier(state, oper, name, value);
state->routingLength += state->cursor - pos; state->routinglen += state->cursor - pos;
return ret == PARSE_SUCCESS ? PSYC_PARSE_ROUTING : ret; return ret == PARSE_SUCCESS ? PSYC_PARSE_ROUTING : ret;
} else { // not a glyph } else { // not a glyph
state->part = PSYC_PART_LENGTH; state->part = PSYC_PART_LENGTH;
@ -203,12 +203,12 @@ psyc_parse (PsycParseState *state, char *oper,
case PSYC_PART_LENGTH: case PSYC_PART_LENGTH:
// End of header, content starts with an optional length then a NL // End of header, content starts with an optional length then a NL
if (psyc_is_numeric(state->buffer.data[state->cursor])) { if (psyc_is_numeric(state->buffer.data[state->cursor])) {
state->contentLengthFound = 1; state->contentlen_found = 1;
state->contentLength = 0; state->contentlen = 0;
do { do {
state->contentLength = state->contentlen =
10 * state->contentLength + 10 * state->contentlen +
state->buffer.data[state->cursor] - '0'; state->buffer.data[state->cursor] - '0';
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
} while (psyc_is_numeric(state->buffer.data[state->cursor])); } while (psyc_is_numeric(state->buffer.data[state->cursor]));
@ -226,7 +226,7 @@ psyc_parse (PsycParseState *state, char *oper,
state->part = PSYC_PART_CONTENT; state->part = PSYC_PART_CONTENT;
} else { // Not start of content, this must be the end. } else { // Not start of content, this must be the end.
// If we have a length then it should've been followed by a \n // If we have a length then it should've been followed by a \n
if (state->contentLengthFound) if (state->contentlen_found)
return PSYC_PARSE_ERROR_LENGTH; return PSYC_PARSE_ERROR_LENGTH;
state->part = PSYC_PART_END; state->part = PSYC_PART_END;
@ -239,10 +239,10 @@ psyc_parse (PsycParseState *state, char *oper,
case PSYC_PART_CONTENT: case PSYC_PART_CONTENT:
// In case of an incomplete binary variable resume parsing it. // In case of an incomplete binary variable resume parsing it.
if (state->valueParsed < state->valueLength) { if (state->value_parsed < state->valuelen) {
ret = psyc_parse_binary_value(state, value, &(state->valueLength), ret = psyc_parse_binary_value(state, value, &(state->valuelen),
&(state->valueParsed)); &(state->value_parsed));
state->contentParsed += value->length; state->content_parsed += value->length;
if (ret == PARSE_INCOMPLETE) if (ret == PARSE_INCOMPLETE)
return PSYC_PARSE_ENTITY_CONT; return PSYC_PARSE_ENTITY_CONT;
@ -252,7 +252,7 @@ psyc_parse (PsycParseState *state, char *oper,
pos = state->cursor; pos = state->cursor;
if (state->contentParsed > 0) { if (state->content_parsed > 0) {
if (state->buffer.data[state->cursor] != '\n') if (state->buffer.data[state->cursor] != '\n')
return PSYC_PARSE_ERROR_MOD_NL; return PSYC_PARSE_ERROR_MOD_NL;
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
@ -264,15 +264,15 @@ psyc_parse (PsycParseState *state, char *oper,
// method does not start with a glyph. // method does not start with a glyph.
if (psyc_is_glyph(state->buffer.data[state->cursor])) { if (psyc_is_glyph(state->buffer.data[state->cursor])) {
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
if (state->contentParsed == 0 if (state->content_parsed == 0
&& state->buffer.data[state->cursor] == '\n') { && state->buffer.data[state->cursor] == '\n') {
*oper = *(state->buffer.data + state->cursor - 1); *oper = *(state->buffer.data + state->cursor - 1);
switch (*oper) { switch (*oper) {
case PSYC_STATE_RESYNC: case PSYC_STATE_RESYNC:
state->contentParsed += 2; state->content_parsed += 2;
return PSYC_PARSE_STATE_RESYNC; return PSYC_PARSE_STATE_RESYNC;
case PSYC_STATE_RESET: case PSYC_STATE_RESET:
state->contentParsed += 2; state->content_parsed += 2;
return PSYC_PARSE_STATE_RESET; return PSYC_PARSE_STATE_RESET;
default: default:
return PSYC_PARSE_ERROR_MOD_NAME; return PSYC_PARSE_ERROR_MOD_NAME;
@ -281,7 +281,7 @@ psyc_parse (PsycParseState *state, char *oper,
state->cursor--; state->cursor--;
ret = psyc_parse_modifier(state, oper, name, value); ret = psyc_parse_modifier(state, oper, name, value);
state->contentParsed += state->cursor - pos; state->content_parsed += state->cursor - pos;
if (ret == PARSE_INCOMPLETE) if (ret == PARSE_INCOMPLETE)
return PSYC_PARSE_ENTITY_START; return PSYC_PARSE_ENTITY_START;
@ -290,7 +290,7 @@ psyc_parse (PsycParseState *state, char *oper,
return ret; return ret;
} else { } else {
state->contentParsed += state->cursor - pos; state->content_parsed += state->cursor - pos;
state->startc = state->cursor; state->startc = state->cursor;
state->part = PSYC_PART_METHOD; state->part = PSYC_PART_METHOD;
// fall thru // fall thru
@ -298,7 +298,7 @@ psyc_parse (PsycParseState *state, char *oper,
case PSYC_PART_METHOD: case PSYC_PART_METHOD:
pos = state->cursor; pos = state->cursor;
ret = psyc_parse_keyword(state, name); ret = parse_keyword(state, name);
if (ret == PARSE_INSUFFICIENT) if (ret == PARSE_INSUFFICIENT)
return ret; return ret;
@ -307,15 +307,15 @@ psyc_parse (PsycParseState *state, char *oper,
if (state->buffer.data[state->cursor] != '\n') if (state->buffer.data[state->cursor] != '\n')
return PSYC_PARSE_ERROR_METHOD; return PSYC_PARSE_ERROR_METHOD;
state->valueLengthFound = 0; state->valuelen_found = 0;
state->valueParsed = 0; state->value_parsed = 0;
state->valueLength = 0; state->valuelen = 0;
if (state->contentLengthFound) { if (state->contentlen_found) {
// Length found, set start position to the beginning of data. // len found, set start position to the beginning of data.
state->cursor++; state->cursor++;
state->startc = state->cursor; state->startc = state->cursor;
state->contentParsed += state->cursor - pos; state->content_parsed += state->cursor - pos;
state->part = PSYC_PART_DATA; state->part = PSYC_PART_DATA;
} else { // Otherwise keep it at the beginning of method. } else { // Otherwise keep it at the beginning of method.
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
@ -332,25 +332,25 @@ psyc_parse (PsycParseState *state, char *oper,
value->data = state->buffer.data + state->cursor; value->data = state->buffer.data + state->cursor;
value->length = 0; value->length = 0;
if (state->contentLengthFound) { // We know the length of the packet. if (state->contentlen_found) { // We know the length of the packet.
if (!state->valueLengthFound) { // start of data if (!state->valuelen_found) { // start of data
state->valueLengthFound = 1; state->valuelen_found = 1;
state->valueLength = state->contentLength - state->contentParsed; state->valuelen = state->contentlen - state->content_parsed;
if (state->valueLength && !(state->flags & PSYC_PARSE_ROUTING_ONLY)) if (state->valuelen && !(state->flags & PSYC_PARSE_ROUTING_ONLY))
state->valueLength--; // \n at the end is not part of data state->valuelen--; // \n at the end is not part of data
} }
if (state->valueParsed < state->valueLength) { if (state->value_parsed < state->valuelen) {
ret = psyc_parse_binary_value(state, value, &(state->valueLength), ret = psyc_parse_binary_value(state, value, &(state->valuelen),
&(state->valueParsed)); &(state->value_parsed));
state->contentParsed += value->length; state->content_parsed += value->length;
if (ret == PARSE_INCOMPLETE) if (ret == PARSE_INCOMPLETE)
return state->valueParsed == value->length return state->value_parsed == value->length
? PSYC_PARSE_BODY_START : PSYC_PARSE_BODY_CONT; ? PSYC_PARSE_BODY_START : PSYC_PARSE_BODY_CONT;
} }
state->part = PSYC_PART_END; state->part = PSYC_PART_END;
return state->valueLength == value->length ? return state->valuelen == value->length ?
PSYC_PARSE_BODY : PSYC_PARSE_BODY_END; PSYC_PARSE_BODY : PSYC_PARSE_BODY_END;
} else { // Search for the terminator. } else { // Search for the terminator.
size_t datac = state->cursor; // start of data size_t datac = state->cursor; // start of data
@ -373,7 +373,7 @@ psyc_parse (PsycParseState *state, char *oper,
if (state->flags & PSYC_PARSE_ROUTING_ONLY) if (state->flags & PSYC_PARSE_ROUTING_ONLY)
value->length++; value->length++;
state->contentParsed += state->cursor - pos; state->content_parsed += state->cursor - pos;
state->cursor += nl; state->cursor += nl;
state->part = PSYC_PART_END; state->part = PSYC_PART_END;
return PSYC_PARSE_BODY; return PSYC_PARSE_BODY;
@ -387,15 +387,15 @@ psyc_parse (PsycParseState *state, char *oper,
case PSYC_PART_END: case PSYC_PART_END:
PSYC_PART_END: PSYC_PART_END:
// if data was not empty next is the \n at the end of data // if data was not empty next is the \n at the end of data
if (state->contentLengthFound && state->valueLengthFound if (state->contentlen_found && state->valuelen_found
&& state->valueLength && !(state->flags & PSYC_PARSE_ROUTING_ONLY)) { && state->valuelen && !(state->flags & PSYC_PARSE_ROUTING_ONLY)) {
state->valueLength = 0; state->valuelen = 0;
state->valueLengthFound = 0; state->valuelen_found = 0;
if (state->buffer.data[state->cursor] != '\n') if (state->buffer.data[state->cursor] != '\n')
return PSYC_PARSE_ERROR_END; return PSYC_PARSE_ERROR_END;
state->contentParsed++; state->content_parsed++;
state->cursor++; state->cursor++;
} }
// End of packet, at this point we have already passed a \n // End of packet, at this point we have already passed a \n
@ -465,12 +465,12 @@ psyc_parse_list (PsycParseListState *state, PsycString *elem)
state->cursor++; state->cursor++;
return PSYC_PARSE_LIST_ELEM; return PSYC_PARSE_LIST_ELEM;
} else { // binary list } else { // binary list
if (!(state->elemParsed < state->elemLength)) { if (!(state->elem_parsed < state->elemlen)) {
// Element starts with a number. // Element starts with a number.
if (psyc_is_numeric(state->buffer.data[state->cursor])) { if (psyc_is_numeric(state->buffer.data[state->cursor])) {
do { do {
state->elemLength = state->elemlen =
10 * state->elemLength + 10 * state->elemlen +
state->buffer.data[state->cursor] - '0'; state->buffer.data[state->cursor] - '0';
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_LIST_INCOMPLETE); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_LIST_INCOMPLETE);
} while (psyc_is_numeric(state->buffer.data[state->cursor])); } while (psyc_is_numeric(state->buffer.data[state->cursor]));
@ -483,16 +483,16 @@ psyc_parse_list (PsycParseListState *state, PsycString *elem)
state->cursor++; state->cursor++;
elem->data = state->buffer.data + state->cursor; elem->data = state->buffer.data + state->cursor;
elem->length = 0; elem->length = 0;
state->elemParsed = 0; state->elem_parsed = 0;
} }
// Start or resume parsing the binary data // Start or resume parsing the binary data
if (state->elemParsed < state->elemLength) { if (state->elem_parsed < state->elemlen) {
if (PARSE_INCOMPLETE == psyc_parse_binary_value((PsycParseState*)state, if (PARSE_INCOMPLETE == psyc_parse_binary_value((PsycParseState*)state,
elem, &state->elemLength, elem, &state->elemlen,
&state->elemParsed)) &state->elem_parsed))
return PSYC_PARSE_LIST_INCOMPLETE; return PSYC_PARSE_LIST_INCOMPLETE;
state->elemLength = 0; state->elemlen = 0;
if (state->cursor >= state->buffer.length) if (state->cursor >= state->buffer.length)
return PSYC_PARSE_LIST_END; return PSYC_PARSE_LIST_END;

View file

@ -84,7 +84,7 @@ psyc_render (PsycPacket * packet, char *buffer, size_t buflen)
// add length if needed // add length if needed
if (packet->flag == PSYC_PACKET_NEED_LENGTH) if (packet->flag == PSYC_PACKET_NEED_LENGTH)
cur += itoa(packet->contentLength, buffer + cur, 10); cur += itoa(packet->contentlen, buffer + cur, 10);
if (packet->flag == PSYC_PACKET_NEED_LENGTH || packet->content.length if (packet->flag == PSYC_PACKET_NEED_LENGTH || packet->content.length
|| packet->stateop || packet->entity.lines || packet->stateop || packet->entity.lines

View file

@ -38,8 +38,9 @@ const PsycDictInt psyc_var_types[] = {
{PSYC_C2STRI("_list"), PSYC_TYPE_LIST}, {PSYC_C2STRI("_list"), PSYC_TYPE_LIST},
{PSYC_C2STRI("_nick"), PSYC_TYPE_NICK}, {PSYC_C2STRI("_nick"), PSYC_TYPE_NICK},
{PSYC_C2STRI("_page"), PSYC_TYPE_PAGE}, {PSYC_C2STRI("_page"), PSYC_TYPE_PAGE},
{PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM}, {PSYC_C2STRI("_table"), PSYC_TYPE_TABLE},
{PSYC_C2STRI("_time"), PSYC_TYPE_TIME}, {PSYC_C2STRI("_time"), PSYC_TYPE_TIME},
{PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM},
}; };
const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars); const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars);