#
# IMCONF usage example
#
#


debug=2           # debug level (cmd line: -dddddddddd)
fork=no           # don't fork
log_stderror=yes  # log to stderr (cmd line: -E)


children=0        # number of children
check_via=no      # (cmd. line: -v)
dns=off           # (cmd. line: -r)
rev_dns=off       # (cmd. line: -R)
port=5060

alias="stefan.lo"

# ------------------ module loading ----------------------------------
mpath="/usr/local/lib64/kamailio/modules"

loadmodule "db_mysql.so"

loadmodule "textops.so"

loadmodule "sl.so"
loadmodule "maxfwd.so"
loadmodule "imc.so"
loadmodule "tm.so"
loadmodule "xlog.so"
loadmodule "registrar.so"
loadmodule "usrloc.so"
loadmodule "mi_fifo.so"

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

# -- mi_fifo params --

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

# -- usrloc params --

modparam("usrloc", "db_mode", 2)

# -- registrar params --

modparam("registrar", "default_expires", 120)

# -- registrar params --

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

# -- imc params --
modparam("imc", "imc_cmd_start_char", "#")
modparam("imc|usrloc", "db_url", "mysql://kamailio:kamailiorw@192.168.2.132/kamailio")

# -- tm params --

modparam("tm", "fr_timer", 10 )
modparam("tm", "fr_inv_timer", 15 )
modparam("tm", "wt_timer", 10 )


route{
    	if ( !mf_process_maxfwd_header("10") )
    	{
        	sl_send_reply("483","To Many Hops");
        	drop();
    	};

        # registrations -
	if(is_method("REGISTER")) {
		save("location");
		exit;
	}
        
	if(uri=~"sip:q.*@")
	{
	        # IMC - message
		xdbg("script: message from [$fu] r-uri [$ru] msg [$rb]\n");
		if(is_method("MESSAGE"))
		{
			log("MESSAGE received -> processing with imc\n");
			sl_send_reply("200", "ok");
			imc_manager();			
			exit;
		} else {
			sl_send_reply("404", "not found");
			exit;
		};
   	} else {
		xdbg("script: message not for room, from [$fu] r-uri [$ru] msg [$rb]\n");
		if(!lookup("location"))
		{
			sl_send_reply("404", "not found");
			exit;
		}
		t_relay();
		exit();
	};
}
