epan: use SPDX indentifiers.
[metze/wireshark/wip.git] / epan / decode_as.h
1 /* decode_as.h
2  * Routines for dissector Decode As handlers
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifndef __DECODE_AS_H__
12 #define __DECODE_AS_H__
13
14 #include "ws_symbol_export.h"
15
16 #include "ftypes/ftypes.h"
17 #include "packet_info.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
22
23 /** @file
24  */
25
26 #define MAX_DECODE_AS_PROMPT_LEN    200
27 #define DECODE_AS_ENTRY "decode_as_entry"
28 #define DECODE_AS_NONE "(none)"
29
30 /*
31  * Filename of the "decode as" entry preferences
32  */
33 #define DECODE_AS_ENTRIES_FILE_NAME "decode_as_entries"
34
35
36 /** callback function definition: return formatted label string */
37 typedef void (*build_label_func)(packet_info *pinfo, gchar* result);
38
39 /** callback function definition: return value used to pass to dissector table */
40 typedef gpointer (*build_valid_func)(packet_info *pinfo);
41
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);
45
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);
50
51 typedef struct decode_as_value_s {
52     build_label_func label_func;
53     guint num_values;
54     build_valid_func* build_values;
55 } decode_as_value_t;
56
57 typedef struct decode_as_s {
58     const char *name;
59     const gchar *title;
60     const gchar *table_name;
61     guint num_items;
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;
70
71 } decode_as_t;
72
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);
75
76 /* Forward declaration to prevent requiring packet.h */
77 struct dissector_table;
78
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.
84  *
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.
90  *
91  * @return Created dissector table with Decode As support
92 */
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);
94
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);
101
102 /** List of registered decode_as_t structs.
103  * For UI code only. Should not be directly accessed by dissectors.
104  */
105 WS_DLL_PUBLIC GList *decode_as_list;
106
107 /* Some useful utilities for Decode As */
108
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.
112  */
113 extern void load_decode_as_entries(void);
114
115 /** Write out the "decode as" entries of the current profile.
116  */
117 WS_DLL_PUBLIC int save_decode_as_entries(gchar** err);
118
119 /** Clear all "decode as" settings.
120  */
121 WS_DLL_PUBLIC void decode_clear_all(void);
122
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.
129  *
130  * @param table_name The table name in which this dissector is found.
131  *
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
135  * number, etc.
136  *
137  * @param selector_type The type of the selector in that dissector table
138  *
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.
142  *
143  * @param user_data Unused.
144  */
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_);
148
149
150 #ifdef __cplusplus
151 }
152 #endif /* __cplusplus */
153
154 #endif /* decode_as.h */