50.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/bash
  2. # database access and persistent storage for registrar on mysql
  3. # Copyright (C) 2010 [email protected]
  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. CFG=50.cfg
  24. if ! (check_sipsak && check_kamailio && check_module "db_mysql" && check_mysql); then
  25. exit 0
  26. fi ;
  27. MYSQL_LOC_A="mysql loc_a --show-warnings --batch --user=ser --password=ser -e"
  28. MYSQL_LOC_B="mysql loc_b --show-warnings --batch --user=ser --password=ser -e"
  29. cp $CFG $CFG.bak
  30. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG #> /dev/null
  31. ret=$?
  32. sleep 1
  33. # register two contacts
  34. echo "adding new contacts"
  35. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost -x 30 &> /dev/null
  36. sipsak -U -C sip:foobar1@localhost -s sip:49721123456789@localhost -H localhost -x 30 &> /dev/null
  37. sipsak -U -C sip:foobar2@localhost -s sip:49721123456790@localhost -H localhost -x 30 &> /dev/null
  38. ret=$?
  39. if [ ! "$ret" -eq 0 ]; then
  40. echo "registration failed"
  41. fi
  42. if [ "$ret" -eq 0 ]; then
  43. TMP=`$MYSQL_LOC_A "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  44. if [ "$TMP" -eq 0 ] ; then
  45. TMP=`$MYSQL_LOC_B "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  46. if [ "$TMP" -eq 0 ] ; then
  47. echo "User 49721123456789 was NOT saved to either loc_a or loc_b"
  48. ret=1
  49. fi
  50. fi;
  51. fi;
  52. if [ "$ret" -eq 0 ]; then
  53. TMP=`$MYSQL_LOC_A "select COUNT(*) from location where username='49721123456790';" | tail -n 1`
  54. if [ "$TMP" -eq 0 ] ; then
  55. TMP=`$MYSQL_LOC_B "select COUNT(*) from location where username='49721123456790';" | tail -n 1`
  56. if [ "$TMP" -eq 0 ] ; then
  57. echo "User 49721123456790 was NOT saved to either loc_a or loc_b"
  58. ret=1
  59. fi
  60. fi;
  61. fi;
  62. if [ "$ret" -eq 0 ]; then
  63. echo "check if the contact is registered"
  64. sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" #&> /dev/null
  65. ret=$?
  66. echo "sipsak exited with status $ret"
  67. fi;
  68. if [ "$ret" -eq 0 ]; then
  69. echo "update the registration"
  70. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
  71. ret=$?
  72. fi;
  73. if [ "$ret" -eq 0 ]; then
  74. echo "check if we get a hint when we try to unregister a non-existent conctact"
  75. sipsak -U -C "sip:foobar2@localhost" -s sip:[email protected] -H localhost -x 0 -q "Contact: <sip:foobar@localhost>" &> /dev/null
  76. ret=$?
  77. fi;
  78. if [ "$ret" -eq 0 ]; then
  79. echo " unregister the contact"
  80. sipsak -U -C "sip:foobar@localhost" -s sip:[email protected] -H localhost -x 0 &> /dev/null
  81. ret=$?
  82. fi;
  83. if [ "$ret" -eq 0 ]; then
  84. echo "unregister the user again should not fail"
  85. sipsak -U -C "sip:foobar@localhost" -s sip:[email protected] -H localhost -x 0 #&> /dev/null
  86. ret=$?
  87. fi;
  88. if [ "$ret" -eq 0 ]; then
  89. echo "check if the other contact is still registered"
  90. sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar1@localhost>" &> /dev/null
  91. ret=$?
  92. fi;
  93. if [ "$ret" -eq 0 ]; then
  94. echo " register the other again"
  95. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost &> /dev/null
  96. ret=$?
  97. fi;
  98. if [ "$ret" -eq 0 ]; then
  99. echo " unregister all contacts"
  100. sipsak -U -C "*" -s sip:[email protected] -H localhost -x 0 &> /dev/null
  101. ret=$?
  102. fi;
  103. if [ "$ret" -eq 0 ]; then
  104. executed=1
  105. ret=`$MYSQL_LOC_A "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  106. if [ "$TMP" -eq 0 ] ; then
  107. ret=`$MYSQL_LOC_B "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  108. fi;
  109. fi;
  110. if [ "x$executed" == "x1" ]; then
  111. echo "After un-registration user has $ret contacts "
  112. fi
  113. if [ "$ret" -eq 0 ]; then
  114. # test min_expires functionality
  115. sipsak -U -C sip:foobar@localhost -s sip:49721123456789@localhost -H localhost -x 2 &> /dev/null
  116. ret=$?
  117. fi;
  118. if [ "$ret" -eq 0 ]; then
  119. sleep 3
  120. # check if the contact is still registered
  121. sipsak -U -C empty -s sip:[email protected] -H localhost -q "Contact: <sip:foobar@localhost>" &> /dev/null
  122. ret=$?
  123. fi;
  124. if [ "$ret" -eq 0 ]; then
  125. # register a few more contacts
  126. sipsak -U -e 9 -s sip:49721123456789@localhost -H localhost &> /dev/null
  127. fi;
  128. $MYSQL_LOC_A "delete from location where username like '497211234567%';"
  129. $MYSQL_LOC_B "delete from location where username like '497211234567%';"
  130. kill_kamailio
  131. mv $CFG.bak $CFG
  132. exit $ret