@ -396,34 +396,6 @@ static void caller_id_incoming_response(struct ast_sip_session *session, pjsip_r
update_incoming_connected_line ( session , rdata ) ;
}
/*!
* \ internal
* \ brief Set name and number information on an identity header .
* \ param pool Memory pool to use for string duplication
* \ param id_hdr A From , P - Asserted - Identity , or Remote - Party - ID header to modify
* \ param id The identity information to apply to the header
*/
static void modify_id_header ( pj_pool_t * pool , pjsip_fromto_hdr * id_hdr , const struct ast_party_id * id )
{
pjsip_name_addr * id_name_addr ;
pjsip_sip_uri * id_uri ;
id_name_addr = ( pjsip_name_addr * ) id_hdr - > uri ;
id_uri = pjsip_uri_get_uri ( id_name_addr - > uri ) ;
if ( id - > name . valid ) {
int name_buf_len = strlen ( id - > name . str ) * 2 + 1 ;
char * name_buf = ast_alloca ( name_buf_len ) ;
ast_escape_quoted ( id - > name . str , name_buf , name_buf_len ) ;
pj_strdup2 ( pool , & id_name_addr - > display , name_buf ) ;
}
if ( id - > number . valid ) {
pj_strdup2 ( pool , & id_uri - > user , id - > number . str ) ;
}
}
/*!
* \ internal
* \ brief Create an identity header for an outgoing message
@ -432,15 +404,12 @@ static void modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, const st
* \ param id The identification information for the new header
* \ return newly - created header
*/
static pjsip_fromto_hdr * create_new_id_hdr ( const pj_str_t * hdr_name , pjsip_ tx_data * tdata , const struct ast_party_id * id )
static pjsip_fromto_hdr * create_new_id_hdr ( const pj_str_t * hdr_name , pjsip_ fromto_hdr * base , pjsip_ tx_data * tdata , const struct ast_party_id * id )
{
pjsip_fromto_hdr * id_hdr ;
pjsip_fromto_hdr * base ;
pjsip_name_addr * id_name_addr ;
pjsip_sip_uri * id_uri ;
base = tdata - > msg - > type = = PJSIP_REQUEST_MSG ? PJSIP_MSG_FROM_HDR ( tdata - > msg ) :
PJSIP_MSG_TO_HDR ( tdata - > msg ) ;
id_hdr = pjsip_from_hdr_create ( tdata - > pool ) ;
id_hdr - > type = PJSIP_H_OTHER ;
pj_strdup ( tdata - > pool , & id_hdr - > name , hdr_name ) ;
@ -500,9 +469,10 @@ static void add_privacy_header(pjsip_tx_data *tdata, const struct ast_party_id *
* \ param tdata The message to add the header to
* \ param id The identification information used to populate the header
*/
static void add_pai_header ( pjsip_tx_data * tdata , const struct ast_party_id * id )
static void add_pai_header ( const struct ast_sip_session * session , pjsip_tx_data * tdata , const struct ast_party_id * id )
{
static const pj_str_t pj_pai_name = { " P-Asserted-Identity " , 19 } ;
pjsip_fromto_hdr * base ;
pjsip_fromto_hdr * pai_hdr ;
pjsip_fromto_hdr * old_pai ;
@ -523,13 +493,16 @@ static void add_pai_header(pjsip_tx_data *tdata, const struct ast_party_id *id)
if ( old_pai - > type = = PJSIP_H_OTHER ) {
pj_list_erase ( old_pai ) ;
} else {
modify_id_header( tdata - > pool , old_pai , id ) ;
ast_sip_ modify_id_header( tdata - > pool , old_pai , id ) ;
add_privacy_header ( tdata , id ) ;
return ;
}
}
pai_hdr = create_new_id_hdr ( & pj_pai_name , tdata , id ) ;
base = tdata - > msg - > type = = PJSIP_REQUEST_MSG ? session - > saved_from_hdr :
PJSIP_MSG_TO_HDR ( tdata - > msg ) ;
pai_hdr = create_new_id_hdr ( & pj_pai_name , base , tdata , id ) ;
if ( ! pai_hdr ) {
return ;
}
@ -602,9 +575,10 @@ static void add_privacy_params(pjsip_tx_data *tdata, pjsip_fromto_hdr *hdr, cons
* \ param tdata The message to add the header to
* \ param id The identification information used to populate the header
*/
static void add_rpid_header ( pjsip_tx_data * tdata , const struct ast_party_id * id )
static void add_rpid_header ( const struct ast_sip_session * session , pjsip_tx_data * tdata , const struct ast_party_id * id )
{
static const pj_str_t pj_rpid_name = { " Remote-Party-ID " , 15 } ;
pjsip_fromto_hdr * base ;
pjsip_fromto_hdr * rpid_hdr ;
pjsip_fromto_hdr * old_rpid ;
@ -625,13 +599,16 @@ static void add_rpid_header(pjsip_tx_data *tdata, const struct ast_party_id *id)
if ( old_rpid - > type = = PJSIP_H_OTHER ) {
pj_list_erase ( old_rpid ) ;
} else {
modify_id_header( tdata - > pool , old_rpid , id ) ;
ast_sip_ modify_id_header( tdata - > pool , old_rpid , id ) ;
add_privacy_params ( tdata , old_rpid , id ) ;
return ;
}
}
rpid_hdr = create_new_id_hdr ( & pj_rpid_name , tdata , id ) ;
base = tdata - > msg - > type = = PJSIP_REQUEST_MSG ? session - > saved_from_hdr :
PJSIP_MSG_TO_HDR ( tdata - > msg ) ;
rpid_hdr = create_new_id_hdr ( & pj_rpid_name , base , tdata , id ) ;
if ( ! rpid_hdr ) {
return ;
}
@ -658,10 +635,10 @@ static void add_id_headers(const struct ast_sip_session *session, pjsip_tx_data
return ;
}
if ( session - > endpoint - > id . send_pai ) {
add_pai_header ( tdata, id ) ;
add_pai_header ( session, tdata, id ) ;
}
if ( session - > endpoint - > id . send_rpid ) {
add_rpid_header ( tdata, id ) ;
add_rpid_header ( session, tdata, id ) ;
}
}
@ -669,10 +646,9 @@ static void add_id_headers(const struct ast_sip_session *session, pjsip_tx_data
* \ internal
* \ brief Session supplement callback for outgoing INVITE requests
*
* For an initial INVITE request , we may change the From header to appropriately
* reflect the identity information . On all INVITEs ( initial and reinvite ) we may
* add other identity headers such as P - Asserted - Identity and Remote - Party - ID based
* on configuration and privacy settings
* On all INVITEs ( initial and reinvite ) we may add other identity headers
* such as P - Asserted - Identity and Remote - Party - ID based on configuration
* and privacy settings
*
* \ param session The session on which the INVITE will be sent
* \ param tdata The outbound INVITE request
@ -686,33 +662,12 @@ static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx
return ;
}
/* Must do a deep copy unless we hold the channel lock the entire time. */
ast_party_id_init ( & connected_id ) ;
ast_channel_lock ( session - > channel ) ;
effective_id = ast_channel_connected_effective_id ( session - > channel ) ;
ast_party_id_copy ( & connected_id , & effective_id ) ;
ast_channel_unlock ( session - > channel ) ;
if ( session - > inv_session - > state < PJSIP_INV_STATE_CONFIRMED ) {
/* Only change the From header on the initial outbound INVITE. Switching it
* mid - call might confuse some UAs .
*/
pjsip_fromto_hdr * from ;
pjsip_dialog * dlg ;
from = pjsip_msg_find_hdr ( tdata - > msg , PJSIP_H_FROM , tdata - > msg - > hdr . next ) ;
dlg = session - > inv_session - > dlg ;
if ( ast_strlen_zero ( session - > endpoint - > fromuser )
& & ( session - > endpoint - > id . trust_outbound
| | ( ast_party_id_presentation ( & connected_id ) & AST_PRES_RESTRICTION ) = = AST_PRES_ALLOWED ) ) {
modify_id_header ( tdata - > pool , from , & connected_id ) ;
modify_id_header ( dlg - > pool , dlg - > local . info , & connected_id ) ;
}
ast_sip_add_usereqphone ( session - > endpoint , tdata - > pool , from - > uri ) ;
ast_sip_add_usereqphone ( session - > endpoint , dlg - > pool , dlg - > local . info - > uri ) ;
}
add_id_headers ( session , tdata , & connected_id ) ;
ast_party_id_free ( & connected_id ) ;
}