[Asterisk-code-review] res_pjsip_transport_websocket: save the original contact host (asterisk[19])
Thomas Guebels
asteriskteam at digium.com
Thu May 5 08:20:14 CDT 2022
Thomas Guebels has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18511 )
Change subject: res_pjsip_transport_websocket: save the original contact host
......................................................................
res_pjsip_transport_websocket: save the original contact host
This is needed to be able to restore it in REGISTER responses,
otherwise the client won't be able to find the contact it created.
ASTERISK-30042
Change-Id: I0c5823918199acf09246b3b206fbde66773688f6
---
M res/res_pjsip_transport_websocket.c
1 file changed, 30 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/11/18511/1
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index 1b882da..9894a8c 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -415,6 +415,32 @@
ast_websocket_unref(session);
}
+static void save_orig_contact_host(pjsip_rx_data *rdata, pjsip_sip_uri *uri)
+{
+ pjsip_param *x_orig_host;
+ pj_str_t p_value;
+#define COLON_LEN 1
+#define MAX_PORT_LEN 5
+
+ if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG ||
+ rdata->msg_info.msg->line.req.method.id != PJSIP_REGISTER_METHOD) {
+ return;
+ }
+
+ ast_debug(1, "Saving contact '%.*s:%d'\n",
+ (int)uri->host.slen, uri->host.ptr, uri->port);
+
+ x_orig_host = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
+ x_orig_host->name = pj_strdup3(rdata->tp_info.pool, "x-ast-orig-host");
+ p_value.slen = pj_strlen(&uri->host) + COLON_LEN + MAX_PORT_LEN;
+ p_value.ptr = (char*)pj_pool_alloc(rdata->tp_info.pool, p_value.slen + 1);
+ p_value.slen = snprintf(p_value.ptr, p_value.slen + 1, "%.*s:%d", (int)uri->host.slen, uri->host.ptr, uri->port);
+ pj_strassign(&x_orig_host->value, &p_value);
+ pj_list_insert_before(&uri->other_param, x_orig_host);
+
+ return;
+}
+
/*!
* \brief Store the transport a message came in on, so it can be used for outbound messages to that contact.
*/
@@ -436,6 +462,10 @@
pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);
const pj_str_t *txp_str = &STR_WS;
+ /* Saving the contact on REGISTER so it can be restored on outbound response
+ * This will actually be done by restore_orig_contact_host in res_pjsip_nat, via nat_on_tx_message */
+ save_orig_contact_host(rdata, uri);
+
if (DEBUG_ATLEAST(4)) {
char src_addr_buffer[AST_SOCKADDR_BUFLEN];
const char *ipv6_s = "", *ipv6_e = "";
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18511
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I0c5823918199acf09246b3b206fbde66773688f6
Gerrit-Change-Number: 18511
Gerrit-PatchSet: 1
Gerrit-Owner: Thomas Guebels <tgu at escaux.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220505/ecebed4c/attachment-0001.html>
More information about the asterisk-code-review
mailing list