Switch stat tap to use wmem_tree_t instead of (sorted) GSList.

Change-Id: I172167eb20793113562b69d1e0e93a4882200404
Reviewed-on: https://code.wireshark.org/review/20019
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2017-02-07 23:07:27 -05:00
parent c5483f4213
commit 70381f774c
9 changed files with 64 additions and 76 deletions

View File

@ -223,7 +223,6 @@ epan_cleanup(void)
expert_cleanup();
capture_dissector_cleanup();
export_pdu_cleanup();
stat_tap_table_cleanup();
disabled_protos_cleanup();
stats_tree_cleanup();
#ifdef HAVE_LUA

View File

@ -40,7 +40,7 @@ typedef struct _stat_cmd_arg {
void* userdata;
} stat_cmd_arg;
static GList *stat_cmd_arg_list=NULL;
static wmem_tree_t *stat_cmd_arg_list=NULL;
/* structure to keep track of what stats have been specified on the
command line.
@ -55,60 +55,63 @@ static GSList *stats_requested = NULL;
* Function called from stat to register the stat's command-line argument
* and initialization routine
* ********************************************************************** */
static gint
sort_by_name(gconstpointer a, gconstpointer b)
{
return strcmp(((const stat_cmd_arg *)a)->cmd, ((const stat_cmd_arg *)b)->cmd);
}
void
register_stat_tap_ui(stat_tap_ui *ui, void *userdata)
{
stat_cmd_arg *newsca;
newsca=(stat_cmd_arg *)g_malloc(sizeof(stat_cmd_arg));
newsca = wmem_new(wmem_epan_scope(), stat_cmd_arg);
newsca->cmd=ui->cli_string;
newsca->func=ui->tap_init_cb;
newsca->userdata=userdata;
stat_cmd_arg_list=g_list_insert_sorted(stat_cmd_arg_list, newsca, sort_by_name);
if (stat_cmd_arg_list == NULL)
stat_cmd_arg_list = wmem_tree_new(wmem_epan_scope());
wmem_tree_insert_string(stat_cmd_arg_list, newsca->cmd, newsca, 0);
}
/* **********************************************************************
* Function called for a stat command-line argument
* ********************************************************************** */
static gboolean
process_stat_cmd_arg_func(const void *key, void *value, void *userdata)
{
char *optstr = (char*)userdata;
stat_cmd_arg *sca = (stat_cmd_arg*)value;
stat_requested *tr;
if (!strncmp((const char*)key, (const char*)optstr, strlen((const char*)key)))
{
tr=(stat_requested *)g_malloc(sizeof (stat_requested));
tr->sca = sca;
tr->arg=g_strdup(optstr);
stats_requested=g_slist_append(stats_requested, tr);
return TRUE;
}
return FALSE;
}
gboolean
process_stat_cmd_arg(char *optstr)
{
GList *entry;
stat_cmd_arg *sca;
stat_requested *tr;
for(entry=g_list_last(stat_cmd_arg_list);entry;entry=g_list_previous(entry)){
sca=(stat_cmd_arg *)entry->data;
if(!strncmp(sca->cmd,optstr,strlen(sca->cmd))){
tr=(stat_requested *)g_malloc(sizeof (stat_requested));
tr->sca = sca;
tr->arg=g_strdup(optstr);
stats_requested=g_slist_append(stats_requested, tr);
return TRUE;
}
}
return FALSE;
return wmem_tree_foreach(stat_cmd_arg_list, process_stat_cmd_arg_func, optstr);
}
/* **********************************************************************
* Function to list all possible tap command-line arguments
* ********************************************************************** */
static gboolean
list_stat_cmd_args_func(const void *key, void *value _U_, void *userdata _U_)
{
fprintf(stderr," %s\n", (const char*)key);
return FALSE;
}
void
list_stat_cmd_args(void)
{
GList *entry;
stat_cmd_arg *sca;
for(entry=stat_cmd_arg_list;entry;entry=g_list_next(entry)){
sca=(stat_cmd_arg *)entry->data;
fprintf(stderr," %s\n",sca->cmd);
}
wmem_tree_foreach(stat_cmd_arg_list, list_stat_cmd_args_func, NULL);
}
/* **********************************************************************
@ -128,25 +131,19 @@ start_requested_stats(void)
}
}
static GSList *registered_stat_tables = NULL;
static gint
insert_sorted_by_cli_string(gconstpointer aparam, gconstpointer bparam)
{
const stat_tap_table_ui *a = (const stat_tap_table_ui *)aparam;
const stat_tap_table_ui *b = (const stat_tap_table_ui *)bparam;
return g_ascii_strcasecmp(a->cli_string, b->cli_string);
}
static wmem_tree_t *registered_stat_tables = NULL;
void register_stat_tap_table_ui(stat_tap_table_ui *ui)
{
registered_stat_tables = g_slist_insert_sorted(registered_stat_tables, ui, insert_sorted_by_cli_string);
if (registered_stat_tables == NULL)
registered_stat_tables = wmem_tree_new(wmem_epan_scope());
wmem_tree_insert_string(registered_stat_tables, ui->cli_string, ui, 0);
}
void new_stat_tap_iterate_tables(GFunc func, gpointer user_data)
void new_stat_tap_iterate_tables(wmem_foreach_func func, gpointer user_data)
{
g_slist_foreach(registered_stat_tables, func, user_data);
wmem_tree_foreach(registered_stat_tables, func, user_data);
}
void new_stat_tap_get_filter(stat_tap_table_ui* new_stat, const char *opt_arg, const char **filter, char** err)
@ -283,18 +280,6 @@ void free_stat_tables(stat_tap_table_ui* new_stat, new_stat_tap_gui_free_cb gui_
g_array_set_size(new_stat->tables, 0);
}
static void
stat_cmd_arg_list_free(gpointer p, gpointer user_data _U_)
{
g_free(p);
}
void stat_tap_table_cleanup(void)
{
g_slist_free(registered_stat_tables);
g_list_foreach(stat_cmd_arg_list, stat_cmd_arg_list_free, NULL);
g_list_free(stat_cmd_arg_list);
}
/*
* Editor modelines

View File

@ -37,6 +37,7 @@ extern "C" {
#include <epan/stat_groups.h>
#include <epan/packet_info.h>
#include <epan/tap.h>
#include <epan/wmem/wmem.h>
typedef enum {
PARAM_UINT, /* Unused? */
@ -169,7 +170,7 @@ typedef struct _new_stat_data_t {
WS_DLL_PUBLIC void register_stat_tap_ui(stat_tap_ui *ui, void *userdata);
WS_DLL_PUBLIC void register_stat_tap_table_ui(stat_tap_table_ui *ui);
WS_DLL_PUBLIC void new_stat_tap_iterate_tables(GFunc func, gpointer user_data);
WS_DLL_PUBLIC void new_stat_tap_iterate_tables(wmem_foreach_func func, gpointer user_data);
WS_DLL_PUBLIC void new_stat_tap_get_filter(stat_tap_table_ui* new_stat, const char *opt_arg, const char **filter, char** err);
WS_DLL_PUBLIC stat_tap_table* new_stat_tap_init_table(const char *name, int num_fields, int num_elements,
const char *filter_string, new_stat_tap_gui_init_cb gui_callback, void* gui_data);
@ -200,8 +201,6 @@ WS_DLL_PUBLIC void list_stat_cmd_args(void);
WS_DLL_PUBLIC void start_requested_stats(void);
extern void stat_tap_table_cleanup(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -140,20 +140,21 @@ simple_stat_init(const char *opt_arg, void* userdata)
init_stat_table(new_stat_tap, filter);
}
void
register_simple_stat_tables(gpointer data, gpointer user_data _U_)
gboolean
register_simple_stat_tables(const void *key, void *value, void *userdata _U_)
{
stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui*)data;
stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui*)value;
stat_tap_ui ui_info;
ui_info.group = new_stat_tap->group;
ui_info.title = new_stat_tap->title; /* construct this from the protocol info? */
ui_info.cli_string = new_stat_tap->cli_string;
ui_info.cli_string = (const char*)key;
ui_info.tap_init_cb = simple_stat_init;
ui_info.nparams = new_stat_tap->nparams;
ui_info.params = new_stat_tap->params;
register_stat_tap_ui(&ui_info, new_stat_tap);
return FALSE;
}
/*

View File

@ -28,6 +28,6 @@ extern void init_iousers(struct register_ct* ct, const char *filter);
extern void init_hostlists(struct register_ct* ct, const char *filter);
extern gboolean register_srt_tables(const void *key, void *value, void *userdata);
extern gboolean register_rtd_tables(const void *key, void *value, void *userdata);
extern void register_simple_stat_tables(gpointer data, gpointer user_data);
extern gboolean register_simple_stat_tables(const void *key, void *value, void *userdata);
#endif /* __TSHARK_TAP_H__ */

View File

@ -266,15 +266,15 @@ gtk_simple_stat_init(const char *opt_arg, void *userdata)
init_simple_stat_tables(new_stat_tap, filter);
}
void register_simple_stat_tables(gpointer data, gpointer user_data _U_)
gboolean register_simple_stat_tables(const void *key, void *value, void *userdata _U_)
{
stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui*)data;
stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui*)value;
tap_param_dlg* stat_dlg;
stat_dlg = g_new(tap_param_dlg, 1);
stat_dlg->win_title = new_stat_tap->title;
stat_dlg->init_string = new_stat_tap->cli_string;
stat_dlg->init_string = (const char*)key;
stat_dlg->tap_init_cb = gtk_simple_stat_init;
stat_dlg->index = -1;
@ -284,6 +284,7 @@ void register_simple_stat_tables(gpointer data, gpointer user_data _U_)
stat_dlg->user_data = new_stat_tap;
register_param_stat(stat_dlg, new_stat_tap->title, new_stat_tap->group);
return FALSE;
}
/*

View File

@ -29,9 +29,10 @@
/** Register function to register dissectors that support a "simple" statistics table.
*
* @param data stat_tap_table_ui* representing dissetor stat table
* @param user_data is unused
* @param key is tap string
* @param value stat_tap_table_ui* representing dissetor stat table
* @param userdata is unused
*/
void register_simple_stat_tables(gpointer data, gpointer user_data);
gboolean register_simple_stat_tables(const void *key, void *value, void *userdata);
#endif /* __SIMPLE_STAT_TABLE_H__ */

View File

@ -49,16 +49,17 @@ simple_stat_init(const char *args, void*) {
}
}
void register_simple_stat_tables(gpointer data, gpointer) {
stat_tap_table_ui *stu = (stat_tap_table_ui*)data;
gboolean register_simple_stat_tables(const void *key, void *value, void*) {
stat_tap_table_ui *stu = (stat_tap_table_ui*)value;
cfg_str_to_stu_[stu->cli_string] = stu;
TapParameterDialog::registerDialog(
stu->title,
stu->cli_string,
(const char*)key,
stu->group,
simple_stat_init,
SimpleStatisticsDialog::createSimpleStatisticsDialog);
return FALSE;
}
enum {

View File

@ -58,9 +58,10 @@ private slots:
/** Register function to register dissectors that support a "simple" statistics table.
*
* @param data stat_tap_table_ui* representing dissetor stat table
* @param key is tap string
* @param value stat_tap_table_ui* representing dissetor stat table
*/
void register_simple_stat_tables(gpointer data, gpointer);
gboolean register_simple_stat_tables(const void *key, void *value, void*);
#endif // __SIMPLE_STATISTICS_DIALOG_H__