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: 253349 $")
00027
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <unistd.h>
00032
00033 #include "asterisk/lock.h"
00034 #include "asterisk/file.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/manager.h"
00040 #include "asterisk/app.h"
00041
00042 static char *app = "UserEvent";
00043
00044 static char *synopsis = "Send an arbitrary event to the manager interface";
00045
00046 static char *descrip =
00047 " UserEvent(eventname[|body]): Sends an arbitrary event to the manager\n"
00048 "interface, with an optional body representing additional arguments. The\n"
00049 "body may be specified as a | delimited list of headers. Each additional\n"
00050 "argument will be placed on a new line in the event. The format of the\n"
00051 "event will be:\n"
00052 " Event: UserEvent\n"
00053 " UserEvent: <specified event name>\n"
00054 " [body]\n"
00055 "If no body is specified, only Event and UserEvent headers will be present.\n";
00056
00057
00058 static int userevent_exec(struct ast_channel *chan, void *data)
00059 {
00060 struct ast_module_user *u;
00061 char *parse, buf[2048] = "";
00062 int x, buflen = 0, xlen;
00063 AST_DECLARE_APP_ARGS(args,
00064 AST_APP_ARG(eventname);
00065 AST_APP_ARG(extra)[100];
00066 );
00067
00068 if (ast_strlen_zero(data)) {
00069 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n");
00070 return -1;
00071 }
00072
00073 u = ast_module_user_add(chan);
00074
00075 parse = ast_strdupa(data);
00076
00077 AST_STANDARD_APP_ARGS(args, parse);
00078
00079 for (x = 0; x < args.argc - 1; x++) {
00080
00081 if (sizeof(buf) <= buflen + (xlen = strlen(args.extra[x])) + 3) {
00082 ast_log(LOG_WARNING, "UserEvent exceeds our buffer length! Truncating.\n");
00083 break;
00084 }
00085 ast_copy_string(buf + buflen, args.extra[x], sizeof(buf) - buflen - 3);
00086 buflen += xlen;
00087 ast_copy_string(buf + buflen, "\r\n", 3);
00088 buflen += 2;
00089 }
00090
00091 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, buf);
00092
00093 ast_module_user_remove(u);
00094
00095 return 0;
00096 }
00097
00098 static int unload_module(void)
00099 {
00100 int res;
00101
00102 res = ast_unregister_application(app);
00103
00104 ast_module_user_hangup_all();
00105
00106 return res;
00107 }
00108
00109 static int load_module(void)
00110 {
00111 return ast_register_application(app, userevent_exec, synopsis, descrip);
00112 }
00113
00114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");