2 * Definitions for preference handling routines
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
16 #endif /* __cplusplus */
20 #include <epan/params.h>
21 #include <epan/range.h>
23 #include <wsutil/color.h>
25 #include "ws_symbol_export.h"
28 #define DEF_HEIGHT 550
30 #define MAX_VAL_LEN 1024
32 #define TAP_UPDATE_DEFAULT_INTERVAL 3000
33 #define ST_DEF_BURSTRES 5
34 #define ST_DEF_BURSTLEN 100
35 #define ST_MAX_BURSTRES 600000 /* somewhat arbirary limit of 10 minutes */
36 #define ST_MAX_BURSTBUCKETS 100 /* somewhat arbirary limit - more buckets degrade performance */
39 struct _e_addr_resolve;
42 * Convert a string listing name resolution types to a bitmask of
45 * Set "*name_resolve" to the bitmask, and return '\0', on success;
46 * return the bad character in the string on error.
49 char string_to_name_resolve(const char *string, struct _e_addr_resolve *name_resolve);
52 * Modes for the starting directory in File Open dialogs.
54 #define FO_STYLE_LAST_OPENED 0 /* start in last directory we looked at */
55 #define FO_STYLE_SPECIFIED 1 /* start in specified directory */
60 #define TB_STYLE_ICONS 0
61 #define TB_STYLE_TEXT 1
62 #define TB_STYLE_BOTH 2
67 #define COLOR_STYLE_DEFAULT 0
68 #define COLOR_STYLE_FLAT 1
69 #define COLOR_STYLE_GRADIENT 2
71 #define COLOR_STYLE_ALPHA 0.25
74 * Types of layout of summary/details/hex panes.
77 layout_unused, /* entry currently unused */
91 layout_pane_content_none,
92 layout_pane_content_plist,
93 layout_pane_content_pdetails,
94 layout_pane_content_pbytes
95 } layout_pane_content_e;
98 * open console behaviour (win32 only)
107 * Places version information will show up
110 version_welcome_only,
134 UPDATE_CHANNEL_DEVELOPMENT,
135 UPDATE_CHANNEL_STABLE
136 } software_update_channel_e;
138 typedef struct _e_prefs {
141 color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg;
142 color_t gui_text_valid, gui_text_invalid, gui_text_deprecated;
143 gboolean restore_filter_after_following_stream;
144 gint gui_toolbar_main_style;
145 gchar *gui_qt_font_name;
146 color_t gui_active_fg;
147 color_t gui_active_bg;
148 gint gui_active_style;
149 color_t gui_inactive_fg;
150 color_t gui_inactive_bg;
151 gint gui_inactive_style;
152 color_t gui_marked_fg;
153 color_t gui_marked_bg;
154 color_t gui_ignored_fg;
155 color_t gui_ignored_bg;
156 gchar *gui_colorized_fg;
157 gchar *gui_colorized_bg;
158 gboolean gui_geometry_save_position;
159 gboolean gui_geometry_save_size;
160 gboolean gui_geometry_save_maximized;
161 console_open_e gui_console_open;
162 guint gui_recent_df_entries_max;
163 guint gui_recent_files_count_max;
164 guint gui_fileopen_style;
165 gchar *gui_fileopen_dir;
166 guint gui_fileopen_preview;
167 gboolean gui_ask_unsaved;
168 gboolean gui_find_wrap;
169 gchar *gui_window_title;
170 gchar *gui_prepend_window_title;
171 gchar *gui_start_title;
172 version_info_e gui_version_placement;
173 layout_type_e gui_layout_type;
174 layout_pane_content_e gui_layout_content_1;
175 layout_pane_content_e gui_layout_content_2;
176 layout_pane_content_e gui_layout_content_3;
177 gchar *gui_interfaces_hide_types;
178 gboolean gui_interfaces_show_hidden;
179 gboolean gui_interfaces_remote_display;
180 gint console_log_level;
181 gchar *capture_device;
182 gchar *capture_devices_linktypes;
183 gchar *capture_devices_descr;
184 gchar *capture_devices_hide;
185 gchar *capture_devices_monitor_mode;
186 gchar *capture_devices_buffersize;
187 gchar *capture_devices_snaplen;
188 gchar *capture_devices_pmode;
189 gchar *capture_devices_filter; /* XXX - Mostly unused. Deprecate? */
190 gboolean capture_prom_mode;
191 gboolean capture_pcap_ng;
192 gboolean capture_real_time;
193 gboolean capture_auto_scroll; /* XXX - Move to recent */
194 gboolean capture_no_interface_load;
195 gboolean capture_no_extcap;
196 gboolean capture_show_info;
197 GList *capture_columns;
198 guint tap_update_interval;
199 gboolean display_hidden_proto_items;
200 gboolean display_byte_fields_with_spaces;
201 gboolean enable_incomplete_dissectors_check;
202 gboolean incomplete_dissectors_check_debug;
203 gboolean strict_conversation_tracking_heuristics;
204 gboolean filter_expressions_old; /* TRUE if old filter expressions preferences were loaded. */
205 gboolean gui_update_enabled;
206 software_update_channel_e gui_update_channel;
207 gint gui_update_interval;
208 gchar *saved_at_version;
209 gboolean unknown_prefs; /* unknown or obsolete pref(s) */
210 gboolean unknown_colorfilters; /* Warn when saving unknown or obsolete color filters. */
211 gboolean gui_qt_packet_list_separator;
212 gboolean gui_qt_show_selected_packet;
213 gboolean gui_qt_show_file_load_time;
214 gboolean gui_packet_editor; /* Enable Packet Editor */
215 elide_mode_e gui_packet_list_elide_mode;
216 gboolean gui_packet_list_show_related;
217 gboolean gui_packet_list_show_minimap;
218 gboolean st_enable_burstinfo;
219 gboolean st_burst_showcount;
220 gint st_burst_resolution;
221 gint st_burst_windowlen;
222 gboolean st_sort_casesensitve;
223 gboolean st_sort_rng_fixorder;
224 gboolean st_sort_rng_nameonly;
225 gint st_sort_defcolflag;
226 gboolean st_sort_defdescending;
227 gboolean st_sort_showfullname;
228 gboolean extcap_save_on_start;
231 WS_DLL_PUBLIC e_prefs prefs;
234 * Routines to let modules that have preference settings register
235 * themselves by name, and to let them register preference settings
240 struct pref_custom_cbs;
242 typedef struct pref_module module_t;
244 /** Sets up memory used by proto routines. Called at program startup */
245 void prefs_init(void);
247 /** Reset preferences to default values. Called at profile change */
248 WS_DLL_PUBLIC void prefs_reset(void);
250 /** Frees memory used by proto routines. Called at program shutdown */
251 void prefs_cleanup(void);
253 /** Provide a hint about the darkness of the current UI theme so that we can adjust colors when needed */
254 WS_DLL_PUBLIC void prefs_set_gui_theme_is_dark(gboolean is_dark);
257 * Register that a protocol has preferences.
259 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
262 * Register an alias for a preference module.
264 WS_DLL_PUBLIC void prefs_register_module_alias(const char *name, module_t *module);
267 * Deregister preferences from a protocol.
269 void prefs_deregister_protocol(int id);
272 * Register that a statistical tap has preferences.
274 * "name" is a name for the tap to use on the command line with "-o"
275 * and in preference files.
277 * "title" is a short human-readable name for the tap.
279 * "description" is a longer human-readable description of the tap.
281 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
282 const char *description, void (*apply_cb)(void));
285 * Register that a codec has preferences.
287 * "name" is a name for the codec to use on the command line with "-o"
288 * and in preference files.
290 * "title" is a short human-readable name for the codec.
292 * "description" is a longer human-readable description of the codec.
294 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
295 const char *description, void (*apply_cb)(void));
298 * Register that a protocol has preferences and group it under a single
301 #define PREFERENCE_GROUPING
302 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
303 void (*apply_cb)(void));
306 * Register that a protocol used to have preferences but no longer does,
307 * by creating an "obsolete" module for it.
309 module_t *prefs_register_protocol_obsolete(int id);
312 * Callback function for module list scanners.
314 typedef guint (*module_cb)(module_t *module, gpointer user_data);
317 * Returns TRUE if module has any submodules
319 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
322 * Call a callback function, with a specified argument, for each module
323 * in the list of all modules. (This list does not include subtrees.)
325 * Ignores "obsolete" modules; their sole purpose is to allow old
326 * preferences for dissectors that no longer have preferences to be
327 * silently ignored in preference files.
329 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
332 * Call a callback function, with a specified argument, for each submodule
333 * of specified modules. If the module is NULL, goes through the top-level
334 * list in the display tree of modules.
336 * Ignores "obsolete" modules; their sole purpose is to allow old
337 * preferences for dissectors that no longer have preferences to be
338 * silently ignored in preference files. Does not ignore subtrees,
339 * as this can be used when walking the display tree of modules.
341 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
344 * Call the "apply" callback function for each module if any of its
345 * preferences have changed, and then clear the flag saying its
346 * preferences have changed, as the module has been notified of that
349 WS_DLL_PUBLIC void prefs_apply_all(void);
352 * Call the "apply" callback function for a specific module if any of
353 * its preferences have changed, and then clear the flag saying its
354 * preferences have changed, as the module has been notified of that
357 WS_DLL_PUBLIC void prefs_apply(module_t *module);
362 typedef struct preference pref_t;
365 * Returns TRUE if the given protocol has registered preferences.
367 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
370 * Returns the module title of a registered protocol (or NULL if unknown).
372 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
374 /** Given a module name, return a pointer to its pref_module struct,
375 * or NULL if it's not found.
377 * @param name The preference module name. Usually the same as the protocol
379 * @return A pointer to the corresponding preference module, or NULL if it
382 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
384 /** Given a module name, and a preference name return a pointer to the given
385 * module's given preference or NULL if it's not found.
387 * @param module The preference module name. Usually the same as the protocol
389 * @param pref The preference name, e.g. "desegment".
390 * @return A pointer to the corresponding preference, or NULL if it
393 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
396 * Register a preference with an unsigned integral value.
398 WS_DLL_PUBLIC void prefs_register_uint_preference(module_t *module, const char *name,
399 const char *title, const char *description, guint base, guint *var);
402 * prefs_register_ callers must conform to the following:
404 * Names must be in lowercase letters only (underscore allowed).
405 * Titles and descriptions must be valid UTF-8 or NULL.
406 * Titles must be short (less than 80 characters)
407 * Titles must not contain newlines.
411 * Register a preference with an Boolean value.
413 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
414 const char *title, const char *description, gboolean *var);
417 * Register a preference with an enumerated value.
419 WS_DLL_PUBLIC void prefs_register_enum_preference(module_t *module, const char *name,
420 const char *title, const char *description, gint *var,
421 const enum_val_t *enumvals, gboolean radio_buttons);
424 * Register a preference with a character-string value.
426 WS_DLL_PUBLIC void prefs_register_string_preference(module_t *module, const char *name,
427 const char *title, const char *description, const char **var);
430 * Register a preference with a file name (string) value.
431 * File name preferences are basically like string preferences
432 * except that the GUI gives the user the ability to browse for the
435 WS_DLL_PUBLIC void prefs_register_filename_preference(module_t *module, const char *name,
436 const char *title, const char *description, const char **var, gboolean for_writing);
439 * Register a preference with a directory name (string) value.
440 * Directory name preferences are basically like string preferences
441 * except that the GUI gives the user the ability to browse for a
444 WS_DLL_PUBLIC void prefs_register_directory_preference(module_t *module, const char *name,
445 const char *title, const char *description, const char **var);
448 * Register a preference with a ranged value.
450 WS_DLL_PUBLIC void prefs_register_range_preference(module_t *module, const char *name,
451 const char *title, const char *description, range_t **var,
455 * Register a static text 'preference'. It can be used to add some info/explanation.
457 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
458 const char *title, const char *description);
461 * Register a uat 'preference'. It adds a button that opens the uat's window in the
462 * preferences tab of the module.
464 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
465 const char *name, const char* title, const char *description, struct epan_uat* uat);
468 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
469 * preferences tab of the module.
471 WS_DLL_PUBLIC void prefs_register_uat_preference_qt(module_t *module,
472 const char *name, const char* title, const char *description, struct epan_uat* uat);
476 * Register a color preference. Currently does not have any "GUI Dialog" support
477 * so the color data needs to be managed independently. Currently used by the
478 * "GUI preferences" to aid in reading/writing the preferences file, but the
479 * "data" is still managed by the specific "GUI preferences" dialog.
481 void prefs_register_color_preference(module_t *module, const char *name,
482 const char *title, const char *description, color_t *color);
485 * Register a custom preference. Currently does not have any "GUI Dialog" support
486 * so data needs to be managed independently. Currently used by the
487 * "GUI preferences" to aid in reading/writing the preferences file, but the
488 * "data" is still managed by the specific "GUI preferences" dialog.
490 void prefs_register_custom_preference(module_t *module, const char *name,
491 const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
495 * Register a (internal) "Decode As" preference with a ranged value.
497 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
498 const char *title, const char *description, range_t **var,
502 * Register a (internal) "Decode As" preference with an unsigned integral value
503 * for a dissector table.
505 void prefs_register_decode_as_preference(module_t *module, const char *name,
506 const char *title, const char *description, guint *var);
509 * Register a preference that used to be supported but no longer is.
511 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
515 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
518 * Call a callback function, with a specified argument, for each preference
521 * If any of the callbacks return a non-zero value, stop and return that
522 * value, otherwise return 0.
524 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
527 /* Parse through a list of comma-separated, possibly quoted strings.
528 * Return a list of the string data.
530 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
532 /* Clear the given list of string data. */
533 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
535 /** Fetch a short preference type name, e.g. "Integer".
537 * @param pref A preference.
539 * @return The preference type name. May be NULL.
542 const char *prefs_pref_type_name(pref_t *pref);
544 /** Fetch a long description of the preference type
546 * @param pref A preference.
548 * @return A description of the preference type including allowed
549 * values for enums. The description may include newlines. Must be
553 char *prefs_pref_type_description(pref_t *pref);
555 /** Fetch a string representation of the preference.
557 * @param pref A preference.
558 * @param source Which value of the preference to return, see pref_source_t.
560 * @return A string representation of the preference. Must be g_free()d.
563 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
565 /* Read the preferences file, fill in "prefs", and return a pointer to it.
567 If we got an error (other than "it doesn't exist") we report it through
570 This is called by epan_load_settings(); programs should call that
571 rather than individually calling the routines it calls. */
572 extern e_prefs *read_prefs(void);
574 /* Write out "prefs" to the user's preferences file, and return 0.
576 If we got an error, stuff a pointer to the path of the preferences file
577 into "*pf_path_return", and return the errno. */
578 WS_DLL_PUBLIC int write_prefs(char **);
581 * Result of setting a preference.
584 PREFS_SET_OK, /* succeeded */
585 PREFS_SET_SYNTAX_ERR, /* syntax error in string */
586 PREFS_SET_NO_SUCH_PREF, /* no such preference */
587 PREFS_SET_OBSOLETE /* preference used to exist but no longer does */
591 * Given a string of the form "<pref name>:<pref value>", as might appear
592 * as an argument to a "-o" option, parse it and set the preference in
593 * question. Return an indication of whether it succeeded or failed
596 * For syntax errors (return value PREFS_SET_SYNTAX_ERR), details (when
597 * available) are written into "errmsg" which must be freed with g_free.
599 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
602 * Get or set a preference's obsolete status. These can be used to make a
603 * preference obsolete after startup so that we can fetch its value but
604 * keep it from showing up in the prefrences dialog.
606 gboolean prefs_get_preference_obsolete(pref_t *pref);
607 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
610 * Get current preference uint value. This allows the preference structure
611 * to remain hidden from those that doesn't really need it
613 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
616 * Get the current range preference value (maintained by pref, so it doesn't need to be freed). This allows the
617 * preference structure to remain hidden from those that doesn't really need it.
619 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
622 * Returns TRUE if the given device is hidden
624 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
627 * Returns TRUE if the given device should capture in monitor mode by default
629 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
631 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
634 * Returns TRUE if the layout pane content is enabled
636 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
640 #endif /* __cplusplus */
645 * Editor modelines - http://www.wireshark.org/tools/modelines.html
650 * indent-tabs-mode: nil
653 * vi: set shiftwidth=4 tabstop=8 expandtab:
654 * :indentSize=4:tabSize=8:noTabs=true: