Have editcap and capinfos loading the wiretap plugins.

epan/filesystem.c
   have get_plugin_dir() calling init_plugin_dir() if necessary

epan/epan.c and epan/report_err.c
   move the report_failure family into the new report_err.c file, have epan_init() calling the initializer

epan/plugins.h and epan/proto.c
   do not have init_plugins() calling the proto_reg functions instead do it in init_proto()

gtk/main.c and tshark.c
   init_plugin_dir() has become suprefluous

capinfos.c and editcap.c
   load the wiretap plugins

Makefiles
   do what's needed to build withe the above changes.




svn path=/trunk/; revision=21935
This commit is contained in:
Luis Ontanon 2007-05-25 17:22:32 +00:00
parent c22f70ec1b
commit 11f06217ce
14 changed files with 191 additions and 73 deletions

View File

@ -207,7 +207,18 @@ mergecap_SOURCES = \
# editcap specifics
editcap_SOURCES = \
editcap.c \
epan/crypt/crypt-md5.c
epan/crypt/crypt-md5.c \
epan/plugins.c \
epan/report_err.c \
epan/privileges.c \
epan/filesystem.c
capinfos_SOURCES = \
capinfos.c \
epan/plugins.c \
epan/report_err.c \
epan/privileges.c \
epan/filesystem.c
# dftest specifics
dftest_SOURCES = \

View File

@ -75,11 +75,11 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
!ENDIF
capinfos_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
wsock32.lib user32.lib \
wsock32.lib user32.lib shell32.lib \
$(GLIB_LIBS)
editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
wsock32.lib user32.lib \
wsock32.lib user32.lib shell32.lib \
$(GLIB_LIBS)
mergecap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
@ -214,19 +214,19 @@ tshark.exe : config.h svnversion.h $(tshark_OBJECTS) getopt.obj epan image\tshar
mt.exe -nologo -manifest "tshark.exe.manifest" -outputresource:tshark.exe;1
!ENDIF
capinfos.exe : config.h capinfos.obj getopt.obj wiretap\wiretap-$(WTAP_VERSION).lib image\capinfos.res
capinfos.exe : config.h capinfos.obj getopt.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj wiretap\wiretap-$(WTAP_VERSION).lib image\capinfos.res
@echo Linking $@
$(LINK) @<<
/OUT:capinfos.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console capinfos.obj getopt.obj $(capinfos_LIBS) image\capinfos.res
/OUT:capinfos.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console capinfos.obj getopt.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj $(capinfos_LIBS) image\capinfos.res
<<
!IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20"
mt.exe -nologo -manifest "capinfos.exe.manifest" -outputresource:capinfos.exe;1
!ENDIF
editcap.exe : config.h editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj wiretap\wiretap-$(WTAP_VERSION).lib image\editcap.res
editcap.exe : config.h editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj epan/unicode-utils.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj wiretap\wiretap-$(WTAP_VERSION).lib image\editcap.res
@echo Linking $@
$(LINK) @<<
/OUT:editcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console editcap.obj getopt.obj strptime.obj epan\crypt\crypt-md5.obj $(editcap_LIBS) image\editcap.res
/OUT:editcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console editcap.obj getopt.obj strptime.obj epan/unicode-utils.obj epan\crypt\crypt-md5.obj epan/plugins.obj epan/report_err.obj epan/privileges.obj epan/filesystem.obj $(editcap_LIBS) image\editcap.res
<<
!IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20"
mt.exe -nologo -manifest "editcap.exe.manifest" -outputresource:editcap.exe;1
@ -870,6 +870,8 @@ install-common-files:
xcopy ".\cfilters" $(INSTALL_DIR) /d
xcopy ".\colorfilters" $(INSTALL_DIR) /d
xcopy ".\dfilters" $(INSTALL_DIR) /d
xcopy ".\epan\wslua\init.lua" $(INSTALL_DIR) /d
xcopy ".\epan\wslua\console.lua" $(INSTALL_DIR) /d
xcopy doc\*.html $(INSTALL_DIR) /d
!IFDEF ETHEREAL_EUG_DIR
xcopy $(ETHEREAL_EUG_DIR) $(INSTALL_DIR) /d
@ -1026,3 +1028,4 @@ clean-deps2:
clean-deps: clean-deps1 clean-deps2

View File

@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
@ -44,6 +45,9 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/filesystem.h>
#include <epan/plugins.h>
#include <epan/report_err.h>
#include "wtap.h"
#ifdef NEED_GETOPT_H
@ -247,6 +251,18 @@ static void usage(gboolean is_error)
fprintf(output, "If no options are given, default is to display all infos\n");
}
/*
* Errors are reported with a console message.
*/
static void
failure_message(const char *msg_format, va_list ap)
{
fprintf(stderr, "capinos: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
int main(int argc, char *argv[])
{
wtap *wth;
@ -256,8 +272,20 @@ int main(int argc, char *argv[])
extern int optind;
int opt;
int status = 0;
char* init_progfile_dir_error;
/* Register wiretap plugins */
/* Process the options first */
if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
init_report_err(failure_message,NULL,NULL);
init_plugins();
register_all_wiretap_modules();
}
/* Process the options */
while ((opt = getopt(argc, argv, "tcsduaeyizvh")) !=-1) {

View File

@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
/*
* Just make sure we include the prototype for strptime as well
@ -54,6 +55,9 @@
#endif
#include "epan/crypt/crypt-md5.h"
#include "epan/plugins.h"
#include "epan/report_err.h"
#include "epan/filesystem.h"
#include "svnversion.h"
@ -346,6 +350,14 @@ static void list_encap_types(void) {
}
}
static void
failure_message(const char *msg_format, va_list ap)
{
fprintf(stderr, "editcap: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
int main(int argc, char *argv[])
{
@ -368,9 +380,19 @@ int main(int argc, char *argv[])
int split_packet_count = 0;
int written_count = 0;
char *filename;
/* Process the options first */
char* init_progfile_dir_error;
/* Register wiretap plugins */
if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
init_report_err(failure_message,NULL,NULL);
init_plugins();
register_all_wiretap_modules();
}
/* Process the options */
while ((opt = getopt(argc, argv, "A:B:c:C:dE:F:hrs:t:T:v")) !=-1) {
switch (opt) {

View File

@ -68,6 +68,7 @@ LIBWIRESHARK_SRC = \
range.c \
reassemble.c \
reedsolomon.c \
report_err.c \
req_resp_hdrs.c \
sigcomp_state_hdlr.c \
sigcomp-udvm.c \

View File

@ -58,10 +58,6 @@
int wslua_init(void*);
#endif
static void (*report_failure_func)(const char *, va_list);
static void (*report_open_failure_func)(const char *, int, gboolean);
static void (*report_read_failure_func)(const char *, int);
gchar*
epan_get_version(void) {
return VERSION;
@ -76,9 +72,7 @@ epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
void (*report_open_failure)(const char *, int, gboolean),
void (*report_read_failure)(const char *, int))
{
report_failure_func = report_failure;
report_open_failure_func = report_open_failure;
report_read_failure_func = report_read_failure;
init_report_err(report_failure, report_open_failure, report_read_failure);
/* initialize memory allocation subsystem */
ep_init_chunk();
@ -136,42 +130,6 @@ epan_circuit_init(void)
circuit_init();
}
/*
* Report a general error.
*/
void
report_failure(const char *msg_format, ...)
{
va_list ap;
va_start(ap, msg_format);
(*report_failure_func)(msg_format, ap);
va_end(ap);
}
/*
* Report an error when trying to open or create a file.
* "err" is assumed to be an error code from Wiretap; positive values are
* UNIX-style errnos, so this can be used for open failures not from
* Wiretap as long as the failue code is just an errno.
*/
void
report_open_failure(const char *filename, int err,
gboolean for_writing)
{
(*report_open_failure_func)(filename, err, for_writing);
}
/*
* Report an error when trying to read a file.
* "err" is assumed to be a UNIX-style errno.
*/
void
report_read_failure(const char *filename, int err)
{
(*report_read_failure_func)(filename, err);
}
epan_dissect_t*
epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
{

View File

@ -636,7 +636,7 @@ get_datafile_dir(void)
* of the plugin directory, so it can just fetch the plugins built
* as part of the build process.
*/
static const char *plugin_dir;
static const char *plugin_dir = NULL;
void
init_plugin_dir(void)
@ -694,6 +694,7 @@ init_plugin_dir(void)
const char *
get_plugin_dir(void)
{
if (!plugin_dir) init_plugin_dir();
return plugin_dir;
}

View File

@ -173,6 +173,7 @@ plugins_scan_dir(const char *dirname)
if ((dir = eth_dir_open(dirname, 0, NULL)) != NULL)
{
while ((file = eth_dir_read_name(dir)) != NULL)
{
name = eth_dir_get_name(file);
@ -344,14 +345,6 @@ plugins_scan_dir(const char *dirname)
continue;
}
/*
* Call its register routine if it has one.
* XXX - just save this and call it with the built-in
* dissector register routines?
*/
if (register_protoinfo != NULL)
register_protoinfo();
}
eth_dir_close(dir);
}
@ -440,6 +433,27 @@ init_plugins(void)
}
}
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)
{

View File

@ -44,6 +44,7 @@ typedef struct _plugin {
WS_VAR_IMPORT plugin *plugin_list;
extern void init_plugins(void);
extern void register_all_plugin_registrations(void);
extern void register_all_plugin_handoffs(void);
extern void register_all_plugin_tap_listeners(void);
extern void register_all_wiretap_modules(void);

View File

@ -354,6 +354,7 @@ proto_init(void (register_all_protocols)(register_cb cb, gpointer client_data),
if(cb)
(*cb)(RA_PLUGIN_REGISTER, NULL, client_data);
init_plugins();
register_all_plugin_registrations();
#endif
/* Now call the "handoff registration" routines of all built-in

80
epan/report_err.c Normal file
View File

@ -0,0 +1,80 @@
/* report_err.h
* Declarations of routines for dissectors to use to report errors to
* the user (e.g., problems with preference settings)
*
* $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib.h>
#include <stdarg.h>
#include "report_err.h"
static void (*report_failure_func)(const char *, va_list);
static void (*report_open_failure_func)(const char *, int, gboolean);
static void (*report_read_failure_func)(const char *, int);
void init_report_err(void (*report_failure)(const char *, va_list),
void (*report_open_failure)(const char *, int, gboolean),
void (*report_read_failure)(const char *, int)) {
report_failure_func = report_failure;
report_open_failure_func = report_open_failure;
report_read_failure_func = report_read_failure;
}
/*
* Report a general error.
*/
void
report_failure(const char *msg_format, ...)
{
va_list ap;
va_start(ap, msg_format);
(*report_failure_func)(msg_format, ap);
va_end(ap);
}
/*
* Report an error when trying to open or create a file.
* "err" is assumed to be an error code from Wiretap; positive values are
* UNIX-style errnos, so this can be used for open failures not from
* Wiretap as long as the failue code is just an errno.
*/
void
report_open_failure(const char *filename, int err,
gboolean for_writing)
{
(*report_open_failure_func)(filename, err, for_writing);
}
/*
* Report an error when trying to read a file.
* "err" is assumed to be a UNIX-style errno.
*/
void
report_read_failure(const char *filename, int err)
{
(*report_read_failure_func)(filename, err);
}

View File

@ -30,6 +30,14 @@
extern "C" {
#endif /* __cplusplus */
/*
* Initialize the report err routines
*/
extern void init_report_err(
void (*report_failure)(const char *, va_list),
void (*report_open_failure)(const char *, int, gboolean),
void (*report_read_failure)(const char *, int));
/*
* Report an error when trying to open a file.
*/

View File

@ -2159,11 +2159,6 @@ main(int argc, char *argv[])
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
/*
* Now attempt to get the pathname of the plugins.
*/
init_plugin_dir();
/* initialize the funnel mini-api */
initialize_funnel_ops();

View File

@ -734,11 +734,6 @@ main(int argc, char *argv[])
init_progfile_dir_error);
}
/*
* Now attempt to get the pathname of the plugins.
*/
init_plugin_dir();
/*
* In order to have the -X opts assigned before the wslua machine starts
* we need to call getopts before epan_init() gets called.