diff options
author | Alexei Gradinari <alex2grad@gmail.com> | 2016-05-19 15:56:26 -0400 |
---|---|---|
committer | Alexei Gradinari <alex2grad@gmail.com> | 2016-05-26 16:18:11 -0500 |
commit | 31f17abe449c2a9b43ef4e820792fb52d4b27d7a (patch) | |
tree | dc5464d92bce81601bcd240c0bdb9b397822bcb4 /res/res_pjsip_registrar.c | |
parent | a6b16d7029a7a44c6a43b3b0f1cbc74cecd11454 (diff) |
res_pjsip: add "via_addr", "via_port", "call_id" to contact
As res_pjsip_nat rewrites contact's address, only the last Via header
can contain the source address of registered endpoint.
Also Call-Id header may contain the source address of registered
endpoint.
Added "via_addr", "via_port", "call_id" to contact.
Added new fields ViaAddress, CallID to AMI event ContactStatus.
ASTERISK-26011
Change-Id: I36bcc0bf422b3e0623680152d80486aeafe4c576
Diffstat (limited to 'res/res_pjsip_registrar.c')
-rw-r--r-- | res/res_pjsip_registrar.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c index cbc33ab80..0e14ab786 100644 --- a/res/res_pjsip_registrar.c +++ b/res/res_pjsip_registrar.c @@ -447,6 +447,13 @@ static int rx_task_core(struct rx_task_data *task_data, struct ao2_container *co char *user_agent = NULL; pjsip_user_agent_hdr *user_agent_hdr; pjsip_expires_hdr *expires_hdr; + pjsip_via_hdr *via_hdr; + pjsip_via_hdr *via_hdr_last; + char *via_addr = NULL; + int via_port = 0; + pjsip_cid_hdr *call_id_hdr; + char *call_id = NULL; + size_t alloc_size; /* So we don't count static contacts against max_contacts we prune them out from the container */ ao2_callback(contacts, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, registrar_prune_static, NULL); @@ -484,11 +491,32 @@ static int rx_task_core(struct rx_task_data *task_data, struct ao2_container *co user_agent_hdr = pjsip_msg_find_hdr_by_name(task_data->rdata->msg_info.msg, &USER_AGENT, NULL); if (user_agent_hdr) { - size_t alloc_size = pj_strlen(&user_agent_hdr->hvalue) + 1; + alloc_size = pj_strlen(&user_agent_hdr->hvalue) + 1; user_agent = ast_alloca(alloc_size); ast_copy_pj_str(user_agent, &user_agent_hdr->hvalue, alloc_size); } + /* Find the first Via header */ + via_hdr = via_hdr_last = (pjsip_via_hdr*) pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, PJSIP_H_VIA, NULL); + if (via_hdr) { + /* Find the last Via header */ + while ( (via_hdr = (pjsip_via_hdr*) pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, + PJSIP_H_VIA, via_hdr->next)) != NULL) { + via_hdr_last = via_hdr; + } + alloc_size = pj_strlen(&via_hdr_last->sent_by.host) + 1; + via_addr = ast_alloca(alloc_size); + ast_copy_pj_str(via_addr, &via_hdr_last->sent_by.host, alloc_size); + via_port=via_hdr_last->sent_by.port; + } + + call_id_hdr = (pjsip_cid_hdr*) pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, PJSIP_H_CALL_ID, NULL); + if (call_id_hdr) { + alloc_size = pj_strlen(&call_id_hdr->id) + 1; + call_id = ast_alloca(alloc_size); + ast_copy_pj_str(call_id, &call_id_hdr->id, alloc_size); + } + /* Iterate each provided Contact header and add, update, or delete */ while ((contact_hdr = pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, PJSIP_H_CONTACT, contact_hdr ? contact_hdr->next : NULL))) { int expiration; @@ -520,7 +548,7 @@ static int rx_task_core(struct rx_task_data *task_data, struct ao2_container *co if (ast_sip_location_add_contact_nolock(task_data->aor, contact_uri, ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1)), path_str ? ast_str_buffer(path_str) : NULL, - user_agent, task_data->endpoint)) { + user_agent, via_addr, via_port, call_id, task_data->endpoint)) { ast_log(LOG_ERROR, "Unable to bind contact '%s' to AOR '%s'\n", contact_uri, aor_name); continue; |