forked from osmocom/wireshark
Move most of the plugin code from epan to wsutil and remove all
knowledge of particular types of plugins. Instead, let particular types of plugins register with the common plugin code, giving a name and a routine to recognize that type of plugin. In particular applications, only process the relevant plugin types. Add a Makefile.common to the codecs directory. svn path=/trunk/; revision=53710daniel/osmux
parent
baf569188a
commit
0cc1545d05
|
@ -761,10 +761,6 @@ if(WIN32)
|
|||
)
|
||||
endif()
|
||||
|
||||
set(WTAP_PLUGIN_SOURCES
|
||||
epan/plugins.c
|
||||
)
|
||||
|
||||
set(SHARK_COMMON_CAPTURE_SRC
|
||||
capture_ifinfo.c
|
||||
capture_ui_utils.c
|
||||
|
@ -1071,7 +1067,6 @@ if(BUILD_mergecap)
|
|||
set(mergecap_FILES
|
||||
mergecap.c
|
||||
svnversion.h
|
||||
${WTAP_PLUGIN_SOURCES}
|
||||
)
|
||||
add_executable(mergecap ${mergecap_FILES})
|
||||
add_dependencies(mergecap svnversion)
|
||||
|
@ -1090,7 +1085,6 @@ if(BUILD_reordercap)
|
|||
set(reordercap_FILES
|
||||
reordercap.c
|
||||
svnversion.h
|
||||
${WTAP_PLUGIN_SOURCES}
|
||||
)
|
||||
add_executable(reordercap ${reordercap_FILES})
|
||||
add_dependencies(reordercap svnversion)
|
||||
|
@ -1110,7 +1104,6 @@ if(BUILD_capinfos)
|
|||
)
|
||||
set(capinfos_FILES
|
||||
capinfos.c
|
||||
${WTAP_PLUGIN_SOURCES}
|
||||
)
|
||||
add_executable(capinfos ${capinfos_FILES})
|
||||
add_dependencies(capinfos svnversion)
|
||||
|
@ -1128,7 +1121,6 @@ if(BUILD_editcap)
|
|||
)
|
||||
set(editcap_FILES
|
||||
editcap.c
|
||||
${WTAP_PLUGIN_SOURCES}
|
||||
)
|
||||
add_executable(editcap ${editcap_FILES})
|
||||
add_dependencies(editcap svnversion)
|
||||
|
|
15
Makefile.am
15
Makefile.am
|
@ -311,13 +311,9 @@ plugin_ldadd = $(_CUSTOM_plugin_ldadd_) \
|
|||
-dlopen plugins/wimax/wimax.la \
|
||||
-dlopen plugins/wimaxmacphy/wimaxmacphy.la
|
||||
|
||||
WTAP_PLUGIN_SOURCES = \
|
||||
epan/plugins.c
|
||||
|
||||
else # HAVE_PLUGINS
|
||||
|
||||
plugin_ldadd =
|
||||
WTAP_PLUGIN_SOURCES =
|
||||
|
||||
endif # HAVE_PLUGINS
|
||||
|
||||
|
@ -389,7 +385,11 @@ if HAVE_Qt
|
|||
wireshark_qt_SOURCES = $(WIRESHARK_COMMON_SRC)
|
||||
wireshark_qt_INCLUDES = $(WIRESHARK_COMMON_INCLUDES)
|
||||
wireshark_qt_CFLAGS = $(AM_CLEAN_CFLAGS) $(py_dissectors_dir)
|
||||
wireshark_qt_LDADD = ui/qt/libqtui.a $(wireshark_ldadd) @Qt_LIBS@
|
||||
wireshark_qt_LDADD = \
|
||||
ui/qt/libqtui.a \
|
||||
$(wireshark_ldadd) \
|
||||
@Qt_LIBS@
|
||||
|
||||
#
|
||||
# XXX - this makes wireshark_qt_LDFLAGS not work; we should figure out
|
||||
# another way to get wireshark-qt linked as a C++ program, perhaps by
|
||||
|
@ -403,7 +403,10 @@ if HAVE_GTK
|
|||
wireshark_SOURCES = $(WIRESHARK_COMMON_SRC)
|
||||
wireshark_INCLUDES = $(WIRESHARK_COMMON_INCLUDES)
|
||||
wireshark_CFLAGS = $(AM_CLEAN_CFLAGS) $(py_dissectors_dir)
|
||||
wireshark_LDADD = ui/gtk/libgtkui.a $(wireshark_ldadd) @GTK_LIBS@
|
||||
wireshark_LDADD = \
|
||||
ui/gtk/libgtkui.a \
|
||||
$(wireshark_ldadd) \
|
||||
@GTK_LIBS@
|
||||
endif
|
||||
|
||||
# Ideally we could trigger automatic c++ linking here with
|
||||
|
|
|
@ -147,8 +147,7 @@ mergecap_SOURCES = \
|
|||
|
||||
# editcap specifics
|
||||
editcap_SOURCES = \
|
||||
editcap.c \
|
||||
$(WTAP_PLUGIN_SOURCES)
|
||||
editcap.c
|
||||
|
||||
# reordercap specifics
|
||||
reordercap_SOURCES = \
|
||||
|
@ -157,8 +156,7 @@ reordercap_SOURCES = \
|
|||
|
||||
# capinfos specifics
|
||||
capinfos_SOURCES = \
|
||||
capinfos.c \
|
||||
$(WTAP_PLUGIN_SOURCES)
|
||||
capinfos.c
|
||||
|
||||
# dftest specifics
|
||||
dftest_SOURCES = \
|
||||
|
|
|
@ -53,9 +53,6 @@ CFLAGS=$(WARNINGS_ARE_ERRORS) $(GENERATED_CFLAGS)
|
|||
|
||||
PLATFORM_SRC = capture-wpcap.c capture_wpcap_packet.c capture_win_ifnames.c
|
||||
|
||||
WTAP_PLUGIN_SOURCES = \
|
||||
epan/plugins.c
|
||||
|
||||
include Makefile.common
|
||||
|
||||
wireshark_OBJECTS = $(WIRESHARK_COMMON_SRC:.c=.obj)
|
||||
|
|
27
capinfos.c
27
capinfos.c
|
@ -78,17 +78,9 @@
|
|||
#include <wsutil/privileges.h>
|
||||
#include <wsutil/filesystem.h>
|
||||
|
||||
/*
|
||||
* The symbols declared in the below are exported from libwireshark,
|
||||
* but we don't want to link whole libwireshark to capinfos.
|
||||
* We link the object directly instead and this needs a little trick
|
||||
* with the WS_BUILD_DLL #define.
|
||||
*/
|
||||
#define WS_BUILD_DLL
|
||||
#define RESET_SYMBOL_EXPORT
|
||||
#include <epan/plugins.h>
|
||||
#undef WS_BUILD_DLL
|
||||
#define RESET_SYMBOL_EXPORT
|
||||
#ifdef HAVE_PLUGINS
|
||||
#include <wsutil/plugins.h>
|
||||
#endif
|
||||
|
||||
#include "wtap.h"
|
||||
#include <wsutil/report_err.h>
|
||||
|
@ -1144,14 +1136,21 @@ main(int argc, char *argv[])
|
|||
init_process_policies();
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
/* Register wiretap plugins */
|
||||
|
||||
if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
|
||||
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
|
||||
g_free(init_progfile_dir_error);
|
||||
} else {
|
||||
/* Register all the plugin types we have. */
|
||||
wtap_register_plugin_types(); /* Types known to libwiretap */
|
||||
|
||||
init_report_err(failure_message,NULL,NULL,NULL);
|
||||
init_plugins();
|
||||
|
||||
/* Scan for plugins. This does *not* call their registration routines;
|
||||
that's done later. */
|
||||
scan_plugins();
|
||||
|
||||
/* Register all libwiretap plugin modules. */
|
||||
register_all_wiretap_modules();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Makefile.am
|
||||
# Automake file for the codecs for Wireshark
|
||||
# Automake file for the libcodec library for Wireshark
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@xxxxxxxxxxxxx>
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 1998 Gerald Combs
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
|
@ -21,6 +21,9 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
include Makefile.common
|
||||
include ../Makefile.am.inc
|
||||
|
||||
if HAVE_WARNINGS_AS_ERRORS
|
||||
AM_CFLAGS = -Werror
|
||||
endif
|
||||
|
@ -28,31 +31,27 @@ endif
|
|||
noinst_LIBRARIES = libcodec.a
|
||||
|
||||
CLEANFILES = \
|
||||
libcodec.a \
|
||||
*~
|
||||
libcodec.a \
|
||||
*~
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
||||
Makefile.in
|
||||
|
||||
# All sources that should be put in the source distribution tarball
|
||||
libcodec_a_SOURCES = \
|
||||
codecs.c codecs.h \
|
||||
G711a/G711adecode.c G711a/G711adecode.h G711a/G711atable.h \
|
||||
G711u/G711udecode.c G711u/G711udecode.h G711u/G711utable.h \
|
||||
G722/G722decode.c G722/G722decode.h \
|
||||
G726/G726decode.c G726/G726decode.h \
|
||||
sbc/sbc.c sbc/sbc.h
|
||||
$(LIBCODEC_SRC) \
|
||||
$(noinst_HEADERS)
|
||||
|
||||
libcodec_a_DEPENDENCIES =
|
||||
|
||||
EXTRA_DIST = \
|
||||
Makefile.nmake \
|
||||
CMakeLists.txt
|
||||
# Common headers
|
||||
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/wiretap
|
||||
|
||||
checkapi:
|
||||
checkapi:
|
||||
$(PERL) ../tools/checkAPIs.pl -g abort -g termoutput -build \
|
||||
codecs.c \
|
||||
G711a/G711adecode.c \
|
||||
G711u/G711udecode.c \
|
||||
G722/G722decode.c \
|
||||
G726/G726decode.c \
|
||||
sbc/sbc.c
|
||||
$(LIBCODEC_SRC)
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt \
|
||||
Makefile.common \
|
||||
Makefile.nmake
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# Makefile.common
|
||||
# Contains the stuff from Makefile.am and Makefile.nmake that is
|
||||
# a) common to both files and
|
||||
# b) portable between both files
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 1998 Gerald Combs
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
LIBCODEC_SRC = \
|
||||
codecs.c \
|
||||
G711a/G711adecode.c \
|
||||
G711u/G711udecode.c \
|
||||
G722/G722decode.c \
|
||||
G726/G726decode.c \
|
||||
sbc/sbc.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
codecs.h \
|
||||
G711a/G711adecode.h G711a/G711atable.h \
|
||||
G711u/G711udecode.h G711u/G711utable.h \
|
||||
G722/G722decode.h \
|
||||
G726/G726decode.h \
|
||||
sbc/sbc.h
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
# $Id$
|
||||
|
||||
include ..\config.nmake
|
||||
include ..\Makefile.nmake.inc
|
||||
|
||||
############### no need to modify below this line #########
|
||||
|
||||
|
@ -11,9 +12,16 @@ CFLAGS=/I.. $(WARNINGS_ARE_ERRORS) $(STANDARD_CFLAGS) \
|
|||
$(GLIB_CFLAGS)
|
||||
|
||||
.c.obj::
|
||||
$(CC) $(CFLAGS) -Fd.\ -c $<
|
||||
$(CC) $(CFLAGS) -Fd.\ -c $<
|
||||
|
||||
CODEC_OBJECTS= \
|
||||
include Makefile.common
|
||||
|
||||
# if you add files here, be sure to include them also in Makefile.am EXTRA_DIST
|
||||
# XXX - if the codec files weren't in subdirectories, we could just do
|
||||
# LIBCODEC_OBJECTS = $(LIBCODEC_SRC:.c=.obj), and wouldn't need rules
|
||||
# for each of the codecs below
|
||||
#
|
||||
LIBCODEC_OBJECTS= \
|
||||
codecs.obj \
|
||||
G711udecode.obj \
|
||||
G711adecode.obj \
|
||||
|
@ -21,10 +29,8 @@ CODEC_OBJECTS= \
|
|||
G726decode.obj \
|
||||
sbc.obj
|
||||
|
||||
|
||||
codecs.lib : $(CODEC_OBJECTS)
|
||||
link /lib /out:codecs.lib $(CODEC_OBJECTS)
|
||||
|
||||
codecs.lib : $(LIBCODEC_OBJECTS)
|
||||
link /lib /out:codecs.lib $(LIBCODEC_OBJECTS)
|
||||
|
||||
codecs.obj: codecs.c codecs.h
|
||||
$(CC) $(CFLAGS) -Fd.\ -c codecs.c /Fo%|fF.obj
|
||||
|
@ -45,7 +51,7 @@ sbc.obj: sbc\sbc.c sbc\sbc.h
|
|||
$(CC) $(CFLAGS) -Fd.\ -c sbc\sbc.c /Fo%|fF.obj
|
||||
|
||||
clean:
|
||||
rm -f $(CODEC_OBJECTS) codecs.lib *.pdb *.sbr
|
||||
rm -f $(LIBCODEC_OBJECTS) codecs.lib *.pdb *.sbr
|
||||
|
||||
distclean: clean
|
||||
|
||||
|
@ -53,9 +59,4 @@ maintainer-clean: distclean
|
|||
|
||||
checkapi:
|
||||
$(PERL) ../tools/checkAPIs.pl -g abort -g termoutput -build \
|
||||
codecs.c \
|
||||
G711a/G711adecode.c \
|
||||
G711u/G711udecode.c \
|
||||
G722/G722decode.c \
|
||||
G726/G726decode.c \
|
||||
sbc/sbc.c
|
||||
$(LIBCODEC_SRC)
|
||||
|
|
|
@ -22,9 +22,82 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include "codecs.h"
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <wsutil/plugins.h>
|
||||
|
||||
/*
|
||||
* List of codec plugins.
|
||||
*/
|
||||
typedef struct {
|
||||
void (*register_codec_module)(void); /* routine to call to register a codec */
|
||||
} codec_plugin;
|
||||
|
||||
static GSList *codec_plugins = NULL;
|
||||
|
||||
/*
|
||||
* Callback for each plugin found.
|
||||
*/
|
||||
static gboolean
|
||||
check_for_codec_plugin(GModule *handle)
|
||||
{
|
||||
gpointer gp;
|
||||
void (*register_codec_module)(void);
|
||||
codec_plugin *plugin;
|
||||
|
||||
/*
|
||||
* Do we have a register_codec_module routine?
|
||||
*/
|
||||
if (!g_module_symbol(handle, "register_codec_module", &gp)) {
|
||||
/* No, so this isn't a codec plugin. */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Yes - this plugin includes one or more codecs.
|
||||
*/
|
||||
register_codec_module = (void (*)(void))gp;
|
||||
|
||||
/*
|
||||
* Add this one to the list of codec plugins.
|
||||
*/
|
||||
plugin = (codec_plugin *)g_malloc(sizeof (codec_plugin));
|
||||
plugin->register_codec_module = register_codec_module;
|
||||
codec_plugins = g_slist_append(codec_plugins, plugin);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
codec_register_plugin_types(void)
|
||||
{
|
||||
add_plugin_type("codec", check_for_codec_plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
register_codec_plugin(gpointer data, gpointer user_data _U_)
|
||||
{
|
||||
codec_plugin *plugin = (codec_plugin *)data;
|
||||
|
||||
(plugin->register_codec_module)();
|
||||
}
|
||||
|
||||
/*
|
||||
* For all codec plugins, call their register routines.
|
||||
*/
|
||||
void
|
||||
register_all_codecs(void)
|
||||
{
|
||||
g_slist_foreach(codec_plugins, register_codec_plugin, NULL);
|
||||
}
|
||||
#endif /* HAVE_PLUGINS */
|
||||
|
||||
struct codec_handle {
|
||||
const char *name;
|
||||
codec_init_fn init_fn;
|
||||
|
|
|
@ -25,6 +25,20 @@
|
|||
#ifndef _CODECS_H_
|
||||
#define _CODECS_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <epan/epan.h>
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
extern void codec_register_plugin_types(void);
|
||||
extern void register_all_codecs(void);
|
||||
#endif
|
||||
|
||||
struct codec_handle;
|
||||
typedef struct codec_handle *codec_handle_t;
|
||||
|
||||
|
@ -38,4 +52,8 @@ extern void *codec_init(codec_handle_t codec);
|
|||
extern void codec_release(codec_handle_t codec, void *context);
|
||||
extern int codec_decode(codec_handle_t codec, void *context, const void *input, int inputSizeBytes, void *output, int *outputSizeBytes);
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _CODECS_H_ */
|
||||
|
|
10
dftest.c
10
dftest.c
|
@ -31,15 +31,17 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <epan/epan.h>
|
||||
|
||||
#include <epan/epan.h>
|
||||
#include <epan/timestamp.h>
|
||||
#include <epan/plugins.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/dfilter/dfilter.h>
|
||||
|
||||
#include <wsutil/plugins.h>
|
||||
#include <wsutil/filesystem.h>
|
||||
#include <wsutil/privileges.h>
|
||||
#include <epan/prefs.h>
|
||||
|
||||
#include "ui/util.h"
|
||||
#include "epan/dfilter/dfilter.h"
|
||||
#include "register.h"
|
||||
|
||||
static void failure_message(const char *msg_format, va_list ap);
|
||||
|
|
24
editcap.c
24
editcap.c
|
@ -80,18 +80,7 @@
|
|||
#include <wsutil/report_err.h>
|
||||
#include <wsutil/strnatcmp.h>
|
||||
#include <wsutil/md5.h>
|
||||
|
||||
/*
|
||||
* The symbols declared in the below are exported from libwireshark,
|
||||
* but we don't want to link whole libwireshark to editcap.
|
||||
* We link the object directly instead and this needs a little trick
|
||||
* with the WS_BUILD_DLL #define.
|
||||
*/
|
||||
#define WS_BUILD_DLL
|
||||
#define RESET_SYMBOL_EXPORT /* wsutil/wsgetopt.h set export behavior above. */
|
||||
#include "epan/plugins.h"
|
||||
#undef WS_BUILD_DLL
|
||||
#define RESET_SYMBOL_EXPORT
|
||||
#include <wsutil/plugins.h>
|
||||
|
||||
#include "svnversion.h"
|
||||
|
||||
|
@ -910,8 +899,17 @@ main(int argc, char *argv[])
|
|||
g_warning("editcap: init_progfile_dir(): %s", init_progfile_dir_error);
|
||||
g_free(init_progfile_dir_error);
|
||||
} else {
|
||||
/* Register all the plugin types we have. */
|
||||
wtap_register_plugin_types(); /* Types known to libwiretap */
|
||||
|
||||
init_report_err(failure_message,NULL,NULL,NULL);
|
||||
init_plugins();
|
||||
|
||||
/* Scan for plugins. This does *not* call their registration routines;
|
||||
that's done later. */
|
||||
scan_plugins();
|
||||
|
||||
/* Register all libwiretap plugin modules. */
|
||||
register_all_wiretap_modules();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1503,7 +1503,6 @@ set(LIBWIRESHARK_FILES
|
|||
osi-utils.c
|
||||
packet-range.c
|
||||
packet.c
|
||||
plugins.c
|
||||
print.c
|
||||
prefs.c
|
||||
proto.c
|
||||
|
|
|
@ -70,7 +70,6 @@ LIBWIRESHARK_SRC = \
|
|||
osi-utils.c \
|
||||
packet-range.c \
|
||||
packet.c \
|
||||
plugins.c \
|
||||
prefs.c \
|
||||
print.c \
|
||||
proto.c \
|
||||
|
@ -218,7 +217,6 @@ LIBWIRESHARK_INCLUDES = \
|
|||
packet.h \
|
||||
packet_info.h \
|
||||
params.h \
|
||||
plugins.h \
|
||||
ppptypes.h \
|
||||
print.h \
|
||||
prefs.h \
|
||||
|
|
14
epan/epan.c
14
epan/epan.c
|
@ -74,6 +74,20 @@ epan_get_version(void) {
|
|||
return VERSION;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register all the plugin types that are part of libwireshark, namely
|
||||
* dissector and tap plugins.
|
||||
*
|
||||
* Must be called before init_plugins(), which must be called before
|
||||
* any registration routines are called.
|
||||
*/
|
||||
void
|
||||
epan_register_plugin_types(void)
|
||||
{
|
||||
register_dissector_plugin_type();
|
||||
register_tap_plugin_type();
|
||||
}
|
||||
|
||||
void
|
||||
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
|
||||
void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
|
||||
|
|
10
epan/epan.h
10
epan/epan.h
|
@ -81,6 +81,16 @@ Ref2 for further edits - delete when done
|
|||
- \ref airpcapdefs
|
||||
- \ref radiotap
|
||||
*/
|
||||
/*
|
||||
* Register all the plugin types that are part of libwireshark.
|
||||
*
|
||||
* Must be called before init_plugins(), which must be called before
|
||||
* any registration routines are called, i.e. before epan_init().
|
||||
*
|
||||
* Must be called only once in a program.
|
||||
*/
|
||||
WS_DLL_PUBLIC void epan_register_plugin_types(void);
|
||||
|
||||
/** init the whole epan module, this is used to be called only once in a program */
|
||||
WS_DLL_PUBLIC
|
||||
void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
#include "addr_resolv.h"
|
||||
#include "tvbuff.h"
|
||||
#include "plugins.h"
|
||||
#include "epan_dissect.h"
|
||||
|
||||
#include "emem.h"
|
||||
|
|
575
epan/plugins.c
575
epan/plugins.c
|
@ -1,575 +0,0 @@
|
|||
/* plugins.c
|
||||
* plugin routines
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "plugins.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* linked list of Lua plugins */
|
||||
wslua_plugin *wslua_plugin_list = NULL;
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_DIRENT_H
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DIRECT_H
|
||||
#include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "wsutil/filesystem.h"
|
||||
#include <wsutil/privileges.h>
|
||||
#include <wsutil/file_util.h>
|
||||
#include <wsutil/report_err.h>
|
||||
|
||||
/* linked list of all plugins */
|
||||
plugin *plugin_list = NULL;
|
||||
|
||||
static void register_all_wiretap_modules(void);
|
||||
static void register_all_codecs(void);
|
||||
|
||||
/*
|
||||
* add a new plugin to the list
|
||||
* returns :
|
||||
* - 0 : OK
|
||||
* - ENOMEM : memory allocation problem
|
||||
* - EEXIST : the same plugin (i.e. name/version) was already registered.
|
||||
*/
|
||||
static int
|
||||
add_plugin(void *handle, gchar *name, gchar *version,
|
||||
void (*register_protoinfo)(void),
|
||||
void (*reg_handoff)(void),
|
||||
void (*register_tap_listener)(void),
|
||||
void (*register_wtap_module)(void),
|
||||
void (*register_codec_module)(void))
|
||||
{
|
||||
plugin *new_plug, *pt_plug;
|
||||
|
||||
pt_plug = plugin_list;
|
||||
if (!pt_plug) /* the list is empty */
|
||||
{
|
||||
new_plug = (plugin *)g_malloc(sizeof(plugin));
|
||||
if (new_plug == NULL)
|
||||
return ENOMEM;
|
||||
plugin_list = new_plug;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
/* check if the same name/version is already registered */
|
||||
if (!strcmp(pt_plug->name, name) &&
|
||||
!strcmp(pt_plug->version, version))
|
||||
{
|
||||
return EEXIST;
|
||||
}
|
||||
|
||||
/* we found the last plugin in the list */
|
||||
if (pt_plug->next == NULL)
|
||||
break;
|
||||
|
||||
pt_plug = pt_plug->next;
|
||||
}
|
||||
new_plug = (plugin *)g_malloc(sizeof(plugin));
|
||||
if (new_plug == NULL)
|
||||
return ENOMEM;
|
||||
pt_plug->next = new_plug;
|
||||
}
|
||||
|
||||
new_plug->handle = (GModule *)handle;
|
||||
new_plug->name = name;
|
||||
new_plug->version = version;
|
||||
new_plug->register_protoinfo = register_protoinfo;
|
||||
new_plug->reg_handoff = reg_handoff;
|
||||
new_plug->register_tap_listener = register_tap_listener;
|
||||
new_plug->register_wtap_module = register_wtap_module;
|
||||
new_plug->register_codec_module = register_codec_module;
|
||||
new_plug->next = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX - when we remove support for old-style plugins (which we should
|
||||
* probably do eventually, as all plugins should be written as new-style
|
||||
* ones), we may want to have "init_plugins()" merely save a pointer
|
||||
* to the plugin's "init" routine, just as we save a pointer to its
|
||||
* "reg_handoff" routine, and have a "register_all_plugins()" routine
|
||||
* to go through the list of plugins and call all of them.
|
||||
*
|
||||
* Then we'd have "epan_init()", or perhaps even something higher up
|
||||
* in the call tree, call "init_plugins()", and have "proto_init()"
|
||||
* call "register_all_plugins()" right after calling "register_all_protocols()";
|
||||
* this might be a bit cleaner.
|
||||
*/
|
||||
static void
|
||||
plugins_scan_dir(const char *dirname)
|
||||
{
|
||||
#define FILENAME_LEN 1024
|
||||
WS_DIR *dir; /* scanned directory */
|
||||
WS_DIRENT *file; /* current file */
|
||||
const char *name;
|
||||
gchar filename[FILENAME_LEN]; /* current file name */
|
||||
GModule *handle; /* handle returned by g_module_open */
|
||||
gchar *version;
|
||||
gpointer gp;
|
||||
void (*register_protoinfo)(void);
|
||||
void (*reg_handoff)(void);
|
||||
void (*register_tap_listener)(void);
|
||||
void (*register_wtap_module)(void);
|
||||
void (*register_codec_module)(void);
|
||||
|
||||
gchar *dot;
|
||||
int cr;
|
||||
|
||||
if ((dir = ws_dir_open(dirname, 0, NULL)) != NULL)
|
||||
{
|
||||
while ((file = ws_dir_read_name(dir)) != NULL)
|
||||
{
|
||||
name = ws_dir_get_name(file);
|
||||
|
||||
/*
|
||||
* GLib 2.x defines G_MODULE_SUFFIX as the extension used on
|
||||
* this platform for loadable modules.
|
||||
*/
|
||||
/* skip anything but files with G_MODULE_SUFFIX */
|
||||
dot = strrchr(name, '.');
|
||||
if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
|
||||
continue;
|
||||
|
||||
g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
|
||||
dirname, name);
|
||||
if ((handle = g_module_open(filename, (GModuleFlags)0)) == NULL)
|
||||
{
|
||||
report_failure("Couldn't load module %s: %s", filename,
|
||||
g_module_error());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_module_symbol(handle, "version", &gp))
|
||||
{
|
||||
report_failure("The plugin %s has no version symbol", name);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
version = (char *)gp;
|
||||
|
||||
/*
|
||||
* Do we have a register routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_register", &gp))
|
||||
{
|
||||
/*
|
||||
* Yes - this plugin includes one or more dissectors.
|
||||
*/
|
||||
register_protoinfo = (void (*)(void))gp;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* No - no dissectors.
|
||||
*/
|
||||
register_protoinfo = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do we have a reg_handoff routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_reg_handoff", &gp))
|
||||
{
|
||||
/*
|
||||
* Yes.
|
||||
*/
|
||||
reg_handoff = (void (*)(void))gp;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* No - that's OK even if we have dissectors, as long
|
||||
* as the plugin registers by name *and* there's
|
||||
* a caller looking for that name.
|
||||
*/
|
||||
reg_handoff = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do we have a register_tap_listener routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_register_tap_listener", &gp))
|
||||
{
|
||||
/*
|
||||
* Yes - this plugin includes one or more taps.
|
||||
*/
|
||||
register_tap_listener = (void (*)(void))gp;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* No - no taps here.
|
||||
*/
|
||||
register_tap_listener = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do we have an old-style init routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_init", &gp))
|
||||
{
|
||||
/*
|
||||
* Yes - do we also have a register routine or a
|
||||
* register_tap_listener routine? If so, this is a bogus
|
||||
* hybrid of an old-style and new-style plugin.
|
||||
*/
|
||||
if (register_protoinfo != NULL || register_tap_listener != NULL)
|
||||
{
|
||||
report_failure("The plugin '%s' has an old plugin init routine\nand a new register or register_tap_listener routine.",
|
||||
name);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's just an unsupported old-style plugin;
|
||||
*/
|
||||
report_failure("The plugin '%s' has an old plugin init routine. Support has been dropped.\n Information on how to update your plugin is available at \nhttp://anonsvn.wireshark.org/wireshark/trunk/doc/README.plugins",
|
||||
name);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do we have a register_wtap_module routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "register_wtap_module", &gp))
|
||||
{
|
||||
register_wtap_module = (void (*)(void))gp;
|
||||
}
|
||||
else
|
||||
{
|
||||
register_wtap_module = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do we have a register_codec_module routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "register_codec_module", &gp))
|
||||
{
|
||||
register_codec_module = (void (*)(void))gp;
|
||||
}
|
||||
else
|
||||
{
|
||||
register_codec_module = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Does this dissector do anything useful?
|
||||
*/
|
||||
if (register_protoinfo == NULL &&
|
||||
register_tap_listener == NULL &&
|
||||
register_wtap_module == NULL &&
|
||||
register_codec_module == NULL )
|
||||
{
|
||||
/*
|
||||
* No.
|
||||
*/
|
||||
report_failure("The plugin '%s' has neither a register routine, "
|
||||
"a register_tap_listener or a register_wtap_module or a register_codec_module routine",
|
||||
name);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, attempt to add it to the list of plugins.
|
||||
*/
|
||||
if ((cr = add_plugin(handle, g_strdup(name), version,
|
||||
register_protoinfo, reg_handoff,
|
||||
register_tap_listener,register_wtap_module,register_codec_module)))
|
||||
{
|
||||
if (cr == EEXIST)
|
||||
fprintf(stderr, "The plugin %s, version %s\n"
|
||||
"was found in multiple directories\n", name, version);
|
||||
else
|
||||
fprintf(stderr, "Memory allocation problem\n"
|
||||
"when processing plugin %s, version %s\n",
|
||||
name, version);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
ws_dir_close(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* init plugins
|
||||
*/
|
||||
void
|
||||
init_plugins(void)
|
||||
{
|
||||
const char *plugin_dir;
|
||||
const char *name;
|
||||
char *plugin_dir_path;
|
||||
char *plugins_pers_dir;
|
||||
WS_DIR *dir; /* scanned directory */
|
||||
WS_DIRENT *file; /* current file */
|
||||
|
||||
if (plugin_list == NULL) /* ensure init_plugins is only run once */
|
||||
{
|
||||
/*
|
||||
* Scan the global plugin directory.
|
||||
* If we're running from a build directory, scan the subdirectories
|
||||
* of that directory, as the global plugin directory is the
|
||||
* "plugins" directory of the source tree, and the subdirectories
|
||||
* are the source directories for the plugins, with the plugins
|
||||
* built in those subdirectories.
|
||||
*/
|
||||
plugin_dir = get_plugin_dir();
|
||||
if (running_in_build_directory())
|
||||
{
|
||||
if ((dir = ws_dir_open(plugin_dir, 0, NULL)) != NULL)
|
||||
{
|
||||
while ((file = ws_dir_read_name(dir)) != NULL)
|
||||
{
|
||||
name = ws_dir_get_name(file);
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
||||
continue; /* skip "." and ".." */
|
||||
/*
|
||||
* Get the full path of a ".libs" subdirectory of that
|
||||
* directory.
|
||||
*/
|
||||
plugin_dir_path = g_strdup_printf(
|
||||
"%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S ".libs",
|
||||
plugin_dir, name);
|
||||
if (test_for_directory(plugin_dir_path) != EISDIR) {
|
||||
/*
|
||||
* Either it doesn't refer to a directory or it
|
||||
* refers to something that doesn't exist.
|
||||
*
|
||||
* Assume that means that the plugins are in
|
||||
* the subdirectory of the plugin directory, not
|
||||
* a ".libs" subdirectory of that subdirectory.
|
||||
*/
|
||||
g_free(plugin_dir_path);
|
||||
plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
|
||||
plugin_dir, name);
|
||||
}
|
||||
plugins_scan_dir(plugin_dir_path);
|
||||
g_free(plugin_dir_path);
|
||||
}
|
||||
ws_dir_close(dir);
|
||||
}
|
||||
}
|
||||
else
|
||||
plugins_scan_dir(plugin_dir);
|
||||
|
||||
/*
|
||||
* If the program wasn't started with special privileges,
|
||||
* scan the users plugin directory. (Even if we relinquish
|
||||
* them, plugins aren't safe unless we've *permanently*
|
||||
* relinquished them, and we can't do that in Wireshark as,
|
||||
* if we need privileges to start capturing, we'd need to
|
||||
* reclaim them before each time we start capturing.)
|
||||
*/
|
||||
if (!started_with_special_privs())
|
||||
{
|
||||
plugins_pers_dir = get_plugins_pers_dir();
|
||||
plugins_scan_dir(plugins_pers_dir);
|
||||
g_free(plugins_pers_dir);
|
||||
}
|
||||
}
|
||||
|
||||
register_all_wiretap_modules();
|
||||
register_all_codecs();
|
||||
}
|
||||
|
||||
void
|
||||
register_all_plugin_registrations(void)
|
||||
{
|
||||
plugin *pt_plug;
|
||||
|
||||
/*
|
||||
* For all plugins with register-handoff routines, call the routines.
|
||||
* This is called from "proto_init()"; it must be called after
|
||||
* "register_all_protocols()" and "init_plugins()" are called,
|
||||
* in case one plugin registers itself either with a built-in
|
||||
* dissector or with another plugin; we must first register all
|
||||
* dissectors, whether built-in or plugin, so their dissector tables
|
||||
* are initialized, and only then register all handoffs.
|
||||
*/
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
if (pt_plug->register_protoinfo)
|
||||
(pt_plug->register_protoinfo)();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_all_plugin_handoffs(void)
|
||||
{
|
||||
plugin *pt_plug;
|
||||
|
||||
/*
|
||||
* For all plugins with register-handoff routines, call the routines.
|
||||
* This is called from "proto_init()"; it must be called after
|
||||
* "register_all_protocols()" and "init_plugins()" are called,
|
||||
* in case one plugin registers itself either with a built-in
|
||||
* dissector or with another plugin; we must first register all
|
||||
* dissectors, whether built-in or plugin, so their dissector tables
|
||||
* are initialized, and only then register all handoffs.
|
||||
*/
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
if (pt_plug->reg_handoff)
|
||||
(pt_plug->reg_handoff)();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_all_plugin_tap_listeners(void)
|
||||
{
|
||||
plugin *pt_plug;
|
||||
|
||||
/*
|
||||
* For all plugins with register-tap-listener routines, call the
|
||||
* routines.
|
||||
*/
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
if (pt_plug->register_tap_listener)
|
||||
(pt_plug->register_tap_listener)();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
register_all_wiretap_modules(void)
|
||||
{
|
||||
plugin *pt_plug;
|
||||
|
||||
/*
|
||||
* For all plugins with register_wtap_module routines, call the
|
||||
* routines.
|
||||
*/
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
if (pt_plug->register_wtap_module)
|
||||
(pt_plug->register_wtap_module)();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
register_all_codecs(void)
|
||||
{
|
||||
plugin *pt_plug;
|
||||
|
||||
/*
|
||||
* For all plugins with register_wtap_module routines, call the
|
||||
* routines.
|
||||
*/
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
if (pt_plug->register_codec_module)
|
||||
(pt_plug->register_codec_module)();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* big HAVE_PLUGINS */
|
||||
|
||||
/*
|
||||
* Dump plugin info to stdout. Copied from ui/gtk/plugins_dlg.c:plugins_scan.
|
||||
*/
|
||||
void
|
||||
plugins_dump_all(void)
|
||||
{
|
||||
#ifdef HAVE_PLUGINS
|
||||
plugin *pt_plug;
|
||||
const char *sep;
|
||||
#endif
|
||||
#ifdef HAVE_LUA
|
||||
wslua_plugin *lua_plug;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
for (pt_plug = plugin_list; pt_plug != NULL; pt_plug = pt_plug->next)
|
||||
{
|
||||
sep = "";
|
||||
|
||||
printf("%s\t%s\t", pt_plug->name, pt_plug->version);
|
||||
if (pt_plug->register_protoinfo)
|
||||
{
|
||||
printf("dissector");
|
||||
sep = ", ";
|
||||
}
|
||||
if (pt_plug->register_tap_listener)
|
||||
{
|
||||
printf("%stap", sep);
|
||||
sep = ", ";
|
||||
}
|
||||
if (pt_plug->register_wtap_module)
|
||||
{
|
||||
printf("%sfile format", sep);
|
||||
sep = ", ";
|
||||
}
|
||||
if (pt_plug->register_codec_module)
|
||||
{
|
||||
printf("%scodec", sep);
|
||||
}
|
||||
printf("\t%s\n", g_module_name(pt_plug->handle));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LUA
|
||||
for (lua_plug = wslua_plugin_list; lua_plug != NULL; lua_plug = lua_plug->next)
|
||||
{
|
||||
printf("%s\t%s\tlua script\t%s\n", lua_plug->name, lua_plug->version, lua_plug->filename);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
93
epan/proto.c
93
epan/proto.c
|
@ -41,7 +41,6 @@
|
|||
#include "strutil.h"
|
||||
#include "addr_resolv.h"
|
||||
#include "oids.h"
|
||||
#include "plugins.h"
|
||||
#include "proto.h"
|
||||
#include "epan_dissect.h"
|
||||
#include "tvbuff.h"
|
||||
|
@ -57,6 +56,8 @@
|
|||
|
||||
#include "wspython/wspy_register.h"
|
||||
|
||||
#include <wsutil/plugins.h>
|
||||
|
||||
#define SUBTREE_ONCE_ALLOCATION_NUMBER 8
|
||||
#define SUBTREE_MAX_LEVELS 256
|
||||
/* Throw an exception if we exceed this many tree items. */
|
||||
|
@ -324,6 +325,87 @@ proto_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
|
|||
return g_ascii_strcasecmp(p1->short_name, p2->short_name);
|
||||
}
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
/*
|
||||
* List of dissector plugins.
|
||||
*/
|
||||
typedef struct {
|
||||
void (*register_protoinfo)(void); /* routine to call to register protocol information */
|
||||
void (*reg_handoff)(void); /* routine to call to register dissector handoff */
|
||||
} dissector_plugin;
|
||||
|
||||
static GSList *dissector_plugins = NULL;
|
||||
|
||||
/*
|
||||
* Callback for each plugin found.
|
||||
*/
|
||||
static gboolean
|
||||
check_for_dissector_plugin(GModule *handle)
|
||||
{
|
||||
gpointer gp;
|
||||
void (*register_protoinfo)(void);
|
||||
void (*reg_handoff)(void);
|
||||
dissector_plugin *plugin;
|
||||
|
||||
/*
|
||||
* Do we have a register routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_register", &gp))
|
||||
register_protoinfo = (void (*)(void))gp;
|
||||
else
|
||||
register_protoinfo = NULL;
|
||||
|
||||
/*
|
||||
* Do we have a reg_handoff routine?
|
||||
*/
|
||||
if (g_module_symbol(handle, "plugin_reg_handoff", &gp))
|
||||
reg_handoff = (void (*)(void))gp;
|
||||
else
|
||||
reg_handoff = NULL;
|
||||
|
||||
/*
|
||||
* If we have neither, we're not a dissector plugin.
|
||||
*/
|
||||
if (register_protoinfo == NULL && reg_handoff == NULL)
|
||||
return FALSE;
|
||||
|
||||
/*
|
||||
* Add this one to the list of dissector plugins.
|
||||
*/
|
||||
plugin = (dissector_plugin *)g_malloc(sizeof (dissector_plugin));
|
||||
plugin->register_protoinfo = register_protoinfo;
|
||||
plugin->reg_handoff = reg_handoff;
|
||||
dissector_plugins = g_slist_append(dissector_plugins, plugin);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
register_dissector_plugin(gpointer data, gpointer user_data _U_)
|
||||
{
|
||||
dissector_plugin *plugin = (dissector_plugin *)data;
|
||||
|
||||
if (plugin->register_protoinfo)
|
||||
(plugin->register_protoinfo)();
|
||||
}
|
||||
|
||||
static void
|
||||
reg_handoff_dissector_plugin(gpointer data, gpointer user_data _U_)
|
||||
{
|
||||
dissector_plugin *plugin = (dissector_plugin *)data;
|
||||
|
||||
if (plugin->reg_handoff)
|
||||
(plugin->reg_handoff)();
|
||||
}
|
||||
|
||||
/*
|
||||
* Register dissector plugin type.
|
||||
*/
|
||||
void
|
||||
register_dissector_plugin_type(void)
|
||||
{
|
||||
add_plugin_type("dissector", check_for_dissector_plugin);
|
||||
}
|
||||
#endif /* HAVE_PLUGINS */
|
||||
|
||||
/* initialize data structures and register protocols and fields */
|
||||
void
|
||||
|
@ -368,12 +450,11 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
/* Now scan for plugins and load all the ones we find, calling
|
||||
their register routines to do the stuff described above. */
|
||||
/* Now call the registration routines for all disssector
|
||||
plugins. */
|
||||
if (cb)
|
||||
(*cb)(RA_PLUGIN_REGISTER, NULL, client_data);
|
||||
init_plugins();
|
||||
register_all_plugin_registrations();
|
||||
g_slist_foreach(dissector_plugins, register_dissector_plugin, NULL);
|
||||
#endif
|
||||
|
||||
/* Now call the "handoff registration" routines of all built-in
|
||||
|
@ -393,7 +474,7 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da
|
|||
/* Now do the same with plugins. */
|
||||
if (cb)
|
||||
(*cb)(RA_PLUGIN_HANDOFF, NULL, client_data);
|
||||
register_all_plugin_handoffs();
|
||||
g_slist_foreach(dissector_plugins, reg_handoff_dissector_plugin, NULL);
|
||||
#endif
|
||||
|
||||
/* sort the protocols by protocol name */
|
||||
|
|
|
@ -603,6 +603,10 @@ WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
|
|||
/** Retrieve the wmem_allocator_t from a proto_node */
|
||||
#define PNODE_POOL(proto_node) ((proto_node)->tree_data->pinfo->pool)
|
||||
|
||||
/** Register dissector plugin type with the plugin system.
|
||||
Called by epan_register_plugin_types(); do not call it yourself. */
|
||||
extern void register_dissector_plugin_type(void);
|
||||
|
||||
/** Sets up memory used by proto routines. Called at program startup */
|
||||
void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),
|
||||
void (register_all_handoffs_func)(register_cb cb, gpointer client_data),
|
||||
|
|
73
epan/tap.c
73
epan/tap.c
|
@ -77,6 +77,77 @@ typedef struct _tap_listener_t {
|
|||
} tap_listener_t;
|
||||
static volatile tap_listener_t *tap_listener_queue=NULL;
|
||||
|
||||
#ifdef HAVE_PLUGINS
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <wsutil/plugins.h>
|
||||
|
||||
/*
|
||||
* List of tap plugins.
|
||||
*/
|
||||
typedef struct {
|
||||
void (*register_tap_listener_fn)(void); /* routine to call to register tap listener */
|
||||
} tap_plugin;
|
||||
|
||||
static GSList *tap_plugins = NULL;
|
||||
|
||||
/*
|
||||
* Callback for each plugin found.
|
||||
*/
|
||||
static gboolean
|
||||
check_for_tap_plugin(GModule *handle)
|
||||
{
|
||||
gpointer gp;
|
||||
void (*register_tap_listener_fn)(void);
|
||||
tap_plugin *plugin;
|
||||
|
||||
/*
|
||||
* Do we have a register_tap_listener routine?
|
||||
*/
|
||||
if (!g_module_symbol(handle, "plugin_register_tap_listener", &gp)) {
|
||||
/* No, so this isn't a tap plugin. */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Yes - this plugin includes one or more taps.
|
||||
*/
|
||||
register_tap_listener_fn = (void (*)(void))gp;
|
||||
|
||||
/*
|
||||
* Add this one to the list of tap plugins.
|
||||
*/
|
||||
plugin = (tap_plugin *)g_malloc(sizeof (tap_plugin));
|
||||
plugin->register_tap_listener_fn = register_tap_listener_fn;
|
||||
tap_plugins = g_slist_append(tap_plugins, plugin);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
register_tap_plugin_type(void)
|
||||
{
|
||||
add_plugin_type("tap", check_for_tap_plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
register_tap_plugin_listener(gpointer data, gpointer user_data _U_)
|
||||
{
|
||||
tap_plugin *plugin = (tap_plugin *)data;
|
||||
|
||||
(plugin->register_tap_listener_fn)();
|
||||
}
|
||||
|
||||
/*
|
||||
* For all tap plugins, call their register routines.
|
||||
*/
|
||||
void
|
||||
register_all_plugin_tap_listeners(void)
|
||||
{
|
||||
g_slist_foreach(tap_plugins, register_tap_plugin_listener, NULL);
|
||||
}
|
||||
#endif /* HAVE_PLUGINS */
|
||||
|
||||
/* **********************************************************************
|
||||
* Init routine only called from epan at application startup
|
||||
* ********************************************************************** */
|
||||
|
@ -87,8 +158,6 @@ void
|
|||
tap_init(void)
|
||||
{
|
||||
tap_packet_index=0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* **********************************************************************
|
||||
|
|
14
epan/tap.h
14
epan/tap.h
|
@ -46,6 +46,20 @@ typedef void (*tap_draw_cb)(void *tapdata);
|
|||