Update packet-dcm.h using DICOM 2018e definitions
[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_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;
230 } e_prefs;
231
232 WS_DLL_PUBLIC e_prefs prefs;
233
234 /*
235  * Routines to let modules that have preference settings register
236  * themselves by name, and to let them register preference settings
237  * by name.
238  */
239 struct pref_module;
240
241 struct pref_custom_cbs;
242
243 typedef struct pref_module module_t;
244
245 /** Sets up memory used by proto routines. Called at program startup */
246 void prefs_init(void);
247
248 /** Reset preferences to default values.  Called at profile change */
249 WS_DLL_PUBLIC void prefs_reset(void);
250
251 /** Frees memory used by proto routines. Called at program shutdown */
252 void prefs_cleanup(void);
253
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);
256
257 /*
258  * Register that a protocol has preferences.
259  */
260 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
261
262 /*
263  * Register an alias for a preference module.
264  */
265 WS_DLL_PUBLIC void prefs_register_module_alias(const char *name, module_t *module);
266
267 /**
268  * Deregister preferences from a protocol.
269  */
270 void prefs_deregister_protocol(int id);
271
272 /*
273  * Register that a statistical tap has preferences.
274  *
275  * "name" is a name for the tap to use on the command line with "-o"
276  * and in preference files.
277  *
278  * "title" is a short human-readable name for the tap.
279  *
280  * "description" is a longer human-readable description of the tap.
281  */
282 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
283     const char *description, void (*apply_cb)(void));
284
285 /*
286  * Register that a codec has preferences.
287  *
288  * "name" is a name for the codec to use on the command line with "-o"
289  * and in preference files.
290  *
291  * "title" is a short human-readable name for the codec.
292  *
293  * "description" is a longer human-readable description of the codec.
294  */
295 WS_DLL_PUBLIC module_t *prefs_register_codec(const char *name, const char *title,
296     const char *description, void (*apply_cb)(void));
297
298 /*
299  * Register that a protocol has preferences and group it under a single
300  * subtree
301  */
302 #define PREFERENCE_GROUPING
303 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
304     void (*apply_cb)(void));
305
306 /*
307  * Register that a protocol used to have preferences but no longer does,
308  * by creating an "obsolete" module for it.
309  */
310 module_t *prefs_register_protocol_obsolete(int id);
311
312 /*
313  * Callback function for module list scanners.
314  */
315 typedef guint (*module_cb)(module_t *module, gpointer user_data);
316
317 /*
318  * Returns TRUE if module has any submodules
319  */
320 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
321
322 /*
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.)
325  *
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.
329  */
330 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
331
332 /*
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.
336  *
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.
341  */
342 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
343
344 /*
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
348  * fact.
349  */
350 WS_DLL_PUBLIC void prefs_apply_all(void);
351
352 /*
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
356  * fact.
357  */
358 WS_DLL_PUBLIC void prefs_apply(module_t *module);
359
360
361 struct preference;
362
363 typedef struct preference pref_t;
364
365 /*
366  * Returns TRUE if the given protocol has registered preferences.
367  */
368 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
369
370 /*
371  * Returns the module title of a registered protocol (or NULL if unknown).
372  */
373 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
374
375 /** Given a module name, return a pointer to its pref_module struct,
376  * or NULL if it's not found.
377  *
378  * @param name The preference module name.  Usually the same as the protocol
379  * name, e.g. "tcp".
380  * @return A pointer to the corresponding preference module, or NULL if it
381  * wasn't found.
382  */
383 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
384
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.
387  *
388  * @param module The preference module name.  Usually the same as the protocol
389  * name, e.g. "tcp".
390  * @param pref The preference name, e.g. "desegment".
391  * @return A pointer to the corresponding preference, or NULL if it
392  * wasn't found.
393  */
394 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
395
396 /*
397  * Register a preference with an unsigned integral value.
398  */
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);
401
402 /*
403  * prefs_register_ callers must conform to the following:
404  *
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.
409  */
410
411 /*
412  * Register a preference with an Boolean value.
413  */
414 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
415     const char *title, const char *description, gboolean *var);
416
417 /*
418  * Register a preference with an enumerated value.
419  */
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);
423
424 /*
425  * Register a preference with a character-string value.
426  */
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);
429
430 /*
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
434  * file.
435  */
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);
438
439 /*
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
443  * directory.
444  */
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);
447
448 /*
449  * Register a preference with a ranged value.
450  */
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,
453     guint32 max_value);
454
455 /*
456  * Register a static text 'preference'. It can be used to add some info/explanation.
457  */
458 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
459     const char *title, const char *description);
460
461 /*
462  * Register a uat 'preference'. It adds a button that opens the uat's window in the
463  * preferences tab of the module.
464  */
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);
467
468 /*
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.
471  */
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);
474
475
476 /*
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.
481  */
482 void prefs_register_color_preference(module_t *module, const char *name,
483     const char *title, const char *description, color_t *color);
484
485 /*
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.
490  */
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,
493     void** custom_data);
494
495 /*
496  * Register a (internal) "Decode As" preference with a ranged value.
497  */
498 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
499     const char *title, const char *description, range_t **var,
500     guint32 max_value);
501
502 /*
503  * Register a (internal) "Decode As" preference with an unsigned integral value
504  * for a dissector table.
505  */
506 void prefs_register_decode_as_preference(module_t *module, const char *name,
507     const char *title, const char *description, guint *var);
508
509 /*
510  * Register a preference that used to be supported but no longer is.
511  */
512 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
513     const char *name);
514
515
516 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
517
518 /*
519  * Call a callback function, with a specified argument, for each preference
520  * in a given module.
521  *
522  * If any of the callbacks return a non-zero value, stop and return that
523  * value, otherwise return 0.
524  */
525 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
526     gpointer user_data);
527
528 /* Parse through a list of comma-separated, possibly quoted strings.
529  *  Return a list of the string data.
530  */
531 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
532
533 /* Clear the given list of string data. */
534 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
535
536 /** Fetch a short preference type name, e.g. "Integer".
537  *
538  * @param pref A preference.
539  *
540  * @return The preference type name. May be NULL.
541  */
542 WS_DLL_PUBLIC
543 const char *prefs_pref_type_name(pref_t *pref);
544
545 /** Fetch a long description of the preference type
546  *
547  * @param pref A preference.
548  *
549  * @return A description of the preference type including allowed
550  * values for enums. The description may include newlines. Must be
551  * g_free()d.
552  */
553 WS_DLL_PUBLIC
554 char *prefs_pref_type_description(pref_t *pref);
555
556 /** Fetch a string representation of the preference.
557  *
558  * @param pref A preference.
559  * @param source Which value of the preference to return, see pref_source_t.
560  *
561  * @return A string representation of the preference. Must be g_free()d.
562  */
563 WS_DLL_PUBLIC
564 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
565
566 /* Read the preferences file, fill in "prefs", and return a pointer to it.
567
568    If we got an error (other than "it doesn't exist") we report it through
569    the UI.
570
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);
574
575 /* Write out "prefs" to the user's preferences file, and return 0.
576
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 **);
580
581 /**
582  * Result of setting a preference.
583  */
584 typedef enum {
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 */
589 } prefs_set_pref_e;
590
591 /*
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
595  * in some fashion.
596  *
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.
599  */
600 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg, char **errmsg);
601
602 /*
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.
606  */
607 gboolean prefs_get_preference_obsolete(pref_t *pref);
608 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
609
610 /*
611  * Get current  preference uint value. This allows the preference structure
612  * to remain hidden from those that doesn't really need it
613  */
614 WS_DLL_PUBLIC guint prefs_get_uint_value(const char *module_name, const char* pref_name);
615
616 /*
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.
619  */
620 WS_DLL_PUBLIC range_t* prefs_get_range_value(const char *module_name, const char* pref_name);
621
622 /*
623  * Returns TRUE if the given device is hidden
624  */
625 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
626
627 /*
628  * Returns TRUE if the given device should capture in monitor mode by default
629  */
630 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
631
632 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
633
634 /*
635  * Returns TRUE if the layout pane content is enabled
636  */
637 WS_DLL_PUBLIC gboolean prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content);
638
639 #ifdef __cplusplus
640 }
641 #endif /* __cplusplus */
642
643 #endif /* prefs.h */
644
645 /*
646  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
647  *
648  * Local variables:
649  * c-basic-offset: 4
650  * tab-width: 8
651  * indent-tabs-mode: nil
652  * End:
653  *
654  * vi: set shiftwidth=4 tabstop=8 expandtab:
655  * :indentSize=4:tabSize=8:noTabs=true:
656  */