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 99
 	#define SELECT_S                5
100 100
 	#define AVP_PVAR_S              6  /* avp or pvar */
101 101
 	#define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
102
+	#define PVARID_S                8  /* $foo.bar...*/
102 103
 
103 104
 	#define STR_BUF_ALLOC_UNIT	128
104 105
 	struct str_buf{
... ...
@@ -124,7 +126,12 @@
124 124
 %}
125 125
 
126 126
 /* start conditions */
127
-%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
127
+%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P PVARID
128
+
129
+/* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
130
+SER_CFG			SER
131
+KAMAILIO_CFG	KAMAILIO|OPENSER
132
+MAXCOMPAT_CFG	MAXCOMPAT|ALL
128 133
 
129 134
 /* action keywords */
130 135
 FORWARD	forward
... ...
@@ -761,8 +768,22 @@ EAT_ABLE	[\ \t\b\r]
761 761
 							return ID;
762 762
 						}
763 763
 
764
-<INITIAL>{VAR_MARK}{LPAREN}	{ state = PVAR_P_S; BEGIN(PVAR_P); p_nest=1; 
765
-								yymore();}
764
+<INITIAL>{VAR_MARK}{LPAREN}	{
765
+								switch(sr_cfg_compat){
766
+									case SR_COMPAT_SER:
767
+										state=ATTR_S; BEGIN(ATTR);
768
+										yyless(1);
769
+										count();
770
+										return ATTR_MARK;
771
+										break;
772
+									case SR_COMPAT_KAMAILIO:
773
+									case SR_COMPAT_MAX:
774
+									default:
775
+										state = PVAR_P_S; BEGIN(PVAR_P);
776
+										p_nest=1; yymore();
777
+										break;
778
+								}
779
+							}
766 780
 	/* eat everything between 2 () and return PVAR token and a string
767 781
 	   containing everything (including $ and ()) */
768 782
 <PVAR_P>{RPAREN}			{	p_nest--;
... ...
@@ -779,14 +800,38 @@ EAT_ABLE	[\ \t\b\r]
779 779
 							}
780 780
 <PVAR_P>.					{ yymore(); }
781 781
 
782
+<PVARID>{ID}|'.'			{yymore(); }
783
+<PVARID>{LPAREN}			{	state = PVAR_P_S; BEGIN(PVAR_P);
784
+								p_nest=1; yymore(); }
785
+<PVARID>.					{ count(); state=INITIAL_S; BEGIN(INITIAL);
786
+								return PVAR;
787
+							}
782 788
 
783
-<INITIAL>{VAR_MARK}			{  state=AVP_PVAR_S; BEGIN(AVP_PVAR); yymore(); }
789
+
790
+<INITIAL>{VAR_MARK}			{
791
+								switch(sr_cfg_compat){
792
+									case SR_COMPAT_SER:
793
+										count();
794
+										state=ATTR_S; BEGIN(ATTR);
795
+										return ATTR_MARK;
796
+										break;
797
+									case SR_COMPAT_KAMAILIO:
798
+										state=PVARID_S; BEGIN(PVARID);
799
+										yymore();
800
+										break;
801
+									case SR_COMPAT_MAX:
802
+									default: 
803
+										state=AVP_PVAR_S; BEGIN(AVP_PVAR);
804
+										yymore();
805
+										break;
806
+								}
807
+							}
784 808
 	/* avp prefix detected -> go to avp mode */
785 809
 <AVP_PVAR>{AVP_PREF}		|
786 810
 <AVP_PVAR>{ID}{LBRACK}		{ state = ATTR_S; BEGIN(ATTR); yyless(1); 
787 811
 							  return ATTR_MARK; }
788 812
 <AVP_PVAR>{ID}{LPAREN}		{ state = PVAR_P_S; BEGIN(PVAR_P); yymore(); }
789
-<AVP_PVAR>{ID}				{ count(); addstr(&s_buf, yytext, yyleng);
813
+<AVP_PVAR>{ID}				{	count(); addstr(&s_buf, yytext, yyleng);
790 814
 								yylval.strval=s_buf.s;
791 815
 								memset(&s_buf, 0, sizeof(s_buf));
792 816
 								state = INITIAL_S;
... ...
@@ -882,6 +927,12 @@ EAT_ABLE	[\ \t\b\r]
882 882
 								}
883 883
 <COMMENT>.|{EAT_ABLE}|{CR}				{ count(); };
884 884
 
885
+<INITIAL>{COM_LINE}!{SER_CFG}{CR}		{ count();
886
+											sr_cfg_compat=SR_COMPAT_SER;}
887
+<INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}	{ count(); 
888
+											sr_cfg_compat=SR_COMPAT_KAMAILIO;}
889
+<INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR}	{ count(); 
890
+												sr_cfg_compat=SR_COMPAT_MAX;}
885 891
 <INITIAL>{COM_LINE}.*{CR}	{ count(); }
886 892
 
887 893
 <INITIAL>{ID}			{ count(); addstr(&s_buf, yytext, yyleng);
... ...
@@ -916,6 +967,8 @@ EAT_ABLE	[\ \t\b\r]
916 916
 													" while parsing"
917 917
 													" avp name\n");
918 918
 											break;
919
+										case PVARID_S:
920
+											p_nest=0;
919 921
 										case PVAR_P_S: 
920 922
 											LOG(L_CRIT, "ERROR: unexpected EOF"
921 923
 													" while parsing pvar name"
922 924
new file mode 100644
... ...
@@ -0,0 +1,43 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2008 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/**
18
+ * @file 
19
+ * @brief  ser/kamailio/openser compatibility macros & vars.
20
+ */
21
+/* 
22
+ * History:
23
+ * --------
24
+ *  2008-11-29  initial version (andrei)
25
+ */
26
+
27
+
28
+#include "sr_compat.h"
29
+
30
+#ifdef SR_SER
31
+#define SR_DEFAULT_COMPAT SR_COMPAT_SER
32
+#elif defined SR_KAMAILIO || defined SR_OPENSER
33
+#define SR_DEFAULT_COMPAT SR_COMPAT_KAMAILIO
34
+#elif defined SR_ALL || defined SR_MAX_COMPAT
35
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
36
+#else
37
+/* default */
38
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
39
+#endif
40
+
41
+int sr_compat=SR_DEFAULT_COMPAT;
42
+int sr_cfg_compat=SR_DEFAULT_COMPAT;
0 43
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2008 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/**
18
+ * @file 
19
+ * @brief  ser/kamailio/openser compatibility macros & vars.
20
+ */
21
+/* 
22
+ * History:
23
+ * --------
24
+ *  2008-11-29  initial version (andrei)
25
+ */
26
+
27
+
28
+#ifndef _sr_compat_h
29
+#define _sr_compat_h
30
+
31
+/** max compat mode: support as many features as possible from all xSERs */
32
+#define SR_COMPAT_MAX 0
33
+/** maximum compatibility mode with ser */
34
+#define SR_COMPAT_SER 1
35
+/** maximum compatibility mode with kamailio/openser */
36
+#define SR_COMPAT_KAMAILIO 2
37
+#define SR_COMPAT_OPENSER 2
38
+
39
+
40
+extern int sr_compat;
41
+extern int sr_cfg_compat;
42
+
43
+#endif /* _sr_compat_h */