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

Function subst_parser

re.c:217–340  ·  view source on GitHub ↗

! \brief Parse a /regular expression/replacement/flags into a subst_expr structure */

Source from the content-addressed store, hash-verified

215/*! \brief Parse a /regular expression/replacement/flags into a subst_expr structure
216 */
217struct subst_expr* subst_parser(str* subst)
218{
219 char c;
220 char* end;
221 char* p;
222 char* re;
223 char* re_end;
224 char* repl;
225 char* repl_end;
226 struct replace_with rw[MAX_REPLACE_WITH];
227 int rw_no;
228 //int escape;
229 int cflags; /* regcomp flags */
230 int replace_all;
231 struct subst_expr* se;
232 regex_t* regex;
233 int max_pmatch;
234 int r;
235
236 /* init */
237 se=0;
238 regex=0;
239 cflags=REG_EXTENDED | REG_NEWLINE; /* don't match newline */
240 replace_all=0;
241 if (subst->len<3){
242 LM_ERR("expression is too short: %.*s\n", subst->len, subst->s);
243 goto error;
244 }
245
246 p=subst->s;
247 end=subst->s+subst->len;
248
249 c=*p;
250 if (c=='\\'){
251 LM_ERR("invalid separator char <%c> in %.*s\n", c,
252 subst->len, subst->s);
253 goto error;
254 }
255 p++;
256
257 /* find re */
258 re=p;
259 for (;p<end;p++){
260 /* if unescaped sep. char */
261 if ((*p==c) && (*(p-1)!='\\')) goto found_re;
262 }
263 LM_ERR("no separator found: %.*s\n", subst->len, subst->s);
264 goto error;
265found_re:
266 re_end=p;
267 if(end< (p+2) ){
268 LM_ERR("string too short\n");
269 goto error;
270 }
271 repl=p+1;
272 if((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITH_SEP))< 0)
273 goto error;
274

Callers 4

tr_eval_reFunction · 0.85
prom_labels_paramFunction · 0.85
fixup_substreFunction · 0.85
fixup_substreFunction · 0.85

Calls 2

parse_replFunction · 0.85
subst_expr_freeFunction · 0.85

Tested by

no test coverage detected