Add a mechanism for registering "obsolete" preference modules, so that

if a dissector had preferences at one point but no longer does, it can
register that fact, so that the old preferences in the preference file
are silently ignored.

Use that mechanism in the NCP dissector.

svn path=/trunk/; revision=5446
This commit is contained in:
Guy Harris 2002-05-11 18:58:02 +00:00
parent e694a0fbe2
commit 0bcf2de0d9
4 changed files with 50 additions and 7 deletions

View File

@ -3,7 +3,7 @@
* Gilbert Ramirez <gram@alumni.rice.edu>
* Modified to allow NCP over TCP/IP decodes by James Coe <jammer@cin.net>
*
* $Id: packet-ncp.c,v 1.56 2002/05/09 23:50:25 gram Exp $
* $Id: packet-ncp.c,v 1.57 2002/05/11 18:58:02 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -258,10 +258,16 @@ proto_register_ncp(void)
static gint *ett[] = {
&ett_ncp,
};
module_t *ncp_module;
proto_ncp = proto_register_protocol("NetWare Core Protocol", "NCP", "ncp");
proto_register_field_array(proto_ncp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Register an obsolete configuration option for what used to be the
initial size of the NCP hash. */
ncp_module = prefs_register_protocol_obsolete(proto_ncp);
prefs_register_obsolete_preference(ncp_module, "initial_hash_size");
}
void

View File

@ -2,7 +2,7 @@
* Definitions for implementation of preference handling routines;
* used by "friends" of the preferences type.
*
* $Id: prefs-int.h,v 1.4 2001/11/04 02:50:19 guy Exp $
* $Id: prefs-int.h,v 1.5 2002/05/11 18:58:02 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -33,6 +33,8 @@ struct pref_module {
GList *prefs; /* list of its preferences */
int numprefs; /* number of preferences */
gboolean prefs_changed; /* if TRUE, a preference has changed since we last checked */
gboolean obsolete; /* if TRUE, this is a module that used to
exist but no longer does */
};
/*

34
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.81 2002/03/31 21:05:11 guy Exp $
* $Id: prefs.c,v 1.82 2002/05/11 18:58:02 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -122,6 +122,7 @@ prefs_register_module(const char *name, const char *title,
module->prefs = NULL; /* no preferences, to start */
module->numprefs = 0;
module->prefs_changed = FALSE;
module->obsolete = FALSE;
/*
* Make sure that only lower-case ASCII letters, numbers,
@ -161,6 +162,22 @@ prefs_register_protocol(int id, void (*apply_cb)(void))
apply_cb);
}
/*
* Register that a protocol used to have preferences but no longer does,
* by creating an "obsolete" module for it.
*/
module_t *
prefs_register_protocol_obsolete(int id)
{
module_t *module;
module = prefs_register_module(proto_get_protocol_filter_name(id),
proto_get_protocol_short_name(id),
NULL);
module->obsolete = TRUE;
return module;
}
/*
* Find a module, given its name.
*/
@ -195,11 +212,15 @@ do_module_callback(gpointer data, gpointer user_data)
module_t *module = data;
module_cb_arg_t *arg = user_data;
(*arg->callback)(module, arg->user_data);
if (!module->obsolete)
(*arg->callback)(module, arg->user_data);
}
/*
* Call a callback function, with a specified argument, for each module.
* Ignores "obsolete" modules; their sole purpose is to allow old
* preferences for dissectors that no longer have preferences to be
* silently ignored in preference files.
*/
void
prefs_module_foreach(module_cb callback, gpointer user_data)
@ -216,6 +237,8 @@ call_apply_cb(gpointer data, gpointer user_data _U_)
{
module_t *module = data;
if (module->obsolete)
return;
if (module->prefs_changed) {
if (module->apply_cb != NULL)
(*module->apply_cb)();
@ -314,7 +337,9 @@ find_preference(module_t *module, const char *name)
gboolean
prefs_is_registered_protocol(char *name)
{
return (find_module(name) != NULL);
module_t *m = find_module(name);
return (m != NULL && !m->obsolete);
}
/*
@ -324,7 +349,8 @@ const char *
prefs_get_title_by_name(char *name)
{
module_t *m = find_module(name);
return (m) ? m->title : NULL;
return (m != NULL && !m->obsolete) ? m->title : NULL;
}
/*

11
prefs.h
View File

@ -1,7 +1,7 @@
/* prefs.h
* Definitions for preference handling routines
*
* $Id: prefs.h,v 1.37 2002/01/13 20:35:08 guy Exp $
* $Id: prefs.h,v 1.38 2002/05/11 18:58:02 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -105,8 +105,17 @@ typedef void (*module_cb)(module_t *module, gpointer user_data);
*/
extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
/*
* Register that a protocol used to have preferences but no longer does,
* by creating an "obsolete" module for it.
*/
extern module_t *prefs_register_protocol_obsolete(int id);
/*
* Call a callback function, with a specified argument, for each module.
* Ignores "obsolete" modules; their sole purpose is to allow old
* preferences for dissectors that no longer have preferences to be
* silently ignored in preference files.
*/
extern void prefs_module_foreach(module_cb callback, gpointer user_data);