aboutsummaryrefslogtreecommitdiffstats
path: root/epan/stats_tree.h
blob: e4d6408eb91fa75780753d248df0eb88ba626828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* stats_tree.h
 * A counter tree API for Wireshark dissectors
 * 2005, Luis E. G. Ontanon
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
#ifndef __STATS_TREE_H
#define __STATS_TREE_H

#include <glib.h>
#include <epan/epan.h>
#include <epan/packet_info.h>
#include <epan/to_str.h>
#include <epan/tap.h>
#include "../stat_menu.h"
#include "../register.h"

#define STAT_TREE_ROOT "root"

/* obscure information regarding the stats_tree */
typedef struct _stats_tree stats_tree;

/* tap packet callback for stats_tree */
typedef int  (*stat_tree_packet_cb)(stats_tree*,
				    packet_info*,
				    epan_dissect_t*,
				    const void *);

/* stats_tree initialization callback */
typedef void  (*stat_tree_init_cb)(stats_tree*);

/* stats_tree cleanup callback */
typedef void  (*stat_tree_cleanup_cb)(stats_tree*);

/* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED
 * abbr: protocol abbr
 * name: protocol display name
 * flags: tap listener flags for per-packet callback
 * packet: per packet callback
 * init: tree initialization callback
 * cleanup: cleanup callback
 */
extern void stats_tree_register(const gchar *tapname,
				const gchar *abbr,
				const gchar *name,
				guint flags,
				stat_tree_packet_cb packet,
				stat_tree_init_cb init,
				stat_tree_cleanup_cb cleanup);

/* registers a new stats tree with default group REGISTER_STAT_GROUP_UNSORTED from a plugin
 * abbr: protocol abbr
 * name: protocol display name
 * flags: tap listener flags for per-packet callback
 * packet: per packet callback
 * init: tree initialization callback
 * cleanup: cleanup callback
 */
extern void stats_tree_register_plugin(const gchar *tapname,
				const gchar *abbr,
				const gchar *name,
				guint flags,
				stat_tree_packet_cb packet,
				stat_tree_init_cb init,
				stat_tree_cleanup_cb cleanup);

/* registers a new stats tree
 * abbr: protocol abbr
 * name: protocol display name
 * flags: tap listener flags for per-packet callback
 * packet: per packet callback
 * init: tree initialization callback
 * cleanup: cleanup callback
 * stat_group: the group this stat belongs to
 */
extern void stats_tree_register_with_group(const gchar *tapname,
				const gchar *abbr,
				const gchar *name,
				guint flags,
				stat_tree_packet_cb packet,
				stat_tree_init_cb init,
				stat_tree_cleanup_cb cleanup,
				register_stat_group_t stat_group);

extern int stats_tree_parent_id_by_name(stats_tree *st, const gchar *parent_name);

/* Creates a node in the tree (to be used in the in init_cb)
* st: the stats_tree in which to create it
* name: the name of the new node
* parent_name: the name of the parent_node (NULL for root)
* with_children: TRUE if this node will have "dynamically created" children
*/
extern int stats_tree_create_node(stats_tree *st,
				  const gchar *name,
				  int parent_id,
				  gboolean with_children);

/* creates a node using it's parent's tree name */
extern int stats_tree_create_node_by_pname(stats_tree *st,
					   const gchar *name,
					   const gchar *parent_name,
					   gboolean with_children);

/* creates a node in the tree, that will contain a ranges list.
 example:
 stats_tree_create_range_node(st,name,parent,
			      "-99","100-199","200-299","300-399","400-", NULL);
*/
extern int stats_tree_create_range_node(stats_tree *st,
					const gchar *name,
					int parent_id,
					...);

extern int stats_tree_create_range_node_string(stats_tree *st,
					const gchar *name,
					int parent_id,
					int num_str_ranges,
					gchar** str_ranges);

extern int stats_tree_range_node_with_pname(stats_tree *st,
					    const gchar *name,
					    const gchar *parent_name,
					    ...);

/* increases by one the ranged node and the sub node to whose range the value belongs */
extern int stats_tree_tick_range(stats_tree *st,
				 const gchar *name,
				 int parent_id,
				 int value_in_range);

#define stats_tree_tick_range_by_pname(st,name,parent_name,value_in_range) \
     stats_tree_tick_range((st),(name),stats_tree_parent_id_by_name((st),(parent_name),(value_in_range))

/* */
extern int stats_tree_create_pivot(stats_tree *st,
				   const gchar *name,
				   int parent_id);

extern int stats_tree_create_pivot_by_pname(stats_tree *st,
					    const gchar *name,
					    const gchar *parent_name);

extern int stats_tree_tick_pivot(stats_tree *st,
				 int pivot_id,
				 const gchar *pivot_value);

/*
 * manipulates the value of the node whose name is given
 * if the node does not exist yet it's created (with counter=1)
 * using parent_name as parent node (NULL for root).
 * with_children=TRUE to indicate that the created node will be a parent
 */
typedef enum _manip_node_mode { MN_INCREASE, MN_SET } manip_node_mode;
extern int stats_tree_manip_node(manip_node_mode mode,
				 stats_tree *st,
				 const gchar *name,
				 int parent_id,
				 gboolean with_children,
				 gint value);

#define increase_stat_node(st,name,parent_id,with_children,value) \
(stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),(value)))

#define tick_stat_node(st,name,parent_id,with_children) \
(stats_tree_manip_node(MN_INCREASE,(st),(name),(parent_id),(with_children),1))

#define set_stat_node(st,name,parent_id,with_children,value) \
(stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),value))

#define zero_stat_node(st,name,parent_id,with_children) \
(stats_tree_manip_node(MN_SET,(st),(name),(parent_id),(with_children),0))

#endif /* __STATS_TREE_H */