Module: kamailio
Branch: master
Commit: cd2f5d4ca2a3ec31c1e67cd08ad025a152241e35
URL:
https://github.com/kamailio/kamailio/commit/cd2f5d4ca2a3ec31c1e67cd08ad025a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-12-09T10:41:41+01:00
core: enclose in quotes the value for #!defenvs
---
Modified: src/core/cfg.lex
Modified: src/core/ppcfg.c
Modified: src/core/ppcfg.h
---
Diff:
https://github.com/kamailio/kamailio/commit/cd2f5d4ca2a3ec31c1e67cd08ad025a…
Patch:
https://github.com/kamailio/kamailio/commit/cd2f5d4ca2a3ec31c1e67cd08ad025a…
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index 551cfab014..84f5630483 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -2087,6 +2087,7 @@ int pp_define_env(const char *text, int len, int qmode)
char *r;
str defname;
str defvalue;
+ str newval;
r = strchr(text, '=');
@@ -2115,6 +2116,13 @@ int pp_define_env(const char *text, int len, int qmode)
LM_ERR("cannot set define name [%s]\n", (char*)text);
return -1;
}
+ if(qmode==KSR_PPDEF_QUOTED) {
+ if(pp_def_qvalue(&defvalue, &newval) < 0) {
+ LM_ERR("failed to enclose in quotes the value\n");
+ return -1;
+ }
+ defvalue = newval;
+ }
if(pp_define_set(defvalue.len, defvalue.s, qmode)<0) {
LM_ERR("cannot set define value [%s]\n", (char*)text);
return -1;
diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c
index 67391557f8..3d91679df6 100644
--- a/src/core/ppcfg.c
+++ b/src/core/ppcfg.c
@@ -48,6 +48,31 @@ static pp_subst_rule_t *pp_subst_rules_tail = NULL;
static int _pp_ifdef_level = 0;
static str_list_t *_ksr_substdef_strlist = NULL;
+int pp_def_qvalue(str *defval, str *outval)
+{
+ str newval;
+ str_list_t *sb;
+
+ if(pv_get_buffer_size() < defval->len + 4) {
+ LM_ERR("defined value is too large\n");
+ return -1;
+ }
+ newval.s = pv_get_buffer();
+ newval.s[0] = '"';
+ memcpy(newval.s + 1, defval->s, defval->len);
+ newval.s[defval->len + 1] = '"';
+ newval.s[defval->len + 2] = '\0';
+ newval.len = defval->len + 2;
+ sb = str_list_block_add(&_ksr_substdef_strlist, newval.s, newval.len);
+ if(sb==NULL) {
+ LM_ERR("failed to link quoted value [%.*s]\n", defval->len,
defval->s);
+ return -1;
+ }
+ *outval = sb->s;
+
+ return 0;
+}
+
int pp_subst_add(char *data)
{
struct subst_expr* se;
@@ -163,22 +188,11 @@ int pp_substdef_add(char *data, int mode)
}
}
if(mode==KSR_PPDEF_QUOTED) {
- if(pv_get_buffer_size() < defvalue.len + 4) {
- LM_ERR("defined value is too large\n");
- return -1;
- }
- newval.s = pv_get_buffer();
- newval.s[0] = '"';
- memcpy(newval.s + 1, defvalue.s, defvalue.len);
- newval.s[defvalue.len + 1] = '"';
- newval.s[defvalue.len + 2] = '\0';
- newval.len = defvalue.len + 2;
- sb = str_list_block_add(&_ksr_substdef_strlist, newval.s, newval.len);
- if(sb==NULL) {
- LM_ERR("failed to handle substdef: [%s]\n", data);
+ if(pp_def_qvalue(&defvalue, &newval) < 0) {
+ LM_ERR("failed to enclose in quotes the value\n");
return -1;
}
- defvalue = sb->s;
+ defvalue = newval;
}
if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_QUOTED)<0) {
LM_ERR("cannot set define value\n");
diff --git a/src/core/ppcfg.h b/src/core/ppcfg.h
index a8d27f7083..d08884775c 100644
--- a/src/core/ppcfg.h
+++ b/src/core/ppcfg.h
@@ -34,6 +34,8 @@ typedef struct ksr_ppdefine {
int dtype;
} ksr_ppdefine_t;
+int pp_def_qvalue(str *defval, str *outval);
+
str* pp_get_define_name(int idx);
ksr_ppdefine_t* pp_get_define(int idx);