Commit 1399f8b4 authored by Pirmin Walthert's avatar Pirmin Walthert Committed by George Joseph
Browse files

res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header

While asterisk is filtering out the x-ast-orig-host parameter from the
contact on response messages, it is not filtering it out from the
request URI and the to header on SIP requests (for example INVITE).

ASTERISK-28884 #close

Change-Id: Id032b33098a1befea9b243ca994184baecccc59e
parent afa2c9a8
......@@ -37,6 +37,9 @@
#define AST_SIP_X_AST_ORIG_HOST "x-ast-orig-host"
#define AST_SIP_X_AST_ORIG_HOST_LEN 15
#define is_sip_uri(uri) \
(PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))
static void save_orig_contact_host(pjsip_rx_data *rdata, pjsip_sip_uri *uri)
{
pjsip_param *x_orig_host;
......@@ -303,6 +306,29 @@ static int nat_invoke_hook(void *obj, void *arg, int flags)
static void restore_orig_contact_host(pjsip_tx_data *tdata)
{
pjsip_contact_hdr *contact;
pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
pjsip_param *x_orig_host;
pjsip_sip_uri *uri;
pjsip_hdr *hdr;
if (tdata->msg->type == PJSIP_REQUEST_MSG) {
if (is_sip_uri(tdata->msg->line.req.uri)) {
uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
pj_list_erase(x_orig_host);
}
}
for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
if (hdr->type == PJSIP_H_TO) {
if (is_sip_uri(((pjsip_fromto_hdr *) hdr)->uri)) {
uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);
while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {
pj_list_erase(x_orig_host);
}
}
}
}
}
if (tdata->msg->type != PJSIP_RESPONSE_MSG) {
return;
......@@ -311,8 +337,7 @@ static void restore_orig_contact_host(pjsip_tx_data *tdata)
contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
while (contact) {
pjsip_sip_uri *contact_uri = pjsip_uri_get_uri(contact->uri);
pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };
pjsip_param *x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);
if (x_orig_host) {
char host_port[x_orig_host->value.slen + 1];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment