Skip to content

Commit

Permalink
add ATTR_TAG_MATCH
Browse files Browse the repository at this point in the history
which sees if attribute A matches tag T
  • Loading branch information
alandekok committed Jan 8, 2018
1 parent 5d98bb3 commit b180b26
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/include/pair.h
Expand Up @@ -176,6 +176,7 @@ typedef struct value_pair_raw {
* @param _y tag belonging to the attribute were checking.
*/
#define TAG_EQ(_x, _y) ((_x == _y) || (_x == TAG_ANY) || ((_x == TAG_NONE) && (_y == TAG_ANY)))
#define ATTR_TAG_MATCH(_a, _t) (!_a->da->flags.has_tag || TAG_EQ(_t, _a->tag))
#define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da) && (!_x->da->flags.has_tag || TAG_EQ(_x->tag, _y->tag)))

#define NUM_ANY INT_MIN
Expand Down
12 changes: 6 additions & 6 deletions src/lib/util/pair.c
Expand Up @@ -758,7 +758,7 @@ void fr_pair_replace(VALUE_PAIR **head, VALUE_PAIR *replace)
* Found the head attribute, replace it,
* and return.
*/
if ((i->da == replace->da) && (!i->da->flags.has_tag || TAG_EQ(replace->tag, i->tag))) {
if ((i->da == replace->da) && ATTR_TAG_MATCH(i, replace->tag)) {
*prev = replace;

/*
Expand Down Expand Up @@ -844,7 +844,7 @@ void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int
next = i->next;
if (i->da->parent->flags.is_root &&
(i->da->attr == attr) && (i->da->vendor == 0) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
ATTR_TAG_MATCH(i, tag)) {
*last = next;
talloc_free(i);
} else {
Expand All @@ -857,7 +857,7 @@ void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int
next = i->next;
if ((i->da->parent->type == FR_TYPE_VENDOR) &&
(i->da->attr == attr) && (i->da->vendor == vendor) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
ATTR_TAG_MATCH(i, tag)) {
*last = next;
talloc_free(i);
} else {
Expand Down Expand Up @@ -1213,7 +1213,7 @@ void fr_pair_validate_debug(TALLOC_CTX *ctx, VALUE_PAIR const *failed[2])
return;
}

if (!TAG_EQ(filter->tag, list->tag)) {
if (!ATTR_TAG_MATCH(list, filter->tag)) {
fr_strerror_printf("Attribute \"%s\" tag \"%i\" didn't match filter tag \"%i\"",
list->da->name, list->tag, filter->tag);
return;
Expand Down Expand Up @@ -1564,7 +1564,7 @@ VALUE_PAIR *fr_pair_list_copy_by_num(TALLOC_CTX *ctx, VALUE_PAIR *from,
vp = fr_pair_cursor_next(&src)) {
VP_VERIFY(vp);

if (vp->da->flags.has_tag && !TAG_EQ(tag, vp->tag)) {
if (!ATTR_TAG_MATCH(vp, tag)) {
continue;
}

Expand Down Expand Up @@ -1837,7 +1837,7 @@ static void fr_pair_list_move_by_num_internal(TALLOC_CTX *ctx, VALUE_PAIR **to,
VP_VERIFY(i);
next = i->next;

if (i->da->flags.has_tag && !TAG_EQ(tag, i->tag)) {
if (!ATTR_TAG_MATCH(i, tag)) {
iprev = i;
continue;
}
Expand Down
14 changes: 7 additions & 7 deletions src/lib/util/pair_cursor.c
Expand Up @@ -212,7 +212,7 @@ VALUE_PAIR *fr_pair_cursor_next_by_num(vp_cursor_t *cursor, unsigned int vendor,
VP_VERIFY(i);
if (i->da->parent->flags.is_root &&
(i->da->attr == attr) && (i->da->vendor == 0) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
ATTR_TAG_MATCH(i, tag)) {
break;
}
}
Expand All @@ -223,7 +223,7 @@ VALUE_PAIR *fr_pair_cursor_next_by_num(vp_cursor_t *cursor, unsigned int vendor,
VP_VERIFY(i);
if ((i->da->parent->type == FR_TYPE_VENDOR) &&
(i->da->attr == attr) && (i->da->vendor == vendor) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
ATTR_TAG_MATCH(i, tag)) {
break;
}
}
Expand Down Expand Up @@ -266,8 +266,7 @@ VALUE_PAIR *fr_pair_cursor_next_by_child_num(vp_cursor_t *cursor,
i != NULL;
i = i->next) {
VP_VERIFY(i);
if ((i->da == da) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
if ((i->da == da) && ATTR_TAG_MATCH(i, tag)) {
break;
}
}
Expand Down Expand Up @@ -303,8 +302,7 @@ VALUE_PAIR *fr_pair_cursor_next_by_da(vp_cursor_t *cursor, fr_dict_attr_t const
i != NULL;
i = i->next) {
VP_VERIFY(i);
if ((i->da == da) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) {
if ((i->da == da) && ATTR_TAG_MATCH(i, tag)) {
break;
}
}
Expand Down Expand Up @@ -339,7 +337,9 @@ VALUE_PAIR *fr_pair_cursor_next_by_ancestor(vp_cursor_t *cursor, fr_dict_attr_t
i = i->next) {
VP_VERIFY(i);
if (fr_dict_parent_common(ancestor, i->da, true) &&
(!i->da->flags.has_tag || TAG_EQ(tag, i->tag))) break;
ATTR_TAG_MATCH(i, tag)) {
break;
}
}

return fr_pair_cursor_update(cursor, i);
Expand Down
2 changes: 1 addition & 1 deletion src/main/tmpl.c
Expand Up @@ -2000,7 +2000,7 @@ size_t tmpl_snprint(char *out, size_t outlen, vp_tmpl_t const *vpt)
return (out_p - out);
}

#define TMPL_TAG_MATCH(_a, _t) ((_a->da == _t->tmpl_da) && (!_a->da->flags.has_tag || TAG_EQ(_t->tmpl_tag, _a->tag)))
#define TMPL_TAG_MATCH(_a, _t) ((_a->da == _t->tmpl_da) && ATTR_TAG_MATCH(_a, _t->tmpl_tag))

static void *_tmpl_cursor_next(void **prev, void *curr, void *ctx)
{
Expand Down

0 comments on commit b180b26

Please sign in to comment.