Make "epan_init()" take, as additional arguments, pointers to routines
authorGuy Harris <guy@alum.mit.edu>
Tue, 23 Mar 2004 21:19:58 +0000 (21:19 -0000)
committerGuy Harris <guy@alum.mit.edu>
Tue, 23 Mar 2004 21:19:58 +0000 (21:19 -0000)
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

14 files changed:
Makefile.common
alert_box.c
alert_box.h
dftest.c
epan/Makefile.am
epan/epan.c
epan/epan.h
epan/report_err.h [moved from report_err.h with 96% similarity]
gtk/main.c
packet-diameter.c
plugins/asn1/packet-asn1.c
plugins/plugin_api.h
plugins/plugin_api_list.c
tethereal.c

index ef985db6a308fd0edbc8d94c4d50d31edd95ea4a..07520908ea631daadea5751bef43de3a77118ec4 100644 (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       \
index d8a18b47db5480956021d9c37e4243ac76a57591..2bb611fa8361e9ec225fb62943db6296cdd69ee6 100644 (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.
- */
-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.
+ * Alert box for a failed attempt to read a file.
+ * "err" is assumed to be a UNIX-style errno.
  */
 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.",
index 667b8101ed87f462d558b00733055376cae5e72b..807f1106f0574d0c8b649d0b4d36e8e68acfbccb 100644 (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.
index 751086f7af7418b793774fa9473bf04ccbb566b9..55af015098466ed113b1ae6bb955b24f67c15b13 100644 (file)
--- a/dftest.c
+++ b/dftest.c
@@ -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>
 
 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));
 }
index ca49c06a39e9f2119a7182b012fe6919647b8945..52a082c378d1e0a50d111b1af331ea9e7444e5fc 100644 (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             \
index 27fcb911773b7c47b355ae0c97b1cd50513228de..b1fc6adc91b7ffc2ea816df2ea7205205ee02f35 100644 (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,
  * 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)
 {
index b3efd355cc9a4e066c7b8151580ca3a0627143e2..3493a7f5a2a5a27183a04e3a55c95950d82011ea 100644 (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);
similarity index 96%
rename from report_err.h
rename to epan/report_err.h
index c3e938cf6a2f2456bdf5d0ab0338e2791d8c5419..ef116eb04606845e0833a8c76485c12a89786311 100644 (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>
index 5074e7dd71d83f1da2d67dc03a2f5e6d8559a455..bd72fcd4ce4af40e36e5d5e69e92f70b253667d4 100644 (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. */
index c5ea037d15274016c54e2f7b13b1f3186aa8a8b5..18c36d81ed7b9d97e3bdeea2c893ba144791d0ff 100644 (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"
 
index 1efcdcaf068e353d33b8fa958a0c19a47bb14618..2c87ae2c0b266d74a8f3f702279627704103e9ce 100644 (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"
index b47f713aed59ac01a0372e5e38013b5bf1cdd3d5..15a49461a609bb2ce89a091aa3d3715e52f54f05 100644 (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"
 
index d522687524e78e47def200fe0b1c0de38abb89b5..28bc0c1ea48ba7443e0d78929ada5f5a7ce30e72 100644 (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);
index d92e77ab41ebf96adfa7881552656e1d9dfb3f6f..2450495d7a1f0580410d9804f1be0f8f78302a12 100644 (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));