#
# $Id$
#
# this example shows use of ser as stateless redirect server
# which rewrites URIs using an exernal utility
#

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

debug=4
fork=1
log_stderror=yes	# (cmd line: -E)
check_via=no # (cmd. line: -v)
dns=no # (cmd. line: -r)
syn_branch=1
reply_to_via=0

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

loadmodule "/usr/lib/ser/modules/sl.so"
loadmodule "/usr/lib/ser/modules/print.so"
loadmodule "/usr/lib/ser/modules/exec_mod.so"
loadmodule "/usr/lib/ser/modules/ext.so"

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

# main routing logic

route{
	# for testing purposes, simply okay all REGISTERs
	if (method=="REGISTER") {
		log("REGISTER");
		sl_send_reply("200", "ok");
		break;
	};

	# obsoleted
	#ext_rewriteuri("echo sip:jiri@iptel.org; echo >/dev/null");
	#break;

	# first dump the message to a file using cat command
	exec_msg("printenv SRCIP > /tmp/exectest.txt; cat >> /tmp/exectest.txt");
	# and then rewrite URI using external utility
	# note that the last echo command trashes input parameter
	if (exec_uri("echo sip:mra@iptel.org;echo sip:mrb@iptel.org;echo>/dev/null")) {

	#if (exec_uri("/tmp/sh.sh")) {
		sl_send_reply("300", "Redirect");
	} else {
		sl_reply_error();
		log(1, "alas, rewriting failed\n");
	};
}