separate function for dissecting the adaptation field
[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   guint        gui_qt_language;       /* Qt Translation language selection */
210 } e_prefs;
211
212 WS_DLL_PUBLIC e_prefs prefs;
213
214 /*
215  * Routines to let modules that have preference settings register
216  * themselves by name, and to let them register preference settings
217  * by name.
218  */
219 struct pref_module;
220
221 struct pref_custom_cbs;
222
223 typedef struct pref_module module_t;
224
225 /** Sets up memory used by proto routines. Called at program startup */
226 void prefs_init(void);
227
228 /** Reset preferences to default values.  Called at profile change */
229 WS_DLL_PUBLIC void prefs_reset(void);
230
231 /** Frees memory used by proto routines. Called at program shutdown */
232 void prefs_cleanup(void);
233
234 /*
235  * Register a module that will have preferences.
236  * Specify the module under which to register it or NULL to register it
237  * at the top level, the name used for the module in the preferences file,
238  * the title used in the tab for it in a preferences dialog box, a
239  * routine to call back when we apply the preferences, and if it should
240  * use the GUI controls provided by the preferences or it has its own.
241  *
242  * This should not be used for dissector preferences;
243  * "prefs_register_protocol()" should be used for that, so that the
244  * preferences go under the "Protocols" subtree, and so that the
245  * name is the protocol name specified at the "proto_register_protocol()"
246  * call so that the "Protocol Properties..." menu item works.
247  */
248 module_t *prefs_register_module(module_t *parent, const char *name,
249     const char *title, const char *description, void (*apply_cb)(void),
250     const gboolean use_gui);
251
252 /*
253  * Register a subtree that will have modules under it.
254  * Specify the module under which to register it or NULL to register it
255  * at the top level and the title used in the tab for it in a preferences
256  * dialog box.
257  */
258 module_t *prefs_register_subtree(module_t *parent, const char *title,
259     const char *description, void (*apply_cb)(void));
260
261 /*
262  * Register that a protocol has preferences.
263  */
264 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
265
266 /*
267  * Register that a statistical tap has preferences.
268  *
269  * "name" is a name for the tap to use on the command line with "-o"
270  * and in preference files.
271  *
272  * "title" is a short human-readable name for the tap.
273  *
274  * "description" is a longer human-readable description of the tap.
275  */
276 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
277                                      const char *description,
278                                      void (*apply_cb)(void));
279
280 /*
281  * Register that a protocol has preferences and group it under a single
282  * subtree
283  */
284 #define PREFERENCE_GROUPING
285 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
286                                                  void (*apply_cb)(void));
287
288 /*
289  * Register that a protocol used to have preferences but no longer does,
290  * by creating an "obsolete" module for it.
291  */
292 module_t *prefs_register_protocol_obsolete(int id);
293
294 /*
295  * Callback function for module list scanners.
296  */
297 typedef guint (*module_cb)(module_t *module, gpointer user_data);
298
299 /*
300  * Returns TRUE if module has any submodules
301  */
302 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
303
304 /*
305  * Call a callback function, with a specified argument, for each module
306  * in the list of all modules.  (This list does not include subtrees.)
307  *
308  * Ignores "obsolete" modules; their sole purpose is to allow old
309  * preferences for dissectors that no longer have preferences to be
310  * silently ignored in preference files.
311  */
312 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
313
314 /*
315  * Call a callback function, with a specified argument, for each submodule
316  * of specified modules.  If the module is NULL, goes through the top-level
317  * list in the display tree of modules.
318  *
319  * Ignores "obsolete" modules; their sole purpose is to allow old
320  * preferences for dissectors that no longer have preferences to be
321  * silently ignored in preference files.  Does not ignore subtrees,
322  * as this can be used when walking the display tree of modules.
323  */
324 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
325
326 /*
327  * Call the "apply" callback function for each module if any of its
328  * preferences have changed, and then clear the flag saying its
329  * preferences have changed, as the module has been notified of that
330  * fact.
331  */
332 WS_DLL_PUBLIC void prefs_apply_all(void);
333
334 /*
335  * Call the "apply" callback function for a specific module if any of
336  * its preferences have changed, and then clear the flag saying its
337  * preferences have changed, as the module has been notified of that
338  * fact.
339  */
340 WS_DLL_PUBLIC void prefs_apply(module_t *module);
341
342
343 struct preference;
344
345 typedef struct preference pref_t;
346
347 /*
348  * Returns TRUE if the given protocol has registered preferences.
349  */
350 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
351
352 /*
353  * Returns the module title of a registered protocol (or NULL if unknown).
354  */
355 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
356
357 /** Given a module name, return a pointer to its pref_module struct,
358  * or NULL if it's not found.
359  *
360  * @param name The preference module name.  Usually the same as the protocol
361  * name, e.g. "tcp".
362  * @return A pointer to the corresponding preference module, or NULL if it
363  * wasn't found.
364  */
365 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
366
367 /** Given a module name, and a preference name return a pointer to the given
368  * module's given preference or NULL if it's not found.
369  *
370  * @param module The preference module name.  Usually the same as the protocol
371  * name, e.g. "tcp".
372  * @param pref The preference name, e.g. "desegment".
373  * @return A pointer to the corresponding preference, or NULL if it
374  * wasn't found.
375  */
376 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
377
378 /*
379  * Register a preference with an unsigned integral value.
380  */
381 WS_DLL_PUBLIC void prefs_register_uint_preference(module_t *module, const char *name,
382     const char *title, const char *description, guint base, guint *var);
383
384 /*
385  * Register a preference with an Boolean value.
386  * Note that the name must be in lowercase letters only (underscore allowed).
387  */
388 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
389     const char *title, const char *description, gboolean *var);
390
391 /*
392  * Register a preference with an enumerated value.
393  */
394 WS_DLL_PUBLIC void prefs_register_enum_preference(module_t *module, const char *name,
395     const char *title, const char *description, gint *var,
396     const enum_val_t *enumvals, gboolean radio_buttons);
397
398 /*
399  * Register a preference with a character-string value.
400  */
401 WS_DLL_PUBLIC void prefs_register_string_preference(module_t *module, const char *name,
402     const char *title, const char *description, const char **var);
403
404 /*
405  * Register a preference with a file name (string) value.
406  * File name preferences are basically like string preferences
407  * except that the GUI gives the user the ability to browse for the
408  * file.
409  */
410 WS_DLL_PUBLIC void prefs_register_filename_preference(module_t *module, const char *name,
411     const char *title, const char *description, const char **var);
412
413 /*
414  * Register a preference with a directory name (string) value.
415  * Directory name preferences are basically like string preferences
416  * except that the GUI gives the user the ability to browse for a
417  * directory.
418  */
419 WS_DLL_PUBLIC void prefs_register_directory_preference(module_t *module, const char *name,
420     const char *title, const char *description, const char **var);
421
422 /*
423  * Register a preference with a ranged value.
424  */
425 WS_DLL_PUBLIC void prefs_register_range_preference(module_t *module, const char *name,
426     const char *title, const char *description, range_t **var,
427     guint32 max_value);
428
429 /*
430  * Register a static text 'preference'. It can be used to add some info/explanation.
431  */
432 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
433     const char *title, const char *description);
434
435 /*
436  * Register a uat 'preference'. It adds a button that opens the uat's window in the
437  * preferences tab of the module.
438  */
439 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
440                                                                                   const char *name,
441                                                                                   const char* title,
442                                                                                   const char *description,
443                                                                                   uat_t* uat);
444
445 /*
446  * Register a color preference.  Currently does not have any "GUI Dialog" support
447  * so the color data needs to be managed independently.  Currently used by the 
448  * "GUI preferences" to aid in reading/writing the preferences file, but the 
449  * "data" is still managed by the specific "GUI preferences" dialog.
450  */
451 void prefs_register_color_preference(module_t *module, const char *name,
452     const char *title, const char *description, color_t *color);
453
454 /*
455  * Register a custom preference.  Currently does not have any "GUI Dialog" support
456  * so data needs to be managed independently.  Currently used by the 
457  * "GUI preferences" to aid in reading/writing the preferences file, but the 
458  * "data" is still managed by the specific "GUI preferences" dialog.
459  */
460 void prefs_register_custom_preference(module_t *module, const char *name,
461     const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
462     void** custom_data);
463
464 /*
465  * Register a preference that used to be supported but no longer is.
466  */
467 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
468     const char *name);
469
470
471 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
472
473 /*
474  * Call a callback function, with a specified argument, for each preference
475  * in a given module.
476  *
477  * If any of the callbacks return a non-zero value, stop and return that
478  * value, otherwise return 0.
479  */
480 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
481     gpointer user_data);
482
483 /* Parse through a list of comma-separated, possibly quoted strings.
484  *  Return a list of the string data.
485  */
486 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
487
488 /* Clear the given list of string data. */
489 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
490
491 /*
492  * Register all non-dissector modules' preferences.
493  */
494 WS_DLL_PUBLIC void prefs_register_modules(void);
495
496 /** Fetch a short preference type name, e.g. "Integer".
497  *
498  * @param pref A preference.
499  *
500  * @return The preference type name. May be NULL.
501  */
502 WS_DLL_PUBLIC
503 const char *prefs_pref_type_name(pref_t *pref);
504
505 /** Fetch a long description of the preference type
506  *
507  * @param pref A preference.
508  *
509  * @return A description of the preference type including allowed
510  * values for enums. The description may include newlines. Must be
511  * g_free()d.
512  */
513 WS_DLL_PUBLIC
514 char *prefs_pref_type_description(pref_t *pref);
515
516 /** Fetch a string representation of the preference.
517  *
518  * @param pref A preference.
519  * @param source Which value of the preference to return, see pref_source_t.
520  *
521  * @return A string representation of the preference. Must be g_free()d.
522  */
523 WS_DLL_PUBLIC
524 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
525
526 /* Read the preferences file, fill in "prefs", and return a pointer to it.
527
528    If we got an error (other than "it doesn't exist") trying to read
529    the global preferences file, stuff the errno into "*gpf_errno_return"
530    on an open error and into "*gpf_read_errno_return" on a read error,
531    stuff a pointer to the path of the file into "*gpf_path_return", and
532    return NULL.
533
534    If we got an error (other than "it doesn't exist") trying to read
535    the user's preferences file, stuff the errno into "*pf_errno_return"
536    on an open error and into "*pf_read_errno_return" on a read error,
537    stuff a pointer to the path of the file into "*pf_path_return", and
538    return NULL. */
539 WS_DLL_PUBLIC e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
540
541 /* Write out "prefs" to the user's preferences file, and return 0.
542
543    If we got an error, stuff a pointer to the path of the preferences file
544    into "*pf_path_return", and return the errno. */
545 WS_DLL_PUBLIC int write_prefs(char **);
546
547 /*
548  * Given a string of the form "<pref name>:<pref value>", as might appear
549  * as an argument to a "-o" option, parse it and set the preference in
550  * question.  Return an indication of whether it succeeded or failed
551  * in some fashion.
552  *
553  * XXX - should supply, for syntax errors, a detailed explanation of
554  * the syntax error.
555  */
556 typedef enum {
557     PREFS_SET_OK,               /* succeeded */
558     PREFS_SET_SYNTAX_ERR,       /* syntax error in string */
559     PREFS_SET_NO_SUCH_PREF,     /* no such preference */
560     PREFS_SET_OBSOLETE          /* preference used to exist but no longer does */
561 } prefs_set_pref_e;
562
563 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
564
565 /*
566  * Get or set a preference's obsolete status. These can be used to make a
567  * preference obsolete after startup so that we can fetch its value but
568  * keep it from showing up in the prefrences dialog.
569  */
570 gboolean prefs_get_preference_obsolete(pref_t *pref);
571 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
572
573
574 /*
575  * Returns TRUE if the given device is hidden
576  */
577 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
578
579 /*
580  * Returns TRUE if the given device should capture in monitor mode by default
581  */
582 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
583
584 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
585
586 #ifdef __cplusplus
587 }
588 #endif /* __cplusplus */
589
590 #endif /* prefs.h */