From: Alan T. DeKok Date: Tue, 18 May 2021 17:28:49 +0000 (-0400) Subject: add parent to map_afrom_substr() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fbceee2e8b530e4fea19cc4c36759b002bc2ac3;p=thirdparty%2Ffreeradius-server.git add parent to map_afrom_substr() the other functions don't seem to need parents. The next step is to support relative attributes, and make "parent" a "map_t **", so that the parsing can walk back up (or down) the map stack, in order to place the maps in the correct place --- diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 7247caa253e..fde2a567159 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -286,7 +286,8 @@ fr_sbuff_parse_rules_t const *map_parse_rules_quoted[T_TOKEN_LAST] = { * * @param[in] ctx for talloc. * @param[in] out Where to write the pointer to the new #map_t. - * @param[in] in to convert to map. + * @param[in] parent the parent map + * @param[in] in the data to parse for creating the map. * @param[in] op_table for lhs OP rhs * @param[in] op_table_len length of op_table * @param[in] lhs_rules rules for parsing LHS attribute references. @@ -297,7 +298,7 @@ fr_sbuff_parse_rules_t const *map_parse_rules_quoted[T_TOKEN_LAST] = { * - >0 on success. * - <=0 on error. */ -ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, fr_sbuff_t *in, +ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t *parent, fr_sbuff_t *in, fr_table_num_sorted_t const *op_table, size_t op_table_len, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, fr_sbuff_parse_rules_t const *p_rules) @@ -310,7 +311,7 @@ ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, fr_sbuff_t *in, fr_sbuff_term_t const *tt = p_rules ? p_rules->terminals : NULL; *out = NULL; - MEM(map = map_alloc(ctx, NULL)); + MEM(map = map_alloc(ctx, parent)); (void)fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, tt); @@ -753,7 +754,7 @@ int map_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *vp_str, { fr_sbuff_t sbuff = FR_SBUFF_IN(vp_str, strlen(vp_str)); - if (map_afrom_substr(ctx, out, &sbuff, map_assignment_op_table, map_assignment_op_table_len, + if (map_afrom_substr(ctx, out, NULL, &sbuff, map_assignment_op_table, map_assignment_op_table_len, lhs_rules, rhs_rules, NULL) < 0) { return -1; } diff --git a/src/lib/server/map.h b/src/lib/server/map.h index 4ae5098c9b2..58baa3f5a17 100644 --- a/src/lib/server/map.h +++ b/src/lib/server/map.h @@ -130,7 +130,7 @@ int map_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *raw, int map_afrom_vp(TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const *rules); -ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, fr_sbuff_t *in, +ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t *parent, fr_sbuff_t *in, fr_table_num_sorted_t const *op_table, size_t op_table_len, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, fr_sbuff_parse_rules_t const *p_rules); diff --git a/src/lib/server/users_file.c b/src/lib/server/users_file.c index 9699e835ec8..4a780c7bf7b 100644 --- a/src/lib/server/users_file.c +++ b/src/lib/server/users_file.c @@ -398,7 +398,7 @@ check_item: /* * Try to parse the check item. */ - slen = map_afrom_substr(t, &new_map, &sbuff, check_cmp_op_table, check_cmp_op_table_len, + slen = map_afrom_substr(t, &new_map, NULL, &sbuff, check_cmp_op_table, check_cmp_op_table_len, &lhs_rules, &rhs_rules, &rhs_term); if (!new_map) { ERROR_MARKER_ADJ(&sbuff, slen, fr_strerror()); @@ -588,7 +588,7 @@ next_reply_item: * lead to here have already checked for those * cases. */ - slen = map_afrom_substr(t, &new_map, &sbuff, map_assignment_op_table, map_assignment_op_table_len, + slen = map_afrom_substr(t, &new_map, NULL, &sbuff, map_assignment_op_table, map_assignment_op_table_len, &lhs_rules, &rhs_rules, &rhs_term); if (!new_map) { ERROR_MARKER_ADJ(&sbuff, slen, fr_strerror());