kam_to_sr.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env sh
  2. #
  3. # This is a simple script which attempts to convert kamailio modules so that
  4. # they can be used with the sip-router core. Most of the changes done by the
  5. # script deal with the changes in the database abstraction layer in the
  6. # sip-router source tree.
  7. #
  8. # Run this script in module directory to convert it from kamailio core to
  9. # sip-router core. The root of the tree should be two levels up, otherwise
  10. # relative paths to headers (../..) would not work and the module will not
  11. # compile.
  12. #
  13. # Some of the changes done by the script:
  14. #
  15. # * Extra defines in the Makefile to make the module link with libsrdb1
  16. # * Path to database headers updated to point to lib/srdb1
  17. # * db_con_t and db_res_t renamed to db1_con_t and db1_res_t in *.[ch]
  18. # * Value type names such as DB_INT changed to DB1_INT in *.[ch]
  19. #
  20. # NOTE: There is no guarantee that the update module would compile or even
  21. # work. Make a backup before running the script. You have been warned!
  22. #
  23. # Written by Jan Janak <[email protected]>
  24. #
  25. if [ ! -f Makefile ] ; then
  26. echo "ERROR: Could not find module Makefile"
  27. echo " Run this file in the module directory"
  28. exit 1
  29. fi
  30. if ! egrep "Makefile\.modules" Makefile >/dev/null ; then
  31. echo "ERROR: Doesn't look like a module..."
  32. exit 1
  33. fi
  34. if ! egrep '^#[ \t]*include[ \t]*".*\/db\/db(_(cap|con|id|key|op|pool|query|res|row|ut|val))?\.h[ \t]*"' *.[ch] >/dev/null ; then
  35. echo "The module does not seem to include old database headers..."
  36. exit 0
  37. fi
  38. echo -n "Updating Makefile..."
  39. cp Makefile Makefile.backup
  40. cat Makefile.backup | gawk '
  41. BEGIN {
  42. serlibpath_seen = 0
  43. libs_seen = 0
  44. defs_seen = 0
  45. }
  46. # If the define already exists then skip it, this ensures that
  47. # we do not add the same line more than once.
  48. /^[ \t]*DEFS[ \t]*\+?=.*OPENSER_MOD_INTERFACE/ {
  49. defs_seen = 1
  50. }
  51. /^[ \t]*DEFS[ \t]*\+?=.*KAMAILIO_MOD_INTERFACE/ {
  52. defs_seen = 1
  53. }
  54. /^[ \t]*SER_LIBS[ \t]*\+?=.*srdb1\/srdb1/ {
  55. libs_seen = 1
  56. }
  57. /^[ \t]*SERLIBPATH[ \t]*=/ {
  58. serlibpath_seen = 1
  59. }
  60. # Write everything just before the line including Makefile.modules,
  61. # this is most likely the last line in the Makefile
  62. /^[ \t]*include[ \t]+.*\/Makefile\.modules[ \t]*$/ {
  63. if (serlibpath_seen == 0) print "SERLIBPATH=../../lib"
  64. if (defs_seen == 0) print "DEFS+=-DKAMAILIO_MOD_INTERFACE"
  65. if (libs_seen == 0) print "SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1"
  66. }
  67. { print $0 }
  68. ' > Makefile
  69. echo "done."
  70. for file in *.[ch] ; do
  71. echo -n "Updating file $file..."
  72. cp $file $file.backup
  73. cat $file.backup | gawk '
  74. /^#[ \t]*include[ \t]*".*\/db\/db(_(cap|con|id|key|op|pool|query|res|row|ut|val))?\.h[ \t]*"/ {
  75. sub("/db/", "/lib/srdb1/", $0);
  76. }
  77. /(^|[^a-zA-Z0-9_])(db_(con|res)_t|struct[ \t]+db_(con|res))([^a-zA-Z0-9_]|$)/ {
  78. gsub("struct[ \t]+db_con", "struct db1_con", $0);
  79. gsub("struct[ \t]+db_res", "struct db1_res", $0);
  80. gsub("db_con_t", "db1_con_t", $0);
  81. gsub("db_res_t", "db1_res_t", $0);
  82. }
  83. /(^|[^a-zA-Z0-9_])DB_((BIG)?INT|DOUBLE|STR(ING)?|DATETIME|BLOB|BITMAP)([^a-zA-Z0-9_]|$)/ {
  84. gsub("DB_INT", "DB1_INT", $0);
  85. gsub("DB_BIGINT", "DB1_BIGINT", $0);
  86. gsub("DB_DOUBLE", "DB1_DOUBLE", $0);
  87. gsub("DB_STR", "DB1_STR", $0);
  88. gsub("DB_DATETIME", "DB1_DATETIME", $0);
  89. gsub("DB_BLOB", "DB1_BLOB", $0);
  90. gsub("DB_BITMAP", "DB1_BITMAP", $0);
  91. }
  92. { print $0 }
  93. ' >$file
  94. echo "done."
  95. done