summaryrefslogtreecommitdiff
path: root/res/res_pjsip
diff options
context:
space:
mode:
authorAlexei Gradinari <alex2grad@gmail.com>2016-05-19 15:56:26 -0400
committerAlexei Gradinari <alex2grad@gmail.com>2016-05-25 10:56:14 -0400
commit230686f4ec82a774e2a41aaa5e86909fd589f9b4 (patch)
treedf6bef07fb69be2c985c5393b5b90863ae63b439 /res/res_pjsip
parentf09f923514c44737693e424b3dab9afccfe0031f (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')
-rw-r--r--res/res_pjsip/location.c17
-rw-r--r--res/res_pjsip/pjsip_options.c10
2 files changed, 27 insertions, 0 deletions
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index ef06456a7..f55bd0fb4 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -122,6 +122,8 @@ static void *contact_alloc(const char *name)
}
ast_string_field_init_extended(contact, reg_server);
+ ast_string_field_init_extended(contact, via_addr);
+ ast_string_field_init_extended(contact, call_id);
/* Dynamic contacts are delimited with ";@" and static ones with "@@" */
if ((aor_separator = strstr(id, ";@")) || (aor_separator = strstr(id, "@@"))) {
@@ -308,6 +310,7 @@ struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_na
int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri,
struct timeval expiration_time, const char *path_info, const char *user_agent,
+ const char *via_addr, int via_port, const char *call_id,
struct ast_sip_endpoint *endpoint)
{
char name[MAX_OBJECT_FIELD * 2 + 3];
@@ -342,6 +345,15 @@ int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri
ast_string_field_set(contact, reg_server, ast_config_AST_SYSTEM_NAME);
}
+ if (!ast_strlen_zero(via_addr)) {
+ ast_string_field_set(contact, via_addr, via_addr);
+ }
+ contact->via_port = via_port;
+
+ if (!ast_strlen_zero(call_id)) {
+ ast_string_field_set(contact, call_id, call_id);
+ }
+
contact->endpoint = ao2_bump(endpoint);
return ast_sorcery_create(ast_sip_get_sorcery(), contact);
@@ -349,6 +361,7 @@ int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri
int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
struct timeval expiration_time, const char *path_info, const char *user_agent,
+ const char *via_addr, int via_port, const char *call_id,
struct ast_sip_endpoint *endpoint)
{
int res;
@@ -361,6 +374,7 @@ int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
ao2_wrlock(lock);
res = ast_sip_location_add_contact_nolock(aor, uri, expiration_time, path_info, user_agent,
+ via_addr, via_port, call_id,
endpoint);
ao2_unlock(lock);
ast_named_lock_put(lock);
@@ -1125,6 +1139,9 @@ int ast_sip_initialize_sorcery_location(void)
ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy));
ast_sorcery_object_field_register(sorcery, "contact", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, user_agent));
ast_sorcery_object_field_register(sorcery, "contact", "reg_server", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, reg_server));
+ ast_sorcery_object_field_register(sorcery, "contact", "via_addr", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, via_addr));
+ ast_sorcery_object_field_register(sorcery, "contact", "via_port", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_contact, via_port));
+ ast_sorcery_object_field_register(sorcery, "contact", "call_id", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, call_id));
ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0);
ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration));
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index b9339f60b..d73766cb2 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -1167,6 +1167,16 @@ static int format_contact_status(void *obj, void *arg, int flags)
ast_str_append(&buf, 0, "URI: %s\r\n", contact->uri);
ast_str_append(&buf, 0, "UserAgent: %s\r\n", contact->user_agent);
ast_str_append(&buf, 0, "RegExpire: %ld\r\n", contact->expiration_time.tv_sec);
+ if (!ast_strlen_zero(contact->via_addr)) {
+ ast_str_append(&buf, 0, "ViaAddress: %s", contact->via_addr);
+ if (contact->via_port) {
+ ast_str_append(&buf, 0, ":%d", contact->via_port);
+ }
+ ast_str_append(&buf, 0, "\r\n");
+ }
+ if (!ast_strlen_zero(contact->call_id)) {
+ ast_str_append(&buf, 0, "CallID: %s\r\n", contact->call_id);
+ }
ast_str_append(&buf, 0, "Status: %s\r\n", ast_sip_get_contact_status_label(status->status));
if (status->status == UNKNOWN) {
ast_str_append(&buf, 0, "RoundtripUsec: N/A\r\n");