default:
cf_log_err(map->ci, "Left hand side of map must be an attribute or list, not a %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
return -1;
}
default:
cf_log_err(map->ci, "Right hand side of map must be an xlat, attribute, exec, or literal, not a %s",
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->rhs->type));
return -1;
}
if (attribute && (!tmpl_is_attr(vpt) && !tmpl_is_attr_unresolved(vpt))) {
cf_log_err(cp, "Expected attr got %s",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "???"));
+ tmpl_type_to_str(vpt->type));
return -1;
}
if (attribute && !tmpl_is_attr(vpt)) {
cf_log_err(cp, "Expected attr got %s",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "???"));
+ tmpl_type_to_str(vpt->type));
return -1;
}
#endif
EVAL_DEBUG(">>> MAP TYPES LHS: %s, RHS: %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "???"),
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "???"));
+ tmpl_type_to_str(map->lhs->type),
+ tmpl_type_to_str(map->rhs->type));
#ifdef WITH_EVAL_DEBUG
tmpl_debug(map->lhs);
tmpl_debug(map->rhs);
static void map_dump(request_t *request, map_t const *map)
{
RDEBUG2(">>> MAP TYPES LHS: %s, RHS: %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "???"),
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "???"));
+ tmpl_type_to_str(map->lhs->type),
+ tmpl_type_to_str(map->rhs->type));
if (map->rhs) {
RDEBUG2(">>> MAP NAMES %s %s", map->lhs->name, map->rhs->name);
!tmpl_is_attr(map->lhs)) {
REDEBUG("Left side \"%.*s\" of map should be an attr or list but is an %s",
(int)map->lhs->len, map->lhs->name,
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
rcode = -2;
goto finish;
}
*/
#define tmpl_assert_type(_cond) \
fr_assert_msg(_cond, "Unexpected tmpl type '%s'", \
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"))
+ tmpl_type_to_str(vpt->type))
+
+
+/** @name Functions for printing and parsing tmpl type names
+ *
+ * @{
+ */
+/** Return a static string containing the type name
+ *
+ * @param[in] type to return name for.
+ * @return name of the type
+ */
+static inline char const *tmpl_type_to_str(tmpl_type_t type)
+{
+ return fr_table_str_by_value(tmpl_type_table, type, "<INVALID>");
+}
+
+/** Return the constant value representing a type
+ *
+ * @param[in] type to return the constant value for.
+ * @return The constant type value or TMPL_TYPE_UNINITIALISED if no type matches.
+ */
+static inline tmpl_type_t tmpl_type_from_str(char const *type)
+{
+ return fr_table_value_by_str(tmpl_type_table, type, TMPL_TYPE_UNINITIALISED);
+}
+/** @} */
/** @name Field accessors for #TMPL_TYPE_ATTR, #TMPL_TYPE_ATTR_UNRESOLVED, #TMPL_TYPE_LIST
*
default:
FR_FAULT_LOG("%s can't print tmpls of type %s", __FUNCTION__,
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"));
+ tmpl_type_to_str(vpt->type));
return;
}
FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pV\" (%p)",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"),
+ tmpl_type_to_str(vpt->type),
vpt->type,
fr_box_strvalue_len(vpt->name, vpt->len), vpt);
}
FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pR\" (%p)",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"),
+ tmpl_type_to_str(vpt->type),
vpt->type,
fr_box_strvalue_len(vpt->name, vpt->len), vpt);
void tmpl_attr_set_request(tmpl_t *vpt, tmpl_request_ref_t request)
{
fr_assert_msg(tmpl_is_attr(vpt), "Expected tmpl type 'attr', got '%s'",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"));
+ tmpl_type_to_str(vpt->type));
if (tmpl_request_list_num_elements(&vpt->data.attribute.rr) > 0) tmpl_request_list_talloc_reverse_free(&vpt->data.attribute.rr);
if (slen != name_len) {
/* This looks wrong, but it produces meaningful errors for unknown attrs */
fr_strerror_printf("Unexpected text after %s",
- fr_table_str_by_value(tmpl_type_table, (*out)->type, "<INVALID>"));
+ tmpl_type_to_str((*out)->type));
return -slen;
}
* @param[in] p_rules Formatting rules for the tmpl.
* @param[in] t_rules Validation rules for attribute references.
* @return
- * - <= 0 on error (offset as negative integer)
- * - > 0 on success (number of bytes parsed).
+ * - < 0 on error (offset as negative integer)
+ * - >= 0 on success (number of bytes parsed).
*
* @see REMARKER to produce pretty error markers from the return value.
*
}
fr_assert_fail("Can't print invalid tmpl type %s",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"));
+ tmpl_type_to_str(vpt->type));
break;
}
if (tmpl_rules_cast(c->data.map->lhs) != FR_TYPE_NULL) {
cf_log_err(map->ci, "Cannot cast virtual attribute %s to %s", map->lhs->name,
- fr_type_to_str(c->data.map->lhs->type));
+ tmpl_type_to_str(c->data.map->lhs->type));
return false;
}
default:
cf_log_err(map->ci, "Left side of map must be an attribute "
"or an xlat (that expands to an attribute), not a %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
return -1;
}
default:
cf_log_err(map->ci, "Left side of map must be an attribute "
"or an xlat (that expands to an attribute), not a %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
return -1;
}
if (!tmpl_is_attr(vpt) && !tmpl_is_list(vpt)) {
cf_log_err(cs, "MUST use attribute or list reference (not %s) in 'foreach'",
- fr_table_str_by_value(tmpl_type_table, vpt->type, "???"));
+ tmpl_type_to_str(vpt->type));
talloc_free(vpt);
return NULL;
}
if (!tmpl_contains_attr(src_vpt)) {
cf_log_err(cs, "Invalid argument to 'subrequest' src must be an attr or list, got %s",
- fr_table_str_by_value(tmpl_type_table, src_vpt->type, "<INVALID>"));
+ tmpl_type_to_str(src_vpt->type));
talloc_free(src_vpt);
goto error;
}
if (!tmpl_contains_attr(dst_vpt)) {
cf_log_err(cs, "Invalid argument to 'subrequest' dst must be an "
"attr or list, got %s",
- fr_table_str_by_value(tmpl_type_table, src_vpt->type, "<INVALID>"));
+ tmpl_type_to_str(src_vpt->type));
talloc_free(src_vpt);
talloc_free(dst_vpt);
goto error;
default:
REDEBUG("Unexpected type %s in left hand side of expression",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
return XLAT_ACTION_FAIL;
}
default:
REDEBUG("Unexpected type %s in right hand side of expression",
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->rhs->type));
return XLAT_ACTION_FAIL;
}
if (!tmpl_is_attr(map->lhs)) {
fr_strerror_printf("Pair left hand side \"%s\" parsed as %s, needed attribute. "
"Check local dictionaries", map->lhs->name,
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
goto error;
}
if (!tmpl_is_unresolved(map->rhs)) {
fr_strerror_printf("Pair right hand side \"%s\" parsed as %s, needed literal. "
"Check serialized data quoting", map->rhs->name,
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->rhs->type));
goto error;
}
default:
cf_log_err(map->ci, "Left hand side of map must be an attribute or list, not a %s",
- fr_table_str_by_value(tmpl_type_table, map->lhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->lhs->type));
return -1;
}
default:
cf_log_err(map->ci, "Right hand side of map must be a field name, not a %s",
- fr_table_str_by_value(tmpl_type_table, map->rhs->type, "<INVALID>"));
+ tmpl_type_to_str(map->rhs->type));
return -1;
}
if (slen < 0) {
talloc_free(key);
DEBUG("Failed casting %pV to data type '%s'",
- &key, fr_table_str_by_value(tmpl_type_table, inst->key_data_type, "<INVALID>"));
+ &key, tmpl_type_to_str(inst->key_data_type));
RETURN_MODULE_FAIL;
}
}
if (inst->requested_address) {
if (!tmpl_is_xlat(inst->requested_address)) {
cf_log_err(conf, "requested_address must be a double quoted expansion, not %s",
- fr_table_str_by_value(tmpl_type_table, inst->requested_address->type, "<INVALID>"));
+ tmpl_type_to_str(inst->requested_address->type));
}
}