From 49ac70defd1134abc55c2d540a984d1e14d6b634 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 25 Feb 2011 09:58:15 -0500 Subject: [PATCH] freetdm: User variables now stored in ftdm_usrmsg_t --- libs/freetdm/docs/variables.txt | 114 ++++---- libs/freetdm/mod_freetdm/mod_freetdm.c | 15 +- libs/freetdm/src/ftdm_io.c | 254 +++++++++++------- libs/freetdm/src/ftdm_state.c | 15 +- libs/freetdm/src/ftdm_variables.c | 42 ++- .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 4 +- .../src/ftmod/ftmod_libpri/ftmod_libpri.c | 4 +- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 21 +- .../ftmod_sangoma_isdn_stack_hndl.c | 4 +- .../ftmod_sangoma_isdn_stack_out.c | 2 +- .../ftmod_sangoma_isdn_support.c | 25 +- .../ftmod_sangoma_isdn_trace.c | 2 - libs/freetdm/src/include/freetdm.h | 132 +++++---- libs/freetdm/src/include/ftdm_declare.h | 1 + libs/freetdm/src/include/private/ftdm_core.h | 52 +++- libs/freetdm/src/include/private/ftdm_state.h | 4 +- 16 files changed, 403 insertions(+), 288 deletions(-) diff --git a/libs/freetdm/docs/variables.txt b/libs/freetdm/docs/variables.txt index b849677277..7d95a67c47 100644 --- a/libs/freetdm/docs/variables.txt +++ b/libs/freetdm/docs/variables.txt @@ -1,41 +1,45 @@ +Using FreeTDM Variables + 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. +The User can include a ftdm_usrmsg_t before sending an event to freetdm. -example #1 - Adding a variable: -------------------------------- +example #1a - Making an outbound call: +-------------------------------------- +To make an outbound call: + ftdm_usrmsg_t usrmsg; + + /* Attach variable to usrmsg */ + ftdm_usrmsg_add_var(&usrmsg, "isdn.prog_ind.descr", "inband-info-available"); + + /* Request FreeTDM to send a PROCEED msg */ + ftdm_channel_call_place_ex(ftdmchan, &usrmsg); + +example #1b - 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; + ftdm_usrmsg_t usrmsg; - /* Attach variable to sigmsg */ - ftdm_event_add_var(&sigmsg, "isdn.prog_ind.descr", "inband-info-available"); + /* Attach variable to usrmsg */ + ftdm_usrmsg_add_var(&usrmsg, "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. + ftdm_channel_call_indicate_ex(ftdmchan, FTDM_CHANNEL_INDICATE_PROCEED, &usrmsg); - -example #2a - Setting raw data without autofree feature: +example #2 - Setting raw data: -------------------------------------------------------- When using ftmod_sangoma_isdn, user wants to transmit a custom Facility IE, inside a FACILITY message. - ftdm_caller_data_t *caller_data; + ftdm_usrmsg_t usrmsg; ftdm_sigmsg_t sigmsg; - uint8_t my_facility_ie [200]; + + uint8_t *my_facility_ie = ftdm_calloc(1, 200); /*memory has to be allocated using ftdm_calloc !! */ unsigned my_facility_ie_len = 0; /* Fill my_facility_ie with custom data here */ @@ -44,49 +48,12 @@ When using ftmod_sangoma_isdn, user wants to transmit a custom Facility IE, insi my_facility_ie[my_facility_ie_len++] = 0x01; my_facility_ie[my_facility_ie_len++] = 0x02; my_facility_ie[my_facility_ie_len++] = 0x03; + + ftdm_usrmsg_set_raw_data(&usrmsg, my_facility_ie, my_facility_ie_len); - - 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); + ftdm_channel_call_send_msg(ftdmchan, sigmsg, usrmsg); /* FreeTDM will automatically free my_facility_ie */ @@ -104,7 +71,7 @@ example #1 - print all variables received from FreeTDM const char *var_value = NULL; /* Read all variables attached to this event */ - iter = ftdm_event_get_var_iterator(sigmsg, iter); + iter = ftdm_sigmsg_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); @@ -117,20 +84,39 @@ example #2 - accessing a specific variable /* Inside event call-back function */ char *string = NULL; - string = ftdm_event_get_var(sigmsg, "isdn.prog_ind.descr"); + string = ftdm_sigmsg_get_var(sigmsg, "isdn.prog_ind.descr"); if (string && *string) { fprintf("Progress indicator:%s\n", string); } -example #3 - accessing raw data +example #3a - accessing raw data ------------------------------- /* Inside event call-back function */ ftdm_size_t len; uint8_t *mydata; - if (ftdm_event_get_raw_data(sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) { + if (ftdm_sig_get_raw_data(sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) { /* raw data is available, do something with mydata here */ } + /* Once this function returns, raw data will be free'd inside FreeTDM */ +example #3b - accessing raw data +------------------------------- + + /* Inside event call-back function */ + ftdm_size_t len; + uint8_t *mydata; + if (ftdm_sig_get_raw_data_detached(sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) { + /* raw data is available, do something with mydata here */ + + } + + : + : + : + + /* User owns raw data and is responsible for free'ing it*/ + ftdm_safe_free(mydata); + diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 4a995bc8de..f1675f2ff1 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1152,10 +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_sigmsg_t sigmsg; + ftdm_hunting_scheme_t hunting; + ftdm_usrmsg_t usrmsg; - memset(&sigmsg, 0, sizeof(ftdm_sigmsg_t)); + memset(&usrmsg, 0, sizeof(ftdm_usrmsg_t)); if (!outbound_profile) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing caller profile\n"); @@ -1384,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_event_add_var(&sigmsg, v, h->value); + ftdm_usrmsg_add_var(&usrmsg, v, h->value); } } } @@ -1411,9 +1411,8 @@ 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 ((status = ftdm_call_place_ex(&caller_data, &hunting, &usrmsg)) != FTDM_SUCCESS) { if (tech_pvt->read_codec.implementation) { switch_core_codec_destroy(&tech_pvt->read_codec); } @@ -1579,9 +1578,9 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session } /* Add any call variable to the dial plan */ - iter = ftdm_event_get_var_iterator(sigmsg, iter); + iter = ftdm_sigmsg_get_var_iterator(sigmsg, iter); for (curr = iter ; curr; curr = ftdm_iterator_next(curr)) { - ftdm_event_get_current_var(curr, &var_name, &var_value); + ftdm_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); diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index bd7b043a34..0b8d51facc 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -65,6 +65,8 @@ ftdm_time_t time_current_throttle_log = 0; 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_done(ftdm_channel_t *ftdmchan); +static ftdm_status_t ftdm_channel_sig_indicate(ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication, ftdm_usrmsg_t *usrmsg); + static int time_is_init = 0; @@ -1898,10 +1900,9 @@ openchan: ftdm_set_flag(check, FTDM_CHANNEL_INUSE); ftdm_set_flag(check, FTDM_CHANNEL_OUTBOUND); *ftdmchan = check; -#if 1 + /* we've got the channel, do not unlock it */ goto done; -#endif unlockchan: ftdm_mutex_unlock(check->mutex); @@ -2062,25 +2063,25 @@ FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_done(const ftdm_channel_t *ftdmc return condition; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status; ftdm_channel_lock(ftdmchan); ftdm_set_flag(ftdmchan, FTDM_CHANNEL_HOLD); - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALTONE, 0); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALTONE, 0, usrmsg); ftdm_channel_unlock(ftdmchan); return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_unhold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_unhold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status; ftdm_channel_lock(ftdmchan); - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_UP, 0); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_UP, 0, usrmsg); ftdm_channel_unlock(ftdmchan); @@ -2107,7 +2108,7 @@ FT_DECLARE(void) ftdm_ack_indication(ftdm_channel_t *fchan, ftdm_channel_indicat } /*! Answer call without locking the channel. The caller must have locked first */ -static ftdm_status_t _ftdm_channel_call_answer_nl(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +static ftdm_status_t _ftdm_channel_call_answer_nl(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; @@ -2117,7 +2118,7 @@ static ftdm_status_t _ftdm_channel_call_answer_nl(const char *file, const char * * use FTDM_SPAN_USE_SKIP_STATES for now while we update the sig modules */ if (ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS) { - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1, usrmsg); if (status != FTDM_SUCCESS) { status = FTDM_ECANCELED; goto done; @@ -2132,7 +2133,7 @@ static ftdm_status_t _ftdm_channel_call_answer_nl(const char *file, const char * } if (ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS_MEDIA) { - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, 1, usrmsg); if (status != FTDM_SUCCESS) { status = FTDM_ECANCELED; goto done; @@ -2147,7 +2148,7 @@ static ftdm_status_t _ftdm_channel_call_answer_nl(const char *file, const char * } } - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_UP, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_UP, 1, usrmsg); if (status != FTDM_SUCCESS) { status = FTDM_ECANCELED; goto done; @@ -2158,19 +2159,19 @@ done: return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_answer(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_answer(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status; /* we leave the locking up to ftdm_channel_call_indicate, DO NOT lock here since ftdm_channel_call_indicate expects * the lock recursivity to be 1 */ - status = _ftdm_channel_call_indicate(file, func, line, ftdmchan, FTDM_CHANNEL_INDICATE_ANSWER); + status = _ftdm_channel_call_indicate(file, func, line, ftdmchan, FTDM_CHANNEL_INDICATE_ANSWER, usrmsg); return status; } /* lock must be acquired by the caller! */ -static ftdm_status_t _ftdm_channel_call_hangup_nl(const char *file, const char *func, int line, ftdm_channel_t *chan) +static ftdm_status_t _ftdm_channel_call_hangup_nl(const char *file, const char *func, int line, ftdm_channel_t *chan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; @@ -2189,7 +2190,7 @@ static ftdm_status_t _ftdm_channel_call_hangup_nl(const char *file, const char * if (ftdm_test_flag(chan, FTDM_CHANNEL_STATE_CHANGE)) { ftdm_channel_cancel_state(file, func, line, chan); } - status = ftdm_channel_set_state(file, func, line, chan, FTDM_CHANNEL_STATE_HANGUP, 1); + status = ftdm_channel_set_state(file, func, line, chan, FTDM_CHANNEL_STATE_HANGUP, 1, usrmsg); } else { /* the signaling stack did not touch the state, * core is responsible from clearing flags and stuff, however, because ftmod_analog @@ -2205,20 +2206,20 @@ static ftdm_status_t _ftdm_channel_call_hangup_nl(const char *file, const char * return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup_with_cause(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_call_cause_t cause) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup_with_cause(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_call_cause_t cause, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; ftdm_channel_lock(ftdmchan); ftdmchan->caller_data.hangup_cause = cause; - status = _ftdm_channel_call_hangup_nl(file, func, line, ftdmchan); + status = _ftdm_channel_call_hangup_nl(file, func, line, ftdmchan, usrmsg); ftdm_channel_unlock(ftdmchan); return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; @@ -2226,7 +2227,7 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NORMAL_CLEARING; - status = _ftdm_channel_call_hangup_nl(file, func, line, ftdmchan); + status = _ftdm_channel_call_hangup_nl(file, func, line, ftdmchan, usrmsg); ftdm_channel_unlock(ftdmchan); return status; @@ -2286,7 +2287,7 @@ FT_DECLARE(uint32_t) ftdm_channel_get_ph_span_id(const ftdm_channel_t *ftdmchan) * someone *MUST* acknowledge the indication, either the signaling stack, this function or the core * at some later point * */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; @@ -2329,10 +2330,10 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const ch /* FIXME: ring and busy cannot be used with all signaling stacks * (particularly isdn stacks I think, we should emulate or just move to hangup with busy cause) */ case FTDM_CHANNEL_INDICATE_RINGING: - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_RINGING, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_RINGING, 1, usrmsg); break; case FTDM_CHANNEL_INDICATE_BUSY: - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_BUSY, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_BUSY, 1, usrmsg); break; case FTDM_CHANNEL_INDICATE_PROCEED: if (!ftdm_test_flag(ftdmchan->span, FTDM_SPAN_USE_PROCEED_STATE) || @@ -2340,15 +2341,15 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const ch ftdm_ack_indication(ftdmchan, indication, status); goto done; } - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROCEED, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROCEED, 1, usrmsg); break; case FTDM_CHANNEL_INDICATE_PROGRESS: - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1, usrmsg); break; case FTDM_CHANNEL_INDICATE_PROGRESS_MEDIA: if (!ftdm_test_flag(ftdmchan->span, FTDM_SPAN_USE_SKIP_STATES)) { if (ftdmchan->state < FTDM_CHANNEL_STATE_PROGRESS) { - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS, 1, usrmsg); if (status != FTDM_SUCCESS) { goto done; } @@ -2360,14 +2361,14 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const ch goto done; } } - status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, 1); + status = ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA, 1, usrmsg); break; case FTDM_CHANNEL_INDICATE_ANSWER: - status = _ftdm_channel_call_answer_nl(file, func, line, ftdmchan); + status = _ftdm_channel_call_answer_nl(file, func, line, ftdmchan, usrmsg); break; default: - ftdm_log(file, func, line, FTDM_LOG_LEVEL_WARNING, "Do not know how to indicate %d\n", indication); - status = FTDM_EINVAL; + /* See if signalling module can provide this indication */ + status = ftdm_channel_sig_indicate(ftdmchan, indication, usrmsg); break; } @@ -2377,40 +2378,17 @@ done: return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_send_msg(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_sigmsg_t *sigmsg) -{ - ftdm_status_t status = FTDM_FAIL; - ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "null channel"); -#ifdef __WINDOWS__ - UNREFERENCED_PARAMETER(file); - UNREFERENCED_PARAMETER(func); - UNREFERENCED_PARAMETER(line); -#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; -} - -FT_DECLARE(ftdm_status_t) _ftdm_channel_reset(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_reset(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "null channel"); ftdm_channel_lock(ftdmchan); - ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_RESET, 1); + ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_RESET, 1, usrmsg); ftdm_channel_unlock(ftdmchan); return FTDM_SUCCESS; } -static ftdm_status_t _ftdm_channel_call_place_nl(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +static ftdm_status_t _ftdm_channel_call_place_nl(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_FAIL; @@ -2453,9 +2431,9 @@ static ftdm_status_t _ftdm_channel_call_place_nl(const char *file, const char *f 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)) { - ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 1); + ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 1, usrmsg); } else { - ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 0); + ftdm_channel_set_state(file, func, line, ftdmchan, FTDM_CHANNEL_STATE_DIALING, 0, usrmsg); } done: @@ -2467,19 +2445,19 @@ done: return status; } -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status; ftdm_channel_lock(ftdmchan); - status = _ftdm_channel_call_place_nl(file, func, line, ftdmchan); + status = _ftdm_channel_call_place_nl(file, func, line, ftdmchan, usrmsg); ftdm_channel_unlock(ftdmchan); return status; } FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, int line, - ftdm_caller_data_t *caller_data, ftdm_hunting_scheme_t *hunting) + ftdm_caller_data_t *caller_data, ftdm_hunting_scheme_t *hunting, ftdm_usrmsg_t *usrmsg) { ftdm_status_t status = FTDM_SUCCESS; ftdm_channel_t *fchan = NULL; @@ -2515,9 +2493,9 @@ FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, i ftdm_channel_set_caller_data(fchan, caller_data); - status = _ftdm_channel_call_place_nl(file, func, line, fchan); + status = _ftdm_channel_call_place_nl(file, func, line, fchan, usrmsg); if (status != FTDM_SUCCESS) { - _ftdm_channel_call_hangup_nl(file, func, line, fchan); + _ftdm_channel_call_hangup_nl(file, func, line, fchan, usrmsg); goto done; } @@ -2605,6 +2583,29 @@ FT_DECLARE(ftdm_status_t) ftdm_span_get_sig_status(ftdm_span_t *span, ftdm_signa } } +static ftdm_status_t ftdm_channel_sig_indicate(ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication, ftdm_usrmsg_t *usrmsg) +{ + ftdm_status_t status = FTDM_FAIL; + if (ftdmchan->span->indicate) { + + ftdm_channel_save_usrmsg(ftdmchan, usrmsg); + + status = ftdmchan->span->indicate(ftdmchan, indication); + if (status == FTDM_NOTIMPL) { + ftdm_log(FTDM_LOG_WARNING, "Do not know how to indicate %s\n", ftdm_channel_indication2str(indication)); + } else if (status != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_WARNING, "Failed to indicate %s\n", ftdm_channel_indication2str(indication)); + } else { /* SUCCESS */ + ftdm_ack_indication(ftdmchan, indication, FTDM_SUCCESS); + } + ftdm_usrmsg_free(&ftdmchan->usrmsg); + } else { + return FTDM_NOTIMPL; + } + return status; +} + + /* this function must be called with the channel lock */ static ftdm_status_t ftdm_channel_done(ftdm_channel_t *ftdmchan) { @@ -3507,7 +3508,8 @@ skipdebug: ftdmchan->dtmf_hangup_buf[ftdmchan->span->dtmf_hangup_len - 1] = *p; if (!strcmp(ftdmchan->dtmf_hangup_buf, ftdmchan->span->dtmf_hangup)) { ftdm_log(FTDM_LOG_DEBUG, "DTMF hangup detected.\n"); - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + + ftdm_channel_set_state(__FILE__, __FUNCTION__, __LINE__, ftdmchan, FTDM_CHANNEL_STATE_HANGUP, 0, NULL); break; } } @@ -5278,9 +5280,7 @@ FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *na static ftdm_status_t ftdm_span_trigger_signal(const ftdm_span_t *span, ftdm_sigmsg_t *sigmsg) { ftdm_status_t status = span->signal_cb(sigmsg); - if (sigmsg->channel) { - ftdm_channel_clear_event_data(sigmsg->channel); - } + ftdm_sigmsg_free(&sigmsg); return status; } @@ -5303,7 +5303,6 @@ FT_DECLARE(ftdm_status_t) ftdm_span_trigger_signals(const ftdm_span_t *span) ftdm_sigmsg_t *sigmsg = NULL; while ((sigmsg = ftdm_queue_dequeue(span->pendingsignals))) { ftdm_span_trigger_signal(span, sigmsg); - ftdm_safe_free(sigmsg); } return FTDM_SUCCESS; } @@ -5316,7 +5315,7 @@ static void execute_safety_hangup(void *data) fchan->hangup_timer = 0; if (fchan->state == FTDM_CHANNEL_STATE_TERMINATING) { ftdm_log_chan(fchan, FTDM_LOG_CRIT, "Forcing hangup since the user did not confirmed our hangup after %dms\n", FORCE_HANGUP_TIMER); - _ftdm_channel_call_hangup_nl(__FILE__, __FUNCTION__, __LINE__, fchan); + _ftdm_channel_call_hangup_nl(__FILE__, __FUNCTION__, __LINE__, fchan, NULL); } else { ftdm_log_chan(fchan, FTDM_LOG_CRIT, "Not performing safety hangup, channel state is %s\n", ftdm_channel_state2str(fchan->state)); } @@ -6019,7 +6018,7 @@ 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) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_get_raw_data(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen) { if (!sigmsg || !sigmsg->raw.len) { return FTDM_FAIL; @@ -6031,57 +6030,112 @@ FT_DECLARE(ftdm_status_t) ftdm_event_get_raw_data(ftdm_sigmsg_t *sigmsg, void ** 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) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_get_raw_data_detached(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen) { - 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; - + 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_channel_save_event_data(ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_set_raw_data(ftdm_sigmsg_t *sigmsg, void *data, ftdm_size_t datalen) { - ftdm_assert_return(!ftdmchan->sigmsg, FTDM_FAIL, "Info from previous event was not cleared\n"); - if (ftdmchan->caller_data.sigmsg) { + 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"); + ftdm_assert_return(datalen, FTDM_FAIL, "Data length not set\n"); + + sigmsg->raw.data = data; + sigmsg->raw.len = datalen; + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_get_raw_data(ftdm_usrmsg_t *usrmsg, void **data, ftdm_size_t *datalen) +{ + if (!usrmsg || !usrmsg->raw.len) { + return FTDM_FAIL; + } + + *data = usrmsg->raw.data; + *datalen = usrmsg->raw.len; + + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_set_raw_data(ftdm_usrmsg_t *usrmsg, void *data, ftdm_size_t datalen) +{ + ftdm_assert_return(usrmsg, FTDM_FAIL, "Trying to set raw data on a NULL event\n"); + ftdm_assert_return(!usrmsg->raw.len, FTDM_FAIL, "Overwriting existing raw data\n"); + ftdm_assert_return(datalen, FTDM_FAIL, "Data length not set\n"); + + usrmsg->raw.data = data; + usrmsg->raw.len = datalen; + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_channel_save_usrmsg(ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg) +{ + ftdm_assert_return(!ftdmchan->usrmsg, FTDM_FAIL, "Info from previous event was not cleared\n"); + if (usrmsg) { /* 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)); + ftdmchan->usrmsg = ftdm_calloc(1, sizeof(ftdm_usrmsg_t)); + memcpy(ftdmchan->usrmsg, usrmsg, sizeof(ftdm_usrmsg_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); - } + if (usrmsg->raw.data) { + ftdmchan->usrmsg->raw.data = usrmsg->raw.data; + ftdmchan->usrmsg->raw.len = usrmsg->raw.len; + + usrmsg->raw.data = NULL; + usrmsg->raw.len = 0; + } + if (usrmsg->variables) { + usrmsg->variables = NULL; } - ftdmchan->caller_data.sigmsg = NULL; } return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_channel_clear_event_data(ftdm_channel_t *ftdmchan) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_free(ftdm_sigmsg_t **sigmsg) { - if (!ftdmchan->sigmsg) { + if (!*sigmsg) { return FTDM_SUCCESS; } - - if (ftdmchan->sigmsg->variables) { - ftdm_event_clear_vars(ftdmchan->sigmsg); + + if ((*sigmsg)->variables) { + hashtable_destroy((*sigmsg)->variables); + (*sigmsg)->variables = NULL; } - 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; + if ((*sigmsg)->raw.data) { + ftdm_safe_free((*sigmsg)->raw.data); + (*sigmsg)->raw.data = NULL; + (*sigmsg)->raw.len = 0; } - ftdm_safe_free(ftdmchan->sigmsg); - ftdmchan->sigmsg = NULL; + ftdm_safe_free(*sigmsg); + return FTDM_SUCCESS; +} + +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_free(ftdm_usrmsg_t **usrmsg) +{ + if (!*usrmsg) { + return FTDM_SUCCESS; + } + + if ((*usrmsg)->variables) { + hashtable_destroy((*usrmsg)->variables); + (*usrmsg)->variables = NULL; + } + + if ((*usrmsg)->raw.data) { + ftdm_safe_free((*usrmsg)->raw.data); + (*usrmsg)->raw.data = NULL; + (*usrmsg)->raw.len = 0; + } + + ftdm_safe_free(*usrmsg); return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftdm_state.c b/libs/freetdm/src/ftdm_state.c index 08902421cd..eea3a6a0c0 100644 --- a/libs/freetdm/src/ftdm_state.c +++ b/libs/freetdm/src/ftdm_state.c @@ -68,6 +68,8 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_complete_state(const char *file, const c return FTDM_SUCCESS; } + ftdm_usrmsg_free(&fchan->usrmsg); + ftdm_clear_flag(fchan, FTDM_CHANNEL_STATE_CHANGE); if (state == FTDM_CHANNEL_STATE_PROGRESS) { @@ -226,12 +228,14 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_cancel_state(const char *file, const char } -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) +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, ftdm_usrmsg_t *usrmsg) { - if (ftdm_channel_save_event_data(ftdmchan) == FTDM_SUCCESS) { - return ftdm_core_set_state(file, func, line, ftdmchan, state, waitrq); + ftdm_channel_save_usrmsg(ftdmchan, usrmsg); + + if (ftdm_core_set_state(file, func, line, ftdmchan, state, waitrq) != FTDM_SUCCESS) { + ftdm_usrmsg_free(&ftdmchan->usrmsg); } - return FTDM_FAIL; + return FTDM_SUCCESS; } /* 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) */ @@ -524,8 +528,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_advance_states(ftdm_channel_t *fchan) * already completed implicitly by the state_processor() function via some internal * 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/ftdm_variables.c b/libs/freetdm/src/ftdm_variables.c index 706970247b..96db383b6e 100644 --- a/libs/freetdm/src/ftdm_variables.c +++ b/libs/freetdm/src/ftdm_variables.c @@ -39,7 +39,7 @@ #include "private/ftdm_core.h" -FT_DECLARE(ftdm_status_t) ftdm_event_add_var(ftdm_sigmsg_t *sigmsg, const char *var_name, const char *value) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_add_var(ftdm_sigmsg_t *sigmsg, const char *var_name, const char *value) { char *t_name = 0, *t_val = 0; @@ -59,7 +59,7 @@ FT_DECLARE(ftdm_status_t) ftdm_event_add_var(ftdm_sigmsg_t *sigmsg, const char * return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_event_remove_var(ftdm_sigmsg_t *sigmsg, const char *var_name) +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_remove_var(ftdm_sigmsg_t *sigmsg, const char *var_name) { if (sigmsg && sigmsg->variables) { hashtable_remove(sigmsg->variables, (void *)var_name); @@ -67,7 +67,7 @@ FT_DECLARE(ftdm_status_t) ftdm_event_remove_var(ftdm_sigmsg_t *sigmsg, const cha return FTDM_SUCCESS; } -FT_DECLARE(const char *) ftdm_event_get_var(ftdm_sigmsg_t *sigmsg, const char *var_name) +FT_DECLARE(const char *) ftdm_sigmsg_get_var(ftdm_sigmsg_t *sigmsg, const char *var_name) { const char *var = NULL; @@ -79,7 +79,7 @@ FT_DECLARE(const char *) ftdm_event_get_var(ftdm_sigmsg_t *sigmsg, const char *v return var; } -FT_DECLARE(ftdm_iterator_t *) ftdm_event_get_var_iterator(const ftdm_sigmsg_t *sigmsg, ftdm_iterator_t *iter) +FT_DECLARE(ftdm_iterator_t *) ftdm_sigmsg_get_var_iterator(const ftdm_sigmsg_t *sigmsg, ftdm_iterator_t *iter) { ftdm_hash_iterator_t *hashiter = NULL; if (!sigmsg) { @@ -99,7 +99,7 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_event_get_var_iterator(const ftdm_sigmsg_t *s return iter; } -FT_DECLARE(ftdm_status_t) ftdm_event_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val) +FT_DECLARE(ftdm_status_t) ftdm_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val) { const void *key = NULL; void *val = NULL; @@ -117,11 +117,35 @@ FT_DECLARE(ftdm_status_t) ftdm_event_get_current_var(ftdm_iterator_t *iter, cons return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_event_clear_vars(ftdm_sigmsg_t *sigmsg) + +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_add_var(ftdm_usrmsg_t *usrmsg, const char *var_name, const char *value) { - if (sigmsg->variables) { - hashtable_destroy(sigmsg->variables); - sigmsg->variables = NULL; + char *t_name = 0, *t_val = 0; + + if (!usrmsg || !var_name || !value) { + return FTDM_FAIL; } + + if (!usrmsg->variables) { + /* initialize on first use */ + usrmsg->variables = create_hashtable(16, ftdm_hash_hashfromstring, ftdm_hash_equalkeys); + ftdm_assert_return(usrmsg->variables, FTDM_FAIL, "Failed to create hash table\n"); + } + + t_name = ftdm_strdup(var_name); + t_val = ftdm_strdup(value); + hashtable_insert(usrmsg->variables, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE); return FTDM_SUCCESS; } + +FT_DECLARE(const char *) ftdm_usrmsg_get_var(ftdm_usrmsg_t *usrmsg, const char *var_name) +{ + const char *var = NULL; + + if (!usrmsg || !usrmsg->variables || !var_name) { + return NULL; + } + + var = (const char *)hashtable_search(((struct hashtable*)usrmsg->variables), (void *)var_name); + return var; +} diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index f9674a5046..a7b84ea5d8 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -285,9 +285,7 @@ static FIO_SPAN_GET_SIG_STATUS_FUNCTION(isdn_get_span_sig_status) */ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) { - ftdm_status_t status = FTDM_SUCCESS; - ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); - return status; + return FTDM_SUCCESS; } /** diff --git a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c index 5f0ae716e1..e051477346 100644 --- a/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c +++ b/libs/freetdm/src/ftmod/ftmod_libpri/ftmod_libpri.c @@ -93,9 +93,7 @@ static FIO_SPAN_GET_SIG_STATUS_FUNCTION(isdn_get_span_sig_status) */ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(isdn_outgoing_call) { - ftdm_status_t status = FTDM_SUCCESS; - ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND); - return status; + 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 9947d40d76..1437b45883 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 @@ -610,9 +610,6 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm sigev.span_id = ftdmchan->span_id; sigev.channel = ftdmchan; - /* Acknowledge the state change */ - ftdm_channel_complete_state(ftdmchan); - #ifdef FTDM_DEBUG_CHAN_MEMORY if (ftdmchan->state == FTDM_CHANNEL_STATE_DIALING) { ftdm_assert(mprotect(ftdmchan, sizeof(*ftdmchan), PROT_READ) == 0, "Failed to mprotect"); @@ -876,15 +873,18 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm break; } + /* Acknowledge the state change */ + ftdm_channel_complete_state(ftdmchan); + /* If sngisdn_info->variables is not NULL, it means did not send any - * sigevent to the user, therefore we have to free that sigmsg */ + * sigevent to the user, therefore we have to free that hashtable */ 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 */ + * sigevent to the user, therefore we have to free that raw data */ if (sngisdn_info->raw_data) { ftdm_safe_free(sngisdn_info->raw_data); sngisdn_info->raw_data = NULL; @@ -902,18 +902,17 @@ static ftdm_status_t ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdm return FTDM_SUCCESS; } -static FIO_CHANNEL_SEND_MSG_FUNCTION(ftdm_sangoma_isdn_send_msg) +static FIO_CHANNEL_INDICATE_FUNCTION(ftdm_sangoma_isdn_indicate) { ftdm_status_t status = FTDM_FAIL; - switch (sigmsg->event_id) { - case FTDM_SIGEVENT_FACILITY: + switch (indication) { + case FTDM_CHANNEL_INDICATE_FACILITY: sngisdn_snd_fac_req(ftdmchan); status = FTDM_SUCCESS; break; default: - ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Unsupported signalling msg requested\n"); - status = FTDM_BREAK; + status = FTDM_NOTIMPL; } return status; } @@ -1092,7 +1091,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_isdn_span_config) span->stop = ftdm_sangoma_isdn_stop; span->signal_type = FTDM_SIGTYPE_ISDN; span->outgoing_call = ftdm_sangoma_isdn_outgoing_call; - span->send_msg = ftdm_sangoma_isdn_send_msg; + span->indicate = ftdm_sangoma_isdn_indicate; span->channel_request = NULL; span->signal_cb = sig_cb; span->get_channel_sig_status = ftdm_sangoma_isdn_get_chan_sig_status; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c index bcc7d938b7..cfc5017a8d 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c @@ -160,7 +160,8 @@ void sngisdn_process_con_ind (sngisdn_event_data_t *sngisdn_event) } } - /* this should be in get_facility_ie function, fix this later */ +#if 1 + /* this section will not be needed once asn decoding function with key-value pairs is implemented */ if (signal_data->facility == SNGISDN_OPT_TRUE && conEvnt->facilityStr.eh.pres) { /* Verify whether the Caller Name will come in a subsequent FACILITY message */ uint16_t ret_val; @@ -187,6 +188,7 @@ void sngisdn_process_con_ind (sngisdn_event_data_t *sngisdn_event) strcpy(ftdmchan->caller_data.cid_name, retrieved_str); } } +#endif if (signal_data->overlap_dial == SNGISDN_OPT_TRUE && !conEvnt->sndCmplt.eh.pres) { ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_COLLECT); 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 be204e5eb3..b56c95b10d 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 @@ -273,7 +273,7 @@ void sngisdn_snd_fac_req(ftdm_channel_t *ftdmchan) facEvnt.facElmt.facStr.val[0] = 0x1C; facEvnt.facElmt.facStr.val[1] = (uint8_t)facEvnt.facElmt.facStr.len; facEvnt.facElmt.facStr.len +=2; /* Need to include the size of identifier + len */ - + ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Sending FACILITY (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_facility_request(signal_data->cc_id, sngisdn_info->suInstId, sngisdn_info->spInstId, &facEvnt, MI_FACIL, signal_data->dchan_id, sngisdn_info->ces)) { 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 55e72a84f5..85048bfbf0 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 @@ -253,6 +253,7 @@ ftdm_status_t get_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb) ftdm_status_t get_called_num(ftdm_channel_t *ftdmchan, CdPtyNmb *cdPtyNmb) { ftdm_caller_data_t *caller_data = &ftdmchan->caller_data; + if (cdPtyNmb->eh.pres != PRSNT_NODEF) { return FTDM_FAIL; } @@ -369,7 +370,6 @@ ftdm_status_t get_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8 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"); @@ -381,7 +381,7 @@ ftdm_status_t get_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8 ftdm_status_t get_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd) { - uint8_t val; + uint8_t val; if (!progInd->eh.pres) { return FTDM_FAIL; } @@ -492,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_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.digits"); + string = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.cg_pty2.digits"); if ((string == NULL) || !(*string)) { return FTDM_FAIL; } @@ -509,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_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.screening_ind"); + string = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.cg_pty2.screening_ind"); if ((string != NULL) && (*string)) { val = ftdm_str2ftdm_screening(string); } @@ -526,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_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.presentation_ind"); + string = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.cg_pty2.presentation_ind"); if ((string != NULL) && (*string)) { val = ftdm_str2ftdm_presentation(string); } @@ -541,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_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.npi"); + string = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.cg_pty2.npi"); if ((string != NULL) && (*string)) { val = ftdm_str2ftdm_npi(string); } @@ -556,7 +556,7 @@ ftdm_status_t set_calling_num2(ftdm_channel_t *ftdmchan, CgPtyNmb *cgPtyNmb) /* Type of Number */ val = FTDM_TON_INVALID; - string = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.cg_pty2.ton"); + string = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.cg_pty2.ton"); if ((string != NULL) && (*string)) { val = ftdm_str2ftdm_ton(string); } @@ -690,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_event_get_var(ftdmchan->sigmsg, "isdn.calling_subaddr"); + clg_subaddr = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.calling_subaddr"); if ((clg_subaddr != NULL) && (*clg_subaddr)) { unsigned len = strlen (clg_subaddr); cgPtySad->eh.pres = PRSNT_NODEF; @@ -723,7 +723,7 @@ ftdm_status_t set_facility_ie_str(ftdm_channel_t *ftdmchan, uint8_t *data, uint8 ftdm_size_t len; uint8_t *mydata; - if (ftdm_event_get_raw_data(ftdmchan->sigmsg, (void**)&mydata, &len) == FTDM_SUCCESS) { + if (ftdm_usrmsg_get_raw_data(ftdmchan->usrmsg, (void**)&mydata, &len) == FTDM_SUCCESS) { if (len > 2 && mydata[0] == SNGISDN_Q931_FACILITY_IE_ID) { len = mydata[1]; memcpy(data, &mydata[2], len); @@ -740,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_event_get_var(ftdmchan->sigmsg, "isdn.prog_ind.descr"); + str = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.prog_ind.descr"); if (str && *str) { /* User wants to override progress indicator */ descr = ftdm_str2ftdm_sngisdn_progind_descr(str); @@ -751,7 +751,7 @@ ftdm_status_t set_prog_ind_ie(ftdm_channel_t *ftdmchan, ProgInd *progInd, ftdm_s return FTDM_SUCCESS; } - str = ftdm_event_get_var(ftdmchan->sigmsg, "isdn.prog_ind.loc"); + str = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "isdn.prog_ind.loc"); if (str && *str) { loc = ftdm_str2ftdm_sngisdn_progind_loc(str); } @@ -1219,7 +1219,7 @@ ftdm_status_t sngisdn_add_raw_data(sngisdn_chan_data_t *sngisdn_info, uint8_t* d 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; @@ -1256,7 +1256,6 @@ void sngisdn_send_signal(sngisdn_chan_data_t *sngisdn_info, ftdm_signal_event_t 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; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_trace.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_trace.c index 9feb5c8c43..88b166a3af 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_trace.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_trace.c @@ -139,7 +139,6 @@ void sngisdn_trace_raw_q921(sngisdn_span_data_t *signal_data, ftdm_trace_dir_t d memcpy(raw_data, data, data_len); sigev.raw.data = raw_data; sigev.raw.len = data_len; - sigev.raw.autofree = 1; ftdm_span_send_signal(signal_data->ftdm_span, &sigev); } @@ -253,7 +252,6 @@ void sngisdn_trace_raw_q931(sngisdn_span_data_t *signal_data, ftdm_trace_dir_t d memcpy(raw_data, data, data_len); sigev.raw.data = raw_data; sigev.raw.len = data_len; - sigev.raw.autofree = 1; ftdm_span_send_signal(signal_data->ftdm_span, &sigev); } } diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 84adf327dd..86c9b739c9 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -339,8 +339,7 @@ typedef struct ftdm_caller_data { ftdm_calling_party_category_t cpc; /*!< Calling party category */ 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 @@ -534,9 +533,10 @@ typedef enum { FTDM_CHANNEL_INDICATE_BUSY, /* Using this indication is equivalent to call ftdm_channel_call_answer API */ FTDM_CHANNEL_INDICATE_ANSWER, + FTDM_CHANNEL_INDICATE_FACILITY, FTDM_CHANNEL_INDICATE_INVALID, } ftdm_channel_indication_t; -#define INDICATION_STRINGS "NONE", "RINGING", "PROCEED", "PROGRESS", "PROGRESS_MEDIA", "BUSY", "ANSWER", "INVALID" +#define INDICATION_STRINGS "NONE", "RINGING", "PROCEED", "PROGRESS", "PROGRESS_MEDIA", "BUSY", "ANSWER", "FACILITY", "INVALID" /*! \brief Move from string to ftdm_channel_indication_t and viceversa */ FTDM_STR2ENUM_P(ftdm_str2channel_indication, ftdm_channel_indication2str, ftdm_channel_indication_t) @@ -550,7 +550,7 @@ typedef struct { typedef void * ftdm_variable_container_t; -/*! \brief Generic signaling message */ +/*! \brief Generic signaling message received from the stack */ struct ftdm_sigmsg { ftdm_signal_event_t event_id; /*!< The type of message */ ftdm_channel_t *channel; /*!< Related channel */ @@ -566,7 +566,16 @@ struct ftdm_sigmsg { ftdm_event_indication_completed_t indication_completed; /*!< valid if the event_id is FTDM_SIGEVENT_INDICATION_COMPLETED */ } ev_data; struct { - uint8_t autofree; /*!< Whether the freetdm core will free it after message delivery */ + ftdm_size_t len; /*!< Data len */ + void *data; /*!< Signaling module specific data */ + } raw; +}; + +/*! \brief Generic user message sent to the stack */ +struct ftdm_usrmsg { + uint32_t call_id; /*!< unique call id for this call */ + ftdm_variable_container_t variables; + struct { ftdm_size_t len; /*!< Data len */ void *data; /*!< Signaling module specific data */ } raw; @@ -702,7 +711,7 @@ struct ftdm_memory_handler { * You don't need these unless your implementing an I/O interface module (most users don't) */ #define FIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan) #define FIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan) -#define FIO_CHANNEL_SEND_MSG_ARGS (ftdm_channel_t *ftdmchan, ftdm_sigmsg_t *sigmsg) +#define FIO_CHANNEL_INDICATE_ARGS (ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication) #define FIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status) #define FIO_CHANNEL_GET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status) #define FIO_SPAN_SET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status) @@ -735,7 +744,7 @@ struct ftdm_memory_handler { * You don't need these unless your implementing an I/O interface module (most users don't) */ typedef ftdm_status_t (*fio_channel_request_t) FIO_CHANNEL_REQUEST_ARGS ; typedef ftdm_status_t (*fio_channel_outgoing_call_t) FIO_CHANNEL_OUTGOING_CALL_ARGS ; -typedef ftdm_status_t (*fio_channel_send_msg_t) FIO_CHANNEL_SEND_MSG_ARGS; +typedef ftdm_status_t (*fio_channel_indicate_t) FIO_CHANNEL_INDICATE_ARGS; typedef ftdm_status_t (*fio_channel_set_sig_status_t) FIO_CHANNEL_SET_SIG_STATUS_ARGS; typedef ftdm_status_t (*fio_channel_get_sig_status_t) FIO_CHANNEL_GET_SIG_STATUS_ARGS; typedef ftdm_status_t (*fio_span_set_sig_status_t) FIO_SPAN_SET_SIG_STATUS_ARGS; @@ -782,7 +791,7 @@ typedef ftdm_status_t (*fio_api_t) FIO_API_ARGS ; * You don't need these unless your implementing an I/O interface module (most users don't) */ #define FIO_CHANNEL_REQUEST_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_REQUEST_ARGS #define FIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_OUTGOING_CALL_ARGS -#define FIO_CHANNEL_SEND_MSG_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_SEND_MSG_ARGS +#define FIO_CHANNEL_INDICATE_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_INDICATE_ARGS #define FIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_SET_SIG_STATUS_ARGS #define FIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_GET_SIG_STATUS_ARGS #define FIO_SPAN_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_SPAN_SET_SIG_STATUS_ARGS @@ -870,23 +879,26 @@ FT_DECLARE(int) ftdm_channel_get_availability(ftdm_channel_t *ftdmchan); * there is no guarantee of whether the event will arrive after or before your execution thread returns * from ftdm_channel_call_answer */ -#define ftdm_channel_call_answer(ftdmchan) _ftdm_channel_call_answer(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_call_answer(ftdmchan) _ftdm_channel_call_answer(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_call_answer_ex(ftdmchan, usrmsg) _ftdm_channel_call_answer(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (usrmsg)) /*! \brief Answer call recording the source code point where the it was called (see ftdm_channel_call_answer for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_answer(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_answer(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Place an outgoing call in the given channel * \deprecated This macro is deprecated since leaves the door open to glare issues, use ftdm_call_place instead */ -#define ftdm_channel_call_place(ftdmchan) _ftdm_channel_call_place(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_call_place(ftdmchan) _ftdm_channel_call_place(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_call_place_ex(ftdmchan, usrmsg) _ftdm_channel_call_place_ex(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (usrmsg)) /*! \brief Place an outgoing call recording the source code point where it was called (see ftdm_channel_call_place for an easy to use macro) * \deprecated This function is deprecated since leaves the door open to glare issues, use ftdm_call_place instead */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Place an outgoing call with the given caller data in a channel according to the hunting scheme provided */ -#define ftdm_call_place(callerdata, hunting) _ftdm_call_place(__FILE__, __FUNCTION__, __LINE__, (callerdata), (hunting)) +#define ftdm_call_place(callerdata, hunting) _ftdm_call_place(__FILE__, __FUNCTION__, __LINE__, (callerdata), (hunting), NULL) +#define ftdm_call_place_ex(callerdata, hunting, usrmsg) _ftdm_call_place(__FILE__, __FUNCTION__, __LINE__, (callerdata), (hunting), (usrmsg)) /*! \brief Place an outgoing call with the given caller data in a channel according to the hunting scheme provided and records * the place where it was called. See ftdm_call_place for an easy to use macro @@ -903,7 +915,7 @@ FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char * \note When this function is successful you are guaranteed to receive FTDM_SIGEVENT_DIALING, this event could even be delivered * before your execution thread returns from this function */ -FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, int line, ftdm_caller_data_t *caller_data, ftdm_hunting_scheme_t *hunting); +FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, int line, ftdm_caller_data_t *caller_data, ftdm_hunting_scheme_t *hunting, ftdm_usrmsg_t *usrmsg); /*! \brief Indicate a new condition in an incoming call * @@ -918,48 +930,48 @@ FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, i * \note You cannot send more than one indication at the time. You must wait for the completed event before * calling this function again (unless the return code was different than FTDM_SUCCESS) */ -#define ftdm_channel_call_indicate(ftdmchan, indication) _ftdm_channel_call_indicate(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (indication)) +#define ftdm_channel_call_indicate(ftdmchan, indication) _ftdm_channel_call_indicate(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (indication), NULL) +#define ftdm_channel_call_indicate_ex(ftdmchan, indication, usrmsg) _ftdm_channel_call_indicate(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (indication), (usrmsg)) /*! \brief Indicate a new condition in an incoming call recording the source code point where it was called (see ftdm_channel_call_indicate for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication); - -/*! \brief Send a message on a call */ -#define ftdm_channel_call_send_msg(ftdmchan, sigmsg) _ftdm_channel_call_send_msg(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (sigmsg)) - -/*! \brief Send a signal on a call recording the source code point where it was called (see ftdm_channel_call_send_msg for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_send_msg(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_sigmsg_t *sigmsg); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication, ftdm_usrmsg_t *usrmsg); /*! \brief Hangup the call without cause */ -#define ftdm_channel_call_hangup(ftdmchan) _ftdm_channel_call_hangup(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_call_hangup(ftdmchan) _ftdm_channel_call_hangup(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_call_hangup_ex(ftdmchan, usrmsg) _ftdm_channel_call_hangup(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (usrmsg)) /*! \brief Hangup the call without cause recording the source code point where it was called (see ftdm_channel_call_hangup for an easy to use macro)*/ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Hangup the call with cause */ -#define ftdm_channel_call_hangup_with_cause(ftdmchan, cause) _ftdm_channel_call_hangup_with_cause(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (cause)) +#define ftdm_channel_call_hangup_with_cause(ftdmchan, cause) _ftdm_channel_call_hangup_with_cause(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (cause), NULL) +#define ftdm_channel_call_hangup_with_cause_ex(ftdmchan, cause, usrmsg) _ftdm_channel_call_hangup_with_cause(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (cause), (usrmsg)) /*! \brief Hangup the call with cause recording the source code point where it was called (see ftdm_channel_call_hangup_with_cause for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup_with_cause(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_call_cause_t); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup_with_cause(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_call_cause_t, ftdm_usrmsg_t *usrmsg); /*! \brief Reset the channel */ -#define ftdm_channel_reset(ftdmchan) _ftdm_channel_reset(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_reset(ftdmchan) _ftdm_channel_reset(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_reset_ex(ftdmchan, usrmsg) _ftdm_channel_reset(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), usrmsg) /*! \brief Reset the channel (see _ftdm_channel_reset for an easy to use macro) * \note if there was a call on this channel, call will be cleared without any notifications to the user */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_reset(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_reset(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Put a call on hold (if supported by the signaling stack) */ -#define ftdm_channel_call_hold(ftdmchan) _ftdm_channel_call_hold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_call_hold(ftdmchan) _ftdm_channel_call_hold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_call_hold_ex(ftdmchan, usrmsg) _ftdm_channel_call_hold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (usrmsg)) /*! \brief Put a call on hold recording the source code point where it was called (see ftdm_channel_call_hold for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Unhold a call */ -#define ftdm_channel_call_unhold(ftdmchan) _ftdm_channel_call_unhold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan)) +#define ftdm_channel_call_unhold(ftdmchan) _ftdm_channel_call_unhold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), NULL) +#define ftdm_channel_call_unhold_ex(ftdmchan, usrmsg) _ftdm_channel_call_unhold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (usrmsg)) /*! \brief Unhold a call recording the source code point where it was called (see ftdm_channel_call_unhold for an easy to use macro) */ -FT_DECLARE(ftdm_status_t) _ftdm_channel_call_unhold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan); +FT_DECLARE(ftdm_status_t) _ftdm_channel_call_unhold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); /*! \brief Check if the call is answered already */ FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_answered(const ftdm_channel_t *ftdmchan); @@ -1373,40 +1385,29 @@ 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 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_event_add_var(ftdm_sigmsg_t *sigmsg, const char *var_name, const char *value); - -/*! \brief Remove a custom variable from the event +/*! \brief Get a custom variable from the sigmsg * \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); +FT_DECLARE(const char *) ftdm_sigmsg_get_var(ftdm_sigmsg_t *sigmsg, const char *var_name); -/*! \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 +/*! \brief Get an iterator to iterate over the sigmsg 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_event_get_var_iterator(const ftdm_sigmsg_t *sigmsg, ftdm_iterator_t *iter); +FT_DECLARE(ftdm_iterator_t *) ftdm_sigmsg_get_var_iterator(const ftdm_sigmsg_t *sigmsg, ftdm_iterator_t *iter); - -/*! \brief Attach raw data to event +/*! \brief Get raw data from sigmsg * \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. + * \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 + * \note data is only valid within the duration of the callback, to receive a data pointer that does not get + * \note destroyed when callback returns, see ftdm_sigmsg_get_raw_data_detached */ -FT_DECLARE(ftdm_status_t) ftdm_event_set_raw_data(ftdm_sigmsg_t *sigmsg, void *data, ftdm_size_t datalen, uint8_t autofree); +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_get_raw_data(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen); /*! \brief Get raw data from event * \param sigmsg The message structure containing the variables @@ -1414,8 +1415,25 @@ FT_DECLARE(ftdm_status_t) ftdm_event_set_raw_data(ftdm_sigmsg_t *sigmsg, void *d * \param datalen datalen will be set to length of data available * \retval FTDM_SUCCESS data is available * \retval FTDM_FAIL no data available + * \note Once this function returns, User owns data, and is responsible to free data using ftdm_safe_free(); */ -FT_DECLARE(ftdm_status_t) ftdm_event_get_raw_data(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen); +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_get_raw_data_detached(ftdm_sigmsg_t *sigmsg, void **data, ftdm_size_t *datalen); + +/*! \brief Add a custom variable to the user message + * \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_usrmsg_add_var(ftdm_usrmsg_t *usrmsg, const char *var_name, const char *value); + +/*! \brief Attach raw data to usrmsg + * \param usrmsg The message structure containing the variables + * \param data pointer to data + * \param datalen datalen length of data + * \retval FTDM_SUCCESS success, data was successfully saved + * \retval FTDM_FAIL failed, event already had data attached to it. + * \note data must have been allocated using ftdm_calloc, FreeTDM will free data once the usrmsg is processed. + */ +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_set_raw_data(ftdm_usrmsg_t *usrmsg, 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 @@ -1424,7 +1442,7 @@ FT_DECLARE(ftdm_status_t) ftdm_event_get_raw_data(ftdm_sigmsg_t *sigmsg, void ** 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_event_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val); +FT_DECLARE(ftdm_status_t) ftdm_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); diff --git a/libs/freetdm/src/include/ftdm_declare.h b/libs/freetdm/src/include/ftdm_declare.h index b443f2d5f5..9c7f9cbe4a 100644 --- a/libs/freetdm/src/include/ftdm_declare.h +++ b/libs/freetdm/src/include/ftdm_declare.h @@ -223,6 +223,7 @@ typedef struct ftdm_conf_node ftdm_conf_node_t; typedef struct ftdm_group ftdm_group_t; typedef size_t ftdm_size_t; typedef struct ftdm_sigmsg ftdm_sigmsg_t; +typedef struct ftdm_usrmsg ftdm_usrmsg_t; typedef struct ftdm_io_interface ftdm_io_interface_t; typedef struct ftdm_stream_handle ftdm_stream_handle_t; typedef struct ftdm_queue ftdm_queue_t; diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h index fa519be9f5..ae8adfb203 100644 --- a/libs/freetdm/src/include/private/ftdm_core.h +++ b/libs/freetdm/src/include/private/ftdm_core.h @@ -468,7 +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; + ftdm_usrmsg_t *usrmsg; }; struct ftdm_span { @@ -494,7 +494,7 @@ struct ftdm_span { teletone_multi_tone_t tone_finder[FTDM_TONEMAP_INVALID+1]; ftdm_channel_t *channels[FTDM_MAX_CHANNELS_SPAN+1]; fio_channel_outgoing_call_t outgoing_call; - fio_channel_send_msg_t send_msg; + fio_channel_indicate_t indicate; fio_channel_set_sig_status_t set_channel_sig_status; fio_channel_get_sig_status_t get_channel_sig_status; fio_span_set_sig_status_t set_span_sig_status; @@ -636,14 +636,50 @@ 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 save data from user */ +FT_DECLARE(ftdm_status_t) ftdm_channel_save_usrmsg(ftdm_channel_t *ftdmchan, ftdm_usrmsg_t *usrmsg); -/*! \brief free data from internal copy (ftdmchan->sigmsg) */ -FT_DECLARE(ftdm_status_t) ftdm_channel_clear_event_data(ftdm_channel_t *ftdmchan); +/*! \brief free usrmsg and variables/raw data attached to it */ +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_free(ftdm_usrmsg_t **usrmsg); + +/*! \brief Get a custom variable from the user message + * \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_usrmsg_get_var(ftdm_usrmsg_t *usrmsg, const char *var_name); + +/*! \brief Get raw data from user message + * \param usrmsg 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 + * \note data is only valid within the duration of the callback, to receive a data pointer that does not get + * \note destroyed when callback returns, see ftdm_sigmsg_get_raw_data_detached + */ +FT_DECLARE(ftdm_status_t) ftdm_usrmsg_get_raw_data(ftdm_usrmsg_t *usrmsg, void **data, ftdm_size_t *datalen); + +/*! \brief free sigmsg and variables/raw data attached to it */ +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_free(ftdm_sigmsg_t **sigmsg); + +/*! \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_sigmsg_add_var(ftdm_sigmsg_t *sigmsg, const char *var_name, const char *value); + +/*! \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_sigmsg_remove_var(ftdm_sigmsg_t *sigmsg, const char *var_name); + +/*! \brief Attach raw data to sigmsg + * \param sigmsg The message structure containing the variables + * \param data pointer to data + * \param datalen datalen length of data + * \retval FTDM_SUCCESS success, data was successfully saved + * \retval FTDM_FAIL failed, event already had data attached to it. + * \note data must have been allocated using ftdm_calloc, FreeTDM will free data once the usrmsg is processed. + */ +FT_DECLARE(ftdm_status_t) ftdm_sigmsg_set_raw_data(ftdm_sigmsg_t *sigmsg, void *data, ftdm_size_t datalen); /*! \brief Assert condition diff --git a/libs/freetdm/src/include/private/ftdm_state.h b/libs/freetdm/src/include/private/ftdm_state.h index 5672839d15..191f8aef82 100644 --- a/libs/freetdm/src/include/private/ftdm_state.h +++ b/libs/freetdm/src/include/private/ftdm_state.h @@ -188,7 +188,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_cancel_state(const char *file, const char * \note If this function is called with the wait parameter set to a non-zero value, the recursivity * of the channel lock must be == 1 because the channel will be unlocked/locked when waiting */ 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 wait); + ftdm_channel_t *ftdmchan, ftdm_channel_state_t state, int wait, ftdm_usrmsg_t *usrmsg); /*!\brief Set the state of a channel immediately and implicitly complete the previous state if needed * \note FTDM_SIGEVENT_INDICATION_COMPLETED will be sent if the state change @@ -207,7 +207,7 @@ FT_DECLARE(ftdm_status_t) _ftdm_set_state(const char *file, const char *func, in #define ftdm_set_state_locked(obj, s) \ do { \ ftdm_channel_lock(obj); \ - ftdm_channel_set_state(__FILE__, __FUNCTION__, __LINE__, obj, s, 0); \ + ftdm_channel_set_state(__FILE__, __FUNCTION__, __LINE__, obj, s, 0, NULL); \ ftdm_channel_unlock(obj); \ } while(0);