|
|
|
@ -147,12 +147,21 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
|
|
|
|
|
subst_comp = rule->subst_comp;
|
|
|
|
|
repl_comp = rule->repl_comp;
|
|
|
|
|
|
|
|
|
|
if(!repl_comp){
|
|
|
|
|
LM_DBG("null replacement\n");
|
|
|
|
|
if (!subst_comp) {
|
|
|
|
|
/*simply copy from the replacing string*/
|
|
|
|
|
if(!repl_comp || !repl_comp->replacement.s || repl_comp->replacement.len == 0){
|
|
|
|
|
LM_ERR("invalid replacing string\n");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
LM_DBG("simply replace the string, subst_comp %p, n_escapes %i\n",
|
|
|
|
|
subst_comp, repl_comp->n_escapes);
|
|
|
|
|
memcpy(result->s, repl_comp->replacement.s,
|
|
|
|
|
repl_comp->replacement.len);
|
|
|
|
|
result->len = repl_comp->replacement.len;
|
|
|
|
|
result->s[result->len] = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(subst_comp){
|
|
|
|
|
/*just in case something went wrong at load time*/
|
|
|
|
|
rc = pcre_fullinfo(subst_comp, NULL, PCRE_INFO_CAPTURECOUNT,
|
|
|
|
|
&cap_cnt);
|
|
|
|
@ -161,7 +170,7 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
|
|
|
|
|
rc);
|
|
|
|
|
return -1;;
|
|
|
|
|
}
|
|
|
|
|
if(repl_comp->max_pmatch > cap_cnt){
|
|
|
|
|
if(repl_comp && repl_comp->max_pmatch > cap_cnt){
|
|
|
|
|
LM_ERR("illegal access to the %i-th subexpr of the subst expr\n",
|
|
|
|
|
repl_comp->max_pmatch);
|
|
|
|
|
return -1;
|
|
|
|
@ -177,25 +186,20 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
|
|
|
|
|
rule->subst_exp.len, rule->subst_exp.s);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*simply copy from the replacing string*/
|
|
|
|
|
if(!subst_comp || (repl_comp->n_escapes <=0)){
|
|
|
|
|
if(!repl_comp->replacement.s || repl_comp->replacement.len == 0){
|
|
|
|
|
LM_ERR("invalid replacing string\n");
|
|
|
|
|
/* copy non-matched prefix of string to output */
|
|
|
|
|
if (ovector[0] > 0) {
|
|
|
|
|
if (ovector[0] >= MAX_PHONE_NB_DIGITS) {
|
|
|
|
|
LM_ERR("overflow\n");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
LM_DBG("simply replace the string, subst_comp %p, n_escapes %i\n",
|
|
|
|
|
subst_comp, repl_comp->n_escapes);
|
|
|
|
|
memcpy(result->s, repl_comp->replacement.s,
|
|
|
|
|
repl_comp->replacement.len);
|
|
|
|
|
result->len = repl_comp->replacement.len;
|
|
|
|
|
result->s[result->len] = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
memcpy(result->s, string.s, ovector[0]);
|
|
|
|
|
result->len += ovector[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (repl_comp) {
|
|
|
|
|
/* offset- offset in the replacement string */
|
|
|
|
|
result->len = repl_nb = offset = 0;
|
|
|
|
|
repl_nb = offset = 0;
|
|
|
|
|
p=repl_comp->replacement.s;
|
|
|
|
|
|
|
|
|
|
while( repl_nb < repl_comp->n_escapes){
|
|
|
|
@ -290,7 +294,7 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
|
|
|
|
|
repl_nb++;
|
|
|
|
|
}
|
|
|
|
|
/* anything left? */
|
|
|
|
|
if( repl_nb && offset < repl_comp->replacement.len){
|
|
|
|
|
if(offset < repl_comp->replacement.len){
|
|
|
|
|
/*copy from the replacing string*/
|
|
|
|
|
size = repl_comp->replacement.len - offset;
|
|
|
|
|
memcpy(result->s + result->len, p + offset, size);
|
|
|
|
@ -298,6 +302,18 @@ int rule_translate(struct sip_msg *msg, str string, dpl_node_t * rule,
|
|
|
|
|
size, p + offset);
|
|
|
|
|
result->len += size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy non-matched suffix of string to output */
|
|
|
|
|
size = string.len - ovector[1];
|
|
|
|
|
if (size > 0) {
|
|
|
|
|
if (result->len + size >= MAX_PHONE_NB_DIGITS) {
|
|
|
|
|
LM_ERR("overflow\n");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
memcpy(result->s + result->len, string.s + ovector[1], size);
|
|
|
|
|
result->len += size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result->s[result->len] = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|