2 * Definitions for preference handling routines
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #endif /* __cplusplus */
36 #include <epan/addr_resolv.h>
37 #include <epan/params.h>
38 #include <epan/range.h>
41 #include "ws_symbol_export.h"
44 #define PR_DEST_FILE 1
47 #define DEF_HEIGHT 550
49 #define MAX_VAL_LEN 1024
51 #define RTP_PLAYER_DEFAULT_VISIBLE 4
52 #define TAP_UPDATE_DEFAULT_INTERVAL 3000
55 * Convert a string listing name resolution types to a bitmask of
58 * Set "*name_resolve" to the bitmask, and return '\0', on success;
59 * return the bad character in the string on error.
62 char string_to_name_resolve(const char *string, e_addr_resolve *name_resolve);
65 * Modes for the starting directory in File Open dialogs.
67 #define FO_STYLE_LAST_OPENED 0 /* start in last directory we looked at */
68 #define FO_STYLE_SPECIFIED 1 /* start in specified directory */
73 #define TB_STYLE_ICONS 0
74 #define TB_STYLE_TEXT 1
75 #define TB_STYLE_BOTH 2
78 * Types of layout of summary/details/hex panes.
81 layout_unused, /* entry currently unused */
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;
102 * open console behaviour (win32 only)
111 * Places version information will show up
114 version_welcome_only,
130 UPDATE_CHANNEL_DEVELOPMENT,
131 UPDATE_CHANNEL_STABLE
132 } software_update_channel_e;
134 typedef struct _e_prefs {
137 const gchar *pr_file;
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;
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 */
212 WS_DLL_PUBLIC e_prefs prefs;
215 * Routines to let modules that have preference settings register
216 * themselves by name, and to let them register preference settings
221 struct pref_custom_cbs;
223 typedef struct pref_module module_t;
225 /** Sets up memory used by proto routines. Called at program startup */
226 void prefs_init(void);
228 /** Reset preferences to default values. Called at profile change */
229 WS_DLL_PUBLIC void prefs_reset(void);
231 /** Frees memory used by proto routines. Called at program shutdown */
232 void prefs_cleanup(void);
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.
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.
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);
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
258 module_t *prefs_register_subtree(module_t *parent, const char *title,
259 const char *description, void (*apply_cb)(void));
262 * Register that a protocol has preferences.
264 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
267 * Register that a statistical tap has preferences.
269 * "name" is a name for the tap to use on the command line with "-o"
270 * and in preference files.
272 * "title" is a short human-readable name for the tap.
274 * "description" is a longer human-readable description of the tap.
276 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
277 const char *description,
278 void (*apply_cb)(void));
281 * Register that a protocol has preferences and group it under a single
284 #define PREFERENCE_GROUPING
285 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
286 void (*apply_cb)(void));
289 * Register that a protocol used to have preferences but no longer does,
290 * by creating an "obsolete" module for it.
292 module_t *prefs_register_protocol_obsolete(int id);
295 * Callback function for module list scanners.
297 typedef guint (*module_cb)(module_t *module, gpointer user_data);
300 * Returns TRUE if module has any submodules
302 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
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.)
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.
312 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
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.
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.
324 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
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
332 WS_DLL_PUBLIC void prefs_apply_all(void);
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
340 WS_DLL_PUBLIC void prefs_apply(module_t *module);
345 typedef struct preference pref_t;
348 * Returns TRUE if the given protocol has registered preferences.
350 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
353 * Returns the module title of a registered protocol (or NULL if unknown).
355 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
357 /** Given a module name, return a pointer to its pref_module struct,
358 * or NULL if it's not found.
360 * @param name The preference module name. Usually the same as the protocol
362 * @return A pointer to the corresponding preference module, or NULL if it
365 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
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.
370 * @param module The preference module name. Usually the same as the protocol
372 * @param pref The preference name, e.g. "desegment".
373 * @return A pointer to the corresponding preference, or NULL if it
376 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
379 * Register a preference with an unsigned integral value.
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);
385 * Register a preference with an Boolean value.
386 * Note that the name must be in lowercase letters only (underscore allowed).
388 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
389 const char *title, const char *description, gboolean *var);
392 * Register a preference with an enumerated value.
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);
399 * Register a preference with a character-string value.
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);
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
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);
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
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);
423 * Register a preference with a ranged value.
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,
430 * Register a static text 'preference'. It can be used to add some info/explanation.
432 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
433 const char *title, const char *description);
436 * Register a uat 'preference'. It adds a button that opens the uat's window in the
437 * preferences tab of the module.
439 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
442 const char *description,
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.
451 void prefs_register_color_preference(module_t *module, const char *name,
452 const char *title, const char *description, color_t *color);
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.
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,
465 * Register a preference that used to be supported but no longer is.
467 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
471 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
474 * Call a callback function, with a specified argument, for each preference
477 * If any of the callbacks return a non-zero value, stop and return that
478 * value, otherwise return 0.
480 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
483 /* Parse through a list of comma-separated, possibly quoted strings.
484 * Return a list of the string data.
486 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
488 /* Clear the given list of string data. */
489 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
492 * Register all non-dissector modules' preferences.
494 WS_DLL_PUBLIC void prefs_register_modules(void);
496 /** Fetch a short preference type name, e.g. "Integer".
498 * @param pref A preference.
500 * @return The preference type name. May be NULL.
503 const char *prefs_pref_type_name(pref_t *pref);
505 /** Fetch a long description of the preference type
507 * @param pref A preference.
509 * @return A description of the preference type including allowed
510 * values for enums. The description may include newlines. Must be
514 char *prefs_pref_type_description(pref_t *pref);
516 /** Fetch a string representation of the preference.
518 * @param pref A preference.
519 * @param source Which value of the preference to return, see pref_source_t.
521 * @return A string representation of the preference. Must be g_free()d.
524 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
526 /* Read the preferences file, fill in "prefs", and return a pointer to it.
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
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
539 WS_DLL_PUBLIC e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
541 /* Write out "prefs" to the user's preferences file, and return 0.
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 **);
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
553 * XXX - should supply, for syntax errors, a detailed explanation of
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 */
563 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
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.
570 gboolean prefs_get_preference_obsolete(pref_t *pref);
571 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
575 * Returns TRUE if the given device is hidden
577 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
580 * Returns TRUE if the given device should capture in monitor mode by default
582 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
584 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
588 #endif /* __cplusplus */