From: Arran Cudbard-Bell Date: Fri, 17 Dec 2021 18:34:09 +0000 (-0600) Subject: Fix dlist definition macros to be safer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f2f177e5449d9578b244e58bf23188f810d3f8d;p=thirdparty%2Ffreeradius-server.git Fix dlist definition macros to be safer --- diff --git a/src/bin/unit_test_map.c b/src/bin/unit_test_map.c index 34872a0edc3..3074e462b0f 100644 --- a/src/bin/unit_test_map.c +++ b/src/bin/unit_test_map.c @@ -86,7 +86,7 @@ static int process_file(char const *filename) .allow_foreign = false, /* tests are in the RADIUS dictionary */ }; - fr_map_list_init(&list); + fr_dlist_map_init(&list); /* * Must be called first, so the handler is called last */ @@ -122,7 +122,7 @@ static int process_file(char const *filename) cf_log_perr(cs, "map_afrom_cs failed"); return EXIT_FAILURE; /* message already printed */ } - if (fr_map_list_empty(&list)) { + if (fr_dlist_map_empty(&list)) { cf_log_err(cs, "'update' sections cannot be empty"); return EXIT_FAILURE; } @@ -141,7 +141,7 @@ static int process_file(char const *filename) printf("%s %s {\n", name1, name2); } - while ((map = fr_map_list_next(&list, map))) { + while ((map = fr_dlist_map_next(&list, map))) { map_print(&FR_SBUFF_OUT(buffer + 1, sizeof(buffer) - 1), map); puts(buffer); } diff --git a/src/include/build.h b/src/include/build.h index e839468f51d..35784f04c25 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -255,17 +255,27 @@ do { \ * * Expands to 1 if types are compatible, else 0. * - * @param _x pointer to check. - * @param _t type to check compatibility with. + * @param[in] _x pointer to check. + * @param[in] _t type to check compatibility with. */ #define IS_COMPATIBLE(_x, _t) _Generic(_x, _t:1, default: 0) +/** Check if a field in a struct is compatible (the C11 way) + * + * Expands to 1 if types are compatible, else 0. + * + * @param[in] _s struct to check. + * @param[in] _f field in struct. + * @param[in] _t type to check compatibility with. + */ +#define IS_FIELD_COMPATIBLE(_s, _f, _t) _Generic(((_s *)0)->_f, _t:1, default: 0) + /* * Only use GCC __attribute__ if were building with a GCClike * compiler. */ #ifdef __GNUC__ -# define CC_HINT(...) __attribute__ ((__VA_ARGS__)) +# define CC_HINT(...) __attribute__((__VA_ARGS__)) # define likely(_x) __builtin_expect((_x), 1) # define unlikely(_x) __builtin_expect((_x), 0) #else diff --git a/src/lib/ldap/map.c b/src/lib/ldap/map.c index 6d76651d043..bba78ea3ce4 100644 --- a/src/lib/ldap/map.c +++ b/src/lib/ldap/map.c @@ -262,7 +262,7 @@ int fr_ldap_map_expand(fr_ldap_map_exp_t *expanded, request_t *request, fr_map_l char const *attr; char attr_buff[1024 + 1]; /* X.501 says we need to support at least 1024 chars for attr names */ - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { if (tmpl_expand(&attr, attr_buff, sizeof(attr_buff), request, map->rhs, NULL, NULL) < 0) { REDEBUG("Expansion of LDAP attribute \"%s\" failed", map->rhs->name); TALLOC_FREE(ctx); @@ -314,7 +314,7 @@ int fr_ldap_map_do(request_t *request, LDAP *handle, fr_ldap_result_t result; char const *name; - while ((map = fr_map_list_next(expanded->maps, map))) { + while ((map = fr_dlist_map_next(expanded->maps, map))) { int ret; name = expanded->attrs[total++]; diff --git a/src/lib/redis/redis.c b/src/lib/redis/redis.c index d883648fb5b..d714a03c710 100644 --- a/src/lib/redis/redis.c +++ b/src/lib/redis/redis.c @@ -425,7 +425,7 @@ int fr_redis_reply_to_map(TALLOC_CTX *ctx, fr_map_list_t *out, request_t *reques } MAP_VERIFY(map); - fr_map_list_insert_tail(out, map); + fr_dlist_map_insert_tail(out, map); return 0; } diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 58678649943..bff3c91945e 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -69,7 +69,7 @@ static inline map_t *map_alloc(TALLOC_CTX *ctx, map_t *parent) } map->parent = parent; - fr_map_list_init(&map->child); + fr_dlist_map_init(&map->child); return map; } @@ -624,7 +624,7 @@ check_for_child: * caller will have to check for this! */ if (is_child && parent) { - fr_map_list_insert_tail(&parent->child, map); + fr_dlist_map_insert_tail(&parent->child, map); } if (parent_p) *parent_p = new_parent; @@ -718,7 +718,7 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, fr_map_list_t *out, map_t *parent, CON * Free in reverse as successive entries have their * prececessors as talloc parent contexts */ - fr_map_list_talloc_reverse_free(out); + fr_dlist_map_talloc_reverse_free(out); return -1; } @@ -733,7 +733,7 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, fr_map_list_t *out, map_t *parent, CON bool qualifiers = our_lhs_rules.disallow_qualifiers; fr_map_list_t child_list; - fr_map_list_init(&child_list); + fr_dlist_map_init(&child_list); subcs = cf_item_to_section(ci); token = cf_section_name2_quote(subcs); @@ -806,11 +806,11 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, fr_map_list_t *out, map_t *parent, CON */ if (_map_afrom_cs(map, &child_list, map, cf_item_to_section(ci), &our_lhs_rules, rhs_rules, validate, uctx, max) < 0) { - fr_map_list_talloc_free(&child_list); + fr_dlist_map_talloc_free(&child_list); talloc_free(map); goto error; } - fr_map_list_move(&map->child, &child_list); + fr_dlist_map_move(&map->child, &child_list); our_lhs_rules.disallow_qualifiers = qualifiers; MAP_VERIFY(map); @@ -840,7 +840,7 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, fr_map_list_t *out, map_t *parent, CON next: parent_ctx = map; - fr_map_list_insert_tail(out, map); + fr_dlist_map_insert_tail(out, map); } return 0; @@ -1150,9 +1150,9 @@ int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t co MEM(n = fr_pair_afrom_da(ctx, tmpl_da(map->lhs))); n->op = map->op; - for (child = fr_map_list_next(&map->child, NULL); + for (child = fr_dlist_map_next(&map->child, NULL); child != NULL; - child = fr_map_list_next(&map->child, child)) { + child = fr_dlist_map_next(&map->child, child)) { fr_pair_list_t list; /* @@ -1947,7 +1947,7 @@ ssize_t map_print(fr_sbuff_t *out, map_t const *map) * If there's no child and no RHS then the * map was invalid. */ - if (fr_map_list_empty(&map->child) && !fr_cond_assert(map->rhs != NULL)) { + if (fr_dlist_map_empty(&map->child) && !fr_cond_assert(map->rhs != NULL)) { fr_sbuff_terminate(out); return 0; } diff --git a/src/lib/server/map.h b/src/lib/server/map.h index 0a2b70beb24..de5f5471e8f 100644 --- a/src/lib/server/map.h +++ b/src/lib/server/map.h @@ -39,6 +39,7 @@ typedef struct vp_list_mod_s vp_list_mod_t; #include #include +#include #ifdef __cplusplus extern "C" { @@ -56,13 +57,12 @@ extern "C" { ['>'] = true, \ ['~'] = true -/** Value pair map list +FR_DLIST_TYPES(map) + +/** Given these are used in so many places, it's more friendly to have a proper type * - * Specifically define a type for lists of map_t to aid type checking */ -typedef struct { - fr_dlist_head_t head; -} fr_map_list_t; +typedef FR_DLIST_HEAD_TYPE(map) fr_map_list_t; /** Value pair map * @@ -75,32 +75,32 @@ typedef struct { * @see tmpl_t */ struct vp_map_s { - tmpl_t *lhs; //!< Typically describes the attribute to add, modify or compare. - tmpl_t *rhs; //!< Typically describes a literal value or a src attribute - ///< to copy or compare. + tmpl_t *lhs; //!< Typically describes the attribute to add, modify or compare. + tmpl_t *rhs; //!< Typically describes a literal value or a src attribute + ///< to copy or compare. - fr_token_t op; //!< The operator that controls insertion of the dst attribute. - fr_type_t cast; //!< Cast value to this type. + fr_token_t op; //!< The operator that controls insertion of the dst attribute. + fr_type_t cast; //!< Cast value to this type. - CONF_ITEM *ci; //!< Config item that the map was created from. Mainly used for - //!< logging validation errors. + CONF_ITEM *ci; //!< Config item that the map was created from. Mainly used for + //!< logging validation errors. - map_t *parent; //! parent map, for nested ones - fr_map_list_t child; //!< a child map. If it exists, `rhs` MUST be NULL - fr_dlist_t entry; //!< List entry. + map_t *parent; //! parent map, for nested ones + fr_map_list_t child; //!< a child map. If it exists, `rhs` MUST be NULL + FR_DLIST_ENTRY_TYPE(map) entry; //!< List entry. }; -FR_DLIST_NEW_TYPE(map_list, fr_map_list_t, head, map_t, entry) +FR_DLIST_FUNCS(map, map_t, entry) /** A list modification * */ struct vp_list_mod_s { - map_t const *map; //!< Original map describing the change to be made. + map_t const *map; //!< Original map describing the change to be made. - fr_map_list_t mod; //!< New map containing the destination (LHS) and - ///< values (RHS). - fr_dlist_t entry; //!< Entry into dlist + fr_map_list_t mod; //!< New map containing the destination (LHS) and + ///< values (RHS). + fr_dlist_t entry; //!< Entry into dlist }; #ifndef WITH_VERIFY_PTR diff --git a/src/lib/server/map_async.c b/src/lib/server/map_async.c index 5b9f5320bb1..af430f81af5 100644 --- a/src/lib/server/map_async.c +++ b/src/lib/server/map_async.c @@ -46,7 +46,7 @@ static inline vp_list_mod_t *list_mod_alloc(TALLOC_CTX *ctx) { vp_list_mod_t *mod; mod = talloc_zero(ctx, vp_list_mod_t); - fr_map_list_init(&mod->mod); + fr_dlist_map_init(&mod->mod); return mod; } @@ -54,7 +54,7 @@ static inline map_t *map_alloc(TALLOC_CTX *ctx) { map_t *map; map = talloc_zero(ctx, map_t); - fr_map_list_init(&map->child); + fr_dlist_map_init(&map->child); return map; } @@ -92,7 +92,7 @@ static inline vp_list_mod_t *list_mod_generic_afrom_map(TALLOC_CTX *ctx, talloc_free(n); return NULL; } - fr_map_list_insert_tail(&n->mod, mod); + fr_dlist_map_insert_tail(&n->mod, mod); return n; } @@ -134,7 +134,7 @@ static inline vp_list_mod_t *list_mod_delete_afrom_map(TALLOC_CTX *ctx, talloc_free(n); return NULL; } - fr_map_list_insert_tail(&n->mod, mod); + fr_dlist_map_insert_tail(&n->mod, mod); return n; } @@ -194,7 +194,7 @@ static inline vp_list_mod_t *list_mod_empty_string_afrom_map(TALLOC_CTX *ctx, talloc_free(n); return NULL; } - fr_map_list_insert_tail(&n->mod, mod); + fr_dlist_map_insert_tail(&n->mod, mod); return n; } @@ -361,7 +361,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, mod->lhs = mutated->lhs; mod->op = mutated->op; mod->rhs = mutated->rhs; - fr_map_list_insert_tail(&n->mod, mod); + fr_dlist_map_insert_tail(&n->mod, mod); goto finish; } @@ -432,7 +432,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, * before this map is applied. */ if (fr_value_box_copy(n_mod->rhs, tmpl_value(n_mod->rhs), &vp->data) < 0) goto error; - fr_map_list_insert_tail(&n->mod, n_mod); + fr_dlist_map_insert_tail(&n->mod, n_mod); MAP_VERIFY(n_mod); } while ((vp = fr_pair_list_next(list, vp))); @@ -455,8 +455,8 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, fr_dcursor_init(&values, &head); - if (fr_value_box_from_str(fr_map_list_head(&n->mod), - tmpl_value(fr_map_list_head(&n->mod)->rhs), type, + if (fr_value_box_from_str(fr_dlist_map_head(&n->mod), + tmpl_value(fr_dlist_map_head(&n->mod)->rhs), type, tmpl_da(mutated->lhs), mutated->rhs->name, mutated->rhs->len, fr_value_unescape_by_quote[(uint8_t)mutated->rhs->quote], false)) { @@ -511,7 +511,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, (void)fr_dcursor_init(&from, rhs_result); while ((vb = fr_dcursor_remove(&from))) { if (vb->type != tmpl_da(mutated->lhs)->type) { - n_vb = fr_value_box_alloc_null(fr_map_list_head(&n->mod)->rhs); + n_vb = fr_value_box_alloc_null(fr_dlist_map_head(&n->mod)->rhs); if (!n_vb) { fr_dcursor_head(&from); fr_dcursor_free_list(&from); @@ -589,7 +589,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, vp = fr_dcursor_current(&from); fr_assert(vp); /* Should have errored out */ do { - n_vb = fr_value_box_alloc_null(fr_map_list_head(&n->mod)->rhs); + n_vb = fr_value_box_alloc_null(fr_dlist_map_head(&n->mod)->rhs); if (!n_vb) { attr_error: fr_dcursor_head(&values); @@ -629,7 +629,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, vb = tmpl_value(mutated->rhs); - n_vb = fr_value_box_alloc_null(fr_map_list_head(&n->mod)->rhs); + n_vb = fr_value_box_alloc_null(fr_dlist_map_head(&n->mod)->rhs); if (!n_vb) { data_error: fr_dcursor_head(&values); @@ -756,7 +756,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, } mod->op = vp->op; - fr_map_list_insert_tail(&n->mod, mod); + fr_dlist_map_insert_tail(&n->mod, mod); } } @@ -776,11 +776,11 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, * If tmpl_value were a pointer we could * assign values directly. */ - fr_value_box_copy(fr_map_list_head(&n->mod)->rhs, tmpl_value(fr_map_list_head(&n->mod)->rhs), fr_dlist_head(&head)); + fr_value_box_copy(fr_dlist_map_head(&n->mod)->rhs, tmpl_value(fr_dlist_map_head(&n->mod)->rhs), fr_dlist_head(&head)); /* * value boxes in tmpls cannot now be the head of a list * - *tmpl_value(fr_map_list_head(&n->mod)->rhs)->next = head->next; + *tmpl_value(fr_dlist_map_head(&n->mod)->rhs)->next = head->next; */ fr_dlist_talloc_free(&head); @@ -826,13 +826,13 @@ static void map_list_mod_to_vps(TALLOC_CTX *ctx, fr_pair_list_t *list, vp_list_m { map_t *mod; - fr_assert(!fr_map_list_empty(&vlm->mod)); + fr_assert(!fr_dlist_map_empty(&vlm->mod)); /* * Fast path... */ - mod = fr_map_list_head(&vlm->mod); - if (fr_map_list_num_elements(&vlm->mod) == 1) { + mod = fr_dlist_map_head(&vlm->mod); + if (fr_dlist_map_num_elements(&vlm->mod) == 1) { fr_pair_t *vp; vp = map_list_mod_to_vp(ctx, mod->lhs, tmpl_value(mod->rhs)); fr_pair_append(list, vp); @@ -844,7 +844,7 @@ static void map_list_mod_to_vps(TALLOC_CTX *ctx, fr_pair_list_t *list, vp_list_m */ for (; mod; - mod = fr_map_list_next(&vlm->mod, mod)) { + mod = fr_dlist_map_next(&vlm->mod, mod)) { fr_pair_t *vp; vp = map_list_mod_to_vp(ctx, mod->lhs, tmpl_value(mod->rhs)); @@ -956,12 +956,12 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) memset(&cc, 0, sizeof(cc)); MAP_VERIFY(map); - fr_assert(!fr_map_list_empty(&vlm->mod)); + fr_assert(!fr_dlist_map_empty(&vlm->mod)); /* * Print debug information for the mods being applied */ - while ((mod = fr_map_list_next(&vlm->mod, mod))) { + while ((mod = fr_dlist_map_next(&vlm->mod, mod))) { fr_value_box_t *vb; MAP_VERIFY(mod); @@ -982,7 +982,7 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) map_list_mod_debug(request, map, mod, vb->type != FR_TYPE_NULL ? vb : NULL); } } - mod = fr_map_list_head(&vlm->mod); /* Reset */ + mod = fr_dlist_map_head(&vlm->mod); /* Reset */ /* * All this has been checked by #map_to_list_mod @@ -1082,7 +1082,7 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) } } - fr_assert(!fr_map_list_next(&vlm->mod, mod)); + fr_assert(!fr_dlist_map_next(&vlm->mod, mod)); /* * Find the destination attribute. We leave with either @@ -1141,7 +1141,7 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) * any of these values. */ if (tmpl_num(map->lhs) != NUM_ALL) { - fr_value_box_t *vb = tmpl_value(fr_map_list_head(&vlm->mod)->rhs); + fr_value_box_t *vb = tmpl_value(fr_dlist_map_head(&vlm->mod)->rhs); if (fr_value_box_cmp(vb, &found->data) == 0) { fr_dcursor_free_item(&list); @@ -1158,7 +1158,7 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) * matches any of these values. */ do { - fr_value_box_t *vb = tmpl_value(fr_map_list_head(&vlm->mod)->rhs); + fr_value_box_t *vb = tmpl_value(fr_dlist_map_head(&vlm->mod)->rhs); if (fr_value_box_cmp(vb, &found->data) == 0) { fr_dcursor_free_item(&list); diff --git a/src/lib/server/pairmove.c b/src/lib/server/pairmove.c index 9f217e4896a..ae662b7a54d 100644 --- a/src/lib/server/pairmove.c +++ b/src/lib/server/pairmove.c @@ -145,7 +145,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro RDEBUG4("::: OVERWRITING %s FROM %d TO %d", to_vp->da->name, i, j); fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order, to_vp, from_vp); + vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); talloc_free(vp); from_vp = NULL; edited[j] = true; @@ -226,7 +226,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro RDEBUG4("::: REPLACING %s FROM %d TO %d", from_vp->da->name, i, j); fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order, to_vp, from_vp); + vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); talloc_free(vp); from_vp = NULL; edited[j] = true; @@ -239,7 +239,7 @@ void radius_pairmove(request_t *request, fr_pair_list_t *to, fr_pair_list_t *fro RDEBUG4("::: REPLACING %s FROM %d TO %d", from_vp->da->name, i, j); fr_pair_remove(from, from_vp); - vp = fr_dlist_replace(&to->order, to_vp, from_vp); + vp = fr_dlist_replace(&to->order.head, to_vp, from_vp); talloc_free(vp); from_vp = NULL; edited[j] = true; diff --git a/src/lib/server/tmpl_dcursor.c b/src/lib/server/tmpl_dcursor.c index 6a0b02cd20b..2b1e10f6842 100644 --- a/src/lib/server/tmpl_dcursor.c +++ b/src/lib/server/tmpl_dcursor.c @@ -587,7 +587,7 @@ int tmpl_extents_find(TALLOC_CTX *ctx, list_ctx = ns->list_ctx; ar = ns->ar; - curr = _tmpl_cursor_eval(&list_head->order, curr, &cc); + curr = _tmpl_cursor_eval(&list_head->order.head, curr, &cc); if (!curr) { /* * References extend beyond current diff --git a/src/lib/server/users_file.c b/src/lib/server/users_file.c index d2df206d9d0..24ba80c20d8 100644 --- a/src/lib/server/users_file.c +++ b/src/lib/server/users_file.c @@ -365,8 +365,8 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR * We MUST be either at a valid entry, OR at EOF. */ MEM(t = talloc_zero(ctx, PAIR_LIST)); - fr_map_list_init(&t->check); - fr_map_list_init(&t->reply); + fr_dlist_map_init(&t->check); + fr_dlist_map_init(&t->reply); t->filename = filename; t->lineno = lineno; t->order = order++; @@ -470,7 +470,7 @@ check_item: do_insert: fr_assert(!new_map->parent); - fr_map_list_insert_tail(&t->check, new_map); + fr_dlist_map_insert_tail(&t->check, new_map); /* * There can be spaces before any comma. @@ -646,7 +646,7 @@ next_reply_item: fr_assert(tmpl_list(new_map->lhs) == PAIR_LIST_REPLY); - if (!new_map->parent) fr_map_list_insert_tail(&t->reply, new_map); + if (!new_map->parent) fr_dlist_map_insert_tail(&t->reply, new_map); (void) fr_sbuff_adv_past_blank(&sbuff, SIZE_MAX, NULL); diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index e41aa96d9cb..1b15519902e 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -591,7 +591,7 @@ static bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_ /* * Sanity check sublists. */ - if (!fr_map_list_empty(&map->child)) { + if (!fr_dlist_map_empty(&map->child)) { fr_dict_attr_t const *da; if (!tmpl_is_attr(map->lhs)) { @@ -611,7 +611,7 @@ static bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_ return false; } - return pass2_fixup_map(fr_map_list_head(&map->child), rules, da); + return pass2_fixup_map(fr_dlist_map_head(&map->child), rules, da); } return true; @@ -627,7 +627,7 @@ static bool pass2_fixup_update(unlang_group_t *g, tmpl_rules_t const *rules) RULES_VERIFY(rules); - while ((map = fr_map_list_next(&gext->map, map))) { + while ((map = fr_dlist_map_next(&gext->map, map))) { /* * Mostly fixup the map, but maybe leave the RHS * unresolved. @@ -660,7 +660,7 @@ static bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules) * the RHS as a reference to a json string, SQL column * name, etc. */ - while ((map = fr_map_list_next(&gext->map, map))) { + while ((map = fr_dlist_map_next(&gext->map, map))) { if (!pass2_fixup_map(map, rules, NULL)) return false; } @@ -669,7 +669,7 @@ static bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules) */ if (!gext->vpt) return true; - return pass2_fixup_tmpl(fr_map_list_head(&gext->map)->ci, &gext->vpt, + return pass2_fixup_tmpl(fr_dlist_map_head(&gext->map)->ci, &gext->vpt, cf_section_to_item(g->cs), rules->dict_def); } @@ -709,7 +709,7 @@ static void unlang_dump(unlang_t *instruction, int depth) g = unlang_generic_to_group(c); gext = unlang_group_to_map(g); map = NULL; - while ((map = fr_map_list_next(&gext->map, map))) { + while ((map = fr_dlist_map_next(&gext->map, map))) { map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map); DEBUG("%.*s%s", depth + 1, unlang_spaces, buffer); } @@ -724,7 +724,7 @@ static void unlang_dump(unlang_t *instruction, int depth) edit = unlang_generic_to_edit(c); map = NULL; - while ((map = fr_map_list_next(&edit->maps, map))) { + while ((map = fr_dlist_map_next(&edit->maps, map))) { map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map); DEBUG("%.*s%s", depth + 1, unlang_spaces, buffer); } @@ -1384,10 +1384,10 @@ static unlang_t *compile_map(unlang_t *parent, unlang_compile_t *unlang_ctx, CON /* * This looks at cs->name2 to determine which list to update */ - fr_map_list_init(&gext->map); + fr_dlist_map_init(&gext->map); rcode = map_afrom_cs(gext, &gext->map, cs, &t_rules, &t_rules, unlang_fixup_map, NULL, 256); if (rcode < 0) return NULL; /* message already printed */ - if (fr_map_list_empty(&gext->map)) { + if (fr_dlist_map_empty(&gext->map)) { cf_log_err(cs, "'map' sections cannot be empty"); goto error; } @@ -1456,10 +1456,10 @@ static unlang_t *compile_update(unlang_t *parent, unlang_compile_t *unlang_ctx, /* * This looks at cs->name2 to determine which list to update */ - fr_map_list_init(&gext->map); + fr_dlist_map_init(&gext->map); rcode = map_afrom_cs(gext, &gext->map, cs, &t_rules, &t_rules, unlang_fixup_update, NULL, 128); if (rcode < 0) return NULL; /* message already printed */ - if (fr_map_list_empty(&gext->map)) { + if (fr_dlist_map_empty(&gext->map)) { cf_log_err(cs, "'update' sections cannot be empty"); error: talloc_free(g); @@ -1515,10 +1515,10 @@ static unlang_t *compile_filter(unlang_t *parent, unlang_compile_t *unlang_ctx, /* * This looks at cs->name2 to determine which list to update */ - fr_map_list_init(&gext->map); + fr_dlist_map_init(&gext->map); rcode = map_afrom_cs(gext, &gext->map, cs, &t_rules, &t_rules, unlang_fixup_filter, NULL, 128); if (rcode < 0) return NULL; /* message already printed */ - if (fr_map_list_empty(&gext->map)) { + if (fr_dlist_map_empty(&gext->map)) { cf_log_err(cs, "'filter' sections cannot be empty"); return NULL; } @@ -1684,7 +1684,7 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang c->debug_name = c->name; c->type = UNLANG_TYPE_EDIT; - fr_map_list_init(&edit->maps); + fr_dlist_map_init(&edit->maps); edit_free = edit; compile_action_defaults(c, unlang_ctx); @@ -1696,7 +1696,7 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang MEM(map = talloc_zero(parent, map_t)); map->op = op; map->ci = cf_section_to_item(cs); - fr_map_list_init(&map->child); + fr_dlist_map_init(&map->child); name = cf_section_name1(cs); @@ -1732,7 +1732,7 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang */ // if (unlang_fixup_update(map, NULL) < 0) goto fail; - fr_map_list_insert_tail(&edit->maps, map); + fr_dlist_map_insert_tail(&edit->maps, map); *prev = c; return out; @@ -1776,7 +1776,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct c->debug_name = c->name; c->type = UNLANG_TYPE_EDIT; - fr_map_list_init(&edit->maps); + fr_dlist_map_init(&edit->maps); edit_free = edit; compile_action_defaults(c, unlang_ctx); @@ -1785,7 +1785,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct /* * Convert this particular map. */ - if (map_afrom_cp(edit, &map, fr_map_list_tail(&edit->maps), cp, &t_rules, &t_rules) < 0) { + if (map_afrom_cp(edit, &map, fr_dlist_map_tail(&edit->maps), cp, &t_rules, &t_rules) < 0) { fail: talloc_free(edit_free); return NULL; @@ -1802,7 +1802,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct */ if (unlang_fixup_update(map, NULL) < 0) goto fail; - fr_map_list_insert_tail(&edit->maps, map); + fr_dlist_map_insert_tail(&edit->maps, map); *prev = c; return out; diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index e2715a60197..1dce9d89c6e 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -488,7 +488,7 @@ static int expand_rhs_list(NDEBUG_UNUSED unlang_frame_state_edit_t *state, reque return -1; } - if (!fr_map_list_empty(&map->child)) { + if (!fr_dlist_map_empty(&map->child)) { REDEBUG("In-place lists not yet implemented"); return -1; } @@ -519,7 +519,7 @@ static unlang_action_t process_edit(rlm_rcode_t *p_result, request_t *request, u */ for (map = state->map; map != NULL; - map = state->map = fr_map_list_next(state->map_head, map)) { + map = state->map = fr_dlist_map_next(state->map_head, map)) { repeatable_set(frame); /* Call us again when done */ switch (state->state) { @@ -663,10 +663,10 @@ static unlang_action_t unlang_edit_state_init(rlm_rcode_t *p_result, request_t * * The edit list creates a local pool which should * generally be large enough for most edits. */ - MEM(state->el = fr_edit_list_alloc(state, fr_map_list_num_elements(&edit->maps))); + MEM(state->el = fr_edit_list_alloc(state, fr_dlist_map_num_elements(&edit->maps))); state->map_head = &edit->maps; - state->map = fr_map_list_head(state->map_head); + state->map = fr_dlist_map_head(state->map_head); fr_pair_list_init(&state->rhs.pair_list); /* diff --git a/src/lib/unlang/map.c b/src/lib/unlang/map.c index 851e1ea4267..612017bb9c7 100644 --- a/src/lib/unlang/map.c +++ b/src/lib/unlang/map.c @@ -271,7 +271,7 @@ static unlang_action_t unlang_update_state_init(rlm_rcode_t *p_result, request_t (sizeof(tmpl_t) * 2) + 128), g->num_children)); /* 128 is for string buffers */ - fr_dcursor_init(&update_state->maps, fr_map_list_dlist_head(&gext->map)); + fr_dcursor_init(&update_state->maps, &gext->map.head); fr_value_box_list_init(&update_state->lhs_result); fr_value_box_list_init(&update_state->rhs_result); fr_dlist_init(&update_state->vlm_head, vp_list_mod_t, entry); diff --git a/src/lib/util/dlist.h b/src/lib/util/dlist.h index 22ce085125e..76aaeccd71f 100644 --- a/src/lib/util/dlist.h +++ b/src/lib/util/dlist.h @@ -1047,97 +1047,126 @@ static inline void fr_dlist_sort(fr_dlist_head_t *list, fr_cmp_t cmp) } } -/* - * Hang onto your hats. This gets weird. +/** Expands to the type name used for the entry wrapper structure + * + * @param[in] _name Prefix we add to type-specific structures. + * @return fr_dlist__entry_t */ -#define FR_DLIST_NEW_TYPE(_name, _list_type, _member_head, _entry_type, _member) \ +#define FR_DLIST_ENTRY_TYPE(_name) fr_dlist_ ## _name ## _entry_t + +/** Expands to the type name used for the head wrapper structure + * + * @param[in] _name Prefix we add to type-specific structures. + * @return fr_dlist__head_t + */ +#define FR_DLIST_HEAD_TYPE(_name) fr_dlist_ ## _name ## _head_t + +/** Define type specific wrapper structs for dlists + * + * @note This macro should be used inside the header for the area of code + * which will use type specific functions. + */ +#define FR_DLIST_TYPES(_name) \ + typedef struct { fr_dlist_t entry; } FR_DLIST_ENTRY_TYPE(_name); \ + typedef struct { fr_dlist_head_t head; } FR_DLIST_HEAD_TYPE(_name); \ + +/** Define type specific wrapper functions for dlists + * + * @note This macro should be used inside the source file that will use + * the type specific functions. + * + * @param[in] _name Prefix we add to type-specific dlist functions. + * @param[in] _element_type Type of structure that'll be inserted into the dlist. + * @param[in] _element_entry Field in the _element_type that holds the dlist entry information. + */ +#define FR_DLIST_FUNCS(_name, _element_type, _element_entry) \ DIAG_OFF(unused-function) \ - static inline fr_dlist_head_t *fr_ ## _name ## _dlist_head(_list_type *list) \ - { return &list->_member_head; } \ -\ - static inline void fr_ ## _name ## _entry_init(_entry_type *entry) \ - { fr_dlist_entry_init(&entry->_member); } \ + _Static_assert(IS_FIELD_COMPATIBLE(_element_type, _element_entry, FR_DLIST_ENTRY_TYPE(_name)) == 1, "Bad dlist entry field type");\ + static inline fr_dlist_head_t *fr_dlist_ ## _name ## _list_head(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return UNCONST(fr_dlist_head_t *, &list->head); } \ + static inline void fr_dlist_ ## _name ## _entry_init(_element_type *entry) \ + { fr_dlist_entry_init(&entry->_element_entry.entry); } \ \ - static inline void fr_ ## _name ## _init(_list_type *list) \ - { _fr_dlist_init(&list->_member_head, offsetof(_entry_type, _member), NULL); } \ + static inline void fr_dlist_ ## _name ## _init(FR_DLIST_HEAD_TYPE(_name) *list) \ + { _fr_dlist_init(&list->head, offsetof(_element_type, _element_entry), NULL); } \ \ - static inline void fr_ ## _name ## _talloc_init(_list_type *list) \ - { _fr_dlist_init(&list->_member_head, offsetof(_entry_type, _member), #_entry_type); } \ + static inline void fr_dlist_ ## _name ## _talloc_init(FR_DLIST_HEAD_TYPE(_name) *list) \ + { _fr_dlist_init(&list->head, offsetof(_element_type, _element_entry), #_element_type); } \ \ - static inline void fr_ ## _name ## _clear(_list_type *list) \ - { fr_dlist_clear(&list->_member_head); } \ + static inline void fr_dlist_ ## _name ## _clear(FR_DLIST_HEAD_TYPE(_name) *list) \ + { fr_dlist_clear(&list->head); } \ \ - static inline bool fr_ ## _name ## _in_list(_list_type *list, _entry_type *ptr) \ - { return fr_dlist_in_list(&list->_member_head, ptr); } \ + static inline bool fr_dlist_ ## _name ## _in_list(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *ptr) \ + { return fr_dlist_in_list(&list->head, ptr); } \ \ - static inline int fr_ ## _name ## _insert_head(_list_type *list, _entry_type *ptr) \ - { return fr_dlist_insert_head(&list->_member_head, ptr); } \ + static inline int fr_dlist_ ## _name ## _insert_head(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *ptr) \ + { return fr_dlist_insert_head(&list->head, ptr); } \ \ - static inline int fr_ ## _name ## _insert_tail(_list_type *list, _entry_type *ptr) \ - { return fr_dlist_insert_tail(&list->_member_head, ptr); } \ + static inline int fr_dlist_ ## _name ## _insert_tail(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *ptr) \ + { return fr_dlist_insert_tail(&list->head, ptr); } \ \ - static inline int fr_ ## _name ## _insert_after(_list_type *list, _entry_type *pos, _entry_type *ptr) \ - { return fr_dlist_insert_after(&list->_member_head, pos, ptr); } \ + static inline int fr_dlist_ ## _name ## _insert_after(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *pos, _element_type *ptr) \ + { return fr_dlist_insert_after(&list->head, pos, ptr); } \ \ - static inline int fr_ ## _name ## _insert_before(_list_type *list, _entry_type *pos, _entry_type *ptr) \ - { return fr_dlist_insert_before(&list->_member_head, pos, ptr); } \ + static inline int fr_dlist_ ## _name ## _insert_before(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *pos, _element_type *ptr) \ + { return fr_dlist_insert_before(&list->head, pos, ptr); } \ \ - static inline _entry_type *fr_ ## _name ## _head(_list_type const *list) \ - { return fr_dlist_head(&list->_member_head); } \ + static inline _element_type *fr_dlist_ ## _name ## _head(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return fr_dlist_head(&list->head); } \ \ - static inline bool fr_ ## _name ## _empty(_list_type const *list) \ - { return fr_dlist_empty(&list->_member_head); } \ + static inline bool fr_dlist_ ## _name ## _empty(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return fr_dlist_empty(&list->head); } \ \ - static inline bool fr_ ## _name ## _initialised(_list_type const *list) \ - { return fr_dlist_initialised(&list->_member_head); } \ + static inline bool fr_dlist_ ## _name ## _initialised(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return fr_dlist_initialised(&list->head); } \ \ - static inline _entry_type *fr_ ## _name ## _tail(_list_type const *list) \ - { return fr_dlist_tail(&list->_member_head); } \ + static inline _element_type *fr_dlist_ ## _name ## _tail(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return fr_dlist_tail(&list->head); } \ \ - static inline _entry_type *fr_ ## _name ## _next(_list_type const *list, _entry_type const *ptr) \ - { return fr_dlist_next(&list->_member_head, ptr); } \ + static inline _element_type *fr_dlist_ ## _name ## _next(FR_DLIST_HEAD_TYPE(_name) const *list, _element_type const *ptr) \ + { return fr_dlist_next(&list->head, ptr); } \ \ - static inline _entry_type *fr_ ## _name ## _prev(_list_type const *list, _entry_type const *ptr) \ - { return fr_dlist_prev(&list->_member_head, ptr); } \ + static inline _element_type *fr_dlist_ ## _name ## _prev(FR_DLIST_HEAD_TYPE(_name) const *list, _element_type const *ptr) \ + { return fr_dlist_prev(&list->head, ptr); } \ \ - static inline _entry_type *fr_ ## _name ## _remove(_list_type *list, _entry_type *ptr) \ - { return fr_dlist_remove(&list->_member_head, ptr); } \ + static inline _element_type *fr_dlist_ ## _name ## _remove(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *ptr) \ + { return fr_dlist_remove(&list->head, ptr); } \ \ - static inline _entry_type *fr_ ## _name ## _pop_head(_list_type *list) \ - { return fr_dlist_pop_head(&list->_member_head); } \ + static inline _element_type *fr_dlist_ ## _name ## _pop_head(FR_DLIST_HEAD_TYPE(_name) *list) \ + { return fr_dlist_pop_head(&list->head); } \ \ - static inline _entry_type *fr_ ## _name ## _pop_tail(_list_type *list) \ - { return fr_dlist_pop_tail(&list->_member_head); } \ + static inline _element_type *fr_dlist_ ## _name ## _pop_tail(FR_DLIST_HEAD_TYPE(_name) *list) \ + { return fr_dlist_pop_tail(&list->head); } \ \ - static inline _entry_type *fr_ ## _name ## _replace(_list_type *list, _entry_type *item, _entry_type *ptr) \ - { return fr_dlist_replace(&list->_member_head, item, ptr); } \ + static inline _element_type *fr_dlist_ ## _name ## _replace(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *item, _element_type *ptr) \ + { return fr_dlist_replace(&list->head, item, ptr); } \ \ - static inline int fr_ ## _name ## _move(_list_type *dst, _list_type *src) \ - { return fr_dlist_move(&dst->_member_head, &src->_member_head); } \ + static inline int fr_dlist_ ## _name ## _move(FR_DLIST_HEAD_TYPE(_name) *dst, FR_DLIST_HEAD_TYPE(_name) *src) \ + { return fr_dlist_move(&dst->head, &src->head); } \ \ - static inline int fr_ ## _name ## _move_head(_list_type *dst, _list_type *src) \ - { return fr_dlist_move_head(&dst->_member_head, &src->_member_head); } \ + static inline int fr_dlist_ ## _name ## _move_head(FR_DLIST_HEAD_TYPE(_name) *dst, FR_DLIST_HEAD_TYPE(_name) *src) \ + { return fr_dlist_move_head(&dst->head, &src->head); } \ \ - static inline void fr_ ## _name ## _talloc_free_head(_list_type *list) \ - { fr_dlist_talloc_free_head(&list->_member_head); } \ + static inline void fr_dlist_ ## _name ## _talloc_free_head(FR_DLIST_HEAD_TYPE(_name) *list) \ + { fr_dlist_talloc_free_head(&list->head); } \ \ - static inline void fr_ ## _name ## _talloc_free_tail(_list_type *list) \ - { fr_dlist_talloc_free_tail(&list->_member_head); } \ + static inline void fr_dlist_ ## _name ## _talloc_free_tail(FR_DLIST_HEAD_TYPE(_name) *list) \ + { fr_dlist_talloc_free_tail(&list->head); } \ \ - static inline void fr_ ## _name ## _talloc_free_item(_list_type *list, _entry_type *ptr) \ - { fr_dlist_talloc_free_item(&list->_member_head, ptr); } \ + static inline void fr_dlist_ ## _name ## _talloc_free_item(FR_DLIST_HEAD_TYPE(_name) *list, _element_type *ptr) \ + { fr_dlist_talloc_free_item(&list->head, ptr); } \ \ - static inline void fr_ ## _name ## _talloc_free(_list_type *list) \ - { fr_dlist_talloc_free(&list->_member_head); } \ + static inline void fr_dlist_ ## _name ## _talloc_free(FR_DLIST_HEAD_TYPE(_name) *list) \ + { fr_dlist_talloc_free(&list->head); } \ \ - static inline void fr_ ## _name ## _talloc_reverse_free(_list_type *list) \ - { fr_dlist_talloc_reverse_free(&list->_member_head); } \ + static inline void fr_dlist_ ## _name ## _talloc_reverse_free(FR_DLIST_HEAD_TYPE(_name) *list) \ + { fr_dlist_talloc_reverse_free(&list->head); } \ \ - static inline unsigned int fr_ ## _name ## _num_elements(_list_type const *list) \ - { return fr_dlist_num_elements(&list->_member_head); } \ + static inline unsigned int fr_dlist_ ## _name ## _num_elements(FR_DLIST_HEAD_TYPE(_name) const *list) \ + { return fr_dlist_num_elements(&list->head); } \ \ - static inline void fr_ ## _name ## _sort(_list_type *list, fr_cmp_t cmp) \ - { fr_dlist_sort(&list->_member_head, cmp); } \ + static inline void fr_dlist_ ## _name ## _sort(FR_DLIST_HEAD_TYPE(_name) *list, fr_cmp_t cmp) \ + { fr_dlist_sort(&list->head, cmp); } \ DIAG_ON(unused-function) diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 546ebbca5b9..b298775cac2 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -32,7 +32,7 @@ RCSID("$Id$") #include #include -FR_DLIST_NEW_TYPE(pair_dlist, fr_pair_list_t, order, fr_pair_t, order_entry) +FR_DLIST_FUNCS(pair, fr_pair_t, order_entry) /** Initialise a pair list header * @@ -46,7 +46,7 @@ void fr_pair_list_init(fr_pair_list_t *list) * in the list and allows us to iterate over * all of them. */ - fr_pair_dlist_talloc_init(list); + fr_dlist_pair_talloc_init(&list->order); } /** Free a fr_pair_t @@ -107,13 +107,12 @@ fr_pair_list_t *fr_pair_list_alloc(TALLOC_CTX *ctx) */ static inline CC_HINT(always_inline) void pair_init_null(fr_pair_t *vp) { - fr_pair_dlist_entry_init(vp); + fr_dlist_pair_entry_init(vp); /* * Legacy cruft */ vp->op = T_OP_EQ; - vp->type = VT_DATA; } /** Dynamically allocate a new attribute with no #fr_dict_attr_t assigned @@ -406,7 +405,6 @@ fr_pair_t *fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp) if (!n) return NULL; n->op = vp->op; - n->type = vp->type; /* * Copy the unknown attribute hierarchy */ @@ -467,7 +465,7 @@ int fr_pair_steal(TALLOC_CTX *ctx, fr_pair_t *vp) */ int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp) { - if (fr_pair_dlist_in_list(list, vp)) { + if (fr_dlist_pair_in_list(&list->order, vp)) { fr_strerror_printf("Pair %pV is a list member, cannot be moved", vp); return -1; } @@ -490,7 +488,7 @@ int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t * */ int fr_pair_steal_prepend(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp) { - if (fr_pair_dlist_in_list(list, vp)) { + if (fr_dlist_pair_in_list(&list->order, vp)) { fr_strerror_printf("Pair %pV is a list member, cannot be moved", vp); return -1; } @@ -510,7 +508,7 @@ int fr_pair_steal_prepend(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t */ void fr_pair_list_free(fr_pair_list_t *list) { - fr_pair_dlist_talloc_free(list); + fr_dlist_pair_talloc_free(&list->order); } /** Is a valuepair list empty @@ -522,7 +520,7 @@ void fr_pair_list_free(fr_pair_list_t *list) */ bool fr_pair_list_empty(fr_pair_list_t const *list) { - return fr_pair_dlist_empty(list); + return fr_dlist_pair_empty(&list->order); } /** Mark malformed or unrecognised attributed as unknown @@ -611,9 +609,9 @@ unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t cons fr_pair_t *vp = NULL; unsigned int count = 0; - if (fr_pair_dlist_empty(list)) return 0; + if (fr_dlist_pair_empty(&list->order)) return 0; - while ((vp = fr_pair_dlist_next(list, vp))) if (da == vp->da) count++; + while ((vp = fr_dlist_pair_next(&list->order, vp))) if (da == vp->da) count++; return count; } @@ -633,11 +631,11 @@ fr_pair_t *fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, { fr_pair_t *vp = UNCONST(fr_pair_t *, prev); - if (fr_pair_dlist_empty(list)) return NULL; + if (fr_dlist_pair_empty(&list->order)) return NULL; PAIR_LIST_VERIFY(list); - while ((vp = fr_pair_dlist_next(list, vp))) if (da == vp->da) return vp; + while ((vp = fr_dlist_pair_next(&list->order, vp))) if (da == vp->da) return vp; return NULL; } @@ -657,7 +655,7 @@ fr_pair_t *fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t con { fr_pair_t *vp = NULL; - if (fr_pair_dlist_empty(list)) return NULL; + if (fr_dlist_pair_empty(&list->order)) return NULL; PAIR_LIST_VERIFY(list); @@ -738,7 +736,7 @@ fr_pair_t *fr_pair_find_by_child_num(fr_pair_list_t const *list, fr_pair_t const fr_dict_attr_t const *da; /* List head may be NULL if it contains no VPs */ - if (fr_pair_dlist_empty(list)) return NULL; + if (fr_dlist_pair_empty(&list->order)) return NULL; PAIR_LIST_VERIFY(list); @@ -764,7 +762,7 @@ fr_pair_t *fr_pair_find_by_child_num_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da; /* List head may be NULL if it contains no VPs */ - if (fr_pair_dlist_empty(list)) return NULL; + if (fr_dlist_pair_empty(&list->order)) return NULL; PAIR_LIST_VERIFY(list); @@ -842,7 +840,7 @@ fr_pair_t *_fr_pair_dcursor_iter_init(fr_dcursor_t *cursor, fr_pair_list_t const fr_dcursor_iter_t iter, void const *uctx, bool is_const) { - return _fr_dcursor_init(cursor, &list->order, + return _fr_dcursor_init(cursor, fr_dlist_pair_list_head(&list->order), iter, uctx, _pair_list_dcursor_insert, _pair_list_dcursor_remove, list, is_const); } @@ -863,7 +861,7 @@ fr_pair_t *_fr_pair_dcursor_iter_init(fr_dcursor_t *cursor, fr_pair_list_t const fr_pair_t *_fr_pair_dcursor_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, bool is_const) { - return _fr_dcursor_init(cursor, &list->order, + return _fr_dcursor_init(cursor, fr_dlist_pair_list_head(&list->order), NULL, NULL, _pair_list_dcursor_insert, _pair_list_dcursor_remove, list, is_const); } @@ -883,7 +881,7 @@ fr_pair_t *_fr_pair_dcursor_by_da_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dict_attr_t const *da, bool is_const) { - return _fr_dcursor_init(cursor, &list->order, + return _fr_dcursor_init(cursor, fr_dlist_pair_list_head(&list->order), fr_pair_iter_next_by_da, da, _pair_list_dcursor_insert, _pair_list_dcursor_remove, list, is_const); } @@ -902,7 +900,7 @@ fr_pair_t *_fr_pair_dcursor_by_ancestor_init(fr_dcursor_t *cursor, fr_pair_list_t const *list, fr_dict_attr_t const *da, bool is_const) { - return _fr_dcursor_init(cursor, &list->order, + return _fr_dcursor_init(cursor, fr_dlist_pair_list_head(&list->order), fr_pair_iter_next_by_ancestor, da, _pair_list_dcursor_insert, _pair_list_dcursor_remove, list, is_const); } @@ -918,7 +916,7 @@ fr_pair_t *_fr_pair_dcursor_by_ancestor_init(fr_dcursor_t *cursor, */ fr_pair_t *fr_pair_list_head(fr_pair_list_t const *list) { - return fr_pair_dlist_head(list); + return fr_dlist_pair_head(&list->order); } /** Get the next item in a valuepair list after a specific entry @@ -932,7 +930,7 @@ fr_pair_t *fr_pair_list_head(fr_pair_list_t const *list) */ fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) { - return fr_pair_dlist_next(list, item); + return fr_dlist_pair_next(&list->order, item); } /** Get the previous item in a valuepair list before a specific entry @@ -945,7 +943,7 @@ fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) */ fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) { - return fr_pair_dlist_prev(list, item); + return fr_dlist_pair_prev(&list->order, item); } /** Get the tail of a valuepair list @@ -958,7 +956,7 @@ fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) */ fr_pair_t *fr_pair_list_tail(fr_pair_list_t const *list) { - return fr_pair_dlist_tail(list); + return fr_dlist_pair_tail(&list->order); } /** Add a VP to the start of the list. @@ -975,12 +973,12 @@ int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add) { PAIR_VERIFY(to_add); - if (fr_pair_dlist_in_list(list, to_add)) { + if (fr_dlist_pair_in_list(&list->order, to_add)) { fr_strerror_printf("Pair %pV already inserted into list", to_add); return -1; } - fr_pair_dlist_insert_head(list, to_add); + fr_dlist_pair_insert_head(&list->order, to_add); return 0; } @@ -999,12 +997,12 @@ int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add) { PAIR_VERIFY(to_add); - if (fr_pair_dlist_in_list(list, to_add)) { + if (fr_dlist_pair_in_list(&list->order, to_add)) { fr_strerror_printf("Pair %pV already inserted into list", to_add); return -1; } - fr_pair_dlist_insert_tail(list, to_add); + fr_dlist_pair_insert_tail(&list->order, to_add); return 0; } @@ -1022,17 +1020,17 @@ int fr_pair_insert_after(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_add { PAIR_VERIFY(to_add); - if (fr_pair_dlist_in_list(list, to_add)) { + if (fr_dlist_pair_in_list(&list->order, to_add)) { fr_strerror_printf("Pair %pV already inserted into list", to_add); return -1; } - if (pos && !fr_pair_dlist_in_list(list, pos)) { + if (pos && !fr_dlist_pair_in_list(&list->order, pos)) { fr_strerror_printf("Pair %pV not in list", pos); return -1; } - fr_pair_dlist_insert_after(list, pos, to_add); + fr_dlist_pair_insert_after(&list->order, pos, to_add); return 0; } @@ -1050,17 +1048,17 @@ int fr_pair_insert_before(fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *to_ad { PAIR_VERIFY(to_add); - if (fr_pair_dlist_in_list(list, to_add)) { + if (fr_dlist_pair_in_list(&list->order, to_add)) { fr_strerror_printf("Pair %pV already inserted into list", to_add); return -1; } - if (pos && !fr_pair_dlist_in_list(list, pos)) { + if (pos && !fr_dlist_pair_in_list(&list->order, pos)) { fr_strerror_printf("Pair %pV not in list", pos); return -1; } - fr_pair_dlist_insert_before(list, pos, to_add); + fr_dlist_pair_insert_before(&list->order, pos, to_add); return 0; } @@ -1234,8 +1232,8 @@ fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp) { fr_pair_t *prev; - prev = fr_pair_dlist_prev(list, vp); - fr_pair_dlist_remove(list, vp); + prev = fr_dlist_pair_prev(&list->order, vp); + fr_dlist_pair_remove(&list->order, vp); return prev; } @@ -1250,8 +1248,8 @@ fr_pair_t *fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) { fr_pair_t *prev; - prev = fr_pair_dlist_prev(list, vp); - fr_pair_dlist_remove(list, vp); + prev = fr_dlist_pair_prev(&list->order, vp); + fr_dlist_pair_remove(&list->order, vp); talloc_free(vp); return prev; @@ -1488,7 +1486,7 @@ int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b) */ void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) { - fr_pair_dlist_sort(list, cmp); + fr_dlist_pair_sort(&list->order, cmp); } /** Write an error to the library errorbuff detailing the mismatch @@ -1547,9 +1545,7 @@ bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter, fr_pai { fr_pair_t *check, *match; - if (fr_pair_dlist_empty(filter) && fr_pair_dlist_empty(list)) { - return true; - } + if (fr_dlist_pair_empty(&filter->order) && fr_dlist_pair_empty(&list->order)) return true; /* * This allows us to verify the sets of validate and reply are equal @@ -1622,9 +1618,7 @@ bool fr_pair_validate_relaxed(fr_pair_t const *failed[2], fr_pair_list_t *filter { fr_pair_t *check, *last_check = NULL, *match = NULL; - if (fr_pair_dlist_empty(filter) && fr_pair_dlist_empty(list)) { - return true; - } + if (fr_dlist_pair_empty(&filter->order) && fr_dlist_pair_empty(&list->order)) return true; /* * This allows us to verify the sets of validate and reply are equal @@ -1867,9 +1861,9 @@ void fr_pair_value_clear(fr_pair_t *vp) break; case FR_TYPE_STRUCTURAL: - if (!fr_pair_dlist_empty(&vp->vp_group)) return; + if (!fr_dlist_pair_empty(&vp->vp_group.order)) return; - while ((child = fr_pair_dlist_pop_tail(&vp->vp_group))) { + while ((child = fr_dlist_pair_pop_tail(&vp->vp_group.order))) { fr_pair_value_clear(child); talloc_free(child); } @@ -2710,7 +2704,6 @@ void fr_pair_list_verify(char const *file, int line, TALLOC_CTX const *expected, */ for (; slow; slow = fr_pair_list_next(list, slow)) { PAIR_VERIFY(slow); - parent = talloc_parent(slow); if (expected && (parent != expected)) goto bad_parent; } @@ -2751,7 +2744,7 @@ void fr_pair_list_tainted(fr_pair_list_t *list) */ void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src) { - fr_pair_dlist_move(dst, src); + fr_dlist_pair_move(&dst->order, &src->order); } /** Move a list of fr_pair_t from a temporary list to the head of a destination list @@ -2761,7 +2754,7 @@ void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src) */ void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src) { - fr_pair_dlist_move_head(dst, src); + fr_dlist_pair_move_head(&dst->order, &src->order); } /** Evaluation function for matching if vp matches a given da @@ -2788,7 +2781,7 @@ bool fr_pair_matches_da(void const *item, void const *uctx) */ size_t fr_pair_list_len(fr_pair_list_t const *list) { - return fr_pair_dlist_num_elements(list); + return fr_dlist_pair_num_elements(&list->order); } /** Parse a list of VPs from a value box. diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index 169f7b4063e..226e865311a 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -44,22 +44,12 @@ extern "C" { # define _CONST #endif -/** The type of value a fr_pair_t contains - * - * This is used to add structure to nested fr_pair_ts and specifies what type of node it is (set, list, data). - * - * xlat is another type of data node which must first be expanded before use. - */ -typedef enum value_type { - VT_INVALID = 0, //!< fr_pair_t is broken - VT_SET, //!< fr_pair_t is #fr_value_box_list - VT_DATA, //!< fr_pair_t has a single value. -} value_type_t; - typedef struct value_pair_s fr_pair_t; +FR_DLIST_TYPES(pair) + typedef struct { - fr_dlist_head_t order; //!< Maintains the relative order of pairs in a list. + FR_DLIST_HEAD_TYPE(pair) order; //!< Maintains the relative order of pairs in a list. } fr_pair_list_t; /** Stores an attribute, a value and various bits of other data @@ -74,7 +64,7 @@ struct value_pair_s { ///< Note: This should not be modified outside ///< of pair.c except via #fr_pair_reinit_from_da. - fr_dlist_t _CONST order_entry; //!< Entry to maintain relative order within a list + FR_DLIST_ENTRY_TYPE(pair) _CONST order_entry; //!< Entry to maintain relative order within a list ///< of pairs. This ensures pairs within the list ///< are encoded in the same order as they were ///< received or inserted. @@ -95,8 +85,6 @@ struct value_pair_s { fr_token_t op; //!< Operator to use when moving or inserting //!< valuepair into a list. char const *xlat; //!< Source string for xlat expansion. - - value_type_t type; //!< Type of pointer in value union. }; }; diff --git a/src/lib/util/strerror_tests.c b/src/lib/util/strerror_tests.c index 7f0b7def149..5f189910dbe 100644 --- a/src/lib/util/strerror_tests.c +++ b/src/lib/util/strerror_tests.c @@ -197,7 +197,7 @@ static void strerror_printf_benchmark(void) printf("printf pop rate %" PRIu64 "\n", rate); /* shared runners are terrible for performance tests */ - if (!getenv("NO_PERFORMANCE_TESTS")) TEST_CHECK(rate > 400000); + if (!getenv("NO_PERFORMANCE_TESTS")) TEST_CHECK(rate > 200000); } diff --git a/src/modules/rlm_attr_filter/rlm_attr_filter.c b/src/modules/rlm_attr_filter/rlm_attr_filter.c index 559610ca4e2..ae83b13533f 100644 --- a/src/modules/rlm_attr_filter/rlm_attr_filter.c +++ b/src/modules/rlm_attr_filter/rlm_attr_filter.c @@ -118,13 +118,13 @@ static int attr_filter_getfile(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, c /* * We apply the rules in the reply items. */ - if (!fr_map_list_empty(&entry->check)) { + if (!fr_dlist_map_empty(&entry->check)) { WARN("%s[%d] Check list is not empty for entry \"%s\".\n", filename, entry->lineno, entry->name); } map = NULL; - while ((map = fr_map_list_next(&entry->reply, map))) { + while ((map = fr_dlist_map_next(&entry->reply, map))) { fr_dict_attr_t const *da; if (!tmpl_is_attr(map->lhs)) { @@ -240,7 +240,7 @@ static unlang_action_t CC_HINT(nonnull(1,2)) attr_filter_common(rlm_rcode_t *p_r fr_pair_list_init(&check_list); - while ((map = fr_map_list_next(&pl->reply, map))) { + while ((map = fr_dlist_map_next(&pl->reply, map))) { if (map_to_vp(packet, &tmp_list, request, map, NULL) < 0) { RPWARN("Failed parsing map %s for check item, skipping it", map->lhs->name); continue; diff --git a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c index 30f87be8e2d..278a78ab900 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c @@ -138,7 +138,7 @@ static cache_status_t cache_entry_find(rlm_cache_entry_t **out, #endif rlm_cache_entry_t *c; - fr_map_list_init(&head); + fr_dlist_map_init(&head); for (s_ret = fr_redis_cluster_state_init(&state, &conn, driver->cluster, request, key, key_len, false); s_ret == REDIS_RCODE_TRY_AGAIN; /* Continue */ s_ret = fr_redis_cluster_state_next(&state, &conn, driver->cluster, request, status, &reply)) { @@ -198,7 +198,7 @@ static cache_status_t cache_entry_find(rlm_cache_entry_t **out, #else c = talloc_zero(NULL, rlm_cache_entry_t); #endif - fr_map_list_init(&c->maps); + fr_dlist_map_init(&c->maps); /* * Convert the key/value pairs back into maps */ @@ -215,30 +215,30 @@ static cache_status_t cache_entry_find(rlm_cache_entry_t **out, /* * Pull out the cache created date */ - if (tmpl_da(fr_map_list_head(&head)->lhs) == attr_cache_created) { + if (tmpl_da(fr_dlist_map_head(&head)->lhs) == attr_cache_created) { map_t *map; - c->created = tmpl_value(fr_map_list_head(&head)->rhs)->vb_date; + c->created = tmpl_value(fr_dlist_map_head(&head)->rhs)->vb_date; - map = fr_map_list_pop_head(&head); + map = fr_dlist_map_pop_head(&head); talloc_free(map); } /* * Pull out the cache expires date */ - if (tmpl_da(fr_map_list_head(&head)->lhs) == attr_cache_expires) { + if (tmpl_da(fr_dlist_map_head(&head)->lhs) == attr_cache_expires) { map_t *map; - c->expires = tmpl_value(fr_map_list_head(&head)->rhs)->vb_date; + c->expires = tmpl_value(fr_dlist_map_head(&head)->rhs)->vb_date; - map = fr_map_list_pop_head(&head); + map = fr_dlist_map_pop_head(&head); talloc_free(map); } c->key = talloc_memdup(c, key, key_len); c->key_len = key_len; - fr_map_list_move(&c->maps, &head); + fr_dlist_map_move(&c->maps, &head); *out = c; return CACHE_OK; @@ -306,7 +306,7 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config fr_value_box_init(&expires_value.data.literal, FR_TYPE_DATE, NULL, true); tmpl_value(&expires_value)->vb_date = c->expires; - cnt = fr_map_list_num_elements(&c->maps) + 2; + cnt = fr_dlist_map_num_elements(&c->maps) + 2; /* * The majority of serialized entries should be under 1k. @@ -342,7 +342,7 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config } argv_p += 3; argv_len_p += 3; - while ((map = fr_map_list_next(&c->maps, map))) { + while ((map = fr_dlist_map_next(&c->maps, map))) { if (fr_redis_tuple_from_map(pool, argv_p, argv_len_p, map) < 0) { REDEBUG("Failed encoding map as Redis K/V pair"); talloc_free(pool); diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 0afe721de12..a4098046b26 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -160,7 +160,7 @@ static rlm_rcode_t cache_merge(rlm_cache_t const *inst, request_t *request, rlm_ RDEBUG2("Merging cache entry into request"); RINDENT(); - while ((map = fr_map_list_next(&c->maps, map))) { + while ((map = fr_dlist_map_next(&c->maps, map))) { /* * The only reason that the application of a map entry * can fail, is if the destination list or request @@ -320,7 +320,7 @@ static unlang_action_t cache_insert(rlm_rcode_t *p_result, if (!c) { RETURN_MODULE_FAIL; } - fr_map_list_init(&c->maps); + fr_dlist_map_init(&c->maps); c->key = talloc_memdup(c, key, key_len); c->key_len = key_len; @@ -337,7 +337,7 @@ static unlang_action_t cache_insert(rlm_rcode_t *p_result, * gathering fr_pair_ts to cache. */ pool = talloc_pool(NULL, 2048); - while ((map = fr_map_list_next(&inst->maps, map))) { + while ((map = fr_dlist_map_next(&inst->maps, map))) { fr_pair_list_t to_cache; fr_pair_list_init(&to_cache); @@ -376,7 +376,7 @@ static unlang_action_t cache_insert(rlm_rcode_t *p_result, MEM(c_map = talloc_zero(c, map_t)); c_map->op = map->op; - fr_map_list_init(&c_map->child); + fr_dlist_map_init(&c_map->child); /* * Now we turn the fr_pair_ts into maps. @@ -425,7 +425,7 @@ static unlang_action_t cache_insert(rlm_rcode_t *p_result, fr_assert(0); } MAP_VERIFY(c_map); - fr_map_list_insert_tail(&c->maps, c_map); + fr_dlist_map_insert_tail(&c->maps, c_map); } talloc_free_children(pool); /* reset pool state */ } @@ -868,7 +868,7 @@ xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, return XLAT_ACTION_FAIL; } - while ((map = fr_map_list_next(&c->maps, map))) { + while ((map = fr_dlist_map_next(&c->maps, map))) { if ((tmpl_da(map->lhs) != tmpl_da(target)) || (tmpl_list(map->lhs) != tmpl_list(target))) continue; @@ -1044,14 +1044,14 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) .allow_foreign = true /* Because we don't know where we'll be called */ }; - fr_map_list_init(&inst->maps); + fr_dlist_map_init(&inst->maps); if (map_afrom_cs(inst, &inst->maps, update, &parse_rules, &parse_rules, cache_verify, NULL, MAX_ATTRMAP) < 0) { return -1; } } - if (fr_map_list_empty(&inst->maps)) { + if (fr_dlist_map_empty(&inst->maps)) { cf_log_err(conf, "Cache config must contain an update section, and " "that section must not be empty"); return -1; diff --git a/src/modules/rlm_cache/serialize.c b/src/modules/rlm_cache/serialize.c index d8fc84bb8b1..96ce1ecf7f3 100644 --- a/src/modules/rlm_cache/serialize.c +++ b/src/modules/rlm_cache/serialize.c @@ -53,7 +53,7 @@ int cache_serialize(TALLOC_CTX *ctx, char **out, rlm_cache_entry_t const *c) /* * It's valid to have an empty cache entry (save allocing the pairs pool) */ - if (fr_map_list_empty(&c->maps)) goto finish; + if (fr_dlist_map_empty(&c->maps)) goto finish; value_pool = talloc_pool(ctx, 512); if (!value_pool) { @@ -63,7 +63,7 @@ int cache_serialize(TALLOC_CTX *ctx, char **out, rlm_cache_entry_t const *c) return -1; } - while ((map = fr_map_list_next(&c->maps, map))) { + while ((map = fr_dlist_map_next(&c->maps, map))) { char *value; ssize_t slen; @@ -167,7 +167,7 @@ int cache_deserialize(rlm_cache_entry_t *c, fr_dict_t const *dict, char *in, ssi MAP_VERIFY(map); /* It's not a special attribute, add it to the map list */ - fr_map_list_insert_tail(&c->maps, map); + fr_dlist_map_insert_tail(&c->maps, map); next: p = q + 1; diff --git a/src/modules/rlm_client/rlm_client.c b/src/modules/rlm_client/rlm_client.c index d295369535d..17fd9258fd9 100644 --- a/src/modules/rlm_client/rlm_client.c +++ b/src/modules/rlm_client/rlm_client.c @@ -177,7 +177,7 @@ static rlm_rcode_t map_proc_client(UNUSED void *mod_inst, UNUSED void *proc_inst uctx.cs = client->cs; RINDENT(); - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { char *field = NULL; if (tmpl_aexpand(request, &field, request, map->rhs, NULL, NULL) < 0) { diff --git a/src/modules/rlm_couchbase/rlm_couchbase.c b/src/modules/rlm_couchbase/rlm_couchbase.c index 47e2d4b2a9a..e3458e0da5d 100644 --- a/src/modules/rlm_couchbase/rlm_couchbase.c +++ b/src/modules/rlm_couchbase/rlm_couchbase.c @@ -153,7 +153,7 @@ static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const * vp_list_mod_t *vlm; fr_dlist_head_t vlm_head; - fr_map_list_init(&map_head); + fr_dlist_map_init(&map_head); fr_dcursor_init(&maps, &map_head); /* diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index 75385b8d997..e9b2de1fef1 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -490,7 +490,7 @@ static int csv_maps_verify(CONF_SECTION *cs, void *mod_inst, UNUSED void *proc_i return -1; } - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { /* * This function doesn't change the map, so it's OK. */ @@ -762,7 +762,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) }; char buffer[8192]; - fr_map_list_init(&inst->map); + fr_dlist_map_init(&inst->map); /* * "update" without "key" is invalid, as we can't run the * module. @@ -907,7 +907,7 @@ static rlm_rcode_t mod_map_apply(rlm_csv_t const *inst, request_t *request, redo: RINDENT(); - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { int field; char *field_name; @@ -1003,7 +1003,7 @@ static unlang_action_t CC_HINT(nonnull) mod_process(rlm_rcode_t *p_result, modul ssize_t slen; fr_value_box_t *key; - if (fr_map_list_empty(&inst->map) || !inst->key) RETURN_MODULE_NOOP; + if (fr_dlist_map_empty(&inst->map) || !inst->key) RETURN_MODULE_NOOP; /* * Expand the key to whatever it is. For attributes, diff --git a/src/modules/rlm_files/rlm_files.c b/src/modules/rlm_files/rlm_files.c index 16479bfb4c9..50dd685e4fd 100644 --- a/src/modules/rlm_files/rlm_files.c +++ b/src/modules/rlm_files/rlm_files.c @@ -152,7 +152,7 @@ static int getusersfile(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **ptre * and probably ':=' for server * configuration items. */ - while ((map = fr_map_list_next(&entry->check, map))) { + while ((map = fr_dlist_map_next(&entry->check, map))) { if (!tmpl_is_attr(map->lhs)) { ERROR("%s[%d] Left side of check item %s is not an attribute", entry->filename, entry->lineno, map->lhs->name); @@ -193,7 +193,7 @@ static int getusersfile(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **ptre * worth doing. */ map = NULL; - while ((map = fr_map_list_next(&entry->reply, map))) { + while ((map = fr_dlist_map_next(&entry->reply, map))) { if (!tmpl_is_attr(map->lhs)) { ERROR("%s[%d] Left side of reply item %s is not an attribute", entry->filename, entry->lineno, map->lhs->name); @@ -477,7 +477,7 @@ redo: /* * Realize the map to a list of VPs */ - while ((map = fr_map_list_next(&pl->check, map))) { + while ((map = fr_dlist_map_next(&pl->check, map))) { fr_pair_list_t tmp_list; /* @@ -529,9 +529,9 @@ redo: fr_pair_list_free(&list); /* ctx may be reply */ - if (!fr_map_list_empty(&pl->reply)) { + if (!fr_dlist_map_empty(&pl->reply)) { map = NULL; - while ((map = fr_map_list_next(&pl->reply, map))) { + while ((map = fr_dlist_map_next(&pl->reply, map))) { fr_pair_list_t tmp_list; fr_pair_list_init(&tmp_list); if (map->op == T_OP_CMP_FALSE) continue; diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index b233f6c4624..a941a8401b7 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -292,7 +292,7 @@ static int mod_map_proc_instantiate(CONF_SECTION *cs, UNUSED void *mod_inst, voi return -1; } - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { CONF_PAIR *cp = cf_item_to_pair(map->ci); char const *p; @@ -343,7 +343,7 @@ static int mod_map_proc_instantiate(CONF_SECTION *cs, UNUSED void *mod_inst, voi * list member was pre-allocated and passed to the * instantiation callback. */ - if (fr_map_list_next(maps, map)) { + if (fr_dlist_map_next(maps, map)) { *tail = cache = talloc_zero(cache, rlm_json_jpath_cache_t); tail = &cache->next; } @@ -454,7 +454,7 @@ static rlm_rcode_t mod_map_proc(UNUSED void *mod_inst, void *proc_inst, request_ goto finish; } - while ((map = fr_map_list_next(maps, map))) { + while ((map = fr_dlist_map_next(maps, map))) { switch (map->rhs->type) { /* * Cached types diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index cb272bdf5d2..381a6d8c015 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -833,9 +833,9 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ } RINDENT(); - for (map = fr_map_list_head(maps), i = 0; + for (map = fr_dlist_map_head(maps), i = 0; map != NULL; - map = fr_map_list_next(maps, map), i++) { + map = fr_dlist_map_next(maps, map), i++) { int ret; fr_ldap_result_t attr; @@ -1418,7 +1418,7 @@ skip_edir: } } - if (!fr_map_list_empty(&inst->user_map) || inst->valuepair_attr) { + if (!fr_dlist_map_empty(&inst->user_map) || inst->valuepair_attr) { RDEBUG2("Processing user attributes"); RINDENT(); if (fr_ldap_map_do(request, handle, inst->valuepair_attr, @@ -1888,7 +1888,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); CONF_SECTION *conf = mctx->inst->conf; - fr_map_list_init(&inst->user_map); + fr_dlist_map_init(&inst->user_map); options = cf_section_find(conf, "options", NULL); if (!options || !cf_pair_find(options, "chase_referrals")) { diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index 6f9e27f0dd3..45112c76d1d 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -330,7 +330,7 @@ static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *pa fr_map_list_t *head = (fr_map_list_t *)out; fr_assert(cf_item_is_section(ci)); - fr_map_list_init(head); + fr_dlist_map_init(head); cs = cf_item_to_section(ci); name2 = cf_section_name2(cs); @@ -349,7 +349,7 @@ static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *pa rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, unlang_fixup_update, NULL, 128); if (rcode < 0) return -1; /* message already printed */ - if (fr_map_list_empty(head)) { + if (fr_dlist_map_empty(head)) { cf_log_err(cs, "'update' sections cannot be empty"); return -1; } diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index b5e3a39721a..c890b111882 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -370,7 +370,7 @@ static void CC_HINT(nonnull) status_check_alloc(udp_handle_t *h) * Create the VPs, and ignore any errors * creating them. */ - while ((map = fr_map_list_next(&inst->parent->status_check_map, map))) { + while ((map = fr_dlist_map_next(&inst->parent->status_check_map, map))) { /* * Skip things which aren't attributes. */ diff --git a/src/modules/rlm_smtp/rlm_smtp.c b/src/modules/rlm_smtp/rlm_smtp.c index b9524e6a864..36095527313 100644 --- a/src/modules/rlm_smtp/rlm_smtp.c +++ b/src/modules/rlm_smtp/rlm_smtp.c @@ -547,7 +547,7 @@ static int header_source(rlm_smtp_thread_t *t, fr_mail_ctx_t *uctx, rlm_smtp_t c * Initialize the sbuff for writing the config elements as header attributes */ fr_sbuff_init_talloc(uctx, &conf_buffer, &conf_ctx, 256, SIZE_MAX); - conf_map = fr_map_list_head(&inst->header_maps); + conf_map = fr_dlist_map_head(&inst->header_maps); /* * Load in all of the header elements supplied in the config @@ -571,10 +571,10 @@ static int header_source(rlm_smtp_thread_t *t, fr_mail_ctx_t *uctx, rlm_smtp_t c next: /* Check if there are more values to parse */ - if (!fr_map_list_next(&inst->header_maps, conf_map)) break; + if (!fr_dlist_map_next(&inst->header_maps, conf_map)) break; /* reinitialize the buffer and move to the next value */ fr_sbuff_init_talloc(uctx, &conf_buffer, &conf_ctx, 256, SIZE_MAX); - conf_map = fr_map_list_next(&inst->header_maps, conf_map); + conf_map = fr_dlist_map_next(&inst->header_maps, conf_map); } /* Add the FROM: line */ @@ -1045,7 +1045,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *header; - fr_map_list_init(&inst->header_maps); + fr_dlist_map_init(&inst->header_maps); header = cf_section_find(conf, "header", NULL); if (!header) return 0; diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 6b215d906cd..b19fd0f428f 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -486,9 +486,9 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ * faster than building a radix tree each time the * map set is evaluated (map->rhs can be dynamic). */ - for (map = fr_map_list_head(maps), i = 0; + for (map = fr_dlist_map_head(maps), i = 0; map && (i < MAX_SQL_FIELD_INDEX); - map = fr_map_list_next(maps, map), i++) { + map = fr_dlist_map_next(maps, map), i++) { /* * Expand the RHS to get the name of the SQL field */ @@ -525,9 +525,9 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ */ while (((ret = rlm_sql_fetch_row(&row, inst, request, &handle)) == RLM_SQL_OK)) { rows++; - for (map = fr_map_list_head(maps), j = 0; + for (map = fr_dlist_map_head(maps), j = 0; map && (j < MAX_SQL_FIELD_INDEX); - map = fr_map_list_next(maps, map), j++) { + map = fr_dlist_map_next(maps, map), j++) { if (field_index[j] < 0) continue; /* We didn't find the map RHS in the field set */ if (map_to_request(request, map, _sql_map_proc_get_value, row[field_index[j]]) < 0) goto error; }