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

added support for state sync/reset packets

This commit is contained in:
Gabor Adam Toth 2011-11-09 19:02:21 +01:00
parent 8a9ef74707
commit d2780c0dbf
8 changed files with 47 additions and 27 deletions

View file

@ -109,7 +109,6 @@ void * psyc_dict_lookup (const PsycDict *dict, size_t size,
{
size_t cursor = 1;
uint8_t i, m = 0;
//memset(&matching, -1, sizeof matching);
if (keylen < 2 || key[0] != '_')
return 0;

View file

@ -63,9 +63,9 @@ void psyc_list_init (PsycList *list, PsycString *elems, size_t num_elems,
inline
size_t psyc_modifier_length (PsycModifier *m)
{
size_t length = 1 + // oper
m->name.length + 1 + // name\t
m->value.length + 1; // value\n
size_t length = 2; // oper\n
if (m->name.length > 0)
length += m->name.length + 1 + m->value.length; // name\tvalue
if (m->flag == PSYC_MODIFIER_NEED_LENGTH) // add length of length if needed
length += psyc_num_length(m->value.length) + 1; // SP length

View file

@ -21,7 +21,7 @@ typedef enum {
PARSE_INSUFFICIENT = 1,
PARSE_COMPLETE = 100,
PARSE_INCOMPLETE = 101,
} parseRC;
} ParseRC;
/**
* Parse variable name or method name.
@ -29,7 +29,7 @@ typedef enum {
* @return PARSE_ERROR or PARSE_SUCCESS
*/
static inline
parseRC psyc_parse_keyword (PsycParseState *state, PsycString *name)
ParseRC psyc_parse_keyword (PsycParseState *state, PsycString *name)
{
name->data = state->buffer.data + state->cursor;
name->length = 0;
@ -54,7 +54,7 @@ parseRC psyc_parse_keyword (PsycParseState *state, PsycString *name)
* @return PARSE_COMPLETE or PARSE_INCOMPLETE
*/
static inline
parseRC psyc_parse_binary_value (PsycParseState *state, PsycString *value,
ParseRC psyc_parse_binary_value (PsycParseState *state, PsycString *value,
size_t *length, size_t *parsed)
{
size_t remaining = *length - *parsed;
@ -81,13 +81,16 @@ parseRC psyc_parse_binary_value (PsycParseState *state, PsycString *value,
* @return PARSE_ERROR or PARSE_SUCCESS
*/
static inline
parseRC psyc_parse_modifier (PsycParseState *state, char *oper,
ParseRC psyc_parse_modifier (PsycParseState *state, char *oper,
PsycString *name, PsycString *value)
{
*oper = *(state->buffer.data + state->cursor);
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
parseRC ret = psyc_parse_keyword(state, name);
if (state->part == PSYC_PART_CONTENT && state->buffer.data[state->cursor] == '\n')
return PARSE_SUCCESS; // only oper is present, used for state sync/reset
ParseRC ret = psyc_parse_keyword(state, name);
if (ret == PARSE_ERROR)
return PSYC_PARSE_ERROR_MOD_NAME;
else if (ret != PARSE_SUCCESS)
@ -162,7 +165,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper,
PP(("Invalid flag combination"))
#endif
parseRC ret; // a return value
ParseRC ret; // a return value
size_t pos = state->cursor; // a cursor position
// Start position of the current line in the buffer
@ -326,8 +329,6 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper,
{
ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT);
}
// fall thru
}
else // No method, which means the packet should end now.
{
@ -335,6 +336,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper,
state->startc = state->cursor;
goto PSYC_PART_END;
}
// fall thru
case PSYC_PART_DATA:
PSYC_PART_DATA:

View file

@ -46,12 +46,12 @@ static inline
size_t psyc_render_modifier (PsycModifier *mod, char *buffer)
{
size_t cur = 0;
buffer[cur++] = mod->oper;
if (mod->name.length > 0)
{
memcpy(buffer + cur, mod->name.data, mod->name.length);
cur += mod->name.length;
if (cur <= 1)
return cur; // error, name can't be empty
if (mod->flag == PSYC_MODIFIER_NEED_LENGTH)
{
@ -62,8 +62,9 @@ size_t psyc_render_modifier (PsycModifier *mod, char *buffer)
buffer[cur++] = '\t';
memcpy(buffer + cur, mod->value.data, mod->value.length);
cur += mod->value.length;
buffer[cur++] = '\n';
}
buffer[cur++] = '\n';
return cur;
}

View file

@ -77,7 +77,7 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length)
break;
case PSYC_UNIFORM_PORT:
if (psyc_is_numeric(c)) {
if (psyc_is_numeric(c) || (uni->port.length == 0 && c == '-')) {
uni->port.length++;
break;
}

6
test/packets/00-no-body Normal file
View file

@ -0,0 +1,6 @@
:_source psyc://foo.example.com/
:_target psyc://bar.example.com/
:_foo bar
:_baz qux
|

View file

@ -0,0 +1,7 @@
:_source psyc://foo.example.com/
:_target psyc://bar.example.com/
=
=_foo bar
=_baz qux
|

View file

@ -0,0 +1,5 @@
:_source psyc://foo.example.com/
:_target psyc://bar.example.com/
?
|