diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-08-04 16:37:48 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-08-04 23:38:13 +0000 |
commit | bbda3dd7c1998b98202af8b24de415412298db86 (patch) | |
tree | 59082faf756fcca12f040a94664edb8e9f865c4b /ui/decode_as_utils.c | |
parent | ce7b041305330e2cb87d895f57381241702c9d85 (diff) |
Write out decode_as entries from the actual dissector tables.
Have a save_decode_as_entries() routine in ui/decode_as_utils.c, that
does all the work of saving the entries by iterating through all the
changed entries with dissector_all_tables_foreach_changed().
When doing so, write out the selector for integral values in decimal, as
older versions of Wireshark only handled decimal values, and some of
those older versions are EOLed and won't be fixed.
Change-Id: I2dab461604524b98e3515867839a4b86c86c5d7b
Reviewed-on: https://code.wireshark.org/review/3426
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/decode_as_utils.c')
-rw-r--r-- | ui/decode_as_utils.c | 82 |
1 files changed, 66 insertions, 16 deletions
diff --git a/ui/decode_as_utils.c b/ui/decode_as_utils.c index cb3cdd3e0c..5a29b3a4ee 100644 --- a/ui/decode_as_utils.c +++ b/ui/decode_as_utils.c @@ -41,6 +41,8 @@ #include "version_info.h" +/* XXX - We might want to switch this to a UAT */ + /* * A list of dissectors that need to be reset. */ @@ -253,9 +255,66 @@ decode_clear_all(void) decode_dcerpc_reset_all(); } -/* XXX - We might want to switch this to a UAT */ -FILE * -decode_as_open(void) { +static void +decode_as_write_entry (const gchar *table_name, ftenum_t selector_type, + gpointer key, gpointer value, gpointer user_data) +{ + FILE *da_file = (FILE *)user_data; + dissector_handle_t current, initial; + const gchar *current_proto_name, *initial_proto_name; + + current = dtbl_entry_get_handle((dtbl_entry_t *)value); + if (current == NULL) + current_proto_name = DECODE_AS_NONE; + else + current_proto_name = dissector_handle_get_short_name(current); + initial = dtbl_entry_get_initial_handle((dtbl_entry_t *)value); + if (initial == NULL) + initial_proto_name = DECODE_AS_NONE; + else + initial_proto_name = dissector_handle_get_short_name(initial); + + switch (selector_type) { + + case FT_UINT8: + case FT_UINT16: + case FT_UINT24: + case FT_UINT32: + /* + * XXX - write these in decimal, regardless of the base of + * the dissector table's selector, as older versions of + * Wireshark used atoi() when reading this file, and + * failed to handle hex or octal numbers. + * + * That will be fixed in future 1.10 and 1.12 releases, + * but pre-1.10 releases are at end-of-life and won't + * be fixed. + */ + fprintf (da_file, + DECODE_AS_ENTRY ": %s,%u,%s,%s\n", + table_name, GPOINTER_TO_UINT(key), initial_proto_name, + current_proto_name); + break; + + case FT_STRING: + case FT_STRINGZ: + case FT_UINT_STRING: + case FT_STRINGZPAD: + fprintf (da_file, + DECODE_AS_ENTRY ": %s,%s,%s,%s\n", + table_name, (gchar *)key, initial_proto_name, + current_proto_name); + break; + + default: + g_assert_not_reached(); + break; + } +} + +void +save_decode_as_entries(void) +{ char *pf_dir_path; char *daf_path; FILE *da_file; @@ -265,7 +324,7 @@ decode_as_open(void) { "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); - return NULL; + return; } daf_path = get_persconffile_path(DECODE_AS_ENTRIES_FILE_NAME, TRUE); @@ -274,7 +333,7 @@ decode_as_open(void) { "Can't open decode_as_entries file\n\"%s\": %s.", daf_path, g_strerror(errno)); g_free(daf_path); - return NULL; + return; } fputs("# \"Decode As\" entries file for Wireshark " VERSION ".\n" @@ -283,18 +342,10 @@ decode_as_open(void) { "# are saved within Wireshark. Making manual changes should be safe,\n" "# however.\n", da_file); - return da_file; -} - -/* XXX We might want to have separate int and string routines. */ -void -decode_as_write_entry(FILE *da_file, const char *table_name, const char *selector, const char *default_proto, const char *current_proto) { - fprintf (da_file, - DECODE_AS_ENTRY ": %s,%s,%s,%s\n", - table_name, selector, default_proto, current_proto); + dissector_all_tables_foreach_changed(decode_as_write_entry, da_file); + fclose(da_file); } - /* * Editor modelines * @@ -307,4 +358,3 @@ decode_as_write_entry(FILE *da_file, const char *table_name, const char *selecto * ex: set shiftwidth=4 tabstop=8 expandtab: * :indentSize=4:tabSize=8:noTabs=true: */ - |