44.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # database access and persistent storage for registrar on unixodbc
  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_sipsak && check_kamailio && check_module "db_unixodbc" && check_unixodbc); then
  24. exit 0
  25. fi ;
  26. CFG=11.cfg
  27. cp $CFG $CFG.tmp
  28. echo "loadmodule \"db_unixodbc/db_unixodbc.so\"" >> $CFG
  29. echo "modparam(\"usrloc\", \"db_url\", \"unixodbc://kamailio:kamailiorw@localhost/kamailio\")" >> $CFG
  30. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG > /dev/null
  31. ret=$?
  32. sleep 1
  33. # register a user
  34. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
  35. ret=$?
  36. if [ "$ret" -eq 0 ]; then
  37. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  38. ret=$?
  39. fi;
  40. if [ "$ret" -eq 0 ]; then
  41. TMP=`echo "select COUNT(*) from location where username='49721123456789';" | $ISQL`
  42. if [ "$TMP" -eq 0 ] ; then
  43. ret=1
  44. fi;
  45. fi;
  46. if [ "$ret" -eq 0 ]; then
  47. # unregister the user
  48. sipsak -U -C "*" -s sip:[email protected] -H localhost -x 0 &> /dev/null
  49. fi;
  50. if [ "$ret" -eq 0 ]; then
  51. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  52. ret=$?
  53. if [ "$ret" -eq 0 ]; then
  54. ret=1
  55. else
  56. ret=0
  57. fi;
  58. fi;
  59. if [ "$ret" -eq 0 ]; then
  60. ret=`echo "select COUNT(*) from location where username='49721123456789';" | $ISQL`
  61. fi;
  62. echo "delete from location where username like '49721123456789%';" | $ISQL
  63. if [ "$ret" -eq 0 ]; then
  64. # register again
  65. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
  66. ret=$?
  67. fi;
  68. kill_kamailio
  69. # restart to test preload_udomain functionality
  70. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG > /dev/null
  71. ret=$?
  72. sleep 1
  73. if [ "$ret" -eq 0 ]; then
  74. # check if the contact is still registered
  75. sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
  76. ret=$?
  77. fi;
  78. # check if the methods value is correct
  79. if [ "$ret" -eq 0 ]; then
  80. $CTL ul show | grep "Methods:: 4294967295" &> /dev/null
  81. ret=$?
  82. fi;
  83. kill_kamailio
  84. echo "delete from location where username like '49721123456789%';" | $ISQL
  85. mv $CFG.tmp $CFG
  86. exit $ret