diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 1badeb596e..ab05dc46fa 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -587,6 +587,8 @@ libwireshark.so.0 libwireshark0 #MINVER# epan_get_version_number@Base 2.5.0 epan_init@Base 2.9.0 epan_inspect_enums@Base 3.7.0 + epan_inspect_enums_bsearch@Base 3.7.0 + epan_inspect_enums_count@Base 3.7.0 epan_load_settings@Base 2.3.0 epan_memmem@Base 1.9.1 epan_new@Base 1.12.0~rc1 diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index aa39e7c63d..224fd7bb23 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -211,7 +211,7 @@ set(LIBWIRESHARK_NONGENERATED_FILES guid-utils.c iana_charsets.c in_cksum.c - introspection-enums.c + introspection.c ipproto.c maxmind_db.c media_params.c diff --git a/epan/introspection-enums.c b/epan/introspection-enums.c index 5bb8f9ea83..7a356da3e2 100644 --- a/epan/introspection-enums.c +++ b/epan/introspection-enums.c @@ -14,8 +14,6 @@ * requirement to re-run the generator script. * */ -#include "config.h" -#include "introspection.h" #include #include #include @@ -428,8 +426,3 @@ static ws_enum_t all_enums[] = { ENUM(STR_UNICODE), { NULL, 0 }, }; - -const ws_enum_t *epan_inspect_enums(void) -{ - return all_enums; -} diff --git a/epan/introspection.c b/epan/introspection.c new file mode 100644 index 0000000000..c42b86b2ec --- /dev/null +++ b/epan/introspection.c @@ -0,0 +1,37 @@ +/* + * Copyright 2021, João Valverde + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "config.h" +#include "introspection.h" +#include +#include + +#include "introspection-enums.c" + +const ws_enum_t *epan_inspect_enums(void) +{ + return all_enums; +} + +static int compare_enum(const void *needle, const void *memb) +{ + return strcmp(needle, ((const ws_enum_t *)memb)->symbol); +} + +size_t epan_inspect_enums_count(void) +{ + /* Exclude null terminator */ + return sizeof(all_enums)/sizeof(ws_enum_t) - 1; +} + +const ws_enum_t *epan_inspect_enums_bsearch(const char *needle) +{ + return bsearch(needle, all_enums, epan_inspect_enums_count(), + sizeof(ws_enum_t), compare_enum); +} diff --git a/epan/introspection.h b/epan/introspection.h index 9a7eb61ab8..43c2946d65 100644 --- a/epan/introspection.h +++ b/epan/introspection.h @@ -11,6 +11,7 @@ #ifndef _INTROSPECTION_H_ #define _INTROSPECTION_H_ +#include #include typedef struct { @@ -28,4 +29,12 @@ typedef struct { WS_DLL_PUBLIC const ws_enum_t *epan_inspect_enums(void); +/** Returns size of enums array not including null terminator. */ +WS_DLL_PUBLIC +size_t epan_inspect_enums_count(void); + +/** Performs a binary search for the magic constant "needle". */ +WS_DLL_PUBLIC +const ws_enum_t *epan_inspect_enums_bsearch(const char *needle); + #endif diff --git a/tools/make-enums.py b/tools/make-enums.py index a201c5fa8c..459fd4a5d8 100755 --- a/tools/make-enums.py +++ b/tools/make-enums.py @@ -44,8 +44,6 @@ source = """\ * requirement to re-run the generator script. * */ -#include "config.h" -#include "introspection.h" """ % (os.path.basename(sys.argv[0])) for f in args.infiles: @@ -68,11 +66,6 @@ for s in symbols: source += """\ { NULL, 0 }, }; - -const ws_enum_t *epan_inspect_enums(void) -{ - return all_enums; -} """ try: