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

# ------------------ module loading ----------------------------------
loadpath "../../modules/:../../modules_k/"
loadmodule "tm"
loadmodule "sl"
loadmodule "rr"
loadmodule "maxfwd"
loadmodule "textops"
loadmodule "xlog"
loadmodule "pv"
loadmodule "../../modules/db_mysql/db_mysql.so"

loadmodule "mi_fifo"
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")

loadmodule "p_usrloc"
modparam("p_usrloc", "db_mode", 3)
modparam("p_usrloc", "read_db_url", "mysql://ser:ser@localhost/ser")
modparam("p_usrloc", "write_db_url", "mysql://ser:ser@localhost/ser")

modparam("p_usrloc", "write_on_db", 1)
#modparam("p_usrloc", "write_on_master_db", 1)
modparam("p_usrloc", "alg_location", 1)

modparam("p_usrloc", "reg_db_table", "locdb")

loadmodule "registrar"
modparam("registrar", "min_expires", 60)


#-------------------------  request routing logic -------------------
route{

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

	if (msg:len >=  2048 ) {
		sl_send_reply("513", "Message Too Large");
		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: p_usrloc applied\r\n");
	}

	route(1);
}

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