diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ef6e49a2a5..caffb92567 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -830,7 +830,8 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, su_free(nua_handle_home(nh), tmp); cur_len = cur_len + tmp_len + 2; } - switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "Call-Info", hold); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Call-Info", hold); + switch_safe_free(hold); } switch_event_fire(&s_event); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "dispatched freeswitch event for message-summary NOTIFY\n"); @@ -1883,7 +1884,7 @@ static void our_sofia_event_callback(nua_event_t event, case nua_i_refer: if (session) { sofia_handle_sip_i_refer(nua, profile, nh, session, sip, de, tags); - } else { + } else if (sip) { const char *req_user = NULL, *req_host = NULL, *action = NULL, *ref_by_user = NULL, *ref_to_user = NULL, *ref_to_host = NULL; char *refer_to = NULL, *referred_by = NULL, *method = NULL, *full_url = NULL; char *params = NULL, *iparams = NULL; @@ -1923,6 +1924,7 @@ static void our_sofia_event_callback(nua_event_t event, if (!method) { method = strdup("INVITE"); + switch_assert(method); } if (!strcasecmp(method, "INVITE")) { @@ -1974,7 +1976,7 @@ static void our_sofia_event_callback(nua_event_t event, - if (sip) { + { char *sql; sofia_nat_parse_t np = { { 0 } }; char *contact_str; @@ -1988,7 +1990,7 @@ static void our_sofia_event_callback(nua_event_t event, np.fs_path = 1; contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, &np); - call_id = sip->sip_call_id->i_id; + call_id = sip->sip_call_id ? sip->sip_call_id->i_id : ""; full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from); full_to = sip_header_as_string(nh->nh_home, (void *) sip->sip_to); full_via = sip_header_as_string(nh->nh_home, (void *) sip->sip_via); @@ -7964,6 +7966,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, case nua_callstate_early: if (answer_recv) { uint8_t match = 0; + switch_assert(tech_pvt); sofia_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA); switch_channel_mark_pre_answered(channel); sofia_set_flag(tech_pvt, TFLAG_SDP); @@ -8046,7 +8049,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_TRUE); if (sofia_media_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); - status = SWITCH_STATUS_FALSE; switch_core_session_rwunlock(other_session); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); goto done; @@ -8057,7 +8059,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (!switch_core_media_ready(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO)) { switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_FALSE); - if ((status = switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0)) != SWITCH_STATUS_SUCCESS) { + if (switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0) != SWITCH_STATUS_SUCCESS) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_core_session_rwunlock(other_session); goto done; @@ -8152,7 +8154,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Re-INVITE to a no-media channel that is not in a bridge.\n"); - is_ok = 0; switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } goto done; @@ -9269,7 +9270,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t } else { /* the other channel is on a different box, we have to go find them */ if (exten && (br_a = switch_channel_get_partner_uuid(channel_a))) { switch_core_session_t *a_session; - switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_t *channel; if ((a_session = switch_core_session_locate(br_a))) { const char *port = NULL; @@ -9300,7 +9301,9 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-host", refer_to->r_url->url_host); switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-params", refer_to->r_url->url_params ? refer_to->r_url->url_params : ""); switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-to-headers", refer_to->r_url->url_headers ? refer_to->r_url->url_headers : ""); - switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "replaces-call-id", replaces->rp_call_id); + if (replaces) { + switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "replaces-call-id", replaces->rp_call_id); + } switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-from-channel-id", switch_core_session_get_uuid(session)); switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "refer-for-channel-id", br_a); @@ -10270,7 +10273,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia profile->ib_calls++; - if (sip->sip_payload && sip->sip_payload->pl_data) { + if (sip && sip->sip_payload && sip->sip_payload->pl_data) { r_sdp = sip->sip_payload->pl_data; } @@ -11712,6 +11715,7 @@ void sofia_handle_sip_i_options(int status, (sess_count >= sess_max || !sofia_test_pflag(profile, PFLAG_RUNNING) || !switch_core_ready_inbound())) { nua_respond(nh, 503, "Maximum Calls In Progress", NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); } else { + switch_assert(sip); nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_IF(sip->sip_record_route, SIPTAG_RECORD_ROUTE(sip->sip_record_route)), TAG_END()); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index b5ac9c51ab..ec5a10ae9a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1174,8 +1174,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) url = tech_pvt->dest; } - url_str = url; - if (!tech_pvt->from_str) { const char *sipip; const char *format; diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 767ec8c8e0..2115d6374d 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -2111,11 +2111,11 @@ static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char * #define SOFIA_PRESENCE_ROLLOVER_YEAR (86400 * 365 * SOFIA_PRESENCE_COLLISION_DELTA) static uint32_t check_presence_epoch(void) { - struct tm tm = {0}; time_t now = switch_epoch_time_now(NULL); uint32_t callsequence = (uint32_t)((now - mod_sofia_globals.presence_epoch) * SOFIA_PRESENCE_COLLISION_DELTA); if (!mod_sofia_globals.presence_year || callsequence >= SOFIA_PRESENCE_ROLLOVER_YEAR) { + struct tm tm; switch_mutex_lock(mod_sofia_globals.mutex); tm = *(localtime(&now)); @@ -2181,7 +2181,6 @@ static void _send_presence_notify(sofia_profile_t *profile, sip_cseq_t *cseq = NULL; uint32_t callsequence; uint32_t now = (uint32_t) switch_epoch_time_now(NULL); - char *our_contact = profile->url, *our_contact_dup = NULL; sofia_destination_t *dst = NULL; char *contact_str, *contact, *user_via = NULL, *send_contact = NULL; @@ -2229,13 +2228,7 @@ static void _send_presence_notify(sofia_profile_t *profile, tp = "udp"; } - if (!switch_stristr("transport=", our_contact)) { - our_contact_dup = switch_mprintf("<%s;transport=%s>", our_contact, tp); - our_contact = our_contact_dup; - } - - - if (!zstr(remote_ip) && sofia_glue_check_nat(profile, remote_ip)) { + if (!zstr(remote_ip) && sofia_glue_check_nat(profile, remote_ip)) { sofia_transport_t transport = sofia_glue_str2transport(tp); switch (transport) { @@ -2372,7 +2365,6 @@ static void _send_presence_notify(sofia_profile_t *profile, switch_safe_free(user_via); switch_safe_free(o_contact_dup); switch_safe_free(send_contact); - switch_safe_free(our_contact_dup); switch_safe_free(path); } @@ -4029,7 +4021,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, if (status < 200) { char *sticky = NULL; - char *contactstr = profile->url, *cs = NULL; + char *contactstr, *cs = NULL; char *p = NULL, *new_contactstr = NULL; sofia_transport_t transport; diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 9b8afe745c..5f1e555c18 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -3410,7 +3410,10 @@ switch_status_t sofia_reg_add_gateway(sofia_profile_t *profile, const char *key, if (!switch_core_hash_find(mod_sofia_globals.gateway_hash, key) && !switch_core_hash_find(mod_sofia_globals.gateway_hash, pkey)) { status = switch_core_hash_insert(mod_sofia_globals.gateway_hash, key, gateway); - status = switch_core_hash_insert(mod_sofia_globals.gateway_hash, pkey, gateway); + status |= switch_core_hash_insert(mod_sofia_globals.gateway_hash, pkey, gateway); + if (status != SWITCH_STATUS_SUCCESS) { + status = SWITCH_STATUS_FALSE; + } } else { status = SWITCH_STATUS_FALSE; }