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

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

debug=9          # debug level (cmd line: -dddddddddd)
fork=yes
children=2
#log_stderror=no	# (cmd line: -E)
log_stderror=yes	# (cmd line: -E)
check_via=yes     # (cmd. line: -v)
dns=on           # (cmd. line: -r)
rev_dns=yes      # (cmd. line: -R)
port=5060
#listen=192.168.57.66
#listen=192.168.50.66
#listen=3ffe:400:190:50:201:2ff:fedd:5050
listen=3ffe:400:190:56:201:2ff:fedd:52b5

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

loadmodule "modules/sl/sl.so"
loadmodule "modules/print/print.so"
loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/usrloc/usrloc.so"

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

# -- usrloc params --
modparam("usrloc", "use_database",   0)

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

# main routing logic

route{
	# filter local stateless ACK generated by authentication of mf replies
	sl_filter_ACK();

	# filter too old messages
	log("LOG: Checking maxfwd\n");
	if (!mf_process_maxfwd_header("10")) {
		log("LOG: Too many hops\n");
		sl_send_reply("483", "Too Many Hops");
		break;
	};
	
	# sign of our domain: there is @ (username), :
    	# (nothing) or . (host) in front of our domain name	
	if (!(uri=~"[@:\.]lugduf-1\.mobis\.ip6([;:].*)*")) {
		route(2);
		# break from route (2) return -- stop then !
		break;
	};
	# here we continue with requests for our domain...

	if (method=="REGISTER") {
		log("LOG Request is REGISTER\n");
		# update Contact database
       		log("LOG: REGISTER -> saving location\n");
		save_contact("location");
		break;
	};

        # native SIP destinations are handled using our USRLOC DB
	if (!lookup_contact("location")) {
		if (method=="ACK") {
			log("Ooops -- an ACK made it here -- probably UAC screwed up to-tags\n");
			break;
		};
		log("LOG: Unable to lookup contact, sending 404\n");
		sl_send_reply("404", "Not Found");
		break;
	};
	forward(uri:host,uri:port);
}

# routing logic for outbound requests targeted out of our domain
route[2] {
	forward("xhosa.mobis.ip6",5060);
}
