00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00031
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/manager.h"
00035 #include "asterisk/app.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 static char *app = "UserEvent";
00062
00063 static int userevent_exec(struct ast_channel *chan, const char *data)
00064 {
00065 char *parse;
00066 int x;
00067 AST_DECLARE_APP_ARGS(args,
00068 AST_APP_ARG(eventname);
00069 AST_APP_ARG(extra)[100];
00070 );
00071 struct ast_str *body = ast_str_create(16);
00072
00073 if (ast_strlen_zero(data)) {
00074 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
00075 ast_free(body);
00076 return -1;
00077 }
00078
00079 if (!body) {
00080 ast_log(LOG_WARNING, "Unable to allocate buffer\n");
00081 return -1;
00082 }
00083
00084 parse = ast_strdupa(data);
00085
00086 AST_STANDARD_APP_ARGS(args, parse);
00087
00088 for (x = 0; x < args.argc - 1; x++) {
00089 ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
00090 }
00091
00092 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, ast_str_buffer(body));
00093 ast_free(body);
00094
00095 return 0;
00096 }
00097
00098 static int unload_module(void)
00099 {
00100 return ast_unregister_application(app);
00101 }
00102
00103 static int load_module(void)
00104 {
00105 return ast_register_application_xml(app, userevent_exec);
00106 }
00107
00108 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");