}
fr_assert(vpt);
+ /*
+ * The caller told us what data type was expected. If we do have data, then try to cast
+ * it to the requested type.
+ */
+ if ((rule->type != FR_TYPE_VOID) && tmpl_contains_data(vpt)) {
+ slen = 0; // for errors
+
+ if (tmpl_is_data_unresolved(vpt)) {
+ tmpl_cast_set(vpt, rule->type);
+
+ if (tmpl_resolve(vpt, NULL) < 0) goto tmpl_error;
+
+ } else if (rule->type != tmpl_value_type(vpt)) {
+ fr_assert(tmpl_is_data(vpt));
+
+ if (tmpl_cast_in_place(vpt, rule->type, NULL) < 0) goto tmpl_error;
+ }
+ }
+
*(tmpl_t **)out = vpt;
goto finish;
}
.flags = (_flags), \
.offset = FR_CONF_FLAG_CHECK((_type), (_flags), &(((_struct *)NULL)->_field), offsetof(_struct, _field))
+/** conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
+ *
+ * This variant takes output hint type. If the type is a bare word, it MUST be of the relevant data type.
+ *
+ * @param[in] _name of the CONF_PAIR to search for.
+ * @param[in] _type to parse the CONF_PAIR as.
+ * @param[in] _flags controlling parsing behaviour.
+ * @param[in] _struct containing the field to write the result to.
+ * @param[in] _field to write the result to.
+ */
+# define FR_CONF_OFFSET_HINT_TYPE(_name, _type, _struct, _field) \
+ .name1 = _name, \
+ .type = (_type), \
+ .flags = CONF_FLAG_TMPL, \
+ .offset = FR_CONF_FLAG_CHECK(FR_TYPE_VOID, CONF_FLAG_TMPL, &(((_struct *)NULL)->_field), offsetof(_struct, _field))
+
/** conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
*
* This variant takes additional flags, and will add CONF_FLAG_MULTI automatically if the field is an array.
#define tmpl_is_regex_xlat_unresolved(vpt) ((vpt)->type == TMPL_TYPE_REGEX_XLAT_UNRESOLVED)
#define tmpl_needs_resolving(vpt) ((vpt)->type & TMPL_FLAG_UNRESOLVED)
+#define tmpl_contains_data(vpt) ((vpt)->type & TMPL_TYPE_DATA)
#define tmpl_contains_attr(vpt) ((vpt)->type & TMPL_FLAG_ATTR)
#define tmpl_contains_regex(vpt) ((vpt)->type & TMPL_FLAG_REGEX)
#define tmpl_contains_xlat(vpt) ((vpt)->type & TMPL_FLAG_XLAT)
+
extern fr_table_num_ordered_t const tmpl_type_table[];
extern size_t tmpl_type_table_len;