aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-09-28 20:23:39 -0700
committerGuy Harris <guy@alum.mit.edu>2018-09-29 03:24:15 +0000
commita699fbdf45481113470cbc56f89e03cdae730f44 (patch)
treec4dc26b9d04f5eef0c5d8a6d4fd10f055d53fb79
parentcc3d23fc6989bffc7aee1f83c9989d5646c95795 (diff)
Add a mechanism to register aliases for preference modules.
That way, we don't need a chunk of code in epan/prefs.c that knows about various preference module mappings; individual dissectors can register aliases as appropriate. (The Nortel Discovery Protocol never *had* any preferences, even when it was the SynOptics Network Management Protocol, so there's no need for it to register an alias.) Change-Id: I4a718dac6bb06801cc06a6ee5a28d7ed81e67e5d Reviewed-on: https://code.wireshark.org/review/29914 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--epan/dissectors/asn1/p1/packet-p1-template.c2
-rw-r--r--epan/dissectors/packet-beep.c2
-rw-r--r--epan/dissectors/packet-dccp.c2
-rw-r--r--epan/dissectors/packet-diameter.c2
-rw-r--r--epan/dissectors/packet-gsm_sms_ud.c2
-rw-r--r--epan/dissectors/packet-gtp.c3
-rw-r--r--epan/dissectors/packet-nsip.c2
-rw-r--r--epan/dissectors/packet-x25.c2
-rw-r--r--epan/prefs.c124
-rw-r--r--epan/prefs.h5
10 files changed, 119 insertions, 27 deletions
diff --git a/epan/dissectors/asn1/p1/packet-p1-template.c b/epan/dissectors/asn1/p1/packet-p1-template.c
index 36b51c59d2..bd6bd06fc1 100644
--- a/epan/dissectors/asn1/p1/packet-p1-template.c
+++ b/epan/dissectors/asn1/p1/packet-p1-template.c
@@ -366,6 +366,8 @@ void proto_register_p1(void) {
/* Register our configuration options for P1, particularly our port */
p1_module = prefs_register_protocol_subtree("OSI/X.400", proto_p1, NULL);
+ /* For reading older preference files with "x411." preferences */
+ prefs_register_module_alias("x411", p1_module);
prefs_register_obsolete_preference(p1_module, "tcp.port");
diff --git a/epan/dissectors/packet-beep.c b/epan/dissectors/packet-beep.c
index ec8ac2a18c..890ca0c126 100644
--- a/epan/dissectors/packet-beep.c
+++ b/epan/dissectors/packet-beep.c
@@ -971,6 +971,8 @@ proto_register_beep(void)
/* Register our configuration options for BEEP, particularly our port */
beep_module = prefs_register_protocol(proto_beep, apply_beep_prefs);
+ /* For reading older preference files with "bxxp." preferences */
+ prefs_register_module_alias("bxxp", beep_module);
prefs_register_bool_preference(beep_module, "strict_header_terminator",
"BEEP Header Requires CRLF",
diff --git a/epan/dissectors/packet-dccp.c b/epan/dissectors/packet-dccp.c
index 601a208e3c..8611bdd28a 100644
--- a/epan/dissectors/packet-dccp.c
+++ b/epan/dissectors/packet-dccp.c
@@ -1283,6 +1283,8 @@ proto_register_dccp(void)
/* reg preferences */
dccp_module = prefs_register_protocol(proto_dccp, NULL);
+ /* For reading older preference files with "dcp." preferences */
+ prefs_register_module_alias("dcp", dccp_module);
prefs_register_bool_preference(
dccp_module, "summary_in_tree",
"Show DCCP summary in protocol tree",
diff --git a/epan/dissectors/packet-diameter.c b/epan/dissectors/packet-diameter.c
index 136e401bb0..f2d9467254 100644
--- a/epan/dissectors/packet-diameter.c
+++ b/epan/dissectors/packet-diameter.c
@@ -2332,6 +2332,8 @@ proto_register_diameter(void)
/* Register configuration options for ports */
diameter_module = prefs_register_protocol(proto_diameter, proto_reg_handoff_diameter);
+ /* For reading older preference files with "Diameter." preferences */
+ prefs_register_module_alias("Diameter", diameter_module);
prefs_register_range_preference(diameter_module, "sctp.ports",
"Diameter SCTP Ports",
diff --git a/epan/dissectors/packet-gsm_sms_ud.c b/epan/dissectors/packet-gsm_sms_ud.c
index 56c8981029..0b24a2023f 100644
--- a/epan/dissectors/packet-gsm_sms_ud.c
+++ b/epan/dissectors/packet-gsm_sms_ud.c
@@ -686,6 +686,8 @@ proto_register_gsm_sms_ud(void)
/* Preferences for GSM SMS UD */
gsm_sms_ud_module = prefs_register_protocol(proto_gsm_sms_ud, NULL);
+ /* For reading older preference files with "smpp-gsm-sms." preferences */
+ prefs_register_module_alias("smpp-gsm-sms", gsm_sms_ud_module);
prefs_register_bool_preference(gsm_sms_ud_module,
"port_number_udh_means_wsp",
"Port Number IE in UDH always triggers CL-WSP dissection",
diff --git a/epan/dissectors/packet-gtp.c b/epan/dissectors/packet-gtp.c
index c3b1b8a2b2..2acb60fcaa 100644
--- a/epan/dissectors/packet-gtp.c
+++ b/epan/dissectors/packet-gtp.c
@@ -10990,6 +10990,9 @@ proto_register_gtp(void)
expert_register_field_array(expert_gtp, ei, array_length(ei));
gtp_module = prefs_register_protocol(proto_gtp, proto_reg_handoff_gtp);
+ /* For reading older preference files with "gtpv0." or "gtpv1." preferences */
+ prefs_register_module_alias("gtpv0", gtp_module);
+ prefs_register_module_alias("gtpv1", gtp_module);
prefs_register_uint_preference(gtp_module, "v0_port", "GTPv0 and GTP' port", "GTPv0 and GTP' port (default 3386)", 10, &g_gtpv0_port);
prefs_register_uint_preference(gtp_module, "v1c_port", "GTPv1 or GTPv2 control plane (GTP-C, GTPv2-C) port", "GTPv1 and GTPv2 control plane port (default 2123)", 10,
diff --git a/epan/dissectors/packet-nsip.c b/epan/dissectors/packet-nsip.c
index 7a20f7408e..d6adef63d8 100644
--- a/epan/dissectors/packet-nsip.c
+++ b/epan/dissectors/packet-nsip.c
@@ -1138,6 +1138,8 @@ proto_register_nsip(void)
/* Register configuration options */
nsip_module = prefs_register_protocol(proto_nsip, NULL);
+ /* For reading older preference files with "nsip." preferences */
+ prefs_register_module_alias("nsip", nsip_module);
prefs_register_obsolete_preference(nsip_module, "udp.port1");
prefs_register_obsolete_preference(nsip_module, "udp.port2");
}
diff --git a/epan/dissectors/packet-x25.c b/epan/dissectors/packet-x25.c
index ae67efb9af..c09a4158aa 100644
--- a/epan/dissectors/packet-x25.c
+++ b/epan/dissectors/packet-x25.c
@@ -2351,6 +2351,8 @@ proto_register_x25(void)
/* Preferences */
x25_module = prefs_register_protocol(proto_x25, NULL);
+ /* For reading older preference files with "x.25." preferences */
+ prefs_register_module_alias("x.25", x25_module);
prefs_register_obsolete_preference(x25_module, "non_q_bit_is_sna");
prefs_register_bool_preference(x25_module, "payload_is_qllc_sna",
"Default to QLLC/SNA",
diff --git a/epan/prefs.c b/epan/prefs.c
index 0b8a383c79..34c05d3075 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -42,12 +42,21 @@
#include "epan/wmem/wmem.h"
#include <epan/stats_tree.h>
+/*
+ * Module alias.
+ */
+typedef struct pref_module_alias {
+ const char *name; /**< name of module alias */
+ module_t *module; /**< module for which it's an alias */
+} module_alias_t;
+
/* Internal functions */
static module_t *find_subtree(module_t *parent, const char *tilte);
static module_t *prefs_register_module_or_subtree(module_t *parent,
const char *name, const char *title, const char *description, gboolean is_subtree,
void (*apply_cb)(void), gboolean use_gui);
static void prefs_register_modules(void);
+static module_t *prefs_find_module_alias(const char *name);
static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
static void free_col_info(GList *);
static void pre_init_prefs(void);
@@ -271,6 +280,11 @@ static wmem_tree_t *prefs_modules = NULL;
*/
static wmem_tree_t *prefs_top_level_modules = NULL;
+/*
+ * List of aliases for modules.
+ */
+static wmem_tree_t *prefs_module_aliases = NULL;
+
/** Sets up memory used by proto routines. Called at program startup */
void
prefs_init(void)
@@ -278,6 +292,7 @@ prefs_init(void)
memset(&prefs, 0, sizeof(prefs));
prefs_modules = wmem_tree_new(wmem_epan_scope());
prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
+ prefs_module_aliases = wmem_tree_new(wmem_epan_scope());
}
/*
@@ -541,6 +556,50 @@ prefs_register_module_or_subtree(module_t *parent, const char *name,
return module;
}
+void
+prefs_register_module_alias(const char *name, module_t *module)
+{
+ module_alias_t *alias;
+ const char *p;
+ guchar c;
+
+ /*
+ * Yes.
+ * Make sure that only ASCII letters, numbers, underscores, hyphens,
+ * and dots appear in the name. We allow upper-case letters, to
+ * handle the Diameter dissector having used "Diameter" rather
+ * than "diameter" as its preference module name in the past.
+ *
+ * Crash if there is, as that's an error in the code, but the name
+ * can be used on the command line, and shouldn't require quoting,
+ * etc.
+ */
+ for (p = name; (c = *p) != '\0'; p++) {
+ if (!(g_ascii_isalpha(c) || g_ascii_isdigit(c) || c == '_' ||
+ c == '-' || c == '.'))
+ g_error("Preference module alias \"%s\" contains invalid characters", name);
+ }
+
+ /*
+ * Make sure there's not already an alias with that
+ * name. Crash if there is, as that's an error in the
+ * code, and the code has to be fixed not to register
+ * more than one alias with the same name.
+ *
+ * We search the list of all aliases.
+ */
+ g_assert(prefs_find_module_alias(name) == NULL);
+
+ alias = wmem_new(wmem_epan_scope(), module_alias_t);
+ alias->name = name;
+ alias->module = module;
+
+ /*
+ * Insert this module in the list of all modules.
+ */
+ wmem_tree_insert_string(prefs_module_aliases, name, alias, WMEM_TREE_STRING_NOCASE);
+}
+
/*
* Register that a protocol has preferences.
*/
@@ -891,6 +950,17 @@ prefs_apply(module_t *module)
call_apply_cb(NULL, module, NULL);
}
+static module_t *
+prefs_find_module_alias(const char *name)
+{
+ module_alias_t *alias;
+
+ alias = (module_alias_t *)wmem_tree_lookup_string(prefs_module_aliases, name, WMEM_TREE_STRING_NOCASE);
+ if (alias == NULL)
+ return NULL;
+ return alias->module;
+}
+
/*
* Register a preference in a module's list of preferences.
* If it has a title, give it an ordinal number; otherwise, it's a
@@ -2999,6 +3069,8 @@ prefs_register_modules(void)
prefs_register_obsolete_preference(gui_module, "hex_dump_highlight_style");
gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
+ /* For reading older preference files with "column." preferences */
+ prefs_register_module_alias("column", gui_column_module);
custom_cbs.free_cb = free_string_like_preference;
custom_cbs.reset_cb = reset_string_like_preference;
@@ -5402,38 +5474,36 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
* its modern name, the Nortel Discovery Protocol (NDP).
*/
if (module == NULL) {
- if (strcmp(pref_name, "column") == 0)
- module = gui_column_module;
- else if (strcmp(pref_name, "Diameter") == 0)
- module = prefs_find_module("diameter");
- else if (strcmp(pref_name, "bxxp") == 0)
- module = prefs_find_module("beep");
- else if (strcmp(pref_name, "gtpv0") == 0 ||
- strcmp(pref_name, "gtpv1") == 0)
- module = prefs_find_module("gtp");
- else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
- module = prefs_find_module("gsm-sms-ud");
- else if (strcmp(pref_name, "dcp") == 0)
- module = prefs_find_module("dccp");
- else if (strcmp(pref_name, "x.25") == 0)
- module = prefs_find_module("x25");
- else if (strcmp(pref_name, "x411") == 0)
- module = prefs_find_module("p1");
- else if (strcmp(pref_name, "nsip") == 0)
- module = prefs_find_module("gprs-ns");
- else if (strcmp(pref_name, "sonmp") == 0)
- module = prefs_find_module("ndp");
- else if (strcmp(pref_name, "etheric") == 0 ||
- strcmp(pref_name, "isup_thin") == 0) {
- /* This protocol was removed 7. July 2009 */
- return PREFS_SET_OBSOLETE;
- } else {
- /* See if the module name matches any protocol aliases. */
+ /*
+ * See if there's a backwards-compatibility name
+ * that maps to this module.
+ */
+ module = prefs_find_module_alias(pref_name);
+ if (module == NULL) {
+ /*
+ * There's no alias for the module; see if the
+ * module name matches any protocol aliases.
+ */
header_field_info *hfinfo = proto_registrar_get_byalias(pref_name);
if (hfinfo) {
module = (module_t *) wmem_tree_lookup_string(prefs_modules, hfinfo->abbrev, WMEM_TREE_STRING_NOCASE);
}
}
+ if (module == NULL) {
+ /*
+ * There aren't any aliases. Was the module
+ * removed rather than renamed?
+ */
+ if (strcmp(pref_name, "etheric") == 0 ||
+ strcmp(pref_name, "isup_thin") == 0) {
+ /*
+ * The dissectors for these protocols were
+ * removed as obsolete on 2009-07-70 in change
+ * 739bfc6ff035583abb9434e0e988048de38a8d9a.
+ */
+ return PREFS_SET_OBSOLETE;
+ }
+ }
if (module) {
g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s\"\n"
"Save your preferences to make this change permanent.",
diff --git a/epan/prefs.h b/epan/prefs.h
index bf560f90e8..3e38d6d7dd 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -258,6 +258,11 @@ WS_DLL_PUBLIC void prefs_set_gui_theme_is_dark(gboolean is_dark);
*/
WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
+/*
+ * Register an alias for a preference module.
+ */
+WS_DLL_PUBLIC void prefs_register_module_alias(const char *name, module_t *module);
+
/**
* Deregister preferences from a protocol.
*/