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