Mon Jun 27 16:50:47 2011

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: 253345 $")
00027 
00028 #include "asterisk/pbx.h"
00029 #include "asterisk/module.h"
00030 #include "asterisk/manager.h"
00031 #include "asterisk/app.h"
00032 
00033 /*** DOCUMENTATION
00034    <application name="UserEvent" language="en_US">
00035       <synopsis>
00036          Send an arbitrary event to the manager interface.
00037       </synopsis>
00038       <syntax>
00039          <parameter name="eventname" required="true" />
00040          <parameter name="body" />
00041       </syntax>
00042       <description>
00043          <para>Sends an arbitrary event to the manager interface, with an optional
00044          <replaceable>body</replaceable> representing additional arguments. The
00045          <replaceable>body</replaceable> may be specified as
00046          a <literal>,</literal> delimited list of headers. Each additional
00047          argument will be placed on a new line in the event. The format of the
00048          event will be:</para>
00049          <para>    Event: UserEvent</para>
00050          <para>    UserEvent: &lt;specified event name&gt;</para>
00051          <para>    [body]</para>
00052          <para>If no <replaceable>body</replaceable> is specified, only Event and UserEvent headers will be present.</para>
00053       </description>
00054    </application>
00055  ***/
00056 
00057 static char *app = "UserEvent";
00058 
00059 static int userevent_exec(struct ast_channel *chan, const char *data)
00060 {
00061    char *parse;
00062    int x;
00063    AST_DECLARE_APP_ARGS(args,
00064       AST_APP_ARG(eventname);
00065       AST_APP_ARG(extra)[100];
00066    );
00067    struct ast_str *body = ast_str_create(16);
00068 
00069    if (ast_strlen_zero(data)) {
00070       ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
00071       ast_free(body);
00072       return -1;
00073    }
00074 
00075    if (!body) {
00076       ast_log(LOG_WARNING, "Unable to allocate buffer\n");
00077       return -1;
00078    }
00079 
00080    parse = ast_strdupa(data);
00081 
00082    AST_STANDARD_APP_ARGS(args, parse);
00083 
00084    for (x = 0; x < args.argc - 1; x++) {
00085       ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
00086    }
00087 
00088    manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, ast_str_buffer(body));
00089    ast_free(body);
00090 
00091    return 0;
00092 }
00093 
00094 static int unload_module(void)
00095 {
00096    return ast_unregister_application(app);
00097 }
00098 
00099 static int load_module(void)
00100 {
00101    return ast_register_application_xml(app, userevent_exec);
00102 }
00103 
00104 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");

Generated on Mon Jun 27 16:50:47 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7