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 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef __DECODE_AS_H__
12 #define __DECODE_AS_H__
14 #include "ws_symbol_export.h"
16 #include "ftypes/ftypes.h"
17 #include "packet_info.h"
21 #endif /* __cplusplus */
26 #define MAX_DECODE_AS_PROMPT_LEN 200
27 #define DECODE_AS_ENTRY "decode_as_entry"
28 #define DECODE_AS_NONE "(none)"
31 * Filename of the "decode as" entry preferences
33 #define DECODE_AS_ENTRIES_FILE_NAME "decode_as_entries"
36 /** callback function definition: return formatted label string */
37 typedef void (*build_label_func)(packet_info *pinfo, gchar* result);
39 /** callback function definition: return value used to pass to dissector table */
40 typedef gpointer (*build_valid_func)(packet_info *pinfo);
42 typedef void (*decode_as_add_to_list_func)(const gchar *table_name, const gchar *proto_name, gpointer value, gpointer user_data);
43 typedef void (*decode_as_populate_list_func)(const gchar *table_name, decode_as_add_to_list_func add_to_list, gpointer ui_element);
44 typedef void (*decode_as_free_func)(gpointer value);
46 /** callback function definition: Clear value from dissector table */
47 typedef gboolean (*decode_as_reset_func)(const gchar *name, gconstpointer pattern);
48 /** callback function definition: Apply value to dissector table */
49 typedef gboolean (*decode_as_change_func)(const gchar *name, gconstpointer pattern, gpointer handle, gchar *list_name);
51 typedef struct decode_as_value_s {
52 build_label_func label_func;
54 build_valid_func* build_values;
57 typedef struct decode_as_s {
60 const gchar *table_name;
62 guint default_index_value;
63 decode_as_value_t* values;
64 const char* pre_value_str;
65 const char* post_value_str;
66 decode_as_populate_list_func populate_list;
67 decode_as_reset_func reset_value;
68 decode_as_change_func change_value;
69 decode_as_free_func free_func;
73 /** register a "Decode As". A copy of the decode_as_t will be maintained by the decode_as module */
74 WS_DLL_PUBLIC void register_decode_as(decode_as_t* reg);
76 /* Forward declaration to prevent requiring packet.h */
77 struct dissector_table;
79 /** Register a "Decode As" entry for the special case where there is no
80 * indication for the next protocol (such as port number etc.).
81 * For now, this will use a uint32 dissector table internally and
82 * assign all registered protocols to 0. The framework to do this can
83 * be kept internal to epan.
85 * @param proto The protocol ID to create the dissector table.
86 * @param title The table name in which this dissector is found.
87 * @param table_name The table name in which this dissector is found.
88 * @param ui_name UI name for created dissector table.
89 * @param label_func Optional prompt text for dissector. If NULL, "Next level protocol as" is used.
91 * @return Created dissector table with Decode As support
93 WS_DLL_PUBLIC struct dissector_table* register_decode_as_next_proto(int proto, const gchar *title, const gchar *table_name, const gchar *ui_name, build_label_func* label_func);
95 /* Walk though the dissector table and provide dissector_handle_t for each item in the table */
96 WS_DLL_PUBLIC void decode_as_default_populate_list(const gchar *table_name, decode_as_add_to_list_func add_to_list, gpointer ui_element);
97 /* Clear a FT_UINT32 value from dissector table list */
98 WS_DLL_PUBLIC gboolean decode_as_default_reset(const gchar *name, gconstpointer pattern);
99 /* Add a FT_UINT32 value to dissector table list */
100 WS_DLL_PUBLIC gboolean decode_as_default_change(const gchar *name, gconstpointer pattern, gpointer handle, gchar *list_name);
102 /** List of registered decode_as_t structs.
103 * For UI code only. Should not be directly accessed by dissectors.
105 WS_DLL_PUBLIC GList *decode_as_list;
107 /* Some useful utilities for Decode As */
109 /** Reset the "decode as" entries and reload ones of the current profile.
110 * This is called by epan_load_settings(); programs should call that
111 * rather than individually calling the routines it calls.
113 extern void load_decode_as_entries(void);
115 /** Write out the "decode as" entries of the current profile.
117 WS_DLL_PUBLIC int save_decode_as_entries(gchar** err);
119 /** Clear all "decode as" settings.
121 WS_DLL_PUBLIC void decode_clear_all(void);
123 /** This routine creates one entry in the list of protocol dissector
124 * that need to be reset. It is called by the g_hash_table_foreach
125 * routine once for each changed entry in a dissector table.
126 * Unfortunately it cannot delete the entry immediately as this screws
127 * up the foreach function, so it builds a list of dissectors to be
128 * reset once the foreach routine finishes.
130 * @param table_name The table name in which this dissector is found.
132 * @param key A pointer to the key for this entry in the dissector
133 * hash table. This is generally the numeric selector of the
134 * protocol, i.e. the ethernet type code, IP port number, TCP port
137 * @param selector_type The type of the selector in that dissector table
139 * @param value A pointer to the value for this entry in the dissector
140 * hash table. This is an opaque pointer that can only be handed back
141 * to routine in the file packet.c - but it's unused.
143 * @param user_data Unused.
145 WS_DLL_PUBLIC void decode_build_reset_list (const gchar *table_name, ftenum_t selector_type,
146 gpointer key, gpointer value _U_,
147 gpointer user_data _U_);
152 #endif /* __cplusplus */
154 #endif /* decode_as.h */