]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Split section name match
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 28 May 2024 02:03:13 +0000 (22:03 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 8 Jun 2024 19:11:00 +0000 (15:11 -0400)
src/lib/server/module.h
src/lib/server/module_rlm.c
src/lib/server/section.c
src/lib/server/section.h

index 48d29ab28de96646a68855fbf143cb1557ce930e..f4115b3f3f102ad5867e3c8c486e65254d9345ad 100644 (file)
@@ -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
index 79342b40b990ee41b822587bff468462d3649bd3..7c19c6571a49e994d6161901ed06d84ef30e8fe3 100644 (file)
@@ -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);
                }
        }
 
index 8745e17cd5ae8f544c89a49886b93b9437c328c6..3dc09eb3920cd55501f63eec6c53cfae9a99e061 100644 (file)
@@ -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);
-}
index 34b502fb2bf2a8bb1273acebe1f0884c1d9121ed..f16664fdb19d5f8b32466df8838feceff866eb6b 100644 (file)
@@ -26,6 +26,7 @@
 RCSIDH(section_h, "$Id$")
 
 #include <stdbool.h>
+#include <freeradius-devel/server/cf_util.h>
 
 #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
 }