#
# $Id$
#
# simple quick-start config script for XMPP GW
#
# make sure in your main SIP server that you send
# only the adequate SIP MESSAGES to XMPP GW
#
#
# ----------- global configuration parameters ------------------------

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

/* Uncomment these lines to enter debugging mode 
fork=no
log_stderror=yes
*/

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

listen=udp:10.10.10.10:5076
alias=sip-xmpp.kamailio.org

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

mpath="/usr/local/lib/kamailio/modules/"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "mi_fifo.so"


# XMPP
loadmodule "xmpp.so"

modparam("xmpp", "domain_separator", "*")
modparam("xmpp", "gateway_domain", "sip-xmpp.kamailio.org")
modparam("xmpp", "xmpp_domain", "xmpp-sip.kamailio.org")
modparam("xmpp", "xmpp_host", "xmpp.kamailio.org")

modparam("xmpp", "backend", "server")
# modparam("xmpp", "backend", "component")

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

# -- mi_fifo params --

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

# -- usrloc params --

# -- 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 -- messages with
	# max_forwards==0, or excessively long requests
	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		exit;
	};

	if (msg:len >=  2048 ) {
		sl_send_reply("513", "Message too big");
		exit;
	};

	### absorb retransmissions ###
	if (!t_newtran()) {
		sl_reply_error();
		return;
	}
	if (method == "MESSAGE") {
		log("*** xmpp-handled MESSAGE message.\n");
		if (xmpp_send_message()) {
			t_reply("200", "Accepted");
		} else {
			t_reply("404", "Not found");
		}
		return;
	}
		
	log("*** xmpp: unhandled message type\n");
	t_reply("503", "Service unavailable");
	return;
}

