TODO SMB2 NegotiateContext....
[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 DEF_WIDTH 750
28 #define DEF_HEIGHT 550
29
30 #define MAX_VAL_LEN  1024
31
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 */
37
38 struct epan_uat;
39 struct _e_addr_resolve;
40
41 /*
42  * Convert a string listing name resolution types to a bitmask of
43  * those types.
44  *
45  * Set "*name_resolve" to the bitmask, and return '\0', on success;
46  * return the bad character in the string on error.
47  */
48 WS_DLL_PUBLIC
49 char string_to_name_resolve(const char *string, struct _e_addr_resolve *name_resolve);
50
51 /*
52  * Modes for the starting directory in File Open dialogs.
53  */
54 #define FO_STYLE_LAST_OPENED    0 /* start in last directory we looked at */
55 #define FO_STYLE_SPECIFIED      1 /* start in specified directory */
56
57 /*
58  * Toolbar styles.
59  */
60 #define TB_STYLE_ICONS          0
61 #define TB_STYLE_TEXT           1
62 #define TB_STYLE_BOTH           2
63
64 /*
65  * Color styles.
66  */
67 #define COLOR_STYLE_DEFAULT     0
68 #define COLOR_STYLE_FLAT        1
69 #define COLOR_STYLE_GRADIENT    2
70
71 #define COLOR_STYLE_ALPHA       0.25
72
73 /*
74  * Types of layout of summary/details/hex panes.
75  */
76 typedef enum {
77     layout_unused,  /* entry currently unused */
78     layout_type_5,
79     layout_type_2,
80     layout_type_1,
81     layout_type_4,
82     layout_type_3,
83     layout_type_6,
84     layout_type_max
85 } layout_type_e;
86
87 /*
88  * Types of pane.
89  */
90 typedef enum {
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;
96
97 /*
98  * open console behaviour (win32 only)
99  */
100 typedef enum {
101     console_open_never,
102     console_open_auto,
103     console_open_always
104 } console_open_e;
105
106 /*
107  * Places version information will show up
108  */
109 typedef enum {
110     version_welcome_only,
111     version_title_only,
112     version_both,
113     version_neither
114 } version_info_e;
115
116 typedef enum {
117     pref_default,
118     pref_stashed,
119     pref_current
120 } pref_source_t;
121
122 typedef enum {
123     ELIDE_LEFT,
124     ELIDE_RIGHT,
125     ELIDE_MIDDLE,
126     ELIDE_NONE
127 } elide_mode_e;
128
129
130 /*
131  * Update channel.
132  */
133 typedef enum {
134     UPDATE_CHANNEL_DEVELOPMENT,
135     UPDATE_CHANNEL_STABLE
136 } software_update_channel_e;
137
138 typedef struct _e_prefs {
139   GList       *col_list;
140   gint         num_cols;
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;
229 } e_prefs;
230
231 WS_DLL_PUBLIC e_prefs prefs;
232
233 /*
234  * Routines to let modules that have preference settings register
235  * themselves by name, and to let them register preference settings
236  * by name.
237  */
238 struct pref_module;
239
240 struct pref_custom_cbs;
241
242 typedef struct pref_module module_t;
243
244 /** Sets up memory used by proto routines. Called at program startup */
245 void prefs_init(void);
246
247 /** Reset preferences to default values.  Called at profile change */
248 WS_DLL_PUBLIC void prefs_reset(void);
249
250 /** Frees memory used by proto routines. Called at program shutdown */
251 void prefs_cleanup(void);
252
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);
255
256 /*
257  * Register that a protocol has preferences.
258  */
259 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
260
261 /*
262  * Register an alias for a preference module.
263  */
264 WS_DLL_PUBLIC void prefs_register_module_alias(const char *name, module_t *module);
265
266 /**
267  * Deregister preferences from a protocol.
268  */
269 void prefs_deregister_protocol(int id);
270
271 /*
272  * Register that a statistical tap has preferences.
273  *
274  * "name" is a name for the tap to use on the command line with "-o"
275  * and in preference files.
276  *
277  * "title" is a short human-readable name for the tap.
278  *
279  * "description" is a longer human-readable description of the tap.
280  */
281 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
282     const char *description, void (*apply_cb)(void));
283
284 /*
285  * Register that a codec has preferences.
286  *
287  * "name" is a name for the codec to use on the command line with "-o"
288  * and in preference files.
289  *
290  * "title" is a short human-readable name for the codec.
291  *
292  * "description" is a longer human-readable description of the codec.
293  */
294 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
295     const char *description, void (*apply_cb)(void));
296
297 /*
298  * Register that a protocol has preferences and group it under a single
299  * subtree
300  */
301 #define PREFERENCE_GROUPING
302 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
303     void (*apply_cb)(void));
304
305 /*
306  * Register that a protocol used to have preferences but no longer does,
307  * by creating an "obsolete" module for it.
308  */
309 module_t *prefs_register_protocol_obsolete(int id);
310
311 /*
312  * Callback function for module list scanners.
313  */
314 typedef guint (*module_cb)(module_t *module, gpointer user_data);
315
316 /*
317  * Returns TRUE if module has any submodules
318  */
319 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
320
321 /*
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.)
324  *
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.
328  */
329 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
330
331 /*
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.
335  *
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.
340  */
341 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
342
343 /*
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
347  * fact.
348  */
349 WS_DLL_PUBLIC void prefs_apply_all(void);
350
351 /*
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
355  * fact.
356  */
357 WS_DLL_PUBLIC void prefs_apply(module_t *module);
358
359
360 struct preference;
361
362 typedef struct preference pref_t;
363
364 /*
365  * Returns TRUE if the given protocol has registered preferences.
366  */
367 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
368
369 /*
370  * Returns the module title of a registered protocol (or NULL if unknown).
371  */
372 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
373
374 /** Given a module name, return a pointer to its pref_module struct,
375  * or NULL if it's not found.
376  *
377  * @param name The preference module name.  Usually the same as the protocol
378  * name, e.g. "tcp".
379  * @return A pointer to the corresponding preference module, or NULL if it
380  * wasn't found.
381  */
382 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
383
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.
386  *
387  * @param module The preference module name.  Usually the same as the protocol
388  * name, e.g. "tcp".
389  * @param pref The preference name, e.g. "desegment".
390  * @return A pointer to the corresponding preference, or NULL if it
391  * wasn't found.
392  */
393 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
394
395 /*
396  * Register a preference with an unsigned integral value.
397  */
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);
400
401 /*
402  * prefs_register_ callers must conform to the following:
403  *
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.
408  */
409
410 /*
411  * Register a preference with an Boolean value.
412  */
413 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
414     const char *title, const char *description, gboolean *var);
415
416 /*
417  * Register a preference with an enumerated value.
418  */
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);
422
423 /*
424  * Register a preference with a character-string value.
425  */
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);
428
429 /*
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
433  * file.
434  */
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);
437
438 /*
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
442  * directory.
443  */
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);
446
447 /*
448  * Register a preference with a ranged value.
449  */
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,
452     guint32 max_value);
453
454 /*
455  * Register a static text 'preference'. It can be used to add some info/explanation.
456  */
457 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
458     const char *title, const char *description);
459
460 /*
461  * Register a uat 'preference'. It adds a button that opens the uat's window in the
462  * preferences tab of the module.
463  */
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);
466
467 /*
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.
470  */
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);
473
474
475 /*
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.
480  */
481 void prefs_register_color_preference(module_t *module, const char *name,
482     const char *title, const char *description, color_t *color);
483
484 /*
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.
489  */
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,
492     void** custom_data);
493
494 /*
495  * Register a (internal) "Decode As" preference with a ranged value.
496  */
497 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
498     const char *title, const char *description, range_t **var,
499     guint32 max_value);
500
501 /*
502  * Register a (internal) "Decode As" preference with an unsigned integral value
503  * for a dissector table.
504  */
505 void prefs_register_decode_as_preference(module_t *module, const char *name,
506     const char *title, const char *description, guint *var);
507
508 /*
509  * Register a preference that used to be supported but no longer is.
510  */
511 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
512     const char *name);
513
514
515 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
516
517 /*
518  * Call a callback function, with a specified argument, for each preference
519  * in a given module.
520  *
521  * If any of the callbacks return a non-zero value, stop and return that
522  * value, otherwise return 0.
523  */
524 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
525     gpointer user_data);
526
527 /* Parse through a list of comma-separated, possibly quoted strings.
528  *  Return a list of the string data.
529  */
530 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
531
532 /* Clear the given list of string data. */
533 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
534
535 /** Fetch a short preference type name, e.g. "Integer".
536  *
537  * @param pref A preference.
538  *
539  * @return The preference type name. May be NULL.
540  */
541 WS_DLL_PUBLIC
542 const char *prefs_pref_type_name(pref_t *pref);
543
544 /** Fetch a long description of the preference type
545  *
546  * @param pref A preference.
547  *
548  * @return A description of the preference type including allowed
549  * values for enums. The description may include newlines. Must be
550  * g_free()d.
551  */
552 WS_DLL_PUBLIC
553 char *prefs_pref_type_description(pref_t *pref);
554
555 /** Fetch a string representation of the preference.
556  *
557  * @param pref A preference.
558  * @param source Which value of the preference to return, see pref_source_t.
559  *
560  * @return A string representation of the preference. Must be g_free()d.
561  */
562 WS_DLL_PUBLIC
563 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
564
565 /* Read the preferences file, fill in "prefs", and return a pointer to it.
566
567    If we got an error (other than "it doesn't exist") we report it through
568    the UI.
569
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);
573
574 /* Write out "prefs" to the user's preferences file, and return 0.
575
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 **);
579
580 /**
581  * Result of setting a preference.
582  */
583 typedef enum {
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 */
588 } prefs_set_pref_e;
589
590 /*
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
594  * in some fashion.
595  *
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.
598  */
599 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
600
601 /*
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.
605  */
606 gboolean prefs_get_preference_obsolete(pref_t *pref);
607 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
608
609 /*
610  * Get current  preference uint value. This allows the preference structure
611  * to remain hidden from those that doesn't really need it
612  */
613 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
614
615 /*
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.
618  */
619 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
620
621 /*
622  * Returns TRUE if the given device is hidden
623  */
624 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
625
626 /*
627  * Returns TRUE if the given device should capture in monitor mode by default
628  */
629 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
630
631 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
632
633 /*
634  * Returns TRUE if the layout pane content is enabled
635  */
636 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
637
638 #ifdef __cplusplus
639 }
640 #endif /* __cplusplus */
641
642 #endif /* prefs.h */
643
644 /*
645  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
646  *
647  * Local variables:
648  * c-basic-offset: 4
649  * tab-width: 8
650  * indent-tabs-mode: nil
651  * End:
652  *
653  * vi: set shiftwidth=4 tabstop=8 expandtab:
654  * :indentSize=4:tabSize=8:noTabs=true:
655  */