psyclpc/src/pkg-psyc.h

70 lines
1.5 KiB
C
Raw Normal View History

2011-05-24 14:29:03 +00:00
#ifdef HAS_PSYC
2011-05-08 19:05:54 +00:00
# ifndef PKG_PSYC_H
2011-04-26 08:02:17 +00:00
/* pkg-psyc takes and produces PSYC packets in form
* of an array of mapping, mapping, string and string
* or int* where necessary.
*/
# include <psyc.h>
# include <psyc/packet.h>
2011-05-09 19:33:45 +00:00
# include <psyc/parse.h>
2011-05-08 19:05:54 +00:00
# include "array.h"
# include "xalloc.h"
# define PACKET_ROUTING 0
# define PACKET_ENTITY 1
# define PACKET_METHOD 2
# define PACKET_BODY 3
2011-05-11 15:09:22 +00:00
2011-05-13 21:17:10 +00:00
# define MAX_LIST_SIZE 1024
# define PSYC_PARSE_ERROR_AMOUNT 1
# define PSYC_PARSE_ERROR_DEGREE 2
# define PSYC_PARSE_ERROR_DATE 3
# define PSYC_PARSE_ERROR_TIME 4
# define PSYC_PARSE_ERROR_FLAG 5
# define PSYC_PARSE_ERROR_LIST 6
# define PSYC_PARSE_ERROR_LIST_TOO_LARGE 7
2011-05-09 19:33:45 +00:00
typedef struct psyc_state_s {
2011-11-01 11:27:05 +00:00
PsycParseState *parser;
2011-05-10 12:09:32 +00:00
vector_t *packet;
// tmp storage for incomplete modifier/body
char oper;
2011-05-11 15:09:22 +00:00
string_t *name;
string_t *value;
2011-05-10 12:09:32 +00:00
size_t value_len;
// tmp storage for remaining unparsed bytes at the end of the buffer
char *remaining;
size_t remaining_len;
2011-05-09 19:33:45 +00:00
} psyc_state_t;
2011-05-08 14:58:35 +00:00
typedef struct psyc_modifier_s {
2011-11-01 11:27:05 +00:00
PsycHeader *header;
p_int num_values;
2011-11-01 11:27:05 +00:00
PsycModifierFlag flag;
} psyc_modifier_t;
static inline void
2011-05-09 19:33:45 +00:00
psyc_free_state (psyc_state_t *ps) {
2011-05-10 12:09:32 +00:00
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);
2011-05-10 13:36:31 +00:00
memset(ps, 0, sizeof(psyc_state_t));
}
2011-04-26 08:02:17 +00:00
2011-05-08 19:05:54 +00:00
# define PKG_PSYC_H
# endif
#endif