From d4547e6151c420c4e579d52e47d2c10d47958dc6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 1 Aug 2020 02:09:50 +0400 Subject: [PATCH 1/2] [Sofia-Sip] Add various accessors and helpers to nua. --- libs/sofia-sip/.update | 2 +- libs/sofia-sip/libsofia-sip-ua/nua/nua.c | 63 ++++++++++++++++++- .../libsofia-sip-ua/nua/sofia-sip/nua.h | 14 +++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index f2ecef0016..67ed62e0fe 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Tue May 12 18:04:14 UTC 2020 +Fri Jul 31 17:46:57 CDT 2020 diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua.c index 451cebb134..fdeac3cad9 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua.c @@ -234,10 +234,14 @@ void nua_destroy(nua_t *nua) #if HAVE_SMIME /* Start NRC Boston */ sm_destroy(nua->sm); #endif /* End NRC Boston */ - su_home_unref(nua->nua_home); + nua_unref(nua); } } +void nua_unref(nua_t *nua) { + if (nua) su_home_unref(nua->nua_home); +} + /** Fetch callback context from nua. * * @param nua Pointer to @nua stack object @@ -1089,3 +1093,60 @@ nua_handle_t *nua_handle_by_call_id(nua_t *nua, const char *call_id) } return NULL; } + +/** Get leg from dialog. */ +const nta_leg_t *nua_get_dialog_state_leg(nua_handle_t *nh) +{ + if (nh && nh->nh_ds) + return nh->nh_ds->ds_leg; + else + return NULL; +} + +/** Get su_home_t from nua handle. */ +su_home_t *nua_handle_get_home(nua_handle_t *nh) +{ + if (nh && nh->nh_home) + return nh->nh_home; + else + return NULL; +} + +/** Get su_home_t from nua. */ +su_home_t *nua_get_home(nua_t *nua) +{ + if (nua && nua->nua_home) + return nua->nua_home; + else + return NULL; +} + +/** Get nta_agent_t from nua. */ +nta_agent_t *nua_get_agent(nua_t *nua) +{ + if (nua && nua->nua_nta) + return nua->nua_nta; + else + return NULL; +} + +/** Set has invite of a nua handle */ +void nua_handle_set_has_invite(nua_handle_t *nh, unsigned val) +{ + if (nh) + nh->nh_has_invite = val; +} + +/** Check if nua handle is destroyed */ +unsigned nua_handle_is_destroyed(nua_handle_t *nh) +{ + assert(nh); + return nh->nh_destroyed; +} + +void nua_handle_dialog_usage_set_refresh_range(nua_handle_t *nh, + unsigned min, unsigned max) { + if (nh && nh->nh_ds && nh->nh_ds->ds_usage) { + nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, min, max); + } +} \ No newline at end of file diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua.h b/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua.h index 37b7667792..5a698359cb 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua.h @@ -47,6 +47,10 @@ #include #endif +#ifndef NTA_H +#include +#endif + #ifndef NUA_TAG_H #include #endif @@ -386,6 +390,16 @@ SOFIAPUBFUN nua_handle_t *nua_handle_by_replaces(nua_t *nua, nua_handle_t *nua_handle_by_call_id(nua_t *nua, const char *call_id); +SOFIAPUBFUN const nta_leg_t *nua_get_dialog_state_leg(nua_handle_t *nh); +SOFIAPUBFUN su_home_t *nua_handle_get_home(nua_handle_t *nh); +SOFIAPUBFUN void nua_unref(nua_t *nua); +SOFIAPUBFUN su_home_t *nua_get_home(nua_t *nua); +SOFIAPUBFUN nta_agent_t *nua_get_agent(nua_t *nua); +SOFIAPUBFUN void nua_handle_set_has_invite(nua_handle_t *nh, unsigned val); +SOFIAPUBFUN unsigned nua_handle_is_destroyed(nua_handle_t *nh); +SOFIAPUBFUN void nua_handle_dialog_usage_set_refresh_range(nua_handle_t *nh, + unsigned min, unsigned max); + SOFIA_END_DECLS #endif From b06036e30fcdf6b2c9b57505c3581f7671d0bbc1 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 1 Aug 2020 02:52:19 +0400 Subject: [PATCH 2/2] [mod_sofia] Cleanup usage of sofia-sip headers. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 +- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 - src/mod/endpoints/mod_sofia/sip-dig.c | 3 - src/mod/endpoints/mod_sofia/sofia.c | 132 +++++++++---------- src/mod/endpoints/mod_sofia/sofia_glue.c | 20 +-- src/mod/endpoints/mod_sofia/sofia_presence.c | 54 ++++---- src/mod/endpoints/mod_sofia/sofia_reg.c | 18 +-- 7 files changed, 114 insertions(+), 118 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 84da642aff..e236b09a38 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2456,7 +2456,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi /* Set sip_to_tag to local tag for inbound channels. */ if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { const char* to_tag = ""; - to_tag = switch_str_nil(nta_leg_get_tag(tech_pvt->nh->nh_ds->ds_leg)); + to_tag = switch_str_nil(nta_leg_get_tag(nua_get_dialog_state_leg(tech_pvt->nh))); if(to_tag) { switch_channel_set_variable(channel, "sip_to_tag", to_tag); } @@ -5251,7 +5251,7 @@ static int notify_csta_callback(void *pArg, int argc, char **argv, char **column //nh = nua_handle(profile->nua, NULL, NUTAG_URL(dst->contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END()); nh = nua_handle(profile->nua, NULL, NUTAG_URL(dst->contact), SIPTAG_FROM_STR(full_to), SIPTAG_TO_STR(full_from), SIPTAG_CONTACT_STR(profile->url), TAG_END()); - cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY); + cseq = sip_cseq_create(nua_handle_get_home(nh), callsequence, SIP_METHOD_NOTIFY); nua_handle_bind(nh, &mod_sofia_globals.destroy_private); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 05e50c952f..3249533730 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -142,7 +142,6 @@ typedef struct private_object private_object_t; #include #include #include -#include "nua_stack.h" #include "sofia-sip/msg_parser.h" #include "sofia-sip/sip_parser.h" #include "sofia-sip/tport_tag.h" diff --git a/src/mod/endpoints/mod_sofia/sip-dig.c b/src/mod/endpoints/mod_sofia/sip-dig.c index 2c87f231d3..2d74eb66f6 100644 --- a/src/mod/endpoints/mod_sofia/sip-dig.c +++ b/src/mod/endpoints/mod_sofia/sip-dig.c @@ -133,9 +133,6 @@ #include "switch.h" -#ifndef WIN32 -#include "../../config.h" -#endif #include "sofia-sip/su.h" diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index a3344fc323..bceec9d906 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -237,9 +237,9 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, SWITCH_STANDARD_STREAM(stream); for (rp = sip->sip_route; rp; rp = rp->r_next) { - char *route = sip_header_as_string(nh->nh_home, (void *) rp); + char *route = sip_header_as_string(nua_handle_get_home(nh), (void *) rp); stream.write_function(&stream, x == 0 ? "%s" : ",%s", route); - su_free(nh->nh_home, route); + su_free(nua_handle_get_home(nh), route); x++; } switch_channel_set_variable(channel, "sip_full_route", stream.data); @@ -249,9 +249,9 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { if (sip->sip_contact) { - char *c = sip_header_as_string(nh->nh_home, (void *) sip->sip_contact); + char *c = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_contact); switch_channel_set_variable(channel, "sip_recover_contact", c); - su_free(nh->nh_home, c); + su_free(nua_handle_get_home(nh), c); } } @@ -267,7 +267,7 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, SWITCH_STANDARD_STREAM(reverse_stream); for(rrp = sip->sip_record_route; rrp; rrp = rrp->r_next) { - char *rr = sip_header_as_string(nh->nh_home, (void *) rrp); + char *rr = sip_header_as_string(nua_handle_get_home(nh), (void *) rrp); forward_stream.write_function(&forward_stream, x == 0 ? "%s" : ",%s", rr); tmp[y++] = rr; if (y == 127) break; @@ -280,7 +280,7 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, while(y >= 0) { reverse_stream.write_function(&reverse_stream, x == 0 ? "%s" : ",%s", tmp[y]); - su_free(nh->nh_home, tmp[y]); + su_free(nua_handle_get_home(nh), tmp[y]); y--; x++; } @@ -305,10 +305,10 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, SWITCH_STANDARD_STREAM(stream); for(vp = sip->sip_via; vp; vp = vp->v_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); stream.write_function(&stream, x == 0 ? "%s" : ",%s", v); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); x++; } @@ -330,9 +330,9 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, switch_channel_set_variable(channel, "sip_from_display", p); } if (p != sip->sip_from->a_display) free(p); - if ((full = sip_header_as_string(nh->nh_home, (void *) sip->sip_from))) { + if ((full = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_from))) { switch_channel_set_variable(channel, "sip_full_from", full); - su_free(nh->nh_home, full); + su_free(nua_handle_get_home(nh), full); } } @@ -345,9 +345,9 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, if (p != sip->sip_to->a_display) free(p); - if ((full = sip_header_as_string(nh->nh_home, (void *) sip->sip_to))) { + if ((full = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_to))) { switch_channel_set_variable(channel, "sip_full_to", full); - su_free(nh->nh_home, full); + su_free(nua_handle_get_home(nh), full); } } @@ -398,9 +398,9 @@ static void sofia_add_invite_header_to_chanvars(switch_channel_t *channel, nua_h if (sip_header) { char *full; - if ((full = sip_header_as_string(nh->nh_home, sip_header))) { + if ((full = sip_header_as_string(nua_handle_get_home(nh), sip_header))) { switch_channel_set_variable(channel, var, full); - su_free(nh->nh_home, full); + su_free(nua_handle_get_home(nh), full); } } } @@ -464,99 +464,99 @@ static void sofia_parse_all_invite_headers(sip_t const *sip, switch_core_session if (sip->sip_via) { sip_via_t *vp; for (vp = sip->sip_via; vp; vp = vp->v_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_via", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if (sip->sip_record_route) { sip_record_route_t *rrp; for (rrp = sip->sip_record_route; rrp; rrp = rrp->r_next) { - char *rr = sip_header_as_string(nh->nh_home, (void *) rrp); + char *rr = sip_header_as_string(nua_handle_get_home(nh), (void *) rrp); switch_channel_add_variable_var_check(channel, "sip_i_record_route", rr, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, rr); + su_free(nua_handle_get_home(nh), rr); } } if (sip->sip_proxy_authorization) { sip_proxy_authorization_t *vp; for (vp = sip->sip_proxy_authorization; vp; vp = vp->au_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_proxy_authorization", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if (sip->sip_call_info) { sip_call_info_t *vp; for (vp = sip->sip_call_info; vp; vp = vp->ci_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_call_info", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if (sip->sip_accept) { sip_accept_t *vp; for (vp = sip->sip_accept; vp; vp = vp->ac_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_accept", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if (sip->sip_authorization) { sip_authorization_t *vp; for (vp = sip->sip_authorization; vp; vp = vp->au_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_authorization", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if ((alert_info = sip_alert_info(sip))) { sip_alert_info_t *vp; for (vp = alert_info; vp; vp = vp->ai_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_alert_info", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if ((passerted = sip_p_asserted_identity(sip))) { sip_p_asserted_identity_t *vp; for (vp = passerted; vp; vp = vp->paid_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_p_asserted_identity", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if ((ppreferred = sip_p_preferred_identity(sip))) { sip_p_preferred_identity_t *vp; for (vp = ppreferred; vp; vp = vp->ppid_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_p_preferred_identity", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if ((rpid = sip_remote_party_id(sip))) { sip_remote_party_id_t *vp; for (vp = rpid; vp; vp = vp->rpid_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_remote_party_id", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } if ((reply_to = sip_reply_to(sip))) { sip_reply_to_t *vp; for (vp = reply_to; vp; vp = vp->rplyto_next) { - char *v = sip_header_as_string(nh->nh_home, (void *) vp); + char *v = sip_header_as_string(nua_handle_get_home(nh), (void *) vp); switch_channel_add_variable_var_check(channel, "sip_i_reply_to", v, SWITCH_FALSE, SWITCH_STACK_PUSH); - su_free(nh->nh_home, v); + su_free(nua_handle_get_home(nh), v); } } @@ -1031,7 +1031,7 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status, call_info = switch_channel_get_variable(channel, "presence_call_info_full"); if (sip->sip_reason) { - char *reason_header = sip_header_as_string(nh->nh_home, (void *) sip->sip_reason); + char *reason_header = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_reason); if (!zstr(reason_header)) { switch_channel_set_variable(channel, "sip_reason", reason_header); @@ -1641,7 +1641,7 @@ static void our_sofia_event_callback(nua_event_t event, if (sip && sip->sip_payload && sip->sip_payload->pl_data) { if (sip->sip_payload->pl_len != strlen(sip->sip_payload->pl_data)) { - sip->sip_payload->pl_data = su_strndup(nh->nh_home, sip->sip_payload->pl_data, sip->sip_payload->pl_len); + sip->sip_payload->pl_data = su_strndup(nua_handle_get_home(nh), sip->sip_payload->pl_data, sip->sip_payload->pl_len); } } @@ -1669,7 +1669,7 @@ static void our_sofia_event_callback(nua_event_t event, switch_channel_set_variable(channel, "sip_invite_failure_phrase", "CANCEL"); if (sip->sip_reason) { - char *reason_header = sip_header_as_string(nh->nh_home, (void *) sip->sip_reason); + char *reason_header = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_reason); if (!zstr(reason_header)) { switch_channel_set_variable(channel, "sip_reason", reason_header); @@ -1997,11 +1997,11 @@ static void our_sofia_event_callback(nua_event_t event, contact_str = sofia_glue_gen_contact_str(profile, sip, nh, de, &np); 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); + full_from = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_from); + full_to = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_to); + full_via = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_via); - full_agent = sip_header_as_string(nh->nh_home, (void *) sip->sip_user_agent); + full_agent = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_user_agent); switch_stun_random_string(to_tag, 12, NULL); @@ -2048,7 +2048,7 @@ static void our_sofia_event_callback(nua_event_t event, sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); - sip_to_tag(nh->nh_home, sip->sip_to, to_tag); + sip_to_tag(nua_handle_get_home(nh), sip->sip_to, to_tag); } nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_TO(sip->sip_to), NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END()); @@ -2271,14 +2271,14 @@ void sofia_process_dispatch_event(sofia_dispatch_event_t **dep) de->nh, sofia_private, de->sip, de, (tagi_t *) de->data->e_tags); nua_destroy_event(de->event); - su_free(nh->nh_home, de); + su_free(nua_handle_get_home(nh), de); switch_mutex_lock(profile->flag_mutex); profile->queued_events--; switch_mutex_unlock(profile->flag_mutex); nua_handle_unref(nh); - nua_stack_unref(nua); + nua_unref(nua); } @@ -2503,20 +2503,20 @@ void sofia_event_callback(nua_event_t event, profile->queued_events++; switch_mutex_unlock(profile->flag_mutex); - de = su_alloc(nh->nh_home, sizeof(*de)); + de = su_alloc(nua_handle_get_home(nh), sizeof(*de)); memset(de, 0, sizeof(*de)); nua_save_event(nua, de->event); de->nh = nua_handle_ref(nh); de->data = nua_event_data(de->event); de->sip = sip_object(de->data->e_msg); de->profile = profile; - de->nua = nua_stack_ref(nua); + de->nua = (nua_t *)su_home_ref(nua_get_home(nua)); if (event == nua_i_invite && !sofia_private) { switch_core_session_t *session; private_object_t *tech_pvt = NULL; - if (!(sofia_private = su_alloc(nh->nh_home, sizeof(*sofia_private)))) { + if (!(sofia_private = su_alloc(nua_handle_get_home(nh), sizeof(*sofia_private)))) { abort(); } @@ -2563,14 +2563,14 @@ void sofia_event_callback(nua_event_t event, if (!sip || !sip->sip_call_id || zstr(sip->sip_call_id->i_id)) { nua_respond(nh, 503, "INVALID INVITE", TAG_END()); nua_destroy_event(de->event); - su_free(nh->nh_home, de); + su_free(nua_handle_get_home(nh), de); switch_mutex_lock(profile->flag_mutex); profile->queued_events--; switch_mutex_unlock(profile->flag_mutex); nua_handle_unref(nh); - nua_stack_unref(nua); + nua_unref(nua); goto end; } @@ -2601,14 +2601,14 @@ void sofia_event_callback(nua_event_t event, } else { nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); nua_destroy_event(de->event); - su_free(nh->nh_home, de); + su_free(nua_handle_get_home(nh), de); switch_mutex_lock(profile->flag_mutex); profile->queued_events--; switch_mutex_unlock(profile->flag_mutex); nua_handle_unref(nh); - nua_stack_unref(nua); + nua_unref(nua); goto end; } @@ -3326,7 +3326,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name); if (sofia_test_pflag(profile, PFLAG_AUTO_ASSIGN_PORT) || sofia_test_pflag(profile, PFLAG_AUTO_ASSIGN_TLS_PORT)) { - sip_via_t *vias = nta_agent_via(profile->nua->nua_nta); + sip_via_t *vias = nta_agent_via(nua_get_agent(profile->nua)); sip_via_t *via = NULL; for (via = vias; via; via = via->v_next) { @@ -9620,9 +9620,9 @@ switch_status_t sofia_proxy_sip_i_message(nua_t *nua, sofia_profile_t *profile, } nua_message(other_tech_pvt->nh, - TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(su_strdup(other_tech_pvt->nh->nh_home, ct))), + TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(su_strdup(nua_handle_get_home(other_tech_pvt->nh), ct))), TAG_IF(!zstr(other_tech_pvt->user_via), SIPTAG_VIA_STR(other_tech_pvt->user_via)), - TAG_IF(pl, SIPTAG_PAYLOAD_STR(su_strdup(other_tech_pvt->nh->nh_home, pl))), + TAG_IF(pl, SIPTAG_PAYLOAD_STR(su_strdup(nua_handle_get_home(other_tech_pvt->nh), pl))), TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)), TAG_END()); } @@ -9670,9 +9670,9 @@ switch_status_t sofia_proxy_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua } nua_info(other_tech_pvt->nh, - TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(su_strdup(other_tech_pvt->nh->nh_home, ct))), + TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(su_strdup(nua_handle_get_home(other_tech_pvt->nh), ct))), TAG_IF(!zstr(other_tech_pvt->user_via), SIPTAG_VIA_STR(other_tech_pvt->user_via)), - TAG_IF(pl, SIPTAG_PAYLOAD_STR(su_strdup(other_tech_pvt->nh->nh_home, pl))), + TAG_IF(pl, SIPTAG_PAYLOAD_STR(su_strdup(nua_handle_get_home(other_tech_pvt->nh), pl))), TAG_IF(!zstr(session_id_header), SIPTAG_HEADER_STR(session_id_header)), TAG_END()); } @@ -10696,7 +10696,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia if ((rpid = sip_remote_party_id(sip))) { if (rpid->rpid_url->url_user) { - char *full_rpid_header = sip_header_as_string(nh->nh_home, (void *) rpid); + char *full_rpid_header = sip_header_as_string(nua_handle_get_home(nh), (void *) rpid); from_user = rpid->rpid_url->url_user; if (!zstr(full_rpid_header)) { switch_channel_set_variable(channel, "sip_Remote-Party-ID", full_rpid_header); @@ -10712,7 +10712,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia if ((passerted = sip_p_asserted_identity(sip))) { if (passerted->paid_url->url_user) { - char *full_paid_header = sip_header_as_string(nh->nh_home, (void *) passerted); + char *full_paid_header = sip_header_as_string(nua_handle_get_home(nh), (void *) passerted); //char *full_paid_header = (char *)(passerted->paid_common->h_data); from_user = passerted->paid_url->url_user; if (!zstr(full_paid_header)) { @@ -10735,7 +10735,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia if ((ppreferred = sip_p_preferred_identity(sip))) { if (ppreferred->ppid_url->url_user) { - char *full_ppid_header = sip_header_as_string(nh->nh_home, (void *) ppreferred); + char *full_ppid_header = sip_header_as_string(nua_handle_get_home(nh), (void *) ppreferred); from_user = ppreferred->ppid_url->url_user; if (!zstr(full_ppid_header)) { switch_channel_set_variable(channel, "sip_P-Preferred-Identity", full_ppid_header); @@ -11024,13 +11024,13 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia } if ((alert_info = sip_alert_info(sip))) { - char *tmp = sip_header_as_string(nh->nh_home, (void *) alert_info); + char *tmp = sip_header_as_string(nua_handle_get_home(nh), (void *) alert_info); switch_channel_set_variable(channel, "alert_info", tmp); - su_free(nh->nh_home, tmp); + su_free(nua_handle_get_home(nh), tmp); } if ((call_info = sip_call_info(sip))) { - call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info); + call_info_str = sip_header_as_string(nua_handle_get_home(nh), (void *) call_info); if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE) && switch_stristr("appearance", call_info_str)) { char *p; @@ -11051,7 +11051,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia call_info = call_info->ci_next; while (call_info) { - call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info); + call_info_str = sip_header_as_string(nua_handle_get_home(nh), (void *) call_info); switch_channel_add_variable_var_check(channel, "sip_call_info", call_info_str, SWITCH_FALSE, SWITCH_STACK_PUSH); call_info = call_info->ci_next; } @@ -11304,7 +11304,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia } if ((privacy = sip_privacy(sip))) { - char *full_priv_header = sip_header_as_string(nh->nh_home, (void *) privacy); + char *full_priv_header = sip_header_as_string(nua_handle_get_home(nh), (void *) privacy); if (!zstr(full_priv_header)) { switch_channel_set_variable(channel, "sip_Privacy", full_priv_header); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index a412f25cd3..27171890dd 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -475,7 +475,7 @@ void sofia_glue_store_session_id(switch_core_session_t *session, sofia_profile_t struct private_object *tech_pvt = switch_core_session_get_private(session); switch_channel_set_variable(channel, SWITCH_RFC7989_SESSION_ID_VARIABLE, a_id); if (tech_pvt && tech_pvt->sofia_private && !tech_pvt->sofia_private->rfc7989_uuid) { - tech_pvt->sofia_private->rfc7989_uuid = su_strdup(tech_pvt->nh->nh_home, a_id); + tech_pvt->sofia_private->rfc7989_uuid = su_strdup(nua_handle_get_home(tech_pvt->nh), a_id); } } @@ -532,7 +532,7 @@ char *sofia_glue_session_id_header(switch_core_session_t *session, sofia_profile struct private_object *tech_pvt = switch_core_session_get_private(session); switch_channel_set_variable(channel, SWITCH_RFC7989_APP_SESSION_ID_VARIABLE, a_id); if (tech_pvt && tech_pvt->sofia_private && !tech_pvt->sofia_private->rfc7989_uuid) { - tech_pvt->sofia_private->rfc7989_uuid = su_strdup(tech_pvt->nh->nh_home, a_id); + tech_pvt->sofia_private->rfc7989_uuid = su_strdup(nua_handle_get_home(tech_pvt->nh), a_id); } } } @@ -559,7 +559,7 @@ char *sofia_glue_session_id_header(switch_core_session_t *session, sofia_profile struct private_object *tech_pvt = switch_core_session_get_private(session); switch_channel_set_variable(channel, SWITCH_RFC7989_APP_SESSION_ID_VARIABLE, a_id); if (tech_pvt && tech_pvt->sofia_private && !tech_pvt->sofia_private->rfc7989_uuid) { - tech_pvt->sofia_private->rfc7989_uuid = su_strdup(tech_pvt->nh->nh_home, a_id); + tech_pvt->sofia_private->rfc7989_uuid = su_strdup(nua_handle_get_home(tech_pvt->nh), a_id); } } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, @@ -601,7 +601,7 @@ char *sofia_glue_session_id_header(switch_core_session_t *session, sofia_profile struct private_object *tech_pvt = switch_core_session_get_private(session); switch_channel_set_variable(channel, SWITCH_RFC7989_APP_SESSION_ID_VARIABLE, a_id); if (tech_pvt && tech_pvt->sofia_private) { - tech_pvt->sofia_private->rfc7989_uuid = su_strdup(tech_pvt->nh->nh_home, a_id); + tech_pvt->sofia_private->rfc7989_uuid = su_strdup(nua_handle_get_home(tech_pvt->nh), a_id); } } b_id = switch_channel_get_variable(channel, SWITCH_RFC7989_SESSION_ID_VARIABLE); @@ -1500,7 +1500,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) switch_safe_free(d_url); - if (!(sofia_private = su_alloc(tech_pvt->nh->nh_home, sizeof(*sofia_private)))) { + if (!(sofia_private = su_alloc(nua_handle_get_home(tech_pvt->nh), sizeof(*sofia_private)))) { abort(); } @@ -1592,14 +1592,14 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) if ((val = switch_channel_get_variable(tech_pvt->channel, "sip_invite_cseq"))) { uint32_t callsequence = (uint32_t) strtoul(val, NULL, 10); - cseq = sip_cseq_create(tech_pvt->nh->nh_home, callsequence, SIP_METHOD_INVITE); + cseq = sip_cseq_create(nua_handle_get_home(tech_pvt->nh), callsequence, SIP_METHOD_INVITE); } switch_channel_clear_flag(channel, CF_MEDIA_ACK); if (handle_full_from) { - tech_pvt->nh->nh_has_invite = 1; + nua_handle_set_has_invite(tech_pvt->nh, 1); } if ((mp = sofia_media_get_multipart(session, "sip_multipart", tech_pvt->mparams.local_sdp_str, &mp_type))) { @@ -3333,8 +3333,8 @@ char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, nua } if (sip->sip_record_route) { - char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); - char *route = sofia_glue_strip_uri(sip_header_as_string(nh->nh_home, (void *) sip->sip_record_route)); + char *full_contact = sip_header_as_string(nua_handle_get_home(nh), (void *) contact); + char *route = sofia_glue_strip_uri(sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_record_route)); char *full_contact_dup; char *route_encoded; int route_encoded_len; @@ -3348,7 +3348,7 @@ char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, nua free(route_encoded); } else if (np->is_nat && np->fs_path) { - char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); + char *full_contact = sip_header_as_string(nua_handle_get_home(nh), (void *) contact); char *full_contact_dup; char *path_encoded; int path_encoded_len; diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index be27121cd1..e1c31c99c8 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -368,7 +368,7 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) if (is_blocking) { sanity = 200; - while(!mstatus && --sanity && !msg_nh->nh_destroyed) { + while(!mstatus && --sanity && !nua_handle_is_destroyed(msg_nh)) { switch_yield(100000); } @@ -2334,7 +2334,7 @@ static void _send_presence_notify(sofia_profile_t *profile, } nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_CONTACT_STR(contact_str), TAG_END()); - cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY); + cseq = sip_cseq_create(nua_handle_get_home(nh), callsequence, SIP_METHOD_NOTIFY); nua_handle_bind(nh, &mod_sofia_globals.destroy_private); @@ -3712,7 +3712,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, contact_user = sip->sip_contact->m_url->url_user; } - full_agent = sip_header_as_string(nh->nh_home, (void *) sip->sip_user_agent); + full_agent = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_user_agent); //tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END()); @@ -3726,7 +3726,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, } } - event = sip_header_as_string(nh->nh_home, (void *) sip->sip_event); + event = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_event); if (to) { to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host); @@ -3864,9 +3864,9 @@ void sofia_presence_handle_sip_i_subscribe(int status, } 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); + full_from = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_from); + full_to = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_to); + full_via = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_via); if (sip->sip_expires && sip->sip_expires->ex_delta > 31536000) { @@ -4062,9 +4062,9 @@ void sofia_presence_handle_sip_i_subscribe(int status, } - if (nh && nh->nh_ds->ds_usage) { + if (nh) { /* nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP); */ - nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta, exp_delta); + nua_handle_dialog_usage_set_refresh_range(nh, exp_delta, exp_delta); } if (contactstr && (p = strchr(contactstr, '@'))) { @@ -4076,7 +4076,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, } if (nh) { - sip_to_tag(nh->nh_home, sip->sip_to, use_to_tag); + sip_to_tag(nua_handle_get_home(nh), sip->sip_to, use_to_tag); } if (mod_sofia_globals.debug_presence > 0) { @@ -4107,7 +4107,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, if (zstr(full_agent) || (*full_agent != 'z' && *full_agent != 'Z')) { /* supress endless loop bug with zoiper */ callsequence = sofia_presence_get_cseq(profile); - cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY); + cseq = sip_cseq_create(nua_handle_get_home(nh), callsequence, SIP_METHOD_NOTIFY); nua_notify(nh, SIPTAG_EXPIRES_STR("0"), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), @@ -4124,7 +4124,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, char *p = NULL; if (sip->sip_call_info) { - full_call_info = sip_header_as_string(nh->nh_home, (void *) sip->sip_call_info); + full_call_info = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_call_info); if ((p = strchr(full_call_info, ';'))) { p++; } @@ -4154,7 +4154,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL); } - su_free(nh->nh_home, full_call_info); + su_free(nua_handle_get_home(nh), full_call_info); } @@ -4165,12 +4165,12 @@ void sofia_presence_handle_sip_i_subscribe(int status, switch_time_t now; if (sip->sip_call_info) { - full_call_info = sip_header_as_string(nh->nh_home, (void *) sip->sip_call_info); + full_call_info = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_call_info); if ((p = strchr(full_call_info, ';'))) { p++; } callsequence = sofia_presence_get_cseq(profile); - cseq = sip_cseq_create(nh->nh_home, callsequence, SIP_METHOD_NOTIFY); + cseq = sip_cseq_create(nua_handle_get_home(nh), callsequence, SIP_METHOD_NOTIFY); nua_notify(nh, SIPTAG_FROM(sip->sip_to), SIPTAG_TO(sip->sip_from), @@ -4205,7 +4205,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, NULL); - su_free(nh->nh_home, full_call_info); + su_free(nua_handle_get_home(nh), full_call_info); } } else if (!strcasecmp(event, "call-info")) { sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE, call_id); @@ -4401,21 +4401,21 @@ void sofia_presence_handle_sip_i_subscribe(int status, } if (event) { - su_free(nh->nh_home, event); + su_free(nua_handle_get_home(nh), event); } if (full_from) { - su_free(nh->nh_home, full_from); + su_free(nua_handle_get_home(nh), full_from); } if (full_to) { - su_free(nh->nh_home, full_to); + su_free(nua_handle_get_home(nh), full_to); } if (full_via) { - su_free(nh->nh_home, full_via); + su_free(nua_handle_get_home(nh), full_via); } if (full_agent) { - su_free(nh->nh_home, full_agent); + su_free(nua_handle_get_home(nh), full_agent); } switch_safe_free(d_user); @@ -4608,7 +4608,7 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n char *open_closed = "", *note_txt = ""; if (sip->sip_user_agent) { - full_agent = sip_header_as_string(nh->nh_home, (void *) sip->sip_user_agent); + full_agent = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_user_agent); } if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status")) @@ -4652,7 +4652,7 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n } } - event_type = sip_header_as_string(nh->nh_home, (void *) sip->sip_event); + event_type = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_event); if (count) { if ((sql = switch_mprintf("delete from sip_presence where sip_user='%q' and sip_host='%q' " @@ -4702,11 +4702,11 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n } if (event_type) { - su_free(nh->nh_home, event_type); + su_free(nua_handle_get_home(nh), event_type); } if (full_agent) { - su_free(nh->nh_home, full_agent); + su_free(nua_handle_get_home(nh), full_agent); } switch_xml_free(xml); @@ -4859,7 +4859,7 @@ void sofia_presence_handle_sip_i_message(int status, sip_unknown_t *un; int first_history_info = 1; - full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from); + full_from = sip_header_as_string(nua_handle_get_home(nh), (void *) sip->sip_from); if ((p = strchr(to_user, '+')) && p != to_user) { switch_copy_string(proto, to_user, sizeof(proto)); @@ -5013,7 +5013,7 @@ void sofia_presence_handle_sip_i_message(int status, switch_safe_free(from_addr); if (full_from) { - su_free(nh->nh_home, full_from); + su_free(nua_handle_get_home(nh), full_from); } } } diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 0ffa235875..81d2ffdabd 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1935,17 +1935,17 @@ uint8_t sofia_reg_handle_register_token(nua_t *nua, sofia_profile_t *profile, nu switch_mutex_unlock(profile->flag_mutex); if (!hnh) { - if (!(sofia_private = su_alloc(nh->nh_home, sizeof(*sofia_private)))) { + if (!(sofia_private = su_alloc(nua_handle_get_home(nh), sizeof(*sofia_private)))) { abort(); } memset(sofia_private, 0, sizeof(*sofia_private)); - sofia_private->call_id = su_strdup(nh->nh_home, call_id); - sofia_private->network_ip = su_strdup(nh->nh_home, network_ip); - sofia_private->network_port = su_strdup(nh->nh_home, network_port_c); - sofia_private->key = su_strdup(nh->nh_home, key); - sofia_private->user = su_strdup(nh->nh_home, to_user); - sofia_private->realm = su_strdup(nh->nh_home, reg_host); + sofia_private->call_id = su_strdup(nua_handle_get_home(nh), call_id); + sofia_private->network_ip = su_strdup(nua_handle_get_home(nh), network_ip); + sofia_private->network_port = su_strdup(nua_handle_get_home(nh), network_port_c); + sofia_private->key = su_strdup(nua_handle_get_home(nh), key); + sofia_private->user = su_strdup(nua_handle_get_home(nh), to_user); + sofia_private->realm = su_strdup(nua_handle_get_home(nh), reg_host); sofia_private->is_static++; *sofia_private_p = sofia_private; @@ -2426,12 +2426,12 @@ void sofia_reg_handle_sip_r_register(int status, char *full; for (; contact; contact = contact->m_next) { - if ((full = sip_header_as_string(nh->nh_home, (void *) contact))) { + if ((full = sip_header_as_string(nua_handle_get_home(nh), (void *) contact))) { if (switch_stristr(gateway->register_contact, full)) { break; } - su_free(nh->nh_home, full); + su_free(nua_handle_get_home(nh), full); } } }