summaryrefslogtreecommitdiffstats
path: root/epan/funnel.h
blob: 7b3e8d95704fe80551eaaf40a653da185efb0959 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/** @file
 *
 * EPAN's GUI mini-API
 *
 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */
#ifndef __FUNNEL_H__
#define __FUNNEL_H__

#include <wireshark.h>
#include <epan/stat_groups.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct _funnel_ops_id_t funnel_ops_id_t; /* Opaque pointer to ops instance */
typedef struct _funnel_text_window_t funnel_text_window_t ;

typedef void (*text_win_close_cb_t)(void*);

typedef void (*funnel_dlg_cb_t)(gchar** user_input, void* data);
typedef void (*funnel_dlg_cb_data_free_t)(void* data);

typedef gboolean (*funnel_bt_cb_t)(funnel_text_window_t* tw, void* data);

typedef void (* funnel_menu_callback)(gpointer);
typedef void (* funnel_menu_callback_data_free)(gpointer);

typedef struct _funnel_bt_t {
	funnel_text_window_t* tw;
	funnel_bt_cb_t func;
	void* data;
	void (*free_fcn)(void*);
	void (*free_data_fcn)(void*);
} funnel_bt_t;

struct progdlg;

typedef struct _funnel_ops_t {
    funnel_ops_id_t *ops_id;
    funnel_text_window_t* (*new_text_window)(funnel_ops_id_t *ops_id, const char* label);
    void (*set_text)(funnel_text_window_t*  win, const char* text);
    void (*append_text)(funnel_text_window_t*  win, const char* text);
    void (*prepend_text)(funnel_text_window_t*  win, const char* text);
    void (*clear_text)(funnel_text_window_t*  win);
    const char* (*get_text)(funnel_text_window_t*  win);
    void (*set_close_cb)(funnel_text_window_t*  win, text_win_close_cb_t cb, void* data);
    void (*set_editable)(funnel_text_window_t*  win, gboolean editable);
    void (*destroy_text_window)(funnel_text_window_t*  win);
    void (*add_button)(funnel_text_window_t*  win, funnel_bt_t* cb, const char* label);

    void (*new_dialog)(funnel_ops_id_t *ops_id,
                    const gchar* title,
                    const gchar** field_names,
                    const gchar** field_values,
                    funnel_dlg_cb_t dlg_cb,
                    void* data,
                    funnel_dlg_cb_data_free_t dlg_cb_data_free);

    void (*close_dialogs)(void);

    void (*retap_packets)(funnel_ops_id_t *ops_id);
    void (*copy_to_clipboard)(GString *str);

    const gchar * (*get_filter)(funnel_ops_id_t *ops_id);
    void (*set_filter)(funnel_ops_id_t *ops_id, const char* filter);
    gchar * (*get_color_filter_slot)(guint8 filt_nr);
    void (*set_color_filter_slot)(guint8 filt_nr, const gchar* filter);
    gboolean (*open_file)(funnel_ops_id_t *ops_id, const char* fname, const char* filter, char** error);
    void (*reload_packets)(funnel_ops_id_t *ops_id);
    void (*redissect_packets)(funnel_ops_id_t *ops_id);
    void (*reload_lua_plugins)(funnel_ops_id_t *ops_id);
    void (*apply_filter)(funnel_ops_id_t *ops_id);

    gboolean (*browser_open_url)(const gchar *url);
    void (*browser_open_data_file)(const gchar *filename);

    struct progdlg* (*new_progress_window)(funnel_ops_id_t *ops_id, const gchar* label, const gchar* task, gboolean terminate_is_stop, gboolean *stop_flag);
    void (*update_progress)(struct progdlg*, float pr, const gchar* task);
    void (*destroy_progress_window)(struct progdlg*);
} funnel_ops_t;

WS_DLL_PUBLIC const funnel_ops_t* funnel_get_funnel_ops(void);
WS_DLL_PUBLIC void funnel_set_funnel_ops(const funnel_ops_t*);

WS_DLL_PUBLIC void funnel_register_menu(const char *name,
                                 register_stat_group_t group,
                                 funnel_menu_callback callback,
                                 gpointer callback_data,
                                 funnel_menu_callback_data_free callback_data_free,
                                 gboolean retap);
void funnel_deregister_menus(void (*callback)(gpointer));

typedef void (*funnel_registration_cb_t)(const char *name,
                                         register_stat_group_t group,
                                         funnel_menu_callback callback,
                                         gpointer callback_data,
                                         gboolean retap);
typedef void (*funnel_deregistration_cb_t)(funnel_menu_callback callback);

WS_DLL_PUBLIC void funnel_register_all_menus(funnel_registration_cb_t r_cb);
WS_DLL_PUBLIC void funnel_reload_menus(funnel_deregistration_cb_t d_cb,
                                       funnel_registration_cb_t r_cb);
WS_DLL_PUBLIC void funnel_cleanup(void);

/**
 * Signature of function that can be called from a custom packet menu entry
 */
typedef void (* funnel_packet_menu_callback)(gpointer, GPtrArray*);

/**
 * Signature of callback function to register packet menu entries
 */
typedef void (*funnel_registration_packet_cb_t)(const char *name,
                                         const char *required_fields,
                                         funnel_packet_menu_callback callback,
                                         gpointer callback_data,
                                         gboolean retap);

/**
 * Entry point for Wireshark GUI to obtain all registered packet menus
 *
 * @param r_cb function which will be called to register each packet menu entry
 */
WS_DLL_PUBLIC void funnel_register_all_packet_menus(funnel_registration_packet_cb_t r_cb);

/**
 * Entry point for Lua code to register a packet menu
 *
 * @param name packet menu item's name
 * @param required_fields fields required to be present for the packet menu to be displayed
 * @param callback function called when the menu item is invoked. The function must take one argument and return nothing.
 * @param callback_data Lua state for the callback function
 * @param retap whether or not to rescan all packets
 */
WS_DLL_PUBLIC void funnel_register_packet_menu(const char *name,
                                 const char *required_fields,
                                 funnel_packet_menu_callback callback,
                                 gpointer callback_data,
                                 gboolean retap);

/**
 * Returns whether the packet menus have been modified since they were last registered
 *
 * @return TRUE if the packet menus were modified since the last registration
 */
WS_DLL_PUBLIC gboolean funnel_packet_menus_modified(void);

/*
 * The functions below allow registering a funnel "console". A console is just a GUI
 * dialog that has an input text widget, an output text widget, and for each user
 * generated input it calls a callback to generate the corresponding output.
 * Very simple... each console type has a name and an entry in the Tools menu to invoke it.
 * Mainly used to present a Lua console to allow inspecting Lua internals and run Lua
 * code using the embedded interpreter.
 */

/**
 * Signature of function that can be called to evaluate code.
  * Returns zero on success, -1 if precompilation failed, positive for runtime errors.
 */
typedef int (*funnel_console_eval_cb_t)(const char *console_input,
                                            char **error_ptr,
                                            char **error_hint,
                                            void *callback_data);

/**
 * Signature of function that can be called to install a logger.
 */
typedef void (*funnel_console_open_cb_t)(void (*print_func)(const char *, void *), void *print_data, void *callback_data);

/**
 * Signature of function that can be called to remove logger.
 */
typedef void (*funnel_console_close_cb_t)(void *callback_data);

/**
 * Signature of function that can be called to free user data.
 */
typedef void (*funnel_console_data_free_cb_t)(void *callback_data);

/**
 * Entry point for Lua code to register a console menu
 */
WS_DLL_PUBLIC void funnel_register_console_menu(const char *name,
                                funnel_console_eval_cb_t eval_cb,
                                funnel_console_open_cb_t open_cb,
                                funnel_console_close_cb_t close_cb,
                                void *callback_data,
                                funnel_console_data_free_cb_t free_data);

/**
 * Signature of callback function to register console menu entries
 */
typedef void (*funnel_registration_console_cb_t)(const char *name,
                                funnel_console_eval_cb_t eval_cb,
                                funnel_console_open_cb_t open_cb,
                                funnel_console_close_cb_t close_cb,
                                void *callback_data);

/**
 * Entry point for Wireshark GUI to obtain all registered console menus
 *
 * @param r_cb function which will be called to register each console menu entry
 */
WS_DLL_PUBLIC void funnel_register_all_console_menus(funnel_registration_console_cb_t r_cb);

extern void initialize_funnel_ops(void);

extern void funnel_dump_all_text_windows(void);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __FUNNEL_H__ */