aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Sharpe <sharpe@ns.aus.com>2004-01-03 18:40:08 +0000
committerRichard Sharpe <sharpe@ns.aus.com>2004-01-03 18:40:08 +0000
commitfa9874ef73e0bb94c525a534b61e8ac75415bc9f (patch)
treebaf17f3e7d92f2855ed3571140193a98c0baa779
parent5d7261eb78a84974c9137fe71c931bacafa054dc (diff)
Apply the patches from Tadaaki Nagao for a global version of disabled
protocols ... svn path=/trunk/; revision=9538
-rw-r--r--AUTHORS4
-rw-r--r--disabled_protos.c160
-rw-r--r--disabled_protos.h8
-rw-r--r--epan/proto.c16
-rw-r--r--epan/proto.h8
-rw-r--r--gtk/main.c29
-rw-r--r--packet-data.c4
-rw-r--r--packet-frame.c10
-rw-r--r--tethereal.c23
9 files changed, 175 insertions, 87 deletions
diff --git a/AUTHORS b/AUTHORS
index 04254d83de..5886c6e017 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1978,6 +1978,10 @@ Michael Shuldman <michaels [AT] inet.no> {
X11 replies, events and errors (matched to their request)
}
+Tadaaki Nagao <nagao [AT] iij.ad.jp> {
+ Added a global version of disabled_protos
+}
+
And assorted fixes and enhancements by the people listed above and by:
Pavel Roskin <proski [AT] gnu.org>
diff --git a/disabled_protos.c b/disabled_protos.c
index bb3c68e840..11b45de9f6 100644
--- a/disabled_protos.c
+++ b/disabled_protos.c
@@ -1,7 +1,7 @@
/* disabled_protos.c
* Code for reading and writing the disabled protocols file.
*
- * $Id: disabled_protos.c,v 1.3 2003/11/16 23:17:15 guy Exp $
+ * $Id: disabled_protos.c,v 1.4 2004/01/03 18:40:07 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -42,11 +42,13 @@
#include "disabled_protos.h"
-#define PROTOCOLS_FILE_NAME "disabled_protos"
+#define GLOBAL_PROTOCOLS_FILE_NAME "disabled_protos"
+#define PROTOCOLS_FILE_NAME "disabled_protos"
/*
* List of disabled protocols
*/
+static GList *global_disabled_protos = NULL;
static GList *disabled_protos = NULL;
#define INIT_BUF_SIZE 128
@@ -61,60 +63,88 @@ static GList *disabled_protos = NULL;
* or "*read_errno_return" is set to the error if a read failed.
*/
+static int read_disabled_protos_list_file(const char *ff_path, FILE *ff,
+ GList **flp);
+
void
-read_disabled_protos_list(char **pref_path_return, int *open_errno_return,
+read_disabled_protos_list(char **gpath_return, int *gopen_errno_return,
+ int *gread_errno_return,
+ char **path_return, int *open_errno_return,
int *read_errno_return)
{
- char *ff_path, *ff_name;
+ int err;
+ char *gff_path, *ff_path;
FILE *ff;
- GList **flp;
- GList *fl_ent;
- protocol_def *prot;
- int c;
- char *prot_name;
- int prot_name_len;
- int prot_name_index;
- int line = 1;
- *pref_path_return = NULL; /* assume no error */
+ /* Construct the pathname of the global disabled protocols file. */
+ gff_path = get_datafile_path(GLOBAL_PROTOCOLS_FILE_NAME);
+
+ /* Read the global disabled protocols file, if it exists. */
+ *gpath_return = NULL;
+ if ((ff = fopen(gff_path, "r")) != NULL) {
+ /* We succeeded in opening it; read it. */
+ err = read_disabled_protos_list_file(gff_path, ff,
+ &global_disabled_protos);
+ if (err != 0) {
+ /* We had an error reading the file; return the errno and the
+ pathname, so our caller can report the error. */
+ *gopen_errno_return = 0;
+ *gread_errno_return = err;
+ *gpath_return = gff_path;
+ } else
+ g_free(gff_path);
+ fclose(ff);
+ } else {
+ /* We failed to open it. If we failed for some reason other than
+ "it doesn't exist", return the errno and the pathname, so our
+ caller can report the error. */
+ if (errno != ENOENT) {
+ *gopen_errno_return = errno;
+ *gread_errno_return = 0;
+ *gpath_return = gff_path;
+ }
+ }
- ff_name = PROTOCOLS_FILE_NAME;
- flp = &disabled_protos;
-
- /* To do: generalize this */
- ff_path = get_persconffile_path(ff_name, FALSE);
- if ((ff = fopen(ff_path, "r")) == NULL) {
- /*
- * Did that fail because we the file didn't exist?
- */
+ /* Construct the pathname of the user's disabled protocols file. */
+ ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, FALSE);
+
+ /* Read the global disabled protocols file, if it exists. */
+ *path_return = NULL;
+ if ((ff = fopen(ff_path, "r")) != NULL) {
+ /* We succeeded in opening it; read it. */
+ err = read_disabled_protos_list_file(ff_path, ff, &disabled_protos);
+ if (err != 0) {
+ /* We had an error reading the file; return the errno and the
+ pathname, so our caller can report the error. */
+ *open_errno_return = 0;
+ *read_errno_return = err;
+ *path_return = ff_path;
+ } else
+ g_free(ff_path);
+ fclose(ff);
+ } else {
+ /* We failed to open it. If we failed for some reason other than
+ "it doesn't exist", return the errno and the pathname, so our
+ caller can report the error. */
if (errno != ENOENT) {
- /*
- * No. Just give up.
- */
- *pref_path_return = ff_path;
*open_errno_return = errno;
*read_errno_return = 0;
- return;
- }
-
- /*
- * Yes. See if there's a "protocols" file; if so, read it.
- */
- g_free(ff_path);
- ff_path = get_persconffile_path(PROTOCOLS_FILE_NAME, FALSE);
- if ((ff = fopen(ff_path, "r")) == NULL) {
- /*
- * Well, that didn't work, either. Just give up.
- * Return an error if the file existed but we couldn't open it.
- */
- if (errno != ENOENT) {
- *pref_path_return = ff_path;
- *open_errno_return = errno;
- *read_errno_return = 0;
- }
- return;
+ *path_return = ff_path;
}
}
+}
+
+static int
+read_disabled_protos_list_file(const char *ff_path, FILE *ff,
+ GList **flp)
+{
+ GList *fl_ent;
+ protocol_def *prot;
+ int c;
+ char *prot_name;
+ int prot_name_len;
+ int prot_name_index;
+ int line = 1;
/* If we already have a list of protocols, discard it. */
if (*flp != NULL) {
@@ -214,16 +244,11 @@ read_disabled_protos_list(char **pref_path_return, int *open_errno_return,
prot->name = g_strdup(prot_name);
*flp = g_list_append(*flp, prot);
}
- g_free(ff_path);
- fclose(ff);
g_free(prot_name);
- return;
+ return 0;
error:
- *pref_path_return = ff_path;
- *open_errno_return = 0;
- *read_errno_return = errno;
- fclose(ff);
+ return errno;
}
/*
@@ -240,7 +265,7 @@ set_disabled_protos_list(void)
* assume all protocols are enabled by default
*/
if (disabled_protos == NULL)
- return; /* nothing to disable */
+ goto skip;
fl_ent = g_list_first(disabled_protos);
@@ -248,10 +273,31 @@ set_disabled_protos_list(void)
prot = (protocol_def *) fl_ent->data;
i = proto_get_id_by_filter_name(prot->name);
if (i == -1) {
- /* XXX - complain here? */
+ /* XXX - complain here? */
+ } else {
+ if (proto_can_toggle_protocol(i))
+ proto_set_decoding(i, FALSE);
+ }
+
+ fl_ent = fl_ent->next;
+ }
+
+skip:
+ if (global_disabled_protos == NULL)
+ return;
+
+ fl_ent = g_list_first(global_disabled_protos);
+
+ while (fl_ent != NULL) {
+ prot = (protocol_def *) fl_ent->data;
+ i = proto_get_id_by_filter_name(prot->name);
+ if (i == -1) {
+ /* XXX - complain here? */
} else {
- if (proto_can_disable_protocol(i))
- proto_set_decoding(i, FALSE);
+ if (proto_can_toggle_protocol(i)) {
+ proto_set_decoding(i, FALSE);
+ proto_set_cant_toggle(i);
+ }
}
fl_ent = fl_ent->next;
@@ -299,7 +345,7 @@ save_disabled_protos_list(char **pref_path_return, int *errno_return)
for (i = proto_get_first_protocol(&cookie); i != -1;
i = proto_get_next_protocol(&cookie)) {
- if (!proto_can_disable_protocol(i)) {
+ if (!proto_can_toggle_protocol(i)) {
continue;
}
diff --git a/disabled_protos.h b/disabled_protos.h
index 867f32f9af..edb77c6cae 100644
--- a/disabled_protos.h
+++ b/disabled_protos.h
@@ -1,7 +1,7 @@
/* disabled_protos.h
* Declarations of routines for reading and writing the disabled protocols file.
*
- * $Id: disabled_protos.h,v 1.1 2003/08/07 00:41:26 guy Exp $
+ * $Id: disabled_protos.h,v 1.2 2004/01/03 18:40:07 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -40,8 +40,10 @@ typedef struct {
* or "*read_errno_return" is set to the error if we got an error reading
* the file.
*/
-void read_disabled_protos_list(char **pref_path_return, int *open_errno_return,
- int *read_errno_return);
+void read_disabled_protos_list(char **gpath_return, int *gopen_errno_return,
+ int *gread_errno_return,
+ char **path_return, int *open_errno_return,
+ int *read_errno_return);
/*
* Disable protocols as per the stored configuration
diff --git a/epan/proto.c b/epan/proto.c
index 8bb58052ae..c43013b12c 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1,7 +1,7 @@
/* proto.c
* Routines for protocol tree
*
- * $Id: proto.c,v 1.128 2003/12/24 23:37:28 guy Exp $
+ * $Id: proto.c,v 1.129 2004/01/03 18:40:08 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -138,7 +138,7 @@ struct _protocol {
GList *fields; /* fields for this protocol */
GList *last_field; /* pointer to end of list of fields */
gboolean is_enabled; /* TRUE if protocol is enabled */
- gboolean can_disable; /* TRUE if protocol can be disabled */
+ gboolean can_toggle; /* TRUE if is_enabled can be changed */
};
/* List of all protocols */
@@ -2235,7 +2235,7 @@ proto_register_protocol(char *name, char *short_name, char *filter_name)
protocol->filter_name = filter_name;
protocol->fields = NULL;
protocol->is_enabled = TRUE; /* protocol is enabled by default */
- protocol->can_disable = TRUE;
+ protocol->can_toggle = TRUE;
protocols = g_list_insert_sorted(protocols, protocol,
proto_compare_name);
@@ -2401,12 +2401,12 @@ proto_is_protocol_enabled(protocol_t *protocol)
}
gboolean
-proto_can_disable_protocol(int proto_id)
+proto_can_toggle_protocol(int proto_id)
{
protocol_t *protocol;
protocol = find_protocol_by_id(proto_id);
- return protocol->can_disable;
+ return protocol->can_toggle;
}
void
@@ -2415,17 +2415,17 @@ proto_set_decoding(int proto_id, gboolean enabled)
protocol_t *protocol;
protocol = find_protocol_by_id(proto_id);
- g_assert(enabled || protocol->can_disable);
+ g_assert(protocol->can_toggle);
protocol->is_enabled = enabled;
}
void
-proto_set_cant_disable(int proto_id)
+proto_set_cant_toggle(int proto_id)
{
protocol_t *protocol;
protocol = find_protocol_by_id(proto_id);
- protocol->can_disable = FALSE;
+ protocol->can_toggle = FALSE;
}
/* for use with static arrays only, since we don't allocate our own copies
diff --git a/epan/proto.h b/epan/proto.h
index 6f052afcfc..3f8278bcb8 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -1,7 +1,7 @@
/* proto.h
* Definitions for protocol display
*
- * $Id: proto.h,v 1.54 2003/12/06 06:09:13 gram Exp $
+ * $Id: proto.h,v 1.55 2004/01/03 18:40:08 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -558,7 +558,7 @@ extern gboolean proto_registrar_is_protocol(int n);
extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
/* Can item #n decoding be disabled? */
-extern gboolean proto_can_disable_protocol(int proto_id);
+extern gboolean proto_can_toggle_protocol(int proto_id);
/* Routines to use to iterate over the protocols and their fields;
* they return the item number of the protocol in question or the
@@ -589,8 +589,8 @@ extern char *proto_get_protocol_filter_name(int proto_id);
/* Enable / Disable protocol */
extern void proto_set_decoding(int proto_id, gboolean enabled);
-/* Disable disabling of protocol */
-extern void proto_set_cant_disable(int proto_id);
+/* Disable disabling/enabling of protocol */
+extern void proto_set_cant_toggle(int proto_id);
/* Get length of registered field according to field type.
* 0 means undeterminable at registration time.
diff --git a/gtk/main.c b/gtk/main.c
index 740bf245fa..966d9ced1b 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.347 2003/12/29 20:05:59 ulfl Exp $
+ * $Id: main.c,v 1.348 2004/01/03 18:40:08 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1760,10 +1760,12 @@ main(int argc, char *argv[])
char *rf_path;
int rf_open_errno;
char *gpf_path, *pf_path;
- char *cf_path, *df_path, *dp_path;
+ char *cf_path, *df_path;
+ char *gdp_path, *dp_path;
int gpf_open_errno, gpf_read_errno;
int pf_open_errno, pf_read_errno;
int cf_open_errno, df_open_errno;
+ int gdp_open_errno, gdp_read_errno;
int dp_open_errno, dp_read_errno;
int err;
#ifdef HAVE_LIBPCAP
@@ -1968,7 +1970,8 @@ main(int argc, char *argv[])
read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
/* Read the disabled protocols file. */
- read_disabled_protos_list(&dp_path, &dp_open_errno, &dp_read_errno);
+ read_disabled_protos_list(&gdp_path, &gdp_open_errno, &gdp_read_errno,
+ &dp_path, &dp_open_errno, &dp_read_errno);
init_cap_file(&cfile);
@@ -2433,7 +2436,7 @@ main(int argc, char *argv[])
prefs_apply_all();
/* disabled protocols as per configuration file */
- if (dp_path == NULL) {
+ if (gdp_path == NULL && dp_path == NULL) {
set_disabled_protos_list();
}
@@ -2702,6 +2705,24 @@ main(int argc, char *argv[])
g_free(df_path);
}
+ /* If the global disabled protocols file exists but we failed to open it,
+ or had an error reading it, pop up an alert box; we defer that until now,
+ so that the alert box is more likely to come up on top of the main
+ window. */
+ if (gdp_path != NULL) {
+ if (gdp_open_errno != 0) {
+ simple_dialog(ESD_TYPE_WARN, NULL,
+ "Could not open global disabled protocols file\n\"%s\": %s.",
+ gdp_path, strerror(gdp_open_errno));
+ }
+ if (gdp_read_errno != 0) {
+ simple_dialog(ESD_TYPE_WARN, NULL,
+ "I/O error reading global disabled protocols file\n\"%s\": %s.",
+ gdp_path, strerror(gdp_read_errno));
+ }
+ g_free(gdp_path);
+ }
+
/* If the user's disabled protocols file exists but we failed to open it,
or had an error reading it, pop up an alert box; we defer that until now,
so that the alert box is more likely to come up on top of the main
diff --git a/packet-data.c b/packet-data.c
index 7583ae3ac2..5964b9c081 100644
--- a/packet-data.c
+++ b/packet-data.c
@@ -2,7 +2,7 @@
* Routines for raw data (default case)
* Gilbert Ramirez <gram@alumni.rice.edu>
*
- * $Id: packet-data.c,v 1.33 2003/04/22 13:47:37 tuexen Exp $
+ * $Id: packet-data.c,v 1.34 2004/01/03 18:40:07 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -67,5 +67,5 @@ proto_register_data(void)
* "Data" is used to dissect something whose normal dissector
* is disabled, so it cannot itself be disabled.
*/
- proto_set_cant_disable(proto_data);
+ proto_set_cant_toggle(proto_data);
}
diff --git a/packet-frame.c b/packet-frame.c
index dc904f8438..65fbf10568 100644
--- a/packet-frame.c
+++ b/packet-frame.c
@@ -2,7 +2,7 @@
*
* Top-most dissector. Decides dissector based on Wiretap Encapsulation Type.
*
- * $Id: packet-frame.c,v 1.42 2003/12/06 06:09:10 gram Exp $
+ * $Id: packet-frame.c,v 1.43 2004/01/03 18:40:07 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -308,7 +308,7 @@ proto_register_frame(void)
/* You can't disable dissection of "Frame", as that would be
tantamount to not doing any dissection whatsoever. */
- proto_set_cant_disable(proto_frame);
+ proto_set_cant_toggle(proto_frame);
proto_short = proto_register_protocol("Short Frame", "Short frame", "short");
proto_malformed = proto_register_protocol("Malformed Packet",
@@ -320,9 +320,9 @@ proto_register_frame(void)
/* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
Packet" aren't really protocols, they're error indications;
disabling them makes no sense. */
- proto_set_cant_disable(proto_short);
- proto_set_cant_disable(proto_malformed);
- proto_set_cant_disable(proto_unreassembled);
+ proto_set_cant_toggle(proto_short);
+ proto_set_cant_toggle(proto_malformed);
+ proto_set_cant_toggle(proto_unreassembled);
/* Our preferences */
frame_module = prefs_register_protocol(proto_frame, NULL);
diff --git a/tethereal.c b/tethereal.c
index 3a672629b3..04280099ba 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -1,6 +1,6 @@
/* tethereal.c
*
- * $Id: tethereal.c,v 1.212 2003/12/18 02:46:45 guy Exp $
+ * $Id: tethereal.c,v 1.213 2004/01/03 18:40:07 sharpe Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -782,9 +782,10 @@ main(int argc, char *argv[])
#endif /* _WIN32 */
char *gpf_path, *pf_path;
- char *dp_path;
+ char *gdp_path, *dp_path;
int gpf_open_errno, gpf_read_errno;
int pf_open_errno, pf_read_errno;
+ int gdp_open_errno, gdp_read_errno;
int dp_open_errno, dp_read_errno;
int err;
#ifdef HAVE_LIBPCAP
@@ -882,7 +883,21 @@ main(int argc, char *argv[])
g_resolv_flags = prefs->name_resolve;
/* Read the disabled protocols file. */
- read_disabled_protos_list(&dp_path, &dp_open_errno, &dp_read_errno);
+ read_disabled_protos_list(&gdp_path, &gdp_open_errno, &gdp_read_errno,
+ &dp_path, &dp_open_errno, &dp_read_errno);
+ if (gdp_path != NULL) {
+ if (gdp_open_errno != 0) {
+ fprintf(stderr,
+ "Could not open global disabled protocols file\n\"%s\": %s.\n",
+ gdp_path, strerror(gdp_open_errno));
+ }
+ if (gdp_read_errno != 0) {
+ fprintf(stderr,
+ "I/O error reading global disabled protocols file\n\"%s\": %s.\n",
+ gdp_path, strerror(gdp_read_errno));
+ }
+ g_free(gdp_path);
+ }
if (dp_path != NULL) {
if (dp_open_errno != 0) {
fprintf(stderr,
@@ -1375,7 +1390,7 @@ main(int argc, char *argv[])
prefs_apply_all();
/* disabled protocols as per configuration file */
- if (dp_path == NULL) {
+ if (gdp_path == NULL && dp_path == NULL) {
set_disabled_protos_list();
}