#
# sample config script to use speeddial module
#

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

check_via=no	# (cmd. line: -v)
dns=no          # (cmd. line: -r)
rev_dns=no      # (cmd. line: -R)

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

loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "mysql.so"
loadmodule "speeddial.so"
loadmodule "jsonrpcs.so"

# ----------------- setting module-specific parameters ---------------

# -- usrloc params --

modparam("usrloc", "db_mode",   0)

# -- rr params --
# add value to ;lr param to make some broken UAs happy
modparam("rr", "enable_full_lr", 1)

# -------------------------  request routing logic -------------------

# main routing logic
route{

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

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

	if (loose_route())
	{
		if (!t_relay())
		{
			sl_reply_error();
		};
		exit;
	};

	if (!uri==myself)
	{
		if (!t_relay())
		{
			sl_reply_error();
		};
		exit;
	};

	if (uri==myself)
	{
		if (method=="REGISTER")
		{
			save("location");
			exit;
		};

		if(uri=~"sip:[0-9]{2}@.*")
			sd_lookup("speeddial");

		lookup("aliases");
		if (!uri==myself)
		{
			if (!t_relay())
			{
				sl_reply_error();
			};
			exit;
		};

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

	if (!t_relay())
	{
		sl_reply_error();
	};
}

