app_userevent.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. *
  18. * \brief UserEvent application -- send manager event
  19. *
  20. * \ingroup applications
  21. */
  22. /*** MODULEINFO
  23. <support_level>core</support_level>
  24. ***/
  25. #include "asterisk.h"
  26. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  27. #include "asterisk/pbx.h"
  28. #include "asterisk/module.h"
  29. #include "asterisk/manager.h"
  30. #include "asterisk/app.h"
  31. /*** DOCUMENTATION
  32. <application name="UserEvent" language="en_US">
  33. <synopsis>
  34. Send an arbitrary event to the manager interface.
  35. </synopsis>
  36. <syntax>
  37. <parameter name="eventname" required="true" />
  38. <parameter name="body" />
  39. </syntax>
  40. <description>
  41. <para>Sends an arbitrary event to the manager interface, with an optional
  42. <replaceable>body</replaceable> representing additional arguments. The
  43. <replaceable>body</replaceable> may be specified as
  44. a <literal>,</literal> delimited list of headers. Each additional
  45. argument will be placed on a new line in the event. The format of the
  46. event will be:</para>
  47. <para> Event: UserEvent</para>
  48. <para> UserEvent: &lt;specified event name&gt;</para>
  49. <para> [body]</para>
  50. <para>If no <replaceable>body</replaceable> is specified, only Event and UserEvent headers will be present.</para>
  51. </description>
  52. </application>
  53. ***/
  54. static char *app = "UserEvent";
  55. static int userevent_exec(struct ast_channel *chan, const char *data)
  56. {
  57. char *parse;
  58. int x;
  59. AST_DECLARE_APP_ARGS(args,
  60. AST_APP_ARG(eventname);
  61. AST_APP_ARG(extra)[100];
  62. );
  63. struct ast_str *body = ast_str_create(16);
  64. if (ast_strlen_zero(data)) {
  65. ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
  66. ast_free(body);
  67. return -1;
  68. }
  69. if (!body) {
  70. ast_log(LOG_WARNING, "Unable to allocate buffer\n");
  71. return -1;
  72. }
  73. parse = ast_strdupa(data);
  74. AST_STANDARD_APP_ARGS(args, parse);
  75. for (x = 0; x < args.argc - 1; x++) {
  76. ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
  77. }
  78. manager_event(EVENT_FLAG_USER, "UserEvent",
  79. "UserEvent: %s\r\n"
  80. "Uniqueid: %s\r\n"
  81. "%s",
  82. args.eventname, chan->uniqueid, ast_str_buffer(body));
  83. ast_free(body);
  84. return 0;
  85. }
  86. static int unload_module(void)
  87. {
  88. return ast_unregister_application(app);
  89. }
  90. static int load_module(void)
  91. {
  92. return ast_register_application_xml(app, userevent_exec);
  93. }
  94. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");