| 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 |
|
| 33 |
|
| 34 |
#include "asterisk.h" |
| 35 |
|
| 36 |
#include "asterisk/pbx.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
#include "asterisk/app.h" |
| 39 |
#include "asterisk/channel.h" |
| 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 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static const char * const app = "Transfer"; |
| 89 |
|
| 90 |
static int transfer_exec(struct ast_channel *chan, const char *data) |
| 91 |
{ |
| 92 |
int res; |
| 93 |
int len; |
| 94 |
char *slash; |
| 95 |
char *tech = NULL; |
| 96 |
char *dest = NULL; |
| 97 |
char *status; |
| 98 |
char *parse; |
| 99 |
int protocol = 0; |
| 100 |
char status_protocol[20]; |
| 101 |
AST_DECLARE_APP_ARGS(args, |
| 102 |
AST_APP_ARG(dest); |
| 103 |
); |
| 104 |
|
| 105 |
if (ast_strlen_zero((char *)data)) { |
| 106 |
ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n"); |
| 107 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE"); |
| 108 |
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol); |
| 109 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol); |
| 110 |
return 0; |
| 111 |
} else |
| 112 |
parse = ast_strdupa(data); |
| 113 |
|
| 114 |
AST_STANDARD_APP_ARGS(args, parse); |
| 115 |
|
| 116 |
dest = args.dest; |
| 117 |
|
| 118 |
if ((slash = strchr(dest, '/')) && (len = (slash - dest))) { |
| 119 |
tech = dest; |
| 120 |
dest = slash + 1; |
| 121 |
|
| 122 |
if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) { |
| 123 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE"); |
| 124 |
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol); |
| 125 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol); |
| 126 |
return 0; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
if (!ast_channel_tech(chan)->transfer) { |
| 132 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED"); |
| 133 |
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol); |
| 134 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol); |
| 135 |
return 0; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
res = ast_transfer_protocol(chan, dest, &protocol); |
| 141 |
|
| 142 |
if (res < 0) { |
| 143 |
status = "FAILURE"; |
| 144 |
res = 0; |
| 145 |
} else { |
| 146 |
status = "SUCCESS"; |
| 147 |
res = 0; |
| 148 |
} |
| 149 |
|
| 150 |
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol); |
| 151 |
ast_debug(1, "ast_transfer channel %s TRANSFERSTATUS=%s, TRANSFERSTATUSPROTOCOL=%s\n", |
| 152 |
ast_channel_name(chan), status, status_protocol); |
| 153 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status); |
| 154 |
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol); |
| 155 |
|
| 156 |
return res; |
| 157 |
} |
| 158 |
|
| 159 |
static int unload_module(void) |
| 160 |
{ |
| 161 |
return ast_unregister_application(app); |
| 162 |
} |
| 163 |
|
| 164 |
static int load_module(void) |
| 165 |
{ |
| 166 |
return ast_register_application_xml(app, transfer_exec); |
| 167 |
} |
| 168 |
|
| 169 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Transfers a caller to another extension"); |