From: Alan T. DeKok Date: Mon, 26 Apr 2021 19:17:55 +0000 (-0400) Subject: add match() API X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=315e161f95c5b1f71e7591201c2cf03e7a2d06d6;p=thirdparty%2Ffreeradius-server.git add match() API --- diff --git a/src/lib/util/htrie.c b/src/lib/util/htrie.c index 4b2f5d2225c..41b5b0fb6fe 100644 --- a/src/lib/util/htrie.c +++ b/src/lib/util/htrie.c @@ -28,6 +28,7 @@ RCSID("$Id$") static fr_htrie_funcs_t const default_funcs[] = { [FR_HTRIE_HASH] = { + .match = (fr_htrie_find_t) fr_hash_table_find, FUNC(hash_table, find), FUNC(hash_table, insert), FUNC(hash_table, replace), @@ -36,6 +37,7 @@ static fr_htrie_funcs_t const default_funcs[] = { FUNC(hash_table, num_elements) }, [FR_HTRIE_RB] = { + .match = (fr_htrie_find_t) fr_rb_find, FUNC(rb, find), FUNC(rb, insert), FUNC(rb, replace), @@ -44,6 +46,7 @@ static fr_htrie_funcs_t const default_funcs[] = { FUNC(rb, num_elements) }, [FR_HTRIE_TRIE] = { + .match = (fr_htrie_find_t) fr_trie_match, FUNC(trie, find), FUNC(trie, insert), FUNC(trie, replace), diff --git a/src/lib/util/htrie.h b/src/lib/util/htrie.h index da723844114..68396e9292e 100644 --- a/src/lib/util/htrie.h +++ b/src/lib/util/htrie.h @@ -51,6 +51,7 @@ typedef uint32_t (*fr_htrie_num_elements_t)(fr_htrie_t *ht); */ typedef struct { fr_htrie_find_t find; //!< Absolute or prefix match. + fr_htrie_find_t match; //!< exact prefix match fr_htrie_insert_t insert; //!< Insert a new item into the store. fr_htrie_replace_t replace; //!< Replace an existing item in store. fr_htrie_remove_t remove; //!< Remove an item from the store. @@ -80,6 +81,14 @@ fr_htrie_t *fr_htrie_alloc(TALLOC_CTX *ctx, fr_trie_key_t get_key, fr_free_t free_data); +/** Match data in a htrie + * + */ +static inline CC_HINT(nonnull) void *fr_htrie_match(fr_htrie_t *ht, void const *data) +{ + return ht->funcs.match(ht->store, data); +} + /** Find data in a htrie * */