Wed Oct 28 11:45:27 2009

Asterisk developer's documentation


app_userevent.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief UserEvent application -- send manager event
00020  * 
00021  * \ingroup applications
00022  */
00023 
00024 #include "asterisk.h"
00025 
00026 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 169366 $")
00027 
00028 #include "asterisk/pbx.h"
00029 #include "asterisk/module.h"
00030 #include "asterisk/manager.h"
00031 #include "asterisk/app.h"
00032 
00033 static char *app = "UserEvent";
00034 
00035 static char *synopsis = "Send an arbitrary event to the manager interface";
00036 
00037 static char *descrip = 
00038 "  UserEvent(eventname[,body]): Sends an arbitrary event to the manager\n"
00039 "interface, with an optional body representing additional arguments.  The\n"
00040 "body may be specified as a | delimeted list of headers. Each additional\n"
00041 "argument will be placed on a new line in the event. The format of the\n"
00042 "event will be:\n"
00043 "    Event: UserEvent\n"
00044 "    UserEvent: <specified event name>\n"
00045 "    [body]\n"
00046 "If no body is specified, only Event and UserEvent headers will be present.\n";
00047 
00048 
00049 static int userevent_exec(struct ast_channel *chan, void *data)
00050 {
00051    char *parse;
00052    int x;
00053    AST_DECLARE_APP_ARGS(args,
00054       AST_APP_ARG(eventname);
00055       AST_APP_ARG(extra)[100];
00056    );
00057    struct ast_str *body = ast_str_create(16);
00058 
00059    if (ast_strlen_zero(data)) {
00060       ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
00061       ast_free(body);
00062       return -1;
00063    }
00064 
00065    if (!body) {
00066       ast_log(LOG_WARNING, "Unable to allocate buffer\n");
00067       return -1;
00068    }
00069 
00070    parse = ast_strdupa(data);
00071 
00072    AST_STANDARD_APP_ARGS(args, parse);
00073 
00074    for (x = 0; x < args.argc - 1; x++) {
00075       ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
00076    }
00077 
00078    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, body->str);
00079    ast_free(body);
00080 
00081    return 0;
00082 }
00083 
00084 static int unload_module(void)
00085 {
00086    return ast_unregister_application(app);
00087 }
00088 
00089 static int load_module(void)
00090 {
00091    return ast_register_application(app, userevent_exec, synopsis, descrip);
00092 }
00093 
00094 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");

Generated on Wed Oct 28 11:45:27 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6