Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / rtd_table.c
blob2adf6ae91dc3d37668bccca95ab8623df0f8ee16
1 /* rtd_table.c
2 * Helper routines common to all RTD taps.
3 * Based on srt_table.c
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <string.h>
16 #include "proto.h"
17 #include "packet_info.h"
18 #include "rtd_table.h"
20 struct register_rtd {
21 int proto_id; /* protocol id (0-indexed) */
22 const char* tap_listen_str; /* string used in register_tap_listener (NULL to use protocol name) */
23 tap_packet_cb rtd_func; /* function to be called for new incoming packets for RTD */
24 unsigned num_tables;
25 unsigned num_timestats;
26 const value_string* vs_type;
27 rtd_filter_check_cb filter_check;
30 int get_rtd_proto_id(register_rtd_t* rtd)
32 if (!rtd) {
33 return -1;
35 return rtd->proto_id;
38 const char* get_rtd_tap_listener_name(register_rtd_t* rtd)
40 return rtd->tap_listen_str;
43 tap_packet_cb get_rtd_packet_func(register_rtd_t* rtd)
45 return rtd->rtd_func;
48 unsigned get_rtd_num_tables(register_rtd_t* rtd) {
49 return rtd->num_tables;
52 const value_string* get_rtd_value_string(register_rtd_t* rtd)
54 return rtd->vs_type;
57 static wmem_tree_t *registered_rtd_tables;
59 void
60 register_rtd_table(const int proto_id, const char* tap_listener, unsigned num_tables, unsigned num_timestats, const value_string* vs_type,
61 tap_packet_cb rtd_packet_func, rtd_filter_check_cb filter_check_cb)
63 register_rtd_t *table;
64 DISSECTOR_ASSERT(rtd_packet_func);
66 table = wmem_new(wmem_epan_scope(), register_rtd_t);
68 table->proto_id = proto_id;
69 if (tap_listener != NULL)
70 table->tap_listen_str = tap_listener;
71 else
72 table->tap_listen_str = proto_get_protocol_filter_name(proto_id);
73 table->rtd_func = rtd_packet_func;
74 table->num_tables = num_tables;
75 table->num_timestats = num_timestats;
76 table->vs_type = vs_type;
77 table->filter_check = filter_check_cb;
79 if (registered_rtd_tables == NULL)
80 registered_rtd_tables = wmem_tree_new(wmem_epan_scope());
82 wmem_tree_insert_string(registered_rtd_tables, proto_get_protocol_filter_name(proto_id), table, 0);
85 void free_rtd_table(rtd_stat_table* table)
87 unsigned i;
89 for (i = 0; i < table->num_rtds; i++)
91 g_free(table->time_stats[i].rtd);
93 g_free(table->time_stats);
94 table->time_stats = NULL;
95 table->num_rtds = 0;
98 void reset_rtd_table(rtd_stat_table* table)
100 unsigned i = 0;
102 for (i = 0; i < table->num_rtds; i++)
103 memset(table->time_stats[i].rtd, 0, sizeof(timestat_t)*table->time_stats[i].num_timestat);
106 register_rtd_t* get_rtd_table_by_name(const char* name)
108 return (register_rtd_t*)wmem_tree_lookup_string(registered_rtd_tables, name, 0);
111 char* rtd_table_get_tap_string(register_rtd_t* rtd)
113 GString *cmd_str = g_string_new(proto_get_protocol_filter_name(rtd->proto_id));
114 g_string_append(cmd_str, ",rtd");
115 return g_string_free(cmd_str, FALSE);
118 void rtd_table_get_filter(register_rtd_t* rtd, const char *opt_arg, const char **filter, char** err)
120 char* cmd_str = rtd_table_get_tap_string(rtd);
121 unsigned len = (unsigned) strlen(cmd_str);
122 *filter=NULL;
123 *err=NULL;
125 if (!strncmp(opt_arg, cmd_str, len))
127 if (opt_arg[len] == ',')
129 *filter = opt_arg + len+1;
133 if (rtd->filter_check)
134 rtd->filter_check(opt_arg, filter, err);
136 g_free(cmd_str);
139 void rtd_table_dissector_init(register_rtd_t* rtd, rtd_stat_table* table, rtd_gui_init_cb gui_callback, void *callback_data)
141 unsigned i;
143 table->num_rtds = rtd->num_tables;
144 table->time_stats = g_new0(rtd_timestat, rtd->num_tables);
146 for (i = 0; i < table->num_rtds; i++)
148 table->time_stats[i].num_timestat = rtd->num_timestats;
149 table->time_stats[i].rtd = g_new0(timestat_t, rtd->num_timestats);
152 if (gui_callback)
153 gui_callback(table, callback_data);
156 void rtd_table_iterate_tables(wmem_foreach_func func, void *user_data)
158 wmem_tree_foreach(registered_rtd_tables, func, user_data);
162 * Editor modelines
164 * Local Variables:
165 * c-basic-offset: 4
166 * tab-width: 8
167 * indent-tabs-mode: nil
168 * End:
170 * ex: set shiftwidth=4 tabstop=8 expandtab:
171 * :indentSize=4:tabSize=8:noTabs=true: