From 14881e72d63d25048464155c5e8cc43a51731b16 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 21 Feb 2016 09:40:18 -0500 Subject: [PATCH] tshark: load decode_as_entries file With Wireshark 2.0, some dissector preferences were removed in favor of 'Decode As' functionality. But the settings saved in the GUI are not loaded in tshark, preventing their use without an explicit call to '-d' option. Let's load decode_as_entries file by default and have it overridden by the '-d' option if required. Ping-Bug: 12124 Change-Id: I134a424cb6cf8fc89b7096a659ef1605314a70a2 Reviewed-on: https://code.wireshark.org/review/13956 Petri-Dish: Michael Mann Reviewed-by: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- tshark.c | 4 ++++ ui/decode_as_utils.c | 19 +++++++++---------- ui/decode_as_utils.h | 2 +- ui/gtk/decode_as_dlg.c | 8 +++++++- ui/qt/decode_as_dialog.cpp | 10 +++++++++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/tshark.c b/tshark.c index 08929b13e8..786afe8371 100644 --- a/tshark.c +++ b/tshark.c @@ -85,6 +85,7 @@ #endif #include "ui/util.h" #include "ui/ui_util.h" +#include "ui/decode_as_utils.h" #include "ui/cli/tshark-tap.h" #include "register.h" #include "filter_files.h" @@ -1297,6 +1298,9 @@ main(int argc, char *argv[]) return 0; } + /* load the decode as entries of this profile */ + load_decode_as_entries(); + tshark_debug("tshark reading preferences"); prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path, diff --git a/ui/decode_as_utils.c b/ui/decode_as_utils.c index 0d9788b36f..61a9dc174e 100644 --- a/ui/decode_as_utils.c +++ b/ui/decode_as_utils.c @@ -312,28 +312,26 @@ decode_as_write_entry (const gchar *table_name, ftenum_t selector_type, } } -void -save_decode_as_entries(void) +int +save_decode_as_entries(gchar** err) { char *pf_dir_path; char *daf_path; FILE *da_file; if (create_persconffile_dir(&pf_dir_path) == -1) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path, - g_strerror(errno)); + *err = g_strdup_printf("Can't create directory\n\"%s\"\nfor recent file: %s.", + pf_dir_path, g_strerror(errno)); g_free(pf_dir_path); - return; + return -1; } daf_path = get_persconffile_path(DECODE_AS_ENTRIES_FILE_NAME, TRUE); if ((da_file = ws_fopen(daf_path, "w")) == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Can't open decode_as_entries file\n\"%s\": %s.", daf_path, - g_strerror(errno)); + *err = g_strdup_printf("Can't open decode_as_entries file\n\"%s\": %s.", + daf_path, g_strerror(errno)); g_free(daf_path); - return; + return -1; } fputs("# \"Decode As\" entries file for Wireshark " VERSION ".\n" @@ -344,6 +342,7 @@ save_decode_as_entries(void) dissector_all_tables_foreach_changed(decode_as_write_entry, da_file); fclose(da_file); + return 0; } /* diff --git a/ui/decode_as_utils.h b/ui/decode_as_utils.h index bc00881644..a8beadef9c 100644 --- a/ui/decode_as_utils.h +++ b/ui/decode_as_utils.h @@ -41,7 +41,7 @@ void load_decode_as_entries(void); /** Write out the "decode as" entries of the current profile. */ -void save_decode_as_entries(void); +int save_decode_as_entries(gchar** err); /** This routine creates one entry in the list of protocol dissector * that need to be reset. It is called by the g_hash_table_foreach diff --git a/ui/gtk/decode_as_dlg.c b/ui/gtk/decode_as_dlg.c index 64eb232b14..382b38676a 100644 --- a/ui/gtk/decode_as_dlg.c +++ b/ui/gtk/decode_as_dlg.c @@ -441,7 +441,13 @@ decode_show_destroy_cb (GtkWidget *win _U_, gpointer user_data _U_) static void decode_show_save_cb (GtkWidget *win _U_, gpointer user_data _U_) { - save_decode_as_entries(); + gchar* err = NULL; + + if (save_decode_as_entries(&err) < 0) + { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err); + g_free(err); + } } /* add a single binding to the Show list */ diff --git a/ui/qt/decode_as_dialog.cpp b/ui/qt/decode_as_dialog.cpp index 0ba94aa556..a50f90d71a 100644 --- a/ui/qt/decode_as_dialog.cpp +++ b/ui/qt/decode_as_dialog.cpp @@ -27,6 +27,7 @@ #include "epan/epan_dissect.h" #include "ui/decode_as_utils.h" +#include "ui/simple_dialog.h" #include #include "qt_ui_utils.h" @@ -640,8 +641,15 @@ void DecodeAsDialog::on_buttonBox_clicked(QAbstractButton *button) applyChanges(); break; case QDialogButtonBox::Save: + { + gchar* err = NULL; + applyChanges(); - save_decode_as_entries(); + if (save_decode_as_entries(&err) < 0) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err); + g_free(err); + } + } break; case QDialogButtonBox::Help: wsApp->helpTopicAction(HELP_DECODE_AS_SHOW_DIALOG);