diff --git a/README.md b/README.md index 923054d848..15cda2e22f 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Step by step tutorials to install FreeSWITCH from packages: ### Build from source Example Dockerfiles to build FreeSWITCH and dependencies from source: - * https://github.com/signalwire/freeswitch/tree/dockerfile/docker/examples + * https://github.com/signalwire/freeswitch/tree/master/docker/examples Step by step tutorials to build FreeSWITCH with provided dependency packages: * [Debian](https://freeswitch.org/confluence/display/FREESWITCH/Debian#Debian-buildfromsource) [Recommended] diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index af6a4f53bd..fafaae3cba 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -310,7 +310,7 @@ extern struct switch_session_manager session_manager; switch_status_t switch_core_sqldb_init(const char **err); -void switch_core_sqldb_destroy(); +void switch_core_sqldb_destroy(void); switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage); void switch_core_sqldb_stop(void); void switch_core_session_init(switch_memory_pool_t *pool); diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index 1af0dec7ac..f65c322d30 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -448,7 +448,7 @@ SWITCH_DECLARE(switch_status_t) switch_img_to_raw(switch_image_t *src, void *des * \param[in] width The raw data width * \param[in] height The raw data height */ -SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height); +SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t** destP, void *src, switch_img_fmt_t fmt, int width, int height); SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, switch_bool_t full, const char *text); SWITCH_DECLARE(switch_image_t *) switch_img_read_file(const char* file_name); diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index a791665c08..1f767d0bde 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -1591,6 +1591,8 @@ GCC_DIAG_ON(deprecated-declarations) context->vid_ready = 1; switch_queue_push(context->eh.video_queue, img); context->last_vid_push = switch_time_now(); + } else { + switch_img_free(&img); } } } diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c index fd7bb3dafa..b035b6d7f9 100644 --- a/src/mod/applications/mod_callcenter/mod_callcenter.c +++ b/src/mod/applications/mod_callcenter/mod_callcenter.c @@ -1969,9 +1969,10 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa playback_array(agent_session, o_announce); } - /* This is used for the waiting caller to quit waiting for a agent */ + /* This is used to set the reason for callcenter_function breakout */ switch_channel_set_variable(member_channel, "cc_agent_found", "true"); switch_channel_set_variable(member_channel, "cc_agent_uuid", agent_uuid); + if (switch_true(switch_channel_get_variable(member_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE)) || switch_true(switch_channel_get_variable(agent_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE))) { switch_channel_set_flag(member_channel, CF_BYPASS_MEDIA_AFTER_BRIDGE); } @@ -1990,6 +1991,12 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa switch_channel_set_variable(agent_channel, "cc_agent_bridged", "false"); switch_channel_set_variable(member_channel, "cc_agent_bridged", "false"); + /* Set member to Abandoned state, previous Trying */ + sql = switch_mprintf("UPDATE members SET state = '%q', session_uuid = '', abandoned_epoch = '%" SWITCH_TIME_T_FMT "' WHERE uuid = '%q' AND instance_id = '%q'", + cc_member_state2str(CC_MEMBER_STATE_ABANDONED), local_epoch_time_now(NULL), h->member_uuid, globals.cc_instance_id); + cc_execute_sql(NULL, sql, NULL); + switch_safe_free(sql); + if ((o_announce = switch_channel_get_variable(member_channel, "cc_bridge_failed_outbound_announce"))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member_session), SWITCH_LOG_DEBUG, "Playing bridge failed audio to agent %s, audio: %s\n", h->agent_name, o_announce); playback_array(agent_session, o_announce); @@ -2008,9 +2015,15 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa bridged = 1; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member_session), SWITCH_LOG_DEBUG, "Member \"%s\" %s is bridged to agent %s\n", h->member_cid_name, h->member_cid_number, h->agent_name); + switch_channel_set_variable(member_channel, "cc_agent_bridged", "true"); switch_channel_set_variable(agent_channel, "cc_agent_bridged", "true"); - switch_channel_set_variable(member_channel, "cc_agent_uuid", agent_uuid); + + /* Update member to Answered state, previous Trying */ + sql = switch_mprintf("UPDATE members SET state = '%q', bridge_epoch = '%" SWITCH_TIME_T_FMT "' WHERE uuid = '%q' AND instance_id = '%q'", + cc_member_state2str(CC_MEMBER_STATE_ANSWERED), local_epoch_time_now(NULL), h->member_uuid, globals.cc_instance_id); + cc_execute_sql(NULL, sql, NULL); + switch_safe_free(sql); } if (bridged) { @@ -2111,7 +2124,7 @@ static void *SWITCH_THREAD_FUNC outbound_agent_thread_run(switch_thread_t *threa } } else { - /* Agent didn't answer or originate failed */ + /* Agent didn't answer or originate/bridge failed */ int delay_next_agent_call = 0; switch_channel_t *member_channel = switch_core_session_get_channel(member_session); switch_channel_clear_app_flag_key(CC_APP_KEY, member_channel, CC_APP_AGENT_CONNECTING); @@ -3051,6 +3064,10 @@ SWITCH_STANDARD_APP(callcenter_function) switch_channel_set_variable(member_channel, "cc_side", "member"); switch_channel_set_variable(member_channel, "cc_member_uuid", member_uuid); + /* Clear flags in case previously set */ + switch_channel_set_variable(member_channel, "cc_agent_found", NULL); + switch_channel_set_variable(member_channel, "cc_agent_bridged", NULL); + /* Add manually imported score */ if (cc_base_score) { cc_base_score_int += atoi(cc_base_score); @@ -3178,8 +3195,8 @@ SWITCH_STANDARD_APP(callcenter_function) args.buf = (void *) &ht; args.buflen = sizeof(h); - /* An agent was found, time to exit and let the bridge do it job */ - if ((p = switch_channel_get_variable(member_channel, "cc_agent_found")) && (agent_found = switch_true(p))) { + /* If the bridge didn't break the loop, break out now */ + if ((p = switch_channel_get_variable(member_channel, "cc_agent_bridged")) && (agent_found = switch_true(p))) { break; } /* If the member thread set a different reason, we monitor it so we can quit the wait */ @@ -3201,8 +3218,6 @@ SWITCH_STANDARD_APP(callcenter_function) switch_channel_set_variable(member_channel, "cc_exit_key", buf); h->member_cancel_reason = CC_MEMBER_CANCEL_REASON_EXIT_WITH_KEY; break; - } else if (!SWITCH_READ_ACCEPTABLE(status)) { - break; } } else { switch_status_t status = switch_ivr_collect_digits_callback(member_session, &args, 0, 0); @@ -3230,12 +3245,18 @@ SWITCH_STANDARD_APP(callcenter_function) h->running = 0; } + /* Stop uuid_broadcasts */ + switch_core_session_flush_private_events(member_session); + switch_channel_stop_broadcast(member_channel); + switch_channel_set_flag_value(member_channel, CF_BREAK, 2); + /* Check if we were removed because FS Core(BREAK) asked us to */ if (h->member_cancel_reason == CC_MEMBER_CANCEL_REASON_NONE && !agent_found) { h->member_cancel_reason = CC_MEMBER_CANCEL_REASON_BREAK_OUT; } switch_channel_set_variable(member_channel, "cc_agent_found", NULL); + /* Canceled for some reason */ if (!switch_channel_up(member_channel) || h->member_cancel_reason != CC_MEMBER_CANCEL_REASON_NONE) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member_session), SWITCH_LOG_DEBUG, "Member %s <%s> abandoned waiting in queue %s\n", switch_str_nil(switch_channel_get_variable(member_channel, "caller_id_name")), switch_str_nil(switch_channel_get_variable(member_channel, "caller_id_number")), queue_name); @@ -3282,12 +3303,6 @@ SWITCH_STANDARD_APP(callcenter_function) } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member_session), SWITCH_LOG_DEBUG, "Member %s <%s> is answered by an agent in queue %s\n", switch_str_nil(switch_channel_get_variable(member_channel, "caller_id_name")), switch_str_nil(switch_channel_get_variable(member_channel, "caller_id_number")), queue_name); - /* Update member state */ - sql = switch_mprintf("UPDATE members SET state = '%q', bridge_epoch = '%" SWITCH_TIME_T_FMT "' WHERE uuid = '%q' AND instance_id = '%q'", - cc_member_state2str(CC_MEMBER_STATE_ANSWERED), local_epoch_time_now(NULL), member_uuid, globals.cc_instance_id); - cc_execute_sql(NULL, sql, NULL); - switch_safe_free(sql); - /* Update some channel variables for xml_cdr needs */ switch_channel_set_variable_printf(member_channel, "cc_cause", "%s", "answered"); if ((queue = get_queue(queue_name))) { diff --git a/src/mod/applications/mod_cidlookup/mod_cidlookup.c b/src/mod/applications/mod_cidlookup/mod_cidlookup.c index 7df22fb3ef..55d7aa0d90 100644 --- a/src/mod/applications/mod_cidlookup/mod_cidlookup.c +++ b/src/mod/applications/mod_cidlookup/mod_cidlookup.c @@ -845,6 +845,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load) Macro expands to: switch_status_t mod_cidlookup_shutdown() */ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown) { + switch_xml_config_cleanup(instructions); switch_event_unbind(&reload_xml_event); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 8e737a78a2..4394d9b02f 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2417,7 +2417,7 @@ SWITCH_STANDARD_API(uptime_function) return SWITCH_STATUS_SUCCESS; } -#define CTL_SYNTAX "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]|mdns_resolve [enable|disable]]" +#define CTL_SYNTAX "[api_expansion [on|off]|recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]|mdns_resolve [enable|disable]]" SWITCH_STANDARD_API(ctl_function) { int argc; @@ -5653,22 +5653,26 @@ SWITCH_STANDARD_API(alias_function) #define COALESCE_SYNTAX "[^^],,..." SWITCH_STANDARD_API(coalesce_function) { - switch_status_t status = SWITCH_STATUS_FALSE; - char *data = (char *) cmd; char *mydata = NULL, *argv[256] = { 0 }; + char *arg = (char *) cmd; int argc = -1; + char delim = ','; - if (data && *data && (mydata = strdup(data))) { - argc = switch_separate_string(mydata, ',', argv, + if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') { + arg += 2; + delim = *arg++; + } + + if (!zstr(arg) && (mydata = strdup(arg))) { + argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0]))); } if (argc > 0) { int i; for (i = 0; i < argc; i++) { - if (argv[i] && *argv[i]) { + if (!zstr(argv[i])) { stream->write_function(stream, argv[i]); - status = SWITCH_STATUS_SUCCESS; break; } } @@ -5676,7 +5680,9 @@ SWITCH_STANDARD_API(coalesce_function) stream->write_function(stream, "-USAGE: %s\n", COALESCE_SYNTAX); } - return status; + switch_safe_free(mydata); + + return SWITCH_STATUS_SUCCESS; } #define SHOW_SYNTAX "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like ]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" @@ -7745,6 +7751,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add complete add"); switch_console_set_complete("add complete del"); switch_console_set_complete("add db_cache status"); + switch_console_set_complete("add fsctl api_expansion on"); + switch_console_set_complete("add fsctl api_expansion off"); switch_console_set_complete("add fsctl debug_level"); switch_console_set_complete("add fsctl debug_pool"); switch_console_set_complete("add fsctl debug_sql"); @@ -7793,6 +7801,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add fsctl shutdown restart elegant"); switch_console_set_complete("add fsctl sps"); switch_console_set_complete("add fsctl sync_clock"); + switch_console_set_complete("add fsctl sync_clock_when_idle"); switch_console_set_complete("add fsctl flush_db_handles"); switch_console_set_complete("add fsctl min_idle_cpu"); switch_console_set_complete("add fsctl send_sighup"); diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index e94b835c3d..9105605185 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -3803,6 +3803,7 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr switch_image_t *use_img = NULL; if (!omember->session || !switch_channel_test_flag(omember->channel, CF_VIDEO_READY) || + (conference_utils_test_flag(omember->conference, CFLAG_VIDEO_MUTE_EXIT_CANVAS) && !conference_utils_member_test_flag(omember, MFLAG_CAN_BE_SEEN)) || switch_core_session_media_flow(omember->session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_SENDONLY || switch_core_session_media_flow(omember->session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_INACTIVE) { continue; } diff --git a/src/mod/applications/mod_cv/mod_cv.cpp b/src/mod/applications/mod_cv/mod_cv.cpp index 800452dd9a..de39943b4b 100644 --- a/src/mod/applications/mod_cv/mod_cv.cpp +++ b/src/mod/applications/mod_cv/mod_cv.cpp @@ -854,7 +854,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi } if (context->rawImage && (context->debug || !context->overlay_count)) { - switch_img_from_raw(frame->img, (uint8_t *)context->rawImage->imageData, SWITCH_IMG_FMT_RGB24, context->rawImage->width, context->rawImage->height); + switch_img_from_raw(&frame->img, (uint8_t *)context->rawImage->imageData, SWITCH_IMG_FMT_RGB24, context->rawImage->width, context->rawImage->height); } int abs = 0; diff --git a/src/mod/applications/mod_enum/mod_enum.c b/src/mod/applications/mod_enum/mod_enum.c index 2908a1eb1e..aa87f24826 100644 --- a/src/mod/applications/mod_enum/mod_enum.c +++ b/src/mod/applications/mod_enum/mod_enum.c @@ -497,6 +497,7 @@ switch_status_t ldns_lookup(const char *number, const char *root, char *server_n /* create a new resolver from /etc/resolv.conf */ if (res) { ldns_resolver_free(res); + res = NULL; } s = ldns_resolver_new_frm_file(&res, NULL); } diff --git a/src/mod/applications/mod_ladspa/mod_ladspa.c b/src/mod/applications/mod_ladspa/mod_ladspa.c index 2bccfffb9c..6e04e414a9 100644 --- a/src/mod/applications/mod_ladspa/mod_ladspa.c +++ b/src/mod/applications/mod_ladspa/mod_ladspa.c @@ -370,6 +370,11 @@ static switch_bool_t ladspa_callback(switch_media_bug_t *bug, void *user_data, s } } } + + if (pvt->ldesc->activate) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "ACTIVATE\n"); + pvt->ldesc->activate(pvt->handle); + } } break; @@ -382,6 +387,10 @@ static switch_bool_t ladspa_callback(switch_media_bug_t *bug, void *user_data, s } if (pvt->handle && pvt->ldesc) { + if (pvt->ldesc->deactivate) { + pvt->ldesc->deactivate(pvt->handle); + } + pvt->ldesc->cleanup(pvt->handle); } diff --git a/src/mod/applications/mod_video_filter/mod_video_filter.c b/src/mod/applications/mod_video_filter/mod_video_filter.c index 7cf1f1dd0f..605559fdbb 100644 --- a/src/mod/applications/mod_video_filter/mod_video_filter.c +++ b/src/mod/applications/mod_video_filter/mod_video_filter.c @@ -645,7 +645,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi } - switch_img_from_raw(frame->img, patch_data, SWITCH_IMG_FMT_ARGB, frame->img->d_w, frame->img->d_h); + switch_img_from_raw(&frame->img, patch_data, SWITCH_IMG_FMT_ARGB, frame->img->d_w, frame->img->d_h); switch_img_free(&img); diff --git a/src/mod/codecs/mod_amr/bitshift.c b/src/mod/codecs/mod_amr/bitshift.c index fd3fc55606..05a00ff1b5 100644 --- a/src/mod/codecs/mod_amr/bitshift.c +++ b/src/mod/codecs/mod_amr/bitshift.c @@ -47,7 +47,7 @@ extern int switch_amr_array_lshift(uint8_t lshift, uint8_t *buf, int a_len) if (!buf || !a_len) return (-1); - if ((lshift < 0) || (lshift > 8)) + if (lshift > 8) return (-1); first_byte = 0xFF >> lshift; diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index a90aba346a..04850a672e 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -817,6 +817,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, int fec = 0, plc = 0; int32_t frame_size = 0, last_frame_size = 0; uint32_t frame_samples; + uint8_t buf[SWITCH_RTP_MAX_BUF_LEN]; if (!context) { return SWITCH_STATUS_FALSE; @@ -842,7 +843,6 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, } if (codec->cur_frame && (jb = switch_core_session_get_jb(session, SWITCH_MEDIA_TYPE_AUDIO))) { switch_frame_t frame = { 0 }; - uint8_t buf[SWITCH_RTP_MAX_BUF_LEN]; uint32_t ts = 0; uint16_t seq = 0; @@ -1105,7 +1105,7 @@ static switch_status_t switch_opus_keep_fec_enabled(switch_codec_t *codec) uint32_t LBRR_threshold_bitrate,LBRR_rate_thres_bps,real_target_bitrate ; opus_int32 a32,b32; uint32_t fs = context->enc_frame_size * 1000 / (codec->implementation->microseconds_per_packet / 1000); - float frame_rate =(float)(1000 / (codec->implementation->microseconds_per_packet / 1000)); + float frame_rate =(float)(1000 / (float)(codec->implementation->microseconds_per_packet / 1000)); uint32_t step = (codec->implementation->microseconds_per_packet / 1000) != 60 ? 8000 / (codec->implementation->microseconds_per_packet / 1000 ) : 134 ; opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(¤t_bitrate)); diff --git a/src/mod/databases/mod_pgsql/mod_pgsql.c b/src/mod/databases/mod_pgsql/mod_pgsql.c index 575252223b..0308f1f1fd 100644 --- a/src/mod/databases/mod_pgsql/mod_pgsql.c +++ b/src/mod/databases/mod_pgsql/mod_pgsql.c @@ -629,6 +629,8 @@ done: error: + pgsql_free_result(&result); + return SWITCH_STATUS_FALSE; } 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 24119f6f8c..652d292e65 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -142,6 +142,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!caller_profile || zstr(caller_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n"); + return NULL; } @@ -150,6 +151,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) if (!switch_config_open_file(&cfg, cf)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + return NULL; } @@ -226,12 +228,14 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) } } else { if (pattern && strcasecmp(pattern, field_data)) { + switch_safe_free(field_expanded); continue; } } if (cid) { if (strcasecmp(cid, caller_profile->caller_id_number)) { + switch_safe_free(field_expanded); continue; } } @@ -266,15 +270,19 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) switch_perform_substitution(re, proceed, argument, field_data, substituted, sizeof(substituted), ovector); argument = substituted; } + switch_regex_safe_free(re); if (!extension) { if (zstr(field_data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No extension!\n"); + switch_safe_free(field_expanded); break; } + if ((extension = switch_caller_extension_new(session, field_data, field_data)) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); + switch_safe_free(field_expanded); break; } } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index a2af9c3849..f14b574adf 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2949,6 +2949,9 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread sofia_set_pflag_locked(profile, PFLAG_WORKER_RUNNING); + /* Seed PRNG for functions within worker thread */ + srand((unsigned)((intptr_t) switch_thread_self() + switch_micro_time_now())); + while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING))) { if (tick) { diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 35704b44ab..8c9dfcc57a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -446,14 +446,16 @@ void sofia_glue_store_session_id(switch_core_session_t *session, sofia_profile_t a_id = switch_strip_whitespace(duped); - if (zstr(a_id)) return; + if (zstr(a_id)) { + goto end; + } p = strchr(a_id, ';'); if (p) *p = '\0'; if (!sofia_glue_is_valid_session_uuid(a_id)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Session-ID: Ignoring \"%s\" parsed as \"%s\"\n", header, a_id); - return; + goto end; } /* RFC7329 compatibility */ @@ -483,7 +485,7 @@ void sofia_glue_store_session_id(switch_core_session_t *session, sofia_profile_t if (!p) { switch_channel_set_flag(channel, CF_RFC7329_COMPAT); switch_channel_set_flag_partner(channel, CF_RFC7329_COMPAT); - return; + goto end; } p++; remote_param = strstr(p, "remote="); @@ -491,7 +493,7 @@ void sofia_glue_store_session_id(switch_core_session_t *session, sofia_profile_t switch_channel_set_flag(channel, CF_RFC7329_COMPAT); switch_channel_set_flag_partner(channel, CF_RFC7329_COMPAT); sofia_glue_check_filter_generic_params(session, profile, p); - return; + goto end; } b_id = remote_param + 7; if (!zstr(b_id) && strlen(b_id) == RFC7989_SESSION_UUID_LEN /*32*/) { @@ -503,6 +505,9 @@ void sofia_glue_store_session_id(switch_core_session_t *session, sofia_profile_t } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Session-ID: invalid uuid, ignored.\n"); } + +end: + switch_safe_free(a_id); } /* add "Session-ID:" header */ diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 5a52341036..63b2a207b5 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -429,6 +429,7 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) switch_safe_free(route_uri); switch_safe_free(ffrom); switch_safe_free(dup); + switch_safe_free(extra_headers); if (profile) { switch_thread_rwlock_unlock(profile->rwlock); @@ -3793,7 +3794,6 @@ void sofia_presence_handle_sip_i_subscribe(int status, if ((sub_max_deviation_var = profile->sip_subscription_max_deviation)) { int sub_deviation; - srand( (unsigned) ( (unsigned)(intptr_t)switch_thread_self() + switch_micro_time_now() ) ); /* random negative number between 0 and negative sub_max_deviation_var: */ sub_deviation = ( rand() % sub_max_deviation_var ) - sub_max_deviation_var; if ( (exp_delta + sub_deviation) > 45 ) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 9791190f5f..d9e04528a8 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -884,7 +884,6 @@ long sofia_reg_uniform_distribution(int max) int result; int range = max + 1; - srand((unsigned)((intptr_t) switch_thread_self() + switch_micro_time_now())); result = (int)((double)rand() / (((double)RAND_MAX + (double)1) / range)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Generated random %ld, max is %d\n", (long) result, max); @@ -894,8 +893,7 @@ long sofia_reg_uniform_distribution(int max) void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int interval) { char *sql; - int mean = interval / 2; - long next, irand; + long next; char buf[32] = ""; int count; @@ -952,8 +950,7 @@ void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int inter /* only update if needed */ if (count) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Updating ping expires for profile %s\n", profile->name); - irand = mean + sofia_reg_uniform_distribution(interval); - next = (long) now + irand; + next = (long) now + interval; sql = switch_mprintf("update sip_registrations set ping_expires = %ld where hostname='%q' and profile_name='%q' and ping_expires <= %ld ", next, mod_sofia_globals.hostname, profile->name, (long) now); @@ -1765,7 +1762,6 @@ uint8_t sofia_reg_handle_register_token(nua_t *nua, sofia_profile_t *profile, nu (( exp_max_deviation_var = profile->sip_expires_max_deviation )) ) { if (exp_max_deviation_var > 0) { int exp_deviation; - srand( (unsigned) ( (unsigned)(intptr_t)switch_thread_self() + switch_micro_time_now() ) ); /* random number between negative exp_max_deviation_var and positive exp_max_deviation_var: */ exp_deviation = ( rand() % ( exp_max_deviation_var * 2 ) ) - exp_max_deviation_var; exptime += exp_deviation; @@ -2013,23 +2009,26 @@ uint8_t sofia_reg_handle_register_token(nua_t *nua, sofia_profile_t *profile, nu sql = switch_mprintf("insert into sip_registrations " "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires," "user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port,sip_username,sip_realm," - "mwi_user,mwi_host, orig_server_host, orig_hostname, sub_host, ping_status, ping_count, force_ping) " - "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q','%q','%q','%q', '%q', %d, %d)", + "mwi_user,mwi_host, orig_server_host, orig_hostname, sub_host, ping_status, ping_count, ping_expires, force_ping) " + "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q','%q','%q','%q', '%q', %d, %ld, %d)", call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : "", contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + profile->sip_expires_late_margin, agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm, - mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host, "Reachable", 0, force_ping); + mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host, "Reachable", 0, + (long) switch_epoch_time_now(NULL) + sofia_reg_uniform_distribution(profile->iping_seconds), force_ping); } else { sql = switch_mprintf("update sip_registrations set call_id='%q'," "sub_host='%q', network_ip='%q',network_port='%q'," "presence_hosts='%q', server_host='%q', orig_server_host='%q'," "hostname='%q', orig_hostname='%q'," - "expires = %ld, force_ping=%d where sip_user='%q' and sip_username='%q' and sip_host='%q' and contact='%q'", + "expires = %ld, ping_expires=%ld, force_ping=%d " + "where sip_user='%q' and sip_username='%q' and sip_host='%q' and contact='%q'", call_id, sub_host, network_ip, network_port_c, profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4, mod_sofia_globals.hostname, mod_sofia_globals.hostname, - (long) reg_time + (long) exptime + profile->sip_expires_late_margin, force_ping, - to_user, username, reg_host, contact_str); + (long) reg_time + (long) exptime + profile->sip_expires_late_margin, + (long) switch_epoch_time_now(NULL) + sofia_reg_uniform_distribution(profile->iping_seconds), + force_ping, to_user, username, reg_host, contact_str); } if (sql) { diff --git a/src/mod/endpoints/mod_verto/mcast/mcast.c b/src/mod/endpoints/mod_verto/mcast/mcast.c index fcb3035872..aaa6da995c 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast.c +++ b/src/mod/endpoints/mod_verto/mcast/mcast.c @@ -86,6 +86,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, if ( setsockopt(handle->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)) != 0 ) { mcast_socket_close(handle); + return -1; } @@ -103,11 +104,13 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, if (setsockopt(handle->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { mcast_socket_close(handle); + return -1; } if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr, sizeof(handle->recv_addr)) < 0) { mcast_socket_close(handle); + return -1; } @@ -124,7 +127,11 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, addr_criteria.ai_flags |= AI_NUMERICHOST; snprintf(service, sizeof(service), "%d", port); - getaddrinfo(host, service, &addr_criteria, &mcast_addr); + if (getaddrinfo(host, service, &addr_criteria, &mcast_addr) != 0) { + mcast_socket_close(handle); + + return -1; + } memset(&handle->recv_addr6, 0, sizeof(handle->recv_addr6)); @@ -134,11 +141,14 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, memcpy(&mreq.ipv6mr_multiaddr, &((struct sockaddr_in6 *)mcast_addr->ai_addr)->sin6_addr, sizeof(struct in6_addr)); + freeaddrinfo(mcast_addr); + mreq.ipv6mr_interface = 0; setsockopt(handle->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, (const char *)&mreq, sizeof(mreq)); if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr6, sizeof(handle->recv_addr6)) < 0) { mcast_socket_close(handle); + return -1; } } diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index d98e1abdef..e7defb99aa 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -771,10 +771,6 @@ static void jsock_send_event(cJSON *event) } switch_thread_rwlock_unlock(verto_globals.event_channel_rwlock); - if (use_jsock) { - switch_thread_rwlock_unlock(use_jsock->rwlock); - use_jsock = NULL; - } } static jrpc_func_t jrpc_get_func(jsock_t *jsock, const char *method) @@ -1069,7 +1065,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * const char *use_passwd = NULL, *verto_context = NULL, *verto_dialplan = NULL; time_t now = switch_epoch_time_now(NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Login sucessful for user: %s domain: %s\n", id, domain ? domain : "N/A"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Login sucessful for user: %s domain: %s\n", id, domain); jsock->logintime = now; jsock->id = switch_core_strdup(jsock->pool, id); diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp.h b/src/mod/event_handlers/mod_amqp/mod_amqp.h index 0717876040..f5c63780a4 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp.h +++ b/src/mod/event_handlers/mod_amqp/mod_amqp.h @@ -87,6 +87,11 @@ typedef struct mod_amqp_keypart_s { int size; } mod_amqp_keypart_t; +typedef struct { + switch_event_types_t id; + char* subclass; +} mod_amqp_events_t; + typedef struct { char *name; @@ -103,7 +108,7 @@ typedef struct { /* Array to store the possible event subscriptions */ int event_subscriptions; switch_event_node_t *event_nodes[SWITCH_EVENT_ALL]; - switch_event_types_t event_ids[SWITCH_EVENT_ALL]; + mod_amqp_events_t events[SWITCH_EVENT_ALL]; switch_event_node_t *eventNode; diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c b/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c index 91feec93d5..73cf09a354 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_connection.c @@ -203,7 +203,11 @@ switch_status_t mod_amqp_connection_create(mod_amqp_connection_t **conn, switch_ amqp_boolean_t ssl_verify_peer = 1; if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Connection missing name attribute\n%s\n", switch_xml_toxml(cfg, 1)); + char *str_tmp = switch_xml_toxml(cfg, 1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Connection missing name attribute\n%s\n", str_tmp); + switch_safe_free(str_tmp); + return SWITCH_STATUS_GENERR; } @@ -260,6 +264,7 @@ switch_status_t mod_amqp_connection_create(mod_amqp_connection_t **conn, switch_ new_con->ssl_verify_peer = ssl_verify_peer; *conn = new_con; + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c b/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c index d7741d3f41..303927285e 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c @@ -186,7 +186,8 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg) profile->name = switch_core_strdup(profile->pool, name); profile->running = 1; memset(profile->format_fields, 0, (MAX_ROUTING_KEY_FORMAT_FIELDS + 1) * sizeof(mod_amqp_keypart_t)); - profile->event_ids[0] = SWITCH_EVENT_ALL; + profile->events[0].id = SWITCH_EVENT_ALL; + profile->events[0].subclass = SWITCH_EVENT_SUBCLASS_ANY; profile->event_subscriptions = 1; profile->conn_root = NULL; profile->conn_active = NULL; @@ -269,7 +270,14 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Found %d subscriptions\n", profile->event_subscriptions); for (arg = 0; arg < profile->event_subscriptions; arg++) { - if (switch_name_event(argv[arg], &(profile->event_ids[arg])) != SWITCH_STATUS_SUCCESS) { + char *subclass = SWITCH_EVENT_SUBCLASS_ANY; + if ((subclass = strchr(argv[arg], '^'))) { + *subclass++ = '\0'; + } + + if (switch_name_event(argv[arg], &(profile->events[arg].id)) == SWITCH_STATUS_SUCCESS) { + profile->events[arg].subclass = subclass; + } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The switch event %s was not recognised.\n", argv[arg]); } } @@ -344,13 +352,13 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg) /* Subscribe events */ for (i = 0; i < profile->event_subscriptions; i++) { if (switch_event_bind_removable("AMQP", - profile->event_ids[i], - SWITCH_EVENT_SUBCLASS_ANY, + profile->events[i].id, + profile->events[i].subclass, mod_amqp_producer_event_handler, profile, &(profile->event_nodes[i])) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->event_ids[i]); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to event handler %d!\n",(int)profile->events[i].id); goto err; } } diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 1ebf5cb7fe..ac58ee8ed9 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -153,16 +153,18 @@ static switch_status_t load_config(switch_xml_t input_cfg) } if ((settings = switch_xml_child(cfg, "settings"))) { + for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); + char *val_no_whitespace = switch_strip_whitespace(val); if (!strcasecmp(var, "address")) { - set_global_dst_addrs(switch_strip_whitespace(val)); + set_global_dst_addrs(val_no_whitespace); } else if (!strcasecmp(var, "source_address")) { - set_global_src_addr(switch_strip_whitespace(val)); + set_global_src_addr(val_no_whitespace); } else if (!strcasecmp(var, "source_address_ipv6")) { - set_global_src_addr6(switch_strip_whitespace(val)); + set_global_src_addr6(val_no_whitespace); } else if (!strcasecmp(var, "bindings")) { set_global_bindings(val); } else if (!strcasecmp(var, "port")) { @@ -183,6 +185,8 @@ static switch_status_t load_config(switch_xml_t input_cfg) } else if (!strcasecmp(var, "loopback")) { globals.loopback = switch_true(val); } + + switch_safe_free(val_no_whitespace); } } @@ -190,6 +194,7 @@ static switch_status_t load_config(switch_xml_t input_cfg) if (globals.bindings) { + for (cur = globals.bindings; cur; count++) { switch_event_types_t type; @@ -293,13 +298,13 @@ static switch_status_t initialize_sockets(switch_xml_t input_cfg) char *host_string; char ipv6_first_octet[3]; - memset(&globals.dst_sockaddrs[globals.num_dst_addrs].sockaddr, 0, sizeof(dst_sockaddr_t)); - - if (globals.num_dst_addrs > MAX_DST_HOSTS) { + if (globals.num_dst_addrs >= MAX_DST_HOSTS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot add destination address: %s, exceeded maximum of %d\n", dst_hosts[i], MAX_DST_HOSTS); continue; } + memset(&globals.dst_sockaddrs[globals.num_dst_addrs], 0, sizeof(dst_sockaddr_t)); + if (switch_sockaddr_info_get(&globals.dst_sockaddrs[globals.num_dst_addrs].sockaddr, dst_hosts[i], SWITCH_UNSPEC, globals.port, 0, module_pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find address: %s\n", dst_hosts[i]); switch_goto_status(SWITCH_STATUS_TERM, fail); @@ -627,8 +632,8 @@ static void event_handler(switch_event_t *event) len = strlen(packet) + strlen((char *) MAGIC); #endif buf = malloc(len + 1); - memset(buf, 0, len + 1); switch_assert(buf); + memset(buf, 0, len + 1); #ifdef HAVE_OPENSSL if (globals.psk) { @@ -777,7 +782,11 @@ static switch_status_t process_packet(char* packet, size_t len) switch_url_decode(val); switch_snprintf(tmpname, sizeof(tmpname), "Orig-%s", var); switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, tmpname, val); - var = term + 1; + if (term) { + var = term + 1; + } else { + var = NULL; + } } else { /* This should be our magic packet, done processing incoming headers */ break; diff --git a/src/mod/formats/mod_imagick/mod_imagick.c b/src/mod/formats/mod_imagick/mod_imagick.c index ce789637cf..5c185a5e44 100644 --- a/src/mod/formats/mod_imagick/mod_imagick.c +++ b/src/mod/formats/mod_imagick/mod_imagick.c @@ -384,10 +384,11 @@ static switch_status_t read_page(pdf_file_context_t *context) if (ret == MagickFalse && context->exception->severity != UndefinedException) { CatchException(context->exception); free(storage); + return SWITCH_STATUS_FALSE; } - switch_img_from_raw(context->img, storage, SWITCH_IMG_FMT_BGR24, w, h); + switch_img_from_raw(&context->img, storage, SWITCH_IMG_FMT_BGR24, w, h); free(storage); } else { switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, image->columns, image->rows, 0); @@ -397,6 +398,8 @@ static switch_status_t read_page(pdf_file_context_t *context) if (ret == MagickFalse && context->exception->severity != UndefinedException) { CatchException(context->exception); + switch_img_free(&img); + return SWITCH_STATUS_FALSE; } diff --git a/src/mod/formats/mod_opusfile/mod_opusfile.c b/src/mod/formats/mod_opusfile/mod_opusfile.c index afd5f51267..1560142263 100644 --- a/src/mod/formats/mod_opusfile/mod_opusfile.c +++ b/src/mod/formats/mod_opusfile/mod_opusfile.c @@ -295,6 +295,7 @@ static switch_status_t switch_opusfile_open(switch_file_handle_t *handle, const context->of = op_open_file(path, &ret); if (!context->of) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[OGG/OPUS File] Error opening %s\n", path); + switch_thread_rwlock_unlock(context->rwlock); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/languages/mod_java/modjava.c b/src/mod/languages/mod_java/modjava.c index a334af302d..899fee2b60 100644 --- a/src/mod/languages/mod_java/modjava.c +++ b/src/mod/languages/mod_java/modjava.c @@ -294,64 +294,57 @@ static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount, static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm_control_t * vmControl) { - jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*); - switch_status_t status; + jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*); + switch_status_t status; char *derr = NULL; pJNI_CreateJavaVM = (jint (*)(JavaVM **, void **, void *))switch_dso_func_sym(javaVMHandle, "JNI_CreateJavaVM", &derr); - if (!derr) - { - JNIEnv *env; - JavaVMInitArgs initArgs; - jint res; + if (!derr) { + JNIEnv *env; + JavaVMInitArgs initArgs; + jint res; - memset(&initArgs, 0, sizeof(initArgs)); - initArgs.version = JNI_VERSION_1_4; - initArgs.nOptions = optionCount; - initArgs.options = options; - initArgs.ignoreUnrecognized = JNI_TRUE; + memset(&initArgs, 0, sizeof(initArgs)); + initArgs.version = JNI_VERSION_1_4; + initArgs.nOptions = optionCount; + initArgs.options = options; + initArgs.ignoreUnrecognized = JNI_TRUE; - res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs); - if (res == JNI_OK) - { - // call FindClass here already so that the Java VM executes the static - // initializer (@see org.freeswitch.Launcher) which loads the jni library - // so we can use jni functions right away (for example in the startup method) - launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher"); - if ( launcherClass == NULL ) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n"); - (*env)->ExceptionDescribe(env); - } + res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs); + if (res == JNI_OK) { + /* call FindClass here already so that the Java VM executes the static + initializer (@see org.freeswitch.Launcher) which loads the jni library + so we can use jni functions right away (for example in the startup method) */ - // store a global reference for use in the launch_java() function - launcherClass = (*env)->NewGlobalRef(env, launcherClass); - if ( launcherClass == NULL ) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - (*env)->ExceptionDescribe(env); - status = SWITCH_STATUS_FALSE; - } - else - { - status = SWITCH_STATUS_SUCCESS; - } + launcherClass = (*env)->FindClass(env, "org/freeswitch/Launcher"); + if ( launcherClass == NULL ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find 'org.freeswitch.Launcher' class!\n"); + (*env)->ExceptionDescribe(env); + } - (*javaVM)->DetachCurrentThread(javaVM); - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n"); - status = SWITCH_STATUS_FALSE; - } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n"); - status = SWITCH_STATUS_FALSE; - } - return status; + /* store a global reference for use in the launch_java() function */ + launcherClass = (*env)->NewGlobalRef(env, launcherClass); + if ( launcherClass == NULL ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + (*env)->ExceptionDescribe(env); + status = SWITCH_STATUS_FALSE; + } else { + status = SWITCH_STATUS_SUCCESS; + } + + (*javaVM)->DetachCurrentThread(javaVM); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n"); + status = SWITCH_STATUS_FALSE; + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n"); + switch_safe_free(derr); + status = SWITCH_STATUS_FALSE; + } + + return status; } SWITCH_MODULE_LOAD_FUNCTION(mod_java_load) diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index 5ea52357dd..1f8d6e017a 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -196,7 +196,7 @@ static switch_status_t en_say_general_count(switch_say_file_handle_t *sh, char * static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, switch_say_args_t *say_args) { - int32_t t = 0; + int64_t t = 0; switch_time_t target = 0, target_now = 0; switch_time_exp_t tm, tm_now; uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0; @@ -287,7 +287,7 @@ static switch_status_t en_say_time(switch_say_file_handle_t *sh, char *tosay, sw if (strchr(tosay, ':')) { switch_time_t tme = switch_str_time(tosay); - t = (int32_t) ((tme) / (int64_t) (1000000)); + t = (int64_t) ((tme) / (int64_t) (1000000)); target = switch_time_make(t, 0); target_now = switch_micro_time_now(); diff --git a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c index 6a8f2aac53..67181e26c4 100644 --- a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c +++ b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c @@ -210,13 +210,6 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con switch_uuid_format(uuid_str, &uuid); switch_snprintf(filename, sizeof(filename), "%s%s%s.tmp.xml", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str); - curl_handle = switch_curl_easy_init(); - headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded"); - - if (!strncasecmp(binding->url, "https", 5)) { - switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); - switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); - } memset(&config_data, 0, sizeof(config_data)); @@ -224,6 +217,14 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con config_data.max_bytes = binding->curl_max_bytes; if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { + curl_handle = switch_curl_easy_init(); + headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded"); + + if (!strncasecmp(binding->url, "https", 5)) { + switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); + switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); + } + if (!zstr(binding->cred)) { switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, binding->auth_scheme); switch_curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred); diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index 43e25b6f9e..8e49462d2c 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -614,7 +614,7 @@ abyss_bool websocket_hook(TSession *r) if (ret != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "handshake error %d\n", ret); - return FALSE; + goto err; } if (switch_event_bind_removable("websocket", SWITCH_EVENT_CUSTOM, "websocket::stophook", stop_hook_event_handler, wsh, &nodes[node_count++]) != SWITCH_STATUS_SUCCESS) { @@ -696,8 +696,11 @@ abyss_bool websocket_hook(TSession *r) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "wsh->down = %d, node_count = %d\n", wsh->down, node_count); switch_yield(2000); + while (--node_count >= 0) switch_event_unbind(&nodes[node_count]); + err: + ws_destroy(wsh); switch_safe_free(wsh); return FALSE; diff --git a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c index 63306c76a3..24c0270a57 100644 --- a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c +++ b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c @@ -176,6 +176,10 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con if (bytes > XML_SCGI_MAX_BYTES) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Data too big!\n"); len = -1; + if (expanded != (char*)buf) { + free(expanded); + } + break; } diff --git a/src/switch_core.c b/src/switch_core.c index 83db2fc0d9..cf2343482a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -3009,7 +3009,7 @@ SWITCH_DECLARE(switch_bool_t) switch_core_ready_outbound(void) return (switch_test_flag((&runtime), SCF_SHUTTING_DOWN) || switch_test_flag((&runtime), SCF_NO_NEW_OUTBOUND_SESSIONS)) ? SWITCH_FALSE : SWITCH_TRUE; } -void switch_core_sqldb_destroy() +void switch_core_sqldb_destroy(void) { if (switch_test_flag((&runtime), SCF_USE_SQL)) { switch_core_sqldb_stop(); diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 0754494ee3..912d5a5012 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -3057,7 +3057,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session uint32_t codec_ms = (int) (engine->read_frame.timestamp - engine->last_ts) / (engine->read_impl.samples_per_second / 1000); if (engine->last_seq && (int) (engine->read_frame.seq - engine->last_seq) > 1) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[%s]: Correcting calculated ptime value from [%d] to [%d] to compensate for [%d] lost packet(s). \n", is_vbr?"VBR":"CBR", codec_ms, codec_ms / (int) (engine->read_frame.seq - engine->last_seq), (int) (engine->read_frame.seq - engine->last_seq - 1)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[CBR]: Correcting calculated ptime value from [%d] to [%d] to compensate for [%d] lost packet(s). \n", codec_ms, codec_ms / (int) (engine->read_frame.seq - engine->last_seq), (int) (engine->read_frame.seq - engine->last_seq - 1)); codec_ms = codec_ms / (int) (engine->read_frame.seq - engine->last_seq); } @@ -3080,9 +3080,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session if (codec_ms > 120) { /* yeah right */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, - "[%s]: Your phone is trying to send timestamps that suggest an increment of %dms per packet\n" + "[CBR]: Your phone is trying to send timestamps that suggest an increment of %dms per packet\n" "That seems hard to believe so I am going to go on ahead and um ignore that, mmkay?\n", - is_vbr?"VBR":"CBR", (int) codec_ms); engine->check_frames = MAX_CODEC_CHECK_FRAMES; goto skip; @@ -3092,8 +3091,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session if (codec_ms != engine->cur_payload_map->codec_ms) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, - "[%s]: Asynchronous PTIME not supported, changing our end from %d to %d\n", - is_vbr?"VBR":"CBR", + "[CBR]: Asynchronous PTIME not supported, changing our end from %d to %d\n", (int) engine->cur_payload_map->codec_ms, (int) codec_ms ); @@ -3123,7 +3121,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session engine->last_ts) / (engine->read_impl.samples_per_second / 1000); if (engine->last_seq && (int) (engine->read_frame.seq - engine->last_seq) > 1) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[%s]: Correcting calculated ptime value from [%d] to [%d] to compensate for [%d] lost packet(s)\n", is_vbr?"VBR":"CBR", codec_ms, codec_ms / (int) (engine->read_frame.seq - engine->last_seq), (int) (engine->read_frame.seq - engine->last_seq - 1)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[VBR]: Correcting calculated ptime value from [%d] to [%d] to compensate for [%d] lost packet(s)\n", codec_ms, codec_ms / (int) (engine->read_frame.seq - engine->last_seq), (int) (engine->read_frame.seq - engine->last_seq - 1)); codec_ms = codec_ms / (int) (engine->read_frame.seq - engine->last_seq); } @@ -3142,8 +3140,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session if (codec_ms > 120) { /*will show too many times with packet loss*/ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG3, - "[%s]: Remote party is trying to send timestamps that suggest an increment of [%d] ms per packet, which is too high. Ignoring.\n", - is_vbr?"VBR":"CBR", + "[VBR]: Remote party is trying to send timestamps that suggest an increment of [%d] ms per packet, which is too high. Ignoring.\n", (int) codec_ms); engine->last_ts = engine->read_frame.timestamp; engine->last_seq = engine->read_frame.seq; @@ -3152,8 +3149,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session if (codec_ms != engine->cur_payload_map->codec_ms) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, - "[%s]: Packet size change detected. Remote PTIME changed from [%d] to [%d]\n", - is_vbr?"VBR":"CBR", + "[VBR]: Packet size change detected. Remote PTIME changed from [%d] to [%d]\n", (int) engine->cur_payload_map->codec_ms, (int) codec_ms ); @@ -6676,10 +6672,6 @@ SWITCH_DECLARE(void) switch_core_session_write_blank_video(switch_core_session_t if (!height) height = 288; if (!fps) fps = 15; - if (!(width && height && fps)) { - return; - } - fr.packet = buf; fr.packetlen = buflen; fr.data = buf + 12; @@ -12443,7 +12435,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_media_params(switch_core_sessi *val++ = '\0'; } - if (name && val) { + if (val) { if (!strcmp(name, "aspect")) { aspect = val; vid++; @@ -15864,7 +15856,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess if (!(switch_core_codec_ready(session->write_codec) && switch_core_codec_ready(frame->codec))) goto error; - if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) { + if (frame->codec && session->write_codec->implementation != frame->codec->implementation) { if (session->write_impl.codec_id == frame->codec->implementation->codec_id || session->write_impl.microseconds_per_packet != frame->codec->implementation->microseconds_per_packet) { ptime_mismatch = TRUE; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 44b653d9ce..a103a6e964 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -3005,7 +3005,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se { char *dp[25]; char *dpstr; - int argc, x, count = 0; + int argc, x; uint32_t stack_count = 0; switch_caller_profile_t *profile, *new_profile, *pp = NULL; switch_channel_t *channel = switch_core_session_get_channel(session); @@ -3059,8 +3059,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se continue; } - count++; - extension = dialplan_interface->hunt_function(session, dparg, new_profile); UNPROTECT_INTERFACE(dialplan_interface); diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 702ee6a79c..5a75aeb573 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -3181,6 +3181,8 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName if (!(ep = switch_loadable_module_get_endpoint_interface(argv[0]))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "EP ERROR\n"); + switch_xml_free(xml); + return 0; } diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 0d377f9c3e..dad3181c2a 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -3521,11 +3521,18 @@ SWITCH_DECLARE(switch_status_t) switch_img_to_raw(switch_image_t *src, void *des #endif } -SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height) +SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t **destP, void *src, switch_img_fmt_t fmt, int width, int height) { #ifdef SWITCH_HAVE_YUV uint32_t fourcc; int ret = -1; + switch_image_t *dest = NULL; + + if (!destP) { + return SWITCH_STATUS_FALSE; + } + + dest = *destP; fourcc = switch_img_fmt2fourcc(fmt); @@ -3574,6 +3581,8 @@ SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void * 0, fourcc); } + *destP = dest; + return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; #else return SWITCH_STATUS_FALSE; @@ -3586,10 +3595,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_ima switch_image_t *dest = NULL; int ret = 0; - if (destP) { - dest = *destP; + if (!destP) { + return SWITCH_STATUS_FALSE; } + dest = *destP; + switch_assert(width > 0); switch_assert(height > 0); @@ -3615,15 +3626,13 @@ SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_ima kFilterBox); } + *destP = dest; + if (ret != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scaling Error: ret: %d\n", ret); return SWITCH_STATUS_FALSE; } - if (destP) { - *destP = dest; - } - return SWITCH_STATUS_SUCCESS; #else return SWITCH_STATUS_FALSE; @@ -3637,10 +3646,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_mirror(switch_image_t *src, switch_im switch_image_t *dest = NULL; int ret = 0; - if (destP) { - dest = *destP; + if (!destP) { + return SWITCH_STATUS_FALSE; } + dest = *destP; + if (dest && src->fmt != dest->fmt) switch_img_free(&dest); if (!dest) dest = switch_img_alloc(NULL, src->fmt, src->d_w, src->d_h, 1); @@ -3660,15 +3671,13 @@ SWITCH_DECLARE(switch_status_t) switch_img_mirror(switch_image_t *src, switch_im } + *destP = dest; + if (ret != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Mirror Error: ret: %d\n", ret); return SWITCH_STATUS_FALSE; } - if (destP) { - *destP = dest; - } - return SWITCH_STATUS_SUCCESS; #else return SWITCH_STATUS_FALSE; diff --git a/src/switch_event.c b/src/switch_event.c index 843469bd72..be49f2fc14 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1909,6 +1909,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch data = (char *) malloc(2048); if (!data) { va_end(ap); + switch_xml_free(xml); + return NULL; } ret = vsnprintf(data, 2048, fmt, ap); @@ -1918,6 +1920,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch #ifndef HAVE_VASPRINTF free(data); #endif + switch_xml_free(xml); + return NULL; } } diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 6dfdcf7248..9a33b43340 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -546,6 +546,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_ping(switch_ivr_dmachine_t * } if (dmachine->pinging) { + switch_mutex_unlock(dmachine->mutex); return SWITCH_STATUS_BREAK; } @@ -2129,7 +2130,7 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data break; } - if (ep->eavesdropper && switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { + if (switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_video_frame(ep->eavesdropper, bug->video_ping_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error writing video to %s\n", switch_core_session_get_name(ep->eavesdropper)); ep->errs++; @@ -2177,10 +2178,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_pop_eavesdropper(switch_cor struct eavesdrop_pvt *ep = (struct eavesdrop_pvt *) switch_core_media_bug_get_user_data(bug); if (ep && ep->eavesdropper && ep->eavesdropper != session) { - switch_core_session_read_lock(ep->eavesdropper); - *sessionp = ep->eavesdropper; - switch_core_media_bug_set_flag(bug, SMBF_PRUNE); - status = SWITCH_STATUS_SUCCESS; + if (switch_core_session_read_lock(ep->eavesdropper) == SWITCH_STATUS_SUCCESS) { + *sessionp = ep->eavesdropper; + switch_core_media_bug_set_flag(bug, SMBF_PRUNE); + status = SWITCH_STATUS_SUCCESS; + } } } diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index f91fc2c69f..527058f70c 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -237,7 +237,7 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj) continue; } - if (switch_channel_media_up(b_channel)) { + if (read_frame && switch_channel_media_up(b_channel)) { if (switch_core_session_write_video_frame(vh->session_b, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { switch_cond_next(); continue; diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index f1e3e39de1..f23549713b 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -909,6 +909,9 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map return -1; } wrote = teletone_mux_tones(ts, map); + if (wrote <= 0) { + return -1; + } if (tto->channels != 1) { if (tto->mux_buflen < wrote * 2 * tto->channels) { @@ -3215,6 +3218,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess l_session = NULL; } + switch_channel_set_variable(oglobals.originate_status[i].peer_channel, "originate_endpoint", chan_type); switch_channel_execute_on(oglobals.originate_status[i].peer_channel, SWITCH_CHANNEL_EXECUTE_ON_ORIGINATE_VARIABLE); switch_channel_api_on(oglobals.originate_status[i].peer_channel, SWITCH_CHANNEL_API_ON_ORIGINATE_VARIABLE); } diff --git a/src/switch_nat.c b/src/switch_nat.c index f6b9bc553b..a1620b4bfd 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -506,7 +506,7 @@ static switch_status_t switch_nat_add_mapping_upnp(switch_port_t port, switch_na if (r == UPNPCOMMAND_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mapped public port %s protocol %s to localport %s\n", port_str, - (proto == SWITCH_NAT_TCP) ? "TCP" : (proto == SWITCH_NAT_UDP ? "UDP" : "UNKNOWN"), port_str); + (proto == SWITCH_NAT_TCP) ? "TCP" : "UDP", port_str); status = SWITCH_STATUS_SUCCESS; } @@ -566,7 +566,7 @@ static switch_status_t switch_nat_del_mapping_upnp(switch_port_t port, switch_na if (r == UPNPCOMMAND_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unmapped public port %s protocol %s to localport %s\n", port_str, - (proto == SWITCH_NAT_TCP) ? "TCP" : (proto == SWITCH_NAT_UDP ? "UDP" : "UNKNOWN"), port_str); + (proto == SWITCH_NAT_TCP) ? "TCP" : "UDP", port_str); status = SWITCH_STATUS_SUCCESS; } return status; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 17f3e66f8c..ad9f8eef1c 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1277,7 +1277,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d } - if (ice->ice_params && ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && + if (ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && !strcasecmp(ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type, "relay")) { do_adj++; } @@ -3010,7 +3010,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_ rtp_session->dtls->sock_output = rtp_session->sock_output; if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { - switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool); + status = switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool); } } @@ -3529,9 +3529,13 @@ SWITCH_DECLARE(dtls_state_t) switch_rtp_dtls_state(switch_rtp_t *rtp_session, dt { dtls_state_t s = DS_OFF; + if (!rtp_session) { + return s; + } + switch_mutex_lock(rtp_session->ice_mutex); - if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) { + if (!rtp_session->dtls && !rtp_session->rtcp_dtls) { s = DS_OFF; goto done; } @@ -3556,9 +3560,13 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_del_dtls(switch_rtp_t *rtp_session, d { switch_status_t status = SWITCH_STATUS_SUCCESS; + if (!rtp_session) { + return SWITCH_STATUS_FALSE; + } + switch_mutex_lock(rtp_session->ice_mutex); - if (!rtp_session || (!rtp_session->dtls && !rtp_session->rtcp_dtls)) { + if (!rtp_session->dtls && !rtp_session->rtcp_dtls) { switch_goto_status(SWITCH_STATUS_FALSE, done); } @@ -6967,13 +6975,10 @@ static void check_timeout(switch_rtp_t *rtp_session) elapsed, rtp_session->media_timeout); if (elapsed > rtp_session->media_timeout) { - - if (rtp_session->session) { switch_channel_t *channel = switch_core_session_get_channel(rtp_session->session); switch_channel_execute_on(channel, "execute_on_media_timeout"); switch_channel_hangup(channel, SWITCH_CAUSE_MEDIA_TIMEOUT); - } } } diff --git a/src/switch_xml.c b/src/switch_xml.c index c43a530252..80b7553907 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1638,11 +1638,25 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file) if ((fd = open(file, O_RDONLY, 0)) > -1) { fstat(fd, &st); - if (!st.st_size) goto error; + if (!st.st_size) { + close(fd); + goto error; + } + m = switch_must_malloc(st.st_size); - if (!(0<(l = read(fd, m, st.st_size)))) goto error; - if (!(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) goto error; + if (!(0 < (l = read(fd, m, st.st_size)))) { + free(m); + close(fd); + goto error; + } + + if (!(root = (switch_xml_root_t)switch_xml_parse_str((char*)m, l))) { + free(m); + close(fd); + goto error; + } + root->dynamic = 1; close(fd); return &root->xml; diff --git a/src/switch_xml_config.c b/src/switch_xml_config.c index 6d67ccdad4..a208a6168e 100644 --- a/src/switch_xml_config.c +++ b/src/switch_xml_config.c @@ -457,7 +457,7 @@ SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instruc char **ptr = (char **) item->ptr; switch_xml_config_string_options_t *string_options = (switch_xml_config_string_options_t *) item->data; /* if (using_strdup) */ - if (string_options && !string_options->pool && !string_options->length) { + if (!string_options || (!string_options->pool && !string_options->length)) { switch_safe_free(*ptr); } }