[asterisk-commits] file: branch file/pimp_sip_nat r381755 - /team/file/pimp_sip_nat/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 19 11:20:21 CST 2013


Author: file
Date: Tue Feb 19 11:20:17 2013
New Revision: 381755

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381755
Log:
Add a test module which rewrites the Contact header of incoming requests to contact the source IP address and port.

Added:
    team/file/pimp_sip_nat/res/res_sip_nat.c   (with props)

Added: 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=auto&rev=381755
==============================================================================
--- team/file/pimp_sip_nat/res/res_sip_nat.c (added)
+++ team/file/pimp_sip_nat/res/res_sip_nat.c Tue Feb 19 11:20:17 2013
@@ -1,0 +1,72 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#undef bzero
+#define bzero bzero
+#include <pjsip.h>
+#include <pjsip_ua.h>
+
+#include "asterisk/res_sip.h"
+#include "asterisk/module.h"
+
+static pj_bool_t nat_on_rx_request(pjsip_rx_data *rdata)
+{
+	pjsip_contact_hdr *contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+	pjsip_sip_uri *uri;
+
+	if (!contact || !(PJSIP_URI_SCHEME_IS_SIP(contact->uri) && !PJSIP_URI_SCHEME_IS_SIPS(contact->uri))) {
+		return PJ_FALSE;
+	}
+
+	uri = pjsip_uri_get_uri(contact->uri);
+	pj_cstr(&uri->host, rdata->pkt_info.src_name);
+	uri->port = rdata->pkt_info.src_port;
+
+	return PJ_FALSE;
+}
+
+static pjsip_module nat_module = {
+	.name = { "NAT", 3 },
+	.id = -1,
+	.priority = PJSIP_MOD_PRIORITY_TSX_LAYER,
+	.on_rx_request = nat_on_rx_request,
+};
+
+static int load_module(void)
+{
+	ast_sip_register_service(&nat_module);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	ast_sip_unregister_service(&nat_module);
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP NAT Support",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_APP_DEPEND,
+	       );

Propchange: team/file/pimp_sip_nat/res/res_sip_nat.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/file/pimp_sip_nat/res/res_sip_nat.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/file/pimp_sip_nat/res/res_sip_nat.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list