]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use more type specific type printing parsing functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Jan 2022 22:20:54 +0000 (16:20 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 24 Jan 2022 22:23:48 +0000 (16:23 -0600)
src/lib/ldap/map.c
src/lib/server/cf_parse.c
src/lib/server/cond_eval.c
src/lib/server/map.c
src/lib/server/tmpl.h
src/lib/server/tmpl_tokenize.c
src/lib/unlang/compile.c
src/lib/unlang/xlat_builtin.c
src/modules/rlm_cache/serialize.c
src/modules/rlm_csv/rlm_csv.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 1938bb5fe3da113a65bf1ef40e4f9d20d3c009b2..4384e6a8e4ac29ecfe3910e5afb398d520bea8fa 100644 (file)
@@ -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, "<INVALID>"));
+                          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, "<INVALID>"));
+                          tmpl_type_to_str(map->rhs->type));
                return -1;
        }
 
index c05af69171835160a8c928b10e712407a65b4523..dddaf6310537ab0ea74f39ffc3fbd469f601c69d 100644 (file)
@@ -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;
        }
 
index 4f311da23f3694941e3b587463f46883710d5034..5aecc84e9dbe1354f97b0764e3538e945a8f3cd6 100644 (file)
@@ -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);
index ad435f5f219d7ee02474f820cb024b94625ace32..667c77c7a3396b3867e7aa1904af5549c6009bfa 100644 (file)
@@ -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, "<INVALID>"));
+                       tmpl_type_to_str(map->lhs->type));
                rcode = -2;
                goto finish;
        }
index 4b278a9c8131a907002534a9e4063563077bbabd..a308c13aa8d14d19c339684bc71acb686122208c 100644 (file)
@@ -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, "<INVALID>"))
+                     tmpl_type_to_str(vpt->type))
+
+
+/** @name Functions for printing and parsing tmpl type names
+ *
+ * @{
+ */
+/** Return a static string containing the type name
+ *
+ * @param[in] type to return name for.
+ * @return name of the type
+ */
+static inline char const *tmpl_type_to_str(tmpl_type_t type)
+{
+       return fr_table_str_by_value(tmpl_type_table, type, "<INVALID>");
+}
+
+/** Return the constant value representing a type
+ *
+ * @param[in] type to return the constant value for.
+ * @return The constant type value or TMPL_TYPE_UNINITIALISED if no type matches.
+ */
+static inline tmpl_type_t tmpl_type_from_str(char const *type)
+{
+       return fr_table_value_by_str(tmpl_type_table, type, TMPL_TYPE_UNINITIALISED);
+}
+/** @} */
 
 /** @name Field accessors for #TMPL_TYPE_ATTR, #TMPL_TYPE_ATTR_UNRESOLVED, #TMPL_TYPE_LIST
  *
index e5166b9cf36950ceec3cec845f5cc15b195bd89a..f062be0c83da76baa4b0d4a7f19406588677a7c2 100644 (file)
@@ -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, "<INVALID>"));
+                            tmpl_type_to_str(vpt->type));
                return;
        }
 
        FR_FAULT_LOG("tmpl_t %s (%.8x) \"%pV\" (%p)",
-                    fr_table_str_by_value(tmpl_type_table, vpt->type, "<INVALID>"),
+                    tmpl_type_to_str(vpt->type),
                     vpt->type,
                     fr_box_strvalue_len(vpt->name, vpt->len), vpt);
 
@@ -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, "<INVALID>"),
+                    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, "<INVALID>"));
+                     tmpl_type_to_str(vpt->type));
 
        if (tmpl_request_list_num_elements(&vpt->data.attribute.rr) > 0) tmpl_request_list_talloc_reverse_free(&vpt->data.attribute.rr);
 
@@ -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, "<INVALID>"));
+                                  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, "<INVALID>"));
+                              tmpl_type_to_str(vpt->type));
                break;
        }
 
index fea00cb78c52e9ff05519bb06749aeb4cc41c265..e4e47ef2f34eca6c493f3069e39726e429a1a190 100644 (file)
@@ -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, "<INVALID>"));
+                          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, "<INVALID>"));
+                          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, "<INVALID>"));
+                                          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, "<INVALID>"));
+                                                  tmpl_type_to_str(src_vpt->type));
                                        talloc_free(src_vpt);
                                        talloc_free(dst_vpt);
                                        goto error;
index 5ed909be2185b33ce219460ce0de7e5c1c1650be..748ef62d5cf0f7b85eab5d8e6f2b89b7036ca25c 100644 (file)
@@ -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, "<INVALID>"));
+                       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, "<INVALID>"));
+                       tmpl_type_to_str(map->rhs->type));
                return XLAT_ACTION_FAIL;
        }
 
index fafbf44a0aee19329d15975540ead2e7be04218f..b0da2bc25ff7ffe56430497122e3432bbe1c501f 100644 (file)
@@ -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, "<INVALID>"));
+                                          tmpl_type_to_str(map->lhs->type));
                        goto error;
                }
 
                if (!tmpl_is_unresolved(map->rhs)) {
                        fr_strerror_printf("Pair right hand side \"%s\" parsed as %s, needed literal.  "
                                           "Check serialized data quoting", map->rhs->name,
-                                          fr_table_str_by_value(tmpl_type_table, map->rhs->type, "<INVALID>"));
+                                          tmpl_type_to_str(map->rhs->type));
                        goto error;
                }
 
index 95c3cc74a2201cf77a71dbab82d8add7f936888e..c0b68399bfdb48773850b46247447e79706b23a3 100644 (file)
@@ -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, "<INVALID>"));
+                          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, "<INVALID>"));
+                          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, "<INVALID>"));
+                             &key, tmpl_type_to_str(inst->key_data_type));
                        RETURN_MODULE_FAIL;
                }
        }
index c36c0a52ceb52e08ea9a9d1f50adfb641d074d11..a6f886b3a72296877a45f7c87d6a91045a0bdb6a 100644 (file)
@@ -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, "<INVALID>"));
+                                  tmpl_type_to_str(inst->requested_address->type));
                }
        }