From: Arran Cudbard-Bell Date: Wed, 6 Jan 2021 16:56:29 +0000 (+0000) Subject: Better names for some tmpl functions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=805de723c38ec8aeec50ca26badf257917b37bdc;p=thirdparty%2Ffreeradius-server.git Better names for some tmpl functions --- diff --git a/src/bin/radclient.h b/src/bin/radclient.h index a623600d532..65785a5069d 100644 --- a/src/bin/radclient.h +++ b/src/bin/radclient.h @@ -51,42 +51,46 @@ extern "C" { #define RDEBUG2(fmt, ...) if (do_output && (fr_debug_lvl > 1)) fprintf(fr_log_fp, "(%" PRIu64 ") " fmt "\n", request->num, ## __VA_ARGS__) typedef struct { - uint64_t accepted; //!< Requests to which we received a accept - uint64_t rejected; //!< Requests to which we received a reject - uint64_t lost; //!< Requests to which we received no response - uint64_t passed; //!< Requests which passed a filter - uint64_t failed; //!< Requests which failed a fitler + uint64_t accepted; //!< Requests to which we received a accept + uint64_t rejected; //!< Requests to which we received a reject + uint64_t lost; //!< Requests to which we received no response + uint64_t passed; //!< Requests which passed a filter + uint64_t failed; //!< Requests which failed a fitler } rc_stats_t; typedef struct { - char const *packets; //!< The file containing the request packet - char const *filters; //!< The file containing the definition of the - //!< packet we want to match. + char const *packets; //!< The file containing the request packet + char const *filters; //!< The file containing the definition of the + //!< packet we want to match. } rc_file_pair_t; typedef struct rc_request rc_request_t; struct rc_request { - uint64_t num; //!< The number (within the file) of the request were reading. + uint64_t num; //!< The number (within the file) of the request were reading. - rc_request_t *prev; - rc_request_t *next; + rc_request_t *prev; + rc_request_t *next; - rc_file_pair_t *files; //!< Request and response file names. + rc_file_pair_t *files; //!< Request and response file names. - fr_pair_t *password; //!< Password.Cleartext - fr_time_delta_t timestamp; + fr_pair_t *password; //!< Password.Cleartext + fr_time_delta_t timestamp; fr_radius_packet_t *packet; //!< The outgoing request. fr_radius_packet_t *reply; //!< The incoming response. - fr_pair_list_t filter; //!< If the reply passes the filter, then the request passes. - FR_CODE filter_code; //!< Expected code of the response packet. - int resend; - int tries; - bool done; //!< Whether the request is complete. + fr_pair_list_t *request_list; + fr_pair_list_t *reply_list; - char const *name; //!< Test name (as specified in the request). + fr_pair_list_t filter; //!< If the reply passes the filter, then the request passes. + FR_CODE filter_code; //!< Expected code of the response packet. + + int resend; + int tries; + bool done; //!< Whether the request is complete. + + char const *name; //!< Test name (as specified in the request). }; #ifdef __cplusplus diff --git a/src/lib/server/map.c b/src/lib/server/map.c index ef87d1306ce..4b3a2ccaf16 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -490,7 +490,7 @@ int map_afrom_cs(TALLOC_CTX *ctx, map_t **out, CONF_SECTION *cs, */ cs_list = p = cf_section_name2(cs); if (cs_list && (strcmp(cf_section_name1(cs), "update") == 0)) { - p += radius_request_name(&our_lhs_rules.request_def, p, REQUEST_CURRENT); + p += tmpl_request_ref_by_name(&our_lhs_rules.request_def, p, REQUEST_CURRENT); if (our_lhs_rules.request_def == REQUEST_UNKNOWN) { cf_log_err(ci, "Default request specified in mapping section is invalid"); return -1; @@ -898,7 +898,7 @@ static int map_exec_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *reque /* * We always put the request pairs into the environment */ - input_pairs = tmpl_request_pair_list(request, PAIR_LIST_REQUEST); + input_pairs = tmpl_list_head(request, PAIR_LIST_REQUEST); /* * Automagically switch output type depending on our destination @@ -996,8 +996,8 @@ int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t co if (tmpl_is_list(map->lhs) && tmpl_is_list(map->rhs)) { fr_pair_list_t *from = NULL; - if (radius_request(&context, tmpl_request(map->rhs)) == 0) { - from = tmpl_request_pair_list(context, tmpl_list(map->rhs)); + if (tmpl_request_ptr(&context, tmpl_request(map->rhs)) == 0) { + from = tmpl_list_head(context, tmpl_list(map->rhs)); } if (!from) return 0; @@ -1310,7 +1310,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f context = request; request_ref = tmpl_request(map->lhs); - if (radius_request(&context, request_ref) < 0) { + if (tmpl_request_ptr(&context, request_ref) < 0) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to invalid request reference \"%s\" in right side of map", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, fr_table_str_by_value(tmpl_request_ref_table, request_ref, "")); @@ -1319,7 +1319,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f } list_ref = tmpl_list(map->lhs); - list = tmpl_request_pair_list(context, list_ref); + list = tmpl_list_head(context, list_ref); if (!list) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\" in left side of map", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, @@ -1328,7 +1328,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f goto finish; } - parent = tmpl_request_pair_list_ctx(context, tmpl_list(map->lhs)); + parent = tmpl_list_ctx(context, tmpl_list(map->lhs)); fr_assert(parent); /* diff --git a/src/lib/server/map_async.c b/src/lib/server/map_async.c index b50c8b84f66..3ec6f7b8634 100644 --- a/src/lib/server/map_async.c +++ b/src/lib/server/map_async.c @@ -203,7 +203,7 @@ static inline fr_pair_list_t *map_check_src_or_dst(request_t *request, map_t con tmpl_pair_list_t list_ref; request_ref = tmpl_request(src_dst); - if (radius_request(&context, request_ref) < 0) { + if (tmpl_request_ptr(&context, request_ref) < 0) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to invalid request reference \"%s\"", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, fr_table_str_by_value(tmpl_request_ref_table, request_ref, "")); @@ -211,7 +211,7 @@ static inline fr_pair_list_t *map_check_src_or_dst(request_t *request, map_t con } list_ref = tmpl_list(src_dst); - list = tmpl_request_pair_list(context, list_ref); + list = tmpl_list_head(context, list_ref); if (!list) { REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\"", (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name, @@ -980,12 +980,12 @@ int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm) * All this has been checked by #map_to_list_mod */ context = request; - if (!fr_cond_assert(mod && radius_request(&context, tmpl_request(mod->lhs)) == 0)) return -1; + if (!fr_cond_assert(mod && tmpl_request_ptr(&context, tmpl_request(mod->lhs)) == 0)) return -1; - vp_list = tmpl_request_pair_list(context, tmpl_list(mod->lhs)); + vp_list = tmpl_list_head(context, tmpl_list(mod->lhs)); if (!fr_cond_assert(vp_list)) return -1; - parent = tmpl_request_pair_list_ctx(context, tmpl_list(mod->lhs)); + parent = tmpl_list_ctx(context, tmpl_list(mod->lhs)); fr_assert(parent); /* diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index 840ea6715fc..c79b381bda1 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -769,9 +769,9 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt); #define tmpl_pair_list_AND_CTX(_ctx, _head, _request, _ref, _list) \ do {\ request_t *_rctx = _request; \ - if ((radius_request(&_rctx, _ref) < 0) || \ - !(_head = tmpl_request_pair_list(_rctx, _list)) || \ - !(_ctx = tmpl_request_pair_list_ctx(_rctx, _list))) {\ + if ((tmpl_request_ptr(&_rctx, _ref) < 0) || \ + !(_head = tmpl_list_head(_rctx, _list)) || \ + !(_ctx = tmpl_list_ctx(_rctx, _list))) {\ _ctx = NULL; \ _head = NULL; \ }\ @@ -846,17 +846,17 @@ typedef enum { void tmpl_debug(tmpl_t const *vpt); -fr_pair_list_t *tmpl_request_pair_list(request_t *request, tmpl_pair_list_t list); +fr_pair_list_t *tmpl_list_head(request_t *request, tmpl_pair_list_t list); -fr_radius_packet_t *tmpl_request_packet(request_t *request, tmpl_pair_list_t list_name); +fr_radius_packet_t *tmpl_packet_ptr(request_t *request, tmpl_pair_list_t list_name); -TALLOC_CTX *tmpl_request_pair_list_ctx(request_t *request, tmpl_pair_list_t list_name); +TALLOC_CTX *tmpl_list_ctx(request_t *request, tmpl_pair_list_t list_name); size_t tmpl_pair_list_name(tmpl_pair_list_t *out, char const *name, tmpl_pair_list_t default_list); -int radius_request(request_t **request, tmpl_request_ref_t name); +int tmpl_request_ptr(request_t **request, tmpl_request_ref_t name); -size_t radius_request_name(tmpl_request_ref_t *out, char const *name, tmpl_request_ref_t unknown); +size_t tmpl_request_ref_by_name(tmpl_request_ref_t *out, char const *name, tmpl_request_ref_t unknown); tmpl_t *tmpl_init_printf(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *fmt, ...); diff --git a/src/lib/server/tmpl_eval.c b/src/lib/server/tmpl_eval.c index 74005d551fd..802901912e0 100644 --- a/src/lib/server/tmpl_eval.c +++ b/src/lib/server/tmpl_eval.c @@ -45,7 +45,7 @@ RCSID("$Id$") * * @see tmpl_cursor_init */ -fr_pair_list_t *tmpl_request_pair_list(request_t *request, tmpl_pair_list_t list) +fr_pair_list_t *tmpl_list_head(request_t *request, tmpl_pair_list_t list) { if (!request) return NULL; @@ -90,7 +90,7 @@ fr_pair_list_t *tmpl_request_pair_list(request_t *request, tmpl_pair_list_t list * * @see tmpl_pair_list */ -TALLOC_CTX *tmpl_request_pair_list_ctx(request_t *request, tmpl_pair_list_t list) +TALLOC_CTX *tmpl_list_ctx(request_t *request, tmpl_pair_list_t list) { if (!request) return NULL; @@ -128,7 +128,7 @@ TALLOC_CTX *tmpl_request_pair_list_ctx(request_t *request, tmpl_pair_list_t list * * @see tmpl_pair_list */ -fr_radius_packet_t *tmpl_request_packet(request_t *request, tmpl_pair_list_t list) +fr_radius_packet_t *tmpl_packet_ptr(request_t *request, tmpl_pair_list_t list) { switch (list) { /* Don't add default */ @@ -161,7 +161,7 @@ fr_radius_packet_t *tmpl_request_packet(request_t *request, tmpl_pair_list_t lis * - 0 if request is valid in this context. * - -1 if request is not valid in this context. */ -int radius_request(request_t **context, tmpl_request_ref_t name) +int tmpl_request_ptr(request_t **context, tmpl_request_ref_t name) { request_t *request = *context; @@ -1213,7 +1213,7 @@ fr_pair_t *tmpl_cursor_init(int *err, TALLOC_CTX *ctx, tmpl_cursor_ctx_t *cc, * Navigate to the correct request context */ while ((rr = fr_dlist_next(&vpt->data.attribute.rr, rr))) { - if (radius_request(&request, rr->request) < 0) { + if (tmpl_request_ptr(&request, rr->request) < 0) { if (err) { *err = -3; fr_strerror_printf("Request context \"%s\" not available", @@ -1228,7 +1228,7 @@ fr_pair_t *tmpl_cursor_init(int *err, TALLOC_CTX *ctx, tmpl_cursor_ctx_t *cc, /* * Get the right list in the specified context */ - list_head = tmpl_request_pair_list(request, tmpl_list(vpt)); + list_head = tmpl_list_head(request, tmpl_list(vpt)); if (!list_head) { if (err) { *err = -2; @@ -1237,7 +1237,7 @@ fr_pair_t *tmpl_cursor_init(int *err, TALLOC_CTX *ctx, tmpl_cursor_ctx_t *cc, } goto error; } - list_ctx = tmpl_request_pair_list_ctx(request, tmpl_list(vpt)); + list_ctx = tmpl_list_ctx(request, tmpl_list(vpt)); /* * Initialise the temporary cursor context @@ -1547,7 +1547,7 @@ int tmpl_extents_find(TALLOC_CTX *ctx, * Navigate to the correct request context */ while ((rr = fr_dlist_next(&vpt->data.attribute.rr, rr))) { - if (radius_request(&request, rr->request) < 0) { + if (tmpl_request_ptr(&request, rr->request) < 0) { fr_strerror_printf("Request context \"%s\" not available", fr_table_str_by_value(tmpl_request_ref_table, rr->request, "")); return -3; @@ -1557,13 +1557,13 @@ int tmpl_extents_find(TALLOC_CTX *ctx, /* * Get the right list in the specified context */ - list_head = tmpl_request_pair_list(request, tmpl_list(vpt)); + list_head = tmpl_list_head(request, tmpl_list(vpt)); if (!list_head) { fr_strerror_printf("List \"%s\" not available in this context", fr_table_str_by_value(pair_list_table, tmpl_list(vpt), "")); return -2; } - list_ctx = tmpl_request_pair_list_ctx(request, tmpl_list(vpt)); + list_ctx = tmpl_list_ctx(request, tmpl_list(vpt)); /* * If it's a list, just return the list head diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 94eada6482a..d71bdf1d27d 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -290,7 +290,7 @@ void tmpl_debug(tmpl_t const *vpt) * These functions also resolve #pair_list_t and #tmpl_request_ref_t values to #request_t * structs and the head of #fr_pair_t lists in those structs. * - * For adding new #fr_pair_t to the lists, the #tmpl_request_pair_list_ctx function can be used + * For adding new #fr_pair_t to the lists, the #tmpl_list_ctx function can be used * to obtain the appropriate TALLOC_CTX pointer. * * @note These don't really have much to do with #tmpl_t. They're in the same @@ -402,7 +402,7 @@ size_t tmpl_pair_list_name(tmpl_pair_list_t *out, char const *name, tmpl_pair_li * @see tmpl_pair_list_name * @see tmpl_request_ref_table */ -size_t radius_request_name(tmpl_request_ref_t *out, char const *name, tmpl_request_ref_t def) +size_t tmpl_request_ref_by_name(tmpl_request_ref_t *out, char const *name, tmpl_request_ref_t def) { char const *p, *q; diff --git a/src/lib/unlang/xlat_eval.c b/src/lib/unlang/xlat_eval.c index 468d904baa3..89d20a60f2a 100644 --- a/src/lib/unlang/xlat_eval.c +++ b/src/lib/unlang/xlat_eval.c @@ -464,7 +464,7 @@ static xlat_action_t xlat_eval_pair_virtual(TALLOC_CTX *ctx, fr_cursor_t *out, r * If there's no packet, we can't print any attribute * referencing it. */ - packet = tmpl_request_packet(request, tmpl_list(vpt)); + packet = tmpl_packet_ptr(request, tmpl_list(vpt)); if (!packet) return XLAT_ACTION_DONE; if (tmpl_da(vpt) == attr_packet_type) { diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index 8fe4d5a0e82..aa4b06eeda8 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -113,7 +113,7 @@ static ssize_t exec_xlat(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, } if (inst->input_list) { - input_pairs = tmpl_request_pair_list(request, inst->input_list); + input_pairs = tmpl_list_head(request, inst->input_list); if (!input_pairs) { REDEBUG("Failed to find input pairs for xlat"); return -1; @@ -270,7 +270,7 @@ static unlang_action_t mod_exec_nowait_resume(rlm_rcode_t *p_result, module_ctx_ if (inst->input) { fr_pair_list_t *input_pairs; - input_pairs = tmpl_request_pair_list(request, inst->input_list); + input_pairs = tmpl_list_head(request, inst->input_list); if (!input_pairs) { RETURN_MODULE_INVALID; } @@ -362,10 +362,10 @@ static unlang_action_t mod_exec_wait_resume(rlm_rcode_t *p_result, module_ctx_t RDEBUG("EXEC GOT -- %pV", m->box); - output_pairs = tmpl_request_pair_list(request, inst->output_list); + output_pairs = tmpl_list_head(request, inst->output_list); fr_assert(output_pairs != NULL); - ctx = tmpl_request_pair_list_ctx(request, inst->output_list); + ctx = tmpl_list_ctx(request, inst->output_list); vps = fr_pair_list_afrom_box(ctx, request->dict, m->box); if (vps) fr_pair_list_move(output_pairs, &vps); @@ -425,14 +425,14 @@ static unlang_action_t CC_HINT(nonnull) mod_exec_dispatch(rlm_rcode_t *p_result, if (inst->input) { fr_pair_list_t *input_pairs; - input_pairs = tmpl_request_pair_list(request, inst->input_list); + input_pairs = tmpl_list_head(request, inst->input_list); if (!input_pairs) RETURN_MODULE_INVALID; env_pairs = *input_pairs; } if (inst->output) { - if (!tmpl_request_pair_list(request, inst->output_list)) { + if (!tmpl_list_head(request, inst->output_list)) { RETURN_MODULE_INVALID; } } diff --git a/src/modules/rlm_ldap/groups.c b/src/modules/rlm_ldap/groups.c index 3c24165dd29..bd011d9c04a 100644 --- a/src/modules/rlm_ldap/groups.c +++ b/src/modules/rlm_ldap/groups.c @@ -310,8 +310,8 @@ unlang_action_t rlm_ldap_cacheable_userobj(rlm_rcode_t *p_result, rlm_ldap_t con } count = ldap_count_values_len(values); - list = tmpl_request_pair_list(request, PAIR_LIST_CONTROL); - list_ctx = tmpl_request_pair_list_ctx(request, PAIR_LIST_CONTROL); + list = tmpl_list_head(request, PAIR_LIST_CONTROL); + list_ctx = tmpl_list_ctx(request, PAIR_LIST_CONTROL); fr_assert(list != NULL); fr_assert(list_ctx != NULL); diff --git a/src/modules/rlm_mruby/rlm_mruby.c b/src/modules/rlm_mruby/rlm_mruby.c index 9f77583d8c6..322b4dd7495 100644 --- a/src/modules/rlm_mruby/rlm_mruby.c +++ b/src/modules/rlm_mruby/rlm_mruby.c @@ -363,7 +363,7 @@ static void add_vp_tuple(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vp continue; } - if (radius_request(&request, tmpl_request(dst)) < 0) { + if (tmpl_request_ptr(&request, tmpl_request(dst)) < 0) { ERROR("Attribute name %s refers to outer request but not in a tunnel, skipping...", ckey); talloc_free(dst); continue; diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index 32ffcf6c419..4ae82a43809 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -331,7 +331,7 @@ static void mod_vptuple(TALLOC_CTX *ctx, rlm_python_t const *inst, request_t *re continue; } - if (radius_request(¤t, tmpl_request(dst)) < 0) { + if (tmpl_request_ptr(¤t, tmpl_request(dst)) < 0) { ERROR("%s - Attribute name %s.%s refers to outer request but not in a tunnel, skipping...", funcname, list_name, s1); talloc_free(dst); diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index dbf57581f67..e184eb442b5 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -751,19 +751,19 @@ static int rest_decode_post(UNUSED rlm_rest_t const *instance, UNUSED rlm_rest_s goto skip; } - if (radius_request(¤t, tmpl_request(dst)) < 0) { + if (tmpl_request_ptr(¤t, tmpl_request(dst)) < 0) { RWDEBUG("Attribute name refers to outer request but not in a tunnel (skipping)"); talloc_free(dst); goto skip; } - vps = tmpl_request_pair_list(current, tmpl_list(dst)); + vps = tmpl_list_head(current, tmpl_list(dst)); if (!vps) { RWDEBUG("List not valid in this context (skipping)"); talloc_free(dst); goto skip; } - ctx = tmpl_request_pair_list_ctx(current, tmpl_list(dst)); + ctx = tmpl_list_ctx(current, tmpl_list(dst)); da = tmpl_da(dst); fr_assert(vps); @@ -1038,17 +1038,17 @@ static int json_pair_alloc(rlm_rest_t const *instance, rlm_rest_section_t const continue; } - if (radius_request(¤t, tmpl_request(dst)) < 0) { + if (tmpl_request_ptr(¤t, tmpl_request(dst)) < 0) { RWDEBUG("Attribute name refers to outer request but not in a tunnel (skipping)"); continue; } - vps = tmpl_request_pair_list(current, tmpl_list(dst)); + vps = tmpl_list_head(current, tmpl_list(dst)); if (!vps) { RWDEBUG("List not valid in this context (skipping)"); continue; } - ctx = tmpl_request_pair_list_ctx(current, tmpl_list(dst)); + ctx = tmpl_list_ctx(current, tmpl_list(dst)); /* * Alternative JSON structure which allows operator,