From cd8ccebbf44b6ea175adefe495c982815eec22bf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 22 Aug 2011 10:58:33 -0500 Subject: [PATCH] save via_string when sent to nh so we can use it in session timer re-invites to fix double nat issue --- .../libsofia-sip-ua/nua/nua_client.c | 3 +++ .../libsofia-sip-ua/nua/nua_dialog.c | 6 +++++ .../libsofia-sip-ua/nua/nua_dialog.h | 1 + .../libsofia-sip-ua/nua/nua_params.c | 14 +++++++++++ .../libsofia-sip-ua/nua/nua_params.h | 2 ++ .../libsofia-sip-ua/nua/nua_server.c | 4 +++ libs/sofia-sip/libsofia-sip-ua/nua/nua_tag.c | 25 +++++++++++++++++++ .../libsofia-sip-ua/nua/sofia-sip/nua_tag.h | 5 ++++ 8 files changed, 60 insertions(+) diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_client.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_client.c index 9facd8cd23..1a3614c6a1 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_client.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_client.c @@ -837,6 +837,9 @@ int nua_client_request_sendmsg(nua_client_request_t *cr) if (!sip->sip_user_agent && NH_PGET(nh, user_agent)) sip_add_make(msg, sip, sip_user_agent_class, NH_PGET(nh, user_agent)); + if (!sip->sip_via && NH_PGET(nh, via)) + sip_add_make(msg, sip, sip_via_class, NH_PGET(nh, via)); + /** Any node implementing one or more event packages SHOULD include an * appropriate @AllowEvents header indicating all supported events in * all methods which initiate dialogs and their responses (such as diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c index d774b82d8d..019691b611 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c @@ -154,6 +154,7 @@ void nua_dialog_store_peer_info(nua_owner_t *own, sip = NULL; /* Redirected */ if (sip == NULL) { + nr->nr_via = NULL, su_free(own, old->nr_via); nr->nr_allow = NULL, su_free(own, old->nr_allow); nr->nr_accept = NULL, su_free(own, old->nr_accept); nr->nr_require = NULL, su_free(own, old->nr_require); @@ -182,6 +183,11 @@ void nua_dialog_store_peer_info(nua_owner_t *own, su_free(own, old->nr_supported); } + if (sip->sip_via) { + nr->nr_via = sip_via_dup(own, sip->sip_via); + su_free(own, old->nr_via); + } + if (sip->sip_user_agent) { nr->nr_user_agent = sip_user_agent_dup(own, sip->sip_user_agent); su_free(own, old->nr_user_agent); diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.h b/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.h index f48b75e435..707e6a60ec 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.h @@ -83,6 +83,7 @@ struct nua_dialog_state */ struct nua_dialog_peer_info { + sip_via_t *nr_via; sip_allow_t *nr_allow; sip_accept_t *nr_accept; sip_require_t *nr_require; diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.c index 8f511796b0..58b480440a 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.c @@ -957,6 +957,16 @@ static int nhp_set_tags(su_home_t *home, value = 0; NHP_SET_STR(nhp, organization, value); } + /* SIPTAG_VIA(via) */ + else if (tag == siptag_via) { + NHP_SET_STR_BY_HEADER(nhp, via, value); + } + /* SIPTAG_VIA_STR(via_str) */ + else if (tag == siptag_via_str) { + if (value == -1) + value = 0; + NHP_SET_STR(nhp, via, value); + } /* NUTAG_REGISTRAR(registrar) */ else if (tag == nutag_registrar) { NHP_SET_STR_BY_URL(nhp, char, registrar, value); @@ -1134,6 +1144,7 @@ int nhp_save_params(nua_handle_t *nh, NHP_ZAP_OVERRIDEN(old, dst, msg_header_free, allow_events); NHP_ZAP_OVERRIDEN(old, dst, su_free, user_agent); NHP_ZAP_OVERRIDEN(old, dst, su_free, organization); + NHP_ZAP_OVERRIDEN(old, dst, su_free, via); NHP_ZAP_OVERRIDEN(old, dst, su_free, m_display); NHP_ZAP_OVERRIDEN(old, dst, su_free, m_username); NHP_ZAP_OVERRIDEN(old, dst, su_free, m_params); @@ -1673,6 +1684,9 @@ int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e, TIF_SIP(SIPTAG_ORGANIZATION, organization), TIF(SIPTAG_ORGANIZATION_STR, organization), + TIF_SIP(SIPTAG_VIA, via), + TIF(SIPTAG_VIA_STR, via), + TIF(NUTAG_INITIAL_ROUTE, initial_route), TIF_STR(NUTAG_INITIAL_ROUTE_STR, initial_route), diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.h b/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.h index 7aa726d5f9..1904a080c5 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_params.h @@ -127,6 +127,7 @@ struct nua_handle_preferences sip_allow_events_t *nhp_allow_events; char const *nhp_user_agent; char const *nhp_organization; + char const *nhp_via; char const *nhp_m_display; char const *nhp_m_username; @@ -195,6 +196,7 @@ struct nua_handle_preferences unsigned nhb_allow_events:1; unsigned nhb_user_agent:1; unsigned nhb_organization:1; + unsigned nhb_via:1; unsigned nhb_m_display:1; unsigned nhb_m_username:1; diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_server.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_server.c index f9649759da..c8c42f44f9 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_server.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_server.c @@ -537,6 +537,10 @@ int nua_server_respond(nua_server_request_t *sr, tagi_t const *tags) sip_add_make(msg, sip, sip_organization_class, NH_PGET(nh, organization)) < 0) ; + else if (!sip->sip_via && NH_PGET(nh, via) && + sip_add_make(msg, sip, sip_via_class, + NH_PGET(nh, via)) < 0) + ; else if (!sip->sip_allow && NH_PGET(nh, allow) && sip_add_dup(msg, sip, (void *)NH_PGET(nh, allow)) < 0) ; diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_tag.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_tag.c index caf36e1036..96ca20baee 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_tag.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_tag.c @@ -2458,6 +2458,31 @@ tag_typedef_t nutag_user_agent = STRTAG_TYPEDEF(user_agent); */ +/**@def NUTAG_VIA() + * + * Via string. + * + * Indicate the Via header used by the stack. + * + * @par Used with + * nua_set_params(), nua_set_hparams() \n + * nua_get_params(), nua_get_hparams(), #nua_r_get_params \n + * any handle-specific nua call + * + * @par Parameter type + * char const * + * + * @par Values + * See @RFC3261 \n + * + * Corresponding tag taking reference parameter is NUTAG_VIA_REF(). + */ +tag_typedef_t nutag_via = STRTAG_TYPEDEF(via); + +/**@def NUTAG_VIA_REF(x) + * Reference tag for NUTAG_VIA(). + */ + /**@def NUTAG_ALLOW() * * Allow a method (or methods). diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h b/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h index fe39c32981..9e710d052d 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h @@ -437,6 +437,11 @@ SOFIAPUBVAR tag_typedef_t nutag_user_agent; #define NUTAG_USER_AGENT_REF(x) nutag_user_agent_ref, tag_str_vr(&(x)) SOFIAPUBVAR tag_typedef_t nutag_user_agent_ref; +#define NUTAG_VIA(x) nutag_via, tag_str_v(x) +SOFIAPUBVAR tag_typedef_t nutag_via; +#define NUTAG_VIA_REF(x) nutag_via_ref, tag_str_vr(&(x)) +SOFIAPUBVAR tag_typedef_t nutag_via_ref; + #define NUTAG_ALLOW(x) nutag_allow, tag_str_v(x) SOFIAPUBVAR tag_typedef_t nutag_allow; #define NUTAG_ALLOW_REF(x) nutag_allow_ref, tag_str_vr(&(x))