Give dissector_all_heur_tables_foreach_table() a sort function.

This makes it a bit more like dissector_all_tables_foreach_table.

Improve comments and clean up whitespace while we're at it.

Change-Id: I5147427f864add285e3bb6cb35ad9fa83bea516c
Reviewed-on: https://code.wireshark.org/review/5714
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-12-10 19:04:50 -08:00
parent 9855beff31
commit 151164d414
4 changed files with 52 additions and 11 deletions

View File

@ -1724,6 +1724,7 @@ typedef struct dissector_foreach_table_info {
/*
* Called for each entry in the table of all dissector tables.
* This is used if we directly process the hash table.
*/
static void
dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
@ -1738,6 +1739,7 @@ dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, con
/*
* Called for each key in the table of all dissector tables.
* This is used if we get a list of table names, sort it, and process the list.
*/
static void
dissector_all_tables_foreach_list_func (gpointer key, gpointer user_data)
@ -1756,8 +1758,8 @@ dissector_all_tables_foreach_list_func (gpointer key, gpointer user_data)
*/
void
dissector_all_tables_foreach_table (DATFunc_table func,
gpointer user_data,
GCompareFunc compare_key_func)
gpointer user_data,
GCompareFunc compare_key_func)
{
dissector_foreach_table_info_t info;
GList *list;
@ -2072,6 +2074,10 @@ dissector_dump_heur_decodes_display(const gchar *table_name, heur_dissector_list
}
/*
* Called for each entry in the table of all heuristic dissector tables.
* This is used if we directly process the hash table.
*/
static void
dissector_all_heur_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
{
@ -2081,19 +2087,46 @@ dissector_all_heur_tables_foreach_table_func (gpointer key, const gpointer value
(*info->caller_func)((gchar*)key, (heur_dissector_list_t *)value, info->caller_data);
}
/*
* Called for each key in the table of all dissector tables.
* This is used if we get a list of table names, sort it, and process the list.
*/
static void
dissector_all_heur_tables_foreach_list_func (gpointer key, gpointer user_data)
{
heur_dissector_list_t *list;
heur_dissector_foreach_table_info_t *info;
list = (heur_dissector_list_t *)g_hash_table_lookup(heur_dissector_lists, key);
info = (heur_dissector_foreach_table_info_t *)user_data;
(*info->caller_func)((gchar*)key, list, 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)
gpointer user_data,
GCompareFunc compare_key_func)
{
heur_dissector_foreach_table_info_t info;
GList *list;
info.caller_data = user_data;
info.caller_func = func;
g_hash_table_foreach(heur_dissector_lists, dissector_all_heur_tables_foreach_table_func, &info);
if (compare_key_func != NULL)
{
list = g_hash_table_get_keys(dissector_tables);
list = g_list_sort(list, compare_key_func);
g_list_foreach(list, dissector_all_heur_tables_foreach_list_func, &info);
g_list_free(list);
}
else
{
g_hash_table_foreach(heur_dissector_lists, dissector_all_heur_tables_foreach_table_func, &info);
}
}
/*
@ -2102,7 +2135,7 @@ dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
void
dissector_dump_heur_decodes(void)
{
dissector_all_heur_tables_foreach_table(dissector_dump_heur_decodes_display, NULL);
dissector_all_heur_tables_foreach_table(dissector_dump_heur_decodes_display, NULL, NULL);
}

View File

@ -183,12 +183,12 @@ WS_DLL_PUBLIC void dissector_table_foreach_handle(const char *table_name, DATFun
/** Iterate over all dissector tables.
*
* Walk all dissector tables calling a user supplied function on each
* Walk the set of dissector tables calling a user supplied function on each
* table.
* @param[in] func The function to call for each table.
* @param[in] user_data User data to pass to the function.
* @param[in] compare_key_func Function used to sort tables before calling
* the function. No sorting is done if NULL. */
* @param[in] compare_key_func Function used to sort the set of tables before
* calling the function. No sorting is done if NULL. */
WS_DLL_PUBLIC void dissector_all_tables_foreach_table (DATFunc_table func,
gpointer user_data, GCompareFunc compare_key_func);
@ -359,8 +359,16 @@ WS_DLL_PUBLIC void register_heur_dissector_list(const char *name,
typedef void (*DATFunc_heur_table) (const gchar *table_name,
heur_dissector_list_t *table, gpointer user_data);
/** Iterate over all heuristic dissector tables.
*
* Walk the set of heuristic dissector tables calling a user supplied function
* on each table.
* @param[in] func The function to call for each table.
* @param[in] user_data User data to pass to the function.
* @param[in] compare_key_func Function used to sort the set of tables before
* calling the function. No sorting is done if NULL. */
WS_DLL_PUBLIC void dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
gpointer user_data);
gpointer user_data, GCompareFunc compare_key_func);
/* true if a heur_dissector list of that anme exists to be registered into */
WS_DLL_PUBLIC gboolean has_heur_dissector_list(const gchar *name);

View File

@ -2262,7 +2262,7 @@ WSLUA_CONSTRUCTOR DissectorTable_heuristic_list (lua_State *L) {
lua_newtable(L);
dissector_all_heur_tables_foreach_table(heur_dissector_tables_list_func, (gpointer)&data);
dissector_all_heur_tables_foreach_table(heur_dissector_tables_list_func, (gpointer)&data, NULL);
WSLUA_RETURN(1); /* The array table of registered heuristic list names */
}

View File

@ -373,7 +373,7 @@ dissector_tables_dlg_init(void)
/* Fill the table with data */
dissector_all_tables_foreach_table(display_dissector_table_names, (gpointer)&dis_tbl_trees, NULL);
dissector_all_heur_tables_foreach_table(display_heur_dissector_table_names, (gpointer)&dis_tbl_trees);
dissector_all_heur_tables_foreach_table(display_heur_dissector_table_names, (gpointer)&dis_tbl_trees, NULL);
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);