From: Arran Cudbard-Bell Date: Tue, 28 May 2024 02:03:13 +0000 (-0400) Subject: Split section name match X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96327a3198c9e884e979780ca6cd4a8a8705e772;p=thirdparty%2Ffreeradius-server.git Split section name match --- diff --git a/src/lib/server/module.h b/src/lib/server/module.h index 48d29ab28de..f4115b3f3f1 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -158,10 +158,10 @@ struct module_method_binding_s { module_method_t method; //!< Module method to call call_env_method_t const *method_env; //!< Method specific call_env. - fr_dlist_head_t name2_list; //!< List of bindings with the same name1. Only initialised + fr_dlist_head_t same_name1; //!< List of bindings with the same name1. Only initialised ///< for the the first name1 binding. ///< DO NOT INITIALISE IN THE MODULE. - fr_dlist_t name2_entry; //!< Linked list of bindings with the same name1. + fr_dlist_t entry; //!< Linked list of bindings with the same name1. ///< Allows us to more quickly iterate over all ///< name2 entries after finding a matching name1. ///< This is also temporarily used to verify the ordering diff --git a/src/lib/server/module_rlm.c b/src/lib/server/module_rlm.c index 79342b40b99..7c19c6571a4 100644 --- a/src/lib/server/module_rlm.c +++ b/src/lib/server/module_rlm.c @@ -982,7 +982,7 @@ static int module_method_validate(module_instance_t *mi) mrlm = module_rlm_from_module(mi->exported); - fr_dlist_init(&bindings, module_method_binding_t, name2_entry); + fr_dlist_init(&bindings, module_method_binding_t, entry); /* * Not all modules export module method bindings @@ -1085,10 +1085,10 @@ static int module_method_validate(module_instance_t *mi) ) ) ) { - fr_dlist_init(&p->name2_list, module_method_binding_t, name2_entry); + fr_dlist_init(&p->same_name1, module_method_binding_t, entry); last_binding = p; } - fr_dlist_insert_tail(&last_binding->name2_list, p); + fr_dlist_insert_tail(&last_binding->same_name1, p); } } diff --git a/src/lib/server/section.c b/src/lib/server/section.c index 8745e17cd5a..3dc09eb3920 100644 --- a/src/lib/server/section.c +++ b/src/lib/server/section.c @@ -96,24 +96,3 @@ name2: return CMP(strcmp(a->name2, b->name2), 0); } - -/* Compare two section names - * - * Respects CF_IDENT_ANY values - * - * @param[in] a First section name. - * @param[in] b Second section name. - * - * @return true if the section names match, false otherwise. - */ -bool section_name_match(section_name_t const *a, section_name_t const *b) -{ - if ((a->name1 == CF_IDENT_ANY) || (b->name2 == CF_IDENT_ANY)) goto name2; - - if (strcmp(a->name1, b->name1) != 0) return false; - -name2: - if ((a->name2 == CF_IDENT_ANY) || (b->name2 == CF_IDENT_ANY)) return true; - - return (strcmp(a->name2, b->name2) == 0); -} diff --git a/src/lib/server/section.h b/src/lib/server/section.h index 34b502fb2bf..f16664fdb19 100644 --- a/src/lib/server/section.h +++ b/src/lib/server/section.h @@ -26,6 +26,7 @@ RCSIDH(section_h, "$Id$") #include +#include #ifdef __cplusplus extern "C" { @@ -45,9 +46,46 @@ typedef struct { char const *name2; //!< Second section name. Usually a packet type like 'access-request', 'access-accept', etc... } section_name_t; -int8_t section_name_cmp(void const *one, void const *two); +/* Compare two sections based on name2 + * + * Respects CF_IDENT_ANY values + * + * @param[in] a First section name. + * @param[in] b Second section name. + * + * @return + * - 1 if name2 values match. + * - 0 if name2 values don't match. + */ +static inline int section_name2_match(section_name_t const *a, section_name_t const *b) +{ + if ((a->name2 == CF_IDENT_ANY) || (b->name2 == CF_IDENT_ANY)) return 1; + + return (strcmp(a->name2, b->name2) == 0) ? 1 : 0; +} + +/* Compare two section names + * + * Respects CF_IDENT_ANY values + * + * @param[in] a First section name. + * @param[in] b Second section name. + * + * @return + * - 1 if the section names match. + * - 0 if the section names don't match. + * - -1 if name1 doesn't match. + * + */ +static inline int section_name_match(section_name_t const *a, section_name_t const *b) +{ + if ((a->name1 == CF_IDENT_ANY) || (b->name2 == CF_IDENT_ANY)) goto name2; + + if (strcmp(a->name1, b->name1) != 0) return -1; -bool section_name_match(section_name_t const *a, section_name_t const *b); +name2: + return section_name2_match(a, b); +} #ifdef __cplusplus }