[Asterisk-code-review] app_reload: Adds Reload application (asterisk[master])
N A
asteriskteam at digium.com
Wed May 26 12:10:59 CDT 2021
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15952 )
Change subject: app_reload: Adds Reload application
......................................................................
app_reload: Adds Reload application
Adds an application to reload modules
from within the dialplan.
ASTERISK-29454
Change-Id: Ic8ab025d8b38dd525b872b41c465c999c5810774
---
A apps/app_reload.c
A doc/CHANGES-staging/app_reload.txt
2 files changed, 130 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/52/15952/1
diff --git a/apps/app_reload.c b/apps/app_reload.c
new file mode 100644
index 0000000..ec34943
--- /dev/null
+++ b/apps/app_reload.c
@@ -0,0 +1,126 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2021, Naveen Albert
+ *
+ * Naveen Albert <asterisk at phreaknet.org>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Reload Asterisk modules
+ *
+ * \author Naveen Albert <asterisk at phreaknet.org>
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/app.h"
+
+/*** DOCUMENTATION
+ <application name="Reload" language="en_US">
+ <synopsis>
+ Reloads an Asterisk module.
+ </synopsis>
+ <syntax>
+ <parameter name="module" required="false">
+ <para>The full name of the target module or resource to reload.
+ Common aliases such as <literal>dialplan</literal>, <literal>voicemail</literal>,
+ and <literal>moh</literal> may be used. If omitted, everything will be reloaded.</para>
+ </parameter>
+ </syntax>
+ <description>
+ <para>Reloads the specified (or all) Asterisk modules and reports success or failure. Note
+ that if a module is reloaded successfully but there are errors with the configuration,
+ this is considered a success.</para>
+ <para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para>
+ <variablelist>
+ <variable name="RELOADSTATUS">
+ <value name="SUCCESS">
+ Module(s) reloaded.
+ </value>
+ <value name="FAILURE">
+ Intended module(s) not completely reloaded successfully.
+ </value>
+ </variable>
+ </variablelist>
+ </description>
+ </application>
+ ***/
+
+static char *app = "Reload";
+
+static int reload_exec(struct ast_channel *chan, const char *data)
+{
+ char *parse, *target = NULL;
+ enum ast_module_reload_result res;
+
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(target);
+ );
+
+ parse = ast_strdupa(data);
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ target = ast_strdupa(args.target);
+
+ /* Common aliases that will be familiar from the CLI */
+ if (!ast_strlen_zero(target)) {
+ if (!strcmp(target, "dialplan")) {
+ target = "pbx_config";
+ } else if (!strcmp(target, "dahdi")) {
+ target = "chan_dahdi";
+ } else if (!strcmp(target, "sip")) {
+ target = "chan_sip";
+ } else if (!strcmp(target, "pjsip")) {
+ target = "chan_pjsip";
+ } else if (!strcmp(target, "iax2")) {
+ target = "chan_iax2";
+ } else if (!strcmp(target, "voicemail")) {
+ target = "app_voicemail";
+ } else if (!strcmp(target, "moh")) {
+ target = "res_musiconhold";
+ }
+ }
+
+ res = ast_module_reload(target);
+
+ if (res == AST_MODULE_RELOAD_SUCCESS) {
+ pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS");
+ } else {
+ pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE");
+ }
+ return 0;
+}
+
+static int unload_module(void)
+{
+ return ast_unregister_application(app);
+}
+
+static int load_module(void)
+{
+ return ast_register_application_xml(app, reload_exec);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Reload module(s)");
diff --git a/doc/CHANGES-staging/app_reload.txt b/doc/CHANGES-staging/app_reload.txt
new file mode 100644
index 0000000..308db15
--- /dev/null
+++ b/doc/CHANGES-staging/app_reload.txt
@@ -0,0 +1,4 @@
+Subject: New Reload application
+
+Adds an application to reload modules
+
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15952
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ic8ab025d8b38dd525b872b41c465c999c5810774
Gerrit-Change-Number: 15952
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210526/55216bc5/attachment.html>
More information about the asterisk-code-review
mailing list