List heuristic tables in Internals->Disscetor tables menu.

svn path=/trunk/; revision=38881
This commit is contained in:
Anders Broman 2011-09-05 13:04:23 +00:00
parent 8947dcb655
commit 377bfd19a0
4 changed files with 107 additions and 9 deletions

View File

@ -321,6 +321,7 @@ dissect_xdlc_control
dissector_add_handle
dissector_add_string
dissector_add_uint
dissector_all_heur_tables_foreach_table
dissector_all_tables_foreach_changed
dissector_all_tables_foreach_table
dissector_change_string

View File

@ -1532,10 +1532,6 @@ get_dissector_table_base(const char *name)
static GHashTable *heur_dissector_lists = NULL;
typedef struct {
heur_dissector_t dissector;
protocol_t *protocol;
} heur_dtbl_entry_t;
/* Finds a heuristic dissector table by field name. */
static heur_dissector_list_t *
@ -1691,6 +1687,38 @@ dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
return status;
}
/*
* 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;
static void
dissector_all_heur_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
{
heur_dissector_foreach_table_info_t *info;
info = user_data;
(*info->caller_func)((gchar*)key, value, info->caller_data);
}
/*
* Walk all heuristic dissector tables calling a user supplied function on each
* table.
*/
void
dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
gpointer user_data)
{
heur_dissector_foreach_table_info_t info;
info.caller_data = user_data;
info.caller_func = func;
g_hash_table_foreach(heur_dissector_lists, dissector_all_heur_tables_foreach_table_func, &info);
}
void
register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
{

View File

@ -132,6 +132,9 @@ typedef void (*DATFunc_handle) (const gchar *table_name, gpointer value,
typedef void (*DATFunc_table) (const gchar *table_name, const gchar *ui_name,
gpointer user_data);
typedef void (*DATFunc_heur_table) (const gchar *table_name,gpointer table,
gpointer user_data);
/* Opaque structure - provides type checking but no access to components */
typedef struct dtbl_entry dtbl_entry_t;
@ -266,6 +269,12 @@ extern void dissector_add_handle(const char *name, dissector_handle_t handle);
by another dissector. */
typedef GSList *heur_dissector_list_t;
typedef struct {
heur_dissector_t dissector;
protocol_t *protocol;
} heur_dtbl_entry_t;
/** A protocol uses this function to register a heuristic sub-dissector list.
* Call this in the parent dissectors proto_register function.
*
@ -275,6 +284,9 @@ typedef GSList *heur_dissector_list_t;
extern void register_heur_dissector_list(const char *name,
heur_dissector_list_t *list);
extern void dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
gpointer user_data);
/** Try all the dissectors in a given heuristic dissector list. This is done,
* until we find one that recognizes the protocol.
* Call this while the parent dissector running.

View File

@ -101,6 +101,7 @@ ui_sort_func(GtkTreeModel *model,
struct dissector_tables_trees {
GtkWidget *str_tree_wgt;
GtkWidget *uint_tree_wgt;
GtkWidget *heuristic_tree_wgt;
};
typedef struct dissector_tables_trees dissector_tables_trees_t;
@ -118,7 +119,7 @@ proto_add_to_list(dissector_tables_tree_info_t *tree_info,
}
static void
decode_proto_add_to_list (const gchar *table_name _U_, ftenum_t selector_type _U_,
decode_proto_add_to_list (const gchar *table_name _U_, ftenum_t selector_type,
gpointer key, gpointer value _U_, gpointer user_data)
{
GtkTreeStore *store;
@ -179,8 +180,44 @@ table_name_add_to_list(dissector_tables_tree_info_t *tree_info,
}
static void
display_dissector_table_names(const char *table_name, const char *ui_name,
gpointer w)
display_heur_dissector_table_entries(gpointer data, gpointer user_data)
{
heur_dtbl_entry_t *dtbl_entry = data;
dissector_tables_tree_info_t *tree_info = user_data;
GtkTreeStore *store;
if(dtbl_entry->protocol){
store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree_info->tree))); /* Get store */
proto_add_to_list(tree_info, store,
(gchar *)proto_get_protocol_long_name(dtbl_entry->protocol),
proto_get_protocol_short_name(dtbl_entry->protocol));
}else{
g_warning("no protocol info");
}
}
static void
display_heur_dissector_table_names(const char *table_name, heur_dissector_list_t *table, gpointer w)
{
dissector_tables_trees_t *dis_tbl_trees;
dissector_tables_tree_info_t *tree_info;
tree_info = g_new(dissector_tables_tree_info_t, 1);
dis_tbl_trees = w;
table_name_add_to_list(tree_info, dis_tbl_trees->heuristic_tree_wgt, "", table_name);
if(table){
g_slist_foreach (*table, display_heur_dissector_table_entries, tree_info);
}
}
static void
display_dissector_table_names(const char *table_name, const char *ui_name, gpointer w)
{
dissector_tables_trees_t *dis_tbl_trees;
dissector_tables_tree_info_t *tree_info;
@ -317,19 +354,39 @@ dissector_tables_dlg_init(void)
gtk_box_pack_start(GTK_BOX(temp_page), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show(scrolled_window);
/* We must display TOP LEVEL Widget before calling init_table() */
/* heuristic tables */
temp_page = gtk_vbox_new(FALSE, 6);
tmp = gtk_label_new("Heuristic tables");
gtk_widget_show(tmp);
hbox = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(hbox), tmp);
gtk_notebook_append_page(GTK_NOTEBOOK(main_nb), temp_page, hbox);
scrolled_window = scrolled_window_new(NULL, NULL);
dis_tbl_trees.heuristic_tree_wgt = init_table();
gtk_widget_show(dis_tbl_trees.heuristic_tree_wgt);
gtk_container_add(GTK_CONTAINER(scrolled_window), dis_tbl_trees.heuristic_tree_wgt);
gtk_box_pack_start(GTK_BOX(temp_page), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show(scrolled_window);
/* We must display TOP LEVEL Widget before calling init_table() */
gtk_widget_show_all(dissector_tables_dlg_w);
g_signal_connect(dissector_tables_dlg_w, "destroy", G_CALLBACK(win_destroy_cb), NULL);
/* Fill the table with data */
dissector_all_tables_foreach_table(display_dissector_table_names, (gpointer)&dis_tbl_trees);
sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(dis_tbl_trees.str_tree_wgt)));
dissector_all_heur_tables_foreach_table(display_heur_dissector_table_names, (gpointer)&dis_tbl_trees);
sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(dis_tbl_trees.str_tree_wgt)));
gtk_tree_sortable_set_sort_column_id(sortable, TABLE_UI_NAME_COL, GTK_SORT_ASCENDING);
sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(dis_tbl_trees.uint_tree_wgt)));
gtk_tree_sortable_set_sort_column_id(sortable, TABLE_UI_NAME_COL, GTK_SORT_ASCENDING);
sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(dis_tbl_trees.heuristic_tree_wgt)));
gtk_tree_sortable_set_sort_column_id(sortable, TABLE_UI_NAME_COL, GTK_SORT_ASCENDING);
}
void