11.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. # database access and persistent storage for registrar on mysql
  3. # Copyright (C) 2007 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. CFG=11.cfg
  24. if ! (check_sipsak && check_kamailio && check_module "db_mysql" && check_mysql); then
  25. exit 0
  26. fi ;
  27. SIPDOMAIN=127.0.0.1
  28. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG -a no > /dev/null
  29. ret=$?
  30. sleep 1
  31. # register two contacts
  32. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  33. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  34. ret=$?
  35. if [ "$ret" -eq 0 ]; then
  36. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  37. ret=$?
  38. fi;
  39. if [ "$ret" -eq 0 ]; then
  40. TMP=`$MYSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  41. if [ "$TMP" -eq 0 ] ; then
  42. ret=1
  43. fi;
  44. fi;
  45. if [ "$ret" -eq 0 ]; then
  46. # check if the contact is registered
  47. sipsak -U -C empty -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -q "Contact: <sip:[email protected]>" > /dev/null 2>&1
  48. ret=$?
  49. fi;
  50. if [ "$ret" -eq 0 ]; then
  51. # update the registration
  52. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  53. ret=$?
  54. fi;
  55. if [ "$ret" -eq 0 ]; then
  56. # check if we get a hint when we try to unregister a non-existent conctact
  57. sipsak -U -C "sip:[email protected]" -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 0 -q "Contact: <sip:[email protected]>" > /dev/null 2>&1
  58. ret=$?
  59. fi;
  60. if [ "$ret" -eq 0 ]; then
  61. # unregister the contact
  62. sipsak -U -C "sip:[email protected]" -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 0 > /dev/null 2>&1
  63. ret=$?
  64. fi;
  65. if [ "$ret" -eq 0 ]; then
  66. # unregister the user again should not fail
  67. sipsak -U -C "sip:[email protected]" -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 0 > /dev/null 2>&1
  68. ret=$?
  69. fi;
  70. if [ "$ret" -eq 0 ]; then
  71. # check if the other contact is still registered
  72. sipsak -U -C empty -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -q "Contact: <sip:[email protected]>" > /dev/null 2>&1
  73. ret=$?
  74. fi;
  75. if [ "$ret" -eq 0 ]; then
  76. # register the other again
  77. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  78. ret=$?
  79. fi;
  80. if [ "$ret" -eq 0 ]; then
  81. # unregister all contacts
  82. sipsak -U -C "*" -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 0 > /dev/null 2>&1
  83. ret=$?
  84. fi;
  85. if [ "$ret" -eq 0 ]; then
  86. # let the timer cleanup the previous registrations
  87. sleep 2
  88. $CTL ul show | grep "AOR:: 49721123456789" > /dev/null
  89. ret=$?
  90. if [ "$ret" -eq 0 ]; then
  91. ret=1
  92. else
  93. ret=0
  94. fi;
  95. fi ;
  96. if [ "$ret" -eq 0 ]; then
  97. ret=`$MYSQL "select COUNT(*) from location where username='49721123456789';" | tail -n 1`
  98. fi;
  99. if [ "$ret" -eq 0 ]; then
  100. # test min_expires functionality
  101. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -x 2 > /dev/null 2>&1
  102. ret=$?
  103. fi;
  104. if [ "$ret" -eq 0 ]; then
  105. sleep 3
  106. # check if the contact is still registered
  107. sipsak -U -C empty -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -q "Contact: <sip:[email protected]>" > /dev/null 2>&1
  108. ret=$?
  109. fi;
  110. if [ "$ret" -eq 0 ]; then
  111. # register a few more contacts
  112. sipsak -U -e 9 -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  113. fi;
  114. if [ "$ret" -eq 0 ]; then
  115. # let the timer cleanup the previous registrations
  116. sleep 3
  117. # and check
  118. TMP=`$MYSQL "select COUNT(*) from location where username like '49721123456789%';" | tail -n 1`
  119. if [ "$TMP" -eq 10 ] ; then
  120. ret=0
  121. else
  122. ret=1
  123. fi;
  124. fi;
  125. $MYSQL "delete from location where username like '49721123456789%';"
  126. if [ "$ret" -eq 0 ]; then
  127. # register again
  128. sipsak -U -C sip:[email protected] -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN > /dev/null 2>&1
  129. ret=$?
  130. fi;
  131. kill_kamailio
  132. # restart to test preload_udomain functionality
  133. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -w . -f $CFG -a no> /dev/null
  134. ret=$?
  135. sleep 1
  136. if [ "$ret" -eq 0 ]; then
  137. # check if the contact is still registered
  138. sipsak -U -C empty -s sip:49721123456789@$SIPDOMAIN -H $SIPDOMAIN -q "Contact: <sip:[email protected]>" > /dev/null 2>&1
  139. ret=$?
  140. fi;
  141. # check if the methods value is correct
  142. if [ "$ret" -eq 0 ]; then
  143. $CTL ul show | grep "Methods:: 4294967295" > /dev/null
  144. ret=$?
  145. fi;
  146. # cleanup
  147. $MYSQL "delete from location where username like '49721123456789%';"
  148. kill_kamailio
  149. exit $ret