Index: apps/app_manager.c =================================================================== --- apps/app_manager.c (revision 0) +++ apps/app_manager.c (revision 0) @@ -0,0 +1,152 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2005, Anthony Minessale II + * + * Anthony Minessale II + * + * Donated by Sangoma Technologies + * + * 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. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +#include +#include +#include + +#include "asterisk.h" + +#include "asterisk/logger.h" +#include "asterisk/module.h" +#include "asterisk/manager.h" +#include "asterisk/pbx.h" +#include "asterisk/strings.h" + +struct event_pair { + + char *key; + char *value; + struct event_pair *next; +}; + +static char *tdesc = "Manager Related Functions"; + +static char *descrip = +" CustomManagerEvent(key:value[|key:value....]): Send custom event through manager interface," +"the arguments must in pairs, first is key, second is value" +; + +LOCAL_USER_DECL; + +static char *app = "ManagerEvent"; +static char *synopsis = "Send Custom Event through manager interface"; + +static void constuct_event(char * eventstr, size_t count, struct event_pair *pairs) +{ + struct event_pair *p = pairs; + while(p && count > 0) { + snprintf(eventstr, count, "%s: %s\r\n", p->key, p->value); + size_t size = strlen(eventstr); + count -= size; + eventstr += size; + p = p->next; + } +} +static struct event_pair * new_event_pair(void) +{ + struct event_pair *pair = malloc(sizeof(struct event_pair)); + if(!pair) { + ast_log(LOG_WARNING, "Event pair allocation failed: Out of memory\n"); + return NULL; + } + memset(pair, 0, sizeof(struct event_pair)); + return pair; +} + +static void free_event_pairs(struct event_pair *pairs) +{ + struct event_pair *p = pairs; + while(p) { + pairs = p->next; + free(p); + p = pairs; + } +} +static int event_exec(struct ast_channel *chan, void *data) +{ + char *announce = NULL, *execdata = NULL; + struct event_pair * event_pairs = NULL, *current_pair = NULL, *pair = NULL; + char *key = NULL, *value = NULL; + char buf[1024]; + if (ast_strlen_zero(data)) { + ast_log(LOG_WARNING, "ManagerEvent requires arguments\n"); + return -1; + } + announce = ast_strdupa(data); + if(!announce) { + ast_log(LOG_ERROR, "Out of memory!\n"); + return -1; + } + while(announce) { + execdata = strchr(announce, '|'); + if(execdata) { + *execdata = '\0'; + ++execdata; + } + if((value = strchr(announce, ':'))) { + *value = '\0'; + key = announce; + ++value; + pair = new_event_pair(); + if(pair) { + pair->key = key; + pair->value = value; + if(current_pair) + current_pair->next = pair; + if(!event_pairs) + event_pairs = pair; + current_pair = pair; + } + } else + ast_log(LOG_WARNING, "Custom Manager Event arguments not in pairs!\n"); + announce = execdata; + } + memset(buf, 0, 1024); + constuct_event(buf, 1024, event_pairs); + manager_event(EVENT_FLAG_USER, "Custom", "%s", buf); + free_event_pairs(event_pairs); + return 0; +} + +int load_module(void) +{ + return ast_register_application(app, event_exec, synopsis, descrip); +} + +int unload_module(void) +{ + return ast_unregister_application(app); +} +char *description(void) +{ + return tdesc; +} +int usecount(void) +{ + int res; + STANDARD_USECOUNT(res); + return res; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} Index: apps/Makefile =================================================================== --- apps/Makefile (revision 83381) +++ apps/Makefile (working copy) @@ -29,7 +29,7 @@ app_dumpchan.so app_waitforsilence.so app_while.so app_setrdnis.so \ app_md5.so app_readfile.so app_chanspy.so app_settransfercapability.so \ app_dictate.so app_externalivr.so app_directed_pickup.so \ - app_mixmonitor.so app_stack.so + app_mixmonitor.so app_stack.so app_manager.c # # Obsolete things...