static LTI *aa_find(LTI **t,char *name,int len,int *insert) { // find/insert node into t LTI *lti=NULL; int iter=(*insert)&ITER; int dir=(*insert)&1; if ((*t)==&aa_sentinel) lti=((*insert)&INSERT)?(*t)=LTI_init(NEW(LTI),name,len):NULL; else { int delta=0; for (int i=0;delta==0 && i<PREVIEWLEN && i<len && i<(*t)->len;i++) delta=name[i]-(*t)->preview[i]; if (!delta) // preview matched, compare full strings delta=strnncmp(name,len,(*t)->name,(*t)->len); int deltadir=delta<0?LEFT:RIGHT; // turn LTZ/Z/GTZ into left/right/right if (delta) { if (LTI_invalid(lti=aa_find(&(*t)->lnk[deltadir],name,len,insert)) && iter && dir!=deltadir) lti=*t; } else if (iter) // matches, but find next smaller/larger lti=aa_most((*t)->lnk[dir],!dir); else // return match lti=(*t),(*insert)=0; } if ((*insert)&INSERT) { // rebalance if necessary aa_skew(t); aa_split(t); } return lti; }
void aa_recommendhi(aa_linkedlist ** l, __AA_CONST char *name) { aa_linkedlist *m = (aa_linkedlist *) malloc(sizeof(*m)), *o = aa_find(*l, name); if (o != NULL) remove(*l, o); m->text = strdup(name); inslist(*l, m); }
void aa_recommendlow(aa_linkedlist ** l, __AA_CONST char *name) { aa_linkedlist *o = aa_find(*l, name); if (o == NULL) { aa_linkedlist *m = (aa_linkedlist *) malloc(sizeof(*m)); m->text = strdup(name); addlist(*l, m); } }
/* returns the mirror field of the most specific aaa record for the given ip address and source */ aa_mirror_right AA_can_mirror(ip_addr_t *address, char *source) { aa_rights *myrights = aa_find(address, source); if (myrights) return myrights->mirror; return 0; }
/* returns the ripupdate field of the most specific aaa record for the given ip address and source * 0 = can't do updates through update port * 1 = can do updates through update port */ int AA_can_ripupdate(ip_addr_t *address, char *source) { aa_rights *myrights = aa_find(address, source); if (myrights) return myrights->ripupdate; return 0; }