prefs: Make all auto port preferences ranges

When a single port is added to a dissector along with an auto
preference, make it create a range preference (defaulting to
that single value.) This converts the rest of the auto port
preferences to ranges.

Ping #14319. Still to do are converting other non-auto port
preferences to auto preferences (e.g., sctp ports), and maybe
some minor cleanups.
This commit is contained in:
John Thacker 2022-08-03 22:53:58 -04:00 committed by A Wireshark GitLab Utility
parent 7238dad792
commit 8604d03a98
1 changed files with 11 additions and 35 deletions

View File

@ -1215,41 +1215,6 @@ void dissector_add_uint_range(const char *name, range_t *range,
}
}
static void
dissector_add_preference(const char *name, dissector_handle_t handle, guint init_value)
{
guint* uint_var;
module_t *module;
gchar *description, *title;
dissector_table_t pref_dissector_table = find_dissector_table(name);
int proto_id = proto_get_id(handle->protocol);
uint_var = wmem_new(wmem_epan_scope(), guint);
*uint_var = init_value;
/* If the dissector already has a preference module, use it */
module = prefs_find_module(proto_get_protocol_filter_name(proto_id));
if (module == NULL)
{
/* Otherwise create a new one */
module = prefs_register_protocol(proto_id, NULL);
}
description = wmem_strdup_printf(wmem_epan_scope(), "Set the %s for %s (if other than the default of %u)",
pref_dissector_table->ui_name, proto_get_protocol_short_name(handle->protocol), *uint_var);
title = wmem_strdup_printf(wmem_epan_scope(), "%s %s", proto_get_protocol_short_name(handle->protocol),
pref_dissector_table->ui_name);
prefs_register_decode_as_preference(module, name, title, description, uint_var);
}
void dissector_add_uint_with_preference(const char *name, const guint32 pattern,
dissector_handle_t handle)
{
dissector_add_preference(name, handle, pattern);
dissector_add_uint(name, pattern, handle);
}
static range_t*
dissector_add_range_preference(const char *name, dissector_handle_t handle, const char* range_str)
{
@ -1313,6 +1278,17 @@ dissector_add_range_preference(const char *name, dissector_handle_t handle, cons
return *range;
}
void dissector_add_uint_with_preference(const char *name, const guint32 pattern,
dissector_handle_t handle)
{
char* range_str;
range_str = wmem_strdup_printf(NULL, "%d", pattern);
dissector_add_range_preference(name, handle, range_str);
wmem_free(NULL, range_str);
dissector_add_uint(name, pattern, handle);
}
void dissector_add_uint_range_with_preference(const char *name, const char* range_str,
dissector_handle_t handle)
{