]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add fr_type_from_str and fr_type_to_str
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Jan 2022 22:01:21 +0000 (16:01 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Jan 2022 22:01:21 +0000 (16:01 -0600)
Which more than halves the length of the function call...

51 files changed:
src/bin/radict.c
src/bin/unit_test_attribute.c
src/lib/eap_aka_sim/decode.c
src/lib/eap_aka_sim/encode.c
src/lib/json/json.c
src/lib/server/cf_parse.c
src/lib/server/command.c
src/lib/server/cond_eval.c
src/lib/server/cond_tokenize.c
src/lib/server/snmp.c
src/lib/server/tmpl_tokenize.c
src/lib/unlang/compile.c
src/lib/unlang/edit.c
src/lib/unlang/xlat_builtin.c
src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_pair.c
src/lib/util/calc.c
src/lib/util/dict_ext_priv.h
src/lib/util/dict_fixup.c
src/lib/util/dict_print.c
src/lib/util/dict_tokenize.c
src/lib/util/dict_unknown.c
src/lib/util/dict_util.c
src/lib/util/dict_validate.c
src/lib/util/edit.c
src/lib/util/pair.c
src/lib/util/proto.c
src/lib/util/struct.c
src/lib/util/types.c
src/lib/util/types.h
src/lib/util/value.c
src/lib/util/value.h
src/modules/rlm_cipher/rlm_cipher.c
src/modules/rlm_csv/rlm_csv.c
src/modules/rlm_date/rlm_date.c
src/modules/rlm_expr/rlm_expr.c
src/modules/rlm_files/rlm_files.c
src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c
src/modules/rlm_lua/lua.c
src/modules/rlm_rest/rest.c
src/modules/rlm_unpack/rlm_unpack.c
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv4/encode.c
src/protocols/dhcpv6/encode.c
src/protocols/dns/encode.c
src/protocols/ethernet/ethernet.c
src/protocols/internal/decode.c
src/protocols/internal/encode.c
src/protocols/radius/base.c
src/protocols/radius/decode.c
src/protocols/radius/encode.c

index 1d0b439e83921f4900a62c8a8f8d45d4c3f38806..e784bce3119316674bf769bd3de14f930c1ba27b 100644 (file)
@@ -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);
index ea1ac85a26b5c52274463dcd667e98bcf3ca543c..c778ca88681d6b619674cff3b7a3d3b0e7851f63 100644 (file)
@@ -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);
                }
index 253e926314f0cbb57e2256a89594742ea587b5af..8482c2a8e0ea116dab0febae9833d05e1d88150f 100644 (file)
@@ -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
index bd612c26b8c510b1fdb1a6ec48f7bff10c10c644..d510bbba692af7b331b1eae194b45780753932a9 100644 (file)
@@ -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;
        }
 
index f78745541bcdafa17415405a829ea861c51e657b..784b28da27fa6fca5255fa8fe684be6c2183d9f5 100644 (file)
@@ -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, "<INVALID>")));
+                       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, "<INVALID>")));
+                       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);
                }
 
index 3012cff411ed344ff0f7e1463d76ef253f5d0d8c..c05af69171835160a8c928b10e712407a65b4523 100644 (file)
@@ -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;
        }
 
index c42384e8e51b19dd428f4feba260158856f5f031..d871c947a673468e3992cefb55b4a110ce57e561 100644 (file)
@@ -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:
index e6d9c418eef04aae93401738d0968d6fc2cb7f53..4f311da23f3694941e3b587463f46883710d5034 100644 (file)
@@ -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;
        }
 
index ec7d46256947534afc688eebbb057d18d39a581d..038d8172034b3589eb083cf1cba6a646b4a59ed0 100644 (file)
@@ -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), "<INVALID>"),
-                     fr_table_str_by_value(fr_value_box_type_table, tmpl_value_type(vpt), "<INVALID>"));
+                     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;
 }
index 27cefa8ea954722a5c405c74627daad3befd826f..ef29ca265c4cea274dfb8d68fa788f20e2003f78 100644 (file)
@@ -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;
        }
 
index 92d3edd269fd8cc2c1674b8704b6a2ab38ed5b4b..56b277d9c4ede2f53636ccd586660eb76e73be59 100644 (file)
@@ -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, "<INVALID>"),
-                            fr_table_str_by_value(fr_value_box_type_table, ar->da->type, "<INVALID>"),
+                            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), "<INVALID>"));
+               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, "<INVALID>"));
+                                          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, "<UNKNOWN>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, da->type, "<UNKNOWN>"));
+                                  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, "<INVALID>"));
+                                                    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, "<INVALID>"),
+                                                    fr_type_to_str(tmpl_da(vpt)->type),
                                                     da, da->name,
-                                                    fr_table_str_by_value(fr_value_box_type_table, da->type, "<INVALID>"));
+                                                    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");
                }
index ac2231c6571ee30962772e9c08e4d40643b1ce7c..fea00cb78c52e9ff05519bb06749aeb4cc41c265 100644 (file)
@@ -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, "<UNKNOWN>"),
+                                                          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, "<INVALID>"));
+                          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, "<INVALID>"));
+                               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, "<INVALID>"),
-                                   fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "<INVALID>"));
+                                   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, "<INVALID>"),
-                                   fr_table_str_by_value(fr_value_box_type_table, tmpl_da(map->lhs)->type, "<INVALID>"));
+                                   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;
        }
 
index 64f4d72d60db8324d25ec226a41a2413ca955dfa..81955e7e52c458eae3e3629224ffbe668bcec0d0 100644 (file)
@@ -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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, state->lhs.vp->vp_type, "<INVALID>"));
+                                          fr_type_to_str(rhs_box->type),
+                                          fr_type_to_str(state->lhs.vp->vp_type));
                        return -1;
                }
 
index ccca6acc4b8cf7597108c38c1f4642c3ad4bd516..5ed909be2185b33ce219460ce0de7e5c1c1650be 100644 (file)
@@ -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, "<INVALID>"));
+               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;
 
index db49c11751b80504b9ca8dd7c0761307ec362cc4..ea2250303af7d55cd16074957558302f9e65bc4f 100644 (file)
@@ -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, "<INVALID>")));
+                                                      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;
index 04a2e9e1a57cfcea69715c80431dfb1e925462aa..e3c244013ea757edc7ece9032da868c6aecf819f 100644 (file)
@@ -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, "<INVALID>"),
-                               fr_table_str_by_value(fr_value_box_type_table, vb->type, "<INVALID>"));
+                               fr_type_to_str(FR_TYPE_OCTETS),
+                               fr_type_to_str(vb->type));
                        continue;
                }
 
index e46301e2426b31b3d09d9864cca71ba42e49275e..95f446b48fb96a8ec60026dc360aad3d827a9eda 100644 (file)
@@ -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, "<INVALID>"));
+                          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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                          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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                          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, "<INVALID>"),
+                                                  fr_type_to_str(a->type),
                                                   fr_tokens[op],
-                                                  fr_table_str_by_value(fr_value_box_type_table, b->type, "<INVALID>"));
+                                                  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, "<INVALID>"));
+                                          fr_type_to_str(hint));
                        rcode = -1;
                        break;
                }
index 1e61227594e74b137711fa9e625567abac463bfb..aa8d3b59c68c7034866feb6b405f98f3b9b78370 100644 (file)
@@ -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, "<UNKNOWN>"));
+                                  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, "<UNKNOWN>"));
+                                  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, "<UNKNOWN>"));
+                                  fr_type_to_str(da->type));
                return NULL;
        }
        return ext->children;
index 9ef2c58c359ba113f21ba0730432ec7cd491a0ee..2a3e0146b54987c41b378271095da05d5c462474 100644 (file)
@@ -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, "<UNKNOWN>"),
+                                          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, "<UNKNOWN>"),
+                                          fr_type_to_str(fixup->da->type),
                                           fr_cwd_strip(fixup->common.filename), fixup->common.line);
                        return -1;
                }
index bca36b7acd90986986270039a812b4a5dd3e336d..499bc4e2c61d386f2a249c54c98503619fe8dd75 100644 (file)
@@ -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, "<INVALID>"),
+                    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;
index a41bb9f92d8db3f0944dc2e5bfa90ec6d6562ec6..d148b8b0d5c00b179ddfaf97a3651ae725d86ab8 100644 (file)
@@ -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, "<UNKNOWN>"),
+                                                          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, "<UNKNOWN>"),
+                                                          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, "<UNKNOWN>"));
+                                                  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, "<INVALID>"));
+                                       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, "<INVALID>"));
+                                       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 */
index b075d6d747c2d0aaf8d160a4cbfd66e90f03640e..3b3c29d0dbeb54deef546779349e3b0ae21b28bf 100644 (file)
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                                  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, "<INVALID>"));
+                                                          fr_type_to_str(our_parent->type));
                                        goto error;
                                }
                                flags.is_raw = is_raw;
index b982bbbbe1ef4b2be545f72c75f7ac6f10103523..d97d736f8676b406d35ac9a607ae8c0fe9a1b8b1 100644 (file)
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, value->type, "<INVALID>"));
+                                          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, "<INVALID>"),
-                                               fr_table_str_by_value(fr_value_box_type_table, da->type, "<INVALID>"));
+                                               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, "<UNKNOWN>"),
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, vendor_root->type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, FR_TYPE_VENDOR, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                             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, "<INVALID>"));
+                             fr_type_to_str(da->type));
 
                /*
                 *      Check the namespace hash table is ok
index 741dfda62e027cdf676db546159efd851b137e43..628e7929f59c833f34246c95ad9ec94e14a1cbb4 100644 (file)
@@ -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, "<UNKNOWN>"));
+                                          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, "<UNKNOWN>"));
+                                          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, "<UNKNOWN>"));
+                                          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, "<UNKNOWN>"));
+                                          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, "<UNKNOWN>"));
+                                                  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, "<UNKNOWN>"));
+                                  fr_type_to_str(type));
                return false;
        }
 
index e088c86baffd95c0d3469ae635d00e23a2843728..4d63ae7ca97bf9112967f993b79334fb8367d01a 100644 (file)
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                          fr_type_to_str(dst->vp_type));
        return -1;
 }
index 8ddbb4adb303479e5c021de629150495833461b9..5d16e715235c75f3ac840c66ab7cb7eefec7f512 100644 (file)
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"),
+                                            fr_type_to_str(vp->da->type),
                                             da, da->name,
-                                            fr_table_str_by_value(fr_value_box_type_table, da->type, "<INVALID>"));
+                                            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, "<INVALID>"),
-                                            fr_table_str_by_value(fr_value_box_type_table, vp->data.type, "<INVALID>"));
+                                            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));
        }
 }
 
index 4cce1fec40c1f745dc75267eff54371d15e0f661..5e8edd7daf52840db8da33eb9a7cba8294430d24 100644 (file)
@@ -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);
index c6756f03131aeed108ee8eb0b89ffe6576c5ccc1..8e1a8f8a231a68eb60b97d2d43bb8770cce15b2c 100644 (file)
@@ -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;
        }
 
index fda81d3d595ef0698e9738f45c8b3c6ba1418b87..814c915dbb9a36e3fc20fabf8245da56e650f782 100644 (file)
@@ -26,6 +26,63 @@ RCSID("$Id$")
 #include <freeradius-devel/util/types.h>
 #include <freeradius-devel/util/value.h>
 
+/** 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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, b, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, b, "<INVALID>"));
+                                  fr_type_to_str(a),
+                                  fr_type_to_str(b));
                return FR_TYPE_NULL;
        }
 
index ab9876d80edb5d84975ba4b4464cfdd63cca08d8..e25f6324b4df71d742cf08561e014962b5fe46bc 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
 #endif
 
 #include <stdbool.h>
+#include <freeradius-devel/util/table.h>
 
 /** 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, "<INVALID>");
+}
+
+/** 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);
 
index a9bf31e6a2899c5587aa05ede3d07fdeac6d54cb..11afdafa210297a5c2cf88cea7ef6854e3e56372 100644 (file)
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"),
+                                  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, "<INVALID>"),
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                               fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                               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, "<INVALID>"),
-                               fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                               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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                  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, "<INVALID>"),
-                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                          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, "<INVALID>"),
-                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                          fr_table_str_by_value(fr_value_box_type_table, dst_type, "<INVALID>"),
+                                          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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst->type, "<INVALID>"));
+                                  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, "<INVALID>"),
-                                  fr_table_str_by_value(fr_value_box_type_table, dst->type, "<INVALID>"));
+                                  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, "<INVALID>"));
+                                          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, "<INVALID>"));
+               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, "<INVALID>"));
+                                  fr_type_to_str(type));
                return -1;
        }
 
index 9204a3e50f9a9c04e80411b79c047d6191b2d241..658921e2212b6dd5f6aa107996d20ff8c92d3395 100644 (file)
@@ -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; \
index 3d76ab10bd2cbad76debf748609cdcee5f84d3bb..a61f68bb717e73023402b5bf42f6ba4f409e0172 100644 (file)
@@ -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:<text>} or %%{hex_decode:<text>} 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;
index 9357aee1923af29be174f427623ac5a7f6068c87..95c3cc74a2201cf77a71dbab82d8add7f936888e 100644 (file)
@@ -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, "<INVALID>"));
+                                  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;
        }
 
index 0daea91462075b59573fbb353b22e1c3ac8c0db4..7a041112e1fcfb4096beb78f4d2ac559bb9427c4 100644 (file)
@@ -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, "<INVALID>"));
+               REDEBUG("Can't convert type %s into date", fr_type_to_str(arg->type));
        }
 
        return XLAT_ACTION_FAIL;
index d84e89b18fc07e18af2bea11cda2d6dd2f213447..5eaa20b8f0fd49128667a6721f0f9259c740dec1 100644 (file)
@@ -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:
index d7fc6039ebdd9bf653b855d72eff6fd7dc309b76..8e97aec386a8ca516cbaa50bcdad92685de57a9d 100644 (file)
@@ -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;
        }
 
index b6aec24e5a6121f8564fc32eaadf3c4e6941ac51..1ff65a235744aba99e628dc6ec5a9bdd08a1406c 100644 (file)
@@ -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);
index 71c2063921f0b78d9b3f8199155ef21ab5fbfa53..076f872d89e87c2833a9f1f393bdbd1d2f3e5ec8 100644 (file)
@@ -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, "<INVALID>"));
+                               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, "<INVALID>"));
+               REDEBUG("Cannot convert %s to Lua type", fr_type_to_str(vp->vp_type));
                return -1;
        }
        return 0;
index 73c0abf045e4cc36d54464c279645f379432f130..673955850f928bf8f861905fcf16d0ad2f8d40f5 100644 (file)
@@ -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, "<INVALID>"));
+               RDEBUG3("Type  : %s", fr_type_to_str(da->type));
 
                q = strchr(p, '&');
                len = (!q) ? (rawlen - (p - raw)) : (unsigned)(q - p);
index baff0c2dedd7385923a9ca38d9b0d60bfef67611..fbce76b3772dc63f98c2263682a7533e62ab8e1e 100644 (file)
@@ -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;
index fbc494a48593bec81007e73aeacc35d2db1699dc..e7973dca78517ae0b0dcc899f8d3508c133997a3 100644 (file)
@@ -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, "<invalid>"), parent->name,
-                      fr_table_str_by_value(fr_value_box_type_table, child->type, "<invalid>"), 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, "<invalid>"), parent->name,
-                              fr_table_str_by_value(fr_value_box_type_table, child->type, "<invalid>"), 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, "<invalid>"), parent->name,
-                      fr_table_str_by_value(fr_value_box_type_table, da->type, "<invalid>"), 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]);
 
index 592643d7796bbf4acf1dfe862717d3bd342644f0..bc1076a9dd0930f085f168094628c87498900227 100644 (file)
@@ -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;
        }
 
index 8f4794e7b25be59ec27e08c1b86ebec6dad9088f..a202d8101084ddb38dea40625ac0d65e9db33e32 100644 (file)
@@ -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;
        }
 
index fede49951284d8d3b9eb3702db0a88935f983ab4..7f97b01841b474cdf590fb21b9c60469ba33000a 100644 (file)
@@ -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;
        }
 
index e74af8e4244aeef79b8ed878b05e49c05f41ced3..193b1eefe7efced55d066dcf9f98a193ad745e56 100644 (file)
@@ -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;
index 19209054a50d51375cae77dd4f4c36b2cdd8bdba..ef98179cb522f5557c291290350f79eec4f324e7 100644 (file)
@@ -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;
index 138ce1be24698b06cf3e70ba4af280847130317d..a17041493c87197103fe76220e37298fb77cecfa 100644 (file)
@@ -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, "<UNKNOWN>"));
+                         fr_type_to_str(vp->vp_type));
 
        return fr_dbuff_set(dbuff, &work_dbuff);
 }
index ec226664a6fd53314cc095a0c5416e7adeca6f13..8a5b917cd371aa1d04380548614f77caeedf35cc 100644 (file)
@@ -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, "<UNKNOWN>"));
+                                  fr_type_to_str(type));
                return false;
        }
 
index 1971fb33fdbf984fcf7ba448f0ebc6b123263292..9879186dca1269c9785755f68bc88acff0a73cec 100644 (file)
@@ -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:
index cab55e6b17e2d3c914bd75536875e585a24deee3..7a0dc35d54eade42c0aab5a16e50dba9c55a9980 100644 (file)
@@ -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, "<UNKNOWN>"));
+                         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: