Przeglądaj źródła

Merge unit tests from kamailio trunk.

* trunk: (126 commits)
  - extend test with one non-digit URI (bug #2694633)
  - fix isql function, remove column delimiter
  - add missing check for kamailio binary on start
  - fix NULL behaviour for db_unixodbc in module
  - add functionality for runtime message forwarding, this is useful
  - remove a few modules that need (now) external libraries
  - change functionality in cr_route, cr_prime_route to not store information
  - improve tests a bit for flags and mask matching
  - fix test description
  - move encode_contact, decode_contact and decode_contact_header function
  - add a new test for carrierroute, non-numerical matching mode
  - fix tests after removal of the uri module and the moving of the $shv vars
  - fix tests, add pv loadmodule..
  - remove options module from test after removal in the tree
  - add missing module and compile checks on start
  - add new utils module to test
  - finish renaming, fix module name in test
  - add new module 'utils', to hold various SIP message related functionality
  - extend registrar test for db_mysql and db_postgres: test also for contact
  - finish refactoring of carrierroute module
  ...
Jan Janak 16 lat temu
rodzic
commit
aa639c4d02
83 zmienionych plików z 6594 dodań i 0 usunięć
  1. 37 0
      test/unit/1.sh
  2. 51 0
      test/unit/10.sh
  3. 80 0
      test/unit/11.cfg
  4. 189 0
      test/unit/11.sh
  5. 112 0
      test/unit/12.cfg
  6. 94 0
      test/unit/12.sh
  7. 55 0
      test/unit/13.cfg
  8. 132 0
      test/unit/13.sh
  9. 39 0
      test/unit/14.cfg
  10. 86 0
      test/unit/14.sh
  11. 43 0
      test/unit/15.sh
  12. 47 0
      test/unit/16.sh
  13. 67 0
      test/unit/17.sh
  14. 47 0
      test/unit/18.sh
  15. 44 0
      test/unit/19.cfg
  16. 50 0
      test/unit/19.sh
  17. 66 0
      test/unit/2.cfg
  18. 51 0
      test/unit/2.sh
  19. 53 0
      test/unit/20.cfg
  20. 52 0
      test/unit/20.sh
  21. 102 0
      test/unit/21.cfg
  22. 55 0
      test/unit/21.sh
  23. 112 0
      test/unit/22.sh
  24. 108 0
      test/unit/23.sh
  25. 58 0
      test/unit/24.sh
  26. 50 0
      test/unit/25.cfg
  27. 152 0
      test/unit/25.sh
  28. 72 0
      test/unit/26.cfg
  29. 149 0
      test/unit/26.sh
  30. 54 0
      test/unit/27.sh
  31. 23 0
      test/unit/28.cfg
  32. 69 0
      test/unit/28.sh
  33. 73 0
      test/unit/29.sh
  34. 65 0
      test/unit/3.sh
  35. 29 0
      test/unit/30.cfg
  36. 72 0
      test/unit/30.sh
  37. 57 0
      test/unit/31.sh
  38. 59 0
      test/unit/32.sh
  39. 28 0
      test/unit/33.cfg
  40. 75 0
      test/unit/33.sh
  41. 26 0
      test/unit/34.cfg
  42. 54 0
      test/unit/34.sh
  43. 56 0
      test/unit/35.cfg
  44. 72 0
      test/unit/35.sh
  45. 72 0
      test/unit/36.sh
  46. 118 0
      test/unit/37.sh
  47. 48 0
      test/unit/38.sh
  48. 62 0
      test/unit/39.sh
  49. 54 0
      test/unit/4.sh
  50. 32 0
      test/unit/40.cfg
  51. 73 0
      test/unit/40.sh
  52. 44 0
      test/unit/41.cfg
  53. 61 0
      test/unit/41.sh
  54. 150 0
      test/unit/42.sh
  55. 98 0
      test/unit/43.sh
  56. 112 0
      test/unit/44.sh
  57. 427 0
      test/unit/5.cfg
  58. 41 0
      test/unit/5.sh
  59. 40 0
      test/unit/6.sh
  60. 1134 0
      test/unit/7.cfg
  61. 42 0
      test/unit/7.sh
  62. 51 0
      test/unit/8.sh
  63. 51 0
      test/unit/9.sh
  64. 13 0
      test/unit/Makefile
  65. 12 0
      test/unit/README
  66. 30 0
      test/unit/carrierroute-2.cfg
  67. 100 0
      test/unit/carrierroute.cfg
  68. 6 0
      test/unit/cpl_ignore.xml
  69. 21 0
      test/unit/cpl_test.xml
  70. 140 0
      test/unit/failure_route.xml
  71. 6 0
      test/unit/include/common
  72. 69 0
      test/unit/include/database
  73. 62 0
      test/unit/include/require
  74. 41 0
      test/unit/inv_auth.xml
  75. 12 0
      test/unit/invite.sip
  76. 93 0
      test/unit/presence.cfg
  77. 4 0
      test/unit/publish.csv
  78. 86 0
      test/unit/publish_scenario.xml
  79. 40 0
      test/unit/reg_auth.xml
  80. 11 0
      test/unit/register.sip
  81. 4 0
      test/unit/subscribe_notify.csv
  82. 58 0
      test/unit/subscribe_notify_scenario.xml
  83. 11 0
      test/unit/unregister.sip

+ 37 - 0
test/unit/1.sh

@@ -0,0 +1,37 @@
+#!/bin/bash
+# load a minimal config
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+
+CFG=1.cfg
+
+# setup config
+echo -e "debug=3" > $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+rm -f $CFG
+
+exit $ret

+ 51 - 0
test/unit/10.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+# test basic db related kamailioctl functionality for dbtext
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+cp $CTL $CTL.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=DBTEXT/g" $CTLRC
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $CTL
+
+./$CTL avp list > /dev/null
+
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL domain showdb > /dev/null
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL lcr show > /dev/null
+	ret=$?
+fi ;
+
+# cleanup
+mv $CTLRC.bak $CTLRC
+mv $CTL.bak $CTL
+
+cd ../test
+exit $ret

+ 80 - 0
test/unit/11.cfg

@@ -0,0 +1,80 @@
+# ----------- global configuration parameters ------------------------
+debug=3
+fork=yes
+log_stderror=no
+children=1
+disable_tcp=yes
+
+# ------------------ module loading ----------------------------------
+mpath="../modules/"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "textops/textops.so"
+loadmodule "xlog/xlog.so"
+loadmodule "pv/pv.so"
+loadmodule "mi_fifo/mi_fifo.so"
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+loadmodule "usrloc/usrloc.so"
+modparam("usrloc", "db_mode", 1)
+
+loadmodule "registrar/registrar.so"
+modparam("registrar", "reg_callid_avp", "$avp(s:foobar)")
+modparam("registrar", "min_expires", 5)
+modparam("usrloc", "timer_interval", 2)
+
+#-------------------------  request routing logic -------------------
+route{
+
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit;
+	}
+
+	if (msg:len >=  2048 ) {
+		sl_send_reply("513", "Message Too Large");
+		exit;
+	}
+
+	if (!method=="REGISTER")
+		record_route();
+
+	if (loose_route()) {
+		# mark routing logic in request
+		append_hf("P-hint: rr-enforced\r\n");
+		route(1);
+	}
+
+	if (!uri==myself) {
+		append_hf("P-hint: outbound\r\n");
+		route(1);
+	}
+
+	if (uri==myself) {
+		if (method=="REGISTER") {
+			save("location");
+			exit;
+		}
+		if (!lookup("location")) {
+			sl_send_reply("404", "Not Found");
+			exit;
+		}
+		$avp(s:foobar) = $ci + "bar";
+#		$avp(s:foobar) = $ci;
+		if (registered("location")) {
+			xlog("already registered");
+		}
+		append_hf("P-hint: usrloc applied\r\n");
+	}
+
+	route(1);
+}
+
+route[1] {
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+	exit;
+}

+ 189 - 0
test/unit/11.sh

@@ -0,0 +1,189 @@
+#!/bin/bash
+# database access and persistent storage for registrar on mysql
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+CFG=11.cfg
+
+if ! (check_sipsak && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+# register two contacts
+sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+sipsak -U -C sip:foobar1@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+ret=$?
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	TMP=`$MYSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
+	if [ "$TMP" -eq 0 ] ; then
+		ret=1
+	fi;
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# check if the contact is registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# update the registration
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# check if we get a hint when we try to unregister a non-existent conctact
+	sipsak -U -C "sip:foobar2@localhost" -s sip:[email protected] -H localhost -x 0 -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# unregister the contact
+	sipsak -U -C "sip:foobar@localhost" -s sip:[email protected] -H localhost -x 0 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# unregister the user again should not fail
+	sipsak -U -C "sip:foobar@localhost" -s sip:[email protected] -H localhost -x 0 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# check if the other contact is still registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar1@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# register the other again
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# unregister all contacts
+	sipsak -U -C "*" -s sip:[email protected] -H localhost -x 0 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ]; then
+		ret=1
+	else
+		ret=0
+	fi;
+fi ;
+
+if [ "$ret" -eq 0 ]; then
+	ret=`$MYSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# test min_expires functionality
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost -x 2 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	sleep 3
+	# check if the contact is still registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# register a few more contacts
+	sipsak -U -e 9 -s sip:49721123456789@localhost -H localhost &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# let the timer cleanup the previous registrations
+	sleep 3
+	# and check
+	TMP=`$MYSQL "select COUNT(*) from location where username like '49721123456789%';" | tail -n 1`
+	if [ "$TMP" -eq 10 ] ; then
+		ret=0
+	else
+		ret=1
+	fi;
+fi;
+
+$MYSQL "delete from location where username like '49721123456789%';"
+
+if [ "$ret" -eq 0 ]; then
+	# register again
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+
+# restart to test preload_udomain functionality
+../$BIN -w . -f ../test/$CFG > /dev/null
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ]; then
+	# check if the contact is still registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+# check if the methods value is correct
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "Methods:: 4294967295" &> /dev/null
+	ret=$?
+fi;
+
+# cleanup
+$MYSQL "delete from location where username like '49721123456789%';"
+
+$KILL
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 112 - 0
test/unit/12.cfg

@@ -0,0 +1,112 @@
+log_stderror=yes
+listen=127.0.0.1
+mpath="../modules/"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "textops/textops.so"
+loadmodule "xlog/xlog.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "pv/pv.so"
+loadmodule "mi_fifo/mi_fifo.so"
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+avp_aliases="identity_user=i:81"
+avp_aliases="identity_domain=i:82"
+avp_aliases="identity_uri=i:83"
+
+route{
+	xlog("received by kamailio[$pp] at '$Tf' from $si:$sp, method: $(rm{s.tolower}), transport: $rP:$Ri:$rp, user agent: $ua\n");
+
+	if !(route(39)) {
+		xlog("L_ERR", "Error getting identity\n");
+		exit;
+	}
+	xlog("L_ERR", "My identity: $avp(identity_uri)\n");
+	$var(x) = "sip:" + $fU +"@" + $td;
+	xlog("var(x): $var(x), MD5 var(x): $(var(x){s.md5})\n");
+
+	if (!method=="REGISTER")
+		record_route();
+
+	if (loose_route()) {
+		# mark routing logic in request
+		append_hf("P-hint: rr-enforced\r\n");
+		route(1);
+	};
+
+	if (!uri==myself) {
+		append_hf("P-hint: outbound\r\n");
+		route(1);
+	};
+	xlog("From header tag: $(hdr(From){param.value,tag})\n");
+	
+	if(is_method("REGISTER")) {
+		if(is_present_hf("Expires")) {
+			xlog("Expires header field present\n");
+			if($(hdr(Expires){s.int}) > 0) {
+				xlog("this is an registration\n");
+			}
+			if($(hdr(Expires){s.int}) == 0) {
+				xlog("this is an unregistration\n");
+			}
+		}
+		if(is_present_hf("Contact")) {
+			xlog("Contact header field present\n");
+			if ($(hdr(Contact){param.value,expires}{s.int}) > 0) {
+				xlog("this is an registration\n");
+			}
+			if ($(ct{param.value,expires}{s.int}) == 0) {
+				xlog("this is an unregistration\n");
+			}
+		}
+	}
+
+	if (uri==myself) {
+		if (method=="REGISTER") {
+		save("location");
+		exit;
+		}
+		if (!lookup("location")) {
+			sl_send_reply("404", "Not Found");
+			exit;
+		}
+		append_hf("P-hint: usrloc applied\r\n");
+	}
+
+	route(1);
+}
+
+route[1] {
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+	exit;
+}
+
+route[39] {
+	if ($ai) {
+		$avp(identity_user)=$(ai{uri.user});
+		$avp(identity_domain)=$(ai{uri.domain});
+		$avp(identity_uri)=$ai;
+		xlog("L_ERR", "Getting identity from P-Asserted-Identity header\n");
+	} else if ($pu) {
+		$avp(identity_user)=$(pu{uri.user});
+		$avp(identity_domain)=$(pu{uri.domain});
+		$avp(identity_uri)=$pu;
+		xlog("L_ERR", "Getting identity from P-Preferred-Identity header\n");
+	} else if ($fu) {
+		$avp(identity_user)=$(fu{uri.user});
+		$avp(identity_domain)=$(fu{uri.domain});
+		$avp(identity_uri)=$fu;
+		xlog("L_ERR", "Getting identity from FROM URI\n");
+	} else {
+		xlog("L_ERR", "No identity for $rm: $fu -> $ru\n");
+		return(-1);
+	}
+
+	return (1);
+}

+ 94 - 0
test/unit/12.sh

@@ -0,0 +1,94 @@
+#!/bin/bash
+# configuration with pseudo-variables, transformations and xlog output
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+CFG=12.cfg
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+if ! (check_netcat && check_kamailio); then
+	exit 0
+fi ;
+
+../$BIN -w . -f $CFG &> $TMPFILE
+ret=$?
+
+sleep 1
+
+# register a user
+cat register.sip | nc -q 1 -u localhost 5060 > /dev/null
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL ul show | grep "AOR:: 1000" > /dev/null
+	ret=$?
+fi ;
+
+# unregister the user
+cat ../test/unregister.sip | nc -q 1 -u localhost 5060 > /dev/null
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL ul show | grep "AOR:: 1000" > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ] ; then
+		ret=1
+	else
+		ret=0
+	fi ;
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	grep "method: register, transport: UDP:127.0.0.1:5060, user agent: Twinkle/1.0"  $TMPFILE > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ] ; then
+		grep "Getting identity from FROM URI" $TMPFILE > /dev/null
+		ret=$?
+		if [ "$ret" -eq 0 ] ; then
+			grep "My identity: sip:[email protected]" $TMPFILE > /dev/null
+			ret=$?
+			if [ "$ret" -eq 0 ] ; then
+				grep "var(x): sip:[email protected], MD5 var(x): b6c3d120cfd9e85addf64ee8943f4eec" $TMPFILE > /dev/null
+				ret=$?
+				if [ "$ret" -eq 0 ] ; then
+					grep "Contact header field present" $TMPFILE > /dev/null
+					ret=$?
+					if [ "$ret" -eq 0 ] ; then
+						grep "this is an registration" $TMPFILE > /dev/null
+						ret=$?
+						if [ "$ret" -eq 0 ] ; then
+							grep "this is an unregistration" $TMPFILE > /dev/null
+							ret=$?
+						fi;
+					fi ;
+				fi ;
+			fi ;
+		fi ;
+	fi ;
+fi ;
+
+cd ../test
+
+$KILL
+rm $TMPFILE
+
+exit $ret

+ 55 - 0
test/unit/13.cfg

@@ -0,0 +1,55 @@
+debug=3
+mpath="../modules"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "xlog/xlog.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "carrierroute/carrierroute.so"
+loadmodule "pv/pv.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+avp_aliases="domain=s:10"
+avp_aliases="carrier=s:11"
+avp_aliases="host=s:12"
+
+route{
+	# initial sanity checks
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		return;
+	};
+	if (msg:len >  max_len) {
+		sl_send_reply("513", "Message too big");
+		return;
+	};
+	cr_user_carrier("$fU", "$fd", "$avp(carrier)");
+	$avp(domain)="start";
+	if (!cr_route("$avp(carrier)", "$avp(domain)", "$rU", "$rU", "call_id", "$avp(host)")) {
+		xlog("L_ERR", "cr_route failed\n");
+		exit;
+	}
+	t_on_failure("1");
+		if (!t_relay()) {
+		sl_reply_error();
+	};
+}
+
+failure_route[1] {
+	revert_uri();
+		if (!cr_next_domain("$avp(carrier)", "$avp(domain)", "$rU", "$avp(host)", "$T_reply_code", "$avp(domain)")) {
+			xlog("L_ERR", "cr_next_domain failed\n");
+			exit;
+		}
+	if (!cr_route("$avp(carrier)", "$avp(domain)", "$rU", "$rU", "call_id", "$avp(host)")) {
+		xlog("L_ERR", "cr_route failed\n");
+		exit;
+	}
+	t_on_failure("1");
+	append_branch();
+	if (!t_relay()) {
+		xlog("L_ERR", "t_relay failed\n");
+		exit;
+	};
+}

+ 132 - 0
test/unit/13.sh

@@ -0,0 +1,132 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+CFG=13.cfg
+
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+
+# setup database
+$MYSQL "insert into carrier_name (id, carrier) values ('1', 'carrier1');"
+$MYSQL "insert into carrier_name (id, carrier) values ('2', 'default');"
+$MYSQL "insert into carrier_name (id, carrier) values ('3', 'carrier2');"
+
+$MYSQL "insert into domain_name (id, domain) values ('10', 'domain1');"
+$MYSQL "insert into domain_name (id, domain) values ('1', 'domain2');"
+$MYSQL "insert into domain_name (id, domain) values ('2', 'domain3');"
+
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('1','1','10','49','0.5','0','host1.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('2','1','10','49','0.5','0','host2.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('3','1','10','42','0.3','0','host3.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('4','1','10','42','0.7','0','host4.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('5','1','10','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('6','1','1','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('7','1','2','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('8','2','10','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('9','2','1','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('10','2','2','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('11','3','10','','1','0','host1.local');"
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('1', '1', '1', '49', 'host1.local', '404', '0', '0', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('2', '1', '1', '49', 'host1.local', '4..', '0', '0', '3');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('3', '2', '1', '49', 'host1.local', '503', '0', '0', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('4', '2', '2', '49', 'host1.local', '5..', '0', '0', '3');"
+
+../$BIN -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+cd ../scripts
+
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL fifo cr_dump_routes > $TMPFILE
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	tmp=`grep -v "Printing routing information:
+Printing tree for carrier 'carrier1' (1)
+Printing tree for domain 'domain2' (1)
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for domain 'domain3' (2)
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for domain 'domain1' (10)
+        42: 70.140 %, 'host4.local': ON, '0', '', '', ''
+        42: 30.060 %, 'host3.local': ON, '0', '', '', ''
+        49: 50.000 %, 'host2.local': ON, '0', '', '', ''
+        49: 50.000 %, 'host1.local': ON, '0', '', '', ''
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for carrier 'default' (2)
+Printing tree for domain 'domain2' (1)
+      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''
+Printing tree for domain 'domain1' (10)
+      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''
+Printing tree for carrier 'carrier2' (3)
+Printing tree for domain 'domain1' (10)
+      NULL: 100.000 %, 'host1.local': ON, '0', '', '', ''" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+fi ;
+
+$KILL
+
+# cleanup database
+$MYSQL "delete from carrier_name where id = 1;"
+$MYSQL "delete from carrier_name where id = 2;"
+$MYSQL "delete from carrier_name where id = 3;"
+$MYSQL "delete from domain_name where id = 10;"
+$MYSQL "delete from domain_name where id = 1;"
+$MYSQL "delete from domain_name where id = 2;"
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierfailureroute where carrier=1;"
+$MYSQL "delete from carrierfailureroute where carrier=2;"
+$MYSQL "delete from carrierfailureroute where carrier=3;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+rm $TMPFILE
+
+exit $ret

+ 39 - 0
test/unit/14.cfg

@@ -0,0 +1,39 @@
+mpath="../modules"
+loadmodule "sl/sl.so"
+loadmodule "xlog/xlog.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "carrierroute/carrierroute.so"
+loadmodule "pv/pv.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+avp_aliases="domain=s:10"
+avp_aliases="carrier=s:11"
+avp_aliases="host=s:12"
+
+route{
+	# initial sanity checks
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		return;
+	};
+	if (msg:len >  max_len) {
+		sl_send_reply("513", "Message too big");
+		return;
+	};
+	if (method == "REGISTER") {
+		if(!cr_route("default", "register", "$rU", "$rU", "call_id", "$avp(s:30)")) {
+			sl_send_reply("403", "Not allowed");
+		}
+		sl_send_reply("200", "OK");
+		return;
+	}
+	if (method == "INVITE") {
+		if(!cr_route("default", "proxy", "$rU", "$rU", "call_id")) {
+			sl_send_reply("403", "Not allowed");
+		}
+		sl_send_reply("100", "Trying");
+		return;
+	}
+}

+ 86 - 0
test/unit/14.sh

@@ -0,0 +1,86 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from config file
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+CFG=14.cfg
+
+if ! (check_kamailio && check_module "carrierroute" ); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "modparam(\"carrierroute\", \"config_file\", \"`pwd`/../test/carrierroute.cfg\")" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+cd ../scripts
+
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL fifo cr_dump_routes > $TMPFILE
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	tmp=`grep -v "Printing routing information:
+Printing tree for carrier 'default' (1)
+Printing tree for domain 'register' (1)
+      NULL: 0.000 %, 'test1': OFF, '0', '', '', ''
+      NULL: 50.000 %, 'test2.localdomain': ON, '0', '', '', ''
+      NULL: 50.000 %, 'test3.localdomain': ON, '0', '', '', ''
+Printing tree for domain 'proxy' (2)
+         2: 87.610 %, 'test7.localdomain': ON, '0', '', '', ''
+         2: 12.516 %, 'test8.localdomain': ON, '0', '', '', ''
+        42: 70.070 %, 'test4': ON, '0', '', '', ''
+        42: 20.020 %, 'test5.localdomain': ON, '0', '', '', ''
+        42: 10.010 %, 'test6.localdomain': ON, '0', '', '', ''
+        49: 0.000 %, 'test5.localdomain': OFF, '0', '', '', ''
+        49: 44.444 %, 'test4': ON, '0', '', '', ''
+        49: 55.556 %, 'test6.localdomain': ON, '0', '', '', ''
+Printing tree for domain 'other' (3)
+      NULL: 0.000 %, 'test1': OFF, '0', '', '', ''
+      NULL: 50.000 %, 'test2.localdomain': OFF, '0', '', '', ''
+            Rule is backed up by: test3.localdomain
+      NULL: 50.000 %, 'test3.localdomain': ON, '0', '', '', ''
+            Rule is backup for: test2.localdomain" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+fi ;
+
+$KILL
+
+cd ../test
+
+mv $CFG.bak $CFG
+rm -f $TMPFILE
+
+exit $ret

+ 43 - 0
test/unit/15.sh

@@ -0,0 +1,43 @@
+#!/bin/bash
+# load all modules without external dependencies with dbtext
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+CFG=15.cfg
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+
+echo "loadmodule \"../modules/db_text/db_text.so\"" >> $CFG
+cat 2.cfg >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"text://`pwd`/../scripts/dbtext/kamailio\")" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+rm $CFG
+
+exit $ret

+ 47 - 0
test/unit/16.sh

@@ -0,0 +1,47 @@
+#!/bin/bash
+# load all modules without external dependencies with postgres
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+# Needs a default kamailio database setup for postgres
+
+if ! (check_kamailio && check_module "db_postgres" ); then
+	exit 0
+fi ;
+
+CFG=2.cfg
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"postgres://openserro:openserro@localhost/openser\")" >> $CFG
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+mv $CFG.bak $CFG
+rm -f dispatcher.list
+
+exit $ret

+ 67 - 0
test/unit/17.sh

@@ -0,0 +1,67 @@
+#!/bin/bash
+# load all modules without external dependencies with db_berkeley
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+if ! (check_kamailio && check_module "db_berkeley" ); then
+	exit 0
+fi ;
+
+CFG=17.cfg
+
+tmp_name=""$RANDOM"_kamailiodb_tmp"
+
+echo "loadmodule \"../modules/db_berkeley/db_berkeley.so\"" >> $CFG
+cat 2.cfg >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"berkeley://`pwd`/../scripts/$tmp_name\")" >> $CFG
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=DB_BERKELEY/g" $CTLRC
+sed -i "s/# INSTALL_EXTRA_TABLES=ask/INSTALL_EXTRA_TABLES=yes/g" $CTLRC
+sed -i "s/# INSTALL_PRESENCE_TABLES=ask/INSTALL_PRESENCE_TABLES=yes/g" $CTLRC
+
+cp $DBCTL $DBCTL.bak
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $DBCTL
+
+./$DBCTL create $tmp_name > /dev/null
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	../$BIN -w . -f ../test/$CFG > /dev/null	
+	ret=$?
+fi ;
+
+sleep 1
+$KILL
+
+# cleanup
+./$DBCTL drop $tmp_name > /dev/null
+mv $CTLRC.bak $CTLRC
+mv $DBCTL.bak $DBCTL
+
+cd ../test/
+rm $CFG
+
+exit $ret

+ 47 - 0
test/unit/18.sh

@@ -0,0 +1,47 @@
+#!/bin/bash
+# runs ../kamailio with all command line arguments.
+# ommited options are -h -v -C -c -D
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+
+# the config file
+CFG=18.cfg
+
+# setup config
+echo -e "debug=3" > $CFG
+
+# start:
+../$BIN -f ./$CFG -l 127.0.0.1 -n 0 -rR -v  -E -d -T -N 0 -b 23 -m 42 -w ./  -u $(id -u)  -g $(id -g) -P ./pid.out -G ./pgid.out  > /dev/null 2>&1
+
+ret=$?
+
+sleep 1
+
+# clean up:
+$KILL
+
+rm $CFG
+exit $ret

+ 44 - 0
test/unit/19.cfg

@@ -0,0 +1,44 @@
+# Kamailio config for lookup / registrar testing
+
+#------------------------Global configuration----------------------------------
+debug=3
+fork=yes
+log_stderror=no
+listen=127.0.0.1
+port=5060
+dns=no
+rev_dns=no
+
+#-----------------------Loading Modules-------------------------------------
+mpath="../modules/"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "maxfwd/maxfwd.so"
+#for debugging purposes only
+loadmodule "mi_fifo/mi_fifo.so"
+
+
+#-----------------------Module parameters-------------------------------------
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+#-----------------------Routing configuration---------------------------------#
+route{
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit();
+	}
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+	}
+
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+

+ 50 - 0
test/unit/19.sh

@@ -0,0 +1,50 @@
+#!/bin/bash
+# check user lockup for proxy functionality with usrloc and registrar for mysql
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=19.cfg
+SRV=5060
+UAS=5070
+UAC=5080
+
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+
+../$BIN -w . -f $CFG &> /dev/null
+sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
+sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null
+
+ret=$?
+
+# cleanup
+killall -9 sipp > /dev/null 2>&1
+$KILL > /dev/null 2>&1
+
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+exit $ret;

+ 66 - 0
test/unit/2.cfg

@@ -0,0 +1,66 @@
+debug=3
+mpath="../modules"
+loadmodule "tm/tm.so"
+loadmodule "acc/acc.so"
+loadmodule "alias_db/alias_db.so"
+loadmodule "auth/auth.so"
+loadmodule "auth_db/auth_db.so"
+loadmodule "avpops/avpops.so"
+loadmodule "benchmark/benchmark.so"
+loadmodule "cfgutils/cfgutils.so"
+loadmodule "dialog/dialog.so"
+loadmodule "dispatcher/dispatcher.so"
+loadmodule "diversion/diversion.so"
+loadmodule "domain/domain.so"
+loadmodule "domainpolicy/domainpolicy.so"
+loadmodule "enum/enum.so"
+loadmodule "exec/exec.so"
+loadmodule "db_flatstore/db_flatstore.so"
+loadmodule "group/group.so"
+loadmodule "htable/htable.so"
+loadmodule "imc/imc.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "mi_datagram/mi_datagram.so"
+loadmodule "mi_fifo/mi_fifo.so"
+loadmodule "msilo/msilo.so"
+loadmodule "nathelper/nathelper.so"
+loadmodule "nat_traversal/nat_traversal.so"
+loadmodule "path/path.so"
+loadmodule "pike/pike.so"
+loadmodule "ratelimit/ratelimit.so"
+loadmodule "rr/rr.so"
+loadmodule "seas/seas.so"
+loadmodule "siptrace/siptrace.so"
+loadmodule "siputils/siputils.so"
+loadmodule "sl/sl.so"
+loadmodule "sms/sms.so"
+loadmodule "speeddial/speeddial.so"
+loadmodule "sst/sst.so"
+loadmodule "statistics/statistics.so"
+loadmodule "textops/textops.so"
+loadmodule "uac/uac.so"
+loadmodule "uac_redirect/uac_redirect.so"
+loadmodule "uri_db/uri_db.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "userblacklist/userblacklist.so"
+loadmodule "registrar/registrar.so"
+loadmodule "permissions/permissions.so"
+loadmodule "pdt/pdt.so"
+loadmodule "pv/pv.so"
+loadmodule "mediaproxy/mediaproxy.so"
+loadmodule "xlog/xlog.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("mi_datagram", "socket_name", "/tmp/kamailio.sock")
+modparam("dialog", "dlg_flag", 10)
+modparam("dialog", "db_mode", 2)
+modparam("tm", "fr_inv_timer_avp", "$avp(i:704)")
+modparam("^auth$|lcr", "rpid_avp", "$avp(i:302)")
+modparam("sms", "modems", "Nokia [d=/dev/ttyS1;b=9600;m=new;l=30] ")
+modparam("sms", "networks", "D1 [m=10] ;d2[ m=20]")
+modparam("sms", "links", "NOKIA[D1;d2]")
+modparam("sst", "sst_flag", 6)
+modparam("usrloc", "nat_bflag", 15)
+modparam("uri_db", "use_uri_table", 1)
+modparam("uri_db", "db_table", "uri")
+modparam("avpops", "avp_table", "usr_preferences")

+ 51 - 0
test/unit/2.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+# load all modules without external dependencies with mysql
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+source include/database
+
+CFG=2.cfg
+
+if ! (check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+touch dispatcher.list
+
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"dispatcher\", \"list_file\", \"`pwd`/../test/dispatcher.list\")" >> $CFG
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+mv $CFG.bak $CFG
+rm -f dispatcher.list
+
+exit $ret

+ 53 - 0
test/unit/20.cfg

@@ -0,0 +1,53 @@
+# Kamailio config for lookup / registrar testing
+
+#------------------------Global configuration----------------------------------
+debug=3
+fork=yes
+log_stderror=yes
+listen=127.0.0.1
+port=5059
+dns=no
+rev_dns=no
+
+#-----------------------Loading Modiules-------------------------------------
+mpath="../modules/"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "acc/acc.so"
+#for debugging purposes only
+loadmodule "mi_fifo/mi_fifo.so"
+loadmodule "xlog/xlog.so"
+
+
+#-----------------------Module parameters-------------------------------------
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:[email protected]/openser")
+modparam("acc", "log_flag", 1)
+modparam("db_mysql", "timeout_interval", 2)
+
+
+#-----------------------Routing configuration---------------------------------#
+
+route{
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit();
+	}
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+	}
+
+	if(method=="INVITE"){
+		setflag(1);
+	}
+
+	if (!t_relay()) {
+			sl_reply_error();
+	}
+}

+ 52 - 0
test/unit/20.sh

@@ -0,0 +1,52 @@
+#! /bin/bash
+# test basic accounting functionality
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG="20.cfg"
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+sipp -sn uas -bg -i localhost -m 1 -f 10 -p 5060 &> /dev/null
+
+../$BIN -w . -f $CFG &> $TMPFILE
+
+sipp -sn uac -s foo 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 10 -p 5061 &> /dev/null
+
+egrep '^ACC:[[:space:]]+transaction[[:space:]]+answered:[[:print:]]*code=200;reason=OK$' $TMPFILE > /dev/null
+ret=$?
+
+# cleanup
+killall -9 sipp &> /dev/null
+$KILL &> /dev/null
+rm $TMPFILE
+
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost\") and (user_agent = \"ser_test\"));"
+
+exit $ret;

+ 102 - 0
test/unit/21.cfg

@@ -0,0 +1,102 @@
+#
+# $Id: kamailio.cfg 2825 2007-09-27 09:05:52Z henningw $
+#
+# simple quick-start config script
+# Please refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
+# for a explanation of possible statements, functions and parameters.
+#
+
+# ----------- global configuration parameters ------------------------
+
+debug=3      # debug level (cmd line: -dddddddddd)
+fork=yes
+log_stderror=no    # (cmd line: -E)
+children=4
+
+listen=127.0.0.1 
+port=5059
+
+dns=no
+rev_dns=no
+
+# ------------------ module loading ----------------------------------
+
+#set module path
+mpath="../modules/"
+
+# Uncomment this if you want to use SQL database
+loadmodule "db_mysql/db_mysql.so"
+
+loadmodule "sl/sl.so"
+loadmodule "rr/rr.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "pv/pv.so"
+loadmodule "registrar/registrar.so"
+loadmodule "textops/textops.so"
+loadmodule "auth/auth.so"
+loadmodule "auth_db/auth_db.so"
+loadmodule "uri_db/uri_db.so"
+loadmodule "xlog/xlog.so"
+
+# ----------------- setting module-specific parameters ---------------
+# -- usrloc params --
+
+# Uncomment this if you want to use SQL database 
+# for persistent storage and comment the previous line
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+# -- auth params --
+# Uncomment if you are using auth module
+#
+modparam("auth_db", "calculate_ha1", 1)
+
+# If you set "calculate_ha1" parameter to 1 (which true in this config), 
+# uncomment also the following parameter)
+#
+modparam("auth_db", "password_column", "password")
+
+# -- 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{
+
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483", "Too Many Hops");
+		exit;
+	}
+
+	if (is_method("ACK")) {
+		xlog("ACK");
+		sl_send_reply("200","OK");
+		exit;
+	}
+
+	if (uri == myself) {
+		if(method==REGISTER) {
+			if (!www_authorize("localhost", "subscriber")) {
+				www_challenge("localhost", "0");
+			} else {
+				if(check_to() && check_from()) {
+					sl_send_reply("200","OK");
+				}
+			}
+		} else {
+			if (!proxy_authorize("localhost", "subscriber")) {
+				proxy_challenge("localhost", "0");
+			} else {
+				if(check_to() && check_from() && does_uri_exist()) {
+					sl_send_reply("200","OK");
+				}
+			}
+		}
+		exit;
+	}
+}

+ 55 - 0
test/unit/21.sh

@@ -0,0 +1,55 @@
+#!/bin/bash
+# tests the authentification via auth_db and uri_db
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+
+CFG=21.cfg
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO subscriber (username, domain, password, email_address) VALUES (\"alice\",\"localhost\",\"alice\",\"alice@localhost\");"
+
+../$BIN -w . -f $CFG &> /dev/null;
+ret=$?
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -s alice 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 1 -auth_uri alice@localhost -p 5061 -sf reg_auth.xml -ap alice &> /dev/null;
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -s alice 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 1 -auth_uri alice@localhost -p 5061 -sf inv_auth.xml -ap alice &> /dev/null;
+	ret=$?
+fi;
+
+#cleanup
+$KILL &> /dev/null;
+killall -9 sipp &> /dev/null;
+$MYSQL "DELETE FROM subscriber WHERE((username = \"alice\") and (domain = \"localhost\"));"
+
+exit $ret;

+ 112 - 0
test/unit/22.sh

@@ -0,0 +1,112 @@
+#!/bin/bash
+# database access and persistent storage for registrar on postgres
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipsak && check_kamailio && check_module "db_postgres" && check_postgres); then
+	exit 0
+fi ;
+
+CFG=11.cfg
+
+cp $CFG $CFG.tmp
+echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
+echo "modparam(\"usrloc\", \"db_url\", \"postgres://openser:openserrw@localhost/openser\")" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+# register a user
+sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+ret=$?
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" > /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	TMP=`${PSQL} "select COUNT(*) from location where username='49721123456789';"`
+	if [ "$TMP" -eq 0 ] ; then
+		ret=1
+	fi;
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# unregister the user
+	sipsak -U -C "*" -s sip:[email protected] -H localhost -x 0 &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ]; then
+		ret=1
+	else
+		ret=0
+	fi;
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	ret=`$PSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
+fi;
+
+$PSQL "delete from location where username like '49721123456789%';"
+
+if [ "$ret" -eq 0 ]; then
+	# register again
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+
+# restart to test preload_udomain functionality
+../$BIN -w . -f ../test/$CFG > /dev/null
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ]; then
+	# check if the contact is still registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+# check if the methods value is correct
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "Methods:: 4294967295" &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+
+$PSQL "delete from location where username like '49721123456789%';"
+
+cd ../test
+mv $CFG.tmp $CFG
+
+exit $ret

+ 108 - 0
test/unit/23.sh

@@ -0,0 +1,108 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from postgres database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_postgres" && check_postgres); then
+	exit 0
+fi ;
+
+CFG=13.cfg
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+echo "modparam(\"carrierroute\", \"db_url\", \"postgres://openserro:openserro@localhost/openser\")" >> $CFG
+
+# setup database
+$PSQL "insert into carrier_name (id, carrier) values ('1', 'carrier1');
+insert into carrier_name (id, carrier) values ('2', 'default');
+insert into carrier_name (id, carrier) values ('3', 'premium');
+insert into domain_name (id, domain) values ('10', 'domain1');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('1','1','49','10','0.5','0','host1.local.domain');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('2','1','49','10','0.5','0','host2.local.domain');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('3','1','42','10','0.3','0','host3.local');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('4','1','42','10','0.7','0','host4.local');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('5','1','1','10','0.5','0','host1-ca.local:5060');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('6','1','1','10','0.5','0','host2-ca.local.domain:5060');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('10','1','','10','0.1','0','host5.local');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('20','2','','10','1','0','host6');
+insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('21','3','','10','1','0','premium.host.local');"
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+cd ../scripts
+
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL fifo cr_dump_routes > $TMPFILE
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	tmp=`grep -v "Printing routing information:
+Printing tree for carrier 'carrier1' (1)
+Printing tree for domain 'domain1' (10)
+         1: 50.000 %, 'host2-ca.local.domain:5060': ON, '0', '', '', ''
+         1: 50.000 %, 'host1-ca.local:5060': ON, '0', '', '', ''
+        42: 70.140 %, 'host4.local': ON, '0', '', '', ''
+        42: 30.060 %, 'host3.local': ON, '0', '', '', ''
+        49: 50.000 %, 'host2.local.domain': ON, '0', '', '', ''
+        49: 50.000 %, 'host1.local.domain': ON, '0', '', '', ''
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for carrier 'default' (2)
+Printing tree for domain 'domain1' (10)
+      NULL: 100.000 %, 'host6': ON, '0', '', '', ''
+Printing tree for carrier 'premium' (3)
+Printing tree for domain 'domain1' (10)
+      NULL: 100.000 %, 'premium.host.local': ON, '0', '', '', ''" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+fi ;
+
+$KILL
+
+# cleanup database
+$PSQL "delete from carrier_name where id = 1;
+delete from carrier_name where id = 2;
+delete from carrier_name where id = 3;
+delete from domain_name where id = 10;
+delete from carrierroute where carrier=1;
+delete from carrierroute where carrier=2;
+delete from carrierroute where carrier=3;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+rm $TMPFILE
+
+exit $ret

+ 58 - 0
test/unit/24.sh

@@ -0,0 +1,58 @@
+#!/bin/bash
+# creates a postgres database with kamailiodbctl and deletes it again
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a mysql database, the root user password must be given
+# in the file 'dbrootpw' in the test directory
+
+source include/common
+
+if [ ! -f ~/.pgpass ] ; then
+       echo "no .pgpass file, not run"
+       exit 0
+fi ;
+
+tmp_name=""$RANDOM"_kamailiodb_tmp"
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=PGSQL/g" $CTLRC
+sed -i "s/# INSTALL_EXTRA_TABLES=ask/INSTALL_EXTRA_TABLES=yes/g" $CTLRC
+sed -i "s/# INSTALL_PRESENCE_TABLES=ask/INSTALL_PRESENCE_TABLES=yes/g" $CTLRC
+
+cp $DBCTL $DBCTL.bak
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $DBCTL
+
+./$DBCTL create $tmp_name &> /dev/null
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	./$DBCTL drop $tmp_name &> /dev/null
+	ret=$?
+fi ;
+
+# cleanup
+mv $CTLRC.bak $CTLRC
+mv $DBCTL.bak $DBCTL
+
+cd ../test
+exit $ret

+ 50 - 0
test/unit/25.cfg

@@ -0,0 +1,50 @@
+debug=0
+listen=127.0.0.1
+port=5059
+
+mpath="../modules/"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "xlog/xlog.so"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "pv/pv.so"
+loadmodule "userblacklist/userblacklist.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("usrloc", "db_mode", 3)
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+route {
+	#xlog("user: $rU\n");
+
+	$avp(i:80) = $rU;
+	$avp(i:81) = $rd;
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+		exit;
+	}
+
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit;
+	}
+
+	if (!check_user_blacklist("$avp(i:80)", "$avp(i:81)")) {
+		xlog("$rU user blacklisted\n");
+		sl_send_reply("403", "Forbidden");
+		exit;
+	}
+
+	if (!check_blacklist("globalblacklist")) {
+		xlog("$rU globally blacklisted\n");
+		sl_send_reply("403", "Forbidden");
+		exit;
+	}
+	xlog("$rU not blacklisted\n");
+
+	t_relay();
+}

+ 152 - 0
test/unit/25.sh

@@ -0,0 +1,152 @@
+#!/bin/bash
+# loads a userblacklist config from mysql database and test some lists
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+function cleanup() {
+	killall -9 sipp > /dev/null 2>&1
+	$KILL > /dev/null 2>&1
+
+	$MYSQL "delete from location where (user_agent = \"ser_test\");"
+	$MYSQL "delete from userblacklist where username='49721123456786';"
+	$MYSQL "delete from userblacklist where username='49721123456788';"
+	$MYSQL "delete from userblacklist where username='49721123456789';"
+	$MYSQL "delete from userblacklist where username='494675231';"
+	$MYSQL "delete from userblacklist where username='494675453';"
+	$MYSQL "delete from userblacklist where username='494675454';"
+	$MYSQL "delete from globalblacklist where description='_test_';"
+	exit $1;
+}
+
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=25.cfg
+
+# add an registrar entry to the db;
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456789\",\"sip:123456789@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456788\",\"sip:123456788@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456787\",\"sip:123456787@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456786\",\"sip:123456786@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456785\",\"sip:223456789@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456784\",\"sip:2.23456789@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+
+# setup userblacklist, first some dummy data
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('494675454','','49900','0');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('494675453','test.domain','49901','0');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('494675231','test','499034132','0');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('494675231','','499034133','1');"
+# some actual data
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('49721123456789','','12345','0');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('49721123456788','','123456788','1');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('49721123456788','','1234','0');"
+# and the global ones
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('123456787','0','_test_');"
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('123456','0','_test_');"
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('1','1','_test_');"
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('','0','_test_');"
+
+
+../$BIN -w . -f $CFG &> /dev/null
+sleep 1
+
+sipp -sn uas -bg -i localhost -p 5060 &> /dev/null
+
+sipp -sn uac -s 49721123456789 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+
+sipp -sn uac -s 49721123456788 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+sipp -sn uac -s 49721123456787 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+
+sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('123456786','1','_test_');"
+../scripts/$CTL fifo reload_blacklist
+
+sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 0 ] ; then
+	cleanup 1
+fi;
+
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist) values ('49721123456786','','12345','0');"
+
+sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+
+sipp -sn uac -s 49721123456785 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+$MYSQL "insert into globalblacklist (prefix, whitelist, description) values ('2','1','_test_');"
+
+../scripts/$CTL fifo reload_blacklist
+
+if [ "$ret" -ne 1 ] ; then
+	cleanup 1
+fi;
+
+sipp -sn uac -s 49721123456785 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -ne 0 ] ; then
+	cleanup 1
+fi;
+
+sipp -sn uac -s 49721123456784 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+sleep 1
+# cleanup:
+cleanup $ret

+ 72 - 0
test/unit/26.cfg

@@ -0,0 +1,72 @@
+debug=3
+mpath="../modules"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "xlog/xlog.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "pv/pv.so"
+loadmodule "carrierroute/carrierroute.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+avp_aliases="domain=s:10"
+avp_aliases="carrier=s:11"
+avp_aliases="host=s:12"
+avp_aliases="comment=s:13"
+
+route{
+	# initial sanity checks
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		return;
+	}
+	if (msg:len >  max_len) {
+		sl_send_reply("513", "Message too big");
+		return;
+	}
+	# set flag for later test
+	setflag(0);
+	resetflag(1);
+	setflag(2);
+
+	# user route
+	if(cr_user_carrier("$rU", "$rd", "$avp(carrier)")) {
+		$avp(domain)="domain0";
+		if (!cr_route("$avp(carrier)", "$avp(domain)", "$rU", "$rU", "call_id", "$avp(comment)")) {
+			xlog("L_ERR", "cr_route failed\n");
+			exit;
+		}
+		t_on_failure("1");
+		$avp(host) = $rd+":"+$rp;
+		#xlog("host: $avp(host), comment: $avp(comment)");
+	} else {
+	# default route
+		if (!cr_route("default", "domain0", "$rU", "$rU", "call_id")) {
+			xlog("L_ERR", "cr_route failed\n");
+			exit;
+		}
+	}
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}
+
+failure_route[1] {
+	revert_uri();
+	if (!cr_next_domain("$avp(carrier)", "$avp(domain)", "$rU", "$avp(host)", "$T_reply_code", "$avp(domain)")) {
+		xlog("L_ERR", "cr_next_domain failed\n");
+		exit;
+	}
+	if (!cr_route("$avp(carrier)", "$avp(domain)", "$rU", "$rU", "call_id")) {
+		xlog("L_ERR", "cr_route failed\n");
+		exit;
+	}
+	$avp(host) = $rd+":"+$rp;
+	t_on_failure("1");
+	append_branch();
+	if (!t_relay()) {
+		xlog("L_ERR", "t_relay failed\n");
+		exit;
+	}
+}

+ 149 - 0
test/unit/26.sh

@@ -0,0 +1,149 @@
+#!/bin/bash
+# do some routing with carrierroute route sets from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=26.cfg
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+
+# setup database
+$MYSQL "insert into carrier_name (id, carrier) values ('1', 'default');"
+$MYSQL "insert into carrier_name (id, carrier) values ('2', 'carrier1');"
+$MYSQL "insert into carrier_name (id, carrier) values ('3', 'carrier2');"
+
+$MYSQL "insert into domain_name (id, domain) values ('10', 'domain0');"
+$MYSQL "insert into domain_name (id, domain) values ('1', 'fallback');"
+$MYSQL "insert into domain_name (id, domain) values ('2', 'domain2');"
+
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('1','1','10','49','0','0','0.5','0','127.0.0.1:7000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host, description)
+values ('2','1','10','49','0','0','0.5','0','127.0.0.1:8000', 'foobar');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('3','2','10','49','0','0','1','0','127.0.0.1:9000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('4','3','10','49','0','3','1','0','127.0.0.1:10001');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('5','3','10','49','1','3','1','0','127.0.0.1:10000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('6','3','10','49','2','3','1','0','127.0.0.1:10002');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('7','3','1','49','0','0','1','0','127.0.0.1:10000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('8','3','2','49','0','0','1','0','127.0.0.1:10000');"
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('1', '3', '10', '49', '127.0.0.1:10000', '5..', '0', '0', '1');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('2', '3', '1', '49', '127.0.0.1:10000', '483', '0', '0', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('3', '3', '1', '49', '127.0.0.1:9000', '4..', '0', '0', '2');"
+
+$MYSQL "alter table subscriber add cr_preferred_carrier int(10) default NULL;"
+
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('49721123456786', 2);"
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('49721123456785', 3);"
+
+
+../$BIN -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 12 -p 7000 &> /dev/null
+	sipp -sn uas -bg -i localhost -m 12 -p 8000 &> /dev/null
+	sipp -sn uac -s 49721123456787 127.0.0.1:5060 -i 127.0.0.1 -m 20 -p 5061 &> /dev/null
+	ret=$?
+	killall sipp &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 9000 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s 49721123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	killall sipp &> /dev/null
+	sipp -sf failure_route.xml -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s 49721123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('4', '3', '1', '49', '127.0.0.1:10000', '4..', '0', '0', '4');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('5', '3', '1', '49', '127.0.0.1:10000', '486', '0', '0', '2');"
+
+if [ ! "$ret" -eq 0 ] ; then
+	../scripts/$CTL fifo cr_reload_routes
+	killall sipp &> /dev/null
+	sipp -sf failure_route.xml -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s 49721123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+
+$KILL
+killall -9 sipp
+
+# cleanup database
+$MYSQL "delete from carrier_name where id = 1;"
+$MYSQL "delete from carrier_name where id = 2;"
+$MYSQL "delete from carrier_name where id = 3;"
+$MYSQL "delete from domain_name where id = 10;"
+$MYSQL "delete from domain_name where id = 1;"
+$MYSQL "delete from domain_name where id = 2;"
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierfailureroute where carrier=1;"
+$MYSQL "delete from carrierfailureroute where carrier=2;"
+$MYSQL "delete from carrierfailureroute where carrier=3;"
+
+$MYSQL "delete from subscriber where username='49721123456786';"
+$MYSQL "delete from subscriber where username='49721123456785';"
+$MYSQL "alter table subscriber drop cr_preferred_carrier;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 54 - 0
test/unit/27.sh

@@ -0,0 +1,54 @@
+#!/bin/bash
+# test publish and subscribe for presence
+
+# Copyright (C) 2008 Voice System
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" \
+	&& check_module "presence" && check_module "presence_xml" \
+	&& check_mysql); then
+	exit 0
+fi ;
+
+CFG=presence.cfg
+
+../$BIN -w . -f $CFG &> /dev/null;
+ret=$?
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+    sipp -sf publish_scenario.xml -i 127.0.0.1 -p 5061 -inf publish.csv 127.0.0.1:5059 -recv_timeout 500000 -m 1 &> /dev/null;
+    ret=$?
+fi;
+
+
+if [ "$ret" -eq 0 ] ; then
+    sipp -sf subscribe_notify_scenario.xml -i 127.0.0.1 -p 5061 -inf subscribe_notify.csv 127.0.0.1:5059 -recv_timeout 500000 -m 1 &> /dev/null;
+    ret=$?
+fi;
+
+
+#cleanup:
+$KILL &> /dev/null;
+killall -9 sipp &> /dev/null;
+
+exit $ret;

+ 23 - 0
test/unit/28.cfg

@@ -0,0 +1,23 @@
+debug=3
+
+mpath="../modules"
+loadmodule "sl.so"
+loadmodule "tm.so"
+loadmodule "db_mysql.so"
+loadmodule "cpl-c.so"
+loadmodule "mi_fifo.so"
+loadmodule "textops.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("cpl-c","cpl_dtd_file","../modules/cpl-c/cpl-06.dtd")
+
+route {
+  if (is_method("INVITE")) {
+        # run incoming script
+         if ( !cpl_run_script("incoming","force_stateful") ) {
+             # script execution failed
+             sl_send_reply("500","CPL script execution failed");
+             exit;
+         };
+  };
+}

+ 69 - 0
test/unit/28.sh

@@ -0,0 +1,69 @@
+#!/bin/bash
+# tests simple cpl-c script operations with mysql
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_module "cpl-c" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=28.cfg
+CPL=cpl_ignore.xml
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+
+../$BIN -w . -f $CFG &> /dev/null;
+ret=$?
+sleep 1
+
+../scripts/$CTL fifo LOAD_CPL sip:[email protected] $CPL
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -m 1 -f 1 127.0.0.1:5060 -sf cpl_test.xml &> /dev/null;
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+  ../scripts/$CTL fifo GET_CPL sip:[email protected] > $TMPFILE 
+  diff $TMPFILE $CPL 
+  ret=$?
+fi; 
+
+if [ "$ret" -eq 0 ] ; then
+  ../scripts/$CTL fifo REMOVE_CPL sip:[email protected]
+  ../scripts/$CTL fifo GET_CPL sip:[email protected] > $TMPFILE
+fi;
+
+diff $TMPFILE $CPL &> /dev/null;
+ret=$?
+
+if [ ! "$ret" -eq 0 ] ; then
+  ret=0
+fi;
+
+#cleanup:
+$KILL &> /dev/null;
+killall -9 sipp &> /dev/null;
+rm $TMPFILE
+
+exit $ret;

+ 73 - 0
test/unit/29.sh

@@ -0,0 +1,73 @@
+#!/bin/bash
+# tests simple cpl-c script operations with postgres
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+if ! (check_sipp && check_kamailio && check_module "db_postgres" && check_module "cpl-c"); then
+	exit 0
+fi ;
+
+CFG=28.cfg
+CPL=cpl_ignore.xml
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+cp $CFG $CFG.tmp
+echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
+echo "modparam(\"cpl-c\", \"db_url\", \"postgres://openser:openserrw@localhost/openser\")" >> $CFG
+
+
+../$BIN -w . -f $CFG &> /dev/null;
+ret=$?
+sleep 1
+
+../scripts/$CTL fifo LOAD_CPL sip:[email protected] $CPL
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -m 1 -f 1 127.0.0.1:5060 -sf cpl_test.xml &> /dev/null;
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+  ../scripts/$CTL fifo GET_CPL sip:[email protected] > $TMPFILE 
+  diff $TMPFILE $CPL 
+  ret=$?
+fi; 
+
+if [ "$ret" -eq 0 ] ; then
+  ../scripts/$CTL fifo REMOVE_CPL sip:[email protected]
+  ../scripts/$CTL fifo GET_CPL sip:[email protected] > $TMPFILE
+fi;
+
+diff $TMPFILE $CPL &> /dev/null;
+ret=$?
+
+if [ ! "$ret" -eq 0 ] ; then
+  ret=0
+fi;
+
+#cleanup:
+$KILL &> /dev/null;
+killall -9 sipp &> /dev/null;
+rm $TMPFILE
+mv $CFG.tmp $CFG
+
+exit $ret;

+ 65 - 0
test/unit/3.sh

@@ -0,0 +1,65 @@
+#!/bin/bash
+# creates a mysql database with kamailiodbctl and deletes it again
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a mysql database, the root user password must be given
+# in the file 'dbrootpw' in the test directory
+
+source include/common
+
+if [ ! -f dbrootpw ] ; then
+	echo "no root password, not run"
+	exit 0
+fi ;
+
+source dbrootpw
+
+tmp_name=""$RANDOM"_kamailiodb_tmp"
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=MYSQL/g" $CTLRC
+sed -i "s/# INSTALL_EXTRA_TABLES=ask/INSTALL_EXTRA_TABLES=yes/g" $CTLRC
+sed -i "s/# INSTALL_PRESENCE_TABLES=ask/INSTALL_PRESENCE_TABLES=yes/g" $CTLRC
+
+cp $DBCTL $DBCTL.bak
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $DBCTL
+
+# set the mysql root password
+cp $DBCTL.mysql $DBCTL.mysql.bak
+sed -i "s/#PW=""/PW="$PW"/g" $DBCTL.mysql
+
+./$DBCTL create $tmp_name > /dev/null
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	./$DBCTL drop $tmp_name > /dev/null
+	ret=$?
+fi ;
+
+# cleanup
+mv $CTLRC.bak $CTLRC
+mv $DBCTL.mysql.bak $DBCTL.mysql
+mv $DBCTL.bak $DBCTL
+
+cd ../test
+exit $ret

+ 29 - 0
test/unit/30.cfg

@@ -0,0 +1,29 @@
+debug=3
+mpath="../modules"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "xlog/xlog.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "pv/pv.so"
+loadmodule "carrierroute/carrierroute.so"
+
+route{
+	# initial sanity checks
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		return;
+	}
+	if (msg:len >  max_len) {
+		sl_send_reply("513", "Message too big");
+		return;
+	}
+
+	# default route
+ 	if (!cr_route("default", "proxy", "$rU", "$rU", "call_id")) {
+		xlog("L_ERR", "cr_route failed\n");
+		exit;
+	}
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}

+ 72 - 0
test/unit/30.sh

@@ -0,0 +1,72 @@
+#!/bin/bash
+# do some routing with carrierroute route sets from a config file
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+if ! (check_sipp && check_kamailio && check_module "carrierroute"); then
+	exit 0
+fi ;
+
+CFG=30.cfg
+
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "modparam(\"carrierroute\", \"config_file\", \"`pwd`/../test/carrierroute-2.cfg\")" >> $CFG
+
+
+../$BIN -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+	# the distribution is not perfect
+	sipp -sn uas -bg -i localhost -m 12 -p 7000 &> /dev/null
+	sipp -sn uas -bg -i localhost -m 12 -p 8000 &> /dev/null
+	sipp -sn uac -s 49721123456787 127.0.0.1:5060 -i 127.0.0.1 -m 20 -p 5061 &> /dev/null
+	ret=$?
+	killall sipp &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 9000 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s 49721123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+killall -9 sipp
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 57 - 0
test/unit/31.sh

@@ -0,0 +1,57 @@
+#!/bin/bash
+# database access with fetch_result for usrloc on mysql
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=11.cfg
+
+DOMAIN="local"
+# setup 500 contacts
+NR=50
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"usrloc\", \"fetch_rows\", 13)" >> $CFG
+
+COUNTER=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	$MYSQL "insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___');"
+done
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+$MYSQL "delete from location where user_agent = '___test___'"
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 59 - 0
test/unit/32.sh

@@ -0,0 +1,59 @@
+#!/bin/bash
+# database access with fetch_result for usrloc on postgres
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_postgres" && check_postgres); then
+	exit 0
+fi ;
+
+CFG=11.cfg
+
+DOMAIN="local"
+# setup 250 contacts
+NR=25
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
+echo "modparam(\"usrloc\", \"db_url\", \"postgres://openser:openserrw@localhost/openser\")" >> $CFG
+echo "modparam(\"usrloc\", \"fetch_rows\", 13)" >> $CFG
+
+
+COUNTER=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	$PSQL "insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___');"
+done
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+$PSQL "delete from location where user_agent = '___test___'"
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 28 - 0
test/unit/33.cfg

@@ -0,0 +1,28 @@
+debug=3
+memlog=2
+mpath="../modules/"
+loadmodule "cfgutils.so"
+loadmodule "pv.so"
+loadmodule "xlog.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+modparam("cfgutils", "initial_probability", 15)
+modparam("cfgutils", "hash_file", "33.cfg")
+
+modparam("pv", "shvset", "debug=i:1")
+modparam("pv", "shvset", "pstngw=s:sip:10.10.10.10")
+modparam("pv", "varset", "init=i:1")
+modparam("pv", "varset", "gw=s:sip:11.11.11.11;transport=tcp")
+
+route{
+	xlog("PGK status:");
+	usleep("100");
+	pkg_status();
+	sleep("1");
+	xlog("SHM status:");
+	shm_status();
+	abort();
+	xlog("end");
+}

+ 75 - 0
test/unit/33.sh

@@ -0,0 +1,75 @@
+#!/bin/bash
+# test cfgutils and pv module
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+if ! (check_netcat && check_kamailio); then
+	exit 0
+fi;
+
+if [ -e core ] ; then
+	echo "core file found, not run"
+	exit 0
+fi;
+
+CFG=33.cfg
+
+cp $CFG $CFG.bak
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+if [ $ret -eq 0 ] ; then
+	../scripts/$CTL fifo check_config_hash |grep "The actual config file hash is identical to the stored one." > /dev/null
+	ret=$?
+fi;
+
+echo " " >> $CFG
+if [ $ret -eq 0 ] ; then
+	../scripts/$CTL fifo check_config_hash |grep "The actual config file hash is identical to the stored one." /dev/null
+	ret=$?
+fi;
+
+if [ ! $ret -eq 0 ] ; then
+	# send a message
+	cat register.sip | nc -q 1 -u localhost 5060 > /dev/null
+fi;
+
+sleep 1
+$KILL &> /dev/null
+ret=$?
+
+if [ $ret -eq 0 ] ; then
+	ret=1
+else
+	ret=0
+fi;
+
+if [ ! -e core ] ; then
+	ret=1
+fi;
+rm core
+mv $CFG.bak $CFG
+
+exit $ret

+ 26 - 0
test/unit/34.cfg

@@ -0,0 +1,26 @@
+mpath="../modules"
+loadmodule "sl.so"
+loadmodule "tm.so"
+loadmodule "usrloc.so"
+loadmodule "presence.so"
+loadmodule "presence_xml.so"
+loadmodule "presence_mwi.so"
+loadmodule "pua.so"
+loadmodule "pua_bla.so"
+loadmodule "pua_mi.so"
+loadmodule "pua_usrloc.so"
+loadmodule "xmpp.so"
+loadmodule "pua_xmpp.so"
+loadmodule "xcap_client.so"
+loadmodule "rls.so"
+loadmodule "presence_dialoginfo.so"
+loadmodule "rr.so"
+loadmodule "dialog.so"
+loadmodule "pua_dialoginfo.so"
+
+modparam("rls", "xcap_root", "http://localhost/xcap-root:8000")
+modparam("presence_xml", "integrated_xcap_server", 1)
+modparam("pua_bla|pua_usrloc", "default_domain", "localhost")
+modparam("pua_bla", "header_name", "Sender")
+modparam("pua_bla|pua_xmpp", "server_address", "sip:[email protected]")
+modparam("dialog", "dlg_flag", 10)

+ 54 - 0
test/unit/34.sh

@@ -0,0 +1,54 @@
+#!/bin/bash
+# load all presence related modules with mysql
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+source include/database
+
+CFG=34.cfg
+
+if ! (check_kamailio && check_module "db_mysql" && check_module "presence" \
+		&& check_module "presence_xml" && check_module "pua" \
+		&& check_module "xcap_client" && check_module "rls" \
+		&& check_module "presence_mwi" && check_module "pua_bla" \
+		&& check_module "pua_mi" && check_module "pua_usrloc" \
+		&& check_module "pua_xmpp" && check_module "xmpp" \
+		&& check_module "presence_dialoginfo" && check_module "pua_dialoginfo" \
+		&& check_mysql); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 56 - 0
test/unit/35.cfg

@@ -0,0 +1,56 @@
+# Kamailio config for lookup / registrar testing
+
+#------------------------Global configuration----------------------------------
+debug=3
+fork=yes
+log_stderror=no
+listen=127.0.0.1
+port=5060
+dns=no
+rev_dns=no
+
+#-----------------------Loading Modules-------------------------------------
+mpath="../modules/"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "pv/pv.so"
+loadmodule "permissions/permissions.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "mi_fifo/mi_fifo.so"
+loadmodule "xlog/xlog.so"
+
+
+#-----------------------Module parameters-------------------------------------
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc|permissions", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+#-----------------------Routing configuration---------------------------------#
+route{
+if (!mf_process_maxfwd_header("10")) {
+	sl_send_reply("483","Too Many Hops");
+	exit();
+}
+
+if (!allow_address("0", "$si", "$sp") || !allow_source_address("0")) {
+	#xlog("permissions allow_address");
+	sl_send_reply("403", "Forbidden");
+}
+
+if (!allow_trusted())  {
+	xlog("permissions allow_trusted");
+	sl_send_reply("403", "Forbidden");
+}
+
+if(!lookup ("location")){
+	sl_send_reply("404", "Not Found");
+}
+
+if (!t_relay()) {
+	sl_reply_error();
+	}
+}
+

+ 72 - 0
test/unit/35.sh

@@ -0,0 +1,72 @@
+#!/bin/bash
+# check permissions module functionality
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=35.cfg
+SRV=5060
+UAS=5070
+UAC=5080
+IP="127.0.0.31"
+MASK=27
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+$MYSQL "INSERT INTO trusted (src_ip, proto) VALUES (\"127.0.0.1\",\"any\");"
+
+$MYSQL "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
+
+../$BIN -w . -f $CFG &> /dev/null
+sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
+sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null
+ret=$?
+$MYSQL "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
+
+if [ "$ret" -eq 0 ] ; then
+	killall sipp
+	IP="127.47.6.254"
+	MASK=10
+	$MYSQL "INSERT INTO address (ip_addr, mask) VALUES ('$IP', '$MASK');"
+	
+	../scripts/$CTL fifo address_reload
+	#../scripts/$CTL fifo address_dump
+
+	sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null
+	sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null
+	ret=$?
+	$MYSQL "DELETE FROM address WHERE (ip_addr='$IP' AND mask='$MASK');"
+fi;
+
+
+# cleanup
+killall -9 sipp > /dev/null 2>&1
+$KILL > /dev/null 2>&1
+
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+$MYSQL "DELETE FROM trusted WHERE (src_ip=\"127.0.0.1\");"
+
+exit $ret;

+ 72 - 0
test/unit/36.sh

@@ -0,0 +1,72 @@
+#!/bin/bash
+# private memory effiency and fragmentation with ul_dump w/ or w/o PKG_MALLOC
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=11.cfg
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+
+# 1768 contacts should fit into 1 MB of PKG memory
+../$BIN -V | grep "PKG_MALLOC" > /dev/null
+if [ $? -eq 0 ]; then
+	NR=176
+else
+	NR=277
+fi;
+
+COUNTER=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	$MYSQL "insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___'); insert into location (username, domain, contact, user_agent) values ('foobar-$COUNTER-$RANDOM', 'local', 'foobar-$COUNTER-$RANDOM@$DOMAIN', '___test___');"
+done
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+if [ $ret -eq 0 ]; then
+	sleep 1
+	for ((i=1;i<=100;i+=1)); do
+		tmp=`../scripts/$CTL fifo ul_dump | grep "AOR" | wc -l`
+		NR_=$(($NR * 10))
+		if ! [ $tmp -eq $NR_ ]; then
+			ret=1
+			break;
+		fi;
+	done
+fi;
+
+sleep 1
+$KILL
+
+$MYSQL "delete from location where user_agent = '___test___'"
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 118 - 0
test/unit/37.sh

@@ -0,0 +1,118 @@
+#!/bin/bash
+# loading times for bigger carrierroute config from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+CFG=13.cfg
+# number of routes, multiplied with 10
+# if you want to increase this above 4500, comment the fifo command below,
+# otherwise this will fails with memory allocation errors (with 1MB PKG mem)
+NR=450
+
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+
+# setup database
+$MYSQL "insert into carrier_name (id, carrier) values ('1', 'default');"
+$MYSQL "insert into carrier_name (id, carrier) values ('2', 'carrier2');"
+$MYSQL "insert into carrier_name (id, carrier) values ('3', 'carrier3');"
+$MYSQL "insert into carrier_name (id, carrier) values ('4', 'carrier4');"
+$MYSQL "insert into carrier_name (id, carrier) values ('5', 'carrier5');"
+$MYSQL "insert into carrier_name (id, carrier) values ('6', 'carrier6');"
+$MYSQL "insert into carrier_name (id, carrier) values ('7', 'carrier7');"
+$MYSQL "insert into carrier_name (id, carrier) values ('8', 'carrier8');"
+$MYSQL "insert into carrier_name (id, carrier) values ('9', 'carrier9');"
+$MYSQL "insert into carrier_name (id, carrier) values ('10', 'carrier10');"
+$MYSQL "insert into carrier_name (id, carrier) values ('11', 'carrier11');"
+
+
+COUNTER=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	domain=`expr $COUNTER % 9`
+	$MYSQL "insert into domain_name (id, domain) values ('$COUNTER', '$domain');"
+	$MYSQL "insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('2','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('3','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('4','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('5','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('6','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('7','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('8','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('9','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('10','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('11','$COUNTER','$RANDOM','0.5','0','host-$RANDOM');"
+
+done
+
+../$BIN -m 128 -w . -f $CFG > /dev/null
+ret=$?
+
+# adjust if you have bigger rule sets
+sleep 20
+
+cd ../scripts
+
+if [ $ret -eq 0 ] ; then
+	tmp=`./$CTL fifo cr_dump_routes | grep "host-" | wc -l`
+	let "TMPNR = $NR * 10"
+	if ! [ $tmp -eq $TMPNR ]; then
+		ret=1
+	fi;
+fi ;
+
+$KILL
+
+# cleanup database
+$MYSQL "delete from carrier_name where id = 1;"
+$MYSQL "delete from carrier_name where id = 2;"
+$MYSQL "delete from carrier_name where id = 3;"
+$MYSQL "delete from carrier_name where id = 4;"
+$MYSQL "delete from carrier_name where id = 5;"
+$MYSQL "delete from carrier_name where id = 6;"
+$MYSQL "delete from carrier_name where id = 7;"
+$MYSQL "delete from carrier_name where id = 8;"
+$MYSQL "delete from carrier_name where id = 9;"
+$MYSQL "delete from carrier_name where id = 10;"
+$MYSQL "delete from carrier_name where id = 11;"
+
+COUNTER=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	$MYSQL "delete from domain_name where id = $COUNTER;"
+done
+
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierroute where carrier=4;"
+$MYSQL "delete from carrierroute where carrier=5;"
+$MYSQL "delete from carrierroute where carrier=6;"
+$MYSQL "delete from carrierroute where carrier=7;"
+$MYSQL "delete from carrierroute where carrier=8;"
+$MYSQL "delete from carrierroute where carrier=9;"
+$MYSQL "delete from carrierroute where carrier=10;"
+$MYSQL "delete from carrierroute where carrier=11;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 48 - 0
test/unit/38.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+# load all modules without external dependencies with unixodbc
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+# Needs a default kamailio database setup for unixodbc
+
+if ! (check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
+	exit 0
+fi ;
+
+CFG=2.cfg
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_unixodbc/db_unixodbc.so\"" >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"unixodbc://openserro:openserro@localhost/openser\")" >> $CFG
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+mv $CFG.bak $CFG
+rm -f dispatcher.list
+
+exit $ret

+ 62 - 0
test/unit/39.sh

@@ -0,0 +1,62 @@
+#!/bin/bash
+# database access with fetch_result for usrloc on unixodbc
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipp && check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
+	exit 0
+fi ;
+
+
+CFG=11.cfg
+
+DOMAIN="local"
+# setup 250 contacts
+NR=25
+
+cp $CFG $CFG.bak
+
+echo "loadmodule \"db_unixodbc/db_unixodbc.so\"" >> $CFG
+echo "modparam(\"usrloc\", \"db_url\", \"unixodbc://openser:openserrw@localhost/openser\")" >> $CFG
+echo "modparam(\"usrloc\", \"fetch_rows\", 13)" >> $CFG
+
+# isql unfortunally only allow one statement per line
+COUNTER=0
+CNT=0
+while [  $COUNTER -lt $NR ]; do
+	COUNTER=$(($COUNTER+1))
+	echo -e "insert into location (id, username, domain, contact, user_agent) values ('$CNT', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+1', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+2', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+3', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+4', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+5', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+6', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+7', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+8', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n insert into location (id, username, domain, contact, user_agent) values ('$CNT+9', 'foobar-$RANDOM', '$DOMAIN', 'foobar-$RANDOM@$DOMAIN', '___test___'); \n " | $ISQL > /dev/null
+	CNT=$(($CNT+10))
+done
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 2
+$KILL
+
+echo "delete from location where user_agent = '___test___'" | $ISQL > /dev/null
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 54 - 0
test/unit/4.sh

@@ -0,0 +1,54 @@
+#!/bin/bash
+# test basic fifo functionality
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+CFG=4.cfg
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+
+# setup config
+echo -e "loadmodule \"../modules/mi_fifo/mi_fifo.so\"" > $CFG
+echo -e "modparam(\"mi_fifo\", \"fifo_name\", \"/tmp/kamailio_fifo\")" >> $CFG
+
+
+        
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ] ; then
+	sleep 1
+	./$CTL ps > /dev/null
+	ret=$?
+fi ;
+
+cd ../test
+
+$KILL
+
+rm -f $CFG
+
+exit $ret

+ 32 - 0
test/unit/40.cfg

@@ -0,0 +1,32 @@
+mpath="../modules"
+
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "pike/pike.so"
+loadmodule "xlog/xlog.so"
+
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+modparam("pike", "sampling_time_unit", 5)
+modparam("pike", "reqs_density_per_unit", 25)
+modparam("pike", "remove_latency", 5)
+modparam("pike", "pike_log_level", 2)
+ 
+route{
+	if (!pike_check_req()) {
+		xlog("drop request");
+		sl_send_reply("500", "overloaded");
+	}
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+	}
+
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}

+ 73 - 0
test/unit/40.sh

@@ -0,0 +1,73 @@
+#!/bin/bash
+# check pike module
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+source include/database
+
+CFG=40.cfg
+SRV=5060
+UAS=5070
+UAC=5080
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+
+# start
+../$BIN -w . -f $CFG &> /dev/null
+ret=$?
+
+# this should work
+if [ "$ret" -eq 0 ]; then
+	sipp -sn uas -bg -i localhost -m 10 -p $UAS &> /dev/null
+	sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -p $UAC &> /dev/null
+	ret=$?
+fi;
+
+# this should be trigger the blocking
+if [ "$ret" -eq 0 ]; then
+	killall -9 sipp > /dev/null 2>&1
+	sipp -sn uas -bg -i localhost -m 11 -p $UAS &> /dev/null
+	sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 11 -p $UAC &> /dev/null
+	ret=$?
+fi;
+
+# this should work again after the timeout
+if [ "$ret" -eq 1 ]; then
+	sleep 7
+	killall -9 sipp > /dev/null 2>&1
+	sipp -sn uas -bg -i localhost -m 15 -p $UAS &> /dev/null
+	sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 15 -p $UAC &> /dev/null
+	ret=$?
+fi;
+
+sleep 1
+$KILL
+killall -9 sipp > /dev/null 2>&1
+
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+exit $ret

+ 44 - 0
test/unit/41.cfg

@@ -0,0 +1,44 @@
+memlog=1
+debug=1
+children=1
+mpath="../modules"
+
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "pv/pv.so"
+loadmodule "avpops/avpops.so"
+loadmodule "mi_fifo/mi_fifo.so"
+loadmodule "xlog/xlog.so"
+
+modparam("usrloc", "db_mode", 3)
+modparam("usrloc|avpops", "db_url", "mysql://openser:openserrw@localhost/openser")
+
+modparam("avpops","avp_table","usr_preferences")
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+route{
+	$avp(s:10) = "foobar";
+	if (!avp_db_load("$avp(s:10)", "$avp(s:679)")) {
+		xlog("avp_db_load failed");
+		sl_reply_error();
+		exit;
+	}
+	
+	$avp(s:679) = "blafasel";
+	if (!avp_db_store("$avp(s:10)", "$avp(s:679)")) {
+		xlog("avp_db_store failed");
+		sl_reply_error();
+		exit;
+	}
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+	}
+
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}

+ 61 - 0
test/unit/41.sh

@@ -0,0 +1,61 @@
+#!/bin/bash
+# test one out of PKG_MEM condition with avpops module
+
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+source include/database
+
+CFG=41.cfg
+SRV=5060
+UAS=5070
+UAC=5080
+
+NR=200
+RT=50
+
+if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+# add an registrar entry to the db;
+$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost:$UAS\",\"udp:127.0.0.1:$UAS\",\"ser_test\",1,-1);"
+
+$MYSQL "INSERT INTO usr_preferences (uuid, attribute, type, value) VALUES (\"foobar\", \"679\", 0, \"foobar!!!!!\");"
+
+# start
+../$BIN -w . -f $CFG &> /dev/null
+ret=$?
+
+if [ "$ret" -eq 0 ]; then
+	sipp -sn uas -bg -i localhost -m $NR -r $RT -p $UAS &> /dev/null
+	sipp -sn uac -s foo 127.0.0.1:$SRV -r $RT -i localhost -m $NR -p $UAC &> /dev/null
+	ret=$?
+fi;
+
+sleep 1
+$KILL
+killall -9 sipp > /dev/null 2>&1
+
+$MYSQL "DELETE FROM location WHERE ((contact = \"sip:foo@localhost:$UAS\") and (user_agent = \"ser_test\"));"
+$MYSQL "DELETE FROM usr_preferences;"
+exit $ret

+ 150 - 0
test/unit/42.sh

@@ -0,0 +1,150 @@
+#!/bin/bash
+# do some (non numerical) routing with carrierroute route sets from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=26.cfg
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+echo "modparam(\"carrierroute\", \"match_mode\", 128)" >> $CFG
+
+# setup database
+$MYSQL "insert into carrier_name (id, carrier) values ('1', 'default');"
+$MYSQL "insert into carrier_name (id, carrier) values ('2', 'carrier1');"
+$MYSQL "insert into carrier_name (id, carrier) values ('3', 'carrier2');"
+
+$MYSQL "insert into domain_name (id, domain) values ('10', 'domain0');"
+$MYSQL "insert into domain_name (id, domain) values ('1', 'fallback');"
+$MYSQL "insert into domain_name (id, domain) values ('2', 'domain2');"
+
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob, strip, rewrite_host)
+values ('1','1','10','ab4-','0','0.5','0','127.0.0.1:7000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob, strip, rewrite_host)
+values ('2','1','10','ab4-','0','0.5','0','127.0.0.1:8000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob, strip, rewrite_host)
+values ('3','2','10','ab4-','0','1','0','127.0.0.1:9000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask,prob, strip, rewrite_host)
+values ('4','3','10','ab4-','0', '3', '1','0','127.0.0.1:10001');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask,prob, strip, rewrite_host)
+values ('5','3','10','ab4-','1', '3', '1','0','127.0.0.1:10000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, mask, prob, strip, rewrite_host)
+values ('6','3','10','ab4-','2', '3', '1','0','127.0.0.1:10002');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob, strip, rewrite_host)
+values ('7','3','1','ab4-','0','1','0','127.0.0.1:10000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, flags, prob, strip, rewrite_host)
+values ('8','3','2','ab4-','0','1','0','127.0.0.1:10000');"
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('1', '3', '10', 'ab4-', '127.0.0.1:10000', '5..', '0', '0', '1');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('2', '3', '1', 'ab4-', '127.0.0.1:10000', '483', '0', '0', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('3', '3', '1', 'ab4-', '127.0.0.1:9000', '4..', '0', '0', '2');"
+
+$MYSQL "alter table subscriber add cr_preferred_carrier int(10) default NULL;"
+
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('ab4-123456786', 2);"
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('ab4-123456785', 3);"
+
+
+../$BIN -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 12 -p 7000 &> /dev/null
+	sipp -sn uas -bg -i localhost -m 12 -p 8000 &> /dev/null
+	sipp -sn uac -s ab4-123456787 127.0.0.1:5060 -i 127.0.0.1 -m 20 -p 5061 &> /dev/null
+	ret=$?
+	killall sipp &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 9000 &> /dev/null
+	sipp -sn uac -s ab4-123456786 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s ab4-123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ] ; then
+	killall sipp &> /dev/null
+	sipp -sf failure_route.xml -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s ab4-123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('4', '3', '1', 'ab4-', '127.0.0.1:10000', '4..', '0', '0', '4');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code,
+flags, mask, next_domain) values ('5', '3', '1', 'ab4-', '127.0.0.1:10000', '486', '0', '0', '2');"
+
+if [ ! "$ret" -eq 0 ] ; then
+	../scripts/$CTL fifo cr_reload_routes
+	killall sipp &> /dev/null
+	sipp -sf failure_route.xml -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s ab4-123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+
+$KILL
+killall -9 sipp
+
+# cleanup database
+$MYSQL "delete from carrier_name where id = 1;"
+$MYSQL "delete from carrier_name where id = 2;"
+$MYSQL "delete from carrier_name where id = 3;"
+$MYSQL "delete from domain_name where id = 10;"
+$MYSQL "delete from domain_name where id = 1;"
+$MYSQL "delete from domain_name where id = 2;"
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierfailureroute where carrier=1;"
+$MYSQL "delete from carrierfailureroute where carrier=2;"
+$MYSQL "delete from carrierfailureroute where carrier=3;"
+
+$MYSQL "delete from subscriber where username='ab4-123456786';"
+$MYSQL "delete from subscriber where username='ab4-123456785';"
+$MYSQL "alter table subscriber drop cr_preferred_carrier;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret

+ 98 - 0
test/unit/43.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+# check forward functionality in utils module
+
+# Copyright (C) 2009 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_kamailio && check_module "utils" && check_module "db_mysql" && check_mysql); then
+	exit 0
+fi ;
+
+CFG=43.cfg
+TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX`
+
+# setup config
+echo "mpath=\"../modules\"" >> $CFG
+echo "loadmodule \"sl/sl.so\"" >> $CFG
+echo "loadmodule \"mi_fifo/mi_fifo.so\"" >> $CFG
+echo "loadmodule \"utils/utils.so\"" >> $CFG
+echo "modparam(\"mi_fifo\", \"fifo_name\", \"/tmp/kamailio_fifo\")" >> $CFG
+echo "modparam(\"utils\", \"forward_active\", 1)" >> $CFG
+echo "route {sl_send_reply(\"404\", \"forbidden\");}" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+../scripts/$CTL fifo forward_list &> /dev/null
+../scripts/$CTL fifo forward_filter 0=REGISTER:INVITE &> /dev/null
+../scripts/$CTL fifo forward_list &> /dev/null
+../scripts/$CTL fifo forward_proxy 0=localhost:7000 &> /dev/null
+../scripts/$CTL fifo forward_list > $TMPFILE 
+
+tmp=`grep -v "Printing forwarding information:
+id switch                         filter proxy
+ 0 off                    REGISTER:INVITE localhost:7000" $TMPFILE`
+if [ "$tmp" = "" ] ; then
+	ret=0
+else
+	ret=1
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uac -s 123456787 127.0.0.1:5060 -i 127.0.0.1 -m 1 -nr &> /dev/null
+	ret=$?
+	killall sipp &> /dev/null
+fi;
+
+if ! [ "$ret" -eq 0 ] ; then
+	../scripts/$CTL fifo forward_switch 0=on
+	../scripts/$CTL fifo forward_list > $TMPFILE
+	tmp=`grep -v "Printing forwarding information:
+id switch                         filter proxy
+ 0 on                    REGISTER:INVITE localhost:7000" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+
+	nc -l -u -p 7000 1> $TMPFILE 2> /dev/null &
+	sipp -sn uac -s 123456787 127.0.0.1:5060 -i 127.0.0.1 -m 1 -nr  &> /dev/null
+	killall sipp &> /dev/null
+	killall nc &> /dev/null
+fi;
+
+NR=`cat $TMPFILE | grep "INVITE sip:" | wc -l`
+if [ "$NR" -eq 1 ] ; then
+	ret=0
+else
+	ret=1
+fi;
+
+rm $CFG
+rm $TMPFILE
+$KILL
+
+exit $ret

+ 112 - 0
test/unit/44.sh

@@ -0,0 +1,112 @@
+#!/bin/bash
+# database access and persistent storage for registrar on unixodbc
+
+# Copyright (C) 2009 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+source include/database
+
+if ! (check_sipsak && check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
+	exit 0
+fi ;
+
+CFG=11.cfg
+
+cp $CFG $CFG.tmp
+echo "loadmodule \"db_unixodbc/db_unixodbc.so\"" >> $CFG
+echo "modparam(\"usrloc\", \"db_url\", \"unixodbc://openser:openserrw@localhost/openser\")" >> $CFG
+
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+# register a user
+sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+ret=$?
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" > /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	TMP=`echo "select COUNT(*) from location where username='49721123456789';" | $ISQL`
+	if [ "$TMP" -eq 0 ] ; then
+		ret=1
+	fi;
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	# unregister the user
+	sipsak -U -C "*" -s sip:[email protected] -H localhost -x 0 &> /dev/null
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "AOR:: 49721123456789" > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ]; then
+		ret=1
+	else
+		ret=0
+	fi;
+fi;
+
+if [ "$ret" -eq 0 ]; then
+	ret=`echo "select COUNT(*) from location where username='49721123456789';" | $ISQL`
+fi;
+
+echo "delete from location where username like '49721123456789%';" | $ISQL
+
+if [ "$ret" -eq 0 ]; then
+	# register again
+	sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+
+# restart to test preload_udomain functionality
+../$BIN -w . -f ../test/$CFG > /dev/null
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ]; then
+	# check if the contact is still registered
+	sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
+	ret=$?
+fi;
+
+# check if the methods value is correct
+if [ "$ret" -eq 0 ]; then
+	./$CTL ul show | grep "Methods:: 4294967295" &> /dev/null
+	ret=$?
+fi;
+
+$KILL
+
+echo "delete from location where username like '49721123456789%';" | $ISQL
+
+cd ../test
+mv $CFG.tmp $CFG
+
+exit $ret

+ 427 - 0
test/unit/5.cfg

@@ -0,0 +1,427 @@
+#
+# $Id$
+#
+# Kamailio basic configuration script
+#     by Anca Vamanu <[email protected]>
+#
+# Please refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
+# for a explanation of possible statements, functions and parameters.
+#
+
+
+####### Global Parameters #########
+
+debug=3
+log_stderror=no
+log_facility=LOG_LOCAL0
+
+fork=yes
+children=4
+
+/* uncomment the following lines to enable debugging */
+#debug=6
+#fork=no
+#log_stderror=yes
+
+/* uncomment the next line to disable TCP (default on) */
+#disable_tcp=yes
+
+/* uncomment the next line to enable the auto temporary blacklisting of 
+   not available destinations (default disabled) */
+#disable_dns_blacklist=no
+
+/* uncomment the next line to enable IPv6 lookup after IPv4 dns 
+   lookup failures (default disabled) */
+#dns_try_ipv6=yes
+
+/* uncomment the next line to disable the auto discovery of local aliases
+   based on revers DNS on IPs (default on) */
+#auto_aliases=no
+
+/* uncomment the following lines to enable TLS support  (default off) */
+#disable_tls = no
+#listen = tls:your_IP:5061
+#tls_verify_server = 1
+#tls_verify_client = 1
+#tls_require_client_certificate = 0
+#tls_method = TLSv1
+#tls_certificate = "/usr/local/etc/kamailio/tls/user/user-cert.pem"
+#tls_private_key = "/usr/local/etc/kamailio/tls/user/user-privkey.pem"
+#tls_ca_list = "/usr/local/etc/kamailio/tls/user/user-calist.pem"
+
+
+port=5060
+
+/* uncomment and configure the following line if you want kamailio to 
+   bind on a specific interface/port/proto (default bind on all available) */
+#listen=udp:192.168.1.2:5060
+
+
+####### Modules Section ########
+
+#set module path
+mpath="../modules"
+
+/* uncomment next line for MySQL DB support */
+#loadmodule "db_mysql.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "pv/pv.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "textops/textops.so"
+loadmodule "mi_fifo/mi_fifo.so"
+loadmodule "uri_db/uri_db.so"
+loadmodule "siputils/siputils.so"
+loadmodule "xlog/xlog.so"
+loadmodule "acc/acc.so"
+
+/* uncomment next lines for MySQL based authentication support 
+   NOTE: a DB (like db_mysql) module must be also loaded */
+#loadmodule "auth.so"
+#loadmodule "auth_db.so"
+/* uncomment next line for aliases support
+   NOTE: a DB (like db_mysql) module must be also loaded */
+#loadmodule "alias_db.so"
+/* uncomment next line for multi-domain support
+   NOTE: a DB (like db_mysql) module must be also loaded
+   NOTE: be sure and enable multi-domain support in all used modules
+         (see "multi-module params" section ) */
+#loadmodule "domain.so"
+/* uncomment the next two lines for presence server support
+   NOTE: a DB (like db_mysql) module must be also loaded */
+#loadmodule "presence.so"
+#loadmodule "presence_xml.so"
+
+
+# ----------------- setting module-specific parameters ---------------
+
+
+# ----- mi_fifo params -----
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+
+
+# ----- rr params -----
+# add value to ;lr param to cope with most of the UAs
+modparam("rr", "enable_full_lr", 1)
+# do not append from tag to the RR (no need for this script)
+modparam("rr", "append_fromtag", 0)
+
+
+# ----- rr params -----
+modparam("registrar", "method_filtering", 1)
+/* uncomment the next line to disable parallel forking via location */
+# modparam("registrar", "append_branches", 0)
+/* uncomment the next line not to allow more than 10 contacts per AOR */
+#modparam("registrar", "max_contacts", 10)
+
+
+# ----- uri_db params -----
+/* by default we disable the DB support in the module as we do not need it
+   in this configuration */
+modparam("uri_db", "use_uri_table", 0)
+modparam("uri_db", "db_url", "")
+
+
+# ----- acc params -----
+/* what sepcial events should be accounted ? */
+modparam("acc", "early_media", 1)
+modparam("acc", "report_ack", 1)
+modparam("acc", "report_cancels", 1)
+/* by default ww do not adjust the direct of the sequential requests.
+   if you enable this parameter, be sure the enable "append_fromtag"
+   in "rr" module */
+modparam("acc", "detect_direction", 0)
+/* account triggers (flags) */
+modparam("acc", "failed_transaction_flag", 3)
+modparam("acc", "log_flag", 1)
+modparam("acc", "log_missed_flag", 2)
+/* uncomment the following lines to enable DB accounting also */
+modparam("acc", "db_flag", 1)
+modparam("acc", "db_missed_flag", 2)
+
+
+# ----- usrloc params -----
+modparam("usrloc", "db_mode",   0)
+/* uncomment the following lines if you want to enable DB persistency
+   for location entries */
+#modparam("usrloc", "db_mode",   2)
+#modparam("usrloc", "db_url",
+#	"mysql://kamailio:[email protected]/kamailio_1_3")
+
+
+# ----- auth_db params -----
+/* uncomment the following lines if you want to enable the DB based
+   authentication */
+#modparam("auth_db", "calculate_ha1", yes)
+#modparam("auth_db", "password_column", "password")
+#modparam("auth_db", "db_url",
+#	"mysql://kamailio:[email protected]/kamailio_1_3")
+#modparam("auth_db", "load_credentials", "")
+
+
+# ----- alias_db params -----
+/* uncomment the following lines if you want to enable the DB based
+   aliases */
+#modparam("alias_db", "db_url",
+#	"mysql://kamailio:[email protected]/kamailio_1_3")
+
+
+# ----- domain params -----
+/* uncomment the following lines to enable multi-domain detection
+   support */
+#modparam("domain", "db_url",
+#	"mysql://kamailio:[email protected]/kamailio_1_3")
+#modparam("domain", "db_mode", 1)   # Use caching
+
+
+# ----- multi-module params -----
+/* uncomment the following line if you want to enable multi-domain support
+   in the modules (dafault off) */
+#modparam("alias_db|auth_db|usrloc|uri_db", "use_domain", 1)
+
+
+# ----- presence params -----
+/* uncomment the following lines if you want to enable presence */
+#modparam("presence|presence_xml", "db_url",
+#	"mysql://kamailio:[email protected]/kamailio_1_3")
+#modparam("presence_xml", "force_active", 1)
+#modparam("presence", "server_address", "sip:192.168.1.2:5060")
+
+
+####### Routing Logic ########
+
+
+# main request routing logic
+
+route{
+
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit;
+	}
+
+	if (has_totag()) {
+		# sequential request withing a dialog should
+		# take the path determined by record-routing
+		if (loose_route()) {
+			if (is_method("BYE")) {
+				setflag(1); # do accouting ...
+				setflag(3); # ... even if the transaction fails
+			}
+			route(1);
+		} else {
+			/* uncomment the following lines if you want to enable presence */
+			##if (is_method("SUBSCRIBE") && $rd == "your.server.ip.address") {
+			##	# in-dialog subscribe requests
+			##	route(2);
+			##	exit;
+			##}
+			if ( is_method("ACK") ) {
+				if ( t_check_trans() ) {
+					# non loose-route, but stateful ACK; must be an ACK after a 487 or e.g. 404 from upstream server
+					t_relay();
+					exit;
+				} else {
+					# ACK without matching transaction ... ignore and discard.\n");
+					exit;
+				}
+			}
+			sl_send_reply("404","Not here");
+		}
+		exit;
+	}
+
+	#initial requests
+
+	# CANCEL processing
+	if (is_method("CANCEL"))
+	{
+		if (t_check_trans())
+			t_relay();
+		exit;
+	}
+
+	t_check_trans();
+
+	# authenticate if from local subscriber (uncomment to enable auth)
+	##if (!(method=="REGISTER") && from_uri==myself)
+	##{
+	##	if (!proxy_authorize("", "subscriber")) {
+	##		proxy_challenge("", "0");
+	##		exit;
+	##	}
+	##	if (!check_from()) {
+	##		sl_send_reply("403","Forbidden auth ID");
+	##		exit;
+	##	}
+	##
+	##	consume_credentials();
+	##	# caller authenticated
+	##}
+
+	# record routing
+	if (!is_method("REGISTER|MESSAGE"))
+		record_route();
+
+	# account only INVITEs
+	if (is_method("INVITE")) {
+		setflag(1); # do accouting
+	}
+	if (!uri==myself)
+	/* replace with following line if multi-domain support is used */
+	##if (!is_uri_host_local())
+	{
+		append_hf("P-hint: outbound\r\n"); 
+		# if you have some interdomain connections via TLS
+		##if($rd=="tls_domain1.net") {
+		##	t_relay("tls:domain1.net");
+		##	exit;
+		##} else if($rd=="tls_domain2.net") {
+		##	t_relay("tls:domain2.net");
+		##	exit;
+		##}
+		route(1);
+	}
+
+	# requests for my domain
+
+	/* uncomment this if you want to enable presence server 
+	   and comment the next 'if' block
+	   NOTE: uncomment also the definition of route[2] from  below */
+	##if( is_method("PUBLISH|SUBSCRIBE"))
+	##		route(2);
+
+	if (is_method("PUBLISH"))
+	{
+		sl_send_reply("503", "Service Unavailable");
+		exit;
+	}
+	
+
+	if (is_method("REGISTER"))
+	{
+		# authenticate the REGISTER requests (uncomment to enable auth)
+		##if (!www_authorize("", "subscriber"))
+		##{
+		##	www_challenge("", "0");
+		##	exit;
+		##}
+		##
+		##if (!check_to()) 
+		##{
+		##	sl_send_reply("403","Forbidden auth ID");
+		##	exit;
+		##}
+
+		if (!save("location"))
+			sl_reply_error();
+
+		exit;
+	}
+
+	if ($rU==NULL) {
+		# request with no Username in RURI
+		sl_send_reply("484","Address Incomplete");
+		exit;
+	}
+
+	# apply DB based aliases (uncomment to enable)
+	##alias_db_lookup("dbaliases");
+
+	if (!lookup("location")) {
+		switch ($retcode) {
+			case -1:
+			case -3:
+				t_newtran();
+				t_reply("404", "Not Found");
+				exit;
+			case -2:
+				sl_send_reply("405", "Method Not Allowed");
+				exit;
+		}
+	}
+
+	# when routing via usrloc, log the missed calls also
+	setflag(2);
+
+	route(1);
+}
+
+
+route[1] {
+	# for INVITEs enable some additional helper routes
+	if (is_method("INVITE")) {
+		t_on_branch("2");
+		t_on_reply("2");
+		t_on_failure("1");
+	}
+
+	if (!t_relay()) {
+		sl_reply_error();
+	};
+	exit;
+}
+
+
+# Presence route
+/* uncomment the whole following route for enabling presence
+   NOTE: do not forget to enable the call of this route from the main
+     route */
+##route[2]
+##{
+##	if (!t_newtran())
+##	{
+##		sl_reply_error();
+##		exit;
+##	};
+##
+##	if(is_method("PUBLISH"))
+##	{
+##		handle_publish();
+##		t_release();
+##	}
+##	else
+##	if( is_method("SUBSCRIBE"))
+##	{
+##		handle_subscribe();
+##		t_release();
+##	}
+##
+##	exit;
+##}
+
+
+branch_route[2] {
+	xlog("new branch at $ru\n");
+}
+
+
+onreply_route[2] {
+	xlog("incoming reply\n");
+}
+
+
+failure_route[1] {
+	if (t_was_cancelled()) {
+		exit;
+	}
+
+	# uncomment the following lines if you want to block client 
+	# redirect based on 3xx replies.
+	##if (t_check_status("3[0-9][0-9]")) {
+	##t_reply("404","Not found");
+	##	exit;
+	##}
+
+	# uncomment the following lines if you want to redirect the failed 
+	# calls to a different new destination
+	##if (t_check_status("486|408")) {
+	##	sethostport("192.168.2.100:5060");
+	##	append_branch();
+	##	# do not set the missed call flag again
+	##	t_relay();
+	##}
+}

+ 41 - 0
test/unit/5.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+# loads the kamailio default config
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+
+CFG=5.cfg
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+        
+
+# start
+../$BIN -w . -f $CFG &> /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+exit $ret

+ 40 - 0
test/unit/6.sh

@@ -0,0 +1,40 @@
+#!/bin/bash
+# checks a configuration with 'kamailio -c' and 'kamailio -C'
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+source include/require
+
+CFG=2.cfg
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+
+# start
+../$BIN -w . -c -f $CFG > /dev/null 2>&1
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	../$BIN -C -f $CFG > /dev/null 2>&1
+	ret=$?
+fi ;
+
+exit $ret

+ 1134 - 0
test/unit/7.cfg

@@ -0,0 +1,1134 @@
+########################################################################
+# This configuration is autogenerated by sip:wizard
+# (http://www.sipwise.com/wizard) on Fri Nov 09 17:06:52 +0100 2007
+# for Kamailio 1.2
+#
+# Copyright (C) 2007 Sipwise ([email protected])
+########################################################################
+
+########################################################################
+# By obtaining, using, and/or copying this configuration and/or its
+# associated documentation, you agree that you have read, understood,
+# and will comply with the Terms of Usage provided at
+# http://www.sipwise.com/news/?page_id=6 as well as the following
+# additions:
+#
+# Permission to use, copy, modify, and distribute this configuration and
+# its associated documentation for any purpose and without fee is hereby
+# granted, provided that the above copyright notice appears in all
+# copies, and that both that copyright notice and this permission notice
+# appear in supporting documentation, and that the name of Sipwise or
+# the author will not be used in advertising or publicity pertaining to
+# distribution of the configuration without specific, written prior
+# permission.
+########################################################################
+
+########################################################################
+# Before using this configuration, read the following prerequisites in
+# order to gain the designated functionallity:
+#
+# base:
+#    You have to insert all locally served domains (i.e. 
+#    "kamailioctl domain add your.domain.com").
+#    
+# nat-mediaproxy:
+#    You have to install mediaproxy 
+#    (http://mediaproxy.ag-projects.com/) for relaying RTP traffic.
+#    
+# usr-preferences:
+#    This feature relies on UUID-based provisioning. Thus, you have 
+#    to add the uuid-column to the subscriber table ("alter table 
+#    subscriber add column uuid varchar(64);") and populate it with a 
+#    UUID (unique user identifier) per user, for example an 
+#    auto-incremented id.
+#    
+# offnet-incoming-sip:
+#    You have to populate the "trusted"-table with rules for 
+#    allowed peering hosts (i.e. src_ip="1.2.3.4", proto="udp", 
+#    from_pattern="^sip:.*@domain.of.peering.host$", tag="1234"). If the 
+#    feature "usr-preferences" is selected, the tag-value is used as 
+#    caller-uuid for such calls.
+#    
+# offnet-pstn:
+#    You have to add a routing entry for lcr (i.e. "kamailioctl  lcr 
+#    addroute '' '' 1 1"). Additionally, you have to add your gateways 
+#    (i.e. "kamailioctl lcr addgw my-test-gw 1.2.3.4 5060 sip udp 1").
+#    
+# ring-timeout:
+#    You have to provision the ring-timeout (AVP ringtimeout as 
+#    type 1) for each user in the usr_preferences table (i.e. 
+#    uuid='1234', username='', domain='', attribute='ringtimeout', 
+#    type=1, value='60'). If no timeout is provisioned, the default 
+#    timeout will be used.
+#    
+# cfu:
+#    You have to provision the call-forward-unconditional as full 
+#    SIP URI (AVP cfu as type 0) for each user in the usr_preferences 
+#    table (i.e. uuid='1234', username='', domain='', attribute='cfu', 
+#    type=0, value='sip:[email protected]').  Forwards to another user 
+#    in the same domain or to other domains are possible.
+#    
+# cfc:
+#    You have to provision the call-forward-conditional as full SIP 
+#    URI (AVP cfc as type 0) for each user in the usr_preferences table 
+#    (i.e. uuid='1234', username='', domain='', attribute='cfc', type=0, 
+#    value='sip:[email protected]').  Forwards to another user in the 
+#    same domain or to other domains are possible.
+#    
+# user-aliases:
+#    You have to add aliases for your users (i.e. "kamailioctl alias 
+#    add 01234567 sip:[email protected]" for usrloc-based aliases or 
+#    make entries into "dbaliases" table for db-based aliases)
+#    
+# cli:
+#    You have to provision the CLI as full SIP URI (AVP cli as type 
+#    0) for each user in the usr_preferences table (i.e. uuid='1234', 
+#    username='', domain='', attribute='cli', type=0, 
+#    value='sip:[email protected]').
+#    
+# clir:
+#    You have to provision '1' to enable CLIR and '0' to disable it 
+#    (AVP clir as type 1) for each user in the usr_preferences table 
+#    (i.e. uuid='1234', username='', domain='', attribute='clir', 
+#    type=1, value='1').
+#    
+# acc-db:
+#    You have to add the columns "src_leg" and "dst_leg" to your 
+#    acc-table ("alter table acc add column src_leg varchar(128); alter 
+#    table acc add column dst_leg varchar(128);").
+#    
+########################################################################
+
+########################################################################
+# Configuration 'sip:wizard - Fri Nov 09 17:06:52 +0100 2007'
+########################################################################
+
+listen = udp:127.0.0.1:5060
+mpath = "../modules"
+children = 8
+debug = 3
+fork = yes
+disable_tcp = no
+log_facility = LOG_DAEMON
+log_stderror = no
+tcp_children = 4
+mhomed = no
+server_signature = yes
+reply_to_via = no
+sip_warning = no
+check_via = no
+dns = no
+rev_dns = no
+disable_core_dump = no
+dns_try_ipv6 = yes
+dns_use_search_list = yes
+
+loadmodule "pv/pv.so"
+
+loadmodule "usrloc/usrloc.so"
+modparam("usrloc", "user_column", "username")
+modparam("usrloc", "domain_column", "domain")
+modparam("usrloc", "contact_column", "contact")
+modparam("usrloc", "expires_column", "expires")
+modparam("usrloc", "q_column", "q")
+modparam("usrloc", "callid_column", "callid")
+modparam("usrloc", "cseq_column", "cseq")
+modparam("usrloc", "methods_column", "methods")
+modparam("usrloc", "flags_column", "flags")
+modparam("usrloc", "user_agent_column", "user_agent")
+modparam("usrloc", "received_column", "received")
+modparam("usrloc", "socket_column", "socket")
+modparam("usrloc", "use_domain", 0)
+modparam("usrloc", "desc_time_order", 0)
+modparam("usrloc", "timer_interval", 60)
+modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("usrloc", "db_mode", 1)
+modparam("usrloc", "matching_mode", 0)
+modparam("usrloc", "cseq_delay", 20)
+modparam("usrloc", "nat_bflag", 6)
+
+loadmodule "maxfwd/maxfwd.so"
+modparam("maxfwd", "max_limit", 256)
+
+loadmodule "rr/rr.so"
+modparam("rr", "enable_full_lr", 0)
+modparam("rr", "append_fromtag", 1)
+modparam("rr", "enable_double_rr", 1)
+modparam("rr", "add_username", 0)
+
+loadmodule "tm/tm.so"
+modparam("tm", "fr_timer", 30)
+modparam("tm", "fr_inv_timer", 120)
+modparam("tm", "wt_timer", 5)
+modparam("tm", "delete_timer", 2)
+modparam("tm", "ruri_matching", 1)
+modparam("tm", "via1_matching", 1)
+modparam("tm", "unix_tx_timeout", 2)
+modparam("tm", "restart_fr_on_each_reply", 1)
+modparam("tm", "pass_provisional_replies", 0)
+modparam("tm", "fr_inv_timer_avp", "$avp(s:callee_fr_inv_timer)")
+
+loadmodule "xlog/xlog.so"
+modparam("xlog", "buf_size", 4096)
+modparam("xlog", "force_color", 0)
+
+loadmodule "mi_fifo/mi_fifo.so"
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
+modparam("mi_fifo", "reply_dir", "/tmp/")
+modparam("mi_fifo", "reply_indent", "\t")
+
+loadmodule "domain/domain.so"
+modparam("domain", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("domain", "db_mode", 1)
+modparam("domain", "domain_table", "domain")
+modparam("domain", "domain_col", "domain")
+
+loadmodule "nathelper/nathelper.so"
+modparam("nathelper", "natping_interval", 0)
+modparam("nathelper", "ping_nated_only", 1)
+modparam("nathelper", "rtpproxy_sock", "unix:/var/run/rtpproxy.sock")
+modparam("nathelper", "rtpproxy_disable_tout", 60)
+modparam("nathelper", "rtpproxy_tout", 1)
+modparam("nathelper", "rtpproxy_retr", 5)
+modparam("nathelper", "sipping_method", "OPTIONS")
+modparam("nathelper", "received_avp", "$avp(i:801)")
+
+loadmodule "textops/textops.so"
+
+loadmodule "mediaproxy/mediaproxy.so"
+modparam("mediaproxy", "mediaproxy_socket", "/var/run/proxydispatcher.sock")
+
+loadmodule "siputils/siputils.so"
+
+loadmodule "registrar/registrar.so"
+modparam("registrar", "default_expires", 3600)
+modparam("registrar", "min_expires", 60)
+modparam("registrar", "max_expires", 0)
+modparam("registrar", "default_q", 0)
+modparam("registrar", "append_branches", 1)
+modparam("registrar", "case_sensitive", 0)
+modparam("registrar", "received_param", "received")
+modparam("registrar", "max_contacts", 0)
+modparam("registrar", "retry_after", 0)
+modparam("registrar", "method_filtering", 0)
+modparam("registrar", "path_mode", 2)
+modparam("registrar", "path_use_received", 0)
+modparam("registrar", "received_avp", "$avp(i:801)")
+
+loadmodule "sl/sl.so"
+modparam("sl", "enable_stats", 1)
+
+loadmodule "db_mysql/db_mysql.so"
+modparam("db_mysql", "ping_interval", 300)
+modparam("db_mysql", "auto_reconnect", 1)
+
+loadmodule "auth/auth.so"
+modparam("auth", "nonce_expire", 300)
+modparam("auth", "rpid_suffix", ";party=calling;id-type=subscriber;screen=yes")
+modparam("auth", "rpid_avp", "$avp(s:rpid)")
+
+loadmodule "auth_db/auth_db.so"
+modparam("auth_db", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("auth_db", "user_column", "username")
+modparam("auth_db", "domain_column", "domain")
+modparam("auth_db", "password_column", "password")
+modparam("auth_db", "password_column_2", "ha1b")
+modparam("auth_db", "calculate_ha1", 1)
+modparam("auth_db", "use_domain", 0)
+modparam("auth_db", "load_credentials", "$avp(s:caller_uuid)=uuid")
+
+loadmodule "uri_db/uri_db.so"
+modparam("uri_db", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("uri_db", "db_table", "subscriber")
+modparam("uri_db", "use_uri_table", 0)
+modparam("uri_db", "use_domain", 0)
+
+loadmodule "avpops/avpops.so"
+modparam("avpops", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("avpops", "avp_table", "usr_preferences")
+modparam("avpops", "use_domain", 0)
+modparam("avpops", "uuid_column", "uuid")
+modparam("avpops", "username_column", "username")
+modparam("avpops", "domain_column", "domain")
+modparam("avpops", "attribute_column", "attribute")
+modparam("avpops", "value_column", "value")
+modparam("avpops", "type_column", "type")
+
+loadmodule "enum/enum.so"
+modparam("enum", "domain_suffix", "e164.org.")
+
+loadmodule "permissions/permissions.so"
+modparam("permissions", "default_allow_file", "permissions.allow")
+modparam("permissions", "default_deny_file", "permissions.deny")
+modparam("permissions", "check_all_branches", 1)
+modparam("permissions", "allow_suffix", ".allow")
+modparam("permissions", "deny_suffix", ".deny")
+modparam("permissions", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("permissions", "db_mode", 1)
+modparam("permissions", "trusted_table", "trusted")
+modparam("permissions", "source_col", "src_ip")
+modparam("permissions", "proto_col", "proto")
+modparam("permissions", "from_col", "from_pattern")
+modparam("permissions", "tag_col", "tag")
+modparam("permissions", "peer_tag_avp", "$avp(s:peer_uuid)")
+
+loadmodule "lcr/lcr.so"
+modparam("lcr", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("lcr", "gw_table", "gw")
+modparam("lcr", "gw_name_column", "gw_name")
+modparam("lcr", "ip_addr_column", "ip_addr")
+modparam("lcr", "port_column", "port")
+modparam("lcr", "uri_scheme_column", "uri_scheme")
+modparam("lcr", "transport_column", "transport")
+modparam("lcr", "grp_id_column", "grp_id")
+modparam("lcr", "lcr_table", "lcr")
+modparam("lcr", "strip_column", "strip")
+modparam("lcr", "prefix_column", "prefix")
+modparam("lcr", "from_uri_column", "from_uri")
+modparam("lcr", "priority_column", "priority")
+modparam("lcr", "gw_uri_avp", "$avp(i:1400)")
+modparam("lcr", "ruri_user_avp", "$avp(i:1402)")
+modparam("lcr", "fr_inv_timer_avp", "$avp(s:fr_inv_timer_avp)")
+modparam("lcr", "fr_inv_timer", 90)
+modparam("lcr", "fr_inv_timer_next", 30)
+modparam("lcr", "rpid_avp", "$avp(s:rpid)")
+modparam("lcr", "flags_avp", "$avp(i:712)")
+
+loadmodule "uac_redirect/uac_redirect.so"
+modparam("uac_redirect", "default_filter", "accept")
+modparam("uac_redirect", "acc_function", "acc_log_request")
+modparam("uac_redirect", "acc_db_table", "acc")
+
+loadmodule "alias_db/alias_db.so"
+modparam("alias_db", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("alias_db", "user_column", "username")
+modparam("alias_db", "domain_column", "domain")
+modparam("alias_db", "alias_user_column", "alias_username")
+modparam("alias_db", "alias_domain_column", "alias_domain")
+modparam("alias_db", "use_domain", 0)
+
+loadmodule "uac/uac.so"
+modparam("uac", "rr_store_param", "vsf")
+modparam("uac", "from_restore_mode", "auto")
+modparam("uac", "from_passwd", "s1p:Wiz4rd!")
+
+loadmodule "acc/acc.so"
+modparam("acc", "early_media", 0)
+modparam("acc", "failed_transaction_flag", 24)
+modparam("acc", "report_ack", 0)
+modparam("acc", "report_cancels", 0)
+modparam("acc", "log_flag", 0)
+modparam("acc", "log_missed_flag", 0)
+modparam("acc", "log_level", 2)
+modparam("acc", "db_flag", 25)
+modparam("acc", "db_missed_flag", 0)
+modparam("acc", "db_table_acc", "acc")
+modparam("acc", "db_table_missed_calls", "missed_calls")
+modparam("acc", "db_url", "mysql://openser:openserrw@localhost/openser")
+modparam("acc", "acc_method_column", "method")
+modparam("acc", "acc_callid_column", "callid")
+modparam("acc", "acc_time_column", "time")
+modparam("acc", "acc_from_tag_column", "from_tag")
+modparam("acc", "detect_direction", 1)
+modparam("acc", "acc_sip_code_column", "sip_code")
+modparam("acc", "acc_sip_reason_column", "sip_reason")
+modparam("acc", "multi_leg_info", "src_leg=$avp(i:901);dst_leg=$avp(i:902)")
+
+########################################################################
+# Request route 'main'
+########################################################################
+route[0]
+{
+	xlog("L_INFO", "New request - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	force_rport();
+	if(msg:len > max_len)
+	{
+		
+		xlog("L_INFO", "Message too big - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		sl_send_reply("513", "Message Too Big");
+		exit;
+	}
+	if (!mf_process_maxfwd_header("10"))
+	{
+		
+		xlog("L_INFO", "Too many hops - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		sl_send_reply("483", "Too Many Hops");
+		exit;
+	}
+	if(!is_method("REGISTER"))
+	{
+		if(nat_uac_test("19"))
+		{
+			record_route(";nat=yes");
+		}
+		else
+		{
+			record_route();
+		}
+	}
+	if(is_method("CANCEL") || is_method("BYE"))
+	{
+		end_media_session();
+	}
+	if(loose_route())
+	{
+		if(!has_totag())
+		{
+			
+			xlog("L_INFO", "Initial loose-routing rejected - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			sl_send_reply("403", "Initial Loose-Routing Rejected");
+			exit;
+		}
+		if(nat_uac_test("19") || search("^Route:.*;nat=yes"))
+		{
+			fix_nated_contact();
+			setbflag(6);
+		}
+		if(is_method("BYE"))
+		{
+			setflag(24); # account failed transactions
+			setflag(25); # account successful transactions
+		}
+		# mark as loose-routed for acc
+		setflag(26);
+		
+		route(12);
+	}
+	if(is_method("REGISTER"))
+	{
+		route(11);
+	}
+	setflag(24); # account failed transactions
+	setflag(25); # account successful transactions
+	if(is_method("INVITE"))
+	{
+		route(13);
+	}
+	if(is_method("CANCEL") || is_method("ACK"))
+	{
+		route(19);
+	}
+	
+	route(20);
+}
+
+########################################################################
+# Request route 'clear-usr-preferences-caller'
+########################################################################
+route[1]
+{
+	xlog("L_INFO", "Clear caller preferences - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	avp_delete("$avp(s:caller_cli)/g");
+	avp_delete("$avp(s:clir)/g");
+	
+}
+
+########################################################################
+# Request route 'clear-usr-preferences-callee'
+########################################################################
+route[2]
+{
+	xlog("L_INFO", "Clear callee preferences - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	avp_delete("$avp(s:callee_fr_inv_timer)/g");
+	avp_delete("$avp(s:cfu)/g");
+	avp_delete("$avp(s:cfc)/g");
+	
+}
+
+########################################################################
+# Request route 'usr-preferences-caller'
+########################################################################
+route[3]
+{
+	route(1);
+	xlog("L_INFO", "Load caller preferences for uuid '$avp(s:caller_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	# load caller avps
+	avp_db_load("$avp(s:caller_uuid)", "*");
+	avp_copy("$avp(s:cli)", "$avp(s:caller_cli)/d");
+	if(is_avp_set("$avp(s:clir)/n") && avp_check("$avp(s:clir)", "eq/i:1"))
+	{
+		# mark for anonymization
+		setflag(28);
+	}
+	
+}
+
+########################################################################
+# Request route 'usr-preferences-callee'
+########################################################################
+route[4]
+{
+	xlog("L_INFO", "Load callee preferences for uuid '$avp(s:callee_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	# load callee avps
+	avp_db_load("$avp(s:callee_uuid)", "*");
+	if(is_avp_set("$avp(s:cfu)/s"))
+	{
+		
+		xlog("L_INFO", "Call-forward-unconditional to '$avp(s:cfu)' found - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(8);
+		avp_delete("$avp(s:caller_uuid)/g");
+		avp_copy("$avp(s:callee_uuid)", "$avp(s:caller_uuid)/d");
+		avp_pushto("$ru", "$avp(s:cfu)");
+		
+		route(3);
+		route(14);
+		exit;
+	}
+	if(is_avp_set("$avp(s:ringtimeout)/n"))
+	{
+		
+		xlog("L_INFO", "Setting ring timeout to $avp(s:ringtimeout) secs - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		avp_copy("$avp(s:ringtimeout)", "$avp(s:callee_fr_inv_timer)/d");
+	}
+	
+}
+
+########################################################################
+# Request route 'acc-caller'
+########################################################################
+route[5]
+{
+	xlog("L_INFO", "Setting acc source-leg for uuid '$avp(s:caller_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	avp_printf("$avp(i:901)", "$avp(s:caller_uuid)|$avp(s:acc_caller_user)|$avp(s:acc_caller_domain)|$avp(s:acc_state)");
+	
+}
+
+########################################################################
+# Request route 'acc-callee'
+########################################################################
+route[6]
+{
+	xlog("L_INFO", "Setting acc destination-leg for uuid '$avp(s:callee_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	avp_printf("$avp(i:902)", "$avp(s:callee_uuid)|$avp(s:acc_callee_user)|$avp(s:acc_callee_domain)");
+	
+}
+
+########################################################################
+# Request route 'acc-failure'
+########################################################################
+route[7]
+{
+	xlog("L_INFO", "Accounting failed request for uuid '$avp(s:caller_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	route(5);
+	route(6);
+	resetflag(24);
+	acc_db_request("404", "acc");
+	
+}
+
+########################################################################
+# Request route 'cfu-acc'
+########################################################################
+route[8]
+{
+	$avp(s:acc_callee_user) = $rU;
+	$avp(s:acc_callee_domain) = $rd;
+	
+	route(5);
+	route(6);
+	avp_delete("$avp(s:acc_caller_user)");
+	avp_delete("$avp(s:acc_caller_domain)");
+	avp_copy("$avp(s:acc_callee_user)", "$avp(s:acc_caller_user)");
+	avp_copy("$avp(s:acc_callee_domain)", "$avp(s:acc_caller_domain)");
+	avp_delete("$avp(s:acc_state)/g");
+	$avp(s:acc_state) = "cfu";
+	
+}
+
+########################################################################
+# Request route 'clir'
+########################################################################
+route[9]
+{
+	if(isflagset(28) && !isflagset(27))
+	{
+		setflag(27);
+		
+		xlog("L_INFO", "Anonymize caller - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		uac_replace_from("Anonymous","sip:[email protected]");
+		if(is_present_hf("Privacy"))
+		{
+			remove_hf("Privacy");
+		}
+		append_hf("Privacy: id\r\n");
+	}
+	
+}
+
+########################################################################
+# Request route 'stop-media-proxy'
+########################################################################
+route[10]
+{
+	if(isflagset(22))
+	{
+		end_media_session();
+	}
+	
+}
+
+########################################################################
+# Request route 'base-route-register'
+########################################################################
+route[11]
+{
+	sl_send_reply("100", "Trying");
+	if(!www_authorize("", "subscriber")) 
+	{
+		
+		xlog("L_INFO", "Register authentication failed - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		www_challenge("", "0");
+		exit;
+	}
+	if(!check_to()) 
+	{
+		
+		xlog("L_INFO", "Spoofed To-URI detected - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		sl_send_reply("403", "Spoofed To-URI Detected");
+		exit;
+	}
+	consume_credentials();
+	if(!search("^Contact:[ ]*\*") && nat_uac_test("19")) 
+	{
+		fix_nated_register();
+		setbflag(6);
+	}
+	if(!save("location")) 
+	{
+		
+		xlog("L_ERR", "Saving contact failed - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		sl_reply_error();
+		exit;
+	}
+	
+	xlog("L_INFO", "Registration successful - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	exit;
+	
+}
+
+########################################################################
+# Request route 'base-outbound'
+########################################################################
+route[12]
+{
+	if(is_present_hf("P-Asserted-Identity"))
+	{
+		remove_hf("P-Asserted-Identity");
+	}
+	if(is_present_hf("Remote-Party-ID"))
+	{
+		remove_hf("Remote-Party-ID");
+	}
+	if(is_avp_set("$avp(s:caller_cli)/s"))
+	{
+		if(!isflagset(28))
+		{
+			
+			xlog("L_INFO", "Set caller CLI '$avp(s:caller_cli)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			append_hf("P-Asserted-Identity: <$avp(s:caller_cli)>\r\n");
+		}
+	}
+	
+	route(9);
+	if(isbflagset(6))
+	{
+		if(!isflagset(22) && !search("^Content-Length:[ ]*0"))
+		{
+			setflag(22);
+			use_media_proxy();
+		}
+		
+		t_on_reply("2");
+	}
+	else
+	{
+		
+		t_on_reply("1");
+	}
+	if(!isflagset(21))
+	{
+		
+		t_on_failure("2");
+		if(!isflagset(26))
+		{
+			$avp(s:acc_callee_user) = $rU;
+			$avp(s:acc_callee_domain) = $rd;
+			
+			route(5);
+			route(6);
+		}
+	}
+	if(isflagset(29))
+	{
+		append_branch();
+	}
+	if(is_present_hf("Proxy-Authorization"))
+	{
+		consume_credentials();
+	}
+	
+	xlog("L_INFO", "Request leaving server, D-URI='$du' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	# no 100 (we already sent it) and no DNS blacklisting
+	if(!t_relay("0x05"))
+	{
+		sl_reply_error();
+		if(is_method("INVITE") && isbflagset(6))
+		{
+			end_media_session();
+		}
+	}
+	exit;
+	
+}
+
+########################################################################
+# Request route 'base-route-invite'
+########################################################################
+route[13]
+{
+	sl_send_reply("100", "Trying");
+	if(from_gw())
+	{
+		$avp(s:caller_uuid) = "0";
+		
+		xlog("L_INFO", "Call from PSTN' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		setflag(23);
+	}
+	else
+	{
+		if(allow_trusted())
+		{
+			if(is_avp_set("$avp(s:peer_uuid)/s"))
+			{
+				# use tag-column from trusted-table as uuid for this caller
+				avp_copy("$avp(s:peer_uuid)", "$avp(s:caller_uuid)/d");
+			}
+			else
+			{
+				# if no uuid is set, use "0" as default uuid
+				$avp(s:caller_uuid) = "0";
+			}
+			
+			xlog("L_INFO", "Call from trusted peer with uuid '$avp(s:caller_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			if(!is_domain_local("$rd"))
+			{
+				
+				xlog("L_INFO", "Rejecting peering attempt with non-local request domain - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+				sl_send_reply("403", "Relaying Denied");
+				exit;
+			}
+			setflag(23);
+		}
+		else
+		{
+			if(!proxy_authorize("", "subscriber")) 
+			{
+				
+				xlog("L_INFO", "Proxy authentication failed - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+				proxy_challenge("", "0");
+				exit;
+			}
+			if(!check_from()) 
+			{
+				
+				xlog("L_INFO", "Spoofed From-URI detected - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+				sl_send_reply("403", "Spoofed From-URI Detected");
+				exit;
+			}
+		}
+	}
+	$avp(s:acc_caller_user) = $fU;
+	$avp(s:acc_caller_domain) = $fd;
+	$avp(s:acc_state) = "call";
+	
+	route(3);
+	if(nat_uac_test("19")) 
+	{
+		fix_nated_contact();
+		setbflag(6);
+	}
+	
+	route(14);
+}
+
+########################################################################
+# Request route 'invite-find-callee'
+########################################################################
+route[14]
+{
+	if(alias_db_lookup("dbaliases"))
+	{
+		
+		xlog("L_INFO", "Callee was aliased - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	}
+	
+	route(2);
+	if(!is_domain_local("$rd"))
+	{
+		setflag(20);
+		$avp(s:callee_uuid) = "0";
+		
+		route(16);
+	}
+	avp_delete("$avp(s:callee_uuid)");
+	avp_db_query("select uuid from subscriber where username = '$rU'", "$avp(s:callee_uuid)");
+	if(is_avp_set("$avp(s:callee_uuid)/s"))
+	{
+		
+		xlog("L_INFO", "Callee is local, uuid='$avp(s:callee_uuid)' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(15);
+	}
+	else
+	{
+		$avp(s:callee_uuid) = "0";
+		
+		xlog("L_INFO", "Callee is not local - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(16);
+	}
+	exit;
+	
+}
+
+########################################################################
+# Request route 'invite-to-internal'
+########################################################################
+route[15]
+{
+	route(4);
+	if(!lookup("location")) 
+	{
+		
+		xlog("L_INFO", "Local user offline - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		$avp(s:acc_callee_user) = $rU;
+		$avp(s:acc_callee_domain) = $rd;
+		
+		route(7);
+		sl_send_reply("404", "User Offline");
+	}
+	else
+	{
+		
+		xlog("L_INFO", "Local user online - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(12);
+	}
+	exit;
+	
+}
+
+########################################################################
+# Request route 'invite-to-external'
+########################################################################
+route[16]
+{
+	if(isflagset(20))
+	{
+		
+		xlog("L_INFO", "Call to foreign domain - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(12);
+		exit;
+	}
+	
+	route(18);
+	if(!isflagset(23))
+	{
+		# don't allow calls relaying from PSTN to PSTN, if not explicitely forwarded
+		if(uri =~ "^sip:[0-9]+@")
+		{
+			# only route numeric users to PSTN
+			if(!load_gws())
+			{
+				
+				xlog("L_ERR", "Error loading PSTN gateways - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+				sl_send_reply("503", "PSTN Termination Currently Unavailable");
+				exit;
+			}
+			if(!next_gw())
+			{
+				
+				xlog("L_ERR", "No PSTN gateways available - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+				sl_send_reply("503", "PSTN Termination Currently Unavailable");
+				exit;
+			}
+			setflag(21);
+			
+			t_on_failure("1");
+			route(12);
+		}
+	}
+	
+	xlog("L_INFO", "Call to unknown user - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	route(7);
+	sl_send_reply("404", "User Not Found");
+	exit;
+	
+}
+
+########################################################################
+# Request route 'normalize-e164'
+########################################################################
+route[17]
+{
+	# European numbering plans look like this:
+	#   CC  = country code (i.e. 43 for Austria)
+	#   NDC = national destination code (i.e. 1 for Vienna)
+	#   SN  = subscriber number (i.e. 4001234)
+	#  
+	#       CC + NDC + SN, i.e. 4314001234
+	#
+	# Within the same CC+NDC, it can be omitted, so if
+	# +4314001234 wants to call +4315002345, one can dial
+	# just 5002345.
+	#
+	# Within the same CC, CC can be ommitted and a "0" is prefixed
+	# to NDC, so if +4314001234 wants to call +4326003456, 
+	# one can dial 026003456.
+	#
+	# For international calls, either "00" or + is prefixed, like
+	# +49123456780 or 0049123456789.
+	#
+	avp_delete("$avp(s:orig_callee_user)/g");
+	$avp(s:orig_callee_user) = $rU;
+	if(uri =~ "^sip:(\+[1-9])?[0-9]+@")
+	{
+		# looks like a PSTN number
+		if(uri =~ "^sip:0[1-9][0-9]+@")
+		{
+			# we have format 0+NDC+SN
+			strip(1);
+			prefix("+49");
+		}
+		else if(uri =~ "^sip:00[1-9]+@")
+		{
+			# we have format 00 + CC + NDC + SN
+			strip(2);
+			prefix("+");
+		}
+		else if(!uri =~ "^sip:\+[1-9][0-9]+@")
+		{
+			# unknown format, maybe NDC wasn't added before?
+			
+			xlog("L_INFO", "Not normalized callee '$avp(s:orig_callee_user)' to E.164 format - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			return(-1);
+		}
+		# else we have "+" + CC + NDC + SN
+		
+		xlog("L_INFO", "Normalized callee '$avp(s:orig_callee_user)' to E.164 format '$rU' - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		return(1);
+	}
+	else
+	{
+		
+		xlog("L_INFO", "Not normalized callee '$avp(s:orig_callee_user)' to E.164 format - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		return(-1);
+	}
+	
+}
+
+########################################################################
+# Request route 'lookup-enum'
+########################################################################
+route[18]
+{
+	route(17);
+	if($rc == 1)
+	{
+		if(enum_query("e164.org."))
+		{
+			# TODO: do GW fallback (load gws, set failure-route)?
+			
+			xlog("L_INFO", "ENUM query succeeded - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			setdsturi("sip:bogus.localhost:5060");
+			
+			route(12);
+			exit;
+		}
+		else
+		{
+			
+			xlog("L_INFO", "ENUM query failed - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			# ENUM query failed, revert $rU
+			avp_pushto("$ru/username", "$avp(s:orig_callee_user)");
+		}
+	}
+	
+}
+
+########################################################################
+# Request route 'base-route-local'
+########################################################################
+route[19]
+{
+	t_on_reply("1");
+	if(t_check_trans())
+	{
+		
+		xlog("L_INFO", "Request leaving server - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		if(!t_relay())
+		{
+			sl_reply_error();
+		}
+	}
+	else
+	{
+		
+		xlog("L_INFO", "Dropping mis-routed request - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	}
+	exit;
+	
+}
+
+########################################################################
+# Request route 'base-route-generic'
+########################################################################
+route[20]
+{
+	xlog("L_INFO", "Method not supported - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	sl_send_reply("501", "Method Not Supported Here");
+	exit;
+	
+}
+
+########################################################################
+# Request route 'base-filter-failover'
+########################################################################
+route[21]
+{
+	if(!t_check_status("408|500|503"))
+	{
+		
+		xlog("L_INFO", "No failover routing needed for this response code - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(10);
+		exit;
+	}
+	
+}
+
+########################################################################
+# Reply route 'base-standard-reply'
+########################################################################
+onreply_route[1]
+{
+	xlog("L_INFO", "Reply - S=$rs D=$rr F=$fu T=$tu IP=$si ID=$ci\n");
+	exit;
+	
+}
+
+########################################################################
+# Reply route 'base-nat-reply'
+########################################################################
+onreply_route[2]
+{
+	xlog("L_INFO", "NAT-Reply - S=$rs D=$rr F=$fu T=$tu IP=$si ID=$ci\n");
+	if(nat_uac_test("1"))
+	{
+		fix_nated_contact();
+	}
+	if(isbflagset(6) && status=~"(180)|(183)|2[0-9][0-9]") 
+	{
+		if(!search("^Content-Length:[ ]*0"))
+		{
+			use_media_proxy();
+		}
+	}
+	exit;
+	
+}
+
+########################################################################
+# Failure route 'pstn-failover'
+########################################################################
+failure_route[1]
+{
+	xlog("L_INFO", "Failure route for PSTN entered - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+	route(21);
+	if(!next_gw())
+	{
+		
+		xlog("L_ERR", "Failed to select next PSTN gateway - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(10);
+		exit;
+	}
+	
+	t_on_failure("1");
+	route(12);
+}
+
+########################################################################
+# Failure route 'base-standard-failure'
+########################################################################
+failure_route[2]
+{
+	if(t_check_status("422|481|487"))
+	{
+		
+		xlog("L_INFO", "Final reply - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(10);
+		exit;
+	}
+	if(t_check_status("301|302"))
+	{
+		avp_delete("$avp(s:acc_caller_user)/g");
+		avp_delete("$avp(s:acc_caller_domain)/g");
+		avp_delete("$avp(s:acc_state)/g");
+		avp_copy("$avp(s:acc_callee_user)", "$avp(s:acc_caller_user)");
+		avp_copy("$avp(s:acc_callee_domain)", "$avp(s:acc_caller_domain)");
+		$avp(s:acc_state) = "cfc";
+		setflag(29);
+		if(!get_redirects("1:1"))
+		{
+			
+			xlog("L_ERROR", "Failed to fetch contact '$ct' from 301/302 - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+			acc_db_request("480", "acc");
+			
+			route(10);
+			t_reply("480", "Temporarily Unavailable");
+			exit;
+		}
+		# get last URI from destination-set and set it as R-URI
+		avp_delete("$avp(s:tmp)/g");
+		$avp(s:tmp) = $ds;	
+		avp_subst("$avp(s:tmp)", "/.*(sip:.+@[^:;>]+).*$/\1/");
+		avp_pushto("$ru", "$avp(s:tmp)");
+		setflag(29);
+		append_branch();
+		
+		t_on_branch("1");
+		xlog("L_INFO", "Redirect from UAC intercepted - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(14);
+		exit;
+	}
+	if($avp(s:cfc) != NULL)
+	{
+		avp_delete("$avp(s:acc_caller_user)/g");
+		avp_delete("$avp(s:acc_caller_domain)/g");
+		avp_delete("$avp(s:acc_state)/g");
+		avp_copy("$avp(s:acc_callee_user)", "$avp(s:acc_caller_user)");
+		avp_copy("$avp(s:acc_callee_domain)", "$avp(s:acc_caller_domain)");
+		$avp(s:acc_state) = "cfc";
+		avp_pushto("$ru", "$avp(s:cfc)");
+		setflag(29);
+		append_branch();
+		
+		t_on_branch("1");
+		xlog("L_INFO", "CFC detected - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		route(14);
+	}
+	
+	route(21);
+	route(10);
+}
+
+########################################################################
+# Branch route 'cfc-drop-local'
+########################################################################
+branch_route[1]
+{
+	if(is_domain_local("$rd"))
+	{
+		
+		xlog("L_INFO", "Dropping local branch - M=$rm RURI=$ru F=$fu T=$tu IP=$si ID=$ci\n");
+		drop();
+	}
+	
+}
+

+ 42 - 0
test/unit/7.sh

@@ -0,0 +1,42 @@
+#!/bin/bash
+# loads a SIP proxy/registrar config with offnet-termination and accounting
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# config generated by sipwise wizard
+
+# Needs a default kamailio database setup for mysql
+
+source include/common
+source include/require
+
+CFG=7.cfg
+
+if ! (check_kamailio); then
+	exit 0
+fi ;
+
+# start
+../$BIN -w . -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+$KILL
+
+exit $ret

+ 51 - 0
test/unit/8.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+# creates a dbtext database with kamailiodbctl and deletes it again
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+
+tmp_name=""$RANDOM"_kamailiodb_tmp"
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=DBTEXT/g" $CTLRC
+sed -i "s/# INSTALL_EXTRA_TABLES=ask/INSTALL_EXTRA_TABLES=yes/g" $CTLRC
+sed -i "s/# INSTALL_PRESENCE_TABLES=ask/INSTALL_PRESENCE_TABLES=yes/g" $CTLRC
+
+cp $DBCTL $DBCTL.bak
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $DBCTL
+
+./$DBCTL create $tmp_name > /dev/null
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	./$DBCTL drop $tmp_name > /dev/null
+	ret=$?
+fi ;
+
+# cleanup
+mv $CTLRC.bak $CTLRC
+mv $DBCTL.bak $DBCTL
+
+
+cd ../test
+exit $ret

+ 51 - 0
test/unit/9.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+# test basic db related kamailioctl functionality for mysql
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of Kamailio, a free SIP server.
+#
+# Kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# Kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+source include/common
+
+cd ../scripts
+
+# setup config file
+cp $CTLRC $CTLRC.bak
+cp $CTL $CTL.bak
+sed -i "s/# DBENGINE=MYSQL/DBENGINE=MYSQL/g" $CTLRC
+sed -i "s/TEST=\"false\"/TEST=\"true\"/g" $CTL
+
+./$CTL avp list > /dev/null
+
+ret=$?
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL domain showdb > /dev/null
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	./$CTL lcr show > /dev/null
+	ret=$?
+fi ;
+
+# cleanup
+mv $CTLRC.bak $CTLRC
+mv $CTL.bak $CTL
+
+cd ../test
+exit $ret

+ 13 - 0
test/unit/Makefile

@@ -0,0 +1,13 @@
+all:
+	-@for FILE in $(wildcard *.sh) ; do \
+		if [ -f $$FILE ] ; then \
+			if [ -x $$FILE ] ; then \
+				echo "run test `basename $$FILE .sh`:" `head "$$FILE" -n 2 | tail -n 1 | cut -c 3-` ; \
+				./$$FILE ; \
+				ret=$$? ; \
+					if [ ! "$$ret" -eq 0 ] ; then \
+						echo "failed" ; \
+					fi ; \
+			fi ; \
+		fi ; \
+	done ;

+ 12 - 0
test/unit/README

@@ -0,0 +1,12 @@
+This directory contains some small "smoke tests", that should assure that
+basic functionality of the server work as required. This tests should consists
+of one shell script and a config file if needed. They should not need much time
+for execution, to allow the run of the complete test suite in a few seconds.
+All test scripts must be self-contained, should not have external dependencies
+and must clean up after they are run. The second line in each scripts should
+contain a small comment that describe the task of the test, it should not
+output any messages on successful runs.
+
+This tests should (in the current state) only run by developers who know
+what they do. They could delete your database, produce core dumps that fill
+your harddisk or do other nasty things..

+ 30 - 0
test/unit/carrierroute-2.cfg

@@ -0,0 +1,30 @@
+domain proxy {
+	prefix 49721123456787 {
+		max_targets = 2
+
+		target 127.0.0.1:7000 {
+			prob = 0.5
+			status = 1
+		}
+		target 127.0.0.1:8000 {
+			prob = 0.5
+			status = 1
+		}
+	}
+	prefix 49721123456786 {
+		max_targets = 1
+
+		target 127.0.0.1:9000 {
+			prob = 1.0
+			status = 1
+		}
+	}
+	prefix 49721123456785 {
+		max_targets = 1
+
+		target 127.0.0.1:10000 {
+			prob = 1.0
+			status = 1
+		}
+	}
+}

+ 100 - 0
test/unit/carrierroute.cfg

@@ -0,0 +1,100 @@
+domain register {
+	prefix NULL {
+		max_targets = 3
+
+		target test1 {
+			prob = 0.400000
+			hash_index = 3
+			status = 0
+		}
+		target test3.localdomain {
+			prob = 0.500000
+			hash_index = 2
+			status = 1
+		}
+		target test2.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 1
+		}
+	}
+}
+
+domain proxy {
+	prefix 2 {
+		max_targets = 2
+
+		target test8.localdomain {
+			prob = 0.100000
+			hash_index = 2
+			status = 1
+		}
+		target test7.localdomain {
+			prob = 0.700000
+			hash_index = 1
+			status = 1
+		}
+	}
+	prefix 42 {
+		max_targets = 3
+
+		target test6.localdomain {
+			prob = 0.100000
+			hash_index = 2
+			status = 1
+		}
+		target test5.localdomain {
+			prob = 0.200000
+			hash_index = 1
+			status = 1
+		}
+		target test4 {
+			prob = 0.700000
+			hash_index = 3
+			status = 1
+		}
+	}
+	prefix 49 {
+		max_targets = 3
+
+		target test6.localdomain {
+			prob = 0.500000
+			hash_index = 3
+			status = 1
+		}
+		target test5.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 0
+		}
+		target test4 {
+			prob = 0.400000
+			hash_index = 2
+			status = 1
+		}
+	}
+}
+
+domain other {
+	prefix NULL {
+		max_targets = 3
+
+		target test1 {
+			prob = 0.400000
+			hash_index = 3
+			status = 0
+		}
+		target test3.localdomain {
+			prob = 0.500000
+			hash_index = 2
+			status = 1
+			backed_up = {1}
+		}
+		target test2.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 0
+			backup = 2
+		}
+	}
+}

+ 6 - 0
test/unit/cpl_ignore.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cpl>
+  <incoming>
+    <reject status="400" reason="Busy" />
+  </incoming>
+</cpl>

+ 21 - 0
test/unit/cpl_test.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<scenario name="invite_client">
+  <send retrans="500">
+      <![CDATA[
+
+      INVITE sip:alice@localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 1 INVITE
+      Contact: sip:alice@[local_ip]:[local_port]
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+      ]]>
+   </send>
+   <recv response="400" auth="true">
+   </recv>
+</scenario>

+ 140 - 0
test/unit/failure_route.xml

@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<scenario name="Basic UAS with failure route">
+
+  <recv request="INVITE">
+  </recv>
+
+  <send retrans="500">
+    <![CDATA[
+
+      SIP/2.0 503 Service Unavailable
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv request="ACK">
+  </recv>
+
+  <recv request="INVITE">
+  </recv>
+
+  <send retrans="500">
+    <![CDATA[
+
+      SIP/2.0 486 Busy Here
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv request="ACK">
+  </recv>
+
+  <recv request="INVITE">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 180 Ringing
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <send retrans="500">
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv request="ACK" optional="true">
+  </recv>
+
+  <recv request="BYE">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <!-- Keep the call open for a while in case the 200 is lost to be     -->
+  <!-- able to retransmit it if we receive the BYE again.               -->
+  <pause milliseconds="4000"/>
+
+
+  <!-- definition of the response time repartition table (unit is ms)   -->
+  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
+
+  <!-- definition of the call length repartition table (unit is ms)     -->
+  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
+
+</scenario>
+

+ 6 - 0
test/unit/include/common

@@ -0,0 +1,6 @@
+DB_ALL_MOD="acc|alias_db|auth_db|avpops|dialog|dialplan|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist"
+CTLRC="kamctlrc"
+CTL="kamctl"
+DBCTL="kamdbctl"
+BIN="kamailio"
+KILL="killall -15 kamailio"

+ 69 - 0
test/unit/include/database

@@ -0,0 +1,69 @@
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of kamailio, a free SIP server.
+#
+# kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+MYSQL="mysql openser --show-warnings --batch --user=openser --password=openserrw -e"
+
+export PGPASSWORD="openserrw"
+PSQL="psql -A -t -n -q -h localhost -U openser openser -c"
+
+ISQL="isql -b -v -d0x0 openser openser openserrw"
+
+function check_mysql() {
+	$MYSQL "select * from location;" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	$MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	$MYSQL "delete from location where user_agent ='___test___';" > /dev/null
+	return 0
+}
+
+function check_postgres() {
+	$PSQL "select * from location;" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	$PSQL "insert into location (user_agent) values ('___test___');" > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	$PSQL "delete from location where user_agent ='___test___';" > /dev/null
+	return 0
+}
+
+function check_unixodbc() {
+	echo "select * from location;" | $ISQL  > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't read from database"
+		return -1
+	fi;
+	echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null
+	if ! [ "$?" -eq 0 ] ; then
+		echo "can't write to database"
+		return -1
+	fi;
+	echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null
+	return 0
+}

+ 62 - 0
test/unit/include/require

@@ -0,0 +1,62 @@
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of kamailio, a free SIP server.
+#
+# kamailio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# kamailio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+function check_kamailio() {
+	if ! (test -e ../kamailio) ; then
+		echo "kamailio not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_module() {
+	if [ $# -ne 1 ]; then
+		echo "wrong number of params in check_module()"
+		return -1
+	fi
+
+	if ! (test -e ../modules/$1/$1.so) ; then
+		echo "modules/$1/$1.so not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_netcat() {
+	if ! ( which nc > /dev/null ); then
+		echo "netcat not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_sipp() {
+	if ! ( which sipp > /dev/null ); then
+		echo "sipp not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_sipsak() {
+	if ! ( which sipsak > /dev/null ); then
+		echo "sipsak not found, not run"
+		return -1
+	fi;
+	return 0
+}

+ 41 - 0
test/unit/inv_auth.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<scenario name="invite_client">
+  <send retrans="500">
+      <![CDATA[
+
+      INVITE sip:alice@localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 1 INVITE
+      Contact: sip:alice@[local_ip]:[local_port]
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+      ]]>
+   </send>
+   <recv response="407" auth="true">
+   </recv>
+
+   <send retrans="500">
+      <![CDATA[
+
+      INVITE sip:alice@localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 2 INVITE
+      Contact: sip:alice@[local_ip]:[local_port]
+      [authentication username=alice password=alice realm=localhost];
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+    ]]>
+   </send>
+   <recv response="200">
+  </recv>
+   </scenario>

+ 12 - 0
test/unit/invite.sip

@@ -0,0 +1,12 @@
+INVITE sip:[email protected] SIP/2.0
+Via: SIP/2.0/UDP 172.17.13.240:5061;rport;branch=z9hG4bKydcnjlpe
+Max-Forwards: 70
+To: <sip:[email protected]>
+From: <sip:[email protected]>;tag=dyggg
+Call-ID: [email protected]
+CSeq: 479 INVITE
+Contact: <sip:[email protected]:5061>;expires=3600
+Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO
+User-Agent: Twinkle/1.0
+Content-Length: 0
+

+ 93 - 0
test/unit/presence.cfg

@@ -0,0 +1,93 @@
+#
+# $Id$
+#
+# simple quick-start config script - Stand-alone presence server
+#
+ 
+# ----------- global configuration parameters ------------------------
+ 
+debug=3      # debug level (cmd line: -dddddddddd)
+fork=yes
+log_stderror=no    # (cmd line: -E)
+children=4
+
+listen=127.0.0.1 
+port=5059
+
+dns=no
+rev_dns=no
+
+# ------------------ module loading ----------------------------------
+
+#set module path
+mpath="../modules/"
+
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "sl/sl.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "textops/textops.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "presence/presence.so"
+loadmodule "presence_xml/presence_xml.so"
+loadmodule "avpops/avpops.so"
+loadmodule "mi_fifo/mi_fifo.so"
+ 
+# ----------------- setting module-specific parameters ---------------
+ 
+# -- rr params --
+# add value to ;lr param to make some broken UAs happy
+modparam("rr", "enable_full_lr", 1)
+ 
+# -- presence params --
+modparam("presence|presence_xml", "db_url", "mysql://openser:openserrw@localhost/openser")
+ 
+modparam("presence_xml", "force_active", 1)
+ 
+modparam("presence", "server_address", "sip:10.10.10.10:5060")
+
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo_presence")
+ 
+# -------------------------  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;
+    };
+ 
+    if (!is_method("SUBSCRIBE|PUBLISH")) {
+        sl_send_reply("488", "Not Acceptable Here");
+        exit;
+    }
+ 
+    # presence handling
+    if (! t_newtran())
+    {
+        sl_reply_error();
+        exit;
+     };
+ 
+    if(is_method("PUBLISH"))
+    {
+        handle_publish();
+        t_release();
+    }
+    else
+    if( is_method("SUBSCRIBE"))
+    {
+        handle_subscribe();
+        t_release();
+    };
+ 
+    exit;
+}

+ 4 - 0
test/unit/publish.csv

@@ -0,0 +1,4 @@
+SEQUENTIAL
+user1;127.0.0.1:5059
+user2;127.0.0.1:5059
+

+ 86 - 0
test/unit/publish_scenario.xml

@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="publish_scenario">
+
+  <!--  First PUBLISH without Etag -->
+  <!--  Then another publish with status 'busy'
+  -->
+    <send retrans="1000">
+    <![CDATA[
+
+
+PUBLISH sip:[field0]@[field1] SIP/2.0
+Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+Max-Forwards: 70
+Contact: sip:[field0]@[local_ip]:[local_port]
+To: <sip:[field0]@[field1]>
+From: <sip:[field0]@[field1]>;tag=[call_number]
+Call-ID: [call_id]
+CSeq: 1 PUBLISH
+Expires: 60
+Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
+Content-Type: application/pidf+xml
+User-Agent: sipp
+Event: presence
+Content-Length: [len]
+
+<?xml version='1.0' encoding='UTF-8'?><presence xmlns='urn:ietf:params:xml:ns:pidf' xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' entity='sip:[field0]@[field1]'><tuple id='t532d494f'><status><basic>open</basic></status></tuple><dm:person id='p98169736'><rpid:activities><rpid:unknown/></rpid:activities></dm:person></presence>
+]]>
+  </send>
+
+  <recv response="200" rtd="true">
+    <action>
+        <!-- Save the ETag value in [$3] -->
+        <ereg regexp=".*"
+              search_in="hdr"
+              header="SIP-ETag:"
+              check_it="true"
+              assign_to="3"/>	
+        <!-- Save the To-tag value in [$4] -->
+        <ereg regexp=".*;tag=(.*)"
+              search_in="hdr"
+              header=To:"
+              check_it="true"
+              assign_to="19,4"/>	
+    </action>
+  </recv>
+
+  <pause min="500" max="1000"/>
+
+  <send retrans="1000">
+    <![CDATA[
+
+PUBLISH sip:[field0]@[field1] SIP/2.0
+Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]---[$4]
+Max-Forwards: 70
+Contact: sip:[field0]@[local_ip]:[local_port]
+To: "[field0]"<sip:[field0]@[field1]>
+From: "[field0]"<sip:[field0]@[field1]>;tag=[call_number]
+Call-ID: [$4]///[call_id]
+CSeq: 1 PUBLISH
+Expires: 60
+Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
+Content-Type: application/pidf+xml
+User-Agent: sipp
+Event: presence
+SIP-If-Match:[$3]
+Content-Length: [len]
+
+<?xml version='1.0' encoding='UTF-8'?><presence xmlns='urn:ietf:params:xml:ns:pidf' xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' entity='sip:[field0]@[field1]'><tuple id='t532d494f'><status><basic>open</basic></status></tuple><dm:person id='p98169736'><rpid:activities><rpid:busy/></rpid:activities><dm:note>Busy</dm:note></dm:person></presence>
+]]>
+  </send>
+
+  <recv response="200" rtd="true">
+      <action>
+        <!-- Save the To-tag value in [$4] -->
+        <ereg regexp=".*;tag=(.*)"
+              search_in="hdr"
+              header=To:"
+              check_it="true"
+              assign_to="19,4"/>	
+    </action>
+  </recv>
+
+</scenario>
+

+ 40 - 0
test/unit/reg_auth.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<scenario name="register_client">
+  <send retrans="500">
+      <![CDATA[
+
+      REGISTER sip:localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 1 REGISTER
+      Contact: sip:alice@[local_ip]:[local_port]
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+      ]]>
+   </send>
+   <recv response="401" auth="true">
+   </recv>
+
+   <send retrans="500">
+      <![CDATA[
+      REGISTER sip:localhost:5059 SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: <sip:alice@localhost>;tag=[call_number]
+      To: <sip:alice@localhost>
+      Call-ID: [call_id]
+      CSeq: 2 REGISTER
+      Contact: sip:alice@[local_ip]:[local_port]
+      [authentication username=alice password=alice realm=localhost];
+      Max-Forwards: 5
+      Expires: 1800
+      User-Agent: SIPp/Linux
+      Content-Length: 0
+    ]]>
+   </send>
+   <recv response="200">
+  </recv>
+   </scenario>

+ 11 - 0
test/unit/register.sip

@@ -0,0 +1,11 @@
+REGISTER sip:127.0.0.1 SIP/2.0
+Via: SIP/2.0/UDP 172.17.13.240:5061;rport;branch=z9hG4bKydcnjlpe
+Max-Forwards: 70
+To: <sip:[email protected]>
+From: <sip:[email protected]>;tag=dyggg
+Call-ID: [email protected]
+CSeq: 479 REGISTER
+Contact: <sip:[email protected]:5061>;expires=3600
+Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO
+User-Agent: Twinkle/1.0
+Content-Length: 0

+ 4 - 0
test/unit/subscribe_notify.csv

@@ -0,0 +1,4 @@
+SEQUENTIAL
+user1;127.0.0.1:5059;user2
+user2;127.0.0.1:5059;user1
+user2;127.0.0.1:5059;user3

+ 58 - 0
test/unit/subscribe_notify_scenario.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="subscribe_notify__presence_scenario">
+
+    <!-- Send SUBSCRIBE for presence  and receive NOTIFY message -->
+
+    <send retrans="1000">
+    <![CDATA[
+
+
+SUBSCRIBE sip:[field2]@[field1] SIP/2.0
+Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+Max-Forwards: 70
+Contact: sip:[field0]@[local_ip]:[local_port]
+To: <sip:[field2]@[field1]>
+From: "[field0]"<sip:[field0]@[field1]>;tag=[call_number]
+Call-ID: [call_id]
+CSeq: 1 SUBSCRIBE
+Expires: 3600
+Accept: multipart/related, application/rlmi+xml, application/pidf+xml
+Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
+User-Agent: sipp
+Event: presence
+Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="202" rtd="true">
+  </recv>
+
+  <recv request="NOTIFY">
+  </recv>
+
+  <send crlf="true">
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      [last_CSeq:]
+      User-Agent: sipp
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <!-- definition of the response time repartition table (unit is ms)   -->
+  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
+
+  <!-- definition of the call length repartition table (unit is ms)     -->
+  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
+
+</scenario>
+

+ 11 - 0
test/unit/unregister.sip

@@ -0,0 +1,11 @@
+REGISTER sip:127.0.0.1 SIP/2.0
+Via: SIP/2.0/UDP 172.17.13.240:5061;rport;branch=z9hG4bKruthdewh
+Max-Forwards: 70
+To: <sip:[email protected]>
+From: <sip:[email protected]>;tag=jwnqc
+Call-ID: [email protected]
+CSeq: 481 REGISTER
+Contact: <sip:[email protected]:5061>;expires=0
+Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO
+User-Agent: Twinkle/1.0
+Content-Length: 0