From 23a7890b6a2133a559fc691c865e617c19b26a7a Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 8 Apr 2017 18:59:17 -0700 Subject: [PATCH] Pull the code to save enabled/disabled lists into libwireshark. It's identical in the GTK+ and Qt UIs, and it should just be done in libwireshark. Rename some routines to just speak of enabled_and_disabled_lists, so we don't have to say enabled_and_disabled_protos_and_heuristic_dissectors or something such as that. Clean up indentation. Change-Id: Ief2e612d9e1b60d8d0123b6bd3409dce5faf6495 Reviewed-on: https://code.wireshark.org/review/20970 Reviewed-by: Guy Harris --- debian/libwireshark0.symbols | 6 +- epan/disabled_protos.c | 97 +++++++++++++++++++----------- epan/disabled_protos.h | 46 +++----------- epan/epan.c | 2 +- rawshark.c | 2 +- sharkd.c | 2 +- tfshark.c | 2 +- tshark.c | 2 +- ui/gtk/main.c | 2 +- ui/gtk/proto_dlg.c | 38 +----------- ui/qt/enabled_protocols_dialog.cpp | 41 +------------ ui/qt/wireshark_application.cpp | 2 +- 12 files changed, 84 insertions(+), 158 deletions(-) diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 4ab1026d78..6b0b943eed 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -1235,7 +1235,7 @@ libwireshark.so.0 libwireshark0 #MINVER# range_add_value@Base 2.3.0 range_remove_value@Base 2.3.0 ranges_are_equal@Base 1.9.1 - read_enabled_and_disabled_protos@Base 2.3.0 + read_enabled_and_disabled_lists@Base 2.3.0 read_enabled_protos_list@Base 2.3.0 read_keytab_file@Base 1.9.1 read_keytab_file_from_preferences@Base 1.9.1 @@ -1331,9 +1331,7 @@ libwireshark.so.0 libwireshark0 #MINVER# s1ap_CauseTransport_vals@Base 1.9.1 s1ap_Cause_vals@Base 2.3.0 save_decode_as_entries@Base 2.3.0 - save_disabled_heur_dissector_list@Base 1.99.8 - save_disabled_protos_list@Base 1.12.0~rc1 - save_enabled_protos_list@Base 2.3.0 + save_enabled_and_disabled_lists@Base 2.3.0 sccp_address_signal_values@Base 1.9.1 sccp_error_cause_values@Base 1.9.1 sccp_message_type_acro_values@Base 1.9.1 diff --git a/epan/disabled_protos.c b/epan/disabled_protos.c index b6e57cbd9f..5b171e8662 100644 --- a/epan/disabled_protos.c +++ b/epan/disabled_protos.c @@ -504,13 +504,6 @@ static gboolean disable_proto_list_check(protocol_t *protocol) return FALSE; } -void -save_disabled_protos_list(char **pref_path_return, int *errno_return) -{ - save_protos_list(pref_path_return, errno_return, DISABLED_PROTOCOLS_FILE_NAME, - NULL, disable_proto_list_check); -} - /************************************************************************ * Enabling dissectors (that are disabled by default) ************************************************************************/ @@ -518,39 +511,30 @@ save_disabled_protos_list(char **pref_path_return, int *errno_return) WS_DLL_PUBLIC void proto_enable_proto_by_name(const char *name) { - protocol_t *protocol; - int proto_id; + protocol_t *protocol; + int proto_id; - proto_id = proto_get_id_by_filter_name(name); - if (proto_id >= 0 ) { - protocol = find_protocol_by_id(proto_id); - if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) && - (proto_is_protocol_enabled(protocol) == FALSE)) { - if (proto_can_toggle_protocol(proto_id) == TRUE) { - proto_set_decoding(proto_id, TRUE); - } - } + proto_id = proto_get_id_by_filter_name(name); + if (proto_id >= 0 ) { + protocol = find_protocol_by_id(proto_id); + if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) && + (proto_is_protocol_enabled(protocol) == FALSE)) { + if (proto_can_toggle_protocol(proto_id) == TRUE) { + proto_set_decoding(proto_id, TRUE); + } } + } } static gboolean enable_proto_list_check(protocol_t *protocol) { - if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) && - (proto_is_protocol_enabled(protocol) == TRUE)) - return TRUE; + if ((proto_is_protocol_enabled_by_default(protocol) == FALSE) && + (proto_is_protocol_enabled(protocol) == TRUE)) + return TRUE; - return FALSE; + return FALSE; } -void -save_enabled_protos_list(char **pref_path_return, int *errno_return) -{ - save_protos_list(pref_path_return, errno_return, ENABLED_PROTOCOLS_FILE_NAME, - "#This file is for enabling protocols that are disabled by default", - enable_proto_list_check); -} - - /************************************************************************ * Heuristic dissectors ************************************************************************/ @@ -822,7 +806,7 @@ sort_heur_dissector_tables(const char *table_name, struct heur_dissector_list *l } } -WS_DLL_PUBLIC void +static void save_disabled_heur_dissector_list(char **pref_path_return, int *errno_return) { gchar *ff_path, *ff_path_new; @@ -920,7 +904,7 @@ disabled_protos_free(gpointer p, gpointer user_data _U_) * dissectors. Report errors through the UI. */ void -read_enabled_and_disabled_protos(void) +read_enabled_and_disabled_lists(void) { char *gpath, *path; int gopen_errno, gread_errno; @@ -1029,8 +1013,53 @@ read_enabled_and_disabled_protos(void) set_disabled_heur_dissector_list(); } +/* + * Write out the lists of enabled and disabled protocols and heuristic + * dissectors to the corresponding files. Report errors through the UI. + */ void -enabled_and_disabled_protos_cleanup(void) +save_enabled_and_disabled_lists(void) +{ + char *pf_dir_path; + char *pf_path; + int pf_save_errno; + + /* Create the directory that holds personal configuration files, if + necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + report_failure("Can't create directory\n\"%s\"\nfor disabled protocols file: %s.", + pf_dir_path, g_strerror(errno)); + g_free(pf_dir_path); + return; + } + + save_protos_list(&pf_path, &pf_save_errno, DISABLED_PROTOCOLS_FILE_NAME, + NULL, disable_proto_list_check); + if (pf_path != NULL) { + report_failure("Could not save to your disabled protocols file\n\"%s\": %s.", + pf_path, g_strerror(pf_save_errno)); + g_free(pf_path); + } + + save_protos_list(&pf_path, &pf_save_errno, ENABLED_PROTOCOLS_FILE_NAME, + "#This file is for enabling protocols that are disabled by default", + enable_proto_list_check); + if (pf_path != NULL) { + report_failure("Could not save to your enabled protocols file\n\"%s\": %s.", + pf_path, g_strerror(pf_save_errno)); + g_free(pf_path); + } + + save_disabled_heur_dissector_list(&pf_path, &pf_save_errno); + if (pf_path != NULL) { + report_failure("Could not save to your disabled heuristic protocol file\n\"%s\": %s.", + pf_path, g_strerror(pf_save_errno)); + g_free(pf_path); + } +} + +void +enabled_and_disabled_lists_cleanup(void) { g_list_foreach(global_disabled_heuristics, disabled_protos_free, NULL); g_list_free(global_disabled_heuristics); diff --git a/epan/disabled_protos.h b/epan/disabled_protos.h index f1f436464f..03da425729 100644 --- a/epan/disabled_protos.h +++ b/epan/disabled_protos.h @@ -28,36 +28,12 @@ extern "C" { #endif /* __cplusplus */ -/* - * Write out a list of disabled protocols. - * - * On success, "*pref_path_return" is set to NULL. - * On error, "*pref_path_return" is set to point to the pathname of - * the file we tried to read - it should be freed by our caller - - * and "*errno_return" is set to the error. - */ -WS_DLL_PUBLIC void -save_disabled_protos_list(char **pref_path_return, int *errno_return); - /* * Disable a particular protocol by name */ - WS_DLL_PUBLIC void proto_disable_proto_by_name(const char *name); -/* - * Write out a list of enabled protocols (that default to being disabled) - * - * On success, "*pref_path_return" is set to NULL. - * On error, "*pref_path_return" is set to point to the pathname of - * the file we tried to read - it should be freed by our caller - - * and "*errno_return" is set to the error. - */ -WS_DLL_PUBLIC void -save_enabled_protos_list(char **pref_path_return, int *errno_return); - - /* * Enable a particular protocol by name. This will only enable * protocols that are disabled by default. All others will be ignored. @@ -65,17 +41,6 @@ save_enabled_protos_list(char **pref_path_return, int *errno_return); WS_DLL_PUBLIC void proto_enable_proto_by_name(const char *name); -/* - * Write out a list of disabled heuristic dissectors. - * - * On success, "*pref_path_return" is set to NULL. - * On error, "*pref_path_return" is set to point to the pathname of - * the file we tried to read - it should be freed by our caller - - * and "*errno_return" is set to the error. - */ -WS_DLL_PUBLIC void -save_disabled_heur_dissector_list(char **pref_path_return, int *errno_return); - /* * Enable/disable a particular heuristic dissector by name * On success (found the protocol), return TRUE. @@ -89,13 +54,20 @@ proto_enable_heuristic_by_name(const char *name, gboolean enable); * dissectors. Report errors through the UI. */ WS_DLL_PUBLIC void -read_enabled_and_disabled_protos(void); +read_enabled_and_disabled_lists(void); + +/* + * Write out the lists of enabled and disabled protocols and heuristic + * dissectors to the corresponding files. Report errors through the UI. + */ +WS_DLL_PUBLIC void +save_enabled_and_disabled_lists(void); /* * Free the internal structures */ extern void -enabled_and_disabled_protos_cleanup(void); +cleanup_enabled_and_disabled_lists(void); #ifdef __cplusplus } diff --git a/epan/epan.c b/epan/epan.c index 936c27d55c..e0503801d1 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -223,7 +223,7 @@ epan_cleanup(void) expert_cleanup(); capture_dissector_cleanup(); export_pdu_cleanup(); - enabled_and_disabled_protos_cleanup(); + cleanup_enabled_and_disabled_lists(); stats_tree_cleanup(); dtd_location(NULL); #ifdef HAVE_LUA diff --git a/rawshark.c b/rawshark.c index 25fa0fa244..248edfd228 100644 --- a/rawshark.c +++ b/rawshark.c @@ -573,7 +573,7 @@ main(int argc, char *argv[]) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); #ifdef _WIN32 ws_init_dll_search_path(); diff --git a/sharkd.c b/sharkd.c index a9a451b78c..64669455d8 100644 --- a/sharkd.c +++ b/sharkd.c @@ -250,7 +250,7 @@ main(int argc, char *argv[]) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); cap_file_init(&cfile); diff --git a/tfshark.c b/tfshark.c index 294a08e0a8..0993b6181e 100644 --- a/tfshark.c +++ b/tfshark.c @@ -630,7 +630,7 @@ main(int argc, char *argv[]) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); cap_file_init(&cfile); diff --git a/tshark.c b/tshark.c index eb7de0f8b6..348b68f0ad 100644 --- a/tshark.c +++ b/tshark.c @@ -1047,7 +1047,7 @@ main(int argc, char *argv[]) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); cap_file_init(&cfile); diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 50b3c4c42d..bfc3aac287 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -1975,7 +1975,7 @@ read_configuration_files(void) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); return prefs_p; } diff --git a/ui/gtk/proto_dlg.c b/ui/gtk/proto_dlg.c index a9fedc305f..012e128be8 100644 --- a/ui/gtk/proto_dlg.c +++ b/ui/gtk/proto_dlg.c @@ -274,42 +274,8 @@ update_was_enabled(void) static void proto_write(gpointer parent_w _U_) { - char *pf_dir_path; - char *pf_path; - int pf_save_errno; - - /* Create the directory that holds personal configuration files, if - necessary. */ - if (create_persconffile_dir(&pf_dir_path) == -1) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Can't create directory\n\"%s\"\nfor disabled protocols file: %s.", pf_dir_path, - g_strerror(errno)); - g_free(pf_dir_path); - } else { - save_disabled_protos_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your disabled protocols file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - - save_enabled_protos_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your enabled protocols file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - - save_disabled_heur_dissector_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your disabled heuristic protocol file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - } + /* Save the current state of the enabled/disabled lists. */ + save_enabled_and_disabled_lists(); } static void diff --git a/ui/qt/enabled_protocols_dialog.cpp b/ui/qt/enabled_protocols_dialog.cpp index f6f891374c..1f1703f051 100644 --- a/ui/qt/enabled_protocols_dialog.cpp +++ b/ui/qt/enabled_protocols_dialog.cpp @@ -261,46 +261,7 @@ bool EnabledProtocolsDialog::applyChanges() void EnabledProtocolsDialog::writeChanges() { - char *pf_dir_path; - char *pf_path; - int pf_save_errno; - - /* Create the directory that holds personal configuration files, if necessary. */ - if (create_persconffile_dir(&pf_dir_path) == -1) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Can't create directory\n\"%s\"\nfor disabled protocols file: %s.", pf_dir_path, - g_strerror(errno)); - g_free(pf_dir_path); - } - else - { - save_disabled_protos_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) - { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your disabled protocols file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - - save_enabled_protos_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) - { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your enabled protocols file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - - save_disabled_heur_dissector_list(&pf_path, &pf_save_errno); - if (pf_path != NULL) - { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - "Could not save to your disabled heuristic protocol file\n\"%s\": %s.", - pf_path, g_strerror(pf_save_errno)); - g_free(pf_path); - } - } + save_enabled_and_disabled_lists(); } void EnabledProtocolsDialog::on_search_line_edit__textChanged(const QString &search_re) diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index a2637adf9b..f1ef200574 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -1175,7 +1175,7 @@ _e_prefs *WiresharkApplication::readConfigurationFiles(bool reset) * Read the files that enable and disable protocols and heuristic * dissectors. */ - read_enabled_and_disabled_protos(); + read_enabled_and_disabled_lists(); return prefs_p; }