debug=0
listen=127.0.0.1
port=5059

loadmodule "tm/tm.so"
loadmodule "sl/sl.so"
loadmodule "usrloc/usrloc.so"
loadmodule "registrar/registrar.so"
loadmodule "xlog/xlog.so"
loadmodule "db_mysql/db_mysql.so"
loadmodule "pv/pv.so"
loadmodule "userblacklist/userblacklist.so"
loadmodule "maxfwd/maxfwd.so"
loadmodule "mi_fifo/mi_fifo.so"

modparam("usrloc", "db_mode", 3)
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
modparam("userblacklist", "match_mode", 128)

request_route {
	#xlog("user: $rU\n");

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

	$avp(i:80) = $rU;
	$avp(i:81) = $rd;

	if(!lookup ("location")){
		sl_send_reply("404", "Not Found");
		exit;
	}

	if (!check_user_blacklist("$avp(i:80)", "$avp(i:81)")) {
		xlog("$rU user blacklisted\n");
		sl_send_reply("403", "Forbidden");
		exit;
	}

	if (!check_blacklist("globalblacklist")) {
		xlog("$rU globally blacklisted\n");
		sl_send_reply("403", "Forbidden");
		exit;
	}
	xlog("$rU not blacklisted\n");

	t_relay();
}