43.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # check forward functionality in utils module
  3. # Copyright (C) 2009 1&1 Internet AG
  4. #
  5. # This file is part of Kamailio, a free SIP server.
  6. #
  7. # Kamailio is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version
  11. #
  12. # Kamailio is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. . include/common
  21. . include/require.sh
  22. . include/database.sh
  23. if ! (check_kamailio && check_module "utils" && check_module "db_mysql" && check_mysql); then
  24. exit 0
  25. fi ;
  26. CFG=43.cfg
  27. TMPFILE=`mktemp -t kamailio-test.XXXXXXXXX`
  28. # setup config
  29. echo "loadmodule \"tm/tm.so\"" > $CFG
  30. echo "loadmodule \"sl/sl.so\"" >> $CFG
  31. echo "loadmodule \"mi_fifo/mi_fifo.so\"" >> $CFG
  32. echo "loadmodule \"utils/utils.so\"" >> $CFG
  33. echo "modparam(\"mi_fifo\", \"fifo_name\", \"/tmp/kamailio_fifo\")" >> $CFG
  34. echo "modparam(\"utils\", \"forward_active\", 1)" >> $CFG
  35. echo "route {sl_send_reply(\"404\", \"forbidden\");}" >> $CFG
  36. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG > /dev/null
  37. ret=$?
  38. sleep 1
  39. $CTL fifo forward_list &> /dev/null
  40. $CTL fifo forward_filter 0=REGISTER:INVITE &> /dev/null
  41. $CTL fifo forward_list &> /dev/null
  42. $CTL fifo forward_proxy 0=127.0.0.1:7000 &> /dev/null
  43. $CTL fifo forward_list > $TMPFILE
  44. tmp=`grep -v "Printing forwarding information:
  45. id switch filter proxy
  46. 0 off REGISTER:INVITE 127.0.0.1:7000" $TMPFILE`
  47. if [ "$tmp" = "" ] ; then
  48. ret=0
  49. else
  50. ret=1
  51. fi ;
  52. if [ "$ret" -eq 0 ] ; then
  53. sipp -sn uac -s 123456787 127.0.0.1:5060 -i 127.0.0.1 -m 1 -nr &> /dev/null
  54. ret=$?
  55. killall sipp &> /dev/null
  56. fi;
  57. if ! [ "$ret" -eq 0 ] ; then
  58. $CTL fifo forward_switch 0=on
  59. $CTL fifo forward_list > $TMPFILE
  60. tmp=`grep -v "Printing forwarding information:
  61. id switch filter proxy
  62. 0 on REGISTER:INVITE 127.0.0.1:7000" $TMPFILE`
  63. if [ "$tmp" = "" ] ; then
  64. ret=0
  65. else
  66. ret=1
  67. fi ;
  68. nc -l -u -p 7000 1> $TMPFILE 2> /dev/null &
  69. sipp -sn uac -s 123456787 127.0.0.1:5060 -i 127.0.0.1 -m 1 -nr &> /dev/null
  70. killall sipp &> /dev/null
  71. killall nc &> /dev/null
  72. fi;
  73. NR=`cat $TMPFILE | grep "INVITE sip:" | wc -l`
  74. if [ "$NR" -eq 1 ] ; then
  75. ret=0
  76. else
  77. ret=1
  78. fi;
  79. rm $CFG
  80. rm $TMPFILE
  81. kill_kamailio
  82. exit $ret