From: Arran Cudbard-Bell Date: Mon, 24 Jan 2022 22:20:54 +0000 (-0600) Subject: Use more type specific type printing parsing functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8df1a44bf72a2bbfb02557242b4bb35efc780a4;p=thirdparty%2Ffreeradius-server.git Use more type specific type printing parsing functions --- diff --git a/src/lib/ldap/map.c b/src/lib/ldap/map.c index 1938bb5fe3..4384e6a8e4 100644 --- a/src/lib/ldap/map.c +++ b/src/lib/ldap/map.c @@ -204,7 +204,7 @@ int fr_ldap_map_verify(map_t *map, UNUSED void *instance) default: cf_log_err(map->ci, "Left hand side of map must be an attribute or list, not a %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); return -1; } @@ -225,7 +225,7 @@ int fr_ldap_map_verify(map_t *map, UNUSED void *instance) default: cf_log_err(map->ci, "Right hand side of map must be an xlat, attribute, exec, or literal, not a %s", - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "")); + tmpl_type_to_str(map->rhs->type)); return -1; } diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index c05af69171..dddaf63105 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -252,7 +252,7 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM if (attribute && (!tmpl_is_attr(vpt) && !tmpl_is_attr_unresolved(vpt))) { cf_log_err(cp, "Expected attr got %s", - fr_table_str_by_value(tmpl_type_table, vpt->type, "???")); + tmpl_type_to_str(vpt->type)); return -1; } @@ -1331,7 +1331,7 @@ static int cf_parse_tmpl_pass2(UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR if (attribute && !tmpl_is_attr(vpt)) { cf_log_err(cp, "Expected attr got %s", - fr_table_str_by_value(tmpl_type_table, vpt->type, "???")); + tmpl_type_to_str(vpt->type)); return -1; } diff --git a/src/lib/server/cond_eval.c b/src/lib/server/cond_eval.c index 4f311da23f..5aecc84e9d 100644 --- a/src/lib/server/cond_eval.c +++ b/src/lib/server/cond_eval.c @@ -624,8 +624,8 @@ static bool cond_eval_map(request_t *request, fr_cond_t const *c, #endif EVAL_DEBUG(">>> MAP TYPES LHS: %s, RHS: %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "???"), - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "???")); + tmpl_type_to_str(map->lhs->type), + tmpl_type_to_str(map->rhs->type)); #ifdef WITH_EVAL_DEBUG tmpl_debug(map->lhs); tmpl_debug(map->rhs); diff --git a/src/lib/server/map.c b/src/lib/server/map.c index ad435f5f21..667c77c7a3 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -49,8 +49,8 @@ RCSID("$Id$") static void map_dump(request_t *request, map_t const *map) { RDEBUG2(">>> MAP TYPES LHS: %s, RHS: %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "???"), - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "???")); + tmpl_type_to_str(map->lhs->type), + tmpl_type_to_str(map->rhs->type)); if (map->rhs) { RDEBUG2(">>> MAP NAMES %s %s", map->lhs->name, map->rhs->name); @@ -1480,7 +1480,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f !tmpl_is_attr(map->lhs)) { REDEBUG("Left side \"%.*s\" of map should be an attr or list but is an %s", (int)map->lhs->len, map->lhs->name, - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); rcode = -2; goto finish; } diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index 4b278a9c81..a308c13aa8 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -590,7 +590,33 @@ typedef struct { */ #define tmpl_assert_type(_cond) \ fr_assert_msg(_cond, "Unexpected tmpl type '%s'", \ - fr_table_str_by_value(tmpl_type_table, vpt->type, "")) + tmpl_type_to_str(vpt->type)) + + +/** @name Functions for printing and parsing tmpl type names + * + * @{ + */ +/** Return a static string containing the type name + * + * @param[in] type to return name for. + * @return name of the type + */ +static inline char const *tmpl_type_to_str(tmpl_type_t type) +{ + return fr_table_str_by_value(tmpl_type_table, type, ""); +} + +/** Return the constant value representing a type + * + * @param[in] type to return the constant value for. + * @return The constant type value or TMPL_TYPE_UNINITIALISED if no type matches. + */ +static inline tmpl_type_t tmpl_type_from_str(char const *type) +{ + return fr_table_value_by_str(tmpl_type_table, type, TMPL_TYPE_UNINITIALISED); +} +/** @} */ /** @name Field accessors for #TMPL_TYPE_ATTR, #TMPL_TYPE_ATTR_UNRESOLVED, #TMPL_TYPE_LIST * diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index e5166b9cf3..f062be0c83 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -217,12 +217,12 @@ void tmpl_attr_debug(tmpl_t const *vpt) default: FR_FAULT_LOG("%s can't print tmpls of type %s", __FUNCTION__, - fr_table_str_by_value(tmpl_type_table, vpt->type, "")); + tmpl_type_to_str(vpt->type)); return; } FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pV\" (%p)", - fr_table_str_by_value(tmpl_type_table, vpt->type, ""), + tmpl_type_to_str(vpt->type), vpt->type, fr_box_strvalue_len(vpt->name, vpt->len), vpt); @@ -257,7 +257,7 @@ void tmpl_debug(tmpl_t const *vpt) } FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pR\" (%p)", - fr_table_str_by_value(tmpl_type_table, vpt->type, ""), + tmpl_type_to_str(vpt->type), vpt->type, fr_box_strvalue_len(vpt->name, vpt->len), vpt); @@ -960,7 +960,7 @@ void tmpl_attr_rewrite_num(tmpl_t *vpt, int16_t from, int16_t to) void tmpl_attr_set_request(tmpl_t *vpt, tmpl_request_ref_t request) { fr_assert_msg(tmpl_is_attr(vpt), "Expected tmpl type 'attr', got '%s'", - fr_table_str_by_value(tmpl_type_table, vpt->type, "")); + tmpl_type_to_str(vpt->type)); if (tmpl_request_list_num_elements(&vpt->data.attribute.rr) > 0) tmpl_request_list_talloc_reverse_free(&vpt->data.attribute.rr); @@ -2075,7 +2075,7 @@ ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, if (slen != name_len) { /* This looks wrong, but it produces meaningful errors for unknown attrs */ fr_strerror_printf("Unexpected text after %s", - fr_table_str_by_value(tmpl_type_table, (*out)->type, "")); + tmpl_type_to_str((*out)->type)); return -slen; } @@ -2540,8 +2540,8 @@ static ssize_t tmpl_afrom_integer_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff * @param[in] p_rules Formatting rules for the tmpl. * @param[in] t_rules Validation rules for attribute references. * @return - * - <= 0 on error (offset as negative integer) - * - > 0 on success (number of bytes parsed). + * - < 0 on error (offset as negative integer) + * - >= 0 on success (number of bytes parsed). * * @see REMARKER to produce pretty error markers from the return value. * @@ -4059,7 +4059,7 @@ ssize_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, } fr_assert_fail("Can't print invalid tmpl type %s", - fr_table_str_by_value(tmpl_type_table, vpt->type, "")); + tmpl_type_to_str(vpt->type)); break; } diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index fea00cb78c..e4e47ef2f3 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -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_type_to_str(c->data.map->lhs->type)); + tmpl_type_to_str(c->data.map->lhs->type)); return false; } @@ -811,7 +811,7 @@ static int unlang_fixup_map(map_t *map, UNUSED void *ctx) default: cf_log_err(map->ci, "Left side of map must be an attribute " "or an xlat (that expands to an attribute), not a %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); return -1; } @@ -1619,7 +1619,7 @@ static int unlang_fixup_edit(map_t *map, void *ctx) default: cf_log_err(map->ci, "Left side of map must be an attribute " "or an xlat (that expands to an attribute), not a %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); return -1; } @@ -2861,7 +2861,7 @@ static unlang_t *compile_foreach(unlang_t *parent, unlang_compile_t *unlang_ctx, if (!tmpl_is_attr(vpt) && !tmpl_is_list(vpt)) { cf_log_err(cs, "MUST use attribute or list reference (not %s) in 'foreach'", - fr_table_str_by_value(tmpl_type_table, vpt->type, "???")); + tmpl_type_to_str(vpt->type)); talloc_free(vpt); return NULL; } @@ -3557,7 +3557,7 @@ get_packet_type: if (!tmpl_contains_attr(src_vpt)) { cf_log_err(cs, "Invalid argument to 'subrequest' src must be an attr or list, got %s", - fr_table_str_by_value(tmpl_type_table, src_vpt->type, "")); + tmpl_type_to_str(src_vpt->type)); talloc_free(src_vpt); goto error; } @@ -3577,7 +3577,7 @@ get_packet_type: if (!tmpl_contains_attr(dst_vpt)) { cf_log_err(cs, "Invalid argument to 'subrequest' dst must be an " "attr or list, got %s", - fr_table_str_by_value(tmpl_type_table, src_vpt->type, "")); + tmpl_type_to_str(src_vpt->type)); talloc_free(src_vpt); talloc_free(dst_vpt); goto error; diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 5ed909be21..748ef62d5c 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1398,7 +1398,7 @@ static xlat_action_t xlat_func_map(TALLOC_CTX *ctx, fr_dcursor_t *out, default: REDEBUG("Unexpected type %s in left hand side of expression", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); return XLAT_ACTION_FAIL; } @@ -1414,7 +1414,7 @@ static xlat_action_t xlat_func_map(TALLOC_CTX *ctx, fr_dcursor_t *out, default: REDEBUG("Unexpected type %s in right hand side of expression", - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "")); + tmpl_type_to_str(map->rhs->type)); return XLAT_ACTION_FAIL; } diff --git a/src/modules/rlm_cache/serialize.c b/src/modules/rlm_cache/serialize.c index fafbf44a0a..b0da2bc25f 100644 --- a/src/modules/rlm_cache/serialize.c +++ b/src/modules/rlm_cache/serialize.c @@ -131,14 +131,14 @@ int cache_deserialize(rlm_cache_entry_t *c, fr_dict_t const *dict, char *in, ssi if (!tmpl_is_attr(map->lhs)) { fr_strerror_printf("Pair left hand side \"%s\" parsed as %s, needed attribute. " "Check local dictionaries", map->lhs->name, - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); goto error; } if (!tmpl_is_unresolved(map->rhs)) { fr_strerror_printf("Pair right hand side \"%s\" parsed as %s, needed literal. " "Check serialized data quoting", map->rhs->name, - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "")); + tmpl_type_to_str(map->rhs->type)); goto error; } diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index 95c3cc74a2..c0b68399bf 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -407,7 +407,7 @@ static int csv_map_verify(map_t *map, void *instance) default: cf_log_err(map->ci, "Left hand side of map must be an attribute or list, not a %s", - fr_table_str_by_value(tmpl_type_table, map->lhs->type, "")); + tmpl_type_to_str(map->lhs->type)); return -1; } @@ -448,7 +448,7 @@ static int csv_map_verify(map_t *map, void *instance) default: cf_log_err(map->ci, "Right hand side of map must be a field name, not a %s", - fr_table_str_by_value(tmpl_type_table, map->rhs->type, "")); + tmpl_type_to_str(map->rhs->type)); return -1; } @@ -1031,7 +1031,7 @@ static unlang_action_t CC_HINT(nonnull) mod_process(rlm_rcode_t *p_result, modul if (slen < 0) { talloc_free(key); DEBUG("Failed casting %pV to data type '%s'", - &key, fr_table_str_by_value(tmpl_type_table, inst->key_data_type, "")); + &key, tmpl_type_to_str(inst->key_data_type)); RETURN_MODULE_FAIL; } } diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index c36c0a52ce..a6f886b3a7 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -457,7 +457,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) if (inst->requested_address) { if (!tmpl_is_xlat(inst->requested_address)) { cf_log_err(conf, "requested_address must be a double quoted expansion, not %s", - fr_table_str_by_value(tmpl_type_table, inst->requested_address->type, "")); + tmpl_type_to_str(inst->requested_address->type)); } }