2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
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.
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.
19 * \brief UserEvent application -- send manager event
21 * \ingroup applications
25 <support_level>core</support_level>
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/manager.h"
35 #include "asterisk/app.h"
36 #include "asterisk/json.h"
37 #include "asterisk/stasis_channels.h"
40 <application name="UserEvent" language="en_US">
42 Send an arbitrary event to the manager interface.
45 <parameter name="eventname" required="true" />
46 <parameter name="body" />
49 <para>Sends an arbitrary event to the manager interface, with an optional
50 <replaceable>body</replaceable> representing additional arguments. The
51 <replaceable>body</replaceable> may be specified as
52 a <literal>,</literal> delimited list of headers. Each additional
53 argument will be placed on a new line in the event. The format of the
55 <para> Event: UserEvent</para>
56 <para> UserEvent: <specified event name></para>
58 <para>If no <replaceable>body</replaceable> is specified, only Event and UserEvent headers will be present.</para>
63 static char *app = "UserEvent";
65 static int userevent_exec(struct ast_channel *chan, const char *data)
69 AST_DECLARE_APP_ARGS(args,
70 AST_APP_ARG(eventname);
71 AST_APP_ARG(extra)[100];
73 RAII_VAR(struct ast_str *, body, ast_str_create(16), ast_free);
74 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
75 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
77 if (ast_strlen_zero(data)) {
78 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
83 ast_log(LOG_WARNING, "Unable to allocate buffer\n");
87 parse = ast_strdupa(data);
89 AST_STANDARD_APP_ARGS(args, parse);
91 for (x = 0; x < args.argc - 1; x++) {
92 ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
95 blob = ast_json_pack("{s: s, s: s, s: s}",
96 "eventname", args.eventname,
97 "body", ast_str_buffer(body));
99 ast_log(LOG_WARNING, "Unable to create message buffer\n");
103 msg = ast_channel_blob_create(
104 chan, ast_channel_user_event_type(), blob);
109 stasis_publish(ast_channel_topic(chan), msg);
114 static int unload_module(void)
116 return ast_unregister_application(app);
119 static int load_module(void)
121 return ast_register_application_xml(app, userevent_exec);
124 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");