2 * Routines for dissector Decode As handlers
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "decode_as.h"
32 GList *decode_as_list = NULL;
34 void register_decode_as(decode_as_t* reg)
36 dissector_table_t decode_table;
38 /* Ensure valid functions */
39 DISSECTOR_ASSERT(reg->populate_list);
40 DISSECTOR_ASSERT(reg->reset_value);
41 DISSECTOR_ASSERT(reg->change_value);
43 /* Ensure the dissector table can't have duplicate protocols
44 that could confuse users */
45 decode_table = find_dissector_table(reg->table_name);
46 /* XXX - This should really be a DISSECTOR_ASSERT but a Bluetooth
47 * dissector is registering for "media_type" dissector table before it
49 * There is also the "fake" DCE/RPC dissector table that needs to be fixed
51 if (decode_table != NULL)
53 /* FT_STRING can at least show the string value in the dialog, so don't penalize them */
54 if ((dissector_table_get_type(decode_table) != FT_STRING) &&
55 (dissector_table_get_proto_allowed(decode_table) != DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE))
57 fprintf(stderr, "%s allows duplicates, which can lead to confuse in the Decode As dialog\n", reg->table_name);
58 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
63 decode_as_list = g_list_append(decode_as_list, reg);
67 struct decode_as_default_populate
69 decode_as_add_to_list_func add_to_list;
74 decode_proto_add_to_list (const gchar *table_name, gpointer value, gpointer user_data)
76 struct decode_as_default_populate* populate = (struct decode_as_default_populate*)user_data;
77 const gchar *proto_name;
79 dissector_handle_t handle;
82 handle = (dissector_handle_t)value;
83 proto_name = dissector_handle_get_short_name(handle);
85 i = dissector_handle_get_protocol_index(handle);
86 if (i >= 0 && !proto_is_protocol_enabled(find_protocol_by_id(i)))
89 populate->add_to_list(table_name, proto_name, value, populate->ui_element);
92 void decode_as_default_populate_list(const gchar *table_name, decode_as_add_to_list_func add_to_list, gpointer ui_element)
94 struct decode_as_default_populate populate;
96 populate.add_to_list = add_to_list;
97 populate.ui_element = ui_element;
99 dissector_table_foreach_handle(table_name, decode_proto_add_to_list, &populate);
102 gboolean decode_as_default_reset(const char *name, const gpointer pattern)
104 switch (get_dissector_table_selector_type(name)) {
109 dissector_reset_uint(name, GPOINTER_TO_UINT(pattern));
115 dissector_reset_string(name, (!pattern)?"":(gchar *) pattern);
124 gboolean decode_as_default_change(const char *name, const gpointer pattern, gpointer handle, gchar* list_name _U_)
126 dissector_handle_t* dissector = (dissector_handle_t*)handle;
127 if (dissector != NULL) {
128 switch (get_dissector_table_selector_type(name)) {
133 dissector_change_uint(name, GPOINTER_TO_UINT(pattern), *dissector);
139 dissector_change_string(name, (!pattern)?"":(gchar *) pattern, *dissector);
157 * indent-tabs-mode: nil
160 * ex: set shiftwidth=4 tabstop=8 expandtab:
161 * :indentSize=4:tabSize=8:noTabs=true: