char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable) { RAII_VAR(struct ast_str *, tmp, ast_str_create(32), ast_free); /* You may be tempted to lock the channel you're about to read from. You * would be wrong. Some dialplan functions put the channel into * autoservice, which deadlocks if the channel is already locked. * ast_str_retrieve_variable() does its own locking, and the dialplan * functions need to as well. We should be fine without the lock. */ if (!tmp) { return NULL; } if (variable[strlen(variable) - 1] == ')') { if (ast_func_read2(control->channel, variable, &tmp, 0)) { return NULL; } } else { if (!ast_str_retrieve_variable(&tmp, 0, control->channel, NULL, variable)) { return NULL; } } return ast_strdup(ast_str_buffer(tmp)); }
void ast_ari_asterisk_get_global_var(struct ast_variable *headers, struct ast_ari_asterisk_get_global_var_args *args, struct ast_ari_response *response) { RAII_VAR(struct ast_json *, json, NULL, ast_json_unref); RAII_VAR(struct ast_str *, tmp, NULL, ast_free); const char *value; ast_assert(response != NULL); if (ast_strlen_zero(args->variable)) { ast_ari_response_error( response, 400, "Bad Request", "Variable name is required"); return; } tmp = ast_str_create(32); if (!tmp) { ast_ari_response_alloc_failed(response); return; } value = ast_str_retrieve_variable(&tmp, 0, NULL, NULL, args->variable); if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) { ast_ari_response_alloc_failed(response); return; } ast_ari_response_ok(response, ast_json_ref(json)); }
char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable) { RAII_VAR(struct ast_str *, tmp, ast_str_create(32), ast_free); SCOPED_CHANNELLOCK(lockvar, control->channel); if (!tmp) { return NULL; } if (variable[strlen(variable) - 1] == ')') { if (ast_func_read2(control->channel, variable, &tmp, 0)) { return NULL; } } else { if (!ast_str_retrieve_variable(&tmp, 0, control->channel, NULL, variable)) { return NULL; } } return ast_strdup(ast_str_buffer(tmp)); }