#include <sys/stat.h>
-#define MAX_ARGV (16)
+/** Maximum number of arguments
+ *
+ * For any one keyword, this is the maxiumum number of arguments that can be passed.
+ */
+#define DICT_MAX_ARGV (8)
+
+/** Maximum stack size
+ *
+ * This is the maximum number of nested BEGIN and $INCLUDE statements.
+ */
+#define DICT_MAX_STACK (32)
+/** This represents explicit BEGIN/END frames pushed onto the stack
+ */
typedef enum {
NEST_NONE = 0,
NEST_ROOT,
*
* Allows vendor and TLV context to persist across $INCLUDEs
*/
-#define MAX_STACK (32)
typedef struct {
fr_dict_t *dict; //!< The dictionary before the current BEGIN-PROTOCOL block.
char *filename; //!< name of the file we're reading
typedef struct {
fr_dict_t *dict; //!< Protocol dictionary we're inserting attributes into.
- dict_tokenize_frame_t stack[MAX_STACK]; //!< stack of attributes to track
+ dict_tokenize_frame_t stack[DICT_MAX_STACK]; //!< stack of attributes to track
int stack_depth; //!< points to the last used stack frame
- fr_dict_attr_t *value_attr; //!< Cache of last attribute to speed up
- ///< value processing.
- fr_dict_attr_t const *relative_attr; //!< for ".82" instead of "1.2.3.82".
- ///< only for parents of type "tlv"
+ fr_dict_attr_t *value_attr; //!< Cache of last attribute to speed up value processing.
+ fr_dict_attr_t const *relative_attr; //!< for ".82" instead of "1.2.3.82". only for parents of type "tlv"
dict_fixup_ctx_t fixup;
} dict_tokenize_ctx_t;
-
-static int _dict_from_file(dict_tokenize_ctx_t *ctx,
+static int _dict_from_file(dict_tokenize_ctx_t *dctx,
char const *dir_name, char const *filename,
char const *src_file, int src_line);
return 0;
}
-static int dict_process_type_field(dict_tokenize_ctx_t *ctx, char const *name, fr_dict_attr_t **da_p)
+static int dict_process_type_field(dict_tokenize_ctx_t *dctx, char const *name, fr_dict_attr_t **da_p)
{
char *p;
fr_type_t type;
type = FR_TYPE_STRUCT;
} else if (strcmp(name, "bit") == 0) {
- if (ctx->stack[ctx->stack_depth].da->type != FR_TYPE_STRUCT) {
+ if (dctx->stack[dctx->stack_depth].da->type != FR_TYPE_STRUCT) {
fr_strerror_const("Bit fields can only be used inside of a STRUCT");
return -1;
}
static TABLE_TYPE_NAME_FUNC_RPTR(table_sorted_value_by_str, fr_dict_flag_parser_t const *,
fr_dict_attr_flag_to_parser, fr_dict_flag_parser_rule_t const *, fr_dict_flag_parser_rule_t const *)
-static int CC_HINT(nonnull) dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_dict_attr_t **da_p)
+static int CC_HINT(nonnull) dict_process_flag_field(dict_tokenize_ctx_t *dctx, char *name, fr_dict_attr_t **da_p)
{
static fr_dict_flag_parser_t dict_common_flags[] = {
{ L("array"), { .func = dict_flag_array } },
* Search the protocol table, then the main table.
* This allows protocols to overload common flags.
*/
- if (!((ctx->dict->proto->attr.flags.table &&
- fr_dict_attr_flag_to_parser(&parser, ctx->dict->proto->attr.flags.table,
- ctx->dict->proto->attr.flags.table_len, key, NULL)) ||
+ if (!((dctx->dict->proto->attr.flags.table &&
+ fr_dict_attr_flag_to_parser(&parser, dctx->dict->proto->attr.flags.table,
+ dctx->dict->proto->attr.flags.table_len, key, NULL)) ||
fr_dict_attr_flag_to_parser(&parser, dict_common_flags, dict_common_flags_len, key, NULL))) {
fr_strerror_printf("Unknown flag '%s'", key);
return -1;
return 0;
}
-static dict_tokenize_frame_t const *dict_gctx_find_frame(dict_tokenize_ctx_t *ctx, dict_nest_t nest)
+static dict_tokenize_frame_t const *dict_dctx_find_frame(dict_tokenize_ctx_t *dctx, dict_nest_t nest)
{
int i;
- for (i = ctx->stack_depth; i > 0; i--) {
- if (ctx->stack[i].nest == nest) return &ctx->stack[i];
+ for (i = dctx->stack_depth; i > 0; i--) {
+ if (dctx->stack[i].nest == nest) return &dctx->stack[i];
}
return NULL;
}
-static int dict_gctx_push(dict_tokenize_ctx_t *ctx, fr_dict_attr_t const *da)
+static int dict_dctx_push(dict_tokenize_ctx_t *dctx, fr_dict_attr_t const *da)
{
- if ((ctx->stack_depth + 1) >= MAX_STACK) {
+ if ((dctx->stack_depth + 1) >= DICT_MAX_STACK) {
fr_strerror_const_push("Attribute definitions are nested too deep.");
return -1;
}
fr_assert(da != NULL);
- ctx->stack_depth++;
- memset(&ctx->stack[ctx->stack_depth], 0, sizeof(ctx->stack[ctx->stack_depth]));
+ dctx->stack_depth++;
+ memset(&dctx->stack[dctx->stack_depth], 0, sizeof(dctx->stack[dctx->stack_depth]));
- ctx->stack[ctx->stack_depth].dict = ctx->stack[ctx->stack_depth - 1].dict;
- ctx->stack[ctx->stack_depth].da = da;
- ctx->stack[ctx->stack_depth].filename = ctx->stack[ctx->stack_depth - 1].filename;
- ctx->stack[ctx->stack_depth].line = ctx->stack[ctx->stack_depth - 1].line;
+ dctx->stack[dctx->stack_depth].dict = dctx->stack[dctx->stack_depth - 1].dict;
+ dctx->stack[dctx->stack_depth].da = da;
+ dctx->stack[dctx->stack_depth].filename = dctx->stack[dctx->stack_depth - 1].filename;
+ dctx->stack[dctx->stack_depth].line = dctx->stack[dctx->stack_depth - 1].line;
return 0;
}
return ctx->stack[ctx->stack_depth].da;
}
-static int dict_finalise(dict_tokenize_ctx_t *ctx)
+static int dict_finalise(dict_tokenize_ctx_t *dctx)
{
- if (dict_fixup_apply(&ctx->fixup) < 0) return -1;
+ if (dict_fixup_apply(&dctx->fixup) < 0) return -1;
- ctx->value_attr = NULL;
- ctx->relative_attr = NULL;
+ dctx->value_attr = NULL;
+ dctx->relative_attr = NULL;
return 0;
}
return 0;
}
-static int dict_set_value_attr(dict_tokenize_ctx_t *ctx, fr_dict_attr_t *da)
+static int dict_set_value_attr(dict_tokenize_ctx_t *dctx, fr_dict_attr_t *da)
{
/*
* Adding an attribute of type 'struct' is an implicit
* BEGIN-STRUCT.
*/
if (da->type == FR_TYPE_STRUCT) {
- if (dict_gctx_push(ctx, da) < 0) return -1;
- ctx->value_attr = NULL;
+ if (dict_dctx_push(dctx, da) < 0) return -1;
+ dctx->value_attr = NULL;
} else if (fr_type_is_leaf(da->type)) {
- memcpy(&ctx->value_attr, &da, sizeof(da));
+ memcpy(&dctx->value_attr, &da, sizeof(da));
} else {
- ctx->value_attr = NULL;
+ dctx->value_attr = NULL;
}
return 0;
}
-static int dict_read_process_common(dict_tokenize_ctx_t *ctx, fr_dict_attr_t **da_p,
+static int dict_read_process_common(dict_tokenize_ctx_t *dctx, fr_dict_attr_t **da_p,
char const *name,
char const *type_name, char *flag_name,
fr_dict_attr_flags_t const *base_flags)
* Allocate the attribute here, and then fill in the fields
* as we start parsing the various elements of the definition.
*/
- da = dict_attr_alloc_null(ctx->dict->pool, ctx->dict->proto);
+ da = dict_attr_alloc_null(dctx->dict->pool, dctx->dict->proto);
if (unlikely(da == NULL)) return -1;
- dict_attr_location_set(ctx, da);
+ dict_attr_location_set(dctx, da);
/*
* Set the attribute flags from the base flags.
/*
* Set the base type of the attribute.
*/
- if (dict_process_type_field(ctx, type_name, &da) < 0) {
+ if (dict_process_type_field(dctx, type_name, &da) < 0) {
error:
talloc_free(da);
return -1;
* Where flags contain variable length fields, this is
* significantly easier than populating a temporary struct.
*/
- if (flag_name) if (dict_process_flag_field(ctx, flag_name, &da) < 0) goto error;
+ if (flag_name) if (dict_process_flag_field(dctx, flag_name, &da) < 0) goto error;
*da_p = da;
return 0;
/*
* Process the ATTRIBUTE command
*/
-static int dict_read_process_attribute(dict_tokenize_ctx_t *ctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
+static int dict_read_process_attribute(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
{
bool set_relative_attr;
return -1;
}
- if (dict_read_process_common(ctx, &da, argv[0], argv[2],
+ if (dict_read_process_common(dctx, &da, argv[0], argv[2],
(argc > 3) ? argv[3] : NULL, base_flags) < 0) {
return -1;
}
* unwind the stack to match.
*/
if (argv[1][0] != '.') {
- parent = dict_gctx_unwind(ctx);
+ parent = dict_gctx_unwind(dctx);
/*
* Allow '0xff00' as attribute numbers, but only
}
} else {
- slen = fr_dict_attr_by_oid_legacy(ctx->dict, &parent, &attr, argv[1]);
+ slen = fr_dict_attr_by_oid_legacy(dctx->dict, &parent, &attr, argv[1]);
if (slen <= 0) goto error;
}
set_relative_attr = (da->type == FR_TYPE_TLV);
} else {
- if (!ctx->relative_attr) {
+ if (!dctx->relative_attr) {
fr_strerror_const("Unknown parent for partial OID");
goto error;
}
- parent = ctx->relative_attr;
+ parent = dctx->relative_attr;
- slen = fr_dict_attr_by_oid_legacy(ctx->dict, &parent, &attr, argv[1]);
+ slen = fr_dict_attr_by_oid_legacy(dctx->dict, &parent, &attr, argv[1]);
if (slen <= 0) goto error;
set_relative_attr = false;
/*
* Add the attribute we allocated earlier
*/
- switch (dict_attr_add_or_fixup(&ctx->fixup, &da)) {
+ switch (dict_attr_add_or_fixup(&dctx->fixup, &da)) {
default:
goto error;
* define VSAs until we define an attribute of type VSA!
*/
if (da->type == FR_TYPE_VSA) {
- if (parent->flags.is_root) ctx->dict->vsa_parent = attr;
+ if (parent->flags.is_root) dctx->dict->vsa_parent = attr;
- if (dict_fixup_vsa_enqueue(&ctx->fixup, UNCONST(fr_dict_attr_t *, da)) < 0) {
+ if (dict_fixup_vsa_enqueue(&dctx->fixup, UNCONST(fr_dict_attr_t *, da)) < 0) {
return -1; /* Leaves attr added */
}
}
* BEGIN-STRUCT.
*/
if (da->type == FR_TYPE_STRUCT) {
- if (dict_gctx_push(ctx, da) < 0) return -1;
- ctx->value_attr = NULL;
+ if (dict_dctx_push(dctx, da) < 0) return -1;
+ dctx->value_attr = NULL;
} else {
- memcpy(&ctx->value_attr, &da, sizeof(da));
+ memcpy(&dctx->value_attr, &da, sizeof(da));
}
- if (set_relative_attr) ctx->relative_attr = da;
+ if (set_relative_attr) dctx->relative_attr = da;
break;
/* Deferred attribute, don't begin the TLV section automatically */
goto error;
}
- frame = dict_gctx_find_frame(dctx, NEST_PROTOCOL);
+ frame = dict_dctx_find_frame(dctx, NEST_PROTOCOL);
if (frame) {
fr_strerror_printf_push("Nested BEGIN-PROTOCOL is forbidden. Previous definition is at %s[%d]",
frame->filename, frame->line);
dctx->dict = found;
- if (dict_gctx_push(dctx, dctx->dict->root) < 0) goto error;
+ if (dict_dctx_push(dctx, dctx->dict->root) < 0) goto error;
dctx->stack[dctx->stack_depth].nest = NEST_PROTOCOL;
return 0;
goto error;
}
- if (dict_gctx_push(dctx, da) < 0) goto error;
+ if (dict_dctx_push(dctx, da) < 0) goto error;
dctx->stack[dctx->stack_depth].nest = NEST_TLV;
return 0;
goto error;
}
- frame = dict_gctx_find_frame(dctx, NEST_VENDOR);
+ frame = dict_dctx_find_frame(dctx, NEST_VENDOR);
if (frame) {
fr_strerror_printf_push("Nested BEGIN-VENDOR is forbidden. Previous definition is at %s[%d]",
frame->filename, frame->line);
fr_assert(vendor_da->type == FR_TYPE_VENDOR);
}
- if (dict_gctx_push(dctx, vendor_da) < 0) goto error;
+ if (dict_dctx_push(dctx, vendor_da) < 0) goto error;
dctx->stack[dctx->stack_depth].nest = NEST_VENDOR;
return 0;
*
* Which is mostly like ATTRIBUTE, but does not have a number.
*/
-static int dict_read_process_define(dict_tokenize_ctx_t *ctx, char **argv, int argc,
+static int dict_read_process_define(dict_tokenize_ctx_t *dctx, char **argv, int argc,
fr_dict_attr_flags_t *base_flags)
{
fr_dict_attr_t const *parent;
return -1;
}
- if (dict_read_process_common(ctx, &da, argv[0], argv[1],
+ if (dict_read_process_common(dctx, &da, argv[0], argv[1],
(argc > 2) ? argv[2] : NULL, base_flags) < 0) {
return -1;
}
goto error;
}
- parent = dict_gctx_unwind(ctx);
+ parent = dict_gctx_unwind(dctx);
if (!fr_cond_assert(parent)) goto error; /* Should have provided us with a parent */
/*
* Add the attribute we allocated earlier
*/
- switch (dict_attr_add_or_fixup(&ctx->fixup, &da)) {
+ switch (dict_attr_add_or_fixup(&dctx->fixup, &da)) {
default:
goto error;
/* New attribute, fixup stack */
case 0:
- if (dict_set_value_attr(ctx, da) < 0) return -1;
+ if (dict_set_value_attr(dctx, da) < 0) return -1;
if (da->type == FR_TYPE_TLV) {
- ctx->relative_attr = da;
+ dctx->relative_attr = da;
} else {
- ctx->relative_attr = NULL;
+ dctx->relative_attr = NULL;
}
break;
/*
* Process the ENUM command
*/
-static int dict_read_process_enum(dict_tokenize_ctx_t *ctx, char **argv, int argc,
+static int dict_read_process_enum(dict_tokenize_ctx_t *dctx, char **argv, int argc,
fr_dict_attr_flags_t *base_flags)
{
fr_dict_attr_t const *parent;
* Allocate the attribute here, and then fill in the fields
* as we start parsing the various elements of the definition.
*/
- da = dict_attr_alloc_null(ctx->dict->pool, ctx->dict->proto);
+ da = dict_attr_alloc_null(dctx->dict->pool, dctx->dict->proto);
if (unlikely(da == NULL)) return -1;
- dict_attr_location_set(ctx, da);
+ dict_attr_location_set(dctx, da);
/*
* Set the attribute flags from the base flags.
/*
* Set the base type of the attribute.
*/
- if (dict_process_type_field(ctx, argv[1], &da) < 0) {
+ if (dict_process_type_field(dctx, argv[1], &da) < 0) {
error:
talloc_free(da);
return -1;
break;
}
- parent = ctx->stack[ctx->stack_depth].da;
+ parent = dctx->stack[dctx->stack_depth].da;
if (!parent) {
fr_strerror_const("Invalid location for ENUM");
goto error;
/*
* Add the attribute we allocated earlier
*/
- switch (dict_attr_add_or_fixup(&ctx->fixup, &da)) {
+ switch (dict_attr_add_or_fixup(&dctx->fixup, &da)) {
default:
goto error;
case 0:
- memcpy(&ctx->value_attr, &da, sizeof(da));
+ memcpy(&dctx->value_attr, &da, sizeof(da));
break;
case 1:
/*
* Process the MEMBER command
*/
-static int dict_read_process_member(dict_tokenize_ctx_t *ctx, char **argv, int argc,
+static int dict_read_process_member(dict_tokenize_ctx_t *dctx, char **argv, int argc,
fr_dict_attr_flags_t *base_flags)
{
fr_dict_attr_t *da;
return -1;
}
- if (ctx->stack[ctx->stack_depth].da->type != FR_TYPE_STRUCT) {
+ if (dctx->stack[dctx->stack_depth].da->type != FR_TYPE_STRUCT) {
fr_strerror_const("MEMBER can only be used for ATTRIBUTEs of type 'struct'");
return -1;
}
- if (dict_read_process_common(ctx, &da, argv[0], argv[1],
+ if (dict_read_process_common(dctx, &da, argv[0], argv[1],
(argc > 2) ? argv[2] : NULL, base_flags) < 0) {
return -1;
}
/*
* If our parent is a fixed-size struct, then we have to be fixed-size, too.
*/
- da->flags.is_known_width |= ctx->stack[ctx->stack_depth].da->flags.is_known_width;
+ da->flags.is_known_width |= dctx->stack[dctx->stack_depth].da->flags.is_known_width;
/*
* Double check bit field magic
*/
- if (ctx->stack[ctx->stack_depth].member_num > 0) {
+ if (dctx->stack[dctx->stack_depth].member_num > 0) {
fr_dict_attr_t const *previous;
- previous = dict_attr_child_by_num(ctx->stack[ctx->stack_depth].da,
- ctx->stack[ctx->stack_depth].member_num);
+ previous = dict_attr_child_by_num(dctx->stack[dctx->stack_depth].da,
+ dctx->stack[dctx->stack_depth].member_num);
/*
* Check that the previous bit field ended on a
* byte boundary.
* Check if the parent 'struct' is fixed size. And if
* so, complain if we're adding a variable sized member.
*/
- if (ctx->stack[ctx->stack_depth].struct_is_closed) {
+ if (dctx->stack[dctx->stack_depth].struct_is_closed) {
fr_strerror_printf("Cannot add MEMBER to 'struct' %s after a variable sized member %s",
- ctx->stack[ctx->stack_depth].da->name,
- ctx->stack[ctx->stack_depth].struct_is_closed->name);
+ dctx->stack[dctx->stack_depth].da->name,
+ dctx->stack[dctx->stack_depth].struct_is_closed->name);
goto error;
}
/*
* @todo - cache the key field in the stack frame, so we don't have to loop over the children.
*/
- for (i = 1; i <= ctx->stack[ctx->stack_depth].member_num; i++) {
- key = dict_attr_child_by_num(ctx->stack[ctx->stack_depth].da, i);
+ for (i = 1; i <= dctx->stack[dctx->stack_depth].member_num; i++) {
+ key = dict_attr_child_by_num(dctx->stack[dctx->stack_depth].da, i);
if (!key) continue; /* really should be WTF? */
if (fr_dict_attr_is_key_field(key)) {
fr_strerror_printf("'struct' %s has a 'key' field %s, and cannot end with a TLV %s",
- ctx->stack[ctx->stack_depth].da->name, key->name, argv[0]);
+ dctx->stack[dctx->stack_depth].da->name, key->name, argv[0]);
goto error;
}
if (da_is_length_field(key)) {
fr_strerror_printf("'struct' %s has a 'length' field %s, and cannot end with a TLV %s",
- ctx->stack[ctx->stack_depth].da->name, key->name, argv[0]);
+ dctx->stack[dctx->stack_depth].da->name, key->name, argv[0]);
goto error;
}
}
}
- if (unlikely(dict_attr_parent_init(&da, ctx->stack[ctx->stack_depth].da) < 0)) goto error;
- if (unlikely(dict_attr_num_init(da, ++ctx->stack[ctx->stack_depth].member_num) < 0)) goto error;
+ if (unlikely(dict_attr_parent_init(&da, dctx->stack[dctx->stack_depth].da) < 0)) goto error;
+ if (unlikely(dict_attr_num_init(da, ++dctx->stack[dctx->stack_depth].member_num) < 0)) goto error;
if (unlikely(dict_attr_finalise(&da, argv[0]) < 0)) goto error;
/*
goto error;
}
- switch (dict_attr_add_or_fixup(&ctx->fixup, &da)) {
+ switch (dict_attr_add_or_fixup(&dctx->fixup, &da)) {
default:
goto error;
* to them.
*/
if (da->type == FR_TYPE_TLV) {
- ctx->relative_attr = dict_attr_child_by_num(ctx->stack[ctx->stack_depth].da,
- ctx->stack[ctx->stack_depth].member_num);
- if (ctx->relative_attr && (dict_gctx_push(ctx, ctx->relative_attr) < 0)) return -1;
+ dctx->relative_attr = dict_attr_child_by_num(dctx->stack[dctx->stack_depth].da,
+ dctx->stack[dctx->stack_depth].member_num);
+ if (dctx->relative_attr && (dict_dctx_push(dctx, dctx->relative_attr) < 0)) return -1;
return 0;
}
/*
* Add the size of this member to the parent struct.
*/
- if (ctx->stack[ctx->stack_depth].da->flags.length) {
+ if (dctx->stack[dctx->stack_depth].da->flags.length) {
/*
* Fixed-size struct can't have MEMBERs of unknown sizes.
*/
if (!da->flags.is_known_width) {
fr_strerror_printf("'struct' %s has fixed size %u, but member %s is of unknown size",
- ctx->stack[ctx->stack_depth].da->name, ctx->stack[ctx->stack_depth].da->flags.length,
+ dctx->stack[dctx->stack_depth].da->name, dctx->stack[dctx->stack_depth].da->flags.length,
argv[0]);
return -1;
}
- ctx->stack[ctx->stack_depth].struct_size += da->flags.length;
+ dctx->stack[dctx->stack_depth].struct_size += da->flags.length;
}
/*
* Check for overflow.
*/
- if (ctx->stack[ctx->stack_depth].da->flags.length &&
- (ctx->stack[ctx->stack_depth].struct_size > ctx->stack[ctx->stack_depth].da->flags.length)) {
+ if (dctx->stack[dctx->stack_depth].da->flags.length &&
+ (dctx->stack[dctx->stack_depth].struct_size > dctx->stack[dctx->stack_depth].da->flags.length)) {
fr_strerror_printf("'struct' %s has fixed size %u, but member %s overflows that length",
- ctx->stack[ctx->stack_depth].da->name, ctx->stack[ctx->stack_depth].da->flags.length,
+ dctx->stack[dctx->stack_depth].da->name, dctx->stack[dctx->stack_depth].da->flags.length,
argv[0]);
return -1;
}
- if (dict_set_value_attr(ctx, da) < 0) return -1;
+ if (dict_set_value_attr(dctx, da) < 0) return -1;
/*
* Check if this MEMBER closes the structure.
* unwound to is a struct, and then if so... get the last child, and mark it
* closed.
*/
- if (!da->flags.is_known_width) ctx->stack[ctx->stack_depth].struct_is_closed = da;
+ if (!da->flags.is_known_width) dctx->stack[dctx->stack_depth].struct_is_closed = da;
break;
/* Deferred attribute, don't begin the TLV section automatically */
*
* Which MUST be a sub-structure of another struct
*/
-static int dict_read_process_struct(dict_tokenize_ctx_t *ctx, char **argv, int argc,
+static int dict_read_process_struct(dict_tokenize_ctx_t *dctx, char **argv, int argc,
UNUSED fr_dict_attr_flags_t *base_flags)
{
fr_value_box_t value = FR_VALUE_BOX_INITIALISER_NULL(value);
return -1;
}
- fr_assert(ctx->stack_depth > 0);
+ fr_assert(dctx->stack_depth > 0);
/*
* Unwind the stack until we find a parent which has a child named "key_attr"
*/
- for (i = ctx->stack_depth; i > 0; i--) {
- parent = dict_attr_by_name(NULL, ctx->stack[i].da, key_attr);
+ for (i = dctx->stack_depth; i > 0; i--) {
+ parent = dict_attr_by_name(NULL, dctx->stack[i].da, key_attr);
if (parent) {
- ctx->stack_depth = i;
+ dctx->stack_depth = i;
break;
}
}
* Else maybe it's a fully qualified name?
*/
if (!parent) {
- parent = fr_dict_attr_by_oid(NULL, ctx->stack[ctx->stack_depth].da->dict->root, key_attr);
+ parent = fr_dict_attr_by_oid(NULL, dctx->stack[dctx->stack_depth].da->dict->root, key_attr);
}
if (!parent) {
* Allocate the attribute here, and then fill in the fields
* as we start parsing the various elements of the definition.
*/
- da = dict_attr_alloc_null(ctx->dict->pool, ctx->dict->proto);
+ da = dict_attr_alloc_null(dctx->dict->pool, dctx->dict->proto);
if (unlikely(da == NULL)) return -1;
- dict_attr_location_set(ctx, da);
+ dict_attr_location_set(dctx, da);
if (unlikely(dict_attr_type_init(&da, FR_TYPE_STRUCT) < 0)) {
error:
* with any other type of length.
*/
if (argc == 4) {
- if (dict_process_flag_field(ctx, argv[3], &da) < 0) goto error;
+ if (dict_process_flag_field(dctx, argv[3], &da) < 0) goto error;
}
/*
/*
* Add the keyed STRUCT to the global namespace, and as a child of "parent".
*/
- switch (dict_attr_add_or_fixup(&ctx->fixup, &da)) {
+ switch (dict_attr_add_or_fixup(&dctx->fixup, &da)) {
default:
goto error;
/*
* A STRUCT definition is an implicit BEGIN-STRUCT.
*/
- ctx->relative_attr = NULL;
- if (dict_gctx_push(ctx, da) < 0) return -1;
+ dctx->relative_attr = NULL;
+ if (dict_dctx_push(dctx, da) < 0) return -1;
/*
* Add the VALUE to the parent attribute, and ensure that
/** Process a value alias
*
*/
-static int dict_read_process_value(dict_tokenize_ctx_t *ctx, char **argv, int argc,
+static int dict_read_process_value(dict_tokenize_ctx_t *dctx, char **argv, int argc,
UNUSED fr_dict_attr_flags_t *base_flags)
{
fr_dict_attr_t *da;
fr_value_box_t value = FR_VALUE_BOX_INITIALISER_NULL(value);
fr_slen_t enum_len;
- fr_dict_attr_t const *parent = ctx->stack[ctx->stack_depth].da;
+ fr_dict_attr_t const *parent = dctx->stack[dctx->stack_depth].da;
if (argc != 3) {
fr_strerror_const("Invalid VALUE syntax");
* * if no `struct`, then the VENDOR for VSAs
* * if no VENDOR, then the dictionary root
*/
- if (!ctx->value_attr || (strcasecmp(argv[0], ctx->value_attr->name) != 0)) {
+ if (!dctx->value_attr || (strcasecmp(argv[0], dctx->value_attr->name) != 0)) {
fr_dict_attr_t const *tmp;
if (!(tmp = fr_dict_attr_by_oid(NULL, parent, argv[0]))) goto fixup;
- ctx->value_attr = fr_dict_attr_unconst(tmp);
+ dctx->value_attr = fr_dict_attr_unconst(tmp);
}
- da = ctx->value_attr;
+ da = dctx->value_attr;
/*
* Verify the enum name matches the expected from.
*/
if (!da) {
fixup:
- if (!fr_cond_assert_msg(ctx->fixup.pool, "fixup pool context invalid")) return -1;
+ if (!fr_cond_assert_msg(dctx->fixup.pool, "fixup pool context invalid")) return -1;
- if (dict_fixup_enumv_enqueue(&ctx->fixup,
- CURRENT_FRAME(ctx)->filename, CURRENT_FRAME(ctx)->line,
+ if (dict_fixup_enumv_enqueue(&dctx->fixup,
+ CURRENT_FRAME(dctx)->filename, CURRENT_FRAME(dctx)->line,
argv[0], strlen(argv[0]),
argv[1], strlen(argv[1]),
argv[2], strlen(argv[2]), parent) < 0) {
bool was_member = false;
struct stat statbuf;
- char *argv[MAX_ARGV];
+ char *argv[DICT_MAX_ARGV];
int argc;
/*
p = strchr(buf, '#');
if (p) *p = '\0';
- argc = fr_dict_str_to_argv(buf, argv, MAX_ARGV);
+ argc = fr_dict_str_to_argv(buf, argv, DICT_MAX_ARGV);
if (argc == 0) continue;
if (argc == 1) {
char const *src_file, int src_line)
{
int ret;
- dict_tokenize_ctx_t ctx;
+ dict_tokenize_ctx_t dctx;
- memset(&ctx, 0, sizeof(ctx));
- ctx.dict = dict;
- dict_fixup_init(NULL, &ctx.fixup);
- ctx.stack[0].dict = dict;
- ctx.stack[0].da = dict->root;
- ctx.stack[0].nest = NEST_ROOT;
+ memset(&dctx, 0, sizeof(dctx));
+ dctx.dict = dict;
+ dict_fixup_init(NULL, &dctx.fixup);
+ dctx.stack[0].dict = dict;
+ dctx.stack[0].da = dict->root;
+ dctx.stack[0].nest = NEST_ROOT;
- ret = _dict_from_file(&ctx, dir_name, filename, src_file, src_line);
+ ret = _dict_from_file(&dctx, dir_name, filename, src_file, src_line);
if (ret < 0) {
- talloc_free(ctx.fixup.pool);
+ talloc_free(dctx.fixup.pool);
return ret;
}
* Fixups should have been applied already to any protocol
* dictionaries.
*/
- return dict_finalise(&ctx);
+ return dict_finalise(&dctx);
}
/** (Re-)Initialize the special internal dictionary
*/
int fr_dict_parse_str(fr_dict_t *dict, char *buf, fr_dict_attr_t const *parent)
{
- int argc;
- char *argv[MAX_ARGV];
- int ret;
- fr_dict_attr_flags_t base_flags;
- dict_tokenize_ctx_t ctx;
+ int argc;
+ char *argv[DICT_MAX_ARGV];
+ int ret;
+ fr_dict_attr_flags_t base_flags;
+ dict_tokenize_ctx_t dctx;
INTERNAL_IF_NULL(dict, -1);
- argc = fr_dict_str_to_argv(buf, argv, MAX_ARGV);
+ argc = fr_dict_str_to_argv(buf, argv, DICT_MAX_ARGV);
if (argc == 0) return 0;
- memset(&ctx, 0, sizeof(ctx));
- ctx.dict = dict;
- ctx.stack[0].dict = dict;
- ctx.stack[0].da = dict->root;
- ctx.stack[0].nest = NEST_ROOT;
+ memset(&dctx, 0, sizeof(dctx));
+ dctx.dict = dict;
+ dctx.stack[0].dict = dict;
+ dctx.stack[0].da = dict->root;
+ dctx.stack[0].nest = NEST_ROOT;
- if (dict_fixup_init(NULL, &ctx.fixup) < 0) return -1;
+ if (dict_fixup_init(NULL, &dctx.fixup) < 0) return -1;
if (strcasecmp(argv[0], "VALUE") == 0) {
if (argc < 4) {
fr_strerror_printf("VALUE needs at least 4 arguments, got %i", argc);
error:
- TALLOC_FREE(ctx.fixup.pool);
+ TALLOC_FREE(dctx.fixup.pool);
return -1;
}
argv[1], dict->root->name);
goto error;
}
- ret = dict_read_process_value(&ctx, argv + 1, argc - 1, &base_flags);
+ ret = dict_read_process_value(&dctx, argv + 1, argc - 1, &base_flags);
if (ret < 0) goto error;
} else if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
- if (parent && (parent != dict->root)) ctx.stack[++ctx.stack_depth].da = parent;
+ if (parent && (parent != dict->root)) dctx.stack[++dctx.stack_depth].da = parent;
memset(&base_flags, 0, sizeof(base_flags));
- ret = dict_read_process_attribute(&ctx,
+ ret = dict_read_process_attribute(&dctx,
argv + 1, argc - 1, &base_flags);
if (ret < 0) goto error;
} else if (strcasecmp(argv[0], "VENDOR") == 0) {
- ret = dict_read_process_vendor(&ctx, argv + 1, argc - 1, &base_flags);
+ ret = dict_read_process_vendor(&dctx, argv + 1, argc - 1, &base_flags);
if (ret < 0) goto error;
} else {
fr_strerror_printf("Invalid input '%s'", argv[0]);
goto error;
}
- return dict_finalise(&ctx);
+ return dict_finalise(&dctx);
}