[sr-dev] git:master: core: added #!substdefs

Daniel-Constantin Mierla miconda at gmail.com
Wed Jul 6 23:20:34 CEST 2011


Module: sip-router
Branch: master
Commit: 8198fd2b82181ef7e37f5bc0c7bbbbd197b4daa7
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8198fd2b82181ef7e37f5bc0c7bbbbd197b4daa7

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Jul  6 15:17:12 2011 +0200

core: added #!substdefs

- similar to substdef but the defined value will be enclosed in double
  quotes

---

 cfg.lex |    2 ++
 cfg.y   |    5 ++++-
 ppcfg.c |   20 +++++++++++++++++---
 ppcfg.h |    2 +-
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/cfg.lex b/cfg.lex
index 68ce3ff..dd67ea8 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -563,6 +563,7 @@ EAT_ABLE	[\ \t\b\r]
 /* pre-processing blocks */
 SUBST       subst
 SUBSTDEF    substdef
+SUBSTDEFS   substdefs
 
 /* include files */
 INCLUDEFILE     "include_file"
@@ -1245,6 +1246,7 @@ IMPORTFILE      "import_file"
 
 <INITIAL>{PREP_START}{SUBST}	{ count();  return SUBST;}
 <INITIAL>{PREP_START}{SUBSTDEF}	{ count();  return SUBSTDEF;}
+<INITIAL>{PREP_START}{SUBSTDEFS}	{ count();  return SUBSTDEFS;}
 
 <INITIAL,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+    { count();
 								if (pp_ifdef_type(1)) return 1;
diff --git a/cfg.y b/cfg.y
index 5d0d10b..b0e18bc 100644
--- a/cfg.y
+++ b/cfg.y
@@ -563,6 +563,7 @@ extern char *finame;
 /*pre-processor*/
 %token SUBST
 %token SUBSTDEF
+%token SUBSTDEFS
 
 /* operators, C like precedence */
 %right EQUAL
@@ -1969,8 +1970,10 @@ event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
 preprocess_stm:
 	SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
 	| SUBST error { yyerror("invalid subst preprocess statement"); }
-	| SUBSTDEF STRING { if(pp_substdef_add($2)<0) YYERROR; }
+	| SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
 	| SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
+	| SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
+	| SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
 	;
 
 /*exp:	rval_expr
diff --git a/ppcfg.c b/ppcfg.c
index 7eb4e64..032e97d 100644
--- a/ppcfg.c
+++ b/ppcfg.c
@@ -81,7 +81,7 @@ int pp_subst_add(char *data)
 	return 0;
 }
 
-int pp_substdef_add(char *data)
+int pp_substdef_add(char *data, int mode)
 {
 	char c;
 	char *p;
@@ -131,17 +131,31 @@ found_regexp:
 found_repl:
 	defvalue.len = p - defvalue.s;
 
+	pp_define_set_type(0);
 	if(pp_define(defname.len, defname.s)<0) {
 		LM_ERR("cannot set define name\n");
 		goto error;
 	}
+	if(mode==1) {
+		/* define the value enclosed in double quotes */
+		*(defvalue.s-1) = '"';
+		defvalue.s[defvalue.len] = '"';
+		defvalue.s--;
+		defvalue.len += 2;
+	}
 	if(pp_define_set(defvalue.len, defvalue.s)<0) {
 		LM_ERR("cannot set define value\n");
 		goto error;
 	}
+	if(mode==1) {
+		defvalue.s++;
+		defvalue.len -= 2;
+		*(defvalue.s-1) = c;
+		defvalue.s[defvalue.len] = c;
+	}
 
-	LM_DBG("### added substdef: [%.*s]=[%.*s]\n", defname.len, defname.s,
-			defvalue.len, defvalue.s);
+	LM_DBG("### added substdef: [%.*s]=[%.*s] (%d)\n", defname.len, defname.s,
+			defvalue.len, defvalue.s, mode);
 
 	return 0;
 
diff --git a/ppcfg.h b/ppcfg.h
index 754d83b..b806daf 100644
--- a/ppcfg.h
+++ b/ppcfg.h
@@ -23,7 +23,7 @@
 #define _PPCFG_H_
 
 int pp_subst_add(char *data);
-int pp_substdef_add(char *data);
+int pp_substdef_add(char *data, int mode);
 int pp_subst_run(char **data);
 
 int  pp_define(int len, const char *text);




More information about the sr-dev mailing list