diff options
author | David Perry <boolean263@protonmail.com> | 2023-06-13 17:12:26 +0000 |
---|---|---|
committer | AndersBroman <a.broman58@gmail.com> | 2023-06-13 17:12:26 +0000 |
commit | 80ae370811595f294c65cb71e1d213d5b49e33fd (patch) | |
tree | 8c2eadf1003a83a02a9da5f04ee6f49d2865e4c9 /epan | |
parent | 801554fb799869690a24cd61b540f1e5f8d2fccb (diff) |
Allow disabling unused dissectors from PHS dialog
Diffstat (limited to 'epan')
-rw-r--r-- | epan/disabled_protos.c | 82 | ||||
-rw-r--r-- | epan/disabled_protos.h | 37 | ||||
-rw-r--r-- | epan/proto.c | 26 | ||||
-rw-r--r-- | epan/proto.h | 3 |
4 files changed, 122 insertions, 26 deletions
diff --git a/epan/disabled_protos.c b/epan/disabled_protos.c index 4cf4772b97..fa0bec43f7 100644 --- a/epan/disabled_protos.c +++ b/epan/disabled_protos.c @@ -62,8 +62,16 @@ static GList *enabled_protos = NULL; static GList *global_disabled_heuristics = NULL; static GList *disabled_heuristics = NULL; +static gboolean unsaved_changes = FALSE; + #define INIT_BUF_SIZE 128 +gboolean +enabled_protos_unsaved_changes(void) +{ + return unsaved_changes; +} + static void discard_existing_list (GList **flp) { @@ -468,21 +476,31 @@ read_protos_list(char **gpath_return, int *gopen_errno_return, /* * Disable a particular protocol by name */ -void +gboolean proto_disable_proto_by_name(const char *name) { - 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(protocol) == TRUE) { - if (proto_can_toggle_protocol(proto_id) == TRUE) { - proto_set_decoding(proto_id, FALSE); - } - } + 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(protocol) == TRUE) { + if (proto_can_toggle_protocol(proto_id) == TRUE) { + unsaved_changes = TRUE; + proto_set_decoding(proto_id, FALSE); + } } + return TRUE; + } + else if (!strcmp(name, "ALL")) { + unsaved_changes = TRUE; + proto_disable_all(); + return TRUE; + } + else { + return FALSE; + } } static gboolean disable_proto_list_check(protocol_t *protocol) @@ -497,7 +515,7 @@ static gboolean disable_proto_list_check(protocol_t *protocol) * Enabling dissectors (that are disabled by default) ************************************************************************/ -WS_DLL_PUBLIC void +gboolean proto_enable_proto_by_name(const char *name) { protocol_t *protocol; @@ -506,12 +524,21 @@ proto_enable_proto_by_name(const char *name) 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_is_protocol_enabled(protocol) == FALSE)) { if (proto_can_toggle_protocol(proto_id) == TRUE) { + unsaved_changes = TRUE; proto_set_decoding(proto_id, TRUE); } } + return TRUE; + } + else if (!strcmp(name, "ALL")) { + unsaved_changes = TRUE; + proto_reenable_all(); + return TRUE; + } + else { + return FALSE; } } @@ -868,11 +895,12 @@ save_disabled_heur_dissector_list(char **pref_path_return, int *errno_return) g_free(ff_path); } -gboolean -proto_enable_heuristic_by_name(const char *name, gboolean enable) +static gboolean +proto_set_heuristic_by_name(const char *name, gboolean enable) { heur_dtbl_entry_t* heur = find_heur_dissector_by_unique_short_name(name); if (heur != NULL) { + unsaved_changes |= (heur->enabled != enable); heur->enabled = enable; return TRUE; } else { @@ -880,6 +908,18 @@ proto_enable_heuristic_by_name(const char *name, gboolean enable) } } +gboolean +proto_enable_heuristic_by_name(const char *name) +{ + return proto_set_heuristic_by_name(name, TRUE); +} + +gboolean +proto_disable_heuristic_by_name(const char *name) +{ + return proto_set_heuristic_by_name(name, FALSE); +} + static void disabled_protos_free(gpointer p, gpointer user_data _U_) { @@ -1000,6 +1040,7 @@ read_enabled_and_disabled_lists(void) set_protos_list(disabled_protos, global_disabled_protos, FALSE); set_protos_list(enabled_protos, global_enabled_protos, TRUE); set_disabled_heur_dissector_list(); + unsaved_changes = FALSE; } /* @@ -1012,6 +1053,7 @@ save_enabled_and_disabled_lists(void) char *pf_dir_path; char *pf_path; int pf_save_errno; + gboolean ok = TRUE; /* Create the directory that holds personal configuration files, if necessary. */ @@ -1028,6 +1070,7 @@ save_enabled_and_disabled_lists(void) report_failure("Could not save to your disabled protocols file\n\"%s\": %s.", pf_path, g_strerror(pf_save_errno)); g_free(pf_path); + ok = FALSE; } save_protos_list(&pf_path, &pf_save_errno, ENABLED_PROTOCOLS_FILE_NAME, @@ -1037,6 +1080,7 @@ save_enabled_and_disabled_lists(void) report_failure("Could not save to your enabled protocols file\n\"%s\": %s.", pf_path, g_strerror(pf_save_errno)); g_free(pf_path); + ok = FALSE; } save_disabled_heur_dissector_list(&pf_path, &pf_save_errno); @@ -1044,7 +1088,11 @@ save_enabled_and_disabled_lists(void) 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); + ok = FALSE; } + + if (ok) + unsaved_changes = FALSE; } void diff --git a/epan/disabled_protos.h b/epan/disabled_protos.h index bea57367bd..56d1c0ad06 100644 --- a/epan/disabled_protos.h +++ b/epan/disabled_protos.h @@ -16,26 +16,47 @@ extern "C" { #endif /* __cplusplus */ +#include <glib.h> +#include <ws_symbol_export.h> + +/* + * Tell if protocols have been enabled/disabled since + * we've last loaded (or saved) the lists. + */ +WS_DLL_PUBLIC gboolean +enabled_protos_unsaved_changes(void); + /* * Disable a particular protocol by name + * On success (found the protocol), return TRUE. + * On failure (didn't find the protocol), return FALSE. */ -WS_DLL_PUBLIC void +WS_DLL_PUBLIC gboolean proto_disable_proto_by_name(const char *name); /* - * Enable a particular protocol by name. This will only enable - * protocols that are disabled by default. All others will be ignored. + * Enable a particular protocol by name + * On success (found the protocol), return TRUE. + * On failure (didn't find the protocol), return FALSE. */ -WS_DLL_PUBLIC void +WS_DLL_PUBLIC gboolean proto_enable_proto_by_name(const char *name); /* - * Enable/disable a particular heuristic dissector by name + * Enable a particular heuristic dissector by name + * On success (found the protocol), return TRUE. + * On failure (didn't find the protocol), return FALSE. + */ +WS_DLL_PUBLIC gboolean +proto_enable_heuristic_by_name(const char *name); + +/* + * Disable a particular heuristic dissector by name * On success (found the protocol), return TRUE. * On failure (didn't find the protocol), return FALSE. */ WS_DLL_PUBLIC gboolean -proto_enable_heuristic_by_name(const char *name, gboolean enable); +proto_disable_heuristic_by_name(const char *name); /* * Read the files that enable and disable protocols and heuristic @@ -43,8 +64,10 @@ proto_enable_heuristic_by_name(const char *name, gboolean enable); * * This is called by epan_load_settings(); programs should call that * rather than individually calling the routines it calls. + * This is only public (instead of extern) to allow users who temporarily + * disable protocols in the PHS GUI to re-enable them. */ -extern void +WS_DLL_PUBLIC void read_enabled_and_disabled_lists(void); /* diff --git a/epan/proto.c b/epan/proto.c index 132bafb7cf..ddd70c4272 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -8030,6 +8030,28 @@ proto_set_decoding(const int proto_id, const gboolean enabled) } void +proto_disable_all(void) +{ + /* This doesn't explicitly disable heuristic protocols, + * but the heuristic doesn't get called if the parent + * protocol isn't enabled. + */ + protocol_t *protocol; + GList *list_item = protocols; + + if (protocols == NULL) + return; + + while (list_item) { + protocol = (protocol_t *)list_item->data; + if (protocol->can_toggle) { + protocol->is_enabled = FALSE; + } + list_item = g_list_next(list_item); + } +} + +void proto_reenable_all(void) { protocol_t *protocol; @@ -8040,8 +8062,8 @@ proto_reenable_all(void) while (list_item) { protocol = (protocol_t *)list_item->data; - if (protocol->can_toggle && protocol->enabled_by_default) - protocol->is_enabled = TRUE; + if (protocol->can_toggle) + protocol->is_enabled = protocol->enabled_by_default; list_item = g_list_next(list_item); } } diff --git a/epan/proto.h b/epan/proto.h index 99d7df0e00..193cbd8f19 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -2705,6 +2705,9 @@ WS_DLL_PUBLIC void proto_disable_by_default(const int proto_id); @param enabled enable / disable the protocol */ WS_DLL_PUBLIC void proto_set_decoding(const int proto_id, const gboolean enabled); +/** Disable all protocols. */ +WS_DLL_PUBLIC void proto_disable_all(void); + /** Re-enable all protocols that are not marked as disabled by default. */ WS_DLL_PUBLIC void proto_reenable_all(void); |