app_celgenuserevent.c 2.4 KB

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