2 * Routines for handling preferences
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 #define WS_LOG_DOMAIN LOG_DOMAIN_EPAN
14 #include "ws_diag_control.h"
26 #include <wsutil/filesystem.h>
27 #include <epan/addr_resolv.h>
28 #include <epan/oids.h>
29 #include <epan/maxmind_db.h>
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/proto.h>
33 #include <epan/strutil.h>
34 #include <epan/column.h>
35 #include <epan/decode_as.h>
36 #include <capture_opts.h>
37 #include <wsutil/file_util.h>
38 #include <wsutil/report_message.h>
39 #include <wsutil/wslog.h>
40 #include <wsutil/ws_assert.h>
41 #include <wsutil/array.h>
43 #include <epan/prefs-int.h>
44 #include <epan/uat-int.h>
46 #include "epan/filter_expressions.h"
48 #include "epan/wmem_scopes.h"
49 #include <epan/stats_tree.h>
51 #define REG_HKCU_WIRESHARK_KEY "Software\\Wireshark"
56 typedef struct pref_module_alias
{
57 const char *name
; /**< name of module alias */
58 module_t
*module
; /**< module for which it's an alias */
61 /* Internal functions */
62 static module_t
*find_subtree(module_t
*parent
, const char *tilte
);
63 static module_t
*prefs_register_module_or_subtree(module_t
*parent
,
64 const char *name
, const char *title
, const char *description
, const char *help
,
65 bool is_subtree
, void (*apply_cb
)(void), bool use_gui
);
66 static void prefs_register_modules(void);
67 static module_t
*prefs_find_module_alias(const char *name
);
68 static prefs_set_pref_e
set_pref(char*, const char*, void *, bool);
69 static void free_col_info(GList
*);
70 static void pre_init_prefs(void);
71 static bool prefs_is_column_visible(const char *cols_hidden
, int col
);
72 static bool prefs_is_column_fmt_visible(const char *cols_hidden
, fmt_data
*cfmt
);
73 static unsigned prefs_module_list_foreach(wmem_tree_t
*module_list
, module_cb callback
,
74 void *user_data
, bool skip_obsolete
);
75 static int find_val_for_string(const char *needle
, const enum_val_t
*haystack
, int default_value
);
77 #define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
78 #define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
79 #define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
81 #define PF_NAME "preferences"
82 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
84 static bool prefs_initialized
;
85 static char *gpf_path
;
86 static char *cols_hidden_list
;
87 static char *cols_hidden_fmt_list
;
88 static bool gui_theme_is_dark
;
91 * XXX - variables to allow us to attempt to interpret the first
92 * "mgcp.{tcp,udp}.port" in a preferences file as
93 * "mgcp.{tcp,udp}.gateway_port" and the second as
94 * "mgcp.{tcp,udp}.callagent_port".
96 static int mgcp_tcp_port_count
;
97 static int mgcp_udp_port_count
;
101 static const enum_val_t gui_console_open_type
[] = {
102 {"NEVER", "NEVER", LOG_CONSOLE_OPEN_NEVER
},
103 {"AUTOMATIC", "AUTOMATIC", LOG_CONSOLE_OPEN_AUTO
},
104 {"ALWAYS", "ALWAYS", LOG_CONSOLE_OPEN_ALWAYS
},
108 static const enum_val_t gui_version_placement_type
[] = {
109 {"WELCOME", "WELCOME", version_welcome_only
},
110 {"TITLE", "TITLE", version_title_only
},
111 {"BOTH", "BOTH", version_both
},
112 {"NEITHER", "NEITHER", version_neither
},
116 static const enum_val_t gui_fileopen_style
[] = {
117 {"LAST_OPENED", "LAST_OPENED", FO_STYLE_LAST_OPENED
},
118 {"SPECIFIED", "SPECIFIED", FO_STYLE_SPECIFIED
},
119 {"CWD", "CWD", FO_STYLE_CWD
},
123 static const enum_val_t gui_toolbar_style
[] = {
124 {"ICONS", "ICONS", 0},
130 static const enum_val_t gui_layout_content
[] = {
132 {"PLIST", "PLIST", 1},
133 {"PDETAILS", "PDETAILS", 2},
134 {"PBYTES", "PBYTES", 3},
135 {"PDIAGRAM", "PDIAGRAM", 4},
139 static const enum_val_t gui_packet_dialog_layout
[] = {
140 {"vertical", "Vertical (Stacked)", layout_vertical
},
141 {"horizontal", "Horizontal (Side-by-side)", layout_horizontal
},
145 static const enum_val_t gui_update_channel
[] = {
146 {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT
},
147 {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE
},
151 static const enum_val_t gui_selection_style
[] = {
152 {"DEFAULT", "DEFAULT", COLOR_STYLE_DEFAULT
},
153 {"FLAT", "FLAT", COLOR_STYLE_FLAT
},
154 {"GRADIENT", "GRADIENT", COLOR_STYLE_GRADIENT
},
158 static const enum_val_t gui_color_scheme
[] = {
159 {"system", "System Default", COLOR_SCHEME_DEFAULT
},
160 {"light", "Light Mode", COLOR_SCHEME_LIGHT
},
161 {"dark", "Dark Mode", COLOR_SCHEME_DARK
},
165 static const enum_val_t gui_packet_list_copy_format_options_for_keyboard_shortcut
[] = {
166 {"TEXT", "Text", COPY_FORMAT_TEXT
},
167 {"CSV", "CSV", COPY_FORMAT_CSV
},
168 {"YAML", "YAML", COPY_FORMAT_YAML
},
169 {"HTML", "HTML", COPY_FORMAT_HTML
},
173 /* None : Historical behavior, no deinterlacing */
174 #define CONV_DEINT_CHOICE_NONE 0
175 /* MI : MAC & Interface */
176 #define CONV_DEINT_CHOICE_MI CONV_DEINT_KEY_MAC + CONV_DEINT_KEY_INTERFACE
177 /* VM : VLAN & MAC */
178 #define CONV_DEINT_CHOICE_VM CONV_DEINT_KEY_VLAN + CONV_DEINT_KEY_MAC
179 /* VMI : VLAN & MAC & Interface */
180 #define CONV_DEINT_CHOICE_VMI CONV_DEINT_KEY_VLAN + CONV_DEINT_KEY_MAC + CONV_DEINT_KEY_INTERFACE
182 static const enum_val_t conv_deint_options
[] = {
183 {"NONE", "NONE", CONV_DEINT_CHOICE_NONE
},
184 {".MI", ".MI", CONV_DEINT_CHOICE_MI
},
185 {"VM.", "VM.", CONV_DEINT_CHOICE_VM
},
186 {"VMI", "VMI", CONV_DEINT_CHOICE_VMI
},
190 static const enum_val_t abs_time_format_options
[] = {
191 {"NEVER", "Never", ABS_TIME_ASCII_NEVER
},
192 {"TREE", "Protocol tree only", ABS_TIME_ASCII_TREE
},
193 {"COLUMN", "Protocol tree and columns", ABS_TIME_ASCII_COLUMN
},
194 {"ALWAYS", "Always", ABS_TIME_ASCII_ALWAYS
},
198 #if defined(HAVE_PCAP_CREATE)
199 /* Can set monitor mode and buffer size. */
200 static int num_capture_cols
= 7;
201 static const char *capture_cols
[7] = {
210 #define CAPTURE_COL_TYPE_DESCRIPTION \
211 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
212 #elif defined(CAN_SET_CAPTURE_BUFFER_SIZE)
213 /* Can set buffer size but not monitor mode. */
214 static int num_capture_cols
= 6;
215 static const char *capture_cols
[6] = {
223 #define CAPTURE_COL_TYPE_DESCRIPTION \
224 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, BUFFER, FILTER\n"
226 /* Can neither set buffer size nor monitor mode. */
227 static int num_capture_cols
= 5;
228 static const char *capture_cols
[5] = {
235 #define CAPTURE_COL_TYPE_DESCRIPTION \
236 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, FILTER\n"
239 static const enum_val_t gui_packet_list_elide_mode
[] = {
240 {"LEFT", "LEFT", ELIDE_LEFT
},
241 {"RIGHT", "RIGHT", ELIDE_RIGHT
},
242 {"MIDDLE", "MIDDLE", ELIDE_MIDDLE
},
243 {"NONE", "NONE", ELIDE_NONE
},
247 /** Struct to hold preference data */
249 const char *name
; /**< name of preference */
250 const char *title
; /**< title to use in GUI */
251 const char *description
; /**< human-readable description of preference */
252 int ordinal
; /**< ordinal number of this preference */
253 int type
; /**< type of that preference */
254 unsigned int effect_flags
; /**< Flags of types effected by preference (PREF_TYPE_DISSECTION, PREF_EFFECT_CAPTURE, etc).
255 Flags must be non-zero to ensure saving to disk */
256 union { /* The Qt preference code assumes that these will all be pointers (and unique) */
262 struct epan_uat
* uat
;
265 } varp
; /**< pointer to variable storing the value */
274 } stashed_val
; /**< original value, when editing from the GUI */
283 } default_val
; /**< the default value of the preference */
285 unsigned base
; /**< input/output base, for PREF_UINT */
286 uint32_t max_value
; /**< maximum value of a range */
288 const enum_val_t
*enumvals
; /**< list of name & values */
289 bool radio_buttons
; /**< true if it should be shown as
290 radio buttons rather than as an
291 option menu or combo box in
292 the preferences tab */
293 } enum_info
; /**< for PREF_ENUM */
294 } info
; /**< display/text file information */
295 struct pref_custom_cbs custom_cbs
; /**< for PREF_CUSTOM */
296 const char *dissector_table
; /**< for PREF_DECODE_AS_RANGE */
297 const char *dissector_desc
; /**< for PREF_DECODE_AS_RANGE */
300 const char* prefs_get_description(pref_t
*pref
)
302 return pref
->description
;
305 const char* prefs_get_title(pref_t
*pref
)
310 int prefs_get_type(pref_t
*pref
)
315 const char* prefs_get_name(pref_t
*pref
)
320 uint32_t prefs_get_max_value(pref_t
*pref
)
322 return pref
->info
.max_value
;
325 const char* prefs_get_dissector_table(pref_t
*pref
)
327 return pref
->dissector_table
;
330 static const char* prefs_get_dissector_description(pref_t
*pref
)
332 return pref
->dissector_desc
;
336 * List of all modules with preference settings.
338 static wmem_tree_t
*prefs_modules
;
341 * List of all modules that should show up at the top level of the
342 * tree in the preference dialog box.
344 static wmem_tree_t
*prefs_top_level_modules
;
347 * List of aliases for modules.
349 static wmem_tree_t
*prefs_module_aliases
;
351 /** Sets up memory used by proto routines. Called at program startup */
355 memset(&prefs
, 0, sizeof(prefs
));
356 prefs_modules
= wmem_tree_new(wmem_epan_scope());
357 prefs_top_level_modules
= wmem_tree_new(wmem_epan_scope());
358 prefs_module_aliases
= wmem_tree_new(wmem_epan_scope());
362 * Free the strings for a string-like preference.
365 free_string_like_preference(pref_t
*pref
)
367 g_free(*pref
->varp
.string
);
368 *pref
->varp
.string
= NULL
;
369 g_free(pref
->default_val
.string
);
370 pref
->default_val
.string
= NULL
;
374 free_pref(void *data
, void *user_data _U_
)
376 pref_t
*pref
= (pref_t
*)data
;
377 int type
= pref
->type
;
379 /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
380 RESET_PREF_OBSOLETE(type
);
386 case PREF_STATIC_TEXT
:
391 case PREF_SAVE_FILENAME
:
392 case PREF_OPEN_FILENAME
:
396 free_string_like_preference(pref
);
399 case PREF_DECODE_AS_RANGE
:
400 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
401 *pref
->varp
.range
= NULL
;
402 wmem_free(wmem_epan_scope(), pref
->default_val
.range
);
403 pref
->default_val
.range
= NULL
;
406 if (strcmp(pref
->name
, "columns") == 0)
407 pref
->stashed_val
.boolval
= true;
408 pref
->custom_cbs
.free_cb(pref
);
410 /* non-generic preferences */
411 case PREF_PROTO_TCP_SNDAMB_ENUM
:
419 free_module_prefs(module_t
*module
, void *data _U_
)
422 g_list_foreach(module
->prefs
, free_pref
, NULL
);
423 g_list_free(module
->prefs
);
425 module
->prefs
= NULL
;
426 module
->numprefs
= 0;
427 if (module
->submodules
) {
428 prefs_module_list_foreach(module
->submodules
, free_module_prefs
, NULL
, false);
430 /* We don't free the actual module: its submodules pointer points to
431 a wmem_tree and the module itself is stored in a wmem_tree
437 /** Frees memory used by proto routines. Called at program shutdown */
441 /* This isn't strictly necessary since we're exiting anyway, but let's
442 * do what clean up we can.
444 prefs_module_list_foreach(prefs_modules
, free_module_prefs
, NULL
, false);
449 /* Shut down mmdbresolve */
450 maxmind_db_pref_cleanup();
452 g_free(prefs
.saved_at_version
);
457 void prefs_set_gui_theme_is_dark(bool is_dark
)
459 gui_theme_is_dark
= is_dark
;
463 * Register a module that will have preferences.
464 * Specify the module under which to register it or NULL to register it
465 * at the top level, the name used for the module in the preferences file,
466 * the title used in the tab for it in a preferences dialog box, and a
467 * routine to call back when we apply the preferences.
470 prefs_register_module(module_t
*parent
, const char *name
, const char *title
,
471 const char *description
, const char *help
, void (*apply_cb
)(void),
474 return prefs_register_module_or_subtree(parent
, name
, title
, description
, help
,
475 false, apply_cb
, use_gui
);
479 prefs_deregister_module(module_t
*parent
, const char *name
, const char *title
)
481 /* Remove this module from the list of all modules */
482 module_t
*module
= (module_t
*)wmem_tree_remove_string(prefs_modules
, name
, WMEM_TREE_STRING_NOCASE
);
487 if (parent
== NULL
) {
488 /* Remove from top */
489 wmem_tree_remove_string(prefs_top_level_modules
, title
, WMEM_TREE_STRING_NOCASE
);
490 } else if (parent
->submodules
) {
491 /* Remove from parent */
492 wmem_tree_remove_string(parent
->submodules
, title
, WMEM_TREE_STRING_NOCASE
);
495 free_module_prefs(module
, NULL
);
496 wmem_free(wmem_epan_scope(), module
);
500 * Register a subtree that will have modules under it.
501 * Specify the module under which to register it or NULL to register it
502 * at the top level and the title used in the tab for it in a preferences
506 prefs_register_subtree(module_t
*parent
, const char *title
, const char *description
,
507 void (*apply_cb
)(void))
509 return prefs_register_module_or_subtree(parent
, NULL
, title
, description
, NULL
,
511 parent
? parent
->use_gui
: false);
515 prefs_register_module_or_subtree(module_t
*parent
, const char *name
,
516 const char *title
, const char *description
,
518 bool is_subtree
, void (*apply_cb
)(void),
523 /* this module may have been created as a subtree item previously */
524 if ((module
= find_subtree(parent
, title
))) {
525 /* the module is currently a subtree */
527 module
->apply_cb
= apply_cb
;
528 module
->description
= description
;
531 if (prefs_find_module(name
) == NULL
) {
532 wmem_tree_insert_string(prefs_modules
, name
, module
,
533 WMEM_TREE_STRING_NOCASE
);
539 module
= wmem_new(wmem_epan_scope(), module_t
);
541 module
->title
= title
;
542 module
->description
= description
;
544 module
->apply_cb
= apply_cb
;
545 module
->prefs
= NULL
; /* no preferences, to start */
546 module
->parent
= parent
;
547 module
->submodules
= NULL
; /* no submodules, to start */
548 module
->numprefs
= 0;
549 module
->prefs_changed_flags
= 0;
550 module
->obsolete
= false;
551 module
->use_gui
= use_gui
;
552 /* A module's preferences affects dissection unless otherwise told */
553 module
->effect_flags
= PREF_EFFECT_DISSECTION
;
556 * Do we have a module name?
560 /* Accept any letter case to conform with protocol names. ASN1 protocols
561 * don't use lower case names, so we can't require lower case. */
562 if (module_check_valid_name(name
, false) != '\0') {
563 ws_error("Preference module \"%s\" contains invalid characters", name
);
567 * Make sure there's not already a module with that
568 * name. Crash if there is, as that's an error in the
569 * code, and the code has to be fixed not to register
570 * more than one module with the same name.
572 * We search the list of all modules; the subtree stuff
573 * doesn't require preferences in subtrees to have names
574 * that reflect the subtree they're in (that would require
575 * protocol preferences to have a bogus "protocol.", or
576 * something such as that, to be added to all their names).
578 if (prefs_find_module(name
) != NULL
)
579 ws_error("Preference module \"%s\" is being registered twice", name
);
582 * Insert this module in the list of all modules.
584 wmem_tree_insert_string(prefs_modules
, name
, module
, WMEM_TREE_STRING_NOCASE
);
587 * This has no name, just a title; check to make sure it's a
588 * subtree, and crash if it's not.
591 ws_error("Preferences module with no name is being registered at the top level");
595 * Insert this module into the appropriate place in the display
598 if (parent
== NULL
) {
600 * It goes at the top.
602 wmem_tree_insert_string(prefs_top_level_modules
, title
, module
, WMEM_TREE_STRING_NOCASE
);
605 * It goes into the list for this module.
608 if (parent
->submodules
== NULL
)
609 parent
->submodules
= wmem_tree_new(wmem_epan_scope());
611 wmem_tree_insert_string(parent
->submodules
, title
, module
, WMEM_TREE_STRING_NOCASE
);
618 prefs_register_module_alias(const char *name
, module_t
*module
)
620 module_alias_t
*alias
;
623 * Accept any name that can occur in protocol names. We allow upper-case
624 * letters, to handle the Diameter dissector having used "Diameter" rather
625 * than "diameter" as its preference module name in the past.
627 * Crash if the name is invalid, as that's an error in the code, but the name
628 * can be used on the command line, and shouldn't require quoting, etc.
630 if (module_check_valid_name(name
, false) != '\0') {
631 ws_error("Preference module alias \"%s\" contains invalid characters", name
);
635 * Make sure there's not already an alias with that
636 * name. Crash if there is, as that's an error in the
637 * code, and the code has to be fixed not to register
638 * more than one alias with the same name.
640 * We search the list of all aliases.
642 if (prefs_find_module_alias(name
) != NULL
)
643 ws_error("Preference module alias \"%s\" is being registered twice", name
);
645 alias
= wmem_new(wmem_epan_scope(), module_alias_t
);
647 alias
->module
= module
;
650 * Insert this module in the list of all modules.
652 wmem_tree_insert_string(prefs_module_aliases
, name
, alias
, WMEM_TREE_STRING_NOCASE
);
656 * Register that a protocol has preferences.
658 module_t
*protocols_module
;
661 prefs_register_protocol(int id
, void (*apply_cb
)(void))
663 protocol_t
*protocol
;
666 * Have we yet created the "Protocols" subtree?
668 if (protocols_module
== NULL
) {
670 * No. Register Protocols subtree as well as any preferences
671 * for non-dissector modules.
674 prefs_register_modules();
676 protocol
= find_protocol_by_id(id
);
677 if (protocol
== NULL
)
678 ws_error("Protocol preferences being registered with an invalid protocol ID");
679 return prefs_register_module(protocols_module
,
680 proto_get_protocol_filter_name(id
),
681 proto_get_protocol_short_name(protocol
),
682 proto_get_protocol_name(id
), NULL
, apply_cb
, true);
686 prefs_deregister_protocol (int id
)
688 protocol_t
*protocol
= find_protocol_by_id(id
);
689 if (protocol
== NULL
)
690 ws_error("Protocol preferences being de-registered with an invalid protocol ID");
691 prefs_deregister_module (protocols_module
,
692 proto_get_protocol_filter_name(id
),
693 proto_get_protocol_short_name(protocol
));
697 prefs_register_protocol_subtree(const char *subtree
, int id
, void (*apply_cb
)(void))
699 protocol_t
*protocol
;
700 module_t
*subtree_module
;
701 module_t
*new_module
;
702 char *sep
= NULL
, *ptr
= NULL
, *orig
= NULL
;
705 * Have we yet created the "Protocols" subtree?
706 * XXX - can we just do this by registering Protocols/{subtree}?
709 if (protocols_module
== NULL
) {
711 * No. Register Protocols subtree as well as any preferences
712 * for non-dissector modules.
715 prefs_register_modules();
718 subtree_module
= protocols_module
;
721 /* take a copy of the buffer, orig keeps a base pointer while ptr
722 * walks through the string */
723 orig
= ptr
= g_strdup(subtree
);
725 while (ptr
&& *ptr
) {
727 if ((sep
= strchr(ptr
, '/')))
730 if (!(new_module
= find_subtree(subtree_module
, ptr
))) {
732 * There's no such module; create it, with the description
733 * being the name (if it's later registered explicitly
734 * with a description, that will override it).
736 ptr
= wmem_strdup(wmem_epan_scope(), ptr
);
737 new_module
= prefs_register_subtree(subtree_module
, ptr
, ptr
, NULL
);
740 subtree_module
= new_module
;
748 protocol
= find_protocol_by_id(id
);
749 if (protocol
== NULL
)
750 ws_error("Protocol subtree being registered with an invalid protocol ID");
751 return prefs_register_module(subtree_module
,
752 proto_get_protocol_filter_name(id
),
753 proto_get_protocol_short_name(protocol
),
754 proto_get_protocol_name(id
), NULL
, apply_cb
, true);
759 * Register that a protocol used to have preferences but no longer does,
760 * by creating an "obsolete" module for it.
763 prefs_register_protocol_obsolete(int id
)
766 protocol_t
*protocol
;
769 * Have we yet created the "Protocols" subtree?
771 if (protocols_module
== NULL
) {
773 * No. Register Protocols subtree as well as any preferences
774 * for non-dissector modules.
777 prefs_register_modules();
779 protocol
= find_protocol_by_id(id
);
780 if (protocol
== NULL
)
781 ws_error("Protocol being registered with an invalid protocol ID");
782 module
= prefs_register_module(protocols_module
,
783 proto_get_protocol_filter_name(id
),
784 proto_get_protocol_short_name(protocol
),
785 proto_get_protocol_name(id
), NULL
, NULL
, true);
786 module
->obsolete
= true;
791 * Register that a statistical tap has preferences.
793 * "name" is a name for the tap to use on the command line with "-o"
794 * and in preference files.
796 * "title" is a short human-readable name for the tap.
798 * "description" is a longer human-readable description of the tap.
800 module_t
*stats_module
;
803 prefs_register_stat(const char *name
, const char *title
,
804 const char *description
, void (*apply_cb
)(void))
807 * Have we yet created the "Statistics" subtree?
809 if (stats_module
== NULL
) {
811 * No. Register Statistics subtree as well as any preferences
812 * for non-dissector modules.
815 prefs_register_modules();
818 return prefs_register_module(stats_module
, name
, title
, description
, NULL
,
823 * Register that a codec has preferences.
825 * "name" is a name for the codec to use on the command line with "-o"
826 * and in preference files.
828 * "title" is a short human-readable name for the codec.
830 * "description" is a longer human-readable description of the codec.
832 module_t
*codecs_module
;
835 prefs_register_codec(const char *name
, const char *title
,
836 const char *description
, void (*apply_cb
)(void))
839 * Have we yet created the "Codecs" subtree?
841 if (codecs_module
== NULL
) {
843 * No. Register Codecs subtree as well as any preferences
844 * for non-dissector modules.
847 prefs_register_modules();
850 return prefs_register_module(codecs_module
, name
, title
, description
, NULL
,
855 prefs_find_module(const char *name
)
857 return (module_t
*)wmem_tree_lookup_string(prefs_modules
, name
, WMEM_TREE_STRING_NOCASE
);
861 find_subtree(module_t
*parent
, const char *name
)
863 return (module_t
*)wmem_tree_lookup_string(parent
? parent
->submodules
: prefs_top_level_modules
, name
, WMEM_TREE_STRING_NOCASE
);
867 * Call a callback function, with a specified argument, for each module
868 * in a list of modules. If the list is NULL, searches the top-level
869 * list in the display tree of modules. If any callback returns a
870 * non-zero value, we stop and return that value, otherwise we
873 * Normally "obsolete" modules are ignored; their sole purpose is to allow old
874 * preferences for dissectors that no longer have preferences to be
875 * silently ignored in preference files. Does not ignore subtrees,
876 * as this can be used when walking the display tree of modules.
887 call_foreach_cb(const void *key _U_
, void *value
, void *data
)
889 module_t
*module
= (module_t
*)value
;
890 call_foreach_t
*call_data
= (call_foreach_t
*)data
;
892 if (!call_data
->skip_obsolete
|| !module
->obsolete
)
893 call_data
->ret
= (*call_data
->callback
)(module
, call_data
->user_data
);
895 return (call_data
->ret
!= 0);
899 prefs_module_list_foreach(wmem_tree_t
*module_list
, module_cb callback
,
900 void *user_data
, bool skip_obsolete
)
902 call_foreach_t call_data
;
904 if (module_list
== NULL
)
905 module_list
= prefs_top_level_modules
;
907 call_data
.callback
= callback
;
908 call_data
.user_data
= user_data
;
910 call_data
.skip_obsolete
= skip_obsolete
;
911 wmem_tree_foreach(module_list
, call_foreach_cb
, &call_data
);
912 return call_data
.ret
;
916 * Returns true if module has any submodules
919 prefs_module_has_submodules(module_t
*module
)
921 if (module
->submodules
== NULL
) {
925 if (wmem_tree_is_empty(module
->submodules
)) {
933 * Call a callback function, with a specified argument, for each module
934 * in the list of all modules. (This list does not include subtrees.)
936 * Ignores "obsolete" modules; their sole purpose is to allow old
937 * preferences for dissectors that no longer have preferences to be
938 * silently ignored in preference files.
941 prefs_modules_foreach(module_cb callback
, void *user_data
)
943 return prefs_module_list_foreach(prefs_modules
, callback
, user_data
, true);
947 * Call a callback function, with a specified argument, for each submodule
948 * of specified modules. If the module is NULL, goes through the top-level
949 * list in the display tree of modules.
951 * Ignores "obsolete" modules; their sole purpose is to allow old
952 * preferences for dissectors that no longer have preferences to be
953 * silently ignored in preference files. Does not ignore subtrees,
954 * as this can be used when walking the display tree of modules.
957 prefs_modules_foreach_submodules(module_t
*module
, module_cb callback
,
960 return prefs_module_list_foreach((module
)?module
->submodules
:prefs_top_level_modules
, callback
, user_data
, true);
964 call_apply_cb(const void *key _U_
, void *value
, void *data _U_
)
966 module_t
*module
= (module_t
*)value
;
968 if (module
->obsolete
)
970 if (module
->prefs_changed_flags
) {
971 if (module
->apply_cb
!= NULL
)
972 (*module
->apply_cb
)();
973 module
->prefs_changed_flags
= 0;
975 if (module
->submodules
)
976 wmem_tree_foreach(module
->submodules
, call_apply_cb
, NULL
);
981 * Call the "apply" callback function for each module if any of its
982 * preferences have changed, and then clear the flag saying its
983 * preferences have changed, as the module has been notified of that
987 prefs_apply_all(void)
989 wmem_tree_foreach(prefs_modules
, call_apply_cb
, NULL
);
993 * Call the "apply" callback function for a specific module if any of
994 * its preferences have changed, and then clear the flag saying its
995 * preferences have changed, as the module has been notified of that
999 prefs_apply(module_t
*module
)
1001 if (module
&& module
->prefs_changed_flags
)
1002 call_apply_cb(NULL
, module
, NULL
);
1006 prefs_find_module_alias(const char *name
)
1008 module_alias_t
*alias
;
1010 alias
= (module_alias_t
*)wmem_tree_lookup_string(prefs_module_aliases
, name
, WMEM_TREE_STRING_NOCASE
);
1013 return alias
->module
;
1017 * Register a preference in a module's list of preferences.
1018 * If it has a title, give it an ordinal number; otherwise, it's a
1019 * preference that won't show up in the UI, so it shouldn't get an
1020 * ordinal number (the ordinal should be the ordinal in the set of
1021 * *visible* preferences).
1024 register_preference(module_t
*module
, const char *name
, const char *title
,
1025 const char *description
, int type
)
1029 const char *name_prefix
= (module
->name
!= NULL
) ? module
->name
: module
->parent
->name
;
1031 preference
= g_new(pref_t
,1);
1032 preference
->name
= name
;
1033 preference
->title
= title
;
1034 preference
->description
= description
;
1035 preference
->type
= type
;
1036 /* Default to module's preference effects */
1037 preference
->effect_flags
= module
->effect_flags
;
1040 preference
->ordinal
= module
->numprefs
;
1042 preference
->ordinal
= -1; /* no ordinal for you */
1045 * Make sure that only lower-case ASCII letters, numbers,
1046 * underscores, and dots appear in the preference name.
1048 * Crash if there is, as that's an error in the code;
1049 * you can make the title and description nice strings
1050 * with capitalization, white space, punctuation, etc.,
1051 * but the name can be used on the command line,
1052 * and shouldn't require quoting, shifting, etc.
1054 for (p
= name
; *p
!= '\0'; p
++)
1055 if (!(g_ascii_islower(*p
) || g_ascii_isdigit(*p
) || *p
== '_' || *p
== '.'))
1056 ws_error("Preference \"%s.%s\" contains invalid characters", module
->name
, name
);
1059 * Make sure there's not already a preference with that
1060 * name. Crash if there is, as that's an error in the
1061 * code, and the code has to be fixed not to register
1062 * more than one preference with the same name.
1064 if (prefs_find_preference(module
, name
) != NULL
)
1065 ws_error("Preference %s has already been registered", name
);
1067 if ((!IS_PREF_OBSOLETE(type
)) &&
1068 /* Don't compare if it's a subtree */
1069 (module
->name
!= NULL
)) {
1071 * Make sure the preference name doesn't begin with the
1072 * module name, as that's redundant and Just Silly.
1074 if (!((strncmp(name
, module
->name
, strlen(module
->name
)) != 0) ||
1075 (((name
[strlen(module
->name
)]) != '.') && ((name
[strlen(module
->name
)]) != '_'))))
1076 ws_error("Preference %s begins with the module name", name
);
1079 /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */
1080 if (preference
->title
) {
1081 const char *cur_char
;
1082 if (preference
->type
!= PREF_STATIC_TEXT
&& g_utf8_strlen(preference
->title
, -1) > 80) { // Arbitrary.
1083 ws_error("Title for preference %s.%s is too long: %s", name_prefix
, preference
->name
, preference
->title
);
1086 if (!g_utf8_validate(preference
->title
, -1, NULL
)) {
1087 ws_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix
, preference
->name
);
1090 for (cur_char
= preference
->title
; *cur_char
; cur_char
= g_utf8_next_char(cur_char
)) {
1091 if (!g_unichar_isprint(g_utf8_get_char(cur_char
))) {
1092 ws_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix
, preference
->name
);
1097 if (preference
->description
) {
1098 if (!g_utf8_validate(preference
->description
, -1, NULL
)) {
1099 ws_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix
, preference
->name
);
1104 * We passed all of our checks. Add the preference.
1106 module
->prefs
= g_list_append(module
->prefs
, preference
);
1114 * Find a preference in a module's list of preferences, given the module
1115 * and the preference's name.
1120 module_t
*submodule
;
1124 preference_match(const void *a
, const void *b
)
1126 const pref_t
*pref
= (const pref_t
*)a
;
1127 const char *name
= (const char *)b
;
1129 return strcmp(name
, pref
->name
);
1133 module_find_pref_cb(const void *key _U_
, void *value
, void *data
)
1135 find_pref_arg_t
* arg
= (find_pref_arg_t
*)data
;
1137 module_t
*module
= (module_t
*)value
;
1142 list_entry
= g_list_find_custom(module
->prefs
, arg
->name
,
1145 if (list_entry
== NULL
)
1148 arg
->list_entry
= list_entry
;
1149 arg
->submodule
= module
;
1153 /* Tries to find a preference, setting containing_module to the (sub)module
1154 * holding this preference. */
1155 static struct preference
*
1156 prefs_find_preference_with_submodule(module_t
*module
, const char *name
,
1157 module_t
**containing_module
)
1159 find_pref_arg_t arg
;
1163 return NULL
; /* invalid parameters */
1165 list_entry
= g_list_find_custom(module
->prefs
, name
,
1167 arg
.submodule
= NULL
;
1169 if (list_entry
== NULL
)
1171 arg
.list_entry
= NULL
;
1172 if (module
->submodules
!= NULL
)
1175 wmem_tree_foreach(module
->submodules
, module_find_pref_cb
, &arg
);
1178 list_entry
= arg
.list_entry
;
1181 if (list_entry
== NULL
)
1182 return NULL
; /* no such preference */
1184 if (containing_module
)
1185 *containing_module
= arg
.submodule
? arg
.submodule
: module
;
1187 return (struct preference
*) list_entry
->data
;
1191 prefs_find_preference(module_t
*module
, const char *name
)
1193 return prefs_find_preference_with_submodule(module
, name
, NULL
);
1197 * Returns true if the given protocol has registered preferences
1200 prefs_is_registered_protocol(const char *name
)
1202 module_t
*m
= prefs_find_module(name
);
1204 return (m
!= NULL
&& !m
->obsolete
);
1208 * Returns the module title of a registered protocol
1211 prefs_get_title_by_name(const char *name
)
1213 module_t
*m
= prefs_find_module(name
);
1215 return (m
!= NULL
&& !m
->obsolete
) ? m
->title
: NULL
;
1219 * Register a preference with an unsigned integral value.
1222 prefs_register_uint_preference(module_t
*module
, const char *name
,
1223 const char *title
, const char *description
,
1224 unsigned base
, unsigned *var
)
1228 preference
= register_preference(module
, name
, title
, description
,
1230 preference
->varp
.uint
= var
;
1231 preference
->default_val
.uint
= *var
;
1232 ws_assert(base
> 0 && base
!= 1 && base
< 37);
1233 preference
->info
.base
= base
;
1237 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
1242 * Register a "custom" preference with a unsigned integral value.
1243 * XXX - This should be temporary until we can find a better way
1244 * to do "custom" preferences
1247 prefs_register_uint_custom_preference(module_t
*module
, const char *name
,
1248 const char *title
, const char *description
,
1249 struct pref_custom_cbs
* custom_cbs
, unsigned *var
)
1253 preference
= register_preference(module
, name
, title
, description
,
1256 preference
->custom_cbs
= *custom_cbs
;
1257 preference
->varp
.uint
= var
;
1258 preference
->default_val
.uint
= *var
;
1262 * Register a preference with an Boolean value.
1265 prefs_register_bool_preference(module_t
*module
, const char *name
,
1266 const char *title
, const char *description
,
1271 preference
= register_preference(module
, name
, title
, description
,
1273 preference
->varp
.boolp
= var
;
1274 preference
->default_val
.boolval
= *var
;
1277 unsigned int prefs_set_bool_value(pref_t
*pref
, bool value
, pref_source_t source
)
1279 unsigned int changed
= 0;
1284 if (pref
->default_val
.boolval
!= value
) {
1285 pref
->default_val
.boolval
= value
;
1286 changed
= prefs_get_effect_flags(pref
);
1290 if (pref
->stashed_val
.boolval
!= value
) {
1291 pref
->stashed_val
.boolval
= value
;
1292 changed
= prefs_get_effect_flags(pref
);
1296 if (*pref
->varp
.boolp
!= value
) {
1297 *pref
->varp
.boolp
= value
;
1298 changed
= prefs_get_effect_flags(pref
);
1302 ws_assert_not_reached();
1309 void prefs_invert_bool_value(pref_t
*pref
, pref_source_t source
)
1314 pref
->default_val
.boolval
= !pref
->default_val
.boolval
;
1317 pref
->stashed_val
.boolval
= !pref
->stashed_val
.boolval
;
1320 *pref
->varp
.boolp
= !(*pref
->varp
.boolp
);
1323 ws_assert_not_reached();
1328 bool prefs_get_bool_value(pref_t
*pref
, pref_source_t source
)
1333 return pref
->default_val
.boolval
;
1335 return pref
->stashed_val
.boolval
;
1337 return *pref
->varp
.boolp
;
1339 ws_assert_not_reached();
1347 * Register a preference with an enumerated value.
1350 * XXX Should we get rid of the radio_buttons parameter and make that
1351 * behavior automatic depending on the number of items?
1354 prefs_register_enum_preference(module_t
*module
, const char *name
,
1355 const char *title
, const char *description
,
1356 int *var
, const enum_val_t
*enumvals
,
1361 /* Validate that the "name one would use on the command line for the value"
1362 * doesn't require quoting, etc. It's all treated case-insensitively so we
1363 * don't care about upper vs lower case.
1365 for (size_t i
= 0; enumvals
[i
].name
!= NULL
; i
++) {
1366 for (const char *p
= enumvals
[i
].name
; *p
!= '\0'; p
++)
1367 if (!(g_ascii_isalnum(*p
) || *p
== '_' || *p
== '.' || *p
== '-'))
1368 ws_error("Preference \"%s.%s\" enum value name \"%s\" contains invalid characters",
1369 module
->name
, name
, enumvals
[i
].name
);
1373 preference
= register_preference(module
, name
, title
, description
,
1375 preference
->varp
.enump
= var
;
1376 preference
->default_val
.enumval
= *var
;
1377 preference
->info
.enum_info
.enumvals
= enumvals
;
1378 preference
->info
.enum_info
.radio_buttons
= radio_buttons
;
1381 unsigned int prefs_set_enum_value(pref_t
*pref
, int value
, pref_source_t source
)
1383 unsigned int changed
= 0;
1388 if (pref
->default_val
.enumval
!= value
) {
1389 pref
->default_val
.enumval
= value
;
1390 changed
= prefs_get_effect_flags(pref
);
1394 if (pref
->stashed_val
.enumval
!= value
) {
1395 pref
->stashed_val
.enumval
= value
;
1396 changed
= prefs_get_effect_flags(pref
);
1400 if (*pref
->varp
.enump
!= value
) {
1401 *pref
->varp
.enump
= value
;
1402 changed
= prefs_get_effect_flags(pref
);
1406 ws_assert_not_reached();
1413 unsigned int prefs_set_enum_string_value(pref_t
*pref
, const char *value
, pref_source_t source
)
1415 int enum_val
= find_val_for_string(value
, pref
->info
.enum_info
.enumvals
, *pref
->varp
.enump
);
1417 return prefs_set_enum_value(pref
, enum_val
, source
);
1420 int prefs_get_enum_value(pref_t
*pref
, pref_source_t source
)
1425 return pref
->default_val
.enumval
;
1427 return pref
->stashed_val
.enumval
;
1429 return *pref
->varp
.enump
;
1431 ws_assert_not_reached();
1438 const enum_val_t
* prefs_get_enumvals(pref_t
*pref
)
1440 return pref
->info
.enum_info
.enumvals
;
1443 bool prefs_get_enum_radiobuttons(pref_t
*pref
)
1445 return pref
->info
.enum_info
.radio_buttons
;
1449 * For use by UI code that sets preferences.
1452 prefs_set_custom_value(pref_t
*pref
, const char *value
, pref_source_t source _U_
)
1454 /* XXX - support pref source for custom preferences */
1455 unsigned int changed
= 0;
1456 pref
->custom_cbs
.set_cb(pref
, value
, &changed
);
1461 register_string_like_preference(module_t
*module
, const char *name
,
1462 const char *title
, const char *description
,
1463 char **var
, int type
,
1464 struct pref_custom_cbs
* custom_cbs
,
1470 pref
= register_preference(module
, name
, title
, description
, type
);
1473 * String preference values should be non-null (as you can't
1474 * keep them null after using the preferences GUI, you can at best
1475 * have them be null strings) and freeable (as we free them
1476 * if we change them).
1478 * If the value is a null pointer, make it a copy of a null
1479 * string, otherwise make it a copy of the value.
1483 *var
= g_strdup("");
1485 *var
= g_strdup(*var
);
1490 pref
->varp
.string
= var
;
1491 pref
->default_val
.string
= g_strdup(*var
);
1492 pref
->stashed_val
.string
= NULL
;
1493 if (type
== PREF_CUSTOM
) {
1494 ws_assert(custom_cbs
);
1495 pref
->custom_cbs
= *custom_cbs
;
1500 * Assign to a string preference.
1503 pref_set_string_like_pref_value(pref_t
*pref
, const char *value
)
1506 g_free((void *)*pref
->varp
.string
);
1508 *pref
->varp
.string
= g_strdup(value
);
1512 * For use by UI code that sets preferences.
1515 prefs_set_string_value(pref_t
*pref
, const char* value
, pref_source_t source
)
1517 unsigned int changed
= 0;
1522 if (*pref
->default_val
.string
) {
1523 if (strcmp(pref
->default_val
.string
, value
) != 0) {
1524 changed
= prefs_get_effect_flags(pref
);
1525 g_free(pref
->default_val
.string
);
1526 pref
->default_val
.string
= g_strdup(value
);
1529 pref
->default_val
.string
= g_strdup(value
);
1533 if (pref
->stashed_val
.string
) {
1534 if (strcmp(pref
->stashed_val
.string
, value
) != 0) {
1535 changed
= prefs_get_effect_flags(pref
);
1536 g_free(pref
->stashed_val
.string
);
1537 pref
->stashed_val
.string
= g_strdup(value
);
1540 pref
->stashed_val
.string
= g_strdup(value
);
1544 if (*pref
->varp
.string
) {
1545 if (strcmp(*pref
->varp
.string
, value
) != 0) {
1546 changed
= prefs_get_effect_flags(pref
);
1547 pref_set_string_like_pref_value(pref
, value
);
1550 pref_set_string_like_pref_value(pref
, value
);
1554 ws_assert_not_reached();
1561 char* prefs_get_string_value(pref_t
*pref
, pref_source_t source
)
1566 return pref
->default_val
.string
;
1568 return pref
->stashed_val
.string
;
1570 return *pref
->varp
.string
;
1572 ws_assert_not_reached();
1580 * Reset the value of a string-like preference.
1583 reset_string_like_preference(pref_t
*pref
)
1585 g_free(*pref
->varp
.string
);
1586 *pref
->varp
.string
= g_strdup(pref
->default_val
.string
);
1590 * Register a preference with a character-string value.
1593 prefs_register_string_preference(module_t
*module
, const char *name
,
1594 const char *title
, const char *description
,
1598 register_string_like_preference(module
, name
, title
, description
,
1599 (char **)var
, PREF_STRING
, NULL
, false);
1604 * Register a preference with a file name (string) value.
1607 prefs_register_filename_preference(module_t
*module
, const char *name
,
1608 const char *title
, const char *description
,
1609 const char **var
, bool for_writing
)
1612 register_string_like_preference(module
, name
, title
, description
, (char **)var
,
1613 for_writing
? PREF_SAVE_FILENAME
: PREF_OPEN_FILENAME
, NULL
, false);
1618 * Register a preference with a directory name (string) value.
1621 prefs_register_directory_preference(module_t
*module
, const char *name
,
1622 const char *title
, const char *description
,
1626 register_string_like_preference(module
, name
, title
, description
,
1627 (char **)var
, PREF_DIRNAME
, NULL
, false);
1631 /* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
1633 prefs_register_range_preference_common(module_t
*module
, const char *name
,
1634 const char *title
, const char *description
,
1635 range_t
**var
, uint32_t max_value
, int type
)
1639 preference
= register_preference(module
, name
, title
, description
, type
);
1640 preference
->info
.max_value
= max_value
;
1643 * Range preference values should be non-null (as you can't
1644 * keep them null after using the preferences GUI, you can at best
1645 * have them be empty ranges) and freeable (as we free them
1646 * if we change them).
1648 * If the value is a null pointer, make it an empty range.
1651 *var
= range_empty(wmem_epan_scope());
1652 preference
->varp
.range
= var
;
1653 preference
->default_val
.range
= range_copy(wmem_epan_scope(), *var
);
1654 preference
->stashed_val
.range
= NULL
;
1660 * Register a preference with a ranged value.
1663 prefs_register_range_preference(module_t
*module
, const char *name
,
1664 const char *title
, const char *description
,
1665 range_t
**var
, uint32_t max_value
)
1667 prefs_register_range_preference_common(module
, name
, title
,
1668 description
, var
, max_value
, PREF_RANGE
);
1672 prefs_set_range_value_work(pref_t
*pref
, const char *value
,
1673 bool return_range_errors
, unsigned int *changed_flags
)
1677 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
1678 return_range_errors
) != CVT_NO_ERROR
) {
1679 return false; /* number was bad */
1682 if (!ranges_are_equal(*pref
->varp
.range
, newrange
)) {
1683 *changed_flags
|= prefs_get_effect_flags(pref
);
1684 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
1685 *pref
->varp
.range
= newrange
;
1687 wmem_free(wmem_epan_scope(), newrange
);
1693 * For use by UI code that sets preferences.
1696 prefs_set_stashed_range_value(pref_t
*pref
, const char *value
)
1700 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
1701 true) != CVT_NO_ERROR
) {
1702 return 0; /* number was bad */
1705 if (!ranges_are_equal(pref
->stashed_val
.range
, newrange
)) {
1706 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
1707 pref
->stashed_val
.range
= newrange
;
1709 wmem_free(wmem_epan_scope(), newrange
);
1711 return prefs_get_effect_flags(pref
);
1715 bool prefs_add_list_value(pref_t
*pref
, void* value
, pref_source_t source
)
1720 pref
->default_val
.list
= g_list_prepend(pref
->default_val
.list
, value
);
1723 pref
->stashed_val
.list
= g_list_prepend(pref
->stashed_val
.list
, value
);
1726 *pref
->varp
.list
= g_list_prepend(*pref
->varp
.list
, value
);
1729 ws_assert_not_reached();
1736 GList
* prefs_get_list_value(pref_t
*pref
, pref_source_t source
)
1741 return pref
->default_val
.list
;
1743 return pref
->stashed_val
.list
;
1745 return *pref
->varp
.list
;
1747 ws_assert_not_reached();
1754 bool prefs_set_range_value(pref_t
*pref
, range_t
*value
, pref_source_t source
)
1756 bool changed
= false;
1761 if (!ranges_are_equal(pref
->default_val
.range
, value
)) {
1762 wmem_free(wmem_epan_scope(), pref
->default_val
.range
);
1763 pref
->default_val
.range
= range_copy(wmem_epan_scope(), value
);
1768 if (!ranges_are_equal(pref
->stashed_val
.range
, value
)) {
1769 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
1770 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), value
);
1775 if (!ranges_are_equal(*pref
->varp
.range
, value
)) {
1776 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
1777 *pref
->varp
.range
= range_copy(wmem_epan_scope(), value
);
1782 ws_assert_not_reached();
1789 range_t
* prefs_get_range_value_real(pref_t
*pref
, pref_source_t source
)
1794 return pref
->default_val
.range
;
1796 return pref
->stashed_val
.range
;
1798 return *pref
->varp
.range
;
1800 ws_assert_not_reached();
1807 range_t
* prefs_get_range_value(const char *module_name
, const char* pref_name
)
1809 pref_t
*pref
= prefs_find_preference(prefs_find_module(module_name
), pref_name
);
1813 return prefs_get_range_value_real(pref
, pref_current
);
1817 prefs_range_add_value(pref_t
*pref
, uint32_t val
)
1819 range_add_value(wmem_epan_scope(), pref
->varp
.range
, val
);
1823 prefs_range_remove_value(pref_t
*pref
, uint32_t val
)
1825 range_remove_value(wmem_epan_scope(), pref
->varp
.range
, val
);
1829 * Register a static text 'preference'. It can be used to add explanatory
1830 * text inline with other preferences in the GUI.
1831 * Note: Static preferences are not saved to the preferences file.
1834 prefs_register_static_text_preference(module_t
*module
, const char *name
,
1836 const char *description
)
1838 register_preference(module
, name
, title
, description
, PREF_STATIC_TEXT
);
1842 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1843 * preferences tab of the module.
1846 prefs_register_uat_preference(module_t
*module
, const char *name
,
1847 const char *title
, const char *description
,
1851 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_UAT
);
1853 preference
->varp
.uat
= uat
;
1857 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
1858 * preferences tab of the module.
1861 prefs_register_uat_preference_qt(module_t
*module
, const char *name
,
1862 const char *title
, const char *description
,
1866 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_UAT
);
1868 preference
->varp
.uat
= uat
;
1871 struct epan_uat
* prefs_get_uat_value(pref_t
*pref
)
1873 return pref
->varp
.uat
;
1877 * Register a color preference.
1880 prefs_register_color_preference(module_t
*module
, const char *name
,
1881 const char *title
, const char *description
,
1884 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_COLOR
);
1886 preference
->varp
.colorp
= color
;
1887 preference
->default_val
.color
= *color
;
1890 bool prefs_set_color_value(pref_t
*pref
, color_t value
, pref_source_t source
)
1892 bool changed
= false;
1897 if ((pref
->default_val
.color
.red
!= value
.red
) ||
1898 (pref
->default_val
.color
.green
!= value
.green
) ||
1899 (pref
->default_val
.color
.blue
!= value
.blue
)) {
1901 pref
->default_val
.color
= value
;
1905 if ((pref
->stashed_val
.color
.red
!= value
.red
) ||
1906 (pref
->stashed_val
.color
.green
!= value
.green
) ||
1907 (pref
->stashed_val
.color
.blue
!= value
.blue
)) {
1909 pref
->stashed_val
.color
= value
;
1913 if ((pref
->varp
.colorp
->red
!= value
.red
) ||
1914 (pref
->varp
.colorp
->green
!= value
.green
) ||
1915 (pref
->varp
.colorp
->blue
!= value
.blue
)) {
1917 *pref
->varp
.colorp
= value
;
1921 ws_assert_not_reached();
1928 color_t
* prefs_get_color_value(pref_t
*pref
, pref_source_t source
)
1933 return &pref
->default_val
.color
;
1935 return &pref
->stashed_val
.color
;
1937 return pref
->varp
.colorp
;
1939 ws_assert_not_reached();
1947 * Register a "custom" preference with a list.
1948 * XXX - This should be temporary until we can find a better way
1949 * to do "custom" preferences
1951 typedef void (*pref_custom_list_init_cb
) (pref_t
* pref
, GList
** value
);
1954 prefs_register_list_custom_preference(module_t
*module
, const char *name
,
1955 const char *title
, const char *description
,
1956 struct pref_custom_cbs
* custom_cbs
,
1957 pref_custom_list_init_cb init_cb
,
1960 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_CUSTOM
);
1962 preference
->custom_cbs
= *custom_cbs
;
1963 init_cb(preference
, list
);
1967 * Register a custom preference.
1970 prefs_register_custom_preference(module_t
*module
, const char *name
,
1971 const char *title
, const char *description
,
1972 struct pref_custom_cbs
* custom_cbs
,
1973 void **custom_data _U_
)
1975 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_CUSTOM
);
1977 preference
->custom_cbs
= *custom_cbs
;
1978 /* XXX - wait until we can handle void** pointers
1979 preference->custom_cbs.init_cb(preference, custom_data);
1984 * Register a dedicated TCP preference for SEQ analysis overriding.
1985 * This is similar to the data structure from enum preference, except
1986 * that when a preference dialog is used, the stashed value is the list
1987 * of frame data pointers whose sequence analysis override will be set
1988 * to the current value if the dialog is accepted.
1990 * We don't need to read or write the value from the preferences file
1991 * (or command line), because the override is reset to the default (0)
1992 * for each frame when a new capture file is loaded.
1995 prefs_register_custom_preference_TCP_Analysis(module_t
*module
, const char *name
,
1996 const char *title
, const char *description
,
1997 int *var
, const enum_val_t
*enumvals
,
2002 preference
= register_preference(module
, name
, title
, description
,
2003 PREF_PROTO_TCP_SNDAMB_ENUM
);
2004 preference
->varp
.enump
= var
;
2005 preference
->default_val
.enumval
= *var
;
2006 preference
->stashed_val
.list
= NULL
;
2007 preference
->info
.enum_info
.enumvals
= enumvals
;
2008 preference
->info
.enum_info
.radio_buttons
= radio_buttons
;
2012 * Register a (internal) "Decode As" preference with a ranged value.
2014 void prefs_register_decode_as_range_preference(module_t
*module
, const char *name
,
2015 const char *title
, const char *description
, range_t
**var
,
2016 uint32_t max_value
, const char *dissector_table
, const char *dissector_description
)
2020 preference
= prefs_register_range_preference_common(module
, name
, title
,
2021 description
, var
, max_value
, PREF_DECODE_AS_RANGE
);
2022 preference
->dissector_desc
= dissector_description
;
2023 preference
->dissector_table
= dissector_table
;
2027 * Register a preference with password value.
2030 prefs_register_password_preference(module_t
*module
, const char *name
,
2031 const char *title
, const char *description
,
2035 register_string_like_preference(module
, name
, title
, description
,
2036 (char **)var
, PREF_PASSWORD
, NULL
, false);
2041 * Register a preference with a dissector name.
2044 prefs_register_dissector_preference(module_t
*module
, const char *name
,
2045 const char *title
, const char *description
,
2049 register_string_like_preference(module
, name
, title
, description
,
2050 (char **)var
, PREF_DISSECTOR
, NULL
, false);
2054 bool prefs_add_decode_as_value(pref_t
*pref
, unsigned value
, bool replace
)
2058 case PREF_DECODE_AS_RANGE
:
2061 /* If range has single value, replace it */
2062 if (((*pref
->varp
.range
)->nranges
== 1) &&
2063 ((*pref
->varp
.range
)->ranges
[0].low
== (*pref
->varp
.range
)->ranges
[0].high
)) {
2064 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2065 *pref
->varp
.range
= range_empty(wmem_epan_scope());
2069 prefs_range_add_value(pref
, value
);
2072 /* XXX - Worth asserting over? */
2079 bool prefs_remove_decode_as_value(pref_t
*pref
, unsigned value
, bool set_default _U_
)
2083 case PREF_DECODE_AS_RANGE
:
2084 /* XXX - We could set to the default if the value is the only one
2087 prefs_range_remove_value(pref
, value
);
2097 * Register a preference that used to be supported but no longer is.
2100 prefs_register_obsolete_preference(module_t
*module
, const char *name
)
2102 register_preference(module
, name
, NULL
, NULL
, PREF_OBSOLETE
);
2106 prefs_set_preference_effect_fields(module_t
*module
, const char *name
)
2108 pref_t
* pref
= prefs_find_preference(module
, name
);
2110 prefs_set_effect_flags(pref
, prefs_get_effect_flags(pref
) | PREF_EFFECT_FIELDS
);
2115 * Check to see if a preference is obsolete.
2118 prefs_get_preference_obsolete(pref_t
*pref
)
2121 return (IS_PREF_OBSOLETE(pref
->type
) ? true : false);
2127 * Make a preference obsolete.
2129 extern prefs_set_pref_e
2130 prefs_set_preference_obsolete(pref_t
*pref
)
2133 SET_PREF_OBSOLETE(pref
->type
);
2134 return PREFS_SET_OK
;
2136 return PREFS_SET_NO_SUCH_PREF
;
2140 pref_stash(pref_t
*pref
, void *unused _U_
)
2142 switch (pref
->type
) {
2145 pref
->stashed_val
.uint
= *pref
->varp
.uint
;
2149 pref
->stashed_val
.boolval
= *pref
->varp
.boolp
;
2153 pref
->stashed_val
.enumval
= *pref
->varp
.enump
;
2157 case PREF_SAVE_FILENAME
:
2158 case PREF_OPEN_FILENAME
:
2161 case PREF_DISSECTOR
:
2162 g_free(pref
->stashed_val
.string
);
2163 pref
->stashed_val
.string
= g_strdup(*pref
->varp
.string
);
2166 case PREF_DECODE_AS_RANGE
:
2168 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2169 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), *pref
->varp
.range
);
2173 pref
->stashed_val
.color
= *pref
->varp
.colorp
;
2176 case PREF_STATIC_TEXT
:
2179 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2183 ws_assert_not_reached();
2190 pref_unstash(pref_t
*pref
, void *unstash_data_p
)
2192 pref_unstash_data_t
*unstash_data
= (pref_unstash_data_t
*)unstash_data_p
;
2193 dissector_table_t sub_dissectors
= NULL
;
2194 dissector_handle_t handle
= NULL
;
2196 /* Revert the preference to its saved value. */
2197 switch (pref
->type
) {
2200 if (*pref
->varp
.uint
!= pref
->stashed_val
.uint
) {
2201 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2202 *pref
->varp
.uint
= pref
->stashed_val
.uint
;
2207 if (*pref
->varp
.boolp
!= pref
->stashed_val
.boolval
) {
2208 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2209 *pref
->varp
.boolp
= pref
->stashed_val
.boolval
;
2214 if (*pref
->varp
.enump
!= pref
->stashed_val
.enumval
) {
2215 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2216 *pref
->varp
.enump
= pref
->stashed_val
.enumval
;
2220 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2222 /* The preference dialogs are modal so the frame_data pointers should
2223 * still be valid; otherwise we could store the frame numbers to
2227 for (GList
* elem
= pref
->stashed_val
.list
; elem
!= NULL
; elem
= elem
->next
) {
2228 fdata
= (frame_data
*)elem
->data
;
2229 if (fdata
->tcp_snd_manual_analysis
!= *pref
->varp
.enump
) {
2230 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2231 fdata
->tcp_snd_manual_analysis
= *pref
->varp
.enump
;
2237 case PREF_SAVE_FILENAME
:
2238 case PREF_OPEN_FILENAME
:
2241 case PREF_DISSECTOR
:
2242 if (strcmp(*pref
->varp
.string
, pref
->stashed_val
.string
) != 0) {
2243 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2244 g_free(*pref
->varp
.string
);
2245 *pref
->varp
.string
= g_strdup(pref
->stashed_val
.string
);
2249 case PREF_DECODE_AS_RANGE
:
2251 const char* table_name
= prefs_get_dissector_table(pref
);
2252 if (!ranges_are_equal(*pref
->varp
.range
, pref
->stashed_val
.range
)) {
2254 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2256 if (unstash_data
->handle_decode_as
) {
2257 sub_dissectors
= find_dissector_table(table_name
);
2258 if (sub_dissectors
!= NULL
) {
2259 const char *handle_desc
= prefs_get_dissector_description(pref
);
2260 // It should perhaps be possible to get this via dissector name.
2261 handle
= dissector_table_get_dissector_handle(sub_dissectors
, handle_desc
);
2262 if (handle
!= NULL
) {
2263 /* Set the current handle to NULL for all the old values
2264 * in the dissector table. If there isn't an initial
2265 * handle, this actually deletes the entry. (If there
2266 * is an initial entry, keep it around so that the
2267 * user can see the original value.)
2269 * XXX - If there's an initial handle which is not this,
2270 * reset it instead? At least this leaves the initial
2271 * handle visible in the Decode As table.
2273 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
2274 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
2275 dissector_change_uint(table_name
, j
, NULL
);
2276 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
2279 dissector_change_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, NULL
);
2280 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
2286 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2287 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->stashed_val
.range
);
2289 if (unstash_data
->handle_decode_as
) {
2290 if ((sub_dissectors
!= NULL
) && (handle
!= NULL
)) {
2292 /* Add new values to the dissector table */
2293 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
2295 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
2296 dissector_change_uint(table_name
, j
, handle
);
2297 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
2300 dissector_change_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, handle
);
2301 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
2309 if (!ranges_are_equal(*pref
->varp
.range
, pref
->stashed_val
.range
)) {
2310 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2311 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2312 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->stashed_val
.range
);
2317 if ((pref
->varp
.colorp
->blue
!= pref
->stashed_val
.color
.blue
) ||
2318 (pref
->varp
.colorp
->red
!= pref
->stashed_val
.color
.red
) ||
2319 (pref
->varp
.colorp
->green
!= pref
->stashed_val
.color
.green
)) {
2320 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2321 *pref
->varp
.colorp
= pref
->stashed_val
.color
;
2325 case PREF_STATIC_TEXT
:
2331 ws_assert_not_reached();
2338 reset_stashed_pref(pref_t
*pref
) {
2339 switch (pref
->type
) {
2342 pref
->stashed_val
.uint
= pref
->default_val
.uint
;
2346 pref
->stashed_val
.boolval
= pref
->default_val
.boolval
;
2350 pref
->stashed_val
.enumval
= pref
->default_val
.enumval
;
2354 case PREF_SAVE_FILENAME
:
2355 case PREF_OPEN_FILENAME
:
2358 case PREF_DISSECTOR
:
2359 g_free(pref
->stashed_val
.string
);
2360 pref
->stashed_val
.string
= g_strdup(pref
->default_val
.string
);
2363 case PREF_DECODE_AS_RANGE
:
2365 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2366 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), pref
->default_val
.range
);
2369 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2370 if (pref
->stashed_val
.list
!= NULL
) {
2371 g_list_free(pref
->stashed_val
.list
);
2372 pref
->stashed_val
.list
= NULL
;
2377 memcpy(&pref
->stashed_val
.color
, &pref
->default_val
.color
, sizeof(color_t
));
2380 case PREF_STATIC_TEXT
:
2386 ws_assert_not_reached();
2392 pref_clean_stash(pref_t
*pref
, void *unused _U_
)
2394 switch (pref
->type
) {
2406 case PREF_SAVE_FILENAME
:
2407 case PREF_OPEN_FILENAME
:
2410 case PREF_DISSECTOR
:
2411 if (pref
->stashed_val
.string
!= NULL
) {
2412 g_free(pref
->stashed_val
.string
);
2413 pref
->stashed_val
.string
= NULL
;
2417 case PREF_DECODE_AS_RANGE
:
2419 if (pref
->stashed_val
.range
!= NULL
) {
2420 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2421 pref
->stashed_val
.range
= NULL
;
2425 case PREF_STATIC_TEXT
:
2431 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2432 if (pref
->stashed_val
.list
!= NULL
) {
2433 g_list_free(pref
->stashed_val
.list
);
2434 pref
->stashed_val
.list
= NULL
;
2439 ws_assert_not_reached();
2446 * Call a callback function, with a specified argument, for each preference
2447 * in a given module.
2449 * If any of the callbacks return a non-zero value, stop and return that
2450 * value, otherwise return 0.
2453 prefs_pref_foreach(module_t
*module
, pref_cb callback
, void *user_data
)
2459 for (elem
= g_list_first(module
->prefs
); elem
!= NULL
; elem
= g_list_next(elem
)) {
2460 pref
= (pref_t
*)elem
->data
;
2461 if (IS_PREF_OBSOLETE(pref
->type
)) {
2463 * This preference is no longer supported; it's
2464 * not a real preference, so we don't call the
2465 * callback for it (i.e., we treat it as if it
2466 * weren't found in the list of preferences,
2467 * and we weren't called in the first place).
2472 ret
= (*callback
)(pref
, user_data
);
2479 static const enum_val_t st_sort_col_vals
[] = {
2480 { "name", "Node name (topic/item)", ST_SORT_COL_NAME
},
2481 { "count", "Item count", ST_SORT_COL_COUNT
},
2482 { "average", "Average value of the node", ST_SORT_COL_AVG
},
2483 { "min", "Minimum value of the node", ST_SORT_COL_MIN
},
2484 { "max", "Maximum value of the node", ST_SORT_COL_MAX
},
2485 { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE
},
2490 stats_callback(void)
2492 /* Test for a sane tap update interval */
2493 if (prefs
.tap_update_interval
< 100 || prefs
.tap_update_interval
> 10000)
2494 prefs
.tap_update_interval
= TAP_UPDATE_DEFAULT_INTERVAL
;
2496 /* burst resolution can't be less than 1 (ms) */
2497 if (prefs
.st_burst_resolution
< 1) {
2498 prefs
.st_burst_resolution
= 1;
2500 else if (prefs
.st_burst_resolution
> ST_MAX_BURSTRES
) {
2501 prefs
.st_burst_resolution
= ST_MAX_BURSTRES
;
2503 /* make sure burst window value makes sense */
2504 if (prefs
.st_burst_windowlen
< prefs
.st_burst_resolution
) {
2505 prefs
.st_burst_windowlen
= prefs
.st_burst_resolution
;
2507 /* round burst window down to multiple of resolution */
2508 prefs
.st_burst_windowlen
-= prefs
.st_burst_windowlen
%prefs
.st_burst_resolution
;
2509 if ((prefs
.st_burst_windowlen
/prefs
.st_burst_resolution
) > ST_MAX_BURSTBUCKETS
) {
2510 prefs
.st_burst_windowlen
= prefs
.st_burst_resolution
*ST_MAX_BURSTBUCKETS
;
2517 /* Ensure there is at least one file count */
2518 if (prefs
.gui_recent_files_count_max
== 0)
2519 prefs
.gui_recent_files_count_max
= 10;
2521 /* Ensure there is at least one display filter entry */
2522 if (prefs
.gui_recent_df_entries_max
== 0)
2523 prefs
.gui_recent_df_entries_max
= 10;
2525 /* number of decimal places should be between 2 and 10 */
2526 if (prefs
.gui_decimal_places1
< 2) {
2527 prefs
.gui_decimal_places1
= 2;
2528 } else if (prefs
.gui_decimal_places1
> 10) {
2529 prefs
.gui_decimal_places1
= 10;
2531 /* number of decimal places should be between 2 and 10 */
2532 if (prefs
.gui_decimal_places2
< 2) {
2533 prefs
.gui_decimal_places2
= 2;
2534 } else if (prefs
.gui_decimal_places2
> 10) {
2535 prefs
.gui_decimal_places2
= 10;
2537 /* number of decimal places should be between 2 and 10 */
2538 if (prefs
.gui_decimal_places3
< 2) {
2539 prefs
.gui_decimal_places3
= 2;
2540 } else if (prefs
.gui_decimal_places3
> 10) {
2541 prefs
.gui_decimal_places3
= 10;
2546 gui_layout_callback(void)
2548 if (prefs
.gui_layout_type
== layout_unused
||
2549 prefs
.gui_layout_type
>= layout_type_max
) {
2550 /* XXX - report an error? It's not a syntax error - we'd need to
2551 add a way of reporting a *semantic* error. */
2552 prefs
.gui_layout_type
= layout_type_2
;
2556 /******************************************************
2557 * All custom preference function callbacks
2558 ******************************************************/
2559 static void custom_pref_no_cb(pref_t
* pref _U_
) {}
2562 * Column preference functions
2564 #define PRS_COL_HIDDEN_FMT "column.hidden"
2565 #define PRS_COL_HIDDEN "column.hide"
2566 #define PRS_COL_FMT "column.format"
2567 #define PRS_COL_NUM "column.number"
2568 static module_t
*gui_column_module
;
2570 static prefs_set_pref_e
2571 column_hidden_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
2575 pref_t
*format_pref
;
2578 * Prefer the new preference to the old format-based preference if we've
2579 * read it. (We probably could just compare the string to NULL and "".)
2581 prefs
.cols_hide_new
= true;
2583 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
2586 * Set the "visible" flag for the existing columns; we need to
2587 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
2588 * after setting it (which might be the case if, for example, we
2589 * set PRS_COL_HIDDEN on the command line).
2591 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2592 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2595 cfmt
= (fmt_data
*)clp
->data
;
2596 cfmt
->visible
= prefs_is_column_visible(*pref
->varp
.string
, cidx
);
2601 return PREFS_SET_OK
;
2605 column_hidden_type_name_cb(void)
2607 return "Packet list hidden columns";
2611 column_hidden_type_description_cb(void)
2613 return g_strdup("List all column indices (1-indexed) to hide in the packet list.");
2617 column_hidden_to_str_cb(pref_t
* pref
, bool default_val
)
2619 GString
*cols_hidden
;
2622 pref_t
*format_pref
;
2626 return g_strdup(pref
->default_val
.string
);
2628 cols_hidden
= g_string_new("");
2629 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2630 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2632 cfmt
= (fmt_data
*) clp
->data
;
2633 if (!cfmt
->visible
) {
2634 if (cols_hidden
->len
)
2635 g_string_append (cols_hidden
, ",");
2636 g_string_append_printf (cols_hidden
, "%i", cidx
);
2642 return g_string_free (cols_hidden
, FALSE
);
2646 column_hidden_is_default_cb(pref_t
* pref
)
2648 char *cur_hidden_str
= column_hidden_to_str_cb(pref
, false);
2649 bool is_default
= g_strcmp0(cur_hidden_str
, pref
->default_val
.string
) == 0;
2651 g_free(cur_hidden_str
);
2655 static prefs_set_pref_e
2656 column_hidden_fmt_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
2660 pref_t
*format_pref
;
2662 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
2665 * Set the "visible" flag for the existing columns; we need to
2666 * do this if we set PRS_COL_HIDDEN_FMT but don't set PRS_COL_FMT
2667 * after setting it (which might be the case if, for example, we
2668 * set PRS_COL_HIDDEN_FMT on the command line; it shouldn't happen
2669 * when reading the configuration file because we write (both of)
2670 * the hidden column prefs before the column format prefs.)
2672 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2673 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2675 cfmt
= (fmt_data
*)clp
->data
;
2676 cfmt
->visible
= prefs_is_column_fmt_visible(*pref
->varp
.string
, cfmt
);
2680 return PREFS_SET_OK
;
2684 column_hidden_fmt_type_name_cb(void)
2686 return "Packet list hidden column formats (deprecated)";
2690 column_hidden_fmt_type_description_cb(void)
2692 return g_strdup("List all column formats to hide in the packet list. Deprecated in favor of the index-based preference.");
2696 column_hidden_fmt_to_str_cb(pref_t
* pref
, bool default_val
)
2698 GString
*cols_hidden
;
2701 pref_t
*format_pref
;
2704 return g_strdup(pref
->default_val
.string
);
2706 cols_hidden
= g_string_new("");
2707 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2708 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2711 cfmt
= (fmt_data
*) clp
->data
;
2712 if (!cfmt
->visible
) {
2713 if (cols_hidden
->len
)
2714 g_string_append (cols_hidden
, ",");
2715 prefs_fmt
= column_fmt_data_to_str(cfmt
);
2716 g_string_append(cols_hidden
, prefs_fmt
);
2722 return g_string_free (cols_hidden
, FALSE
);
2726 column_hidden_fmt_is_default_cb(pref_t
* pref
)
2728 char *cur_hidden_str
= column_hidden_fmt_to_str_cb(pref
, false);
2729 bool is_default
= g_strcmp0(cur_hidden_str
, pref
->default_val
.string
) == 0;
2731 g_free(cur_hidden_str
);
2735 /* Number of columns "preference". This is only used internally and is not written to the
2739 column_num_reset_cb(pref_t
* pref
)
2741 *pref
->varp
.uint
= pref
->default_val
.uint
;
2744 static prefs_set_pref_e
2745 column_num_set_cb(pref_t
* pref _U_
, const char* value _U_
, unsigned int* changed_flags _U_
)
2747 /* Don't write this to the preferences file */
2748 return PREFS_SET_OK
;
2752 column_num_type_name_cb(void)
2758 column_num_type_description_cb(void)
2760 return g_strdup("");
2764 column_num_is_default_cb(pref_t
* pref _U_
)
2770 column_num_to_str_cb(pref_t
* pref _U_
, bool default_val _U_
)
2772 return g_strdup("");
2776 * Column format custom preference functions
2779 column_format_init_cb(pref_t
* pref
, GList
** value
)
2781 fmt_data
*src_cfmt
, *dest_cfmt
;
2784 pref
->varp
.list
= value
;
2786 pref
->default_val
.list
= NULL
;
2787 for (entry
= *pref
->varp
.list
; entry
!= NULL
; entry
= g_list_next(entry
)) {
2788 src_cfmt
= (fmt_data
*)entry
->data
;
2789 dest_cfmt
= g_new(fmt_data
,1);
2790 dest_cfmt
->title
= g_strdup(src_cfmt
->title
);
2791 dest_cfmt
->fmt
= src_cfmt
->fmt
;
2792 if (src_cfmt
->custom_fields
) {
2793 dest_cfmt
->custom_fields
= g_strdup(src_cfmt
->custom_fields
);
2794 dest_cfmt
->custom_occurrence
= src_cfmt
->custom_occurrence
;
2796 dest_cfmt
->custom_fields
= NULL
;
2797 dest_cfmt
->custom_occurrence
= 0;
2799 dest_cfmt
->visible
= src_cfmt
->visible
;
2800 dest_cfmt
->display
= src_cfmt
->display
;
2801 pref
->default_val
.list
= g_list_append(pref
->default_val
.list
, dest_cfmt
);
2804 column_register_fields();
2808 column_format_free_cb(pref_t
* pref
)
2810 free_col_info(*pref
->varp
.list
);
2811 free_col_info(pref
->default_val
.list
);
2815 column_format_reset_cb(pref_t
* pref
)
2817 fmt_data
*src_cfmt
, *dest_cfmt
;
2819 pref_t
*col_num_pref
;
2821 free_col_info(*pref
->varp
.list
);
2822 *pref
->varp
.list
= NULL
;
2824 for (entry
= pref
->default_val
.list
; entry
!= NULL
; entry
= g_list_next(entry
)) {
2825 src_cfmt
= (fmt_data
*)entry
->data
;
2826 dest_cfmt
= g_new(fmt_data
,1);
2827 dest_cfmt
->title
= g_strdup(src_cfmt
->title
);
2828 dest_cfmt
->fmt
= src_cfmt
->fmt
;
2829 if (src_cfmt
->custom_fields
) {
2830 dest_cfmt
->custom_fields
= g_strdup(src_cfmt
->custom_fields
);
2831 dest_cfmt
->custom_occurrence
= src_cfmt
->custom_occurrence
;
2833 dest_cfmt
->custom_fields
= NULL
;
2834 dest_cfmt
->custom_occurrence
= 0;
2836 dest_cfmt
->visible
= src_cfmt
->visible
;
2837 dest_cfmt
->display
= src_cfmt
->display
;
2838 *pref
->varp
.list
= g_list_append(*pref
->varp
.list
, dest_cfmt
);
2841 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2842 ws_assert(col_num_pref
!= NULL
); /* Should never happen */
2843 column_num_reset_cb(col_num_pref
);
2846 static prefs_set_pref_e
2847 column_format_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags _U_
)
2849 GList
*col_l
, *col_l_elt
;
2852 pref_t
*hidden_pref
, *col_num_pref
;
2854 col_l
= prefs_get_string_list(value
);
2856 return PREFS_SET_SYNTAX_ERR
;
2857 if ((g_list_length(col_l
) % 2) != 0) {
2858 /* A title didn't have a matching format. */
2859 prefs_clear_string_list(col_l
);
2860 return PREFS_SET_SYNTAX_ERR
;
2862 /* Check to make sure all column formats are valid. */
2863 col_l_elt
= g_list_first(col_l
);
2865 fmt_data cfmt_check
;
2867 /* Go past the title. */
2868 col_l_elt
= col_l_elt
->next
;
2870 /* Some predefined columns have been migrated to use custom columns.
2871 * We'll convert these silently here */
2872 try_convert_to_custom_column((char **)&col_l_elt
->data
);
2874 /* Parse the format to see if it's valid. */
2875 if (!parse_column_format(&cfmt_check
, (char *)col_l_elt
->data
)) {
2876 /* It's not a valid column format. */
2877 prefs_clear_string_list(col_l
);
2878 return PREFS_SET_SYNTAX_ERR
;
2880 if (cfmt_check
.fmt
== COL_CUSTOM
) {
2881 /* We don't need the custom column field on this pass. */
2882 g_free(cfmt_check
.custom_fields
);
2885 /* Go past the format. */
2886 col_l_elt
= col_l_elt
->next
;
2889 /* They're all valid; process them. */
2890 free_col_info(*pref
->varp
.list
);
2891 *pref
->varp
.list
= NULL
;
2892 if (prefs
.cols_hide_new
) {
2893 hidden_pref
= prefs_find_preference(gui_column_module
, PRS_COL_HIDDEN
);
2895 hidden_pref
= prefs_find_preference(gui_column_module
, PRS_COL_HIDDEN_FMT
);
2897 ws_assert(hidden_pref
!= NULL
); /* Should never happen */
2898 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2899 ws_assert(col_num_pref
!= NULL
); /* Should never happen */
2900 llen
= g_list_length(col_l
);
2901 *col_num_pref
->varp
.uint
= llen
/ 2;
2902 col_l_elt
= g_list_first(col_l
);
2905 cfmt
= g_new(fmt_data
,1);
2906 cfmt
->title
= g_strdup((char *)col_l_elt
->data
);
2907 col_l_elt
= col_l_elt
->next
;
2908 parse_column_format(cfmt
, (char *)col_l_elt
->data
);
2909 if (prefs
.cols_hide_new
) {
2910 cfmt
->visible
= prefs_is_column_visible(*hidden_pref
->varp
.string
, cidx
);
2912 cfmt
->visible
= prefs_is_column_fmt_visible(*hidden_pref
->varp
.string
, cfmt
);
2914 col_l_elt
= col_l_elt
->next
;
2915 *pref
->varp
.list
= g_list_append(*pref
->varp
.list
, cfmt
);
2919 prefs_clear_string_list(col_l
);
2920 free_string_like_preference(hidden_pref
);
2921 column_register_fields();
2922 return PREFS_SET_OK
;
2927 column_format_type_name_cb(void)
2929 return "Packet list column format";
2933 column_format_type_description_cb(void)
2935 return g_strdup("Each pair of strings consists of a column title and its format");
2939 column_format_is_default_cb(pref_t
* pref
)
2941 GList
*clp
= *pref
->varp
.list
,
2942 *pref_col
= g_list_first(clp
),
2943 *def_col
= g_list_first(pref
->default_val
.list
);
2944 fmt_data
*cfmt
, *def_cfmt
;
2945 bool is_default
= true;
2946 pref_t
*col_num_pref
;
2948 /* See if the column data has changed from the default */
2949 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2950 if (col_num_pref
&& *col_num_pref
->varp
.uint
!= col_num_pref
->default_val
.uint
) {
2953 while (pref_col
&& def_col
) {
2954 cfmt
= (fmt_data
*) pref_col
->data
;
2955 def_cfmt
= (fmt_data
*) def_col
->data
;
2956 if ((g_strcmp0(cfmt
->title
, def_cfmt
->title
) != 0) ||
2957 (cfmt
->fmt
!= def_cfmt
->fmt
) ||
2958 (((cfmt
->fmt
== COL_CUSTOM
) && (cfmt
->custom_fields
)) &&
2959 ((g_strcmp0(cfmt
->custom_fields
, def_cfmt
->custom_fields
) != 0) ||
2960 (cfmt
->display
!= def_cfmt
->display
)))) {
2965 pref_col
= pref_col
->next
;
2966 def_col
= def_col
->next
;
2974 column_format_to_str_cb(pref_t
* pref
, bool default_val
)
2976 GList
*pref_l
= default_val
? pref
->default_val
.list
: *pref
->varp
.list
;
2977 GList
*clp
= g_list_first(pref_l
);
2980 char *column_format_str
;
2984 cfmt
= (fmt_data
*) clp
->data
;
2985 col_l
= g_list_append(col_l
, g_strdup(cfmt
->title
));
2986 col_l
= g_list_append(col_l
, column_fmt_data_to_str(cfmt
));
2990 column_format_str
= join_string_list(col_l
);
2991 prefs_clear_string_list(col_l
);
2992 return column_format_str
;
2996 /****** Capture column custom preference functions ******/
2998 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
2999 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
3000 to prefs->default_val.list.
3003 capture_column_init_cb(pref_t
* pref
, GList
** capture_cols_values
)
3005 GList
*ccv_list
= *capture_cols_values
,
3010 dlist
= g_list_append(dlist
, g_strdup((char *)ccv_list
->data
));
3011 ccv_list
= ccv_list
->next
;
3014 pref
->default_val
.list
= dlist
;
3015 pref
->varp
.list
= &prefs
.capture_columns
;
3016 pref
->stashed_val
.boolval
= false;
3019 /* Free the prefs->capture_columns list strings and remove the list entries.
3020 Note that since pref->varp.list points to &prefs.capture_columns, it is
3024 capture_column_free_cb(pref_t
* pref
)
3026 prefs_clear_string_list(prefs
.capture_columns
);
3027 prefs
.capture_columns
= NULL
;
3029 if (pref
->stashed_val
.boolval
== true) {
3030 prefs_clear_string_list(pref
->default_val
.list
);
3031 pref
->default_val
.list
= NULL
;
3035 /* Copy pref->default_val.list to *pref->varp.list.
3038 capture_column_reset_cb(pref_t
* pref
)
3040 GList
*vlist
= NULL
, *dlist
;
3042 /* Free the column name strings and remove the links from *pref->varp.list */
3043 prefs_clear_string_list(*pref
->varp
.list
);
3045 for (dlist
= pref
->default_val
.list
; dlist
!= NULL
; dlist
= g_list_next(dlist
)) {
3046 vlist
= g_list_append(vlist
, g_strdup((char *)dlist
->data
));
3048 *pref
->varp
.list
= vlist
;
3051 static prefs_set_pref_e
3052 capture_column_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags _U_
)
3054 GList
*col_l
= prefs_get_string_list(value
);
3060 return PREFS_SET_SYNTAX_ERR
;
3062 capture_column_free_cb(pref
);
3064 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
3065 to the full list of valid capture column names. */
3066 col_l_elt
= g_list_first(col_l
);
3067 if (!(*(char *)col_l_elt
->data
)) {
3068 for (i
= 0; i
< num_capture_cols
; i
++) {
3069 col_name
= g_strdup(capture_cols
[i
]);
3070 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3074 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
3077 bool found_match
= false;
3078 col_name
= (char *)col_l_elt
->data
;
3080 for (i
= 0; i
< num_capture_cols
; i
++) {
3081 if (strcmp(col_name
, capture_cols
[i
])==0) {
3087 /* One or more cols are invalid so use the entire list of valid cols. */
3088 for (i
= 0; i
< num_capture_cols
; i
++) {
3089 col_name
= g_strdup(capture_cols
[i
]);
3090 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3092 pref
->varp
.list
= &prefs
.capture_columns
;
3093 prefs_clear_string_list(col_l
);
3094 return PREFS_SET_SYNTAX_ERR
;
3096 col_l_elt
= col_l_elt
->next
;
3099 col_l_elt
= g_list_first(col_l
);
3101 col_name
= (char *)col_l_elt
->data
;
3102 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3103 col_l_elt
= col_l_elt
->next
;
3105 pref
->varp
.list
= &prefs
.capture_columns
;
3107 return PREFS_SET_OK
;
3112 capture_column_type_name_cb(void)
3114 return "Column list";
3118 capture_column_type_description_cb(void)
3121 "List of columns to be displayed in the capture options dialog.\n"
3122 CAPTURE_COL_TYPE_DESCRIPTION
);
3126 capture_column_is_default_cb(pref_t
* pref
)
3128 GList
*pref_col
= g_list_first(prefs
.capture_columns
),
3129 *def_col
= g_list_first(pref
->default_val
.list
);
3130 bool is_default
= true;
3132 /* See if the column data has changed from the default */
3133 while (pref_col
&& def_col
) {
3134 if (strcmp((char *)pref_col
->data
, (char *)def_col
->data
) != 0) {
3138 pref_col
= pref_col
->next
;
3139 def_col
= def_col
->next
;
3142 /* Ensure the same column count */
3143 if (((pref_col
== NULL
) && (def_col
!= NULL
)) ||
3144 ((pref_col
!= NULL
) && (def_col
== NULL
)))
3151 capture_column_to_str_cb(pref_t
* pref
, bool default_val
)
3154 GList
*pref_l
= default_val
? pref
->default_val
.list
: prefs
.capture_columns
;
3155 GList
*clp
= g_list_first(pref_l
);
3156 GList
*col_l
= NULL
;
3158 char *capture_column_str
;
3161 col
= (char *) clp
->data
;
3162 col_l
= g_list_append(col_l
, g_strdup(col
));
3166 capture_column_str
= join_string_list(col_l
);
3167 prefs_clear_string_list(col_l
);
3168 return capture_column_str
;
3171 static prefs_set_pref_e
3172 colorized_frame_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
3174 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
3175 return PREFS_SET_OK
;
3179 colorized_frame_type_name_cb(void)
3181 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
3182 * file until the colors can be changed in the GUI. Currently this is not really
3183 * possible since the STOCK-icons for these colors are hardcoded.
3185 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
3186 * add these 10 colors to the list of colors that can be changed through
3194 colorized_frame_type_description_cb(void)
3196 return g_strdup("");
3200 colorized_frame_is_default_cb(pref_t
* pref _U_
)
3206 colorized_frame_to_str_cb(pref_t
* pref _U_
, bool default_val _U_
)
3208 return g_strdup("");
3212 * Register all non-dissector modules' preferences.
3214 static module_t
*gui_module
;
3215 static module_t
*gui_color_module
;
3216 static module_t
*nameres_module
;
3219 prefs_register_modules(void)
3221 module_t
*printing
, *capture_module
, *console_module
,
3222 *gui_layout_module
, *gui_font_module
;
3223 module_t
*extcap_module
;
3224 unsigned int layout_gui_flags
;
3225 struct pref_custom_cbs custom_cbs
;
3227 if (protocols_module
!= NULL
) {
3228 /* Already setup preferences */
3233 * These are "simple" GUI preferences that can be read/written using the
3234 * preference module API. These preferences still use their own
3235 * configuration screens for access, but this cuts down on the
3236 * preference "string compare list" in set_pref()
3238 extcap_module
= prefs_register_module(NULL
, "extcap", "Extcap Utilities",
3239 "Extcap Utilities", NULL
, NULL
, false);
3241 /* Setting default value to true */
3242 prefs
.extcap_save_on_start
= true;
3243 prefs_register_bool_preference(extcap_module
, "gui_save_on_start",
3244 "Save arguments on start of capture",
3245 "Save arguments on start of capture",
3246 &prefs
.extcap_save_on_start
);
3249 * These are "simple" GUI preferences that can be read/written using the
3250 * preference module API. These preferences still use their own
3251 * configuration screens for access, but this cuts down on the
3252 * preference "string compare list" in set_pref()
3254 gui_module
= prefs_register_module(NULL
, "gui", "User Interface",
3255 "User Interface", NULL
, &gui_callback
, false);
3257 * The GUI preferences don't affect dissection in general.
3258 * Any changes are signaled in other ways, so PREF_EFFECT_GUI doesn't
3259 * explicitly do anything, but wslua_set_preference expects *some*
3260 * effect flag to be set if the preference was changed.
3261 * We have to do this again for all the submodules (except for the
3262 * layout submodule, which has its own effect flag).
3264 unsigned gui_effect_flags
= prefs_get_module_effect_flags(gui_module
);
3265 gui_effect_flags
|= PREF_EFFECT_GUI
;
3266 gui_effect_flags
&= (~PREF_EFFECT_DISSECTION
);
3267 prefs_set_module_effect_flags(gui_module
, gui_effect_flags
);
3270 * gui.console_open is stored in the registry in addition to the
3271 * preferences file. It is also read independently by ws_log_init()
3272 * for early log initialization of the console.
3274 prefs_register_enum_preference(gui_module
, "console_open",
3275 "Open a console window",
3276 "Open a console window (Windows only)",
3277 (int *)&ws_log_console_open
, gui_console_open_type
, false);
3279 prefs_register_obsolete_preference(gui_module
, "scrollbar_on_right");
3280 prefs_register_obsolete_preference(gui_module
, "packet_list_sel_browse");
3281 prefs_register_obsolete_preference(gui_module
, "protocol_tree_sel_browse");
3282 prefs_register_obsolete_preference(gui_module
, "tree_view_altern_colors");
3283 prefs_register_obsolete_preference(gui_module
, "expert_composite_eyecandy");
3284 prefs_register_obsolete_preference(gui_module
, "filter_toolbar_show_in_statusbar");
3286 prefs_register_bool_preference(gui_module
, "restore_filter_after_following_stream",
3287 "Restore current display filter after following a stream",
3288 "Restore current display filter after following a stream?",
3289 &prefs
.restore_filter_after_following_stream
);
3291 prefs_register_obsolete_preference(gui_module
, "protocol_tree_line_style");
3293 prefs_register_obsolete_preference(gui_module
, "protocol_tree_expander_style");
3295 prefs_register_obsolete_preference(gui_module
, "hex_dump_highlight_style");
3297 prefs_register_obsolete_preference(gui_module
, "packet_editor.enabled");
3299 gui_column_module
= prefs_register_subtree(gui_module
, "Columns", "Columns", NULL
);
3300 prefs_set_module_effect_flags(gui_column_module
, gui_effect_flags
);
3301 /* For reading older preference files with "column." preferences */
3302 prefs_register_module_alias("column", gui_column_module
);
3305 custom_cbs
.free_cb
= free_string_like_preference
;
3306 custom_cbs
.reset_cb
= reset_string_like_preference
;
3307 custom_cbs
.set_cb
= column_hidden_set_cb
;
3308 custom_cbs
.type_name_cb
= column_hidden_type_name_cb
;
3309 custom_cbs
.type_description_cb
= column_hidden_type_description_cb
;
3310 custom_cbs
.is_default_cb
= column_hidden_is_default_cb
;
3311 custom_cbs
.to_str_cb
= column_hidden_to_str_cb
;
3312 register_string_like_preference(gui_column_module
, PRS_COL_HIDDEN
, "Packet list hidden columns",
3313 "List all column indices (1-indexed) to hide in the packet list",
3314 &cols_hidden_list
, PREF_CUSTOM
, &custom_cbs
, false);
3316 custom_cbs
.set_cb
= column_hidden_fmt_set_cb
;
3317 custom_cbs
.type_name_cb
= column_hidden_fmt_type_name_cb
;
3318 custom_cbs
.type_description_cb
= column_hidden_fmt_type_description_cb
;
3319 custom_cbs
.is_default_cb
= column_hidden_fmt_is_default_cb
;
3320 custom_cbs
.to_str_cb
= column_hidden_fmt_to_str_cb
;
3322 register_string_like_preference(gui_column_module
, PRS_COL_HIDDEN_FMT
, "Packet list hidden column formats (deprecated)",
3323 "List all column formats to hide in the packet list; deprecated in favor of the index-based preference",
3324 &cols_hidden_fmt_list
, PREF_CUSTOM
, &custom_cbs
, false);
3326 custom_cbs
.free_cb
= column_format_free_cb
;
3327 custom_cbs
.reset_cb
= column_format_reset_cb
;
3328 custom_cbs
.set_cb
= column_format_set_cb
;
3329 custom_cbs
.type_name_cb
= column_format_type_name_cb
;
3330 custom_cbs
.type_description_cb
= column_format_type_description_cb
;
3331 custom_cbs
.is_default_cb
= column_format_is_default_cb
;
3332 custom_cbs
.to_str_cb
= column_format_to_str_cb
;
3334 prefs_register_list_custom_preference(gui_column_module
, PRS_COL_FMT
, "Packet list column format",
3335 "Each pair of strings consists of a column title and its format", &custom_cbs
,
3336 column_format_init_cb
, &prefs
.col_list
);
3338 /* Number of columns. This is only used internally and is not written to the
3341 custom_cbs
.free_cb
= custom_pref_no_cb
;
3342 custom_cbs
.reset_cb
= column_num_reset_cb
;
3343 custom_cbs
.set_cb
= column_num_set_cb
;
3344 custom_cbs
.type_name_cb
= column_num_type_name_cb
;
3345 custom_cbs
.type_description_cb
= column_num_type_description_cb
;
3346 custom_cbs
.is_default_cb
= column_num_is_default_cb
;
3347 custom_cbs
.to_str_cb
= column_num_to_str_cb
;
3348 prefs_register_uint_custom_preference(gui_column_module
, PRS_COL_NUM
, "Number of columns",
3349 "Number of columns in col_list", &custom_cbs
, &prefs
.num_cols
);
3351 /* User Interface : Font */
3352 gui_font_module
= prefs_register_subtree(gui_module
, "Font", "Font", NULL
);
3353 prefs_set_module_effect_flags(gui_font_module
, gui_effect_flags
);
3355 prefs_register_obsolete_preference(gui_font_module
, "font_name");
3357 prefs_register_obsolete_preference(gui_font_module
, "gtk2.font_name");
3359 register_string_like_preference(gui_font_module
, "qt.font_name", "Font name",
3360 "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
3361 &prefs
.gui_font_name
, PREF_STRING
, NULL
, true);
3363 /* User Interface : Colors */
3364 gui_color_module
= prefs_register_subtree(gui_module
, "Colors", "Colors", NULL
);
3365 unsigned gui_color_effect_flags
= gui_effect_flags
| PREF_EFFECT_GUI_COLOR
;
3366 prefs_set_module_effect_flags(gui_color_module
, gui_color_effect_flags
);
3368 prefs_register_enum_preference(gui_color_module
, "color_scheme", "Color scheme", "Color scheme",
3369 &prefs
.gui_color_scheme
, gui_color_scheme
, false);
3371 prefs_register_color_preference(gui_color_module
, "active_frame.fg", "Foreground color for an active selected item",
3372 "Foreground color for an active selected item", &prefs
.gui_active_fg
);
3374 prefs_register_color_preference(gui_color_module
, "active_frame.bg", "Background color for an active selected item",
3375 "Background color for an active selected item", &prefs
.gui_active_bg
);
3377 prefs_register_enum_preference(gui_color_module
, "active_frame.style", "Color style for an active selected item",
3378 "Color style for an active selected item", &prefs
.gui_active_style
, gui_selection_style
, false);
3380 prefs_register_color_preference(gui_color_module
, "inactive_frame.fg", "Foreground color for an inactive selected item",
3381 "Foreground color for an inactive selected item", &prefs
.gui_inactive_fg
);
3383 prefs_register_color_preference(gui_color_module
, "inactive_frame.bg", "Background color for an inactive selected item",
3384 "Background color for an inactive selected item", &prefs
.gui_inactive_bg
);
3386 prefs_register_enum_preference(gui_color_module
, "inactive_frame.style", "Color style for an inactive selected item",
3387 "Color style for an inactive selected item", &prefs
.gui_inactive_style
, gui_selection_style
, false);
3389 prefs_register_color_preference(gui_color_module
, "marked_frame.fg", "Color preferences for a marked frame",
3390 "Color preferences for a marked frame", &prefs
.gui_marked_fg
);
3392 prefs_register_color_preference(gui_color_module
, "marked_frame.bg", "Color preferences for a marked frame",
3393 "Color preferences for a marked frame", &prefs
.gui_marked_bg
);
3395 prefs_register_color_preference(gui_color_module
, "ignored_frame.fg", "Color preferences for a ignored frame",
3396 "Color preferences for a ignored frame", &prefs
.gui_ignored_fg
);
3398 prefs_register_color_preference(gui_color_module
, "ignored_frame.bg", "Color preferences for a ignored frame",
3399 "Color preferences for a ignored frame", &prefs
.gui_ignored_bg
);
3401 prefs_register_color_preference(gui_color_module
, "stream.client.fg", "TCP stream window color preference",
3402 "TCP stream window color preference", &prefs
.st_client_fg
);
3404 prefs_register_color_preference(gui_color_module
, "stream.client.bg", "TCP stream window color preference",
3405 "TCP stream window color preference", &prefs
.st_client_bg
);
3407 prefs_register_color_preference(gui_color_module
, "stream.server.fg", "TCP stream window color preference",
3408 "TCP stream window color preference", &prefs
.st_server_fg
);
3410 prefs_register_color_preference(gui_color_module
, "stream.server.bg", "TCP stream window color preference",
3411 "TCP stream window color preference", &prefs
.st_server_bg
);
3413 custom_cbs
.free_cb
= free_string_like_preference
;
3414 custom_cbs
.reset_cb
= reset_string_like_preference
;
3415 custom_cbs
.set_cb
= colorized_frame_set_cb
;
3416 custom_cbs
.type_name_cb
= colorized_frame_type_name_cb
;
3417 custom_cbs
.type_description_cb
= colorized_frame_type_description_cb
;
3418 custom_cbs
.is_default_cb
= colorized_frame_is_default_cb
;
3419 custom_cbs
.to_str_cb
= colorized_frame_to_str_cb
;
3420 register_string_like_preference(gui_column_module
, "colorized_frame.fg", "Colorized Foreground",
3421 "Filter Colorized Foreground",
3422 &prefs
.gui_colorized_fg
, PREF_CUSTOM
, &custom_cbs
, true);
3424 custom_cbs
.free_cb
= free_string_like_preference
;
3425 custom_cbs
.reset_cb
= reset_string_like_preference
;
3426 custom_cbs
.set_cb
= colorized_frame_set_cb
;
3427 custom_cbs
.type_name_cb
= colorized_frame_type_name_cb
;
3428 custom_cbs
.type_description_cb
= colorized_frame_type_description_cb
;
3429 custom_cbs
.is_default_cb
= colorized_frame_is_default_cb
;
3430 custom_cbs
.to_str_cb
= colorized_frame_to_str_cb
;
3431 register_string_like_preference(gui_column_module
, "colorized_frame.bg", "Colorized Background",
3432 "Filter Colorized Background",
3433 &prefs
.gui_colorized_bg
, PREF_CUSTOM
, &custom_cbs
, true);
3435 prefs_register_color_preference(gui_color_module
, "color_filter_bg.valid", "Valid color filter background",
3436 "Valid color filter background", &prefs
.gui_text_valid
);
3438 prefs_register_color_preference(gui_color_module
, "color_filter_bg.invalid", "Invalid color filter background",
3439 "Invalid color filter background", &prefs
.gui_text_invalid
);
3441 prefs_register_color_preference(gui_color_module
, "color_filter_bg.deprecated", "Deprecated color filter background",
3442 "Deprecated color filter background", &prefs
.gui_text_deprecated
);
3444 prefs_register_enum_preference(gui_module
, "fileopen.style",
3445 "Where to start the File Open dialog box",
3446 "Where to start the File Open dialog box",
3447 &prefs
.gui_fileopen_style
, gui_fileopen_style
, false);
3449 prefs_register_uint_preference(gui_module
, "recent_files_count.max",
3450 "The max. number of items in the open recent files list",
3451 "The max. number of items in the open recent files list",
3453 &prefs
.gui_recent_files_count_max
);
3455 prefs_register_uint_preference(gui_module
, "recent_display_filter_entries.max",
3456 "The max. number of entries in the display filter list",
3457 "The max. number of entries in the display filter list",
3459 &prefs
.gui_recent_df_entries_max
);
3461 register_string_like_preference(gui_module
, "fileopen.dir", "Start Directory",
3462 "Directory to start in when opening File Open dialog.",
3463 &prefs
.gui_fileopen_dir
, PREF_DIRNAME
, NULL
, true);
3465 prefs_register_obsolete_preference(gui_module
, "fileopen.remembered_dir");
3467 prefs_register_uint_preference(gui_module
, "fileopen.preview",
3468 "The preview timeout in the File Open dialog",
3469 "The preview timeout in the File Open dialog",
3471 &prefs
.gui_fileopen_preview
);
3473 register_string_like_preference(gui_module
, "tlskeylog_command", "Program to launch with TLS Keylog",
3474 "Program path or command line to launch with SSLKEYLOGFILE",
3475 &prefs
.gui_tlskeylog_command
, PREF_STRING
, NULL
, true);
3477 prefs_register_bool_preference(gui_module
, "ask_unsaved",
3478 "Ask to save unsaved capture files",
3479 "Ask to save unsaved capture files?",
3480 &prefs
.gui_ask_unsaved
);
3482 prefs_register_bool_preference(gui_module
, "autocomplete_filter",
3483 "Display autocompletion for filter text",
3484 "Display an autocomplete suggestion for display and capture filter controls",
3485 &prefs
.gui_autocomplete_filter
);
3487 prefs_register_bool_preference(gui_module
, "find_wrap",
3488 "Wrap to beginning/end of file during search",
3489 "Wrap to beginning/end of file during search?",
3490 &prefs
.gui_find_wrap
);
3492 prefs_register_obsolete_preference(gui_module
, "use_pref_save");
3494 prefs_register_bool_preference(gui_module
, "geometry.save.position",
3495 "Save window position at exit",
3496 "Save window position at exit?",
3497 &prefs
.gui_geometry_save_position
);
3499 prefs_register_bool_preference(gui_module
, "geometry.save.size",
3500 "Save window size at exit",
3501 "Save window size at exit?",
3502 &prefs
.gui_geometry_save_size
);
3504 prefs_register_bool_preference(gui_module
, "geometry.save.maximized",
3505 "Save window maximized state at exit",
3506 "Save window maximized state at exit?",
3507 &prefs
.gui_geometry_save_maximized
);
3509 prefs_register_obsolete_preference(gui_module
, "macosx_style");
3511 prefs_register_obsolete_preference(gui_module
, "geometry.main.x");
3512 prefs_register_obsolete_preference(gui_module
, "geometry.main.y");
3513 prefs_register_obsolete_preference(gui_module
, "geometry.main.width");
3514 prefs_register_obsolete_preference(gui_module
, "geometry.main.height");
3515 prefs_register_obsolete_preference(gui_module
, "toolbar_main_show");
3517 prefs_register_enum_preference(gui_module
, "toolbar_main_style",
3518 "Main Toolbar style",
3519 "Main Toolbar style",
3520 &prefs
.gui_toolbar_main_style
, gui_toolbar_style
, false);
3522 prefs_register_obsolete_preference(gui_module
, "toolbar_filter_style");
3523 prefs_register_obsolete_preference(gui_module
, "webbrowser");
3525 prefs_register_bool_preference(gui_module
, "update.enabled",
3526 "Check for updates",
3527 "Check for updates (Windows and macOS only)",
3528 &prefs
.gui_update_enabled
);
3530 prefs_register_enum_preference(gui_module
, "update.channel",
3532 "The type of update to fetch. You should probably leave this set to STABLE.",
3533 (int*)(void*)(&prefs
.gui_update_channel
), gui_update_channel
, false);
3535 prefs_register_uint_preference(gui_module
, "update.interval",
3536 "How often to check for software updates",
3537 "How often to check for software updates in seconds",
3539 &prefs
.gui_update_interval
);
3541 prefs_register_uint_preference(gui_module
, "debounce.timer",
3542 "How long to wait before processing computationally intensive user input",
3543 "How long to wait (in milliseconds) before processing "
3544 "computationally intensive user input. "
3545 "If you type quickly, consider lowering the value for a 'snappier' "
3547 "If you type slowly, consider increasing the value to avoid performance issues. "
3548 "This is currently used to delay searches in View -> Internals -> Supported Protocols "
3549 "and Preferences -> Advanced menu.",
3551 &prefs
.gui_debounce_timer
);
3553 register_string_like_preference(gui_module
, "window_title", "Custom window title",
3554 "Custom window title to be appended to the existing title\n"
3555 "%C = capture comment from command line\n"
3556 "%F = file path of the capture file\n"
3557 "%P = profile name\n"
3558 "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3559 "%V = version info",
3560 &prefs
.gui_window_title
, PREF_STRING
, NULL
, true);
3562 register_string_like_preference(gui_module
, "prepend_window_title", "Custom window title prefix",
3563 "Custom window title to be prepended to the existing title\n"
3564 "%C = capture comment from command line\n"
3565 "%F = file path of the capture file\n"
3566 "%P = profile name\n"
3567 "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3568 "%V = version info",
3569 &prefs
.gui_prepend_window_title
, PREF_STRING
, NULL
, true);
3571 register_string_like_preference(gui_module
, "start_title", "Custom start page title",
3572 "Custom start page title",
3573 &prefs
.gui_start_title
, PREF_STRING
, NULL
, true);
3575 prefs_register_enum_preference(gui_module
, "version_placement",
3576 "Show version in the start page and/or main screen's title bar",
3577 "Show version in the start page and/or main screen's title bar",
3578 (int*)(void*)(&prefs
.gui_version_placement
), gui_version_placement_type
, false);
3580 prefs_register_obsolete_preference(gui_module
, "auto_scroll_on_expand");
3581 prefs_register_obsolete_preference(gui_module
, "auto_scroll_percentage");
3583 prefs_register_uint_preference(gui_module
, "max_export_objects",
3584 "Maximum number of exported objects",
3585 "The maximum number of objects that can be exported",
3587 &prefs
.gui_max_export_objects
);
3588 prefs_register_uint_preference(gui_module
, "max_tree_items",
3589 "Maximum number of tree items",
3590 "The maximum number of items that can be added to the dissection tree (Increase with caution)",
3592 &prefs
.gui_max_tree_items
);
3594 * Used independently by proto_tree_add_node, call_dissector*, dissector_try_heuristic,
3595 * and increment_dissection_depth.
3597 prefs_register_uint_preference(gui_module
, "max_tree_depth",
3598 "Maximum dissection depth",
3599 "The maximum depth for dissection tree and protocol layer checks. (Increase with caution)",
3601 &prefs
.gui_max_tree_depth
);
3603 prefs_register_bool_preference(gui_module
, "welcome_page.show_recent",
3604 "Show recent files on the welcome page",
3605 "This will enable or disable the 'Open' list on the welcome page.",
3606 &prefs
.gui_welcome_page_show_recent
);
3608 /* User Interface : Layout */
3609 gui_layout_module
= prefs_register_subtree(gui_module
, "Layout", "Layout", gui_layout_callback
);
3610 /* Adjust the preference effects of layout GUI for better handling of preferences at Wireshark (GUI) level */
3611 layout_gui_flags
= prefs_get_module_effect_flags(gui_layout_module
);
3612 layout_gui_flags
|= PREF_EFFECT_GUI_LAYOUT
;
3613 layout_gui_flags
&= (~PREF_EFFECT_DISSECTION
);
3615 prefs_register_uint_preference(gui_layout_module
, "layout_type",
3617 "Layout type (1-6)",
3619 (unsigned*)(void*)(&prefs
.gui_layout_type
));
3620 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_type", layout_gui_flags
);
3622 prefs_register_enum_preference(gui_layout_module
, "layout_content_1",
3623 "Layout content of the pane 1",
3624 "Layout content of the pane 1",
3625 (int*)(void*)(&prefs
.gui_layout_content_1
), gui_layout_content
, false);
3626 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_1", layout_gui_flags
);
3628 prefs_register_enum_preference(gui_layout_module
, "layout_content_2",
3629 "Layout content of the pane 2",
3630 "Layout content of the pane 2",
3631 (int*)(void*)(&prefs
.gui_layout_content_2
), gui_layout_content
, false);
3632 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_2", layout_gui_flags
);
3634 prefs_register_enum_preference(gui_layout_module
, "layout_content_3",
3635 "Layout content of the pane 3",
3636 "Layout content of the pane 3",
3637 (int*)(void*)(&prefs
.gui_layout_content_3
), gui_layout_content
, false);
3638 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_3", layout_gui_flags
);
3640 prefs_register_bool_preference(gui_layout_module
, "packet_list_separator.enabled",
3641 "Enable Packet List Separator",
3642 "Enable Packet List Separator",
3643 &prefs
.gui_packet_list_separator
);
3645 prefs_register_bool_preference(gui_layout_module
, "packet_header_column_definition.enabled",
3646 "Show column definition in packet list header",
3647 "Show column definition in packet list header",
3648 &prefs
.gui_packet_header_column_definition
);
3650 /* packet_list_hover_style affects the colors, not the layout.
3651 * It's in the layout module to group it with the other packet list
3652 * preferences for the user's benefit with the dialog.
3654 prefs_register_bool_preference(gui_layout_module
, "packet_list_hover_style.enabled",
3655 "Enable Packet List mouse-over colorization",
3656 "Enable Packet List mouse-over colorization",
3657 &prefs
.gui_packet_list_hover_style
);
3658 prefs_set_effect_flags_by_name(gui_layout_module
, "packet_list_hover_style.enabled", gui_color_effect_flags
);
3660 prefs_register_bool_preference(gui_layout_module
, "show_selected_packet.enabled",
3661 "Show selected packet in the Status Bar",
3662 "Show selected packet in the Status Bar",
3663 &prefs
.gui_show_selected_packet
);
3665 prefs_register_bool_preference(gui_layout_module
, "show_file_load_time.enabled",
3666 "Show file load time in the Status Bar",
3667 "Show file load time in the Status Bar",
3668 &prefs
.gui_show_file_load_time
);
3670 prefs_register_enum_preference(gui_layout_module
, "packet_dialog_layout",
3671 "Packet Dialog layout",
3672 "Packet Dialog layout",
3673 (unsigned*)(void*)(&prefs
.gui_packet_dialog_layout
), gui_packet_dialog_layout
, false);
3675 prefs_register_enum_preference(gui_module
, "packet_list_elide_mode",
3677 "The position of \"...\" (ellipsis) in packet list text.",
3678 (int*)(void*)(&prefs
.gui_packet_list_elide_mode
), gui_packet_list_elide_mode
, false);
3679 prefs_register_uint_preference(gui_module
, "decimal_places1",
3680 "Count of decimal places for values of type 1",
3681 "Sets the count of decimal places for values of type 1."
3682 "Type 1 values are defined by authors."
3683 "Value can be in range 2 to 10.",
3684 10,&prefs
.gui_decimal_places1
);
3686 prefs_register_uint_preference(gui_module
, "decimal_places2",
3687 "Count of decimal places for values of type 2",
3688 "Sets the count of decimal places for values of type 2."
3689 "Type 2 values are defined by authors."
3690 "Value can be in range 2 to 10.",
3691 10,&prefs
.gui_decimal_places2
);
3693 prefs_register_uint_preference(gui_module
, "decimal_places3",
3694 "Count of decimal places for values of type 3",
3695 "Sets the count of decimal places for values of type 3."
3696 "Type 3 values are defined by authors."
3697 "Value can be in range 2 to 10.",
3698 10,&prefs
.gui_decimal_places3
);
3700 prefs_register_bool_preference(gui_module
, "rtp_player_use_disk1",
3701 "RTP Player saves temporary data to disk",
3702 "If set to true, RTP Player saves temporary data to "
3703 "temp files on disk. If not set, it uses memory."
3704 "Every stream uses one file therefore you might touch "
3705 "OS limit for count of opened files."
3706 "When ui.rtp_player_use_disk2 is set to true too, it uses "
3707 " two files per RTP stream together."
3708 ,&prefs
.gui_rtp_player_use_disk1
);
3710 prefs_register_bool_preference(gui_module
, "rtp_player_use_disk2",
3711 "RTP Player saves temporary dictionary for data to disk",
3712 "If set to true, RTP Player saves temporary dictionary to "
3713 "temp files on disk. If not set, it uses memory."
3714 "Every stream uses one file therefore you might touch "
3715 "OS limit for count of opened files."
3716 "When ui.rtp_player_use_disk1 is set to true too, it uses "
3717 " two files per RTP stream."
3718 ,&prefs
.gui_rtp_player_use_disk2
);
3720 prefs_register_enum_preference(gui_layout_module
, "gui_packet_list_copy_format_options_for_keyboard_shortcut",
3721 "Allows text to be copied with selected format",
3722 "Allows text to be copied with selected format when copied via keyboard",
3723 (int*)(void*)(&prefs
.gui_packet_list_copy_format_options_for_keyboard_shortcut
),
3724 gui_packet_list_copy_format_options_for_keyboard_shortcut
, false);
3726 prefs_register_bool_preference(gui_layout_module
, "gui_packet_list_copy_text_with_aligned_columns",
3727 "Allows text to be copied with aligned columns",
3728 "Allows text to be copied with aligned columns when copied via menu or keyboard",
3729 &prefs
.gui_packet_list_copy_text_with_aligned_columns
);
3731 prefs_register_bool_preference(gui_layout_module
, "packet_list_show_related",
3732 "Show Related Packets",
3733 "Show related packet indicators in the first column",
3734 &prefs
.gui_packet_list_show_related
);
3736 prefs_register_bool_preference(gui_layout_module
, "packet_list_show_minimap",
3737 "Enable Intelligent Scroll Bar",
3738 "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
3739 &prefs
.gui_packet_list_show_minimap
);
3741 prefs_register_bool_preference(gui_module
, "packet_list_is_sortable",
3742 "Allow packet list to be sortable",
3743 "To prevent sorting by mistake (which can take some time to calculate), it can be disabled",
3744 &prefs
.gui_packet_list_sortable
);
3746 prefs_register_uint_preference(gui_module
, "packet_list_cached_rows_max",
3747 "Maximum cached rows",
3748 "Maximum number of rows that can be sorted by columns that require dissection. Increasing this increases memory consumption by caching column text",
3750 &prefs
.gui_packet_list_cached_rows_max
);
3752 prefs_register_bool_preference(gui_module
, "interfaces_show_hidden",
3753 "Show hidden interfaces",
3754 "Show all interfaces, including interfaces marked as hidden",
3755 &prefs
.gui_interfaces_show_hidden
);
3757 prefs_register_bool_preference(gui_module
, "interfaces_remote_display",
3758 "Show Remote interfaces",
3759 "Show remote interfaces in the interface selection",
3760 &prefs
.gui_interfaces_remote_display
);
3762 register_string_like_preference(gui_module
, "interfaces_hidden_types", "Hide interface types in list",
3763 "Hide the given interface types in the startup list.\n"
3764 "A comma-separated string of interface type values (e.g. 5,9).\n"
3773 "8 = External Capture,\n"
3775 &prefs
.gui_interfaces_hide_types
, PREF_STRING
, NULL
, true);
3777 prefs_register_bool_preference(gui_module
, "io_graph_automatic_update",
3778 "Enables automatic updates for IO Graph",
3779 "Enables automatic updates for IO Graph",
3780 &prefs
.gui_io_graph_automatic_update
);
3782 prefs_register_bool_preference(gui_module
, "io_graph_enable_legend",
3783 "Enables the legend of IO Graph",
3784 "Enables the legend of IO Graph",
3785 &prefs
.gui_io_graph_enable_legend
);
3787 prefs_register_bool_preference(gui_module
, "show_byteview_in_dialog",
3788 "Show the byte view in the packet details dialog",
3789 "Show the byte view in the packet details dialog",
3790 &prefs
.gui_packet_details_show_byteview
);
3793 * These are preferences that can be read/written using the
3794 * preference module API. These preferences still use their own
3795 * configuration screens for access, but this cuts down on the
3796 * preference "string compare list" in set_pref()
3798 console_module
= prefs_register_module(NULL
, "console", "Console",
3799 "Console logging and debugging output", NULL
, NULL
, false);
3801 prefs_register_obsolete_preference(console_module
, "log.level");
3803 prefs_register_bool_preference(console_module
, "incomplete_dissectors_check_debug",
3804 "Print debug line for incomplete dissectors",
3805 "Look for dissectors that left some bytes undecoded (debug)",
3806 &prefs
.incomplete_dissectors_check_debug
);
3808 /* Display filter Expressions
3809 * This used to be an array of individual fields that has now been
3810 * converted to a UAT. Just make it part of the GUI category even
3811 * though the name of the preference will never be seen in preference
3814 filter_expression_register_uat(gui_module
);
3817 * These are preferences that can be read/written using the
3818 * preference module API. These preferences still use their own
3819 * configuration screens for access, but this cuts down on the
3820 * preference "string compare list" in set_pref()
3822 capture_module
= prefs_register_module(NULL
, "capture", "Capture",
3823 "Capture preferences", NULL
, NULL
, false);
3824 /* Capture preferences don't affect dissection */
3825 prefs_set_module_effect_flags(capture_module
, PREF_EFFECT_CAPTURE
);
3827 register_string_like_preference(capture_module
, "device", "Default capture device",
3828 "Default capture device",
3829 &prefs
.capture_device
, PREF_STRING
, NULL
, false);
3831 register_string_like_preference(capture_module
, "devices_linktypes", "Interface link-layer header type",
3832 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
3833 &prefs
.capture_devices_linktypes
, PREF_STRING
, NULL
, false);
3835 register_string_like_preference(capture_module
, "devices_descr", "Interface descriptions",
3836 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
3837 &prefs
.capture_devices_descr
, PREF_STRING
, NULL
, false);
3839 register_string_like_preference(capture_module
, "devices_hide", "Hide interface",
3840 "Hide interface? (Ex: eth0,eth3,...)",
3841 &prefs
.capture_devices_hide
, PREF_STRING
, NULL
, false);
3843 register_string_like_preference(capture_module
, "devices_monitor_mode", "Capture in monitor mode",
3844 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
3845 &prefs
.capture_devices_monitor_mode
, PREF_STRING
, NULL
, false);
3847 register_string_like_preference(capture_module
, "devices_buffersize", "Interface buffer size",
3848 "Interface buffer size (Ex: en0(1),en1(143),...)",
3849 &prefs
.capture_devices_buffersize
, PREF_STRING
, NULL
, false);
3851 register_string_like_preference(capture_module
, "devices_snaplen", "Interface snap length",
3852 "Interface snap length (Ex: en0(65535),en1(1430),...)",
3853 &prefs
.capture_devices_snaplen
, PREF_STRING
, NULL
, false);
3855 register_string_like_preference(capture_module
, "devices_pmode", "Interface promiscuous mode",
3856 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
3857 &prefs
.capture_devices_pmode
, PREF_STRING
, NULL
, false);
3859 prefs_register_bool_preference(capture_module
, "prom_mode", "Capture in promiscuous mode",
3860 "Capture in promiscuous mode?", &prefs
.capture_prom_mode
);
3862 prefs_register_bool_preference(capture_module
, "monitor_mode", "Capture in monitor mode on 802.11 devices",
3863 "Capture in monitor mode on all 802.11 devices that support it?", &prefs
.capture_monitor_mode
);
3865 register_string_like_preference(capture_module
, "devices_filter", "Interface capture filter",
3866 "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
3867 &prefs
.capture_devices_filter
, PREF_STRING
, NULL
, false);
3869 prefs_register_bool_preference(capture_module
, "pcap_ng", "Capture in pcapng format",
3870 "Capture in pcapng format?", &prefs
.capture_pcap_ng
);
3872 prefs_register_bool_preference(capture_module
, "real_time_update", "Update packet list in real time during capture",
3873 "Update packet list in real time during capture?", &prefs
.capture_real_time
);
3875 prefs_register_uint_preference(capture_module
, "update_interval",
3876 "Capture update interval",
3877 "Capture update interval in ms",
3879 &prefs
.capture_update_interval
);
3881 prefs_register_bool_preference(capture_module
, "no_interface_load", "Don't load interfaces on startup",
3882 "Don't automatically load capture interfaces on startup", &prefs
.capture_no_interface_load
);
3884 prefs_register_bool_preference(capture_module
, "no_extcap", "Disable external capture interfaces",
3885 "Disable external capture modules (extcap)", &prefs
.capture_no_extcap
);
3887 prefs_register_obsolete_preference(capture_module
, "auto_scroll");
3889 prefs_register_bool_preference(capture_module
, "show_info", "Show capture information dialog while capturing",
3890 "Show capture information dialog while capturing?", &prefs
.capture_show_info
);
3892 prefs_register_obsolete_preference(capture_module
, "syntax_check_filter");
3894 custom_cbs
.free_cb
= capture_column_free_cb
;
3895 custom_cbs
.reset_cb
= capture_column_reset_cb
;
3896 custom_cbs
.set_cb
= capture_column_set_cb
;
3897 custom_cbs
.type_name_cb
= capture_column_type_name_cb
;
3898 custom_cbs
.type_description_cb
= capture_column_type_description_cb
;
3899 custom_cbs
.is_default_cb
= capture_column_is_default_cb
;
3900 custom_cbs
.to_str_cb
= capture_column_to_str_cb
;
3901 prefs_register_list_custom_preference(capture_module
, "columns", "Capture options dialog column list",
3902 "List of columns to be displayed", &custom_cbs
, capture_column_init_cb
, &prefs
.capture_columns
);
3904 /* Name Resolution */
3905 nameres_module
= prefs_register_module(NULL
, "nameres", "Name Resolution",
3906 "Name Resolution", "ChCustPreferencesSection.html#ChCustPrefsNameSection", addr_resolve_pref_apply
, true);
3907 addr_resolve_pref_init(nameres_module
);
3908 oid_pref_init(nameres_module
);
3909 maxmind_db_pref_init(nameres_module
);
3912 * None of these have any effect; we keep them as obsolete preferences
3913 * in order to avoid errors when reading older preference files.
3915 printing
= prefs_register_module(NULL
, "print", "Printing",
3916 "Printing", NULL
, NULL
, false);
3917 prefs_register_obsolete_preference(printing
, "format");
3918 prefs_register_obsolete_preference(printing
, "command");
3919 prefs_register_obsolete_preference(printing
, "file");
3922 codecs_module
= prefs_register_module(NULL
, "codecs", "Codecs",
3923 "Codecs", NULL
, NULL
, true);
3926 stats_module
= prefs_register_module(NULL
, "statistics", "Statistics",
3927 "Statistics", "ChCustPreferencesSection.html#_statistics", &stats_callback
, true);
3929 prefs_register_uint_preference(stats_module
, "update_interval",
3930 "Tap update interval in ms",
3931 "Determines time between tap updates",
3933 &prefs
.tap_update_interval
);
3935 prefs_register_uint_preference(stats_module
, "flow_graph_max_export_items",
3936 "Maximum Flow Graph items to export as image",
3937 "The maximum number of Flow Graph items (frames) "
3938 "to include when exporting the graph as an image. "
3939 "Note that some formats (e.g., JPEG) have inherent "
3940 "pixel limits and image viewers might be unable to "
3941 "handle very large images.",
3943 &prefs
.flow_graph_max_export_items
);
3945 prefs_register_bool_preference(stats_module
, "st_enable_burstinfo",
3946 "Enable the calculation of burst information",
3947 "If enabled burst rates will be calculated for statistics that use the stats_tree system. "
3948 "Burst rates are calculated over a much shorter time interval than the rate column.",
3949 &prefs
.st_enable_burstinfo
);
3951 prefs_register_bool_preference(stats_module
, "st_burst_showcount",
3952 "Show burst count for item rather than rate",
3953 "If selected the stats_tree statistics nodes will show the count of events "
3954 "within the burst window instead of a burst rate. Burst rate is calculated "
3955 "as number of events within burst window divided by the burst windown length.",
3956 &prefs
.st_burst_showcount
);
3958 prefs_register_uint_preference(stats_module
, "st_burst_resolution",
3959 "Burst rate resolution (ms)",
3960 "Sets the duration of the time interval into which events are grouped when calculating "
3961 "the burst rate. Higher resolution (smaller number) increases processing overhead.",
3962 10,&prefs
.st_burst_resolution
);
3964 prefs_register_uint_preference(stats_module
, "st_burst_windowlen",
3965 "Burst rate window size (ms)",
3966 "Sets the duration of the sliding window during which the burst rate is "
3967 "measured. Longer window relative to burst rate resolution increases "
3968 "processing overhead. Will be truncated to a multiple of burst resolution.",
3969 10,&prefs
.st_burst_windowlen
);
3971 prefs_register_enum_preference(stats_module
, "st_sort_defcolflag",
3972 "Default sort column for stats_tree stats",
3973 "Sets the default column by which stats based on the stats_tree "
3974 "system is sorted.",
3975 &prefs
.st_sort_defcolflag
, st_sort_col_vals
, false);
3977 prefs_register_bool_preference(stats_module
, "st_sort_defdescending",
3978 "Default stats_tree sort order is descending",
3979 "When selected, statistics based on the stats_tree system will by default "
3980 "be sorted in descending order.",
3981 &prefs
.st_sort_defdescending
);
3983 prefs_register_bool_preference(stats_module
, "st_sort_casesensitve",
3984 "Case sensitive sort of stats_tree item names",
3985 "When selected, the item/node names of statistics based on the stats_tree "
3986 "system will be sorted taking case into account. Else the case of the name "
3988 &prefs
.st_sort_casesensitve
);
3990 prefs_register_bool_preference(stats_module
, "st_sort_rng_nameonly",
3991 "Always sort 'range' nodes by name",
3992 "When selected, the stats_tree nodes representing a range of values "
3993 "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
3994 "node). Else range nodes are sorted by the same column as the rest of "
3996 &prefs
.st_sort_rng_nameonly
);
3998 prefs_register_bool_preference(stats_module
, "st_sort_rng_fixorder",
3999 "Always sort 'range' nodes in ascending order",
4000 "When selected, the stats_tree nodes representing a range of values "
4001 "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
4002 "the sort direction of the tree. Only effective if \"Always sort "
4003 "'range' nodes by name\" is also selected.",
4004 &prefs
.st_sort_rng_fixorder
);
4006 prefs_register_bool_preference(stats_module
, "st_sort_showfullname",
4007 "Display the full stats_tree plug-in name",
4008 "When selected, the full name (including menu path) of the stats_tree "
4009 "plug-in is show in windows. If cleared the plug-in name is shown "
4010 "without menu path (only the part of the name after last '/' character.)",
4011 &prefs
.st_sort_showfullname
);
4014 protocols_module
= prefs_register_module(NULL
, "protocols", "Protocols",
4015 "Protocols", "ChCustPreferencesSection.html#ChCustPrefsProtocolsSection", NULL
, true);
4017 prefs_register_bool_preference(protocols_module
, "display_hidden_proto_items",
4018 "Display hidden protocol items",
4019 "Display all hidden protocol items in the packet list.",
4020 &prefs
.display_hidden_proto_items
);
4022 prefs_register_bool_preference(protocols_module
, "display_byte_fields_with_spaces",
4023 "Display byte fields with a space character between bytes",
4024 "Display all byte fields with a space character between each byte in the packet list.",
4025 &prefs
.display_byte_fields_with_spaces
);
4028 * Note the -t / option only affects the display of the packet timestamp
4029 * in the default time column; this is for all other absolute times.
4031 prefs_register_enum_preference(protocols_module
, "display_abs_time_ascii",
4032 "Format absolute times like asctime",
4033 "When to format absolute times similar to asctime instead of ISO 8601, for backwards compatibility with older Wireshark.",
4034 (int*)&prefs
.display_abs_time_ascii
, abs_time_format_options
, false);
4036 prefs_register_bool_preference(protocols_module
, "enable_incomplete_dissectors_check",
4037 "Look for incomplete dissectors",
4038 "Look for dissectors that left some bytes undecoded.",
4039 &prefs
.enable_incomplete_dissectors_check
);
4041 prefs_register_bool_preference(protocols_module
, "strict_conversation_tracking_heuristics",
4042 "Enable stricter conversation tracking heuristics",
4043 "Protocols may use things like VLAN ID or interface ID to narrow the potential for duplicate conversations. "
4044 "Currently ICMP and ICMPv6 use this preference to add VLAN ID to conversation tracking, and IPv4 uses this preference to take VLAN ID into account during reassembly",
4045 &prefs
.strict_conversation_tracking_heuristics
);
4047 prefs_register_bool_preference(protocols_module
, "ignore_dup_frames",
4048 "Ignore duplicate frames",
4049 "Ignore frames that are exact duplicates of any previous frame.",
4050 &prefs
.ignore_dup_frames
);
4052 prefs_register_enum_preference(protocols_module
, "conversation_deinterlacing_key",
4053 "Deinterlacing conversations key",
4054 "Separate into different conversations frames that look like duplicates but have different Interface, MAC, or VLAN field values.",
4055 (int *)&prefs
.conversation_deinterlacing_key
, conv_deint_options
, false);
4057 prefs_register_uint_preference(protocols_module
, "ignore_dup_frames_cache_entries",
4058 "The max number of hashes to keep in memory for determining duplicates frames",
4059 "If \"Ignore duplicate frames\" is set, this setting sets the maximum number "
4060 "of cache entries to maintain. A 0 means no limit.",
4061 10, &prefs
.ignore_dup_frames_cache_entries
);
4064 /* Obsolete preferences
4065 * These "modules" were reorganized/renamed to correspond to their GUI
4066 * configuration screen within the preferences dialog
4069 /* taps is now part of the stats module */
4070 prefs_register_module(NULL
, "taps", "TAPS", "TAPS", NULL
, NULL
, false);
4071 /* packet_list is now part of the protocol (parent) module */
4072 prefs_register_module(NULL
, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL
, NULL
, false);
4073 /* stream is now part of the gui module */
4074 prefs_register_module(NULL
, "stream", "STREAM", "STREAM", NULL
, NULL
, false);
4078 /* Parse through a list of comma-separated, possibly quoted strings.
4079 Return a list of the string data. */
4081 prefs_get_string_list(const char *str
)
4083 enum { PRE_STRING
, IN_QUOT
, NOT_IN_QUOT
};
4085 int state
= PRE_STRING
, i
= 0;
4086 bool backslash
= false;
4087 unsigned char cur_c
;
4088 const size_t default_size
= 64;
4089 GString
*slstr
= NULL
;
4092 /* Allocate a buffer for the first string. */
4093 slstr
= g_string_sized_new(default_size
);
4097 if (cur_c
== '\0') {
4098 /* It's the end of the input, so it's the end of the string we
4099 were working on, and there's no more input. */
4100 if (state
== IN_QUOT
|| backslash
) {
4101 /* We were in the middle of a quoted string or backslash escape,
4102 and ran out of characters; that's an error. */
4103 g_string_free(slstr
, TRUE
);
4104 prefs_clear_string_list(sl
);
4108 sl
= g_list_append(sl
, g_string_free(slstr
, FALSE
));
4110 g_string_free(slstr
, TRUE
);
4113 if (cur_c
== '"' && !backslash
) {
4116 /* We hadn't yet started processing a string; this starts the
4117 string, and we're now quoting. */
4121 /* We're in the middle of a quoted string, and we saw a quotation
4122 mark; we're no longer quoting. */
4123 state
= NOT_IN_QUOT
;
4126 /* We're working on a string, but haven't seen a quote; we're
4133 } else if (cur_c
== '\\' && !backslash
) {
4134 /* We saw a backslash, and the previous character wasn't a
4135 backslash; escape the next character.
4137 This also means we've started a new string. */
4139 if (state
== PRE_STRING
)
4140 state
= NOT_IN_QUOT
;
4141 } else if (cur_c
== ',' && state
!= IN_QUOT
&& !backslash
) {
4142 /* We saw a comma, and we're not in the middle of a quoted string
4143 and it wasn't preceded by a backslash; it's the end of
4144 the string we were working on... */
4145 if (slstr
->len
> 0) {
4146 sl
= g_list_append(sl
, g_string_free(slstr
, FALSE
));
4147 slstr
= g_string_sized_new(default_size
);
4150 /* ...and the beginning of a new string. */
4152 } else if (!g_ascii_isspace(cur_c
) || state
!= PRE_STRING
) {
4153 /* Either this isn't a white-space character, or we've started a
4154 string (i.e., already seen a non-white-space character for that
4155 string and put it into the string).
4157 The character is to be put into the string; do so. */
4158 g_string_append_c(slstr
, cur_c
);
4160 /* If it was backslash-escaped, we're done with the backslash escape. */
4168 char *join_string_list(GList
*sl
)
4170 GString
*joined_str
= g_string_new("");
4173 unsigned item_count
= 0;
4175 cur
= first
= g_list_first(sl
);
4178 str
= (char *)cur
->data
;
4181 g_string_append_c(joined_str
, ',');
4183 if (item_count
% 2) {
4184 /* Wrap the line. */
4185 g_string_append(joined_str
, "\n\t");
4187 g_string_append_c(joined_str
, ' ');
4189 g_string_append_c(joined_str
, '"');
4191 gunichar uc
= g_utf8_get_char (str
);
4193 if (uc
== '"' || uc
== '\\')
4194 g_string_append_c(joined_str
, '\\');
4196 if (g_unichar_isprint(uc
))
4197 g_string_append_unichar (joined_str
, uc
);
4199 str
= g_utf8_next_char (str
);
4202 g_string_append_c(joined_str
, '"');
4206 return g_string_free(joined_str
, FALSE
);
4210 prefs_clear_string_list(GList
*sl
)
4212 g_list_free_full(sl
, g_free
);
4216 * Takes a string, a pointer to an array of "enum_val_t"s, and a default int
4218 * The array must be terminated by an entry with a null "name" string.
4220 * If the string matches a "name" string in an entry, the value from that
4221 * entry is returned.
4223 * Otherwise, if a string matches a "description" string in an entry, the
4224 * value from that entry is returned; we do that for backwards compatibility,
4225 * as we used to have only a "name" string that was used both for command-line
4226 * and configuration-file values and in the GUI (which meant either that
4227 * the GUI had what might be somewhat cryptic values to select from or that
4228 * the "-o" flag took long strings, often with spaces in them).
4230 * Otherwise, the default value that was passed as the third argument is
4234 find_val_for_string(const char *needle
, const enum_val_t
*haystack
,
4239 for (i
= 0; haystack
[i
].name
!= NULL
; i
++) {
4240 if (g_ascii_strcasecmp(needle
, haystack
[i
].name
) == 0) {
4241 return haystack
[i
].value
;
4244 for (i
= 0; haystack
[i
].name
!= NULL
; i
++) {
4245 if (g_ascii_strcasecmp(needle
, haystack
[i
].description
) == 0) {
4246 return haystack
[i
].value
;
4249 return default_value
;
4252 /* Preferences file format:
4253 * - Configuration directives start at the beginning of the line, and
4254 * are terminated with a colon.
4255 * - Directives can be continued on the next line by preceding them with
4260 # This is a comment line
4262 print.file: /a/very/long/path/
4267 /* Initialize non-dissector preferences to wired-in default values Called
4268 * at program startup and any time the profile changes. (The dissector
4269 * preferences are assumed to be set to those values by the dissectors.)
4270 * They may be overridden by the global preferences file or the user's
4276 if (prefs_initialized
)
4282 * Ensure the "global" preferences have been initialized so the
4283 * preference API has the proper default values to work from
4287 prefs_register_modules();
4289 prefs_initialized
= true;
4293 * Initialize non-dissector preferences used by the "register preference" API
4294 * to default values so the default values can be used when registered.
4296 * String, filename, and directory preferences will be g_freed so they must
4300 pre_init_prefs(void)
4305 static const char *col_fmt_packets
[] = {
4306 "No.", "%m", "Time", "%t",
4307 "Source", "%s", "Destination", "%d",
4308 "Protocol", "%p", "Length", "%L",
4310 static const char **col_fmt
= col_fmt_packets
;
4313 if (!is_packet_configuration_namespace()) {
4314 static const char *col_fmt_logs
[] = {
4317 "Event name", "%Cus:sysdig.event_name:0:R",
4318 "Dir", "%Cus:evt.dir:0:R",
4319 "Proc Name", "%Cus:proc.name:0:R",
4320 "PID", "%Cus:proc.pid:0:R",
4321 "TID", "%Cus:thread.tid:0:R",
4322 "FD", "%Cus:fd.num:0:R",
4323 "FD Name", "%Cus:fd.name:0:R",
4324 "Container Name", "%Cus:container.name:0:R",
4325 "Arguments", "%Cus:evt.args:0:R",
4328 col_fmt
= col_fmt_logs
;
4332 prefs
.restore_filter_after_following_stream
= false;
4333 prefs
.gui_toolbar_main_style
= TB_STYLE_ICONS
;
4334 /* We try to find the best font in the Qt code */
4335 g_free(prefs
.gui_font_name
);
4336 prefs
.gui_font_name
= g_strdup("");
4337 prefs
.gui_active_fg
.red
= 0;
4338 prefs
.gui_active_fg
.green
= 0;
4339 prefs
.gui_active_fg
.blue
= 0;
4340 prefs
.gui_active_bg
.red
= 52223;
4341 prefs
.gui_active_bg
.green
= 59647;
4342 prefs
.gui_active_bg
.blue
= 65535;
4343 prefs
.gui_active_style
= COLOR_STYLE_DEFAULT
;
4344 prefs
.gui_inactive_fg
.red
= 0;
4345 prefs
.gui_inactive_fg
.green
= 0;
4346 prefs
.gui_inactive_fg
.blue
= 0;
4347 prefs
.gui_inactive_bg
.red
= 61439;
4348 prefs
.gui_inactive_bg
.green
= 61439;
4349 prefs
.gui_inactive_bg
.blue
= 61439;
4350 prefs
.gui_inactive_style
= COLOR_STYLE_DEFAULT
;
4351 prefs
.gui_marked_fg
.red
= 65535;
4352 prefs
.gui_marked_fg
.green
= 65535;
4353 prefs
.gui_marked_fg
.blue
= 65535;
4354 prefs
.gui_marked_bg
.red
= 0;
4355 prefs
.gui_marked_bg
.green
= 8224;
4356 prefs
.gui_marked_bg
.blue
= 10794;
4357 prefs
.gui_ignored_fg
.red
= 32767;
4358 prefs
.gui_ignored_fg
.green
= 32767;
4359 prefs
.gui_ignored_fg
.blue
= 32767;
4360 prefs
.gui_ignored_bg
.red
= 65535;
4361 prefs
.gui_ignored_bg
.green
= 65535;
4362 prefs
.gui_ignored_bg
.blue
= 65535;
4363 g_free(prefs
.gui_colorized_fg
);
4364 prefs
.gui_colorized_fg
= g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
4365 g_free(prefs
.gui_colorized_bg
);
4366 prefs
.gui_colorized_bg
= g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
4367 prefs
.st_client_fg
.red
= 32767;
4368 prefs
.st_client_fg
.green
= 0;
4369 prefs
.st_client_fg
.blue
= 0;
4370 prefs
.st_client_bg
.red
= 64507;
4371 prefs
.st_client_bg
.green
= 60909;
4372 prefs
.st_client_bg
.blue
= 60909;
4373 prefs
.st_server_fg
.red
= 0;
4374 prefs
.st_server_fg
.green
= 0;
4375 prefs
.st_server_fg
.blue
= 32767;
4376 prefs
.st_server_bg
.red
= 60909;
4377 prefs
.st_server_bg
.green
= 60909;
4378 prefs
.st_server_bg
.blue
= 64507;
4380 if (gui_theme_is_dark
) {
4381 // Green, red and yellow with HSV V = 84
4382 prefs
.gui_text_valid
.red
= 0x0000; /* dark green */
4383 prefs
.gui_text_valid
.green
= 0x66ff;
4384 prefs
.gui_text_valid
.blue
= 0x0000;
4385 prefs
.gui_text_invalid
.red
= 0x66FF; /* dark red */
4386 prefs
.gui_text_invalid
.green
= 0x0000;
4387 prefs
.gui_text_invalid
.blue
= 0x0000;
4388 prefs
.gui_text_deprecated
.red
= 0x66FF; /* dark yellow / olive */
4389 prefs
.gui_text_deprecated
.green
= 0x66FF;
4390 prefs
.gui_text_deprecated
.blue
= 0x0000;
4392 // Green, red and yellow with HSV V = 20
4393 prefs
.gui_text_valid
.red
= 0xAFFF; /* light green */
4394 prefs
.gui_text_valid
.green
= 0xFFFF;
4395 prefs
.gui_text_valid
.blue
= 0xAFFF;
4396 prefs
.gui_text_invalid
.red
= 0xFFFF; /* light red */
4397 prefs
.gui_text_invalid
.green
= 0xAFFF;
4398 prefs
.gui_text_invalid
.blue
= 0xAFFF;
4399 prefs
.gui_text_deprecated
.red
= 0xFFFF; /* light yellow */
4400 prefs
.gui_text_deprecated
.green
= 0xFFFF;
4401 prefs
.gui_text_deprecated
.blue
= 0xAFFF;
4404 prefs
.gui_geometry_save_position
= true;
4405 prefs
.gui_geometry_save_size
= true;
4406 prefs
.gui_geometry_save_maximized
= true;
4407 prefs
.gui_fileopen_style
= FO_STYLE_LAST_OPENED
;
4408 prefs
.gui_recent_df_entries_max
= 10;
4409 prefs
.gui_recent_files_count_max
= 10;
4410 g_free(prefs
.gui_fileopen_dir
);
4411 prefs
.gui_fileopen_dir
= g_strdup(get_persdatafile_dir());
4412 prefs
.gui_fileopen_preview
= 3;
4413 g_free(prefs
.gui_tlskeylog_command
);
4414 prefs
.gui_tlskeylog_command
= g_strdup("");
4415 prefs
.gui_ask_unsaved
= true;
4416 prefs
.gui_autocomplete_filter
= true;
4417 prefs
.gui_find_wrap
= true;
4418 prefs
.gui_update_enabled
= true;
4419 prefs
.gui_update_channel
= UPDATE_CHANNEL_STABLE
;
4420 prefs
.gui_update_interval
= 60*60*24; /* Seconds */
4421 prefs
.gui_debounce_timer
= 400; /* milliseconds */
4422 g_free(prefs
.gui_window_title
);
4423 prefs
.gui_window_title
= g_strdup("");
4424 g_free(prefs
.gui_prepend_window_title
);
4425 prefs
.gui_prepend_window_title
= g_strdup("");
4426 g_free(prefs
.gui_start_title
);
4427 prefs
.gui_start_title
= g_strdup("The World's Most Popular Network Protocol Analyzer");
4428 prefs
.gui_version_placement
= version_both
;
4429 prefs
.gui_welcome_page_show_recent
= true;
4430 prefs
.gui_layout_type
= layout_type_2
;
4431 prefs
.gui_layout_content_1
= layout_pane_content_plist
;
4432 prefs
.gui_layout_content_2
= layout_pane_content_pdetails
;
4433 prefs
.gui_layout_content_3
= layout_pane_content_pbytes
;
4434 prefs
.gui_packet_list_elide_mode
= ELIDE_RIGHT
;
4435 prefs
.gui_packet_list_copy_format_options_for_keyboard_shortcut
= COPY_FORMAT_TEXT
;
4436 prefs
.gui_packet_list_copy_text_with_aligned_columns
= false;
4437 prefs
.gui_packet_list_show_related
= true;
4438 prefs
.gui_packet_list_show_minimap
= true;
4439 prefs
.gui_packet_list_sortable
= true;
4440 prefs
.gui_packet_list_cached_rows_max
= 10000;
4441 g_free (prefs
.gui_interfaces_hide_types
);
4442 prefs
.gui_interfaces_hide_types
= g_strdup("");
4443 prefs
.gui_interfaces_show_hidden
= false;
4444 prefs
.gui_interfaces_remote_display
= true;
4445 prefs
.gui_packet_list_separator
= false;
4446 prefs
.gui_packet_header_column_definition
= true;
4447 prefs
.gui_packet_list_hover_style
= true;
4448 prefs
.gui_show_selected_packet
= false;
4449 prefs
.gui_show_file_load_time
= false;
4450 prefs
.gui_max_export_objects
= 1000;
4451 prefs
.gui_max_tree_items
= 1 * 1000 * 1000;
4452 prefs
.gui_max_tree_depth
= 5 * 100;
4453 prefs
.gui_decimal_places1
= DEF_GUI_DECIMAL_PLACES1
;
4454 prefs
.gui_decimal_places2
= DEF_GUI_DECIMAL_PLACES2
;
4455 prefs
.gui_decimal_places3
= DEF_GUI_DECIMAL_PLACES3
;
4457 if (prefs
.col_list
) {
4458 free_col_info(prefs
.col_list
);
4459 prefs
.col_list
= NULL
;
4461 for (i
= 0; i
< num_cols
; i
++) {
4462 cfmt
= g_new0(fmt_data
,1);
4463 cfmt
->title
= g_strdup(col_fmt
[i
* 2]);
4464 cfmt
->visible
= true;
4465 cfmt
->display
= COLUMN_DISPLAY_STRINGS
;
4466 parse_column_format(cfmt
, col_fmt
[(i
* 2) + 1]);
4467 prefs
.col_list
= g_list_append(prefs
.col_list
, cfmt
);
4469 prefs
.num_cols
= num_cols
;
4471 /* set the default values for the capture dialog box */
4472 prefs
.capture_prom_mode
= true;
4473 prefs
.capture_monitor_mode
= false;
4474 prefs
.capture_pcap_ng
= true;
4475 prefs
.capture_real_time
= true;
4476 prefs
.capture_update_interval
= DEFAULT_UPDATE_INTERVAL
;
4477 prefs
.capture_no_extcap
= false;
4478 prefs
.capture_show_info
= false;
4480 if (!prefs
.capture_columns
) {
4481 /* First time through */
4482 for (i
= 0; i
< num_capture_cols
; i
++) {
4483 col_name
= g_strdup(capture_cols
[i
]);
4484 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
4488 /* set the default values for the tap/statistics dialog box */
4489 prefs
.tap_update_interval
= TAP_UPDATE_DEFAULT_INTERVAL
;
4490 prefs
.flow_graph_max_export_items
= 1000;
4491 prefs
.st_enable_burstinfo
= true;
4492 prefs
.st_burst_showcount
= false;
4493 prefs
.st_burst_resolution
= ST_DEF_BURSTRES
;
4494 prefs
.st_burst_windowlen
= ST_DEF_BURSTLEN
;
4495 prefs
.st_sort_casesensitve
= true;
4496 prefs
.st_sort_rng_fixorder
= true;
4497 prefs
.st_sort_rng_nameonly
= true;
4498 prefs
.st_sort_defcolflag
= ST_SORT_COL_COUNT
;
4499 prefs
.st_sort_defdescending
= true;
4500 prefs
.st_sort_showfullname
= false;
4503 prefs
.display_hidden_proto_items
= false;
4504 prefs
.display_byte_fields_with_spaces
= false;
4505 prefs
.display_abs_time_ascii
= ABS_TIME_ASCII_TREE
;
4506 prefs
.ignore_dup_frames
= false;
4507 prefs
.ignore_dup_frames_cache_entries
= 10000;
4509 /* set the default values for the io graph dialog */
4510 prefs
.gui_io_graph_automatic_update
= true;
4511 prefs
.gui_io_graph_enable_legend
= true;
4513 /* set the default values for the packet dialog */
4514 prefs
.gui_packet_dialog_layout
= layout_vertical
;
4515 prefs
.gui_packet_details_show_byteview
= true;
4519 * Reset a single dissector preference.
4522 reset_pref(pref_t
*pref
)
4530 * This preference is no longer supported; it's not a
4531 * real preference, so we don't reset it (i.e., we
4532 * treat it as if it weren't found in the list of
4533 * preferences, and we weren't called in the first place).
4535 if (IS_PREF_OBSOLETE(type
))
4538 RESET_PREF_OBSOLETE(type
);
4543 *pref
->varp
.uint
= pref
->default_val
.uint
;
4547 *pref
->varp
.boolp
= pref
->default_val
.boolval
;
4551 case PREF_PROTO_TCP_SNDAMB_ENUM
:
4552 *pref
->varp
.enump
= pref
->default_val
.enumval
;
4556 case PREF_SAVE_FILENAME
:
4557 case PREF_OPEN_FILENAME
:
4560 case PREF_DISSECTOR
:
4561 reset_string_like_preference(pref
);
4565 case PREF_DECODE_AS_RANGE
:
4566 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
4567 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->default_val
.range
);
4570 case PREF_STATIC_TEXT
:
4576 *pref
->varp
.colorp
= pref
->default_val
.color
;
4580 pref
->custom_cbs
.reset_cb(pref
);
4586 reset_pref_cb(void *data
, void *user_data
)
4588 pref_t
*pref
= (pref_t
*) data
;
4589 module_t
*module
= (module_t
*)user_data
;
4591 if (pref
&& (pref
->type
== PREF_RANGE
|| pref
->type
== PREF_DECODE_AS_RANGE
)) {
4593 * Some dissectors expect the range (returned via prefs_get_range_value)
4594 * to remain valid if it has not changed. If it did change, then we
4595 * should set "prefs_changed_flags" to ensure that the preference apply
4596 * callback is invoked. That callback will notify dissectors that it
4597 * should no longer assume the range to be valid.
4599 if (ranges_are_equal(*pref
->varp
.range
, pref
->default_val
.range
)) {
4600 /* Optimization: do not invoke apply callback if nothing changed. */
4603 module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
4609 * Reset all preferences for a module.
4612 reset_module_prefs(const void *key _U_
, void *value
, void *data _U_
)
4614 module_t
*module
= (module_t
*)value
;
4615 g_list_foreach(module
->prefs
, reset_pref_cb
, module
);
4619 /* Reset preferences */
4623 prefs_initialized
= false;
4624 g_free(prefs
.saved_at_version
);
4625 prefs
.saved_at_version
= NULL
;
4628 * Unload all UAT preferences.
4633 * Unload any loaded MIBs.
4638 * Reset the non-dissector preferences.
4643 * Reset the non-UAT dissector preferences.
4645 wmem_tree_foreach(prefs_modules
, reset_module_prefs
, NULL
);
4654 DWORD data_size
= sizeof(DWORD
);
4657 ret
= RegOpenKeyExA(HKEY_CURRENT_USER
, REG_HKCU_WIRESHARK_KEY
, 0, KEY_READ
, &hTestKey
);
4658 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_FILE_NOT_FOUND
) {
4659 ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY
": 0x%lx", ret
);
4663 ret
= RegQueryValueExA(hTestKey
, LOG_HKCU_CONSOLE_OPEN
, NULL
, NULL
, (LPBYTE
)&data
, &data_size
);
4664 if (ret
== ERROR_SUCCESS
) {
4665 ws_log_console_open
= (ws_log_console_open_pref
)data
;
4666 ws_noisy("Got "LOG_HKCU_CONSOLE_OPEN
" from Windows registry: %d", ws_log_console_open
);
4668 else if (ret
!= ERROR_FILE_NOT_FOUND
) {
4669 ws_noisy("Error reading registry key "LOG_HKCU_CONSOLE_OPEN
": 0x%lx", ret
);
4672 RegCloseKey(hTestKey
);
4677 prefs_read_module(const char *module
)
4683 module_t
*target_module
= prefs_find_module(module
);
4684 if (!target_module
) {
4688 /* Construct the pathname of the user's preferences file for the module. */
4689 char *pf_name
= wmem_strdup_printf(NULL
, "%s.cfg", module
);
4690 pf_path
= get_persconffile_path(pf_name
, true);
4691 wmem_free(NULL
, pf_name
);
4693 /* Read the user's module preferences file, if it exists and is not a dir. */
4694 if (!test_for_regular_file(pf_path
) || ((pf
= ws_fopen(pf_path
, "r")) == NULL
)) {
4696 /* Fall back to the user's generic preferences file. */
4697 pf_path
= get_persconffile_path(PF_NAME
, true);
4698 pf
= ws_fopen(pf_path
, "r");
4702 /* We succeeded in opening it; read it. */
4703 err
= read_prefs_file(pf_path
, pf
, set_pref
, target_module
);
4705 /* We had an error reading the file; report it. */
4706 report_warning("Error reading your preferences file \"%s\": %s.",
4707 pf_path
, g_strerror(err
));
4712 /* We failed to open it. If we failed for some reason other than
4713 "it doesn't exist", return the errno and the pathname, so our
4714 caller can report the error. */
4715 if (errno
!= ENOENT
) {
4716 report_warning("Can't open your preferences file \"%s\": %s.",
4717 pf_path
, g_strerror(errno
));
4725 /* Read the preferences file, fill in "prefs", and return a pointer to it.
4727 If we got an error (other than "it doesn't exist") we report it through
4736 /* clean up libsmi structures before reading prefs */
4746 * If we don't already have the pathname of the global preferences
4747 * file, construct it. Then, in either case, try to open the file.
4749 if (gpf_path
== NULL
) {
4751 * We don't have the path; try the new path first, and, if that
4752 * file doesn't exist, try the old path.
4754 gpf_path
= get_datafile_path(PF_NAME
);
4755 if ((pf
= ws_fopen(gpf_path
, "r")) == NULL
&& errno
== ENOENT
) {
4757 * It doesn't exist by the new name; try the old name.
4760 gpf_path
= get_datafile_path(OLD_GPF_NAME
);
4761 pf
= ws_fopen(gpf_path
, "r");
4765 * We have the path; try it.
4767 pf
= ws_fopen(gpf_path
, "r");
4771 * If we were able to open the file, read it.
4772 * XXX - if it failed for a reason other than "it doesn't exist",
4777 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
4780 mgcp_tcp_port_count
= 0;
4781 mgcp_udp_port_count
= 0;
4783 /* We succeeded in opening it; read it. */
4784 err
= read_prefs_file(gpf_path
, pf
, set_pref
, NULL
);
4786 /* We had an error reading the file; report it. */
4787 report_warning("Error reading global preferences file \"%s\": %s.",
4788 gpf_path
, g_strerror(err
));
4792 /* We failed to open it. If we failed for some reason other than
4793 "it doesn't exist", report the error. */
4794 if (errno
!= ENOENT
) {
4796 report_warning("Can't open global preferences file \"%s\": %s.",
4797 gpf_path
, g_strerror(errno
));
4802 /* Construct the pathname of the user's preferences file. */
4803 pf_path
= get_persconffile_path(PF_NAME
, true);
4805 /* Read the user's preferences file, if it exists. */
4806 if ((pf
= ws_fopen(pf_path
, "r")) != NULL
) {
4808 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
4811 mgcp_tcp_port_count
= 0;
4812 mgcp_udp_port_count
= 0;
4814 /* We succeeded in opening it; read it. */
4815 err
= read_prefs_file(pf_path
, pf
, set_pref
, NULL
);
4817 /* We had an error reading the file; report it. */
4818 report_warning("Error reading your preferences file \"%s\": %s.",
4819 pf_path
, g_strerror(err
));
4824 /* We failed to open it. If we failed for some reason other than
4825 "it doesn't exist", return the errno and the pathname, so our
4826 caller can report the error. */
4827 if (errno
!= ENOENT
) {
4828 report_warning("Can't open your preferences file \"%s\": %s.",
4829 pf_path
, g_strerror(errno
));
4834 /* load SMI modules if needed */
4840 /* read the preferences file (or similar) and call the callback
4841 * function to set each key/value pair found */
4843 read_prefs_file(const char *pf_path
, FILE *pf
,
4844 pref_set_pair_cb pref_set_pair_fct
, void *private_data
)
4847 START
, /* beginning of a line */
4848 IN_VAR
, /* processing key name */
4849 PRE_VAL
, /* finished processing key name, skipping white space before value */
4850 IN_VAL
, /* processing value */
4851 IN_SKIP
/* skipping to the end of the line */
4856 bool got_val
= false;
4857 int fline
= 1, pline
= 1;
4858 char hint
[] = "(save preferences to remove this warning)";
4861 cur_val
= g_string_new("");
4862 cur_var
= g_string_new("");
4864 /* Try to read in the profile name in the first line of the preferences file. */
4865 if (fscanf(pf
, "# Configuration file for %127[^\r\n]", ver
) == 1) {
4866 /* Assume trailing period and remove it */
4867 g_free(prefs
.saved_at_version
);
4868 prefs
.saved_at_version
= g_strndup(ver
, strlen(ver
) - 1);
4872 while ((got_c
= ws_getc_unlocked(pf
)) != EOF
) {
4873 if (got_c
== '\r') {
4874 /* Treat CR-LF at the end of a line like LF, so that if we're reading
4875 * a Windows-format file on UN*X, we handle it the same way we'd handle
4876 * a UN*X-format file. */
4877 got_c
= ws_getc_unlocked(pf
);
4880 if (got_c
!= '\n') {
4881 /* Put back the character after the CR, and process the CR normally. */
4886 if (got_c
== '\n') {
4894 if (g_ascii_isalnum(got_c
)) {
4895 if (cur_var
->len
> 0) {
4897 if (cur_val
->len
> 0) {
4898 if (cur_val
->str
[cur_val
->len
-1] == ',') {
4900 * If the pref has a trailing comma, eliminate it.
4902 cur_val
->str
[cur_val
->len
-1] = '\0';
4903 ws_warning("%s line %d: trailing comma in \"%s\" %s", pf_path
, pline
, cur_var
->str
, hint
);
4906 /* Call the routine to set the preference; it will parse
4907 the value as appropriate.
4909 Since we're reading a file, rather than processing
4910 explicit user input, for range preferences, silently
4911 lower values in excess of the range's maximum, rather
4912 than reporting errors and failing. */
4913 switch (pref_set_pair_fct(cur_var
->str
, cur_val
->str
, private_data
, false)) {
4918 case PREFS_SET_SYNTAX_ERR
:
4919 report_warning("Syntax error in preference \"%s\" at line %d of\n%s %s",
4920 cur_var
->str
, pline
, pf_path
, hint
);
4923 case PREFS_SET_NO_SUCH_PREF
:
4924 ws_warning("No such preference \"%s\" at line %d of\n%s %s",
4925 cur_var
->str
, pline
, pf_path
, hint
);
4926 prefs
.unknown_prefs
= true;
4929 case PREFS_SET_OBSOLETE
:
4931 * If an attempt is made to save the
4932 * preferences, a popup warning will be
4933 * displayed stating that obsolete prefs
4934 * have been detected and the user will
4935 * be given the opportunity to save these
4936 * prefs under a different profile name.
4937 * The prefs in question need to be listed
4938 * in the console window so that the
4939 * user can make an informed choice.
4941 ws_warning("Obsolete preference \"%s\" at line %d of\n%s %s",
4942 cur_var
->str
, pline
, pf_path
, hint
);
4943 prefs
.unknown_prefs
= true;
4947 ws_warning("Incomplete preference at line %d: of\n%s %s", pline
, pf_path
, hint
);
4952 g_string_truncate(cur_var
, 0);
4953 g_string_append_c(cur_var
, (char) got_c
);
4955 } else if (g_ascii_isspace(got_c
) && cur_var
->len
> 0 && got_val
) {
4957 } else if (got_c
== '#') {
4960 ws_warning("Malformed preference at line %d of\n%s %s", fline
, pf_path
, hint
);
4965 g_string_append_c(cur_var
, (char) got_c
);
4967 /* This is a colon (':') */
4969 g_string_truncate(cur_val
, 0);
4971 * Set got_val to true to accommodate prefs such as
4972 * "gui.fileopen.dir" that do not require a value.
4978 if (!g_ascii_isspace(got_c
)) {
4980 g_string_append_c(cur_val
, (char) got_c
);
4984 g_string_append_c(cur_val
, (char) got_c
);
4990 if (cur_var
->len
> 0) {
4992 /* Call the routine to set the preference; it will parse
4993 the value as appropriate.
4995 Since we're reading a file, rather than processing
4996 explicit user input, for range preferences, silently
4997 lower values in excess of the range's maximum, rather
4998 than reporting errors and failing. */
4999 switch (pref_set_pair_fct(cur_var
->str
, cur_val
->str
, private_data
, false)) {
5004 case PREFS_SET_SYNTAX_ERR
:
5005 ws_warning("Syntax error in preference %s at line %d of\n%s %s",
5006 cur_var
->str
, pline
, pf_path
, hint
);
5009 case PREFS_SET_NO_SUCH_PREF
:
5010 ws_warning("No such preference \"%s\" at line %d of\n%s %s",
5011 cur_var
->str
, pline
, pf_path
, hint
);
5012 prefs
.unknown_prefs
= true;
5015 case PREFS_SET_OBSOLETE
:
5016 prefs
.unknown_prefs
= true;
5020 ws_warning("Incomplete preference at line %d of\n%s %s",
5021 pline
, pf_path
, hint
);
5025 g_string_free(cur_val
, TRUE
);
5026 g_string_free(cur_var
, TRUE
);
5035 * If we were handed a preference starting with "uat:", try to turn it into
5036 * a valid uat entry.
5039 prefs_set_uat_pref(char *uat_entry
, char **errmsg
) {
5044 colonp
= strchr(uat_entry
, ':');
5052 * Skip over any white space (there probably won't be any, but
5053 * as we allow it in the preferences file, we might as well
5056 while (g_ascii_isspace(*p
))
5060 * Put the colon back, so if our caller uses, in an
5061 * error message, the string they passed us, the message
5068 uat
= uat_find(uat_entry
);
5071 *errmsg
= g_strdup("Unknown preference");
5075 ret
= uat_load_str(uat
, p
, errmsg
);
5080 * Given a string of the form "<pref name>:<pref value>", as might appear
5081 * as an argument to a "-o" option, parse it and set the preference in
5082 * question. Return an indication of whether it succeeded or failed
5086 prefs_set_pref(char *prefarg
, char **errmsg
)
5089 prefs_set_pref_e ret
;
5092 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
5093 * seen to values that keep us from trying to interpret them
5094 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
5095 * as, from the command line, we have no way of guessing which
5096 * the user had in mind.
5098 mgcp_tcp_port_count
= -1;
5099 mgcp_udp_port_count
= -1;
5103 colonp
= strchr(prefarg
, ':');
5105 return PREFS_SET_SYNTAX_ERR
;
5111 * Skip over any white space (there probably won't be any, but
5112 * as we allow it in the preferences file, we might as well
5115 while (g_ascii_isspace(*p
))
5117 /* The empty string is a legal value for range preferences (PREF_RANGE,
5118 * PREF_DECODE_AS_RANGE), and string-like preferences (PREF_STRING,
5119 * PREF_SAVE_FILENAME, PREF_OPEN_FILENAME, PREF_DIRNAME), indeed often
5120 * not just useful but the default. A user might have a value saved
5121 * to their preference file but want to override it to default behavior.
5122 * Individual preference handlers of those types should be prepared to
5123 * deal with an empty string. For other types, it is up to set_pref() to
5124 * test for the empty string and set PREFS_SET_SYNTAX_ERROR there.
5126 if (strcmp(prefarg
, "uat")) {
5127 ret
= set_pref(prefarg
, p
, NULL
, true);
5129 ret
= prefs_set_uat_pref(p
, errmsg
) ? PREFS_SET_OK
: PREFS_SET_SYNTAX_ERR
;
5131 *colonp
= ':'; /* put the colon back */
5135 unsigned prefs_get_uint_value_real(pref_t
*pref
, pref_source_t source
)
5140 return pref
->default_val
.uint
;
5142 return pref
->stashed_val
.uint
;
5144 return *pref
->varp
.uint
;
5146 ws_assert_not_reached();
5153 unsigned prefs_get_uint_value(const char *module_name
, const char* pref_name
)
5155 pref_t
*pref
= prefs_find_preference(prefs_find_module(module_name
), pref_name
);
5159 return prefs_get_uint_value_real(pref
, pref_current
);
5162 char* prefs_get_password_value(pref_t
*pref
, pref_source_t source
)
5164 return prefs_get_string_value(pref
, source
);
5168 unsigned int prefs_set_uint_value(pref_t
*pref
, unsigned value
, pref_source_t source
)
5170 unsigned int changed
= 0;
5174 if (pref
->default_val
.uint
!= value
) {
5175 pref
->default_val
.uint
= value
;
5176 changed
= prefs_get_effect_flags(pref
);
5180 if (pref
->stashed_val
.uint
!= value
) {
5181 pref
->stashed_val
.uint
= value
;
5182 changed
= prefs_get_effect_flags(pref
);
5186 if (*pref
->varp
.uint
!= value
) {
5187 *pref
->varp
.uint
= value
;
5188 changed
= prefs_get_effect_flags(pref
);
5192 ws_assert_not_reached();
5200 * For use by UI code that sets preferences.
5203 prefs_set_password_value(pref_t
*pref
, const char* value
, pref_source_t source
)
5205 return prefs_set_string_value(pref
, value
, source
);
5209 unsigned prefs_get_uint_base(pref_t
*pref
)
5211 return pref
->info
.base
;
5215 * Returns true if the given device is hidden
5218 prefs_is_capture_device_hidden(const char *name
)
5220 char *tok
, *devices
;
5223 if (prefs
.capture_devices_hide
&& name
) {
5224 devices
= g_strdup (prefs
.capture_devices_hide
);
5225 len
= strlen (name
);
5226 for (tok
= strtok (devices
, ","); tok
; tok
= strtok(NULL
, ",")) {
5227 if (strlen (tok
) == len
&& strcmp (name
, tok
) == 0) {
5239 * Returns true if the given column is visible (not hidden)
5242 prefs_is_column_visible(const char *cols_hidden
, int col
)
5244 char *tok
, *cols
, *p
;
5248 * Do we have a list of hidden columns?
5252 * Yes - check the column against each of the ones in the
5255 cols
= g_strdup(cols_hidden
);
5256 for (tok
= strtok(cols
, ","); tok
; tok
= strtok(NULL
, ",")) {
5257 tok
= g_strstrip(tok
);
5259 cidx
= (int)strtol(tok
, &p
, 10);
5260 if (p
== tok
|| *p
!= '\0') {
5267 * OK, they match, so it's one of the hidden fields,
5268 * hence not visible.
5277 * No - either there are no hidden columns or this isn't one
5278 * of them - so it is visible.
5284 * Returns true if the given column is visible (not hidden)
5287 prefs_is_column_fmt_visible(const char *cols_hidden
, fmt_data
*cfmt
)
5290 fmt_data cfmt_hidden
;
5293 * Do we have a list of hidden columns?
5297 * Yes - check the column against each of the ones in the
5300 cols
= g_strdup(cols_hidden
);
5301 for (tok
= strtok(cols
, ","); tok
; tok
= strtok(NULL
, ",")) {
5302 tok
= g_strstrip(tok
);
5305 * Parse this column format.
5307 if (!parse_column_format(&cfmt_hidden
, tok
)) {
5309 * It's not valid; ignore it.
5315 * Does it match the column?
5317 if (cfmt
->fmt
!= cfmt_hidden
.fmt
) {
5319 g_free(cfmt_hidden
.custom_fields
);
5320 cfmt_hidden
.custom_fields
= NULL
;
5323 if (cfmt
->fmt
== COL_CUSTOM
) {
5325 * A custom column has to have the same custom field
5328 if (cfmt_hidden
.custom_fields
&& cfmt
->custom_fields
) {
5329 if (strcmp(cfmt
->custom_fields
,
5330 cfmt_hidden
.custom_fields
) != 0) {
5331 /* Different fields. */
5332 g_free(cfmt_hidden
.custom_fields
);
5333 cfmt_hidden
.custom_fields
= NULL
;
5336 if (cfmt
->custom_occurrence
!= cfmt_hidden
.custom_occurrence
) {
5337 /* Different occurrences settings. */
5338 g_free(cfmt_hidden
.custom_fields
);
5339 cfmt_hidden
.custom_fields
= NULL
;
5346 * OK, they match, so it's one of the hidden fields,
5347 * hence not visible.
5349 g_free(cfmt_hidden
.custom_fields
);
5357 * No - either there are no hidden columns or this isn't one
5358 * of them - so it is visible.
5364 * Returns true if the given device should capture in monitor mode by default
5367 prefs_capture_device_monitor_mode(const char *name
)
5369 char *tok
, *devices
;
5372 if (prefs
.capture_devices_monitor_mode
&& name
) {
5373 devices
= g_strdup (prefs
.capture_devices_monitor_mode
);
5374 len
= strlen (name
);
5375 for (tok
= strtok (devices
, ","); tok
; tok
= strtok(NULL
, ",")) {
5376 if (strlen (tok
) == len
&& strcmp (name
, tok
) == 0) {
5388 * Returns true if the user has marked this column as visible
5391 prefs_capture_options_dialog_column_is_visible(const char *column
)
5396 for (curr
= g_list_first(prefs
.capture_columns
); curr
; curr
= g_list_next(curr
)) {
5397 col
= (char *)curr
->data
;
5398 if (col
&& (g_ascii_strcasecmp(col
, column
) == 0)) {
5406 prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content
)
5408 return ((prefs
.gui_layout_content_1
== layout_pane_content
) ||
5409 (prefs
.gui_layout_content_2
== layout_pane_content
) ||
5410 (prefs
.gui_layout_content_3
== layout_pane_content
));
5413 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
5414 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
5415 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
5418 * Extract the red, green, and blue components of a 24-bit RGB value
5419 * and convert them from [0,255] to [0,65535].
5421 #define RED_COMPONENT(x) (uint16_t) (((((x) >> 16) & 0xff) * 65535 / 255))
5422 #define GREEN_COMPONENT(x) (uint16_t) (((((x) >> 8) & 0xff) * 65535 / 255))
5423 #define BLUE_COMPONENT(x) (uint16_t) ( (((x) & 0xff) * 65535 / 255))
5426 string_to_name_resolve(const char *string
, e_addr_resolve
*name_resolve
)
5430 memset(name_resolve
, 0, sizeof(e_addr_resolve
));
5431 while ((c
= *string
++) != '\0') {
5434 name_resolve
->maxmind_geoip
= true;
5437 name_resolve
->mac_name
= true;
5440 name_resolve
->network_name
= true;
5443 name_resolve
->use_external_net_name_resolver
= true;
5446 name_resolve
->transport_name
= true;
5449 name_resolve
->dns_pkt_addr_resolution
= true;
5452 name_resolve
->handshake_sni_addr_resolution
= true;
5455 name_resolve
->vlan_name
= true;
5459 * Unrecognized letter.
5468 deprecated_heur_dissector_pref(char *pref_name
, const char *value
)
5470 struct heur_pref_name
5472 const char* pref_name
;
5473 const char* short_name
;
5474 bool more_dissectors
; /* For multiple dissectors controlled by the same preference */
5477 struct heur_pref_name heur_prefs
[] = {
5478 {"acn.heuristic_acn", "acn_udp", 0},
5479 {"bfcp.enable", "bfcp_tcp", 1},
5480 {"bfcp.enable", "bfcp_udp", 0},
5481 {"bt-dht.enable", "bittorrent_dht_udp", 0},
5482 {"bt-utp.enable", "bt_utp_udp", 0},
5483 {"cattp.enable", "cattp_udp", 0},
5484 {"cfp.enable", "fp_eth", 0},
5485 {"dicom.heuristic", "dicom_tcp", 0},
5486 {"dnp3.heuristics", "dnp3_tcp", 1},
5487 {"dnp3.heuristics", "dnp3_udp", 0},
5488 {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
5489 {"esl.enable", "esl_eth", 0},
5490 {"fp.udp_heur", "fp_udp", 0},
5491 {"gvsp.enable_heuristic", "gvsp_udp", 0},
5492 {"hdcp2.enable", "hdcp2_tcp", 0},
5493 {"hislip.enable_heuristic", "hislip_tcp", 0},
5494 {"infiniband.dissect_eoib", "mellanox_eoib", 1},
5495 {"infiniband.identify_payload", "eth_over_ib", 0},
5496 {"jxta.udp.heuristic", "jxta_udp", 0},
5497 {"jxta.tcp.heuristic", "jxta_tcp", 0},
5498 {"jxta.sctp.heuristic", "jxta_sctp", 0},
5499 {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
5500 {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
5501 {"norm.heuristic_norm", "rmt_norm_udp", 0},
5502 {"openflow.heuristic", "openflow_tcp", 0},
5503 {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
5504 {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
5505 {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
5506 {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
5507 {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
5508 {"rtp.heuristic_rtp", "rtp_udp", 1},
5509 {"rtp.heuristic_rtp", "rtp_stun", 0},
5510 {"teredo.heuristic_teredo", "teredo_udp", 0},
5511 {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
5512 {"xml.heuristic", "xml_http", 1},
5513 {"xml.heuristic", "xml_sip", 1},
5514 {"xml.heuristic", "xml_media", 0},
5515 {"xml.heuristic_tcp", "xml_tcp", 0},
5516 {"xml.heuristic_udp", "xml_udp", 0},
5520 heur_dtbl_entry_t
* heuristic
;
5523 for (i
= 0; i
< array_length(heur_prefs
); i
++)
5525 if (strcmp(pref_name
, heur_prefs
[i
].pref_name
) == 0)
5527 heuristic
= find_heur_dissector_by_unique_short_name(heur_prefs
[i
].short_name
);
5528 if (heuristic
!= NULL
) {
5529 heuristic
->enabled
= ((g_ascii_strcasecmp(value
, "true") == 0) ? true : false);
5532 if (!heur_prefs
[i
].more_dissectors
)
5542 deprecated_enable_dissector_pref(char *pref_name
, const char *value
)
5544 struct dissector_pref_name
5546 const char* pref_name
;
5547 const char* short_name
;
5550 struct dissector_pref_name dissector_prefs
[] = {
5551 {"transum.tsumenabled", "TRANSUM"},
5552 {"snort.enable_snort_dissector", "Snort"},
5553 {"prp.enable", "PRP"},
5559 for (i
= 0; i
< array_length(dissector_prefs
); i
++)
5561 if (strcmp(pref_name
, dissector_prefs
[i
].pref_name
) == 0)
5563 proto_id
= proto_get_id_by_short_name(dissector_prefs
[i
].short_name
);
5565 proto_set_decoding(proto_id
, ((g_ascii_strcasecmp(value
, "true") == 0) ? true : false));
5574 deprecated_port_pref(char *pref_name
, const char *value
)
5576 struct port_pref_name
5578 const char* pref_name
;
5579 const char* module_name
; /* the protocol filter name */
5580 const char* table_name
;
5584 struct obsolete_pref_name
5586 const char* pref_name
;
5589 /* For now this is only supporting TCP/UDP port and RTP payload
5590 * types dissector preferences, which are assumed to be decimal */
5591 /* module_name is the filter name of the destination port preference,
5592 * which is usually the same as the original module but not
5593 * necessarily (e.g., if the preference is for what is now a PINO.)
5594 * XXX: Most of these were changed pre-2.0. Can we end support
5595 * for migrating legacy preferences at some point?
5597 struct port_pref_name port_prefs
[] = {
5599 {"cmp.tcp_alternate_port", "cmp", "tcp.port", 10},
5600 {"h248.tcp_port", "h248", "tcp.port", 10},
5601 {"cops.tcp.cops_port", "cops", "tcp.port", 10},
5602 {"dhcpfo.tcp_port", "dhcpfo", "tcp.port", 10},
5603 {"enttec.tcp_port", "enttec", "tcp.port", 10},
5604 {"forces.tcp_alternate_port", "forces", "tcp.port", 10},
5605 {"ged125.tcp_port", "ged125", "tcp.port", 10},
5606 {"hpfeeds.dissector_port", "hpfeeds", "tcp.port", 10},
5607 {"lsc.port", "lsc", "tcp.port", 10},
5608 {"megaco.tcp.txt_port", "megaco", "tcp.port", 10},
5609 {"netsync.tcp_port", "netsync", "tcp.port", 10},
5610 {"osi.tpkt_port", "osi", "tcp.port", 10},
5611 {"rsync.tcp_port", "rsync", "tcp.port", 10},
5612 {"sametime.tcp_port", "sametime", "tcp.port", 10},
5613 {"sigcomp.tcp.port2", "sigcomp", "tcp.port", 10},
5614 {"synphasor.tcp_port", "synphasor", "tcp.port", 10},
5615 {"tipc.alternate_port", "tipc", "tcp.port", 10},
5616 {"vnc.alternate_port", "vnc", "tcp.port", 10},
5617 {"scop.port", "scop", "tcp.port", 10},
5618 {"scop.port_secure", "scop", "tcp.port", 10},
5619 {"tpncp.tcp.trunkpack_port", "tpncp", "tcp.port", 10},
5621 {"h248.udp_port", "h248", "udp.port", 10},
5622 {"actrace.udp_port", "actrace", "udp.port", 10},
5623 {"brp.port", "brp", "udp.port", 10},
5624 {"bvlc.additional_udp_port", "bvlc", "udp.port", 10},
5625 {"capwap.udp.port.control", "capwap", "udp.port", 10},
5626 {"capwap.udp.port.data", "capwap", "udp.port", 10},
5627 {"coap.udp_port", "coap", "udp.port", 10},
5628 {"enttec.udp_port", "enttec", "udp.port", 10},
5629 {"forces.udp_alternate_port", "forces", "udp.port", 10},
5630 {"ldss.udp_port", "ldss", "udp.port", 10},
5631 {"lmp.udp_port", "lmp", "udp.port", 10},
5632 {"ltp.port", "ltp", "udp.port", 10},
5633 {"lwres.udp.lwres_port", "lwres", "udp.port", 10},
5634 {"megaco.udp.txt_port", "megaco", "udp.port", 10},
5635 {"pfcp.port_pfcp", "pfcp", "udp.port", 10},
5636 {"pgm.udp.encap_ucast_port", "pgm", "udp.port", 10},
5637 {"pgm.udp.encap_mcast_port", "pgm", "udp.port", 10},
5638 {"quic.udp.quic.port", "quic", "udp.port", 10},
5639 {"quic.udp.quics.port", "quic", "udp.port", 10},
5640 {"radius.alternate_port", "radius", "udp.port", 10},
5641 {"rdt.default_udp_port", "rdt", "udp.port", 10},
5642 {"alc.default.udp_port", "alc", "udp.port", 10},
5643 {"sigcomp.udp.port2", "sigcomp", "udp.port", 10},
5644 {"synphasor.udp_port", "synphasor", "udp.port", 10},
5645 {"tdmop.udpport", "tdmop", "udp.port", 10},
5646 {"uaudp.port1", "uaudp", "udp.port", 10},
5647 {"uaudp.port2", "uaudp", "udp.port", 10},
5648 {"uaudp.port3", "uaudp", "udp.port", 10},
5649 {"uaudp.port4", "uaudp", "udp.port", 10},
5650 {"uhd.dissector_port", "uhd", "udp.port", 10},
5651 {"vrt.dissector_port", "vrt", "udp.port", 10},
5652 {"tpncp.udp.trunkpack_port", "tpncp", "udp.port", 10},
5654 {"hnbap.port", "hnbap", "sctp.port", 10},
5655 {"m2pa.port", "m2pa", "sctp.port", 10},
5656 {"megaco.sctp.txt_port", "megaco", "sctp.port", 10},
5657 {"rua.port", "rua", "sctp.port", 10},
5659 {"lapd.sctp_payload_protocol_identifier", "lapd", "sctp.ppi", 10},
5661 {"ranap.sccp_ssn", "ranap", "sccp.ssn", 10},
5664 struct port_pref_name port_range_prefs
[] = {
5666 {"couchbase.tcp.ports", "couchbase", "tcp.port", 10},
5667 {"gsm_ipa.tcp_ports", "gsm_ipa", "tcp.port", 10},
5668 {"kafka.tcp.ports", "kafka", "tcp.port", 10},
5669 {"kt.tcp.ports", "kt", "tcp.port", 10},
5670 {"memcache.tcp.ports", "memcache", "tcp.port", 10},
5671 {"mrcpv2.tcp.port_range", "mrcpv2", "tcp.port", 10},
5672 {"pdu_transport.ports.tcp", "pdu_transport", "tcp.port", 10},
5673 {"rtsp.tcp.port_range", "rtsp", "tcp.port", 10},
5674 {"sip.tcp.ports", "sip", "tcp.port", 10},
5675 {"someip.ports.tcp", "someip", "tcp.port", 10},
5676 {"tds.tcp_ports", "tds", "tcp.port", 10},
5677 {"tpkt.tcp.ports", "tpkt", "tcp.port", 10},
5678 {"uma.tcp.ports", "uma", "tcp.port", 10},
5680 {"aruba_erm.udp.ports", "arubs_erm", "udp.port", 10},
5681 {"diameter.udp.ports", "diameter", "udp.port", 10},
5682 {"dmp.udp_ports", "dmp", "udp.port", 10},
5683 {"dns.udp.ports", "dns", "udp.port", 10},
5684 {"gsm_ipa.udp_ports", "gsm_ipa", "udp.port", 10},
5685 {"hcrt.dissector_udp_port", "hcrt", "udp.port", 10},
5686 {"memcache.udp.ports", "memcache", "udp.port", 10},
5687 {"nb_rtpmux.udp_ports", "nb_rtpmux", "udp.port", 10},
5688 {"gprs-ns.udp.ports", "gprs-ns", "udp.port", 10},
5689 {"p_mul.udp_ports", "p_mul", "udp.port", 10},
5690 {"pdu_transport.ports.udp", "pdu_transport", "udp.port", 10},
5691 {"radius.ports", "radius", "udp.port", 10},
5692 {"sflow.ports", "sflow", "udp.port", 10},
5693 {"someip.ports.udp", "someip", "udp.port", 10},
5694 {"sscop.udp.ports", "sscop", "udp.port", 10},
5695 {"tftp.udp_ports", "tftp", "udp.port", 10},
5696 {"tipc.udp.ports", "tipc", "udp.port", 10},
5698 {"amr.dynamic.payload.type", "amr", "rtp.pt", 10},
5699 {"amr.wb.dynamic.payload.type", "amr_wb", "rtp.pt", 10},
5700 {"dvb-s2_modeadapt.dynamic.payload.type", "dvb-s2_modeadapt", "rtp.pt", 10},
5701 {"evs.dynamic.payload.type", "evs", "rtp.pt", 10},
5702 {"h263p.dynamic.payload.type", "h263p", "rtp.pt", 10},
5703 {"h264.dynamic.payload.type", "h264", "rtp.pt", 10},
5704 {"h265.dynamic.payload.type", "h265", "rtp.pt", 10},
5705 {"ismacryp.dynamic.payload.type", "ismacryp", "rtp.pt", 10},
5706 {"iuup.dynamic.payload.type", "iuup", "rtp.pt", 10},
5707 {"lapd.rtp_payload_type", "lapd", "rtp.pt", 10},
5708 {"mp4ves.dynamic.payload.type", "mp4ves", "rtp.pt", 10},
5709 {"mtp2.rtp_payload_type", "mtp2", "rtp.pt", 10},
5710 {"opus.dynamic.payload.type", "opus", "rtp.pt", 10},
5711 {"rtp.rfc2198_payload_type", "rtp_rfc2198", "rtp.pt", 10},
5712 {"rtpevent.event_payload_type_value", "rtpevent", "rtp.pt", 10},
5713 {"rtpevent.cisco_nse_payload_type_value", "rtpevent", "rtp.pt", 10},
5714 {"rtpmidi.midi_payload_type_value", "rtpmidi", "rtp.pt", 10},
5715 {"vp8.dynamic.payload.type", "vp8", "rtp.pt", 10},
5717 {"diameter.sctp.ports", "diameter", "sctp.port", 10},
5718 {"sgsap.sctp_ports", "sgsap", "sctp.port", 10},
5720 {"pcap.ssn", "pcap", "sccp.ssn", 10},
5723 /* These are subdissectors of TPKT/OSITP that used to have a
5724 TCP port preference even though they were never
5725 directly on TCP. Convert them to use Decode As
5726 with the TPKT dissector handle */
5727 struct port_pref_name tpkt_subdissector_port_prefs
[] = {
5728 {"dap.tcp.port", "dap", "tcp.port", 10},
5729 {"disp.tcp.port", "disp", "tcp.port", 10},
5730 {"dop.tcp.port", "dop", "tcp.port", 10},
5731 {"dsp.tcp.port", "dsp", "tcp.port", 10},
5732 {"p1.tcp.port", "p1", "tcp.port", 10},
5733 {"p7.tcp.port", "p7", "tcp.port", 10},
5734 {"rdp.tcp.port", "rdp", "tcp.port", 10},
5737 /* These are obsolete preferences from the dissectors' view,
5738 (typically because of a switch from a single value to a
5739 range value) but the name of the preference conflicts
5740 with the generated preference name from the dissector table.
5741 Don't allow the obsolete preference through to be handled */
5742 struct obsolete_pref_name obsolete_prefs
[] = {
5743 {"diameter.tcp.port"},
5745 {"mrcpv2.tcp.port"},
5753 dissector_table_t sub_dissectors
;
5754 dissector_handle_t handle
, tpkt_handle
;
5758 static bool sanity_checked
;
5759 if (!sanity_checked
) {
5760 sanity_checked
= true;
5761 for (i
= 0; i
< G_N_ELEMENTS(port_prefs
); i
++) {
5762 module
= prefs_find_module(port_prefs
[i
].module_name
);
5764 ws_warning("Deprecated ports pref check - module '%s' not found", port_prefs
[i
].module_name
);
5767 pref
= prefs_find_preference(module
, port_prefs
[i
].table_name
);
5769 ws_warning("Deprecated ports pref '%s.%s' not found", module
->name
, port_prefs
[i
].table_name
);
5772 if (pref
->type
!= PREF_DECODE_AS_RANGE
) {
5773 ws_warning("Deprecated ports pref '%s.%s' has wrong type: %#x (%s)", module
->name
, port_prefs
[i
].table_name
, pref
->type
, prefs_pref_type_name(pref
));
5778 for (i
= 0; i
< G_N_ELEMENTS(port_prefs
); i
++) {
5779 if (strcmp(pref_name
, port_prefs
[i
].pref_name
) == 0) {
5780 if (!ws_basestrtou32(value
, NULL
, &uval
, port_prefs
[i
].base
))
5781 return false; /* number was bad */
5783 module
= prefs_find_module(port_prefs
[i
].module_name
);
5784 pref
= prefs_find_preference(module
, port_prefs
[i
].table_name
);
5786 module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
5787 if (pref
->type
== PREF_DECODE_AS_RANGE
) {
5788 // The legacy preference was a port number, but the new
5789 // preference is a port range. Add to existing range.
5791 prefs_range_add_value(pref
, uval
);
5796 /* If the value is zero, it wouldn't add to the Decode As tables */
5799 sub_dissectors
= find_dissector_table(port_prefs
[i
].table_name
);
5800 if (sub_dissectors
!= NULL
) {
5801 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
5802 if (handle
!= NULL
) {
5803 dissector_change_uint(port_prefs
[i
].table_name
, uval
, handle
);
5804 decode_build_reset_list(port_prefs
[i
].table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(uval
), NULL
, NULL
);
5813 for (i
= 0; i
< array_length(port_range_prefs
); i
++)
5815 if (strcmp(pref_name
, port_range_prefs
[i
].pref_name
) == 0)
5817 uint32_t range_i
, range_j
;
5819 sub_dissectors
= find_dissector_table(port_range_prefs
[i
].table_name
);
5820 if (sub_dissectors
!= NULL
) {
5821 switch (dissector_table_get_type(sub_dissectors
)) {
5829 ws_error("The dissector table %s (%s) is not an integer type - are you using a buggy plugin?", port_range_prefs
[i
].table_name
, get_dissector_table_ui_name(port_range_prefs
[i
].table_name
));
5830 ws_assert_not_reached();
5833 module
= prefs_find_module(port_range_prefs
[i
].module_name
);
5834 pref
= prefs_find_preference(module
, port_range_prefs
[i
].table_name
);
5837 if (!prefs_set_range_value_work(pref
, value
, true, &module
->prefs_changed_flags
))
5839 return false; /* number was bad */
5842 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
5843 if (handle
!= NULL
) {
5845 for (range_i
= 0; range_i
< (*pref
->varp
.range
)->nranges
; range_i
++) {
5846 for (range_j
= (*pref
->varp
.range
)->ranges
[range_i
].low
; range_j
< (*pref
->varp
.range
)->ranges
[range_i
].high
; range_j
++) {
5847 dissector_change_uint(port_range_prefs
[i
].table_name
, range_j
, handle
);
5848 decode_build_reset_list(port_range_prefs
[i
].table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(range_j
), NULL
, NULL
);
5851 dissector_change_uint(port_range_prefs
[i
].table_name
, (*pref
->varp
.range
)->ranges
[range_i
].high
, handle
);
5852 decode_build_reset_list(port_range_prefs
[i
].table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[range_i
].high
), NULL
, NULL
);
5862 for (i
= 0; i
< array_length(tpkt_subdissector_port_prefs
); i
++)
5864 if (strcmp(pref_name
, tpkt_subdissector_port_prefs
[i
].pref_name
) == 0)
5866 /* XXX - give an error if it doesn't fit in a unsigned? */
5867 if (!ws_basestrtou32(value
, NULL
, &uval
, tpkt_subdissector_port_prefs
[i
].base
))
5868 return false; /* number was bad */
5870 /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
5871 if ((uval
!= 0) && (uval
!= 102))
5873 tpkt_handle
= find_dissector("tpkt");
5874 if (tpkt_handle
!= NULL
) {
5875 dissector_change_uint(tpkt_subdissector_port_prefs
[i
].table_name
, uval
, tpkt_handle
);
5883 for (i
= 0; i
< array_length(obsolete_prefs
); i
++)
5885 if (strcmp(pref_name
, obsolete_prefs
[i
].pref_name
) == 0)
5887 /* Just ignore the preference */
5894 static prefs_set_pref_e
5895 set_pref(char *pref_name
, const char *value
, void *private_data
,
5896 bool return_range_errors
)
5902 char *dotp
, *last_dotp
;
5903 static char *filter_label
= NULL
;
5904 static bool filter_enabled
= false;
5905 module_t
*module
, *containing_module
, *target_module
;
5908 bool converted_pref
= false;
5910 target_module
= (module_t
*)private_data
;
5912 //The PRS_GUI field names are here for backwards compatibility
5913 //display filters have been converted to a UAT.
5914 if (strcmp(pref_name
, PRS_GUI_FILTER_LABEL
) == 0) {
5915 /* Assume that PRS_GUI_FILTER_EXPR follows this preference. In case of
5916 * malicious preference files, free the previous value to limit the size
5917 * of leaked memory. */
5918 g_free(filter_label
);
5919 filter_label
= g_strdup(value
);
5920 } else if (strcmp(pref_name
, PRS_GUI_FILTER_ENABLED
) == 0) {
5921 filter_enabled
= (strcmp(value
, "TRUE") == 0) ? true : false;
5922 } else if (strcmp(pref_name
, PRS_GUI_FILTER_EXPR
) == 0) {
5923 /* Comments not supported for "old" preference style */
5924 filter_expression_new(filter_label
, value
, "", filter_enabled
);
5925 g_free(filter_label
);
5926 filter_label
= NULL
;
5927 /* Remember to save the new UAT to file. */
5928 prefs
.filter_expressions_old
= true;
5929 } else if (strcmp(pref_name
, "gui.version_in_start_page") == 0) {
5930 /* Convert deprecated value to closest current equivalent */
5931 if (g_ascii_strcasecmp(value
, "true") == 0) {
5932 prefs
.gui_version_placement
= version_both
;
5934 prefs
.gui_version_placement
= version_neither
;
5936 } else if (strcmp(pref_name
, "name_resolve") == 0 ||
5937 strcmp(pref_name
, "capture.name_resolve") == 0) {
5939 * Handle the deprecated name resolution options.
5941 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
5942 * RESOLV_ALL and RESOLV_NONE.
5944 * Otherwise, we treat it as a list of name types we want to resolve.
5946 if (g_ascii_strcasecmp(value
, "true") == 0) {
5947 gbl_resolv_flags
.mac_name
= true;
5948 gbl_resolv_flags
.network_name
= true;
5949 gbl_resolv_flags
.transport_name
= true;
5951 else if (g_ascii_strcasecmp(value
, "false") == 0) {
5952 disable_name_resolution();
5955 /* start out with none set */
5956 disable_name_resolution();
5957 if (string_to_name_resolve(value
, &gbl_resolv_flags
) != '\0')
5958 return PREFS_SET_SYNTAX_ERR
;
5960 } else if (deprecated_heur_dissector_pref(pref_name
, value
)) {
5961 /* Handled within deprecated_heur_dissector_pref() if found */
5962 } else if (deprecated_enable_dissector_pref(pref_name
, value
)) {
5963 /* Handled within deprecated_enable_dissector_pref() if found */
5964 } else if (deprecated_port_pref(pref_name
, value
)) {
5965 /* Handled within deprecated_port_pref() if found */
5966 } else if (strcmp(pref_name
, "console.log.level") == 0) {
5967 /* Handled on the command line within ws_log_parse_args() */
5968 return PREFS_SET_OK
;
5970 /* Handle deprecated "global" options that don't have a module
5971 * associated with them
5973 if ((strcmp(pref_name
, "name_resolve_concurrency") == 0) ||
5974 (strcmp(pref_name
, "name_resolve_load_smi_modules") == 0) ||
5975 (strcmp(pref_name
, "name_resolve_suppress_smi_errors") == 0)) {
5976 module
= nameres_module
;
5979 /* To which module does this preference belong? */
5981 last_dotp
= pref_name
;
5983 dotp
= strchr(last_dotp
, '.');
5985 /* Either there's no such module, or no module was specified.
5986 In either case, that means there's no such preference. */
5987 return PREFS_SET_NO_SUCH_PREF
;
5989 *dotp
= '\0'; /* separate module and preference name */
5990 module
= prefs_find_module(pref_name
);
5993 * XXX - "Diameter" rather than "diameter" was used in earlier
5994 * versions of Wireshark; if we didn't find the module, and its name
5995 * was "Diameter", look for "diameter" instead.
5997 * In addition, the BEEP protocol used to be the BXXP protocol,
5998 * so if we didn't find the module, and its name was "bxxp",
5999 * look for "beep" instead.
6001 * Also, the preferences for GTP v0 and v1 were combined under
6002 * a single "gtp" heading, and the preferences for SMPP were
6003 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
6004 * However, SMPP now has its own preferences, so we just map
6005 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
6007 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
6008 * and "nsip" to "gprs_ns".
6010 * The SynOptics Network Management Protocol (SONMP) is now known by
6011 * its modern name, the Nortel Discovery Protocol (NDP).
6013 if (module
== NULL
) {
6015 * See if there's a backwards-compatibility name
6016 * that maps to this module.
6018 module
= prefs_find_module_alias(pref_name
);
6019 if (module
== NULL
) {
6021 * There's no alias for the module; see if the
6022 * module name matches any protocol aliases.
6024 header_field_info
*hfinfo
= proto_registrar_get_byalias(pref_name
);
6026 module
= (module_t
*) wmem_tree_lookup_string(prefs_modules
, hfinfo
->abbrev
, WMEM_TREE_STRING_NOCASE
);
6029 if (module
== NULL
) {
6031 * There aren't any aliases. Was the module
6032 * removed rather than renamed?
6034 if (strcmp(pref_name
, "etheric") == 0 ||
6035 strcmp(pref_name
, "isup_thin") == 0) {
6037 * The dissectors for these protocols were
6038 * removed as obsolete on 2009-07-70 in change
6039 * 739bfc6ff035583abb9434e0e988048de38a8d9a.
6041 return PREFS_SET_OBSOLETE
;
6045 converted_pref
= true;
6046 prefs
.unknown_prefs
= true;
6049 *dotp
= '.'; /* put the preference string back */
6050 dotp
++; /* skip past separator to preference name */
6055 /* The pref is located in the module or a submodule.
6056 * Assume module, then search for a submodule holding the pref. */
6057 containing_module
= module
;
6058 pref
= prefs_find_preference_with_submodule(module
, dotp
, &containing_module
);
6061 prefs
.unknown_prefs
= true;
6063 /* "gui" prefix was added to column preferences for better organization
6064 * within the preferences file
6066 if (module
== gui_column_module
) {
6067 /* While this has a subtree, there is no apply callback, so no
6068 * need to use prefs_find_preference_with_submodule to update
6069 * containing_module. It would not be useful. */
6070 pref
= prefs_find_preference(module
, pref_name
);
6072 else if (strcmp(module
->name
, "mgcp") == 0) {
6074 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
6075 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
6076 * were used in earlier versions of Wireshark; if we didn't find the
6077 * preference, it was an MGCP preference, and its name was
6078 * "display raw text toggle" or "display dissect tree", look for
6079 * "display_raw_text" or "display_dissect_tree" instead.
6081 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
6082 * the gateway and callagent ports were given those names; we interpret
6083 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
6084 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
6085 * they were registered by the MCCP dissector and thus that's the
6086 * order in which they were written to the preferences file. (If
6087 * we're not reading the preferences file, but are handling stuff
6088 * from a "-o" command-line option, we have no clue which the user
6089 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
6090 * or "mgcp.{tcp,udp}.callagent_port" instead.)
6092 if (strcmp(dotp
, "display raw text toggle") == 0)
6093 pref
= prefs_find_preference(module
, "display_raw_text");
6094 else if (strcmp(dotp
, "display dissect tree") == 0)
6095 pref
= prefs_find_preference(module
, "display_dissect_tree");
6096 else if (strcmp(dotp
, "tcp.port") == 0) {
6097 mgcp_tcp_port_count
++;
6098 if (mgcp_tcp_port_count
== 1) {
6099 /* It's the first one */
6100 pref
= prefs_find_preference(module
, "tcp.gateway_port");
6101 } else if (mgcp_tcp_port_count
== 2) {
6102 /* It's the second one */
6103 pref
= prefs_find_preference(module
, "tcp.callagent_port");
6105 /* Otherwise it's from the command line, and we don't bother
6107 } else if (strcmp(dotp
, "udp.port") == 0) {
6108 mgcp_udp_port_count
++;
6109 if (mgcp_udp_port_count
== 1) {
6110 /* It's the first one */
6111 pref
= prefs_find_preference(module
, "udp.gateway_port");
6112 } else if (mgcp_udp_port_count
== 2) {
6113 /* It's the second one */
6114 pref
= prefs_find_preference(module
, "udp.callagent_port");
6116 /* Otherwise it's from the command line, and we don't bother
6119 } else if (strcmp(module
->name
, "smb") == 0) {
6120 /* Handle old names for SMB preferences. */
6121 if (strcmp(dotp
, "smb.trans.reassembly") == 0)
6122 pref
= prefs_find_preference(module
, "trans_reassembly");
6123 else if (strcmp(dotp
, "smb.dcerpc.reassembly") == 0)
6124 pref
= prefs_find_preference(module
, "dcerpc_reassembly");
6125 } else if (strcmp(module
->name
, "ndmp") == 0) {
6126 /* Handle old names for NDMP preferences. */
6127 if (strcmp(dotp
, "ndmp.desegment") == 0)
6128 pref
= prefs_find_preference(module
, "desegment");
6129 } else if (strcmp(module
->name
, "diameter") == 0) {
6130 /* Handle old names for Diameter preferences. */
6131 if (strcmp(dotp
, "diameter.desegment") == 0)
6132 pref
= prefs_find_preference(module
, "desegment");
6133 } else if (strcmp(module
->name
, "pcli") == 0) {
6134 /* Handle old names for PCLI preferences. */
6135 if (strcmp(dotp
, "pcli.udp_port") == 0)
6136 pref
= prefs_find_preference(module
, "udp_port");
6137 } else if (strcmp(module
->name
, "artnet") == 0) {
6138 /* Handle old names for ARTNET preferences. */
6139 if (strcmp(dotp
, "artnet.udp_port") == 0)
6140 pref
= prefs_find_preference(module
, "udp_port");
6141 } else if (strcmp(module
->name
, "mapi") == 0) {
6142 /* Handle old names for MAPI preferences. */
6143 if (strcmp(dotp
, "mapi_decrypt") == 0)
6144 pref
= prefs_find_preference(module
, "decrypt");
6145 } else if (strcmp(module
->name
, "fc") == 0) {
6146 /* Handle old names for Fibre Channel preferences. */
6147 if (strcmp(dotp
, "reassemble_fc") == 0)
6148 pref
= prefs_find_preference(module
, "reassemble");
6149 else if (strcmp(dotp
, "fc_max_frame_size") == 0)
6150 pref
= prefs_find_preference(module
, "max_frame_size");
6151 } else if (strcmp(module
->name
, "fcip") == 0) {
6152 /* Handle old names for Fibre Channel-over-IP preferences. */
6153 if (strcmp(dotp
, "desegment_fcip_messages") == 0)
6154 pref
= prefs_find_preference(module
, "desegment");
6155 else if (strcmp(dotp
, "fcip_port") == 0)
6156 pref
= prefs_find_preference(module
, "target_port");
6157 } else if (strcmp(module
->name
, "gtp") == 0) {
6158 /* Handle old names for GTP preferences. */
6159 if (strcmp(dotp
, "gtpv0_port") == 0)
6160 pref
= prefs_find_preference(module
, "v0_port");
6161 else if (strcmp(dotp
, "gtpv1c_port") == 0)
6162 pref
= prefs_find_preference(module
, "v1c_port");
6163 else if (strcmp(dotp
, "gtpv1u_port") == 0)
6164 pref
= prefs_find_preference(module
, "v1u_port");
6165 else if (strcmp(dotp
, "gtp_dissect_tpdu") == 0)
6166 pref
= prefs_find_preference(module
, "dissect_tpdu");
6167 else if (strcmp(dotp
, "gtpv0_dissect_cdr_as") == 0)
6168 pref
= prefs_find_preference(module
, "v0_dissect_cdr_as");
6169 else if (strcmp(dotp
, "gtpv0_check_etsi") == 0)
6170 pref
= prefs_find_preference(module
, "v0_check_etsi");
6171 else if (strcmp(dotp
, "gtpv1_check_etsi") == 0)
6172 pref
= prefs_find_preference(module
, "v1_check_etsi");
6173 } else if (strcmp(module
->name
, "ip") == 0) {
6174 /* Handle old names for IP preferences. */
6175 if (strcmp(dotp
, "ip_summary_in_tree") == 0)
6176 pref
= prefs_find_preference(module
, "summary_in_tree");
6177 } else if (strcmp(module
->name
, "iscsi") == 0) {
6178 /* Handle old names for iSCSI preferences. */
6179 if (strcmp(dotp
, "iscsi_port") == 0)
6180 pref
= prefs_find_preference(module
, "target_port");
6181 } else if (strcmp(module
->name
, "lmp") == 0) {
6182 /* Handle old names for LMP preferences. */
6183 if (strcmp(dotp
, "lmp_version") == 0)
6184 pref
= prefs_find_preference(module
, "version");
6185 } else if (strcmp(module
->name
, "mtp3") == 0) {
6186 /* Handle old names for MTP3 preferences. */
6187 if (strcmp(dotp
, "mtp3_standard") == 0)
6188 pref
= prefs_find_preference(module
, "standard");
6189 else if (strcmp(dotp
, "net_addr_format") == 0)
6190 pref
= prefs_find_preference(module
, "addr_format");
6191 } else if (strcmp(module
->name
, "nlm") == 0) {
6192 /* Handle old names for NLM preferences. */
6193 if (strcmp(dotp
, "nlm_msg_res_matching") == 0)
6194 pref
= prefs_find_preference(module
, "msg_res_matching");
6195 } else if (strcmp(module
->name
, "ppp") == 0) {
6196 /* Handle old names for PPP preferences. */
6197 if (strcmp(dotp
, "ppp_fcs") == 0)
6198 pref
= prefs_find_preference(module
, "fcs_type");
6199 else if (strcmp(dotp
, "ppp_vj") == 0)
6200 pref
= prefs_find_preference(module
, "decompress_vj");
6201 } else if (strcmp(module
->name
, "rsvp") == 0) {
6202 /* Handle old names for RSVP preferences. */
6203 if (strcmp(dotp
, "rsvp_process_bundle") == 0)
6204 pref
= prefs_find_preference(module
, "process_bundle");
6205 } else if (strcmp(module
->name
, "tcp") == 0) {
6206 /* Handle old names for TCP preferences. */
6207 if (strcmp(dotp
, "tcp_summary_in_tree") == 0)
6208 pref
= prefs_find_preference(module
, "summary_in_tree");
6209 else if (strcmp(dotp
, "tcp_analyze_sequence_numbers") == 0)
6210 pref
= prefs_find_preference(module
, "analyze_sequence_numbers");
6211 else if (strcmp(dotp
, "tcp_relative_sequence_numbers") == 0)
6212 pref
= prefs_find_preference(module
, "relative_sequence_numbers");
6213 else if (strcmp(dotp
, "dissect_experimental_options_with_magic") == 0)
6214 pref
= prefs_find_preference(module
, "dissect_experimental_options_rfc6994");
6215 } else if (strcmp(module
->name
, "udp") == 0) {
6216 /* Handle old names for UDP preferences. */
6217 if (strcmp(dotp
, "udp_summary_in_tree") == 0)
6218 pref
= prefs_find_preference(module
, "summary_in_tree");
6219 } else if (strcmp(module
->name
, "ndps") == 0) {
6220 /* Handle old names for NDPS preferences. */
6221 if (strcmp(dotp
, "desegment_ndps") == 0)
6222 pref
= prefs_find_preference(module
, "desegment_tcp");
6223 } else if (strcmp(module
->name
, "http") == 0) {
6224 /* Handle old names for HTTP preferences. */
6225 if (strcmp(dotp
, "desegment_http_headers") == 0)
6226 pref
= prefs_find_preference(module
, "desegment_headers");
6227 else if (strcmp(dotp
, "desegment_http_body") == 0)
6228 pref
= prefs_find_preference(module
, "desegment_body");
6229 } else if (strcmp(module
->name
, "smpp") == 0) {
6230 /* Handle preferences that moved from SMPP. */
6231 module_t
*new_module
= prefs_find_module("gsm-sms-ud");
6233 if (strcmp(dotp
, "port_number_udh_means_wsp") == 0) {
6234 pref
= prefs_find_preference(new_module
, "port_number_udh_means_wsp");
6235 containing_module
= new_module
;
6236 } else if (strcmp(dotp
, "try_dissect_1st_fragment") == 0) {
6237 pref
= prefs_find_preference(new_module
, "try_dissect_1st_fragment");
6238 containing_module
= new_module
;
6241 } else if (strcmp(module
->name
, "asn1") == 0) {
6242 /* Handle old generic ASN.1 preferences (it's not really a
6243 rename, as the new preferences support multiple ports,
6244 but we might as well copy them over). */
6245 if (strcmp(dotp
, "tcp_port") == 0)
6246 pref
= prefs_find_preference(module
, "tcp_ports");
6247 else if (strcmp(dotp
, "udp_port") == 0)
6248 pref
= prefs_find_preference(module
, "udp_ports");
6249 else if (strcmp(dotp
, "sctp_port") == 0)
6250 pref
= prefs_find_preference(module
, "sctp_ports");
6251 } else if (strcmp(module
->name
, "llcgprs") == 0) {
6252 if (strcmp(dotp
, "ignore_cipher_bit") == 0)
6253 pref
= prefs_find_preference(module
, "autodetect_cipher_bit");
6254 } else if (strcmp(module
->name
, "erf") == 0) {
6255 if (strcmp(dotp
, "erfeth") == 0) {
6256 /* Handle the old "erfeth" preference; map it to the new
6257 "ethfcs" preference, and map the values to those for
6258 the new preference. */
6259 pref
= prefs_find_preference(module
, "ethfcs");
6260 if (strcmp(value
, "ethfcs") == 0 || strcmp(value
, "Ethernet with FCS") == 0)
6262 else if (strcmp(value
, "eth") == 0 || strcmp(value
, "Ethernet") == 0)
6264 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6266 } else if (strcmp(dotp
, "erfatm") == 0) {
6267 /* Handle the old "erfatm" preference; map it to the new
6268 "aal5_type" preference, and map the values to those for
6269 the new preference. */
6270 pref
= prefs_find_preference(module
, "aal5_type");
6271 if (strcmp(value
, "atm") == 0 || strcmp(value
, "ATM") == 0)
6273 else if (strcmp(value
, "llc") == 0 || strcmp(value
, "LLC") == 0)
6275 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6277 } else if (strcmp(dotp
, "erfhdlc") == 0) {
6278 /* Handle the old "erfhdlc" preference; map it to the new
6279 "hdlc_type" preference, and map the values to those for
6280 the new preference. */
6281 pref
= prefs_find_preference(module
, "hdlc_type");
6282 if (strcmp(value
, "chdlc") == 0 || strcmp(value
, "Cisco HDLC") == 0)
6284 else if (strcmp(value
, "ppp") == 0 || strcmp(value
, "PPP serial") == 0)
6286 else if (strcmp(value
, "fr") == 0 || strcmp(value
, "Frame Relay") == 0)
6288 else if (strcmp(value
, "mtp2") == 0 || strcmp(value
, "SS7 MTP2") == 0)
6290 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6293 } else if (strcmp(module
->name
, "eth") == 0) {
6294 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
6295 if (strcmp(dotp
, "qinq_ethertype") == 0) {
6296 module_t
*new_module
= prefs_find_module("vlan");
6298 pref
= prefs_find_preference(new_module
, "qinq_ethertype");
6299 containing_module
= new_module
;
6302 } else if (strcmp(module
->name
, "taps") == 0) {
6303 /* taps preferences moved to "statistics" module */
6304 if (strcmp(dotp
, "update_interval") == 0)
6305 pref
= prefs_find_preference(stats_module
, dotp
);
6306 } else if (strcmp(module
->name
, "packet_list") == 0) {
6307 /* packet_list preferences moved to protocol module */
6308 if (strcmp(dotp
, "display_hidden_proto_items") == 0)
6309 pref
= prefs_find_preference(protocols_module
, dotp
);
6310 } else if (strcmp(module
->name
, "stream") == 0) {
6311 /* stream preferences moved to gui color module */
6312 if ((strcmp(dotp
, "client.fg") == 0) ||
6313 (strcmp(dotp
, "client.bg") == 0) ||
6314 (strcmp(dotp
, "server.fg") == 0) ||
6315 (strcmp(dotp
, "server.bg") == 0))
6316 pref
= prefs_find_preference(gui_color_module
, pref_name
);
6317 } else if (strcmp(module
->name
, "nameres") == 0) {
6318 if (strcmp(pref_name
, "name_resolve_concurrency") == 0) {
6319 pref
= prefs_find_preference(nameres_module
, pref_name
);
6320 } else if (strcmp(pref_name
, "name_resolve_load_smi_modules") == 0) {
6321 pref
= prefs_find_preference(nameres_module
, "load_smi_modules");
6322 } else if (strcmp(pref_name
, "name_resolve_suppress_smi_errors") == 0) {
6323 pref
= prefs_find_preference(nameres_module
, "suppress_smi_errors");
6325 } else if (strcmp(module
->name
, "extcap") == 0) {
6326 /* Handle the old "sshdump.remotesudo" preference; map it to the new
6327 "sshdump.remotepriv" preference, and map the boolean values to the
6328 appropriate strings of the new preference. */
6329 if (strcmp(dotp
, "sshdump.remotesudo") == 0) {
6330 pref
= prefs_find_preference(module
, "sshdump.remotepriv");
6331 if (g_ascii_strcasecmp(value
, "true") == 0)
6338 converted_pref
= true;
6341 if (pref
== NULL
) {
6342 if (strcmp(module
->name
, "extcap") == 0 && g_list_length(module
->prefs
) <= 1) {
6344 * Assume that we've skipped extcap preference registration
6345 * and that only extcap.gui_save_on_start is loaded.
6347 return PREFS_SET_OK
;
6349 return PREFS_SET_NO_SUCH_PREF
; /* no such preference */
6352 if (target_module
&& target_module
!= containing_module
) {
6354 return PREFS_SET_OK
;
6358 if (IS_PREF_OBSOLETE(type
)) {
6359 return PREFS_SET_OBSOLETE
; /* no such preference any more */
6361 RESET_PREF_OBSOLETE(type
);
6364 if (converted_pref
) {
6365 ws_warning("Preference \"%s\" has been converted to \"%s.%s\"\n"
6366 "Save your preferences to make this change permanent.",
6367 pref_name
, module
->name
? module
->name
: module
->parent
->name
, prefs_get_name(pref
));
6373 if (!ws_basestrtou32(value
, NULL
, &uval
, pref
->info
.base
))
6374 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6375 if (*pref
->varp
.uint
!= uval
) {
6376 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6377 *pref
->varp
.uint
= uval
;
6381 /* XXX - give an error if it's neither "true" nor "false"? */
6382 if (g_ascii_strcasecmp(value
, "true") == 0)
6386 if (*pref
->varp
.boolp
!= bval
) {
6387 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6388 *pref
->varp
.boolp
= bval
;
6393 /* XXX - give an error if it doesn't match? */
6394 enum_val
= find_val_for_string(value
, pref
->info
.enum_info
.enumvals
,
6396 if (*pref
->varp
.enump
!= enum_val
) {
6397 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6398 *pref
->varp
.enump
= enum_val
;
6403 case PREF_SAVE_FILENAME
:
6404 case PREF_OPEN_FILENAME
:
6406 case PREF_DISSECTOR
:
6407 containing_module
->prefs_changed_flags
|= prefs_set_string_value(pref
, value
, pref_current
);
6411 /* Read value is every time empty */
6412 containing_module
->prefs_changed_flags
|= prefs_set_string_value(pref
, "", pref_current
);
6417 if (!prefs_set_range_value_work(pref
, value
, return_range_errors
,
6418 &containing_module
->prefs_changed_flags
))
6419 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6422 case PREF_DECODE_AS_RANGE
:
6424 /* This is for backwards compatibility in case any of the preferences
6425 that shared the "Decode As" preference name and used to be PREF_RANGE
6426 are now applied directly to the Decode As funtionality */
6428 dissector_table_t sub_dissectors
;
6429 dissector_handle_t handle
;
6432 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
6433 return_range_errors
) != CVT_NO_ERROR
) {
6434 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6437 if (!ranges_are_equal(*pref
->varp
.range
, newrange
)) {
6438 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
6439 *pref
->varp
.range
= newrange
;
6440 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6442 const char* table_name
= prefs_get_dissector_table(pref
);
6443 sub_dissectors
= find_dissector_table(table_name
);
6444 if (sub_dissectors
!= NULL
) {
6445 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
6446 if (handle
!= NULL
) {
6447 /* Delete all of the old values from the dissector table */
6448 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
6449 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
6450 dissector_delete_uint(table_name
, j
, handle
);
6451 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
6454 dissector_delete_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, handle
);
6455 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
6458 /* Add new values to the dissector table */
6459 for (i
= 0; i
< newrange
->nranges
; i
++) {
6460 for (j
= newrange
->ranges
[i
].low
; j
< newrange
->ranges
[i
].high
; j
++) {
6461 dissector_change_uint(table_name
, j
, handle
);
6462 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
6465 dissector_change_uint(table_name
, newrange
->ranges
[i
].high
, handle
);
6466 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(newrange
->ranges
[i
].high
), NULL
, NULL
);
6469 /* XXX - Do we save the decode_as_entries file here? */
6473 wmem_free(wmem_epan_scope(), newrange
);
6480 if (!ws_hexstrtou32(value
, NULL
, &cval
))
6481 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6482 if ((pref
->varp
.colorp
->red
!= RED_COMPONENT(cval
)) ||
6483 (pref
->varp
.colorp
->green
!= GREEN_COMPONENT(cval
)) ||
6484 (pref
->varp
.colorp
->blue
!= BLUE_COMPONENT(cval
))) {
6485 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6486 pref
->varp
.colorp
->red
= RED_COMPONENT(cval
);
6487 pref
->varp
.colorp
->green
= GREEN_COMPONENT(cval
);
6488 pref
->varp
.colorp
->blue
= BLUE_COMPONENT(cval
);
6494 return pref
->custom_cbs
.set_cb(pref
, value
, &containing_module
->prefs_changed_flags
);
6496 case PREF_STATIC_TEXT
:
6498 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6500 /* There's no point in setting the TCP sequence override
6501 * value from the command line, because the pref is different
6502 * for each frame and reset to the default (0) for each new
6510 return PREFS_SET_OK
;
6516 } write_gui_pref_arg_t
;
6519 prefs_pref_type_name(pref_t
*pref
)
6521 const char *type_name
= "[Unknown]";
6525 return type_name
; /* ...or maybe assert? */
6530 if (IS_PREF_OBSOLETE(type
)) {
6531 type_name
= "Obsolete";
6533 RESET_PREF_OBSOLETE(type
);
6539 switch (pref
->info
.base
) {
6542 type_name
= "Decimal";
6546 type_name
= "Octal";
6550 type_name
= "Hexadecimal";
6556 type_name
= "Boolean";
6560 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6561 type_name
= "Choice";
6565 type_name
= "String";
6568 case PREF_SAVE_FILENAME
:
6569 case PREF_OPEN_FILENAME
:
6570 type_name
= "Filename";
6574 type_name
= "Directory";
6578 type_name
= "Range";
6582 type_name
= "Color";
6586 if (pref
->custom_cbs
.type_name_cb
)
6587 return pref
->custom_cbs
.type_name_cb();
6588 type_name
= "Custom";
6591 case PREF_DECODE_AS_RANGE
:
6592 type_name
= "Range (for Decode As)";
6595 case PREF_STATIC_TEXT
:
6596 type_name
= "Static text";
6604 type_name
= "Password";
6607 case PREF_DISSECTOR
:
6608 type_name
= "Dissector";
6615 prefs_get_effect_flags(pref_t
*pref
)
6620 return pref
->effect_flags
;
6624 prefs_set_effect_flags(pref_t
*pref
, unsigned int flags
)
6628 ws_error("Setting \"%s\" preference effect flags to 0", pref
->name
);
6630 pref
->effect_flags
= flags
;
6635 prefs_set_effect_flags_by_name(module_t
* module
, const char *pref
, unsigned int flags
)
6637 prefs_set_effect_flags(prefs_find_preference(module
, pref
), flags
);
6641 prefs_get_module_effect_flags(module_t
* module
)
6646 return module
->effect_flags
;
6650 prefs_set_module_effect_flags(module_t
* module
, unsigned int flags
)
6652 if (module
!= NULL
) {
6654 ws_error("Setting module \"%s\" preference effect flags to 0", module
->name
);
6656 module
->effect_flags
= flags
;
6661 prefs_pref_type_description(pref_t
*pref
)
6663 const char *type_desc
= "An unknown preference type";
6667 return ws_strdup_printf("%s.", type_desc
); /* ...or maybe assert? */
6672 if (IS_PREF_OBSOLETE(type
)) {
6673 type_desc
= "An obsolete preference";
6675 RESET_PREF_OBSOLETE(type
);
6681 switch (pref
->info
.base
) {
6684 type_desc
= "A decimal number";
6688 type_desc
= "An octal number";
6692 type_desc
= "A hexadecimal number";
6698 type_desc
= "true or false (case-insensitive)";
6702 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6704 const enum_val_t
*enum_valp
= pref
->info
.enum_info
.enumvals
;
6705 GString
*enum_str
= g_string_new("One of: ");
6706 GString
*desc_str
= g_string_new("\nEquivalently, one of: ");
6707 bool distinct
= false;
6708 while (enum_valp
->name
!= NULL
) {
6709 g_string_append(enum_str
, enum_valp
->name
);
6710 g_string_append(desc_str
, enum_valp
->description
);
6711 if (g_strcmp0(enum_valp
->name
, enum_valp
->description
) != 0) {
6715 if (enum_valp
->name
!= NULL
) {
6716 g_string_append(enum_str
, ", ");
6717 g_string_append(desc_str
, ", ");
6721 g_string_append(enum_str
, desc_str
->str
);
6723 g_string_free(desc_str
, TRUE
);
6724 g_string_append(enum_str
, "\n(case-insensitive).");
6725 return g_string_free(enum_str
, FALSE
);
6729 type_desc
= "A string";
6732 case PREF_SAVE_FILENAME
:
6733 case PREF_OPEN_FILENAME
:
6734 type_desc
= "A path to a file";
6738 type_desc
= "A path to a directory";
6743 type_desc
= "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
6749 type_desc
= "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
6754 if (pref
->custom_cbs
.type_description_cb
)
6755 return pref
->custom_cbs
.type_description_cb();
6756 type_desc
= "A custom value";
6759 case PREF_DECODE_AS_RANGE
:
6760 type_desc
= "A string denoting an positive integer range for Decode As";
6763 case PREF_STATIC_TEXT
:
6764 type_desc
= "[Static text]";
6768 type_desc
= "Configuration data stored in its own file";
6772 type_desc
= "Password (never stored on disk)";
6775 case PREF_DISSECTOR
:
6776 type_desc
= "A dissector name";
6782 return g_strdup(type_desc
);
6786 prefs_pref_is_default(pref_t
*pref
)
6789 if (!pref
) return false;
6792 if (IS_PREF_OBSOLETE(type
)) {
6795 RESET_PREF_OBSOLETE(type
);
6801 if (pref
->default_val
.uint
== *pref
->varp
.uint
)
6806 if (pref
->default_val
.boolval
== *pref
->varp
.boolp
)
6811 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6812 if (pref
->default_val
.enumval
== *pref
->varp
.enump
)
6817 case PREF_SAVE_FILENAME
:
6818 case PREF_OPEN_FILENAME
:
6821 case PREF_DISSECTOR
:
6822 if (!(g_strcmp0(pref
->default_val
.string
, *pref
->varp
.string
)))
6826 case PREF_DECODE_AS_RANGE
:
6829 if ((ranges_are_equal(pref
->default_val
.range
, *pref
->varp
.range
)))
6836 if ((pref
->default_val
.color
.red
== pref
->varp
.colorp
->red
) &&
6837 (pref
->default_val
.color
.green
== pref
->varp
.colorp
->green
) &&
6838 (pref
->default_val
.color
.blue
== pref
->varp
.colorp
->blue
))
6844 return pref
->custom_cbs
.is_default_cb(pref
);
6846 case PREF_STATIC_TEXT
:
6849 /* ws_assert_not_reached(); */
6856 prefs_pref_to_str(pref_t
*pref
, pref_source_t source
) {
6857 const char *pref_text
= "[Unknown]";
6858 void *valp
; /* pointer to preference value */
6859 color_t
*pref_color
;
6860 char *tmp_value
, *ret_value
;
6864 return g_strdup(pref_text
);
6869 valp
= &pref
->default_val
;
6870 /* valp = &boolval, &enumval, etc. are implied by union property */
6871 pref_color
= &pref
->default_val
.color
;
6874 valp
= &pref
->stashed_val
;
6875 /* valp = &boolval, &enumval, etc. are implied by union property */
6876 pref_color
= &pref
->stashed_val
.color
;
6879 valp
= pref
->varp
.uint
;
6880 /* valp = boolval, enumval, etc. are implied by union property */
6881 pref_color
= pref
->varp
.colorp
;
6884 return g_strdup(pref_text
);
6888 if (IS_PREF_OBSOLETE(type
)) {
6889 pref_text
= "[Obsolete]";
6891 RESET_PREF_OBSOLETE(type
);
6898 unsigned pref_uint
= *(unsigned *) valp
;
6899 switch (pref
->info
.base
) {
6902 return ws_strdup_printf("%u", pref_uint
);
6905 return ws_strdup_printf("%#o", pref_uint
);
6908 return ws_strdup_printf("%#x", pref_uint
);
6914 return g_strdup((*(bool *) valp
) ? "TRUE" : "FALSE");
6917 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6919 int pref_enumval
= *(int *) valp
;
6920 const enum_val_t
*enum_valp
= pref
->info
.enum_info
.enumvals
;
6922 * TODO - We write the "description" value, because the "name" values
6923 * weren't validated to be command line friendly until 5.0, and a few
6924 * of them had to be changed. This allows older versions of Wireshark
6925 * to read preferences that they supported, as we supported either
6926 * the short name or the description when reading the preference files
6927 * or an "-o" option. Once 5.0 is the oldest supported version, switch
6928 * to writing the name below.
6930 while (enum_valp
->name
!= NULL
) {
6931 if (enum_valp
->value
== pref_enumval
)
6932 return g_strdup(enum_valp
->description
);
6939 case PREF_SAVE_FILENAME
:
6940 case PREF_OPEN_FILENAME
:
6943 case PREF_DISSECTOR
:
6944 return g_strdup(*(const char **) valp
);
6946 case PREF_DECODE_AS_RANGE
:
6948 /* Convert wmem to g_alloc memory */
6949 tmp_value
= range_convert_range(NULL
, *(range_t
**) valp
);
6950 ret_value
= g_strdup(tmp_value
);
6951 wmem_free(NULL
, tmp_value
);
6955 return ws_strdup_printf("%02x%02x%02x",
6956 (pref_color
->red
* 255 / 65535),
6957 (pref_color
->green
* 255 / 65535),
6958 (pref_color
->blue
* 255 / 65535));
6961 if (pref
->custom_cbs
.to_str_cb
)
6962 return pref
->custom_cbs
.to_str_cb(pref
, source
== pref_default
? true : false);
6963 pref_text
= "[Custom]";
6966 case PREF_STATIC_TEXT
:
6967 pref_text
= "[Static text]";
6972 uat_t
*uat
= pref
->varp
.uat
;
6973 if (uat
&& uat
->filename
)
6974 return ws_strdup_printf("[Managed in the file \"%s\"]", uat
->filename
);
6976 pref_text
= "[Managed in an unknown file]";
6983 return g_strdup(pref_text
);
6987 * Write out a single dissector preference.
6990 write_pref(void *data
, void *user_data
)
6992 pref_t
*pref
= (pref_t
*)data
;
6993 write_pref_arg_t
*arg
= (write_pref_arg_t
*)user_data
;
7000 if (IS_PREF_OBSOLETE(type
)) {
7002 * This preference is no longer supported; it's not a
7003 * real preference, so we don't write it out (i.e., we
7004 * treat it as if it weren't found in the list of
7005 * preferences, and we weren't called in the first place).
7009 RESET_PREF_OBSOLETE(type
);
7014 case PREF_STATIC_TEXT
:
7016 /* Nothing to do; don't bother printing the description */
7018 case PREF_DECODE_AS_RANGE
:
7019 /* Data is saved through Decode As mechanism and not part of preferences file */
7021 case PREF_PROTO_TCP_SNDAMB_ENUM
:
7022 /* Not written to the preference file because the override is only
7023 * for the lifetime of the capture file and there is no single
7031 if (pref
->type
!= PREF_CUSTOM
|| pref
->custom_cbs
.type_name_cb() != NULL
) {
7033 * The prefix will either be the module name or the parent
7034 * name if it's a subtree
7036 const char *name_prefix
= (arg
->module
->name
!= NULL
) ? arg
->module
->name
: arg
->module
->parent
->name
;
7037 char *type_desc
, *pref_text
;
7038 const char * def_prefix
= prefs_pref_is_default(pref
) ? "#" : "";
7040 if (pref
->type
== PREF_CUSTOM
)
7041 fprintf(arg
->pf
, "\n# %s", pref
->custom_cbs
.type_name_cb());
7042 fprintf(arg
->pf
, "\n");
7043 if (pref
->description
&&
7044 (g_ascii_strncasecmp(pref
->description
,"", 2) != 0)) {
7045 if (pref
->type
!= PREF_CUSTOM
) {
7046 /* We get duplicate lines otherwise. */
7048 desc_lines
= g_strsplit(pref
->description
, "\n", 0);
7049 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7050 fprintf(arg
->pf
, "# %s\n", desc_lines
[i
]);
7052 g_strfreev(desc_lines
);
7055 fprintf(arg
->pf
, "# No description\n");
7058 type_desc
= prefs_pref_type_description(pref
);
7059 desc_lines
= g_strsplit(type_desc
, "\n", 0);
7060 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7061 fprintf(arg
->pf
, "# %s\n", desc_lines
[i
]);
7063 g_strfreev(desc_lines
);
7066 pref_text
= prefs_pref_to_str(pref
, pref_current
);
7067 fprintf(arg
->pf
, "%s%s.%s: ", def_prefix
, name_prefix
, pref
->name
);
7068 if (pref
->type
!= PREF_PASSWORD
)
7070 desc_lines
= g_strsplit(pref_text
, "\n", 0);
7071 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7072 fprintf(arg
->pf
, "%s%s\n", i
== 0 ? "" : def_prefix
, desc_lines
[i
]);
7075 fprintf(arg
->pf
, "\n");
7076 g_strfreev(desc_lines
);
7078 /* We never store password value */
7079 fprintf(arg
->pf
, "\n");
7087 count_non_uat_pref(void *data
, void *user_data
)
7089 pref_t
*pref
= (pref_t
*)data
;
7090 int *arg
= (int *)user_data
;
7096 case PREF_DECODE_AS_RANGE
:
7097 case PREF_PROTO_TCP_SNDAMB_ENUM
:
7098 //These types are not written in preference file
7106 static int num_non_uat_prefs(module_t
*module
)
7110 g_list_foreach(module
->prefs
, count_non_uat_pref
, &num
);
7116 * Write out all preferences for a module.
7119 write_module_prefs(module_t
*module
, void *user_data
)
7121 write_gui_pref_arg_t
*gui_pref_arg
= (write_gui_pref_arg_t
*)user_data
;
7122 write_pref_arg_t arg
;
7124 /* The GUI module needs to be explicitly called out so it
7125 can be written out of order */
7126 if ((module
== gui_module
) && (gui_pref_arg
->is_gui_module
!= true))
7129 /* Write a header for the main modules and GUI sub-modules */
7130 if (((module
->parent
== NULL
) || (module
->parent
== gui_module
)) &&
7131 ((prefs_module_has_submodules(module
)) ||
7132 (num_non_uat_prefs(module
) > 0) ||
7133 (module
->name
== NULL
))) {
7134 if ((module
->name
== NULL
) && (module
->parent
!= NULL
)) {
7135 fprintf(gui_pref_arg
->pf
, "\n####### %s: %s ########\n", module
->parent
->title
, module
->title
);
7137 fprintf(gui_pref_arg
->pf
, "\n####### %s ########\n", module
->title
);
7141 arg
.module
= module
;
7142 arg
.pf
= gui_pref_arg
->pf
;
7143 g_list_foreach(arg
.module
->prefs
, write_pref
, &arg
);
7145 if (prefs_module_has_submodules(module
))
7146 return prefs_modules_foreach_submodules(module
, write_module_prefs
, user_data
);
7153 write_registry(void)
7160 ret
= RegCreateKeyExA(HKEY_CURRENT_USER
, REG_HKCU_WIRESHARK_KEY
, 0, NULL
,
7161 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
,
7163 if (ret
!= ERROR_SUCCESS
) {
7164 ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY
": 0x%lx", ret
);
7168 data
= ws_log_console_open
;
7169 data_size
= sizeof(DWORD
);
7170 ret
= RegSetValueExA(hTestKey
, LOG_HKCU_CONSOLE_OPEN
, 0, REG_DWORD
, (const BYTE
*)&data
, data_size
);
7171 if (ret
== ERROR_SUCCESS
) {
7172 ws_noisy("Wrote "LOG_HKCU_CONSOLE_OPEN
" to Windows registry: 0x%lu", data
);
7175 ws_noisy("Error writing registry key "LOG_HKCU_CONSOLE_OPEN
": 0x%lx", ret
);
7178 RegCloseKey(hTestKey
);
7182 /* Write out "prefs" to the user's preferences file, and return 0.
7184 If the preferences file path is NULL, write to stdout.
7186 If we got an error, stuff a pointer to the path of the preferences file
7187 into "*pf_path_return", and return the errno. */
7189 write_prefs(char **pf_path_return
)
7193 write_gui_pref_arg_t write_gui_pref_info
;
7195 /* Needed for "-G defaultprefs" */
7203 * - Split output lines longer than MAX_VAL_LEN
7204 * - Create a function for the preference directory check/creation
7205 * so that duplication can be avoided with filter.c
7208 if (pf_path_return
!= NULL
) {
7209 pf_path
= get_persconffile_path(PF_NAME
, true);
7210 if ((pf
= ws_fopen(pf_path
, "w")) == NULL
) {
7211 *pf_path_return
= pf_path
;
7220 * If the preferences file is being written, be sure to write UAT files
7221 * first that were migrated from the preferences file.
7223 if (pf_path_return
!= NULL
) {
7224 if (prefs
.filter_expressions_old
) {
7226 prefs
.filter_expressions_old
= false;
7227 if (!uat_save(uat_get_table_by_name("Display expressions"), &err
)) {
7228 ws_warning("Unable to save Display expressions: %s", err
);
7233 module_t
*extcap_module
= prefs_find_module("extcap");
7234 if (extcap_module
&& !prefs
.capture_no_extcap
) {
7235 char *ext_path
= get_persconffile_path("extcap.cfg", true);
7237 if ((extf
= ws_fopen(ext_path
, "w")) == NULL
) {
7238 if (errno
!= EISDIR
) {
7239 ws_warning("Unable to save extcap preferences \"%s\": %s",
7240 ext_path
, g_strerror(errno
));
7246 fputs("# Extcap configuration file for Wireshark " VERSION
".\n"
7248 "# This file is regenerated each time preferences are saved within\n"
7249 "# Wireshark. Making manual changes should be safe, however.\n"
7250 "# Preferences that have been commented out have not been\n"
7251 "# changed from their default value.\n", extf
);
7253 write_gui_pref_info
.pf
= extf
;
7254 write_gui_pref_info
.is_gui_module
= false;
7256 write_module_prefs(extcap_module
, &write_gui_pref_info
);
7263 fputs("# Configuration file for Wireshark " VERSION
".\n"
7265 "# This file is regenerated each time preferences are saved within\n"
7266 "# Wireshark. Making manual changes should be safe, however.\n"
7267 "# Preferences that have been commented out have not been\n"
7268 "# changed from their default value.\n", pf
);
7271 * For "backwards compatibility" the GUI module is written first as it's
7272 * at the top of the file. This is followed by all modules that can't
7273 * fit into the preferences read/write API. Finally the remaining modules
7274 * are written in alphabetical order (including of course the protocol preferences)
7276 write_gui_pref_info
.pf
= pf
;
7277 write_gui_pref_info
.is_gui_module
= true;
7279 write_module_prefs(gui_module
, &write_gui_pref_info
);
7281 write_gui_pref_info
.is_gui_module
= false;
7282 prefs_modules_foreach_submodules(NULL
, write_module_prefs
, &write_gui_pref_info
);
7286 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
7287 an error indication, or maybe write to a new preferences file and
7288 rename that file on top of the old one only if there are not I/O
7293 /** The col_list is only partly managed by the custom preference API
7294 * because its data is shared between multiple preferences, so
7298 free_col_info(GList
*list
)
7301 GList
*list_head
= list
;
7303 while (list
!= NULL
) {
7304 cfmt
= (fmt_data
*)list
->data
;
7306 g_free(cfmt
->title
);
7307 g_free(cfmt
->custom_fields
);
7309 list
= g_list_next(list
);
7311 g_list_free(list_head
);
7320 * indent-tabs-mode: nil
7323 * ex: set shiftwidth=4 tabstop=8 expandtab:
7324 * :indentSize=4:tabSize=8:noTabs=true: