Skip to content

Commit

Permalink
Simplify radius_vpt_get_vp
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 23, 2014
1 parent a0c857e commit 5736d0e
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/main/valuepair.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,32 +1662,24 @@ int radius_vpt_get_vp(VALUE_PAIR **out, REQUEST *request, value_pair_tmpl_t cons
* name.
*/
case VPT_TYPE_ATTR:
{
int16_t num;
vp_cursor_t cursor;

if (vpt->vpt_num == NUM_ANY) {
vp = pairfind(*vps, vpt->vpt_da->attr, vpt->vpt_da->vendor, vpt->vpt_tag);
if (!vp) return -1;
} else {
int16_t num;
vp_cursor_t cursor;
break;
}

/*
* It's faster to just repeat the 3-4 lines of pairfind here.
*/
num = vpt->vpt_num;
for (vp = fr_cursor_init(&cursor, vps);
vp != NULL;
vp = fr_cursor_next(&cursor)) {
VERIFY_VP(vp);
if ((vp->da == vpt->vpt_da) && (!vp->da->flags.has_tag || (vpt->vpt_tag == TAG_ANY) || (vp->tag == vpt->vpt_tag))) {
if (num == 0) {
*out = vp;
return 0;
}
num--;
}
}
return -1;
vp = fr_cursor_init(&cursor, vps);
num = vpt->vpt_num;
while((vp = fr_cursor_next_by_da(&cursor, vpt->vpt_da, vpt->vpt_tag))) {
VERIFY_VP(vp);
if (num-- == 0) goto finish;
}
break;
return -1;
}

case VPT_TYPE_LIST:
vp = *vps;
Expand All @@ -1701,9 +1693,8 @@ int radius_vpt_get_vp(VALUE_PAIR **out, REQUEST *request, value_pair_tmpl_t cons
return -1;
}

if (out) {
*out = vp;
}
finish:
if (out) *out = vp;

return 0;
}
Expand Down

0 comments on commit 5736d0e

Please sign in to comment.