Snort: speed up parsing of options by avoiding g_snprintf()
[metze/wireshark/wip.git] / epan / stat_tap_ui.h
index cba5d46dc32c8e2ef24cb9b6d62af5ad2e9ae034..39220df30a84aea5dfacaaf0aa4952af7ebc387d 100644 (file)
@@ -37,12 +37,13 @@ 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? */
     PARAM_STRING, /* Unused? */
     PARAM_ENUM,   /* SCSI SRT */
-    PARAM_UUID,   /* Unused? */
+    PARAM_UUID,   /* DCE-RPC. Unused? */
     PARAM_FILTER
 } param_type;
 
@@ -84,9 +85,20 @@ typedef struct _stat_tap_table_item_type
         guint uint_value;
         gint  int_value;
         const char* string_value;
-        gfloat float_value;
+        double float_value;
         gint enum_value;
     } value;
+    /* Scratch space for the dissector. Alternatively we could also add support
+     * for hidden columns. */
+    union
+    {
+        guint uint_value;
+        gint  int_value;
+        const char* string_value;
+        double float_value;
+        gint enum_value;
+        void* ptr_value;
+    } user_data;
 } stat_tap_table_item_type;
 
 /* Possible alignments */
@@ -114,37 +126,38 @@ typedef struct _stat_tap_table
     guint num_elements;
     stat_tap_table_item_type **elements;
 
-} new_stat_tap_table;
+} stat_tap_table;
 
-typedef void (*new_stat_tap_gui_init_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
-typedef void (*new_stat_tap_gui_reset_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
-typedef void (*new_stat_tap_gui_free_cb)(new_stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
+typedef void (*new_stat_tap_gui_init_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
+typedef void (*new_stat_tap_gui_reset_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
+typedef void (*new_stat_tap_gui_free_cb)(stat_tap_table* stat_table, void* gui_data); /* GTK+ only? */
 
 /*
- * UI information for a tap.
+ * UI information for a tap with a table-based UI.
  */
-typedef struct _new_stat_tap_ui {
+typedef struct _stat_tap_table_ui {
     register_stat_group_t  group;      /* group to which statistic belongs */
     const char            *title;      /* title of statistic */
     const char            *tap_name;
     const char            *cli_string; /* initial part of the "-z" argument for statistic */
-    void (* stat_tap_init_cb)(struct _new_stat_tap_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data);
+    void (* stat_tap_init_cb)(struct _stat_tap_table_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data);
     tap_packet_cb packet_func;
-    void (* stat_tap_reset_table_cb)(new_stat_tap_table* table);
-    void (* stat_tap_free_table_item_cb)(new_stat_tap_table* table, guint row, guint column, stat_tap_table_item_type* field_data);
-    void (* new_stat_filter_check_cb)(const char *opt_arg, const char **filter, char** err); /* Dissector chance to reject filter */
+    void (* stat_tap_reset_table_cb)(stat_tap_table* table);
+    void (* stat_tap_free_table_item_cb)(stat_tap_table* table, guint row, guint column, stat_tap_table_item_type* field_data);
+    void (* stat_filter_check_cb)(const char *opt_arg, const char **filter, char** err); /* Dissector chance to reject filter */
     size_t                 nfields;    /* number of fields */
     stat_tap_table_item*   fields;
     size_t                 nparams;    /* number of parameters */
     tap_param             *params;     /* pointer to table of parameter info */
-    GArray                *tables;     /* An array of new_stat_tap_table* */
-} new_stat_tap_ui;
+    GArray                *tables;     /* An array of stat_tap_table* */
+    guint                  refcount;   /* a reference count for deallocation */
+} stat_tap_table_ui;
 
 
 /** tap data
  */
 typedef struct _new_stat_data_t {
-    new_stat_tap_ui *new_stat_tap_data;
+    stat_tap_table_ui *stat_tap_data;
     void        *user_data;       /**< "GUI" specifics (if necessary) */
 } new_stat_data_t;
 
@@ -156,18 +169,32 @@ 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_new_stat_tap_ui(new_stat_tap_ui *ui);
-WS_DLL_PUBLIC void new_stat_tap_iterate_tables(GFunc func, gpointer user_data);
-WS_DLL_PUBLIC void new_stat_tap_get_filter(new_stat_tap_ui* new_stat, const char *opt_arg, const char **filter, char** err);
-WS_DLL_PUBLIC new_stat_tap_table* new_stat_tap_init_table(const char *name, int num_fields, int num_elements,
+WS_DLL_PUBLIC void register_stat_tap_table_ui(stat_tap_table_ui *ui);
+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);
-WS_DLL_PUBLIC void new_stat_tap_add_table(new_stat_tap_ui* new_stat, new_stat_tap_table* table);
+WS_DLL_PUBLIC void new_stat_tap_add_table(stat_tap_table_ui* new_stat, stat_tap_table* table);
+
+WS_DLL_PUBLIC void new_stat_tap_init_table_row(stat_tap_table *stat_table, guint table_index, guint num_fields, const stat_tap_table_item_type* fields);
+WS_DLL_PUBLIC stat_tap_table_item_type* new_stat_tap_get_field_data(const stat_tap_table *stat_table, guint table_index, guint field_index);
+WS_DLL_PUBLIC void new_stat_tap_set_field_data(stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data);
+WS_DLL_PUBLIC void reset_stat_table(stat_tap_table_ui* new_stat, new_stat_tap_gui_reset_cb gui_callback, void *callback_data);
+
+WS_DLL_PUBLIC stat_tap_table_ui *new_stat_tap_by_name(const char *name);
 
-WS_DLL_PUBLIC void new_stat_tap_init_table_row(new_stat_tap_table *stat_table, guint table_index, guint num_fields, const stat_tap_table_item_type* fields);
-WS_DLL_PUBLIC stat_tap_table_item_type* new_stat_tap_get_field_data(const new_stat_tap_table *stat_table, guint table_index, guint field_index);
-WS_DLL_PUBLIC void new_stat_tap_set_field_data(new_stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data);
-WS_DLL_PUBLIC void reset_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_reset_cb gui_callback, void *callback_data);
-WS_DLL_PUBLIC void free_stat_table(new_stat_tap_ui* new_stat, new_stat_tap_gui_free_cb gui_callback, void *callback_data);
+/** Free all of the tables associated with a stat_tap_table_ui.
+ *
+ * Frees data created by stat_tap_ui.stat_tap_init_cb.
+ * stat_tap_table_ui.stat_tap_free_table_item_cb is called for each index in each
+ * row.
+ *
+ * @param new_stat Parent stat_tap_table_ui struct, provided by the dissector.
+ * @param gui_callback Per-table callback, run before rows are removed.
+ * Provided by the UI.
+ * @param callback_data Data for the per-table callback.
+ */
+WS_DLL_PUBLIC void free_stat_tables(stat_tap_table_ui* new_stat, new_stat_tap_gui_free_cb gui_callback, void *callback_data);
 
 
 WS_DLL_PUBLIC gboolean process_stat_cmd_arg(char *optstr);