[asterisk-commits] file: branch file/pimp_sip_nat r382337 - /team/file/pimp_sip_nat/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 1 07:16:43 CST 2013
Author: file
Date: Fri Mar 1 07:16:40 2013
New Revision: 382337
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382337
Log:
Rewrite, rewrite, rewrite.
Modified:
team/file/pimp_sip_nat/res/res_sip_nat.c
Modified: team/file/pimp_sip_nat/res/res_sip_nat.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_nat/res/res_sip_nat.c?view=diff&rev=382337&r1=382336&r2=382337
==============================================================================
--- team/file/pimp_sip_nat/res/res_sip_nat.c (original)
+++ team/file/pimp_sip_nat/res/res_sip_nat.c Fri Mar 1 07:16:40 2013
@@ -101,14 +101,14 @@
return pjsip_uri_get_uri(contact->uri);
}
-static pj_status_t nat_on_tx_request(pjsip_tx_data *tdata)
+static pj_status_t nat_on_tx_message(pjsip_tx_data *tdata)
{
RAII_VAR(struct ao2_container *, transports, NULL, ao2_cleanup);
RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
struct request_transport_details details = { 0, };
pjsip_via_hdr *via = NULL;
struct ast_sockaddr addr = { { 0, } };
- pjsip_sip_uri *uri;
+ pjsip_sip_uri *uri = NULL;
/* If a transport selector is in use we know the transport or factory, so explicitly find it */
if (tdata->tp_sel.type == PJSIP_TPSELECTOR_TRANSPORT) {
@@ -129,9 +129,20 @@
return PJ_SUCCESS;
}
- via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
- details.local_address = via->sent_by.host;
- details.local_port = via->sent_by.port;
+ if ((uri = nat_get_contact_sip_uri(tdata))) {
+ details.local_address = uri->host;
+ details.local_port = uri->port;
+ } else if ((tdata->msg->type == PJSIP_REQUEST_MSG) &&
+ (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL))) {
+ details.local_address = via->sent_by.host;
+ details.local_port = via->sent_by.port;
+ } else {
+ return PJ_SUCCESS;
+ }
+
+ if (!details.local_port) {
+ details.local_port = (details.type == AST_SIP_TRANSPORT_TLS) ? 5061 : 5060;
+ }
}
if (!(transports = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "transport", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL)) ||
@@ -148,21 +159,19 @@
return PJ_SUCCESS;
}
- if (!via) {
- via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
- }
-
- /* Update the via header with the external address */
- pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport->external_address));
- if (transport->external_signaling_port) {
- via->sent_by.port = transport->external_signaling_port;
- }
-
/* Update the contact header with the external address */
- if ((uri = nat_get_contact_sip_uri(tdata))) {
- uri->host = via->sent_by.host;
+ if (uri || (uri = nat_get_contact_sip_uri(tdata))) {
+ pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport->external_address));
if (transport->external_signaling_port) {
uri->port = transport->external_signaling_port;
+ }
+ }
+
+ /* Update the via header if relevant */
+ if ((tdata->msg->type == PJSIP_REQUEST_MSG) && (via || (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL)))) {
+ pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport->external_address));
+ if (transport->external_signaling_port) {
+ via->sent_by.port = transport->external_signaling_port;
}
}
@@ -174,7 +183,8 @@
.id = -1,
.priority = PJSIP_MOD_PRIORITY_TRANSPORT_LAYER + 4,
.on_rx_request = nat_on_rx_request,
- .on_tx_request = nat_on_tx_request,
+ .on_tx_request = nat_on_tx_message,
+ .on_tx_response = nat_on_tx_message,
};
static int load_module(void)
More information about the asterisk-commits
mailing list