Browse code

Kamailio to sip-router module conversion script.

This is a simple script which attempts to convert modules that use kamalio
core to sip-router core.

Signed-off-by: Jan Janak <jan@iptel.org>

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