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 <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2017-04-08 18:59:17 -07:00
parent 92ebd63892
commit 23a7890b6a
12 changed files with 84 additions and 158 deletions

View File

@ -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

View File

@ -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);

View File

@ -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
}

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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;
}