/* * Launch a Manager Event * * Copyright (c) 2004-2007 Anthony Minessale II * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include static char *tdesc = "Event Application"; static char *app = "Event"; static char *synopsis = "Sends an Event from the dialplan or AGI\n\n" "Usage: Event(Event=MyEvent|Name=fred|Info=${EXTEN})\n" "Headers and thier values are up to you.\n" "The Flag: header actually can control which channel the event comes in on\n" "One of (system,call,log,verbose,command,agent,user)\n"; STANDARD_LOCAL_USER; LOCAL_USER_DECL; static int event_exec(struct ast_channel *chan, void *data) { int res=0; struct localuser *u; char event_data[1024]; char tmp[256]; char event[256]; char *stack; char *var, *val; int ok=0 , flag = EVENT_FLAG_USER; memset(event_data, 0, sizeof(event_data)); if (!data) { ast_log(LOG_WARNING, "event requires an argument\n"); return -1; } LOCAL_USER_ADD(u); stack = (char *) data; val=stack; while(val) { val = strsep(&stack, "|"); if (!val) break; var = strsep(&val, "="); if (!var) break; if (!strcasecmp(var, "event") && val) { strncpy(event, val, sizeof(event)); ok++; } else { if (!strcasecmp(var, "flag") && val) { if (!strcasecmp(val, "system")) { flag = EVENT_FLAG_SYSTEM; } else if (!strcasecmp(val, "call")) { flag = EVENT_FLAG_CALL; } else if (!strcasecmp(val, "log")) { flag = EVENT_FLAG_LOG; } else if (!strcasecmp(val, "verbose")) { flag = EVENT_FLAG_VERBOSE; } else if (!strcasecmp(val, "command")) { flag = EVENT_FLAG_COMMAND; } else if (!strcasecmp(val, "agent")) { flag = EVENT_FLAG_AGENT; } else { flag = EVENT_FLAG_USER; } } snprintf(tmp, sizeof(tmp), "%s: %s\r\n", var, val); strncat(event_data, tmp, sizeof(event_data)); } } if (!ok) { ast_log(LOG_WARNING, "Event requires at least an Event= arguement\n"); return -1; } manager_event(flag, event, "%sExtension: %s\r\nChannel: %s\r\nUniqueid: %s\r\n", event_data, chan->exten, chan->name, chan->uniqueid); LOCAL_USER_REMOVE(u); return res; } int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; return ast_unregister_application(app); } int load_module(void) { return ast_register_application(app, event_exec, tdesc, synopsis); } char *description(void) { return tdesc; } int usecount(void) { int res; STANDARD_USECOUNT(res); return res; } char *key() { return ASTERISK_GPL_KEY; }