Skip to content

Commit

Permalink
use macro for common code
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Aug 8, 2019
1 parent 6127ac0 commit be7e9a4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/util/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ static bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
}

#define FORBID_OTHER_FLAGS(_flag) do { if (all_flags & ~shift_ ## _flag) { fr_strerror_printf("The '" STRINGIFY(_flag) "' flag cannot be used with any other flag"); return false; } } while (0)
#define ALLOW_FLAG(_flag) do { all_flags &= ~shift_ ## _flag; } while (0)

// is_root
// is_unknown
Expand Down Expand Up @@ -544,9 +545,8 @@ static bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
/*
* "has_tag" can also be used with "encrypt", and "internal" (for testing)
*/
all_flags &= ~shift_encrypt;
all_flags &= ~shift_internal;

ALLOW_FLAG(encrypt);
ALLOW_FLAG(internal);
FORBID_OTHER_FLAGS(has_tag);
}

Expand Down Expand Up @@ -619,7 +619,7 @@ static bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
return false;
}

all_flags &= ~shift_internal;
ALLOW_FLAG(internal);
FORBID_OTHER_FLAGS(virtual);
}

Expand Down Expand Up @@ -878,9 +878,9 @@ static bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
* MS-MPPE-Keys use octets[18],encrypt=1
* EAP-SIM-RAND uses array
*/
all_flags &= ~shift_internal;
all_flags &= ~shift_encrypt;
all_flags &= ~shift_array;
ALLOW_FLAG(internal);
ALLOW_FLAG(encrypt);
ALLOW_FLAG(array);

if (all_flags) {
fr_strerror_printf("The 'octets[...]' syntax cannot be used any other flag");
Expand Down

0 comments on commit be7e9a4

Please sign in to comment.