MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / tr_eval_re

Function tr_eval_re

transformations.c:2064–2175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2062static struct subst_expr *subst_re = NULL;
2063static str buf_re = { 0, 0 };
2064int tr_eval_re(struct sip_msg *msg, tr_param_t *tp, int subtype,
2065 pv_value_t *val)
2066{
2067 int match_no=0;
2068 pv_value_t v;
2069 str *result;
2070 str sv;
2071 char *s, *e, *p;
2072 char *buf;
2073
2074 if (!val)
2075 return -1;
2076
2077 if (val->flags & PV_VAL_NULL)
2078 return 0;
2079
2080 if(!(val->flags&PV_VAL_STR) || val->rs.len<=0)
2081 goto error;
2082
2083 switch (subtype) {
2084 case TR_RE_SUBST:
2085 if (tp->type == TR_PARAM_STRING) {
2086 sv = tp->v.s;
2087 } else {
2088 if(pv_get_spec_value(msg, (pv_spec_p)tp->v.data, &v)!=0
2089 || (!(v.flags&PV_VAL_STR)) || v.rs.len<=0) {
2090 LM_ERR("cannot get value from spec\n");
2091 goto error;
2092 }
2093 sv = v.rs;
2094 }
2095 /* temporary use the regex input buffer to check the subst */
2096 buf = pkg_realloc(reg_input_buf, sv.len);
2097 if (!buf) {
2098 LM_ERR("not enough memory for regex buffer %d [%.*s]\n",
2099 sv.len, sv.len, sv.s);
2100 goto error;
2101 }
2102 reg_input_buf = buf;
2103 /* copy un-escaped str to buf */
2104 for (s = sv.s, e = sv.s + sv.len, p = buf; s < e; s++, p++) {
2105 if (*s=='\\') {
2106 if (s + 1 >= e)
2107 break;
2108 if (*(s + 1) == TR_RBRACKET || *(s + 1) == TR_LBRACKET) {
2109 s++;
2110 sv.len--;
2111 }
2112 }
2113 *p = *s;
2114 }
2115 sv.s = buf;
2116
2117 LM_DBG("Trying to apply regexp [%.*s] on : [%.*s]\n",
2118 sv.len,sv.s,val->rs.len, val->rs.s);
2119 if (subst_re==NULL || !buf_re.s || buf_re.len != sv.len ||
2120 memcmp(buf_re.s, sv.s, sv.len) != 0) {
2121 LM_DBG("we must compile the regexp\n");

Callers

nothing calls this directly

Calls 4

pv_get_spec_valueFunction · 0.85
subst_expr_freeFunction · 0.85
subst_parserFunction · 0.85
subst_strFunction · 0.85

Tested by

no test coverage detected