Go to the documentation of this file.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: 253346 $")
00027
00028 #include "asterisk/pbx.h"
00029 #include "asterisk/module.h"
00030 #include "asterisk/manager.h"
00031 #include "asterisk/app.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 static char *app = "UserEvent";
00058
00059 static int userevent_exec(struct ast_channel *chan, void *data)
00060 {
00061 char *parse;
00062 int x;
00063 AST_DECLARE_APP_ARGS(args,
00064 AST_APP_ARG(eventname);
00065 AST_APP_ARG(extra)[100];
00066 );
00067 struct ast_str *body = ast_str_create(16);
00068
00069 if (ast_strlen_zero(data)) {
00070 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
00071 ast_free(body);
00072 return -1;
00073 }
00074
00075 if (!body) {
00076 ast_log(LOG_WARNING, "Unable to allocate buffer\n");
00077 return -1;
00078 }
00079
00080 parse = ast_strdupa(data);
00081
00082 AST_STANDARD_APP_ARGS(args, parse);
00083
00084 for (x = 0; x < args.argc - 1; x++) {
00085 ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
00086 }
00087
00088 manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, ast_str_buffer(body));
00089 ast_free(body);
00090
00091 return 0;
00092 }
00093
00094 static int unload_module(void)
00095 {
00096 return ast_unregister_application(app);
00097 }
00098
00099 static int load_module(void)
00100 {
00101 return ast_register_application_xml(app, userevent_exec);
00102 }
00103
00104 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");