diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2017-08-29 15:34:31 +0100 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2017-12-14 22:12:38 +0000 |
commit | cebb8ea20ec2d4c1c1c000304c6cc6e7e9ccb8ad (patch) | |
tree | 7f1dfc10f5d802be657a6dcd6d3194b6e723bb9e /epan/epan.c | |
parent | 629596ebefa34a2677c341ab899e51cecbe254f0 (diff) |
Add new plugin type for libwireshark
Allow epan itself to be extended by plugins. Adds the following new plugin
interfaces:
void plugin_epan_init()
void plugin_epan_dissect_init(epan_dissect_t *)
void plugin_epan_dissect_cleanup(epan_dissect_t *)
void plugin_epan_cleanup()
void plugin_epan_register_all_protocols(register_cb, gointer) [OPTIONAL]
void plugin_epan_register_all_handoffs(register_cb, gointer) [OPTIONAL]
Any one of these can be an empty function but the first four must be
present.
The motivation for the change is a better way to implement a language binding
other than registering a fake protocol and stuffing everything into a single
dissector call (and maybe require an extra packet_info field) but I expect
there would be other interesting use cases.
Change-Id: I215d50750ac7561fe25fdcdcfbc6a3f351984785
Reviewed-on: https://code.wireshark.org/review/24813
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'epan/epan.c')
-rw-r--r-- | epan/epan.c | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/epan/epan.c b/epan/epan.c index 5b7a64ac74..42d9208d61 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -70,6 +70,10 @@ #include "stats_tree.h" #include <dtd.h> +#ifdef HAVE_PLUGINS +#include <wsutil/plugins.h> +#endif + #ifdef HAVE_LUA #include <lua.h> #include <wslua/wslua.h> @@ -92,10 +96,14 @@ #include <libxml/parser.h> #endif +static GSList *epan_register_all_procotols = NULL; +static GSList *epan_register_all_handoffs = NULL; + static wmem_allocator_t *pinfo_pool_cache = NULL; #ifdef HAVE_PLUGINS plugins_t *libwireshark_plugins = NULL; +static GSList *epan_plugins = NULL; #endif const gchar* @@ -140,6 +148,41 @@ quiet_gcrypt_logger (void *dummy _U_, int level, const char *format, va_list arg } #endif // _WIN32 +#ifdef HAVE_PLUGINS +static void +epan_plugin_init(gpointer data, gpointer user_data _U_) +{ + ((epan_plugin *)data)->init(); +} + +static void +epan_plugin_dissect_init(gpointer data, gpointer user_data) +{ + ((epan_plugin *)data)->dissect_init((epan_dissect_t *)user_data); +} + +static void +epan_plugin_dissect_cleanup(gpointer data, gpointer user_data) +{ + ((epan_plugin *)data)->dissect_cleanup((epan_dissect_t *)user_data); +} + +static void +epan_plugin_cleanup(gpointer data, gpointer user_data _U_) +{ + ((epan_plugin *)data)->cleanup(); +} + +void epan_register_plugin(const epan_plugin *plug) +{ + epan_plugins = g_slist_prepend(epan_plugins, (epan_plugin *)plug); + if (plug->register_all_protocols) + epan_register_all_procotols = g_slist_prepend(epan_register_all_procotols, plug->register_all_protocols); + if (plug->register_all_handoffs) + epan_register_all_handoffs = g_slist_prepend(epan_register_all_handoffs, plug->register_all_handoffs); +} +#endif + gboolean epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), @@ -185,8 +228,12 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da conversation_init(); capture_dissector_init(); reassembly_tables_init(); - proto_init(register_all_protocols_func, register_all_handoffs_func, - cb, client_data); +#ifdef HAVE_PLUGINS + g_slist_foreach(epan_plugins, epan_plugin_init, NULL); +#endif + epan_register_all_procotols = g_slist_prepend(epan_register_all_procotols, register_all_protocols_func); + epan_register_all_handoffs = g_slist_prepend(epan_register_all_handoffs, register_all_handoffs_func); + proto_init(epan_register_all_procotols, epan_register_all_handoffs, cb, client_data); packet_cache_proto_handles(); dfilter_init(); final_registration_all_protocols(); @@ -244,6 +291,16 @@ epan_load_settings(void) void epan_cleanup(void) { +#ifdef HAVE_PLUGINS + g_slist_foreach(epan_plugins, epan_plugin_cleanup, NULL); + g_slist_free_full(epan_plugins, g_free); + epan_plugins = NULL; +#endif + g_slist_free(epan_register_all_procotols); + epan_register_all_procotols = NULL; + g_slist_free(epan_register_all_handoffs); + epan_register_all_handoffs = NULL; + dfilter_cleanup(); proto_cleanup(); prefs_cleanup(); @@ -401,6 +458,10 @@ epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_pr } edt->tvb = NULL; + +#ifdef HAVE_PLUGINS + g_slist_foreach(epan_plugins, epan_plugin_dissect_init, edt); +#endif } void @@ -512,6 +573,10 @@ epan_dissect_cleanup(epan_dissect_t* edt) { g_assert(edt); +#ifdef HAVE_PLUGINS + g_slist_foreach(epan_plugins, epan_plugin_dissect_cleanup, edt); +#endif + g_slist_free(edt->pi.proto_data); g_slist_free(edt->pi.dependent_frames); |