| 457 | |
| 458 | |
| 459 | int add_rt_info( |
| 460 | ptree_node_t *pn, |
| 461 | rt_info_t* r, |
| 462 | unsigned int rgid, |
| 463 | osips_malloc_f malloc_f, |
| 464 | osips_free_f free_f |
| 465 | ) |
| 466 | { |
| 467 | rg_entry_t *trg=NULL; |
| 468 | rt_info_wrp_t *rtl_wrp=NULL; |
| 469 | rt_info_wrp_t *rtlw=NULL; |
| 470 | int i=0; |
| 471 | |
| 472 | if((NULL == pn) || (NULL == r)) |
| 473 | goto err_exit; |
| 474 | |
| 475 | if (NULL == (rtl_wrp = (rt_info_wrp_t*) |
| 476 | func_malloc(malloc_f, sizeof(rt_info_wrp_t)))) { |
| 477 | LM_ERR("no more shm mem\n"); |
| 478 | goto err_exit; |
| 479 | } |
| 480 | memset( rtl_wrp, 0, sizeof(rt_info_wrp_t)); |
| 481 | rtl_wrp->rtl = r; |
| 482 | |
| 483 | if(NULL==pn->rg) { |
| 484 | /* allocate the routing groups array */ |
| 485 | pn->rg_len = RG_INIT_LEN; |
| 486 | if(NULL == (pn->rg = (rg_entry_t*)func_malloc(malloc_f, |
| 487 | pn->rg_len*sizeof(rg_entry_t)))) { |
| 488 | /* recover the old pointer to be able to shm_free mem */ |
| 489 | goto err_exit; |
| 490 | } |
| 491 | memset( pn->rg, 0, pn->rg_len*sizeof(rg_entry_t)); |
| 492 | pn->rg_pos=0; |
| 493 | } |
| 494 | /* search for the rgid up to the rg_pos */ |
| 495 | for(i=0; (i<pn->rg_pos) && (pn->rg[i].rgid!=rgid); i++); |
| 496 | if(i==pn->rg_len) { |
| 497 | /* realloc & copy the old rg */ |
| 498 | trg = pn->rg; |
| 499 | if(NULL == (pn->rg = (rg_entry_t*)func_malloc(malloc_f, |
| 500 | (pn->rg_len + RG_INIT_LEN)*sizeof(rg_entry_t)))) { |
| 501 | /* recover the old pointer to be able to shm_free mem */ |
| 502 | pn->rg = trg; |
| 503 | goto err_exit; |
| 504 | } |
| 505 | memset(pn->rg+pn->rg_len, 0, RG_INIT_LEN*sizeof(rg_entry_t)); |
| 506 | memcpy(pn->rg, trg, pn->rg_len*sizeof(rg_entry_t)); |
| 507 | pn->rg_len+=RG_INIT_LEN; |
| 508 | func_free(free_f, trg); |
| 509 | } |
| 510 | /* insert into list */ |
| 511 | r->ref_cnt++; |
| 512 | if(NULL==pn->rg[i].rtlw){ |
| 513 | pn->rg[i].rtlw = rtl_wrp; |
| 514 | pn->rg[i].rgid = rgid; |
| 515 | pn->rg_pos++; |
| 516 | goto ok_exit; |
no outgoing calls
no test coverage detected