diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 478317efac..2924a4fe7d 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -97,28 +97,28 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state( \param str the string to check \return the code */ -SWITCH_DECLARE(switch_call_cause_t) switch_channel_str2cause(const char *str); +SWITCH_DECLARE(switch_call_cause_t) switch_channel_str2cause(_In_ const char *str); /*! \brief return the cause code for a given channel \param channel the channel \return the code */ -SWITCH_DECLARE(switch_call_cause_t) switch_channel_get_cause(switch_channel_t *channel); +SWITCH_DECLARE(switch_call_cause_t) switch_channel_get_cause(_In_ switch_channel_t *channel); /*! \brief return a cause string for a given cause \param cause the code to check \return the string */ -SWITCH_DECLARE(const char *) switch_channel_cause2str(switch_call_cause_t cause); +SWITCH_DECLARE(const char *) switch_channel_cause2str(_In_ switch_call_cause_t cause); /*! \brief View the timetable of a channel \param channel channel to retrieve timetable from \return a pointer to the channel's timetable (created, answered, etc..) */ -SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch_channel_t *channel); +SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(_In_ switch_channel_t *channel); /*! \brief Allocate a new channel @@ -126,7 +126,7 @@ SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch \param pool memory_pool to use for allocation \return SWITCH_STATUS_SUCCESS if successful */ -SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_memory_pool_t *pool); +SWITCH_DECLARE(switch_status_t) switch_channel_alloc(_In_ switch_channel_t **channel, _In_ switch_memory_pool_t *pool); /*! \brief Connect a newly allocated channel to a session object and setup it's initial state @@ -418,7 +418,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan \param channel channel to test \return number of digits in the queue */ -SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(switch_channel_t *channel); +SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(_In_ switch_channel_t *channel); /*! \brief Queue DTMF on a given channel @@ -426,8 +426,8 @@ SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(switch_channel_t *channel) \param dtmf digit \return SWITCH_STATUS_SUCCESS if successful */ -SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf); -SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string); +SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(_In_ switch_channel_t *channel, _In_ const switch_dtmf_t *dtmf); +SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(_In_ switch_channel_t *channel, _In_ const char *dtmf_string); /*! \brief Retrieve DTMF digits from a given channel @@ -435,30 +435,30 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_ \param dtmf digit \return number of bytes read into the buffer */ -SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf); -SWITCH_DECLARE(void) switch_channel_flush_dtmf(switch_channel_t *channel); -SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(switch_channel_t *channel, char *dtmf_str, switch_size_t len); +SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf); +SWITCH_DECLARE(void) switch_channel_flush_dtmf(_In_ switch_channel_t *channel); +SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(_In_ switch_channel_t *channel, _Out_opt_bytecapcount_(len) char *dtmf_str, _In_ switch_size_t len); /*! \brief Render the name of the provided state enum \param state state to get name of \return the string representation of the state */ -SWITCH_DECLARE(const char *) switch_channel_state_name(switch_channel_state_t state); +SWITCH_DECLARE(const char *) switch_channel_state_name(_In_ switch_channel_state_t state); /*! \brief Render the enum of the provided state name \param name the name of the state \return the enum value (numeric) */ -SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(const char *name); +SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(_In_ const char *name); /*! \brief Add information about a given channel to an event object \param channel channel to add information about \param event event to add information to */ -SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, switch_event_t *event); +SWITCH_DECLARE(void) switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event); /*! \brief Expand varaibles in a string based on the variables in a paticular channel @@ -467,9 +467,9 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw \return the original string if no expansion takes place otherwise a new string that must be freed \note it's necessary to test if the return val is the same as the input and free the string if it is not. */ -SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel, const char *in); -SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *channel, switch_caller_profile_t *caller_profile, const char *prefix); -SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *channel); +SWITCH_DECLARE(char *) switch_channel_expand_variables(_In_ switch_channel_t *channel, _In_ const char *in); +SWITCH_DECLARE(char *) switch_channel_build_param_string(_In_ switch_channel_t *channel, _In_opt_ switch_caller_profile_t *caller_profile, _In_opt_ const char *prefix); +SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(_In_ switch_channel_t *channel); #define switch_channel_stop_broadcast(_channel) if (switch_channel_test_flag(_channel, CF_BROADCAST)) switch_channel_set_flag(_channel, CF_BREAK | CF_STOP_BROADCAST) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 8a16fb0343..3a9fe68b87 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -405,7 +405,7 @@ SWITCH_DECLARE(void *) switch_core_alloc(_In_ switch_memory_pool_t *pool, _In_ s \return a void pointer to the newly allocated memory \note the memory will be in scope as long as the session exists */ -SWITCH_DECLARE(void *) switch_core_session_alloc(_In_ switch_core_session_t *session, _In_ switch_size_t memory); +_Ret_ SWITCH_DECLARE(void *) switch_core_session_alloc(_In_ switch_core_session_t *session, _In_ switch_size_t memory); /*! \brief Copy a string using permanent memory allocation @@ -512,7 +512,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(_In_ switch_co \param session the session to retrieve from \return a pointer to the channel object */ -SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(_In_ switch_core_session_t *session); +_Ret_ SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(_In_ switch_core_session_t *session); /*! \brief Signal a session's state machine thread that a state change has occured diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 825e7dc7e7..a6ea59f42a 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -98,7 +98,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channe \param event the event to parse \return SWITCH_STATUS_SUCCESS if successful */ -SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event); +SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(_In_ switch_core_session_t *session, _In_ switch_event_t *event); /*! \brief Parse all commands from an event @@ -388,8 +388,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess \param peer_session_data data to pass to the DTMF callback for peer_session \return SWITCH_STATUS_SUCCESS if all is well */ -SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session, - switch_core_session_t *peer_session, +SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(_In_ switch_core_session_t *session, + _In_ switch_core_session_t *peer_session, switch_input_callback_function_t dtmf_callback, void *session_data, void *peer_session_data); @@ -408,7 +408,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t * \param dialplan the new dialplan (OPTIONAL, may be NULL) \param context the new context (OPTIONAL, may be NULL) */ -SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan, const char *context); +SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan, const char *context); /*! \brief Transfer an existing session to another location in the future diff --git a/src/include/switch_platform.h b/src/include/switch_platform.h index d0ef03ea19..217f3fce10 100644 --- a/src/include/switch_platform.h +++ b/src/include/switch_platform.h @@ -313,6 +313,8 @@ SWITCH_END_EXTERN_C #define _Inout_ #define _Inout_opt_ #define _In_bytecount_(x) +#define _Out_opt_bytecapcount_(x) +#define _Ret_ #endif diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index d6e87ea0db..8613e78723 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1465,7 +1465,6 @@ SWITCH_STANDARD_API(originate_function) } caller_channel = switch_core_session_get_channel(caller_session); - switch_assert(caller_channel != NULL); switch_channel_clear_state_handler(caller_channel, NULL); if (*exten == '&' && *(exten + 1)) { @@ -2016,8 +2015,6 @@ SWITCH_STANDARD_API(uuid_setvar_function) switch_channel_t *channel; channel = switch_core_session_get_channel(psession); - switch_assert(channel != NULL); - if (switch_strlen_zero(var_name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); stream->write_function(stream, "-ERR No variable specified\n"); @@ -2063,8 +2060,6 @@ SWITCH_STANDARD_API(uuid_getvar_function) if ((psession = switch_core_session_locate(uuid))) { switch_channel_t *channel; channel = switch_core_session_get_channel(psession); - - switch_assert(channel != NULL); if (switch_strlen_zero(var_name)) { stream->write_function(stream, "-ERR No variable name specified!\n"); @@ -2119,7 +2114,6 @@ SWITCH_STANDARD_API(uuid_dump_function) char *buf; channel = switch_core_session_get_channel(psession); - switch_assert(channel != NULL); if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { switch_xml_t xml; diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 16639363dc..ea6a8849fa 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1366,7 +1366,6 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread, switch_assert(member != NULL); channel = switch_core_session_get_channel(member->session); - switch_assert(channel != NULL); read_codec = switch_core_session_get_read_codec(member->session); switch_assert(read_codec != NULL); @@ -1550,7 +1549,6 @@ static void conference_loop_output(conference_member_t * member) uint32_t low_count = 0, bytes = samples * 2; call_list_t *call_list = NULL, *cp = NULL; - switch_assert(channel != NULL); switch_assert(member->conference != NULL); if (switch_core_timer_init(&timer, member->conference->timer_name, interval, tsamples, NULL) == SWITCH_STATUS_SUCCESS) { @@ -2450,13 +2448,10 @@ static void conference_list_pretty(conference_obj_t * conference, switch_stream_ channel = switch_core_session_get_channel(member->session); profile = switch_channel_get_caller_profile(channel); - stream->write_function(stream, "%u) %s (%s)\n", member->id, profile->caller_id_name, profile->caller_id_number); - } switch_mutex_unlock(conference->member_mutex); - } static void conference_list(conference_obj_t * conference, switch_stream_handle_t *stream, char *delim) @@ -2486,7 +2481,6 @@ static void conference_list(conference_obj_t * conference, switch_stream_handle_ profile = switch_channel_get_caller_profile(channel); name = switch_channel_get_name(channel); - stream->write_function(stream, "%u%s%s%s%s%s%s%s%s%s", member->id, delim, name, delim, uuid, delim, profile->caller_id_name, delim, profile->caller_id_number, delim); @@ -3637,7 +3631,6 @@ static switch_status_t audio_bridge_on_ring(switch_core_session_t *session) switch_channel_t *channel = NULL; channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CUSTOM RING\n"); @@ -3684,12 +3677,10 @@ static switch_status_t conference_outcall(conference_obj_t * conference, } peer_channel = switch_core_session_get_channel(peer_session); - switch_assert(peer_channel != NULL); rdlock = 1; goto callup; } - conference_name = conference->name; if (switch_thread_rwlock_tryrdlock(conference->rwlock) != SWITCH_STATUS_SUCCESS) { @@ -3699,7 +3690,6 @@ static switch_status_t conference_outcall(conference_obj_t * conference, if (session != NULL) { caller_channel = switch_core_session_get_channel(session); - } if (switch_strlen_zero(cid_name)) { @@ -3723,7 +3713,6 @@ static switch_status_t conference_outcall(conference_obj_t * conference, rdlock = 1; peer_channel = switch_core_session_get_channel(peer_session); - switch_assert(peer_channel != NULL); /* make sure the conference still exists */ if (!switch_test_flag(conference, CFLAG_RUNNING)) { @@ -3942,8 +3931,6 @@ SWITCH_STANDARD_APP(conference_auto_function) switch_channel_t *channel = switch_core_session_get_channel(session); call_list_t *call_list, *np; - switch_assert(channel != NULL); - call_list = switch_channel_get_private(channel, "_conference_autocall_list_"); if (switch_strlen_zero(data)) { @@ -3987,8 +3974,6 @@ SWITCH_STANDARD_APP(conference_function) conf_xml_cfg_t xml_cfg = { 0 }; switch_event_t *params = NULL; - switch_assert(channel != NULL); - if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid arguments\n"); return; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index db53fae7df..64ce99e933 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -111,10 +111,7 @@ SWITCH_STANDARD_APP(set_user_function) { switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params; char *user, *mailbox, *domain; - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); + switch_channel_t *channel = switch_core_session_get_channel(session); if (switch_strlen_zero(data)) { goto error; @@ -164,29 +161,19 @@ SWITCH_STANDARD_APP(set_user_function) SWITCH_STANDARD_APP(ring_ready_function) { - switch_channel_t *channel; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - switch_channel_ring_ready(channel); + switch_channel_ring_ready(switch_core_session_get_channel(session)); } SWITCH_STANDARD_APP(break_function) { - switch_channel_t *channel; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - switch_channel_set_flag(channel, CF_BREAK); + switch_channel_set_flag(switch_core_session_get_channel(session), CF_BREAK); } SWITCH_STANDARD_APP(queue_dtmf_function) { - switch_channel_t *channel; - channel = switch_core_session_get_channel(session); - switch_channel_queue_dtmf_string(channel, (const char *) data); - + switch_channel_queue_dtmf_string(switch_core_session_get_channel(session), (const char *) data); } - SWITCH_STANDARD_APP(send_dtmf_function) { switch_core_session_send_dtmf_string(session, (const char *) data); @@ -329,12 +316,8 @@ SWITCH_STANDARD_APP(eval_function) SWITCH_STANDARD_APP(phrase_function) { - switch_channel_t *channel; char *mydata = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) { const char *lang; char *macro = mydata; @@ -344,7 +327,7 @@ SWITCH_STANDARD_APP(phrase_function) *mdata++ = '\0'; } - lang = switch_channel_get_variable(channel, "language"); + lang = switch_channel_get_variable(switch_core_session_get_channel(session), "language"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, switch_str_nil(mdata), switch_str_nil(lang)); switch_ivr_phrase_macro(session, macro, mdata, lang, NULL); @@ -353,35 +336,23 @@ SWITCH_STANDARD_APP(phrase_function) SWITCH_STANDARD_APP(hangup_function) { - switch_channel_t *channel; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (!switch_strlen_zero(data)) { cause = switch_channel_str2cause(data); } - switch_channel_hangup(channel, cause); + switch_channel_hangup(switch_core_session_get_channel(session), cause); } SWITCH_STANDARD_APP(answer_function) { - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - switch_channel_answer(channel); + switch_channel_answer(switch_core_session_get_channel(session)); } SWITCH_STANDARD_APP(pre_answer_function) { - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - switch_channel_pre_answer(channel); + switch_channel_pre_answer(switch_core_session_get_channel(session)); } SWITCH_STANDARD_APP(redirect_function) @@ -420,12 +391,8 @@ SWITCH_STANDARD_APP(deflect_function) SWITCH_STANDARD_APP(set_function) { - switch_channel_t *channel; char *var, *val = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); } else { @@ -440,7 +407,7 @@ SWITCH_STANDARD_APP(set_function) } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var, val ? val : "UNDEF"); - switch_channel_set_variable(channel, var, val); + switch_channel_set_variable(switch_core_session_get_channel(session), var, val); } } @@ -470,14 +437,10 @@ SWITCH_STANDARD_APP(set_global_function) SWITCH_STANDARD_APP(set_profile_var_function) { - switch_channel_t *channel; switch_caller_profile_t *caller_profile; char *name, *val = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - caller_profile = switch_channel_get_caller_profile(channel); + caller_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(session)); if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); @@ -550,14 +513,11 @@ SWITCH_STANDARD_APP(set_profile_var_function) SWITCH_STANDARD_APP(export_function) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); const char *exports; char *new_exports = NULL, *new_exports_d = NULL, *var, *val = NULL, *var_name = NULL; int local = 1; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); } else { @@ -599,27 +559,18 @@ SWITCH_STANDARD_APP(export_function) SWITCH_STANDARD_APP(unset_function) { - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n"); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "UNSET [%s]\n", (char *) data); - switch_channel_set_variable(channel, data, NULL); + switch_channel_set_variable(switch_core_session_get_channel(session), data, NULL); } } SWITCH_STANDARD_APP(log_function) { - switch_channel_t *channel; char *level, *log_str; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (data && (level = strdup(data))) { switch_log_level_t ltype = SWITCH_LOG_DEBUG; @@ -640,15 +591,11 @@ SWITCH_STANDARD_APP(log_function) SWITCH_STANDARD_APP(info_function) { - switch_channel_t *channel; switch_event_t *event; char *buf; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); + switch_channel_event_set_data(switch_core_session_get_channel(session), event); switch_event_serialize(event, &buf, SWITCH_FALSE); switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); @@ -659,17 +606,13 @@ SWITCH_STANDARD_APP(info_function) SWITCH_STANDARD_APP(event_function) { - switch_channel_t *channel; switch_event_t *event; char *argv[25] = { 0 }; int argc = 0; char *lbuf; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_APPLICATION) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); + switch_channel_event_set_data(switch_core_session_get_channel(session), event); if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) { int x = 0; @@ -700,13 +643,7 @@ SWITCH_STANDARD_APP(event_function) SWITCH_STANDARD_APP(privacy_function) { - switch_channel_t *channel; - switch_caller_profile_t *caller_profile; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - caller_profile = switch_channel_get_caller_profile(channel); + switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(session)); if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No privacy mode specified.\n"); @@ -742,15 +679,11 @@ SWITCH_STANDARD_APP(strftime_function) switch_size_t retsize; switch_time_exp_t tm; char date[80] = ""; - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); switch_time_exp_lt(&tm, switch_timestamp_now()); switch_strftime(date, &retsize, sizeof(date), argv[1], &tm); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", argv[0], date); - switch_channel_set_variable(channel, argv[0], date); + switch_channel_set_variable(switch_core_session_get_channel(session), argv[0], date); } } @@ -1025,8 +958,6 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit const char *terminators; switch_channel_t *channel = switch_core_session_get_channel(session); const char *p; - - switch_assert(channel); if (!(terminators = switch_channel_get_variable(channel, SWITCH_PLAYBACK_TERMINATORS_VARIABLE))) { terminators = "*"; @@ -1067,8 +998,6 @@ SWITCH_STANDARD_APP(speak_function) char *mydata = NULL; switch_input_args_t args = { 0 }; - switch_assert(channel != NULL); - if (switch_strlen_zero(data) || !(mydata = switch_core_session_strdup(session, data))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Params!\n"); return; @@ -1122,12 +1051,9 @@ SWITCH_STANDARD_APP(speak_function) SWITCH_STANDARD_APP(playback_function) { - switch_channel_t *channel = switch_core_session_get_channel(session); switch_input_args_t args = { 0 }; - switch_assert(channel != NULL); - - switch_channel_pre_answer(channel); + switch_channel_pre_answer(switch_core_session_get_channel(session)); args.input_callback = on_dtmf; switch_ivr_play_file(session, NULL, data, &args); @@ -1135,7 +1061,6 @@ SWITCH_STANDARD_APP(playback_function) SWITCH_STANDARD_APP(gentones_function) { - switch_channel_t *channel; char *tone_script = NULL; switch_input_args_t args = { 0 }; char *l; @@ -1146,12 +1071,7 @@ SWITCH_STANDARD_APP(gentones_function) return; } - tone_script = switch_core_session_strdup(session, data); - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - switch_channel_pre_answer(channel); + switch_channel_pre_answer(switch_core_session_get_channel(session)); if ((l = strchr(tone_script, '|'))) { *l++ = '\0'; @@ -1208,8 +1128,6 @@ SWITCH_STANDARD_APP(record_function) const char *tmp; int rate; - switch_assert(channel != NULL); - if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) { argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } else { @@ -1301,8 +1219,6 @@ SWITCH_STANDARD_APP(audio_bridge_function) uint8_t no_media_bridge = 0; switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; - assert(caller_channel != NULL); - if (switch_strlen_zero(data)) { return; } diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 41fb9ff8ee..cc6cbc16c6 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -547,8 +547,6 @@ SWITCH_STANDARD_DIALPLAN(enum_dialplan_hunt) enum_route_t *rtp; char *dp = (char *) arg; - assert(channel != NULL); - if (!caller_profile) { caller_profile = switch_channel_get_caller_profile(channel); } @@ -597,8 +595,6 @@ SWITCH_STANDARD_APP(enum_app_function) uint32_t cnt = 1; switch_channel_t *channel = switch_core_session_get_channel(session); - assert(channel != NULL); - if (!(mydata = switch_core_session_strdup(session, data))) { return; } diff --git a/src/mod/applications/mod_esf/mod_esf.c b/src/mod/applications/mod_esf/mod_esf.c index f6336a03d6..89da297789 100644 --- a/src/mod/applications/mod_esf/mod_esf.c +++ b/src/mod/applications/mod_esf/mod_esf.c @@ -56,7 +56,7 @@ typedef enum { SWITCH_STANDARD_APP(bcast_function) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_socket_t *socket; switch_sockaddr_t *audio_addr = NULL, *control_packet_addr; switch_frame_t *read_frame; @@ -77,11 +77,6 @@ SWITCH_STANDARD_APP(bcast_function) switch_port_t mcast_control_port = 6061; char *mcast_port_str = "34567"; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - if (!switch_strlen_zero((char *) data)) { mydata = switch_core_session_strdup(session, data); assert(mydata != NULL); diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 78e1cd61d3..fa1f651b2a 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -40,10 +40,7 @@ SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL); static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen) { - switch_core_session_t *bleg; - switch_channel_t *channel; - - bleg = (switch_core_session_t *) buf; + switch_core_session_t *bleg = (switch_core_session_t *) buf; switch (itype) { case SWITCH_INPUT_TYPE_DTMF: @@ -51,10 +48,8 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit switch_dtmf_t *dtmf = (switch_dtmf_t *) input; if (dtmf->digit == '*') { - channel = switch_core_session_get_channel(session); - if (switch_channel_test_flag(channel, CF_ORIGINATOR)) { - channel = switch_core_session_get_channel(bleg); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + if (switch_channel_test_flag(switch_core_session_get_channel(session), CF_ORIGINATOR)) { + switch_channel_hangup(switch_core_session_get_channel(bleg), SWITCH_CAUSE_NORMAL_CLEARING); return SWITCH_STATUS_BREAK; } } @@ -67,10 +62,8 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit return SWITCH_STATUS_SUCCESS; } - #define check_string(s) if (!switch_strlen_zero(s) && !strcasecmp(s, "undef")) { s = NULL; } - static switch_status_t read_frame_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data) { switch_queue_t *fifo = (switch_queue_t *) user_data; @@ -194,7 +187,7 @@ SWITCH_STANDARD_APP(fifo_function) int argc; char *mydata = NULL, *argv[5] = { 0 }; fifo_node_t *node; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); int nowait = 0; const char *moh = NULL; const char *announce = NULL; @@ -208,8 +201,7 @@ SWITCH_STANDARD_APP(fifo_function) return; } - - if (switch_strlen_zero(data)) { + if (switch_strlen_zero(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Args\n"); return; } @@ -221,17 +213,13 @@ SWITCH_STANDARD_APP(fifo_function) return; } - channel = switch_core_session_get_channel(session); - - switch_mutex_lock(globals.mutex); + switch_mutex_lock(globals.mutex); if (!(node = switch_core_hash_find(globals.fifo_hash, argv[0]))) { node = create_node(argv[0]); } switch_mutex_unlock(globals.mutex); - - - moh = switch_channel_get_variable(channel, "fifo_music"); + moh = switch_channel_get_variable(channel, "fifo_music"); announce = switch_channel_get_variable(channel, "fifo_announce"); if (argc > 2) { @@ -254,8 +242,7 @@ SWITCH_STANDARD_APP(fifo_function) check_string(announce); check_string(moh); - - if (moh) { + if (moh) { switch_ivr_broadcast(uuid, moh, SMF_LOOP | SMF_ECHO_ALEG); } @@ -284,9 +271,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_park(session, NULL); - - - if (switch_channel_ready(channel)) { + if (switch_channel_ready(channel)) { if (announce) { switch_ivr_play_file(session, NULL, announce, NULL); } @@ -345,9 +330,8 @@ SWITCH_STANDARD_APP(fifo_function) switch_mutex_unlock(node->mutex); switch_channel_answer(channel); } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(channel, event); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_start"); @@ -360,9 +344,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_channel_set_variable(channel, "fifo_status", "WAITING"); switch_channel_set_variable(channel, "fifo_timestamp", date); - - - while(switch_channel_ready(channel)) { + while(switch_channel_ready(channel)) { if (moh) { args.read_frame_callback = read_frame_callback; args.user_data = node->fifo; @@ -389,8 +371,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_channel_t *other_channel = switch_core_session_get_channel(other_session); switch_caller_profile_t *cloned_profile; - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(other_channel, event); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "caller_pop"); @@ -404,9 +385,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_fire(&event); } - - - if (announce) { + if (announce) { switch_ivr_play_file(session, NULL, announce, NULL); } else { switch_ivr_sleep(session, 500); @@ -477,8 +456,7 @@ SWITCH_STANDARD_APP(fifo_function) } } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(channel, event); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop"); @@ -495,7 +473,6 @@ SWITCH_STANDARD_APP(fifo_function) } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE); } - } static int xml_hash(switch_xml_t xml, switch_hash_t *hash, char *container, char *tag, int cc_off, int verbose) diff --git a/src/mod/applications/mod_limit/mod_limit.c b/src/mod/applications/mod_limit/mod_limit.c index 72d05630b3..d0e4f1d238 100644 --- a/src/mod/applications/mod_limit/mod_limit.c +++ b/src/mod/applications/mod_limit/mod_limit.c @@ -284,18 +284,13 @@ static switch_status_t do_config() static switch_status_t hanguphook(switch_core_session_t *session) { - switch_channel_t *channel; - switch_channel_state_t state; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); const char *realm = NULL; const char *id = NULL; char *sql = NULL; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - state = switch_channel_get_state(channel); - - if (state == CS_HANGUP || state == CS_RING) { + if (state == CS_HANGUP || state == CS_RING) { id = switch_channel_get_variable(channel, "limit_id"); realm = switch_channel_get_variable(channel, "limit_realm"); sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';", @@ -406,16 +401,12 @@ SWITCH_STANDARD_API(db_api_function) SWITCH_STANDARD_APP(db_function) { - switch_channel_t *channel; int argc = 0; char *argv[4] = { 0 }; char *mydata = NULL; char *sql = NULL; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - if (!switch_strlen_zero(data)) { + if (!switch_strlen_zero(data)) { mydata = switch_core_session_strdup(session, data); argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0]))); } @@ -423,9 +414,8 @@ SWITCH_STANDARD_APP(db_function) if (argc < 4 || !argv[0]) { goto error; } - - - if (!strcasecmp(argv[0], "insert")) { + + if (!strcasecmp(argv[0], "insert")) { sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]); switch_assert(sql); limit_execute_sql(sql, globals.mutex); @@ -441,12 +431,8 @@ SWITCH_STANDARD_APP(db_function) switch_safe_free(sql); return; - - error: +error: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE); - - - } @@ -536,16 +522,12 @@ SWITCH_STANDARD_API(group_api_function) SWITCH_STANDARD_APP(group_function) { - switch_channel_t *channel; int argc = 0; char *argv[3] = { 0 }; char *mydata = NULL; char *sql; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - if (!switch_strlen_zero(data)) { + if (!switch_strlen_zero(data)) { mydata = switch_core_session_strdup(session, data); argc = switch_separate_string(mydata, ':', argv, (sizeof(argv) / sizeof(argv[0]))); } @@ -585,10 +567,7 @@ SWITCH_STANDARD_APP(limit_function) int max = 0, got = 0; char buf[80] = ""; callback_t cbt = { 0 }; - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_channel_t *channel = switch_core_session_get_channel(session); if (!switch_strlen_zero(data)) { mydata = switch_core_session_strdup(session, data); @@ -600,12 +579,9 @@ SWITCH_STANDARD_APP(limit_function) return; } + switch_mutex_lock(globals.mutex); - switch_mutex_lock(globals.mutex); - - - - realm = argv[0]; + realm = argv[0]; id = argv[1]; max = atoi(argv[2]); @@ -639,11 +615,8 @@ SWITCH_STANDARD_APP(limit_function) limit_execute_sql(sql, NULL); switch_safe_free(sql); - - done: - +done: switch_mutex_unlock(globals.mutex); - } diff --git a/src/mod/applications/mod_rss/mod_rss.c b/src/mod/applications/mod_rss/mod_rss.c index c514408489..358df1055e 100644 --- a/src/mod/applications/mod_rss/mod_rss.c +++ b/src/mod/applications/mod_rss/mod_rss.c @@ -155,7 +155,7 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit SWITCH_STANDARD_APP(rss_function) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status; const char *err = NULL; struct dtmf_buffer dtb = { 0 }; @@ -185,16 +185,12 @@ SWITCH_STANDARD_APP(rss_function) uint32_t matches = 0; switch_input_args_t args = { 0 }; const char *vcf = NULL; - char *chanvars = NULL; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + char *chanvars = switch_channel_build_param_string(channel, NULL, NULL); if ((vcf = switch_channel_get_variable(channel, "rss_alt_config"))) { cf = vcf; } - chanvars = switch_channel_build_param_string(channel, NULL, NULL); if (!(cxml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); return; diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index a15f29eb06..127d3e0dd9 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -792,13 +792,9 @@ static switch_status_t vm_macro_get(switch_core_session_t *session, uint32_t timeout) { switch_input_args_t args = { 0 }, *ap = NULL; - switch_channel_t *channel; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_size_t bslen; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (buf && buflen) { memset(buf, 0, buflen); args.input_callback = cancel_on_dtmf; @@ -870,7 +866,7 @@ typedef enum { static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile, char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; switch_file_handle_t fh = { 0 }; switch_input_args_t args = { 0 }; @@ -878,8 +874,6 @@ static switch_status_t create_file(switch_core_session_t *session, vm_profile_t char input[10] = "" , key_buf[80] = ""; cc_t cc = { 0 }; switch_codec_t *read_codec; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); read_codec = switch_core_session_get_read_codec(session); @@ -1040,15 +1034,13 @@ static void message_count(vm_profile_t *profile, const char *myid, const char *d static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t *profile, listen_callback_t *cbt) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; switch_input_args_t args = { 0 }; char term; char input[10] = "" , key_buf[80] = ""; switch_file_handle_t fh = { 0 }; cc_t cc = { 0 }; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); if(switch_channel_ready(channel)) { @@ -1227,10 +1219,10 @@ end: static void voicemail_check_main(switch_core_session_t *session, const char *profile_name, const char *domain_name, const char *id, int auth) { vm_check_state_t vm_check_state = VM_CHECK_START; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_caller_profile_t *caller_profile; vm_profile_t *profile; - switch_xml_t x_domain, x_domain_root, x_user, x_params, x_param; + switch_xml_t x_domain = NULL, x_domain_root = NULL, x_user = NULL, x_params, x_param; switch_status_t status; char pass_buf[80] = "", *mypass = NULL, id_buf[80] = "", *myfolder = NULL; const char *thepass = NULL, *myid = id; @@ -1246,16 +1238,11 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro int heard_auto_saved = 0, heard_auto_new = 0; char *email_vm = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name); return; } - x_user = x_domain = x_domain_root = NULL; - timeout = profile->digit_timeout; attempts = profile->max_login_attempts; @@ -1684,7 +1671,7 @@ end: static switch_status_t voicemail_leave_main(switch_core_session_t *session, const char *profile_name, const char *domain_name, const char *id) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); char *myfolder = "inbox"; char sql[256]; prefs_callback_t cbt; @@ -1693,7 +1680,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons char *file_path = NULL; char *dir_path = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_caller_profile_t *caller_profile; + switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(channel); switch_file_handle_t fh = { 0 }; switch_input_args_t args = { 0 }; char *email_vm = NULL; @@ -1719,10 +1706,6 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons return SWITCH_STATUS_FALSE; } - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - caller_profile = switch_channel_get_caller_profile(channel); if(switch_strlen_zero(profile->storage_dir)) { dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, SWITCH_PATH_SEPARATOR, @@ -2059,10 +2042,7 @@ SWITCH_STANDARD_APP(voicemail_function) const char *id = NULL; const char *auth_var = NULL; int x = 0, check = 0, auth = 0; - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); + switch_channel_t *channel = switch_core_session_get_channel(session); if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", SWITCH_GLOBAL_dirs.storage_dir); diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c index ff92d0838e..80c3c80103 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -52,13 +52,8 @@ SWITCH_STANDARD_APP(dial_function) int argc; char *argv[4] = { 0 }; char *mydata; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - if (data && (mydata = switch_core_session_strdup(session, data))) { if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { goto error; @@ -89,11 +84,7 @@ SWITCH_STANDARD_APP(avoid_function) { void *y = NULL; int x = 0; - - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_channel_t *channel = switch_core_session_get_channel(session); for (x = 0; x < 5; x++) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Avoiding initial deadlock on channel %s.\n", switch_channel_get_name(channel)); @@ -109,11 +100,7 @@ SWITCH_STANDARD_APP(goto_function) int argc; char *argv[3] = { 0 }; char *mydata; - switch_channel_t *channel; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - + if (data && (mydata = switch_core_session_strdup(session, data))) { if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 1) { goto error; @@ -134,7 +121,7 @@ SWITCH_STANDARD_APP(goto_function) SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) { switch_caller_extension_t *extension = NULL; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); char *cf = "extensions.conf"; switch_config_t cfg; char *var, *val; @@ -144,9 +131,6 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) cf = arg; } - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - if (!caller_profile) { caller_profile = switch_channel_get_caller_profile(channel); } diff --git a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c index 0e7ace9f25..f94c279ba9 100644 --- a/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c +++ b/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c @@ -86,16 +86,13 @@ static void load_config(void) SWITCH_STANDARD_DIALPLAN(directory_dialplan_hunt) { switch_caller_extension_t *extension = NULL; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); char *var, *val; char filter[256]; switch_directory_handle_t dh; char app[512]; char *data; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - if (!caller_profile) { caller_profile = switch_channel_get_caller_profile(channel); } @@ -103,7 +100,6 @@ SWITCH_STANDARD_DIALPLAN(directory_dialplan_hunt) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name, caller_profile->destination_number); - if (!(globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) { return NULL; } diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index 0c27de0115..8d1119c54f 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -47,14 +47,11 @@ typedef enum { static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t xexten, switch_caller_extension_t **extension) { switch_xml_t xcond, xaction; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); char *exten_name = (char *) switch_xml_attr_soft(xexten, "name"); int proceed = 0; char *expression_expanded = NULL, *field_expanded = NULL; - - channel = switch_core_session_get_channel(session); - for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next) { char *field = NULL; char *do_break_a = NULL; @@ -186,11 +183,10 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root, switch_xml_t * node) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_GENERR; switch_event_t *params = NULL; - channel = switch_core_session_get_channel(session); switch_event_create(¶ms, SWITCH_EVENT_MESSAGE); switch_assert(params); @@ -204,11 +200,9 @@ static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switc SWITCH_STANDARD_DIALPLAN(dialplan_hunt) { switch_caller_extension_t *extension = NULL; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten; char *alt_path = (char *) arg; - - channel = switch_core_session_get_channel(session); if (!caller_profile) { if (!(caller_profile = switch_channel_get_caller_profile(channel))) { diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 5c0be8c7fd..8d016cfec7 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -906,7 +906,6 @@ static int activate_rtp(struct private_object *tech_pvt) static int do_candidates(struct private_object *tech_pvt, int force) { switch_channel_t *channel = switch_core_session_get_channel(tech_pvt->session); - switch_assert(channel != NULL); if (switch_test_flag(tech_pvt, TFLAG_DO_CAND)) { return 1; @@ -1052,7 +1051,7 @@ static int do_describe(struct private_object *tech_pvt, int force) static switch_status_t negotiate_media(switch_core_session_t *session) { switch_status_t ret = SWITCH_STATUS_FALSE; - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); struct private_object *tech_pvt = NULL; switch_time_t started; switch_time_t now; @@ -1061,9 +1060,6 @@ static switch_status_t negotiate_media(switch_core_session_t *session) tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - switch_set_flag_locked(tech_pvt, TFLAG_IO); started = switch_timestamp_now(); @@ -1148,15 +1144,12 @@ static switch_status_t negotiate_media(switch_core_session_t *session) */ static switch_status_t channel_on_init(switch_core_session_t *session) { - switch_channel_t *channel; + switch_channel_t *channel = switch_core_session_get_channel(session); struct private_object *tech_pvt = NULL; tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt->read_frame.buflen = SWITCH_RTP_MAX_BUF_LEN; switch_set_flag(tech_pvt, TFLAG_READY); @@ -1171,12 +1164,9 @@ static switch_status_t channel_on_init(switch_core_session_t *session) static switch_status_t channel_on_ring(switch_core_session_t *session) { - switch_channel_t *channel = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); struct private_object *tech_pvt = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1205,12 +1195,9 @@ static switch_status_t channel_on_execute(switch_core_session_t *session) static switch_status_t channel_on_hangup(switch_core_session_t *session) { - switch_channel_t *channel = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); struct private_object *tech_pvt = NULL; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1258,18 +1245,13 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) { - switch_channel_t *channel = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); struct private_object *tech_pvt = NULL; - if (!(channel = switch_core_session_get_channel(session))) { - return SWITCH_STATUS_SUCCESS; - } - if (!(tech_pvt = switch_core_session_get_private(session))) { return SWITCH_STATUS_SUCCESS; } - switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); @@ -1351,12 +1333,9 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) { struct private_object *tech_pvt = NULL; - switch_channel_t *channel = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); int payload = 0; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = (struct private_object *) switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1452,13 +1431,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) { struct private_object *tech_pvt; - switch_channel_t *channel = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; int bytes = 0, samples = 0, frames = 0; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = (struct private_object *) switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1506,10 +1482,6 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_answer_channel(switch_core_session_t *session) { struct private_object *tech_pvt; - switch_channel_t *channel = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1524,12 +1496,8 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session) static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { - switch_channel_t *channel; struct private_object *tech_pvt; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -1564,13 +1532,9 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event) { - switch_channel_t *channel; struct private_object *tech_pvt; char *subject, *body; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); @@ -2572,7 +2536,6 @@ static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlses switch_assert(tech_pvt != NULL); channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using Existing session for %s\n", ldl_session_get_id(dlsession)); diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 9f179bc99a..91526c8ed1 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -339,8 +339,6 @@ static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *i } channel = switch_core_session_get_channel(tech_pvt->session); - switch_assert(channel != NULL); - if (tech_pvt->samprate || *samprate) { unsigned short samples = iax_build_codec_rates(); @@ -456,26 +454,15 @@ static void tech_init(private_t * tech_pvt, switch_core_session_t *session) */ static switch_status_t channel_on_init(switch_core_session_t *session) { - switch_channel_t *channel; - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - iax_set_private(tech_pvt->iax_session, tech_pvt); switch_set_flag_locked(tech_pvt, TFLAG_IO); - - //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session)); - //switch_mutex_lock(tech_pvt->mutex); - /* Move Channel's State Machine to RING */ - switch_channel_set_state(channel, CS_RING); + switch_channel_set_state(switch_core_session_get_channel(session), CS_RING); switch_mutex_lock(globals.mutex); globals.calls++; switch_mutex_unlock(globals.mutex); @@ -485,52 +472,24 @@ static switch_status_t channel_on_init(switch_core_session_t *session) static switch_status_t channel_on_ring(switch_core_session_t *session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(switch_core_session_get_channel(session))); return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_on_execute(switch_core_session_t *session) { - - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); - - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(switch_core_session_get_channel(session))); return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_on_hangup(switch_core_session_t *session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; + private_t *tech_pvt = switch_core_session_get_private(session); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - //switch_thread_cond_signal(tech_pvt->cond); if (tech_pvt->read_codec.implementation) { switch_core_codec_destroy(&tech_pvt->read_codec); @@ -548,7 +507,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) iax_session_destroy(&tech_pvt->iax_session); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(switch_core_session_get_channel(session))); switch_mutex_lock(globals.mutex); globals.calls--; if (globals.calls < 0) { @@ -561,21 +520,14 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); switch (sig) { case SWITCH_SIG_KILL: switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - //switch_thread_cond_signal(tech_pvt->cond); + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_NORMAL_CLEARING); break; case SWITCH_SIG_BREAK: switch_set_flag_locked(tech_pvt, TFLAG_BREAK); @@ -601,9 +553,7 @@ static switch_status_t channel_on_transmit(switch_core_session_t *session) static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); return SWITCH_STATUS_SUCCESS; @@ -611,20 +561,15 @@ static switch_status_t channel_waitfor_read(switch_core_session_t *session, int static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); return SWITCH_STATUS_SUCCESS; - } static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (tech_pvt->iax_session) { iax_send_dtmf(tech_pvt->iax_session, dtmf->digit); @@ -635,16 +580,11 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; + private_t *tech_pvt = switch_core_session_get_private(session); switch_time_t started = switch_timestamp_now(); unsigned int elapsed; switch_byte_t *data; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); tech_pvt->read_frame.flags = SFF_NONE; *frame = NULL; @@ -655,7 +595,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch switch_yield(1000); continue; } - //switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex); if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { switch_clear_flag(tech_pvt, TFLAG_BREAK); goto cng; @@ -685,12 +624,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_SUCCESS; } } - - switch_yield(1000); } - return SWITCH_STATUS_FALSE; cng: @@ -701,19 +637,11 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt->read_frame.flags = SFF_CNG; *frame = &tech_pvt->read_frame; return SWITCH_STATUS_SUCCESS; - } static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - //switch_frame_t *pframe; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (!switch_test_flag(tech_pvt, TFLAG_IO)) { @@ -732,13 +660,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc static switch_status_t channel_answer_channel(switch_core_session_t *session) { - private_t *tech_pvt; - switch_channel_t *channel = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) { @@ -750,13 +672,7 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session) static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { - switch_channel_t *channel; - private_t *tech_pvt; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = (private_t *) switch_core_session_get_private(session); + private_t *tech_pvt = (private_t *) switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); switch (msg->message_id) { @@ -824,7 +740,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - if (iax_set_codec(tech_pvt, tech_pvt->iax_session, &req, &cap, &samprate, IAX_QUERY) != SWITCH_STATUS_SUCCESS) { switch_core_session_destroy(new_session); return SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL; @@ -844,23 +759,16 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event) { - switch_channel_t *channel; - struct private_object *tech_pvt; - char *body; + struct private_object *tech_pvt = switch_core_session_get_private(session); + char *body = switch_event_get_body(event); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - - if (!(body = switch_event_get_body(event))) { + if (!body) { body = ""; } @@ -893,7 +801,6 @@ switch_io_routines_t iax_io_routines = { SWITCH_MODULE_LOAD_FUNCTION(mod_iax_load) { - module_pool = pool; *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -980,7 +887,6 @@ static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxeve SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) { - //int refresh; struct iax_event *iaxevent = NULL; switch_event_t *s_event; if (load_config() != SWITCH_STATUS_SUCCESS) { @@ -1111,7 +1017,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) break; } - if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), iaxevent->ies.username, globals.dialplan, @@ -1128,7 +1033,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) switch_snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); switch_channel_set_name(channel, name); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - } if (iax_set_codec(tech_pvt, iaxevent->session, @@ -1163,7 +1067,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel)); switch_set_flag_locked(tech_pvt, TFLAG_HANGUP); switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED); - //switch_thread_cond_signal(tech_pvt->cond); iaxevent->session = NULL; } break; @@ -1177,7 +1080,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) int bytes, frames; if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) { - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "audio with no codec yet!\n"); break; } @@ -1192,13 +1094,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); /* wake up the i/o thread */ switch_set_flag_locked(tech_pvt, TFLAG_VOICE); - //switch_thread_cond_signal(tech_pvt->cond); } } break; case IAX_EVENT_TRANSFER: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call transfer occurred.\n"); - //session[0] = iaxevent->session; break; case IAX_EVENT_DTMF: if (channel) { @@ -1206,7 +1106,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) if (globals.debug) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel)); } - switch_channel_queue_dtmf(channel, &dtmf); } @@ -1215,10 +1114,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Don't know what to do with IAX event %d.\n", iaxevent->etype); break; } - iax_event_free(iaxevent); } - } running = 0; diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 196e6d5a1d..37c64fd904 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -165,25 +165,18 @@ static switch_status_t pa_cmd(const char *dest, switch_core_session_t *session, */ static switch_status_t channel_on_init(switch_core_session_t *session) { - switch_channel_t *channel; - private_t *tech_pvt = NULL; + switch_channel_t *channel = switch_core_session_get_channel(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_time_t last; int waitsec = globals.ring_interval * 1000000; switch_file_handle_t fh = { 0 }; const char *val, *ring_file = NULL, *hold_file = NULL; int16_t abuf[2048]; - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - last = switch_timestamp_now() - waitsec; - - if ((val = switch_channel_get_variable(channel, "pa_hold_file"))) { hold_file = val; } else { @@ -196,12 +189,9 @@ static switch_status_t channel_on_init(switch_core_session_t *session) if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n", switch_channel_get_name(channel), switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER)); - - if (engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); return SWITCH_STATUS_FALSE; @@ -297,40 +287,17 @@ static switch_status_t channel_on_init(switch_core_session_t *session) switch_channel_set_state(channel, CS_RING); return SWITCH_STATUS_SUCCESS; - } static switch_status_t channel_on_ring(switch_core_session_t *session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(channel)); - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL RING\n", switch_channel_get_name(switch_core_session_get_channel(session))); return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_on_execute(switch_core_session_t *session) { - - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); - - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(switch_core_session_get_channel(session))); return SWITCH_STATUS_SUCCESS; } @@ -429,13 +396,7 @@ static void remove_pvt(private_t * tech_pvt) static switch_status_t channel_on_hangup(switch_core_session_t *session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); remove_pvt(tech_pvt); @@ -450,20 +411,15 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session) switch_core_file_close(&tech_pvt->fh); } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(switch_core_session_get_channel(session))); return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + switch_channel_t *channel = switch_core_session_get_channel(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); switch (sig) { @@ -476,7 +432,6 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL KILL\n", switch_channel_get_name(channel)); - return SWITCH_STATUS_SUCCESS; } @@ -488,47 +443,24 @@ static switch_status_t channel_on_transmit(switch_core_session_t *session) static switch_status_t channel_on_loopback(switch_core_session_t *session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); - return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_waitfor_read(switch_core_session_t *session, int ms, int stream_id) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_waitfor_write(switch_core_session_t *session, int ms, int stream_id) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - return SWITCH_STATUS_SUCCESS; - } static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) { - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF ON CALL %s [%c]\n", tech_pvt->call_id, dtmf->digit); @@ -538,15 +470,9 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; + private_t *tech_pvt = switch_core_session_get_private(session); int samples = 0; switch_status_t status = SWITCH_STATUS_FALSE; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (!globals.audio_stream) { @@ -590,7 +516,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch return SWITCH_STATUS_SUCCESS; hold: - { switch_size_t olen = globals.read_codec.implementation->samples_per_frame; if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) { @@ -605,7 +530,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch goto cng; } - tech_pvt->hold_frame.datalen = (uint32_t) (olen * sizeof(int16_t)); tech_pvt->hold_frame.samples = (uint32_t) olen; *frame = &tech_pvt->hold_frame; @@ -642,13 +566,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; switch_status_t status = SWITCH_STATUS_FALSE; - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); if (!globals.audio_stream) { @@ -672,35 +591,18 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc } return status; - } static switch_status_t channel_answer_channel(switch_core_session_t *session) { - private_t *tech_pvt; - switch_channel_t *channel = NULL; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); - return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { - switch_channel_t *channel; - private_t *tech_pvt; - - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); + private_t *tech_pvt = switch_core_session_get_private(session); switch_assert(tech_pvt != NULL); - switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_ANSWER: channel_answer_channel(session); @@ -743,7 +645,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags) { - if ((*new_session = switch_core_session_request(portaudio_endpoint_interface, pool)) != 0) { private_t *tech_pvt; switch_channel_t *channel; @@ -790,7 +691,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi } return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } @@ -817,14 +717,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load) "Input Device: %d, Output Device: %d, Ring Device: %d Sample Rate: %d MS: %d\n", globals.indev, globals.outdev, globals.ringdev, globals.sample_rate, globals.codec_ms); - switch_core_hash_init(&globals.call_hash, module_pool); switch_mutex_init(&globals.device_lock, SWITCH_MUTEX_NESTED, module_pool); switch_mutex_init(&globals.pvt_lock, SWITCH_MUTEX_NESTED, module_pool); switch_mutex_init(&globals.flag_mutex, SWITCH_MUTEX_NESTED, module_pool); - - if (switch_event_reserve_subclass(MY_EVENT_RINGING) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n"); return SWITCH_STATUS_GENERR; @@ -1043,8 +940,7 @@ static void PrintSupportedStandardSampleRates(const PaStreamParameters * inputPa int i, printCount, cr = 7; PaError err; static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, - 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1 - }; + 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1}; printCount = cr; for (i = 0; standardSampleRates[i] > 0; i++) { @@ -1093,8 +989,6 @@ static int dump_info(void) PaError err; const char *line = "--------------------------------------------------------------------------------\n"; - - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "PortAudio version number = %d\nPortAudio version text = '%s'\n", Pa_GetVersion(), Pa_GetVersionText()); if (globals.audio_stream) { @@ -1194,8 +1088,6 @@ static int dump_info(void) return err; } - - static switch_status_t engage_device(int sample_rate, int codec_ms) { PaStreamParameters inputParameters, outputParameters; @@ -1236,13 +1128,9 @@ static switch_status_t engage_device(int sample_rate, int codec_ms) return SWITCH_STATUS_FALSE; } - - globals.read_frame.rate = sample_rate; globals.read_frame.codec = &globals.read_codec; - - switch_mutex_lock(globals.device_lock); /* LOCKED ************************************************************************************************** */ inputParameters.device = globals.indev; @@ -1261,7 +1149,6 @@ static switch_status_t engage_device(int sample_rate, int codec_ms) /* UNLOCKED ************************************************************************************************* */ switch_mutex_unlock(globals.device_lock); - if (err != paNoError) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n"); switch_core_codec_destroy(&globals.read_codec); @@ -1271,14 +1158,9 @@ static switch_status_t engage_device(int sample_rate, int codec_ms) } } - - return SWITCH_STATUS_SUCCESS; - - } - static switch_status_t engage_ring_device(int sample_rate, int channels) { PaStreamParameters outputParameters; @@ -1301,7 +1183,6 @@ static switch_status_t engage_ring_device(int sample_rate, int channels) /* UNLOCKED ************************************************************************************************* */ switch_mutex_unlock(globals.device_lock); - if (err != paNoError) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open ring device!\n"); return SWITCH_STATUS_FALSE; @@ -1312,8 +1193,6 @@ static switch_status_t engage_ring_device(int sample_rate, int channels) return SWITCH_STATUS_SUCCESS; } - - static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream) { char *dtmf_str = argv[0]; @@ -1382,7 +1261,6 @@ static switch_status_t switch_call(char **argv, int argc, switch_stream_handle_t switch_mutex_unlock(globals.pvt_lock); return SWITCH_STATUS_SUCCESS; - } static switch_status_t hangup_call(char **argv, int argc, switch_stream_handle_t *stream) @@ -1406,7 +1284,6 @@ static switch_status_t hangup_call(char **argv, int argc, switch_stream_handle_t switch_mutex_unlock(globals.pvt_lock); return SWITCH_STATUS_SUCCESS; - } static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t *stream) @@ -1446,12 +1323,9 @@ static switch_status_t answer_call(char **argv, int argc, switch_stream_handle_t } done: switch_mutex_unlock(globals.pvt_lock); - stream->write_function(stream, "Answered %d channels.\n", x); - return SWITCH_STATUS_SUCCESS; - } static switch_status_t do_flags(char **argv, int argc, switch_stream_handle_t *stream) @@ -1676,19 +1550,9 @@ SWITCH_STANDARD_API(pa_cmd) http = switch_event_get_header(stream->event, "http-host"); } - if (http) { stream->write_function(stream, "Content-type: text/html\n\n"); -#if 0 - switch_event_header_t *hp; - stream->write_function(stream, "
"); - for (hp = stream->event->headers; hp; hp = hp->next) { - stream->write_function(stream, "[%s]=[%s]\n", hp->name, hp->value); - } - stream->write_function(stream, ""); -#endif - wcmd = switch_str_nil(switch_event_get_header(stream->event, "wcmd")); action = switch_event_get_header(stream->event, "action"); @@ -1815,13 +1679,10 @@ SWITCH_STANDARD_API(pa_cmd) } done: - if (http) { - stream->write_function(stream, "