aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-04-08 18:59:17 -0700
committerGuy Harris <guy@alum.mit.edu>2017-04-09 02:00:37 +0000
commit23a7890b6a2133a559fc691c865e617c19b26a7a (patch)
tree86c981542f9270215e1010720e4ad2280cb814d8 /epan
parent92ebd6389203448168a2769fa473bbbad95ec159 (diff)
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>
Diffstat (limited to 'epan')
-rw-r--r--epan/disabled_protos.c97
-rw-r--r--epan/disabled_protos.h46
-rw-r--r--epan/epan.c2
3 files changed, 73 insertions, 72 deletions
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
+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_protos_cleanup(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
@@ -29,36 +29,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.
*/
@@ -66,17 +42,6 @@ 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.
* On failure (didn't find the protocol), return FALSE.
@@ -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