psyclpc/src/pkg-psyc.h

54 lines
1.0 KiB
C

#ifdef USE_PSYC
# ifndef PKG_PSYC_H
/* pkg-psyc takes and produces PSYC packets in form
* of an array of mapping, mapping, string and string
* or int* where necessary.
*/
# include <psyc/parse.h>
# include "array.h"
# include "xalloc.h"
enum {
PSYC_ROUTING = 0,
PSYC_ENTITY = 1,
PSYC_METHOD = 2,
PSYC_BODY = 3,
};
typedef struct psyc_state_s {
psycParseState *parser;
vector_t *packet;
// tmp storage for incomplete modifier/body
char oper;
string_t *name;
string_t *value;
size_t value_len;
// tmp storage for remaining unparsed bytes at the end of the buffer
char *remaining;
size_t remaining_len;
} psyc_state_t;
static inline void
psyc_free_state (psyc_state_t *ps) {
if (!ps)
return;
if (ps->name)
pfree((void *) ps->name);
if (ps->value)
pfree((void *) ps->value);
if (ps->remaining)
pfree((void *) ps->remaining);
if (ps->parser)
pfree((void *) ps->parser);
if (ps->packet)
free_array(ps->packet);
memset(ps, 0, sizeof(psyc_state_t));
}
# define PKG_PSYC_H
# endif
#endif