More PortAudio removal.
[metze/wireshark/wip.git] / epan / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #ifndef __PREFS_H__
12 #define __PREFS_H__
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif /* __cplusplus */
17
18 #include <glib.h>
19
20 #include <epan/params.h>
21 #include <epan/range.h>
22
23 #include <wsutil/color.h>
24
25 #include "ws_symbol_export.h"
26
27 #define PR_DEST_CMD  0
28 #define PR_DEST_FILE 1
29
30 #define DEF_WIDTH 750
31 #define DEF_HEIGHT 550
32
33 #define MAX_VAL_LEN  1024
34
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 */
40
41 struct epan_uat;
42 struct _e_addr_resolve;
43
44 /*
45  * Convert a string listing name resolution types to a bitmask of
46  * those types.
47  *
48  * Set "*name_resolve" to the bitmask, and return '\0', on success;
49  * return the bad character in the string on error.
50  */
51 WS_DLL_PUBLIC
52 char string_to_name_resolve(const char *string, struct _e_addr_resolve *name_resolve);
53
54 /*
55  * Modes for the starting directory in File Open dialogs.
56  */
57 #define FO_STYLE_LAST_OPENED    0 /* start in last directory we looked at */
58 #define FO_STYLE_SPECIFIED      1 /* start in specified directory */
59
60 /*
61  * Toolbar styles.
62  */
63 #define TB_STYLE_ICONS          0
64 #define TB_STYLE_TEXT           1
65 #define TB_STYLE_BOTH           2
66
67 /*
68  * Types of layout of summary/details/hex panes.
69  */
70 typedef enum {
71     layout_unused,  /* entry currently unused */
72     layout_type_5,
73     layout_type_2,
74     layout_type_1,
75     layout_type_4,
76     layout_type_3,
77     layout_type_6,
78     layout_type_max
79 } layout_type_e;
80
81 /*
82  * Types of pane.
83  */
84 typedef enum {
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;
90
91 /*
92  * open console behaviour (win32 only)
93  */
94 typedef enum {
95     console_open_never,
96     console_open_auto,
97     console_open_always
98 } console_open_e;
99
100 /*
101  * Places version information will show up
102  */
103 typedef enum {
104     version_welcome_only,
105     version_title_only,
106     version_both,
107     version_neither
108 } version_info_e;
109
110 typedef enum {
111     pref_default,
112     pref_stashed,
113     pref_current
114 } pref_source_t;
115
116 typedef enum {
117     ELIDE_LEFT,
118     ELIDE_RIGHT,
119     ELIDE_MIDDLE,
120     ELIDE_NONE
121 } elide_mode_e;
122
123
124 /*
125  * Update channel.
126  */
127 typedef enum {
128     UPDATE_CHANNEL_DEVELOPMENT,
129     UPDATE_CHANNEL_STABLE
130 } software_update_channel_e;
131
132 typedef struct _e_prefs {
133   gint         pr_format;
134   gint         pr_dest;
135   gchar       *pr_file;
136   gchar       *pr_cmd;
137   GList       *col_list;
138   gint         num_cols;
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;
186 #endif
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;
195 #endif
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;
236 } e_prefs;
237
238 WS_DLL_PUBLIC e_prefs prefs;
239
240 /*
241  * Routines to let modules that have preference settings register
242  * themselves by name, and to let them register preference settings
243  * by name.
244  */
245 struct pref_module;
246
247 struct pref_custom_cbs;
248
249 typedef struct pref_module module_t;
250
251 /** Sets up memory used by proto routines. Called at program startup */
252 void prefs_init(void);
253
254 /** Reset preferences to default values.  Called at profile change */
255 WS_DLL_PUBLIC void prefs_reset(void);
256
257 /** Frees memory used by proto routines. Called at program shutdown */
258 void prefs_cleanup(void);
259
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);
262
263 /*
264  * Register that a protocol has preferences.
265  */
266 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
267
268 /**
269  * Deregister preferences from a protocol.
270  */
271 void prefs_deregister_protocol(int id);
272
273 /*
274  * Register that a statistical tap has preferences.
275  *
276  * "name" is a name for the tap to use on the command line with "-o"
277  * and in preference files.
278  *
279  * "title" is a short human-readable name for the tap.
280  *
281  * "description" is a longer human-readable description of the tap.
282  */
283 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
284     const char *description, void (*apply_cb)(void));
285
286 /*
287  * Register that a codec has preferences.
288  *
289  * "name" is a name for the codec to use on the command line with "-o"
290  * and in preference files.
291  *
292  * "title" is a short human-readable name for the codec.
293  *
294  * "description" is a longer human-readable description of the codec.
295  */
296 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
297     const char *description, void (*apply_cb)(void));
298
299 /*
300  * Register that a protocol has preferences and group it under a single
301  * subtree
302  */
303 #define PREFERENCE_GROUPING
304 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
305     void (*apply_cb)(void));
306
307 /*
308  * Register that a protocol used to have preferences but no longer does,
309  * by creating an "obsolete" module for it.
310  */
311 module_t *prefs_register_protocol_obsolete(int id);
312
313 /*
314  * Callback function for module list scanners.
315  */
316 typedef guint (*module_cb)(module_t *module, gpointer user_data);
317
318 /*
319  * Returns TRUE if module has any submodules
320  */
321 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
322
323 /*
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.)
326  *
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.
330  */
331 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
332
333 /*
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.
337  *
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.
342  */
343 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
344
345 /*
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
349  * fact.
350  */
351 WS_DLL_PUBLIC void prefs_apply_all(void);
352
353 /*
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
357  * fact.
358  */
359 WS_DLL_PUBLIC void prefs_apply(module_t *module);
360
361
362 struct preference;
363
364 typedef struct preference pref_t;
365
366 /*
367  * Returns TRUE if the given protocol has registered preferences.
368  */
369 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
370
371 /*
372  * Returns the module title of a registered protocol (or NULL if unknown).
373  */
374 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
375
376 /** Given a module name, return a pointer to its pref_module struct,
377  * or NULL if it's not found.
378  *
379  * @param name The preference module name.  Usually the same as the protocol
380  * name, e.g. "tcp".
381  * @return A pointer to the corresponding preference module, or NULL if it
382  * wasn't found.
383  */
384 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
385
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.
388  *
389  * @param module The preference module name.  Usually the same as the protocol
390  * name, e.g. "tcp".
391  * @param pref The preference name, e.g. "desegment".
392  * @return A pointer to the corresponding preference, or NULL if it
393  * wasn't found.
394  */
395 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
396
397 /*
398  * Register a preference with an unsigned integral value.
399  */
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);
402
403 /*
404  * prefs_register_ callers must conform to the following:
405  *
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.
410  */
411
412 /*
413  * Register a preference with an Boolean value.
414  */
415 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
416     const char *title, const char *description, gboolean *var);
417
418 /*
419  * Register a preference with an enumerated value.
420  */
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);
424
425 /*
426  * Register a preference with a character-string value.
427  */
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);
430
431 /*
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
435  * file.
436  */
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);
439
440 /*
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
444  * directory.
445  */
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);
448
449 /*
450  * Register a preference with a ranged value.
451  */
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,
454     guint32 max_value);
455
456 /*
457  * Register a static text 'preference'. It can be used to add some info/explanation.
458  */
459 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
460     const char *title, const char *description);
461
462 /*
463  * Register a uat 'preference'. It adds a button that opens the uat's window in the
464  * preferences tab of the module.
465  */
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);
468
469 /*
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.
472  */
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);
475
476
477 /*
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.
482  */
483 void prefs_register_color_preference(module_t *module, const char *name,
484     const char *title, const char *description, color_t *color);
485
486 /*
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.
491  */
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,
494     void** custom_data);
495
496 /*
497  * Register a (internal) "Decode As" preference with a ranged value.
498  */
499 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
500     const char *title, const char *description, range_t **var,
501     guint32 max_value);
502
503 /*
504  * Register a (internal) "Decode As" preference with an unsigned integral value
505  * for a dissector table.
506  */
507 void prefs_register_decode_as_preference(module_t *module, const char *name,
508     const char *title, const char *description, guint *var);
509
510 /*
511  * Register a preference that used to be supported but no longer is.
512  */
513 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
514     const char *name);
515
516
517 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
518
519 /*
520  * Call a callback function, with a specified argument, for each preference
521  * in a given module.
522  *
523  * If any of the callbacks return a non-zero value, stop and return that
524  * value, otherwise return 0.
525  */
526 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
527     gpointer user_data);
528
529 /* Parse through a list of comma-separated, possibly quoted strings.
530  *  Return a list of the string data.
531  */
532 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
533
534 /* Clear the given list of string data. */
535 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
536
537 /** Fetch a short preference type name, e.g. "Integer".
538  *
539  * @param pref A preference.
540  *
541  * @return The preference type name. May be NULL.
542  */
543 WS_DLL_PUBLIC
544 const char *prefs_pref_type_name(pref_t *pref);
545
546 /** Fetch a long description of the preference type
547  *
548  * @param pref A preference.
549  *
550  * @return A description of the preference type including allowed
551  * values for enums. The description may include newlines. Must be
552  * g_free()d.
553  */
554 WS_DLL_PUBLIC
555 char *prefs_pref_type_description(pref_t *pref);
556
557 /** Fetch a string representation of the preference.
558  *
559  * @param pref A preference.
560  * @param source Which value of the preference to return, see pref_source_t.
561  *
562  * @return A string representation of the preference. Must be g_free()d.
563  */
564 WS_DLL_PUBLIC
565 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
566
567 /* Read the preferences file, fill in "prefs", and return a pointer to it.
568
569    If we got an error (other than "it doesn't exist") we report it through
570    the UI.
571
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);
575
576 /* Write out "prefs" to the user's preferences file, and return 0.
577
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 **);
581
582 /**
583  * Result of setting a preference.
584  */
585 typedef enum {
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 */
590 } prefs_set_pref_e;
591
592 /*
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
596  * in some fashion.
597  *
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.
600  */
601 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
602
603 /*
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.
607  */
608 gboolean prefs_get_preference_obsolete(pref_t *pref);
609 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
610
611 /*
612  * Get current  preference uint value. This allows the preference structure
613  * to remain hidden from those that doesn't really need it
614  */
615 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
616
617 /*
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.
620  */
621 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
622
623 /*
624  * Returns TRUE if the given device is hidden
625  */
626 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
627
628 /*
629  * Returns TRUE if the given device should capture in monitor mode by default
630  */
631 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
632
633 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
634
635 /*
636  * Returns TRUE if the layout pane content is enabled
637  */
638 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
639
640 #ifdef __cplusplus
641 }
642 #endif /* __cplusplus */
643
644 #endif /* prefs.h */
645
646 /*
647  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
648  *
649  * Local variables:
650  * c-basic-offset: 4
651  * tab-width: 8
652  * indent-tabs-mode: nil
653  * End:
654  *
655  * vi: set shiftwidth=4 tabstop=8 expandtab:
656  * :indentSize=4:tabSize=8:noTabs=true:
657  */