Navigation Menu

Skip to content

Commit

Permalink
Allow value aliases (enumerations) to work with any attribute type, n…
Browse files Browse the repository at this point in the history
…ot just integers
  • Loading branch information
arr2036 committed May 15, 2017
1 parent 17eb690 commit 619ffaa
Show file tree
Hide file tree
Showing 41 changed files with 537 additions and 513 deletions.
32 changes: 19 additions & 13 deletions src/include/dict.h
Expand Up @@ -26,6 +26,14 @@
#include <freeradius-devel/token.h>
#include <freeradius-devel/types.h>

/*
* Avoid circular type references.
*/
typedef struct dict_attr fr_dict_attr_t;
typedef struct fr_dict fr_dict_t;

#include <freeradius-devel/value.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -72,17 +80,14 @@ typedef struct attr_flags {

extern const FR_NAME_NUMBER dict_attr_types[];
extern const size_t dict_attr_sizes[FR_TYPE_MAX + 1][2];

typedef struct dict_attr fr_dict_attr_t;
typedef struct fr_dict fr_dict_t;
extern fr_dict_t *fr_dict_internal;

/** Dictionary attribute
*/
struct dict_attr {
unsigned int vendor; //!< Vendor that defines this attribute.
unsigned int attr; //!< Attribute number.
fr_type_t type; //!< Value type.
fr_type_t type; //!< Value type.

fr_dict_attr_t const *parent; //!< Immediate parent of this attribute.
fr_dict_attr_t const **children; //!< Children of this attribute.
Expand All @@ -100,8 +105,8 @@ struct dict_attr {
*/
typedef struct dict_enum {
fr_dict_attr_t const *da; //!< Dictionary attribute enum is associated with.
int64_t value; //!< Enum value
char name[1]; //!< Enum name.
char const *alias; //!< Enum name.
fr_value_box_t const *value; //!< Enum value (what name maps to).
} fr_dict_enum_t;

/** Private enterprise
Expand Down Expand Up @@ -151,7 +156,6 @@ typedef struct dict_vendor {
*/
extern bool const fr_dict_attr_allowed_chars[UINT8_MAX];
extern bool const fr_dict_non_data_types[FR_TYPE_MAX + 1];
extern bool const fr_dict_enum_types[FR_TYPE_MAX + 1];

/*
* Dictionary debug
Expand All @@ -166,12 +170,13 @@ int fr_dict_vendor_add(fr_dict_t *dict, char const *name, unsigned int value);
int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int attr,
fr_type_t type, fr_dict_attr_flags_t flags);

int fr_dict_enum_add(fr_dict_t *dict, char const *attr, char const *alias, int value);
int fr_dict_enum_add_alias(fr_dict_attr_t const *da, char const *alias,
fr_value_box_t const *value, bool coerce, bool replace);

int fr_dict_str_to_argv(char *str, char **argv, int max_argc);

int fr_dict_from_file(TALLOC_CTX *ctx, fr_dict_t **out,
char const *dir, char const *fn, char const *name);
char const *dir, char const *fn, char const *name);

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

Expand All @@ -183,7 +188,6 @@ fr_dict_attr_t const *fr_dict_root(fr_dict_t const *dict);
/*
* Unknown ephemeral attributes
*/

fr_dict_attr_t *fr_dict_unknown_acopy(TALLOC_CTX *ctx, fr_dict_attr_t const *da);

fr_dict_attr_t const *fr_dict_unknown_add(fr_dict_t *dict, fr_dict_attr_t const *old);
Expand Down Expand Up @@ -245,11 +249,13 @@ fr_dict_attr_t const *fr_dict_attr_child_by_da(fr_dict_attr_t const *parent, fr_

fr_dict_attr_t const *fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr);

fr_dict_enum_t *fr_dict_enum_by_da(fr_dict_t *dict, fr_dict_attr_t const *da, int64_t value);
fr_dict_enum_t *fr_dict_enum_by_da(fr_dict_t *dict, fr_dict_attr_t const *da,
fr_value_box_t const *value);

char const *fr_dict_enum_name_by_da(fr_dict_t *dict, fr_dict_attr_t const *da, int64_t value);
char const *fr_dict_enum_alias_by_da(fr_dict_t *dict, fr_dict_attr_t const *da,
fr_value_box_t const *value);

fr_dict_enum_t *fr_dict_enum_by_name(fr_dict_t *dict, fr_dict_attr_t const *da, char const *val);
fr_dict_enum_t *fr_dict_enum_by_alias(fr_dict_t *dict, fr_dict_attr_t const *da, char const *val);

/*
* Validation
Expand Down
2 changes: 1 addition & 1 deletion src/include/token.h
Expand Up @@ -67,7 +67,7 @@ typedef enum fr_token {

typedef struct FR_NAME_NUMBER {
char const *name;
int number;
int32_t number;
} FR_NAME_NUMBER;

extern const FR_NAME_NUMBER fr_tokens_table[];
Expand Down
49 changes: 26 additions & 23 deletions src/include/value.h
Expand Up @@ -17,6 +17,12 @@
#define _FR_VALUE_H
#include <freeradius-devel/inet.h>
#include <freeradius-devel/types.h>

/*
* Avoid circular type references.
*/
typedef struct value_box fr_value_box_t;

#include <freeradius-devel/dict.h>

extern size_t const fr_value_box_field_sizes[];
Expand All @@ -31,7 +37,6 @@ extern size_t const fr_value_box_offsets[];
*
* fr_type_t should be an enumeration of the values in this union.
*/
typedef struct value_box fr_value_box_t;
struct value_box {
union {
/*
Expand All @@ -45,49 +50,47 @@ struct value_box {
uint8_t filter[32]; //!< Ascend binary format (a packed data structure).

};
size_t length;
size_t length;
};

/*
* Fixed length values
*/
fr_ipaddr_t ip; //!< IPv4/6 address/prefix.

uint8_t ifid[8]; //!< IPv6 interface ID (should be struct?).
uint8_t ether[6]; //!< Ethernet (MAC) address.

bool boolean; //!< A truth value.

struct {
union {
uint8_t uint8; //!< 8bit unsigned integer.
uint16_t uint16; //!< 16bit unsigned integer.
uint32_t uint32; //!< 32bit unsigned integer.
uint64_t uint64; //!< 64bit unsigned integer.
uint128_t uint128; //!< 128bit unsigned integer.

int8_t int8; //!< 8bit signed integer.
int16_t int16; //!< 16bit signed integer.
int32_t int32; //!< 32bit signed integer.
int64_t int64; //!< 64bit signed integer;
};
fr_dict_attr_t const *enumv; //!< Enumeration values for integer type.
};
uint8_t uint8; //!< 8bit unsigned integer.
uint16_t uint16; //!< 16bit unsigned integer.
uint32_t uint32; //!< 32bit unsigned integer.
uint64_t uint64; //!< 64bit unsigned integer.
uint128_t uint128; //!< 128bit unsigned integer.

int8_t int8; //!< 8bit signed integer.
int16_t int16; //!< 16bit signed integer.
int32_t int32; //!< 32bit signed integer.
int64_t int64; //!< 64bit signed integer;

float float32; //!< Single precision float.
double float64; //!< Double precision float.

uint32_t date; //!< Date (32bit Unix timestamp).
uint64_t date_miliseconds; //!< milliseconds since the epoch.
uint64_t date_microseconds; //!< microseconds since the epoch.
uint64_t date_nanoseconds; //!< nanoseconds since the epoch.
uint64_t date_miliseconds; //!< Milliseconds since the epoch.
uint64_t date_microseconds; //!< Microseconds since the epoch.
uint64_t date_nanoseconds; //!< Nanoseconds since the epoch.

/*
* System specific - Used for runtime
* configuration only.
* System specific - Used for runtime configuration only.
*/
size_t size; //!< System specific file/memory size.
struct timeval timeval; //!< A time value with usec precision.

} datum;

fr_dict_attr_t const *enumv; //!< Enumeration values.

fr_type_t type; //!< Type of this value-box.

bool tainted; //!< i.e. did it come from an untrusted source
Expand Down

0 comments on commit 619ffaa

Please sign in to comment.