/* create a new parser */ parser_t *parser_new(xmpp_ctx_t *ctx, parser_start_callback startcb, parser_end_callback endcb, parser_stanza_callback stanzacb, void *userdata) { parser_t *parser; parser = xmpp_alloc(ctx, sizeof(parser_t)); if (parser != NULL) { parser->ctx = ctx; parser->xmlctx = NULL; memset(&parser->handlers, 0, sizeof(xmlSAXHandler)); parser->handlers.startElement = _start_element; parser->handlers.endElement = _end_element; parser->handlers.characters = _characters; parser->startcb = startcb; parser->endcb = endcb; parser->stanzacb = stanzacb; parser->userdata = userdata; parser->depth = 0; parser->stanza = NULL; parser_reset(parser); } return parser; }
static int parse_data(const char *data, Parser *parser) { char *ptr; for (ptr = (char *)data; *ptr; ptr++) { switch (parser->lineState) { case STATE_PREFIX: ptr = parse_state_prefix(ptr, parser); break; case STATE_KEY: ptr = parse_state_key(ptr, parser); break; case STATE_VALUE: ptr = parse_state_value(ptr, parser); break; } } if (parser->currItem) { if (parser->lineState == STATE_VALUE) *parser->ptr = '\0'; else parser_reset(parser); } return 1; }
struct parser *new_parser(int sockfd) { char *buf = xmalloc(RECV_BUF_SIZE + 1); struct parser *p = xmalloc(sizeof(struct parser)); p->sockfd = sockfd; p->recv_buf = buf; parser_reset(p); return p; }
static char * parse_state_key(char *ptr, Parser *parser) { ItemNode *item = parser->currItem; switch (*ptr) { case '\r': case '\t': case ' ': break; case '\n': parser_reset(parser); break; case '#': parser_reset(parser); while (*ptr && (*ptr != '\n')) ptr++; ptr--; break; case '.': *parser->ptr = '\0'; strncpy(item->module, item->key, sizeof(item->module)-1); parser->ptr = item->key; while (*ptr == '.') ptr++; if (*ptr != '.') ptr--; break; case '=': parser->lineState = STATE_VALUE; *parser->ptr = '\0'; parser->ptr = item->value; break; default: *parser->ptr++ = *ptr; break; } return ptr; }
parser_t *parser_new(xmpp_ctx_t *ctx, parser_start_callback startcb, parser_end_callback endcb, parser_stanza_callback stanzacb, void *userdata) { parser_t *parser; parser = xmpp_alloc(ctx, sizeof(parser_t)); if (parser != NULL) { parser->ctx = ctx; parser->expat = NULL; parser->startcb = startcb; parser->endcb = endcb; parser->stanzacb = stanzacb; parser->userdata = userdata; parser->depth = 0; parser->stanza = NULL; parser_reset(parser); } return parser; }
/* reset the parser */ void conn_parser_reset(xmpp_conn_t * const conn) { conn->reset_parser = 0; parser_reset(conn->parser); }