00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "asterisk.h"
00025
00026 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 169368 $")
00027
00028 #include "asterisk/pbx.h"
00029 #include "asterisk/module.h"
00030 #include "asterisk/manager.h"
00031 #include "asterisk/app.h"
00032
00033 static char *app = "UserEvent";
00034
00035 static char *synopsis = "Send an arbitrary event to the manager interface";
00036
00037 static char *descrip =
00038 " UserEvent(eventname[,body]): Sends an arbitrary event to the manager\n"
00039 "interface, with an optional body representing additional arguments. The\n"
00040 "body may be specified as a | delimeted list of headers. Each additional\n"
00041 "argument will be placed on a new line in the event. The format of the\n"
00042 "event will be:\n"
00043 " Event: UserEvent\n"
00044 " UserEvent: <specified event name>\n"
00045 " [body]\n"
00046 "If no body is specified, only Event and UserEvent headers will be present.\n";
00047
00048
00049 static int userevent_exec(struct ast_channel *chan, void *data)
00050 {
00051 char *parse;
00052 int x;
00053 AST_DECLARE_APP_ARGS(args,
00054 AST_APP_ARG(eventname);
00055 AST_APP_ARG(extra)[100];
00056 );
00057 struct ast_str *body = ast_str_create(16);
00058
00059 if (ast_strlen_zero(data)) {
00060 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
00061 ast_free(body);
00062 return -1;
00063 }
00064
00065 if (!body) {
00066 ast_log(LOG_WARNING, "Unable to allocate buffer\n");
00067 return -1;
00068 }
00069
00070 parse = ast_strdupa(data);
00071
00072 AST_STANDARD_APP_ARGS(args, parse);
00073
00074 for (x = 0; x < args.argc - 1; x++) {
00075 ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
00076 }
00077
00078 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, body->str);
00079 ast_free(body);
00080
00081 return 0;
00082 }
00083
00084 static int unload_module(void)
00085 {
00086 return ast_unregister_application(app);
00087 }
00088
00089 static int load_module(void)
00090 {
00091 return ast_register_application(app, userevent_exec, synopsis, descrip);
00092 }
00093
00094 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");