[SR-Dev] git:andrei/script_vars: script: ser, kamailio and max compat mode support
Andrei Pelinescu-Onciul
andrei at iptel.org
Mon Dec 1 13:20:51 CET 2008
Module: sip-router
Branch: andrei/script_vars
Commit: f69ff7d9697349bf767f355be93eb15cdeab4e60
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f69ff7d9697349bf767f355be93eb15cdeab4e60
Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date: Sat Nov 29 17:12:16 2008 +0100
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)
---
NEWS | 18 +++++++++++++++-
cfg.lex | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
sr_compat.c | 43 ++++++++++++++++++++++++++++++++++++++++
sr_compat.h | 44 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 162 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index f9c0867..03852ee 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,24 @@
-Release notes for SIP Express Router (ser)
+Release notes for SIP Router (sr)
***********************************************
$Id$
+sip-router changes
+
+core:
+ - support for dual module interfaces: ser and kamailio
+config script changes:
+ - script mode can be switched between ser compatible, kamailio compatible
+ and max compatibility (compatible with both as much as possible), using
+ #!SER
+ #!KAMAILIO
+ #!OPENSER
+ #!ALL
+ #!MAXCOMPAT
+ where #!KAMAILIO is equivalent with #!OPENSER and #!ALL with #!MAXCOMPAT
+ - support for kamailio style pvars
+
+
2.1.0 changes
diff --git a/cfg.lex b/cfg.lex
index b196c32..c4f5a14 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -89,6 +89,7 @@
#include "usr_avp.h"
#include "select.h"
#include "cfg.tab.h"
+ #include "sr_compat.h"
/* states */
#define INITIAL_S 0
@@ -99,6 +100,7 @@
#define SELECT_S 5
#define AVP_PVAR_S 6 /* avp or pvar */
#define PVAR_P_S 7 /* pvar: $(...) or $foo(...)*/
+ #define PVARID_S 8 /* $foo.bar...*/
#define STR_BUF_ALLOC_UNIT 128
struct str_buf{
@@ -124,7 +126,12 @@
%}
/* start conditions */
-%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
+%x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P PVARID
+
+/* config script types : #!SER or #!KAMAILIO or #!MAX_COMPAT */
+SER_CFG SER
+KAMAILIO_CFG KAMAILIO|OPENSER
+MAXCOMPAT_CFG MAXCOMPAT|ALL
/* action keywords */
FORWARD forward
@@ -761,8 +768,22 @@ EAT_ABLE [\ \t\b\r]
return ID;
}
-<INITIAL>{VAR_MARK}{LPAREN} { state = PVAR_P_S; BEGIN(PVAR_P); p_nest=1;
- yymore();}
+<INITIAL>{VAR_MARK}{LPAREN} {
+ switch(sr_cfg_compat){
+ case SR_COMPAT_SER:
+ state=ATTR_S; BEGIN(ATTR);
+ yyless(1);
+ count();
+ return ATTR_MARK;
+ break;
+ case SR_COMPAT_KAMAILIO:
+ case SR_COMPAT_MAX:
+ default:
+ state = PVAR_P_S; BEGIN(PVAR_P);
+ p_nest=1; yymore();
+ break;
+ }
+ }
/* eat everything between 2 () and return PVAR token and a string
containing everything (including $ and ()) */
<PVAR_P>{RPAREN} { p_nest--;
@@ -779,14 +800,38 @@ EAT_ABLE [\ \t\b\r]
}
<PVAR_P>. { yymore(); }
+<PVARID>{ID}|'.' {yymore(); }
+<PVARID>{LPAREN} { state = PVAR_P_S; BEGIN(PVAR_P);
+ p_nest=1; yymore(); }
+<PVARID>. { count(); state=INITIAL_S; BEGIN(INITIAL);
+ return PVAR;
+ }
-<INITIAL>{VAR_MARK} { state=AVP_PVAR_S; BEGIN(AVP_PVAR); yymore(); }
+
+<INITIAL>{VAR_MARK} {
+ switch(sr_cfg_compat){
+ case SR_COMPAT_SER:
+ count();
+ state=ATTR_S; BEGIN(ATTR);
+ return ATTR_MARK;
+ break;
+ case SR_COMPAT_KAMAILIO:
+ state=PVARID_S; BEGIN(PVARID);
+ yymore();
+ break;
+ case SR_COMPAT_MAX:
+ default:
+ state=AVP_PVAR_S; BEGIN(AVP_PVAR);
+ yymore();
+ break;
+ }
+ }
/* avp prefix detected -> go to avp mode */
<AVP_PVAR>{AVP_PREF} |
<AVP_PVAR>{ID}{LBRACK} { state = ATTR_S; BEGIN(ATTR); yyless(1);
return ATTR_MARK; }
<AVP_PVAR>{ID}{LPAREN} { state = PVAR_P_S; BEGIN(PVAR_P); yymore(); }
-<AVP_PVAR>{ID} { count(); addstr(&s_buf, yytext, yyleng);
+<AVP_PVAR>{ID} { count(); addstr(&s_buf, yytext, yyleng);
yylval.strval=s_buf.s;
memset(&s_buf, 0, sizeof(s_buf));
state = INITIAL_S;
@@ -882,6 +927,12 @@ EAT_ABLE [\ \t\b\r]
}
<COMMENT>.|{EAT_ABLE}|{CR} { count(); };
+<INITIAL>{COM_LINE}!{SER_CFG}{CR} { count();
+ sr_cfg_compat=SR_COMPAT_SER;}
+<INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR} { count();
+ sr_cfg_compat=SR_COMPAT_KAMAILIO;}
+<INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count();
+ sr_cfg_compat=SR_COMPAT_MAX;}
<INITIAL>{COM_LINE}.*{CR} { count(); }
<INITIAL>{ID} { count(); addstr(&s_buf, yytext, yyleng);
@@ -916,6 +967,8 @@ EAT_ABLE [\ \t\b\r]
" while parsing"
" avp name\n");
break;
+ case PVARID_S:
+ p_nest=0;
case PVAR_P_S:
LOG(L_CRIT, "ERROR: unexpected EOF"
" while parsing pvar name"
diff --git a/sr_compat.c b/sr_compat.c
new file mode 100644
index 0000000..79660ab
--- /dev/null
+++ b/sr_compat.c
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/**
+ * @file
+ * @brief ser/kamailio/openser compatibility macros & vars.
+ */
+/*
+ * History:
+ * --------
+ * 2008-11-29 initial version (andrei)
+ */
+
+
+#include "sr_compat.h"
+
+#ifdef SR_SER
+#define SR_DEFAULT_COMPAT SR_COMPAT_SER
+#elif defined SR_KAMAILIO || defined SR_OPENSER
+#define SR_DEFAULT_COMPAT SR_COMPAT_KAMAILIO
+#elif defined SR_ALL || defined SR_MAX_COMPAT
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
+#else
+/* default */
+#define SR_DEFAULT_COMPAT SR_COMPAT_MAX
+#endif
+
+int sr_compat=SR_DEFAULT_COMPAT;
+int sr_cfg_compat=SR_DEFAULT_COMPAT;
diff --git a/sr_compat.h b/sr_compat.h
new file mode 100644
index 0000000..ba46bde
--- /dev/null
+++ b/sr_compat.h
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/**
+ * @file
+ * @brief ser/kamailio/openser compatibility macros & vars.
+ */
+/*
+ * History:
+ * --------
+ * 2008-11-29 initial version (andrei)
+ */
+
+
+#ifndef _sr_compat_h
+#define _sr_compat_h
+
+/** max compat mode: support as many features as possible from all xSERs */
+#define SR_COMPAT_MAX 0
+/** maximum compatibility mode with ser */
+#define SR_COMPAT_SER 1
+/** maximum compatibility mode with kamailio/openser */
+#define SR_COMPAT_KAMAILIO 2
+#define SR_COMPAT_OPENSER 2
+
+
+extern int sr_compat;
+extern int sr_cfg_compat;
+
+#endif /* _sr_compat_h */
More information about the sr-dev
mailing list