#
# $Id$
#
# simple quick-start config script
#

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

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

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

#listen=192.168.80.64
#port=5060
#children=4

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

#check_via=no	# (cmd. line: -v)

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

loadmodule "/usr/local/lib/ser/modules/sl.so"		
loadmodule "/usr/local/lib/ser/modules/tm.so"		
loadmodule "/usr/local/lib/ser/modules/maxfwd.so"	

loadmodule "/usr/local/lib/ser/modules/sms.so"

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

# -- sms params --

modparam("sms", "modems", "Nokia[d=/dev/ttyS1;s=0;t=sip:p-cscf@cidra.com.ar;c=+543411234567]")
modparam("sms", "networks", "D1 [m=10]")
modparam("sms", "links", "NOKIA[D1]")
#modparam("sms", "domain_str", "cidra.com.ar")

# -------------------------  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");
		break;
	};

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

	# El GW sms2sip solo procesa MESSAGEs
	if (!method=="MESSAGE") {
		sl_send_reply("502","Bad gateway - SMS error");
		break;
	};

	# El GW sms2sip solo procesa paquetes dirigidos a el
	if (!uri==myself) {
		sl_send_reply("502","Bad gateway - SMS error");
		break;
	};

	# Put the SIP msg in the specified network queue.
	if (sms_send_msg_to_net("D1")) {
		if (!t_reply("202", "yes sir, SMS sent over")) {
			# if replying failed, retry statelessly
			sl_reply_error();
		};
	} 
	else {
		if (!t_reply("502", "Bad gateway - SMS error"))	{
			# if replying failed, retry statelessly
			sl_reply_error();
		};
		break;
	};
}
