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