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

Function subst_f

modules/textops/textops.c:466–508  ·  view source on GitHub ↗

sed-perl style re: s/regular expression/replacement/flags */

Source from the content-addressed store, hash-verified

464
465/* sed-perl style re: s/regular expression/replacement/flags */
466static int subst_f(struct sip_msg* msg, struct subst_expr *se)
467{
468 struct lump* l;
469 struct replace_lst* lst;
470 struct replace_lst* rpl;
471 char* begin;
472 int off;
473 int ret;
474 int nmatches;
475
476 begin=get_header(msg); /* start after first line to avoid replacing
477 the uri */
478 off=begin-msg->buf;
479 ret=-1;
480 if ((lst=subst_run(se, begin, msg, &nmatches))==0)
481 goto error; /* not found */
482 for (rpl=lst; rpl; rpl=rpl->next){
483 LM_DBG("%s: replacing at offset %d [%.*s] with [%.*s]\n",
484 exports.name, rpl->offset+off,
485 rpl->size, rpl->offset+off+msg->buf,
486 rpl->rpl.len, rpl->rpl.s);
487 if ((l=del_lump(msg, rpl->offset+off, rpl->size, 0))==0)
488 goto error;
489 /* hack to avoid re-copying rpl, possible because both
490 * replace_lst & lumps use pkg_malloc */
491 if (insert_new_lump_after(l, rpl->rpl.s, rpl->rpl.len, 0)==0){
492 LM_ERR("ERROR: %s: subst_f: could not insert new lump\n",
493 exports.name);
494 goto error;
495 }
496 /* hack continued: set rpl.s to 0 so that replace_lst_free will
497 * not free it */
498 rpl->rpl.s=0;
499 rpl->rpl.len=0;
500 }
501 ret=1;
502error:
503 LM_DBG("lst was %p\n", lst);
504 if (lst) replace_lst_free(lst);
505 if (nmatches<0)
506 LM_ERR("ERROR: %s: subst_run failed\n", exports.name);
507 return ret;
508}
509
510
511/* sed-perl style re: s/regular expression/replacement/flags, like

Callers

nothing calls this directly

Calls 5

get_headerFunction · 0.85
subst_runFunction · 0.85
del_lumpFunction · 0.85
insert_new_lump_afterFunction · 0.85
replace_lst_freeFunction · 0.85

Tested by

no test coverage detected