--- res/res_pjsip_caller_id.c.orig 2016-02-05 21:32:40.000000000 +0100 +++ res/res_pjsip_caller_id.c 2016-02-27 12:14:44.435712150 +0100 @@ -398,6 +398,29 @@ /*! * \internal + * \brief Set URI to Anonymous 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 + */ +static void anonymize_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr) +{ + char *anonymous_disp = "Anonymous"; + char *anonymous_user = "anonymous"; + char *anonymous_host = "anonymous.invalid"; + + 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); + + pj_strdup2(pool, &id_name_addr->display, anonymous_disp); + pj_strdup2(pool, &id_uri->user, anonymous_user); + pj_strdup2(pool, &id_uri->host, anonymous_host); +} + +/*! + * \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 @@ -677,11 +700,14 @@ 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); + if (ast_strlen_zero(session->endpoint->fromuser)) { + if (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); + } else if ((ast_party_id_presentation(&connected_id) & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { + anonymize_id_header(tdata->pool, from); + anonymize_id_header(dlg->pool, dlg->local.info); + } } ast_sip_add_usereqphone(session->endpoint, tdata->pool, from->uri);