From 7a36d0beac6c5e1253076a2b42d778fd389695e6 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Tue, 19 Mar 2013 07:39:25 +0000 Subject: Close #1645: Added run-time setting 'pjsip_cfg()->req_has_via_alias' and compile-time setting 'PJSIP_REQ_HAS_VIA_ALIAS', the default value is PJ_TRUE. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4442 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_config.h | 22 ++++++++++++++++++++++ pjsip/src/pjsip/sip_config.c | 3 ++- pjsip/src/pjsip/sip_util.c | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index b72c6d02..bc895c59 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -120,6 +120,14 @@ typedef struct pjsip_cfg_t */ pj_bool_t follow_early_media_fork; + /** + * Specify whether "alias" param should be added to the Via header + * in any outgoing request with connection oriented transport. + * + * Default is PJSIP_REQ_HAS_VIA_ALIAS. + */ + pj_bool_t req_has_via_alias; + } endpt; /** Transaction layer settings. */ @@ -315,6 +323,20 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) #endif +/** + * Specify whether "alias" param should be added to the Via header + * in any outgoing request with connection oriented transport. + * + * This option can also be controlled at run-time by the + * \a req_has_via_alias setting in pjsip_cfg_t. + * + * Default is PJ_TRUE. + */ +#ifndef PJSIP_REQ_HAS_VIA_ALIAS +# define PJSIP_REQ_HAS_VIA_ALIAS PJ_TRUE +#endif + + /** * Accept call replace in early state when invite is not initiated * by the user agent. RFC 3891 Section 3 disallows this, however, diff --git a/pjsip/src/pjsip/sip_config.c b/pjsip/src/pjsip/sip_config.c index 8c0dac1d..dacc2f82 100644 --- a/pjsip/src/pjsip/sip_config.c +++ b/pjsip/src/pjsip/sip_config.c @@ -30,7 +30,8 @@ pjsip_cfg_t pjsip_sip_cfg_var = 0, 0, PJSIP_DONT_SWITCH_TO_TCP, - PJSIP_FOLLOW_EARLY_MEDIA_FORK + PJSIP_FOLLOW_EARLY_MEDIA_FORK, + PJSIP_REQ_HAS_VIA_ALIAS }, /* Transaction settings */ diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c index ed4fd9c0..411251d0 100644 --- a/pjsip/src/pjsip/sip_util.c +++ b/pjsip/src/pjsip/sip_util.c @@ -1201,6 +1201,28 @@ static void stateless_send_transport_cb( void *token, } via->rport_param = pjsip_cfg()->endpt.disable_rport ? -1 : 0; + /* Add/remove "alias" param to/from Via header on connection + * oriented/less transport, if configured. + */ + if (pjsip_cfg()->endpt.req_has_via_alias && + tdata->msg->type == PJSIP_REQUEST_MSG) + { + const pj_str_t ALIAS_STR = {"alias", 5}; + pjsip_param *alias_param; + pj_bool_t is_datagram; + + alias_param = pjsip_param_find(&via->other_param, &ALIAS_STR); + is_datagram = (stateless_data->cur_transport->flag & + PJSIP_TRANSPORT_DATAGRAM); + if (!is_datagram && !alias_param) { + alias_param = PJ_POOL_ZALLOC_T(tdata->pool, pjsip_param); + alias_param->name = ALIAS_STR; + pj_list_push_back(&via->other_param, alias_param); + } else if (is_datagram && alias_param) { + pj_list_erase(alias_param); + } + } + pjsip_tx_data_invalidate_msg(tdata); /* Send message using this transport. */ -- cgit v1.2.3