| 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/channel.h" |
| 36 |
#include "asterisk/pbx.h" |
| 37 |
#include "asterisk/module.h" |
| 38 |
#include "asterisk/lock.h" |
| 39 |
#include "asterisk/app.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 |
static char *app = "SoftHangup"; |
| 68 |
|
| 69 |
enum { |
| 70 |
OPTION_ALL = (1 << 0), |
| 71 |
}; |
| 72 |
|
| 73 |
AST_APP_OPTIONS(app_opts,{ |
| 74 |
AST_APP_OPTION('a', OPTION_ALL), |
| 75 |
}); |
| 76 |
|
| 77 |
static int softhangup_exec(struct ast_channel *chan, const char *data) |
| 78 |
{ |
| 79 |
struct ast_channel *c = NULL; |
| 80 |
char *cut, *opts[0]; |
| 81 |
char name[AST_CHANNEL_NAME] = "", *parse; |
| 82 |
struct ast_flags flags = {0}; |
| 83 |
int lenmatch; |
| 84 |
AST_DECLARE_APP_ARGS(args, |
| 85 |
AST_APP_ARG(channel); |
| 86 |
AST_APP_ARG(options); |
| 87 |
); |
| 88 |
struct ast_channel_iterator *iter; |
| 89 |
|
| 90 |
if (ast_strlen_zero(data)) { |
| 91 |
ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n"); |
| 92 |
return 0; |
| 93 |
} |
| 94 |
|
| 95 |
parse = ast_strdupa(data); |
| 96 |
AST_STANDARD_APP_ARGS(args, parse); |
| 97 |
|
| 98 |
if (args.argc == 2) |
| 99 |
ast_app_parse_options(app_opts, &flags, opts, args.options); |
| 100 |
lenmatch = strlen(args.channel); |
| 101 |
|
| 102 |
if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) { |
| 103 |
return -1; |
| 104 |
} |
| 105 |
|
| 106 |
while ((c = ast_channel_iterator_next(iter))) { |
| 107 |
ast_channel_lock(c); |
| 108 |
ast_copy_string(name, ast_channel_name(c), sizeof(name)); |
| 109 |
if (ast_test_flag(&flags, OPTION_ALL)) { |
| 110 |
|
| 111 |
if (!strcmp(ast_channel_tech(c)->type, "CAPI")) { |
| 112 |
cut = strrchr(name, '/'); |
| 113 |
|
| 114 |
} else { |
| 115 |
|
| 116 |
cut = strrchr(name,'-'); |
| 117 |
} |
| 118 |
|
| 119 |
if (cut) |
| 120 |
*cut = 0; |
| 121 |
} |
| 122 |
if (!strcasecmp(name, args.channel)) { |
| 123 |
ast_verb(4, "Soft hanging %s up.\n", ast_channel_name(c)); |
| 124 |
ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); |
| 125 |
if (!ast_test_flag(&flags, OPTION_ALL)) { |
| 126 |
ast_channel_unlock(c); |
| 127 |
c = ast_channel_unref(c); |
| 128 |
break; |
| 129 |
} |
| 130 |
} |
| 131 |
ast_channel_unlock(c); |
| 132 |
c = ast_channel_unref(c); |
| 133 |
} |
| 134 |
|
| 135 |
ast_channel_iterator_destroy(iter); |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
static int unload_module(void) |
| 141 |
{ |
| 142 |
return ast_unregister_application(app); |
| 143 |
} |
| 144 |
|
| 145 |
static int load_module(void) |
| 146 |
{ |
| 147 |
return ast_register_application_xml(app, softhangup_exec); |
| 148 |
} |
| 149 |
|
| 150 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel"); |