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) */
211 WS_DLL_PUBLIC e_prefs prefs;
214 * Routines to let modules that have preference settings register
215 * themselves by name, and to let them register preference settings
220 struct pref_custom_cbs;
222 typedef struct pref_module module_t;
224 /** Sets up memory used by proto routines. Called at program startup */
225 void prefs_init(void);
227 /** Reset preferences to default values. Called at profile change */
228 WS_DLL_PUBLIC void prefs_reset(void);
230 /** Frees memory used by proto routines. Called at program shutdown */
231 void prefs_cleanup(void);
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.
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.
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);
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
257 module_t *prefs_register_subtree(module_t *parent, const char *title,
258 const char *description, void (*apply_cb)(void));
261 * Register that a protocol has preferences.
263 WS_DLL_PUBLIC module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
266 * Register that a statistical tap has preferences.
268 * "name" is a name for the tap to use on the command line with "-o"
269 * and in preference files.
271 * "title" is a short human-readable name for the tap.
273 * "description" is a longer human-readable description of the tap.
275 WS_DLL_PUBLIC module_t *prefs_register_stat(const char *name, const char *title,
276 const char *description,
277 void (*apply_cb)(void));
280 * Register that a protocol has preferences and group it under a single
283 #define PREFERENCE_GROUPING
284 WS_DLL_PUBLIC module_t *prefs_register_protocol_subtree(const char *subtree, int id,
285 void (*apply_cb)(void));
288 * Register that a protocol used to have preferences but no longer does,
289 * by creating an "obsolete" module for it.
291 module_t *prefs_register_protocol_obsolete(int id);
294 * Callback function for module list scanners.
296 typedef guint (*module_cb)(module_t *module, gpointer user_data);
299 * Returns TRUE if module has any submodules
301 WS_DLL_PUBLIC gboolean prefs_module_has_submodules(module_t *module);
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.)
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.
311 WS_DLL_PUBLIC guint prefs_modules_foreach(module_cb callback, gpointer user_data);
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.
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.
323 WS_DLL_PUBLIC guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
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
331 WS_DLL_PUBLIC void prefs_apply_all(void);
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
339 WS_DLL_PUBLIC void prefs_apply(module_t *module);
344 typedef struct preference pref_t;
347 * Returns TRUE if the given protocol has registered preferences.
349 WS_DLL_PUBLIC gboolean prefs_is_registered_protocol(const char *name);
352 * Returns the module title of a registered protocol (or NULL if unknown).
354 WS_DLL_PUBLIC const char *prefs_get_title_by_name(const char *name);
356 /** Given a module name, return a pointer to its pref_module struct,
357 * or NULL if it's not found.
359 * @param name The preference module name. Usually the same as the protocol
361 * @return A pointer to the corresponding preference module, or NULL if it
364 WS_DLL_PUBLIC module_t *prefs_find_module(const char *name);
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.
369 * @param module The preference module name. Usually the same as the protocol
371 * @param pref The preference name, e.g. "desegment".
372 * @return A pointer to the corresponding preference, or NULL if it
375 WS_DLL_PUBLIC pref_t *prefs_find_preference(module_t * module, const char *pref);
378 * Register a preference with an unsigned integral value.
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);
384 * Register a preference with an Boolean value.
385 * Note that the name must be in lowercase letters only (underscore allowed).
387 WS_DLL_PUBLIC void prefs_register_bool_preference(module_t *module, const char *name,
388 const char *title, const char *description, gboolean *var);
391 * Register a preference with an enumerated value.
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);
398 * Register a preference with a character-string value.
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);
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
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);
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
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);
422 * Register a preference with a ranged value.
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,
429 * Register a static text 'preference'. It can be used to add some info/explanation.
431 WS_DLL_PUBLIC void prefs_register_static_text_preference(module_t *module, const char *name,
432 const char *title, const char *description);
435 * Register a uat 'preference'. It adds a button that opens the uat's window in the
436 * preferences tab of the module.
438 WS_DLL_PUBLIC void prefs_register_uat_preference(module_t *module,
441 const char *description,
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.
450 void prefs_register_color_preference(module_t *module, const char *name,
451 const char *title, const char *description, color_t *color);
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.
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,
464 * Register a preference that used to be supported but no longer is.
466 WS_DLL_PUBLIC void prefs_register_obsolete_preference(module_t *module,
470 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
473 * Call a callback function, with a specified argument, for each preference
476 * If any of the callbacks return a non-zero value, stop and return that
477 * value, otherwise return 0.
479 WS_DLL_PUBLIC guint prefs_pref_foreach(module_t *module, pref_cb callback,
482 /* Parse through a list of comma-separated, possibly quoted strings.
483 * Return a list of the string data.
485 WS_DLL_PUBLIC GList *prefs_get_string_list(const gchar *str);
487 /* Clear the given list of string data. */
488 WS_DLL_PUBLIC void prefs_clear_string_list(GList *sl);
491 * Register all non-dissector modules' preferences.
493 WS_DLL_PUBLIC void prefs_register_modules(void);
495 /** Fetch a short preference type name, e.g. "Integer".
497 * @param pref A preference.
499 * @return The preference type name. May be NULL.
502 const char *prefs_pref_type_name(pref_t *pref);
504 /** Fetch a long description of the preference type
506 * @param pref A preference.
508 * @return A description of the preference type including allowed
509 * values for enums. The description may include newlines. Must be
513 char *prefs_pref_type_description(pref_t *pref);
515 /** Fetch a string representation of the preference.
517 * @param pref A preference.
518 * @param source Which value of the preference to return, see pref_source_t.
520 * @return A string representation of the preference. Must be g_free()d.
523 char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
525 /* Read the preferences file, fill in "prefs", and return a pointer to it.
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
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
538 WS_DLL_PUBLIC e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
540 /* Write out "prefs" to the user's preferences file, and return 0.
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 **);
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
552 * XXX - should supply, for syntax errors, a detailed explanation of
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 */
562 WS_DLL_PUBLIC prefs_set_pref_e prefs_set_pref(char *prefarg);
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.
569 gboolean prefs_get_preference_obsolete(pref_t *pref);
570 prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
574 * Returns TRUE if the given device is hidden
576 WS_DLL_PUBLIC gboolean prefs_is_capture_device_hidden(const char *name);
579 * Returns TRUE if the given device should capture in monitor mode by default
581 WS_DLL_PUBLIC gboolean prefs_capture_device_monitor_mode(const char *name);
583 WS_DLL_PUBLIC gboolean prefs_capture_options_dialog_column_is_visible(const gchar *column);
587 #endif /* __cplusplus */