diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index e62a22a1ee..436cfef708 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -220,6 +220,7 @@ SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel); \returns SWITCH_STATUS_SUCCESS if successful */ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *channel, const char *varname, const char *value); +SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt, ...); SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner(switch_channel_t *channel, const char *varname, const char *value); SWITCH_DECLARE(const char *) switch_channel_get_variable_partner(switch_channel_t *channel, const char *varname); diff --git a/src/switch_channel.c b/src/switch_channel.c index 1fa12c550b..838abe5f7f 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -578,6 +578,37 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *ch return SWITCH_STATUS_FALSE; } +switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data); + +SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt, ...) +{ + int ret = 0; + char *data; + va_list ap; + switch_assert(channel != NULL); + + if (!switch_strlen_zero(varname)) { + switch_mutex_lock(channel->profile_mutex); + switch_event_del_header(channel->variables, varname); + + va_start(ap, fmt); + ret = switch_vasprintf(&data, fmt, ap); + va_end(ap); + + if (ret == -1) { + switch_mutex_unlock(channel->profile_mutex); + return SWITCH_STATUS_MEMERR; + } + + switch_event_base_add_header(channel->variables, SWITCH_STACK_BOTTOM, varname, data); + + switch_mutex_unlock(channel->profile_mutex); + return SWITCH_STATUS_SUCCESS; + } + + return SWITCH_STATUS_FALSE; +} + SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner(switch_channel_t *channel, const char *varname, const char *value) { diff --git a/src/switch_event.c b/src/switch_event.c index 3a2dac52a5..6b22128d4d 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -625,7 +625,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header(switch_event_t *event, c return status; } -static switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data) +switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data) { switch_event_header_t *header; void *pop;