2004-06-21 23:00:00 +00:00
|
|
|
/*
|
2005-09-15 15:44:26 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-06-21 23:00:00 +00:00
|
|
|
*
|
2005-09-15 15:44:26 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2004-06-21 23:00:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-15 15:44:26 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-15 15:44:26 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief UserEvent application -- send manager event
|
2005-09-15 15:44:26 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2004-06-21 23:00:00 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-15 15:44:26 +00:00
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <stdio.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <string.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <unistd.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/manager.h"
|
2004-06-21 23:00:00 +00:00
|
|
|
|
|
|
|
static char *tdesc = "Custom User Event Application";
|
|
|
|
|
|
|
|
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"
|
|
|
|
" [body]\n"
|
|
|
|
"If the body is not specified, only Event, Channel, and Uniqueid fields\n"
|
|
|
|
"will be present. Returns 0.";
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int userevent_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
struct localuser *u;
|
2005-10-19 18:19:02 +00:00
|
|
|
char *info;
|
|
|
|
char eventname[512];
|
2004-06-21 23:00:00 +00:00
|
|
|
char *eventbody;
|
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2004-06-21 23:00:00 +00:00
|
|
|
ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
2006-01-21 20:57:06 +00:00
|
|
|
if (!(info = ast_strdupa(data))) {
|
2006-01-21 17:50:04 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2004-10-24 03:17:37 +00:00
|
|
|
snprintf(eventname, sizeof(eventname), "UserEvent%s", info);
|
2004-06-21 23:00:00 +00:00
|
|
|
eventbody = strchr(eventname, '|');
|
|
|
|
if (eventbody) {
|
|
|
|
*eventbody = '\0';
|
|
|
|
eventbody++;
|
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2004-06-21 23:00:00 +00:00
|
|
|
if(eventbody) {
|
|
|
|
ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody);
|
2005-09-13 23:36:55 +00:00
|
|
|
manager_event(EVENT_FLAG_USER, eventname,
|
2004-06-21 23:00:00 +00:00
|
|
|
"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);
|
2005-09-13 23:36:55 +00:00
|
|
|
manager_event(EVENT_FLAG_USER, eventname,
|
2004-06-21 23:00:00 +00:00
|
|
|
"Channel: %s\r\nUniqueid: %s\r\n", chan->name, chan->uniqueid);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int unload_module(void *mod)
|
2004-06-21 23:00:00 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2004-06-21 23:00:00 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2004-06-21 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static int load_module(void *mod)
|
2004-06-21 23:00:00 +00:00
|
|
|
{
|
|
|
|
return ast_register_application(app, userevent_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *description(void)
|
2004-06-21 23:00:00 +00:00
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
2006-04-14 14:08:19 +00:00
|
|
|
static const char *key(void)
|
2004-06-21 23:00:00 +00:00
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|
2006-04-14 14:08:19 +00:00
|
|
|
|
|
|
|
STD_MOD1;
|