# ----------- global configuration parameters ------------------------
debug=2
fork=yes
log_stderror=no
children=1
disable_tcp=yes

alias=localhost

#!trydef DBMOD	"db_mysql"
loadmodule DBMOD

loadmodule "tm"
loadmodule "sl"
loadmodule "rr"
loadmodule "maxfwd"
loadmodule "textops"
loadmodule "xlog"
loadmodule "pv"
loadmodule "mi_fifo"
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")

loadmodule "usrloc"
modparam("usrloc", "db_mode", 1)

loadmodule "registrar"
modparam("registrar", "min_expires", 5)
modparam("usrloc", "timer_interval", 1)

#!trydef FETCHROWS	2000
modparam("usrloc", "fetch_rows", FETCHROWS)

#!trydef DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
modparam("usrloc", "db_url", DBURL)

#-------------------------  request routing logic -------------------
request_route {

	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483", "Too Many Hops");
		exit;
	}

	if (!method=="REGISTER")
		record_route();

	if (loose_route()) {
		# mark routing logic in request
		append_hf("P-hint: rr-enforced\r\n");
		route(1);
	}

	if (!uri==myself) {
		append_hf("P-hint: outbound\r\n");
		route(1);
	}

	if (uri==myself) {
		if (method=="REGISTER") {
			save("location");
			exit;
		}
		if (!lookup("location")) {
			sl_send_reply("404", "Not Found");
			exit;
		}
		append_hf("P-hint: usrloc applied\r\n");
	}

	route(1);
}

route[1] {
	if (!t_relay()) {
		sl_reply_error();
	}
	exit;
}

