Wireshark  4.3.0
The Wireshark network protocol analyzer
stats_tree.h
Go to the documentation of this file.
1 
11 #ifndef __STATS_TREE_H
12 #define __STATS_TREE_H
13 
14 #include <glib.h>
15 #include <epan/epan.h>
16 #include <epan/packet_info.h>
17 #include <epan/tap.h>
18 #include <epan/stat_groups.h>
19 #include "ws_symbol_export.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
25 #define STAT_TREE_ROOT "root"
26 #define STATS_TREE_MENU_SEPARATOR "//"
27 
28 #define ST_FLG_AVERAGE 0x10000000 /* Calculate averages for nodes, rather than totals */
29 #define ST_FLG_ROOTCHILD 0x20000000 /* This node is a direct child of the root node */
30 #define ST_FLG_DEF_NOEXPAND 0x01000000 /* This node should not be expanded by default */
31 #define ST_FLG_SORT_DESC 0x00800000 /* When sorting, sort ascending instead of decending */
32 #define ST_FLG_SORT_TOP 0x00400000 /* When sorting always keep these lines on of list */
33 #define ST_FLG_SRTCOL_MASK 0x000F0000 /* Mask for sort column ID */
34 #define ST_FLG_SRTCOL_SHIFT 16 /* Number of bits to shift masked result */
35 
36 #define ST_FLG_MASK (ST_FLG_AVERAGE|ST_FLG_ROOTCHILD|ST_FLG_DEF_NOEXPAND| \
37  ST_FLG_SORT_TOP|ST_FLG_SORT_DESC|ST_FLG_SRTCOL_MASK)
38 
39 #define ST_SORT_COL_NAME 1 /* Sort nodes by node names */
40 #define ST_SORT_COL_COUNT 2 /* Sort nodes by node count */
41 #define ST_SORT_COL_AVG 3 /* Sort nodes by node average */
42 #define ST_SORT_COL_MIN 4 /* Sort nodes by minimum node value */
43 #define ST_SORT_COL_MAX 5 /* Sort nodes by maximum node value */
44 #define ST_SORT_COL_BURSTRATE 6 /* Sort nodes by burst rate */
45 
46 /* obscure information regarding the stats_tree */
47 typedef struct _stats_tree stats_tree;
48 
49 /* tap packet callback for stats_tree */
50 typedef tap_packet_status (*stat_tree_packet_cb)(stats_tree*,
51  packet_info *,
53  const void *,
54  tap_flags_t flags);
55 
56 /* stats_tree initialization callback */
57 typedef void (*stat_tree_init_cb)(stats_tree *);
58 
59 /* stats_tree cleanup callback */
60 typedef void (*stat_tree_cleanup_cb)(stats_tree *);
61 
62 typedef enum _stat_node_datatype {
63  STAT_DT_INT,
64  STAT_DT_FLOAT
65 } stat_node_datatype;
66 
67 typedef struct _stats_tree_cfg stats_tree_cfg;
68 
79 WS_DLL_PUBLIC stats_tree_cfg *stats_tree_register(const gchar *tapname,
80  const gchar *abbr,
81  const gchar *path,
82  guint flags,
83  stat_tree_packet_cb packet,
84  stat_tree_init_cb init,
85  stat_tree_cleanup_cb cleanup);
86 
97 WS_DLL_PUBLIC stats_tree_cfg *stats_tree_register_plugin(const gchar *tapname,
98  const gchar *abbr,
99  const gchar *path,
100  guint flags,
101  stat_tree_packet_cb packet,
102  stat_tree_init_cb init,
103  stat_tree_cleanup_cb cleanup);
104 
109 WS_DLL_PUBLIC void stats_tree_set_group(stats_tree_cfg *st_config, register_stat_group_t stat_group);
110 
116 WS_DLL_PUBLIC void stats_tree_set_first_column_name(stats_tree_cfg *st_config, const char *column_name);
117 
118 
119 WS_DLL_PUBLIC int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);
120 
121 /* Creates a node in the tree (to be used in the in init_cb)
122  * st: the stats_tree in which to create it
123  * name: the name of the new node
124  * parent_name: the name of the parent_node (NULL for root)
125  * datatype: datatype used for the value of the node
126  * with_children: TRUE if this node will have "dynamically created" children
127  */
128 WS_DLL_PUBLIC int stats_tree_create_node(stats_tree *st,
129  const gchar *name,
130  int parent_id,
131  stat_node_datatype datatype,
132  gboolean with_children);
133 
134 /* creates a node using its parent's tree name */
135 WS_DLL_PUBLIC int stats_tree_create_node_by_pname(stats_tree *st,
136  const gchar *name,
137  const gchar *parent_name,
138  stat_node_datatype datatype,
139  gboolean with_children);
140 
141 /* creates a node in the tree, that will contain a ranges list.
142  example:
143  stats_tree_create_range_node(st,name,parent,
144  "-99","100-199","200-299","300-399","400-", NULL);
145 */
146 WS_DLL_PUBLIC int stats_tree_create_range_node(stats_tree *st,
147  const gchar *name,
148  int parent_id,
149  ...);
150 
151 WS_DLL_PUBLIC int stats_tree_create_range_node_string(stats_tree *st,
152  const gchar *name,
153  int parent_id,
154  int num_str_ranges,
155  gchar** str_ranges);
156 
157 WS_DLL_PUBLIC int stats_tree_range_node_with_pname(stats_tree *st,
158  const gchar *name,
159  const gchar *parent_name,
160  ...);
161 
162 /* increases by one the ranged node and the sub node to whose range the value belongs */
163 WS_DLL_PUBLIC int stats_tree_tick_range(stats_tree *st,
164  const gchar *name,
165  int parent_id,
166  int value_in_range);
167 
168 #define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
169  stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range)))
170 
171 /* */
172 WS_DLL_PUBLIC int stats_tree_create_pivot(stats_tree *st,
173  const gchar *name,
174  int parent_id);
175 
176 WS_DLL_PUBLIC int stats_tree_create_pivot_by_pname(stats_tree *st,
177  const gchar *name,
178  const gchar *parent_name);
179 
180 WS_DLL_PUBLIC int stats_tree_tick_pivot(stats_tree *st,
181  int pivot_id,
182  const gchar *pivot_value);
183 
184 extern void stats_tree_cleanup(void);
185 
186 
187 /*
188  * manipulates the value of the node whose name is given
189  * if the node does not exist yet it's created (with counter=1)
190  * using parent_name as parent node (NULL for root).
191  * with_children=TRUE to indicate that the created node will be a parent
192  */
193 typedef enum _manip_node_mode {
194  MN_INCREASE,
195  MN_SET,
196  MN_AVERAGE,
197  MN_AVERAGE_NOTICK,
198  MN_SET_FLAGS,
199  MN_CLEAR_FLAGS
200 } manip_node_mode;
201 WS_DLL_PUBLIC int stats_tree_manip_node_int(manip_node_mode mode,
202  stats_tree *st,
203  const gchar *name,
204  int parent_id,
205  gboolean with_children,
206  gint value);
207 
208 WS_DLL_PUBLIC int stats_tree_manip_node_float(manip_node_mode mode,
209  stats_tree *st,
210  const gchar *name,
211  int parent_id,
212  gboolean with_children,
213  gfloat value);
214 
215 #define increase_stat_node(st,name,parent_id,with_children,value) \
216  (stats_tree_manip_node_int(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))
217 
218 #define tick_stat_node(st,name,parent_id,with_children) \
219  (stats_tree_manip_node_int(MN_INCREASE,(st),(name),(parent_id),(with_children),1))
220 
221 #define set_stat_node(st,name,parent_id,with_children,value) \
222  (stats_tree_manip_node_int(MN_SET,(st),(name),(parent_id),(with_children),value))
223 
224 #define zero_stat_node(st,name,parent_id,with_children) \
225  (stats_tree_manip_node_int(MN_SET,(st),(name),(parent_id),(with_children),0))
226 
227 /*
228  * Add value to average calculation WITHOUT ticking node. Node MUST be ticked separately!
229  *
230  * Intention is to allow code to separately tick node (backward compatibility for plugin)
231  * and set value to use for averages. Older versions without average support will then at
232  * least show a count instead of 0.
233  */
234 #define avg_stat_node_add_value_notick(st,name,parent_id,with_children,value) \
235  (stats_tree_manip_node_int(MN_AVERAGE_NOTICK,(st),(name),(parent_id),(with_children),value))
236 
237 /* Tick node and add a new value to the average calculation for this stats node. */
238 #define avg_stat_node_add_value_int(st,name,parent_id,with_children,value) \
239  (stats_tree_manip_node_int(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
240 
241 #define avg_stat_node_add_value_float(st,name,parent_id,with_children,value) \
242  (stats_tree_manip_node_float(MN_AVERAGE,(st),(name),(parent_id),(with_children),value))
243 
244 /* Set flags for this node. Node created if it does not yet exist. */
245 #define stat_node_set_flags(st,name,parent_id,with_children,flags) \
246  (stats_tree_manip_node_int(MN_SET_FLAGS,(st),(name),(parent_id),(with_children),flags))
247 
248 /* Clear flags for this node. Node created if it does not yet exist. */
249 #define stat_node_clear_flags(st,name,parent_id,with_children,flags) \
250  (stats_tree_manip_node_int(MN_CLEAR_FLAGS,(st),(name),(parent_id),(with_children),flags))
251 
252 #ifdef __cplusplus
253 }
254 #endif /* __cplusplus */
255 
256 #endif /* __STATS_TREE_H */
257 
258 /*
259  * Editor modelines - https://www.wireshark.org/tools/modelines.html
260  *
261  * Local variables:
262  * c-basic-offset: 4
263  * tab-width: 8
264  * indent-tabs-mode: nil
265  * End:
266  *
267  * vi: set shiftwidth=4 tabstop=8 expandtab:
268  * :indentSize=4:tabSize=8:noTabs=true:
269  */
enum register_stat_group_e register_stat_group_t
WS_DLL_PUBLIC void stats_tree_set_first_column_name(stats_tree_cfg *st_config, const char *column_name)
Definition: stats_tree.c:338
WS_DLL_PUBLIC stats_tree_cfg * stats_tree_register(const gchar *tapname, const gchar *abbr, const gchar *path, guint flags, stat_tree_packet_cb packet, stat_tree_init_cb init, stat_tree_cleanup_cb cleanup)
WS_DLL_PUBLIC void stats_tree_set_group(stats_tree_cfg *st_config, register_stat_group_t stat_group)
Definition: stats_tree.c:331
WS_DLL_PUBLIC stats_tree_cfg * stats_tree_register_plugin(const gchar *tapname, const gchar *abbr, const gchar *path, guint flags, stat_tree_packet_cb packet, stat_tree_init_cb init, stat_tree_cleanup_cb cleanup)
Definition: packet_info.h:44
Definition: stats_tree_priv.h:136
guint flags
Definition: stats_tree_priv.h:152
stat_tree_packet_cb packet
Definition: stats_tree_priv.h:147
Definition: stats_tree_priv.h:102
Definition: packet-epl-profile-parser.c:83
Definition: epan_dissect.h:28
tap_packet_status
Definition: tap.h:25