app_reload.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /*! \file
  19. *
  20. * \brief Reload Asterisk modules
  21. *
  22. * \author Naveen Albert <asterisk@phreaknet.org>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>extended</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. #include "asterisk/logger.h"
  31. #include "asterisk/channel.h"
  32. #include "asterisk/pbx.h"
  33. #include "asterisk/module.h"
  34. #include "asterisk/app.h"
  35. /*** DOCUMENTATION
  36. <application name="Reload" language="en_US">
  37. <since>
  38. <version>16.20.0</version>
  39. <version>18.6.0</version>
  40. <version>19.0.0</version>
  41. </since>
  42. <synopsis>
  43. Reloads an Asterisk module, blocking the channel until the reload has completed.
  44. </synopsis>
  45. <syntax>
  46. <parameter name="module" required="false">
  47. <para>The full name(s) of the target module(s) or resource(s) to reload.
  48. If omitted, everything will be reloaded.</para>
  49. <para>The full names MUST be specified (e.g. <literal>chan_iax2</literal>
  50. to reload IAX2 or <literal>pbx_config</literal> to reload the dialplan.</para>
  51. </parameter>
  52. </syntax>
  53. <description>
  54. <para>Reloads the specified (or all) Asterisk modules and reports success or failure.
  55. Success is determined by each individual module, and if all reloads are successful,
  56. that is considered an aggregate success. If multiple modules are specified and any
  57. module fails, then FAILURE will be returned. It is still possible that other modules
  58. did successfully reload, however.</para>
  59. <para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para>
  60. <variablelist>
  61. <variable name="RELOADSTATUS">
  62. <value name="SUCCESS">
  63. Specified module(s) reloaded successfully.
  64. </value>
  65. <value name="FAILURE">
  66. Some or all of the specified modules failed to reload.
  67. </value>
  68. </variable>
  69. </variablelist>
  70. </description>
  71. </application>
  72. ***/
  73. static char *app = "Reload";
  74. static int reload_exec(struct ast_channel *chan, const char *data)
  75. {
  76. char *targets, *target = NULL;
  77. enum ast_module_reload_result res = AST_MODULE_RELOAD_SUCCESS;
  78. targets = ast_strdupa(data);
  79. ast_autoservice_start(chan);
  80. if (ast_strlen_zero(targets)) { /* Reload everything */
  81. res = ast_module_reload(targets);
  82. } else {
  83. while((target = ast_strsep(&targets, ',', AST_STRSEP_ALL))) {
  84. res |= ast_module_reload(target);
  85. }
  86. }
  87. ast_autoservice_stop(chan);
  88. if (res == AST_MODULE_RELOAD_SUCCESS) {
  89. pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS");
  90. } else {
  91. pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE");
  92. }
  93. return 0;
  94. }
  95. static int unload_module(void)
  96. {
  97. return ast_unregister_application(app);
  98. }
  99. static int load_module(void)
  100. {
  101. return ast_register_application_xml(app, reload_exec);
  102. }
  103. AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Reload module(s)");