| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 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 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 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 |
|
| 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"); |