1 /* stats_tree_priv.h 2 * implementor's API for stats_tree 3 * 2005, Luis E. G. Ontanon 4 * 5 * Wireshark - Network traffic analyzer 6 * By Gerald Combs <gerald@wireshark.org> 7 * Copyright 1998 Gerald Combs 8 * 9 * SPDX-License-Identifier: GPL-2.0-or-later 10 */ 11 12 #ifndef __STATS_TREE_PRIV_H 13 #define __STATS_TREE_PRIV_H 14 15 #include "stats_tree.h" 16 #include "ws_symbol_export.h" 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif /* __cplusplus */ 21 22 #define INDENT_MAX 32 23 #define NUM_BUF_SIZE 32 24 25 /** implementations should define this to contain its own node related data 26 * as well as some operations on it */ 27 typedef struct _st_node_pres st_node_pres; 28 29 /** implementations should define this to contain its own dynamic tree related data 30 * as well as some operations on it */ 31 typedef struct _tree_pres tree_pres; 32 33 /** implementations should define this to contain its own static tree related data 34 * as well as some operations on it */ 35 typedef struct _tree_cfg_pres tree_cfg_pres; 36 37 38 typedef struct _stat_node stat_node; 39 typedef struct _stats_tree_cfg stats_tree_cfg; 40 41 typedef struct _range_pair { 42 gint floor; 43 gint ceil; 44 } range_pair_t; 45 46 typedef struct _burst_bucket burst_bucket; 47 struct _burst_bucket { 48 burst_bucket *next; 49 burst_bucket *prev; 50 gint count; 51 double bucket_no; 52 double start_time; 53 }; 54 55 struct _stat_node { 56 gchar* name; 57 int id; 58 stat_node_datatype datatype; 59 60 /** the counter it keeps */ 61 gint counter; 62 /** total of all values submitted - for computing averages */ 63 union { 64 gint64 int_total; 65 gdouble float_total; 66 } total; 67 union { 68 gint int_min; 69 gfloat float_min; 70 } minvalue; 71 union { 72 gint int_max; 73 gfloat float_max; 74 } maxvalue; 75 76 gint st_flags; 77 78 /** fields for burst rate calculation */ 79 gint bcount; 80 burst_bucket *bh, *bt; 81 gint max_burst; 82 double burst_time; 83 84 /** children nodes by name */ 85 GHashTable *hash; 86 87 /** the owner of this node */ 88 stats_tree *st; 89 90 /** relatives */ 91 stat_node *parent; 92 stat_node *children; 93 stat_node *next; 94 95 /** used to check if value is within range */ 96 range_pair_t *rng; 97 98 /** node presentation data */ 99 st_node_pres *pr; 100 }; 101 102 struct _stats_tree { 103 /** the "class" from which it's derived */ 104 stats_tree_cfg *cfg; 105 106 char *filter; 107 108 /* times */ 109 double start; 110 double elapsed; 111 double now; 112 113 int st_flags; 114 gint num_columns; 115 gchar *display_name; 116 117 /** used to lookup named parents: 118 * key: parent node name 119 * value: parent node 120 */ 121 GHashTable *names; 122 123 /** used for quicker lookups of parent nodes */ 124 GPtrArray *parents; 125 126 /** 127 * tree representation 128 * to be defined (if needed) by the implementations 129 */ 130 tree_pres *pr; 131 132 /** every tree in nature has one */ 133 stat_node root; 134 }; 135 136 struct _stats_tree_cfg { 137 gchar* abbr; 138 gchar* name; 139 gchar* tapname; 140 register_stat_group_t stat_group; 141 142 gboolean plugin; 143 144 /** dissector defined callbacks */ 145 stat_tree_packet_cb packet; 146 stat_tree_init_cb init; 147 stat_tree_cleanup_cb cleanup; 148 149 /** tap listener flags for the per-packet callback */ 150 guint flags; 151 152 /* 153 * node presentation callbacks 154 */ 155 156 /** last to be called at node creation */ 157 void (*setup_node_pr)(stat_node*); 158 159 /** 160 * tree presentation callbacks 161 */ 162 tree_cfg_pres *pr; 163 164 165 tree_pres *(*new_tree_pr)(stats_tree*); 166 void (*free_tree_pr)(stats_tree*); 167 168 /** flags for the stats tree (sorting etc.) default values to new trees */ 169 guint st_flags; 170 }; 171 172 /* guess what, this is it! */ 173 WS_DLL_PUBLIC void stats_tree_presentation(void (*registry_iterator)(gpointer,gpointer,gpointer), 174 void (*setup_node_pr)(stat_node*), 175 void (*free_tree_pr)(stats_tree*), 176 void *data); 177 178 WS_DLL_PUBLIC stats_tree *stats_tree_new(stats_tree_cfg *cfg, tree_pres *pr, const char *filter); 179 180 /** callback for taps */ 181 WS_DLL_PUBLIC tap_packet_status stats_tree_packet(void*, packet_info*, epan_dissect_t*, const void *); 182 183 /** callback for reset */ 184 WS_DLL_PUBLIC void stats_tree_reset(void *p_st); 185 186 /** callback for clear */ 187 WS_DLL_PUBLIC void stats_tree_reinit(void *p_st); 188 189 /* callback for destoy */ 190 WS_DLL_PUBLIC void stats_tree_free(stats_tree *st); 191 192 /** given an ws_optarg splits the abbr part 193 and returns a newly allocated buffer containing it */ 194 WS_DLL_PUBLIC gchar *stats_tree_get_abbr(const gchar *ws_optarg); 195 196 /** obtains a stats tree from the registry given its abbr */ 197 WS_DLL_PUBLIC stats_tree_cfg *stats_tree_get_cfg_by_abbr(const char *abbr); 198 199 /** obtains a stats tree list from the registry 200 caller should free returned list with g_list_free() */ 201 WS_DLL_PUBLIC GList *stats_tree_get_cfg_list(void); 202 203 /** used to calcuate the size of the indentation and the longest string */ 204 WS_DLL_PUBLIC guint stats_tree_branch_max_namelen(const stat_node *node, guint indent); 205 206 /** a text representation of a node, 207 if buffer is NULL returns a newly allocated string */ 208 WS_DLL_PUBLIC gchar *stats_tree_node_to_str(const stat_node *node, 209 gchar *buffer, guint len); 210 211 /** get the display name for the stats_tree (or node name) based on the 212 st_sort_showfullname preference. If not set remove everything before 213 last unescaped backslash. Caller must free the result */ 214 WS_DLL_PUBLIC gchar* stats_tree_get_displayname (gchar* fullname); 215 216 /** returns the column number of the default column to sort on */ 217 WS_DLL_PUBLIC gint stats_tree_get_default_sort_col (stats_tree *st); 218 219 /** returns the default sort order to use */ 220 WS_DLL_PUBLIC gboolean stats_tree_is_default_sort_DESC (stats_tree *st); 221 222 /** returns the column name for a given column index */ 223 WS_DLL_PUBLIC const gchar* stats_tree_get_column_name (gint col_index); 224 225 /** returns the maximum number of characters in the value of a column */ 226 WS_DLL_PUBLIC gint stats_tree_get_column_size (gint col_index); 227 228 /** returns the formatted column values for the current node 229 as array of gchar*. Caller must free entries and free array */ 230 WS_DLL_PUBLIC gchar** stats_tree_get_values_from_node (const stat_node* node); 231 232 /** function to compare two nodes for sort, based on sort_column. */ 233 WS_DLL_PUBLIC gint stats_tree_sort_compare (const stat_node *a, 234 const stat_node *b, 235 gint sort_column, 236 gboolean sort_descending); 237 238 /** wrapper for stats_tree_sort_compare() function that can be called from array sort. */ 239 WS_DLL_PUBLIC gint stat_node_array_sortcmp (gconstpointer a, 240 gconstpointer b, 241 gpointer user_data); 242 243 /** function to copy stats_tree into GString. format deternmines output format */ 244 WS_DLL_PUBLIC GString* stats_tree_format_as_str(const stats_tree* st, 245 st_format_type format_type, 246 gint sort_column, 247 gboolean sort_descending); 248 249 /** helper funcation to add note to formatted stats_tree */ 250 WS_DLL_PUBLIC void stats_tree_format_node_as_str(const stat_node *node, 251 GString *s, 252 st_format_type format_type, 253 guint indent, 254 const gchar *path, 255 gint maxnamelen, 256 gint sort_column, 257 gboolean sort_descending); 258 259 #ifdef __cplusplus 260 } 261 #endif /* __cplusplus */ 262 263 #endif /* __STATS_TREE_PRIV_H */ 264