[Asterisk-code-review] xmldoc: Allow XML docs to be reloaded. (asterisk[master])

N A asteriskteam at digium.com
Sat Nov 5 07:12:50 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19474 )


Change subject: xmldoc: Allow XML docs to be reloaded.
......................................................................

xmldoc: Allow XML docs to be reloaded.

The XML docs are currently only loaded on
startup with no way to update them during runtime.
This makes it impossible to load modules that
use ACO/Sorcery (which require documentation).

This adds a CLI command to reload the XML docs
during runtime so that documentation can be updated
without a full restart of Asterisk.

ASTERISK-30289 #close

Change-Id: I4f265b0e5517e757c5453a0f241201a5788d3a07
---
A doc/CHANGES-staging/xmldoc.txt
M main/xmldoc.c
2 files changed, 77 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/19474/1

diff --git a/doc/CHANGES-staging/xmldoc.txt b/doc/CHANGES-staging/xmldoc.txt
new file mode 100644
index 0000000..50324e4
--- /dev/null
+++ b/doc/CHANGES-staging/xmldoc.txt
@@ -0,0 +1,5 @@
+Subject: xmldocs
+
+The XML documentation can now be reloaded without restarting
+Asterisk, which makes it possible to load new modules that
+enforce documentation without restarting Asterisk.
diff --git a/main/xmldoc.c b/main/xmldoc.c
index f924717..565ad59 100644
--- a/main/xmldoc.c
+++ b/main/xmldoc.c
@@ -2860,13 +2860,13 @@
 
 static struct ast_cli_entry cli_dump_xmldocs = AST_CLI_DEFINE(handle_dump_docs, "Dump the XML docs to the specified file");
 
-/*! \brief Close and unload XML documentation. */
-static void xmldoc_unload_documentation(void)
+static char *handle_reload_docs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static struct ast_cli_entry cli_reload_xmldocs = AST_CLI_DEFINE(handle_reload_docs, "Reload the XML docs");
+
+static void xmldoc_purge_documentation(void)
 {
 	struct documentation_tree *doctree;
 
-	ast_cli_unregister(&cli_dump_xmldocs);
-
 	AST_RWLIST_WRLOCK(&xmldoc_tree);
 	while ((doctree = AST_RWLIST_REMOVE_HEAD(&xmldoc_tree, entry))) {
 		ast_free(doctree->filename);
@@ -2874,11 +2874,20 @@
 		ast_free(doctree);
 	}
 	AST_RWLIST_UNLOCK(&xmldoc_tree);
+}
+
+/*! \brief Close and unload XML documentation. */
+static void xmldoc_unload_documentation(void)
+{
+	ast_cli_unregister(&cli_reload_xmldocs);
+	ast_cli_unregister(&cli_dump_xmldocs);
+
+	xmldoc_purge_documentation();
 
 	ast_xml_finish();
 }
 
-int ast_xmldoc_load_documentation(void)
+static int xmldoc_load_documentation(int first_time)
 {
 	struct ast_xml_node *root_node;
 	struct ast_xml_doc *tmpdoc;
@@ -2907,12 +2916,17 @@
 		ast_config_destroy(cfg);
 	}
 
-	/* initialize the XML library. */
-	ast_xml_init();
+	if (first_time) {
+		/* initialize the XML library. */
+		ast_xml_init();
+	}
 
-	ast_cli_register(&cli_dump_xmldocs);
-	/* register function to be run when asterisk finish. */
-	ast_register_cleanup(xmldoc_unload_documentation);
+	if (first_time) {
+		ast_cli_register(&cli_dump_xmldocs);
+		ast_cli_register(&cli_reload_xmldocs);
+		/* register function to be run when asterisk finish. */
+		ast_register_cleanup(xmldoc_unload_documentation);
+	}
 
 	globbuf.gl_offs = 0;    /* slots to reserve in gl_pathv */
 
@@ -2993,4 +3007,32 @@
 	return 0;
 }
 
+int ast_xmldoc_load_documentation(void)
+{
+	return xmldoc_load_documentation(1);
+}
+
+static int xmldoc_reload_documentation(void)
+{
+	xmldoc_purge_documentation();
+	return xmldoc_load_documentation(0);
+}
+
+static char *handle_reload_docs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "xmldoc reload";
+		e->usage =
+			"Usage: xmldoc reload\n"
+			"  Reload XML documentation\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	xmldoc_reload_documentation();
+	return CLI_SUCCESS;
+}
+
 #endif /* AST_XML_DOCS */

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19474
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I4f265b0e5517e757c5453a0f241201a5788d3a07
Gerrit-Change-Number: 19474
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221105/d29d2ef5/attachment-0001.html>


More information about the asterisk-code-review mailing list