Index: UPGRADE.txt =================================================================== --- UPGRADE.txt (revision 102808) +++ UPGRADE.txt (working copy) @@ -92,6 +92,9 @@ * QUEUE_MEMBER_COUNT() has been deprecated in favor of the QUEUE_MEMBER() function. For more information, issue a "show function QUEUE_MEMBER" from the CLI. +* IMPORT() has been deprecated in favor of CHANVAR() which provides an identical + interface for reading channel variables. + CDR: * The cdr_sqlite module has been marked as deprecated in favor of Index: CHANGES =================================================================== --- CHANGES (revision 102808) +++ CHANGES (working copy) @@ -70,6 +70,8 @@ ID for the call (not the Asterisk call ID or unique ID), provided that the channel driver supports this. For SIP, you get the SIP call-ID for the bridged channel which you can store in the CDR with a custom field. + * Added the CHANVAR dialplan function which allows you to read channel variables + from or set channel variables on arbitrary active channels. CLI Changes ----------- Index: funcs/func_logic.c =================================================================== --- funcs/func_logic.c (revision 102808) +++ funcs/func_logic.c (working copy) @@ -150,6 +150,13 @@ AST_APP_ARG(channel); AST_APP_ARG(varname); ); + static int dep_warning = 0; + + if (!dep_warning) { + ast_log(LOG_WARNING, "This has been deprecated in favor of CHANVAR() which has an identical interface.\n"); + dep_warning = 1; + } + AST_STANDARD_APP_ARGS(args, data); buf[0] = 0; if (!ast_strlen_zero(args.varname)) { Index: funcs/func_channel.c =================================================================== --- funcs/func_channel.c (revision 102808) +++ funcs/func_channel.c (working copy) @@ -138,6 +138,64 @@ return ret; } +static int acf_chanvar_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) +{ + struct ast_channel *chan2; + struct ast_str *str; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(channel); + AST_APP_ARG(varname); + ); + + AST_STANDARD_APP_ARGS(args, data); + + if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.varname)) { + ast_log(LOG_ERROR, "Usage: Set(foo=${CHANVAR(,)})\n"); + return -1; + } + + if (!(chan2 = ast_get_channel_by_name_locked(args.channel))) { + ast_log(LOG_NOTICE, "Channel: %s does not exist!\n", args.channel); + return -1; + } + + str = ast_str_alloca(strlen(args.varname) + 4); + ast_str_set(&str, 0, "${%s}", args.varname); + + pbx_substitute_variables_helper(chan2, str->str, buf, len); + + ast_channel_unlock(chan2); + + return 0; +} + +static int acf_chanvar_write(struct ast_channel *chan, const char *cmd, char *var, const char *value) +{ + struct ast_channel *chan2; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(channel); + AST_APP_ARG(varname); + ); + + AST_STANDARD_APP_ARGS(args, var); + + if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.varname)) { + ast_log(LOG_ERROR, "Usage: Set(CHANVAR(,)=value)\n"); + return -1; + } + + if (!(chan2 = ast_get_channel_by_name_locked(args.channel))) { + ast_log(LOG_NOTICE, "Channel: %s does not exist!\n", args.channel); + return -1; + } + + pbx_builtin_setvar_helper(chan2, args.varname, value); + + ast_channel_unlock(chan2); + + return 0; +} + static struct ast_custom_function channel_function = { .name = "CHANNEL", .synopsis = "Gets/sets various pieces of information about the channel.", @@ -193,14 +251,38 @@ .write = func_channel_write, }; +static struct ast_custom_function chanvar_function = { + .name = "CHANVAR", + .synopsis = + "Reads or writes a variables from or to another channel.\n", + .syntax = "CHANVAR(channel,variable)", + .desc = + "Reads or writes a variables from or to another channel.\n" + "Examples;\n" + "Read: Set(foo=${CHANVAR(${BRIDGEPEER},UNIQUEID)})\n" + "Write: Set(CHANVAR(${BRIDGEPEER},UNIQUEID)=${foo})\n", + .read = acf_chanvar_read, + .write = acf_chanvar_write, +}; + static int unload_module(void) { - return ast_custom_function_unregister(&channel_function); + int res; + + res = ast_custom_function_unregister(&channel_function); + res |= ast_custom_function_unregister(&chanvar_function); + + return res; } static int load_module(void) { - return ast_custom_function_register(&channel_function); + int res; + + res = ast_custom_function_register(&channel_function); + res |= ast_custom_function_register(&chanvar_function); + + return res; } AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan function");