kam_to_sr.sh 3.4 KB

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