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

Function repl_exp_parse

modules/dialplan/dp_repl.c:46–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45
46struct subst_expr* repl_exp_parse(str subst)
47{
48 struct replace_with rw[MAX_REPLACE_WITH];
49 int rw_no;
50 struct subst_expr * se;
51 int replace_all;
52 char * p, *end, *repl, *repl_end;
53 int max_pmatch, r;
54
55 se = 0;
56 replace_all = 0;
57 p = subst.s;
58 end = p + subst.len;
59 rw_no = 0;
60
61 repl = p;
62 if((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITHOUT_SEP))< 0)
63 goto error;
64
65 repl_end=p;
66
67 /* construct the subst_expr structure */
68 se = shm_malloc(sizeof(struct subst_expr)+
69 ((rw_no)?(rw_no-1)*sizeof(struct replace_with):0));
70 /* 1 replace_with structure is already included in subst_expr */
71 if (se==0){
72 LM_ERR("out of shm memory (subst_expr)\n");
73 goto error;
74 }
75 memset((void*)se, 0, sizeof(struct subst_expr));
76
77 se->replacement.len=repl_end-repl;
78 if (!(se->replacement.s=shm_malloc(se->replacement.len * sizeof(char))) ){
79 LM_ERR("out of shm memory \n");
80 goto error;
81 }
82 if(!rw_no){
83 replace_all = 1;
84 }
85 /* start copying */
86 memcpy(se->replacement.s, repl, se->replacement.len);
87 se->re=0;
88 se->replace_all=replace_all;
89 se->n_escapes=rw_no;
90 se->max_pmatch=max_pmatch;
91
92 /*replace_with is a simple structure, no shm alloc needed*/
93 for (r=0; r<rw_no; r++) se->replace[r]=rw[r];
94 return se;
95
96error:
97 if (se) { repl_expr_free(se);}
98 return NULL;
99}
100
101
102#define MAX_PHONE_NB_DIGITS 127

Callers 1

build_ruleFunction · 0.85

Calls 3

parse_replFunction · 0.85
shm_mallocFunction · 0.85
repl_expr_freeFunction · 0.85

Tested by

no test coverage detected