[Asterisk-code-review] res_pjsip_transport_websocket: save the original contact host (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Fri May 13 09:06:36 CDT 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18531 )
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(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
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/+/18531
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I0c5823918199acf09246b3b206fbde66773688f6
Gerrit-Change-Number: 18531
Gerrit-PatchSet: 2
Gerrit-Owner: Thomas Guebels <tgu at escaux.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220513/a4eb1abd/attachment-0001.html>
More information about the asterisk-code-review
mailing list