Skip to content

Commit

Permalink
Add and expose fr_dict_parse_str()
Browse files Browse the repository at this point in the history
For unit testing of the dictionaries
  • Loading branch information
alandekok committed Nov 17, 2015
1 parent 2b168bd commit 809ca4b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/include/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ int fr_dict_init(TALLOC_CTX *ctx, fr_dict_t **out,

int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename);

int fr_dict_parse_str(char *str, fr_dict_attr_t const *parent, unsigned int vendor);

void fr_dict_attr_free(fr_dict_attr_t const **da);

int fr_dict_unknown_vendor_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t const **out,
Expand Down
33 changes: 33 additions & 0 deletions src/lib/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,39 @@ int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename)

#define MAX_ARGV (16)

/*
* External API for testing
*/
int fr_dict_parse_str(char *buf, fr_dict_attr_t const *parent, unsigned int vendor)
{
int argc;
char *argv[MAX_ARGV];

argc = fr_dict_str_to_argv(buf, argv, MAX_ARGV);
if (argc == 0) return 0;

if (strcasecmp(argv[0], "VALUE") == 0) {
return process_value(argv + 1, argc - 1);
}

if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
if (!parent) parent = fr_main_dict->root;

return process_attribute(parent, vendor, argv + 1, argc - 1);
}

if (strcasecmp(argv[0], "VALUE-ALIAS") == 0) {
return process_value_alias(argv + 1, argc - 1);
}

if (strcasecmp(argv[0], "VENDOR") == 0) {
return process_vendor(argv + 1, argc - 1);
}

fr_strerror_printf("Invalid input '%s'", argv[0]);
return -1;
}

/*
* Initialize the dictionary.
*/
Expand Down

0 comments on commit 809ca4b

Please sign in to comment.