debug=2
loadmodule "db_mysql"
loadmodule "corex"
loadmodule "tm"
loadmodule "sl"
loadmodule "xlog"
loadmodule "maxfwd"
loadmodule "carrierroute"
loadmodule "pv"
loadmodule "tmx"
loadmodule "mi_fifo"

modparam("carrierroute", "config_source", "db")

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

request_route {
	# initial sanity checks
	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483", "Too Many Hops");
		return;
	};
	cr_user_carrier("$fU", "$fd", "$avp(s:11)");
	$avp(s:10)="start";
	if (!cr_route("$avp(s:11)", "$avp(s:10)", "$rU", "$rU", "call_id", "$avp(s:12)")) {
		xlog("L_ERR", "cr_route failed\n");
		exit;
	}
	t_on_failure("1");
	if (!t_relay()) {
		sl_reply_error();
	}
}

failure_route[1] {
	revert_uri();
	if (!cr_next_domain("$avp(s:11)", "$avp(s:10)", "$rU", "$avp(s:12)", "$T_reply_code", "$avp(s:10)")) {
		xlog("L_ERR", "cr_next_domain failed\n");
		exit;
	}
	if (!cr_route("$avp(s:11)", "$avp(s:10)", "$rU", "$rU", "call_id", "$avp(s:12)")) {
		xlog("L_ERR", "cr_route failed\n");
		exit;
	}
	t_on_failure("1");
	append_branch();
	if (!t_relay()) {
		xlog("L_ERR", "t_relay failed\n");
		exit;
	}
}
