#
# $Id$
#
# this example shows how to use forking on failure
#

log_stderror=1
fork=no
listen=192.168.2.16
debug=3
# ------------------ module loading ----------------------------------

# Uncomment this if you want to use SQL database
loadmodule "modules/tm/tm.so"
loadmodule "modules/sl/sl.so"
loadmodule "modules/maxfwd/maxfwd.so"
# -------------------------  request routing logic -------------------

# main routing logic

route{

	# initial sanity checks -- messages with
	# max_forwards==0, or excessively long requests
	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483", "Too Many Hops");
		break;
	};
	if (len_gt( max_len )) {
		sl_send_reply("513", "Message too big");
		break;
	};

	/* skip register for testing purposes */
	if (method=="REGISTER") { sl_send_reply("200", "ok"); break; };

	if (!method=="ACK")
		log(1, "forwarding now to primary destination\n");
	if (method=="INVITE") {
		rewriteuri("sip:xxx@192.168.2.16:5064");
		# if transaction is broken, try an alternative route
		t_on_failure("1");
		# if a provisional came, stop alternating
		t_on_reply("1");
	};
	t_relay();
}

failure_route[1] {
	log(1, "trying at alternate destination\n");
	append_branch("sip:yyy@192.168.2.16:5064");
	t_relay();
}

onreply_route[1] {
	log(1, "reply came in\n");
	if (status=~"18[0-9]")  {
		log(1, "provisional -- resetting negative failure\n");
		t_on_failure("0");
	};
}
