app_stasis.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/stasis.h"
  33. #include "asterisk/stasis_app_impl.h"
  34. /*** DOCUMENTATION
  35. <application name="Stasis" language="en_US">
  36. <synopsis>Invoke an external Stasis application.</synopsis>
  37. <syntax>
  38. <parameter name="app_name" required="true">
  39. <para>Name of the application to invoke.</para>
  40. </parameter>
  41. <parameter name="args">
  42. <para>Optional comma-delimited arguments for the
  43. application invocation.</para>
  44. </parameter>
  45. </syntax>
  46. <description>
  47. <para>
  48. Invoke a Stasis application.
  49. </para>
  50. </description>
  51. </application>
  52. ***/
  53. /*! \brief Maximum number of arguments for the Stasis dialplan application */
  54. #define MAX_ARGS 128
  55. /*! \brief Dialplan application name */
  56. static const char *stasis = "Stasis";
  57. /*! /brief Stasis dialplan application callback */
  58. static int app_exec(struct ast_channel *chan, const char *data)
  59. {
  60. char *parse = NULL;
  61. AST_DECLARE_APP_ARGS(args,
  62. AST_APP_ARG(app_name);
  63. AST_APP_ARG(app_argv)[MAX_ARGS];
  64. );
  65. ast_assert(chan != NULL);
  66. ast_assert(data != NULL);
  67. /* parse the arguments */
  68. parse = ast_strdupa(data);
  69. AST_STANDARD_APP_ARGS(args, parse);
  70. if (args.argc < 1) {
  71. ast_log(LOG_WARNING, "Stasis app_name argument missing\n");
  72. return -1;
  73. }
  74. return stasis_app_exec(
  75. chan, args.app_name, args.argc - 1, args.app_argv);
  76. }
  77. static int load_module(void)
  78. {
  79. int r = 0;
  80. stasis_app_ref();
  81. r |= ast_register_application_xml(stasis, app_exec);
  82. return r;
  83. }
  84. static int unload_module(void)
  85. {
  86. int r = 0;
  87. r |= ast_unregister_application(stasis);
  88. stasis_app_unref();
  89. return r;
  90. }
  91. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
  92. .load = load_module,
  93. .unload = unload_module,
  94. .nonoptreq = "res_stasis",
  95. );