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 Pointer to optional function to generate prompt text
90 * for dissector. If NULL, "Next level protocol as" is used.
92 * @return Created dissector table with Decode As support
94 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);
96 /* Walk though the dissector table and provide dissector_handle_t for each item in the table */
97 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);
98 /* Clear a FT_UINT32 value from dissector table list */
99 WS_DLL_PUBLIC gboolean decode_as_default_reset(const gchar *name, gconstpointer pattern);
100 /* Add a FT_UINT32 value to dissector table list */
101 WS_DLL_PUBLIC gboolean decode_as_default_change(const gchar *name, gconstpointer pattern, gpointer handle, gchar *list_name);
103 /** List of registered decode_as_t structs.
104 * For UI code only. Should not be directly accessed by dissectors.
106 WS_DLL_PUBLIC GList *decode_as_list;
108 /* Some useful utilities for Decode As */
110 /** Reset the "decode as" entries and reload ones of the current profile.
111 * This is called by epan_load_settings(); programs should call that
112 * rather than individually calling the routines it calls.
114 extern void load_decode_as_entries(void);
116 /** Write out the "decode as" entries of the current profile.
118 WS_DLL_PUBLIC int save_decode_as_entries(gchar** err);
120 /** Clear all "decode as" settings.
122 WS_DLL_PUBLIC void decode_clear_all(void);
124 /** This routine creates one entry in the list of protocol dissector
125 * that need to be reset. It is called by the g_hash_table_foreach
126 * routine once for each changed entry in a dissector table.
127 * Unfortunately it cannot delete the entry immediately as this screws
128 * up the foreach function, so it builds a list of dissectors to be
129 * reset once the foreach routine finishes.
131 * @param table_name The table name in which this dissector is found.
133 * @param key A pointer to the key for this entry in the dissector
134 * hash table. This is generally the numeric selector of the
135 * protocol, i.e. the ethernet type code, IP port number, TCP port
138 * @param selector_type The type of the selector in that dissector table
140 * @param value A pointer to the value for this entry in the dissector
141 * hash table. This is an opaque pointer that can only be handed back
142 * to routine in the file packet.c - but it's unused.
144 * @param user_data Unused.
146 WS_DLL_PUBLIC void decode_build_reset_list (const gchar *table_name, ftenum_t selector_type,
147 gpointer key, gpointer value _U_,
148 gpointer user_data _U_);
153 #endif /* __cplusplus */
155 #endif /* decode_as.h */