tvbuff_composite: fix buffer overflow due to wrong offset adjustment
[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 Pointer to optional function to generate prompt text
90  *  for dissector.  If NULL, "Next level protocol as" is used.
91  *
92  * @return Created dissector table with Decode As support
93 */
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);
95
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);
102
103 /** List of registered decode_as_t structs.
104  * For UI code only. Should not be directly accessed by dissectors.
105  */
106 WS_DLL_PUBLIC GList *decode_as_list;
107
108 /* Some useful utilities for Decode As */
109
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.
113  */
114 extern void load_decode_as_entries(void);
115
116 /** Write out the "decode as" entries of the current profile.
117  */
118 WS_DLL_PUBLIC int save_decode_as_entries(gchar** err);
119
120 /** Clear all "decode as" settings.
121  */
122 WS_DLL_PUBLIC void decode_clear_all(void);
123
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.
130  *
131  * @param table_name The table name in which this dissector is found.
132  *
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
136  * number, etc.
137  *
138  * @param selector_type The type of the selector in that dissector table
139  *
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.
143  *
144  * @param user_data Unused.
145  */
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_);
149
150
151 #ifdef __cplusplus
152 }
153 #endif /* __cplusplus */
154
155 #endif /* decode_as.h */