Debian Codegraph @

apps/app_bridgeaddchan.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2015, Digium, Inc.
5 *
6 * Alec Davis <[email protected]>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19 /*! \file
20 *
21 * \brief Application to place the channel into an existing Bridge
22 *
23 * \author Alec Davis
24 *
25 * \ingroup applications
26 */
27
28 /*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/file.h"
35 #include "asterisk/module.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/bridge.h"
38 #include "asterisk/features.h"
39
40 /*** DOCUMENTATION
41 <application name="BridgeAdd" language="en_US">
42 <since>
43 <version>14.0.0</version>
44 </since>
45 <synopsis>
46 Join a bridge that contains the specified channel.
47 </synopsis>
48 <syntax>
49 <parameter name="channel" required="true">
50 <para>The current channel joins the bridge containing the channel
51 identified by the channel name, channel name prefix, or channel
52 uniqueid.</para>
53 </parameter>
54 </syntax>
55 <description>
56 <para>This application places the incoming channel into
57 the bridge containing the specified channel. The specified
58 channel only needs to be the prefix of a full channel name
59 IE. 'PJSIP/cisco0001'.
60 </para>
61 <para>This application sets the following channel variable upon completion:</para>
62 <variablelist>
63 <variable name="BRIDGERESULT">
64 <para>The result of the bridge attempt as a text string.</para>
65 <value name="SUCCESS" />
66 <value name="FAILURE" />
67 <value name="LOOP" />
68 <value name="NONEXISTENT" />
69 </variable>
70 </variablelist>
71 </description>
72 </application>
73 ***/
74
75 static const char app[] = "BridgeAdd";
76
77 static int bridgeadd_exec(struct ast_channel *chan, const char *data)
78 {
79 struct ast_channel *c_ref;
80 struct ast_bridge_features chan_features;
81 struct ast_bridge *bridge;
82 char *c_name;
83 int failed;
84
85 /* Answer the channel if needed */
86 if (ast_channel_state(chan) != AST_STATE_UP) {
87 ast_answer(chan);
88 }
89
90 if (ast_strlen_zero(data)) {
91 data = "";
92 c_ref = NULL;
93 } else {
94 c_ref = ast_channel_get_by_name_prefix(data, strlen(data));
95 }
96 if (!c_ref) {
97 ast_verb(4, "Channel '%s' not found\n", data);
98 pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "NONEXISTENT");
99 return 0;
100 }
101 if (chan == c_ref) {
102 ast_channel_unref(c_ref);
103 pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "LOOP");
104 return 0;
105 }
106
107 c_name = ast_strdupa(ast_channel_name(c_ref));
108
109 ast_channel_lock(c_ref);
110 bridge = ast_channel_get_bridge(c_ref);
111 ast_channel_unlock(c_ref);
112
113 ast_channel_unref(c_ref);
114
115 if (!bridge) {
116 ast_verb(4, "Channel '%s' is not in a bridge\n", c_name);
117 pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "FAILURE");
118 return 0;
119 }
120
121 ast_verb(4, "%s is joining %s in bridge %s\n",
122 ast_channel_name(chan), c_name, bridge->uniqueid);
123
124 failed = ast_bridge_features_init(&chan_features)
125 || ast_bridge_join(bridge, chan, NULL, &chan_features, NULL, 0);
126 if (failed) {
127 ast_verb(4, "%s failed to join %s in bridge %s\n",
128 ast_channel_name(chan), c_name, bridge->uniqueid);
129 }
130
131 ast_bridge_features_cleanup(&chan_features);
132 ao2_cleanup(bridge);
133 pbx_builtin_setvar_helper(chan, "BRIDGERESULT", failed ? "FAILURE" : "SUCCESS");
134 return 0;
135 }
136
137 static int unload_module(void)
138 {
139 return ast_unregister_application(app);
140 }
141
142 static int load_module(void)
143 {
144 return ast_register_application_xml(app, bridgeadd_exec);
145 }
146
147 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Bridge Add Channel Application");