| 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/app.h" |
| 35 |
#include "asterisk/ari.h" |
| 36 |
#include "asterisk/module.h" |
| 37 |
#include "asterisk/pbx.h" |
| 38 |
#include "asterisk/stasis.h" |
| 39 |
#include "asterisk/stasis_app_impl.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 |
#define MAX_ARGS 128 |
| 83 |
|
| 84 |
|
| 85 |
static const char *stasis = "Stasis"; |
| 86 |
|
| 87 |
|
| 88 |
static int app_exec(struct ast_channel *chan, const char *data) |
| 89 |
{ |
| 90 |
char *parse = NULL; |
| 91 |
char *connection_id; |
| 92 |
int ret = -1; |
| 93 |
|
| 94 |
AST_DECLARE_APP_ARGS(args, |
| 95 |
AST_APP_ARG(app_name); |
| 96 |
AST_APP_ARG(app_argv)[MAX_ARGS]; |
| 97 |
); |
| 98 |
|
| 99 |
ast_assert(chan != NULL); |
| 100 |
ast_assert(data != NULL); |
| 101 |
|
| 102 |
pbx_builtin_setvar_helper(chan, "STASISSTATUS", ""); |
| 103 |
|
| 104 |
|
| 105 |
parse = ast_strdupa(data); |
| 106 |
AST_STANDARD_APP_ARGS(args, parse); |
| 107 |
|
| 108 |
if (args.argc < 1) { |
| 109 |
ast_log(LOG_WARNING, "Stasis app_name argument missing\n"); |
| 110 |
goto done; |
| 111 |
} |
| 112 |
|
| 113 |
if (stasis_app_is_registered(args.app_name)) { |
| 114 |
ast_debug(3, "%s: App '%s' is already registered\n", |
| 115 |
ast_channel_name(chan), args.app_name); |
| 116 |
ret = stasis_app_exec(chan, args.app_name, args.argc - 1, args.app_argv); |
| 117 |
goto done; |
| 118 |
} |
| 119 |
ast_debug(3, "%s: App '%s' is NOT already registered\n", |
| 120 |
ast_channel_name(chan), args.app_name); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
connection_id = ast_ari_create_per_call_websocket(args.app_name, chan); |
| 128 |
if (ast_strlen_zero(connection_id)) { |
| 129 |
ast_log(LOG_WARNING, |
| 130 |
"%s: Stasis app '%s' doesn't exist\n", |
| 131 |
ast_channel_name(chan), args.app_name); |
| 132 |
goto done; |
| 133 |
} |
| 134 |
|
| 135 |
ret = stasis_app_exec(chan, connection_id, args.argc - 1, args.app_argv); |
| 136 |
ast_ari_close_per_call_websocket(connection_id); |
| 137 |
|
| 138 |
done: |
| 139 |
if (ret) { |
| 140 |
|
| 141 |
if (!ast_check_hangup(chan)) { |
| 142 |
ret = 0; |
| 143 |
} else { |
| 144 |
ret = -1; |
| 145 |
} |
| 146 |
pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED"); |
| 147 |
} else { |
| 148 |
pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS"); |
| 149 |
} |
| 150 |
|
| 151 |
return ret; |
| 152 |
} |
| 153 |
|
| 154 |
static int load_module(void) |
| 155 |
{ |
| 156 |
return ast_register_application_xml(stasis, app_exec); |
| 157 |
} |
| 158 |
|
| 159 |
static int unload_module(void) |
| 160 |
{ |
| 161 |
return ast_unregister_application(stasis); |
| 162 |
} |
| 163 |
|
| 164 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application", |
| 165 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 166 |
.load = load_module, |
| 167 |
.unload = unload_module, |
| 168 |
.requires = "res_stasis,res_ari", |
| 169 |
); |