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_autocomplete_filter;
169 gboolean gui_find_wrap;
170 gchar *gui_window_title;
171 gchar *gui_prepend_window_title;
172 gchar *gui_start_title;
173 version_info_e gui_version_placement;
174 layout_type_e gui_layout_type;
175 layout_pane_content_e gui_layout_content_1;
176 layout_pane_content_e gui_layout_content_2;
177 layout_pane_content_e gui_layout_content_3;
178 gchar *gui_interfaces_hide_types;
179 gboolean gui_interfaces_show_hidden;
180 gboolean gui_interfaces_remote_display;
181 gint console_log_level;
182 gchar *capture_device;
183 gchar *capture_devices_linktypes;
184 gchar *capture_devices_descr;
185 gchar *capture_devices_hide;
186 gchar *capture_devices_monitor_mode;
187 gchar *capture_devices_buffersize;
188 gchar *capture_devices_snaplen;
189 gchar *capture_devices_pmode;
190 gchar *capture_devices_filter; /* XXX - Mostly unused. Deprecate? */
191 gboolean capture_prom_mode;
192 gboolean capture_pcap_ng;
193 gboolean capture_real_time;
194 gboolean capture_auto_scroll; /* XXX - Move to recent */
195 gboolean capture_no_interface_load;
196 gboolean capture_no_extcap;
197 gboolean capture_show_info;
198 GList *capture_columns;
199 guint tap_update_interval;
200 gboolean display_hidden_proto_items;
201 gboolean display_byte_fields_with_spaces;
202 gboolean enable_incomplete_dissectors_check;
203 gboolean incomplete_dissectors_check_debug;
204 gboolean strict_conversation_tracking_heuristics;
205 gboolean filter_expressions_old; /* TRUE if old filter expressions preferences were loaded. */
206 gboolean gui_update_enabled;
207 software_update_channel_e gui_update_channel;
208 gint gui_update_interval;
209 gchar *saved_at_version;
210 gboolean unknown_prefs; /* unknown or obsolete pref(s) */
211 gboolean unknown_colorfilters; /* Warn when saving unknown or obsolete color filters. */
212 gboolean gui_qt_packet_list_separator;
213 gboolean gui_qt_show_selected_packet;
214 gboolean gui_qt_show_file_load_time;
215 gboolean gui_packet_editor; /* Enable Packet Editor */
216 elide_mode_e gui_packet_list_elide_mode;
217 gboolean gui_packet_list_show_related;
218 gboolean gui_packet_list_show_minimap;
219 gboolean st_enable_burstinfo;
220 gboolean st_burst_showcount;
221 gint st_burst_resolution;
222 gint st_burst_windowlen;
223 gboolean st_sort_casesensitve;
224 gboolean st_sort_rng_fixorder;
225 gboolean st_sort_rng_nameonly;
226 gint st_sort_defcolflag;
227 gboolean st_sort_defdescending;
228 gboolean st_sort_showfullname;
229 gboolean extcap_save_on_start;
232 WS_DLL_PUBLIC e_prefs prefs;
235 * Routines to let modules that have preference settings register
236 * themselves by name, and to let them register preference settings
241 struct pref_custom_cbs;
243 typedef struct pref_module module_t;
245 /** Sets up memory used by proto routines. Called at program startup */
246 void prefs_init(void);
248 /** Reset preferences to default values. Called at profile change */
249 WS_DLL_PUBLIC void prefs_reset(void);
251 /** Frees memory used by proto routines. Called at program shutdown */
252 void prefs_cleanup(void);
254 /** Provide a hint about the darkness of the current UI theme so that we can adjust colors when needed */
255 WS_DLL_PUBLIC void prefs_set_gui_theme_is_dark(gboolean is_dark);
258 * Register that a protocol has preferences.
260 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
263 * Register an alias for a preference module.
265 WS_DLL_PUBLIC void prefs_register_module_alias(const char *name, module_t *module);
268 * Deregister preferences from a protocol.
270 void prefs_deregister_protocol(int id);
273 * Register that a statistical tap has preferences.
275 * "name" is a name for the tap to use on the command line with "-o"
276 * and in preference files.
278 * "title" is a short human-readable name for the tap.
280 * "description" is a longer human-readable description of the tap.
282 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
283 const char *description, void (*apply_cb)(void));
286 * Register that a codec has preferences.
288 * "name" is a name for the codec to use on the command line with "-o"
289 * and in preference files.
291 * "title" is a short human-readable name for the codec.
293 * "description" is a longer human-readable description of the codec.
295 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
296 const char *description, void (*apply_cb)(void));
299 * Register that a protocol has preferences and group it under a single
302 #define PREFERENCE_GROUPING
303 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
304 void (*apply_cb)(void));
307 * Register that a protocol used to have preferences but no longer does,
308 * by creating an "obsolete" module for it.
310 module_t *prefs_register_protocol_obsolete(int id);
313 * Callback function for module list scanners.
315 typedef guint (*module_cb)(module_t *module, gpointer user_data);
318 * Returns TRUE if module has any submodules
320 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
323 * Call a callback function, with a specified argument, for each module
324 * in the list of all modules. (This list does not include subtrees.)
326 * Ignores "obsolete" modules; their sole purpose is to allow old
327 * preferences for dissectors that no longer have preferences to be
328 * silently ignored in preference files.
330 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
333 * Call a callback function, with a specified argument, for each submodule
334 * of specified modules. If the module is NULL, goes through the top-level
335 * list in the display tree of modules.
337 * Ignores "obsolete" modules; their sole purpose is to allow old
338 * preferences for dissectors that no longer have preferences to be
339 * silently ignored in preference files. Does not ignore subtrees,
340 * as this can be used when walking the display tree of modules.
342 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
345 * Call the "apply" callback function for each module if any of its
346 * preferences have changed, and then clear the flag saying its
347 * preferences have changed, as the module has been notified of that
350 WS_DLL_PUBLIC void prefs_apply_all(void);
353 * Call the "apply" callback function for a specific module if any of
354 * its preferences have changed, and then clear the flag saying its
355 * preferences have changed, as the module has been notified of that
358 WS_DLL_PUBLIC void prefs_apply(module_t *module);
363 typedef struct preference pref_t;
366 * Returns TRUE if the given protocol has registered preferences.
368 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
371 * Returns the module title of a registered protocol (or NULL if unknown).
373 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
375 /** Given a module name, return a pointer to its pref_module struct,
376 * or NULL if it's not found.
378 * @param name The preference module name. Usually the same as the protocol
380 * @return A pointer to the corresponding preference module, or NULL if it
383 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
385 /** Given a module name, and a preference name return a pointer to the given
386 * module's given preference or NULL if it's not found.
388 * @param module The preference module name. Usually the same as the protocol
390 * @param pref The preference name, e.g. "desegment".
391 * @return A pointer to the corresponding preference, or NULL if it
394 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
397 * Register a preference with an unsigned integral value.
399 WS_DLL_PUBLIC void prefs_register_uint_preference(module_t *module, const char *name,
400 const char *title, const char *description, guint base, guint *var);
403 * prefs_register_ callers must conform to the following:
405 * Names must be in lowercase letters only (underscore allowed).
406 * Titles and descriptions must be valid UTF-8 or NULL.
407 * Titles must be short (less than 80 characters)
408 * Titles must not contain newlines.
412 * Register a preference with an Boolean value.
414 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
415 const char *title, const char *description, gboolean *var);
418 * Register a preference with an enumerated value.
420 WS_DLL_PUBLIC void prefs_register_enum_preference(module_t *module, const char *name,
421 const char *title, const char *description, gint *var,
422 const enum_val_t *enumvals, gboolean radio_buttons);
425 * Register a preference with a character-string value.
427 WS_DLL_PUBLIC void prefs_register_string_preference(module_t *module, const char *name,
428 const char *title, const char *description, const char **var);
431 * Register a preference with a file name (string) value.
432 * File name preferences are basically like string preferences
433 * except that the GUI gives the user the ability to browse for the
436 WS_DLL_PUBLIC void prefs_register_filename_preference(module_t *module, const char *name,
437 const char *title, const char *description, const char **var, gboolean for_writing);
440 * Register a preference with a directory name (string) value.
441 * Directory name preferences are basically like string preferences
442 * except that the GUI gives the user the ability to browse for a
445 WS_DLL_PUBLIC void prefs_register_directory_preference(module_t *module, const char *name,
446 const char *title, const char *description, const char **var);
449 * Register a preference with a ranged value.
451 WS_DLL_PUBLIC void prefs_register_range_preference(module_t *module, const char *name,
452 const char *title, const char *description, range_t **var,
456 * Register a static text 'preference'. It can be used to add some info/explanation.
458 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
459 const char *title, const char *description);
462 * Register a uat 'preference'. It adds a button that opens the uat's window in the
463 * preferences tab of the module.
465 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
466 const char *name, const char* title, const char *description, struct epan_uat* uat);
469 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
470 * preferences tab of the module.
472 WS_DLL_PUBLIC void prefs_register_uat_preference_qt(module_t *module,
473 const char *name, const char* title, const char *description, struct epan_uat* uat);
477 * Register a color preference. Currently does not have any "GUI Dialog" support
478 * so the color data needs to be managed independently. Currently used by the
479 * "GUI preferences" to aid in reading/writing the preferences file, but the
480 * "data" is still managed by the specific "GUI preferences" dialog.
482 void prefs_register_color_preference(module_t *module, const char *name,
483 const char *title, const char *description, color_t *color);
486 * Register a custom preference. Currently does not have any "GUI Dialog" support
487 * so data needs to be managed independently. Currently used by the
488 * "GUI preferences" to aid in reading/writing the preferences file, but the
489 * "data" is still managed by the specific "GUI preferences" dialog.
491 void prefs_register_custom_preference(module_t *module, const char *name,
492 const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
496 * Register a (internal) "Decode As" preference with a ranged value.
498 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
499 const char *title, const char *description, range_t **var,
503 * Register a (internal) "Decode As" preference with an unsigned integral value
504 * for a dissector table.
506 void prefs_register_decode_as_preference(module_t *module, const char *name,
507 const char *title, const char *description, guint *var);
510 * Register a preference that used to be supported but no longer is.
512 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
516 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
519 * Call a callback function, with a specified argument, for each preference
522 * If any of the callbacks return a non-zero value, stop and return that
523 * value, otherwise return 0.
525 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
528 /* Parse through a list of comma-separated, possibly quoted strings.
529 * Return a list of the string data.
531 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
533 /* Clear the given list of string data. */
534 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
536 /** Fetch a short preference type name, e.g. "Integer".
538 * @param pref A preference.
540 * @return The preference type name. May be NULL.
543 const char *prefs_pref_type_name(pref_t *pref);
545 /** Fetch a long description of the preference type
547 * @param pref A preference.
549 * @return A description of the preference type including allowed
550 * values for enums. The description may include newlines. Must be
554 char *prefs_pref_type_description(pref_t *pref);
556 /** Fetch a string representation of the preference.
558 * @param pref A preference.
559 * @param source Which value of the preference to return, see pref_source_t.
561 * @return A string representation of the preference. Must be g_free()d.
564 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
566 /* Read the preferences file, fill in "prefs", and return a pointer to it.
568 If we got an error (other than "it doesn't exist") we report it through
571 This is called by epan_load_settings(); programs should call that
572 rather than individually calling the routines it calls. */
573 extern e_prefs *read_prefs(void);
575 /* Write out "prefs" to the user's preferences file, and return 0.
577 If we got an error, stuff a pointer to the path of the preferences file
578 into "*pf_path_return", and return the errno. */
579 WS_DLL_PUBLIC int write_prefs(char **);
582 * Result of setting a preference.
585 PREFS_SET_OK, /* succeeded */
586 PREFS_SET_SYNTAX_ERR, /* syntax error in string */
587 PREFS_SET_NO_SUCH_PREF, /* no such preference */
588 PREFS_SET_OBSOLETE /* preference used to exist but no longer does */
592 * Given a string of the form "<pref name>:<pref value>", as might appear
593 * as an argument to a "-o" option, parse it and set the preference in
594 * question. Return an indication of whether it succeeded or failed
597 * For syntax errors (return value PREFS_SET_SYNTAX_ERR), details (when
598 * available) are written into "errmsg" which must be freed with g_free.
600 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
603 * Get or set a preference's obsolete status. These can be used to make a
604 * preference obsolete after startup so that we can fetch its value but
605 * keep it from showing up in the prefrences dialog.
607 gboolean prefs_get_preference_obsolete(pref_t *pref);
608 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
611 * Get current preference uint value. This allows the preference structure
612 * to remain hidden from those that doesn't really need it
614 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
617 * Get the current range preference value (maintained by pref, so it doesn't need to be freed). This allows the
618 * preference structure to remain hidden from those that doesn't really need it.
620 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
623 * Returns TRUE if the given device is hidden
625 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
628 * Returns TRUE if the given device should capture in monitor mode by default
630 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
632 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
635 * Returns TRUE if the layout pane content is enabled
637 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
641 #endif /* __cplusplus */
646 * Editor modelines - http://www.wireshark.org/tools/modelines.html
651 * indent-tabs-mode: nil
654 * vi: set shiftwidth=4 tabstop=8 expandtab:
655 * :indentSize=4:tabSize=8:noTabs=true: