res_rtp_asterisk: Avoid close the rtp/rtcp fd twice.
[asterisk/asterisk.git] / apps / app_channelredirect.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Sergey Basmanov
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 ChannelRedirect application
20  *
21  * \author Sergey Basmanov <sergey_basmanov@mail.ru>
22  *
23  * \ingroup applications
24  */
25
26 /*** MODULEINFO
27         <support_level>core</support_level>
28  ***/
29
30 #include "asterisk.h"
31
32 #include "asterisk/file.h"
33 #include "asterisk/channel.h"
34 #include "asterisk/pbx.h"
35 #include "asterisk/module.h"
36 #include "asterisk/lock.h"
37 #include "asterisk/app.h"
38 #include "asterisk/features.h"
39
40 /*** DOCUMENTATION
41         <application name="ChannelRedirect" language="en_US">
42                 <synopsis>
43                         Redirects given channel to a dialplan target
44                 </synopsis>
45                 <syntax>
46                         <parameter name="channel" required="true" />
47                         <parameter name="context" required="false" />
48                         <parameter name="extension" required="false" />
49                         <parameter name="priority" required="true" />
50                 </syntax>
51                 <description>
52                         <para>Sends the specified channel to the specified extension priority</para>
53
54                         <para>This application sets the following channel variables upon completion</para>
55                         <variablelist>
56                                 <variable name="CHANNELREDIRECT_STATUS">
57                                         <value name="NOCHANNEL" />
58                                         <value name="SUCCESS" />
59                                         <para>Are set to the result of the redirection</para>
60                                 </variable>
61                         </variablelist>
62                 </description>
63         </application>
64  ***/
65 static const char app[] = "ChannelRedirect";
66
67 static int asyncgoto_exec(struct ast_channel *chan, const char *data)
68 {
69         int res = -1;
70         char *info;
71         struct ast_channel *chan2 = NULL;
72
73         AST_DECLARE_APP_ARGS(args,
74                 AST_APP_ARG(channel);
75                 AST_APP_ARG(label);
76         );
77
78         if (ast_strlen_zero(data)) {
79                 ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
80                 return -1;
81         }
82
83         info = ast_strdupa(data);
84         AST_STANDARD_APP_ARGS(args, info);
85
86         if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
87                 ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
88                 return -1;
89         }
90
91         if (!(chan2 = ast_channel_get_by_name(args.channel))) {
92                 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
93                 pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
94                 return 0;
95         }
96
97         res = ast_async_parseable_goto(chan2, args.label);
98
99         chan2 = ast_channel_unref(chan2);
100
101         pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
102
103         return res;
104 }
105
106 static int unload_module(void)
107 {
108         return ast_unregister_application(app);
109 }
110
111 static int load_module(void)
112 {
113         return ast_register_application_xml(app, asyncgoto_exec) ?
114                 AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
115 }
116
117 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");