From 329507fe20ae5dcbed3e7b494ce6fffeb9990af3 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Tue, 16 Aug 2016 14:36:10 -0600 Subject: res_pjsip: Add contact_user to endpoint contact_user, when specified on an endpoint, will override the user portion of the Contact header on outgoing requests. Change-Id: Icd4ebfda2f2e44d3ac749d0b4066630e988407d4 --- res/res_pjsip.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'res/res_pjsip.c') diff --git a/res/res_pjsip.c b/res/res_pjsip.c index aafb3a211..96c07d501 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -913,6 +913,12 @@ then the context setting is used. + + Force the user on the outgoing Contact header to this value. + + On outbound requests, force the user portion of the Contact header to this value. + + Authentication type @@ -2869,8 +2875,16 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, /* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */ pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri); dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0); + dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL); + if (!ast_strlen_zero(endpoint->contact_user)) { + pjsip_sip_uri *sip_uri; + + sip_uri = pjsip_uri_get_uri(dlg->local.contact->uri); + pj_strdup2(dlg->pool, &sip_uri->user, endpoint->contact_user); + } + /* If a request user has been specified and we are permitted to change it, do so */ if (!ast_strlen_zero(request_user)) { pjsip_sip_uri *sip_uri; @@ -3172,6 +3186,18 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s return -1; } + if (endpoint && !ast_strlen_zero(endpoint->contact_user)){ + pjsip_contact_hdr *contact_hdr; + pjsip_sip_uri *contact_uri; + static const pj_str_t HCONTACT = { "Contact", 7 }; + + contact_hdr = pjsip_msg_find_hdr_by_name((*tdata)->msg, &HCONTACT, NULL); + if (contact_hdr) { + contact_uri = pjsip_uri_get_uri(contact_hdr->uri); + pj_strdup2(pool, &contact_uri->user, endpoint->contact_user); + } + } + /* Add the user=phone parameter if applicable */ ast_sip_add_usereqphone(endpoint, (*tdata)->pool, (*tdata)->msg->line.req.uri); -- cgit v1.2.3