summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-12-10 20:15:36 -0800
committerGuy Harris <guy@alum.mit.edu>2014-12-11 04:16:33 +0000
commit339df3d96de1e5fb7f978a5f0b71d90f28cc8d12 (patch)
treef1a24b44a2768ae84778c0d2e193a62cb9831679 /epan
parent151164d4140b1ab882e3b0778e0aabdbaad06191 (diff)
downloadwireshark-339df3d96de1e5fb7f978a5f0b71d90f28cc8d12.tar.gz
Add a heur_dissector_table_foreach() function.
This is, for heuristic dissector tables, the equivalent of dissector_table_foreach() for keyed dissector tables. Change-Id: I4b2f870e1c1179fda1adddd93930b83aaaaf8763 Reviewed-on: https://code.wireshark.org/review/5715 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rw-r--r--epan/packet.c77
-rw-r--r--epan/packet.h14
2 files changed, 72 insertions, 19 deletions
diff --git a/epan/packet.c b/epan/packet.c
index 6dd5e9c613..7cbf652cb2 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -2046,33 +2046,54 @@ dissector_try_heuristic(heur_dissector_list_t sub_dissectors, tvbuff_t *tvb,
return status;
}
+typedef struct heur_dissector_foreach_info {
+ gpointer caller_data;
+ DATFunc_heur caller_func;
+ GHFunc next_func;
+ const gchar *table_name;
+} heur_dissector_foreach_info_t;
+
/*
- * Called for each entry in the table of all heuristic dissector tables.
+ * Called for each entry in a heuristic dissector table.
*/
-typedef struct heur_dissector_foreach_table_info {
- gpointer caller_data;
- DATFunc_heur_table caller_func;
-} heur_dissector_foreach_table_info_t;
+static void
+heur_dissector_table_foreach_func (gpointer data, gpointer user_data)
+{
+ heur_dissector_foreach_info_t *info;
+ g_assert(data);
+ g_assert(user_data);
-static void
-dissector_dump_heur_decodes_display(const gchar *table_name, heur_dissector_list_t *listptr, const gpointer user_data _U_)
+ info = (heur_dissector_foreach_info_t *)user_data;
+ info->caller_func(info->table_name, (heur_dtbl_entry_t *)data,
+ info->caller_data);
+}
+
+/*
+ * Walk one heuristic dissector table's list calling a user supplied function
+ * on each entry.
+ */
+void
+heur_dissector_table_foreach (const char *table_name,
+ DATFunc_heur func,
+ gpointer user_data)
{
- heur_dissector_list_t sub_dissectors = *listptr;
- GSList *entry;
- heur_dtbl_entry_t *hdtbl_entry;
+ heur_dissector_foreach_info_t info;
+ heur_dissector_list_t *list = find_heur_dissector_list(table_name);
- for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
- hdtbl_entry = (heur_dtbl_entry_t *)entry->data;
- if (hdtbl_entry->protocol != NULL) {
- printf("%s\t%s\t%c\n",
- table_name,
- proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)),
- (proto_is_protocol_enabled(hdtbl_entry->protocol) && hdtbl_entry->enabled) ? 'T' : 'F');
- }
- }
+ info.table_name = table_name;
+ info.caller_func = func;
+ info.caller_data = user_data;
+ g_slist_foreach (*list, heur_dissector_table_foreach_func, &info);
}
+/*
+ * Called for each entry in the table of all heuristic dissector tables.
+ */
+typedef struct heur_dissector_foreach_table_info {
+ gpointer caller_data;
+ DATFunc_heur_table caller_func;
+} heur_dissector_foreach_table_info_t;
/*
* Called for each entry in the table of all heuristic dissector tables.
@@ -2129,6 +2150,24 @@ dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
}
}
+static void
+display_heur_dissector_table_entries(const char *table_name,
+ heur_dtbl_entry_t *hdtbl_entry, gpointer user_data _U_)
+{
+ if (hdtbl_entry->protocol != NULL) {
+ printf("%s\t%s\t%c\n",
+ table_name,
+ proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)),
+ (proto_is_protocol_enabled(hdtbl_entry->protocol) && hdtbl_entry->enabled) ? 'T' : 'F');
+ }
+}
+
+static void
+dissector_dump_heur_decodes_display(const gchar *table_name, heur_dissector_list_t *listptr _U_, const gpointer user_data _U_)
+{
+ heur_dissector_table_foreach(table_name, display_heur_dissector_table_entries, NULL);
+}
+
/*
* For each heuristic dissector table, dump list of dissectors (filter_names) for that table
*/
diff --git a/epan/packet.h b/epan/packet.h
index 2ac0b8b82b..637d359cfa 100644
--- a/epan/packet.h
+++ b/epan/packet.h
@@ -356,9 +356,23 @@ typedef struct {
WS_DLL_PUBLIC void register_heur_dissector_list(const char *name,
heur_dissector_list_t *list);
+typedef void (*DATFunc_heur) (const gchar *table_name,
+ heur_dtbl_entry_t *entry, gpointer user_data);
typedef void (*DATFunc_heur_table) (const gchar *table_name,
heur_dissector_list_t *table, gpointer user_data);
+/** Iterate over heuristic dissectors in a table.
+ *
+ * Walk one heuristic dissector table's list calling a user supplied function
+ * on each entry.
+ *
+ * @param[in] table_name The name of the dissector table, e.g. "tcp".
+ * @param[in] func The function to call for each dissector.
+ * @param[in] user_data User data to pass to the function.
+ */
+WS_DLL_PUBLIC void heur_dissector_table_foreach(const char *table_name,
+ DATFunc_heur func, gpointer user_data);
+
/** Iterate over all heuristic dissector tables.
*
* Walk the set of heuristic dissector tables calling a user supplied function