#
# $Id$
#
# example script showing use of nathelper module with RTP proxy
# (incomplete for sake of brevity)
#

# ----------- global configuration parameters ------------------------

# debugging mode
debug=3          
fork=no
log_stderror=yes

# ------------------ module loading ----------------------------------

loadmodule "modules/nathelper/nathelper.so"
loadmodule "modules/rtpproxy/rtpproxy.so"
loadmodule "modules/textops/textops.so"
loadmodule "modules/tm/tm.so"
loadmodule "modules/rr/rr.so"
loadmodule "modules/registrar/registrar.so"
loadmodule "modules/usrloc/usrloc.so"
loadmodule "modules/sl/sl.so"


# ------------------ request-routing script --------------------------

# main routing logic

route{

	# compulsory processing of Route header fields and adding RR
	loose_route();

	# ATA's are symmetric but don't advertise it -- force use of rport 
	if (search("User-Agent: Cisco ATA.*")) {
		setflag(1); # remember this is ATA
		force_rport();
		fix_nated_contact();
	};

	/* registration (uses rewritten contacts) */
	if (method=="REGISTER") {
		save("foo.bar.com");
		break;
	};

	if (method=="INVITE") {
		record_route();
		if (isflagset(1)) { # ATA ?
			force_rtp_proxy();
		};
		/* set up reply processing */
		t_on_reply("1");
	};

	if (method == "INVITE" || method == "CANCEL") {
		if (!lookup("foo.bar.com")) {
			sl_send_reply("404", "Not Found");
			break;
		};
	};

	/* set up reply processing and forward statefully */
	t_relay();
}

# all incoming replies for t_onrepli-ed transactions enter here
onreply_route[1] {
	if (status=~"2[0-9][0-9]" && search("Server: Cisco ATA.*"))
		fix_nated_contact();
		force_rtp_proxy();
}
