diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2017-10-01 00:56:03 +0100 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2017-12-14 08:43:57 +0000 |
commit | 995812c5f1add94df1c237596939130c1704b099 (patch) | |
tree | 42542c56b9a70c7d2d231c8bc36649be35af46b4 /doc/plugins.example | |
parent | a9821caab8a1f2c6e265bd5b63a060f1f241c704 (diff) |
Refactor plugin registration and loading
Put different types of plugins (libwiretap, libwireshark) in different
subdirectories, give libwiretap and libwireshark init routines that
load the plugins, and have them scan the appropriate subdirectories
so that we don't even *try* to, for example, load libwireshark plugins
in programs that only use libwiretap.
Compiled plugins are stored in subfolders of the plugin folders, with
the subfolder name being the Wireshark minor version number (X.Y). There is
another hierarchical level for each Wireshark library (libwireshark, libwscodecs
and libwiretap).
The folder names are respectively plugins/X.Y/{epan,codecs,wiretap}.
Currently we only distribute "epan" (libwireshark) plugins.
Change-Id: I3438787a6f45820d64ba4ca91cbe3c8864708acb
Reviewed-on: https://code.wireshark.org/review/23983
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'doc/plugins.example')
-rw-r--r-- | doc/plugins.example/Makefile.am | 10 | ||||
-rw-r--r-- | doc/plugins.example/configure.ac | 9 | ||||
-rw-r--r-- | doc/plugins.example/hello.c | 21 |
3 files changed, 31 insertions, 9 deletions
diff --git a/doc/plugins.example/Makefile.am b/doc/plugins.example/Makefile.am index df90503908..d33e186757 100644 --- a/doc/plugins.example/Makefile.am +++ b/doc/plugins.example/Makefile.am @@ -11,13 +11,15 @@ WARNFLAGS = -Wall -Wextra plugindir := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --define-variable=libdir=$(libdir) --variable plugindir wireshark) -release_version := $(notdir $(plugindir)) +epan_plugindir = $(plugindir)/epan -plugin_LTLIBRARIES = hello.la +VERSION_RELEASE := $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --variable VERSION_RELEASE wireshark) + +epan_plugin_LTLIBRARIES = hello.la hello_la_SOURCES = hello.c -hello_la_CPPFLAGS = -DVERSION_RELEASE=\"$(release_version)\" +hello_la_CPPFLAGS = -DVERSION_RELEASE=\"$(VERSION_RELEASE)\" hello_la_CFLAGS = $(WIRESHARK_CFLAGS) -fvisibility=hidden $(WARNFLAGS) @@ -25,7 +27,7 @@ hello_la_LDFLAGS = -module -avoid-version -shared hello_la_LIBADD = $(WIRESHARK_LIBS) -homedir = $${HOME}/.local/lib/wireshark/plugins/$(release_version) +homedir = $${HOME}/.local/lib/wireshark/plugins/$(VERSION_RELEASE)/epan install-home: $(MKDIR_P) $(homedir) || exit 1; \ diff --git a/doc/plugins.example/configure.ac b/doc/plugins.example/configure.ac index 07e9845d10..df66a02cc2 100644 --- a/doc/plugins.example/configure.ac +++ b/doc/plugins.example/configure.ac @@ -22,6 +22,15 @@ AC_CONFIG_SRCDIR([hello.c]) dnl Requires Wireshark 2.5.0 or greater. PKG_CHECK_MODULES([WIRESHARK], [wireshark >= 2.5]) +saved_CFLAGS="$CFLAGS"; saved_LIBS="$LIBS"; +CFLAGS="$WIRESHARK_CFLAGS" +LIBS="$WIRESHARK_LIBS" +AC_CHECK_FUNCS([proto_register_plugin], + [AC_DEFINE([HAVE_PLUGINS], 1, [Define to 1 if Wireshark supports loading plugins])], + [AC_MSG_ERROR([Wireshark was compiled without support for plugins])] +) +CFLAGS="$saved_CFLAGS"; LIBS="$saved_LIBS" + AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile]) diff --git a/doc/plugins.example/hello.c b/doc/plugins.example/hello.c index fce0a5372b..455b4741a6 100644 --- a/doc/plugins.example/hello.c +++ b/doc/plugins.example/hello.c @@ -12,6 +12,7 @@ #endif #include <epan/packet.h> +#include <epan/proto.h> #include <ws_attributes.h> #ifndef VERSION @@ -25,8 +26,6 @@ DLL_PUBLIC const gchar plugin_release[] = VERSION_RELEASE; DLL_PUBLIC void plugin_register(void); -DLL_PUBLIC void plugin_reg_handoff(void); - static int proto_hello = -1; static dissector_handle_t handle_hello; @@ -38,14 +37,26 @@ dissect_hello(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *dat return tvb_captured_length(tvb); } -void plugin_register(void) +static void +proto_register_hello(void) { - proto_hello = proto_register_protocol("Wireshark Hello Plugin", "Hello", "hello"); + proto_hello = proto_register_protocol("Wireshark Hello Plugin", "Hello WS", "hello_ws"); handle_hello = create_dissector_handle(dissect_hello, proto_hello); register_postdissector(handle_hello); } -void plugin_reg_handoff(void) +static void +proto_reg_handoff_hello(void) { /* empty */ } + +void +plugin_register(void) +{ + static proto_plugin plug; + + plug.register_protoinfo = proto_register_hello; + plug.register_handoff = proto_reg_handoff_hello; /* or NULL */ + proto_register_plugin(&plug); +} |