diff --git a/lib/common/output_html.c b/lib/common/output_html.c index fc06641..6127df2 100644 --- a/lib/common/output_html.c +++ b/lib/common/output_html.c @@ -113,18 +113,11 @@ add_error_node(gpointer data, gpointer user_data) { } static void -html_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest) { +finish_reset_common(pcmk__output_t *out, crm_exit_t exit_status, bool print) { private_data_t *priv = out->priv; htmlNodePtr head_node = NULL; htmlNodePtr charset_node = NULL; - /* If root is NULL, html_init failed and we are being called from pcmk__output_free - * in the pcmk__output_new path. - */ - if (priv == NULL || priv->root == NULL) { - return; - } - if (cgi_output && print) { fprintf(out->dest, "Content-Type: text/html\n\n"); } @@ -174,6 +167,20 @@ html_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy if (print) { htmlDocDump(out->dest, priv->root->doc); } +} + +static void +html_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest) { + private_data_t *priv = out->priv; + + /* If root is NULL, html_init failed and we are being called from pcmk__output_free + * in the pcmk__output_new path. + */ + if (priv == NULL || priv->root == NULL) { + return; + } + + finish_reset_common(out, exit_status, print); if (copy_dest != NULL) { *copy_dest = copy_xml(priv->root); @@ -185,8 +192,7 @@ html_reset(pcmk__output_t *out) { CRM_ASSERT(out != NULL); if (out->priv != NULL) { - private_data_t *priv = out->priv; - htmlDocDump(out->dest, priv->root->doc); + finish_reset_common(out, CRM_EX_OK, true); } html_free_priv(out); diff --git a/lib/common/output_xml.c b/lib/common/output_xml.c index 858da3f..b64a71d 100644 --- a/lib/common/output_xml.c +++ b/lib/common/output_xml.c @@ -106,17 +106,10 @@ add_error_node(gpointer data, gpointer user_data) { } static void -xml_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest) { +finish_reset_common(pcmk__output_t *out, crm_exit_t exit_status, bool print) { xmlNodePtr node; private_data_t *priv = out->priv; - /* If root is NULL, xml_init failed and we are being called from pcmk__output_free - * in the pcmk__output_new path. - */ - if (priv == NULL || priv->root == NULL) { - return; - } - if (legacy_xml) { GSList *node = priv->errors; @@ -148,6 +141,20 @@ xml_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_ fprintf(out->dest, "%s", buf); free(buf); } +} + +static void +xml_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest) { + private_data_t *priv = out->priv; + + /* If root is NULL, xml_init failed and we are being called from pcmk__output_free + * in the pcmk__output_new path. + */ + if (priv == NULL || priv->root == NULL) { + return; + } + + finish_reset_common(out, exit_status, print); if (copy_dest != NULL) { *copy_dest = copy_xml(priv->root); @@ -156,15 +163,10 @@ xml_finish(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_ static void xml_reset(pcmk__output_t *out) { - char *buf = NULL; - CRM_ASSERT(out != NULL); if (out->priv != NULL) { - private_data_t *priv = out->priv; - buf = dump_xml_formatted_with_text(priv->root); - fprintf(out->dest, "%s", buf); - free(buf); + finish_reset_common(out, CRM_EX_OK, true); } xml_free_priv(out);