Module: kamailio
Branch: master
Commit: 41babc99c83c74ca3d1494698455394dd8458e87
URL:
https://github.com/kamailio/kamailio/commit/41babc99c83c74ca3d1494698455394…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-09-22T09:35:04+02:00
core: added #!defexps preprocessor directive
- similar to #!defexp but the resulted value is enclosed in double
quotes
---
Modified: src/core/cfg.lex
Modified: src/core/ppcfg.c
Modified: src/core/ppcfg.h
---
Diff:
https://github.com/kamailio/kamailio/commit/41babc99c83c74ca3d1494698455394…
Patch:
https://github.com/kamailio/kamailio/commit/41babc99c83c74ca3d1494698455394…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index e508d420e3..cc0afb8f22 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -576,6 +576,7 @@ ENDIF endif
TRYDEF "trydefine"|"trydef"
REDEF "redefine"|"redef"
DEFEXP defexp
+DEFEXPS defexps
DEFENV defenv
DEFENVS defenvs
TRYDEFENV trydefenv
@@ -1344,6 +1345,10 @@ IMPORTFILE "import_file"
ksr_cfg_print_part(yytext);
pp_define_set_type(KSR_PPDEF_DEFEXP);
state = DEFINE_S; BEGIN(DEFINE_ID); }
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFEXPS}{EAT_ABLE}+ { count();
+ ksr_cfg_print_part(yytext);
+ pp_define_set_type(KSR_PPDEF_DEFEXPS);
+ state = DEFINE_S; BEGIN(DEFINE_ID); }
<DEFINE_ID>{ID}{MINUS} { count();
ksr_cfg_print_part(yytext);
LM_CRIT(
@@ -2150,8 +2155,13 @@ int pp_define_set(int len, char *text, int mode)
return -1;
}
- if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP) {
- sval = pp_defexp_eval(text, len);
+ if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP
+ || pp_defines[ppos].dtype == KSR_PPDEF_DEFEXPS) {
+ if(pp_defines[ppos].dtype == KSR_PPDEF_DEFEXP) {
+ sval = pp_defexp_eval(text, len, 0);
+ } else {
+ sval = pp_defexp_eval(text, len, 1);
+ }
if(sval==NULL) {
LM_NOTICE("no value returned to set the defexp [%.*s]\n",
pp_defines[ppos].name.len, pp_defines[ppos].name.s);
diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c
index 8e43e9722d..e8aac78233 100644
--- a/src/core/ppcfg.c
+++ b/src/core/ppcfg.c
@@ -461,7 +461,7 @@ void pp_ifexp_eval(char *exval, int exlen)
snexpr_destroy(e, &vars);
}
-char *pp_defexp_eval(char *exval, int exlen)
+char *pp_defexp_eval(char *exval, int exlen, int qmode)
{
str exstr;
struct snexpr_var_list vars = {0};
@@ -505,13 +505,25 @@ char *pp_defexp_eval(char *exval, int exlen)
sval.len = strlen(result->param.stz.sval);
}
- res = (char*)pkg_malloc(sval.len + 1);
+ if(qmode==1) {
+ res = (char*)pkg_malloc(sval.len + 3);
+ } else {
+ res = (char*)pkg_malloc(sval.len + 1);
+ }
if(res==NULL) {
PKG_MEM_ERROR;
goto done;
}
- memcpy(res, sval.s, sval.len);
- res[sval.len] = '\0';
+ if(qmode==1) {
+ res[0] = '"';
+ memcpy(res, sval.s+1, sval.len);
+ res[sval.len+1] = '"';
+ res[sval.len+2] = '\0';
+ LM_DBG("expression quoted string result: [%s]\n", res);
+ } else {
+ memcpy(res, sval.s, sval.len);
+ res[sval.len] = '\0';
+ }
done:
snexpr_result_free(result);
diff --git a/src/core/ppcfg.h b/src/core/ppcfg.h
index 7b5b016c08..f461535ed8 100644
--- a/src/core/ppcfg.h
+++ b/src/core/ppcfg.h
@@ -35,6 +35,7 @@
#define KSR_PPDEF_TRYDEF 1
#define KSR_PPDEF_REDEF 2
#define KSR_PPDEF_DEFEXP 3
+#define KSR_PPDEF_DEFEXPS 4
typedef struct ksr_ppdefine {
str name;
@@ -68,7 +69,7 @@ void ksr_cfg_print_initial_state(void);
void pp_ifexp_eval(char *exval, int exlen);
void pp_ifexp_state(int state);
-char *pp_defexp_eval(char *exval, int exlen);
+char *pp_defexp_eval(char *exval, int exlen, int qmode);
#endif /*_PPCFG_H_*/