diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-05-20 13:29:22 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-05-20 13:29:22 +0000 |
commit | 27c5f21d71c3a6b55066375583d18b00dd69fffb (patch) | |
tree | 1626ecb40c5f155ff2b0df4fa2a8d4f5d5623d4b /apps/app_userevent.c | |
parent | 83b19113e394a32562a6bbc92d816f61aeb1bc6a (diff) |
- add a UserEvent action that allows a manager client to "broadcast" an event
to all connected manager clients
- update the UserEvent application to use the application argument parsing
macros and to allow headers to be specified as pipe delimeted arguments
(issue #5324, original patch by outtolunc, committed patch by Corydon)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@29017 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_userevent.c')
-rw-r--r-- | apps/app_userevent.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/apps/app_userevent.c b/apps/app_userevent.c index 8d2586779..78cc22775 100644 --- a/apps/app_userevent.c +++ b/apps/app_userevent.c @@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/pbx.h" #include "asterisk/module.h" #include "asterisk/manager.h" +#include "asterisk/app.h" static char *tdesc = "Custom User Event Application"; @@ -46,24 +47,27 @@ static char *app = "UserEvent"; static char *synopsis = "Send an arbitrary event to the manager interface"; static char *descrip = -" UserEvent(eventname[|body]): Sends an arbitrary event to the\n" -"manager interface, with an optional body representing additional\n" -"arguments. The format of the event will be:\n" -" Event: UserEvent<specified event name>\n" -" Channel: <channel name>\n" -" Uniqueid: <call uniqueid>\n" +" UserEvent(eventname[|body]): Sends an arbitrary event to the manager\n" +"interface, with an optional body representing additional arguments. The\n" +"body may be specified as a | delimeted list of headers. Each additional\n" +"argument will be placed on a new line in the event. The format of the\n" +"event will be:\n" +" Event: UserEvent\n" +" UserEvent: <specified event name>\n" " [body]\n" -"If the body is not specified, only Event, Channel, and Uniqueid fields\n" -"will be present. Returns 0."; +"If no body is specified, only Event and UserEvent headers will be present.\n"; LOCAL_USER_DECL; static int userevent_exec(struct ast_channel *chan, void *data) { struct localuser *u; - char *info; - char eventname[512]; - char *eventbody; + char *parse, buf[2048] = ""; + int x, buflen = 0; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(eventname); + AST_APP_ARG(extra)[100]; + ); if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n"); @@ -72,26 +76,19 @@ static int userevent_exec(struct ast_channel *chan, void *data) LOCAL_USER_ADD(u); - info = ast_strdupa(data); + parse = ast_strdupa(data); - snprintf(eventname, sizeof(eventname), "UserEvent%s", info); - eventbody = strchr(eventname, '|'); - if (eventbody) { - *eventbody = '\0'; - eventbody++; - } - - if(eventbody) { - ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody); - manager_event(EVENT_FLAG_USER, eventname, - "Channel: %s\r\nUniqueid: %s\r\n%s\r\n", - chan->name, chan->uniqueid, eventbody); - } else { - ast_log(LOG_DEBUG, "Sending user event: %s\n", eventname); - manager_event(EVENT_FLAG_USER, eventname, - "Channel: %s\r\nUniqueid: %s\r\n", chan->name, chan->uniqueid); + AST_STANDARD_APP_ARGS(args, parse); + + for (x = 0; x < args.argc - 1; x++) { + ast_copy_string(buf + buflen, args.extra[x], sizeof(buf) - buflen - 2); + buflen += strlen(args.extra[x]); + ast_copy_string(buf + buflen, "\r\n", 3); + buflen += 2; } + manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s\r\n", args.eventname, buf); + LOCAL_USER_REMOVE(u); return 0; } |