dcerpc-netlogon: improve NetrLogonGetCapabilities dissection
[wireshark-sm.git] / epan / conversation_filter.c
blobe8bbbc1e75a05385822f2eadadbcc258b533cd24
1 /* conversation_filter.c
2 * Routines for dissector-generated conversation filters for use as
3 * display and color filters
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 <glib.h>
15 #include "packet.h"
17 #include "conversation_filter.h"
20 GList *packet_conv_filter_list;
21 GList *log_conv_filter_list;
23 static GSList *conversation_proto_names;
25 void conversation_filters_init(void)
27 // add_conversation_filter_protocol prepends entries to the list. Add
28 // lower layers first so that upper-layer conversations take precedence.
29 add_conversation_filter_protocol("eth");
30 add_conversation_filter_protocol("ipv6");
31 add_conversation_filter_protocol("ip");
32 add_conversation_filter_protocol("udp");
33 add_conversation_filter_protocol("tcp");
36 static void do_register_conversation_filter(GList **conv_filter_list, const char *proto_name, const char *display_name,
37 is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string, void *user_data) {
38 conversation_filter_t *entry;
40 entry = g_new(conversation_filter_t, 1);
42 entry->proto_name = proto_name;
43 entry->display_name = display_name;
44 entry->is_filter_valid = is_filter_valid;
45 entry->build_filter_string = build_filter_string;
46 entry->user_data = user_data;
48 *conv_filter_list = g_list_append(*conv_filter_list, entry);
51 void register_conversation_filter(const char *proto_name, const char *display_name,
52 is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string, void *user_data) {
53 do_register_conversation_filter(&packet_conv_filter_list,
54 proto_name,
55 display_name,
56 is_filter_valid,
57 build_filter_string,
58 user_data);
61 void register_log_conversation_filter(const char *proto_name, const char *display_name,
62 is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string, void *user_data) {
63 do_register_conversation_filter(&log_conv_filter_list,
64 proto_name,
65 display_name,
66 is_filter_valid,
67 build_filter_string,
68 user_data);
71 void add_conversation_filter_protocol(const char *proto_name)
73 for (GSList *cur_entry = conversation_proto_names; cur_entry; cur_entry = g_slist_next(cur_entry)) {
74 if (strcmp(proto_name, cur_entry->data) == 0) {
75 return;
78 conversation_proto_names = g_slist_prepend(conversation_proto_names, (void *)proto_name);
81 static struct conversation_filter_s* find_conversation_filter(GList *conv_filter_list, const char *name)
83 GList *list_entry = conv_filter_list;
84 conversation_filter_t* filter;
86 while (list_entry != NULL) {
87 filter = (conversation_filter_t*)list_entry->data;
88 if (!strcmp(filter->proto_name, name))
89 return filter;
91 list_entry = g_list_next(list_entry);
94 return NULL;
97 static void conversation_filter_free(void *p, void *user_data _U_)
99 g_free(p);
102 void conversation_filters_cleanup(void)
104 g_list_foreach(packet_conv_filter_list, conversation_filter_free, NULL);
105 g_list_free(packet_conv_filter_list);
106 g_list_foreach(log_conv_filter_list, conversation_filter_free, NULL);
107 g_list_free(log_conv_filter_list);
109 g_slist_free(conversation_proto_names);
112 static char *conversation_filter_from_pinfo(GList *conv_filter_list, struct _packet_info *pinfo)
114 conversation_filter_t *conv_filter;
115 char *filter;
117 for (GSList *cur_entry = conversation_proto_names; cur_entry; cur_entry = g_slist_next(cur_entry)) {
118 conv_filter = find_conversation_filter(conv_filter_list, (const char *) cur_entry->data);
119 if (conv_filter && conv_filter->is_filter_valid(pinfo, conv_filter->user_data)) {
120 if ((filter = conv_filter->build_filter_string(pinfo, conv_filter->user_data)) != NULL)
121 return filter;
125 return NULL;
128 char *conversation_filter_from_packet(struct _packet_info *pinfo)
130 return conversation_filter_from_pinfo(packet_conv_filter_list, pinfo);
133 char *conversation_filter_from_log(struct _packet_info *pinfo)
135 return conversation_filter_from_pinfo(log_conv_filter_list, pinfo);
139 * Editor modelines - https://www.wireshark.org/tools/modelines.html
141 * Local variables:
142 * c-basic-offset: 4
143 * tab-width: 8
144 * indent-tabs-mode: nil
145 * End:
147 * vi: set shiftwidth=4 tabstop=8 expandtab:
148 * :indentSize=4:tabSize=8:noTabs=true: