regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / epan / plugin_if.h
bloba168060dda74241c50366d2f5e75371b45088d9b
1 /** @file
2 * An API for Wireshark plugins
4 * This enables wireshark dissectors, especially those implemented by plugins
5 * to register menubar entries, which then will call a pre-defined callback
6 * function for the dissector or plugin.
8 * Also it implements additional methods, which allow plugins to interoperate
9 * with the main GUI.
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
17 #ifndef EPAN_PLUGIN_IF_H
18 #define EPAN_PLUGIN_IF_H
20 #include "ws_symbol_export.h"
21 #include "ws_attributes.h"
23 #include <glib.h>
24 #include <epan/epan.h>
25 #include <epan/packet_info.h>
26 #include <cfile.h>
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
32 #define EXT_MENUBAR_MAX_DEPTH 5
34 typedef enum
36 EXT_MENUBAR_GTK_GUI,
37 EXT_MENUBAR_QT_GUI
38 } ext_menubar_gui_type;
40 /* menubar callback */
41 typedef void (*ext_menubar_action_cb)(ext_menubar_gui_type gui_type, void *gui_object, void *user_data);
43 typedef enum
45 EXT_MENUBAR_MENU,
46 EXT_MENUBAR_ITEM,
47 EXT_MENUBAR_SEPARATOR,
48 EXT_MENUBAR_URL
49 } ext_menubar_entry_t;
51 typedef struct _ext_menubar_t ext_menubar_t;
52 typedef ext_menubar_t ext_menu_t;
54 struct _ext_menubar_t
56 ext_menubar_entry_t type;
57 ext_menu_t * parent;
58 int proto;
59 GList * children;
60 unsigned submenu_cnt;
61 unsigned item_cnt;
63 char * name;
64 char * label;
66 char * tooltip;
67 bool is_plugin;
68 void *user_data;
70 ext_menubar_action_cb callback;
72 char * parent_menu;
75 typedef void (*ext_toolbar_action_cb)(void *toolbar_item, void *item_data, void *user_data);
77 typedef enum
79 EXT_TOOLBAR_BAR,
80 EXT_TOOLBAR_ITEM
81 } ext_toolbar_entry_t;
83 typedef enum
85 EXT_TOOLBAR_BOOLEAN,
86 EXT_TOOLBAR_BUTTON,
87 EXT_TOOLBAR_STRING,
88 EXT_TOOLBAR_SELECTOR
89 } ext_toolbar_item_t;
91 typedef struct _ext_toolbar_value_t
93 char * value;
94 char * display;
96 bool is_default;
98 } ext_toolbar_value_t;
100 typedef struct _ext_toolbar_t
102 ext_toolbar_entry_t type;
104 GList * children;
105 unsigned submenu_cnt;
106 unsigned item_cnt;
108 char * name;
109 char * defvalue;
110 char * tooltip;
111 void *user_data;
113 bool is_required;
114 bool capture_only;
115 ext_toolbar_item_t item_type;
117 GList * values;
118 char * regex;
120 ext_toolbar_action_cb callback;
122 } ext_toolbar_t;
124 typedef enum
126 EXT_TOOLBAR_UPDATE_VALUE,
127 EXT_TOOLBAR_UPDATE_DATA,
128 EXT_TOOLBAR_UPDATE_DATABYINDEX,
129 EXT_TOOLBAR_UPDATE_DATA_ADD,
130 EXT_TOOLBAR_UPDATE_DATA_REMOVE,
131 EXT_TOOLBAR_SET_ACTIVE
132 } ext_toolbar_update_type_t;
134 typedef struct _ext_toolbar_update_t
136 ext_toolbar_update_type_t type;
137 bool silent;
138 void *user_data;
139 void *data_index;
140 } ext_toolbar_update_t;
142 /* Registers a new main menu.
144 * This will register a new main menu entry, underneath all other menu entries will
145 * be sorted
147 * @param proto_id the proto item for the protocol this menu entry belongs too
148 * @param name the entry name (the internal used one) for the menu item
149 * @param menulabel the entry label (the displayed name) for the menu item
150 * @param is_plugin must be set to true for plugin registration
152 WS_DLL_PUBLIC ext_menu_t * ext_menubar_register_menu(
153 int proto_id, const char * menulabel, bool is_plugin);
155 /* Sets a parent menu for the user menu.
157 * This will set a parent menu, which allows this menu to be filtered underneath
158 * the given menu as a submenu. If the parent menu does not exist, the main menu
159 * will be used
161 * @param menu the menu for which to add the entry
162 * @param parentmenu a valid menu name for the parent menu
164 WS_DLL_PUBLIC ext_menu_t * ext_menubar_set_parentmenu(
165 ext_menu_t * menu, const char * parentmenu);
167 /* Registers a new main menu.
169 * This will register a new sub menu entry, underneath the parent menu
171 * @param parent the parent menu for this submenu
172 * @param name the entry name (the internal used one) for the menu item
173 * @param menulabel the entry label (the displayed name) for the menu item
175 WS_DLL_PUBLIC ext_menu_t * ext_menubar_add_submenu(
176 ext_menu_t * parent, const char *menulabel);
178 /* Registers a new menubar entry.
180 * This registers a new menubar entry, which will have the given name, and
181 * call the provided callback on activation
183 * @param parent_menu the parent menu for this entry
184 * @param name the entry name (the internal used one) for the menu item
185 * @param label the entry label (the displayed name) for the menu item
186 * @param tooltip a tooltip to be displayed on mouse-over
187 * @param callback the action which will be invoked after click on the menu item
189 WS_DLL_PUBLIC void ext_menubar_add_entry(
190 ext_menu_t * parent_menu,
191 const char *label,
192 const char *tooltip,
193 ext_menubar_action_cb callback,
194 void *user_data);
196 /* Registers a new separator entry.
198 * @note This will not work using the legacy GTK interface, due to
199 * restrictions on how separators are handled in the menu
201 * @param parent_menu the parent menu for this entry
203 WS_DLL_PUBLIC void ext_menubar_add_separator(ext_menu_t *parent_menu);
205 /* Registers a entry for a website call
207 * This registers a new menubar entry, which will call the given website, using
208 * the predefined webbrowser
210 * @param parent_menu the parent menu for this entry
211 * @param name the entry name (the internal used one) for the menu item
212 * @param label the entry label (the displayed name) for the menu item
213 * @param tooltip a tooltip to be displayed on mouse-over
214 * @param url the url for the website
216 WS_DLL_PUBLIC void ext_menubar_add_website(ext_menu_t * parent, const char *label,
217 const char *tooltip, const char *url);
219 /* Registers a toolbar.
221 * This will register a new toolbar, which can contain various gui elements
223 * @param toolbar_label the entry label (the displayed name) for the toolbar item
225 WS_DLL_PUBLIC ext_toolbar_t * ext_toolbar_register_toolbar(const char * toolbar_label);
227 /* Removes a toolbar from the system.
229 * This will remove the provided toolbar from the application
231 * @param toolbar the toolbar to be removed
233 WS_DLL_PUBLIC void ext_toolbar_unregister_toolbar(ext_toolbar_t * toolbar);
235 /* Removes a toolbar from the system by providing the name of the toolbar.
237 * This will remove the provided toolbar from the application
239 * @param toolbar_name the name of the toolbar to be removed
241 WS_DLL_PUBLIC void ext_toolbar_unregister_toolbar_by_name(const char * toolbar_name);
243 /* Registers a new toolbar entry.
245 * This registers a new toolbar entry, which will have the given name, and
246 * call the provided callback on activation
248 * The callback will be fired on different events, depending on the item type
249 * and the implementation of the item type in a GUI element. The following types should
250 * behave as following
252 * * EXT_TOOLBAR_STRING - Every change of the content fires the callback
253 * * EXT_TOOLBAR_BOOLEAN - Every change of the value fires the callback
254 * * EXT_TOOLBAR_BUTTON - if the button is pressed, the callback fires
255 * * EXT_TOOLBAR_SELECTION - every time the selection changes the callback fires
257 * @param parent_bar the parent toolbar for this entry
258 * @param name the entry name (the internal used one) for the item
259 * @param label the entry label (the displayed name) for the item
260 * @param defvalue the default value for the toolbar element
261 * @param tooltip a tooltip to be displayed on mouse-over
262 * @param capture_only entry is only active, if capture is active
263 * @param callback the action which will be invoked after click on the item
264 * @param value_list a non-null list of values, if the item type is EXT_TOOLBAR_SELECTOR
265 * @param valid_regex a validation regular expression for EXT_TOOLBAR_STRING
267 * @return a reference to the newly created toolbar entry
269 WS_DLL_PUBLIC ext_toolbar_t * ext_toolbar_add_entry(
270 ext_toolbar_t * parent_bar,
271 ext_toolbar_item_t type,
272 const char *label,
273 const char *defvalue,
274 const char *tooltip,
275 bool capture_only,
276 GList * value_list,
277 bool is_required,
278 const char * valid_regex,
279 ext_toolbar_action_cb callback,
280 void *user_data);
282 WS_DLL_PUBLIC GList * ext_toolbar_add_val(GList * entries, char * value, char * display, bool is_default);
284 WS_DLL_PUBLIC void ext_toolbar_register_update_cb(ext_toolbar_t * entry, ext_toolbar_action_cb callback, void *item_data);
286 /* Updates the entry values
288 * Update the values for the entry, it is up to the implemented widget, to interpret the
289 * given character values
291 * @param entry the entry to be updated
292 * @param data the data for the entry
293 * @param silent the update for the entry should not trigger additional actions
295 WS_DLL_PUBLIC void ext_toolbar_update_value(ext_toolbar_t * entry, void *data, bool silent);
297 /* Updates the entry data
299 * Update the data for the entry, it is up to the implemented widget, to interpret the given character data
301 * @param entry the entry to be updated
302 * @param data the data for the entry
303 * @param silent the update for the entry should not trigger additional actions
305 WS_DLL_PUBLIC void ext_toolbar_update_data(ext_toolbar_t * entry, void *data, bool silent);
307 /* Updates the entry data by index
309 * This is used to update a single entry of a selector list, by giving it's value and a new display
310 * entry
312 * @param entry the toolbar item to be updated
313 * @param data the display data for the entry
314 * @param idx the value for the entry to be updated
315 * @param silent the update for the entry should not trigger additional actions
317 WS_DLL_PUBLIC void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, void *data, void *idx, bool silent);
319 /* Adds the entry data by index
321 * This is used to add a single entry to a selector list, by giving it's new value and a new display
322 * entry. If the value already exists, the selector may choose to ignore the command
324 * @param entry the toolbar item to be updated
325 * @param data the display data for the entry to be added
326 * @param idx the value for the entry to be added
327 * @param silent the adding of the entry should not trigger additional actions
329 WS_DLL_PUBLIC void ext_toolbar_update_data_add_entry(ext_toolbar_t * entry, void *data, void *idx, bool silent);
331 /* Removes an entry data by index
333 * This is used to remove a single entry to a selector list, by giving it's value and a display
334 * entry. If the value already exists, the selector may choose to ignore the command. Both value
335 * and display must be given, as it is not established, how the entry is found in the selector list
337 * @param entry the toolbar item to be updated
338 * @param data the display data for the entry to be removed
339 * @param idx the value for the entry to be removed
340 * @param silent the removal of the entry should not trigger additional actions
342 WS_DLL_PUBLIC void ext_toolbar_update_data_remove_entry(ext_toolbar_t * entry, void *data, void *idx, bool silent);
344 /* Search for and return if found an entry from the toolbar with the given label */
345 WS_DLL_PUBLIC ext_toolbar_t * ext_toolbar_entry_by_label(const ext_toolbar_t * toolbar, const char * label);
347 /* Set the ui element for the given enry to the status */
348 WS_DLL_PUBLIC void ext_toolbar_update_data_set_active(ext_toolbar_t * entry, bool status);
351 * Structure definition for the plugin_if_get_ws_info function
354 typedef struct _ws_info_t
356 bool ws_info_supported; /* false if no libpcap */
357 file_state cf_state; /* Current state of capture file */
358 char *cf_filename; /* Name of capture file */
359 uint32_t cf_count; /* Total number of frames */
360 uint32_t cf_framenr; /**< Currently displayed frame number */
361 bool frame_passed_dfilter; /**< true = display, false = no display */
362 } ws_info_t;
366 * Enumeration of possible actions, which are registered in GUI interfaces
368 typedef enum
370 /* Applies a given string as filter */
371 PLUGIN_IF_FILTER_ACTION_APPLY,
373 /* Prepares the given string as filter */
374 PLUGIN_IF_FILTER_ACTION_PREPARE,
376 /* Saves a preference entry */
377 PLUGIN_IF_PREFERENCE_SAVE,
379 /* Jumps to the provided frame number */
380 PLUGIN_IF_GOTO_FRAME,
382 /* Gets status information about the currently loaded capture file */
383 PLUGIN_IF_GET_WS_INFO,
385 /* Gets information from frame_data for current packet */
386 PLUGIN_IF_GET_FRAME_DATA,
388 /* Gets information from capture_file */
389 PLUGIN_IF_GET_CAPTURE_FILE,
391 /* Remove toolbar */
392 PLUGIN_IF_REMOVE_TOOLBAR
394 } plugin_if_callback_t;
397 typedef void (*plugin_if_gui_cb)(GHashTable * data_set);
399 WS_DLL_PUBLIC void plugin_if_register_gui_cb(plugin_if_callback_t actionType, plugin_if_gui_cb callback);
401 /* Applies the given filter string as display filter */
402 WS_DLL_PUBLIC void plugin_if_apply_filter(const char * filter_string, bool force);
404 /* Saves the given preference to the main preference storage */
405 WS_DLL_PUBLIC void plugin_if_save_preference(const char * pref_module, const char * pref_key, const char * pref_value);
407 /* Jumps to the given frame number */
408 WS_DLL_PUBLIC void plugin_if_goto_frame(uint32_t framenr);
410 /* Takes a snapshot of status information from Wireshark */
411 WS_DLL_PUBLIC void plugin_if_get_ws_info(ws_info_t ** ws_info);
413 typedef void* (*plugin_if_frame_data_cb)(frame_data*, void*);
414 /* Gets frame_data for current packet, data are extracted by extract_cb */
415 WS_DLL_PUBLIC void* plugin_if_get_frame_data(plugin_if_frame_data_cb extract_cb, void *user_data);
417 typedef void* (*plugin_if_capture_file_cb)(capture_file*, void*);
418 /* Gets capture_file, data are extracted by extract_cb */
419 WS_DLL_PUBLIC void* plugin_if_get_capture_file(plugin_if_capture_file_cb extract_cb, void* user_data);
421 /* Private Method for retrieving the menubar entries
423 * Is only to be used by the UI interfaces to retrieve the menu entries
425 WS_DLL_PUBLIC GList * ext_menubar_get_entries(void);
427 /* Private Method for retrieving the toolbar entries
429 * Is only to be used by the UI interfaces to retrieve the toolbar entries
431 WS_DLL_PUBLIC GList * ext_toolbar_get_entries(void);
433 #ifdef __cplusplus
435 #endif /* __cplusplus */
437 #endif /* EPAN_PLUGIN_IF_H */
440 * Editor modelines
442 * Local Variables:
443 * c-basic-offset: 4
444 * tab-width: 8
445 * indent-tabs-mode: nil
446 * End:
448 * ex: set shiftwidth=4 tabstop=8 expandtab:
449 * :indentSize=4:tabSize=8:noTabs=true: