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
26 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
28 #include "asterisk/pbx.h"
29 #include "asterisk/module.h"
30 #include "asterisk/manager.h"
31 #include "asterisk/app.h"
33 static char *app
= "UserEvent";
35 static char *synopsis
= "Send an arbitrary event to the manager interface";
37 static char *descrip
=
38 " UserEvent(eventname[,body]): Sends an arbitrary event to the manager\n"
39 "interface, with an optional body representing additional arguments. The\n"
40 "body may be specified as a | delimeted list of headers. Each additional\n"
41 "argument will be placed on a new line in the event. The format of the\n"
44 " UserEvent: <specified event name>\n"
46 "If no body is specified, only Event and UserEvent headers will be present.\n";
49 static int userevent_exec(struct ast_channel
*chan
, void *data
)
51 char *parse
, buf
[2048] = "";
53 AST_DECLARE_APP_ARGS(args
,
54 AST_APP_ARG(eventname
);
55 AST_APP_ARG(extra
)[100];
58 if (ast_strlen_zero(data
)) {
59 ast_log(LOG_WARNING
, "UserEvent requires an argument (eventname,optional event body)\n");
63 parse
= ast_strdupa(data
);
65 AST_STANDARD_APP_ARGS(args
, parse
);
67 for (x
= 0; x
< args
.argc
- 1; x
++) {
68 ast_copy_string(buf
+ buflen
, args
.extra
[x
], sizeof(buf
) - buflen
- 2);
69 buflen
+= strlen(args
.extra
[x
]);
70 ast_copy_string(buf
+ buflen
, "\r\n", 3);
74 manager_event(EVENT_FLAG_USER
, "UserEvent", "UserEvent: %s\r\n%s", args
.eventname
, buf
);
79 static int unload_module(void)
81 return ast_unregister_application(app
);
84 static int load_module(void)
86 return ast_register_application(app
, userevent_exec
, synopsis
, descrip
);
89 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Custom User Event Application");