26 RCSIDH(pair_h,
"$Id: 24c64235b1a55c1b35ed06a94f417d242b18f2a0 $")
28 #include <freeradius-devel/libradius.h>
34 #ifdef WITH_VERIFY_PTR
35 # define VERIFY_VP(_x) fr_pair_verify(__FILE__, __LINE__, _x)
36 # define VERIFY_LIST(_x) fr_pair_list_verify(__FILE__, __LINE__, NULL, _x)
37 # define VERIFY_PACKET(_x) (void) talloc_get_type_abort(_x, RADIUS_PACKET)
44 # define VERIFY_VP(_x) fr_assert(_x)
45 # define VERIFY_LIST(_x) fr_assert(_x)
46 # define VERIFY_PACKET(_x) fr_assert(_x)
60 uint8_t
const *octets;
62 struct in_addr ipaddr;
64 size_t filter[32/
sizeof(size_t)];
68 struct in6_addr ipv6addr;
69 uint8_t ipv6prefix[18];
80 uint8_t ipv4prefix[6];
165 #define vp_strvalue data.strvalue
166 #define vp_integer data.integer
167 #define vp_ipaddr data.ipaddr.s_addr
168 #define vp_date data.date
169 #define vp_filter data.filter
170 #define vp_octets data.octets
171 #define vp_ifid data.ifid
172 #define vp_ipv6addr data.ipv6addr
173 #define vp_ipv6prefix data.ipv6prefix
174 #define vp_byte data.byte
175 #define vp_short data.ushort
176 #define vp_ether data.ether
177 #define vp_signed data.sinteger
178 #define vp_integer64 data.integer64
179 #define vp_ipv4prefix data.ipv4prefix
180 #define vp_decimal data.decimal
182 #define vp_length data.length
184 # define debug_pair(vp) do { if (fr_debug_lvl && fr_log_fp) { \
185 fr_pair_fprint(fr_log_fp, vp); \
189 #define TAG_VALID(x) ((x) > 0 && (x) < 0x20)
190 #define TAG_VALID_ZERO(x) ((x) < 0x20)
191 #define TAG_ANY INT8_MIN
198 #define TAG_EQ(_x, _y) ((_x == _y) || (_x == TAG_ANY) || ((_x == TAG_NONE) && (_y == TAG_ANY)))
199 #define ATTRIBUTE_EQ(_x, _y) ((_x && _y) && (_x->da == _y->da) && (!_x->da->flags.has_tag || TAG_EQ(_x->tag, _y->tag)))
201 #define NUM_ANY INT_MIN
202 #define NUM_ALL (INT_MIN + 1)
203 #define NUM_COUNT (INT_MIN + 2)
204 #define NUM_LAST (INT_MIN + 3)
222 unsigned int vendor,
unsigned int attr, int8_t tag,
PW_TYPE type,
227 typedef int8_t (*
fr_cmp_t)(
void const *a,
void const *b);
236 #define fr_pair_cmp_op(_op, _a, _b) value_data_cmp_op(_op, _a->da->type, &_a->data, _b->da->type, &_b->data)
252 unsigned int vendor,
unsigned int attr, int8_t tag);
255 unsigned int vendor,
unsigned int attr, int8_t tag);
257 unsigned int vendor,
unsigned int attr, int8_t tag);
void fr_pair_list_free(VALUE_PAIR **)
Free memory used by a valuepair list.
int8_t(* fr_cmp_t)(void const *a, void const *b)
bool fr_pair_validate_relaxed(VALUE_PAIR const *failed[2], VALUE_PAIR *filter, VALUE_PAIR *list)
Uses fr_pair_cmp to verify all VALUE_PAIRs in list match the filter defined by check.
VALUE_PAIR has a single value.
void fr_pair_list_fprint(FILE *, VALUE_PAIR const *vp)
Print a list of attributes and enumv.
VALUE_PAIR * fr_pair_afrom_num(TALLOC_CTX *ctx, unsigned int vendor, unsigned int attr)
Create a new valuepair.
void fr_pair_list_mcopy_by_num(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from, unsigned int vendor, unsigned int attr, int8_t tag)
Copy / delete matching pairs between VALUE_PAIR lists.
char * fr_pair_asprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp, char quote)
Print one attribute and value to a string.
void fr_pair_validate_debug(TALLOC_CTX *ctx, VALUE_PAIR const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
int8_t tag
Tag value used to group valuepairs.
void size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, char quote)
Print the value of an attribute to a string.
void fr_pair_steal(TALLOC_CTX *ctx, VALUE_PAIR *vp)
Steal one VP.
struct vp_cursor vp_cursor_t
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
valuepair value must be xlat expanded when it's added to VALUE_PAIR tree.
VALUE_PAIR * fr_pair_list_copy_by_num(TALLOC_CTX *ctx, VALUE_PAIR *from, unsigned int vendor, unsigned int attr, int8_t tag)
Copy matching pairs.
void fr_pair_fprint(FILE *, VALUE_PAIR const *vp)
Print one attribute and value to FP.
void fr_pair_list_move_by_num(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from, unsigned int vendor, unsigned int attr, int8_t tag)
Move matching pairs between VALUE_PAIR lists.
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
char * fr_pair_value_asprint(TALLOC_CTX *ctx, VALUE_PAIR const *vp, char quote)
Print one attribute value to a string.
int fr_pair_update_by_num(TALLOC_CTX *ctx, VALUE_PAIR **list, unsigned int vendor, unsigned int attr, int8_t tag, PW_TYPE type, value_data_t *value)
Create a new VALUE_PAIR or replace the value of the head pair in the specified list.
void fr_pair_value_strsteal(VALUE_PAIR *vp, char const *src)
Reparent an allocated char buffer to a VALUE_PAIR.
VALUE_PAIR * fr_pair_list_copy(TALLOC_CTX *ctx, VALUE_PAIR *from)
Copy a pairlist.
enum value_type value_type_t
The type of value a VALUE_PAIR contains.
char r_opand[1024]
Right hand side of the pair.
void fr_pair_value_strcpy(VALUE_PAIR *vp, char const *src)
Copy data into an "string" data type.
int fr_pair_mark_xlat(VALUE_PAIR *vp, char const *value)
Mark a valuepair for xlat expansion.
void fr_pair_add(VALUE_PAIR **head, VALUE_PAIR *vp)
Add a VP to the end of the list.
struct value_pair VALUE_PAIR
Stores an attribute, a value and various bits of other data.
A VALUE_PAIR in string format.
char * fr_pair_type_snprint(TALLOC_CTX *ctx, PW_TYPE type)
value_data_t * next
Next in a series of value_data.
Stores an attribute, a value and various bits of other data.
VALUE_PAIR * found
pairfind marker.
int8_t fr_pair_cmp_by_da_tag(void const *a, void const *b)
value_type
The type of value a VALUE_PAIR contains.
bool fr_pair_validate(VALUE_PAIR const *failed[2], VALUE_PAIR *filter, VALUE_PAIR *list)
Uses fr_pair_cmp to verify all VALUE_PAIRs in list match the filter defined by check.
FR_TOKEN op
Operator to use when moving or inserting valuepair into a list.
int fr_pair_value_from_str(VALUE_PAIR *vp, char const *value, size_t len)
Convert string value to native attribute value.
void fr_pair_delete_by_num(VALUE_PAIR **head, unsigned int vendor, unsigned int attr, int8_t tag)
Delete matching pairs.
VALUE_PAIR * fr_pair_find_by_da(VALUE_PAIR *head, fr_dict_attr_t const *da, int8_t tag)
Find the pair with the matching DAs.
size_t fr_pair_value_snprint_json(char *out, size_t outlen, VALUE_PAIR const *vp)
void fr_pair_list_move(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from)
Move pairs from source list to destination list respecting operator.
size_t length
Length of value data.
FR_TOKEN fr_pair_raw_from_str(char const **ptr, VALUE_PAIR_RAW *raw)
Read a single valuepair from a buffer, and advance the pointer.
void fr_pair_value_memsteal(VALUE_PAIR *vp, uint8_t const *src)
Reparent an allocated octet buffer to a VALUE_PAIR.
void fr_pair_list_sort(VALUE_PAIR **vps, fr_cmp_t cmp)
Sort a linked list of VALUE_PAIRs using merge sort.
value_type_t type
Type of pointer in value union.
VALUE_PAIR * current
The current attribute.
int fr_pair_to_unknown(VALUE_PAIR *vp)
Mark malformed or unrecognised attributed as unknown.
int fr_pair_list_afrom_file(TALLOC_CTX *ctx, VALUE_PAIR **out, FILE *fp, bool *pfiledone)
VALUE_PAIR * next
Next attribute to process.
VALUE_PAIR has multiple values.
PRIVATE void decimal(struct DATA *p, double d)
void fr_pair_value_strnsteal(VALUE_PAIR *vp, char *src, size_t len)
Reparent an allocated char buffer to a VALUE_PAIR reallocating the buffer to the correct size...
VALUE_PAIR * last
Temporary only used for fr_cursor_insert.
VALUE_PAIR * fr_pair_copy(TALLOC_CTX *ctx, VALUE_PAIR const *vp)
Copy a single valuepair.
size_t fr_pair_snprint(char *out, size_t outlen, VALUE_PAIR const *vp)
Print one attribute and value to a string.
int fr_pair_cmp(VALUE_PAIR *a, VALUE_PAIR *b)
Compare two pairs, using the operator from "a".
VALUE_PAIR * fr_pair_find_by_num(VALUE_PAIR *head, unsigned int vendor, unsigned int attr, int8_t tag)
Find the pair with the matching attribute.
VALUE_PAIR * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute.
fr_dict_attr_t const * da
Dictionary attribute defines the attribute.
void fr_pair_value_bstrncpy(VALUE_PAIR *vp, void const *src, size_t len)
Copy data into an "string" data type.
char l_opand[256]
Left hand side of the pair.
void fr_pair_replace(VALUE_PAIR **head, VALUE_PAIR *add)
Replace all matching VPs.
FR_TOKEN fr_pair_list_afrom_str(TALLOC_CTX *ctx, char const *buffer, VALUE_PAIR **head)
Read one line of attribute/value pairs into a list.
FR_TOKEN quote
Type of quoting around the r_opand.
void fr_pair_value_snprintf(VALUE_PAIR *vp, char const *fmt,...) CC_HINT(format(printf
VALUE_PAIR * fr_pair_make(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op)
Create a VALUE_PAIR from ASCII strings.
void fr_pair_value_memcpy(VALUE_PAIR *vp, uint8_t const *src, size_t len)
Copy data into an "octets" data type.
PW_TYPE
Internal data types used within libfreeradius.
int fr_pair_list_cmp(VALUE_PAIR *a, VALUE_PAIR *b)
Determine equality of two lists.
struct value_pair_raw VALUE_PAIR_RAW
A VALUE_PAIR in string format.