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

Function reindex_dests

modules/dispatcher/dispatch.c:469–516  ·  view source on GitHub ↗

compact destinations from sets for fast access */

Source from the content-addressed store, hash-verified

467
468/* compact destinations from sets for fast access */
469int reindex_dests( ds_data_t *d_data)
470{
471 int j;
472 ds_set_p sp = NULL;
473 ds_dest_p dp = NULL, dp0= NULL;
474
475 for( sp=d_data->sets ; sp!= NULL ; sp=sp->next )
476 {
477 if (sp->nr == 0) {
478 continue;
479 }
480
481 dp0 = (ds_dest_p)shm_malloc(sp->nr*sizeof(ds_dest_t));
482 if(dp0==NULL)
483 {
484 LM_ERR("no more memory!\n");
485 goto err1;
486 }
487 memset(dp0, 0, sp->nr*sizeof(ds_dest_t));
488
489 /*copy from the old pointer to destination, and then free it*/
490 for(j=sp->nr-1; j>=0 && sp->dlist!= NULL; j--)
491 {
492 memcpy(&dp0[j], sp->dlist, sizeof(ds_dest_t));
493 if(j==sp->nr-1)
494 dp0[j].next = NULL;
495 else
496 dp0[j].next = &dp0[j+1];
497
498 dp = sp->dlist;
499 sp->dlist = dp->next;
500
501 shm_free(dp);
502 dp=NULL;
503 }
504
505 sp->dlist=dp0;
506
507 re_calculate_active_dsts(sp);
508
509 }
510
511 LM_DBG("found [%d] dest sets\n", d_data->sets_no);
512 return 0;
513
514err1:
515 return -1;
516}
517
518
519/* variables used to generate the pvar name */

Callers 1

ds_load_dataFunction · 0.85

Calls 3

shm_mallocFunction · 0.85
shm_freeFunction · 0.85
re_calculate_active_dstsFunction · 0.85

Tested by

no test coverage detected