#
# configuration for Jabber module testing
# (sample config file using the module with presence support)
#
# $ID: daniel $
#


debug=9          # debug level (cmd line: -dddddddddd)
#fork=yes          # (cmd. line: -D)
fork=no
log_stderror=yes  # (cmd line: -E)
#log_stderror=no   # (cmd line: -E)


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

listen=10.0.0.179
port=5060

# for more info: sip_router -h

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

#modules
loadmodule "modules/print/print.so"
loadmodule "modules/textops/textops.so"
loadmodule "modules/tm/tm.so"

loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/sl/sl.so"
loadmodule "modules/mysql/mysql.so"
loadmodule "modules/jabber/jabber.so"
loadmodule "modules/registrar/registrar.so"
loadmodule "modules/usrloc/usrloc.so"
loadmodule "modules/pa/pa.so"
loadmodule "modules/mi_fifo/mi_fifo.so"

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

# -- mi_fifo params --

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

# -- registrar params --

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

# -- usrloc params --
modparam("usrloc", "use_domain", 1)
modparam("usrloc", "db_mode", 0)

# -- jabber params --

modparam("jabber","db_url","mysql://user:password@127.0.0.1/sip_jab")
modparam("jabber","jaddress","jabber.server.com")
modparam("jabber","jport",5222)
modparam("jabber","workers",2)
modparam("jabber","max_jobs",10)
modparam("jabber","cache_time",200)
modparam("jabber","delay_time",60)
modparam("jabber","jdomain","jabber.server.com=*")
modparam("jabber","aliases","4;aim.jabber.server.com;icq.jabber.server.com;msn.jabber.server.com=%;yahoo.jabber.server.com;")

route{

	#if ( !mf_process_maxfwd_header("10") )
	#{
	#	sl_send_reply("483","To Many Hops");
	#	drop();
	#};
    
	if (uri=~"[@:]sip\.server\.com([;:].*)*")
	{
		# for testing purposes, simply okay all REGISTERs
		if (method=="REGISTER")
		{
			if (t_newtran()) 
			{
				save("location");
				log("REGISTER received -> reply okay\n");
			};
			if(search("egistration"))
			{
				log("XJAB: Going ONline in Jabber network!!!\n");
				if(jab_go_online())
				{
					sl_send_reply("200", "Accepted");
				}
				else
				{
					sl_send_reply("404","Not found");
				};
			}
			else
			{
				log("XJAB: Going OFFline in Jabber network!!!\n");
				if(jab_go_offline())
				{
					sl_send_reply("200", "Accepted");
				}
				else
				{
					sl_send_reply("404","Not found");
				};
			};
			break;
		};
		if (method=="SUBSCRIBE") 
		{
			if (t_newtran()) 
			{
				subscribe("registrar");
			};
			break;
		};
		if(!lookup("location"))
		{
			sl_send_reply("404","Not found");
			break;
		};
	};							
    
	if ((search("To:.*@icq\.jabber\.server\.com"))
        || (search("To:.*@jabber\.server\.com"))
        || (search("To:.*@msn\.jabber\.server\.com"))
        || (search("To:.*@yahoo\.jabber\.server\.com")))
    {
	    if (! t_newtran())
    	{
			sl_reply_error();
			break;
	    };
		if (method=="MESSAGE")
		{
	    	log("MESSAGE received -> manage it with XJAB\n");
		    if(search("\n:on"))
			{
				if (jab_go_online())
			    {
					sl_send_reply("200","Accepted");
			    }else{
					sl_send_reply("404","Not found");
		    	};
				break;
			};
		    if(search("\n:off"))
			{
				if (jab_go_offline())
			    {
					sl_send_reply("200","Accepted");
			    }else{
					sl_send_reply("404","Not found");
		    	};
				break;
			};
			
		    if(search("\n:join"))
			{
				if (jab_join_jconf())
			    {
					sl_send_reply("200","Accepted");
			    }else{
					sl_send_reply("404","Not Found");
		    	};
				break;
			};
		    
			if(search("\n:exit"))
			{
				if (jab_exit_jconf())
			    {
					sl_send_reply("200","Accepted");
			    }else{
					sl_send_reply("404","Not Found");
		    	};
				break;
			};
			
			if (jab_send_message())
		    {
				sl_send_reply("200","Accepted");
		    }else{
				sl_send_reply("503","Service Unavailable");
	    	};
			break;
		};
		if (method=="SUBSCRIBE") {
			subscribe("jabber");
			break;
		};
	    log("NON_Message request received for JABBER gateway->dropt!\n");
    	sl_send_reply("202","Accepted");
		break;
    };
	if (!t_relay()) 
	{
		sl_reply_error();
	};

    #forward(uri:host,uri:port);
}
