2011-05-06 20:15:37 +00:00
|
|
|
#ifdef USE_PSYC
|
2011-05-08 19:05:54 +00:00
|
|
|
# ifndef PKG_PSYC_H
|
2011-05-06 20:15:37 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2011-05-12 14:40:45 +00:00
|
|
|
# include <psyc/packet.h>
|
2011-05-09 19:33:45 +00:00
|
|
|
# include <psyc/parse.h>
|
2011-05-06 20:15:37 +00:00
|
|
|
|
2011-05-08 19:05:54 +00:00
|
|
|
# include "array.h"
|
|
|
|
# include "xalloc.h"
|
|
|
|
|
2011-05-12 11:54:56 +00:00
|
|
|
# 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
|
|
|
|
|
2011-05-22 22:55:39 +00:00
|
|
|
# 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-05-10 12:09:32 +00:00
|
|
|
psycParseState *parser;
|
|
|
|
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
|
|
|
|
2011-05-12 14:40:45 +00:00
|
|
|
typedef struct psyc_modifier_s {
|
|
|
|
psycHeader *header;
|
2011-05-20 08:36:18 +00:00
|
|
|
p_int num_values;
|
2011-05-12 14:40:45 +00:00
|
|
|
psycModifierFlag flag;
|
|
|
|
} psyc_modifier_t;
|
|
|
|
|
2011-05-06 20:15:37 +00:00
|
|
|
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-05-06 20:15:37 +00:00
|
|
|
}
|
2011-04-26 08:02:17 +00:00
|
|
|
|
2011-05-08 19:05:54 +00:00
|
|
|
# define PKG_PSYC_H
|
|
|
|
# endif
|
2011-05-06 20:15:37 +00:00
|
|
|
#endif
|