frame: print debug line according to new console preference.
[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  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef __PREFS_H__
24 #define __PREFS_H__
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30 #include <glib.h>
31
32 #include "color_filters.h"
33
34 #include <epan/params.h>
35 #include <epan/range.h>
36
37 #include "ws_symbol_export.h"
38
39 #define PR_DEST_CMD  0
40 #define PR_DEST_FILE 1
41
42 #define DEF_WIDTH 750
43 #define DEF_HEIGHT 550
44
45 #define MAX_VAL_LEN  1024
46
47 #define RTP_PLAYER_DEFAULT_VISIBLE 4
48 #define TAP_UPDATE_DEFAULT_INTERVAL 3000
49 #define ST_DEF_BURSTRES 5
50 #define ST_DEF_BURSTLEN 100
51 #define ST_MAX_BURSTRES 600000 /* somewhat arbirary limit of 10 minutes */
52 #define ST_MAX_BURSTBUCKETS 100 /* somewhat arbirary limit - more buckets degrade performance */
53
54 struct epan_uat;
55 struct _e_addr_resolve;
56
57 /*
58  * Convert a string listing name resolution types to a bitmask of
59  * those types.
60  *
61  * Set "*name_resolve" to the bitmask, and return '\0', on success;
62  * return the bad character in the string on error.
63  */
64 WS_DLL_PUBLIC
65 char string_to_name_resolve(const char *string, struct _e_addr_resolve *name_resolve);
66
67 /*
68  * Modes for the starting directory in File Open dialogs.
69  */
70 #define FO_STYLE_LAST_OPENED    0 /* start in last directory we looked at */
71 #define FO_STYLE_SPECIFIED      1 /* start in specified directory */
72
73 /*
74  * Toolbar styles.
75  */
76 #define TB_STYLE_ICONS          0
77 #define TB_STYLE_TEXT           1
78 #define TB_STYLE_BOTH           2
79
80 /*
81  * Types of layout of summary/details/hex panes.
82  */
83 typedef enum {
84     layout_unused,  /* entry currently unused */
85     layout_type_5,
86     layout_type_2,
87     layout_type_1,
88     layout_type_4,
89     layout_type_3,
90     layout_type_6,
91     layout_type_max
92 } layout_type_e;
93
94 /*
95  * Types of pane.
96  */
97 typedef enum {
98     layout_pane_content_none,
99     layout_pane_content_plist,
100     layout_pane_content_pdetails,
101     layout_pane_content_pbytes
102 } layout_pane_content_e;
103
104 /*
105  * open console behaviour (win32 only)
106  */
107 typedef enum {
108     console_open_never,
109     console_open_auto,
110     console_open_always
111 } console_open_e;
112
113 /*
114  * Places version information will show up
115  */
116 typedef enum {
117     version_welcome_only,
118     version_title_only,
119     version_both,
120     version_neither
121 } version_info_e;
122
123 typedef enum {
124     pref_default,
125     pref_stashed,
126     pref_current
127 } pref_source_t;
128
129 typedef enum {
130     ELIDE_LEFT,
131     ELIDE_RIGHT,
132     ELIDE_MIDDLE,
133     ELIDE_NONE
134 } elide_mode_e;
135
136
137 /*
138  * Update channel.
139  */
140 typedef enum {
141     UPDATE_CHANNEL_DEVELOPMENT,
142     UPDATE_CHANNEL_STABLE
143 } software_update_channel_e;
144
145 typedef struct _e_prefs {
146   gint         pr_format;
147   gint         pr_dest;
148   gchar       *pr_file;
149   gchar       *pr_cmd;
150   GList       *col_list;
151   gint         num_cols;
152   color_t      st_client_fg, st_client_bg, st_server_fg, st_server_bg;
153   color_t      gui_text_valid, gui_text_invalid, gui_text_deprecated;
154   gboolean     gui_altern_colors;
155   gboolean     gui_expert_composite_eyecandy;
156   gboolean     filter_toolbar_show_in_statusbar;
157   gint         gui_ptree_line_style;
158   gint         gui_ptree_expander_style;
159   gboolean     gui_hex_dump_highlight_style;
160   gint         gui_toolbar_main_style;
161   gint         gui_toolbar_filter_style; /* GTK only? */
162   gchar       *gui_gtk2_font_name;
163   gchar       *gui_qt_font_name;
164   color_t      gui_marked_fg;
165   color_t      gui_marked_bg;
166   color_t      gui_ignored_fg;
167   color_t      gui_ignored_bg;
168   gchar       *gui_colorized_fg;
169   gchar       *gui_colorized_bg;
170   gboolean     gui_geometry_save_position;
171   gboolean     gui_geometry_save_size;
172   gboolean     gui_geometry_save_maximized;
173   gboolean     gui_macosx_style;
174   console_open_e gui_console_open;
175   guint        gui_recent_df_entries_max;
176   guint        gui_recent_files_count_max;
177   guint        gui_fileopen_style;
178   gchar       *gui_fileopen_dir;
179   guint        gui_fileopen_preview;
180   gboolean     gui_ask_unsaved;
181   gboolean     gui_find_wrap;
182   gboolean     gui_use_pref_save;
183   gchar       *gui_webbrowser;
184   gchar       *gui_window_title;
185   gchar       *gui_prepend_window_title;
186   gchar       *gui_start_title;
187   version_info_e gui_version_placement;
188   gboolean     gui_auto_scroll_on_expand;
189   guint        gui_auto_scroll_percentage;
190   layout_type_e gui_layout_type;
191   layout_pane_content_e gui_layout_content_1;
192   layout_pane_content_e gui_layout_content_2;
193   layout_pane_content_e gui_layout_content_3;
194   gchar       *gui_interfaces_hide_types;
195   gint         console_log_level;
196   gchar       *capture_device;
197   gchar       *capture_devices_linktypes;
198   gchar       *capture_devices_descr;
199   gchar       *capture_devices_hide;
200   gchar       *capture_devices_monitor_mode;
201 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
202   gchar       *capture_devices_buffersize;
203 #endif
204   gchar       *capture_devices_snaplen;
205   gchar       *capture_devices_pmode;
206   gchar       *capture_devices_filter; /* XXX - Mostly unused. Deprecate? */
207   gboolean     capture_prom_mode;
208   gboolean     capture_pcap_ng;
209   gboolean     capture_real_time;
210   gboolean     capture_auto_scroll;
211   gboolean     capture_show_info;
212   GList       *capture_columns;
213   guint        rtp_player_max_visible;
214   guint        tap_update_interval;
215   gboolean     display_hidden_proto_items;
216   gboolean     display_byte_fields_with_spaces;
217   gboolean     enable_incomplete_dissectors_check;
218   gboolean     incomplete_dissectors_check_debug;
219   gpointer     filter_expressions;/* Actually points to &head */
220   gboolean     gui_update_enabled;
221   software_update_channel_e gui_update_channel;
222   gint         gui_update_interval;
223   gchar       *saved_at_version;
224   gboolean     unknown_prefs; /* unknown or obsolete pref(s) */
225   gboolean     unknown_colorfilters; /* Warn when saving unknown or obsolete color filters. */
226   gboolean     gui_qt_packet_list_separator;
227   gboolean     gui_packet_editor; /* Enable Packet Editor */
228   elide_mode_e gui_packet_list_elide_mode;
229   gboolean     gui_packet_list_show_related;
230   gboolean     gui_packet_list_show_minimap;
231   gboolean     st_enable_burstinfo;
232   gboolean     st_burst_showcount;
233   gint         st_burst_resolution;
234   gint         st_burst_windowlen;
235   gboolean     st_sort_casesensitve;
236   gboolean     st_sort_rng_fixorder;
237   gboolean     st_sort_rng_nameonly;
238   gint         st_sort_defcolflag;
239   gboolean     st_sort_defdescending;
240   gboolean     st_sort_showfullname;
241 #ifdef HAVE_EXTCAP
242   gboolean     extcap_save_on_start;
243 #endif
244 } e_prefs;
245
246 WS_DLL_PUBLIC e_prefs prefs;
247
248 /*
249  * Routines to let modules that have preference settings register
250  * themselves by name, and to let them register preference settings
251  * by name.
252  */
253 struct pref_module;
254
255 struct pref_custom_cbs;
256
257 typedef struct pref_module module_t;
258
259 /** Sets up memory used by proto routines. Called at program startup */
260 void prefs_init(void);
261
262 /** Reset preferences to default values.  Called at profile change */
263 WS_DLL_PUBLIC void prefs_reset(void);
264
265 /** Frees memory used by proto routines. Called at program shutdown */
266 void prefs_cleanup(void);
267
268 /*
269  * Register a module that will have preferences.
270  * Specify the module under which to register it or NULL to register it
271  * at the top level, the name used for the module in the preferences file,
272  * the title used in the tab for it in a preferences dialog box, a
273  * routine to call back when we apply the preferences, and if it should
274  * use the GUI controls provided by the preferences or it has its own.
275  *
276  * This should not be used for dissector preferences;
277  * "prefs_register_protocol()" should be used for that, so that the
278  * preferences go under the "Protocols" subtree, and so that the
279  * name is the protocol name specified at the "proto_register_protocol()"
280  * call so that the "Protocol Properties..." menu item works.
281  */
282 WS_DLL_PUBLIC module_t *prefs_register_module(module_t *parent, const char *name,
283     const char *title, const char *description, void (*apply_cb)(void),
284     const gboolean use_gui);
285
286 /*
287  * Register a subtree that will have modules under it.
288  * Specify the module under which to register it or NULL to register it
289  * at the top level and the title used in the tab for it in a preferences
290  * dialog box.
291  */
292 WS_DLL_PUBLIC module_t *prefs_register_subtree(module_t *parent, const char *title,
293     const char *description, void (*apply_cb)(void));
294
295 /*
296  * Register that a protocol has preferences.
297  */
298 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
299
300 /**
301  * Deregister preferences from a protocol.
302  */
303 void prefs_deregister_protocol(int id);
304
305 /*
306  * Register that a statistical tap has preferences.
307  *
308  * "name" is a name for the tap to use on the command line with "-o"
309  * and in preference files.
310  *
311  * "title" is a short human-readable name for the tap.
312  *
313  * "description" is a longer human-readable description of the tap.
314  */
315 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
316     const char *description, void (*apply_cb)(void));
317
318 /*
319  * Register that a protocol has preferences and group it under a single
320  * subtree
321  */
322 #define PREFERENCE_GROUPING
323 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
324     void (*apply_cb)(void));
325
326 /*
327  * Register that a protocol used to have preferences but no longer does,
328  * by creating an "obsolete" module for it.
329  */
330 module_t *prefs_register_protocol_obsolete(int id);
331
332 /*
333  * Callback function for module list scanners.
334  */
335 typedef guint (*module_cb)(module_t *module, gpointer user_data);
336
337 /*
338  * Returns TRUE if module has any submodules
339  */
340 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
341
342 /*
343  * Call a callback function, with a specified argument, for each module
344  * in the list of all modules.  (This list does not include subtrees.)
345  *
346  * Ignores "obsolete" modules; their sole purpose is to allow old
347  * preferences for dissectors that no longer have preferences to be
348  * silently ignored in preference files.
349  */
350 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
351
352 /*
353  * Call a callback function, with a specified argument, for each submodule
354  * of specified modules.  If the module is NULL, goes through the top-level
355  * list in the display tree of modules.
356  *
357  * Ignores "obsolete" modules; their sole purpose is to allow old
358  * preferences for dissectors that no longer have preferences to be
359  * silently ignored in preference files.  Does not ignore subtrees,
360  * as this can be used when walking the display tree of modules.
361  */
362 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
363
364 /*
365  * Call the "apply" callback function for each module if any of its
366  * preferences have changed, and then clear the flag saying its
367  * preferences have changed, as the module has been notified of that
368  * fact.
369  */
370 WS_DLL_PUBLIC void prefs_apply_all(void);
371
372 /*
373  * Call the "apply" callback function for a specific module if any of
374  * its preferences have changed, and then clear the flag saying its
375  * preferences have changed, as the module has been notified of that
376  * fact.
377  */
378 WS_DLL_PUBLIC void prefs_apply(module_t *module);
379
380
381 struct preference;
382
383 typedef struct preference pref_t;
384
385 /*
386  * Returns TRUE if the given protocol has registered preferences.
387  */
388 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
389
390 /*
391  * Returns the module title of a registered protocol (or NULL if unknown).
392  */
393 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
394
395 /** Given a module name, return a pointer to its pref_module struct,
396  * or NULL if it's not found.
397  *
398  * @param name The preference module name.  Usually the same as the protocol
399  * name, e.g. "tcp".
400  * @return A pointer to the corresponding preference module, or NULL if it
401  * wasn't found.
402  */
403 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
404
405 /** Given a module name, and a preference name return a pointer to the given
406  * module's given preference or NULL if it's not found.
407  *
408  * @param module The preference module name.  Usually the same as the protocol
409  * name, e.g. "tcp".
410  * @param pref The preference name, e.g. "desegment".
411  * @return A pointer to the corresponding preference, or NULL if it
412  * wasn't found.
413  */
414 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
415
416 /*
417  * Register a preference with an unsigned integral value.
418  */
419 WS_DLL_PUBLIC void prefs_register_uint_preference(module_t *module, const char *name,
420     const char *title, const char *description, guint base, guint *var);
421
422 /*
423  * Register a preference with an Boolean value.
424  * Note that the name must be in lowercase letters only (underscore allowed).
425  */
426 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
427     const char *title, const char *description, gboolean *var);
428
429 /*
430  * Register a preference with an enumerated value.
431  */
432 WS_DLL_PUBLIC void prefs_register_enum_preference(module_t *module, const char *name,
433     const char *title, const char *description, gint *var,
434     const enum_val_t *enumvals, gboolean radio_buttons);
435
436 /*
437  * Register a preference with a character-string value.
438  */
439 WS_DLL_PUBLIC void prefs_register_string_preference(module_t *module, const char *name,
440     const char *title, const char *description, const char **var);
441
442 /*
443  * Register a preference with a file name (string) value.
444  * File name preferences are basically like string preferences
445  * except that the GUI gives the user the ability to browse for the
446  * file.
447  */
448 WS_DLL_PUBLIC void prefs_register_filename_preference(module_t *module, const char *name,
449     const char *title, const char *description, const char **var);
450
451 /*
452  * Register a preference with a directory name (string) value.
453  * Directory name preferences are basically like string preferences
454  * except that the GUI gives the user the ability to browse for a
455  * directory.
456  */
457 WS_DLL_PUBLIC void prefs_register_directory_preference(module_t *module, const char *name,
458     const char *title, const char *description, const char **var);
459
460 /*
461  * Register a preference with a ranged value.
462  */
463 WS_DLL_PUBLIC void prefs_register_range_preference(module_t *module, const char *name,
464     const char *title, const char *description, range_t **var,
465     guint32 max_value);
466
467 /*
468  * Register a static text 'preference'. It can be used to add some info/explanation.
469  */
470 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
471     const char *title, const char *description);
472
473 /*
474  * Register a uat 'preference'. It adds a button that opens the uat's window in the
475  * preferences tab of the module.
476  */
477 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
478     const char *name, const char* title, const char *description,  struct epan_uat* uat);
479
480 /*
481  * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
482  * preferences tab of the module.
483  */
484 WS_DLL_PUBLIC void prefs_register_uat_preference_qt(module_t *module,
485     const char *name, const char* title, const char *description,  struct epan_uat* uat);
486
487
488 /*
489  * Register a color preference.  Currently does not have any "GUI Dialog" support
490  * so the color data needs to be managed independently.  Currently used by the
491  * "GUI preferences" to aid in reading/writing the preferences file, but the
492  * "data" is still managed by the specific "GUI preferences" dialog.
493  */
494 void prefs_register_color_preference(module_t *module, const char *name,
495     const char *title, const char *description, color_t *color);
496
497 /*
498  * Register a custom preference.  Currently does not have any "GUI Dialog" support
499  * so data needs to be managed independently.  Currently used by the
500  * "GUI preferences" to aid in reading/writing the preferences file, but the
501  * "data" is still managed by the specific "GUI preferences" dialog.
502  */
503 void prefs_register_custom_preference(module_t *module, const char *name,
504     const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
505     void** custom_data);
506
507 /*
508  * Register a (internal) "Decode As" preference with a ranged value.
509  */
510 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
511     const char *title, const char *description, range_t **var,
512     guint32 max_value);
513
514 /*
515  * Register a (internal) "Decode As" preference with an unsigned integral value
516  * for a dissector table.
517  */
518 void prefs_register_decode_as_preference(module_t *module, const char *name,
519     const char *title, const char *description, guint *var);
520
521 /*
522  * Register a preference that used to be supported but no longer is.
523  */
524 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
525     const char *name);
526
527
528 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
529
530 /*
531  * Call a callback function, with a specified argument, for each preference
532  * in a given module.
533  *
534  * If any of the callbacks return a non-zero value, stop and return that
535  * value, otherwise return 0.
536  */
537 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
538     gpointer user_data);
539
540 /* Parse through a list of comma-separated, possibly quoted strings.
541  *  Return a list of the string data.
542  */
543 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
544
545 /* Clear the given list of string data. */
546 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
547
548 /** Fetch a short preference type name, e.g. "Integer".
549  *
550  * @param pref A preference.
551  *
552  * @return The preference type name. May be NULL.
553  */
554 WS_DLL_PUBLIC
555 const char *prefs_pref_type_name(pref_t *pref);
556
557 /** Fetch a long description of the preference type
558  *
559  * @param pref A preference.
560  *
561  * @return A description of the preference type including allowed
562  * values for enums. The description may include newlines. Must be
563  * g_free()d.
564  */
565 WS_DLL_PUBLIC
566 char *prefs_pref_type_description(pref_t *pref);
567
568 /** Fetch a string representation of the preference.
569  *
570  * @param pref A preference.
571  * @param source Which value of the preference to return, see pref_source_t.
572  *
573  * @return A string representation of the preference. Must be g_free()d.
574  */
575 WS_DLL_PUBLIC
576 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
577
578 /* Read the preferences file, fill in "prefs", and return a pointer to it.
579
580    If we got an error (other than "it doesn't exist") trying to read
581    the global preferences file, stuff the errno into "*gpf_errno_return"
582    on an open error and into "*gpf_read_errno_return" on a read error,
583    stuff a pointer to the path of the file into "*gpf_path_return", and
584    return NULL.
585
586    If we got an error (other than "it doesn't exist") trying to read
587    the user's preferences file, stuff the errno into "*pf_errno_return"
588    on an open error and into "*pf_read_errno_return" on a read error,
589    stuff a pointer to the path of the file into "*pf_path_return", and
590    return NULL. */
591 WS_DLL_PUBLIC e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
592
593 /* Write out "prefs" to the user's preferences file, and return 0.
594
595    If we got an error, stuff a pointer to the path of the preferences file
596    into "*pf_path_return", and return the errno. */
597 WS_DLL_PUBLIC int write_prefs(char **);
598
599 /*
600  * Given a string of the form "<pref name>:<pref value>", as might appear
601  * as an argument to a "-o" option, parse it and set the preference in
602  * question.  Return an indication of whether it succeeded or failed
603  * in some fashion.
604  *
605  * XXX - should supply, for syntax errors, a detailed explanation of
606  * the syntax error.
607  */
608 typedef enum {
609     PREFS_SET_OK,               /* succeeded */
610     PREFS_SET_SYNTAX_ERR,       /* syntax error in string */
611     PREFS_SET_NO_SUCH_PREF,     /* no such preference */
612     PREFS_SET_OBSOLETE          /* preference used to exist but no longer does */
613 } prefs_set_pref_e;
614
615 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
616
617 /*
618  * Get or set a preference's obsolete status. These can be used to make a
619  * preference obsolete after startup so that we can fetch its value but
620  * keep it from showing up in the prefrences dialog.
621  */
622 gboolean prefs_get_preference_obsolete(pref_t *pref);
623 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
624
625
626 /*
627  * Returns TRUE if the given device is hidden
628  */
629 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
630
631 /*
632  * Returns TRUE if the given device should capture in monitor mode by default
633  */
634 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
635
636 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
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  */