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

@@ -114,18 +114,7 @@ static void _start_element(void *userdata,
/* 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) {
/* starting a new toplevel stanza */
parser->stanza = xmpp_stanza_new(parser->ctx);
if (!parser->stanza) {
/* FIXME: can't allocate, disconnect */
}
xmpp_stanza_set_name(parser->stanza, name);
_set_attributes(parser->stanza, attrs);
if (ns)
xmpp_stanza_set_ns(parser->stanza, ns);
} else { } else {
/* starting a child of parser->stanza */
child = xmpp_stanza_new(parser->ctx); child = xmpp_stanza_new(parser->ctx);
if (!child) { if (!child) {
/* FIXME: can't allocate, disconnect */ /* FIXME: can't allocate, disconnect */
@@ -135,13 +124,10 @@ static void _start_element(void *userdata,
if (ns) if (ns)
xmpp_stanza_set_ns(child, 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);
/* the child is owned by the toplevel stanza now */
xmpp_stanza_release(child); xmpp_stanza_release(child);
}
/* make child the current stanza */
parser->stanza = child; parser->stanza = child;
} }
} }