Tue Aug 20 16:34:23 2013

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

Generated on 20 Aug 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1