<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9544">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Jenkins2: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">xmldoc.c: Fix dump of xml document<br><br>The "xmldoc dump" cli command was simply concatenating xml documents<br>into the output file. The resulting file had multiple "xml"<br>processing instructions and multiple root elements which is illegal.<br>Normally this isn't an issue because Asterisk has only 1 main xml<br>documentation file but codec_opus has its own file so if it's<br>downloaded and you do "xmldoc dump", the result is invalid.<br><br>* Added 2 new functions to xml.c:<br> ast_xml_copy_node_list creates a copy of a list of children.<br> ast_xml_add_child_list adds a list to an existing list.<br><br>* Modified handle_dump_docs to create a new output document and<br> add to it the children from each input file. It then dumps the<br> new document to the output file.<br><br>Change-Id: I3f182d38c75776aee76413dadd2d489d54a85c07<br>---<br>M include/asterisk/xml.h<br>M main/xml.c<br>M main/xmldoc.c<br>3 files changed, 78 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/xml.h b/include/asterisk/xml.h</span><br><span>index d80fb26..7221558 100644</span><br><span>--- a/include/asterisk/xml.h</span><br><span>+++ b/include/asterisk/xml.h</span><br><span>@@ -83,6 +83,23 @@</span><br><span> struct ast_xml_node *ast_xml_add_child(struct ast_xml_node *parent, struct ast_xml_node *child);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Add a list of child nodes, to a specified parent node.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param parent Where to add the child node.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param child The child list to add.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL on error.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-NULL The added child list on success.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_xml_node *ast_xml_add_child_list(struct ast_xml_node *parent, struct ast_xml_node *child);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Create a copy of a n ode list.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param list The list to copy.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL on error.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-NULL The copied list.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_xml_node *ast_xml_copy_node_list(struct ast_xml_node *list);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Close an already open document and free the used</span><br><span> * structure.</span><br><span> * \retval doc The document reference.</span><br><span>diff --git a/main/xml.c b/main/xml.c</span><br><span>index 1b90aa9..d60dd90 100644</span><br><span>--- a/main/xml.c</span><br><span>+++ b/main/xml.c</span><br><span>@@ -142,6 +142,22 @@</span><br><span> return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_xml_node *ast_xml_add_child_list(struct ast_xml_node *parent, struct ast_xml_node *child)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!parent || !child) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return (struct ast_xml_node *) xmlAddChildList((xmlNode *) parent, (xmlNode *) child);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_xml_node *ast_xml_copy_node_list(struct ast_xml_node *list)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!list) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return (struct ast_xml_node *) xmlCopyNodeList((xmlNode *) list);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size)</span><br><span> {</span><br><span> xmlDoc *doc;</span><br><span>diff --git a/main/xmldoc.c b/main/xmldoc.c</span><br><span>index 7ab27a7..b4649ac 100644</span><br><span>--- a/main/xmldoc.c</span><br><span>+++ b/main/xmldoc.c</span><br><span>@@ -2783,6 +2783,8 @@</span><br><span> static char *handle_dump_docs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span> struct documentation_tree *doctree;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_doc *dumpdoc;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_node *dumproot;</span><br><span> FILE *f;</span><br><span> </span><br><span> switch (cmd) {</span><br><span>@@ -2799,15 +2801,53 @@</span><br><span> if (a->argc != 3) {</span><br><span> return CLI_SHOWUSAGE;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ dumpdoc = ast_xml_new();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dumpdoc) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Could not create new XML document\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ dumproot = ast_xml_new_node("docs");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dumproot) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_close(dumpdoc);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Could not create new XML root node\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_set_root(dumpdoc, dumproot);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_RWLIST_RDLOCK(&xmldoc_tree);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_node *root_node = ast_xml_get_root(doctree->doc);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_node *kids = ast_xml_node_get_children(root_node);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_xml_node *kids_copy;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If there are no kids someone screwed up, but we check anyway. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!kids) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ kids_copy = ast_xml_copy_node_list(kids);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!kids_copy) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_close(dumpdoc);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Could not create copy of XML node list\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_add_child_list(dumproot, kids_copy);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_RWLIST_UNLOCK(&xmldoc_tree);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!(f = fopen(a->argv[2], "w"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_close(dumpdoc);</span><br><span> ast_log(LOG_ERROR, "Could not open file '%s': %s\n", a->argv[2], strerror(errno));</span><br><span> return CLI_FAILURE;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_RWLIST_RDLOCK(&xmldoc_tree);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_xml_doc_dump_file(f, doctree->doc);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_RWLIST_UNLOCK(&xmldoc_tree);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_doc_dump_file(f, dumpdoc);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_xml_close(dumpdoc);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> fclose(f);</span><br><span> return CLI_SUCCESS;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9544">change 9544</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9544"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I3f182d38c75776aee76413dadd2d489d54a85c07 </div>
<div style="display:none"> Gerrit-Change-Number: 9544 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>