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

Function tr_eval_nameaddr

transformations.c:2451–2636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2449static struct to_body *nameaddr_to_body = NULL;
2450
2451int tr_eval_nameaddr(struct sip_msg *msg, tr_param_t *tp, int subtype,
2452 pv_value_t *val)
2453{
2454 struct to_param* topar;
2455 pv_value_t v;
2456 int index, total;
2457 struct to_body *nameaddr = NULL;
2458
2459 if (!val)
2460 return -1;
2461
2462 if (val->flags & PV_VAL_NULL)
2463 return 0;
2464
2465 if(!(val->flags&PV_VAL_STR) || val->rs.len<=0)
2466 goto error;
2467
2468 LM_DBG("String to transform %.*s\n", val->rs.len, val->rs.s);
2469
2470 if(nameaddr_str.len==0 || nameaddr_str.len!=val->rs.len ||
2471 strncmp(nameaddr_str.s, val->rs.s, val->rs.len)!=0)
2472 {
2473 /* copy the value in the global variable */
2474 if(val->rs.len+CRLF_LEN > nameaddr_str.len)
2475 {
2476 if(nameaddr_str.s) pkg_free(nameaddr_str.s);
2477 nameaddr_str.s =
2478 (char*)pkg_malloc((val->rs.len+CRLF_LEN+1)*sizeof(char));
2479 if(nameaddr_str.s==NULL)
2480 {
2481 LM_ERR("no more private memory\n");
2482 memset(&nameaddr_str, 0, sizeof(str));
2483 goto error;
2484 }
2485 }
2486 nameaddr_str.len = val->rs.len + CRLF_LEN;
2487 memcpy(nameaddr_str.s, val->rs.s, val->rs.len);
2488 memcpy(nameaddr_str.s + val->rs.len, CRLF, CRLF_LEN);
2489 nameaddr_str.s[nameaddr_str.len] = '\0';
2490
2491 /* reset old values */
2492 if (nameaddr_to_body) {
2493 free_to(nameaddr_to_body);
2494 nameaddr_to_body = NULL;
2495 }
2496
2497 /* parse TO hdr + params */
2498 nameaddr_to_body = (struct to_body*)pkg_malloc(sizeof(struct to_body));
2499 if(nameaddr_to_body==NULL)
2500 {
2501 LM_ERR("no more private memory\n");
2502 /* keep the buffer, but flush the content to force the realloc
2503 next time */
2504 nameaddr_str.s[0] = 0;
2505 goto error;
2506 }
2507 parse_multi_to(nameaddr_str.s, nameaddr_str.s + nameaddr_str.len,
2508 nameaddr_to_body);

Callers

nothing calls this directly

Calls 4

free_toFunction · 0.85
parse_multi_toFunction · 0.85
pv_get_spec_valueFunction · 0.85
int2strFunction · 0.85

Tested by

no test coverage detected