Browse code

script: ser, kamailio and max compat mode support

- script mode can be switched between ser compatible, kamailio
compatible and max compatibility (compatible with both as much as
possible), using #!SER, #!KAMAILIO or #!ALL on the first line
(#!OPENSER and #!MAXCOMPAT are also allowed)

Andrei Pelinescu-Onciul authored on 29/11/2008 16:12:16
Showing 4 changed files
... ...
@@ -1,8 +1,24 @@
1
-Release notes for SIP Express Router (ser)
1
+Release notes for SIP Router (sr)
2 2
 ***********************************************
3 3
 
4 4
 $Id$
5 5
 
6
+sip-router changes
7
+
8
+core:
9
+  - support for dual module interfaces: ser and kamailio
10
+config script changes:
11
+  - script mode can be switched between ser compatible, kamailio compatible
12
+    and max compatibility (compatible with both as much as possible), using
13
+      #!SER
14
+      #!KAMAILIO
15
+      #!OPENSER
16
+      #!ALL
17
+      #!MAXCOMPAT
18
+    where #!KAMAILIO is equivalent with #!OPENSER and #!ALL with #!MAXCOMPAT
19
+  - support for kamailio style pvars
20
+
21
+
6 22
 
7 23
 
8 24
 2.1.0 changes
... ...
@@ -89,6 +89,7 @@
89 89
 	#include "usr_avp.h"
90 90
 	#include "select.h"
91 91
 	#include "cfg.tab.h"
92
+	#include "sr_compat.h"
92 93
 
93 94
 	/* states */
94 95
 	#define INITIAL_S		0
... ...
@@ -99,6 +100,7 @@
99 100
 	#define SELECT_S                5
100 101
 	#define AVP_PVAR_S              6  /* avp or pvar */
101 102
 	#define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
103
+	#define PVARID_S                8  /* $foo.bar...*/
102 104
 
103 105
 	#define STR_BUF_ALLOC_UNIT	128
104 106
 	struct str_buf{
... ...
@@ -124,7 +126,12 @@
124 126
 %}
125 127
 
126 128
 /* start conditions */
127
-%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
129
+%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P PVARID
130
+
131
+/* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
132
+SER_CFG			SER
133
+KAMAILIO_CFG	KAMAILIO|OPENSER
134
+MAXCOMPAT_CFG	MAXCOMPAT|ALL
128 135
 
129 136
 /* action keywords */
130 137
 FORWARD	forward
... ...
@@ -761,8 +768,22 @@ EAT_ABLE	[\ \t\b\r]
761 768
 							return ID;
762 769
 						}
763 770
 
764
-<INITIAL>{VAR_MARK}{LPAREN}	{ state = PVAR_P_S; BEGIN(PVAR_P); p_nest=1; 
765
-								yymore();}
771
+<INITIAL>{VAR_MARK}{LPAREN}	{
772
+								switch(sr_cfg_compat){
773
+									case SR_COMPAT_SER:
774
+										state=ATTR_S; BEGIN(ATTR);
775
+										yyless(1);
776
+										count();
777
+										return ATTR_MARK;
778
+										break;
779
+									case SR_COMPAT_KAMAILIO:
780
+									case SR_COMPAT_MAX:
781
+									default:
782
+										state = PVAR_P_S; BEGIN(PVAR_P);
783
+										p_nest=1; yymore();
784
+										break;
785
+								}
786
+							}
766 787
 	/* eat everything between 2 () and return PVAR token and a string
767 788
 	   containing everything (including $ and ()) */
768 789
 <PVAR_P>{RPAREN}			{	p_nest--;
... ...
@@ -779,14 +800,38 @@ EAT_ABLE	[\ \t\b\r]
779 800
 							}
780 801
 <PVAR_P>.					{ yymore(); }
781 802
 
803
+<PVARID>{ID}|'.'			{yymore(); }
804
+<PVARID>{LPAREN}			{	state = PVAR_P_S; BEGIN(PVAR_P);
805
+								p_nest=1; yymore(); }
806
+<PVARID>.					{ count(); state=INITIAL_S; BEGIN(INITIAL);
807
+								return PVAR;
808
+							}
782 809
 
783
-<INITIAL>{VAR_MARK}			{  state=AVP_PVAR_S; BEGIN(AVP_PVAR); yymore(); }
810
+
811
+<INITIAL>{VAR_MARK}			{
812
+								switch(sr_cfg_compat){
813
+									case SR_COMPAT_SER:
814
+										count();
815
+										state=ATTR_S; BEGIN(ATTR);
816
+										return ATTR_MARK;
817
+										break;
818
+									case SR_COMPAT_KAMAILIO:
819
+										state=PVARID_S; BEGIN(PVARID);
820
+										yymore();
821
+										break;
822
+									case SR_COMPAT_MAX:
823
+									default: 
824
+										state=AVP_PVAR_S; BEGIN(AVP_PVAR);
825
+										yymore();
826
+										break;
827
+								}
828
+							}
784 829
 	/* avp prefix detected -> go to avp mode */
785 830
 <AVP_PVAR>{AVP_PREF}		|
786 831
 <AVP_PVAR>{ID}{LBRACK}		{ state = ATTR_S; BEGIN(ATTR); yyless(1); 
787 832
 							  return ATTR_MARK; }
788 833
 <AVP_PVAR>{ID}{LPAREN}		{ state = PVAR_P_S; BEGIN(PVAR_P); yymore(); }
789
-<AVP_PVAR>{ID}				{ count(); addstr(&s_buf, yytext, yyleng);
834
+<AVP_PVAR>{ID}				{	count(); addstr(&s_buf, yytext, yyleng);
790 835
 								yylval.strval=s_buf.s;
791 836
 								memset(&s_buf, 0, sizeof(s_buf));
792 837
 								state = INITIAL_S;
... ...
@@ -882,6 +927,12 @@ EAT_ABLE	[\ \t\b\r]
882 927
 								}
883 928
 <COMMENT>.|{EAT_ABLE}|{CR}				{ count(); };
884 929
 
930
+<INITIAL>{COM_LINE}!{SER_CFG}{CR}		{ count();
931
+											sr_cfg_compat=SR_COMPAT_SER;}
932
+<INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}	{ count(); 
933
+											sr_cfg_compat=SR_COMPAT_KAMAILIO;}
934
+<INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR}	{ count(); 
935
+												sr_cfg_compat=SR_COMPAT_MAX;}
885 936
 <INITIAL>{COM_LINE}.*{CR}	{ count(); }
886 937
 
887 938
 <INITIAL>{ID}			{ count(); addstr(&s_buf, yytext, yyleng);
... ...
@@ -916,6 +967,8 @@ EAT_ABLE	[\ \t\b\r]
916 967
 													" while parsing"
917 968
 													" avp name\n");
918 969
 											break;
970
+										case PVARID_S:
971
+											p_nest=0;
919 972
 										case PVAR_P_S: 
920 973
 											LOG(L_CRIT, "ERROR: unexpected EOF"
921 974
 													" while parsing pvar name"
922 975
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2008 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/**
19
+ * @file 
20
+ * @brief  ser/kamailio/openser compatibility macros & vars.
21
+ */
22
+/* 
23
+ * History:
24
+ * --------
25
+ *  2008-11-29  initial version (andrei)
26
+ */
27
+
28
+
29
+#include "sr_compat.h"
30
+
31
+#ifdef SR_SER
32
+#define SR_DEFAULT_COMPAT SR_COMPAT_SER
33
+#elif defined SR_KAMAILIO || defined SR_OPENSER
34
+#define SR_DEFAULT_COMPAT SR_COMPAT_KAMAILIO
35
+#elif defined SR_ALL || defined SR_MAX_COMPAT
36
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
37
+#else
38
+/* default */
39
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
40
+#endif
41
+
42
+int sr_compat=SR_DEFAULT_COMPAT;
43
+int sr_cfg_compat=SR_DEFAULT_COMPAT;
0 44
new file mode 100644
... ...
@@ -0,0 +1,44 @@
1
+/* 
2
+ * $Id$
3
+ * 
4
+ * Copyright (C) 2008 iptelorg GmbH
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+/**
19
+ * @file 
20
+ * @brief  ser/kamailio/openser compatibility macros & vars.
21
+ */
22
+/* 
23
+ * History:
24
+ * --------
25
+ *  2008-11-29  initial version (andrei)
26
+ */
27
+
28
+
29
+#ifndef _sr_compat_h
30
+#define _sr_compat_h
31
+
32
+/** max compat mode: support as many features as possible from all xSERs */
33
+#define SR_COMPAT_MAX 0
34
+/** maximum compatibility mode with ser */
35
+#define SR_COMPAT_SER 1
36
+/** maximum compatibility mode with kamailio/openser */
37
+#define SR_COMPAT_KAMAILIO 2
38
+#define SR_COMPAT_OPENSER 2
39
+
40
+
41
+extern int sr_compat;
42
+extern int sr_cfg_compat;
43
+
44
+#endif /* _sr_compat_h */