#
# $Id$
#
#

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

debug=9          # debug level (cmd line: -dddddddddd)
fork=no
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=5070
listen=193.175.132.164  #hope
#listen=193.175.135.190  #oxany

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

loadmodule "modules/sl/sl.so"
loadmodule "modules/print/print.so"
loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/usrloc/usrloc.so"
loadmodule "modules/rr/rr.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;
	};

	# Do strict routing if route headers present
	rewriteFromRoute();

	# sign of our domain: there is @ (username), :
    	# (nothing) or . (host) in front of our domain name	
	if (!(uri=~"[@:\.]hope\.fokus\.gmd\.de([;:].*)*")) {
		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;
	};

	if (method=="MESSAGE") {
		addRecordRoute();
		if (uri=~"sip:[0-9]+@") {
			rewritehostport("fesarius.fokus.gmd.de:5070");
			forward(uri:host,uri:port);
			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(uri:host,uri:port);
}