Asterisk - The Open Source Telephony Project GIT-master-0bf3178
app_reload.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2021, Naveen Albert
5 *
6 * Naveen Albert <asterisk@phreaknet.org>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief Reload Asterisk modules
22 *
23 * \author Naveen Albert <asterisk@phreaknet.org>
24 *
25 * \ingroup applications
26 */
27
28/*** MODULEINFO
29 <support_level>extended</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include "asterisk/logger.h"
35#include "asterisk/channel.h"
36#include "asterisk/pbx.h"
37#include "asterisk/module.h"
38#include "asterisk/app.h"
39
40/*** DOCUMENTATION
41 <application name="Reload" language="en_US">
42 <since>
43 <version>16.20.0</version>
44 <version>18.6.0</version>
45 <version>19.0.0</version>
46 </since>
47 <synopsis>
48 Reloads an Asterisk module, blocking the channel until the reload has completed.
49 </synopsis>
50 <syntax>
51 <parameter name="module" required="false">
52 <para>The full name(s) of the target module(s) or resource(s) to reload.
53 If omitted, everything will be reloaded.</para>
54 <para>The full names MUST be specified (e.g. <literal>chan_iax2</literal>
55 to reload IAX2 or <literal>pbx_config</literal> to reload the dialplan.</para>
56 </parameter>
57 </syntax>
58 <description>
59 <para>Reloads the specified (or all) Asterisk modules and reports success or failure.
60 Success is determined by each individual module, and if all reloads are successful,
61 that is considered an aggregate success. If multiple modules are specified and any
62 module fails, then FAILURE will be returned. It is still possible that other modules
63 did successfully reload, however.</para>
64 <para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para>
65 <variablelist>
66 <variable name="RELOADSTATUS">
67 <value name="SUCCESS">
68 Specified module(s) reloaded successfully.
69 </value>
70 <value name="FAILURE">
71 Some or all of the specified modules failed to reload.
72 </value>
73 </variable>
74 </variablelist>
75 </description>
76 </application>
77 ***/
78
79static char *app = "Reload";
80
81static int reload_exec(struct ast_channel *chan, const char *data)
82{
83 char *targets, *target = NULL;
85
86 targets = ast_strdupa(data);
88 if (ast_strlen_zero(targets)) { /* Reload everything */
89 res = ast_module_reload(targets);
90 } else {
91 while((target = ast_strsep(&targets, ',', AST_STRSEP_ALL))) {
92 res |= ast_module_reload(target);
93 }
94 }
96
97 if (res == AST_MODULE_RELOAD_SUCCESS) {
98 pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS");
99 } else {
100 pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE");
101 }
102 return 0;
103}
104
105static int unload_module(void)
106{
108}
109
110static int load_module(void)
111{
113}
114
static int reload_exec(struct ast_channel *chan, const char *data)
Definition: app_reload.c:81
static char * app
Definition: app_reload.c:79
static int load_module(void)
Definition: app_reload.c:110
static int unload_module(void)
Definition: app_reload.c:105
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Reload module(s)")
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
General Asterisk PBX channel definitions.
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
Support for logging to various files, console and syslog Configuration in file logger....
Asterisk module definitions.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
ast_module_reload_result
Possible return types for ast_module_reload.
Definition: module.h:109
@ AST_MODULE_RELOAD_SUCCESS
Definition: module.h:110
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Definition: loader.c:1721
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
@ AST_STRSEP_ALL
Definition: strings.h:258
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition: utils.c:1835
Main Channel structure associated with a channel.