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; }
static int add_rule(rt_data_t *rdata, char *grplst, str *prefix, rt_info_t *rule) { long int t; char *tmp; char *ep; int n; tmp=grplst; n=0; /* parse the grplst */ while(tmp && (*tmp!=0)) { errno = 0; t = strtol(tmp, &ep, 10); if (ep == tmp) { LM_ERR("bad grp id '%c' (%d)[%s]\n", *ep, (int)(ep-grplst), grplst); goto error; } if ((!IS_SPACE(*ep)) && (*ep != SEP) && (*ep != SEP1) && (*ep!=0)) { LM_ERR("bad char %c (%d) [%s]\n", *ep, (int)(ep-grplst), grplst); goto error; } if (errno == ERANGE && (t== LONG_MAX || t== LONG_MIN)) { LM_ERR("out of bounds\n"); goto error; } n++; /* add rule -> has prefix? */ if (prefix->len) { /* add the routing rule */ if ( add_prefix(rdata->pt, prefix, rule, (unsigned int)t)!=0 ) { LM_ERR("failed to add prefix route\n"); goto error; } } else { if ( add_rt_info( &rdata->noprefix, rule, (unsigned int)t)!=0 ) { LM_ERR("failed to add prefixless route\n"); goto error; } } /* keep parsing */ if(IS_SPACE(*ep)) EAT_SPACE(ep); if(ep && (*ep == SEP || *ep == SEP1)) ep++; tmp = ep; } if(n==0) { LM_ERR("no id in grp list [%s]\n", grplst); goto error; } return 0; error: return -1; }