summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2016-01-26 11:25:35 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-01-26 11:25:36 -0600
commit4cc784eb049ee24246dad3c9d4ba46e25ab9f64b (patch)
treef7e59dd508a3d5b1f7fbe637794e4ccb4b4f842f
parentc9a0f4f8ff9785657caee25a1b1a2d1bc6f9f047 (diff)
parent4a3275abb9e6528f5bacbb454446a3e2e7115d88 (diff)
Merge "Stasis: Use custom structure when setting variables." into 13
-rw-r--r--res/stasis/control.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/res/stasis/control.c b/res/stasis/control.c
index 57b5e9964..ebb7e0194 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -623,10 +623,36 @@ int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int d
return 0;
}
+/*!
+ * \brief structure for queuing ARI channel variable setting
+ *
+ * It may seem weird to define this custom structure given that we already have
+ * ast_var_t and ast_variable defined elsewhere. The problem with those is that
+ * they are not tolerant of NULL channel variable value pointers. In fact, in both
+ * cases, the best they could do is to have a zero-length variable value. However,
+ * when un-setting a channel variable, it is important to pass a NULL value, not
+ * a zero-length string.
+ */
+struct chanvar {
+ /*! Name of variable to set/unset */
+ char *name;
+ /*! Value of variable to set. If unsetting, this will be NULL */
+ char *value;
+};
+
+static void free_chanvar(void *data)
+{
+ struct chanvar *var = data;
+
+ ast_free(var->name);
+ ast_free(var->value);
+ ast_free(var);
+}
+
static int app_control_set_channel_var(struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
- struct ast_variable *var = data;
+ struct chanvar *var = data;
pbx_builtin_setvar_helper(control->channel, var->name, var->value);
@@ -635,14 +661,29 @@ static int app_control_set_channel_var(struct stasis_app_control *control,
int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
{
- struct ast_variable *var;
+ struct chanvar *var;
- var = ast_variable_new(variable, value, "ARI");
+ var = ast_calloc(1, sizeof(*var));
if (!var) {
return -1;
}
- stasis_app_send_command_async(control, app_control_set_channel_var, var, ast_free_ptr);
+ var->name = ast_strdup(variable);
+ if (!var->name) {
+ free_chanvar(var);
+ return -1;
+ }
+
+ /* It's kosher for value to be NULL. It means the variable is being unset */
+ if (value) {
+ var->value = ast_strdup(value);
+ if (!var->value) {
+ free_chanvar(var);
+ return -1;
+ }
+ }
+
+ stasis_app_send_command_async(control, app_control_set_channel_var, var, free_chanvar);
return 0;
}