diff '--exclude=.git' -Naur asterisk-16.5.0/include/asterisk/res_pjsip.h asterisk-16.5.0-contact_host/include/asterisk/res_pjsip.h
--- asterisk-16.5.0/include/asterisk/res_pjsip.h 2019-09-06 09:00:22.000000000 +0200
+++ asterisk-16.5.0-contact_host/include/asterisk/res_pjsip.h 2019-09-06 10:03:44.813731644 +0200
@@ -802,6 +802,8 @@
unsigned int faxdetect_timeout;
/*! Override the user on the outgoing Contact header with this value. */
char *contact_user;
+ /*! Override the host on the outgoing Contact header with this value. */
+ char *contact_host;
/*! Whether to response SDP offer with single most preferred codec. */
unsigned int preferred_codec_only;
/*! Do we allow an asymmetric RTP codec? */
diff '--exclude=.git' -Naur asterisk-16.5.0/res/res_pjsip/pjsip_configuration.c asterisk-16.5.0-contact_host/res/res_pjsip/pjsip_configuration.c
--- asterisk-16.5.0/res/res_pjsip/pjsip_configuration.c 2019-09-06 09:00:22.000000000 +0200
+++ asterisk-16.5.0-contact_host/res/res_pjsip/pjsip_configuration.c 2019-09-06 09:07:49.421407159 +0200
@@ -1115,6 +1115,29 @@
return 0;
}
+static int contact_host_handler(const struct aco_option *opt,
+ struct ast_variable *var, void *obj)
+{
+ struct ast_sip_endpoint *endpoint = obj;
+
+ ast_free(endpoint->contact_host);
+ endpoint->contact_host = ast_strdup(var->value);
+
+ return endpoint->contact_host ? 0 : -1;
+}
+
+static int contact_host_to_str(const void *obj, const intptr_t *args, char **buf)
+{
+ const struct ast_sip_endpoint *endpoint = obj;
+
+ *buf = ast_strdup(endpoint->contact_host);
+ if (!(*buf)) {
+ return -1;
+ }
+
+ return 0;
+}
+
static void *sip_nat_hook_alloc(const char *name)
{
return ast_sorcery_generic_alloc(sizeof(struct ast_sip_nat_hook), NULL);
@@ -1935,6 +1958,7 @@
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_acl", "", endpoint_acl_handler, contact_acl_to_str, NULL, 0, 0);
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "subscribe_context", "", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct ast_sip_endpoint, subscription.context));
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_user", "", contact_user_handler, contact_user_to_str, NULL, 0, 0);
+ ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_host", "", contact_host_handler, contact_host_to_str, NULL, 0, 0);
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "preferred_codec_only", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, preferred_codec_only));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "asymmetric_rtp_codec", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, asymmetric_rtp_codec));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtcp_mux", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtcp_mux));
@@ -2075,6 +2099,7 @@
ast_variables_destroy(endpoint->channel_vars);
AST_VECTOR_FREE(&endpoint->ident_method_order);
ast_free(endpoint->contact_user);
+ ast_free(endpoint->contact_host);
ast_free_acl_list(endpoint->contact_acl);
ast_free_acl_list(endpoint->acl);
}
diff '--exclude=.git' -Naur asterisk-16.5.0/res/res_pjsip/pjsip_message_filter.c asterisk-16.5.0-contact_host/res/res_pjsip/pjsip_message_filter.c
--- asterisk-16.5.0/res/res_pjsip/pjsip_message_filter.c 2019-09-06 09:00:22.000000000 +0200
+++ asterisk-16.5.0-contact_host/res/res_pjsip/pjsip_message_filter.c 2019-09-06 11:02:03.583860203 +0200
@@ -282,7 +282,7 @@
pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);
/* prm.ret_addr is allocated from the tdata pool OR the transport so it is perfectly fine to just do an assignment like this */
- pj_strassign(&uri->host, &prm.ret_addr);
+ //pj_strassign(&uri->host, &prm.ret_addr);
uri->port = prm.ret_port;
ast_debug(5, "Re-wrote Contact URI host/port to %.*s:%d (this may be re-written again later)\n",
(int)pj_strlen(&uri->host), pj_strbuf(&uri->host), uri->port);
diff '--exclude=.git' -Naur asterisk-16.5.0/res/res_pjsip.c asterisk-16.5.0-contact_host/res/res_pjsip.c
--- asterisk-16.5.0/res/res_pjsip.c 2019-09-06 09:00:22.000000000 +0200
+++ asterisk-16.5.0-contact_host/res/res_pjsip.c 2019-09-06 09:04:55.752797210 +0200
@@ -1013,6 +1013,12 @@
On outbound requests, force the user portion of the Contact header to this value.
+
+ Force the host on the outgoing Contact header to this value.
+
+ On outbound requests, force the host portion of the Contact header to this value.
+
+
Allow the sending and receiving RTP codec to differ
@@ -3569,6 +3575,13 @@
pj_strdup2(dlg->pool, &sip_uri->user, endpoint->contact_user);
}
+ if (!ast_strlen_zero(endpoint->contact_host)) {
+ pjsip_sip_uri *sip_uri;
+
+ sip_uri = pjsip_uri_get_uri(dlg->local.contact->uri);
+ pj_strdup2(dlg->pool, &sip_uri->host, endpoint->contact_host);
+ }
+
/* 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;
@@ -3900,6 +3913,19 @@
}
}
+ if (endpoint && !ast_strlen_zero(endpoint->contact_host)){
+ pjsip_contact_hdr *contact_hdr;
+ pjsip_sip_uri *contact_uri;
+ static const pj_str_t HCONTACT = { "Contact", 7 };
+ static const pj_str_t HCONTACTSHORT = { "m", 1 };
+
+ contact_hdr = pjsip_msg_find_hdr_by_names((*tdata)->msg, &HCONTACT, &HCONTACTSHORT, NULL);
+ if (contact_hdr) {
+ contact_uri = pjsip_uri_get_uri(contact_hdr->uri);
+ pj_strdup2(pool, &contact_uri->host, endpoint->contact_host);
+ }
+ }
+
/* Add the user=phone parameter if applicable */
ast_sip_add_usereqphone(endpoint, (*tdata)->pool, (*tdata)->msg->line.req.uri);
diff '--exclude=.git' -Naur asterisk-16.5.0/res/res_pjsip_nat.c asterisk-16.5.0-contact_host/res/res_pjsip_nat.c
--- asterisk-16.5.0/res/res_pjsip_nat.c 2019-09-06 09:00:22.000000000 +0200
+++ asterisk-16.5.0-contact_host/res/res_pjsip_nat.c 2019-09-06 11:04:22.693135316 +0200
@@ -336,7 +336,7 @@
if (!ast_sockaddr_isnull(&transport_state->external_signaling_address)) {
/* Update the contact header with the external address */
if (uri || (uri = nat_get_contact_sip_uri(tdata))) {
- pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));
+ //pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));
if (transport->external_signaling_port) {
uri->port = transport->external_signaling_port;
ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);