30#define USE_CONSTRUCTOR
39# define TEST_INIT test_init()
46#include <freeradius-devel/util/conf.h>
47#include <freeradius-devel/util/dict.h>
48#include <freeradius-devel/util/sbuff.h>
61#ifdef TEST_NESTED_PAIRS
79#ifdef TEST_NESTED_PAIRS
93 TEST_CASE(
"Allocation using fr_pair_afrom_da");
105 TEST_MSG(
"Expected vp->vp_strvalue == test_string");
115 TEST_CASE(
"Allocation using fr_pair_afrom_child_num");
134 TEST_CASE(
"Allocation using fr_pair_afrom_da_nested");
143 TEST_CASE(
"Top list does not have the tlv child attribute");
146 TEST_CASE(
"Top list does have the tlv attribute");
150 TEST_CASE(
"Parent list does have the tlv child attribute");
164 TEST_CASE(
"Allocation using fr_pair_afrom_da_nested");
173 TEST_CASE(
"Top list still has the tlv attribute");
177 TEST_CASE(
"Parent list does not have the tlv child attribute");
194 TEST_CASE(
"Allocation using fr_pair_copy");
207 TEST_CASE(
"Compare fr_pair_cmp(copy == vp) should be TRUE");
219 TEST_CASE(
"Allocate a new attribute fr_pair_afrom_da");
225 TEST_CASE(
"Stealing 'vp' pair using fr_pair_steal()");
228 TEST_CASE(
"Checking if talloc_parent(vp) == autofree");
237 TEST_CASE(
"Allocate a new attribute fr_pair_afrom_da");
243 TEST_CASE(
"Converting regular 'vp' as unknown");
246 TEST_CASE(
"Checking if a real 'raw' vp");
255 TEST_CASE(
"Searching for fr_dict_attr_test_uint32 using fr_pair_dcursor_by_da_init()");
272 TEST_CASE(
"Expected (needle->da == fr_dict_attr_test_uint32)");
281 TEST_CASE(
"Searching for fr_dict_attr_test_tlv_string as ascend of fr_dict_attr_test_tlv using fr_pair_dcursor_by_ancestor_init()");
298 TEST_CASE(
"Expected (needle->da == fr_dict_attr_test_tlv_string)");
317 vp->vp_uint32 = 6809;
324 TEST_CASE(
"Searching for fr_dict_attr_test_tlv_string as ascend of fr_dict_attr_test_tlv using fr_pair_dcursor_by_ancestor_init()");
330 TEST_CASE(
"First box is a string with value 'hello'");
332 TEST_CHECK(strcmp(box->vb_strvalue,
"hello") == 0);
336 TEST_CASE(
"First box is a uint32 with value 6809");
342 TEST_CASE(
"First box is a uint8 r with value 12");
361 TEST_CASE(
"Search for fr_dict_attr_test_string using fr_pair_find_by_da_idx()");
367 TEST_CASE(
"Expected (vp->da == fr_dict_attr_test_string)");
375 TEST_CASE(
"Search for FR_TEST_ATTR_STRING using fr_pair_find_by_child_num_idx()");
381 TEST_CASE(
"Expected (vp->da == fr_dict_attr_test_string)");
387 fr_pair_t *vp1, *vp2, *vp3, *vp4, *vp5, *vp_found;
409 TEST_CASE(
"Find child node in first TLV");
410 TEST_CHECK_PAIR(vp_found, vp1);
413 TEST_CASE(
"Find child node in second TLV");
414 TEST_CHECK_PAIR(vp_found, vp2);
431 TEST_CASE(
"Find child node in first TLV");
432 TEST_CHECK_PAIR(vp_found, vp1);
448 TEST_CASE(
"A nested attribute is found before a flat one");
449 TEST_CHECK_PAIR(vp_found, vp1);
463 TEST_CASE(
"Find a flat attribute when there is no nesting");
464 TEST_CHECK_PAIR(vp_found, vp5);
466 TEST_CASE(
"Find nothing when the attribute is not there at all");
478 TEST_CASE(
"Add 3 pairs using fr_pair_append()");
500 fr_pair_t *leaf1, *leaf2, *found, *inter1, *inter2;
506 TEST_CASE(
"Add nested attribute including parents");
511 TEST_CASE(
"Check nested attributes added");
519 TEST_CHECK_PAIR(found, leaf1);
521 TEST_CASE(
"Ensure no flat list attribute created");
523 TEST_CHECK_PAIR(found, NULL);
525 TEST_CASE(
"Add additional nested attribute where parents exist");
531 TEST_CASE(
"Check additional leaf added under existing parent");
533 TEST_CHECK_PAIR(found, leaf2);
535 TEST_CASE(
"Check no extra parent attributes created");
537 TEST_CHECK_PAIR(found, inter1);
539 TEST_CHECK_PAIR(found, NULL);
542 TEST_CHECK_PAIR(found, inter2);
544 TEST_CHECK_PAIR(found, NULL);
551 TEST_CASE(
"Delete fr_dict_attr_test_string using fr_pair_delete_by_child_num()");
554 TEST_CASE(
"The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
557 TEST_CASE(
"Add fr_dict_attr_test_string back into 'test_pairs'");
568 TEST_CASE(
"Add using fr_pair_prepend_by_da()");
573 TEST_CASE(
"Expected (vp->da == fr_dict_attr_test_string)");
587 TEST_CASE(
"Update Add using fr_pair_prepend_by_da()");
589 vp->vp_uint32 = 54321;
591 TEST_CASE(
"Expected fr_dict_attr_test_uint32 (vp->vp_uint32 == 54321)");
605 TEST_CASE(
"Delete fr_dict_attr_test_string using fr_pair_delete_by_da()");
608 TEST_CASE(
"The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
611 TEST_CASE(
"Add fr_dict_attr_test_string back into 'test_pairs'");
619 TEST_CASE(
"Delete fr_dict_attr_test_string using fr_pair_delete()");
623 TEST_CASE(
"The fr_dict_attr_test_string shouldn't exist in 'test_pairs'");
626 TEST_CASE(
"Add fr_dict_attr_test_string back into 'test_pairs'");
634 TEST_CASE(
"Create the vp1 'Test-Integer = 123'");
641 vp1->vp_uint32 = 123;
643 TEST_CASE(
"Create the vp2 'Test-Integer = 321'");
650 vp2->vp_uint32 = 321;
652 TEST_CASE(
"Compare fr_pair_cmp(vp1 == vp2) should be FALSE");
669 TEST_CASE(
"Check if 'local_pairs1' == 'local_pairs2' using fr_pair_list_cmp()");
682 TEST_CASE(
"Copy 'test_pairs' into 'local_pairs'");
685 TEST_CASE(
"Check if 'local_pairs' == 'test_pairs' using fr_pair_list_cmp()");
697 TEST_CASE(
"Copy 'test_pairs' into 'local_pairs'");
700 TEST_CASE(
"The 'local_pairs' should have only fr_dict_attr_test_string");
705 TEST_CASE(
"Expected (vp->da == fr_dict_attr_test_string)");
719 TEST_CASE(
"Copy 'test_pairs' into 'local_pairs'");
722 TEST_CASE(
"The 'local_pairs' should have only one attribute in it");
725 TEST_CASE(
"The 'local_pairs' should have only fr_dict_attr_test_tlv_string (ancestor of 'Test-TLV-Root'");
728 TEST_CASE(
"Validating we copied the attribute");
732#ifdef TEST_NESTED_PAIRS
733 TEST_CASE(
"Expected copied attribute == fr_dict_attr_test_tlv)");
736 TEST_CASE(
"Expected copied attribute == fr_dict_attr_test_tlv_string)");
740 TEST_CASE(
"Verifying the copied attribute");
743 TEST_CASE(
"Expecting nothing else in local list");
756 TEST_CASE(
"Create 'local_pairs' with 3 attributes not ordered");
759 TEST_CASE(
"Add fr_dict_attr_test_string back into 'local_pairs'");
770 TEST_CASE(
"Sorting 'local_pairs' by fr_pair_list_sort(local_pairs, fr_pair_cmp_by_da)");
773 TEST_CASE(
"1st (da == fr_dict_attr_test_string)");
777 TEST_CASE(
"2nd (da == fr_dict_attr_test_octets)");
781 TEST_CASE(
"3rd (da == fr_dict_attr_test_ipv4_addr)");
785 TEST_CASE(
"4th (da == fr_dict_attr_test_uint32)");
789 TEST_CASE(
"5th (da == fr_dict_attr_test_date)");
793 TEST_CASE(
"6th (da == fr_dict_attr_test_enum)");
804 TEST_CASE(
"Create 'vp1' with Test-Integer = 123");
806 vp1->vp_uint32 = 123;
817 TEST_CASE(
"Copy 'vp1' to 'vp2' using fr_pair_value_copy()");
837 TEST_CASE(
"Convert 'test_string' value to attribute value using fr_pair_value_from_str()");
843 TEST_CASE(
"Check (vp->vp_string == test_string)");
857 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_strdup()");
863 TEST_CASE(
"Check (vp->vp_string == test_string)");
870 char *copy_test_string;
881 talloc_set_type(copy_test_string,
char);
883 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()");
889 TEST_CASE(
"Check (vp->vp_string == copy_test_string)");
905 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_strdup_shallow()");
908 TEST_CASE(
"Trim the length of the string buffer using fr_pair_value_strtrim()");
914 TEST_CASE(
"Check (vp->vp_string == test_string)");
932 TEST_CASE(
"Copy content of 'fmt_test' to attribute value using fr_pair_value_aprintf()");
938 TEST_CASE(
"Check (vp->vp_string == fmt_test)");
953 TEST_CASE(
"Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
959 TEST_CASE(
"Copy 'test_string' to the pre-allocated pointer");
965 TEST_CASE(
"Check (vp->vp_string == test_string)");
980 TEST_CASE(
"Pre-allocate 1 byte of memory buffer using fr_pair_value_bstr_alloc()");
983 TEST_CASE(
"Re-allocate (test_string_len-1) byte of memory buffer using fr_pair_value_bstr_realloc()");
989 TEST_CASE(
"Copy 'test_string' to the pre-allocated pointer");
995 TEST_CASE(
"Check (vp->vp_string == test_string)");
1009 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup()");
1012 TEST_CASE(
"Check (vp->vp_string == test_string)");
1019 char *copy_test_string;
1028 talloc_set_type(copy_test_string,
char);
1030 TEST_CASE(
"Copy content of 'copy_test_string' to attribute value using fr_pair_value_bstrdup_buffer()");
1033 TEST_CASE(
"Check (vp->vp_string == test_string)");
1034 TEST_CHECK(
vp && strcmp(
vp->vp_strvalue, copy_test_string) == 0);
1042 char *copy_test_string;
1051 talloc_set_type(copy_test_string,
char);
1053 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_bstrndup_shallow()");
1056 TEST_CASE(
"Check (vp->vp_string == copy_test_string)");
1065 char *copy_test_string;
1074 talloc_set_type(copy_test_string,
char);
1076 TEST_CASE(
"Copy content of 'test_string' to attribute value using fr_pair_value_bstrdup_buffer_shallow()");
1079 TEST_CASE(
"Check (vp->vp_string == copy_test_string)");
1096 TEST_CASE(
"Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
1099 TEST_CASE(
"Copy 'test_octets' to the pre-allocated pointer");
1102 TEST_CASE(
"Check (out == test_octets)");
1105 TEST_CASE(
"Check (vp->vp_octets == test_octets)");
1120 TEST_CASE(
"Pre-allocate a memory buffer using fr_pair_value_bstr_alloc()");
1123 TEST_CASE(
"Copy 'test_octets' to the pre-allocated pointer");
1126 TEST_CASE(
"Realloc pre-allocated pointer to fit extra 'test_octets' copy");
1129 TEST_CASE(
"Copy 'test_octets' into the tail");
1132 TEST_CASE(
"Check first chunk (out == test_octets)");
1137 TEST_CASE(
"Check first chunk (vp->vp_octets == test_octets)");
1140 TEST_CASE(
"Check second chunk (out+NUM_ELEMENTS(test_octets) == test_octets)");
1143 TEST_CASE(
"Check second chunk (vp->vp_octets+NUM_ELEMENTS(test_octets) == test_octets)");
1157 TEST_CASE(
"Copy content of 'test_octets' to attribute value using fr_pair_value_memdup()");
1160 TEST_CASE(
"Check (vp->vp_octets == test_octets)");
1176 talloc_set_type(copy_test_octets,
uint8_t);
1178 TEST_CASE(
"Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer()");
1181 TEST_CASE(
"Check (vp->vp_octets == test_octets)");
1199 talloc_set_type(copy_test_octets,
uint8_t);
1201 TEST_CASE(
"Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_shallow()");
1204 TEST_CASE(
"Check (vp->vp_octets == test_octets)");
1222 talloc_set_type(copy_test_octets,
uint8_t);
1224 TEST_CASE(
"Copy content of 'test_octets' to attribute value using fr_pair_value_memdup_buffer_shallow()");
1227 TEST_CASE(
"Check (vp->vp_octets == copy_test_octets)");
1245 vp->vp_uint32 = 123;
1247 TEST_CASE(
"Lookup enum value attribute using fr_pair_value_enum()");
1250 TEST_MSG(
"Checking fr_pair_value_enum()");
1252 TEST_CHECK(var && strcmp(var,
"test123") == 0);
1253 TEST_MSG(
"Expected var == 'test123'");
1267 vp->vp_uint32 = 123;
1269 TEST_CASE(
"Lookup enum value attribute using fr_pair_value_enum_box()");
1272 TEST_MSG(
"Checking fr_pair_value_enum()");
1275 TEST_MSG(
"Expected vb->vb_uint32 == 123");
1315 memcpy(buf,
"testXXXX", 8);
1321 TEST_MSG(
"Expected slen=4 (matched 'test' protocol), got %zd", (
ssize_t)slen);
1324 TEST_MSG(
"Expected out_dict==test_dict; OOB read of sentinel byte made the buggy code early-return with dict_def (NULL)");
1334#define TEST_PRINT_PAIR(_func, _parent, _vp, _expected) \
1336 char buffer[1024]; \
1337 fr_sbuff_t sbuff = FR_SBUFF_OUT(buffer, sizeof(buffer)); \
1340 slen = _func(&sbuff, _parent, _vp); \
1341 TEST_CHECK(slen > 0); \
1342 TEST_MSG(#_func " returned %zd: %s", slen, fr_strerror()); \
1344 TEST_CHECK(strcmp(buffer, _expected) == 0); \
1345 TEST_MSG("expected: %s", _expected); \
1346 TEST_MSG("got : %s", buffer); \
1360 TEST_CASE(
"Print one leaf pair, relative to its own parent");
1376 TEST_CASE(
"Build Test-Nested-Top-TLV.Child-TLV.Leaf-String");
1382 TEST_CASE(
"The full name is printed when there is no parent");
1385 TEST_CHECK(strcmp(
buffer,
"Test-Nested-Top-TLV-0.Child-TLV.Leaf-String = ") == 0);
1388 TEST_CASE(
"Naming a parent trims that much off the front");
1389 fr_sbuff_set_to_start(&sbuff);
1408 TEST_CASE(
"A bare word is printed without quotes");
1413 TEST_CASE(
"A double quoted string keeps its quotes");
1414 fr_sbuff_set_to_start(&sbuff);
1426 TEST_CASE(
"A pair which holds no secret prints its value");
1433 TEST_CASE(
"A pair which holds a secret prints a placeholder instead");
1449 TEST_CASE(
"A structural pair with no children");
1455 TEST_CASE(
"A structural pair with one child, which needs no separator");
1461 TEST_CASE(
"A structural pair with two children, separated by a comma");
1466 "Test-TLV-0 = { String = \"one\", String = \"two\" }");
1468 TEST_CASE(
"Secrets are hidden inside structural pairs, too");
1471 "Test-TLV-0 = { String = \"one\", String = <<< secret >>> }");
1485 TEST_CASE(
"An empty list prints nothing");
1489 TEST_CASE(
"Two pairs are separated by a comma");
1496 fr_sbuff_set_to_start(&sbuff);
1498 TEST_CHECK(strcmp(
buffer,
"Test-String-0 = \"one\", Test-Uint32-0 = 2") == 0);
1520 TEST_CASE(
"fr_pair_debug() writes one pair");
1535 TEST_CASE(
"fr_pair_list_debug() writes the whole list");
static int const char char buffer[256]
#define TEST_CHECK_(cond,...)
#define TEST_ASSERT(cond)
Common initialisation for acutest binaries.
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
bool fr_dict_attr_can_contain(fr_dict_attr_t const *parent, fr_dict_attr_t const *child)
See if a structural da is allowed to contain another da.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_slen_t fr_dict_by_protocol_substr(fr_dict_attr_err_t *err, fr_dict_t const **out, fr_sbuff_t *name, fr_dict_t const *dict_def)
Look up a protocol name embedded in another string.
fr_dict_attr_t const * fr_dict_attr_test_tlv_string
fr_dict_attr_t const * fr_dict_attr_test_nested_leaf_string
fr_dict_attr_t const * fr_dict_attr_test_enum
fr_dict_attr_t const * fr_dict_attr_test_date
fr_dict_attr_t const * fr_dict_attr_test_tlv
fr_dict_attr_t const * fr_dict_attr_test_nested_top_tlv
fr_dict_attr_t const * fr_dict_attr_test_uint32
fr_dict_attr_t const * fr_dict_attr_test_octets
fr_dict_attr_t const * fr_dict_attr_test_string
fr_dict_attr_t const * fr_dict_attr_test_ipv4_addr
fr_dict_attr_t const * fr_dict_attr_test_nested_child_tlv
int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs)
Initialise a test dictionary and add our test_defs to it.
fr_dict_attr_t const * fr_dict_attr_test_uint8
fr_dict_attr_t const * fr_dict_attr_test_group
fr_dict_attr_t const * fr_dict_attr_test_nested_leaf_int32
fr_dict_attr_t const * fr_dict_attr_test_vsa
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
int fr_pair_value_memdup_buffer(fr_pair_t *vp, uint8_t const *src, bool tainted)
Copy data from a talloced buffer into an "octets" data type.
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
int fr_pair_value_enum_box(fr_value_box_t const **out, fr_pair_t *vp)
Get value box of a VP, optionally prefer enum value.
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
int fr_pair_delete_by_da_nested(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list, and prune any empty branches.
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
fr_cmp_ret_t fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b)
Determine equality of two lists.
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
int fr_pair_value_bstrdup_buffer_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a string to a "string" type value pair.
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
fr_pair_t * fr_pair_find_by_child_num_idx(fr_pair_list_t const *list, fr_dict_attr_t const *parent, unsigned int attr, unsigned int idx)
Find the pair with the matching child attribute at a given index.
int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b)
Compare two pairs, using the operator from "a".
int fr_pair_value_bstrndup_shallow(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Assign a string to a "string" type value pair.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
fr_cmp_ret_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da.
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
int fr_pair_update_by_da_parent(fr_pair_t *parent, fr_pair_t **out, fr_dict_attr_t const *da)
Return the first fr_pair_t matching the fr_dict_attr_t or alloc a new fr_pair_t and its subtree (and ...
int fr_pair_list_copy_by_ancestor(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *parent_da)
Duplicate pairs in a list where the da is a descendant of parent_da.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
int fr_pair_value_mem_realloc(fr_pair_t *vp, uint8_t **out, size_t size)
Change the length of a buffer for a "octets" type value pair.
char const * fr_pair_value_enum(fr_pair_t const *vp, char buff[20])
Return a const buffer for an enum type attribute.
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
int fr_pair_value_bstr_alloc(fr_pair_t *vp, char **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "string" type value pair.
int fr_pair_value_bstr_realloc(fr_pair_t *vp, char **out, size_t size)
Change the length of a buffer for a "string" type value pair.
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t, adding the parent attributes if required.
int fr_pair_delete_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const *parent, unsigned int attr)
Delete matching pairs from the specified list.
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp)
Steal one VP.
int fr_pair_value_memdup_shallow(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Assign a buffer to a "octets" type value pair.
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "octets" type value pair.
int fr_pair_value_strtrim(fr_pair_t *vp)
Trim the length of the string buffer to match the length of the C string.
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the start of the list.
fr_value_box_t * fr_pair_dcursor_value_init(fr_dcursor_t *cursor)
Initialises a special dcursor over a fr_pair_list_t, but which returns fr_value_box_t.
int fr_pair_list_copy_by_da(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_dict_attr_t const *da)
Duplicate pairs in a list matching the specified da.
int fr_pair_raw_afrom_pair(fr_pair_t *vp, uint8_t const *data, size_t data_len)
Mark malformed attribute as raw.
int fr_pair_value_memdup_buffer_shallow(fr_pair_t *vp, uint8_t const *src, bool tainted)
Assign a talloced buffer to a "octets" type value pair.
int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a vp, but don't copy it.
int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and prepend)
fr_pair_t * fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int attr)
Create a new valuepair.
static void test_fr_pair_value_memdup_shallow(void)
static void test_fr_pair_print_secure(void)
static void test_fr_pair_list_copy_by_ancestor(void)
static void test_fr_dict_by_protocol_substr_no_overflow(void)
static void test_fr_pair_afrom_child_num(void)
static void test_fr_pair_value_aprintf(void)
static void test_fr_pair_value_mem_realloc(void)
static void test_fr_pair_value_memdup_buffer(void)
static void test_fr_pair_value_enum_box(void)
static void test_fr_pair_value_bstrdup_buffer(void)
static void test_fr_pair_value_copy(void)
static void test_fr_pair_delete(void)
static void test_fr_pair_list_cmp(void)
static void test_fr_pair_print(void)
static void test_fr_pair_copy(void)
static void test_fr_pair_afrom_da(void)
static void test_fr_pair_value_mem_alloc(void)
static void test_fr_pair_value_bstrndup(void)
static void test_fr_pair_find_by_child_num_idx(void)
static void test_fr_pair_value_bstrndup_shallow(void)
static void test_fr_pair_value_bstrdup_buffer_shallow(void)
static void test_fr_pair_print_secure_children(void)
fr_pair_print_secure() walks the children of a structural pair
static void test_fr_pair_list_copy(void)
static void test_fr_pair_value_memdup_buffer_shallow(void)
static void test_fr_pair_value_bstr_realloc(void)
static void test_fr_pair_dcursor_by_da_init(void)
static void test_fr_pair_print_name(void)
static void test_fr_pair_delete_by_da(void)
static void test_fr_pair_append(void)
static void test_fr_pair_value_strdup_shallow(void)
static void test_fr_pair_find_by_da_idx(void)
static void test_fr_pair_nested_verify(void)
static void test_fr_pair_print_value_quoted(void)
#define TEST_PRINT_PAIR(_func, _parent, _vp, _expected)
Print one pair into a buffer, and compare it against what we expect.
static void test_fr_pair_value_strtrim(void)
static void test_fr_pair_value_enum(void)
static void test_fr_pair_value_bstr_alloc(void)
static void test_fr_pair_list_sort(void)
static void test_fr_pair_value_strdup(void)
static void test_fr_pair_cmp(void)
static void test_fr_pair_list_print(void)
static void test_fr_pair_prepend_by_da(void)
static void test_fr_pair_afrom_da_nested(void)
static void test_fr_pair_list_copy_by_da(void)
static void test_fr_pair_value_from_str(void)
static void test_fr_pair_append_by_da_parent(void)
static void test_fr_pair_steal(void)
static void test_fr_pair_delete_by_child_num(void)
static void test_fr_pair_dcursor_by_ancestor_init(void)
static void test_fr_pair_delete_by_da_nested(void)
static void test_init(void)
Global initialisation.
static void test_fr_pair_raw_afrom_pair(void)
static void test_fr_pair_update_by_da_parent(void)
static void test_fr_pair_find_by_da_nested(void)
static void test_fr_pair_dcursor_value_init(void)
static void test_fr_pair_value_memdup(void)
int dict_protocol_add(fr_dict_t *dict)
Add a protocol to the global protocol table.
static void test_fr_pair_debug(void)
fr_pair_debug() and fr_pair_list_debug() write to a FILE, not to an sbuff
static fr_pair_list_t test_pairs
static fr_dict_t * test_dict
Helper functions for pair tests.
static int fr_pair_test_list_alloc_nested(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static uint8_t test_octets[]
static int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static size_t test_string_len
static char const * test_string
#define local_pairs
Convenience macro for accessing the state list.
#define fr_sbuff_init_in(_out, _start, _len_or_end)
#define FR_SBUFF_OUT(_start, _len_or_end)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
fr_pair_value_bstrdup_buffer(vp, eap_session->identity, true)
size_t strlcpy(char *dst, char const *src, size_t siz)
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
#define talloc_strdup(_ctx, _str)
static int64_t fr_time_unwrap(fr_time_t time)
ssize_t fr_pair_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const *vp))
Print one attribute and value to a string.
void fr_pair_debug(FILE *fp, fr_pair_t const *pair)
Dumps a pair to the default logging destination - Useful for calling from debuggers.
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list)
Dumps a list to the default logging destination - Useful for calling from debuggers.
int fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
static fr_slen_t quote ssize_t fr_pair_print_name(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const **vp_p)
Print an attribute name.
ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_token_t quote)
Print the value of an attribute to a string.
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes descended from the specified fr_dict_attr_t.
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
ssize_t fr_pair_print_secure(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_t const *vp))
Print one attribute and value to a string with escape rules.
ssize_t fr_pair_list_print(fr_sbuff_t *out, fr_dict_attr_t const *parent, fr_pair_list_t const *list)
Print a pair list.
char const * fr_strerror(void)
Get the last library error.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER
void fr_value_box_set_secret(fr_value_box_t *box, bool secret)
Mark a box as holding a secret, or not.
fr_sbuff_unescape_rules_t const fr_value_unescape_double
static size_t char ** out