diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 77f9a79ee0..9539cb7bfb 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -36,6 +36,9 @@ #define __FUNCTION__ __SWITCH_FUNC__ #endif +#define OPENZAP_VAR_PREFIX "openzap_" +#define OPENZAP_VAR_PREFIX_LEN 8 + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openzap_shutdown); SWITCH_MODULE_DEFINITION(mod_openzap, mod_openzap_load, mod_openzap_shutdown, NULL); @@ -883,6 +886,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi int direction = ZAP_TOP_DOWN; zap_caller_data_t caller_data = {{ 0 }}; char *span_name = NULL; + switch_event_header_t *h; if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -968,6 +972,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } + zap_channel_clear_vars(zchan); + for (h = var_event->headers; h; h = h->next) { + if (!strncasecmp(h->name, OPENZAP_VAR_PREFIX, OPENZAP_VAR_PREFIX_LEN)) { + char *v = h->name + OPENZAP_VAR_PREFIX_LEN; + if (!switch_strlen_zero(v)) { + zap_channel_add_var(zchan, v, h->value); + } + } + } + if ((*new_session = switch_core_session_request(openzap_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index 567a0e53eb..ae95e34021 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -447,6 +447,7 @@ struct zap_channel { struct zap_caller_data caller_data; struct zap_span *span; struct zap_io_interface *zio; + zap_hash_t *variable_hash; }; @@ -573,6 +574,9 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo zap_status_t zap_channel_wait(zap_channel_t *zchan, zap_wait_flag_t *flags, int32_t to); zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *datalen); zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t datasize, zap_size_t *datalen); +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value); +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name); +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan); zap_status_t zap_global_init(void); zap_status_t zap_global_destroy(void); void zap_global_set_logger(zap_logger_t logger); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 8d74f9faf6..1472d2e697 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -242,6 +242,7 @@ static zap_status_t zap_channel_destroy(zap_channel_t *zchan) zap_buffer_destroy(&zchan->gen_dtmf_buffer); zap_buffer_destroy(&zchan->dtmf_buffer); zap_buffer_destroy(&zchan->fsk_buffer); + hashtable_destroy(zchan->variable_hash); zap_safe_free(zchan->dtmf_hangup_buf); @@ -457,7 +458,8 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha zap_mutex_create(&new_chan->mutex); zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0); zap_buffer_create(&new_chan->gen_dtmf_buffer, 128, 128, 0); - + new_chan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + new_chan->dtmf_hangup_buf = calloc (span->dtmf_hangup_len + 1, sizeof (char)); zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY); @@ -2015,6 +2017,46 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t data return status; } +zap_status_t zap_channel_clear_vars(zap_channel_t *zchan) +{ + if(zchan->variable_hash) { + hashtable_destroy(zchan->variable_hash); + } + zchan->variable_hash = create_hashtable(16, zap_hash_hashfromstring, zap_hash_equalkeys); + + if(!zchan->variable_hash) + return ZAP_FAIL; + + return ZAP_SUCCESS; +} + +zap_status_t zap_channel_add_var(zap_channel_t *zchan, const char *var_name, const char *value) +{ + char *t_name = 0, *t_val = 0; + + if(!zchan->variable_hash || !var_name || !value) + { + return ZAP_FAIL; + } + + t_name = strdup(var_name); + t_val = strdup(value); + + if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) { + return ZAP_SUCCESS; + } + return ZAP_FAIL; +} + +const char * zap_channel_get_var(zap_channel_t *zchan, const char *var_name) +{ + if(!zchan->variable_hash || !var_name) + { + return NULL; + } + return (const char *) hashtable_search(zchan->variable_hash, (void *)var_name); +} + static struct { zap_io_interface_t *pika_interface; } interfaces;