app_celgenuserevent.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2008, 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 Generate User-Defined CEL event
  19. *
  20. * \author Steve Murphy
  21. *
  22. * \ingroup applications
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/module.h"
  30. #include "asterisk/app.h"
  31. #include "asterisk/channel.h"
  32. #include "asterisk/cel.h"
  33. /*** DOCUMENTATION
  34. <application name="CELGenUserEvent" language="en_US">
  35. <synopsis>
  36. Generates a CEL User Defined Event.
  37. </synopsis>
  38. <syntax>
  39. <parameter name="event-name" required="true">
  40. <argument name="event-name" required="true">
  41. </argument>
  42. <argument name="extra" required="false">
  43. <para>Extra text to be included with the event.</para>
  44. </argument>
  45. </parameter>
  46. </syntax>
  47. <description>
  48. <para>A CEL event will be immediately generated by this channel, with the supplied name for a type.</para>
  49. </description>
  50. </application>
  51. ***/
  52. static char *app = "CELGenUserEvent";
  53. static int celgenuserevent_exec(struct ast_channel *chan, const char *data)
  54. {
  55. int res = 0;
  56. char *parse;
  57. RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
  58. AST_DECLARE_APP_ARGS(args,
  59. AST_APP_ARG(event);
  60. AST_APP_ARG(extra);
  61. );
  62. if (ast_strlen_zero(data)) {
  63. return 0;
  64. }
  65. parse = ast_strdupa(data);
  66. AST_STANDARD_APP_ARGS(args, parse);
  67. blob = ast_json_pack("{s: s, s: {s: s}}",
  68. "event", args.event,
  69. "extra", "extra", S_OR(args.extra, ""));
  70. if (!blob) {
  71. return res;
  72. }
  73. ast_cel_publish_event(chan, AST_CEL_USER_DEFINED, blob);
  74. return res;
  75. }
  76. static int unload_module(void)
  77. {
  78. ast_unregister_application(app);
  79. return 0;
  80. }
  81. static int load_module(void)
  82. {
  83. int res = ast_register_application_xml(app, celgenuserevent_exec);
  84. if (res) {
  85. return AST_MODULE_LOAD_DECLINE;
  86. } else {
  87. return AST_MODULE_LOAD_SUCCESS;
  88. }
  89. }
  90. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Generate an User-Defined CEL event",
  91. .support_level = AST_MODULE_SUPPORT_CORE,
  92. .load = load_module,
  93. .unload = unload_module,
  94. );