Don't do SIP contact/route DNS if we're not using the result.
[asterisk/asterisk.git] / apps / app_userevent.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * See http://www.asterisk.org for more information about
7  * the Asterisk project. Please do not directly contact
8  * any of the maintainers of this project for assistance;
9  * the project provides a web site, mailing lists and IRC
10  * channels for your use.
11  *
12  * This program is free software, distributed under the terms of
13  * the GNU General Public License Version 2. See the LICENSE file
14  * at the top of the source tree.
15  */
16
17 /*! \file
18  *
19  * \brief UserEvent application -- send manager event
20  * 
21  * \ingroup applications
22  */
23
24 /*** MODULEINFO
25         <support_level>core</support_level>
26  ***/
27
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/manager.h"
35 #include "asterisk/app.h"
36
37 /*** DOCUMENTATION
38         <application name="UserEvent" language="en_US">
39                 <synopsis>
40                         Send an arbitrary event to the manager interface.
41                 </synopsis>
42                 <syntax>
43                         <parameter name="eventname" required="true" />
44                         <parameter name="body" />
45                 </syntax>
46                 <description>
47                         <para>Sends an arbitrary event to the manager interface, with an optional
48                         <replaceable>body</replaceable> representing additional arguments. The
49                         <replaceable>body</replaceable> may be specified as
50                         a <literal>,</literal> delimited list of headers. Each additional
51                         argument will be placed on a new line in the event. The format of the
52                         event will be:</para>
53                         <para>    Event: UserEvent</para>
54                         <para>    UserEvent: &lt;specified event name&gt;</para>
55                         <para>    [body]</para>
56                         <para>If no <replaceable>body</replaceable> is specified, only Event and UserEvent headers will be present.</para>
57                 </description>
58         </application>
59  ***/
60
61 static char *app = "UserEvent";
62
63 static int userevent_exec(struct ast_channel *chan, const char *data)
64 {
65         char *parse;
66         int x;
67         AST_DECLARE_APP_ARGS(args,
68                 AST_APP_ARG(eventname);
69                 AST_APP_ARG(extra)[100];
70         );
71         struct ast_str *body = ast_str_create(16);
72
73         if (ast_strlen_zero(data)) {
74                 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
75                 ast_free(body);
76                 return -1;
77         }
78
79         if (!body) {
80                 ast_log(LOG_WARNING, "Unable to allocate buffer\n");
81                 return -1;
82         }
83
84         parse = ast_strdupa(data);
85
86         AST_STANDARD_APP_ARGS(args, parse);
87
88         for (x = 0; x < args.argc - 1; x++) {
89                 ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
90         }
91
92         /*** DOCUMENTATION
93         <managerEventInstance>
94                 <synopsis>A user defined event raised from the dialplan.</synopsis>
95                 <parameter name="UserEvent">
96                         <para>The event name, as specified in the dialplan.</para>
97                 </parameter>
98                 <see-also>
99                         <ref type="application">UserEvent</ref>
100                 </see-also>
101         </managerEventInstance>
102         ***/
103         manager_event(EVENT_FLAG_USER, "UserEvent",
104                         "UserEvent: %s\r\n"
105                         "Uniqueid: %s\r\n"
106                         "%s",
107                         args.eventname, ast_channel_uniqueid(chan), ast_str_buffer(body));
108
109         ast_free(body);
110
111         return 0;
112 }
113
114 static int unload_module(void)
115 {
116         return ast_unregister_application(app);
117 }
118
119 static int load_module(void)
120 {
121         return ast_register_application_xml(app, userevent_exec);
122 }
123
124 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");