From: Alan T. DeKok Date: Wed, 16 Dec 2020 15:51:47 +0000 (-0500) Subject: add function which converts one map_t to fr_cond_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59c0cc66a847d56e4ea5313ea0251cf98a495a5f;p=thirdparty%2Ffreeradius-server.git add function which converts one map_t to fr_cond_t in preparation for using it in rlm_files --- diff --git a/src/lib/server/cond.h b/src/lib/server/cond.h index 4d526496885..582e89ddfcb 100644 --- a/src/lib/server/cond.h +++ b/src/lib/server/cond.h @@ -109,6 +109,8 @@ ssize_t cond_print(fr_sbuff_t *out, fr_cond_t const *c); bool fr_cond_walk(fr_cond_t *head, bool (*callback)(fr_cond_t *cond, void *uctx), void *uctx); +int fr_cond_from_map(TALLOC_CTX *ctx, fr_cond_t **head, map_t *map); + #ifdef __cplusplus } #endif diff --git a/src/lib/server/cond_tokenize.c b/src/lib/server/cond_tokenize.c index a78a753e34d..0794a81e25d 100644 --- a/src/lib/server/cond_tokenize.c +++ b/src/lib/server/cond_tokenize.c @@ -1684,3 +1684,35 @@ bool fr_cond_walk(fr_cond_t *c, bool (*callback)(fr_cond_t *cond, void *uctx), v return true; } + +/** Convert a single map to a condition. + * + * @param ctx the talloc context where the condition is allocated + * @param[out] head the newly allocated condition. Should only be one! + * @param[in] map the map to convert. MAY be freed. + * @return + * - <0 on error "map" is untouched. + * - 0 on success - "map" MAY be freed + */ +int fr_cond_from_map(TALLOC_CTX *ctx, fr_cond_t **head, map_t *map) +{ + fr_cond_t *cond = talloc_zero(ctx, fr_cond_t); + + if (!cond) return -1; + + cond->type = COND_TYPE_MAP; + cond->data.map = map; + + if (cond_normalise(ctx, T_BARE_WORD, &cond) < 0) return -1; + + /* + * If the condition is still a MAP, then make the map + * owned by the condition. + */ + if (cond->type == COND_TYPE_MAP) { + (void) talloc_steal(cond, map); + } + + *head = cond; + return 0; +}