[Serusers] sems voicemail: t_relay / t_newtran and socket closing problem

Dennis Real dennis.real at helinet.de
Thu Jun 9 14:59:50 CEST 2005


Hi,

I have a strange problem with stateful processing using t_relay and t_newtran. 
For normal routing I use t_relay but all sems modules require the usage of 
t_newtran, e.g.: 

	if ( !t_newtran() ) 
	{
    		sl_reply_error();
	};
	t_write_unix("/tmp/am_sock", "voicemail");

The problem now is how to handle BYE and CANCEL messages for deestablishing 
connections. For the echo server (reachable at 4242 at 192.168.11.1) I use the 
following code for getting back transaction and closing socket to sems:

	if ( uri=~"^sip:4242@" && ( method=="BYE" || method=="CANCEL" ) )
	{
		if (!t_newtran())
		{
			sl_send_reply("500", "could not create transaction");
			break;
		};
	
		if( !t_write_unix("/tmp/am_sock", "bye") ) 
		{
		    t_reply("500", "error contacting sems");
		};

		break;

	}

This works fine. But how can I do this for voicemail? The uri will not be 
changed so I can't destinguish between BYE for a normal and a voicemail 
connection.

All other destinations do not use t_newtran (and no socket to sems) so simply 
t_relay is used for BYE and CANCEL messages.

The whole ser.cfg is attached below.

Regards and thanks for your help,
Dennis



# ser.cfg
# ----------- global configuration parameters ------------------------

debug=3
fork=yes
log_stderror=yes
check_via=no
dns=no      
rev_dns=no  
fifo="/tmp/ser_fifo"
fifo_mode=0666
fifo_db_url="mysql://ser:heslo@localhost/ser"
listen=192.168.11.1
listen=127.0.0.1
alias=192.168.11.1
alias=127.0.0.1

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

loadmodule "/usr/local/lib/ser/modules/mysql.so"
loadmodule "/usr/local/lib/ser/modules/sl.so"
loadmodule "/usr/local/lib/ser/modules/tm.so"
loadmodule "/usr/local/lib/ser/modules/rr.so"
loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
loadmodule "/usr/local/lib/ser/modules/usrloc.so"
loadmodule "/usr/local/lib/ser/modules/registrar.so"
loadmodule "/usr/local/lib/ser/modules/auth.so"
loadmodule "/usr/local/lib/ser/modules/auth_db.so"
loadmodule "/usr/local/lib/ser/modules/acc.so"
loadmodule "/usr/local/lib/ser/modules/exec.so"
loadmodule "/usr/local/lib/ser/modules/group.so"
loadmodule "/usr/local/lib/ser/modules/msilo.so"
loadmodule "/usr/local/lib/ser/modules/print.so"
loadmodule "/usr/local/lib/ser/modules/textops.so"
loadmodule "/usr/local/lib/ser/modules/uri.so"
loadmodule "/usr/local/lib/ser/modules/uri_db.so"
loadmodule "/usr/local/lib/ser/modules/xlog.so"
loadmodule "/usr/local/lib/ser/modules/speeddial.so"
loadmodule "/usr/local/lib/ser/modules/domain.so"
loadmodule "/usr/local/lib/ser/modules/mediaproxy.so"

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

modparam("usrloc", "db_mode", 1)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("rr", "enable_full_lr", 1)
modparam("acc", "log_level", 1)
modparam("acc", "log_flag", 1 )
modparam("acc", "log_missed_flag", 2)
modparam("acc", "db_url", "mysql://ser:heslo@localhost/ser")
modparam("acc", "db_flag", 1)
modparam("acc", "db_missed_flag", 2)
modparam("acc", "log_fmt", "cdfimorstup")
modparam("xlog", "buf_size", 8192)
modparam("registrar", "default_expires", 180)
modparam("registrar",  "nat_flag",         3)
modparam("mediaproxy", "natping_interval", 52)
modparam("mediaproxy", "mediaproxy_socket", "/var/run/proxydispatcher.sock")
modparam("mediaproxy", "sip_asymmetrics", 
"/usr/local/etc/ser/sip-asymmetrics-clients")
modparam("mediaproxy", "rtp_asymmetrics", 
"/usr/local/etc/ser/rtp-asymmetrics-clients")


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

route {

	if ( !mf_process_maxfwd_header("10") ) 
	{
		log(1, "LOG: Too many hops. LOOP?\n");
		if ( method!="ACK" )
		{
			sl_send_reply("483", "Too many hops");
		}
		break;
	};


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

	record_route();	


	if ( uri=~"^sip:4242@" && ( method=="BYE" || method=="CANCEL" ) )
	{
		if (!t_newtran())
		{
			sl_send_reply("500", "could not create transaction");
			break;
		};

	
		if( !t_write_unix("/tmp/am_sock", "bye") ) 
		{
		    t_reply("500", "error contacting sems");
		};

		break;

	}
	else if ( method=="BYE" || method=="CANCEL" )
	{

		end_media_session();
		setflag(1);
	}

	if ( client_nat_test("3") && !search("^Record-Route:") ) 
	{
		force_rport();
		fix_contact();
	};


	if ( loose_route() ) 
	{
		if (method=="INVITE" || method=="ACK") 
		{
			use_media_proxy();
		};

		t_relay();
		break;
	};


	if ( method=="ACK" )
	{
		use_media_proxy();
	}

	######

  	if ( !(uri==myself) )
	{

		append_hf("P-hint: OUTBOUND ON INTERNET\r\n");
		if ( !t_relay() ) 
		{
   			sl_reply_error();
   			break;
		};

    	break;
	};


	######

	if ( uri==myself )
	{

		if ( method=="REGISTER" ) 
		{

				if ( client_nat_test("3") ) 
				{
					setflag(3);
					force_rport();
					fix_contact();
				}


				if ( !www_authorize("192.168.11.1", "subscriber") ) 
				{
					www_challenge("192.168.11.1", "1");
					break;
				}


				if ( !save("location") ) 
				{
					sl_reply_error();
					break;
			    };


   		 	break;

  		
		} # method==register

		else if ( method=="INVITE" ) 
		{

			if ( !proxy_authorize("", "subscriber") )  
			{
				proxy_challenge("", "1" );
				break;
			};


			t_on_failure("1");
			t_on_reply("1");
			use_media_proxy();


			# ------------------------------------------------------------------------
			# echo server
			# ------------------------------------------------------------------------

			if ( uri=~"^sip:4242 at .*" )
			{

				# switch to statefull mode:
				if ( !t_newtran() )
				{
					sl_send_reply("500","could not create transaction");
					break;
				};


				if( !t_write_unix("/tmp/am_sock", "echo") ) 
				{
					t_reply("500", "error contacting sems");
				};

				break;

			}


			# offline? 
			if ( !lookup("location") ) 
			{
				if ( !t_newtran() ) 
				{
    				sl_reply_error();
				};

				t_write_unix("/tmp/am_sock", "voicemail");

    			break;
			};


		} # method==invite


		# route

		append_hf("P-hint: USRLOC\r\n");
		if ( !t_relay() ) 
		{
			end_media_session();
    		sl_reply_error();
   		 	break;
		};


	} ; # uri==myself

} /* end of initial routing logic */


############################################################################################

onreply_route[1] 
{
	if ( status=~"(183)|(2[0-9][0-9])" ) 
	{
		if ( client_nat_test("1") ) 
		{
            fix_contact();
        };
        use_media_proxy();
    };
}


failure_route[1] 
{
	end_media_session();
}




More information about the sr-users mailing list