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 PR_DEST_FILE 1
31 #define DEF_HEIGHT 550
33 #define MAX_VAL_LEN 1024
35 #define TAP_UPDATE_DEFAULT_INTERVAL 3000
36 #define ST_DEF_BURSTRES 5
37 #define ST_DEF_BURSTLEN 100
38 #define ST_MAX_BURSTRES 600000 /* somewhat arbirary limit of 10 minutes */
39 #define ST_MAX_BURSTBUCKETS 100 /* somewhat arbirary limit - more buckets degrade performance */
42 struct _e_addr_resolve;
45 * Convert a string listing name resolution types to a bitmask of
48 * Set "*name_resolve" to the bitmask, and return '\0', on success;
49 * return the bad character in the string on error.
52 char string_to_name_resolve(const char *string, struct _e_addr_resolve *name_resolve);
55 * Modes for the starting directory in File Open dialogs.
57 #define FO_STYLE_LAST_OPENED 0 /* start in last directory we looked at */
58 #define FO_STYLE_SPECIFIED 1 /* start in specified directory */
63 #define TB_STYLE_ICONS 0
64 #define TB_STYLE_TEXT 1
65 #define TB_STYLE_BOTH 2
68 * Types of layout of summary/details/hex panes.
71 layout_unused, /* entry currently unused */
85 layout_pane_content_none,
86 layout_pane_content_plist,
87 layout_pane_content_pdetails,
88 layout_pane_content_pbytes
89 } layout_pane_content_e;
92 * open console behaviour (win32 only)
101 * Places version information will show up
104 version_welcome_only,
128 UPDATE_CHANNEL_DEVELOPMENT,
129 UPDATE_CHANNEL_STABLE
130 } software_update_channel_e;
132 typedef struct _e_prefs {
139 color_t st_client_fg, st_client_bg, st_server_fg, st_server_bg;
140 color_t gui_text_valid, gui_text_invalid, gui_text_deprecated;
141 gboolean gui_altern_colors; /* GTK only */
142 gboolean gui_expert_composite_eyecandy;
143 gboolean filter_toolbar_show_in_statusbar;
144 gboolean restore_filter_after_following_stream;
145 gint gui_ptree_line_style;
146 gint gui_ptree_expander_style;
147 gboolean gui_hex_dump_highlight_style;
148 gint gui_toolbar_main_style;
149 gint gui_toolbar_filter_style; /* GTK only? */
150 gchar *gui_gtk2_font_name;
151 gchar *gui_qt_font_name;
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 gboolean gui_macosx_style; /* GTK only */
162 console_open_e gui_console_open;
163 guint gui_recent_df_entries_max;
164 guint gui_recent_files_count_max;
165 guint gui_fileopen_style;
166 gchar *gui_fileopen_dir;
167 guint gui_fileopen_preview;
168 gboolean gui_ask_unsaved;
169 gboolean gui_find_wrap;
170 gboolean gui_use_pref_save;
171 gchar *gui_webbrowser;
172 gchar *gui_window_title;
173 gchar *gui_prepend_window_title;
174 gchar *gui_start_title;
175 version_info_e gui_version_placement;
176 gboolean gui_auto_scroll_on_expand; /* GTK+ only */
177 guint gui_auto_scroll_percentage; /* GTK+ only */
178 layout_type_e gui_layout_type;
179 layout_pane_content_e gui_layout_content_1;
180 layout_pane_content_e gui_layout_content_2;
181 layout_pane_content_e gui_layout_content_3;
182 gchar *gui_interfaces_hide_types;
183 gboolean gui_interfaces_show_hidden;
184 #ifdef HAVE_PCAP_REMOTE
185 gboolean gui_interfaces_remote_display;
187 gint console_log_level;
188 gchar *capture_device;
189 gchar *capture_devices_linktypes;
190 gchar *capture_devices_descr;
191 gchar *capture_devices_hide;
192 gchar *capture_devices_monitor_mode;
193 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
194 gchar *capture_devices_buffersize;
196 gchar *capture_devices_snaplen;
197 gchar *capture_devices_pmode;
198 gchar *capture_devices_filter; /* XXX - Mostly unused. Deprecate? */
199 gboolean capture_prom_mode;
200 gboolean capture_pcap_ng;
201 gboolean capture_real_time;
202 gboolean capture_auto_scroll;
203 gboolean capture_no_extcap;
204 gboolean capture_show_info;
205 GList *capture_columns;
206 guint tap_update_interval;
207 gboolean display_hidden_proto_items;
208 gboolean display_byte_fields_with_spaces;
209 gboolean enable_incomplete_dissectors_check;
210 gboolean incomplete_dissectors_check_debug;
211 gboolean strict_conversation_tracking_heuristics;
212 gboolean gui_update_enabled;
213 software_update_channel_e gui_update_channel;
214 gint gui_update_interval;
215 gchar *saved_at_version;
216 gboolean unknown_prefs; /* unknown or obsolete pref(s) */
217 gboolean unknown_colorfilters; /* Warn when saving unknown or obsolete color filters. */
218 gboolean gui_qt_packet_list_separator;
219 gboolean gui_qt_show_selected_packet;
220 gboolean gui_qt_show_file_load_time;
221 gboolean gui_packet_editor; /* Enable Packet Editor */
222 elide_mode_e gui_packet_list_elide_mode;
223 gboolean gui_packet_list_show_related;
224 gboolean gui_packet_list_show_minimap;
225 gboolean st_enable_burstinfo;
226 gboolean st_burst_showcount;
227 gint st_burst_resolution;
228 gint st_burst_windowlen;
229 gboolean st_sort_casesensitve;
230 gboolean st_sort_rng_fixorder;
231 gboolean st_sort_rng_nameonly;
232 gint st_sort_defcolflag;
233 gboolean st_sort_defdescending;
234 gboolean st_sort_showfullname;
235 gboolean extcap_save_on_start;
238 WS_DLL_PUBLIC e_prefs prefs;
241 * Routines to let modules that have preference settings register
242 * themselves by name, and to let them register preference settings
247 struct pref_custom_cbs;
249 typedef struct pref_module module_t;
251 /** Sets up memory used by proto routines. Called at program startup */
252 void prefs_init(void);
254 /** Reset preferences to default values. Called at profile change */
255 WS_DLL_PUBLIC void prefs_reset(void);
257 /** Frees memory used by proto routines. Called at program shutdown */
258 void prefs_cleanup(void);
260 /** Provide a hint about the darkness of the current UI theme so that we can adjust colors when needed */
261 WS_DLL_PUBLIC void prefs_set_gui_theme_is_dark(gboolean is_dark);
264 * Register that a protocol has preferences.
266 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
269 * Deregister preferences from a protocol.
271 void prefs_deregister_protocol(int id);
274 * Register that a statistical tap has preferences.
276 * "name" is a name for the tap to use on the command line with "-o"
277 * and in preference files.
279 * "title" is a short human-readable name for the tap.
281 * "description" is a longer human-readable description of the tap.
283 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
284 const char *description, void (*apply_cb)(void));
287 * Register that a codec has preferences.
289 * "name" is a name for the codec to use on the command line with "-o"
290 * and in preference files.
292 * "title" is a short human-readable name for the codec.
294 * "description" is a longer human-readable description of the codec.
296 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
297 const char *description, void (*apply_cb)(void));
300 * Register that a protocol has preferences and group it under a single
303 #define PREFERENCE_GROUPING
304 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
305 void (*apply_cb)(void));
308 * Register that a protocol used to have preferences but no longer does,
309 * by creating an "obsolete" module for it.
311 module_t *prefs_register_protocol_obsolete(int id);
314 * Callback function for module list scanners.
316 typedef guint (*module_cb)(module_t *module, gpointer user_data);
319 * Returns TRUE if module has any submodules
321 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
324 * Call a callback function, with a specified argument, for each module
325 * in the list of all modules. (This list does not include subtrees.)
327 * Ignores "obsolete" modules; their sole purpose is to allow old
328 * preferences for dissectors that no longer have preferences to be
329 * silently ignored in preference files.
331 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
334 * Call a callback function, with a specified argument, for each submodule
335 * of specified modules. If the module is NULL, goes through the top-level
336 * list in the display tree of modules.
338 * Ignores "obsolete" modules; their sole purpose is to allow old
339 * preferences for dissectors that no longer have preferences to be
340 * silently ignored in preference files. Does not ignore subtrees,
341 * as this can be used when walking the display tree of modules.
343 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
346 * Call the "apply" callback function for each module if any of its
347 * preferences have changed, and then clear the flag saying its
348 * preferences have changed, as the module has been notified of that
351 WS_DLL_PUBLIC void prefs_apply_all(void);
354 * Call the "apply" callback function for a specific module if any of
355 * its preferences have changed, and then clear the flag saying its
356 * preferences have changed, as the module has been notified of that
359 WS_DLL_PUBLIC void prefs_apply(module_t *module);
364 typedef struct preference pref_t;
367 * Returns TRUE if the given protocol has registered preferences.
369 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
372 * Returns the module title of a registered protocol (or NULL if unknown).
374 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
376 /** Given a module name, return a pointer to its pref_module struct,
377 * or NULL if it's not found.
379 * @param name The preference module name. Usually the same as the protocol
381 * @return A pointer to the corresponding preference module, or NULL if it
384 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
386 /** Given a module name, and a preference name return a pointer to the given
387 * module's given preference or NULL if it's not found.
389 * @param module The preference module name. Usually the same as the protocol
391 * @param pref The preference name, e.g. "desegment".
392 * @return A pointer to the corresponding preference, or NULL if it
395 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
398 * Register a preference with an unsigned integral value.
400 WS_DLL_PUBLIC void prefs_register_uint_preference(module_t *module, const char *name,
401 const char *title, const char *description, guint base, guint *var);
404 * prefs_register_ callers must conform to the following:
406 * Names must be in lowercase letters only (underscore allowed).
407 * Titles and descriptions must be valid UTF-8 or NULL.
408 * Titles must be short (less than 80 characters)
409 * Titles must not contain newlines.
413 * Register a preference with an Boolean value.
415 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
416 const char *title, const char *description, gboolean *var);
419 * Register a preference with an enumerated value.
421 WS_DLL_PUBLIC void prefs_register_enum_preference(module_t *module, const char *name,
422 const char *title, const char *description, gint *var,
423 const enum_val_t *enumvals, gboolean radio_buttons);
426 * Register a preference with a character-string value.
428 WS_DLL_PUBLIC void prefs_register_string_preference(module_t *module, const char *name,
429 const char *title, const char *description, const char **var);
432 * Register a preference with a file name (string) value.
433 * File name preferences are basically like string preferences
434 * except that the GUI gives the user the ability to browse for the
437 WS_DLL_PUBLIC void prefs_register_filename_preference(module_t *module, const char *name,
438 const char *title, const char *description, const char **var, gboolean for_writing);
441 * Register a preference with a directory name (string) value.
442 * Directory name preferences are basically like string preferences
443 * except that the GUI gives the user the ability to browse for a
446 WS_DLL_PUBLIC void prefs_register_directory_preference(module_t *module, const char *name,
447 const char *title, const char *description, const char **var);
450 * Register a preference with a ranged value.
452 WS_DLL_PUBLIC void prefs_register_range_preference(module_t *module, const char *name,
453 const char *title, const char *description, range_t **var,
457 * Register a static text 'preference'. It can be used to add some info/explanation.
459 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
460 const char *title, const char *description);
463 * Register a uat 'preference'. It adds a button that opens the uat's window in the
464 * preferences tab of the module.
466 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
467 const char *name, const char* title, const char *description, struct epan_uat* uat);
470 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
471 * preferences tab of the module.
473 WS_DLL_PUBLIC void prefs_register_uat_preference_qt(module_t *module,
474 const char *name, const char* title, const char *description, struct epan_uat* uat);
478 * Register a color preference. Currently does not have any "GUI Dialog" support
479 * so the color data needs to be managed independently. Currently used by the
480 * "GUI preferences" to aid in reading/writing the preferences file, but the
481 * "data" is still managed by the specific "GUI preferences" dialog.
483 void prefs_register_color_preference(module_t *module, const char *name,
484 const char *title, const char *description, color_t *color);
487 * Register a custom preference. Currently does not have any "GUI Dialog" support
488 * so data needs to be managed independently. Currently used by the
489 * "GUI preferences" to aid in reading/writing the preferences file, but the
490 * "data" is still managed by the specific "GUI preferences" dialog.
492 void prefs_register_custom_preference(module_t *module, const char *name,
493 const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
497 * Register a (internal) "Decode As" preference with a ranged value.
499 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
500 const char *title, const char *description, range_t **var,
504 * Register a (internal) "Decode As" preference with an unsigned integral value
505 * for a dissector table.
507 void prefs_register_decode_as_preference(module_t *module, const char *name,
508 const char *title, const char *description, guint *var);
511 * Register a preference that used to be supported but no longer is.
513 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
517 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
520 * Call a callback function, with a specified argument, for each preference
523 * If any of the callbacks return a non-zero value, stop and return that
524 * value, otherwise return 0.
526 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
529 /* Parse through a list of comma-separated, possibly quoted strings.
530 * Return a list of the string data.
532 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
534 /* Clear the given list of string data. */
535 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
537 /** Fetch a short preference type name, e.g. "Integer".
539 * @param pref A preference.
541 * @return The preference type name. May be NULL.
544 const char *prefs_pref_type_name(pref_t *pref);
546 /** Fetch a long description of the preference type
548 * @param pref A preference.
550 * @return A description of the preference type including allowed
551 * values for enums. The description may include newlines. Must be
555 char *prefs_pref_type_description(pref_t *pref);
557 /** Fetch a string representation of the preference.
559 * @param pref A preference.
560 * @param source Which value of the preference to return, see pref_source_t.
562 * @return A string representation of the preference. Must be g_free()d.
565 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
567 /* Read the preferences file, fill in "prefs", and return a pointer to it.
569 If we got an error (other than "it doesn't exist") we report it through
572 This is called by epan_load_settings(); programs should call that
573 rather than individually calling the routines it calls. */
574 extern e_prefs *read_prefs(void);
576 /* Write out "prefs" to the user's preferences file, and return 0.
578 If we got an error, stuff a pointer to the path of the preferences file
579 into "*pf_path_return", and return the errno. */
580 WS_DLL_PUBLIC int write_prefs(char **);
583 * Result of setting a preference.
586 PREFS_SET_OK, /* succeeded */
587 PREFS_SET_SYNTAX_ERR, /* syntax error in string */
588 PREFS_SET_NO_SUCH_PREF, /* no such preference */
589 PREFS_SET_OBSOLETE /* preference used to exist but no longer does */
593 * Given a string of the form "<pref name>:<pref value>", as might appear
594 * as an argument to a "-o" option, parse it and set the preference in
595 * question. Return an indication of whether it succeeded or failed
598 * For syntax errors (return value PREFS_SET_SYNTAX_ERR), details (when
599 * available) are written into "errmsg" which must be freed with g_free.
601 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
604 * Get or set a preference's obsolete status. These can be used to make a
605 * preference obsolete after startup so that we can fetch its value but
606 * keep it from showing up in the prefrences dialog.
608 gboolean prefs_get_preference_obsolete(pref_t *pref);
609 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
612 * Get current preference uint value. This allows the preference structure
613 * to remain hidden from those that doesn't really need it
615 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
618 * Get the current range preference value (maintained by pref, so it doesn't need to be freed). This allows the
619 * preference structure to remain hidden from those that doesn't really need it.
621 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
624 * Returns TRUE if the given device is hidden
626 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
629 * Returns TRUE if the given device should capture in monitor mode by default
631 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
633 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
636 * Returns TRUE if the layout pane content is enabled
638 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
642 #endif /* __cplusplus */
647 * Editor modelines - http://www.wireshark.org/tools/modelines.html
652 * indent-tabs-mode: nil
655 * vi: set shiftwidth=4 tabstop=8 expandtab:
656 * :indentSize=4:tabSize=8:noTabs=true: