diff --git a/libs/freetdm/Makefile.am b/libs/freetdm/Makefile.am
index a26035b2ef..782eaf680e 100644
--- a/libs/freetdm/Makefile.am
+++ b/libs/freetdm/Makefile.am
@@ -76,6 +76,7 @@ libfreetdm_la_SOURCES = \
$(SRC)/ftdm_queue.c \
$(SRC)/ftdm_sched.c \
$(SRC)/ftdm_call_utils.c \
+ $(SRC)/ftdm_variables.c \
$(SRC)/ftdm_config.c \
$(SRC)/ftdm_callerid.c \
$(SRC)/fsk.c \
diff --git a/libs/freetdm/docs/variables.txt b/libs/freetdm/docs/variables.txt
new file mode 100644
index 0000000000..f667b48e53
--- /dev/null
+++ b/libs/freetdm/docs/variables.txt
@@ -0,0 +1,138 @@
+1. User application sending variables or raw buffer to FreeTDM
+==============================================================
+
+The User can attach a ftdm_sigmsg_t to ftdm_caller_data_t before sending an event to freetdm.
+
+example #1 - Adding a variable:
+-------------------------------
+
+When using ftmod_sangoma_isdn, user want to specify progress indicator inside PROCEED message.
+
+
+ ftdm_caller_data_t *caller_data;
+ ftdm_sigmsg_t sigmsg;
+
+ /* Attach variable to sigmsg */
+ ftdm_event_add_var(&sigmsg, "isdn.prog_ind.descr", "inband-info-available");
+
+
+ /* Attach sigmsg to channel's caller_data */
+ caller_data = ftdm_channel_get_caller_data(ftdmchan);
+ caller_data->sigmsg = &sigmsg;
+
+ /* Request FreeTDM to send a PROCEED msg */
+ ftdm_channel_call_indicate(ftdmchan, FTDM_CHANNEL_INDICATE_PROCEED);
+
+Note:
+1.When ftdm_channel_call_indicate returns, caller_data->sigmsg will be NULL.
+
+
+
+example #2a - Setting raw data without autofree feature:
+--------------------------------------------------------
+
+When using ftmod_sangoma_isdn, user wants to transmit a custom Facility IE, inside a FACILITY message.
+
+ ftdm_caller_data_t *caller_data;
+ ftdm_sigmsg_t sigmsg;
+ uint8_t my_facility_ie [200];
+ unsigned my_facility_ie_len = 0;
+
+ /* Fill my_facility_ie with custom data here */
+ my_facility_ie[my_facility_ie_len++] = 0x1C; /* Q.931 Facility IE ID */
+ my_facility_ie[my_facility_ie_len++] = 0x03; /* Length of facility IE */
+ my_facility_ie[my_facility_ie_len++] = 0x01;
+ my_facility_ie[my_facility_ie_len++] = 0x02;
+ my_facility_ie[my_facility_ie_len++] = 0x03;
+
+
+ sigmsg.raw.data = my_facility_ie;
+ sigmsg.raw.len = my_facility_ie_len;
+ sigmsg.raw.autofree = 0;
+
+ /* Attach sigmsg to channel's caller_data */
+ caller_data = ftdm_channel_get_caller_data(ftdmchan);
+ caller_data->sigmsg = &sigmsg;
+
+ sigmsg.event_id = FTDM_SIGEVENT_FACILITY;
+
+ ftdm_channel_call_send_msg(ftdmchan, sigmsg);
+
+
+
+example #2b - Setting raw data with autofree feature:
+-----------------------------------------------------
+
+ ftdm_caller_data_t *caller_data;
+ ftdm_sigmsg_t sigmsg;
+ uint8_t *my_facility_ie = ftdm_calloc(1, 200);
+ unsigned my_facility_ie_len = 0;
+
+ /* Fill my_facility_ie with custom data here */
+ my_facility_ie[my_facility_ie_len++] = 0x1C; /* Q.931 Facility IE ID */
+ my_facility_ie[my_facility_ie_len++] = 0x03; /* Length of facility IE */
+ my_facility_ie[my_facility_ie_len++] = 0x01;
+ my_facility_ie[my_facility_ie_len++] = 0x02;
+ my_facility_ie[my_facility_ie_len++] = 0x03;
+
+
+ sigmsg.raw.data = my_facility_ie;
+ sigmsg.raw.len = my_facility_ie_len;
+ sigmsg.raw.autofree = 1;
+
+ /* Attach sigmsg to channel's caller_data */
+ caller_data = ftdm_channel_get_caller_data(ftdmchan);
+ caller_data->sigmsg = &sigmsg;
+
+ sigmsg.event_id = FTDM_SIGEVENT_FACILITY;
+
+ ftdm_channel_call_send_msg(ftdmchan, sigmsg);
+
+ /* FreeTDM will automatically free my_facility_ie */
+
+
+2. User application receiving variables and raw buffer from FreeTDM
+==================================================================
+
+example #1 - print all variables received from FreeTDM
+------------------------------------------------------
+
+ /* Inside event call-back function */
+ ftdm_iterator_t *iter = NULL;
+ ftdm_iterator_t *curr = NULL;
+ const char *var_name = NULL;
+ const char *var_value = NULL;
+
+ ftdm_caller_data_t *caller_data = ftdm_channel_get_caller_data(sigmsg->channel);
+
+ /* Read all variables attached to this event */
+ iter = ftdm_event_get_var_iterator(sigmsg, iter);
+ for (curr = iter ; curr; curr = ftdm_iterator_next(curr)) {
+ ftdm_get_current_var(curr, &var_name, &var_value);
+ fprintf("Call Variable: %s=%s\n", var_name, var_value);
+ }
+ ftdm_iterator_free(iter);
+
+
+example #2 - accessing a specific variable
+------------------------------------------
+
+ /* Inside event call-back function */
+ char *string = NULL;
+ string = ftdm_event_get_var(sigmsg, "isdn.prog_ind.descr");
+ if (string && *string) {
+ fprintf("Progress indicator:%s\n", string);
+ }
+
+
+example #3 - accessing raw data
+-------------------------------
+
+ /* Inside event call-back function */
+ ftdm_size_t len;
+ uint8_t *mydata;
+ if (ftdm_event_get_raw_data(ftdmchan->sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) {
+ /* raw data is available, do something with mydata here */
+ }
+
+
diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c
index ef945cf629..4a995bc8de 100755
--- a/libs/freetdm/mod_freetdm/mod_freetdm.c
+++ b/libs/freetdm/mod_freetdm/mod_freetdm.c
@@ -874,7 +874,7 @@ static switch_status_t channel_receive_message_b(switch_core_session_t *session,
default:
break;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1152,7 +1152,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
int argc = 0;
const char *var;
const char *dest_num = NULL, *callerid_num = NULL;
- ftdm_hunting_scheme_t hunting;
+ ftdm_hunting_scheme_t hunting;
+ ftdm_sigmsg_t sigmsg;
+
+ memset(&sigmsg, 0, sizeof(ftdm_sigmsg_t));
if (!outbound_profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n");
@@ -1343,11 +1346,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
if ((var = channel_get_variable(session, var_event, "freetdm_calling_party_category"))) {
ftdm_set_calling_party_category(var, (uint8_t *)&caller_data.cpc);
}
-
- if ((var = channel_get_variable(session, var_event, "freetdm_custom_call_data"))) {
- ftdm_set_string(caller_data.raw_data, var);
- caller_data.raw_data_len = (uint32_t)strlen(var);
- }
if (!zstr(dest)) {
ftdm_set_string(caller_data.dnis.digits, dest);
@@ -1386,7 +1384,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
char *v = h->name + FREETDM_VAR_PREFIX_LEN;
if (!zstr(v)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding outbound freetdm variable %s=%s to channel %d:%d\n", v, h->value, span_id, chan_id);
- ftdm_call_add_var(&caller_data, v, h->value);
+ ftdm_event_add_var(&sigmsg, v, h->value);
}
}
}
@@ -1413,6 +1411,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
hunt_data.caller_profile = caller_profile;
hunt_data.tech_pvt = tech_pvt;
caller_data.priv = &hunt_data;
+ caller_data.sigmsg = &sigmsg;
if ((status = ftdm_call_place(&caller_data, &hunting)) != FTDM_SUCCESS) {
if (tech_pvt->read_codec.implementation) {
@@ -1430,7 +1429,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
}
goto fail;
}
-
ftdm_channel_init(caller_data.fchan);
return SWITCH_CAUSE_SUCCESS;
@@ -1552,6 +1550,8 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session
switch_channel_set_variable_printf(channel, "freetdm_chan_number", "%d", chanid);
switch_channel_set_variable_printf(channel, "freetdm_bearer_capability", "%d", channel_caller_data->bearer_capability);
switch_channel_set_variable_printf(channel, "freetdm_bearer_layer1", "%d", channel_caller_data->bearer_layer1);
+ switch_channel_set_variable_printf(channel, "screening_ind", ftdm_screening2str(channel_caller_data->screen));
+ switch_channel_set_variable_printf(channel, "presentation_ind", ftdm_presentation2str(channel_caller_data->pres));
if (globals.sip_headers) {
switch_channel_set_variable(channel, "sip_h_X-FreeTDM-SpanName", ftdm_channel_get_span_name(sigmsg->channel));
@@ -1577,28 +1577,17 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session
switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-Screen", "%d", channel_caller_data->screen);
switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-Presentation", "%d", channel_caller_data->pres);
}
- if (channel_caller_data->raw_data_len) {
- switch_channel_set_variable_printf(channel, "freetdm_custom_call_data", "%s", channel_caller_data->raw_data);
- }
- /* Add any channel variable to the dial plan */
- iter = ftdm_channel_get_var_iterator(sigmsg->channel, NULL);
- for (curr = iter ; curr; curr = ftdm_iterator_next(curr)) {
- ftdm_channel_get_current_var(curr, &var_name, &var_value);
- snprintf(name, sizeof(name), FREETDM_VAR_PREFIX "%s", var_name);
- switch_channel_set_variable_printf(channel, name, "%s", var_value);
- }
/* Add any call variable to the dial plan */
- iter = ftdm_call_get_var_iterator(channel_caller_data, iter);
+ iter = ftdm_event_get_var_iterator(sigmsg, iter);
for (curr = iter ; curr; curr = ftdm_iterator_next(curr)) {
- ftdm_call_get_current_var(curr, &var_name, &var_value);
+ ftdm_event_get_current_var(curr, &var_name, &var_value);
snprintf(name, sizeof(name), FREETDM_VAR_PREFIX "%s", var_name);
switch_channel_set_variable_printf(channel, name, "%s", var_value);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call Variable: %s=%s\n", name, var_value);
}
ftdm_iterator_free(iter);
-
switch_channel_set_state(channel, CS_INIT);
if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
@@ -2149,8 +2138,6 @@ static FIO_SIGNAL_CB_FUNCTION(on_clear_channel_signal)
switch(sigmsg->event_id) {
case FTDM_SIGEVENT_START:
{
- ftdm_call_add_var(caller_data, "screening_ind", ftdm_screening2str(caller_data->screen));
- ftdm_call_add_var(caller_data, "presentation_ind", ftdm_presentation2str(caller_data->pres));
return ftdm_channel_from_event(sigmsg, &session);
}
break;
diff --git a/libs/freetdm/msvc/freetdm.2008.vcproj b/libs/freetdm/msvc/freetdm.2008.vcproj
index 0539ff3f42..348a66f50b 100644
--- a/libs/freetdm/msvc/freetdm.2008.vcproj
+++ b/libs/freetdm/msvc/freetdm.2008.vcproj
@@ -428,6 +428,10 @@
RelativePath="..\src\ftdm_call_utils.c"
>
+
+
diff --git a/libs/freetdm/msvc/freetdm.2010.vcxproj b/libs/freetdm/msvc/freetdm.2010.vcxproj
index aecb9ef79c..62a36ff225 100644
--- a/libs/freetdm/msvc/freetdm.2010.vcxproj
+++ b/libs/freetdm/msvc/freetdm.2010.vcxproj
@@ -203,6 +203,7 @@
+
@@ -222,4 +223,4 @@
-
\ No newline at end of file
+
diff --git a/libs/freetdm/msvc/freetdm.2010.vcxproj.filters b/libs/freetdm/msvc/freetdm.2010.vcxproj.filters
index e6dc40d372..9f15c9c737 100644
--- a/libs/freetdm/msvc/freetdm.2010.vcxproj.filters
+++ b/libs/freetdm/msvc/freetdm.2010.vcxproj.filters
@@ -85,6 +85,9 @@
Source Files
+
+ Source Files
+
Source Files
@@ -131,4 +134,4 @@
Source Files
-
\ No newline at end of file
+
diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c
index 01125e2f61..bd7b043a34 100644
--- a/libs/freetdm/src/ftdm_io.c
+++ b/libs/freetdm/src/ftdm_io.c
@@ -62,10 +62,8 @@ struct tm *localtime_r(const time_t *clock, struct tm *result);
ftdm_time_t time_last_throttle_log = 0;
ftdm_time_t time_current_throttle_log = 0;
-static ftdm_iterator_t *get_iterator(ftdm_iterator_type_t type, ftdm_iterator_t *iter);
static ftdm_status_t ftdm_call_set_call_id(ftdm_channel_t *fchan, ftdm_caller_data_t *caller_data);
static ftdm_status_t ftdm_call_clear_call_id(ftdm_caller_data_t *caller_data);
-static ftdm_status_t ftdm_channel_clear_vars(ftdm_channel_t *ftdmchan);
static ftdm_status_t ftdm_channel_done(ftdm_channel_t *ftdmchan);
static int time_is_init = 0;
@@ -2390,12 +2388,14 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_send_msg(const char *file, const ch
#endif
ftdm_channel_lock(ftdmchan);
+ ftdm_channel_save_event_data(ftdmchan);
if (ftdmchan->span->send_msg) {
status = ftdmchan->span->send_msg(ftdmchan, sigmsg);
} else {
status = FTDM_NOTIMPL;
ftdm_log(FTDM_LOG_ERROR, "send_msg method not implemented in this span!\n");
}
+ ftdm_channel_clear_event_data(ftdmchan);
ftdm_channel_unlock(ftdmchan);
return status;
}
@@ -2450,13 +2450,12 @@ static ftdm_status_t _ftdm_channel_call_place_nl(const char *file, const char *f
goto done;
}
- /* in case of success, *before* unlocking the channel, we must set the call started flag and the call id
- * that is a guarantee that signaling modules expect from us */
ftdm_set_flag(ftdmchan, FTDM_CHANNEL_CALL_STARTED);
ftdm_call_set_call_id(ftdmchan, &ftdmchan->caller_data);
if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_NONBLOCK)) {
- /* be aware this waiting unlocks the channel and locks it back when done */
- ftdm_wait_for_flag_cleared(ftdmchan, FTDM_CHANNEL_STATE_CHANGE, 100);
+ ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 1);
+ } else {
+ ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 0);
}
done:
@@ -2633,7 +2632,7 @@ static ftdm_status_t ftdm_channel_done(ftdm_channel_t *ftdmchan)
ftdm_buffer_destroy(&ftdmchan->pre_buffer);
ftdmchan->pre_buffer_size = 0;
ftdm_mutex_unlock(ftdmchan->pre_buffer_mutex);
- ftdm_channel_clear_vars(ftdmchan);
+
if (ftdmchan->hangup_timer) {
ftdm_sched_cancel_timer(globals.timingsched, ftdmchan->hangup_timer);
}
@@ -4032,166 +4031,7 @@ done:
return status;
}
-FT_DECLARE(void) ftdm_call_clear_data(ftdm_caller_data_t *caller_data)
-{
- ftdm_call_clear_vars(caller_data);
- memset(&caller_data->raw_data, 0, sizeof(caller_data->raw_data));
- caller_data->raw_data_len = 0;
- return;
-}
-
-FT_DECLARE(ftdm_status_t) ftdm_call_clear_vars(ftdm_caller_data_t *caller_data)
-{
- if (caller_data->variables) {
- hashtable_destroy(caller_data->variables);
- }
- caller_data->variables = NULL;
- return FTDM_SUCCESS;
-}
-
-FT_DECLARE(ftdm_status_t) ftdm_call_remove_var(ftdm_caller_data_t *caller_data, const char *var_name)
-{
- if (caller_data->variables) {
- hashtable_remove(caller_data->variables, (void *)var_name);
- }
-
- return FTDM_SUCCESS;
-}
-
-
-FT_DECLARE(ftdm_status_t) ftdm_call_add_var(ftdm_caller_data_t *caller_data, const char *var_name, const char *value)
-{
- char *t_name = 0, *t_val = 0;
-
- if (!var_name || !value) {
- return FTDM_FAIL;
- }
-
- if (!caller_data->variables) {
- /* initialize on first use */
- caller_data->variables = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys);
- ftdm_assert_return(caller_data->variables, FTDM_FAIL, "Failed to create hash table\n");
- }
-
- t_name = ftdm_strdup(var_name);
- t_val = ftdm_strdup(value);
- hashtable_insert(caller_data->variables, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE);
- return FTDM_SUCCESS;
-}
-
-FT_DECLARE(const char *) ftdm_call_get_var(ftdm_caller_data_t *caller_data, const char *var_name)
-{
- const char *var = NULL;
-
- if (!caller_data->variables || !var_name) {
- return NULL;
- }
-
- var = (const char *)hashtable_search(((struct hashtable*)caller_data->variables), (void *)var_name);
- return var;
-}
-
-FT_DECLARE(ftdm_iterator_t *) ftdm_call_get_var_iterator(const ftdm_caller_data_t *caller_data, ftdm_iterator_t *iter)
-{
- ftdm_hash_iterator_t *hashiter = NULL;
- hashiter = caller_data->variables == NULL ? NULL : hashtable_first(caller_data->variables);
-
- if (hashiter == NULL) {
- return NULL;
- }
-
- if (!(iter = get_iterator(FTDM_ITERATOR_VARS, iter))) {
- return NULL;
- }
- iter->pvt.hashiter = hashiter;
- return iter;
-}
-
-FT_DECLARE(ftdm_status_t) ftdm_call_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val)
-{
- const void *key = NULL;
- void *val = NULL;
-
- *var_name = NULL;
- *var_val = NULL;
-
- ftdm_assert_return(iter && (iter->type == FTDM_ITERATOR_VARS) && iter->pvt.hashiter, FTDM_FAIL, "Cannot get variable from invalid iterator!\n");
-
- hashtable_this(iter->pvt.hashiter, &key, NULL, &val);
-
- *var_name = key;
- *var_val = val;
-
- return FTDM_SUCCESS;
-}
-
-
-static ftdm_status_t ftdm_channel_clear_vars(ftdm_channel_t *ftdmchan)
-{
- ftdm_channel_lock(ftdmchan);
-
- if (ftdmchan->variable_hash) {
- hashtable_destroy(ftdmchan->variable_hash);
- }
- ftdmchan->variable_hash = NULL;
-
- ftdm_channel_unlock(ftdmchan);
- return FTDM_SUCCESS;
-}
-
-FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const char *var_name, const char *value)
-{
- char *t_name = 0, *t_val = 0;
-
- ftdm_status_t status = FTDM_FAIL;
-
- if (!var_name || !value) {
- return FTDM_FAIL;
- }
-
- ftdm_channel_lock(ftdmchan);
-
- if (!ftdmchan->variable_hash) {
- /* initialize on first use */
- ftdmchan->variable_hash = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys);
- if (!ftdmchan->variable_hash) {
- goto done;
- }
- }
-
- t_name = ftdm_strdup(var_name);
- t_val = ftdm_strdup(value);
-
- hashtable_insert(ftdmchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE);
-
- status = FTDM_SUCCESS;
-
-done:
- ftdm_channel_unlock(ftdmchan);
-
- return status;
-}
-
-
-FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name)
-{
- const char *var = NULL;
-
- ftdm_channel_lock(ftdmchan);
-
- if (!ftdmchan->variable_hash || !var_name) {
- goto done;
- }
-
- var = (const char *)hashtable_search(ftdmchan->variable_hash, (void *)var_name);
-
-done:
- ftdm_channel_unlock(ftdmchan);
-
- return var;
-}
-
-static ftdm_iterator_t *get_iterator(ftdm_iterator_type_t type, ftdm_iterator_t *iter)
+FT_DECLARE(ftdm_iterator_t) *get_iterator(ftdm_iterator_type_t type, ftdm_iterator_t *iter)
{
int allocated = 0;
if (iter) {
@@ -4215,25 +4055,6 @@ static ftdm_iterator_t *get_iterator(ftdm_iterator_type_t type, ftdm_iterator_t
return iter;
}
-FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t *ftdmchan, ftdm_iterator_t *iter)
-{
- ftdm_hash_iterator_t *hashiter = NULL;
- ftdm_channel_lock(ftdmchan);
- hashiter = ftdmchan->variable_hash == NULL ? NULL : hashtable_first(ftdmchan->variable_hash);
- ftdm_channel_unlock(ftdmchan);
-
-
- if (hashiter == NULL) {
- return NULL;
- }
-
- if (!(iter = get_iterator(FTDM_ITERATOR_VARS, iter))) {
- return NULL;
- }
- iter->pvt.hashiter = hashiter;
- return iter;
-}
-
FT_DECLARE(ftdm_iterator_t *) ftdm_span_get_chan_iterator(const ftdm_span_t *span, ftdm_iterator_t *iter)
{
if (!(iter = get_iterator(FTDM_ITERATOR_CHANS, iter))) {
@@ -4244,24 +4065,6 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_span_get_chan_iterator(const ftdm_span_t *spa
return iter;
}
-FT_DECLARE(ftdm_status_t) ftdm_channel_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val)
-{
- const void *key = NULL;
- void *val = NULL;
-
- *var_name = NULL;
- *var_val = NULL;
-
- ftdm_assert_return(iter && (iter->type == FTDM_ITERATOR_VARS) && iter->pvt.hashiter, FTDM_FAIL, "Cannot get variable from invalid iterator!\n");
-
- hashtable_this(iter->pvt.hashiter, &key, NULL, &val);
-
- *var_name = key;
- *var_val = val;
-
- return FTDM_SUCCESS;
-}
-
FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter)
{
ftdm_assert_return(iter && iter->type, NULL, "Invalid iterator\n");
@@ -5476,13 +5279,8 @@ static ftdm_status_t ftdm_span_trigger_signal(const ftdm_span_t *span, ftdm_sigm
{
ftdm_status_t status = span->signal_cb(sigmsg);
if (sigmsg->channel) {
- ftdm_call_clear_data(&(sigmsg->channel->caller_data));
- }
- if (sigmsg->raw.autofree) {
- ftdm_safe_free(sigmsg->raw.data);
- sigmsg->raw.data = NULL;
- sigmsg->raw.len = 0;
- }
+ ftdm_channel_clear_event_data(sigmsg->channel);
+ }
return status;
}
@@ -6221,6 +6019,71 @@ static ftdm_status_t ftdm_call_clear_call_id(ftdm_caller_data_t *caller_data)
return FTDM_SUCCESS;
}
+FT_DECLARE(ftdm_status_t) ftdm_event_get_raw_data(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen)
+{
+ if (!sigmsg || !sigmsg->raw.len) {
+ return FTDM_FAIL;
+ }
+
+ *data = sigmsg->raw.data;
+ *datalen = sigmsg->raw.len;
+
+ return FTDM_SUCCESS;
+}
+
+FT_DECLARE(ftdm_status_t) ftdm_event_set_raw_data(ftdm_sigmsg_t *sigmsg, void *data, ftdm_size_t datalen, uint8_t autofree)
+{
+ ftdm_assert_return(sigmsg, FTDM_FAIL, "Trying to set raw data on a NULL event\n");
+ ftdm_assert_return(sigmsg->raw.len, FTDM_FAIL, "Overwriting existing raw data\n");
+
+ sigmsg->raw.data = ftdm_calloc(1, datalen);
+ memcpy(sigmsg->raw.data, data, datalen);
+ sigmsg->raw.len = datalen;
+ sigmsg->raw.autofree = autofree;
+
+ return FTDM_SUCCESS;
+}
+
+FT_DECLARE(ftdm_status_t) ftdm_channel_save_event_data(ftdm_channel_t *ftdmchan)
+{
+ ftdm_assert_return(!ftdmchan->sigmsg, FTDM_FAIL, "Info from previous event was not cleared\n");
+ if (ftdmchan->caller_data.sigmsg) {
+ /* Copy sigmsg from user to internal copy so user can set new variables without race condition */
+ ftdmchan->sigmsg = ftdm_calloc(1, sizeof(ftdm_sigmsg_t));
+ memcpy(ftdmchan->sigmsg, ftdmchan->caller_data.sigmsg, sizeof(ftdm_sigmsg_t));
+
+ if (ftdmchan->caller_data.sigmsg->raw.data) {
+ ftdm_event_set_raw_data(ftdmchan->sigmsg, ftdmchan->caller_data.sigmsg->raw.data, ftdmchan->caller_data.sigmsg->raw.len, 1);
+
+ if (ftdmchan->caller_data.sigmsg->raw.autofree) {
+ ftdm_safe_free(ftdmchan->caller_data.sigmsg->raw.data);
+ }
+ }
+ ftdmchan->caller_data.sigmsg = NULL;
+ }
+ return FTDM_SUCCESS;
+}
+
+FT_DECLARE(ftdm_status_t) ftdm_channel_clear_event_data(ftdm_channel_t *ftdmchan)
+{
+ if (!ftdmchan->sigmsg) {
+ return FTDM_SUCCESS;
+ }
+
+ if (ftdmchan->sigmsg->variables) {
+ ftdm_event_clear_vars(ftdmchan->sigmsg);
+ }
+
+ if (ftdmchan->sigmsg->raw.data && ftdmchan->sigmsg->raw.autofree) {
+ ftdm_safe_free(ftdmchan->sigmsg->raw.data);
+ ftdmchan->sigmsg->raw.data = NULL;
+ ftdmchan->sigmsg->raw.len = 0;
+ }
+
+ ftdm_safe_free(ftdmchan->sigmsg);
+ ftdmchan->sigmsg = NULL;
+ return FTDM_SUCCESS;
+}
diff --git a/libs/freetdm/src/ftdm_state.c b/libs/freetdm/src/ftdm_state.c
index de62c0f0e7..08902421cd 100644
--- a/libs/freetdm/src/ftdm_state.c
+++ b/libs/freetdm/src/ftdm_state.c
@@ -40,13 +40,15 @@ FTDM_STR2ENUM(ftdm_str2ftdm_channel_state, ftdm_channel_state2str, ftdm_channel_
FTDM_ENUM_NAMES(CHANNEL_STATE_STATUS_NAMES, CHANNEL_STATE_STATUS_STRINGS)
FTDM_STR2ENUM(ftdm_str2ftdm_state_status, ftdm_state_status2str, ftdm_state_status_t, CHANNEL_STATE_STATUS_NAMES, FTDM_STATE_STATUS_INVALID)
+static ftdm_status_t ftdm_core_set_state(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int waitrq);
+
/* This function is only needed for boost and we should get rid of it at the next refactoring */
FT_DECLARE(ftdm_status_t) ftdm_channel_init(ftdm_channel_t *fchan)
{
ftdm_channel_lock(fchan);
if (fchan->init_state != FTDM_CHANNEL_STATE_DOWN) {
- ftdm_channel_set_state(__FILE__, __FUNCTION__, __LINE__, fchan, fchan->init_state, 1);
+ ftdm_core_set_state(__FILE__, __FUNCTION__, __LINE__, fchan, fchan->init_state, 1);
fchan->init_state = FTDM_CHANNEL_STATE_DOWN;
}
@@ -121,7 +123,7 @@ FT_DECLARE(ftdm_status_t) _ftdm_set_state(const char *file, const char *func, in
the current state */
_ftdm_channel_complete_state(file, func, line, fchan);
}
- return ftdm_channel_set_state(file, func, line, fchan, state, 0);
+ return ftdm_core_set_state(file, func, line, fchan, state, 0);
}
static int ftdm_parse_state_map(ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, ftdm_state_map_t *state_map)
@@ -223,9 +225,18 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_cancel_state(const char *file, const char
return FTDM_SUCCESS;
}
+
+FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int waitrq)
+{
+ if (ftdm_channel_save_event_data(ftdmchan) == FTDM_SUCCESS) {
+ return ftdm_core_set_state(file, func, line, ftdmchan, state, waitrq);
+ }
+ return FTDM_FAIL;
+}
+
/* this function MUST be called with the channel lock held. If waitrq == 1, the channel will be unlocked/locked (never call it with waitrq == 1 with an lock recursivity > 1) */
#define DEFAULT_WAIT_TIME 1000
-FT_DECLARE(ftdm_status_t) ftdm_channel_set_state(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int waitrq)
+static ftdm_status_t ftdm_core_set_state(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int waitrq)
{
ftdm_status_t status;
int ok = 1;
@@ -514,6 +525,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_advance_states(ftdm_channel_t *fchan)
* call to ftdm_set_state() */
fchan->state_status = FTDM_STATE_STATUS_PROCESSED;
}
+ ftdm_channel_clear_event_data(fchan);
}
return FTDM_SUCCESS;
diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c
index 608b0b6ac0..9947d40d76 100644
--- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c
+++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c
@@ -649,8 +649,7 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Sending incoming call from %s to %s to FTDM core\n", ftdmchan->caller_data.ani.digits, ftdmchan->caller_data.dnis.digits);
/* we have enough information to inform FTDM of the call*/
- sigev.event_id = FTDM_SIGEVENT_START;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_START);
}
break;
case FTDM_CHANNEL_STATE_DIALING: /* outgoing call request */
@@ -674,8 +673,8 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
{
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
/*OUTBOUND...so we were told by the line of this so noifiy the user*/
- sigev.event_id = FTDM_SIGEVENT_PROCEED;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_PROCEED);
+
if (sngisdn_test_flag(sngisdn_info, FLAG_MEDIA_READY)) {
ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA);
}
@@ -694,8 +693,8 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
{
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
/* OUTBOUND...so we were told by the line of this so notify the user */
- sigev.event_id = FTDM_SIGEVENT_RINGING;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_RINGING);
+
if (sngisdn_test_flag(sngisdn_info, FLAG_MEDIA_READY)) {
ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA);
}
@@ -710,8 +709,8 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
/*check if the channel is inbound or outbound*/
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
/*OUTBOUND...so we were told by the line of this so noifiy the user*/
- sigev.event_id = FTDM_SIGEVENT_PROGRESS;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_PROGRESS);
} else {
/* Send a progress message, indicating: Call is not end-to-end ISDN, further call progress may be available */
ftdm_sngisdn_progind_t prog_ind = {SNGISDN_PROGIND_LOC_USER, SNGISDN_PROGIND_DESCR_NETE_ISDN};
@@ -722,8 +721,7 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
case FTDM_CHANNEL_STATE_PROGRESS_MEDIA:
{
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
- sigev.event_id = FTDM_SIGEVENT_PROGRESS_MEDIA;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_PROGRESS_MEDIA);
} else {
/* Send a progress message, indicating: In-band information/pattern available */
ftdm_sngisdn_progind_t prog_ind = {SNGISDN_PROGIND_LOC_USER, SNGISDN_PROGIND_DESCR_IB_AVAIL};
@@ -736,8 +734,8 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
/* check if the channel is inbound or outbound */
if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND)) {
/* OUTBOUND ... so we were told by the line that the other side answered */
- sigev.event_id = FTDM_SIGEVENT_UP;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_UP);
if (ftdmchan->span->trunk_type == FTDM_TRUNK_BRI_PTMP &&
((sngisdn_span_data_t*)ftdmchan->span->signal_data)->signalling == SNGISDN_SIGNALING_NET) {
@@ -763,8 +761,7 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
case FTDM_CHANNEL_STATE_TERMINATING: /* call is hung up by the remote end */
{
/* this state is set when the line is hanging up */
- sigev.event_id = FTDM_SIGEVENT_STOP;
- ftdm_span_send_signal(ftdmchan->span, &sigev);
+ sngisdn_send_signal(sngisdn_info, FTDM_SIGEVENT_STOP);
}
break;
case FTDM_CHANNEL_STATE_HANGUP: /* call is hung up locally */
@@ -878,7 +875,22 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm
}
break;
}
-
+
+ /* If sngisdn_info->variables is not NULL, it means did not send any
+ * sigevent to the user, therefore we have to free that sigmsg */
+ if (sngisdn_info->variables) {
+ hashtable_destroy(sngisdn_info->variables);
+ sngisdn_info->variables = NULL;
+ }
+
+ /* If sngisdn_info->raw_data is not NULL, it means did not send any
+ * sigevent to the user, therefore we have to free that sigmsg */
+ if (sngisdn_info->raw_data) {
+ ftdm_safe_free(sngisdn_info->raw_data);
+ sngisdn_info->raw_data = NULL;
+ sngisdn_info->raw_data_len = 0;
+ }
+
if (ftdmchan->state == initial_state) {
ftdm_assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE), "state change flag is still set, but we did not change state\n");
}
@@ -902,8 +914,7 @@ static FIO_CHANNEL_SEND_MSG_FUNCTION(ftdm_sangoma_isdn_send_msg)
default:
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Unsupported signalling msg requested\n");
status = FTDM_BREAK;
- }
- ftdm_call_clear_data(&ftdmchan->caller_data);
+ }
return status;
}
@@ -911,34 +922,25 @@ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(ftdm_sangoma_isdn_outgoing_call)
{
sngisdn_chan_data_t *sngisdn_info = ftdmchan->call_data;
ftdm_status_t status = FTDM_FAIL;
-
- switch (ftdmchan->state) {
- case FTDM_CHANNEL_STATE_DOWN:
- {
- if (sngisdn_test_flag(sngisdn_info, FLAG_GLARE)) {
- /* A call came in after we called ftdm_channel_open_chan for this call, but before we got here */
- ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Glare detected - aborting outgoing call\n");
+ if (ftdmchan->state == FTDM_CHANNEL_STATE_DOWN) {
+ if (sngisdn_test_flag(sngisdn_info, FLAG_GLARE)) {
+ /* A call came in after we called ftdm_channel_open_chan for this call, but before we got here */
+ ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Glare detected - aborting outgoing call\n");
- sngisdn_set_flag(sngisdn_info, FLAG_LOCAL_ABORT);
- ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE);
+ sngisdn_set_flag(sngisdn_info, FLAG_LOCAL_ABORT);
+ ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_HANGUP_COMPLETE);
- status = FTDM_BREAK;
- } else {
- ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_DIALING);
- status = FTDM_SUCCESS;
- }
- }
- break;
- default:
- {
- /* the channel is already used...this can't be, end the request */
- ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Outgoing call requested channel in already in use\n");
status = FTDM_BREAK;
+ } else {
+ status = FTDM_SUCCESS;
}
- break;
+ } else {
+ /* the channel is already used...this can't be, end the request */
+ ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Outgoing call requested channel in already in use (%s)\n", ftdm_channel_state2str(ftdmchan->state));
+ status = FTDM_BREAK;
}
-
+
return status;
}
static FIO_CHANNEL_GET_SIG_STATUS_FUNCTION(ftdm_sangoma_isdn_get_chan_sig_status)
diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h
index 80dc73f0fa..79ca889d25 100644
--- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h
+++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h
@@ -179,6 +179,15 @@ typedef struct sngisdn_chan_data {
uint8_t globalFlg;
sngisdn_glare_data_t glare;
ftdm_timer_id_t timers[SNGISDN_NUM_TIMERS];
+
+ /* variables saved here will be sent to the user application
+ on next SIGEVENT_XXX */
+ ftdm_hash_t* variables;
+
+ /* raw_data saved here will be sent to the user application
+ on next SIGEVENT_XXX */
+ void *raw_data;
+ ftdm_size_t raw_data_len;
} sngisdn_chan_data_t;
/* Span specific data */
@@ -414,6 +423,12 @@ ftdm_status_t set_restart_ind_ie(ftdm_channel_t *ftdmchan, RstInd *rstInd);
ftdm_status_t set_facility_ie(ftdm_channel_t *ftdmchan, FacilityStr *facilityStr);
ftdm_status_t set_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8_t *data_len);
+
+ftdm_status_t sngisdn_add_var(sngisdn_chan_data_t *sngisdn_info, const char* var, const char* val);
+ftdm_status_t sngisdn_add_raw_data(sngisdn_chan_data_t *sngisdn_info, uint8_t* data, ftdm_size_t data_len);
+ftdm_status_t sngisdn_clear_data(sngisdn_chan_data_t *sngisdn_info);
+void sngisdn_send_signal(sngisdn_chan_data_t *sngisdn_info, ftdm_signal_event_t event_id);
+
uint8_t sngisdn_get_infoTranCap_from_user(ftdm_bearer_cap_t bearer_capability);
uint8_t sngisdn_get_usrInfoLyr1Prot_from_user(ftdm_user_layer1_prot_t layer1_prot);
ftdm_bearer_cap_t sngisdn_get_infoTranCap_from_stack(uint8_t bearer_capability);
diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c
index 4b27f21e1c..be204e5eb3 100644
--- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c
+++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c
@@ -156,8 +156,6 @@ void sngisdn_snd_proceed(ftdm_channel_t *ftdmchan, ftdm_sngisdn_progind_t prog_i
set_prog_ind_ie(ftdmchan, &cnStEvnt.progInd, prog_ind);
set_facility_ie(ftdmchan, &cnStEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
-
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending PROCEED (suId:%d suInstId:%u spInstId:%u dchan:%d ces:%d)\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, signal_data->dchan_id, sngisdn_info->ces);
if(sng_isdn_con_status(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, &cnStEvnt, MI_CALLPROC, signal_data->dchan_id, sngisdn_info->ces)) {
@@ -189,7 +187,6 @@ void sngisdn_snd_progress(ftdm_channel_t *ftdmchan, ftdm_sngisdn_progind_t prog_
memset(&cnStEvnt, 0, sizeof(cnStEvnt));
set_prog_ind_ie(ftdmchan, &cnStEvnt.progInd, prog_ind);
set_facility_ie(ftdmchan, &cnStEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending PROGRESS (suId:%d suInstId:%u spInstId:%u dchan:%d ces:%d)\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, signal_data->dchan_id, sngisdn_info->ces);
if(sng_isdn_con_status(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId,&cnStEvnt, MI_PROGRESS, signal_data->dchan_id, sngisdn_info->ces)) {
@@ -216,7 +213,6 @@ void sngisdn_snd_alert(ftdm_channel_t *ftdmchan, ftdm_sngisdn_progind_t prog_ind
set_prog_ind_ie(ftdmchan, &cnStEvnt.progInd, prog_ind);
set_facility_ie(ftdmchan, &cnStEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending ALERT (suId:%d suInstId:%u spInstId:%u dchan:%d ces:%d)\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, signal_data->dchan_id, sngisdn_info->ces);
@@ -241,11 +237,10 @@ void sngisdn_snd_connect(ftdm_channel_t *ftdmchan)
}
memset(&cnStEvnt, 0, sizeof(cnStEvnt));
-
+
set_chan_id_ie(ftdmchan, &cnStEvnt.chanId);
set_prog_ind_ie(ftdmchan, &cnStEvnt.progInd, prog_ind);
set_facility_ie(ftdmchan, &cnStEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending CONNECT (suId:%d suInstId:%u spInstId:%u dchan:%d ces:%d)\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, signal_data->dchan_id, sngisdn_info->ces);
if (sng_isdn_con_response(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, &cnStEvnt, signal_data->dchan_id, sngisdn_info->ces)) {
@@ -272,7 +267,6 @@ void sngisdn_snd_fac_req(ftdm_channel_t *ftdmchan)
/* No point in sending a FACILITY message if there is no Facility IE to transmit */
return;
}
- ftdm_call_clear_data(&ftdmchan->caller_data);
facEvnt.facElmt.eh.pres = PRSNT_NODEF;
facEvnt.facElmt.facStr.pres = PRSNT_NODEF;
@@ -306,7 +300,7 @@ void sngisdn_snd_info_req(ftdm_channel_t *ftdmchan)
//ftdm_log_chan_msg(ftdmchan, FTDM_LOG_INFO, "Sending INFO REQ\n");
- ftdm_call_clear_data(&ftdmchan->caller_data);
+
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending INFO REQ (suId:%d dchan:%d ces:%d)\n", signal_data->cc_id, signal_data->dchan_id, sngisdn_info->ces);
@@ -327,8 +321,6 @@ void sngisdn_snd_status_enq(ftdm_channel_t *ftdmchan)
//ftdm_log_chan_msg(ftdmchan, FTDM_LOG_INFO, "Sending STATUS ENQ\n");
memset(&staEvnt, 0, sizeof(StaEvnt));
-
- ftdm_call_clear_data(&ftdmchan->caller_data);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Sending Status ENQ on suId:%d suInstId:%u spInstId:%d dchan:%d ces:%d\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, signal_data->dchan_id, sngisdn_info->ces);
if (sng_isdn_status_request(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, &staEvnt, MI_STATENQ)) {
@@ -367,8 +359,7 @@ void sngisdn_snd_disconnect(ftdm_channel_t *ftdmchan)
discEvnt.causeDgn[0].recommend.pres = NOTPRSNT;
discEvnt.causeDgn[0].dgnVal.pres = NOTPRSNT;
- set_facility_ie(ftdmchan, &discEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
+ set_facility_ie(ftdmchan, &discEvnt.facilityStr);
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending DISCONNECT (suId:%d suInstId:%u spInstId:%u)\n", signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId);
if (sng_isdn_disc_request(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, &discEvnt)) {
@@ -416,7 +407,6 @@ void sngisdn_snd_release(ftdm_channel_t *ftdmchan, uint8_t glare)
}
set_facility_ie(ftdmchan, &relEvnt.facilityStr);
- ftdm_call_clear_data(&ftdmchan->caller_data);
ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending RELEASE/RELEASE COMPLETE (suId:%d suInstId:%u spInstId:%u)\n", signal_data->cc_id, suInstId, spInstId);
diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c
index 23fe08b983..55e72a84f5 100644
--- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c
+++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c
@@ -225,26 +225,26 @@ ftdm_status_t get_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
}
if (cgPtyNmb->screenInd.pres == PRSNT_NODEF) {
- ftdm_call_add_var(caller_data, "isdn.cg_pty2.screen_ind", ftdm_screening2str(cgPtyNmb->screenInd.val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.cg_pty2.screen_ind", ftdm_screening2str(cgPtyNmb->screenInd.val));
}
if (cgPtyNmb->presInd0.pres == PRSNT_NODEF) {
- ftdm_call_add_var(caller_data, "isdn.cg_pty2.presentation_ind", ftdm_presentation2str(cgPtyNmb->presInd0.val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.cg_pty2.presentation_ind", ftdm_presentation2str(cgPtyNmb->presInd0.val));
}
if (cgPtyNmb->nmbPlanId.pres == PRSNT_NODEF) {
- ftdm_call_add_var(caller_data, "isdn.cg_pty2.npi", ftdm_npi2str(cgPtyNmb->nmbPlanId.val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.cg_pty2.npi", ftdm_npi2str(cgPtyNmb->nmbPlanId.val));
}
if (cgPtyNmb->typeNmb1.pres == PRSNT_NODEF) {
- ftdm_call_add_var(caller_data, "isdn.cg_pty2.ton", ftdm_ton2str(cgPtyNmb->typeNmb1.val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.cg_pty2.ton", ftdm_ton2str(cgPtyNmb->typeNmb1.val));
}
if (cgPtyNmb->nmbDigits.pres == PRSNT_NODEF) {
char digits_string [32];
memcpy(digits_string, (const char*)cgPtyNmb->nmbDigits.val, cgPtyNmb->nmbDigits.len);
digits_string[cgPtyNmb->nmbDigits.len] = '\0';
- ftdm_call_add_var(caller_data, "isdn.cg_pty2.digits", digits_string);
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.cg_pty2.digits", digits_string);
}
memcpy(&caller_data->ani, &caller_data->cid_num, sizeof(caller_data->ani));
return FTDM_SUCCESS;
@@ -343,7 +343,7 @@ ftdm_status_t get_calling_subaddr(ftdm_channel_t *ftdmchan, CgPtySad *cgPtySad)
memcpy(subaddress, (char*)cgPtySad->sadInfo.val, cgPtySad->sadInfo.len);
subaddress[cgPtySad->sadInfo.len] = '\0';
- ftdm_call_add_var(&ftdmchan->caller_data, "isdn.calling_subaddr", subaddress);
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.calling_subaddr", subaddress);
return FTDM_SUCCESS;
}
@@ -358,21 +358,20 @@ ftdm_status_t get_facility_ie(ftdm_channel_t *ftdmchan, FacilityStr *facilityStr
ftdm_status_t get_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8_t data_len)
{
- ftdm_caller_data_t *caller_data = &ftdmchan->caller_data;
sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) ftdmchan->span->signal_data;
if (signal_data->facility_ie_decode == SNGISDN_OPT_FALSE) {
- /* size of facilityStr->facilityStr.len is a uint8_t so no need to check
- for overflow here as facilityStr->facilityStr.len will always be smaller
- than sizeof(caller_data->raw_data) */
+ /* Max size of Facility IE is 255 */
+ uint8_t my_data [255];
- memset(caller_data->raw_data, 0, sizeof(caller_data->raw_data));
/* Always include Facility IE identifier + len so this can be used as a sanity check by the user */
- caller_data->raw_data[0] = SNGISDN_Q931_FACILITY_IE_ID;
- caller_data->raw_data[1] = data_len;
-
- memcpy(&caller_data->raw_data[2], data, data_len);
- caller_data->raw_data_len = data_len+2;
+ my_data[0] = SNGISDN_Q931_FACILITY_IE_ID;
+ my_data[1] = data_len;
+ memcpy(&my_data[2], data, data_len);
+
+
+ sngisdn_add_raw_data((sngisdn_chan_data_t*)ftdmchan->call_data, data, data_len+2);
+
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "Raw Facility IE copied available\n");
} else {
/* Call libsng_isdn to process facility IE's here */
@@ -412,7 +411,7 @@ ftdm_status_t get_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd)
val = SNGISDN_PROGIND_DESCR_INVALID;
break;
}
- ftdm_call_add_var(&ftdmchan->caller_data, "isdn.prog_ind.descr", ftdm_sngisdn_progind_descr2str(val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.prog_ind.descr", ftdm_sngisdn_progind_descr2str(val));
}
if (progInd->location.pres) {
@@ -443,7 +442,7 @@ ftdm_status_t get_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd)
val = SNGISDN_PROGIND_LOC_INVALID;
break;
}
- ftdm_call_add_var(&ftdmchan->caller_data, "isdn.prog_ind.loc", ftdm_sngisdn_progind_loc2str(val));
+ sngisdn_add_var((sngisdn_chan_data_t*)ftdmchan->call_data, "isdn.prog_ind.loc", ftdm_sngisdn_progind_loc2str(val));
}
return FTDM_SUCCESS;
}
@@ -493,7 +492,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
uint8_t len,val;
ftdm_caller_data_t *caller_data = &ftdmchan->caller_data;
- string = ftdm_call_get_var(caller_data, "isdn.cg_pty2.digits");
+ string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.digits");
if ((string == NULL) || !(*string)) {
return FTDM_FAIL;
}
@@ -510,7 +509,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
cgPtyNmb->screenInd.pres = PRSNT_NODEF;
val = FTDM_SCREENING_INVALID;
- string = ftdm_call_get_var(caller_data, "isdn.cg_pty2.screening_ind");
+ string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.screening_ind");
if ((string != NULL) && (*string)) {
val = ftdm_str2ftdm_screening(string);
}
@@ -527,7 +526,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
cgPtyNmb->presInd0.pres = PRSNT_NODEF;
val = FTDM_PRES_INVALID;
- string = ftdm_call_get_var(caller_data, "isdn.cg_pty2.presentation_ind");
+ string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.presentation_ind");
if ((string != NULL) && (*string)) {
val = ftdm_str2ftdm_presentation(string);
}
@@ -542,7 +541,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
cgPtyNmb->nmbPlanId.pres = PRSNT_NODEF;
val = FTDM_NPI_INVALID;
- string = ftdm_call_get_var(caller_data, "isdn.cg_pty2.npi");
+ string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.npi");
if ((string != NULL) && (*string)) {
val = ftdm_str2ftdm_npi(string);
}
@@ -557,7 +556,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb)
/* Type of Number */
val = FTDM_TON_INVALID;
- string = ftdm_call_get_var(caller_data, "isdn.cg_pty2.ton");
+ string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.ton");
if ((string != NULL) && (*string)) {
val = ftdm_str2ftdm_ton(string);
}
@@ -691,7 +690,7 @@ ftdm_status_t set_calling_name(ftdm_channel_t *ftdmchan, ConEvnt *conEvnt)
ftdm_status_t set_calling_subaddr(ftdm_channel_t *ftdmchan, CgPtySad *cgPtySad)
{
const char* clg_subaddr = NULL;
- clg_subaddr = ftdm_call_get_var(&ftdmchan->caller_data, "isdn.calling_subaddr");
+ clg_subaddr = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.calling_subaddr");
if ((clg_subaddr != NULL) && (*clg_subaddr)) {
unsigned len = strlen (clg_subaddr);
cgPtySad->eh.pres = PRSNT_NODEF;
@@ -721,14 +720,17 @@ ftdm_status_t set_facility_ie(ftdm_channel_t *ftdmchan, FacilityStr *facilityStr
ftdm_status_t set_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8_t *data_len)
{
- int len;
- ftdm_caller_data_t *caller_data = &ftdmchan->caller_data;
- if (caller_data->raw_data_len > 0 && caller_data->raw_data[0] == SNGISDN_Q931_FACILITY_IE_ID) {
- len = caller_data->raw_data[1];
- memcpy(data, &caller_data->raw_data[2], len);
- *data_len = len;
- return FTDM_SUCCESS;
- }
+ ftdm_size_t len;
+ uint8_t *mydata;
+
+ if (ftdm_event_get_raw_data(ftdmchan->sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) {
+ if (len > 2 && mydata[0] == SNGISDN_Q931_FACILITY_IE_ID) {
+ len = mydata[1];
+ memcpy(data, &mydata[2], len);
+ *data_len = len;
+ return FTDM_SUCCESS;
+ }
+ }
return FTDM_FAIL;
}
@@ -738,7 +740,7 @@ ftdm_status_t set_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd, ftdm_s
int descr = prog_ind.descr;
int loc = prog_ind.loc;
- str = ftdm_call_get_var(&ftdmchan->caller_data, "isdn.prog_ind.descr");
+ str = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.prog_ind.descr");
if (str && *str) {
/* User wants to override progress indicator */
descr = ftdm_str2ftdm_sngisdn_progind_descr(str);
@@ -749,7 +751,7 @@ ftdm_status_t set_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd, ftdm_s
return FTDM_SUCCESS;
}
- str = ftdm_call_get_var(&ftdmchan->caller_data, "isdn.prog_ind.loc");
+ str = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.prog_ind.loc");
if (str && *str) {
loc = ftdm_str2ftdm_sngisdn_progind_loc(str);
}
@@ -861,7 +863,7 @@ ftdm_status_t set_chan_id_ie(ftdm_channel_t *ftdmchan, ChanId *chanId)
ftdm_status_t set_bear_cap_ie(ftdm_channel_t *ftdmchan, BearCap *bearCap)
{
sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) ftdmchan->span->signal_data;
-
+
bearCap->eh.pres = PRSNT_NODEF;
bearCap->infoTranCap.pres = PRSNT_NODEF;
bearCap->infoTranCap.val = sngisdn_get_infoTranCap_from_user(ftdmchan->caller_data.bearer_capability);
@@ -1194,6 +1196,75 @@ void sngisdn_print_spans(ftdm_stream_handle_t *stream)
return;
}
+ftdm_status_t sngisdn_add_var(sngisdn_chan_data_t *sngisdn_info, const char* var, const char* val)
+{
+ char *t_name = 0, *t_val = 0;
+ if (!var || !val) {
+ return FTDM_FAIL;
+ }
+ if (!sngisdn_info->variables) {
+ /* initialize on first use */
+ sngisdn_info->variables = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys);
+ ftdm_assert_return(sngisdn_info->variables, FTDM_FAIL, "Failed to create hash table\n");
+ }
+ t_name = ftdm_strdup(var);
+ t_val = ftdm_strdup(val);
+ hashtable_insert(sngisdn_info->variables, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE);
+ return FTDM_SUCCESS;
+}
+
+ftdm_status_t sngisdn_add_raw_data(sngisdn_chan_data_t *sngisdn_info, uint8_t* data, ftdm_size_t data_len)
+{
+ ftdm_assert_return(!sngisdn_info->raw_data, FTDM_FAIL, "Overwriting existing raw data\n");
+
+ sngisdn_info->raw_data = ftdm_calloc(1, data_len);
+ ftdm_assert_return(sngisdn_info->raw_data, FTDM_FAIL, "Failed to allocate raw data\n");
+
+ memcpy(sngisdn_info->raw_data, data, data_len);
+ sngisdn_info->raw_data_len = data_len;
+ return FTDM_SUCCESS;
+}
+
+void sngisdn_send_signal(sngisdn_chan_data_t *sngisdn_info, ftdm_signal_event_t event_id)
+{
+ ftdm_sigmsg_t sigev;
+ ftdm_channel_t *ftdmchan = sngisdn_info->ftdmchan;
+
+ memset(&sigev, 0, sizeof(sigev));
+
+ sigev.chan_id = ftdmchan->chan_id;
+ sigev.span_id = ftdmchan->span_id;
+ sigev.channel = ftdmchan;
+ sigev.event_id = event_id;
+
+ if (sngisdn_info->variables) {
+ /*
+ * variables now belongs to the ftdm core, and
+ * will be cleared after sigev is processed by user. Set
+ * local pointer to NULL so we do not attempt to
+ * destroy it */
+ sigev.variables = sngisdn_info->variables;
+ sngisdn_info->variables = NULL;
+ }
+
+ if (sngisdn_info->raw_data) {
+ /*
+ * raw_data now belongs to the ftdm core, and
+ * will be cleared after sigev is processed by user. Set
+ * local pointer to NULL so we do not attempt to
+ * destroy it */
+
+ sigev.raw.data = sngisdn_info->raw_data;
+ sigev.raw.len = sngisdn_info->raw_data_len;
+ sigev.raw.autofree = 1;
+
+ sngisdn_info->raw_data = NULL;
+ sngisdn_info->raw_data_len = 0;
+ }
+ ftdm_span_send_signal(ftdmchan->span, &sigev);
+}
+
+
/* For Emacs:
* Local Variables:
* mode:c
diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h
index 77abf6ab3e..84adf327dd 100644
--- a/libs/freetdm/src/include/freetdm.h
+++ b/libs/freetdm/src/include/freetdm.h
@@ -172,7 +172,7 @@ typedef enum {
/*! \brief I/O channel type */
typedef enum {
FTDM_CHAN_TYPE_B, /*!< Bearer channel */
- FTDM_CHAN_TYPE_DQ921, /*< DQ921 channel (D-channel) */
+ FTDM_CHAN_TYPE_DQ921, /*!< DQ921 channel (D-channel) */
FTDM_CHAN_TYPE_DQ931, /*!< DQ931 channel */
FTDM_CHAN_TYPE_FXS, /*!< FXS analog channel */
FTDM_CHAN_TYPE_FXO, /*!< FXO analog channel */
@@ -214,6 +214,7 @@ typedef void *(*ftdm_queue_dequeue_func_t)(ftdm_queue_t *queue);
typedef ftdm_status_t (*ftdm_queue_wait_func_t)(ftdm_queue_t *queue, int ms);
typedef ftdm_status_t (*ftdm_queue_get_interrupt_func_t)(ftdm_queue_t *queue, ftdm_interrupt_t **interrupt);
typedef ftdm_status_t (*ftdm_queue_destroy_func_t)(ftdm_queue_t **queue);
+
typedef struct ftdm_queue_handler {
ftdm_queue_create_func_t create;
ftdm_queue_enqueue_func_t enqueue;
@@ -223,7 +224,6 @@ typedef struct ftdm_queue_handler {
ftdm_queue_destroy_func_t destroy;
} ftdm_queue_handler_t;
-
/*! \brief Type Of Number (TON) */
typedef enum {
FTDM_TON_UNKNOWN = 0,
@@ -318,8 +318,6 @@ typedef struct {
uint8_t plan;
} ftdm_number_t;
-typedef void * ftdm_variable_container_t;
-
/*! \brief Caller information */
typedef struct ftdm_caller_data {
char cid_date[8]; /*!< Caller ID date */
@@ -333,21 +331,24 @@ typedef struct ftdm_caller_data {
uint8_t pres; /*!< Presentation*/
char collected[FTDM_DIGITS_LIMIT]; /*!< Collected digits so far */
int hangup_cause; /*!< Hangup cause */
- char raw_data[1024]; /*!< Protocol specific raw caller data */
- uint32_t raw_data_len; /*!< Raw data length */
/* these 2 are undocumented right now, only used by boost: */
/* bearer capability */
ftdm_bearer_cap_t bearer_capability;
/* user information layer 1 protocol */
ftdm_user_layer1_prot_t bearer_layer1;
ftdm_calling_party_category_t cpc; /*!< Calling party category */
- ftdm_variable_container_t variables; /*!< Variables attached to this call */
- /* We need call_id inside caller_data for the user to be able to retrieve
+
+ ftdm_channel_t *fchan; /*!< FreeTDM channel associated (can be NULL) */
+ ftdm_sigmsg_t *sigmsg; /*!< Set by user if additional parameters need to sent */
+
+ /*
+ * We need call_id inside caller_data for the user to be able to retrieve
* the call_id when ftdm_channel_call_place is called. This is the only time
* that the user can use caller_data.call_id to obtain the call_id. The user
- * should use the call_id from sigmsg otherwise */
+ * should use the call_id from sigmsg otherwise
+ */
uint32_t call_id; /*!< Unique call ID for this call */
- ftdm_channel_t *fchan; /*!< FreeTDM channel associated (can be NULL) */
+
void *priv; /*!< Private data for the FreeTDM user */
} ftdm_caller_data_t;
@@ -547,6 +548,8 @@ typedef struct {
ftdm_status_t status;
} ftdm_event_indication_completed_t;
+typedef void * ftdm_variable_container_t;
+
/*! \brief Generic signaling message */
struct ftdm_sigmsg {
ftdm_signal_event_t event_id; /*!< The type of message */
@@ -555,6 +558,7 @@ struct ftdm_sigmsg {
uint32_t span_id; /*!< easy access to span_id */
uint32_t call_id; /*!< unique call id for this call */
void *call_priv; /*!< Private data for the FreeTDM user from ftdm_caller_data->priv */
+ ftdm_variable_container_t variables;
union {
ftdm_event_sigstatus_t sigstatus; /*!< valid if event_id is FTDM_SIGEVENT_SIGSTATUS_CHANGED */
ftdm_event_trace_t trace; /*!< valid if event_id is FTDM_SIGEVENT_TRACE or FTDM_SIGEVENT_TRACE_RAW */
@@ -563,7 +567,7 @@ struct ftdm_sigmsg {
} ev_data;
struct {
uint8_t autofree; /*!< Whether the freetdm core will free it after message delivery */
- uint32_t len; /*!< Data len */
+ ftdm_size_t len; /*!< Data len */
void *data; /*!< Signaling module specific data */
} raw;
};
@@ -1369,24 +1373,49 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data
*/
FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t datasize, ftdm_size_t *datalen);
-/*! \brief Add a custom variable to the channel
+/*! \brief Add a custom variable to the event
* \note This variables may be used by signaling modules to override signaling parameters
* \todo Document which signaling variables are available
* */
-FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const char *var_name, const char *value);
+FT_DECLARE(ftdm_status_t) ftdm_event_add_var(ftdm_sigmsg_t *sigmsg, const char *var_name, const char *value);
-/*! \brief Get a custom variable from the channel.
- * \note The variable pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed. */
-FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name);
+/*! \brief Remove a custom variable from the event
+ * \note The variable pointer returned is only valid while the before the event is processed and it'll be destroyed once the event is processed. */
+FT_DECLARE(ftdm_status_t) ftdm_event_remove_var(ftdm_sigmsg_t *sigmsg, const char *var_name);
-/*! \brief Get an iterator to iterate over the channel variables
- * \param ftdmchan The channel structure containing the variables
+/*! \brief Get a custom variable from the event
+ * \note The variable pointer returned is only valid while the before the event is processed and it'll be destroyed once the event is processed. */
+FT_DECLARE(const char *) ftdm_event_get_var(ftdm_sigmsg_t *sigmsg, const char *var_name);
+
+/*! \brief Get an iterator to iterate over the event variables
+ * \param sigmsg The message structure containing the variables
* \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
* \note The iterator pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed.
* This iterator is completely non-thread safe, if you are adding variables or removing variables while iterating
* results are unpredictable
*/
-FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t *ftdmchan, ftdm_iterator_t *iter);
+FT_DECLARE(ftdm_iterator_t *) ftdm_event_get_var_iterator(const ftdm_sigmsg_t *sigmsg, ftdm_iterator_t *iter);
+
+
+/*! \brief Attach raw data to event
+ * \param sigmsg The message structure containing the variables
+ * \param data pointer to data
+ * \param datalen datalen length of data
+ * \param autofree when set to non-zero, freetdm will automatically free data once event is processed
+ * \retval FTDM_SUCCESS success, data was successfully saved
+ * \retval FTDM_FAIL failed, event already had data attached to it.
+ * \note When using autofree, data must have been allocated using ftdm_calloc.
+ */
+FT_DECLARE(ftdm_status_t) ftdm_event_set_raw_data(ftdm_sigmsg_t *sigmsg, void *data, ftdm_size_t datalen, uint8_t autofree);
+
+/*! \brief Get raw data from event
+ * \param sigmsg The message structure containing the variables
+ * \param data data will point to available data pointer if available
+ * \param datalen datalen will be set to length of data available
+ * \retval FTDM_SUCCESS data is available
+ * \retval FTDM_FAIL no data available
+ */
+FT_DECLARE(ftdm_status_t) ftdm_event_get_raw_data(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen);
/*! \brief Get iterator current value (depends on the iterator type)
* \note Channel iterators return a pointer to ftdm_channel_t
@@ -1395,7 +1424,7 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t
FT_DECLARE(void *) ftdm_iterator_current(ftdm_iterator_t *iter);
/*! \brief Get variable name and value for the current iterator position */
-FT_DECLARE(ftdm_status_t) ftdm_channel_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
+FT_DECLARE(ftdm_status_t) ftdm_event_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
/*! \brief Advance iterator */
FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter);
@@ -1405,40 +1434,6 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter);
*/
FT_DECLARE(ftdm_status_t) ftdm_iterator_free(ftdm_iterator_t *iter);
-/*! \brief Add a custom variable to the call
- * \note This variables may be used by signaling modules to override signaling parameters
- * \todo Document which signaling variables are available
- * */
-FT_DECLARE(ftdm_status_t) ftdm_call_add_var(ftdm_caller_data_t *caller_data, const char *var_name, const char *value);
-
-/*! \brief Get a custom variable from the call.
- * \note The variable pointer returned is only valid during the callback receiving SIGEVENT. */
-FT_DECLARE(const char *) ftdm_call_get_var(ftdm_caller_data_t *caller_data, const char *var_name);
-
-/*! \brief Get an iterator to iterate over the channel variables
- * \param caller_data The signal msg structure containing the variables
- * \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
- * \note The iterator pointer returned is only valid while the signal message and it'll be destroyed when the signal message is processed.
- * This iterator is completely non-thread safe, if you are adding variables or removing variables while iterating
- * results are unpredictable
- */
-FT_DECLARE(ftdm_iterator_t *) ftdm_call_get_var_iterator(const ftdm_caller_data_t *caller_data, ftdm_iterator_t *iter);
-
-/*! \brief Get variable name and value for the current iterator position */
-FT_DECLARE(ftdm_status_t) ftdm_call_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
-
-/*! \brief Clear all variables attached to the call
- * \note Variables are cleared at the end of each call back, so it is not necessary for the user to call this function.
- * \todo Document which signaling variables are available
- * */
-FT_DECLARE(ftdm_status_t) ftdm_call_clear_vars(ftdm_caller_data_t *caller_data);
-
-/*! \brief Remove a variable attached to the call
- * \note Removes a variable that was attached to the call.
- * \todo Document which call variables are available
- * */
-FT_DECLARE(ftdm_status_t) ftdm_call_remove_var(ftdm_caller_data_t *caller_data, const char *var_name);
-
/*! \brief Clears all the temporary data attached to this call
* \note Clears caller_data->variables and caller_data->raw_data.
* */
diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h
index 7b26d655c5..fa519be9f5 100644
--- a/libs/freetdm/src/include/private/ftdm_core.h
+++ b/libs/freetdm/src/include/private/ftdm_core.h
@@ -468,6 +468,7 @@ struct ftdm_channel {
ftdm_interrupt_t *state_completed_interrupt; /*!< Notify when a state change is completed */
int32_t txdrops;
int32_t rxdrops;
+ ftdm_sigmsg_t *sigmsg;
};
struct ftdm_span {
@@ -588,6 +589,10 @@ FT_DECLARE(ftdm_status_t) ftdm_span_close_all(void);
FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan);
FT_DECLARE(void) ftdm_ack_indication(ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication, ftdm_status_t status);
+
+FT_DECLARE(ftdm_iterator_t) *get_iterator(ftdm_iterator_type_t type, ftdm_iterator_t *iter);
+
+
/*!
* \brief Retrieves an event from the span
*
@@ -625,10 +630,21 @@ FT_DECLARE(ftdm_status_t) ftdm_span_trigger_signals(const ftdm_span_t *span);
/*! \brief clear the tone detector state */
FT_DECLARE(void) ftdm_channel_clear_detected_tones(ftdm_channel_t *ftdmchan);
-/* start/stop echo cancelling at the beginning/end of a call */
+/*! \brief adjust echocanceller for beginning of call */
FT_DECLARE(void) ftdm_set_echocancel_call_begin(ftdm_channel_t *chan);
+
+/*! \brief adjust echocanceller for end of call */
FT_DECLARE(void) ftdm_set_echocancel_call_end(ftdm_channel_t *chan);
+/*! \brief clear variables hashtable inside sigmsg */
+FT_DECLARE(ftdm_status_t) ftdm_event_clear_vars(ftdm_sigmsg_t *sigmsg);
+
+/*! \brief save data from user(ftdmchan->caller_data.sigmsg) into internal copy (ftdmchan->sigmsg) */
+FT_DECLARE(ftdm_status_t) ftdm_channel_save_event_data(ftdm_channel_t *ftdmchan);
+
+/*! \brief free data from internal copy (ftdmchan->sigmsg) */
+FT_DECLARE(ftdm_status_t) ftdm_channel_clear_event_data(ftdm_channel_t *ftdmchan);
+
/*!
\brief Assert condition
*/