| 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 |
#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 |
|
| 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 |
static const char app[] = "ChannelRedirect"; |
| 69 |
|
| 70 |
static int asyncgoto_exec(struct ast_channel *chan, const char *data) |
| 71 |
{ |
| 72 |
int res = -1; |
| 73 |
char *info; |
| 74 |
struct ast_channel *chan2 = NULL; |
| 75 |
|
| 76 |
AST_DECLARE_APP_ARGS(args, |
| 77 |
AST_APP_ARG(channel); |
| 78 |
AST_APP_ARG(label); |
| 79 |
); |
| 80 |
|
| 81 |
if (ast_strlen_zero(data)) { |
| 82 |
ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app); |
| 83 |
return -1; |
| 84 |
} |
| 85 |
|
| 86 |
info = ast_strdupa(data); |
| 87 |
AST_STANDARD_APP_ARGS(args, info); |
| 88 |
|
| 89 |
if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) { |
| 90 |
ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app); |
| 91 |
return -1; |
| 92 |
} |
| 93 |
|
| 94 |
if (!(chan2 = ast_channel_get_by_name(args.channel))) { |
| 95 |
ast_log(LOG_WARNING, "No such channel: %s\n", args.channel); |
| 96 |
pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL"); |
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
res = ast_async_parseable_goto(chan2, args.label); |
| 101 |
|
| 102 |
chan2 = ast_channel_unref(chan2); |
| 103 |
|
| 104 |
pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS"); |
| 105 |
|
| 106 |
return res; |
| 107 |
} |
| 108 |
|
| 109 |
static int unload_module(void) |
| 110 |
{ |
| 111 |
return ast_unregister_application(app); |
| 112 |
} |
| 113 |
|
| 114 |
static int load_module(void) |
| 115 |
{ |
| 116 |
return ast_register_application_xml(app, asyncgoto_exec) ? |
| 117 |
AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS; |
| 118 |
} |
| 119 |
|
| 120 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target"); |