parser/expat: reduce code duplication

This commit is contained in:
Dmitry Podgorny
2015-12-21 13:46:51 +02:00
parent 6f612d4f4d
commit 38545af533

View File

@@ -109,41 +109,27 @@ static void _start_element(void *userdata,
parser->startcb((char *)name, (char **)attrs, parser->startcb((char *)name, (char **)attrs,
parser->userdata); parser->userdata);
} else { } else {
/* build stanzas at depth 1 */ /* build stanzas at depth 1 */
if (!parser->stanza && parser->depth != 1) { if (!parser->stanza && parser->depth != 1) {
/* something terrible happened */ /* something terrible happened */
/* FIXME: shutdown disconnect */ /* FIXME: shutdown disconnect */
xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?"); xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
} else if (!parser->stanza) { } else {
/* starting a new toplevel stanza */ child = xmpp_stanza_new(parser->ctx);
parser->stanza = xmpp_stanza_new(parser->ctx); if (!child) {
if (!parser->stanza) { /* FIXME: can't allocate, disconnect */
/* FIXME: can't allocate, disconnect */ }
} xmpp_stanza_set_name(child, name);
xmpp_stanza_set_name(parser->stanza, name); _set_attributes(child, attrs);
_set_attributes(parser->stanza, attrs); if (ns)
if (ns) xmpp_stanza_set_ns(child, ns);
xmpp_stanza_set_ns(parser->stanza, ns);
} else {
/* starting a child of parser->stanza */
child = xmpp_stanza_new(parser->ctx);
if (!child) {
/* FIXME: can't allocate, disconnect */
}
xmpp_stanza_set_name(child, name);
_set_attributes(child, attrs);
if (ns)
xmpp_stanza_set_ns(child, ns);
/* add child to parent */ if (parser->stanza != NULL) {
xmpp_stanza_add_child(parser->stanza, child); xmpp_stanza_add_child(parser->stanza, child);
xmpp_stanza_release(child);
/* the child is owned by the toplevel stanza now */ }
xmpp_stanza_release(child); parser->stanza = child;
}
/* make child the current stanza */
parser->stanza = child;
}
} }
if (ns) xmpp_free(parser->ctx, ns); if (ns) xmpp_free(parser->ctx, ns);