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

Function replace_build

re.c:389–499  ·  view source on GitHub ↗

! \brief Replies will be allocated with the proper size & rpl.len set * \return 0 on success, <0 on error */

Source from the content-addressed store, hash-verified

387 * \return 0 on success, <0 on error
388 */
389static int replace_build(const char* match, int nmatch, regmatch_t* pmatch,
390 struct subst_expr* se, struct sip_msg* msg, str* rpl)
391{
392 int r;
393 str* uri;
394 pv_value_t sv;
395 char* p;
396 char* dest;
397 char* end;
398 int size;
399#define REPLACE_BUFFER_SIZE 1024
400 static char rbuf[REPLACE_BUFFER_SIZE];
401
402#if 0
403 /* use static bufer now since we cannot easily get the length */
404 rpl->len=replace_len(match, nmatch, pmatch, se, msg);
405 if (rpl->len==0){
406 rpl->s=0; /* empty string */
407 return 0;
408 }
409 rpl->s=pkg_malloc(rpl->len);
410 if (rpl->s==0){
411 LM_ERR("out of pkg mem (rpl)\n");
412 goto error;
413 }
414#endif
415
416 p=se->replacement.s;
417 end=p+se->replacement.len;
418 dest=rbuf;
419 for (r=0; r<se->n_escapes; r++){
420 /* copy the unescaped parts */
421 size=se->replacement.s+se->replace[r].offset-p;
422 if(dest-rbuf+size>=REPLACE_BUFFER_SIZE-1){
423 LM_ERR("overflow\n");
424 goto error;
425 }
426 memcpy(dest, p, size);
427 p+=size+se->replace[r].size;
428 dest+=size;
429 switch(se->replace[r].type){
430 case REPLACE_NMATCH:
431 if ((se->replace[r].u.nmatch<nmatch)&&(
432 pmatch[se->replace[r].u.nmatch].rm_so!=-1)){
433 /* do the replace */
434 size=pmatch[se->replace[r].u.nmatch].rm_eo-
435 pmatch[se->replace[r].u.nmatch].rm_so;
436 if(dest-rbuf+size>=REPLACE_BUFFER_SIZE-1){
437 LM_ERR("overflow\n");
438 goto error;
439 }
440 memcpy(dest,
441 match+pmatch[se->replace[r].u.nmatch].rm_so,
442 size);
443 dest+=size;
444 };
445 break;
446 case REPLACE_CHAR:

Callers 1

subst_runFunction · 0.85

Calls 2

replace_lenFunction · 0.85
pv_get_spec_valueFunction · 0.85

Tested by

no test coverage detected