1 /* stat_tap_ui.h 2 * Declarations of routines to register UI information for stats 3 * 4 * Wireshark - Network traffic analyzer 5 * By Gerald Combs <gerald@wireshark.org> 6 * Copyright 1998 Gerald Combs 7 * 8 * SPDX-License-Identifier: GPL-2.0-or-later 9 */ 10 11 #ifndef __STAT_TAP_UI_H__ 12 #define __STAT_TAP_UI_H__ 13 14 #include "ws_symbol_export.h" 15 16 #include <epan/params.h> 17 #include <epan/stat_groups.h> 18 #include <epan/packet_info.h> 19 #include <epan/tap.h> 20 #include <epan/wmem_scopes.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif /* __cplusplus */ 25 26 /* 27 * Parameters for taps. 28 */ 29 30 typedef enum { 31 PARAM_UINT, /* Unused? */ 32 PARAM_STRING, /* Unused? */ 33 PARAM_ENUM, /* SCSI SRT */ 34 PARAM_UUID, /* DCE-RPC. Unused? */ 35 PARAM_FILTER 36 } param_type; 37 38 typedef struct _tap_param { 39 param_type type; /* type of parameter */ 40 const char *name; /* name to use in error messages */ 41 const char *title; /* title to use in GUI widgets */ 42 const enum_val_t *enum_vals; /* values for PARAM_ENUM */ 43 gboolean optional; /* TRUE if the parameter is optional */ 44 } tap_param; 45 46 /* 47 * UI information for a tap. 48 */ 49 typedef void (* stat_tap_init_cb)(const char *, void*); 50 typedef struct _stat_tap_ui { 51 register_stat_group_t group; /* group to which statistic belongs */ 52 const char *title; /* title of statistic */ 53 const char *cli_string; /* initial part of the "-z" argument for statistic */ 54 stat_tap_init_cb tap_init_cb; /* callback to init function of the tap */ 55 size_t nparams; /* number of parameters */ 56 tap_param *params; /* pointer to table of parameter info */ 57 } stat_tap_ui; 58 59 typedef enum { 60 TABLE_ITEM_NONE = 0, 61 TABLE_ITEM_UINT, 62 TABLE_ITEM_INT, 63 TABLE_ITEM_STRING, 64 TABLE_ITEM_FLOAT, 65 TABLE_ITEM_ENUM 66 } stat_tap_table_item_enum; 67 68 typedef struct _stat_tap_table_item_type 69 { 70 stat_tap_table_item_enum type; 71 union 72 { 73 guint uint_value; 74 gint int_value; 75 const char* string_value; 76 double float_value; 77 gint enum_value; 78 } value; 79 /* Scratch space for the dissector. Alternatively we could also add support 80 * for hidden columns. */ 81 union 82 { 83 guint uint_value; 84 gint int_value; 85 const char* string_value; 86 double float_value; 87 gint enum_value; 88 void* ptr_value; 89 } user_data; 90 } stat_tap_table_item_type; 91 92 /* Possible alignments */ 93 typedef enum { 94 TAP_ALIGN_LEFT = 0, 95 TAP_ALIGN_RIGHT 96 } tap_alignment_type; 97 98 typedef struct _stat_tap_table_item 99 { 100 stat_tap_table_item_enum type; 101 tap_alignment_type align; 102 const char* column_name; 103 const char* field_format; /* printf style formating of field. Currently unused? */ 104 105 } stat_tap_table_item; 106 107 108 /* Description of a UI table */ 109 typedef struct _stat_tap_table 110 { 111 const char* title; 112 const char *filter_string; /**< append procedure number (%d) to this string to create a display filter */ 113 guint num_fields; 114 guint num_elements; 115 stat_tap_table_item_type **elements; 116 117 } stat_tap_table; 118 119 /* 120 * UI information for a tap with a table-based UI. 121 */ 122 typedef struct _stat_tap_table_ui { 123 register_stat_group_t group; /* group to which statistic belongs */ 124 const char *title; /* title of statistic */ 125 const char *tap_name; 126 const char *cli_string; /* initial part of the "-z" argument for statistic */ 127 void (* stat_tap_init_cb)(struct _stat_tap_table_ui* new_stat); 128 tap_packet_cb packet_func; 129 void (* stat_tap_reset_table_cb)(stat_tap_table* table); 130 void (* stat_tap_free_table_item_cb)(stat_tap_table* table, guint row, guint column, stat_tap_table_item_type* field_data); 131 void (* stat_filter_check_cb)(const char *opt_arg, const char **filter, char** err); /* Dissector chance to reject filter */ 132 size_t nfields; /* number of fields */ 133 stat_tap_table_item* fields; 134 size_t nparams; /* number of parameters */ 135 tap_param *params; /* pointer to table of parameter info */ 136 GArray *tables; /* An array of stat_tap_table* */ 137 guint refcount; /* a reference count for deallocation */ 138 } stat_tap_table_ui; 139 140 141 /** tap data 142 */ 143 typedef struct _stat_data_t { 144 stat_tap_table_ui *stat_tap_data; 145 void *user_data; /**< "GUI" specifics (if necessary) */ 146 } stat_data_t; 147 148 149 /** Register UI information for a tap. 150 * 151 * @param ui UI information for the tap. 152 * @param userdata Additional data for the init routine. 153 */ 154 WS_DLL_PUBLIC void register_stat_tap_ui(stat_tap_ui *ui, void *userdata); 155 156 WS_DLL_PUBLIC void register_stat_tap_table_ui(stat_tap_table_ui *ui); 157 WS_DLL_PUBLIC void stat_tap_iterate_tables(wmem_foreach_func func, gpointer user_data); 158 WS_DLL_PUBLIC void stat_tap_get_filter(stat_tap_table_ui* new_stat, const char *opt_arg, const char **filter, char** err); 159 WS_DLL_PUBLIC stat_tap_table* stat_tap_init_table(const char *name, int num_fields, int num_elements, 160 const char *filter_string); 161 WS_DLL_PUBLIC void stat_tap_add_table(stat_tap_table_ui* new_stat, stat_tap_table* table); 162 WS_DLL_PUBLIC stat_tap_table *stat_tap_find_table(stat_tap_table_ui *ui, const char *name); 163 WS_DLL_PUBLIC void stat_tap_init_table_row(stat_tap_table *stat_table, guint table_index, guint num_fields, const stat_tap_table_item_type* fields); 164 WS_DLL_PUBLIC stat_tap_table_item_type* stat_tap_get_field_data(const stat_tap_table *stat_table, guint table_index, guint field_index); 165 WS_DLL_PUBLIC void stat_tap_set_field_data(stat_tap_table *stat_table, guint table_index, guint field_index, stat_tap_table_item_type* field_data); 166 WS_DLL_PUBLIC void reset_stat_table(stat_tap_table_ui* new_stat); 167 168 WS_DLL_PUBLIC stat_tap_table_ui *stat_tap_by_name(const char *name); 169 170 /** Free all of the tables associated with a stat_tap_table_ui. 171 * 172 * Frees data created by stat_tap_ui.stat_tap_init_cb. 173 * stat_tap_table_ui.stat_tap_free_table_item_cb is called for each index in each 174 * row. 175 * 176 * @param new_stat Parent stat_tap_table_ui struct, provided by the dissector. 177 */ 178 WS_DLL_PUBLIC void free_stat_tables(stat_tap_table_ui* new_stat); 179 180 181 WS_DLL_PUBLIC gboolean process_stat_cmd_arg(const char *optstr); 182 183 WS_DLL_PUBLIC void list_stat_cmd_args(void); 184 185 WS_DLL_PUBLIC void start_requested_stats(void); 186 187 #ifdef __cplusplus 188 } 189 #endif /* __cplusplus */ 190 191 #endif 192 193 /* 194 * Editor modelines 195 * 196 * Local Variables: 197 * c-basic-offset: 4 198 * tab-width: 8 199 * indent-tabs-mode: nil 200 * End: 201 * 202 * ex: set shiftwidth=4 tabstop=8 expandtab: 203 * :indentSize=4:tabSize=8:noTabs=true: 204 */ 205