Make "epan_init()" take, as additional arguments, pointers to routines

that dissectors should call to report file open and read errors, and
have "report_open_failure()" and "report_read_failure()" call through
those pointers, rather than being defined and exported by the
application using libethereal - instead, the application would define
those functions and pass pointers to them to 'epan_init()".

Move "report_err.h" to the epan directory, as the functions it declares
are now part of the libethereal API.

svn path=/trunk/; revision=10470
This commit is contained in:
Guy Harris 2004-03-23 21:19:58 +00:00
parent bf1315c256
commit 121f06fab7
14 changed files with 92 additions and 55 deletions

View File

@ -3,7 +3,7 @@
# a) common to both files and
# b) portable between both files
#
# $Id: Makefile.common,v 1.34 2004/03/23 19:51:05 guy Exp $
# $Id: Makefile.common,v 1.35 2004/03/23 21:19:55 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@ethereal.com>
@ -340,7 +340,6 @@ ethereal_INCLUDES = \
menu.h \
progress_dlg.h \
proto_hier_stats.h \
report_err.h \
simple_dialog.h \
statusbar.h \
summary.h \

View File

@ -2,7 +2,7 @@
* Routines to put up various "standard" alert boxes used in multiple
* places
*
* $Id: alert_box.c,v 1.4 2004/02/21 02:15:05 guy Exp $
* $Id: alert_box.c,v 1.5 2004/03/23 21:19:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -35,7 +35,6 @@
#include <epan/dfilter/dfilter.h>
#include "alert_box.h"
#include "report_err.h"
#include "simple_dialog.h"
@ -59,19 +58,11 @@ open_failure_alert_box(const char *filename, int err, gboolean for_writing)
}
/*
* Open/create errors are reported with an alert box in Ethereal.
* Alert box for a failed attempt to read a file.
* "err" is assumed to be a UNIX-style errno.
*/
void
report_open_failure(const char *filename, int err, gboolean for_writing)
{
open_failure_alert_box(filename, err, for_writing);
}
/*
* Read errors are reported with an alert box in Ethereal.
*/
void
report_read_failure(const char *filename, int err)
read_failure_alert_box(const char *filename, int err)
{
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"An error occurred while reading from the file \"%s\": %s.",

View File

@ -2,7 +2,7 @@
* Routines to put up various "standard" alert boxes used in multiple
* places
*
* $Id: alert_box.h,v 1.3 2004/02/11 01:37:11 guy Exp $
* $Id: alert_box.h,v 1.4 2004/03/23 21:19:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -39,6 +39,12 @@ extern "C" {
extern void open_failure_alert_box(const char *filename, int err,
gboolean for_writing);
/*
* Alert box for a failed attempt to read a file.
* "err" is assumed to be a UNIX-style errno.
*/
extern void read_failure_alert_box(const char *filename, int err);
/*
* Alert box for a failed attempt to write to a file.
* "err" is assumed to be a UNIX-style errno.

View File

@ -1,6 +1,6 @@
/* dftest.c.c
*
* $Id: dftest.c,v 1.9 2004/03/18 19:04:31 obiot Exp $
* $Id: dftest.c,v 1.10 2004/03/23 21:19:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -50,6 +50,10 @@
packet_info pi;
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
int
main(int argc, char **argv)
{
@ -67,7 +71,8 @@ main(int argc, char **argv)
by the dissectors, and we must do it before we read the preferences,
in case any dissectors register preferences. */
epan_init(PLUGIN_DIR,register_all_protocols,
register_all_protocol_handoffs);
register_all_protocol_handoffs,
open_failure_message, read_failure_message);
/* now register the preferences for any non-dissector modules.
we must do that before we read the preferences as well. */
@ -138,22 +143,23 @@ main(int argc, char **argv)
/*
* Open/create errors are reported with an console message in "dftest".
*/
void
report_open_failure(const char *filename, int err, gboolean for_writing)
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
char *errmsg;
char *errmsg;
errmsg = g_strdup_printf(file_open_error_message(err, for_writing), filename);
fprintf(stderr, "dftest: %s\n", errmsg);
g_free(errmsg);
errmsg = g_strdup_printf(file_open_error_message(err, for_writing),
filename);
fprintf(stderr, "dftest: %s\n", errmsg);
g_free(errmsg);
}
/*
* Read errors are reported with an console message in "dftest".
*/
void
report_read_failure(const char *filename, int err)
static void
read_failure_message(const char *filename, int err)
{
fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.",
filename, strerror(err));
fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.",
filename, strerror(err));
}

View File

@ -2,7 +2,7 @@
# Automake file for the EPAN library
# (Ethereal Protocol ANalyzer Library)
#
# $Id: Makefile.am,v 1.43 2004/03/22 21:29:52 gerald Exp $
# $Id: Makefile.am,v 1.44 2004/03/23 21:19:56 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@ethereal.com>
@ -52,7 +52,7 @@ libethereal_la_SOURCES = \
column-utils.h \
epan.c \
epan.h \
epan_dissect.h \
epan_dissect.h \
except.c \
except.h \
exceptions.h \
@ -79,6 +79,7 @@ libethereal_la_SOURCES = \
proto.h \
resolv.c \
resolv.h \
report_err.h \
slab.h \
sna-utils.c \
sna-utils.h \

View File

@ -1,6 +1,6 @@
/* epan.h
*
* $Id: epan.c,v 1.23 2003/05/04 18:50:53 gerald Exp $
* $Id: epan.c,v 1.24 2004/03/23 21:19:56 guy Exp $
*
* Ethereal Protocol Analyzer Library
*/
@ -12,6 +12,7 @@
#include <glib.h>
#include "epan.h"
#include "epan_dissect.h"
#include "report_err.h"
#include "conversation.h"
#include "circuit.h"
@ -21,6 +22,9 @@
#include "../tap.h"
#include "resolv.h"
static void (*report_open_failure_func)(const char *, int, gboolean);
static void (*report_read_failure_func)(const char *, int);
/*
* XXX - this takes the plugin directory as an argument, because
* libethereal now has its own configure script and "config.h" file,
@ -43,9 +47,13 @@
* libraries are located.)
*/
void
epan_init(const char *plugin_dir, void (register_all_protocols)(void),
void (register_all_handoffs)(void))
epan_init(const char *plugin_dir, void (*register_all_protocols)(void),
void (*register_all_handoffs)(void),
void (*report_open_failure)(const char *, int, gboolean),
void (*report_read_failure)(const char *, int))
{
report_open_failure_func = report_open_failure;
report_read_failure_func = report_read_failure;
except_init();
tvbuff_init();
frame_data_init();
@ -81,6 +89,25 @@ epan_circuit_init(void)
circuit_init();
}
/*
* Report an error when trying to open a file.
*/
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.
*/
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

@ -1,6 +1,6 @@
/* epan.h
*
* $Id: epan.h,v 1.15 2002/10/22 08:44:33 guy Exp $
* $Id: epan.h,v 1.16 2004/03/23 21:19:56 guy Exp $
*
* Ethereal Protocol Analyzer Library
*
@ -32,8 +32,10 @@ typedef struct _epan_dissect_t epan_dissect_t;
#include "dfilter/dfilter.h"
void epan_init(const char * plugindir, void (register_all_protocols)(void),
void (register_all_handoffs)(void));
void epan_init(const char * plugindir, void (*register_all_protocols)(void),
void (*register_all_handoffs)(void),
void (*report_open_failure)(const char *, int, gboolean),
void (*report_read_failure)(const char *, int));
void epan_cleanup(void);
void epan_conversation_init(void);
void epan_circuit_init(void);

View File

@ -2,7 +2,7 @@
* Declarations of routines for dissectors to use to report errors to
* the user (e.g., problems with preference settings)
*
* $Id: report_err.h,v 1.1 2004/02/21 02:15:06 guy Exp $
* $Id: report_err.h,v 1.1 2004/03/23 21:19:56 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>

View File

@ -1,6 +1,6 @@
/* main.c
*
* $Id: main.c,v 1.419 2004/03/20 06:34:08 guy Exp $
* $Id: main.c,v 1.420 2004/03/23 21:19:56 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1939,7 +1939,8 @@ main(int argc, char *argv[])
"-G" flag, as the "-G" flag dumps information registered by the
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
epan_init(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs);
epan_init(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs,
open_failure_alert_box, read_failure_alert_box);
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */

View File

@ -1,7 +1,7 @@
/* packet-diameter.c
* Routines for Diameter packet disassembly
*
* $Id: packet-diameter.c,v 1.64 2004/03/21 23:19:36 guy Exp $
* $Id: packet-diameter.c,v 1.65 2004/03/23 21:19:55 guy Exp $
*
* Copyright (c) 2001 by David Frascone <dave@frascone.com>
*
@ -48,7 +48,7 @@
#include "xmlstub.h"
#include <epan/packet.h>
#include <epan/resolv.h>
#include "report_err.h"
#include <epan/report_err.h>
#include "prefs.h"
#include "packet-tcp.h"

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2003 by Matthijs Melchior <matthijs.melchior@xs4all.nl>
*
* $Id: packet-asn1.c,v 1.21 2004/03/02 23:45:34 jmayer Exp $
* $Id: packet-asn1.c,v 1.22 2004/03/23 21:19:58 guy Exp $
*
* A plugin for:
*
@ -82,8 +82,8 @@
#include "prefs.h"
#include <epan/strutil.h>
#include <epan/filesystem.h>
#include <epan/report_err.h>
#include "asn1.h"
#include "report_err.h"
#include "simple_dialog.h"
#include "plugins/plugin_api_defs.h"

View File

@ -1,7 +1,7 @@
/* plugin_api.h
* Routines for Ethereal plugins.
*
* $Id: plugin_api.h,v 1.60 2004/03/04 07:07:03 guy Exp $
* $Id: plugin_api.h,v 1.61 2004/03/23 21:19:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* Copyright 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
@ -45,6 +45,7 @@
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/report_err.h>
#include "prefs.h"
#include "reassemble.h"
#include "packet-giop.h"
@ -57,7 +58,6 @@
#include "xdlc.h"
#include "epan/except.h"
#include "epan/filesystem.h"
#include "report_err.h"
#include "plugin_table.h"

View File

@ -1,7 +1,7 @@
/* plugin_api_list.c
* Used to generate various included files for plugin API
*
* $Id: plugin_api_list.c,v 1.30 2004/03/04 07:07:03 guy Exp $
* $Id: plugin_api_list.c,v 1.31 2004/03/23 21:19:57 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -29,6 +29,8 @@
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/filesystem.h>
#include <epan/report_err.h>
#include <epan/except.h>
#include "prefs.h"
#include "reassemble.h"
#include "packet-giop.h"
@ -39,8 +41,6 @@
#include "tap.h"
#include "asn1.h"
#include "xdlc.h"
#include "epan/except.h"
#include "report_err.h"
gint check_col(column_info*, gint);
void col_clear(column_info*, gint);

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.232 2004/03/18 19:04:31 obiot Exp $
* $Id: tethereal.c,v 1.233 2004/03/23 21:19:56 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -96,7 +96,6 @@
#include "ringbuffer.h"
#include <epan/epan_dissect.h>
#include "tap.h"
#include "report_err.h"
#include <epan/timestamp.h>
#ifdef HAVE_LIBPCAP
@ -186,6 +185,10 @@ static int pipe_dispatch(int, loop_data *, struct pcap_hdr *, \
#endif /* _WIN32 */
#endif
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
capture_file cfile;
#ifdef HAVE_LIBPCAP
typedef struct {
@ -836,7 +839,8 @@ main(int argc, char *argv[])
"-G" flag, as the "-G" flag dumps information registered by the
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
epan_init(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs);
epan_init(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs,
open_failure_message, read_failure_message);
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */
@ -2970,8 +2974,8 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
/*
* Open/create errors are reported with an console message in Tethereal.
*/
void
report_open_failure(const char *filename, int err, gboolean for_writing)
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
char *errmsg;
@ -3328,8 +3332,8 @@ pipe_dispatch(int fd, loop_data *ld, struct pcap_hdr *hdr,
/*
* Read errors are reported with an console message in Tethereal.
*/
void
report_read_failure(const char *filename, int err)
static void
read_failure_message(const char *filename, int err)
{
fprintf(stderr, "tethereal: An error occurred while reading from the file \"%s\": %s.",
filename, strerror(err));