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 */
210 gboolean gui_packet_editor
; /* Enable Packet Editor */
213 WS_DLL_PUBLIC e_prefs prefs
;
216 * Routines to let modules that have preference settings register
217 * themselves by name, and to let them register preference settings
222 struct pref_custom_cbs
;
224 typedef struct pref_module module_t
;
226 /** Sets up memory used by proto routines. Called at program startup */
227 void prefs_init(void);
229 /** Reset preferences to default values. Called at profile change */
230 WS_DLL_PUBLIC
void prefs_reset(void);
232 /** Frees memory used by proto routines. Called at program shutdown */
233 void prefs_cleanup(void);
236 * Register a module that will have preferences.
237 * Specify the module under which to register it or NULL to register it
238 * at the top level, the name used for the module in the preferences file,
239 * the title used in the tab for it in a preferences dialog box, a
240 * routine to call back when we apply the preferences, and if it should
241 * use the GUI controls provided by the preferences or it has its own.
243 * This should not be used for dissector preferences;
244 * "prefs_register_protocol()" should be used for that, so that the
245 * preferences go under the "Protocols" subtree, and so that the
246 * name is the protocol name specified at the "proto_register_protocol()"
247 * call so that the "Protocol Properties..." menu item works.
249 module_t
*prefs_register_module(module_t
*parent
, const char *name
,
250 const char *title
, const char *description
, void (*apply_cb
)(void),
251 const gboolean use_gui
);
254 * Register a subtree that will have modules under it.
255 * Specify the module under which to register it or NULL to register it
256 * at the top level and the title used in the tab for it in a preferences
259 module_t
*prefs_register_subtree(module_t
*parent
, const char *title
,
260 const char *description
, void (*apply_cb
)(void));
263 * Register that a protocol has preferences.
265 WS_DLL_PUBLIC module_t
*prefs_register_protocol(int id
, void (*apply_cb
)(void));
268 * Register that a statistical tap has preferences.
270 * "name" is a name for the tap to use on the command line with "-o"
271 * and in preference files.
273 * "title" is a short human-readable name for the tap.
275 * "description" is a longer human-readable description of the tap.
277 WS_DLL_PUBLIC module_t
*prefs_register_stat(const char *name
, const char *title
,
278 const char *description
,
279 void (*apply_cb
)(void));
282 * Register that a protocol has preferences and group it under a single
285 #define PREFERENCE_GROUPING
286 WS_DLL_PUBLIC module_t
*prefs_register_protocol_subtree(const char *subtree
, int id
,
287 void (*apply_cb
)(void));
290 * Register that a protocol used to have preferences but no longer does,
291 * by creating an "obsolete" module for it.
293 module_t
*prefs_register_protocol_obsolete(int id
);
296 * Callback function for module list scanners.
298 typedef guint (*module_cb
)(module_t
*module
, gpointer user_data
);
301 * Returns TRUE if module has any submodules
303 WS_DLL_PUBLIC gboolean
prefs_module_has_submodules(module_t
*module
);
306 * Call a callback function, with a specified argument, for each module
307 * in the list of all modules. (This list does not include subtrees.)
309 * Ignores "obsolete" modules; their sole purpose is to allow old
310 * preferences for dissectors that no longer have preferences to be
311 * silently ignored in preference files.
313 WS_DLL_PUBLIC guint
prefs_modules_foreach(module_cb callback
, gpointer user_data
);
316 * Call a callback function, with a specified argument, for each submodule
317 * of specified modules. If the module is NULL, goes through the top-level
318 * list in the display tree of modules.
320 * Ignores "obsolete" modules; their sole purpose is to allow old
321 * preferences for dissectors that no longer have preferences to be
322 * silently ignored in preference files. Does not ignore subtrees,
323 * as this can be used when walking the display tree of modules.
325 WS_DLL_PUBLIC guint
prefs_modules_foreach_submodules(module_t
*module
, module_cb callback
, gpointer user_data
);
328 * Call the "apply" callback function for each module if any of its
329 * preferences have changed, and then clear the flag saying its
330 * preferences have changed, as the module has been notified of that
333 WS_DLL_PUBLIC
void prefs_apply_all(void);
336 * Call the "apply" callback function for a specific module if any of
337 * its preferences have changed, and then clear the flag saying its
338 * preferences have changed, as the module has been notified of that
341 WS_DLL_PUBLIC
void prefs_apply(module_t
*module
);
346 typedef struct preference pref_t
;
349 * Returns TRUE if the given protocol has registered preferences.
351 WS_DLL_PUBLIC gboolean
prefs_is_registered_protocol(const char *name
);
354 * Returns the module title of a registered protocol (or NULL if unknown).
356 WS_DLL_PUBLIC
const char *prefs_get_title_by_name(const char *name
);
358 /** Given a module name, return a pointer to its pref_module struct,
359 * or NULL if it's not found.
361 * @param name The preference module name. Usually the same as the protocol
363 * @return A pointer to the corresponding preference module, or NULL if it
366 WS_DLL_PUBLIC module_t
*prefs_find_module(const char *name
);
368 /** Given a module name, and a preference name return a pointer to the given
369 * module's given preference or NULL if it's not found.
371 * @param module The preference module name. Usually the same as the protocol
373 * @param pref The preference name, e.g. "desegment".
374 * @return A pointer to the corresponding preference, or NULL if it
377 WS_DLL_PUBLIC pref_t
*prefs_find_preference(module_t
* module
, const char *pref
);
380 * Register a preference with an unsigned integral value.
382 WS_DLL_PUBLIC
void prefs_register_uint_preference(module_t
*module
, const char *name
,
383 const char *title
, const char *description
, guint base
, guint
*var
);
386 * Register a preference with an Boolean value.
387 * Note that the name must be in lowercase letters only (underscore allowed).
389 WS_DLL_PUBLIC
void prefs_register_bool_preference(module_t
*module
, const char *name
,
390 const char *title
, const char *description
, gboolean
*var
);
393 * Register a preference with an enumerated value.
395 WS_DLL_PUBLIC
void prefs_register_enum_preference(module_t
*module
, const char *name
,
396 const char *title
, const char *description
, gint
*var
,
397 const enum_val_t
*enumvals
, gboolean radio_buttons
);
400 * Register a preference with a character-string value.
402 WS_DLL_PUBLIC
void prefs_register_string_preference(module_t
*module
, const char *name
,
403 const char *title
, const char *description
, const char **var
);
406 * Register a preference with a file name (string) value.
407 * File name preferences are basically like string preferences
408 * except that the GUI gives the user the ability to browse for the
411 WS_DLL_PUBLIC
void prefs_register_filename_preference(module_t
*module
, const char *name
,
412 const char *title
, const char *description
, const char **var
);
415 * Register a preference with a directory name (string) value.
416 * Directory name preferences are basically like string preferences
417 * except that the GUI gives the user the ability to browse for a
420 WS_DLL_PUBLIC
void prefs_register_directory_preference(module_t
*module
, const char *name
,
421 const char *title
, const char *description
, const char **var
);
424 * Register a preference with a ranged value.
426 WS_DLL_PUBLIC
void prefs_register_range_preference(module_t
*module
, const char *name
,
427 const char *title
, const char *description
, range_t
**var
,
431 * Register a static text 'preference'. It can be used to add some info/explanation.
433 WS_DLL_PUBLIC
void prefs_register_static_text_preference(module_t
*module
, const char *name
,
434 const char *title
, const char *description
);
437 * Register a uat 'preference'. It adds a button that opens the uat's window in the
438 * preferences tab of the module.
440 WS_DLL_PUBLIC
void prefs_register_uat_preference(module_t
*module
,
443 const char *description
,
447 * Register a color preference. Currently does not have any "GUI Dialog" support
448 * so the color data needs to be managed independently. Currently used by the
449 * "GUI preferences" to aid in reading/writing the preferences file, but the
450 * "data" is still managed by the specific "GUI preferences" dialog.
452 void prefs_register_color_preference(module_t
*module
, const char *name
,
453 const char *title
, const char *description
, color_t
*color
);
456 * Register a custom preference. Currently does not have any "GUI Dialog" support
457 * so data needs to be managed independently. Currently used by the
458 * "GUI preferences" to aid in reading/writing the preferences file, but the
459 * "data" is still managed by the specific "GUI preferences" dialog.
461 void prefs_register_custom_preference(module_t
*module
, const char *name
,
462 const char *title
, const char *description
, struct pref_custom_cbs
* custom_cbs
,
466 * Register a preference that used to be supported but no longer is.
468 WS_DLL_PUBLIC
void prefs_register_obsolete_preference(module_t
*module
,
472 typedef guint (*pref_cb
)(pref_t
*pref
, gpointer user_data
);
475 * Call a callback function, with a specified argument, for each preference
478 * If any of the callbacks return a non-zero value, stop and return that
479 * value, otherwise return 0.
481 WS_DLL_PUBLIC guint
prefs_pref_foreach(module_t
*module
, pref_cb callback
,
484 /* Parse through a list of comma-separated, possibly quoted strings.
485 * Return a list of the string data.
487 WS_DLL_PUBLIC GList
*prefs_get_string_list(const gchar
*str
);
489 /* Clear the given list of string data. */
490 WS_DLL_PUBLIC
void prefs_clear_string_list(GList
*sl
);
493 * Register all non-dissector modules' preferences.
495 WS_DLL_PUBLIC
void prefs_register_modules(void);
497 /** Fetch a short preference type name, e.g. "Integer".
499 * @param pref A preference.
501 * @return The preference type name. May be NULL.
504 const char *prefs_pref_type_name(pref_t
*pref
);
506 /** Fetch a long description of the preference type
508 * @param pref A preference.
510 * @return A description of the preference type including allowed
511 * values for enums. The description may include newlines. Must be
515 char *prefs_pref_type_description(pref_t
*pref
);
517 /** Fetch a string representation of the preference.
519 * @param pref A preference.
520 * @param source Which value of the preference to return, see pref_source_t.
522 * @return A string representation of the preference. Must be g_free()d.
525 char *prefs_pref_to_str(pref_t
*pref
, pref_source_t source
);
527 /* Read the preferences file, fill in "prefs", and return a pointer to it.
529 If we got an error (other than "it doesn't exist") trying to read
530 the global preferences file, stuff the errno into "*gpf_errno_return"
531 on an open error and into "*gpf_read_errno_return" on a read error,
532 stuff a pointer to the path of the file into "*gpf_path_return", and
535 If we got an error (other than "it doesn't exist") trying to read
536 the user's preferences file, stuff the errno into "*pf_errno_return"
537 on an open error and into "*pf_read_errno_return" on a read error,
538 stuff a pointer to the path of the file into "*pf_path_return", and
540 WS_DLL_PUBLIC e_prefs
*read_prefs(int *, int *, char **, int *, int *, char **);
542 /* Write out "prefs" to the user's preferences file, and return 0.
544 If we got an error, stuff a pointer to the path of the preferences file
545 into "*pf_path_return", and return the errno. */
546 WS_DLL_PUBLIC
int write_prefs(char **);
549 * Given a string of the form "<pref name>:<pref value>", as might appear
550 * as an argument to a "-o" option, parse it and set the preference in
551 * question. Return an indication of whether it succeeded or failed
554 * XXX - should supply, for syntax errors, a detailed explanation of
558 PREFS_SET_OK
, /* succeeded */
559 PREFS_SET_SYNTAX_ERR
, /* syntax error in string */
560 PREFS_SET_NO_SUCH_PREF
, /* no such preference */
561 PREFS_SET_OBSOLETE
/* preference used to exist but no longer does */
564 WS_DLL_PUBLIC prefs_set_pref_e
prefs_set_pref(char *prefarg
);
567 * Get or set a preference's obsolete status. These can be used to make a
568 * preference obsolete after startup so that we can fetch its value but
569 * keep it from showing up in the prefrences dialog.
571 gboolean
prefs_get_preference_obsolete(pref_t
*pref
);
572 prefs_set_pref_e
prefs_set_preference_obsolete(pref_t
*pref
);
576 * Returns TRUE if the given device is hidden
578 WS_DLL_PUBLIC gboolean
prefs_is_capture_device_hidden(const char *name
);
581 * Returns TRUE if the given device should capture in monitor mode by default
583 WS_DLL_PUBLIC gboolean
prefs_capture_device_monitor_mode(const char *name
);
585 WS_DLL_PUBLIC gboolean
prefs_capture_options_dialog_column_is_visible(const gchar
*column
);
589 #endif /* __cplusplus */