app_stasis.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012 - 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  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 Stasis dialplan application.
  21. *
  22. * \author David M. Lee, II <dlee@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <depend>res_stasis</depend>
  26. <support_level>core</support_level>
  27. ***/
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/app.h"
  31. #include "asterisk/module.h"
  32. #include "asterisk/pbx.h"
  33. #include "asterisk/stasis.h"
  34. #include "asterisk/stasis_app_impl.h"
  35. /*** DOCUMENTATION
  36. <application name="Stasis" language="en_US">
  37. <synopsis>Invoke an external Stasis application.</synopsis>
  38. <syntax>
  39. <parameter name="app_name" required="true">
  40. <para>Name of the application to invoke.</para>
  41. </parameter>
  42. <parameter name="args">
  43. <para>Optional comma-delimited arguments for the
  44. application invocation.</para>
  45. </parameter>
  46. </syntax>
  47. <description>
  48. <para>Invoke a Stasis application.</para>
  49. <para>This application will set the following channel variable upon
  50. completion:</para>
  51. <variablelist>
  52. <variable name="STASISSTATUS">
  53. <para>This indicates the status of the execution of the
  54. Stasis application.</para>
  55. <value name="SUCCESS">
  56. The channel has exited Stasis without any failures in
  57. Stasis.
  58. </value>
  59. <value name="FAILED">
  60. A failure occurred when executing the Stasis
  61. The app registry is not instantiated; The app
  62. application. Some (not all) possible reasons for this:
  63. requested is not registered; The app requested is not
  64. active; Stasis couldn't send a start message.
  65. </value>
  66. </variable>
  67. </variablelist>
  68. </description>
  69. </application>
  70. ***/
  71. /*! \brief Maximum number of arguments for the Stasis dialplan application */
  72. #define MAX_ARGS 128
  73. /*! \brief Dialplan application name */
  74. static const char *stasis = "Stasis";
  75. /*! /brief Stasis dialplan application callback */
  76. static int app_exec(struct ast_channel *chan, const char *data)
  77. {
  78. char *parse = NULL;
  79. int ret = -1;
  80. AST_DECLARE_APP_ARGS(args,
  81. AST_APP_ARG(app_name);
  82. AST_APP_ARG(app_argv)[MAX_ARGS];
  83. );
  84. ast_assert(chan != NULL);
  85. ast_assert(data != NULL);
  86. pbx_builtin_setvar_helper(chan, "STASISSTATUS", "");
  87. /* parse the arguments */
  88. parse = ast_strdupa(data);
  89. AST_STANDARD_APP_ARGS(args, parse);
  90. if (args.argc < 1) {
  91. ast_log(LOG_WARNING, "Stasis app_name argument missing\n");
  92. } else {
  93. ret = stasis_app_exec(chan,
  94. args.app_name,
  95. args.argc - 1,
  96. args.app_argv);
  97. }
  98. if (ret == -1) {
  99. pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
  100. } else {
  101. pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS");
  102. }
  103. return ret;
  104. }
  105. static int load_module(void)
  106. {
  107. int r = 0;
  108. stasis_app_ref();
  109. r |= ast_register_application_xml(stasis, app_exec);
  110. return r;
  111. }
  112. static int unload_module(void)
  113. {
  114. int r = 0;
  115. r |= ast_unregister_application(stasis);
  116. stasis_app_unref();
  117. return r;
  118. }
  119. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
  120. .support_level = AST_MODULE_SUPPORT_CORE,
  121. .load = load_module,
  122. .unload = unload_module,
  123. .nonoptreq = "res_stasis",
  124. );