memcpy(&flags, base_flags, sizeof(flags));
+ /*
+ * If our parent is a fixed-size struct, then we have to be fixed-size, too.
+ */
+ flags.is_known_width |= ctx->stack[ctx->stack_depth].da->flags.is_known_width;
+
if (dict_process_type_field(ctx, argv[1], &type, &flags) < 0) return -1;
/*
case FR_TYPE_TIME_DELTA:
case FR_TYPE_STRING:
case FR_TYPE_OCTETS:
+ case FR_TYPE_STRUCT:
break;
}
return false;
}
+ /*
+ * If we have arrays of structs, then the structure MUST be known width.
+ */
+ flags->is_known_width |= flags->array;
+
ALLOW_FLAG(extra);
- /* @todo - allow arrays of struct? */
ALLOW_FLAG(subtype);
+ ALLOW_FLAG(array);
break;
case FR_TYPE_TLV:
case FR_TYPE_STRUCT:
ALLOW_FLAG(internal);
+ ALLOW_FLAG(array);
if (all_flags) {
fr_strerror_const("Invalid flag for attribute of type 'struct'");
return false;
ALLOW_FLAG(extra);
ALLOW_FLAG(subtype);
+ if (parent->flags.is_known_width && !flags->is_known_width && !flags->length) {
+ fr_strerror_const("Variable-sized fields cannot be used within a 'struct' which is 'array'");
+ return false;
+ }
+
if (flags->array) {
switch (type) {
case FR_TYPE_FIXED_SIZE:
break;
}
}
+
if (all_flags) {
fr_strerror_const("Invalid flag for attribute inside of a 'struct'");
return false;
return false;
}
-#if 0
- if (parent->type == FR_TYPE_STRUCT) {
- /*
- * @todo - check PREVIOUS element. if it's non-fixed size, then error out.
- * Move validation code from dict_read_process_member() to here
- */
- switch (type) {
- case FR_TYPE_FIXED_SIZE:
- break;
-
- case FR_TYPE_TLV:
- case FR_TYPE_STRING:
- case FR_TYPE_OCTETS:
- if (flags->length != 0) {
- fr_strerror_const("The 'octets' type MUST be fixed-width when used inside of a 'struct'");
- return false;
- }
- break;
-
- default:
- break;
- }
- }
-#endif
-
/*
* Initialize the length field, which is needed for the attr_valid() callback.
*/
flags->length = fr_value_box_network_length(&box);
}
+ if (type == FR_TYPE_STRUCT) flags->is_known_width |= flags->array;
+
/*
* Run protocol-specific validation functions, BEFORE we
* do the rest of the checks.