- 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: https://origsvn.digium.com/svn/asterisk/trunk@29017 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2006-05-20 13:29:22 +00:00
parent db55898c0d
commit 9d53a3e7f5
3 changed files with 56 additions and 28 deletions

View File

@@ -127,6 +127,11 @@ Manager:
call. This is useful when trying to link recording filenames back to call. This is useful when trying to link recording filenames back to
a particular call from the queue. a particular call from the queue.
* app_userevent has been modified to always send Event: UserEvent with the
additional header UserEvent: <userspec>. Also, the Channel and UniqueID
headers are not automatically sent, unless you specify them as separate
arguments. Please see the application help for the new syntax.
Variables: Variables:
* The builtin variables ${CALLERID}, ${CALLERIDNAME}, ${CALLERIDNUM}, * The builtin variables ${CALLERID}, ${CALLERIDNAME}, ${CALLERIDNUM},

View File

@@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pbx.h" #include "asterisk/pbx.h"
#include "asterisk/module.h" #include "asterisk/module.h"
#include "asterisk/manager.h" #include "asterisk/manager.h"
#include "asterisk/app.h"
static char *tdesc = "Custom User Event Application"; 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 *synopsis = "Send an arbitrary event to the manager interface";
static char *descrip = static char *descrip =
" UserEvent(eventname[|body]): Sends an arbitrary event to the\n" " UserEvent(eventname[|body]): Sends an arbitrary event to the manager\n"
"manager interface, with an optional body representing additional\n" "interface, with an optional body representing additional arguments. The\n"
"arguments. The format of the event will be:\n" "body may be specified as a | delimeted list of headers. Each additional\n"
" Event: UserEvent<specified event name>\n" "argument will be placed on a new line in the event. The format of the\n"
" Channel: <channel name>\n" "event will be:\n"
" Uniqueid: <call uniqueid>\n" " Event: UserEvent\n"
" UserEvent: <specified event name>\n"
" [body]\n" " [body]\n"
"If the body is not specified, only Event, Channel, and Uniqueid fields\n" "If no body is specified, only Event and UserEvent headers will be present.\n";
"will be present. Returns 0.";
LOCAL_USER_DECL; LOCAL_USER_DECL;
static int userevent_exec(struct ast_channel *chan, void *data) static int userevent_exec(struct ast_channel *chan, void *data)
{ {
struct localuser *u; struct localuser *u;
char *info; char *parse, buf[2048] = "";
char eventname[512]; int x, buflen = 0;
char *eventbody; AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(eventname);
AST_APP_ARG(extra)[100];
);
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n"); 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); LOCAL_USER_ADD(u);
info = ast_strdupa(data); parse = ast_strdupa(data);
snprintf(eventname, sizeof(eventname), "UserEvent%s", info); AST_STANDARD_APP_ARGS(args, parse);
eventbody = strchr(eventname, '|');
if (eventbody) { for (x = 0; x < args.argc - 1; x++) {
*eventbody = '\0'; ast_copy_string(buf + buflen, args.extra[x], sizeof(buf) - buflen - 2);
eventbody++; buflen += strlen(args.extra[x]);
} ast_copy_string(buf + buflen, "\r\n", 3);
buflen += 2;
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);
} }
manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s\r\n", args.eventname, buf);
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return 0; return 0;
} }

View File

@@ -1631,6 +1631,31 @@ static int process_events(struct mansession *s)
return ret; return ret;
} }
static char mandescr_userevent[] =
"Description: Send an event to manager sessions.\n"
"Variables: (Names marked with * are required)\n"
" *UserEvent: EventStringToSend\n"
" Header1: Content1\n"
" HeaderN: ContentN\n";
static int action_userevent(struct mansession *s, struct message *m)
{
char *event = astman_get_header(m, "UserEvent");
char body[2048] = "";
int x, bodylen = 0;
for (x = 0; x < m->hdrcount; x++) {
if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
bodylen += strlen(m->headers[x]);
ast_copy_string(body + bodylen, "\r\n", 3);
bodylen += 2;
}
}
manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, body);
return 0;
}
static int process_message(struct mansession *s, struct message *m) static int process_message(struct mansession *s, struct message *m)
{ {
char action[80] = ""; char action[80] = "";
@@ -2327,6 +2352,7 @@ int init_manager(void)
ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus ); ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus );
ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount ); ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount );
ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands); ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands);
ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent);
ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent); ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent);
ast_cli_register(&show_mancmd_cli); ast_cli_register(&show_mancmd_cli);