int add_prefix( ptree_t *ptree, str* prefix, rt_info_t *r, unsigned int rg ) { char* tmp=NULL; int res = 0; if(NULL==ptree) { LM_ERR("ptree is null\n"); goto err_exit; } tmp = prefix->s; while(tmp < (prefix->s+prefix->len)) { if(NULL == tmp) { LM_ERR("prefix became null\n"); goto err_exit; } if( !IS_DECIMAL_DIGIT(*tmp) ) { /* unknown character in the prefix string */ LM_ERR("is not decimal digit\n"); goto err_exit; } if( tmp == (prefix->s+prefix->len-1) ) { /* last digit in the prefix string */ LM_DBG("adding info %p, %d at: " "%p (%d)\n", r, rg, &(ptree->ptnode[*tmp-'0']), *tmp-'0'); res = add_rt_info(&(ptree->ptnode[*tmp-'0']), r,rg); if(res < 0 ) { LM_ERR("adding rt info doesn't work\n"); goto err_exit; } unode++; res = 1; goto ok_exit; } /* process the current digit in the prefix */ if(NULL == ptree->ptnode[*tmp - '0'].next) { /* allocate new node */ INIT_PTREE_NODE(ptree, ptree->ptnode[*tmp - '0'].next); inode+=10; #if 0 printf("new tree node: %p (bp: %p)\n", ptree->ptnode[*tmp - '0'].next, ptree->ptnode[*tmp - '0'].next->bp ); #endif } ptree = ptree->ptnode[*tmp-'0'].next; tmp++; } ok_exit: return 0; err_exit: return -1; }
rt_data_t* build_rt_data( void ) { rt_data_t *rdata=NULL; if( NULL==(rdata=shm_malloc(sizeof(rt_data_t)))) { LM_ERR("no more shm mem\n"); goto err_exit; } memset(rdata, 0, sizeof(rt_data_t)); INIT_PTREE_NODE(NULL, rdata->pt); rdata->pgw_tree = map_create( AVLMAP_SHARED ); rdata->carriers_tree = map_create( AVLMAP_SHARED ); if (rdata->pgw_tree == NULL || rdata->carriers_tree == NULL) { LM_ERR("Initializing avl failed!\n"); if (rdata->pgw_tree) map_destroy(rdata->pgw_tree, 0); goto err_exit; } return rdata; err_exit: if (rdata) shm_free(rdata); return 0; }
rt_data_t* build_rt_data( void ) { rt_data_t *rdata; if( NULL==(rdata=shm_malloc(sizeof(rt_data_t)))) { LM_ERR("no more shm mem\n"); goto err_exit; } memset(rdata, 0, sizeof(rt_data_t)); INIT_PTREE_NODE(NULL, rdata->pt); return rdata; err_exit: return 0; }