diff options
author | Sebastien Duthil <sduthil@proformatique.com> | 2016-11-11 11:45:37 -0500 |
---|---|---|
committer | Sebastien Duthil <sduthil@proformatique.com> | 2016-11-14 13:51:56 -0500 |
commit | c6d755de11e98c1f6f33b1b35db9725f64f72053 (patch) | |
tree | 2299d268ffdce70a50dafacc20cc56509a79f4c4 /res/ari | |
parent | 7540036427f87bfe3c87357ac33c08561f191e98 (diff) |
res_ari: Add support for channel variables in ARI events.
This works the same as for AMI manager variables. Set
"channelvars=foo,bar" in your ari.conf general section, and then the
channel variables "foo" and "bar" (along with their values), will
appear in every Stasis websocket channel event.
ASTERISK-26492 #close
patches:
ari_vars.diff submitted by Mark Michelson
Change-Id: I5609ba239259577c0948645df776d7f3bc864229
Diffstat (limited to 'res/ari')
-rw-r--r-- | res/ari/ari_model_validators.c | 9 | ||||
-rw-r--r-- | res/ari/ari_model_validators.h | 1 | ||||
-rw-r--r-- | res/ari/config.c | 20 |
3 files changed, 30 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c index 03cd3a238..9fd844c4d 100644 --- a/res/ari/ari_model_validators.c +++ b/res/ari/ari_model_validators.c @@ -1051,6 +1051,15 @@ int ast_ari_validate_channel(struct ast_json *json) res = 0; } } else + if (strcmp("channelvars", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + prop_is_valid = ast_ari_validate_object( + ast_json_object_iter_value(iter)); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI Channel field channelvars failed validation\n"); + res = 0; + } + } else if (strcmp("connected", ast_json_object_iter_key(iter)) == 0) { int prop_is_valid; has_connected = 1; diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h index 0b08ce85e..fcd9fc11c 100644 --- a/res/ari/ari_model_validators.h +++ b/res/ari/ari_model_validators.h @@ -1432,6 +1432,7 @@ ari_validator ast_ari_validate_application_fn(void); * Channel * - accountcode: string (required) * - caller: CallerID (required) + * - channelvars: object * - connected: CallerID (required) * - creationtime: Date (required) * - dialplan: DialplanCEP (required) diff --git a/res/ari/config.c b/res/ari/config.c index deaa78073..a080bb713 100644 --- a/res/ari/config.c +++ b/res/ari/config.c @@ -26,6 +26,8 @@ #include "asterisk/config_options.h" #include "asterisk/http_websocket.h" +#include "asterisk/app.h" +#include "asterisk/channel.h" #include "internal.h" /*! \brief Locking container for safe configuration access. */ @@ -316,6 +318,22 @@ static int process_config(int reload) return 0; } +#define MAX_VARS 128 + +static int channelvars_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) +{ + char *parse = NULL; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(vars)[MAX_VARS]; + ); + + parse = ast_strdupa(var->value); + AST_STANDARD_APP_ARGS(args, parse); + + ast_channel_set_ari_vars(args.argc, args.vars); + return 0; +} + int ast_ari_config_init(void) { if (aco_info_init(&cfg_info)) { @@ -339,6 +357,8 @@ int ast_ari_config_init(void) aco_option_register(&cfg_info, "websocket_write_timeout", ACO_EXACT, general_options, AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX); + aco_option_register_custom(&cfg_info, "channelvars", ACO_EXACT, general_options, + "", channelvars_handler, 0); /* ARI type=user category options */ aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL, |