From: Arran Cudbard-Bell Date: Mon, 24 Jan 2022 22:01:21 +0000 (-0600) Subject: Add fr_type_from_str and fr_type_to_str X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e035634048d8eccfd71fa2b4edcca8af3cc8ac52;p=thirdparty%2Ffreeradius-server.git Add fr_type_from_str and fr_type_to_str Which more than halves the length of the function call... --- diff --git a/src/bin/radict.c b/src/bin/radict.c index 1d0b439e83..e784bce311 100644 --- a/src/bin/radict.c +++ b/src/bin/radict.c @@ -157,7 +157,7 @@ static void da_print_info_td(fr_dict_t const *dict, fr_dict_attr_t const *da) fr_dict_root(dict)->name, oid_str, da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?"), + fr_type_to_str(da->type), flags); if (print_values) { @@ -175,7 +175,7 @@ static void da_print_info_td(fr_dict_t const *dict, fr_dict_attr_t const *da) fr_dict_root(dict)->name, oid_str, da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?"), + fr_type_to_str(da->type), flags, enumv->name, enumv->value); diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index ea1ac85a26..c778ca8868 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -995,7 +995,7 @@ static size_t parse_typed_value(command_result_t *result, fr_value_box_t *box, c /* * Parse data types */ - type = fr_table_value_by_longest_prefix(&match_len, fr_value_box_type_table, in, inlen, FR_TYPE_NULL); + type = fr_table_value_by_longest_prefix(&match_len, fr_type_table, in, inlen, FR_TYPE_NULL); if (fr_type_is_null(type)) { RETURN_PARSE_ERROR(0); } @@ -1248,7 +1248,7 @@ static size_t command_calc(command_result_t *result, command_file_ctx_t *cc, p += 2; fr_skip_whitespace(p); - type = fr_table_value_by_longest_prefix(&match_len, fr_value_box_type_table, p, end - p, FR_TYPE_MAX); + type = fr_table_value_by_longest_prefix(&match_len, fr_type_table, p, end - p, FR_TYPE_MAX); if (type == FR_TYPE_MAX) RETURN_PARSE_ERROR(0); fr_value_box_init(out, type, NULL, false); } diff --git a/src/lib/eap_aka_sim/decode.c b/src/lib/eap_aka_sim/decode.c index 253e926314..8482c2a8e0 100644 --- a/src/lib/eap_aka_sim/decode.c +++ b/src/lib/eap_aka_sim/decode.c @@ -535,7 +535,7 @@ static ssize_t sim_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_di FR_PROTO_TRACE("Parent %s len %zu", parent->name, attr_len); FR_PROTO_HEX_DUMP(data, attr_len, __FUNCTION__ ); - FR_PROTO_TRACE("Type \"%s\" (%u)", fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?"), parent->type); + FR_PROTO_TRACE("Type \"%s\" (%u)", fr_type_to_str(parent->type), parent->type); /* * Special cases, attributes that either have odd formats, or need diff --git a/src/lib/eap_aka_sim/encode.c b/src/lib/eap_aka_sim/encode.c index bd612c26b8..d510bbba69 100644 --- a/src/lib/eap_aka_sim/encode.c +++ b/src/lib/eap_aka_sim/encode.c @@ -292,7 +292,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, switch (da->type) { case FR_TYPE_STRUCTURAL: fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; default: @@ -596,7 +596,7 @@ static ssize_t encode_rfc_hdr(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsign switch (da_stack->da[depth]->type) { case FR_TYPE_STRUCTURAL: fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; default: @@ -737,7 +737,7 @@ static ssize_t encode_tlv_hdr(fr_dbuff_t *dbuff, if (da_stack->da[depth]->type != FR_TYPE_TLV) { fr_strerror_printf("%s: Expected type \"tlv\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; } diff --git a/src/lib/json/json.c b/src/lib/json/json.c index f78745541b..784b28da27 100644 --- a/src/lib/json/json.c +++ b/src/lib/json/json.c @@ -585,8 +585,7 @@ static json_object *json_object_afrom_pair_list(TALLOC_CTX *ctx, fr_pair_list_t /* * Add "type" to newly created keys. */ - MEM(type_name = json_object_new_string(fr_table_str_by_value(fr_value_box_type_table, - vp->vp_type, ""))); + MEM(type_name = json_object_new_string(fr_type_to_str(vp->vp_type))); json_object_object_add_ex(vp_object, "type", type_name, JSON_C_OBJECT_KEY_IS_CONSTANT); /* @@ -845,8 +844,7 @@ static struct json_object *json_array_afrom_pair_list(TALLOC_CTX *ctx, fr_pair_l MEM(name = json_object_new_string(fr_sbuff_start(&attr_name))); json_object_object_add_ex(attrobj, "name", name, JSON_C_OBJECT_KEY_IS_CONSTANT); - MEM(type_name = json_object_new_string(fr_table_str_by_value(fr_value_box_type_table, - vp->vp_type, ""))); + MEM(type_name = json_object_new_string(fr_type_to_str(vp->vp_type))); json_object_object_add_ex(attrobj, "type", type_name, JSON_C_OBJECT_KEY_IS_CONSTANT); } diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index 3012cff411..c05af69171 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -538,7 +538,7 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM fr_assert(type < FR_TYPE_MAX); cf_log_err(cp, "type '%s' (%i) is not supported in the configuration files", - fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?"), type); + fr_type_to_str(type), type); goto error; } diff --git a/src/lib/server/command.c b/src/lib/server/command.c index c42384e8e5..d871c947a6 100644 --- a/src/lib/server/command.c +++ b/src/lib/server/command.c @@ -242,7 +242,7 @@ static bool fr_command_valid_syntax(fr_cmd_argv_t *argv) if (uppercase) { fr_type_t type; - type = fr_table_value_by_str(fr_value_box_type_table, argv->name, FR_TYPE_NULL); + type = fr_table_value_by_str(fr_type_table, argv->name, FR_TYPE_NULL); switch (type) { case FR_TYPE_MAX: case FR_TYPE_NULL: diff --git a/src/lib/server/cond_eval.c b/src/lib/server/cond_eval.c index e6d9c418ee..4f311da23f 100644 --- a/src/lib/server/cond_eval.c +++ b/src/lib/server/cond_eval.c @@ -161,8 +161,7 @@ static bool cond_eval_tmpl(request_t *request, tmpl_t const *in, fr_value_box_t if (fr_value_box_cast(box, box, tmpl_rules_cast(vpt), NULL, &vp->data) < 0) { if (request) RPEDEBUG("Failed casting %pV to type %s", box, - fr_table_str_by_value(fr_value_box_type_table, - tmpl_rules_cast(vpt), "??")); + fr_type_to_str(tmpl_rules_cast(vpt))); goto done; } break; @@ -509,8 +508,7 @@ static int cond_realize_attr(request_t *request, fr_value_box_t **realized, fr_v fr_value_box_init_null(box); if (fr_value_box_cast(request, box, cast_type, da, &vp->data) < 0) { if (request) RPEDEBUG("Failed casting %pV to type %s", &vp->data, - fr_table_str_by_value(fr_value_box_type_table, - tmpl_rules_cast(vpt), "??")); + fr_type_to_str(tmpl_rules_cast(vpt))); return false; } diff --git a/src/lib/server/cond_tokenize.c b/src/lib/server/cond_tokenize.c index ec7d462569..038d817203 100644 --- a/src/lib/server/cond_tokenize.c +++ b/src/lib/server/cond_tokenize.c @@ -100,8 +100,7 @@ ssize_t cond_print(fr_sbuff_t *out, fr_cond_t const *in) case COND_TYPE_MAP: if (tmpl_rules_cast(c->data.map->lhs)) { FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "<%s>", - fr_table_str_by_value(fr_value_box_type_table, - tmpl_rules_cast(c->data.map->lhs), "??")); + fr_type_to_str(tmpl_rules_cast(c->data.map->lhs))); } FR_SBUFF_RETURN(map_print, &our_out, c->data.map); break; @@ -206,8 +205,8 @@ static int cond_cast_tmpl(tmpl_t *vpt, fr_type_t type, tmpl_t *other) fr_assert(tmpl_is_data(vpt)); fr_assert_msg(fr_type_is_null(tmpl_rules_cast(vpt)) || (tmpl_rules_cast(vpt) == tmpl_value_type(vpt)), "Cast mismatch, target was %s, but output was %s", - fr_table_str_by_value(fr_value_box_type_table, tmpl_rules_cast(vpt), ""), - fr_table_str_by_value(fr_value_box_type_table, tmpl_value_type(vpt), "")); + fr_type_to_str(tmpl_rules_cast(vpt)), + fr_type_to_str(tmpl_value_type(vpt))); (void) tmpl_cast_set(vpt, FR_TYPE_NULL); return 0; } diff --git a/src/lib/server/snmp.c b/src/lib/server/snmp.c index 27cefa8ea9..ef29ca265c 100644 --- a/src/lib/server/snmp.c +++ b/src/lib/server/snmp.c @@ -639,7 +639,7 @@ static ssize_t snmp_process_index_attr(fr_dcursor_t *out, request_t *request, if (da_stack->da[depth]->type != FR_TYPE_UINT32) { fr_strerror_printf("Bad index attribute: Index attribute \"%s\" should be a integer, " "but is a %s", da_stack->da[depth]->name, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); goto error; } diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 92d3edd269..56b277d9c4 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -152,7 +152,7 @@ void tmpl_attr_ref_debug(const tmpl_attr_t *ar, int i) FR_FAULT_LOG("\t[%u] %s %s %s%s%s%s (%p) attr %u", i, fr_table_str_by_value(attr_table, ar->type, ""), - fr_table_str_by_value(fr_value_box_type_table, ar->da->type, ""), + fr_type_to_str(ar->da->type), ar->da->name, ar->num != NUM_ANY ? "[" : "", ar->num != NUM_ANY ? fr_table_str_by_value(attr_num_table, ar->num, buffer) : "", @@ -267,8 +267,7 @@ void tmpl_debug(tmpl_t const *vpt) return; case TMPL_TYPE_DATA: - FR_FAULT_LOG("\ttype : %s", fr_table_str_by_value(fr_value_box_type_table, - tmpl_value_type(vpt), "")); + FR_FAULT_LOG("\ttype : %s", fr_type_to_str(tmpl_value_type(vpt))); FR_FAULT_LOG("\tlen : %zu", tmpl_value_length(vpt)); FR_FAULT_LOG("\tvalue : %pV", tmpl_value(vpt)); @@ -1659,8 +1658,7 @@ do_suffix: fr_strerror_printf("Parent type of nested attribute %s must be of type " "\"struct\", \"tlv\", \"vendor\", \"vsa\" or \"group\", got \"%s\"", da->name, - fr_table_str_by_value(fr_value_box_type_table, - da->type, "")); + fr_type_to_str(da->type)); fr_sbuff_set(name, &m_s); goto error; } @@ -2911,7 +2909,7 @@ ssize_t tmpl_cast_from_substr(fr_type_t *out, fr_sbuff_t *in) if (fr_sbuff_next_if_char(&our_in, '<')) { fr_sbuff_marker(&m, &our_in); - fr_sbuff_out_by_longest_prefix(&slen, &cast, fr_value_box_type_table, &our_in, FR_TYPE_NULL); + fr_sbuff_out_by_longest_prefix(&slen, &cast, fr_type_table, &our_in, FR_TYPE_NULL); if (fr_type_is_null(cast)) { fr_strerror_const("Unknown data type"); FR_SBUFF_ERROR_RETURN(&our_in); @@ -2946,7 +2944,7 @@ int tmpl_cast_set(tmpl_t *vpt, fr_type_t dst_type) switch (dst_type) { default: fr_strerror_printf("Forbidden data type '%s' in cast", - fr_table_str_by_value(fr_value_box_type_table, dst_type, "??")); + fr_type_to_str(dst_type)); return -1; /* @@ -3009,8 +3007,8 @@ int tmpl_cast_set(tmpl_t *vpt, fr_type_t dst_type) if (!fr_type_cast(dst_type, src_type)) { fr_strerror_printf("Cannot cast type '%s' to '%s'", - fr_table_str_by_value(fr_value_box_type_table, src_type, "??"), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "??")); + fr_type_to_str(src_type), + fr_type_to_str(dst_type)); return -1; } break; @@ -3694,8 +3692,8 @@ int tmpl_attr_unresolved_add(fr_dict_t *dict_def, tmpl_t *vpt, if (type != da->type) { fr_strerror_printf("Attribute %s of type %s already defined with type %s", - da->name, fr_table_str_by_value(fr_value_box_type_table, type, ""), - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + da->name, fr_type_to_str(type), + fr_type_to_str(da->type)); return -1; } @@ -4364,7 +4362,7 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt) fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR " "attribute \"%s\" (%s) not rooted in a dictionary", file, line, tmpl_da(vpt)->name, - fr_table_str_by_value(fr_value_box_type_table, tmpl_da(vpt)->type, "")); + fr_type_to_str(tmpl_da(vpt)->type)); } da = tmpl_da(vpt); @@ -4374,9 +4372,9 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt) "and global dictionary pointer %p \"%s\" (%s) differ", file, line, tmpl_da(vpt), tmpl_da(vpt)->name, - fr_table_str_by_value(fr_value_box_type_table, tmpl_da(vpt)->type, ""), + fr_type_to_str(tmpl_da(vpt)->type), da, da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); } if (tmpl_list(vpt) >= PAIR_LIST_UNKNOWN) { @@ -4531,7 +4529,7 @@ ssize_t tmpl_preparse(char const **out, size_t *outlen, char const *in, size_t i /* nothing */ } - cast = fr_table_value_by_substr(fr_value_box_type_table, p, q - p, FR_TYPE_NULL); + cast = fr_table_value_by_substr(fr_type_table, p, q - p, FR_TYPE_NULL); if (fr_type_is_null(cast)) { return_P("Unknown data type"); } diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index ac2231c657..fea00cb78c 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -353,7 +353,7 @@ static bool pass2_fixup_cond_map(fr_cond_t *c, CONF_ITEM *ci, fr_dict_t const *d if (tmpl_cast_in_place(map->rhs, tmpl_da(map->lhs)->type, tmpl_da(map->lhs)) < 0) { cf_log_err(map->ci, "Failed to parse data type %s from string: %pV", - fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, ""), + fr_type_to_str(tmpl_da(map->lhs)->type), fr_box_strvalue_len(map->rhs->name, map->rhs->len)); return false; } /* else the cast was successful */ @@ -501,7 +501,7 @@ static bool pass2_fixup_cond_map(fr_cond_t *c, CONF_ITEM *ci, fr_dict_t const *d 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_table_str_by_value(fr_value_box_type_table, c->data.map->lhs->type, "")); + fr_type_to_str(c->data.map->lhs->type)); return false; } @@ -617,7 +617,7 @@ static bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_ default: cf_log_err(map->ci, "Sublists can only be assigned to structural attributes, not to type %s", - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return false; } @@ -1037,8 +1037,8 @@ int unlang_fixup_update(map_t *map, UNUSED void *ctx) */ if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) { cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, ""), - fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "")); + fr_type_to_str(FR_TYPE_STRING), + fr_type_to_str(tmpl_da(map->lhs)->type)); return -1; } @@ -1164,8 +1164,8 @@ static int unlang_fixup_filter(map_t *map, UNUSED void *ctx) */ if (tmpl_cast_in_place(map->rhs, type, tmpl_da(map->lhs)) < 0) { cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, ""), - fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "")); + fr_type_to_str(FR_TYPE_STRING), + fr_type_to_str(tmpl_da(map->lhs)->type)); return -1; } } /* else we can't precompile the data */ @@ -2568,7 +2568,7 @@ static unlang_t *compile_switch(unlang_t *parent, unlang_compile_t *unlang_ctx, htype = fr_htrie_hint(type); if (htype == FR_HTRIE_INVALID) { cf_log_err(cs, "Invalid data type '%s' used for 'switch' statement", - fr_table_str_by_value(fr_value_box_type_table, type, "???")); + fr_type_to_str(type)); goto error; } diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 64f4d72d60..81955e7e52 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -336,8 +336,8 @@ static int apply_edits(request_t *request, unlang_frame_state_edit_t *state, map default: fr_strerror_printf("Cannot assign '%s' type to structural type '%s'", - fr_table_str_by_value(fr_value_box_type_table, rhs_box->type, ""), - fr_table_str_by_value(fr_value_box_type_table, state->lhs.vp->vp_type, "")); + fr_type_to_str(rhs_box->type), + fr_type_to_str(state->lhs.vp->vp_type)); return -1; } diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index ccca6acc4b..5ed909be21 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1059,7 +1059,7 @@ static xlat_action_t xlat_func_debug_attr(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcur RIDEBUG3("attr : %u", vp->da->attr); vendor = fr_dict_vendor_by_da(vp->da); if (vendor) RIDEBUG2("vendor : %i (%s)", vendor->pen, vendor->name); - RIDEBUG3("type : %s", fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "")); + RIDEBUG3("type : %s", fr_type_to_str(vp->vp_type)); if (fr_box_is_variable_size(&vp->data)) { RIDEBUG3("length : %zu", vp->vp_length); @@ -1067,12 +1067,12 @@ static xlat_action_t xlat_func_debug_attr(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcur if (!RDEBUG_ENABLED4) continue; - for (i = 0; i < fr_value_box_type_table_len; i++) { + for (i = 0; i < fr_type_table_len; i++) { int pad; fr_value_box_t *dst = NULL; - type = &fr_value_box_type_table[i]; + type = &fr_type_table[i]; if ((fr_type_t) type->value == vp->vp_type) goto next_type; @@ -1251,7 +1251,7 @@ static xlat_action_t xlat_func_integer(TALLOC_CTX *ctx, fr_dcursor_t *out, default: error: RPEDEBUG("Failed converting %pV (%s) to an integer", in_vb, - fr_table_str_by_value(fr_value_box_type_table, in_vb->type, "???")); + fr_type_to_str(in_vb->type)); talloc_free(in_vb); return XLAT_ACTION_FAIL; diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index db49c11751..ea2250303a 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -645,8 +645,7 @@ static xlat_exp_t *xlat_expr_cast_alloc(TALLOC_CTX *ctx, fr_type_t type) xlat_exp_set_type(node, XLAT_BOX); xlat_exp_set_name_buffer_shallow(node, talloc_strdup(node, - fr_table_str_by_value(fr_value_box_type_table, - type, ""))); + fr_type_to_str(type))); fr_value_box_init(&node->data, FR_TYPE_UINT8, attr_cast_base, false); node->data.vb_uint8 = type; @@ -746,7 +745,7 @@ static ssize_t tokenize_field(TALLOC_CTX *input_ctx, xlat_exp_t **head, xlat_fla fr_sbuff_skip_whitespace(&in); - fr_sbuff_out_by_longest_prefix(&slen, &cast_type, fr_value_box_type_table, &in, FR_TYPE_VOID); + fr_sbuff_out_by_longest_prefix(&slen, &cast_type, fr_type_table, &in, FR_TYPE_VOID); if (cast_type == FR_TYPE_VOID) { fr_sbuff_set(&in, &marker); goto check_more; diff --git a/src/lib/unlang/xlat_pair.c b/src/lib/unlang/xlat_pair.c index 04a2e9e1a5..e3c244013e 100644 --- a/src/lib/unlang/xlat_pair.c +++ b/src/lib/unlang/xlat_pair.c @@ -105,8 +105,8 @@ int xlat_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out, if (vb->type != FR_TYPE_OCTETS) { RWDEBUG("Skipping value \"%pV\", expected value of type %s, got type %s", vb, - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_OCTETS, ""), - fr_table_str_by_value(fr_value_box_type_table, vb->type, "")); + fr_type_to_str(FR_TYPE_OCTETS), + fr_type_to_str(vb->type)); continue; } diff --git a/src/lib/util/calc.c b/src/lib/util/calc.c index e46301e242..95f446b48f 100644 --- a/src/lib/util/calc.c +++ b/src/lib/util/calc.c @@ -573,7 +573,7 @@ static const fr_type_t upcast_cmp[FR_TYPE_MAX + 1][FR_TYPE_MAX + 1] = { static int invalid_type(fr_type_t type) { fr_strerror_printf("Cannot perform mathematical operations on data type %s", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return -1; } @@ -584,16 +584,16 @@ static int handle_result(fr_type_t type, fr_token_t op, int rcode) } else if (rcode == ERR_UNDERFLOW) { fr_strerror_printf("Value underflows '%s' when calculating result.", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); } else if (rcode == ERR_OVERFLOW) { fr_strerror_printf("Value overflows '%s' when calculating result.", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); } else if (rcode == ERR_INVALID) { fr_strerror_printf("Invalid assignment operator '%s' for result type '%s'.", fr_tokens[op], - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); } return rcode; @@ -1028,7 +1028,7 @@ static int cast_ipv4_addr(fr_value_box_t *out, fr_value_box_t const *in) switch (in->type) { default: fr_strerror_printf("Cannot operate on ipaddr and %s", - fr_table_str_by_value(fr_value_box_type_table, in->type, "")); + fr_type_to_str(in->type)); return -1; case FR_TYPE_IPV4_PREFIX: @@ -1155,7 +1155,7 @@ static int calc_ipv4_prefix(UNUSED TALLOC_CTX *ctx, fr_value_box_t *dst, fr_valu default: fr_strerror_printf("Invalid input data type '%s' for logical 'and'", - fr_table_str_by_value(fr_value_box_type_table, a->type, "")); + fr_type_to_str(a->type)); return -1; } @@ -1208,7 +1208,7 @@ static int cast_ipv6_addr(fr_value_box_t *out, fr_value_box_t const *in) switch (in->type) { default: fr_strerror_printf("Cannot operate on ipv6addr and %s", - fr_table_str_by_value(fr_value_box_type_table, in->type, "")); + fr_type_to_str(in->type)); return -1; case FR_TYPE_IPV6_PREFIX: @@ -1706,7 +1706,7 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint case T_OP_LT: if (hint != FR_TYPE_BOOL) { fr_strerror_printf("Invalid destination type '%s' for comparison operator", - fr_table_str_by_value(fr_value_box_type_table, hint, "")); + fr_type_to_str(hint)); goto done; } @@ -1729,9 +1729,9 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint if (hint == FR_TYPE_NULL) { fr_strerror_printf("Cannot compare incompatible types (%s)... %s (%s)...", - fr_table_str_by_value(fr_value_box_type_table, a->type, ""), + fr_type_to_str(a->type), fr_tokens[op], - fr_table_str_by_value(fr_value_box_type_table, b->type, "")); + fr_type_to_str(b->type)); goto done; } @@ -1785,7 +1785,7 @@ int fr_value_calc_binary_op(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t hint func = calc_type[hint]; if (!func) { fr_strerror_printf("Cannot perform any operations for destination type %s", - fr_table_str_by_value(fr_value_box_type_table, hint, "")); + fr_type_to_str(hint)); rcode = -1; break; } diff --git a/src/lib/util/dict_ext_priv.h b/src/lib/util/dict_ext_priv.h index 1e61227594..aa8d3b59c6 100644 --- a/src/lib/util/dict_ext_priv.h +++ b/src/lib/util/dict_ext_priv.h @@ -116,7 +116,7 @@ static inline int dict_attr_ref_set(fr_dict_attr_t const *da, fr_dict_attr_t con ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_REF); if (unlikely(!ext)) { fr_strerror_printf("%s (%s) contains no 'ref' extension", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return -1; } ext->ref = ref; @@ -131,7 +131,7 @@ static inline int dict_attr_children_set(fr_dict_attr_t const *da, fr_dict_attr_ ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_CHILDREN); if (unlikely(!ext)) { fr_strerror_printf("%s (%s) contains no 'children' extension", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return -1; } ext->children = children; @@ -146,7 +146,7 @@ static inline fr_dict_attr_t const **dict_attr_children(fr_dict_attr_t const *da ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_CHILDREN); if (unlikely(!ext)) { fr_strerror_printf("%s (%s) contains no 'children' extension", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return NULL; } return ext->children; diff --git a/src/lib/util/dict_fixup.c b/src/lib/util/dict_fixup.c index 9ef2c58c35..2a3e0146b5 100644 --- a/src/lib/util/dict_fixup.c +++ b/src/lib/util/dict_fixup.c @@ -476,7 +476,7 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu if (fr_type_is_non_leaf(da->type) || fr_type_is_non_leaf(fixup->da->type) || dict_attr_children(da) || dict_attr_children(fixup->da)) { fr_strerror_printf("Reference MUST be to a simple data type of type '%s' at %s[%d]", - fr_table_str_by_value(fr_value_box_type_table, fixup->da->type, ""), + fr_type_to_str(fixup->da->type), fr_cwd_strip(fixup->common.filename), fixup->common.line); return -1; } @@ -495,7 +495,7 @@ static inline CC_HINT(always_inline) int dict_fixup_clone_apply(UNUSED dict_fixu if (!copied) { fr_strerror_printf("Reference copied no VALUEs from type type '%s' at %s[%d]", - fr_table_str_by_value(fr_value_box_type_table, fixup->da->type, ""), + fr_type_to_str(fixup->da->type), fr_cwd_strip(fixup->common.filename), fixup->common.line); return -1; } diff --git a/src/lib/util/dict_print.c b/src/lib/util/dict_print.c index bca36b7acd..499bc4e2c6 100644 --- a/src/lib/util/dict_print.c +++ b/src/lib/util/dict_print.c @@ -179,7 +179,7 @@ static int dict_attr_debug(fr_dict_attr_t const *da, void *uctx) our_uctx->prefix, da->name, da->attr, - fr_table_str_by_value(fr_value_box_type_table, da->type, ""), + fr_type_to_str(da->type), our_uctx->flags); dict_attr_ext_debug(our_uctx->prefix, da); /* Print all the extension debug info */ @@ -250,7 +250,7 @@ static int dict_attr_export(fr_dict_attr_t const *da, void *uctx) FR_FAULT_LOG("ATTRIBUTE\t%-40s\t%-20s\t%s\t%s", our_uctx->prefix, our_uctx->oid, - fr_table_str_by_value(fr_value_box_type_table, da->type, "???"), + fr_type_to_str(da->type), our_uctx->flags); return 0; diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index a41bb9f92d..d148b8b0d5 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -269,7 +269,7 @@ static int dict_process_type_field(dict_tokenize_ctx_t *ctx, char const *name, f /* * find the type of the attribute. */ - type = fr_table_value_by_str(fr_value_box_type_table, name, FR_TYPE_NULL); + type = fr_type_from_str(name); if (fr_type_is_null(type)) { fr_strerror_printf("Unknown data type '%s'", name); return -1; @@ -399,11 +399,11 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type (strncmp(key, "int", 3) == 0)) { fr_type_t subtype; - subtype = fr_table_value_by_str(fr_value_box_type_table, key, FR_TYPE_NULL); + subtype = fr_type_from_str(key); if (fr_type_is_null(subtype)) { unknown_type: fr_strerror_printf("Unknown or unsupported %s type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, ""), + fr_type_to_str(type), key); return -1; } @@ -448,7 +448,7 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type precision = fr_table_value_by_str(fr_time_precision_table, key, -1); if (precision < 0) { fr_strerror_printf("Unknown %s precision '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, ""), + fr_type_to_str(type), key); return -1; } @@ -468,7 +468,7 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type if (type != FR_TYPE_GROUP) { fr_strerror_printf("The 'ref' flag cannot be used for type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return -1; } @@ -1009,7 +1009,7 @@ static int dict_read_process_enum(dict_tokenize_ctx_t *ctx, char **argv, int arg default: fr_strerror_printf("ENUMs can only be a leaf type, not %s", - fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?")); + fr_type_to_str(type)); break; } @@ -1317,7 +1317,7 @@ static int dict_read_process_value(dict_tokenize_ctx_t *ctx, char **argv, int ar */ if (!fr_type_is_leaf(da->type)) { fr_strerror_printf_push("Cannot define VALUE for attribute '%s' of data type '%s'", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return -1; } @@ -1327,7 +1327,7 @@ static int dict_read_process_value(dict_tokenize_ctx_t *ctx, char **argv, int ar fr_strerror_printf_push("Invalid VALUE '%s' for attribute '%s' of data type '%s'", argv[2], da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return -1; } @@ -2257,7 +2257,7 @@ static int _dict_from_file(dict_tokenize_ctx_t *ctx, if (da->type != FR_TYPE_TLV) { fr_strerror_printf_push("Attribute '%s' should be a 'tlv', but is a '%s'", argv[1], - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); goto error; } @@ -2359,7 +2359,7 @@ static int _dict_from_file(dict_tokenize_ctx_t *ctx, if (da->type != FR_TYPE_VSA) { fr_strerror_printf_push("Invalid parent for BEGIN-VENDOR. " "Attribute '%s' should be 'vsa' but is '%s'", p, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); goto error; } @@ -2617,9 +2617,9 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char c * fr_dict_attr_add(), because we know what we're doing, and * that function does too many checks. */ - for (i = 0; i < fr_value_box_type_table_len; i++) { + for (i = 0; i < fr_type_table_len; i++) { fr_dict_attr_t *n; - fr_table_num_ordered_t const *p = &fr_value_box_type_table[i]; + fr_table_num_ordered_t const *p = &fr_type_table[i]; switch (p->value) { case FR_TYPE_NULL: /* Can't cast to NULL */ diff --git a/src/lib/util/dict_unknown.c b/src/lib/util/dict_unknown.c index b075d6d747..3b3c29d0db 100644 --- a/src/lib/util/dict_unknown.c +++ b/src/lib/util/dict_unknown.c @@ -291,7 +291,7 @@ fr_dict_attr_t *fr_dict_unknown_vendor_afrom_num(TALLOC_CTX *ctx, default: fr_strerror_printf("Unknown vendors can only be parented by a vsa, not a %s", - fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?")); + fr_type_to_str(parent->type)); return NULL; } } @@ -315,7 +315,7 @@ fr_dict_attr_t *fr_dict_unknown_tlv_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t co fr_strerror_printf("%s: Cannot allocate unknown tlv attribute (%u) with parent type %s", __FUNCTION__, num, - fr_table_str_by_value(fr_value_box_type_table, parent->type, "")); + fr_type_to_str(parent->type)); return NULL; } @@ -342,7 +342,7 @@ fr_dict_attr_t *fr_dict_unknown_attr_afrom_num(TALLOC_CTX *ctx, fr_dict_attr_t c fr_strerror_printf("%s: Cannot allocate unknown octets attribute (%u) with parent type %s", __FUNCTION__, num, - fr_table_str_by_value(fr_value_box_type_table, parent->type, "")); + fr_type_to_str(parent->type)); return NULL; } @@ -477,8 +477,7 @@ ssize_t fr_dict_unknown_afrom_oid_substr(TALLOC_CTX *ctx, default: fr_strerror_printf("Parent OID component (%s) specified a non-structural type (%s)", our_parent->name, - fr_table_str_by_value(fr_value_box_type_table, - our_parent->type, "")); + fr_type_to_str(our_parent->type)); goto error; } } else { @@ -580,8 +579,7 @@ ssize_t fr_dict_unknown_afrom_oid_substr(TALLOC_CTX *ctx, */ if (fr_sbuff_is_char(in, '.')) { fr_strerror_printf("Interior OID component cannot proceed a %s type", - fr_table_str_by_value(fr_value_box_type_table, - our_parent->type, "")); + fr_type_to_str(our_parent->type)); goto error; } flags.is_raw = is_raw; diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index b982bbbbe1..d97d736f86 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -1012,14 +1012,14 @@ int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child) if (!dict_attr_can_have_children(parent)) { fr_strerror_printf("Cannot add children to attribute '%s' of type %s", parent->name, - fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?")); + fr_type_to_str(parent->type)); return -1; } if ((parent->type == FR_TYPE_VSA) && (child->type != FR_TYPE_VENDOR)) { fr_strerror_printf("Cannot add non-vendor children to attribute '%s' of type %s", parent->name, - fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?")); + fr_type_to_str(parent->type)); return -1; } @@ -1122,7 +1122,7 @@ int dict_attr_add_to_namespace(fr_dict_attr_t const *parent, fr_dict_attr_t *da) ((parent->type == FR_TYPE_VSA) || parent->flags.is_root)) { fr_strerror_printf("Cannot insert attribute '%s' of type %s into %s", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?"), + fr_type_to_str(da->type), parent->name); goto error; } @@ -1181,9 +1181,9 @@ static int dict_attr_compatible(fr_dict_attr_t const *parent, fr_dict_attr_t con fr_strerror_printf_push("Cannot add duplicate attribute with different type " "(old attribute \"%s\" has type %s, new attribute \"%s\" has type %s)", old->name, - fr_table_str_by_value(fr_value_box_type_table, old->type, "?Unknown?"), + fr_type_to_str(old->type), n->name, - fr_table_str_by_value(fr_value_box_type_table, n->type, "?Unknown?")); + fr_type_to_str(n->type)); return -1; } @@ -1322,7 +1322,7 @@ int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_ENUMV); if (!ext) { fr_strerror_printf("VALUE cannot be defined for %s attributes", - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return -1; } @@ -1368,16 +1368,16 @@ int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, if (!coerce) { fr_strerror_printf("%s: Type mismatch between attribute (%s) and enum (%s)", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, ""), - fr_table_str_by_value(fr_value_box_type_table, value->type, "")); + fr_type_to_str(da->type), + fr_type_to_str(value->type)); return -1; } if (fr_value_box_cast(enumv, enum_value, da->type, NULL, value) < 0) { fr_strerror_printf_push("%s: Failed coercing enum type (%s) to attribute type (%s)", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, value->type, ""), - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(value->type), + fr_type_to_str(da->type)); return -1; } @@ -1525,7 +1525,7 @@ int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name) default: fr_strerror_printf("Attribute is wrong type for auto-numbering, expected numeric type, got %s", - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return -1; } @@ -1779,7 +1779,7 @@ ssize_t fr_dict_oid_component(fr_dict_attr_err_t *err, fr_strerror_printf("Attribute '%s' is type %s and cannot contain child attributes. " "Error at OID \"%.*s\"", parent->name, - fr_table_str_by_value(fr_value_box_type_table, parent->type, ""), + fr_type_to_str(parent->type), (int)fr_sbuff_remaining(in), fr_sbuff_current(in)); if (err) *err =FR_DICT_ATTR_NO_CHILDREN; @@ -2224,8 +2224,8 @@ fr_dict_attr_t const *fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root default: fr_strerror_printf("Wrong type for vendor root, expected '%s', got '%s'", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_VSA, ""), - fr_table_str_by_value(fr_value_box_type_table, vendor_root->type, "")); + fr_type_to_str(FR_TYPE_VSA), + fr_type_to_str(vendor_root->type)); return NULL; } @@ -2237,8 +2237,8 @@ fr_dict_attr_t const *fr_dict_vendor_da_by_num(fr_dict_attr_t const *vendor_root if (vendor->type != FR_TYPE_VENDOR) { fr_strerror_printf("Wrong type for vendor, expected '%s' got '%s'", - fr_table_str_by_value(fr_value_box_type_table, vendor->type, ""), - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_VENDOR, "")); + fr_type_to_str(vendor->type), + fr_type_to_str(FR_TYPE_VENDOR)); return NULL; } @@ -2833,7 +2833,7 @@ fr_dict_enum_value_t *fr_dict_enum_by_value(fr_dict_attr_t const *da, fr_value_b ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_ENUMV); if (!ext) { fr_strerror_printf("VALUE cannot be defined for %s attributes", - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return NULL; } @@ -2881,7 +2881,7 @@ fr_dict_enum_value_t *fr_dict_enum_by_name(fr_dict_attr_t const *da, char const ext = fr_dict_attr_ext(da, FR_DICT_ATTR_EXT_ENUMV); if (!ext) { fr_strerror_printf("VALUE cannot be defined for %s attributes", - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return NULL; } @@ -3447,8 +3447,8 @@ int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load) if (da->type != p->type) { fr_strerror_printf("Attribute '%s' should be type %s, but defined as type %s", da->name, - fr_table_str_by_value(fr_value_box_type_table, p->type, "?Unknown?"), - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(p->type), + fr_type_to_str(da->type)); return -1; } @@ -4065,12 +4065,12 @@ void fr_dict_attr_verify(char const *file, int line, fr_dict_attr_t const *da) fr_assert_msg(fr_dict_attr_has_ext(da, FR_DICT_ATTR_EXT_CHILDREN), "CONSISTENCY CHECK FAILED %s[%u]: %s missing 'children' extension", file, line, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); fr_assert_msg(fr_dict_attr_has_ext(da, FR_DICT_ATTR_EXT_NAMESPACE), "CONSISTENCY CHECK FAILED %s[%u]: %s missing 'namespace' extension", file, line, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); /* * Check the namespace hash table is ok diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index 741dfda62e..628e7929f5 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -103,7 +103,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, switch (type) { default: fr_strerror_printf("The 'array' flag cannot be used with attributes of type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; case FR_TYPE_IPV4_ADDR: @@ -228,14 +228,14 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, default: fr_strerror_printf("Type %s cannot hold extra flags", - fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?")); + fr_type_to_str(type)); return false; } if ((flags->subtype == FLAG_LENGTH_UINT16) && ((type != FR_TYPE_STRING) && (type != FR_TYPE_OCTETS) && (type != FR_TYPE_STRUCT))) { fr_strerror_printf("The 'length' flag cannot be used used with type %s", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; } @@ -263,7 +263,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, if ((flags->length != 2) && (flags->length != 4) && (flags->length != 8)) { fr_strerror_printf("Invalid length %u for attribute of type '%s'", - flags->length, fr_table_str_by_value(fr_value_box_type_table, type, "")); + flags->length, fr_type_to_str(type)); return false; } @@ -272,7 +272,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, (flags->flag_time_res != FR_TIME_RES_USEC) && (flags->flag_time_res != FR_TIME_RES_NSEC)) { fr_strerror_printf("Invalid precision for attribute of type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; } break; @@ -323,7 +323,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, if (parent->type != FR_TYPE_VSA) { fr_strerror_printf("Attributes of type 'vendor' MUST have a parent of type 'vsa' " "instead of '%s'", - fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?")); + fr_type_to_str(parent->type)); return false; } @@ -382,7 +382,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, */ if (!v) { fr_strerror_printf("Attributes of type '%s' require a parent attribute", - fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?")); + fr_type_to_str(type)); return false; } @@ -422,7 +422,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, case FR_TYPE_NULL: fr_strerror_printf("Attributes of type '%s' cannot be used in dictionaries", - fr_table_str_by_value(fr_value_box_type_table, type, "?Unknown?")); + fr_type_to_str(type)); return false; default: @@ -442,7 +442,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, (flags->flag_time_res != FR_TIME_RES_MSEC) && (flags->flag_time_res != FR_TIME_RES_NSEC)) { fr_strerror_printf("Invalid precision for attribute of type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; } } else if (!flags->extra) { @@ -548,7 +548,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, default: fr_strerror_printf("Attributes of type '%s' cannot have child attributes", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; } diff --git a/src/lib/util/edit.c b/src/lib/util/edit.c index e088c86baf..4d63ae7ca9 100644 --- a/src/lib/util/edit.c +++ b/src/lib/util/edit.c @@ -1122,7 +1122,7 @@ int fr_edit_list_apply_list_assignment(fr_edit_list_t *el, fr_pair_t *dst, fr_to if (!fr_type_is_structural(dst->vp_type)) { fr_strerror_printf("Cannot perform list assignment to non-structural type '%s'", - fr_table_str_by_value(fr_value_box_type_table, dst->vp_type, "")); + fr_type_to_str(dst->vp_type)); return -1; } @@ -1187,6 +1187,6 @@ int fr_edit_list_apply_list_assignment(fr_edit_list_t *el, fr_pair_t *dst, fr_to fr_strerror_printf("Invalid assignment operator %s for destination type %s", fr_tokens[op], - fr_table_str_by_value(fr_value_box_type_table, dst->vp_type, "")); + fr_type_to_str(dst->vp_type)); return -1; } diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 8ddbb4adb3..5d16e71523 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -292,7 +292,7 @@ fr_pair_t *fr_pair_afrom_da_with_pool(TALLOC_CTX *ctx, fr_dict_attr_t const *da, default: fr_strerror_printf("Pooled fr_pair_t can only be allocated for " "'string' and 'octets' types not '%s'", - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); return NULL; } @@ -1916,7 +1916,7 @@ int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, switch (vp->da->type) { case FR_TYPE_STRUCTURAL: fr_strerror_printf("Attributes of type '%s' are not yet supported", - fr_table_str_by_value(fr_value_box_type_table, vp->da->type, "")); + fr_type_to_str(vp->da->type)); return -1; default: @@ -2629,9 +2629,9 @@ void fr_pair_verify(char const *file, int line, fr_pair_t const *vp) "dictionary pointer %p \"%s\" (%s) " "and global dictionary pointer %p \"%s\" (%s) differ", file, line, vp->da, vp->da->name, - fr_table_str_by_value(fr_value_box_type_table, vp->da->type, ""), + fr_type_to_str(vp->da->type), da, da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + fr_type_to_str(da->type)); } } @@ -2640,8 +2640,8 @@ void fr_pair_verify(char const *file, int line, fr_pair_t const *vp) fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: fr_pair_t (raw/unknown) attribute %p \"%s\" " "data type incorrect. Expected %s, got %s", file, line, vp->da, vp->da->name, - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_OCTETS, ""), - fr_table_str_by_value(fr_value_box_type_table, vp->data.type, "")); + fr_type_to_str(FR_TYPE_OCTETS), + fr_type_to_str(vp->data.type)); } } else if (!fr_type_is_structural(vp->da->type) && (vp->da->type != vp->data.type)) { char data_type_int[10], da_type_int[10]; @@ -2652,8 +2652,8 @@ void fr_pair_verify(char const *file, int line, fr_pair_t const *vp) fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: fr_pair_t attribute %p \"%s\" " "data type (%s) does not match da type (%s)", file, line, vp->da, vp->da->name, - fr_table_str_by_value(fr_value_box_type_table, vp->data.type, data_type_int), - fr_table_str_by_value(fr_value_box_type_table, vp->da->type, da_type_int)); + fr_table_str_by_value(fr_type_table, vp->data.type, data_type_int), + fr_table_str_by_value(fr_type_table, vp->da->type, da_type_int)); } } diff --git a/src/lib/util/proto.c b/src/lib/util/proto.c index 4cce1fec40..5e8edd7daf 100644 --- a/src/lib/util/proto.c +++ b/src/lib/util/proto.c @@ -79,7 +79,7 @@ void fr_proto_da_stack_print(char const *file, int line, char const *func, fr_da fr_log(&default_log, L_DBG, file, line, "stk: %s [%i] %s: %s, vendor: 0x%x (%u), attr: 0x%x (%u)", (i == (int)depth) ? ">" : " ", i, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[i]->type, "?Unknown?"), + fr_type_to_str(da_stack->da[i]->type), da_stack->da[i]->name, fr_dict_vendor_num_by_da(da_stack->da[i]), fr_dict_vendor_num_by_da(da_stack->da[i]), da_stack->da[i]->attr, da_stack->da[i]->attr); diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index c6756f0313..8e1a8f8a23 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -476,7 +476,7 @@ ssize_t fr_struct_to_network(fr_dbuff_t *dbuff, if (parent->type != FR_TYPE_STRUCT) { fr_strerror_printf("%s: Expected type \"struct\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?")); + fr_type_to_str(parent->type)); return -1; } diff --git a/src/lib/util/types.c b/src/lib/util/types.c index fda81d3d59..814c915dbb 100644 --- a/src/lib/util/types.c +++ b/src/lib/util/types.c @@ -26,6 +26,63 @@ RCSID("$Id$") #include #include +/** Map data types to names representing those types + */ +fr_table_num_ordered_t const fr_type_table[] = { + { L("null"), FR_TYPE_NULL }, + { L("string"), FR_TYPE_STRING }, + { L("octets"), FR_TYPE_OCTETS }, + + { L("ipaddr"), FR_TYPE_IPV4_ADDR }, + { L("ipv4addr"), FR_TYPE_IPV4_ADDR }, + { L("ipv4prefix"), FR_TYPE_IPV4_PREFIX }, + { L("ipv6addr"), FR_TYPE_IPV6_ADDR }, + { L("ipv6prefix"), FR_TYPE_IPV6_PREFIX }, + { L("ifid"), FR_TYPE_IFID }, + { L("combo-ip"), FR_TYPE_COMBO_IP_ADDR }, + { L("combo-prefix"), FR_TYPE_COMBO_IP_PREFIX }, + { L("ether"), FR_TYPE_ETHERNET }, + + { L("bool"), FR_TYPE_BOOL }, + + { L("uint8"), FR_TYPE_UINT8 }, + { L("uint16"), FR_TYPE_UINT16 }, + { L("uint32"), FR_TYPE_UINT32 }, + { L("uint64"), FR_TYPE_UINT64 }, + + { L("int8"), FR_TYPE_INT8 }, + { L("int16"), FR_TYPE_INT16 }, + { L("int32"), FR_TYPE_INT32 }, + { L("int64"), FR_TYPE_INT64 }, + + { L("float32"), FR_TYPE_FLOAT32 }, + { L("float64"), FR_TYPE_FLOAT64 }, + + { L("date"), FR_TYPE_DATE }, + { L("time_delta"), FR_TYPE_TIME_DELTA }, + + { L("size"), FR_TYPE_SIZE }, + + { L("tlv"), FR_TYPE_TLV }, + { L("struct"), FR_TYPE_STRUCT }, + + { L("vsa"), FR_TYPE_VSA }, + { L("vendor"), FR_TYPE_VENDOR }, + { L("group"), FR_TYPE_GROUP }, + + /* + * Alternative names + */ + { L("cidr"), FR_TYPE_IPV4_PREFIX }, + { L("byte"), FR_TYPE_UINT8 }, + { L("short"), FR_TYPE_UINT16 }, + { L("integer"), FR_TYPE_UINT32 }, + { L("integer64"), FR_TYPE_UINT64 }, + { L("decimal"), FR_TYPE_FLOAT64 }, + { L("signed"), FR_TYPE_INT32 } +}; +size_t fr_type_table_len = NUM_ELEMENTS(fr_type_table); + #define ARRAY_BEG(_type) { [_type] = true, #define ARRAY_MID(_type) [_type] = true, #define ARRAY_END(_type) [_type] = true } @@ -454,16 +511,16 @@ fr_type_t fr_type_promote(fr_type_t a, fr_type_t b) */ if (unlikely(type_promote_table[a][b] != type_promote_table[b][a])) { fr_strerror_printf("Inverse type mapping inconsistent for a = %s, b = %s", - fr_table_str_by_value(fr_value_box_type_table, a, ""), - fr_table_str_by_value(fr_value_box_type_table, b, "")); + fr_type_to_str(a), + fr_type_to_str(b)); return FR_TYPE_NULL; } if (unlikely(type_promote_table[a][b] == FR_TYPE_NULL)) { fr_strerror_printf("No type promotions for a = %s, b = %s", - fr_table_str_by_value(fr_value_box_type_table, a, ""), - fr_table_str_by_value(fr_value_box_type_table, b, "")); + fr_type_to_str(a), + fr_type_to_str(b)); return FR_TYPE_NULL; } diff --git a/src/lib/util/types.h b/src/lib/util/types.h index ab9876d80e..e25f6324b4 100644 --- a/src/lib/util/types.h +++ b/src/lib/util/types.h @@ -29,6 +29,7 @@ extern "C" { #endif #include +#include /** Internal data types */ @@ -339,6 +340,29 @@ extern bool const fr_type_non_leaf[FR_TYPE_MAX + 1]; #define fr_type_is_non_leaf(_x) (fr_type_non_leaf[_x]) /** @} */ +extern fr_table_num_ordered_t const fr_type_table[]; +extern size_t fr_type_table_len; + +/** Return a static string containing the type name + * + * @param[in] type to return name for. + * @return name of the type + */ +static inline char const *fr_type_to_str(fr_type_t type) +{ + return fr_table_str_by_value(fr_type_table, type, ""); +} + +/** Return the constant value representing a type + * + * @param[in] type to return the constant value for. + * @return The constant type value or FR_TYPE_NULL if no type matches. + */ +static inline fr_type_t fr_type_from_str(char const *type) +{ + return fr_table_value_by_str(fr_type_table, type, FR_TYPE_NULL); +} + bool fr_type_cast(fr_type_t dst, fr_type_t src); fr_type_t fr_type_promote(fr_type_t a, fr_type_t b); diff --git a/src/lib/util/value.c b/src/lib/util/value.c index a9bf31e6a2..11afdafa21 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -94,64 +94,6 @@ static_assert(SIZEOF_MEMBER(fr_value_box_t, vb_float32) == 4, static_assert(SIZEOF_MEMBER(fr_value_box_t, vb_float64) == 8, "vb_float64 has unexpected length"); - -/** Map data types to names representing those types - */ -fr_table_num_ordered_t const fr_value_box_type_table[] = { - { L("null"), FR_TYPE_NULL }, - { L("string"), FR_TYPE_STRING }, - { L("octets"), FR_TYPE_OCTETS }, - - { L("ipaddr"), FR_TYPE_IPV4_ADDR }, - { L("ipv4addr"), FR_TYPE_IPV4_ADDR }, - { L("ipv4prefix"), FR_TYPE_IPV4_PREFIX }, - { L("ipv6addr"), FR_TYPE_IPV6_ADDR }, - { L("ipv6prefix"), FR_TYPE_IPV6_PREFIX }, - { L("ifid"), FR_TYPE_IFID }, - { L("combo-ip"), FR_TYPE_COMBO_IP_ADDR }, - { L("combo-prefix"), FR_TYPE_COMBO_IP_PREFIX }, - { L("ether"), FR_TYPE_ETHERNET }, - - { L("bool"), FR_TYPE_BOOL }, - - { L("uint8"), FR_TYPE_UINT8 }, - { L("uint16"), FR_TYPE_UINT16 }, - { L("uint32"), FR_TYPE_UINT32 }, - { L("uint64"), FR_TYPE_UINT64 }, - - { L("int8"), FR_TYPE_INT8 }, - { L("int16"), FR_TYPE_INT16 }, - { L("int32"), FR_TYPE_INT32 }, - { L("int64"), FR_TYPE_INT64 }, - - { L("float32"), FR_TYPE_FLOAT32 }, - { L("float64"), FR_TYPE_FLOAT64 }, - - { L("date"), FR_TYPE_DATE }, - { L("time_delta"), FR_TYPE_TIME_DELTA }, - - { L("size"), FR_TYPE_SIZE }, - - { L("tlv"), FR_TYPE_TLV }, - { L("struct"), FR_TYPE_STRUCT }, - - { L("vsa"), FR_TYPE_VSA }, - { L("vendor"), FR_TYPE_VENDOR }, - { L("group"), FR_TYPE_GROUP }, - - /* - * Alternative names - */ - { L("cidr"), FR_TYPE_IPV4_PREFIX }, - { L("byte"), FR_TYPE_UINT8 }, - { L("short"), FR_TYPE_UINT16 }, - { L("integer"), FR_TYPE_UINT32 }, - { L("integer64"), FR_TYPE_UINT64 }, - { L("decimal"), FR_TYPE_FLOAT64 }, - { L("signed"), FR_TYPE_INT32 } -}; -size_t fr_value_box_type_table_len = NUM_ELEMENTS(fr_value_box_type_table); - /** How many bytes on-the-wire would a #fr_value_box_t value consume * * This is for the generic NETWORK format. For field sizes in the in-memory @@ -1388,7 +1330,7 @@ ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value) unsupported: fr_strerror_printf("%s: Cannot encode type \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, value->type, "")); + fr_type_to_str(value->type)); return FR_VALUE_BOX_NET_ERROR; } @@ -1656,14 +1598,14 @@ ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, if (len < min) { fr_strerror_printf("Got truncated value parsing type \"%s\". " "Expected length >= %zu bytes, got %zu bytes", - fr_table_str_by_value(fr_value_box_type_table, type, ""), + fr_type_to_str(type), min, len); return -(len); } if (len > max) { fr_strerror_printf("Found trailing garbage parsing type \"%s\". " "Expected length <= %zu bytes, got %zu bytes", - fr_table_str_by_value(fr_value_box_type_table, type, ""), + fr_type_to_str(type), max, len); return -(max); } @@ -1898,7 +1840,7 @@ ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, case FR_TYPE_SIZE: case FR_TYPE_NON_LEAF: fr_strerror_printf("Cannot decode type \"%s\" - Is not a value", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); break; } @@ -1963,7 +1905,7 @@ int fr_value_box_to_key(uint8_t **out, size_t *outlen, fr_value_box_t const *val default: fr_strerror_printf("Invalid data type '%s' for getting key", - fr_table_str_by_value(fr_value_box_type_table, value->type, "")); + fr_type_to_str(value->type)); return -1; } @@ -1989,8 +1931,8 @@ static int fr_value_box_fixed_size_from_octets(fr_value_box_t *dst, if (src->vb_length < network_min_size(dst_type)) { fr_strerror_printf("Invalid cast from %s to %s. Source is length %zd is smaller than " "destination type size %zd", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_length, network_min_size(dst_type)); return -1; @@ -1999,8 +1941,8 @@ static int fr_value_box_fixed_size_from_octets(fr_value_box_t *dst, if (src->vb_length > network_max_size(dst_type)) { fr_strerror_printf("Invalid cast from %s to %s. Source length %zd is greater than " "destination type size %zd", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_length, network_max_size(dst_type)); return -1; @@ -2217,8 +2159,8 @@ static inline int fr_value_box_cast_to_ipv4addr(TALLOC_CTX *ctx, fr_value_box_t if (memcmp(src->vb_ip.addr.v6.s6_addr, v4_v6_map, sizeof(v4_v6_map)) != 0) { bad_v6_prefix_map: fr_strerror_printf("Invalid cast from %s to %s. No IPv4-IPv6 mapping prefix", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -2231,8 +2173,8 @@ static inline int fr_value_box_cast_to_ipv4addr(TALLOC_CTX *ctx, fr_value_box_t if (src->vb_ip.prefix != 32) { fr_strerror_printf("Invalid cast from %s to %s. Only /32 (not %i/) prefixes may be " "cast to IP address types", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_ip.prefix); return -1; } @@ -2243,8 +2185,8 @@ static inline int fr_value_box_cast_to_ipv4addr(TALLOC_CTX *ctx, fr_value_box_t if (src->vb_ip.prefix != 128) { fr_strerror_printf("Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be " "cast to IP address types", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_ip.prefix); return -1; } @@ -2256,8 +2198,8 @@ static inline int fr_value_box_cast_to_ipv4addr(TALLOC_CTX *ctx, fr_value_box_t case FR_TYPE_OCTETS: if (src->vb_length != sizeof(dst->vb_ip.addr.v4.s_addr)) { fr_strerror_printf("Invalid cast from %s to %s. Needed octet string of length %zu, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), sizeof(dst->vb_ip.addr.v4.s_addr), src->vb_length); return -1; } @@ -2275,8 +2217,8 @@ static inline int fr_value_box_cast_to_ipv4addr(TALLOC_CTX *ctx, fr_value_box_t default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -2332,8 +2274,8 @@ static inline int fr_value_box_cast_to_ipv4prefix(TALLOC_CTX *ctx, fr_value_box_ if (memcmp(src->vb_ip.addr.v6.s6_addr, v4_v6_map, sizeof(v4_v6_map)) != 0) { bad_v6_prefix_map: fr_strerror_printf("Invalid cast from %s to %s. No IPv4-IPv6 mapping prefix", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } memcpy(&dst->vb_ip.addr.v4.s_addr, &src->vb_ip.addr.v6.s6_addr[sizeof(v4_v6_map)], @@ -2346,8 +2288,8 @@ static inline int fr_value_box_cast_to_ipv4prefix(TALLOC_CTX *ctx, fr_value_box_ if (src->vb_ip.prefix < (sizeof(v4_v6_map) << 3)) { fr_strerror_printf("Invalid cast from %s to %s. Expected prefix >= %u bits got %u bits", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), (unsigned int)(sizeof(v4_v6_map) << 3), src->vb_ip.prefix); return -1; } @@ -2363,8 +2305,8 @@ static inline int fr_value_box_cast_to_ipv4prefix(TALLOC_CTX *ctx, fr_value_box_ case FR_TYPE_OCTETS: if (src->vb_length != sizeof(dst->vb_ip.addr.v4.s_addr) + 1) { fr_strerror_printf("Invalid cast from %s to %s. Needed octet string of length %zu, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), sizeof(dst->vb_ip.addr.v4.s_addr) + 1, src->vb_length); return -1; } @@ -2384,8 +2326,8 @@ static inline int fr_value_box_cast_to_ipv4prefix(TALLOC_CTX *ctx, fr_value_box_ default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -2452,8 +2394,8 @@ static inline int fr_value_box_cast_to_ipv6addr(TALLOC_CTX *ctx, fr_value_box_t if (src->vb_ip.prefix != 32) { fr_strerror_printf("Invalid cast from %s to %s. Only /32 (not /%i) prefixes may be " "cast to IP address types", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_ip.prefix); return -1; } @@ -2470,8 +2412,8 @@ static inline int fr_value_box_cast_to_ipv6addr(TALLOC_CTX *ctx, fr_value_box_t if (src->vb_ip.prefix != 128) { fr_strerror_printf("Invalid cast from %s to %s. Only /128 (not /%i) prefixes may be " "cast to IP address types", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_ip.prefix); return -1; } @@ -2483,8 +2425,8 @@ static inline int fr_value_box_cast_to_ipv6addr(TALLOC_CTX *ctx, fr_value_box_t case FR_TYPE_OCTETS: if (src->vb_length != sizeof(dst->vb_ip.addr.v6.s6_addr)) { fr_strerror_printf("Invalid cast from %s to %s. Needed octet string of length %zu, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), sizeof(dst->vb_ip.addr.v6.s6_addr), src->vb_length); return -1; } @@ -2493,8 +2435,8 @@ static inline int fr_value_box_cast_to_ipv6addr(TALLOC_CTX *ctx, fr_value_box_t default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); break; } @@ -2574,8 +2516,8 @@ static inline int fr_value_box_cast_to_ipv6prefix(TALLOC_CTX *ctx, fr_value_box_ case FR_TYPE_OCTETS: if (src->vb_length != (sizeof(dst->vb_ip.addr.v6.s6_addr) + 2)) { fr_strerror_printf("Invalid cast from %s to %s. Needed octet string of length %zu, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), sizeof(dst->vb_ip.addr.v6.s6_addr) + 2, src->vb_length); return -1; } @@ -2586,8 +2528,8 @@ static inline int fr_value_box_cast_to_ipv6prefix(TALLOC_CTX *ctx, fr_value_box_ default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } return 0; @@ -2647,8 +2589,8 @@ static inline int fr_value_box_cast_to_ethernet(TALLOC_CTX *ctx, fr_value_box_t default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -2744,8 +2686,8 @@ static inline int fr_value_box_cast_to_bool(TALLOC_CTX *ctx, fr_value_box_t *dst default: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -2774,15 +2716,15 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f */ if (!fr_cond_assert_msg(len > 0, "Invalid cast from %s to %s. " "invalid source type len, expected > 0, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), len)) return -1; if (!fr_cond_assert_msg(len <= sizeof(uint64_t), "Invalid cast from %s to %s. " "invalid source type len, expected <= %zu, got %zu", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), sizeof(uint64_t), len)) return -1; #endif @@ -2843,8 +2785,8 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f if ((int64_t)tmp < min) { fr_strerror_printf("Invalid cast from %s to %s. %"PRId64" " "outside value range %"PRId64"-%"PRIu64, - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), (int64_t)tmp, min, fr_value_box_integer_max[dst_type]); return -1; @@ -2852,8 +2794,8 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f } else if (tmp > fr_value_box_integer_max[dst_type]) { fr_strerror_printf("Invalid cast from %s to %s. %"PRIu64" " "outside value range 0-%"PRIu64, - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), tmp, fr_value_box_integer_max[dst_type]); return -1; } @@ -2998,8 +2940,8 @@ static inline int fr_value_box_cast_to_integer(TALLOC_CTX *ctx, fr_value_box_t * bad_cast: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -3106,8 +3048,8 @@ static inline int fr_value_box_cast_to_float(UNUSED TALLOC_CTX *ctx, fr_value_bo bad_cast: fr_strerror_printf("Invalid cast from %s to %s. Unsupported", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -3141,8 +3083,8 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, if (fr_type_is_non_leaf(dst_type)) { fr_strerror_printf("Invalid cast from %s to %s. Can only cast simple data types", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -3233,8 +3175,8 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, case FR_TYPE_VOID: case FR_TYPE_MAX: fr_strerror_printf("Invalid cast from %s to %s. Invalid destination type", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(src->type), + fr_type_to_str(dst_type)); return -1; } @@ -3251,8 +3193,8 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, if (src->vb_length < network_min_size(dst_type)) { fr_strerror_printf("Invalid cast from %s to %s. Source is length %zd is smaller than " "destination type size %zd", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_length, network_min_size(dst_type)); return -1; @@ -3261,8 +3203,8 @@ int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, if (src->vb_length > network_max_size(dst_type)) { fr_strerror_printf("Invalid cast from %s to %s. Source length %zd is greater than " "destination type size %zd", - fr_table_str_by_value(fr_value_box_type_table, src->type, ""), - fr_table_str_by_value(fr_value_box_type_table, dst_type, ""), + fr_type_to_str(src->type), + fr_type_to_str(dst_type), src->vb_length, network_max_size(dst_type)); return -1; @@ -3402,7 +3344,7 @@ int fr_value_unbox_ipaddr(fr_ipaddr_t *dst, fr_value_box_t *src) { if (!fr_type_is_ip(src->type)) { fr_strerror_printf("Unboxing failed. Needed IPv4/6 addr/prefix, had type %s", - fr_table_str_by_value(fr_value_box_type_table, src->type, "?Unknown?")); + fr_type_to_str(src->type)); return -1; } @@ -4005,8 +3947,8 @@ int fr_value_box_bstrn_append(TALLOC_CTX *ctx, fr_value_box_t *dst, char const * if (dst->type != FR_TYPE_STRING) { fr_strerror_printf("%s: Expected boxed value of type %s, got type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_STRING, ""), - fr_table_str_by_value(fr_value_box_type_table, dst->type, "")); + fr_type_to_str(FR_TYPE_STRING), + fr_type_to_str(dst->type)); return -1; } @@ -4287,8 +4229,8 @@ int fr_value_box_mem_append(TALLOC_CTX *ctx, fr_value_box_t *dst, uint8_t const if (dst->type != FR_TYPE_OCTETS) { fr_strerror_printf("%s: Expected boxed value of type %s, got type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_OCTETS, ""), - fr_table_str_by_value(fr_value_box_type_table, dst->type, "")); + fr_type_to_str(FR_TYPE_OCTETS), + fr_type_to_str(dst->type)); return -1; } @@ -4468,7 +4410,7 @@ fr_slen_t fr_value_box_from_numeric_substr(fr_value_box_t *dst, fr_type_t dst_ty if (err == FR_SBUFF_PARSE_ERROR_NOT_FOUND) { fr_strerror_printf("Failed parsing string as type '%s'", - fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_type_to_str(dst_type)); } else { fr_sbuff_parse_error_to_strerror(err); } @@ -4969,7 +4911,7 @@ parse: break; default: - fr_strerror_printf("Cannot parse input as data type %s", fr_table_str_by_value(fr_value_box_type_table, dst_type, "")); + fr_strerror_printf("Cannot parse input as data type %s", fr_type_to_str(dst_type)); return -1; } @@ -5540,7 +5482,7 @@ int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, default: fr_strerror_printf("Invalid argument. Can't concatenate boxes to type %s", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return -1; } diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 9204a3e50f..658921e221 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -65,9 +65,6 @@ extern "C" { # define _CONST #endif -extern fr_table_num_ordered_t const fr_value_box_type_table[]; -extern size_t fr_value_box_type_table_len; - extern size_t const fr_value_box_field_sizes[]; extern size_t const fr_value_box_offsets[]; @@ -597,8 +594,8 @@ static inline int fr_value_unbox_ethernet_addr(fr_ethernet_t *dst, fr_value_box_ { if (unlikely(src->type != FR_TYPE_ETHERNET)) { \ fr_strerror_printf("Unboxing failed. Needed type %s, had type %s", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_ETHERNET, "?Unknown?"), - fr_table_str_by_value(fr_value_box_type_table, src->type, "?Unknown?")); + fr_type_to_str(FR_TYPE_ETHERNET), + fr_type_to_str(src->type)); return -1; \ } memcpy(dst, src->vb_ether, sizeof(src->vb_ether)); /* Must be src, dst is a pointer */ @@ -609,8 +606,8 @@ static inline int fr_value_unbox_ethernet_addr(fr_ethernet_t *dst, fr_value_box_ static inline int fr_value_unbox_##_field(_ctype *var, fr_value_box_t const *src) { \ if (unlikely(src->type != _type)) { \ fr_strerror_printf("Unboxing failed. Needed type %s, had type %s", \ - fr_table_str_by_value(fr_value_box_type_table, _type, "?Unknown?"), \ - fr_table_str_by_value(fr_value_box_type_table, src->type, "?Unknown?")); \ + fr_type_to_str(_type), \ + fr_type_to_str(src->type)); \ return -1; \ } \ *var = src->vb_##_field; \ diff --git a/src/modules/rlm_cipher/rlm_cipher.c b/src/modules/rlm_cipher/rlm_cipher.c index 3d76ab10bd..a61f68bb71 100644 --- a/src/modules/rlm_cipher/rlm_cipher.c +++ b/src/modules/rlm_cipher/rlm_cipher.c @@ -811,8 +811,8 @@ static xlat_action_t cipher_rsa_verify_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, if (in_head->type != FR_TYPE_OCTETS) { REDEBUG("Signature argument wrong type, expected %s, got %s. " "Use %%{base64_decode:} or %%{hex_decode:} if signature is armoured", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_OCTETS, "?Unknown?"), - fr_table_str_by_value(fr_value_box_type_table, in_head->type, "?Unknown?")); + fr_type_to_str(FR_TYPE_OCTETS), + fr_type_to_str(in_head->type)); return XLAT_ACTION_FAIL; } sig = in_head->vb_octets; diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index 9357aee192..95c3cc74a2 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -538,7 +538,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) default: cf_log_err(conf, "Invalid key data type '%s'", - fr_table_str_by_value(fr_value_box_type_table, inst->key_data_type, "")); + fr_type_to_str(inst->key_data_type)); return -1; } } else { @@ -551,7 +551,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) htype = fr_htrie_hint(inst->key_data_type); if (htype == FR_HTRIE_INVALID) { cf_log_err(conf, "Invalid data type '%s' used for CSV file.", - fr_table_str_by_value(fr_value_box_type_table, inst->key_data_type, "???")); + fr_type_to_str(inst->key_data_type)); return -1; } diff --git a/src/modules/rlm_date/rlm_date.c b/src/modules/rlm_date/rlm_date.c index 0daea91462..7a041112e1 100644 --- a/src/modules/rlm_date/rlm_date.c +++ b/src/modules/rlm_date/rlm_date.c @@ -213,7 +213,7 @@ static xlat_action_t xlat_date_convert(TALLOC_CTX *ctx, fr_dcursor_t *out, return date_convert_string(ctx, out, request, arg->vb_strvalue, inst); default: - REDEBUG("Can't convert type %s into date", fr_table_str_by_value(fr_value_box_type_table, arg->type, "")); + REDEBUG("Can't convert type %s into date", fr_type_to_str(arg->type)); } return XLAT_ACTION_FAIL; diff --git a/src/modules/rlm_expr/rlm_expr.c b/src/modules/rlm_expr/rlm_expr.c index d84e89b18f..5eaa20b8f0 100644 --- a/src/modules/rlm_expr/rlm_expr.c +++ b/src/modules/rlm_expr/rlm_expr.c @@ -285,7 +285,7 @@ static bool get_number(request_t *request, char const **string, int64_t *answer) case FR_TYPE_STRUCTURAL: REDEBUG("Cannot convert %s of type '%s' to integer", - vp->da->name, fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "?Unknown?")); + vp->da->name, fr_type_to_str(vp->vp_type)); goto error; default: diff --git a/src/modules/rlm_files/rlm_files.c b/src/modules/rlm_files/rlm_files.c index d7fc6039eb..8e97aec386 100644 --- a/src/modules/rlm_files/rlm_files.c +++ b/src/modules/rlm_files/rlm_files.c @@ -357,7 +357,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) inst->key_data_type = tmpl_expanded_type(inst->key); if (fr_htrie_hint(inst->key_data_type) == FR_HTRIE_INVALID) { cf_log_err(mctx->inst->conf, "Invalid data type '%s' for 'files' module.", - fr_table_str_by_value(fr_value_box_type_table, inst->key_data_type, "???")); + fr_type_to_str(inst->key_data_type)); return -1; } diff --git a/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c b/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c index b6aec24e5a..1ff65a2357 100644 --- a/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c +++ b/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c @@ -652,7 +652,7 @@ static int match_subword(rlm_isc_dhcp_tokenizer_t *state, char const *cmd, rlm_i semicolon = MAYBE_SEMICOLON; } - type = fr_table_value_by_str(fr_value_box_type_table, type_name, FR_TYPE_NULL); + type = fr_type_from_str(type_name); if (type == FR_TYPE_NULL) { fr_strerror_printf("unknown data type '%.*s'", (int) (next - cmd), cmd); diff --git a/src/modules/rlm_lua/lua.c b/src/modules/rlm_lua/lua.c index 71c2063921..076f872d89 100644 --- a/src/modules/rlm_lua/lua.c +++ b/src/modules/rlm_lua/lua.c @@ -100,7 +100,7 @@ static int fr_lua_marshall(request_t *request, lua_State *L, fr_pair_t const *vp slen = fr_pair_print_value_quoted(&FR_SBUFF_OUT(buff, sizeof(buff)), vp, T_BARE_WORD); if (slen < 0) { REDEBUG("Cannot convert %s to Lua type, insufficient buffer space", - fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "")); + fr_type_to_str(vp->vp_type)); return -1; } @@ -174,7 +174,7 @@ static int fr_lua_marshall(request_t *request, lua_State *L, fr_pair_t const *vp break; case FR_TYPE_NON_LEAF: - REDEBUG("Cannot convert %s to Lua type", fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "")); + REDEBUG("Cannot convert %s to Lua type", fr_type_to_str(vp->vp_type)); return -1; } return 0; diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 73c0abf045..673955850f 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -764,7 +764,7 @@ static int rest_decode_post(UNUSED rlm_rest_t const *instance, UNUSED rlm_rest_s fr_assert(vps); RINDENT(); - RDEBUG3("Type : %s", fr_table_str_by_value(fr_value_box_type_table, da->type, "")); + RDEBUG3("Type : %s", fr_type_to_str(da->type)); q = strchr(p, '&'); len = (!q) ? (rawlen - (p - raw)) : (unsigned)(q - p); diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index baff0c2ded..fbce76b377 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -101,7 +101,7 @@ static xlat_action_t unpack_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, return XLAT_ACTION_FAIL; } - type = fr_table_value_by_str(fr_value_box_type_table, type_vb->vb_strvalue, FR_TYPE_NULL); + type = fr_type_from_str(type_vb->vb_strvalue); if (fr_type_is_null(type)) { REDEBUG("Invalid data type '%s'", type_vb->vb_strvalue); return XLAT_ACTION_FAIL; diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index fbc494a485..e7973dca78 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -212,8 +212,8 @@ static ssize_t decode_raw(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t c child = unknown; /* const issues */ FR_PROTO_TRACE("decode context changed %s:%s -> %s:%s", - fr_table_str_by_value(fr_value_box_type_table, parent->type, ""), parent->name, - fr_table_str_by_value(fr_value_box_type_table, child->type, ""), child->name); + fr_type_to_str(parent->type), parent->name, + fr_type_to_str(child->type), child->name); slen = decode_value(ctx, out, child, data, data_len); if (slen < 0) fr_dict_unknown_free(&child); @@ -333,8 +333,8 @@ static ssize_t decode_tlv(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t c child = unknown; } FR_PROTO_TRACE("decode context changed %s:%s -> %s:%s", - fr_table_str_by_value(fr_value_box_type_table, parent->type, ""), parent->name, - fr_table_str_by_value(fr_value_box_type_table, child->type, ""), child->name); + fr_type_to_str(parent->type), parent->name, + fr_type_to_str(child->type), child->name); tlv_len = decode_value(ctx, out, child, p + 2, p[1]); if (tlv_len < 0) { @@ -543,8 +543,8 @@ ssize_t fr_dhcpv4_decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, if (!da) return -1; } FR_PROTO_TRACE("decode context changed %s:%s -> %s:%s", - fr_table_str_by_value(fr_value_box_type_table, parent->type, ""), parent->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, ""), da->name); + fr_type_to_str(parent->type), parent->name, + fr_type_to_str(da->type), da->name); if (da->type == FR_TYPE_VSA) return decode_vsa(ctx, out, da, data + 2, data[1]); diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index 592643d779..bc1076a9dd 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -499,7 +499,7 @@ static ssize_t encode_vsio_hdr(fr_dbuff_t *dbuff, */ if (da->type != FR_TYPE_VSA) { fr_strerror_printf("%s: Expected type \"vsa\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -518,7 +518,7 @@ static ssize_t encode_vsio_hdr(fr_dbuff_t *dbuff, if (dv->type != FR_TYPE_VENDOR) { fr_strerror_printf("%s: Expected type \"vsa\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, dv->type, "?Unknown?")); + fr_type_to_str(dv->type)); return PAIR_ENCODE_FATAL_ERROR; } diff --git a/src/protocols/dhcpv6/encode.c b/src/protocols/dhcpv6/encode.c index 8f4794e7b2..a202d81010 100644 --- a/src/protocols/dhcpv6/encode.c +++ b/src/protocols/dhcpv6/encode.c @@ -142,7 +142,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, case FR_TYPE_VENDOR: case FR_TYPE_VSA: fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; default: @@ -655,7 +655,7 @@ static ssize_t encode_tlv_hdr(fr_dbuff_t *dbuff, if (da_stack->da[depth]->type != FR_TYPE_TLV) { fr_strerror_printf("%s: Expected type \"tlv\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -715,7 +715,7 @@ static ssize_t encode_vsio_hdr(fr_dbuff_t *dbuff, */ if (da->type != FR_TYPE_VSA) { fr_strerror_printf("%s: Expected type \"vsa\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -727,7 +727,7 @@ static ssize_t encode_vsio_hdr(fr_dbuff_t *dbuff, if (dv->type != FR_TYPE_VENDOR) { fr_strerror_printf("%s: Expected type \"vsa\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, dv->type, "?Unknown?")); + fr_type_to_str(dv->type)); return PAIR_ENCODE_FATAL_ERROR; } diff --git a/src/protocols/dns/encode.c b/src/protocols/dns/encode.c index fede499512..7f97b01841 100644 --- a/src/protocols/dns/encode.c +++ b/src/protocols/dns/encode.c @@ -161,7 +161,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, case FR_TYPE_VSA: case FR_TYPE_GROUP: fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; default: @@ -494,7 +494,7 @@ static ssize_t encode_tlv_hdr(fr_dbuff_t *dbuff, if (da_stack->da[depth]->type != FR_TYPE_TLV) { fr_strerror_printf("%s: Expected type \"tlv\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; } diff --git a/src/protocols/ethernet/ethernet.c b/src/protocols/ethernet/ethernet.c index e74af8e424..193b1eefe7 100644 --- a/src/protocols/ethernet/ethernet.c +++ b/src/protocols/ethernet/ethernet.c @@ -371,8 +371,8 @@ static int fr_ethernet_set_option(void *proto_ctx, fr_proto_opt_group_t group, i case PROTO_OPT_L2_PAYLOAD_LEN: if (in->type != FR_TYPE_SIZE) { fr_strerror_printf("Unboxing failed. Needed type %s, had type %s", - fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_SIZE, "?Unknown?"), - fr_table_str_by_value(fr_value_box_type_table, in->type, "?Unknown?")); + fr_type_to_str(FR_TYPE_SIZE), + fr_type_to_str(in->type)); return -1; } ether_ctx->payload_len = in->vb_size; diff --git a/src/protocols/internal/decode.c b/src/protocols/internal/decode.c index 19209054a5..ef98179cb5 100644 --- a/src/protocols/internal/decode.c +++ b/src/protocols/internal/decode.c @@ -290,7 +290,7 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic case FR_TYPE_VSA: /* An attribute holding vendor definitions */ if (unlikely(unknown)) { fr_strerror_printf("%s: %s can't be marked as unknown", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); fr_dbuff_set(&work_dbuff, &ext_field); goto error; } @@ -300,7 +300,7 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic if (unlikely(tainted)) { bad_tainted: fr_strerror_printf("%s: %s can't be marked as tainted", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); fr_dbuff_set(&work_dbuff, &enc_field); error: if (unknown) fr_dict_unknown_free(&da); @@ -308,7 +308,7 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic } FR_PROTO_TRACE("Decoding %s - %s", da->name, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); slen = internal_decode_pair(ctx, out, parent_da, &work_dbuff, decode_ctx); if (slen <= 0) goto error; diff --git a/src/protocols/internal/encode.c b/src/protocols/internal/encode.c index 138ce1be24..a17041493c 100644 --- a/src/protocols/internal/encode.c +++ b/src/protocols/internal/encode.c @@ -219,7 +219,7 @@ static ssize_t internal_encode(fr_dbuff_t *dbuff, default: fr_strerror_printf("%s: Unexpected attribute type \"%s\"", - __FUNCTION__, fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + __FUNCTION__, fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -250,7 +250,7 @@ static ssize_t internal_encode(fr_dbuff_t *dbuff, FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff) - vlen, "header"); FR_PROTO_HEX_DUMP(fr_dbuff_start(&value_dbuff), vlen, "value %s", - fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "")); + fr_type_to_str(vp->vp_type)); return fr_dbuff_set(dbuff, &work_dbuff); } diff --git a/src/protocols/radius/base.c b/src/protocols/radius/base.c index ec226664a6..8a5b917cd3 100644 --- a/src/protocols/radius/base.c +++ b/src/protocols/radius/base.c @@ -1262,7 +1262,7 @@ static bool attr_valid(UNUSED fr_dict_t *dict, fr_dict_attr_t const *parent, default: fr_strerror_printf("The 'encrypt' flag cannot be used with attributes of type '%s'", - fr_table_str_by_value(fr_value_box_type_table, type, "")); + fr_type_to_str(type)); return false; } diff --git a/src/protocols/radius/decode.c b/src/protocols/radius/decode.c index 1971fb33fd..9879186dca 100644 --- a/src/protocols/radius/decode.c +++ b/src/protocols/radius/decode.c @@ -1451,7 +1451,7 @@ ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out, * Double-check the length after decrypting the * attribute. */ - FR_PROTO_TRACE("Type \"%s\" (%u)", fr_table_str_by_value(fr_value_box_type_table, parent->type, "?Unknown?"), parent->type); + FR_PROTO_TRACE("Type \"%s\" (%u)", fr_type_to_str(parent->type), parent->type); switch (parent->type) { case FR_TYPE_LEAF: diff --git a/src/protocols/radius/encode.c b/src/protocols/radius/encode.c index cab55e6b17..7a0dc35d54 100644 --- a/src/protocols/radius/encode.c +++ b/src/protocols/radius/encode.c @@ -398,7 +398,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, if (fr_type_is_structural(da->type)) { fr_strerror_printf("%s: Called with structural type %s", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -617,7 +617,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, } FR_PROTO_HEX_DUMP(fr_dbuff_start(&work_dbuff), fr_dbuff_used(&work_dbuff), "value %s", - fr_table_str_by_value(fr_value_box_type_table, vp->vp_type, "")); + fr_type_to_str(vp->vp_type)); /* * Rebuilds the TLV stack for encoding the next attribute @@ -1110,7 +1110,7 @@ static ssize_t encode_vendor(fr_dbuff_t *dbuff, if (da->type != FR_TYPE_VENDOR) { fr_strerror_printf("%s: Expected type \"vendor\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -1177,7 +1177,7 @@ static ssize_t encode_vsa(fr_dbuff_t *dbuff, if (da->type != FR_TYPE_VSA) { fr_strerror_printf("%s: Expected type \"vsa\" got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da->type, "?Unknown?")); + fr_type_to_str(da->type)); return PAIR_ENCODE_FATAL_ERROR; } @@ -1357,7 +1357,7 @@ static ssize_t encode_rfc(fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned i case FR_TYPE_VENDOR: /* FR_TYPE_STRUCT is actually allowed... */ fr_strerror_printf("%s: Expected leaf type got \"%s\"", __FUNCTION__, - fr_table_str_by_value(fr_value_box_type_table, da_stack->da[depth]->type, "?Unknown?")); + fr_type_to_str(da_stack->da[depth]->type)); return PAIR_ENCODE_FATAL_ERROR; default: