#
# $Id$
#
# iptel.org real world configuration
#

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

#debug=8          # debug level (cmd line: -dddddddddd)
debug=3
fork=no
children=2
#log_stderror=no	# (cmd line: -E)
log_stderror=yes	# (cmd line: -E)
check_via=yes     # (cmd. line: -v)
dns=no           # (cmd. line: -r)
rev_dns=no	# (cmd. line: -R)
port=5060
#port=8060

fifo="/tmp/ser_fifo"

# advertise IP address in Via (as opposed to advertising DNS name
# which is annoying for downstream servers and some phones can
# not handle DNS at all)
#listen=195.37.77.100
#listen=127.0.0.1

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

loadmodule "../sip_router/modules/sl/sl.so"
loadmodule "../sip_router/modules/print/print.so"
loadmodule "../sip_router/modules/tm/tm.so"
loadmodule "../sip_router/modules/acc/acc.so"
loadmodule "../sip_router/modules/rr/rr.so"
loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
loadmodule "../sip_router/modules/usrloc/usrloc.so"
loadmodule "../sip_router/modules/registrar/registrar.so"

# ----------------- setting module-specific parameters ---------------

# -- usrloc params --


# -- acc params --
# report ACKs too for sake of completeness -- as we account PSTN
# destinations which are RR, ACKs should show up
modparam("acc", "report_ack", 1)
# don't bother me with early media reports (I don't like 183 
# too much anyway...ever thought of timer C hitting after
# listening to music-on-hold for five minutes?)
modparam("acc", "early_media", 0)
modparam("acc", "log_level", 1)
# that is the flag for which we will account -- don't forget to
# set the same one :-)
modparam("acc", "acc_flag", 3 )
# we are interested only in succesful transactions
modparam("acc", "failed_transactions", 0 )
modparam("acc", "missed_flag", 2 )

# -- tm params --
modparam("tm", "fr_timer", 103 )
modparam("tm", "retr_timer1p1", 4 )
modparam("tm", "fr_inv_timer", 4 )
modparam("tm", "wt_timer", 8 )
modparam("tm", "noisy_ctimer", 0 )

# -------------------------  request routing logic -------------------

# main routing logic

route{
	# for testing purposes, simply okay all REGISTERs
	if (method=="REGISTER") {
		log("REGISTER");
		sl_send_reply("200", "ok");
		#t_replicate("localhost", "9");
		break;
	};

	if (!t_relay_to("fox.iptel.org", "12345" )) {
		sl_reply_error();
	};
	/* t_reply("100", "trying"); */
	break;

	#rewritehost("iptel.org");
	if (!t_relay()) {
		sl_reply_error();
	};
	break;

	# print a message if a call was missed
	setflag(2);

	rewriteuri("a@blb.com");
	append_branch("b@blb.com");
	append_branch("c@blb.com");

#	forward( "fox.iptel.org", 9 );
	t_relay_to("bat.iptel.org", "5088");
#	t_relay();
}

route[3] {
	lookup("location");
}

reply_route[1] {
	# revert to original inbound uri -- good if we want
	# to modify it; if we rewrite it completely as in the 
	# line after it, it is actually useless
	revert_uri();
	# this one will return 404 too
	rewriteuri("sip:nonsense@iptel.org");
	append_branch();
	# and if we don't yet get a positive reply (we won't --
	# we will receive 404", try another forking destination
	t_on_negative("2");
}

reply_route[2] {
	revert_uri();
	rewriteuri("sip:foo@iptel.org");
	# give it one more try; if it fails too (it will, there
	# is no foo), a lowest-code message will be relayed
	# upstream
	append_branch();
}