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/application_flavor.h>
27 #include <wsutil/filesystem.h>
28 #include <epan/addr_resolv.h>
29 #include <epan/oids.h>
30 #include <epan/maxmind_db.h>
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/proto.h>
34 #include <epan/strutil.h>
35 #include <epan/column.h>
36 #include <epan/decode_as.h>
37 #include <ui/capture_opts.h>
38 #include <wsutil/file_util.h>
39 #include <wsutil/report_message.h>
40 #include <wsutil/wslog.h>
41 #include <wsutil/ws_assert.h>
42 #include <wsutil/array.h>
44 #include <epan/prefs-int.h>
45 #include <epan/uat-int.h>
47 #include "epan/filter_expressions.h"
49 #include "epan/wmem_scopes.h"
50 #include <epan/stats_tree.h>
52 #define REG_HKCU_WIRESHARK_KEY "Software\\Wireshark"
57 typedef struct pref_module_alias
{
58 const char *name
; /**< name of module alias */
59 module_t
*module
; /**< module for which it's an alias */
62 /* Internal functions */
63 static module_t
*find_subtree(module_t
*parent
, const char *tilte
);
64 static module_t
*prefs_register_module_or_subtree(module_t
*parent
,
65 const char *name
, const char *title
, const char *description
, const char *help
,
66 bool is_subtree
, void (*apply_cb
)(void), bool use_gui
);
67 static void prefs_register_modules(void);
68 static module_t
*prefs_find_module_alias(const char *name
);
69 static prefs_set_pref_e
set_pref(char*, const char*, void *, bool);
70 static void free_col_info(GList
*);
71 static void pre_init_prefs(void);
72 static bool prefs_is_column_visible(const char *cols_hidden
, int col
);
73 static bool prefs_is_column_fmt_visible(const char *cols_hidden
, fmt_data
*cfmt
);
74 static unsigned prefs_module_list_foreach(wmem_tree_t
*module_list
, module_cb callback
,
75 void *user_data
, bool skip_obsolete
);
76 static int find_val_for_string(const char *needle
, const enum_val_t
*haystack
, int default_value
);
78 #define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
79 #define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
80 #define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
82 #define PF_NAME "preferences"
83 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
85 static bool prefs_initialized
;
86 static char *gpf_path
;
87 static char *cols_hidden_list
;
88 static char *cols_hidden_fmt_list
;
89 static bool gui_theme_is_dark
;
92 * XXX - variables to allow us to attempt to interpret the first
93 * "mgcp.{tcp,udp}.port" in a preferences file as
94 * "mgcp.{tcp,udp}.gateway_port" and the second as
95 * "mgcp.{tcp,udp}.callagent_port".
97 static int mgcp_tcp_port_count
;
98 static int mgcp_udp_port_count
;
102 static const enum_val_t gui_console_open_type
[] = {
103 {"NEVER", "NEVER", LOG_CONSOLE_OPEN_NEVER
},
104 {"AUTOMATIC", "AUTOMATIC", LOG_CONSOLE_OPEN_AUTO
},
105 {"ALWAYS", "ALWAYS", LOG_CONSOLE_OPEN_ALWAYS
},
109 static const enum_val_t gui_version_placement_type
[] = {
110 {"WELCOME", "WELCOME", version_welcome_only
},
111 {"TITLE", "TITLE", version_title_only
},
112 {"BOTH", "BOTH", version_both
},
113 {"NEITHER", "NEITHER", version_neither
},
117 static const enum_val_t gui_fileopen_style
[] = {
118 {"LAST_OPENED", "LAST_OPENED", FO_STYLE_LAST_OPENED
},
119 {"SPECIFIED", "SPECIFIED", FO_STYLE_SPECIFIED
},
120 {"CWD", "CWD", FO_STYLE_CWD
},
124 static const enum_val_t gui_toolbar_style
[] = {
125 {"ICONS", "ICONS", 0},
131 static const enum_val_t gui_layout_content
[] = {
133 {"PLIST", "PLIST", 1},
134 {"PDETAILS", "PDETAILS", 2},
135 {"PBYTES", "PBYTES", 3},
136 {"PDIAGRAM", "PDIAGRAM", 4},
140 static const enum_val_t gui_packet_dialog_layout
[] = {
141 {"vertical", "Vertical (Stacked)", layout_vertical
},
142 {"horizontal", "Horizontal (Side-by-side)", layout_horizontal
},
146 static const enum_val_t gui_update_channel
[] = {
147 {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT
},
148 {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE
},
152 static const enum_val_t gui_selection_style
[] = {
153 {"DEFAULT", "DEFAULT", COLOR_STYLE_DEFAULT
},
154 {"FLAT", "FLAT", COLOR_STYLE_FLAT
},
155 {"GRADIENT", "GRADIENT", COLOR_STYLE_GRADIENT
},
159 static const enum_val_t gui_color_scheme
[] = {
160 {"system", "System Default", COLOR_SCHEME_DEFAULT
},
161 {"light", "Light Mode", COLOR_SCHEME_LIGHT
},
162 {"dark", "Dark Mode", COLOR_SCHEME_DARK
},
166 static const enum_val_t gui_packet_list_copy_format_options_for_keyboard_shortcut
[] = {
167 {"TEXT", "Text", COPY_FORMAT_TEXT
},
168 {"CSV", "CSV", COPY_FORMAT_CSV
},
169 {"YAML", "YAML", COPY_FORMAT_YAML
},
170 {"HTML", "HTML", COPY_FORMAT_HTML
},
174 /* None : Historical behavior, no deinterlacing */
175 #define CONV_DEINT_CHOICE_NONE 0
176 /* MI : MAC & Interface */
177 #define CONV_DEINT_CHOICE_MI CONV_DEINT_KEY_MAC + CONV_DEINT_KEY_INTERFACE
178 /* VM : VLAN & MAC */
179 #define CONV_DEINT_CHOICE_VM CONV_DEINT_KEY_VLAN + CONV_DEINT_KEY_MAC
180 /* VMI : VLAN & MAC & Interface */
181 #define CONV_DEINT_CHOICE_VMI CONV_DEINT_KEY_VLAN + CONV_DEINT_KEY_MAC + CONV_DEINT_KEY_INTERFACE
183 static const enum_val_t conv_deint_options
[] = {
184 {"NONE", "NONE", CONV_DEINT_CHOICE_NONE
},
185 {".MI", ".MI", CONV_DEINT_CHOICE_MI
},
186 {"VM.", "VM.", CONV_DEINT_CHOICE_VM
},
187 {"VMI", "VMI", CONV_DEINT_CHOICE_VMI
},
191 static const enum_val_t abs_time_format_options
[] = {
192 {"NEVER", "Never", ABS_TIME_ASCII_NEVER
},
193 {"TREE", "Protocol tree only", ABS_TIME_ASCII_TREE
},
194 {"COLUMN", "Protocol tree and columns", ABS_TIME_ASCII_COLUMN
},
195 {"ALWAYS", "Always", ABS_TIME_ASCII_ALWAYS
},
199 static int num_capture_cols
= 7;
200 static const char *capture_cols
[7] = {
209 #define CAPTURE_COL_TYPE_DESCRIPTION \
210 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
212 static const enum_val_t gui_packet_list_elide_mode
[] = {
213 {"LEFT", "LEFT", ELIDE_LEFT
},
214 {"RIGHT", "RIGHT", ELIDE_RIGHT
},
215 {"MIDDLE", "MIDDLE", ELIDE_MIDDLE
},
216 {"NONE", "NONE", ELIDE_NONE
},
220 /** Struct to hold preference data */
222 const char *name
; /**< name of preference */
223 const char *title
; /**< title to use in GUI */
224 const char *description
; /**< human-readable description of preference */
225 int ordinal
; /**< ordinal number of this preference */
226 int type
; /**< type of that preference */
227 unsigned int effect_flags
; /**< Flags of types effected by preference (PREF_TYPE_DISSECTION, PREF_EFFECT_CAPTURE, etc).
228 Flags must be non-zero to ensure saving to disk */
229 union { /* The Qt preference code assumes that these will all be pointers (and unique) */
235 struct epan_uat
* uat
;
238 } varp
; /**< pointer to variable storing the value */
247 } stashed_val
; /**< original value, when editing from the GUI */
256 } default_val
; /**< the default value of the preference */
258 unsigned base
; /**< input/output base, for PREF_UINT */
259 uint32_t max_value
; /**< maximum value of a range */
261 const enum_val_t
*enumvals
; /**< list of name & values */
262 bool radio_buttons
; /**< true if it should be shown as
263 radio buttons rather than as an
264 option menu or combo box in
265 the preferences tab */
266 } enum_info
; /**< for PREF_ENUM */
267 } info
; /**< display/text file information */
268 struct pref_custom_cbs custom_cbs
; /**< for PREF_CUSTOM */
269 const char *dissector_table
; /**< for PREF_DECODE_AS_RANGE */
270 const char *dissector_desc
; /**< for PREF_DECODE_AS_RANGE */
273 const char* prefs_get_description(pref_t
*pref
)
275 return pref
->description
;
278 const char* prefs_get_title(pref_t
*pref
)
283 int prefs_get_type(pref_t
*pref
)
288 const char* prefs_get_name(pref_t
*pref
)
293 uint32_t prefs_get_max_value(pref_t
*pref
)
295 return pref
->info
.max_value
;
298 const char* prefs_get_dissector_table(pref_t
*pref
)
300 return pref
->dissector_table
;
303 static const char* prefs_get_dissector_description(pref_t
*pref
)
305 return pref
->dissector_desc
;
309 * List of all modules with preference settings.
311 static wmem_tree_t
*prefs_modules
;
314 * List of all modules that should show up at the top level of the
315 * tree in the preference dialog box.
317 static wmem_tree_t
*prefs_top_level_modules
;
320 * List of aliases for modules.
322 static wmem_tree_t
*prefs_module_aliases
;
324 /** Sets up memory used by proto routines. Called at program startup */
328 memset(&prefs
, 0, sizeof(prefs
));
329 prefs_modules
= wmem_tree_new(wmem_epan_scope());
330 prefs_top_level_modules
= wmem_tree_new(wmem_epan_scope());
331 prefs_module_aliases
= wmem_tree_new(wmem_epan_scope());
335 * Free the strings for a string-like preference.
338 free_string_like_preference(pref_t
*pref
)
340 g_free(*pref
->varp
.string
);
341 *pref
->varp
.string
= NULL
;
342 g_free(pref
->default_val
.string
);
343 pref
->default_val
.string
= NULL
;
347 free_pref(void *data
, void *user_data _U_
)
349 pref_t
*pref
= (pref_t
*)data
;
350 int type
= pref
->type
;
352 /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
353 RESET_PREF_OBSOLETE(type
);
359 case PREF_STATIC_TEXT
:
364 case PREF_SAVE_FILENAME
:
365 case PREF_OPEN_FILENAME
:
369 free_string_like_preference(pref
);
372 case PREF_DECODE_AS_RANGE
:
373 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
374 *pref
->varp
.range
= NULL
;
375 wmem_free(wmem_epan_scope(), pref
->default_val
.range
);
376 pref
->default_val
.range
= NULL
;
379 if (strcmp(pref
->name
, "columns") == 0)
380 pref
->stashed_val
.boolval
= true;
381 pref
->custom_cbs
.free_cb(pref
);
383 /* non-generic preferences */
384 case PREF_PROTO_TCP_SNDAMB_ENUM
:
392 free_module_prefs(module_t
*module
, void *data _U_
)
395 g_list_foreach(module
->prefs
, free_pref
, NULL
);
396 g_list_free(module
->prefs
);
398 module
->prefs
= NULL
;
399 module
->numprefs
= 0;
400 if (module
->submodules
) {
401 prefs_module_list_foreach(module
->submodules
, free_module_prefs
, NULL
, false);
403 /* We don't free the actual module: its submodules pointer points to
404 a wmem_tree and the module itself is stored in a wmem_tree
410 /** Frees memory used by proto routines. Called at program shutdown */
414 /* This isn't strictly necessary since we're exiting anyway, but let's
415 * do what clean up we can.
417 prefs_module_list_foreach(prefs_modules
, free_module_prefs
, NULL
, false);
422 /* Shut down mmdbresolve */
423 maxmind_db_pref_cleanup();
425 g_free(prefs
.saved_at_version
);
430 void prefs_set_gui_theme_is_dark(bool is_dark
)
432 gui_theme_is_dark
= is_dark
;
436 * Register a module that will have preferences.
437 * Specify the module under which to register it or NULL to register it
438 * at the top level, the name used for the module in the preferences file,
439 * the title used in the tab for it in a preferences dialog box, and a
440 * routine to call back when we apply the preferences.
443 prefs_register_module(module_t
*parent
, const char *name
, const char *title
,
444 const char *description
, const char *help
, void (*apply_cb
)(void),
447 return prefs_register_module_or_subtree(parent
, name
, title
, description
, help
,
448 false, apply_cb
, use_gui
);
452 prefs_deregister_module(module_t
*parent
, const char *name
, const char *title
)
454 /* Remove this module from the list of all modules */
455 module_t
*module
= (module_t
*)wmem_tree_remove_string(prefs_modules
, name
, WMEM_TREE_STRING_NOCASE
);
460 if (parent
== NULL
) {
461 /* Remove from top */
462 wmem_tree_remove_string(prefs_top_level_modules
, title
, WMEM_TREE_STRING_NOCASE
);
463 } else if (parent
->submodules
) {
464 /* Remove from parent */
465 wmem_tree_remove_string(parent
->submodules
, title
, WMEM_TREE_STRING_NOCASE
);
468 free_module_prefs(module
, NULL
);
469 wmem_free(wmem_epan_scope(), module
);
473 * Register a subtree that will have modules under it.
474 * Specify the module under which to register it or NULL to register it
475 * at the top level and the title used in the tab for it in a preferences
479 prefs_register_subtree(module_t
*parent
, const char *title
, const char *description
,
480 void (*apply_cb
)(void))
482 return prefs_register_module_or_subtree(parent
, NULL
, title
, description
, NULL
,
484 parent
? parent
->use_gui
: false);
488 prefs_register_module_or_subtree(module_t
*parent
, const char *name
,
489 const char *title
, const char *description
,
491 bool is_subtree
, void (*apply_cb
)(void),
496 /* this module may have been created as a subtree item previously */
497 if ((module
= find_subtree(parent
, title
))) {
498 /* the module is currently a subtree */
500 module
->apply_cb
= apply_cb
;
501 module
->description
= description
;
504 if (prefs_find_module(name
) == NULL
) {
505 wmem_tree_insert_string(prefs_modules
, name
, module
,
506 WMEM_TREE_STRING_NOCASE
);
512 module
= wmem_new(wmem_epan_scope(), module_t
);
514 module
->title
= title
;
515 module
->description
= description
;
517 module
->apply_cb
= apply_cb
;
518 module
->prefs
= NULL
; /* no preferences, to start */
519 module
->parent
= parent
;
520 module
->submodules
= NULL
; /* no submodules, to start */
521 module
->numprefs
= 0;
522 module
->prefs_changed_flags
= 0;
523 module
->obsolete
= false;
524 module
->use_gui
= use_gui
;
525 /* A module's preferences affects dissection unless otherwise told */
526 module
->effect_flags
= PREF_EFFECT_DISSECTION
;
529 * Do we have a module name?
533 /* Accept any letter case to conform with protocol names. ASN1 protocols
534 * don't use lower case names, so we can't require lower case. */
535 if (module_check_valid_name(name
, false) != '\0') {
536 ws_error("Preference module \"%s\" contains invalid characters", name
);
540 * Make sure there's not already a module with that
541 * name. Crash if there is, as that's an error in the
542 * code, and the code has to be fixed not to register
543 * more than one module with the same name.
545 * We search the list of all modules; the subtree stuff
546 * doesn't require preferences in subtrees to have names
547 * that reflect the subtree they're in (that would require
548 * protocol preferences to have a bogus "protocol.", or
549 * something such as that, to be added to all their names).
551 if (prefs_find_module(name
) != NULL
)
552 ws_error("Preference module \"%s\" is being registered twice", name
);
555 * Insert this module in the list of all modules.
557 wmem_tree_insert_string(prefs_modules
, name
, module
, WMEM_TREE_STRING_NOCASE
);
560 * This has no name, just a title; check to make sure it's a
561 * subtree, and crash if it's not.
564 ws_error("Preferences module with no name is being registered at the top level");
568 * Insert this module into the appropriate place in the display
571 if (parent
== NULL
) {
573 * It goes at the top.
575 wmem_tree_insert_string(prefs_top_level_modules
, title
, module
, WMEM_TREE_STRING_NOCASE
);
578 * It goes into the list for this module.
581 if (parent
->submodules
== NULL
)
582 parent
->submodules
= wmem_tree_new(wmem_epan_scope());
584 wmem_tree_insert_string(parent
->submodules
, title
, module
, WMEM_TREE_STRING_NOCASE
);
591 prefs_register_module_alias(const char *name
, module_t
*module
)
593 module_alias_t
*alias
;
596 * Accept any name that can occur in protocol names. We allow upper-case
597 * letters, to handle the Diameter dissector having used "Diameter" rather
598 * than "diameter" as its preference module name in the past.
600 * Crash if the name is invalid, as that's an error in the code, but the name
601 * can be used on the command line, and shouldn't require quoting, etc.
603 if (module_check_valid_name(name
, false) != '\0') {
604 ws_error("Preference module alias \"%s\" contains invalid characters", name
);
608 * Make sure there's not already an alias with that
609 * name. Crash if there is, as that's an error in the
610 * code, and the code has to be fixed not to register
611 * more than one alias with the same name.
613 * We search the list of all aliases.
615 if (prefs_find_module_alias(name
) != NULL
)
616 ws_error("Preference module alias \"%s\" is being registered twice", name
);
618 alias
= wmem_new(wmem_epan_scope(), module_alias_t
);
620 alias
->module
= module
;
623 * Insert this module in the list of all modules.
625 wmem_tree_insert_string(prefs_module_aliases
, name
, alias
, WMEM_TREE_STRING_NOCASE
);
629 * Register that a protocol has preferences.
631 module_t
*protocols_module
;
634 prefs_register_protocol(int id
, void (*apply_cb
)(void))
636 protocol_t
*protocol
;
639 * Have we yet created the "Protocols" subtree?
641 if (protocols_module
== NULL
) {
643 * No. Register Protocols subtree as well as any preferences
644 * for non-dissector modules.
647 prefs_register_modules();
649 protocol
= find_protocol_by_id(id
);
650 if (protocol
== NULL
)
651 ws_error("Protocol preferences being registered with an invalid protocol ID");
652 return prefs_register_module(protocols_module
,
653 proto_get_protocol_filter_name(id
),
654 proto_get_protocol_short_name(protocol
),
655 proto_get_protocol_name(id
), NULL
, apply_cb
, true);
659 prefs_deregister_protocol (int id
)
661 protocol_t
*protocol
= find_protocol_by_id(id
);
662 if (protocol
== NULL
)
663 ws_error("Protocol preferences being de-registered with an invalid protocol ID");
664 prefs_deregister_module (protocols_module
,
665 proto_get_protocol_filter_name(id
),
666 proto_get_protocol_short_name(protocol
));
670 prefs_register_protocol_subtree(const char *subtree
, int id
, void (*apply_cb
)(void))
672 protocol_t
*protocol
;
673 module_t
*subtree_module
;
674 module_t
*new_module
;
675 char *sep
= NULL
, *ptr
= NULL
, *orig
= NULL
;
678 * Have we yet created the "Protocols" subtree?
679 * XXX - can we just do this by registering Protocols/{subtree}?
682 if (protocols_module
== NULL
) {
684 * No. Register Protocols subtree as well as any preferences
685 * for non-dissector modules.
688 prefs_register_modules();
691 subtree_module
= protocols_module
;
694 /* take a copy of the buffer, orig keeps a base pointer while ptr
695 * walks through the string */
696 orig
= ptr
= g_strdup(subtree
);
698 while (ptr
&& *ptr
) {
700 if ((sep
= strchr(ptr
, '/')))
703 if (!(new_module
= find_subtree(subtree_module
, ptr
))) {
705 * There's no such module; create it, with the description
706 * being the name (if it's later registered explicitly
707 * with a description, that will override it).
709 ptr
= wmem_strdup(wmem_epan_scope(), ptr
);
710 new_module
= prefs_register_subtree(subtree_module
, ptr
, ptr
, NULL
);
713 subtree_module
= new_module
;
721 protocol
= find_protocol_by_id(id
);
722 if (protocol
== NULL
)
723 ws_error("Protocol subtree being registered with an invalid protocol ID");
724 return prefs_register_module(subtree_module
,
725 proto_get_protocol_filter_name(id
),
726 proto_get_protocol_short_name(protocol
),
727 proto_get_protocol_name(id
), NULL
, apply_cb
, true);
732 * Register that a protocol used to have preferences but no longer does,
733 * by creating an "obsolete" module for it.
736 prefs_register_protocol_obsolete(int id
)
739 protocol_t
*protocol
;
742 * Have we yet created the "Protocols" subtree?
744 if (protocols_module
== NULL
) {
746 * No. Register Protocols subtree as well as any preferences
747 * for non-dissector modules.
750 prefs_register_modules();
752 protocol
= find_protocol_by_id(id
);
753 if (protocol
== NULL
)
754 ws_error("Protocol being registered with an invalid protocol ID");
755 module
= prefs_register_module(protocols_module
,
756 proto_get_protocol_filter_name(id
),
757 proto_get_protocol_short_name(protocol
),
758 proto_get_protocol_name(id
), NULL
, NULL
, true);
759 module
->obsolete
= true;
764 * Register that a statistical tap has preferences.
766 * "name" is a name for the tap to use on the command line with "-o"
767 * and in preference files.
769 * "title" is a short human-readable name for the tap.
771 * "description" is a longer human-readable description of the tap.
773 module_t
*stats_module
;
776 prefs_register_stat(const char *name
, const char *title
,
777 const char *description
, void (*apply_cb
)(void))
780 * Have we yet created the "Statistics" subtree?
782 if (stats_module
== NULL
) {
784 * No. Register Statistics subtree as well as any preferences
785 * for non-dissector modules.
788 prefs_register_modules();
791 return prefs_register_module(stats_module
, name
, title
, description
, NULL
,
796 * Register that a codec has preferences.
798 * "name" is a name for the codec to use on the command line with "-o"
799 * and in preference files.
801 * "title" is a short human-readable name for the codec.
803 * "description" is a longer human-readable description of the codec.
805 module_t
*codecs_module
;
808 prefs_register_codec(const char *name
, const char *title
,
809 const char *description
, void (*apply_cb
)(void))
812 * Have we yet created the "Codecs" subtree?
814 if (codecs_module
== NULL
) {
816 * No. Register Codecs subtree as well as any preferences
817 * for non-dissector modules.
820 prefs_register_modules();
823 return prefs_register_module(codecs_module
, name
, title
, description
, NULL
,
828 prefs_find_module(const char *name
)
830 return (module_t
*)wmem_tree_lookup_string(prefs_modules
, name
, WMEM_TREE_STRING_NOCASE
);
834 find_subtree(module_t
*parent
, const char *name
)
836 return (module_t
*)wmem_tree_lookup_string(parent
? parent
->submodules
: prefs_top_level_modules
, name
, WMEM_TREE_STRING_NOCASE
);
840 * Call a callback function, with a specified argument, for each module
841 * in a list of modules. If the list is NULL, searches the top-level
842 * list in the display tree of modules. If any callback returns a
843 * non-zero value, we stop and return that value, otherwise we
846 * Normally "obsolete" modules are ignored; their sole purpose is to allow old
847 * preferences for dissectors that no longer have preferences to be
848 * silently ignored in preference files. Does not ignore subtrees,
849 * as this can be used when walking the display tree of modules.
860 call_foreach_cb(const void *key _U_
, void *value
, void *data
)
862 module_t
*module
= (module_t
*)value
;
863 call_foreach_t
*call_data
= (call_foreach_t
*)data
;
865 if (!call_data
->skip_obsolete
|| !module
->obsolete
)
866 call_data
->ret
= (*call_data
->callback
)(module
, call_data
->user_data
);
868 return (call_data
->ret
!= 0);
872 prefs_module_list_foreach(wmem_tree_t
*module_list
, module_cb callback
,
873 void *user_data
, bool skip_obsolete
)
875 call_foreach_t call_data
;
877 if (module_list
== NULL
)
878 module_list
= prefs_top_level_modules
;
880 call_data
.callback
= callback
;
881 call_data
.user_data
= user_data
;
883 call_data
.skip_obsolete
= skip_obsolete
;
884 wmem_tree_foreach(module_list
, call_foreach_cb
, &call_data
);
885 return call_data
.ret
;
889 * Returns true if module has any submodules
892 prefs_module_has_submodules(module_t
*module
)
894 if (module
->submodules
== NULL
) {
898 if (wmem_tree_is_empty(module
->submodules
)) {
906 * Call a callback function, with a specified argument, for each module
907 * in the list of all modules. (This list does not include subtrees.)
909 * Ignores "obsolete" modules; their sole purpose is to allow old
910 * preferences for dissectors that no longer have preferences to be
911 * silently ignored in preference files.
914 prefs_modules_foreach(module_cb callback
, void *user_data
)
916 return prefs_module_list_foreach(prefs_modules
, callback
, user_data
, true);
920 * Call a callback function, with a specified argument, for each submodule
921 * of specified modules. If the module is NULL, goes through the top-level
922 * list in the display tree of modules.
924 * Ignores "obsolete" modules; their sole purpose is to allow old
925 * preferences for dissectors that no longer have preferences to be
926 * silently ignored in preference files. Does not ignore subtrees,
927 * as this can be used when walking the display tree of modules.
930 prefs_modules_foreach_submodules(module_t
*module
, module_cb callback
,
933 return prefs_module_list_foreach((module
)?module
->submodules
:prefs_top_level_modules
, callback
, user_data
, true);
937 call_apply_cb(const void *key _U_
, void *value
, void *data _U_
)
939 module_t
*module
= (module_t
*)value
;
941 if (module
->obsolete
)
943 if (module
->prefs_changed_flags
) {
944 if (module
->apply_cb
!= NULL
)
945 (*module
->apply_cb
)();
946 module
->prefs_changed_flags
= 0;
948 if (module
->submodules
)
949 wmem_tree_foreach(module
->submodules
, call_apply_cb
, NULL
);
954 * Call the "apply" callback function for each module if any of its
955 * preferences have changed, and then clear the flag saying its
956 * preferences have changed, as the module has been notified of that
960 prefs_apply_all(void)
962 wmem_tree_foreach(prefs_modules
, call_apply_cb
, NULL
);
966 * Call the "apply" callback function for a specific module if any of
967 * its preferences have changed, and then clear the flag saying its
968 * preferences have changed, as the module has been notified of that
972 prefs_apply(module_t
*module
)
974 if (module
&& module
->prefs_changed_flags
)
975 call_apply_cb(NULL
, module
, NULL
);
979 prefs_find_module_alias(const char *name
)
981 module_alias_t
*alias
;
983 alias
= (module_alias_t
*)wmem_tree_lookup_string(prefs_module_aliases
, name
, WMEM_TREE_STRING_NOCASE
);
986 return alias
->module
;
990 * Register a preference in a module's list of preferences.
991 * If it has a title, give it an ordinal number; otherwise, it's a
992 * preference that won't show up in the UI, so it shouldn't get an
993 * ordinal number (the ordinal should be the ordinal in the set of
994 * *visible* preferences).
997 register_preference(module_t
*module
, const char *name
, const char *title
,
998 const char *description
, int type
)
1002 const char *name_prefix
= (module
->name
!= NULL
) ? module
->name
: module
->parent
->name
;
1004 preference
= g_new(pref_t
,1);
1005 preference
->name
= name
;
1006 preference
->title
= title
;
1007 preference
->description
= description
;
1008 preference
->type
= type
;
1009 /* Default to module's preference effects */
1010 preference
->effect_flags
= module
->effect_flags
;
1013 preference
->ordinal
= module
->numprefs
;
1015 preference
->ordinal
= -1; /* no ordinal for you */
1018 * Make sure that only lower-case ASCII letters, numbers,
1019 * underscores, and dots appear in the preference name.
1021 * Crash if there is, as that's an error in the code;
1022 * you can make the title and description nice strings
1023 * with capitalization, white space, punctuation, etc.,
1024 * but the name can be used on the command line,
1025 * and shouldn't require quoting, shifting, etc.
1027 for (p
= name
; *p
!= '\0'; p
++)
1028 if (!(g_ascii_islower(*p
) || g_ascii_isdigit(*p
) || *p
== '_' || *p
== '.'))
1029 ws_error("Preference \"%s.%s\" contains invalid characters", module
->name
, name
);
1032 * Make sure there's not already a preference with that
1033 * name. Crash if there is, as that's an error in the
1034 * code, and the code has to be fixed not to register
1035 * more than one preference with the same name.
1037 if (prefs_find_preference(module
, name
) != NULL
)
1038 ws_error("Preference %s has already been registered", name
);
1040 if ((!IS_PREF_OBSOLETE(type
)) &&
1041 /* Don't compare if it's a subtree */
1042 (module
->name
!= NULL
)) {
1044 * Make sure the preference name doesn't begin with the
1045 * module name, as that's redundant and Just Silly.
1047 if (!((strncmp(name
, module
->name
, strlen(module
->name
)) != 0) ||
1048 (((name
[strlen(module
->name
)]) != '.') && ((name
[strlen(module
->name
)]) != '_'))))
1049 ws_error("Preference %s begins with the module name", name
);
1052 /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */
1053 if (preference
->title
) {
1054 const char *cur_char
;
1055 if (preference
->type
!= PREF_STATIC_TEXT
&& g_utf8_strlen(preference
->title
, -1) > 80) { // Arbitrary.
1056 ws_error("Title for preference %s.%s is too long: %s", name_prefix
, preference
->name
, preference
->title
);
1059 if (!g_utf8_validate(preference
->title
, -1, NULL
)) {
1060 ws_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix
, preference
->name
);
1063 for (cur_char
= preference
->title
; *cur_char
; cur_char
= g_utf8_next_char(cur_char
)) {
1064 if (!g_unichar_isprint(g_utf8_get_char(cur_char
))) {
1065 ws_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix
, preference
->name
);
1070 if (preference
->description
) {
1071 if (!g_utf8_validate(preference
->description
, -1, NULL
)) {
1072 ws_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix
, preference
->name
);
1077 * We passed all of our checks. Add the preference.
1079 module
->prefs
= g_list_append(module
->prefs
, preference
);
1087 * Find a preference in a module's list of preferences, given the module
1088 * and the preference's name.
1093 module_t
*submodule
;
1097 preference_match(const void *a
, const void *b
)
1099 const pref_t
*pref
= (const pref_t
*)a
;
1100 const char *name
= (const char *)b
;
1102 return strcmp(name
, pref
->name
);
1106 module_find_pref_cb(const void *key _U_
, void *value
, void *data
)
1108 find_pref_arg_t
* arg
= (find_pref_arg_t
*)data
;
1110 module_t
*module
= (module_t
*)value
;
1115 list_entry
= g_list_find_custom(module
->prefs
, arg
->name
,
1118 if (list_entry
== NULL
)
1121 arg
->list_entry
= list_entry
;
1122 arg
->submodule
= module
;
1126 /* Tries to find a preference, setting containing_module to the (sub)module
1127 * holding this preference. */
1129 prefs_find_preference_with_submodule(module_t
*module
, const char *name
,
1130 module_t
**containing_module
)
1132 find_pref_arg_t arg
;
1136 return NULL
; /* invalid parameters */
1138 list_entry
= g_list_find_custom(module
->prefs
, name
,
1140 arg
.submodule
= NULL
;
1142 if (list_entry
== NULL
)
1144 arg
.list_entry
= NULL
;
1145 if (module
->submodules
!= NULL
)
1148 wmem_tree_foreach(module
->submodules
, module_find_pref_cb
, &arg
);
1151 list_entry
= arg
.list_entry
;
1154 if (list_entry
== NULL
)
1155 return NULL
; /* no such preference */
1157 if (containing_module
)
1158 *containing_module
= arg
.submodule
? arg
.submodule
: module
;
1160 return (pref_t
*) list_entry
->data
;
1164 prefs_find_preference(module_t
*module
, const char *name
)
1166 return prefs_find_preference_with_submodule(module
, name
, NULL
);
1170 * Returns true if the given protocol has registered preferences
1173 prefs_is_registered_protocol(const char *name
)
1175 module_t
*m
= prefs_find_module(name
);
1177 return (m
!= NULL
&& !m
->obsolete
);
1181 * Returns the module title of a registered protocol
1184 prefs_get_title_by_name(const char *name
)
1186 module_t
*m
= prefs_find_module(name
);
1188 return (m
!= NULL
&& !m
->obsolete
) ? m
->title
: NULL
;
1192 * Register a preference with an unsigned integral value.
1195 prefs_register_uint_preference(module_t
*module
, const char *name
,
1196 const char *title
, const char *description
,
1197 unsigned base
, unsigned *var
)
1201 preference
= register_preference(module
, name
, title
, description
,
1203 preference
->varp
.uint
= var
;
1204 preference
->default_val
.uint
= *var
;
1205 ws_assert(base
> 0 && base
!= 1 && base
< 37);
1206 preference
->info
.base
= base
;
1210 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
1215 * Register a "custom" preference with a unsigned integral value.
1216 * XXX - This should be temporary until we can find a better way
1217 * to do "custom" preferences
1220 prefs_register_uint_custom_preference(module_t
*module
, const char *name
,
1221 const char *title
, const char *description
,
1222 struct pref_custom_cbs
* custom_cbs
, unsigned *var
)
1226 preference
= register_preference(module
, name
, title
, description
,
1229 preference
->custom_cbs
= *custom_cbs
;
1230 preference
->varp
.uint
= var
;
1231 preference
->default_val
.uint
= *var
;
1235 * Register a preference with an Boolean value.
1238 prefs_register_bool_preference(module_t
*module
, const char *name
,
1239 const char *title
, const char *description
,
1244 preference
= register_preference(module
, name
, title
, description
,
1246 preference
->varp
.boolp
= var
;
1247 preference
->default_val
.boolval
= *var
;
1250 unsigned int prefs_set_bool_value(pref_t
*pref
, bool value
, pref_source_t source
)
1252 unsigned int changed
= 0;
1257 if (pref
->default_val
.boolval
!= value
) {
1258 pref
->default_val
.boolval
= value
;
1259 changed
= prefs_get_effect_flags(pref
);
1263 if (pref
->stashed_val
.boolval
!= value
) {
1264 pref
->stashed_val
.boolval
= value
;
1265 changed
= prefs_get_effect_flags(pref
);
1269 if (*pref
->varp
.boolp
!= value
) {
1270 *pref
->varp
.boolp
= value
;
1271 changed
= prefs_get_effect_flags(pref
);
1275 ws_assert_not_reached();
1282 void prefs_invert_bool_value(pref_t
*pref
, pref_source_t source
)
1287 pref
->default_val
.boolval
= !pref
->default_val
.boolval
;
1290 pref
->stashed_val
.boolval
= !pref
->stashed_val
.boolval
;
1293 *pref
->varp
.boolp
= !(*pref
->varp
.boolp
);
1296 ws_assert_not_reached();
1301 bool prefs_get_bool_value(pref_t
*pref
, pref_source_t source
)
1306 return pref
->default_val
.boolval
;
1308 return pref
->stashed_val
.boolval
;
1310 return *pref
->varp
.boolp
;
1312 ws_assert_not_reached();
1320 * Register a preference with an enumerated value.
1323 * XXX Should we get rid of the radio_buttons parameter and make that
1324 * behavior automatic depending on the number of items?
1327 prefs_register_enum_preference(module_t
*module
, const char *name
,
1328 const char *title
, const char *description
,
1329 int *var
, const enum_val_t
*enumvals
,
1334 /* Validate that the "name one would use on the command line for the value"
1335 * doesn't require quoting, etc. It's all treated case-insensitively so we
1336 * don't care about upper vs lower case.
1338 for (size_t i
= 0; enumvals
[i
].name
!= NULL
; i
++) {
1339 for (const char *p
= enumvals
[i
].name
; *p
!= '\0'; p
++)
1340 if (!(g_ascii_isalnum(*p
) || *p
== '_' || *p
== '.' || *p
== '-'))
1341 ws_error("Preference \"%s.%s\" enum value name \"%s\" contains invalid characters",
1342 module
->name
, name
, enumvals
[i
].name
);
1346 preference
= register_preference(module
, name
, title
, description
,
1348 preference
->varp
.enump
= var
;
1349 preference
->default_val
.enumval
= *var
;
1350 preference
->info
.enum_info
.enumvals
= enumvals
;
1351 preference
->info
.enum_info
.radio_buttons
= radio_buttons
;
1354 unsigned int prefs_set_enum_value(pref_t
*pref
, int value
, pref_source_t source
)
1356 unsigned int changed
= 0;
1361 if (pref
->default_val
.enumval
!= value
) {
1362 pref
->default_val
.enumval
= value
;
1363 changed
= prefs_get_effect_flags(pref
);
1367 if (pref
->stashed_val
.enumval
!= value
) {
1368 pref
->stashed_val
.enumval
= value
;
1369 changed
= prefs_get_effect_flags(pref
);
1373 if (*pref
->varp
.enump
!= value
) {
1374 *pref
->varp
.enump
= value
;
1375 changed
= prefs_get_effect_flags(pref
);
1379 ws_assert_not_reached();
1386 unsigned int prefs_set_enum_string_value(pref_t
*pref
, const char *value
, pref_source_t source
)
1388 int enum_val
= find_val_for_string(value
, pref
->info
.enum_info
.enumvals
, *pref
->varp
.enump
);
1390 return prefs_set_enum_value(pref
, enum_val
, source
);
1393 int prefs_get_enum_value(pref_t
*pref
, pref_source_t source
)
1398 return pref
->default_val
.enumval
;
1400 return pref
->stashed_val
.enumval
;
1402 return *pref
->varp
.enump
;
1404 ws_assert_not_reached();
1411 const enum_val_t
* prefs_get_enumvals(pref_t
*pref
)
1413 return pref
->info
.enum_info
.enumvals
;
1416 bool prefs_get_enum_radiobuttons(pref_t
*pref
)
1418 return pref
->info
.enum_info
.radio_buttons
;
1422 * For use by UI code that sets preferences.
1425 prefs_set_custom_value(pref_t
*pref
, const char *value
, pref_source_t source _U_
)
1427 /* XXX - support pref source for custom preferences */
1428 unsigned int changed
= 0;
1429 pref
->custom_cbs
.set_cb(pref
, value
, &changed
);
1434 register_string_like_preference(module_t
*module
, const char *name
,
1435 const char *title
, const char *description
,
1436 char **var
, int type
,
1437 struct pref_custom_cbs
* custom_cbs
,
1443 pref
= register_preference(module
, name
, title
, description
, type
);
1446 * String preference values should be non-null (as you can't
1447 * keep them null after using the preferences GUI, you can at best
1448 * have them be null strings) and freeable (as we free them
1449 * if we change them).
1451 * If the value is a null pointer, make it a copy of a null
1452 * string, otherwise make it a copy of the value.
1456 *var
= g_strdup("");
1458 *var
= g_strdup(*var
);
1463 pref
->varp
.string
= var
;
1464 pref
->default_val
.string
= g_strdup(*var
);
1465 pref
->stashed_val
.string
= NULL
;
1466 if (type
== PREF_CUSTOM
) {
1467 ws_assert(custom_cbs
);
1468 pref
->custom_cbs
= *custom_cbs
;
1473 * Assign to a string preference.
1476 pref_set_string_like_pref_value(pref_t
*pref
, const char *value
)
1479 g_free((void *)*pref
->varp
.string
);
1481 *pref
->varp
.string
= g_strdup(value
);
1485 * For use by UI code that sets preferences.
1488 prefs_set_string_value(pref_t
*pref
, const char* value
, pref_source_t source
)
1490 unsigned int changed
= 0;
1495 if (*pref
->default_val
.string
) {
1496 if (strcmp(pref
->default_val
.string
, value
) != 0) {
1497 changed
= prefs_get_effect_flags(pref
);
1498 g_free(pref
->default_val
.string
);
1499 pref
->default_val
.string
= g_strdup(value
);
1502 pref
->default_val
.string
= g_strdup(value
);
1506 if (pref
->stashed_val
.string
) {
1507 if (strcmp(pref
->stashed_val
.string
, value
) != 0) {
1508 changed
= prefs_get_effect_flags(pref
);
1509 g_free(pref
->stashed_val
.string
);
1510 pref
->stashed_val
.string
= g_strdup(value
);
1513 pref
->stashed_val
.string
= g_strdup(value
);
1517 if (*pref
->varp
.string
) {
1518 if (strcmp(*pref
->varp
.string
, value
) != 0) {
1519 changed
= prefs_get_effect_flags(pref
);
1520 pref_set_string_like_pref_value(pref
, value
);
1523 pref_set_string_like_pref_value(pref
, value
);
1527 ws_assert_not_reached();
1534 char* prefs_get_string_value(pref_t
*pref
, pref_source_t source
)
1539 return pref
->default_val
.string
;
1541 return pref
->stashed_val
.string
;
1543 return *pref
->varp
.string
;
1545 ws_assert_not_reached();
1553 * Reset the value of a string-like preference.
1556 reset_string_like_preference(pref_t
*pref
)
1558 g_free(*pref
->varp
.string
);
1559 *pref
->varp
.string
= g_strdup(pref
->default_val
.string
);
1563 * Register a preference with a character-string value.
1566 prefs_register_string_preference(module_t
*module
, const char *name
,
1567 const char *title
, const char *description
,
1571 register_string_like_preference(module
, name
, title
, description
,
1572 (char **)var
, PREF_STRING
, NULL
, false);
1577 * Register a preference with a file name (string) value.
1580 prefs_register_filename_preference(module_t
*module
, const char *name
,
1581 const char *title
, const char *description
,
1582 const char **var
, bool for_writing
)
1585 register_string_like_preference(module
, name
, title
, description
, (char **)var
,
1586 for_writing
? PREF_SAVE_FILENAME
: PREF_OPEN_FILENAME
, NULL
, false);
1591 * Register a preference with a directory name (string) value.
1594 prefs_register_directory_preference(module_t
*module
, const char *name
,
1595 const char *title
, const char *description
,
1599 register_string_like_preference(module
, name
, title
, description
,
1600 (char **)var
, PREF_DIRNAME
, NULL
, false);
1604 /* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
1606 prefs_register_range_preference_common(module_t
*module
, const char *name
,
1607 const char *title
, const char *description
,
1608 range_t
**var
, uint32_t max_value
, int type
)
1612 preference
= register_preference(module
, name
, title
, description
, type
);
1613 preference
->info
.max_value
= max_value
;
1616 * Range preference values should be non-null (as you can't
1617 * keep them null after using the preferences GUI, you can at best
1618 * have them be empty ranges) and freeable (as we free them
1619 * if we change them).
1621 * If the value is a null pointer, make it an empty range.
1624 *var
= range_empty(wmem_epan_scope());
1625 preference
->varp
.range
= var
;
1626 preference
->default_val
.range
= range_copy(wmem_epan_scope(), *var
);
1627 preference
->stashed_val
.range
= NULL
;
1633 * Register a preference with a ranged value.
1636 prefs_register_range_preference(module_t
*module
, const char *name
,
1637 const char *title
, const char *description
,
1638 range_t
**var
, uint32_t max_value
)
1640 prefs_register_range_preference_common(module
, name
, title
,
1641 description
, var
, max_value
, PREF_RANGE
);
1645 prefs_set_range_value_work(pref_t
*pref
, const char *value
,
1646 bool return_range_errors
, unsigned int *changed_flags
)
1650 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
1651 return_range_errors
) != CVT_NO_ERROR
) {
1652 return false; /* number was bad */
1655 if (!ranges_are_equal(*pref
->varp
.range
, newrange
)) {
1656 *changed_flags
|= prefs_get_effect_flags(pref
);
1657 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
1658 *pref
->varp
.range
= newrange
;
1660 wmem_free(wmem_epan_scope(), newrange
);
1666 * For use by UI code that sets preferences.
1669 prefs_set_stashed_range_value(pref_t
*pref
, const char *value
)
1673 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
1674 true) != CVT_NO_ERROR
) {
1675 return 0; /* number was bad */
1678 if (!ranges_are_equal(pref
->stashed_val
.range
, newrange
)) {
1679 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
1680 pref
->stashed_val
.range
= newrange
;
1682 wmem_free(wmem_epan_scope(), newrange
);
1684 return prefs_get_effect_flags(pref
);
1688 bool prefs_add_list_value(pref_t
*pref
, void* value
, pref_source_t source
)
1693 pref
->default_val
.list
= g_list_prepend(pref
->default_val
.list
, value
);
1696 pref
->stashed_val
.list
= g_list_prepend(pref
->stashed_val
.list
, value
);
1699 *pref
->varp
.list
= g_list_prepend(*pref
->varp
.list
, value
);
1702 ws_assert_not_reached();
1709 GList
* prefs_get_list_value(pref_t
*pref
, pref_source_t source
)
1714 return pref
->default_val
.list
;
1716 return pref
->stashed_val
.list
;
1718 return *pref
->varp
.list
;
1720 ws_assert_not_reached();
1727 bool prefs_set_range_value(pref_t
*pref
, range_t
*value
, pref_source_t source
)
1729 bool changed
= false;
1734 if (!ranges_are_equal(pref
->default_val
.range
, value
)) {
1735 wmem_free(wmem_epan_scope(), pref
->default_val
.range
);
1736 pref
->default_val
.range
= range_copy(wmem_epan_scope(), value
);
1741 if (!ranges_are_equal(pref
->stashed_val
.range
, value
)) {
1742 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
1743 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), value
);
1748 if (!ranges_are_equal(*pref
->varp
.range
, value
)) {
1749 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
1750 *pref
->varp
.range
= range_copy(wmem_epan_scope(), value
);
1755 ws_assert_not_reached();
1762 range_t
* prefs_get_range_value_real(pref_t
*pref
, pref_source_t source
)
1767 return pref
->default_val
.range
;
1769 return pref
->stashed_val
.range
;
1771 return *pref
->varp
.range
;
1773 ws_assert_not_reached();
1780 range_t
* prefs_get_range_value(const char *module_name
, const char* pref_name
)
1782 pref_t
*pref
= prefs_find_preference(prefs_find_module(module_name
), pref_name
);
1786 return prefs_get_range_value_real(pref
, pref_current
);
1790 prefs_range_add_value(pref_t
*pref
, uint32_t val
)
1792 range_add_value(wmem_epan_scope(), pref
->varp
.range
, val
);
1796 prefs_range_remove_value(pref_t
*pref
, uint32_t val
)
1798 range_remove_value(wmem_epan_scope(), pref
->varp
.range
, val
);
1802 * Register a static text 'preference'. It can be used to add explanatory
1803 * text inline with other preferences in the GUI.
1804 * Note: Static preferences are not saved to the preferences file.
1807 prefs_register_static_text_preference(module_t
*module
, const char *name
,
1809 const char *description
)
1811 register_preference(module
, name
, title
, description
, PREF_STATIC_TEXT
);
1815 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1816 * preferences tab of the module.
1819 prefs_register_uat_preference(module_t
*module
, const char *name
,
1820 const char *title
, const char *description
,
1824 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_UAT
);
1826 preference
->varp
.uat
= uat
;
1830 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
1831 * preferences tab of the module.
1834 prefs_register_uat_preference_qt(module_t
*module
, const char *name
,
1835 const char *title
, const char *description
,
1839 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_UAT
);
1841 preference
->varp
.uat
= uat
;
1844 struct epan_uat
* prefs_get_uat_value(pref_t
*pref
)
1846 return pref
->varp
.uat
;
1850 * Register a color preference.
1853 prefs_register_color_preference(module_t
*module
, const char *name
,
1854 const char *title
, const char *description
,
1857 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_COLOR
);
1859 preference
->varp
.colorp
= color
;
1860 preference
->default_val
.color
= *color
;
1863 bool prefs_set_color_value(pref_t
*pref
, color_t value
, pref_source_t source
)
1865 bool changed
= false;
1870 if ((pref
->default_val
.color
.red
!= value
.red
) ||
1871 (pref
->default_val
.color
.green
!= value
.green
) ||
1872 (pref
->default_val
.color
.blue
!= value
.blue
)) {
1874 pref
->default_val
.color
= value
;
1878 if ((pref
->stashed_val
.color
.red
!= value
.red
) ||
1879 (pref
->stashed_val
.color
.green
!= value
.green
) ||
1880 (pref
->stashed_val
.color
.blue
!= value
.blue
)) {
1882 pref
->stashed_val
.color
= value
;
1886 if ((pref
->varp
.colorp
->red
!= value
.red
) ||
1887 (pref
->varp
.colorp
->green
!= value
.green
) ||
1888 (pref
->varp
.colorp
->blue
!= value
.blue
)) {
1890 *pref
->varp
.colorp
= value
;
1894 ws_assert_not_reached();
1901 color_t
* prefs_get_color_value(pref_t
*pref
, pref_source_t source
)
1906 return &pref
->default_val
.color
;
1908 return &pref
->stashed_val
.color
;
1910 return pref
->varp
.colorp
;
1912 ws_assert_not_reached();
1920 * Register a "custom" preference with a list.
1921 * XXX - This should be temporary until we can find a better way
1922 * to do "custom" preferences
1924 typedef void (*pref_custom_list_init_cb
) (pref_t
* pref
, GList
** value
);
1927 prefs_register_list_custom_preference(module_t
*module
, const char *name
,
1928 const char *title
, const char *description
,
1929 struct pref_custom_cbs
* custom_cbs
,
1930 pref_custom_list_init_cb init_cb
,
1933 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_CUSTOM
);
1935 preference
->custom_cbs
= *custom_cbs
;
1936 init_cb(preference
, list
);
1940 * Register a custom preference.
1943 prefs_register_custom_preference(module_t
*module
, const char *name
,
1944 const char *title
, const char *description
,
1945 struct pref_custom_cbs
* custom_cbs
,
1946 void **custom_data _U_
)
1948 pref_t
* preference
= register_preference(module
, name
, title
, description
, PREF_CUSTOM
);
1950 preference
->custom_cbs
= *custom_cbs
;
1951 /* XXX - wait until we can handle void** pointers
1952 preference->custom_cbs.init_cb(preference, custom_data);
1957 * Register a dedicated TCP preference for SEQ analysis overriding.
1958 * This is similar to the data structure from enum preference, except
1959 * that when a preference dialog is used, the stashed value is the list
1960 * of frame data pointers whose sequence analysis override will be set
1961 * to the current value if the dialog is accepted.
1963 * We don't need to read or write the value from the preferences file
1964 * (or command line), because the override is reset to the default (0)
1965 * for each frame when a new capture file is loaded.
1968 prefs_register_custom_preference_TCP_Analysis(module_t
*module
, const char *name
,
1969 const char *title
, const char *description
,
1970 int *var
, const enum_val_t
*enumvals
,
1975 preference
= register_preference(module
, name
, title
, description
,
1976 PREF_PROTO_TCP_SNDAMB_ENUM
);
1977 preference
->varp
.enump
= var
;
1978 preference
->default_val
.enumval
= *var
;
1979 preference
->stashed_val
.list
= NULL
;
1980 preference
->info
.enum_info
.enumvals
= enumvals
;
1981 preference
->info
.enum_info
.radio_buttons
= radio_buttons
;
1985 * Register a (internal) "Decode As" preference with a ranged value.
1987 void prefs_register_decode_as_range_preference(module_t
*module
, const char *name
,
1988 const char *title
, const char *description
, range_t
**var
,
1989 uint32_t max_value
, const char *dissector_table
, const char *dissector_description
)
1993 preference
= prefs_register_range_preference_common(module
, name
, title
,
1994 description
, var
, max_value
, PREF_DECODE_AS_RANGE
);
1995 preference
->dissector_desc
= dissector_description
;
1996 preference
->dissector_table
= dissector_table
;
2000 * Register a preference with password value.
2003 prefs_register_password_preference(module_t
*module
, const char *name
,
2004 const char *title
, const char *description
,
2008 register_string_like_preference(module
, name
, title
, description
,
2009 (char **)var
, PREF_PASSWORD
, NULL
, false);
2014 * Register a preference with a dissector name.
2017 prefs_register_dissector_preference(module_t
*module
, const char *name
,
2018 const char *title
, const char *description
,
2022 register_string_like_preference(module
, name
, title
, description
,
2023 (char **)var
, PREF_DISSECTOR
, NULL
, false);
2027 bool prefs_add_decode_as_value(pref_t
*pref
, unsigned value
, bool replace
)
2031 case PREF_DECODE_AS_RANGE
:
2034 /* If range has single value, replace it */
2035 if (((*pref
->varp
.range
)->nranges
== 1) &&
2036 ((*pref
->varp
.range
)->ranges
[0].low
== (*pref
->varp
.range
)->ranges
[0].high
)) {
2037 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2038 *pref
->varp
.range
= range_empty(wmem_epan_scope());
2042 prefs_range_add_value(pref
, value
);
2045 /* XXX - Worth asserting over? */
2052 bool prefs_remove_decode_as_value(pref_t
*pref
, unsigned value
, bool set_default _U_
)
2056 case PREF_DECODE_AS_RANGE
:
2057 /* XXX - We could set to the default if the value is the only one
2060 prefs_range_remove_value(pref
, value
);
2070 * Register a preference that used to be supported but no longer is.
2073 prefs_register_obsolete_preference(module_t
*module
, const char *name
)
2075 register_preference(module
, name
, NULL
, NULL
, PREF_OBSOLETE
);
2079 prefs_set_preference_effect_fields(module_t
*module
, const char *name
)
2081 pref_t
* pref
= prefs_find_preference(module
, name
);
2083 prefs_set_effect_flags(pref
, prefs_get_effect_flags(pref
) | PREF_EFFECT_FIELDS
);
2088 * Check to see if a preference is obsolete.
2091 prefs_get_preference_obsolete(pref_t
*pref
)
2094 return (IS_PREF_OBSOLETE(pref
->type
) ? true : false);
2100 * Make a preference obsolete.
2102 extern prefs_set_pref_e
2103 prefs_set_preference_obsolete(pref_t
*pref
)
2106 SET_PREF_OBSOLETE(pref
->type
);
2107 return PREFS_SET_OK
;
2109 return PREFS_SET_NO_SUCH_PREF
;
2113 pref_stash(pref_t
*pref
, void *unused _U_
)
2115 switch (pref
->type
) {
2118 pref
->stashed_val
.uint
= *pref
->varp
.uint
;
2122 pref
->stashed_val
.boolval
= *pref
->varp
.boolp
;
2126 pref
->stashed_val
.enumval
= *pref
->varp
.enump
;
2130 case PREF_SAVE_FILENAME
:
2131 case PREF_OPEN_FILENAME
:
2134 case PREF_DISSECTOR
:
2135 g_free(pref
->stashed_val
.string
);
2136 pref
->stashed_val
.string
= g_strdup(*pref
->varp
.string
);
2139 case PREF_DECODE_AS_RANGE
:
2141 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2142 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), *pref
->varp
.range
);
2146 pref
->stashed_val
.color
= *pref
->varp
.colorp
;
2149 case PREF_STATIC_TEXT
:
2152 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2156 ws_assert_not_reached();
2163 pref_unstash(pref_t
*pref
, void *unstash_data_p
)
2165 pref_unstash_data_t
*unstash_data
= (pref_unstash_data_t
*)unstash_data_p
;
2166 dissector_table_t sub_dissectors
= NULL
;
2167 dissector_handle_t handle
= NULL
;
2169 /* Revert the preference to its saved value. */
2170 switch (pref
->type
) {
2173 if (*pref
->varp
.uint
!= pref
->stashed_val
.uint
) {
2174 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2175 *pref
->varp
.uint
= pref
->stashed_val
.uint
;
2180 if (*pref
->varp
.boolp
!= pref
->stashed_val
.boolval
) {
2181 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2182 *pref
->varp
.boolp
= pref
->stashed_val
.boolval
;
2187 if (*pref
->varp
.enump
!= pref
->stashed_val
.enumval
) {
2188 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2189 *pref
->varp
.enump
= pref
->stashed_val
.enumval
;
2193 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2195 /* The preference dialogs are modal so the frame_data pointers should
2196 * still be valid; otherwise we could store the frame numbers to
2200 for (GList
* elem
= pref
->stashed_val
.list
; elem
!= NULL
; elem
= elem
->next
) {
2201 fdata
= (frame_data
*)elem
->data
;
2202 if (fdata
->tcp_snd_manual_analysis
!= *pref
->varp
.enump
) {
2203 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2204 fdata
->tcp_snd_manual_analysis
= *pref
->varp
.enump
;
2210 case PREF_SAVE_FILENAME
:
2211 case PREF_OPEN_FILENAME
:
2214 case PREF_DISSECTOR
:
2215 if (strcmp(*pref
->varp
.string
, pref
->stashed_val
.string
) != 0) {
2216 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2217 g_free(*pref
->varp
.string
);
2218 *pref
->varp
.string
= g_strdup(pref
->stashed_val
.string
);
2222 case PREF_DECODE_AS_RANGE
:
2224 const char* table_name
= prefs_get_dissector_table(pref
);
2225 if (!ranges_are_equal(*pref
->varp
.range
, pref
->stashed_val
.range
)) {
2227 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2229 if (unstash_data
->handle_decode_as
) {
2230 sub_dissectors
= find_dissector_table(table_name
);
2231 if (sub_dissectors
!= NULL
) {
2232 const char *handle_desc
= prefs_get_dissector_description(pref
);
2233 // It should perhaps be possible to get this via dissector name.
2234 handle
= dissector_table_get_dissector_handle(sub_dissectors
, handle_desc
);
2235 if (handle
!= NULL
) {
2236 /* Set the current handle to NULL for all the old values
2237 * in the dissector table. If there isn't an initial
2238 * handle, this actually deletes the entry. (If there
2239 * is an initial entry, keep it around so that the
2240 * user can see the original value.)
2242 * XXX - If there's an initial handle which is not this,
2243 * reset it instead? At least this leaves the initial
2244 * handle visible in the Decode As table.
2246 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
2247 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
2248 dissector_change_uint(table_name
, j
, NULL
);
2249 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
2252 dissector_change_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, NULL
);
2253 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
2259 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2260 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->stashed_val
.range
);
2262 if (unstash_data
->handle_decode_as
) {
2263 if ((sub_dissectors
!= NULL
) && (handle
!= NULL
)) {
2265 /* Add new values to the dissector table */
2266 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
2268 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
2269 dissector_change_uint(table_name
, j
, handle
);
2270 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
2273 dissector_change_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, handle
);
2274 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
2282 if (!ranges_are_equal(*pref
->varp
.range
, pref
->stashed_val
.range
)) {
2283 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2284 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
2285 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->stashed_val
.range
);
2290 if ((pref
->varp
.colorp
->blue
!= pref
->stashed_val
.color
.blue
) ||
2291 (pref
->varp
.colorp
->red
!= pref
->stashed_val
.color
.red
) ||
2292 (pref
->varp
.colorp
->green
!= pref
->stashed_val
.color
.green
)) {
2293 unstash_data
->module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
2294 *pref
->varp
.colorp
= pref
->stashed_val
.color
;
2298 case PREF_STATIC_TEXT
:
2304 ws_assert_not_reached();
2311 reset_stashed_pref(pref_t
*pref
) {
2312 switch (pref
->type
) {
2315 pref
->stashed_val
.uint
= pref
->default_val
.uint
;
2319 pref
->stashed_val
.boolval
= pref
->default_val
.boolval
;
2323 pref
->stashed_val
.enumval
= pref
->default_val
.enumval
;
2327 case PREF_SAVE_FILENAME
:
2328 case PREF_OPEN_FILENAME
:
2331 case PREF_DISSECTOR
:
2332 g_free(pref
->stashed_val
.string
);
2333 pref
->stashed_val
.string
= g_strdup(pref
->default_val
.string
);
2336 case PREF_DECODE_AS_RANGE
:
2338 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2339 pref
->stashed_val
.range
= range_copy(wmem_epan_scope(), pref
->default_val
.range
);
2342 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2343 if (pref
->stashed_val
.list
!= NULL
) {
2344 g_list_free(pref
->stashed_val
.list
);
2345 pref
->stashed_val
.list
= NULL
;
2350 memcpy(&pref
->stashed_val
.color
, &pref
->default_val
.color
, sizeof(color_t
));
2353 case PREF_STATIC_TEXT
:
2359 ws_assert_not_reached();
2365 pref_clean_stash(pref_t
*pref
, void *unused _U_
)
2367 switch (pref
->type
) {
2379 case PREF_SAVE_FILENAME
:
2380 case PREF_OPEN_FILENAME
:
2383 case PREF_DISSECTOR
:
2384 if (pref
->stashed_val
.string
!= NULL
) {
2385 g_free(pref
->stashed_val
.string
);
2386 pref
->stashed_val
.string
= NULL
;
2390 case PREF_DECODE_AS_RANGE
:
2392 if (pref
->stashed_val
.range
!= NULL
) {
2393 wmem_free(wmem_epan_scope(), pref
->stashed_val
.range
);
2394 pref
->stashed_val
.range
= NULL
;
2398 case PREF_STATIC_TEXT
:
2404 case PREF_PROTO_TCP_SNDAMB_ENUM
:
2405 if (pref
->stashed_val
.list
!= NULL
) {
2406 g_list_free(pref
->stashed_val
.list
);
2407 pref
->stashed_val
.list
= NULL
;
2412 ws_assert_not_reached();
2419 * Call a callback function, with a specified argument, for each preference
2420 * in a given module.
2422 * If any of the callbacks return a non-zero value, stop and return that
2423 * value, otherwise return 0.
2426 prefs_pref_foreach(module_t
*module
, pref_cb callback
, void *user_data
)
2432 for (elem
= g_list_first(module
->prefs
); elem
!= NULL
; elem
= g_list_next(elem
)) {
2433 pref
= (pref_t
*)elem
->data
;
2434 if (IS_PREF_OBSOLETE(pref
->type
)) {
2436 * This preference is no longer supported; it's
2437 * not a real preference, so we don't call the
2438 * callback for it (i.e., we treat it as if it
2439 * weren't found in the list of preferences,
2440 * and we weren't called in the first place).
2445 ret
= (*callback
)(pref
, user_data
);
2452 static const enum_val_t st_sort_col_vals
[] = {
2453 { "name", "Node name (topic/item)", ST_SORT_COL_NAME
},
2454 { "count", "Item count", ST_SORT_COL_COUNT
},
2455 { "average", "Average value of the node", ST_SORT_COL_AVG
},
2456 { "min", "Minimum value of the node", ST_SORT_COL_MIN
},
2457 { "max", "Maximum value of the node", ST_SORT_COL_MAX
},
2458 { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE
},
2463 stats_callback(void)
2465 /* Test for a sane tap update interval */
2466 if (prefs
.tap_update_interval
< 100 || prefs
.tap_update_interval
> 10000)
2467 prefs
.tap_update_interval
= TAP_UPDATE_DEFAULT_INTERVAL
;
2469 /* burst resolution can't be less than 1 (ms) */
2470 if (prefs
.st_burst_resolution
< 1) {
2471 prefs
.st_burst_resolution
= 1;
2473 else if (prefs
.st_burst_resolution
> ST_MAX_BURSTRES
) {
2474 prefs
.st_burst_resolution
= ST_MAX_BURSTRES
;
2476 /* make sure burst window value makes sense */
2477 if (prefs
.st_burst_windowlen
< prefs
.st_burst_resolution
) {
2478 prefs
.st_burst_windowlen
= prefs
.st_burst_resolution
;
2480 /* round burst window down to multiple of resolution */
2481 prefs
.st_burst_windowlen
-= prefs
.st_burst_windowlen
%prefs
.st_burst_resolution
;
2482 if ((prefs
.st_burst_windowlen
/prefs
.st_burst_resolution
) > ST_MAX_BURSTBUCKETS
) {
2483 prefs
.st_burst_windowlen
= prefs
.st_burst_resolution
*ST_MAX_BURSTBUCKETS
;
2490 /* Ensure there is at least one file count */
2491 if (prefs
.gui_recent_files_count_max
== 0)
2492 prefs
.gui_recent_files_count_max
= 10;
2494 /* Ensure there is at least one display filter entry */
2495 if (prefs
.gui_recent_df_entries_max
== 0)
2496 prefs
.gui_recent_df_entries_max
= 10;
2498 /* number of decimal places should be between 2 and 10 */
2499 if (prefs
.gui_decimal_places1
< 2) {
2500 prefs
.gui_decimal_places1
= 2;
2501 } else if (prefs
.gui_decimal_places1
> 10) {
2502 prefs
.gui_decimal_places1
= 10;
2504 /* number of decimal places should be between 2 and 10 */
2505 if (prefs
.gui_decimal_places2
< 2) {
2506 prefs
.gui_decimal_places2
= 2;
2507 } else if (prefs
.gui_decimal_places2
> 10) {
2508 prefs
.gui_decimal_places2
= 10;
2510 /* number of decimal places should be between 2 and 10 */
2511 if (prefs
.gui_decimal_places3
< 2) {
2512 prefs
.gui_decimal_places3
= 2;
2513 } else if (prefs
.gui_decimal_places3
> 10) {
2514 prefs
.gui_decimal_places3
= 10;
2519 gui_layout_callback(void)
2521 if (prefs
.gui_layout_type
== layout_unused
||
2522 prefs
.gui_layout_type
>= layout_type_max
) {
2523 /* XXX - report an error? It's not a syntax error - we'd need to
2524 add a way of reporting a *semantic* error. */
2525 prefs
.gui_layout_type
= layout_type_2
;
2529 /******************************************************
2530 * All custom preference function callbacks
2531 ******************************************************/
2532 static void custom_pref_no_cb(pref_t
* pref _U_
) {}
2535 * Column preference functions
2537 #define PRS_COL_HIDDEN_FMT "column.hidden"
2538 #define PRS_COL_HIDDEN "column.hide"
2539 #define PRS_COL_FMT "column.format"
2540 #define PRS_COL_NUM "column.number"
2541 static module_t
*gui_column_module
;
2543 static prefs_set_pref_e
2544 column_hidden_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
2548 pref_t
*format_pref
;
2551 * Prefer the new preference to the old format-based preference if we've
2552 * read it. (We probably could just compare the string to NULL and "".)
2554 prefs
.cols_hide_new
= true;
2556 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
2559 * Set the "visible" flag for the existing columns; we need to
2560 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
2561 * after setting it (which might be the case if, for example, we
2562 * set PRS_COL_HIDDEN on the command line).
2564 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2565 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2568 cfmt
= (fmt_data
*)clp
->data
;
2569 cfmt
->visible
= prefs_is_column_visible(*pref
->varp
.string
, cidx
);
2574 return PREFS_SET_OK
;
2578 column_hidden_type_name_cb(void)
2580 return "Packet list hidden columns";
2584 column_hidden_type_description_cb(void)
2586 return g_strdup("List all column indices (1-indexed) to hide in the packet list.");
2590 column_hidden_to_str_cb(pref_t
* pref
, bool default_val
)
2592 GString
*cols_hidden
;
2595 pref_t
*format_pref
;
2599 return g_strdup(pref
->default_val
.string
);
2601 cols_hidden
= g_string_new("");
2602 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2603 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2605 cfmt
= (fmt_data
*) clp
->data
;
2606 if (!cfmt
->visible
) {
2607 if (cols_hidden
->len
)
2608 g_string_append (cols_hidden
, ",");
2609 g_string_append_printf (cols_hidden
, "%i", cidx
);
2615 return g_string_free (cols_hidden
, FALSE
);
2619 column_hidden_is_default_cb(pref_t
* pref
)
2621 char *cur_hidden_str
= column_hidden_to_str_cb(pref
, false);
2622 bool is_default
= g_strcmp0(cur_hidden_str
, pref
->default_val
.string
) == 0;
2624 g_free(cur_hidden_str
);
2628 static prefs_set_pref_e
2629 column_hidden_fmt_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
2633 pref_t
*format_pref
;
2635 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
2638 * Set the "visible" flag for the existing columns; we need to
2639 * do this if we set PRS_COL_HIDDEN_FMT but don't set PRS_COL_FMT
2640 * after setting it (which might be the case if, for example, we
2641 * set PRS_COL_HIDDEN_FMT on the command line; it shouldn't happen
2642 * when reading the configuration file because we write (both of)
2643 * the hidden column prefs before the column format prefs.)
2645 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2646 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2648 cfmt
= (fmt_data
*)clp
->data
;
2649 cfmt
->visible
= prefs_is_column_fmt_visible(*pref
->varp
.string
, cfmt
);
2653 return PREFS_SET_OK
;
2657 column_hidden_fmt_type_name_cb(void)
2659 return "Packet list hidden column formats (deprecated)";
2663 column_hidden_fmt_type_description_cb(void)
2665 return g_strdup("List all column formats to hide in the packet list. Deprecated in favor of the index-based preference.");
2669 column_hidden_fmt_to_str_cb(pref_t
* pref
, bool default_val
)
2671 GString
*cols_hidden
;
2674 pref_t
*format_pref
;
2677 return g_strdup(pref
->default_val
.string
);
2679 cols_hidden
= g_string_new("");
2680 format_pref
= prefs_find_preference(gui_column_module
, PRS_COL_FMT
);
2681 clp
= (format_pref
) ? *format_pref
->varp
.list
: NULL
;
2684 cfmt
= (fmt_data
*) clp
->data
;
2685 if (!cfmt
->visible
) {
2686 if (cols_hidden
->len
)
2687 g_string_append (cols_hidden
, ",");
2688 prefs_fmt
= column_fmt_data_to_str(cfmt
);
2689 g_string_append(cols_hidden
, prefs_fmt
);
2695 return g_string_free (cols_hidden
, FALSE
);
2699 column_hidden_fmt_is_default_cb(pref_t
* pref
)
2701 char *cur_hidden_str
= column_hidden_fmt_to_str_cb(pref
, false);
2702 bool is_default
= g_strcmp0(cur_hidden_str
, pref
->default_val
.string
) == 0;
2704 g_free(cur_hidden_str
);
2708 /* Number of columns "preference". This is only used internally and is not written to the
2712 column_num_reset_cb(pref_t
* pref
)
2714 *pref
->varp
.uint
= pref
->default_val
.uint
;
2717 static prefs_set_pref_e
2718 column_num_set_cb(pref_t
* pref _U_
, const char* value _U_
, unsigned int* changed_flags _U_
)
2720 /* Don't write this to the preferences file */
2721 return PREFS_SET_OK
;
2725 column_num_type_name_cb(void)
2731 column_num_type_description_cb(void)
2733 return g_strdup("");
2737 column_num_is_default_cb(pref_t
* pref _U_
)
2743 column_num_to_str_cb(pref_t
* pref _U_
, bool default_val _U_
)
2745 return g_strdup("");
2749 * Column format custom preference functions
2752 column_format_init_cb(pref_t
* pref
, GList
** value
)
2754 fmt_data
*src_cfmt
, *dest_cfmt
;
2757 pref
->varp
.list
= value
;
2759 pref
->default_val
.list
= NULL
;
2760 for (entry
= *pref
->varp
.list
; entry
!= NULL
; entry
= g_list_next(entry
)) {
2761 src_cfmt
= (fmt_data
*)entry
->data
;
2762 dest_cfmt
= g_new(fmt_data
,1);
2763 dest_cfmt
->title
= g_strdup(src_cfmt
->title
);
2764 dest_cfmt
->fmt
= src_cfmt
->fmt
;
2765 if (src_cfmt
->custom_fields
) {
2766 dest_cfmt
->custom_fields
= g_strdup(src_cfmt
->custom_fields
);
2767 dest_cfmt
->custom_occurrence
= src_cfmt
->custom_occurrence
;
2769 dest_cfmt
->custom_fields
= NULL
;
2770 dest_cfmt
->custom_occurrence
= 0;
2772 dest_cfmt
->visible
= src_cfmt
->visible
;
2773 dest_cfmt
->display
= src_cfmt
->display
;
2774 pref
->default_val
.list
= g_list_append(pref
->default_val
.list
, dest_cfmt
);
2777 column_register_fields();
2781 column_format_free_cb(pref_t
* pref
)
2783 free_col_info(*pref
->varp
.list
);
2784 free_col_info(pref
->default_val
.list
);
2788 column_format_reset_cb(pref_t
* pref
)
2790 fmt_data
*src_cfmt
, *dest_cfmt
;
2792 pref_t
*col_num_pref
;
2794 free_col_info(*pref
->varp
.list
);
2795 *pref
->varp
.list
= NULL
;
2797 for (entry
= pref
->default_val
.list
; entry
!= NULL
; entry
= g_list_next(entry
)) {
2798 src_cfmt
= (fmt_data
*)entry
->data
;
2799 dest_cfmt
= g_new(fmt_data
,1);
2800 dest_cfmt
->title
= g_strdup(src_cfmt
->title
);
2801 dest_cfmt
->fmt
= src_cfmt
->fmt
;
2802 if (src_cfmt
->custom_fields
) {
2803 dest_cfmt
->custom_fields
= g_strdup(src_cfmt
->custom_fields
);
2804 dest_cfmt
->custom_occurrence
= src_cfmt
->custom_occurrence
;
2806 dest_cfmt
->custom_fields
= NULL
;
2807 dest_cfmt
->custom_occurrence
= 0;
2809 dest_cfmt
->visible
= src_cfmt
->visible
;
2810 dest_cfmt
->display
= src_cfmt
->display
;
2811 *pref
->varp
.list
= g_list_append(*pref
->varp
.list
, dest_cfmt
);
2814 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2815 ws_assert(col_num_pref
!= NULL
); /* Should never happen */
2816 column_num_reset_cb(col_num_pref
);
2819 static prefs_set_pref_e
2820 column_format_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags _U_
)
2822 GList
*col_l
, *col_l_elt
;
2825 pref_t
*hidden_pref
, *col_num_pref
;
2827 col_l
= prefs_get_string_list(value
);
2829 return PREFS_SET_SYNTAX_ERR
;
2830 if ((g_list_length(col_l
) % 2) != 0) {
2831 /* A title didn't have a matching format. */
2832 prefs_clear_string_list(col_l
);
2833 return PREFS_SET_SYNTAX_ERR
;
2835 /* Check to make sure all column formats are valid. */
2836 col_l_elt
= g_list_first(col_l
);
2838 fmt_data cfmt_check
;
2840 /* Go past the title. */
2841 col_l_elt
= col_l_elt
->next
;
2843 /* Some predefined columns have been migrated to use custom columns.
2844 * We'll convert these silently here */
2845 try_convert_to_custom_column((char **)&col_l_elt
->data
);
2847 /* Parse the format to see if it's valid. */
2848 if (!parse_column_format(&cfmt_check
, (char *)col_l_elt
->data
)) {
2849 /* It's not a valid column format. */
2850 prefs_clear_string_list(col_l
);
2851 return PREFS_SET_SYNTAX_ERR
;
2853 if (cfmt_check
.fmt
== COL_CUSTOM
) {
2854 /* We don't need the custom column field on this pass. */
2855 g_free(cfmt_check
.custom_fields
);
2858 /* Go past the format. */
2859 col_l_elt
= col_l_elt
->next
;
2862 /* They're all valid; process them. */
2863 free_col_info(*pref
->varp
.list
);
2864 *pref
->varp
.list
= NULL
;
2865 if (prefs
.cols_hide_new
) {
2866 hidden_pref
= prefs_find_preference(gui_column_module
, PRS_COL_HIDDEN
);
2868 hidden_pref
= prefs_find_preference(gui_column_module
, PRS_COL_HIDDEN_FMT
);
2870 ws_assert(hidden_pref
!= NULL
); /* Should never happen */
2871 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2872 ws_assert(col_num_pref
!= NULL
); /* Should never happen */
2873 llen
= g_list_length(col_l
);
2874 *col_num_pref
->varp
.uint
= llen
/ 2;
2875 col_l_elt
= g_list_first(col_l
);
2878 cfmt
= g_new(fmt_data
,1);
2879 cfmt
->title
= g_strdup((char *)col_l_elt
->data
);
2880 col_l_elt
= col_l_elt
->next
;
2881 parse_column_format(cfmt
, (char *)col_l_elt
->data
);
2882 if (prefs
.cols_hide_new
) {
2883 cfmt
->visible
= prefs_is_column_visible(*hidden_pref
->varp
.string
, cidx
);
2885 cfmt
->visible
= prefs_is_column_fmt_visible(*hidden_pref
->varp
.string
, cfmt
);
2887 col_l_elt
= col_l_elt
->next
;
2888 *pref
->varp
.list
= g_list_append(*pref
->varp
.list
, cfmt
);
2892 prefs_clear_string_list(col_l
);
2893 free_string_like_preference(hidden_pref
);
2894 column_register_fields();
2895 return PREFS_SET_OK
;
2900 column_format_type_name_cb(void)
2902 return "Packet list column format";
2906 column_format_type_description_cb(void)
2908 return g_strdup("Each pair of strings consists of a column title and its format");
2912 column_format_is_default_cb(pref_t
* pref
)
2914 GList
*clp
= *pref
->varp
.list
,
2915 *pref_col
= g_list_first(clp
),
2916 *def_col
= g_list_first(pref
->default_val
.list
);
2917 fmt_data
*cfmt
, *def_cfmt
;
2918 bool is_default
= true;
2919 pref_t
*col_num_pref
;
2921 /* See if the column data has changed from the default */
2922 col_num_pref
= prefs_find_preference(gui_column_module
, PRS_COL_NUM
);
2923 if (col_num_pref
&& *col_num_pref
->varp
.uint
!= col_num_pref
->default_val
.uint
) {
2926 while (pref_col
&& def_col
) {
2927 cfmt
= (fmt_data
*) pref_col
->data
;
2928 def_cfmt
= (fmt_data
*) def_col
->data
;
2929 if ((g_strcmp0(cfmt
->title
, def_cfmt
->title
) != 0) ||
2930 (cfmt
->fmt
!= def_cfmt
->fmt
) ||
2931 (((cfmt
->fmt
== COL_CUSTOM
) && (cfmt
->custom_fields
)) &&
2932 ((g_strcmp0(cfmt
->custom_fields
, def_cfmt
->custom_fields
) != 0) ||
2933 (cfmt
->display
!= def_cfmt
->display
)))) {
2938 pref_col
= pref_col
->next
;
2939 def_col
= def_col
->next
;
2947 column_format_to_str_cb(pref_t
* pref
, bool default_val
)
2949 GList
*pref_l
= default_val
? pref
->default_val
.list
: *pref
->varp
.list
;
2950 GList
*clp
= g_list_first(pref_l
);
2953 char *column_format_str
;
2957 cfmt
= (fmt_data
*) clp
->data
;
2958 col_l
= g_list_append(col_l
, g_strdup(cfmt
->title
));
2959 col_l
= g_list_append(col_l
, column_fmt_data_to_str(cfmt
));
2963 column_format_str
= join_string_list(col_l
);
2964 prefs_clear_string_list(col_l
);
2965 return column_format_str
;
2969 /****** Capture column custom preference functions ******/
2971 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
2972 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
2973 to prefs->default_val.list.
2976 capture_column_init_cb(pref_t
* pref
, GList
** capture_cols_values
)
2978 GList
*ccv_list
= *capture_cols_values
,
2983 dlist
= g_list_append(dlist
, g_strdup((char *)ccv_list
->data
));
2984 ccv_list
= ccv_list
->next
;
2987 pref
->default_val
.list
= dlist
;
2988 pref
->varp
.list
= &prefs
.capture_columns
;
2989 pref
->stashed_val
.boolval
= false;
2992 /* Free the prefs->capture_columns list strings and remove the list entries.
2993 Note that since pref->varp.list points to &prefs.capture_columns, it is
2997 capture_column_free_cb(pref_t
* pref
)
2999 prefs_clear_string_list(prefs
.capture_columns
);
3000 prefs
.capture_columns
= NULL
;
3002 if (pref
->stashed_val
.boolval
== true) {
3003 prefs_clear_string_list(pref
->default_val
.list
);
3004 pref
->default_val
.list
= NULL
;
3008 /* Copy pref->default_val.list to *pref->varp.list.
3011 capture_column_reset_cb(pref_t
* pref
)
3013 GList
*vlist
= NULL
, *dlist
;
3015 /* Free the column name strings and remove the links from *pref->varp.list */
3016 prefs_clear_string_list(*pref
->varp
.list
);
3018 for (dlist
= pref
->default_val
.list
; dlist
!= NULL
; dlist
= g_list_next(dlist
)) {
3019 vlist
= g_list_append(vlist
, g_strdup((char *)dlist
->data
));
3021 *pref
->varp
.list
= vlist
;
3024 static prefs_set_pref_e
3025 capture_column_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags _U_
)
3027 GList
*col_l
= prefs_get_string_list(value
);
3033 return PREFS_SET_SYNTAX_ERR
;
3035 capture_column_free_cb(pref
);
3037 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
3038 to the full list of valid capture column names. */
3039 col_l_elt
= g_list_first(col_l
);
3040 if (!(*(char *)col_l_elt
->data
)) {
3041 for (i
= 0; i
< num_capture_cols
; i
++) {
3042 col_name
= g_strdup(capture_cols
[i
]);
3043 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3047 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
3050 bool found_match
= false;
3051 col_name
= (char *)col_l_elt
->data
;
3053 for (i
= 0; i
< num_capture_cols
; i
++) {
3054 if (strcmp(col_name
, capture_cols
[i
])==0) {
3060 /* One or more cols are invalid so use the entire list of valid cols. */
3061 for (i
= 0; i
< num_capture_cols
; i
++) {
3062 col_name
= g_strdup(capture_cols
[i
]);
3063 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3065 pref
->varp
.list
= &prefs
.capture_columns
;
3066 prefs_clear_string_list(col_l
);
3067 return PREFS_SET_SYNTAX_ERR
;
3069 col_l_elt
= col_l_elt
->next
;
3072 col_l_elt
= g_list_first(col_l
);
3074 col_name
= (char *)col_l_elt
->data
;
3075 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
3076 col_l_elt
= col_l_elt
->next
;
3078 pref
->varp
.list
= &prefs
.capture_columns
;
3080 return PREFS_SET_OK
;
3085 capture_column_type_name_cb(void)
3087 return "Column list";
3091 capture_column_type_description_cb(void)
3094 "List of columns to be displayed in the capture options dialog.\n"
3095 CAPTURE_COL_TYPE_DESCRIPTION
);
3099 capture_column_is_default_cb(pref_t
* pref
)
3101 GList
*pref_col
= g_list_first(prefs
.capture_columns
),
3102 *def_col
= g_list_first(pref
->default_val
.list
);
3103 bool is_default
= true;
3105 /* See if the column data has changed from the default */
3106 while (pref_col
&& def_col
) {
3107 if (strcmp((char *)pref_col
->data
, (char *)def_col
->data
) != 0) {
3111 pref_col
= pref_col
->next
;
3112 def_col
= def_col
->next
;
3115 /* Ensure the same column count */
3116 if (((pref_col
== NULL
) && (def_col
!= NULL
)) ||
3117 ((pref_col
!= NULL
) && (def_col
== NULL
)))
3124 capture_column_to_str_cb(pref_t
* pref
, bool default_val
)
3127 GList
*pref_l
= default_val
? pref
->default_val
.list
: prefs
.capture_columns
;
3128 GList
*clp
= g_list_first(pref_l
);
3129 GList
*col_l
= NULL
;
3131 char *capture_column_str
;
3134 col
= (char *) clp
->data
;
3135 col_l
= g_list_append(col_l
, g_strdup(col
));
3139 capture_column_str
= join_string_list(col_l
);
3140 prefs_clear_string_list(col_l
);
3141 return capture_column_str
;
3144 static prefs_set_pref_e
3145 colorized_frame_set_cb(pref_t
* pref
, const char* value
, unsigned int* changed_flags
)
3147 (*changed_flags
) |= prefs_set_string_value(pref
, value
, pref_current
);
3148 return PREFS_SET_OK
;
3152 colorized_frame_type_name_cb(void)
3154 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
3155 * file until the colors can be changed in the GUI. Currently this is not really
3156 * possible since the STOCK-icons for these colors are hardcoded.
3158 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
3159 * add these 10 colors to the list of colors that can be changed through
3167 colorized_frame_type_description_cb(void)
3169 return g_strdup("");
3173 colorized_frame_is_default_cb(pref_t
* pref _U_
)
3179 colorized_frame_to_str_cb(pref_t
* pref _U_
, bool default_val _U_
)
3181 return g_strdup("");
3185 * Register all non-dissector modules' preferences.
3187 static module_t
*gui_module
;
3188 static module_t
*gui_color_module
;
3189 static module_t
*nameres_module
;
3192 prefs_register_modules(void)
3194 module_t
*printing
, *capture_module
, *console_module
,
3195 *gui_layout_module
, *gui_font_module
;
3196 module_t
*extcap_module
;
3197 unsigned int layout_gui_flags
;
3198 struct pref_custom_cbs custom_cbs
;
3200 if (protocols_module
!= NULL
) {
3201 /* Already setup preferences */
3206 * These are "simple" GUI preferences that can be read/written using the
3207 * preference module API. These preferences still use their own
3208 * configuration screens for access, but this cuts down on the
3209 * preference "string compare list" in set_pref()
3211 extcap_module
= prefs_register_module(NULL
, "extcap", "Extcap Utilities",
3212 "Extcap Utilities", NULL
, NULL
, false);
3214 /* Setting default value to true */
3215 prefs
.extcap_save_on_start
= true;
3216 prefs_register_bool_preference(extcap_module
, "gui_save_on_start",
3217 "Save arguments on start of capture",
3218 "Save arguments on start of capture",
3219 &prefs
.extcap_save_on_start
);
3222 * These are "simple" GUI preferences that can be read/written using the
3223 * preference module API. These preferences still use their own
3224 * configuration screens for access, but this cuts down on the
3225 * preference "string compare list" in set_pref()
3227 gui_module
= prefs_register_module(NULL
, "gui", "User Interface",
3228 "User Interface", NULL
, &gui_callback
, false);
3230 * The GUI preferences don't affect dissection in general.
3231 * Any changes are signaled in other ways, so PREF_EFFECT_GUI doesn't
3232 * explicitly do anything, but wslua_set_preference expects *some*
3233 * effect flag to be set if the preference was changed.
3234 * We have to do this again for all the submodules (except for the
3235 * layout submodule, which has its own effect flag).
3237 unsigned gui_effect_flags
= prefs_get_module_effect_flags(gui_module
);
3238 gui_effect_flags
|= PREF_EFFECT_GUI
;
3239 gui_effect_flags
&= (~PREF_EFFECT_DISSECTION
);
3240 prefs_set_module_effect_flags(gui_module
, gui_effect_flags
);
3243 * gui.console_open is stored in the registry in addition to the
3244 * preferences file. It is also read independently by ws_log_init()
3245 * for early log initialization of the console.
3247 prefs_register_enum_preference(gui_module
, "console_open",
3248 "Open a console window",
3249 "Open a console window (Windows only)",
3250 (int *)&ws_log_console_open
, gui_console_open_type
, false);
3252 prefs_register_obsolete_preference(gui_module
, "scrollbar_on_right");
3253 prefs_register_obsolete_preference(gui_module
, "packet_list_sel_browse");
3254 prefs_register_obsolete_preference(gui_module
, "protocol_tree_sel_browse");
3255 prefs_register_obsolete_preference(gui_module
, "tree_view_altern_colors");
3256 prefs_register_obsolete_preference(gui_module
, "expert_composite_eyecandy");
3257 prefs_register_obsolete_preference(gui_module
, "filter_toolbar_show_in_statusbar");
3259 prefs_register_bool_preference(gui_module
, "restore_filter_after_following_stream",
3260 "Restore current display filter after following a stream",
3261 "Restore current display filter after following a stream?",
3262 &prefs
.restore_filter_after_following_stream
);
3264 prefs_register_obsolete_preference(gui_module
, "protocol_tree_line_style");
3266 prefs_register_obsolete_preference(gui_module
, "protocol_tree_expander_style");
3268 prefs_register_obsolete_preference(gui_module
, "hex_dump_highlight_style");
3270 prefs_register_obsolete_preference(gui_module
, "packet_editor.enabled");
3272 gui_column_module
= prefs_register_subtree(gui_module
, "Columns", "Columns", NULL
);
3273 prefs_set_module_effect_flags(gui_column_module
, gui_effect_flags
);
3274 /* For reading older preference files with "column." preferences */
3275 prefs_register_module_alias("column", gui_column_module
);
3278 custom_cbs
.free_cb
= free_string_like_preference
;
3279 custom_cbs
.reset_cb
= reset_string_like_preference
;
3280 custom_cbs
.set_cb
= column_hidden_set_cb
;
3281 custom_cbs
.type_name_cb
= column_hidden_type_name_cb
;
3282 custom_cbs
.type_description_cb
= column_hidden_type_description_cb
;
3283 custom_cbs
.is_default_cb
= column_hidden_is_default_cb
;
3284 custom_cbs
.to_str_cb
= column_hidden_to_str_cb
;
3285 register_string_like_preference(gui_column_module
, PRS_COL_HIDDEN
, "Packet list hidden columns",
3286 "List all column indices (1-indexed) to hide in the packet list",
3287 &cols_hidden_list
, PREF_CUSTOM
, &custom_cbs
, false);
3289 custom_cbs
.set_cb
= column_hidden_fmt_set_cb
;
3290 custom_cbs
.type_name_cb
= column_hidden_fmt_type_name_cb
;
3291 custom_cbs
.type_description_cb
= column_hidden_fmt_type_description_cb
;
3292 custom_cbs
.is_default_cb
= column_hidden_fmt_is_default_cb
;
3293 custom_cbs
.to_str_cb
= column_hidden_fmt_to_str_cb
;
3295 register_string_like_preference(gui_column_module
, PRS_COL_HIDDEN_FMT
, "Packet list hidden column formats (deprecated)",
3296 "List all column formats to hide in the packet list; deprecated in favor of the index-based preference",
3297 &cols_hidden_fmt_list
, PREF_CUSTOM
, &custom_cbs
, false);
3299 custom_cbs
.free_cb
= column_format_free_cb
;
3300 custom_cbs
.reset_cb
= column_format_reset_cb
;
3301 custom_cbs
.set_cb
= column_format_set_cb
;
3302 custom_cbs
.type_name_cb
= column_format_type_name_cb
;
3303 custom_cbs
.type_description_cb
= column_format_type_description_cb
;
3304 custom_cbs
.is_default_cb
= column_format_is_default_cb
;
3305 custom_cbs
.to_str_cb
= column_format_to_str_cb
;
3307 prefs_register_list_custom_preference(gui_column_module
, PRS_COL_FMT
, "Packet list column format",
3308 "Each pair of strings consists of a column title and its format", &custom_cbs
,
3309 column_format_init_cb
, &prefs
.col_list
);
3311 /* Number of columns. This is only used internally and is not written to the
3314 custom_cbs
.free_cb
= custom_pref_no_cb
;
3315 custom_cbs
.reset_cb
= column_num_reset_cb
;
3316 custom_cbs
.set_cb
= column_num_set_cb
;
3317 custom_cbs
.type_name_cb
= column_num_type_name_cb
;
3318 custom_cbs
.type_description_cb
= column_num_type_description_cb
;
3319 custom_cbs
.is_default_cb
= column_num_is_default_cb
;
3320 custom_cbs
.to_str_cb
= column_num_to_str_cb
;
3321 prefs_register_uint_custom_preference(gui_column_module
, PRS_COL_NUM
, "Number of columns",
3322 "Number of columns in col_list", &custom_cbs
, &prefs
.num_cols
);
3324 /* User Interface : Font */
3325 gui_font_module
= prefs_register_subtree(gui_module
, "Font", "Font", NULL
);
3326 prefs_set_module_effect_flags(gui_font_module
, gui_effect_flags
);
3328 prefs_register_obsolete_preference(gui_font_module
, "font_name");
3330 prefs_register_obsolete_preference(gui_font_module
, "gtk2.font_name");
3332 register_string_like_preference(gui_font_module
, "qt.font_name", "Font name",
3333 "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
3334 &prefs
.gui_font_name
, PREF_STRING
, NULL
, true);
3336 /* User Interface : Colors */
3337 gui_color_module
= prefs_register_subtree(gui_module
, "Colors", "Colors", NULL
);
3338 unsigned gui_color_effect_flags
= gui_effect_flags
| PREF_EFFECT_GUI_COLOR
;
3339 prefs_set_module_effect_flags(gui_color_module
, gui_color_effect_flags
);
3341 prefs_register_enum_preference(gui_color_module
, "color_scheme", "Color scheme", "Color scheme",
3342 &prefs
.gui_color_scheme
, gui_color_scheme
, false);
3344 prefs_register_color_preference(gui_color_module
, "active_frame.fg", "Foreground color for an active selected item",
3345 "Foreground color for an active selected item", &prefs
.gui_active_fg
);
3347 prefs_register_color_preference(gui_color_module
, "active_frame.bg", "Background color for an active selected item",
3348 "Background color for an active selected item", &prefs
.gui_active_bg
);
3350 prefs_register_enum_preference(gui_color_module
, "active_frame.style", "Color style for an active selected item",
3351 "Color style for an active selected item", &prefs
.gui_active_style
, gui_selection_style
, false);
3353 prefs_register_color_preference(gui_color_module
, "inactive_frame.fg", "Foreground color for an inactive selected item",
3354 "Foreground color for an inactive selected item", &prefs
.gui_inactive_fg
);
3356 prefs_register_color_preference(gui_color_module
, "inactive_frame.bg", "Background color for an inactive selected item",
3357 "Background color for an inactive selected item", &prefs
.gui_inactive_bg
);
3359 prefs_register_enum_preference(gui_color_module
, "inactive_frame.style", "Color style for an inactive selected item",
3360 "Color style for an inactive selected item", &prefs
.gui_inactive_style
, gui_selection_style
, false);
3362 prefs_register_color_preference(gui_color_module
, "marked_frame.fg", "Color preferences for a marked frame",
3363 "Color preferences for a marked frame", &prefs
.gui_marked_fg
);
3365 prefs_register_color_preference(gui_color_module
, "marked_frame.bg", "Color preferences for a marked frame",
3366 "Color preferences for a marked frame", &prefs
.gui_marked_bg
);
3368 prefs_register_color_preference(gui_color_module
, "ignored_frame.fg", "Color preferences for a ignored frame",
3369 "Color preferences for a ignored frame", &prefs
.gui_ignored_fg
);
3371 prefs_register_color_preference(gui_color_module
, "ignored_frame.bg", "Color preferences for a ignored frame",
3372 "Color preferences for a ignored frame", &prefs
.gui_ignored_bg
);
3374 prefs_register_color_preference(gui_color_module
, "stream.client.fg", "TCP stream window color preference",
3375 "TCP stream window color preference", &prefs
.st_client_fg
);
3377 prefs_register_color_preference(gui_color_module
, "stream.client.bg", "TCP stream window color preference",
3378 "TCP stream window color preference", &prefs
.st_client_bg
);
3380 prefs_register_color_preference(gui_color_module
, "stream.server.fg", "TCP stream window color preference",
3381 "TCP stream window color preference", &prefs
.st_server_fg
);
3383 prefs_register_color_preference(gui_color_module
, "stream.server.bg", "TCP stream window color preference",
3384 "TCP stream window color preference", &prefs
.st_server_bg
);
3386 custom_cbs
.free_cb
= free_string_like_preference
;
3387 custom_cbs
.reset_cb
= reset_string_like_preference
;
3388 custom_cbs
.set_cb
= colorized_frame_set_cb
;
3389 custom_cbs
.type_name_cb
= colorized_frame_type_name_cb
;
3390 custom_cbs
.type_description_cb
= colorized_frame_type_description_cb
;
3391 custom_cbs
.is_default_cb
= colorized_frame_is_default_cb
;
3392 custom_cbs
.to_str_cb
= colorized_frame_to_str_cb
;
3393 register_string_like_preference(gui_column_module
, "colorized_frame.fg", "Colorized Foreground",
3394 "Filter Colorized Foreground",
3395 &prefs
.gui_colorized_fg
, PREF_CUSTOM
, &custom_cbs
, true);
3397 custom_cbs
.free_cb
= free_string_like_preference
;
3398 custom_cbs
.reset_cb
= reset_string_like_preference
;
3399 custom_cbs
.set_cb
= colorized_frame_set_cb
;
3400 custom_cbs
.type_name_cb
= colorized_frame_type_name_cb
;
3401 custom_cbs
.type_description_cb
= colorized_frame_type_description_cb
;
3402 custom_cbs
.is_default_cb
= colorized_frame_is_default_cb
;
3403 custom_cbs
.to_str_cb
= colorized_frame_to_str_cb
;
3404 register_string_like_preference(gui_column_module
, "colorized_frame.bg", "Colorized Background",
3405 "Filter Colorized Background",
3406 &prefs
.gui_colorized_bg
, PREF_CUSTOM
, &custom_cbs
, true);
3408 prefs_register_color_preference(gui_color_module
, "color_filter_bg.valid", "Valid color filter background",
3409 "Valid color filter background", &prefs
.gui_text_valid
);
3411 prefs_register_color_preference(gui_color_module
, "color_filter_bg.invalid", "Invalid color filter background",
3412 "Invalid color filter background", &prefs
.gui_text_invalid
);
3414 prefs_register_color_preference(gui_color_module
, "color_filter_bg.deprecated", "Deprecated color filter background",
3415 "Deprecated color filter background", &prefs
.gui_text_deprecated
);
3417 prefs_register_enum_preference(gui_module
, "fileopen.style",
3418 "Where to start the File Open dialog box",
3419 "Where to start the File Open dialog box",
3420 &prefs
.gui_fileopen_style
, gui_fileopen_style
, false);
3422 prefs_register_uint_preference(gui_module
, "recent_files_count.max",
3423 "The max. number of items in the open recent files list",
3424 "The max. number of items in the open recent files list",
3426 &prefs
.gui_recent_files_count_max
);
3428 prefs_register_uint_preference(gui_module
, "recent_display_filter_entries.max",
3429 "The max. number of entries in the display filter list",
3430 "The max. number of entries in the display filter list",
3432 &prefs
.gui_recent_df_entries_max
);
3434 register_string_like_preference(gui_module
, "fileopen.dir", "Start Directory",
3435 "Directory to start in when opening File Open dialog.",
3436 &prefs
.gui_fileopen_dir
, PREF_DIRNAME
, NULL
, true);
3438 prefs_register_obsolete_preference(gui_module
, "fileopen.remembered_dir");
3440 prefs_register_uint_preference(gui_module
, "fileopen.preview",
3441 "The preview timeout in the File Open dialog",
3442 "The preview timeout in the File Open dialog",
3444 &prefs
.gui_fileopen_preview
);
3446 register_string_like_preference(gui_module
, "tlskeylog_command", "Program to launch with TLS Keylog",
3447 "Program path or command line to launch with SSLKEYLOGFILE",
3448 &prefs
.gui_tlskeylog_command
, PREF_STRING
, NULL
, true);
3450 prefs_register_bool_preference(gui_module
, "ask_unsaved",
3451 "Ask to save unsaved capture files",
3452 "Ask to save unsaved capture files?",
3453 &prefs
.gui_ask_unsaved
);
3455 prefs_register_bool_preference(gui_module
, "autocomplete_filter",
3456 "Display autocompletion for filter text",
3457 "Display an autocomplete suggestion for display and capture filter controls",
3458 &prefs
.gui_autocomplete_filter
);
3460 prefs_register_bool_preference(gui_module
, "find_wrap",
3461 "Wrap to beginning/end of file during search",
3462 "Wrap to beginning/end of file during search?",
3463 &prefs
.gui_find_wrap
);
3465 prefs_register_obsolete_preference(gui_module
, "use_pref_save");
3467 prefs_register_bool_preference(gui_module
, "geometry.save.position",
3468 "Save window position at exit",
3469 "Save window position at exit?",
3470 &prefs
.gui_geometry_save_position
);
3472 prefs_register_bool_preference(gui_module
, "geometry.save.size",
3473 "Save window size at exit",
3474 "Save window size at exit?",
3475 &prefs
.gui_geometry_save_size
);
3477 prefs_register_bool_preference(gui_module
, "geometry.save.maximized",
3478 "Save window maximized state at exit",
3479 "Save window maximized state at exit?",
3480 &prefs
.gui_geometry_save_maximized
);
3482 prefs_register_obsolete_preference(gui_module
, "macosx_style");
3484 prefs_register_obsolete_preference(gui_module
, "geometry.main.x");
3485 prefs_register_obsolete_preference(gui_module
, "geometry.main.y");
3486 prefs_register_obsolete_preference(gui_module
, "geometry.main.width");
3487 prefs_register_obsolete_preference(gui_module
, "geometry.main.height");
3488 prefs_register_obsolete_preference(gui_module
, "toolbar_main_show");
3490 prefs_register_enum_preference(gui_module
, "toolbar_main_style",
3491 "Main Toolbar style",
3492 "Main Toolbar style",
3493 &prefs
.gui_toolbar_main_style
, gui_toolbar_style
, false);
3495 prefs_register_obsolete_preference(gui_module
, "toolbar_filter_style");
3496 prefs_register_obsolete_preference(gui_module
, "webbrowser");
3498 prefs_register_bool_preference(gui_module
, "update.enabled",
3499 "Check for updates",
3500 "Check for updates (Windows and macOS only)",
3501 &prefs
.gui_update_enabled
);
3503 prefs_register_enum_preference(gui_module
, "update.channel",
3505 "The type of update to fetch. You should probably leave this set to STABLE.",
3506 (int*)(void*)(&prefs
.gui_update_channel
), gui_update_channel
, false);
3508 prefs_register_uint_preference(gui_module
, "update.interval",
3509 "How often to check for software updates",
3510 "How often to check for software updates in seconds",
3512 &prefs
.gui_update_interval
);
3514 prefs_register_uint_preference(gui_module
, "debounce.timer",
3515 "How long to wait before processing computationally intensive user input",
3516 "How long to wait (in milliseconds) before processing "
3517 "computationally intensive user input. "
3518 "If you type quickly, consider lowering the value for a 'snappier' "
3520 "If you type slowly, consider increasing the value to avoid performance issues. "
3521 "This is currently used to delay searches in View -> Internals -> Supported Protocols "
3522 "and Preferences -> Advanced menu.",
3524 &prefs
.gui_debounce_timer
);
3526 register_string_like_preference(gui_module
, "window_title", "Custom window title",
3527 "Custom window title to be appended to the existing title\n"
3528 "%C = capture comment from command line\n"
3529 "%F = file path of the capture file\n"
3530 "%P = profile name\n"
3531 "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3532 "%V = version info",
3533 &prefs
.gui_window_title
, PREF_STRING
, NULL
, true);
3535 register_string_like_preference(gui_module
, "prepend_window_title", "Custom window title prefix",
3536 "Custom window title to be prepended to the existing title\n"
3537 "%C = capture comment from command line\n"
3538 "%F = file path of the capture file\n"
3539 "%P = profile name\n"
3540 "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3541 "%V = version info",
3542 &prefs
.gui_prepend_window_title
, PREF_STRING
, NULL
, true);
3544 register_string_like_preference(gui_module
, "start_title", "Custom start page title",
3545 "Custom start page title",
3546 &prefs
.gui_start_title
, PREF_STRING
, NULL
, true);
3548 prefs_register_enum_preference(gui_module
, "version_placement",
3549 "Show version in the start page and/or main screen's title bar",
3550 "Show version in the start page and/or main screen's title bar",
3551 (int*)(void*)(&prefs
.gui_version_placement
), gui_version_placement_type
, false);
3553 prefs_register_obsolete_preference(gui_module
, "auto_scroll_on_expand");
3554 prefs_register_obsolete_preference(gui_module
, "auto_scroll_percentage");
3556 prefs_register_uint_preference(gui_module
, "max_export_objects",
3557 "Maximum number of exported objects",
3558 "The maximum number of objects that can be exported",
3560 &prefs
.gui_max_export_objects
);
3561 prefs_register_uint_preference(gui_module
, "max_tree_items",
3562 "Maximum number of tree items",
3563 "The maximum number of items that can be added to the dissection tree (Increase with caution)",
3565 &prefs
.gui_max_tree_items
);
3567 * Used independently by proto_tree_add_node, call_dissector*, dissector_try_heuristic,
3568 * and increment_dissection_depth.
3570 prefs_register_uint_preference(gui_module
, "max_tree_depth",
3571 "Maximum dissection depth",
3572 "The maximum depth for dissection tree and protocol layer checks. (Increase with caution)",
3574 &prefs
.gui_max_tree_depth
);
3576 prefs_register_bool_preference(gui_module
, "welcome_page.show_recent",
3577 "Show recent files on the welcome page",
3578 "This will enable or disable the 'Open' list on the welcome page.",
3579 &prefs
.gui_welcome_page_show_recent
);
3581 /* User Interface : Layout */
3582 gui_layout_module
= prefs_register_subtree(gui_module
, "Layout", "Layout", gui_layout_callback
);
3583 /* Adjust the preference effects of layout GUI for better handling of preferences at Wireshark (GUI) level */
3584 layout_gui_flags
= prefs_get_module_effect_flags(gui_layout_module
);
3585 layout_gui_flags
|= PREF_EFFECT_GUI_LAYOUT
;
3586 layout_gui_flags
&= (~PREF_EFFECT_DISSECTION
);
3588 prefs_register_uint_preference(gui_layout_module
, "layout_type",
3590 "Layout type (1-6)",
3592 (unsigned*)(void*)(&prefs
.gui_layout_type
));
3593 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_type", layout_gui_flags
);
3595 prefs_register_enum_preference(gui_layout_module
, "layout_content_1",
3596 "Layout content of the pane 1",
3597 "Layout content of the pane 1",
3598 (int*)(void*)(&prefs
.gui_layout_content_1
), gui_layout_content
, false);
3599 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_1", layout_gui_flags
);
3601 prefs_register_enum_preference(gui_layout_module
, "layout_content_2",
3602 "Layout content of the pane 2",
3603 "Layout content of the pane 2",
3604 (int*)(void*)(&prefs
.gui_layout_content_2
), gui_layout_content
, false);
3605 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_2", layout_gui_flags
);
3607 prefs_register_enum_preference(gui_layout_module
, "layout_content_3",
3608 "Layout content of the pane 3",
3609 "Layout content of the pane 3",
3610 (int*)(void*)(&prefs
.gui_layout_content_3
), gui_layout_content
, false);
3611 prefs_set_effect_flags_by_name(gui_layout_module
, "layout_content_3", layout_gui_flags
);
3613 prefs_register_bool_preference(gui_layout_module
, "packet_list_separator.enabled",
3614 "Enable Packet List Separator",
3615 "Enable Packet List Separator",
3616 &prefs
.gui_packet_list_separator
);
3618 prefs_register_bool_preference(gui_layout_module
, "packet_header_column_definition.enabled",
3619 "Show column definition in packet list header",
3620 "Show column definition in packet list header",
3621 &prefs
.gui_packet_header_column_definition
);
3623 /* packet_list_hover_style affects the colors, not the layout.
3624 * It's in the layout module to group it with the other packet list
3625 * preferences for the user's benefit with the dialog.
3627 prefs_register_bool_preference(gui_layout_module
, "packet_list_hover_style.enabled",
3628 "Enable Packet List mouse-over colorization",
3629 "Enable Packet List mouse-over colorization",
3630 &prefs
.gui_packet_list_hover_style
);
3631 prefs_set_effect_flags_by_name(gui_layout_module
, "packet_list_hover_style.enabled", gui_color_effect_flags
);
3633 prefs_register_bool_preference(gui_layout_module
, "show_selected_packet.enabled",
3634 "Show selected packet in the Status Bar",
3635 "Show selected packet in the Status Bar",
3636 &prefs
.gui_show_selected_packet
);
3638 prefs_register_bool_preference(gui_layout_module
, "show_file_load_time.enabled",
3639 "Show file load time in the Status Bar",
3640 "Show file load time in the Status Bar",
3641 &prefs
.gui_show_file_load_time
);
3643 prefs_register_enum_preference(gui_layout_module
, "packet_dialog_layout",
3644 "Packet Dialog layout",
3645 "Packet Dialog layout",
3646 (unsigned*)(void*)(&prefs
.gui_packet_dialog_layout
), gui_packet_dialog_layout
, false);
3648 prefs_register_enum_preference(gui_module
, "packet_list_elide_mode",
3650 "The position of \"...\" (ellipsis) in packet list text.",
3651 (int*)(void*)(&prefs
.gui_packet_list_elide_mode
), gui_packet_list_elide_mode
, false);
3652 prefs_register_uint_preference(gui_module
, "decimal_places1",
3653 "Count of decimal places for values of type 1",
3654 "Sets the count of decimal places for values of type 1."
3655 "Type 1 values are defined by authors."
3656 "Value can be in range 2 to 10.",
3657 10,&prefs
.gui_decimal_places1
);
3659 prefs_register_uint_preference(gui_module
, "decimal_places2",
3660 "Count of decimal places for values of type 2",
3661 "Sets the count of decimal places for values of type 2."
3662 "Type 2 values are defined by authors."
3663 "Value can be in range 2 to 10.",
3664 10,&prefs
.gui_decimal_places2
);
3666 prefs_register_uint_preference(gui_module
, "decimal_places3",
3667 "Count of decimal places for values of type 3",
3668 "Sets the count of decimal places for values of type 3."
3669 "Type 3 values are defined by authors."
3670 "Value can be in range 2 to 10.",
3671 10,&prefs
.gui_decimal_places3
);
3673 prefs_register_bool_preference(gui_module
, "rtp_player_use_disk1",
3674 "RTP Player saves temporary data to disk",
3675 "If set to true, RTP Player saves temporary data to "
3676 "temp files on disk. If not set, it uses memory."
3677 "Every stream uses one file therefore you might touch "
3678 "OS limit for count of opened files."
3679 "When ui.rtp_player_use_disk2 is set to true too, it uses "
3680 " two files per RTP stream together."
3681 ,&prefs
.gui_rtp_player_use_disk1
);
3683 prefs_register_bool_preference(gui_module
, "rtp_player_use_disk2",
3684 "RTP Player saves temporary dictionary for data to disk",
3685 "If set to true, RTP Player saves temporary dictionary to "
3686 "temp files on disk. If not set, it uses memory."
3687 "Every stream uses one file therefore you might touch "
3688 "OS limit for count of opened files."
3689 "When ui.rtp_player_use_disk1 is set to true too, it uses "
3690 " two files per RTP stream."
3691 ,&prefs
.gui_rtp_player_use_disk2
);
3693 prefs_register_enum_preference(gui_layout_module
, "gui_packet_list_copy_format_options_for_keyboard_shortcut",
3694 "Allows text to be copied with selected format",
3695 "Allows text to be copied with selected format when copied via keyboard",
3696 (int*)(void*)(&prefs
.gui_packet_list_copy_format_options_for_keyboard_shortcut
),
3697 gui_packet_list_copy_format_options_for_keyboard_shortcut
, false);
3699 prefs_register_bool_preference(gui_layout_module
, "gui_packet_list_copy_text_with_aligned_columns",
3700 "Allows text to be copied with aligned columns",
3701 "Allows text to be copied with aligned columns when copied via menu or keyboard",
3702 &prefs
.gui_packet_list_copy_text_with_aligned_columns
);
3704 prefs_register_bool_preference(gui_layout_module
, "packet_list_show_related",
3705 "Show Related Packets",
3706 "Show related packet indicators in the first column",
3707 &prefs
.gui_packet_list_show_related
);
3709 prefs_register_bool_preference(gui_layout_module
, "packet_list_show_minimap",
3710 "Enable Intelligent Scroll Bar",
3711 "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
3712 &prefs
.gui_packet_list_show_minimap
);
3714 prefs_register_bool_preference(gui_module
, "packet_list_is_sortable",
3715 "Allow packet list to be sortable",
3716 "To prevent sorting by mistake (which can take some time to calculate), it can be disabled",
3717 &prefs
.gui_packet_list_sortable
);
3719 prefs_register_uint_preference(gui_module
, "packet_list_cached_rows_max",
3720 "Maximum cached rows",
3721 "Maximum number of rows that can be sorted by columns that require dissection. Increasing this increases memory consumption by caching column text",
3723 &prefs
.gui_packet_list_cached_rows_max
);
3725 prefs_register_bool_preference(gui_module
, "interfaces_show_hidden",
3726 "Show hidden interfaces",
3727 "Show all interfaces, including interfaces marked as hidden",
3728 &prefs
.gui_interfaces_show_hidden
);
3730 prefs_register_bool_preference(gui_module
, "interfaces_remote_display",
3731 "Show Remote interfaces",
3732 "Show remote interfaces in the interface selection",
3733 &prefs
.gui_interfaces_remote_display
);
3735 register_string_like_preference(gui_module
, "interfaces_hidden_types", "Hide interface types in list",
3736 "Hide the given interface types in the startup list.\n"
3737 "A comma-separated string of interface type values (e.g. 5,9).\n"
3746 "8 = External Capture,\n"
3748 &prefs
.gui_interfaces_hide_types
, PREF_STRING
, NULL
, true);
3750 prefs_register_bool_preference(gui_module
, "io_graph_automatic_update",
3751 "Enables automatic updates for IO Graph",
3752 "Enables automatic updates for IO Graph",
3753 &prefs
.gui_io_graph_automatic_update
);
3755 prefs_register_bool_preference(gui_module
, "io_graph_enable_legend",
3756 "Enables the legend of IO Graph",
3757 "Enables the legend of IO Graph",
3758 &prefs
.gui_io_graph_enable_legend
);
3760 prefs_register_bool_preference(gui_module
, "show_byteview_in_dialog",
3761 "Show the byte view in the packet details dialog",
3762 "Show the byte view in the packet details dialog",
3763 &prefs
.gui_packet_details_show_byteview
);
3766 * These are preferences that can be read/written using the
3767 * preference module API. These preferences still use their own
3768 * configuration screens for access, but this cuts down on the
3769 * preference "string compare list" in set_pref()
3771 console_module
= prefs_register_module(NULL
, "console", "Console",
3772 "Console logging and debugging output", NULL
, NULL
, false);
3774 prefs_register_obsolete_preference(console_module
, "log.level");
3776 prefs_register_bool_preference(console_module
, "incomplete_dissectors_check_debug",
3777 "Print debug line for incomplete dissectors",
3778 "Look for dissectors that left some bytes undecoded (debug)",
3779 &prefs
.incomplete_dissectors_check_debug
);
3781 /* Display filter Expressions
3782 * This used to be an array of individual fields that has now been
3783 * converted to a UAT. Just make it part of the GUI category even
3784 * though the name of the preference will never be seen in preference
3787 filter_expression_register_uat(gui_module
);
3790 * These are preferences that can be read/written using the
3791 * preference module API. These preferences still use their own
3792 * configuration screens for access, but this cuts down on the
3793 * preference "string compare list" in set_pref()
3795 capture_module
= prefs_register_module(NULL
, "capture", "Capture",
3796 "Capture preferences", NULL
, NULL
, false);
3797 /* Capture preferences don't affect dissection */
3798 prefs_set_module_effect_flags(capture_module
, PREF_EFFECT_CAPTURE
);
3800 register_string_like_preference(capture_module
, "device", "Default capture device",
3801 "Default capture device",
3802 &prefs
.capture_device
, PREF_STRING
, NULL
, false);
3804 register_string_like_preference(capture_module
, "devices_linktypes", "Interface link-layer header type",
3805 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
3806 &prefs
.capture_devices_linktypes
, PREF_STRING
, NULL
, false);
3808 register_string_like_preference(capture_module
, "devices_descr", "Interface descriptions",
3809 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
3810 &prefs
.capture_devices_descr
, PREF_STRING
, NULL
, false);
3812 register_string_like_preference(capture_module
, "devices_hide", "Hide interface",
3813 "Hide interface? (Ex: eth0,eth3,...)",
3814 &prefs
.capture_devices_hide
, PREF_STRING
, NULL
, false);
3816 register_string_like_preference(capture_module
, "devices_monitor_mode", "Capture in monitor mode",
3817 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
3818 &prefs
.capture_devices_monitor_mode
, PREF_STRING
, NULL
, false);
3820 register_string_like_preference(capture_module
, "devices_buffersize", "Interface buffer size",
3821 "Interface buffer size (Ex: en0(1),en1(143),...)",
3822 &prefs
.capture_devices_buffersize
, PREF_STRING
, NULL
, false);
3824 register_string_like_preference(capture_module
, "devices_snaplen", "Interface snap length",
3825 "Interface snap length (Ex: en0(65535),en1(1430),...)",
3826 &prefs
.capture_devices_snaplen
, PREF_STRING
, NULL
, false);
3828 register_string_like_preference(capture_module
, "devices_pmode", "Interface promiscuous mode",
3829 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
3830 &prefs
.capture_devices_pmode
, PREF_STRING
, NULL
, false);
3832 prefs_register_bool_preference(capture_module
, "prom_mode", "Capture in promiscuous mode",
3833 "Capture in promiscuous mode?", &prefs
.capture_prom_mode
);
3835 prefs_register_bool_preference(capture_module
, "monitor_mode", "Capture in monitor mode on 802.11 devices",
3836 "Capture in monitor mode on all 802.11 devices that support it?", &prefs
.capture_monitor_mode
);
3838 register_string_like_preference(capture_module
, "devices_filter", "Interface capture filter",
3839 "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
3840 &prefs
.capture_devices_filter
, PREF_STRING
, NULL
, false);
3842 prefs_register_bool_preference(capture_module
, "pcap_ng", "Capture in pcapng format",
3843 "Capture in pcapng format?", &prefs
.capture_pcap_ng
);
3845 prefs_register_bool_preference(capture_module
, "real_time_update", "Update packet list in real time during capture",
3846 "Update packet list in real time during capture?", &prefs
.capture_real_time
);
3848 prefs_register_uint_preference(capture_module
, "update_interval",
3849 "Capture update interval",
3850 "Capture update interval in ms",
3852 &prefs
.capture_update_interval
);
3854 prefs_register_bool_preference(capture_module
, "no_interface_load", "Don't load interfaces on startup",
3855 "Don't automatically load capture interfaces on startup", &prefs
.capture_no_interface_load
);
3857 prefs_register_bool_preference(capture_module
, "no_extcap", "Disable external capture interfaces",
3858 "Disable external capture modules (extcap)", &prefs
.capture_no_extcap
);
3860 prefs_register_obsolete_preference(capture_module
, "auto_scroll");
3862 prefs_register_bool_preference(capture_module
, "show_info", "Show capture information dialog while capturing",
3863 "Show capture information dialog while capturing?", &prefs
.capture_show_info
);
3865 prefs_register_obsolete_preference(capture_module
, "syntax_check_filter");
3867 custom_cbs
.free_cb
= capture_column_free_cb
;
3868 custom_cbs
.reset_cb
= capture_column_reset_cb
;
3869 custom_cbs
.set_cb
= capture_column_set_cb
;
3870 custom_cbs
.type_name_cb
= capture_column_type_name_cb
;
3871 custom_cbs
.type_description_cb
= capture_column_type_description_cb
;
3872 custom_cbs
.is_default_cb
= capture_column_is_default_cb
;
3873 custom_cbs
.to_str_cb
= capture_column_to_str_cb
;
3874 prefs_register_list_custom_preference(capture_module
, "columns", "Capture options dialog column list",
3875 "List of columns to be displayed", &custom_cbs
, capture_column_init_cb
, &prefs
.capture_columns
);
3877 /* Name Resolution */
3878 nameres_module
= prefs_register_module(NULL
, "nameres", "Name Resolution",
3879 "Name Resolution", "ChCustPreferencesSection.html#ChCustPrefsNameSection", addr_resolve_pref_apply
, true);
3880 addr_resolve_pref_init(nameres_module
);
3881 oid_pref_init(nameres_module
);
3882 maxmind_db_pref_init(nameres_module
);
3885 * None of these have any effect; we keep them as obsolete preferences
3886 * in order to avoid errors when reading older preference files.
3888 printing
= prefs_register_module(NULL
, "print", "Printing",
3889 "Printing", NULL
, NULL
, false);
3890 prefs_register_obsolete_preference(printing
, "format");
3891 prefs_register_obsolete_preference(printing
, "command");
3892 prefs_register_obsolete_preference(printing
, "file");
3895 codecs_module
= prefs_register_module(NULL
, "codecs", "Codecs",
3896 "Codecs", NULL
, NULL
, true);
3899 stats_module
= prefs_register_module(NULL
, "statistics", "Statistics",
3900 "Statistics", "ChCustPreferencesSection.html#_statistics", &stats_callback
, true);
3902 prefs_register_uint_preference(stats_module
, "update_interval",
3903 "Tap update interval in ms",
3904 "Determines time between tap updates",
3906 &prefs
.tap_update_interval
);
3908 prefs_register_uint_preference(stats_module
, "flow_graph_max_export_items",
3909 "Maximum Flow Graph items to export as image",
3910 "The maximum number of Flow Graph items (frames) "
3911 "to include when exporting the graph as an image. "
3912 "Note that some formats (e.g., JPEG) have inherent "
3913 "pixel limits and image viewers might be unable to "
3914 "handle very large images.",
3916 &prefs
.flow_graph_max_export_items
);
3918 prefs_register_bool_preference(stats_module
, "st_enable_burstinfo",
3919 "Enable the calculation of burst information",
3920 "If enabled burst rates will be calculated for statistics that use the stats_tree system. "
3921 "Burst rates are calculated over a much shorter time interval than the rate column.",
3922 &prefs
.st_enable_burstinfo
);
3924 prefs_register_bool_preference(stats_module
, "st_burst_showcount",
3925 "Show burst count for item rather than rate",
3926 "If selected the stats_tree statistics nodes will show the count of events "
3927 "within the burst window instead of a burst rate. Burst rate is calculated "
3928 "as number of events within burst window divided by the burst windown length.",
3929 &prefs
.st_burst_showcount
);
3931 prefs_register_uint_preference(stats_module
, "st_burst_resolution",
3932 "Burst rate resolution (ms)",
3933 "Sets the duration of the time interval into which events are grouped when calculating "
3934 "the burst rate. Higher resolution (smaller number) increases processing overhead.",
3935 10,&prefs
.st_burst_resolution
);
3937 prefs_register_uint_preference(stats_module
, "st_burst_windowlen",
3938 "Burst rate window size (ms)",
3939 "Sets the duration of the sliding window during which the burst rate is "
3940 "measured. Longer window relative to burst rate resolution increases "
3941 "processing overhead. Will be truncated to a multiple of burst resolution.",
3942 10,&prefs
.st_burst_windowlen
);
3944 prefs_register_enum_preference(stats_module
, "st_sort_defcolflag",
3945 "Default sort column for stats_tree stats",
3946 "Sets the default column by which stats based on the stats_tree "
3947 "system is sorted.",
3948 &prefs
.st_sort_defcolflag
, st_sort_col_vals
, false);
3950 prefs_register_bool_preference(stats_module
, "st_sort_defdescending",
3951 "Default stats_tree sort order is descending",
3952 "When selected, statistics based on the stats_tree system will by default "
3953 "be sorted in descending order.",
3954 &prefs
.st_sort_defdescending
);
3956 prefs_register_bool_preference(stats_module
, "st_sort_casesensitve",
3957 "Case sensitive sort of stats_tree item names",
3958 "When selected, the item/node names of statistics based on the stats_tree "
3959 "system will be sorted taking case into account. Else the case of the name "
3961 &prefs
.st_sort_casesensitve
);
3963 prefs_register_bool_preference(stats_module
, "st_sort_rng_nameonly",
3964 "Always sort 'range' nodes by name",
3965 "When selected, the stats_tree nodes representing a range of values "
3966 "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
3967 "node). Else range nodes are sorted by the same column as the rest of "
3969 &prefs
.st_sort_rng_nameonly
);
3971 prefs_register_bool_preference(stats_module
, "st_sort_rng_fixorder",
3972 "Always sort 'range' nodes in ascending order",
3973 "When selected, the stats_tree nodes representing a range of values "
3974 "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
3975 "the sort direction of the tree. Only effective if \"Always sort "
3976 "'range' nodes by name\" is also selected.",
3977 &prefs
.st_sort_rng_fixorder
);
3979 prefs_register_bool_preference(stats_module
, "st_sort_showfullname",
3980 "Display the full stats_tree plug-in name",
3981 "When selected, the full name (including menu path) of the stats_tree "
3982 "plug-in is show in windows. If cleared the plug-in name is shown "
3983 "without menu path (only the part of the name after last '/' character.)",
3984 &prefs
.st_sort_showfullname
);
3987 protocols_module
= prefs_register_module(NULL
, "protocols", "Protocols",
3988 "Protocols", "ChCustPreferencesSection.html#ChCustPrefsProtocolsSection", NULL
, true);
3990 prefs_register_bool_preference(protocols_module
, "display_hidden_proto_items",
3991 "Display hidden protocol items",
3992 "Display all hidden protocol items in the packet list.",
3993 &prefs
.display_hidden_proto_items
);
3995 prefs_register_bool_preference(protocols_module
, "display_byte_fields_with_spaces",
3996 "Display byte fields with a space character between bytes",
3997 "Display all byte fields with a space character between each byte in the packet list.",
3998 &prefs
.display_byte_fields_with_spaces
);
4001 * Note the -t / option only affects the display of the packet timestamp
4002 * in the default time column; this is for all other absolute times.
4004 prefs_register_enum_preference(protocols_module
, "display_abs_time_ascii",
4005 "Format absolute times like asctime",
4006 "When to format absolute times similar to asctime instead of ISO 8601, for backwards compatibility with older Wireshark.",
4007 (int*)&prefs
.display_abs_time_ascii
, abs_time_format_options
, false);
4009 prefs_register_bool_preference(protocols_module
, "enable_incomplete_dissectors_check",
4010 "Look for incomplete dissectors",
4011 "Look for dissectors that left some bytes undecoded.",
4012 &prefs
.enable_incomplete_dissectors_check
);
4014 prefs_register_bool_preference(protocols_module
, "strict_conversation_tracking_heuristics",
4015 "Enable stricter conversation tracking heuristics",
4016 "Protocols may use things like VLAN ID or interface ID to narrow the potential for duplicate conversations. "
4017 "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",
4018 &prefs
.strict_conversation_tracking_heuristics
);
4020 prefs_register_bool_preference(protocols_module
, "ignore_dup_frames",
4021 "Ignore duplicate frames",
4022 "Ignore frames that are exact duplicates of any previous frame.",
4023 &prefs
.ignore_dup_frames
);
4025 prefs_register_enum_preference(protocols_module
, "conversation_deinterlacing_key",
4026 "Deinterlacing conversations key",
4027 "Separate into different conversations frames that look like duplicates but have different Interface, MAC, or VLAN field values.",
4028 (int *)&prefs
.conversation_deinterlacing_key
, conv_deint_options
, false);
4030 prefs_register_uint_preference(protocols_module
, "ignore_dup_frames_cache_entries",
4031 "The max number of hashes to keep in memory for determining duplicates frames",
4032 "If \"Ignore duplicate frames\" is set, this setting sets the maximum number "
4033 "of cache entries to maintain. A 0 means no limit.",
4034 10, &prefs
.ignore_dup_frames_cache_entries
);
4037 /* Obsolete preferences
4038 * These "modules" were reorganized/renamed to correspond to their GUI
4039 * configuration screen within the preferences dialog
4042 /* taps is now part of the stats module */
4043 prefs_register_module(NULL
, "taps", "TAPS", "TAPS", NULL
, NULL
, false);
4044 /* packet_list is now part of the protocol (parent) module */
4045 prefs_register_module(NULL
, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL
, NULL
, false);
4046 /* stream is now part of the gui module */
4047 prefs_register_module(NULL
, "stream", "STREAM", "STREAM", NULL
, NULL
, false);
4051 /* Parse through a list of comma-separated, possibly quoted strings.
4052 Return a list of the string data. */
4054 prefs_get_string_list(const char *str
)
4056 enum { PRE_STRING
, IN_QUOT
, NOT_IN_QUOT
};
4058 int state
= PRE_STRING
, i
= 0;
4059 bool backslash
= false;
4060 unsigned char cur_c
;
4061 const size_t default_size
= 64;
4062 GString
*slstr
= NULL
;
4065 /* Allocate a buffer for the first string. */
4066 slstr
= g_string_sized_new(default_size
);
4070 if (cur_c
== '\0') {
4071 /* It's the end of the input, so it's the end of the string we
4072 were working on, and there's no more input. */
4073 if (state
== IN_QUOT
|| backslash
) {
4074 /* We were in the middle of a quoted string or backslash escape,
4075 and ran out of characters; that's an error. */
4076 g_string_free(slstr
, TRUE
);
4077 prefs_clear_string_list(sl
);
4081 sl
= g_list_append(sl
, g_string_free(slstr
, FALSE
));
4083 g_string_free(slstr
, TRUE
);
4086 if (cur_c
== '"' && !backslash
) {
4089 /* We hadn't yet started processing a string; this starts the
4090 string, and we're now quoting. */
4094 /* We're in the middle of a quoted string, and we saw a quotation
4095 mark; we're no longer quoting. */
4096 state
= NOT_IN_QUOT
;
4099 /* We're working on a string, but haven't seen a quote; we're
4106 } else if (cur_c
== '\\' && !backslash
) {
4107 /* We saw a backslash, and the previous character wasn't a
4108 backslash; escape the next character.
4110 This also means we've started a new string. */
4112 if (state
== PRE_STRING
)
4113 state
= NOT_IN_QUOT
;
4114 } else if (cur_c
== ',' && state
!= IN_QUOT
&& !backslash
) {
4115 /* We saw a comma, and we're not in the middle of a quoted string
4116 and it wasn't preceded by a backslash; it's the end of
4117 the string we were working on... */
4118 if (slstr
->len
> 0) {
4119 sl
= g_list_append(sl
, g_string_free(slstr
, FALSE
));
4120 slstr
= g_string_sized_new(default_size
);
4123 /* ...and the beginning of a new string. */
4125 } else if (!g_ascii_isspace(cur_c
) || state
!= PRE_STRING
) {
4126 /* Either this isn't a white-space character, or we've started a
4127 string (i.e., already seen a non-white-space character for that
4128 string and put it into the string).
4130 The character is to be put into the string; do so. */
4131 g_string_append_c(slstr
, cur_c
);
4133 /* If it was backslash-escaped, we're done with the backslash escape. */
4141 char *join_string_list(GList
*sl
)
4143 GString
*joined_str
= g_string_new("");
4146 unsigned item_count
= 0;
4148 cur
= first
= g_list_first(sl
);
4151 str
= (char *)cur
->data
;
4154 g_string_append_c(joined_str
, ',');
4156 if (item_count
% 2) {
4157 /* Wrap the line. */
4158 g_string_append(joined_str
, "\n\t");
4160 g_string_append_c(joined_str
, ' ');
4162 g_string_append_c(joined_str
, '"');
4164 gunichar uc
= g_utf8_get_char (str
);
4166 if (uc
== '"' || uc
== '\\')
4167 g_string_append_c(joined_str
, '\\');
4169 if (g_unichar_isprint(uc
))
4170 g_string_append_unichar (joined_str
, uc
);
4172 str
= g_utf8_next_char (str
);
4175 g_string_append_c(joined_str
, '"');
4179 return g_string_free(joined_str
, FALSE
);
4183 prefs_clear_string_list(GList
*sl
)
4185 g_list_free_full(sl
, g_free
);
4189 * Takes a string, a pointer to an array of "enum_val_t"s, and a default int
4191 * The array must be terminated by an entry with a null "name" string.
4193 * If the string matches a "name" string in an entry, the value from that
4194 * entry is returned.
4196 * Otherwise, if a string matches a "description" string in an entry, the
4197 * value from that entry is returned; we do that for backwards compatibility,
4198 * as we used to have only a "name" string that was used both for command-line
4199 * and configuration-file values and in the GUI (which meant either that
4200 * the GUI had what might be somewhat cryptic values to select from or that
4201 * the "-o" flag took long strings, often with spaces in them).
4203 * Otherwise, the default value that was passed as the third argument is
4207 find_val_for_string(const char *needle
, const enum_val_t
*haystack
,
4212 for (i
= 0; haystack
[i
].name
!= NULL
; i
++) {
4213 if (g_ascii_strcasecmp(needle
, haystack
[i
].name
) == 0) {
4214 return haystack
[i
].value
;
4217 for (i
= 0; haystack
[i
].name
!= NULL
; i
++) {
4218 if (g_ascii_strcasecmp(needle
, haystack
[i
].description
) == 0) {
4219 return haystack
[i
].value
;
4222 return default_value
;
4225 /* Preferences file format:
4226 * - Configuration directives start at the beginning of the line, and
4227 * are terminated with a colon.
4228 * - Directives can be continued on the next line by preceding them with
4233 # This is a comment line
4235 print.file: /a/very/long/path/
4240 /* Initialize non-dissector preferences to wired-in default values Called
4241 * at program startup and any time the profile changes. (The dissector
4242 * preferences are assumed to be set to those values by the dissectors.)
4243 * They may be overridden by the global preferences file or the user's
4249 if (prefs_initialized
)
4255 * Ensure the "global" preferences have been initialized so the
4256 * preference API has the proper default values to work from
4260 prefs_register_modules();
4262 prefs_initialized
= true;
4266 * Initialize non-dissector preferences used by the "register preference" API
4267 * to default values so the default values can be used when registered.
4269 * String, filename, and directory preferences will be g_freed so they must
4273 pre_init_prefs(void)
4278 static const char *col_fmt_packets
[] = {
4279 "No.", "%m", "Time", "%t",
4280 "Source", "%s", "Destination", "%d",
4281 "Protocol", "%p", "Length", "%L",
4283 static const char **col_fmt
= col_fmt_packets
;
4286 if (application_flavor_is_stratoshark()) {
4287 static const char *col_fmt_logs
[] = {
4290 "Event name", "%Cus:sysdig.event_name:0:R",
4291 "Dir", "%Cus:evt.dir:0:R",
4292 "Proc Name", "%Cus:proc.name:0:R",
4293 "PID", "%Cus:proc.pid:0:R",
4294 "TID", "%Cus:thread.tid:0:R",
4295 "FD", "%Cus:fd.num:0:R",
4296 "FD Name", "%Cus:fd.name:0:R",
4297 "Container Name", "%Cus:container.name:0:R",
4298 "Arguments", "%Cus:evt.args:0:R",
4301 col_fmt
= col_fmt_logs
;
4305 prefs
.restore_filter_after_following_stream
= false;
4306 prefs
.gui_toolbar_main_style
= TB_STYLE_ICONS
;
4307 /* We try to find the best font in the Qt code */
4308 g_free(prefs
.gui_font_name
);
4309 prefs
.gui_font_name
= g_strdup("");
4310 prefs
.gui_active_fg
.red
= 0;
4311 prefs
.gui_active_fg
.green
= 0;
4312 prefs
.gui_active_fg
.blue
= 0;
4313 prefs
.gui_active_bg
.red
= 52223;
4314 prefs
.gui_active_bg
.green
= 59647;
4315 prefs
.gui_active_bg
.blue
= 65535;
4316 prefs
.gui_active_style
= COLOR_STYLE_DEFAULT
;
4317 prefs
.gui_inactive_fg
.red
= 0;
4318 prefs
.gui_inactive_fg
.green
= 0;
4319 prefs
.gui_inactive_fg
.blue
= 0;
4320 prefs
.gui_inactive_bg
.red
= 61439;
4321 prefs
.gui_inactive_bg
.green
= 61439;
4322 prefs
.gui_inactive_bg
.blue
= 61439;
4323 prefs
.gui_inactive_style
= COLOR_STYLE_DEFAULT
;
4324 prefs
.gui_marked_fg
.red
= 65535;
4325 prefs
.gui_marked_fg
.green
= 65535;
4326 prefs
.gui_marked_fg
.blue
= 65535;
4327 prefs
.gui_marked_bg
.red
= 0;
4328 prefs
.gui_marked_bg
.green
= 8224;
4329 prefs
.gui_marked_bg
.blue
= 10794;
4330 prefs
.gui_ignored_fg
.red
= 32767;
4331 prefs
.gui_ignored_fg
.green
= 32767;
4332 prefs
.gui_ignored_fg
.blue
= 32767;
4333 prefs
.gui_ignored_bg
.red
= 65535;
4334 prefs
.gui_ignored_bg
.green
= 65535;
4335 prefs
.gui_ignored_bg
.blue
= 65535;
4336 g_free(prefs
.gui_colorized_fg
);
4337 prefs
.gui_colorized_fg
= g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
4338 g_free(prefs
.gui_colorized_bg
);
4339 prefs
.gui_colorized_bg
= g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
4340 prefs
.st_client_fg
.red
= 32767;
4341 prefs
.st_client_fg
.green
= 0;
4342 prefs
.st_client_fg
.blue
= 0;
4343 prefs
.st_client_bg
.red
= 64507;
4344 prefs
.st_client_bg
.green
= 60909;
4345 prefs
.st_client_bg
.blue
= 60909;
4346 prefs
.st_server_fg
.red
= 0;
4347 prefs
.st_server_fg
.green
= 0;
4348 prefs
.st_server_fg
.blue
= 32767;
4349 prefs
.st_server_bg
.red
= 60909;
4350 prefs
.st_server_bg
.green
= 60909;
4351 prefs
.st_server_bg
.blue
= 64507;
4353 if (gui_theme_is_dark
) {
4354 // Green, red and yellow with HSV V = 84
4355 prefs
.gui_text_valid
.red
= 0x0000; /* dark green */
4356 prefs
.gui_text_valid
.green
= 0x66ff;
4357 prefs
.gui_text_valid
.blue
= 0x0000;
4358 prefs
.gui_text_invalid
.red
= 0x66FF; /* dark red */
4359 prefs
.gui_text_invalid
.green
= 0x0000;
4360 prefs
.gui_text_invalid
.blue
= 0x0000;
4361 prefs
.gui_text_deprecated
.red
= 0x66FF; /* dark yellow / olive */
4362 prefs
.gui_text_deprecated
.green
= 0x66FF;
4363 prefs
.gui_text_deprecated
.blue
= 0x0000;
4365 // Green, red and yellow with HSV V = 20
4366 prefs
.gui_text_valid
.red
= 0xAFFF; /* light green */
4367 prefs
.gui_text_valid
.green
= 0xFFFF;
4368 prefs
.gui_text_valid
.blue
= 0xAFFF;
4369 prefs
.gui_text_invalid
.red
= 0xFFFF; /* light red */
4370 prefs
.gui_text_invalid
.green
= 0xAFFF;
4371 prefs
.gui_text_invalid
.blue
= 0xAFFF;
4372 prefs
.gui_text_deprecated
.red
= 0xFFFF; /* light yellow */
4373 prefs
.gui_text_deprecated
.green
= 0xFFFF;
4374 prefs
.gui_text_deprecated
.blue
= 0xAFFF;
4377 prefs
.gui_geometry_save_position
= true;
4378 prefs
.gui_geometry_save_size
= true;
4379 prefs
.gui_geometry_save_maximized
= true;
4380 prefs
.gui_fileopen_style
= FO_STYLE_LAST_OPENED
;
4381 prefs
.gui_recent_df_entries_max
= 10;
4382 prefs
.gui_recent_files_count_max
= 10;
4383 g_free(prefs
.gui_fileopen_dir
);
4384 prefs
.gui_fileopen_dir
= g_strdup(get_persdatafile_dir());
4385 prefs
.gui_fileopen_preview
= 3;
4386 g_free(prefs
.gui_tlskeylog_command
);
4387 prefs
.gui_tlskeylog_command
= g_strdup("");
4388 prefs
.gui_ask_unsaved
= true;
4389 prefs
.gui_autocomplete_filter
= true;
4390 prefs
.gui_find_wrap
= true;
4391 prefs
.gui_update_enabled
= true;
4392 prefs
.gui_update_channel
= UPDATE_CHANNEL_STABLE
;
4393 prefs
.gui_update_interval
= 60*60*24; /* Seconds */
4394 prefs
.gui_debounce_timer
= 400; /* milliseconds */
4395 g_free(prefs
.gui_window_title
);
4396 prefs
.gui_window_title
= g_strdup("");
4397 g_free(prefs
.gui_prepend_window_title
);
4398 prefs
.gui_prepend_window_title
= g_strdup("");
4399 g_free(prefs
.gui_start_title
);
4400 prefs
.gui_start_title
= g_strdup("The World's Most Popular Network Protocol Analyzer");
4401 prefs
.gui_version_placement
= version_both
;
4402 prefs
.gui_welcome_page_show_recent
= true;
4403 prefs
.gui_layout_type
= layout_type_2
;
4404 prefs
.gui_layout_content_1
= layout_pane_content_plist
;
4405 prefs
.gui_layout_content_2
= layout_pane_content_pdetails
;
4406 prefs
.gui_layout_content_3
= layout_pane_content_pbytes
;
4407 prefs
.gui_packet_list_elide_mode
= ELIDE_RIGHT
;
4408 prefs
.gui_packet_list_copy_format_options_for_keyboard_shortcut
= COPY_FORMAT_TEXT
;
4409 prefs
.gui_packet_list_copy_text_with_aligned_columns
= false;
4410 prefs
.gui_packet_list_show_related
= true;
4411 prefs
.gui_packet_list_show_minimap
= true;
4412 prefs
.gui_packet_list_sortable
= true;
4413 prefs
.gui_packet_list_cached_rows_max
= 10000;
4414 g_free (prefs
.gui_interfaces_hide_types
);
4415 prefs
.gui_interfaces_hide_types
= g_strdup("");
4416 prefs
.gui_interfaces_show_hidden
= false;
4417 prefs
.gui_interfaces_remote_display
= true;
4418 prefs
.gui_packet_list_separator
= false;
4419 prefs
.gui_packet_header_column_definition
= true;
4420 prefs
.gui_packet_list_hover_style
= true;
4421 prefs
.gui_show_selected_packet
= false;
4422 prefs
.gui_show_file_load_time
= false;
4423 prefs
.gui_max_export_objects
= 1000;
4424 prefs
.gui_max_tree_items
= 1 * 1000 * 1000;
4425 prefs
.gui_max_tree_depth
= 5 * 100;
4426 prefs
.gui_decimal_places1
= DEF_GUI_DECIMAL_PLACES1
;
4427 prefs
.gui_decimal_places2
= DEF_GUI_DECIMAL_PLACES2
;
4428 prefs
.gui_decimal_places3
= DEF_GUI_DECIMAL_PLACES3
;
4430 if (prefs
.col_list
) {
4431 free_col_info(prefs
.col_list
);
4432 prefs
.col_list
= NULL
;
4434 for (i
= 0; i
< num_cols
; i
++) {
4435 cfmt
= g_new0(fmt_data
,1);
4436 cfmt
->title
= g_strdup(col_fmt
[i
* 2]);
4437 cfmt
->visible
= true;
4438 cfmt
->display
= COLUMN_DISPLAY_STRINGS
;
4439 parse_column_format(cfmt
, col_fmt
[(i
* 2) + 1]);
4440 prefs
.col_list
= g_list_append(prefs
.col_list
, cfmt
);
4442 prefs
.num_cols
= num_cols
;
4444 /* set the default values for the capture dialog box */
4445 prefs
.capture_prom_mode
= true;
4446 prefs
.capture_monitor_mode
= false;
4447 prefs
.capture_pcap_ng
= true;
4448 prefs
.capture_real_time
= true;
4449 prefs
.capture_update_interval
= DEFAULT_UPDATE_INTERVAL
;
4450 prefs
.capture_no_extcap
= false;
4451 prefs
.capture_show_info
= false;
4453 if (!prefs
.capture_columns
) {
4454 /* First time through */
4455 for (i
= 0; i
< num_capture_cols
; i
++) {
4456 col_name
= g_strdup(capture_cols
[i
]);
4457 prefs
.capture_columns
= g_list_append(prefs
.capture_columns
, col_name
);
4461 /* set the default values for the tap/statistics dialog box */
4462 prefs
.tap_update_interval
= TAP_UPDATE_DEFAULT_INTERVAL
;
4463 prefs
.flow_graph_max_export_items
= 1000;
4464 prefs
.st_enable_burstinfo
= true;
4465 prefs
.st_burst_showcount
= false;
4466 prefs
.st_burst_resolution
= ST_DEF_BURSTRES
;
4467 prefs
.st_burst_windowlen
= ST_DEF_BURSTLEN
;
4468 prefs
.st_sort_casesensitve
= true;
4469 prefs
.st_sort_rng_fixorder
= true;
4470 prefs
.st_sort_rng_nameonly
= true;
4471 prefs
.st_sort_defcolflag
= ST_SORT_COL_COUNT
;
4472 prefs
.st_sort_defdescending
= true;
4473 prefs
.st_sort_showfullname
= false;
4476 prefs
.display_hidden_proto_items
= false;
4477 prefs
.display_byte_fields_with_spaces
= false;
4478 prefs
.display_abs_time_ascii
= ABS_TIME_ASCII_TREE
;
4479 prefs
.ignore_dup_frames
= false;
4480 prefs
.ignore_dup_frames_cache_entries
= 10000;
4482 /* set the default values for the io graph dialog */
4483 prefs
.gui_io_graph_automatic_update
= true;
4484 prefs
.gui_io_graph_enable_legend
= true;
4486 /* set the default values for the packet dialog */
4487 prefs
.gui_packet_dialog_layout
= layout_vertical
;
4488 prefs
.gui_packet_details_show_byteview
= true;
4492 * Reset a single dissector preference.
4495 reset_pref(pref_t
*pref
)
4503 * This preference is no longer supported; it's not a
4504 * real preference, so we don't reset it (i.e., we
4505 * treat it as if it weren't found in the list of
4506 * preferences, and we weren't called in the first place).
4508 if (IS_PREF_OBSOLETE(type
))
4511 RESET_PREF_OBSOLETE(type
);
4516 *pref
->varp
.uint
= pref
->default_val
.uint
;
4520 *pref
->varp
.boolp
= pref
->default_val
.boolval
;
4524 case PREF_PROTO_TCP_SNDAMB_ENUM
:
4525 *pref
->varp
.enump
= pref
->default_val
.enumval
;
4529 case PREF_SAVE_FILENAME
:
4530 case PREF_OPEN_FILENAME
:
4533 case PREF_DISSECTOR
:
4534 reset_string_like_preference(pref
);
4538 case PREF_DECODE_AS_RANGE
:
4539 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
4540 *pref
->varp
.range
= range_copy(wmem_epan_scope(), pref
->default_val
.range
);
4543 case PREF_STATIC_TEXT
:
4549 *pref
->varp
.colorp
= pref
->default_val
.color
;
4553 pref
->custom_cbs
.reset_cb(pref
);
4559 reset_pref_cb(void *data
, void *user_data
)
4561 pref_t
*pref
= (pref_t
*) data
;
4562 module_t
*module
= (module_t
*)user_data
;
4564 if (pref
&& (pref
->type
== PREF_RANGE
|| pref
->type
== PREF_DECODE_AS_RANGE
)) {
4566 * Some dissectors expect the range (returned via prefs_get_range_value)
4567 * to remain valid if it has not changed. If it did change, then we
4568 * should set "prefs_changed_flags" to ensure that the preference apply
4569 * callback is invoked. That callback will notify dissectors that it
4570 * should no longer assume the range to be valid.
4572 if (ranges_are_equal(*pref
->varp
.range
, pref
->default_val
.range
)) {
4573 /* Optimization: do not invoke apply callback if nothing changed. */
4576 module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
4582 * Reset all preferences for a module.
4585 reset_module_prefs(const void *key _U_
, void *value
, void *data _U_
)
4587 module_t
*module
= (module_t
*)value
;
4588 g_list_foreach(module
->prefs
, reset_pref_cb
, module
);
4592 /* Reset preferences */
4596 prefs_initialized
= false;
4597 g_free(prefs
.saved_at_version
);
4598 prefs
.saved_at_version
= NULL
;
4601 * Unload all UAT preferences.
4606 * Unload any loaded MIBs.
4611 * Reset the non-dissector preferences.
4616 * Reset the non-UAT dissector preferences.
4618 wmem_tree_foreach(prefs_modules
, reset_module_prefs
, NULL
);
4627 DWORD data_size
= sizeof(DWORD
);
4630 ret
= RegOpenKeyExA(HKEY_CURRENT_USER
, REG_HKCU_WIRESHARK_KEY
, 0, KEY_READ
, &hTestKey
);
4631 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_FILE_NOT_FOUND
) {
4632 ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY
": 0x%lx", ret
);
4636 ret
= RegQueryValueExA(hTestKey
, LOG_HKCU_CONSOLE_OPEN
, NULL
, NULL
, (LPBYTE
)&data
, &data_size
);
4637 if (ret
== ERROR_SUCCESS
) {
4638 ws_log_console_open
= (ws_log_console_open_pref
)data
;
4639 ws_noisy("Got "LOG_HKCU_CONSOLE_OPEN
" from Windows registry: %d", ws_log_console_open
);
4641 else if (ret
!= ERROR_FILE_NOT_FOUND
) {
4642 ws_noisy("Error reading registry key "LOG_HKCU_CONSOLE_OPEN
": 0x%lx", ret
);
4645 RegCloseKey(hTestKey
);
4650 prefs_read_module(const char *module
)
4656 module_t
*target_module
= prefs_find_module(module
);
4657 if (!target_module
) {
4661 /* Construct the pathname of the user's preferences file for the module. */
4662 char *pf_name
= wmem_strdup_printf(NULL
, "%s.cfg", module
);
4663 pf_path
= get_persconffile_path(pf_name
, true);
4664 wmem_free(NULL
, pf_name
);
4666 /* Read the user's module preferences file, if it exists and is not a dir. */
4667 if (!test_for_regular_file(pf_path
) || ((pf
= ws_fopen(pf_path
, "r")) == NULL
)) {
4669 /* Fall back to the user's generic preferences file. */
4670 pf_path
= get_persconffile_path(PF_NAME
, true);
4671 pf
= ws_fopen(pf_path
, "r");
4675 /* We succeeded in opening it; read it. */
4676 err
= read_prefs_file(pf_path
, pf
, set_pref
, target_module
);
4678 /* We had an error reading the file; report it. */
4679 report_warning("Error reading your preferences file \"%s\": %s.",
4680 pf_path
, g_strerror(err
));
4685 /* We failed to open it. If we failed for some reason other than
4686 "it doesn't exist", return the errno and the pathname, so our
4687 caller can report the error. */
4688 if (errno
!= ENOENT
) {
4689 report_warning("Can't open your preferences file \"%s\": %s.",
4690 pf_path
, g_strerror(errno
));
4698 /* Read the preferences file, fill in "prefs", and return a pointer to it.
4700 If we got an error (other than "it doesn't exist") we report it through
4709 /* clean up libsmi structures before reading prefs */
4719 * If we don't already have the pathname of the global preferences
4720 * file, construct it. Then, in either case, try to open the file.
4722 if (gpf_path
== NULL
) {
4724 * We don't have the path; try the new path first, and, if that
4725 * file doesn't exist, try the old path.
4727 gpf_path
= get_datafile_path(PF_NAME
);
4728 if ((pf
= ws_fopen(gpf_path
, "r")) == NULL
&& errno
== ENOENT
) {
4730 * It doesn't exist by the new name; try the old name.
4733 gpf_path
= get_datafile_path(OLD_GPF_NAME
);
4734 pf
= ws_fopen(gpf_path
, "r");
4738 * We have the path; try it.
4740 pf
= ws_fopen(gpf_path
, "r");
4744 * If we were able to open the file, read it.
4745 * XXX - if it failed for a reason other than "it doesn't exist",
4750 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
4753 mgcp_tcp_port_count
= 0;
4754 mgcp_udp_port_count
= 0;
4756 /* We succeeded in opening it; read it. */
4757 err
= read_prefs_file(gpf_path
, pf
, set_pref
, NULL
);
4759 /* We had an error reading the file; report it. */
4760 report_warning("Error reading global preferences file \"%s\": %s.",
4761 gpf_path
, g_strerror(err
));
4765 /* We failed to open it. If we failed for some reason other than
4766 "it doesn't exist", report the error. */
4767 if (errno
!= ENOENT
) {
4769 report_warning("Can't open global preferences file \"%s\": %s.",
4770 gpf_path
, g_strerror(errno
));
4775 /* Construct the pathname of the user's preferences file. */
4776 pf_path
= get_persconffile_path(PF_NAME
, true);
4778 /* Read the user's preferences file, if it exists. */
4779 if ((pf
= ws_fopen(pf_path
, "r")) != NULL
) {
4781 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
4784 mgcp_tcp_port_count
= 0;
4785 mgcp_udp_port_count
= 0;
4787 /* We succeeded in opening it; read it. */
4788 err
= read_prefs_file(pf_path
, pf
, set_pref
, NULL
);
4790 /* We had an error reading the file; report it. */
4791 report_warning("Error reading your preferences file \"%s\": %s.",
4792 pf_path
, g_strerror(err
));
4797 /* We failed to open it. If we failed for some reason other than
4798 "it doesn't exist", return the errno and the pathname, so our
4799 caller can report the error. */
4800 if (errno
!= ENOENT
) {
4801 report_warning("Can't open your preferences file \"%s\": %s.",
4802 pf_path
, g_strerror(errno
));
4807 /* load SMI modules if needed */
4813 /* read the preferences file (or similar) and call the callback
4814 * function to set each key/value pair found */
4816 read_prefs_file(const char *pf_path
, FILE *pf
,
4817 pref_set_pair_cb pref_set_pair_fct
, void *private_data
)
4820 START
, /* beginning of a line */
4821 IN_VAR
, /* processing key name */
4822 PRE_VAL
, /* finished processing key name, skipping white space before value */
4823 IN_VAL
, /* processing value */
4824 IN_SKIP
/* skipping to the end of the line */
4829 bool got_val
= false;
4830 int fline
= 1, pline
= 1;
4831 char hint
[] = "(save preferences to remove this warning)";
4834 cur_val
= g_string_new("");
4835 cur_var
= g_string_new("");
4837 /* Try to read in the profile name in the first line of the preferences file. */
4838 if (fscanf(pf
, "# Configuration file for %127[^\r\n]", ver
) == 1) {
4839 /* Assume trailing period and remove it */
4840 g_free(prefs
.saved_at_version
);
4841 prefs
.saved_at_version
= g_strndup(ver
, strlen(ver
) - 1);
4845 while ((got_c
= ws_getc_unlocked(pf
)) != EOF
) {
4846 if (got_c
== '\r') {
4847 /* Treat CR-LF at the end of a line like LF, so that if we're reading
4848 * a Windows-format file on UN*X, we handle it the same way we'd handle
4849 * a UN*X-format file. */
4850 got_c
= ws_getc_unlocked(pf
);
4853 if (got_c
!= '\n') {
4854 /* Put back the character after the CR, and process the CR normally. */
4859 if (got_c
== '\n') {
4867 if (g_ascii_isalnum(got_c
)) {
4868 if (cur_var
->len
> 0) {
4870 if (cur_val
->len
> 0) {
4871 if (cur_val
->str
[cur_val
->len
-1] == ',') {
4873 * If the pref has a trailing comma, eliminate it.
4875 cur_val
->str
[cur_val
->len
-1] = '\0';
4876 ws_warning("%s line %d: trailing comma in \"%s\" %s", pf_path
, pline
, cur_var
->str
, hint
);
4879 /* Call the routine to set the preference; it will parse
4880 the value as appropriate.
4882 Since we're reading a file, rather than processing
4883 explicit user input, for range preferences, silently
4884 lower values in excess of the range's maximum, rather
4885 than reporting errors and failing. */
4886 switch (pref_set_pair_fct(cur_var
->str
, cur_val
->str
, private_data
, false)) {
4891 case PREFS_SET_SYNTAX_ERR
:
4892 report_warning("Syntax error in preference \"%s\" at line %d of\n%s %s",
4893 cur_var
->str
, pline
, pf_path
, hint
);
4896 case PREFS_SET_NO_SUCH_PREF
:
4897 ws_warning("No such preference \"%s\" at line %d of\n%s %s",
4898 cur_var
->str
, pline
, pf_path
, hint
);
4899 prefs
.unknown_prefs
= true;
4902 case PREFS_SET_OBSOLETE
:
4904 * If an attempt is made to save the
4905 * preferences, a popup warning will be
4906 * displayed stating that obsolete prefs
4907 * have been detected and the user will
4908 * be given the opportunity to save these
4909 * prefs under a different profile name.
4910 * The prefs in question need to be listed
4911 * in the console window so that the
4912 * user can make an informed choice.
4914 ws_warning("Obsolete preference \"%s\" at line %d of\n%s %s",
4915 cur_var
->str
, pline
, pf_path
, hint
);
4916 prefs
.unknown_prefs
= true;
4920 ws_warning("Incomplete preference at line %d: of\n%s %s", pline
, pf_path
, hint
);
4925 g_string_truncate(cur_var
, 0);
4926 g_string_append_c(cur_var
, (char) got_c
);
4928 } else if (g_ascii_isspace(got_c
) && cur_var
->len
> 0 && got_val
) {
4930 } else if (got_c
== '#') {
4933 ws_warning("Malformed preference at line %d of\n%s %s", fline
, pf_path
, hint
);
4938 g_string_append_c(cur_var
, (char) got_c
);
4940 /* This is a colon (':') */
4942 g_string_truncate(cur_val
, 0);
4944 * Set got_val to true to accommodate prefs such as
4945 * "gui.fileopen.dir" that do not require a value.
4951 if (!g_ascii_isspace(got_c
)) {
4953 g_string_append_c(cur_val
, (char) got_c
);
4957 g_string_append_c(cur_val
, (char) got_c
);
4963 if (cur_var
->len
> 0) {
4965 /* Call the routine to set the preference; it will parse
4966 the value as appropriate.
4968 Since we're reading a file, rather than processing
4969 explicit user input, for range preferences, silently
4970 lower values in excess of the range's maximum, rather
4971 than reporting errors and failing. */
4972 switch (pref_set_pair_fct(cur_var
->str
, cur_val
->str
, private_data
, false)) {
4977 case PREFS_SET_SYNTAX_ERR
:
4978 ws_warning("Syntax error in preference %s at line %d of\n%s %s",
4979 cur_var
->str
, pline
, pf_path
, hint
);
4982 case PREFS_SET_NO_SUCH_PREF
:
4983 ws_warning("No such preference \"%s\" at line %d of\n%s %s",
4984 cur_var
->str
, pline
, pf_path
, hint
);
4985 prefs
.unknown_prefs
= true;
4988 case PREFS_SET_OBSOLETE
:
4989 prefs
.unknown_prefs
= true;
4993 ws_warning("Incomplete preference at line %d of\n%s %s",
4994 pline
, pf_path
, hint
);
4998 g_string_free(cur_val
, TRUE
);
4999 g_string_free(cur_var
, TRUE
);
5008 * If we were handed a preference starting with "uat:", try to turn it into
5009 * a valid uat entry.
5012 prefs_set_uat_pref(char *uat_entry
, char **errmsg
) {
5017 colonp
= strchr(uat_entry
, ':');
5025 * Skip over any white space (there probably won't be any, but
5026 * as we allow it in the preferences file, we might as well
5029 while (g_ascii_isspace(*p
))
5033 * Put the colon back, so if our caller uses, in an
5034 * error message, the string they passed us, the message
5041 uat
= uat_find(uat_entry
);
5044 *errmsg
= g_strdup("Unknown preference");
5048 ret
= uat_load_str(uat
, p
, errmsg
);
5053 * Given a string of the form "<pref name>:<pref value>", as might appear
5054 * as an argument to a "-o" option, parse it and set the preference in
5055 * question. Return an indication of whether it succeeded or failed
5059 prefs_set_pref(char *prefarg
, char **errmsg
)
5062 prefs_set_pref_e ret
;
5065 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
5066 * seen to values that keep us from trying to interpret them
5067 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
5068 * as, from the command line, we have no way of guessing which
5069 * the user had in mind.
5071 mgcp_tcp_port_count
= -1;
5072 mgcp_udp_port_count
= -1;
5076 colonp
= strchr(prefarg
, ':');
5078 return PREFS_SET_SYNTAX_ERR
;
5084 * Skip over any white space (there probably won't be any, but
5085 * as we allow it in the preferences file, we might as well
5088 while (g_ascii_isspace(*p
))
5090 /* The empty string is a legal value for range preferences (PREF_RANGE,
5091 * PREF_DECODE_AS_RANGE), and string-like preferences (PREF_STRING,
5092 * PREF_SAVE_FILENAME, PREF_OPEN_FILENAME, PREF_DIRNAME), indeed often
5093 * not just useful but the default. A user might have a value saved
5094 * to their preference file but want to override it to default behavior.
5095 * Individual preference handlers of those types should be prepared to
5096 * deal with an empty string. For other types, it is up to set_pref() to
5097 * test for the empty string and set PREFS_SET_SYNTAX_ERROR there.
5099 if (strcmp(prefarg
, "uat")) {
5100 ret
= set_pref(prefarg
, p
, NULL
, true);
5102 ret
= prefs_set_uat_pref(p
, errmsg
) ? PREFS_SET_OK
: PREFS_SET_SYNTAX_ERR
;
5104 *colonp
= ':'; /* put the colon back */
5108 unsigned prefs_get_uint_value(pref_t
*pref
, pref_source_t source
)
5113 return pref
->default_val
.uint
;
5115 return pref
->stashed_val
.uint
;
5117 return *pref
->varp
.uint
;
5119 ws_assert_not_reached();
5126 char* prefs_get_password_value(pref_t
*pref
, pref_source_t source
)
5128 return prefs_get_string_value(pref
, source
);
5132 unsigned int prefs_set_uint_value(pref_t
*pref
, unsigned value
, pref_source_t source
)
5134 unsigned int changed
= 0;
5138 if (pref
->default_val
.uint
!= value
) {
5139 pref
->default_val
.uint
= value
;
5140 changed
= prefs_get_effect_flags(pref
);
5144 if (pref
->stashed_val
.uint
!= value
) {
5145 pref
->stashed_val
.uint
= value
;
5146 changed
= prefs_get_effect_flags(pref
);
5150 if (*pref
->varp
.uint
!= value
) {
5151 *pref
->varp
.uint
= value
;
5152 changed
= prefs_get_effect_flags(pref
);
5156 ws_assert_not_reached();
5164 * For use by UI code that sets preferences.
5167 prefs_set_password_value(pref_t
*pref
, const char* value
, pref_source_t source
)
5169 return prefs_set_string_value(pref
, value
, source
);
5173 unsigned prefs_get_uint_base(pref_t
*pref
)
5175 return pref
->info
.base
;
5179 * Returns true if the given device is hidden
5182 prefs_is_capture_device_hidden(const char *name
)
5184 char *tok
, *devices
;
5187 if (prefs
.capture_devices_hide
&& name
) {
5188 devices
= g_strdup (prefs
.capture_devices_hide
);
5189 len
= strlen (name
);
5190 for (tok
= strtok (devices
, ","); tok
; tok
= strtok(NULL
, ",")) {
5191 if (strlen (tok
) == len
&& strcmp (name
, tok
) == 0) {
5203 * Returns true if the given column is visible (not hidden)
5206 prefs_is_column_visible(const char *cols_hidden
, int col
)
5208 char *tok
, *cols
, *p
;
5212 * Do we have a list of hidden columns?
5216 * Yes - check the column against each of the ones in the
5219 cols
= g_strdup(cols_hidden
);
5220 for (tok
= strtok(cols
, ","); tok
; tok
= strtok(NULL
, ",")) {
5221 tok
= g_strstrip(tok
);
5223 cidx
= (int)strtol(tok
, &p
, 10);
5224 if (p
== tok
|| *p
!= '\0') {
5231 * OK, they match, so it's one of the hidden fields,
5232 * hence not visible.
5241 * No - either there are no hidden columns or this isn't one
5242 * of them - so it is visible.
5248 * Returns true if the given column is visible (not hidden)
5251 prefs_is_column_fmt_visible(const char *cols_hidden
, fmt_data
*cfmt
)
5254 fmt_data cfmt_hidden
;
5257 * Do we have a list of hidden columns?
5261 * Yes - check the column against each of the ones in the
5264 cols
= g_strdup(cols_hidden
);
5265 for (tok
= strtok(cols
, ","); tok
; tok
= strtok(NULL
, ",")) {
5266 tok
= g_strstrip(tok
);
5269 * Parse this column format.
5271 if (!parse_column_format(&cfmt_hidden
, tok
)) {
5273 * It's not valid; ignore it.
5279 * Does it match the column?
5281 if (cfmt
->fmt
!= cfmt_hidden
.fmt
) {
5283 g_free(cfmt_hidden
.custom_fields
);
5284 cfmt_hidden
.custom_fields
= NULL
;
5287 if (cfmt
->fmt
== COL_CUSTOM
) {
5289 * A custom column has to have the same custom field
5292 if (cfmt_hidden
.custom_fields
&& cfmt
->custom_fields
) {
5293 if (strcmp(cfmt
->custom_fields
,
5294 cfmt_hidden
.custom_fields
) != 0) {
5295 /* Different fields. */
5296 g_free(cfmt_hidden
.custom_fields
);
5297 cfmt_hidden
.custom_fields
= NULL
;
5300 if (cfmt
->custom_occurrence
!= cfmt_hidden
.custom_occurrence
) {
5301 /* Different occurrences settings. */
5302 g_free(cfmt_hidden
.custom_fields
);
5303 cfmt_hidden
.custom_fields
= NULL
;
5310 * OK, they match, so it's one of the hidden fields,
5311 * hence not visible.
5313 g_free(cfmt_hidden
.custom_fields
);
5321 * No - either there are no hidden columns or this isn't one
5322 * of them - so it is visible.
5328 * Returns true if the given device should capture in monitor mode by default
5331 prefs_capture_device_monitor_mode(const char *name
)
5333 char *tok
, *devices
;
5336 if (prefs
.capture_devices_monitor_mode
&& name
) {
5337 devices
= g_strdup (prefs
.capture_devices_monitor_mode
);
5338 len
= strlen (name
);
5339 for (tok
= strtok (devices
, ","); tok
; tok
= strtok(NULL
, ",")) {
5340 if (strlen (tok
) == len
&& strcmp (name
, tok
) == 0) {
5352 * Returns true if the user has marked this column as visible
5355 prefs_capture_options_dialog_column_is_visible(const char *column
)
5360 for (curr
= g_list_first(prefs
.capture_columns
); curr
; curr
= g_list_next(curr
)) {
5361 col
= (char *)curr
->data
;
5362 if (col
&& (g_ascii_strcasecmp(col
, column
) == 0)) {
5370 prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content
)
5372 return ((prefs
.gui_layout_content_1
== layout_pane_content
) ||
5373 (prefs
.gui_layout_content_2
== layout_pane_content
) ||
5374 (prefs
.gui_layout_content_3
== layout_pane_content
));
5377 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
5378 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
5379 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
5382 * Extract the red, green, and blue components of a 24-bit RGB value
5383 * and convert them from [0,255] to [0,65535].
5385 #define RED_COMPONENT(x) (uint16_t) (((((x) >> 16) & 0xff) * 65535 / 255))
5386 #define GREEN_COMPONENT(x) (uint16_t) (((((x) >> 8) & 0xff) * 65535 / 255))
5387 #define BLUE_COMPONENT(x) (uint16_t) ( (((x) & 0xff) * 65535 / 255))
5390 string_to_name_resolve(const char *string
, e_addr_resolve
*name_resolve
)
5394 memset(name_resolve
, 0, sizeof(e_addr_resolve
));
5395 while ((c
= *string
++) != '\0') {
5398 name_resolve
->maxmind_geoip
= true;
5401 name_resolve
->mac_name
= true;
5404 name_resolve
->network_name
= true;
5407 name_resolve
->use_external_net_name_resolver
= true;
5410 name_resolve
->transport_name
= true;
5413 name_resolve
->dns_pkt_addr_resolution
= true;
5416 name_resolve
->handshake_sni_addr_resolution
= true;
5419 name_resolve
->vlan_name
= true;
5423 * Unrecognized letter.
5432 deprecated_heur_dissector_pref(char *pref_name
, const char *value
)
5434 struct heur_pref_name
5436 const char* pref_name
;
5437 const char* short_name
;
5438 bool more_dissectors
; /* For multiple dissectors controlled by the same preference */
5441 struct heur_pref_name heur_prefs
[] = {
5442 {"acn.heuristic_acn", "acn_udp", 0},
5443 {"bfcp.enable", "bfcp_tcp", 1},
5444 {"bfcp.enable", "bfcp_udp", 0},
5445 {"bt-dht.enable", "bittorrent_dht_udp", 0},
5446 {"bt-utp.enable", "bt_utp_udp", 0},
5447 {"cattp.enable", "cattp_udp", 0},
5448 {"cfp.enable", "fp_eth", 0},
5449 {"dicom.heuristic", "dicom_tcp", 0},
5450 {"dnp3.heuristics", "dnp3_tcp", 1},
5451 {"dnp3.heuristics", "dnp3_udp", 0},
5452 {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
5453 {"esl.enable", "esl_eth", 0},
5454 {"fp.udp_heur", "fp_udp", 0},
5455 {"gvsp.enable_heuristic", "gvsp_udp", 0},
5456 {"hdcp2.enable", "hdcp2_tcp", 0},
5457 {"hislip.enable_heuristic", "hislip_tcp", 0},
5458 {"infiniband.dissect_eoib", "mellanox_eoib", 1},
5459 {"infiniband.identify_payload", "eth_over_ib", 0},
5460 {"jxta.udp.heuristic", "jxta_udp", 0},
5461 {"jxta.tcp.heuristic", "jxta_tcp", 0},
5462 {"jxta.sctp.heuristic", "jxta_sctp", 0},
5463 {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
5464 {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
5465 {"norm.heuristic_norm", "rmt_norm_udp", 0},
5466 {"openflow.heuristic", "openflow_tcp", 0},
5467 {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
5468 {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
5469 {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
5470 {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
5471 {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
5472 {"rtp.heuristic_rtp", "rtp_udp", 1},
5473 {"rtp.heuristic_rtp", "rtp_stun", 0},
5474 {"teredo.heuristic_teredo", "teredo_udp", 0},
5475 {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
5476 {"xml.heuristic", "xml_http", 1},
5477 {"xml.heuristic", "xml_sip", 1},
5478 {"xml.heuristic", "xml_media", 0},
5479 {"xml.heuristic_tcp", "xml_tcp", 0},
5480 {"xml.heuristic_udp", "xml_udp", 0},
5484 heur_dtbl_entry_t
* heuristic
;
5487 for (i
= 0; i
< array_length(heur_prefs
); i
++)
5489 if (strcmp(pref_name
, heur_prefs
[i
].pref_name
) == 0)
5491 heuristic
= find_heur_dissector_by_unique_short_name(heur_prefs
[i
].short_name
);
5492 if (heuristic
!= NULL
) {
5493 heuristic
->enabled
= ((g_ascii_strcasecmp(value
, "true") == 0) ? true : false);
5496 if (!heur_prefs
[i
].more_dissectors
)
5506 deprecated_enable_dissector_pref(char *pref_name
, const char *value
)
5508 struct dissector_pref_name
5510 const char* pref_name
;
5511 const char* short_name
;
5514 struct dissector_pref_name dissector_prefs
[] = {
5515 {"transum.tsumenabled", "TRANSUM"},
5516 {"snort.enable_snort_dissector", "Snort"},
5517 {"prp.enable", "PRP"},
5523 for (i
= 0; i
< array_length(dissector_prefs
); i
++)
5525 if (strcmp(pref_name
, dissector_prefs
[i
].pref_name
) == 0)
5527 proto_id
= proto_get_id_by_short_name(dissector_prefs
[i
].short_name
);
5529 proto_set_decoding(proto_id
, ((g_ascii_strcasecmp(value
, "true") == 0) ? true : false));
5538 deprecated_port_pref(char *pref_name
, const char *value
)
5540 struct port_pref_name
5542 const char* pref_name
;
5543 const char* module_name
; /* the protocol filter name */
5544 const char* table_name
;
5548 struct obsolete_pref_name
5550 const char* pref_name
;
5553 /* For now this is only supporting TCP/UDP port and RTP payload
5554 * types dissector preferences, which are assumed to be decimal */
5555 /* module_name is the filter name of the destination port preference,
5556 * which is usually the same as the original module but not
5557 * necessarily (e.g., if the preference is for what is now a PINO.)
5558 * XXX: Most of these were changed pre-2.0. Can we end support
5559 * for migrating legacy preferences at some point?
5561 struct port_pref_name port_prefs
[] = {
5563 {"cmp.tcp_alternate_port", "cmp", "tcp.port", 10},
5564 {"h248.tcp_port", "h248", "tcp.port", 10},
5565 {"cops.tcp.cops_port", "cops", "tcp.port", 10},
5566 {"dhcpfo.tcp_port", "dhcpfo", "tcp.port", 10},
5567 {"enttec.tcp_port", "enttec", "tcp.port", 10},
5568 {"forces.tcp_alternate_port", "forces", "tcp.port", 10},
5569 {"ged125.tcp_port", "ged125", "tcp.port", 10},
5570 {"hpfeeds.dissector_port", "hpfeeds", "tcp.port", 10},
5571 {"lsc.port", "lsc", "tcp.port", 10},
5572 {"megaco.tcp.txt_port", "megaco", "tcp.port", 10},
5573 {"netsync.tcp_port", "netsync", "tcp.port", 10},
5574 {"osi.tpkt_port", "osi", "tcp.port", 10},
5575 {"rsync.tcp_port", "rsync", "tcp.port", 10},
5576 {"sametime.tcp_port", "sametime", "tcp.port", 10},
5577 {"sigcomp.tcp.port2", "sigcomp", "tcp.port", 10},
5578 {"synphasor.tcp_port", "synphasor", "tcp.port", 10},
5579 {"tipc.alternate_port", "tipc", "tcp.port", 10},
5580 {"vnc.alternate_port", "vnc", "tcp.port", 10},
5581 {"scop.port", "scop", "tcp.port", 10},
5582 {"scop.port_secure", "scop", "tcp.port", 10},
5583 {"tpncp.tcp.trunkpack_port", "tpncp", "tcp.port", 10},
5585 {"h248.udp_port", "h248", "udp.port", 10},
5586 {"actrace.udp_port", "actrace", "udp.port", 10},
5587 {"brp.port", "brp", "udp.port", 10},
5588 {"bvlc.additional_udp_port", "bvlc", "udp.port", 10},
5589 {"capwap.udp.port.control", "capwap", "udp.port", 10},
5590 {"capwap.udp.port.data", "capwap", "udp.port", 10},
5591 {"coap.udp_port", "coap", "udp.port", 10},
5592 {"enttec.udp_port", "enttec", "udp.port", 10},
5593 {"forces.udp_alternate_port", "forces", "udp.port", 10},
5594 {"ldss.udp_port", "ldss", "udp.port", 10},
5595 {"lmp.udp_port", "lmp", "udp.port", 10},
5596 {"ltp.port", "ltp", "udp.port", 10},
5597 {"lwres.udp.lwres_port", "lwres", "udp.port", 10},
5598 {"megaco.udp.txt_port", "megaco", "udp.port", 10},
5599 {"pfcp.port_pfcp", "pfcp", "udp.port", 10},
5600 {"pgm.udp.encap_ucast_port", "pgm", "udp.port", 10},
5601 {"pgm.udp.encap_mcast_port", "pgm", "udp.port", 10},
5602 {"quic.udp.quic.port", "quic", "udp.port", 10},
5603 {"quic.udp.quics.port", "quic", "udp.port", 10},
5604 {"radius.alternate_port", "radius", "udp.port", 10},
5605 {"rdt.default_udp_port", "rdt", "udp.port", 10},
5606 {"alc.default.udp_port", "alc", "udp.port", 10},
5607 {"sigcomp.udp.port2", "sigcomp", "udp.port", 10},
5608 {"synphasor.udp_port", "synphasor", "udp.port", 10},
5609 {"tdmop.udpport", "tdmop", "udp.port", 10},
5610 {"uaudp.port1", "uaudp", "udp.port", 10},
5611 {"uaudp.port2", "uaudp", "udp.port", 10},
5612 {"uaudp.port3", "uaudp", "udp.port", 10},
5613 {"uaudp.port4", "uaudp", "udp.port", 10},
5614 {"uhd.dissector_port", "uhd", "udp.port", 10},
5615 {"vrt.dissector_port", "vrt", "udp.port", 10},
5616 {"tpncp.udp.trunkpack_port", "tpncp", "udp.port", 10},
5618 {"hnbap.port", "hnbap", "sctp.port", 10},
5619 {"m2pa.port", "m2pa", "sctp.port", 10},
5620 {"megaco.sctp.txt_port", "megaco", "sctp.port", 10},
5621 {"rua.port", "rua", "sctp.port", 10},
5623 {"lapd.sctp_payload_protocol_identifier", "lapd", "sctp.ppi", 10},
5625 {"ranap.sccp_ssn", "ranap", "sccp.ssn", 10},
5628 struct port_pref_name port_range_prefs
[] = {
5630 {"couchbase.tcp.ports", "couchbase", "tcp.port", 10},
5631 {"gsm_ipa.tcp_ports", "gsm_ipa", "tcp.port", 10},
5632 {"kafka.tcp.ports", "kafka", "tcp.port", 10},
5633 {"kt.tcp.ports", "kt", "tcp.port", 10},
5634 {"memcache.tcp.ports", "memcache", "tcp.port", 10},
5635 {"mrcpv2.tcp.port_range", "mrcpv2", "tcp.port", 10},
5636 {"pdu_transport.ports.tcp", "pdu_transport", "tcp.port", 10},
5637 {"rtsp.tcp.port_range", "rtsp", "tcp.port", 10},
5638 {"sip.tcp.ports", "sip", "tcp.port", 10},
5639 {"someip.ports.tcp", "someip", "tcp.port", 10},
5640 {"tds.tcp_ports", "tds", "tcp.port", 10},
5641 {"tpkt.tcp.ports", "tpkt", "tcp.port", 10},
5642 {"uma.tcp.ports", "uma", "tcp.port", 10},
5644 {"aruba_erm.udp.ports", "arubs_erm", "udp.port", 10},
5645 {"diameter.udp.ports", "diameter", "udp.port", 10},
5646 {"dmp.udp_ports", "dmp", "udp.port", 10},
5647 {"dns.udp.ports", "dns", "udp.port", 10},
5648 {"gsm_ipa.udp_ports", "gsm_ipa", "udp.port", 10},
5649 {"hcrt.dissector_udp_port", "hcrt", "udp.port", 10},
5650 {"memcache.udp.ports", "memcache", "udp.port", 10},
5651 {"nb_rtpmux.udp_ports", "nb_rtpmux", "udp.port", 10},
5652 {"gprs-ns.udp.ports", "gprs-ns", "udp.port", 10},
5653 {"p_mul.udp_ports", "p_mul", "udp.port", 10},
5654 {"pdu_transport.ports.udp", "pdu_transport", "udp.port", 10},
5655 {"radius.ports", "radius", "udp.port", 10},
5656 {"sflow.ports", "sflow", "udp.port", 10},
5657 {"someip.ports.udp", "someip", "udp.port", 10},
5658 {"sscop.udp.ports", "sscop", "udp.port", 10},
5659 {"tftp.udp_ports", "tftp", "udp.port", 10},
5660 {"tipc.udp.ports", "tipc", "udp.port", 10},
5662 {"amr.dynamic.payload.type", "amr", "rtp.pt", 10},
5663 {"amr.wb.dynamic.payload.type", "amr_wb", "rtp.pt", 10},
5664 {"dvb-s2_modeadapt.dynamic.payload.type", "dvb-s2_modeadapt", "rtp.pt", 10},
5665 {"evs.dynamic.payload.type", "evs", "rtp.pt", 10},
5666 {"h263p.dynamic.payload.type", "h263p", "rtp.pt", 10},
5667 {"h264.dynamic.payload.type", "h264", "rtp.pt", 10},
5668 {"h265.dynamic.payload.type", "h265", "rtp.pt", 10},
5669 {"ismacryp.dynamic.payload.type", "ismacryp", "rtp.pt", 10},
5670 {"iuup.dynamic.payload.type", "iuup", "rtp.pt", 10},
5671 {"lapd.rtp_payload_type", "lapd", "rtp.pt", 10},
5672 {"mp4ves.dynamic.payload.type", "mp4ves", "rtp.pt", 10},
5673 {"mtp2.rtp_payload_type", "mtp2", "rtp.pt", 10},
5674 {"opus.dynamic.payload.type", "opus", "rtp.pt", 10},
5675 {"rtp.rfc2198_payload_type", "rtp_rfc2198", "rtp.pt", 10},
5676 {"rtpevent.event_payload_type_value", "rtpevent", "rtp.pt", 10},
5677 {"rtpevent.cisco_nse_payload_type_value", "rtpevent", "rtp.pt", 10},
5678 {"rtpmidi.midi_payload_type_value", "rtpmidi", "rtp.pt", 10},
5679 {"vp8.dynamic.payload.type", "vp8", "rtp.pt", 10},
5681 {"diameter.sctp.ports", "diameter", "sctp.port", 10},
5682 {"sgsap.sctp_ports", "sgsap", "sctp.port", 10},
5684 {"pcap.ssn", "pcap", "sccp.ssn", 10},
5687 /* These are subdissectors of TPKT/OSITP that used to have a
5688 TCP port preference even though they were never
5689 directly on TCP. Convert them to use Decode As
5690 with the TPKT dissector handle */
5691 struct port_pref_name tpkt_subdissector_port_prefs
[] = {
5692 {"dap.tcp.port", "dap", "tcp.port", 10},
5693 {"disp.tcp.port", "disp", "tcp.port", 10},
5694 {"dop.tcp.port", "dop", "tcp.port", 10},
5695 {"dsp.tcp.port", "dsp", "tcp.port", 10},
5696 {"p1.tcp.port", "p1", "tcp.port", 10},
5697 {"p7.tcp.port", "p7", "tcp.port", 10},
5698 {"rdp.tcp.port", "rdp", "tcp.port", 10},
5701 /* These are obsolete preferences from the dissectors' view,
5702 (typically because of a switch from a single value to a
5703 range value) but the name of the preference conflicts
5704 with the generated preference name from the dissector table.
5705 Don't allow the obsolete preference through to be handled */
5706 struct obsolete_pref_name obsolete_prefs
[] = {
5707 {"diameter.tcp.port"},
5709 {"mrcpv2.tcp.port"},
5717 dissector_table_t sub_dissectors
;
5718 dissector_handle_t handle
, tpkt_handle
;
5722 static bool sanity_checked
;
5723 if (!sanity_checked
) {
5724 sanity_checked
= true;
5725 for (i
= 0; i
< G_N_ELEMENTS(port_prefs
); i
++) {
5726 module
= prefs_find_module(port_prefs
[i
].module_name
);
5728 ws_warning("Deprecated ports pref check - module '%s' not found", port_prefs
[i
].module_name
);
5731 pref
= prefs_find_preference(module
, port_prefs
[i
].table_name
);
5733 ws_warning("Deprecated ports pref '%s.%s' not found", module
->name
, port_prefs
[i
].table_name
);
5736 if (pref
->type
!= PREF_DECODE_AS_RANGE
) {
5737 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
));
5742 for (i
= 0; i
< G_N_ELEMENTS(port_prefs
); i
++) {
5743 if (strcmp(pref_name
, port_prefs
[i
].pref_name
) == 0) {
5744 if (!ws_basestrtou32(value
, NULL
, &uval
, port_prefs
[i
].base
))
5745 return false; /* number was bad */
5747 module
= prefs_find_module(port_prefs
[i
].module_name
);
5748 pref
= prefs_find_preference(module
, port_prefs
[i
].table_name
);
5750 module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
5751 if (pref
->type
== PREF_DECODE_AS_RANGE
) {
5752 // The legacy preference was a port number, but the new
5753 // preference is a port range. Add to existing range.
5755 prefs_range_add_value(pref
, uval
);
5760 /* If the value is zero, it wouldn't add to the Decode As tables */
5763 sub_dissectors
= find_dissector_table(port_prefs
[i
].table_name
);
5764 if (sub_dissectors
!= NULL
) {
5765 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
5766 if (handle
!= NULL
) {
5767 dissector_change_uint(port_prefs
[i
].table_name
, uval
, handle
);
5768 decode_build_reset_list(port_prefs
[i
].table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(uval
), NULL
, NULL
);
5777 for (i
= 0; i
< array_length(port_range_prefs
); i
++)
5779 if (strcmp(pref_name
, port_range_prefs
[i
].pref_name
) == 0)
5781 uint32_t range_i
, range_j
;
5783 sub_dissectors
= find_dissector_table(port_range_prefs
[i
].table_name
);
5784 if (sub_dissectors
!= NULL
) {
5785 switch (dissector_table_get_type(sub_dissectors
)) {
5793 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
));
5794 ws_assert_not_reached();
5797 module
= prefs_find_module(port_range_prefs
[i
].module_name
);
5798 pref
= prefs_find_preference(module
, port_range_prefs
[i
].table_name
);
5801 if (!prefs_set_range_value_work(pref
, value
, true, &module
->prefs_changed_flags
))
5803 return false; /* number was bad */
5806 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
5807 if (handle
!= NULL
) {
5809 for (range_i
= 0; range_i
< (*pref
->varp
.range
)->nranges
; range_i
++) {
5810 for (range_j
= (*pref
->varp
.range
)->ranges
[range_i
].low
; range_j
< (*pref
->varp
.range
)->ranges
[range_i
].high
; range_j
++) {
5811 dissector_change_uint(port_range_prefs
[i
].table_name
, range_j
, handle
);
5812 decode_build_reset_list(port_range_prefs
[i
].table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(range_j
), NULL
, NULL
);
5815 dissector_change_uint(port_range_prefs
[i
].table_name
, (*pref
->varp
.range
)->ranges
[range_i
].high
, handle
);
5816 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
);
5826 for (i
= 0; i
< array_length(tpkt_subdissector_port_prefs
); i
++)
5828 if (strcmp(pref_name
, tpkt_subdissector_port_prefs
[i
].pref_name
) == 0)
5830 /* XXX - give an error if it doesn't fit in a unsigned? */
5831 if (!ws_basestrtou32(value
, NULL
, &uval
, tpkt_subdissector_port_prefs
[i
].base
))
5832 return false; /* number was bad */
5834 /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
5835 if ((uval
!= 0) && (uval
!= 102))
5837 tpkt_handle
= find_dissector("tpkt");
5838 if (tpkt_handle
!= NULL
) {
5839 dissector_change_uint(tpkt_subdissector_port_prefs
[i
].table_name
, uval
, tpkt_handle
);
5847 for (i
= 0; i
< array_length(obsolete_prefs
); i
++)
5849 if (strcmp(pref_name
, obsolete_prefs
[i
].pref_name
) == 0)
5851 /* Just ignore the preference */
5858 static prefs_set_pref_e
5859 set_pref(char *pref_name
, const char *value
, void *private_data
,
5860 bool return_range_errors
)
5866 char *dotp
, *last_dotp
;
5867 static char *filter_label
= NULL
;
5868 static bool filter_enabled
= false;
5869 module_t
*module
, *containing_module
, *target_module
;
5872 bool converted_pref
= false;
5874 target_module
= (module_t
*)private_data
;
5876 //The PRS_GUI field names are here for backwards compatibility
5877 //display filters have been converted to a UAT.
5878 if (strcmp(pref_name
, PRS_GUI_FILTER_LABEL
) == 0) {
5879 /* Assume that PRS_GUI_FILTER_EXPR follows this preference. In case of
5880 * malicious preference files, free the previous value to limit the size
5881 * of leaked memory. */
5882 g_free(filter_label
);
5883 filter_label
= g_strdup(value
);
5884 } else if (strcmp(pref_name
, PRS_GUI_FILTER_ENABLED
) == 0) {
5885 filter_enabled
= (strcmp(value
, "TRUE") == 0) ? true : false;
5886 } else if (strcmp(pref_name
, PRS_GUI_FILTER_EXPR
) == 0) {
5887 /* Comments not supported for "old" preference style */
5888 filter_expression_new(filter_label
, value
, "", filter_enabled
);
5889 g_free(filter_label
);
5890 filter_label
= NULL
;
5891 /* Remember to save the new UAT to file. */
5892 prefs
.filter_expressions_old
= true;
5893 } else if (strcmp(pref_name
, "gui.version_in_start_page") == 0) {
5894 /* Convert deprecated value to closest current equivalent */
5895 if (g_ascii_strcasecmp(value
, "true") == 0) {
5896 prefs
.gui_version_placement
= version_both
;
5898 prefs
.gui_version_placement
= version_neither
;
5900 } else if (strcmp(pref_name
, "name_resolve") == 0 ||
5901 strcmp(pref_name
, "capture.name_resolve") == 0) {
5903 * Handle the deprecated name resolution options.
5905 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
5906 * RESOLV_ALL and RESOLV_NONE.
5908 * Otherwise, we treat it as a list of name types we want to resolve.
5910 if (g_ascii_strcasecmp(value
, "true") == 0) {
5911 gbl_resolv_flags
.mac_name
= true;
5912 gbl_resolv_flags
.network_name
= true;
5913 gbl_resolv_flags
.transport_name
= true;
5915 else if (g_ascii_strcasecmp(value
, "false") == 0) {
5916 disable_name_resolution();
5919 /* start out with none set */
5920 disable_name_resolution();
5921 if (string_to_name_resolve(value
, &gbl_resolv_flags
) != '\0')
5922 return PREFS_SET_SYNTAX_ERR
;
5924 } else if (deprecated_heur_dissector_pref(pref_name
, value
)) {
5925 /* Handled within deprecated_heur_dissector_pref() if found */
5926 } else if (deprecated_enable_dissector_pref(pref_name
, value
)) {
5927 /* Handled within deprecated_enable_dissector_pref() if found */
5928 } else if (deprecated_port_pref(pref_name
, value
)) {
5929 /* Handled within deprecated_port_pref() if found */
5930 } else if (strcmp(pref_name
, "console.log.level") == 0) {
5931 /* Handled on the command line within ws_log_parse_args() */
5932 return PREFS_SET_OK
;
5934 /* Handle deprecated "global" options that don't have a module
5935 * associated with them
5937 if ((strcmp(pref_name
, "name_resolve_concurrency") == 0) ||
5938 (strcmp(pref_name
, "name_resolve_load_smi_modules") == 0) ||
5939 (strcmp(pref_name
, "name_resolve_suppress_smi_errors") == 0)) {
5940 module
= nameres_module
;
5943 /* To which module does this preference belong? */
5945 last_dotp
= pref_name
;
5947 dotp
= strchr(last_dotp
, '.');
5949 /* Either there's no such module, or no module was specified.
5950 In either case, that means there's no such preference. */
5951 return PREFS_SET_NO_SUCH_PREF
;
5953 *dotp
= '\0'; /* separate module and preference name */
5954 module
= prefs_find_module(pref_name
);
5957 * XXX - "Diameter" rather than "diameter" was used in earlier
5958 * versions of Wireshark; if we didn't find the module, and its name
5959 * was "Diameter", look for "diameter" instead.
5961 * In addition, the BEEP protocol used to be the BXXP protocol,
5962 * so if we didn't find the module, and its name was "bxxp",
5963 * look for "beep" instead.
5965 * Also, the preferences for GTP v0 and v1 were combined under
5966 * a single "gtp" heading, and the preferences for SMPP were
5967 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
5968 * However, SMPP now has its own preferences, so we just map
5969 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
5971 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
5972 * and "nsip" to "gprs_ns".
5974 * The SynOptics Network Management Protocol (SONMP) is now known by
5975 * its modern name, the Nortel Discovery Protocol (NDP).
5977 if (module
== NULL
) {
5979 * See if there's a backwards-compatibility name
5980 * that maps to this module.
5982 module
= prefs_find_module_alias(pref_name
);
5983 if (module
== NULL
) {
5985 * There's no alias for the module; see if the
5986 * module name matches any protocol aliases.
5988 header_field_info
*hfinfo
= proto_registrar_get_byalias(pref_name
);
5990 module
= (module_t
*) wmem_tree_lookup_string(prefs_modules
, hfinfo
->abbrev
, WMEM_TREE_STRING_NOCASE
);
5993 if (module
== NULL
) {
5995 * There aren't any aliases. Was the module
5996 * removed rather than renamed?
5998 if (strcmp(pref_name
, "etheric") == 0 ||
5999 strcmp(pref_name
, "isup_thin") == 0) {
6001 * The dissectors for these protocols were
6002 * removed as obsolete on 2009-07-70 in change
6003 * 739bfc6ff035583abb9434e0e988048de38a8d9a.
6005 return PREFS_SET_OBSOLETE
;
6009 converted_pref
= true;
6010 prefs
.unknown_prefs
= true;
6013 *dotp
= '.'; /* put the preference string back */
6014 dotp
++; /* skip past separator to preference name */
6019 /* The pref is located in the module or a submodule.
6020 * Assume module, then search for a submodule holding the pref. */
6021 containing_module
= module
;
6022 pref
= prefs_find_preference_with_submodule(module
, dotp
, &containing_module
);
6025 prefs
.unknown_prefs
= true;
6027 /* "gui" prefix was added to column preferences for better organization
6028 * within the preferences file
6030 if (module
== gui_column_module
) {
6031 /* While this has a subtree, there is no apply callback, so no
6032 * need to use prefs_find_preference_with_submodule to update
6033 * containing_module. It would not be useful. */
6034 pref
= prefs_find_preference(module
, pref_name
);
6036 else if (strcmp(module
->name
, "mgcp") == 0) {
6038 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
6039 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
6040 * were used in earlier versions of Wireshark; if we didn't find the
6041 * preference, it was an MGCP preference, and its name was
6042 * "display raw text toggle" or "display dissect tree", look for
6043 * "display_raw_text" or "display_dissect_tree" instead.
6045 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
6046 * the gateway and callagent ports were given those names; we interpret
6047 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
6048 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
6049 * they were registered by the MCCP dissector and thus that's the
6050 * order in which they were written to the preferences file. (If
6051 * we're not reading the preferences file, but are handling stuff
6052 * from a "-o" command-line option, we have no clue which the user
6053 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
6054 * or "mgcp.{tcp,udp}.callagent_port" instead.)
6056 if (strcmp(dotp
, "display raw text toggle") == 0)
6057 pref
= prefs_find_preference(module
, "display_raw_text");
6058 else if (strcmp(dotp
, "display dissect tree") == 0)
6059 pref
= prefs_find_preference(module
, "display_dissect_tree");
6060 else if (strcmp(dotp
, "tcp.port") == 0) {
6061 mgcp_tcp_port_count
++;
6062 if (mgcp_tcp_port_count
== 1) {
6063 /* It's the first one */
6064 pref
= prefs_find_preference(module
, "tcp.gateway_port");
6065 } else if (mgcp_tcp_port_count
== 2) {
6066 /* It's the second one */
6067 pref
= prefs_find_preference(module
, "tcp.callagent_port");
6069 /* Otherwise it's from the command line, and we don't bother
6071 } else if (strcmp(dotp
, "udp.port") == 0) {
6072 mgcp_udp_port_count
++;
6073 if (mgcp_udp_port_count
== 1) {
6074 /* It's the first one */
6075 pref
= prefs_find_preference(module
, "udp.gateway_port");
6076 } else if (mgcp_udp_port_count
== 2) {
6077 /* It's the second one */
6078 pref
= prefs_find_preference(module
, "udp.callagent_port");
6080 /* Otherwise it's from the command line, and we don't bother
6083 } else if (strcmp(module
->name
, "smb") == 0) {
6084 /* Handle old names for SMB preferences. */
6085 if (strcmp(dotp
, "smb.trans.reassembly") == 0)
6086 pref
= prefs_find_preference(module
, "trans_reassembly");
6087 else if (strcmp(dotp
, "smb.dcerpc.reassembly") == 0)
6088 pref
= prefs_find_preference(module
, "dcerpc_reassembly");
6089 } else if (strcmp(module
->name
, "ndmp") == 0) {
6090 /* Handle old names for NDMP preferences. */
6091 if (strcmp(dotp
, "ndmp.desegment") == 0)
6092 pref
= prefs_find_preference(module
, "desegment");
6093 } else if (strcmp(module
->name
, "diameter") == 0) {
6094 /* Handle old names for Diameter preferences. */
6095 if (strcmp(dotp
, "diameter.desegment") == 0)
6096 pref
= prefs_find_preference(module
, "desegment");
6097 } else if (strcmp(module
->name
, "pcli") == 0) {
6098 /* Handle old names for PCLI preferences. */
6099 if (strcmp(dotp
, "pcli.udp_port") == 0)
6100 pref
= prefs_find_preference(module
, "udp_port");
6101 } else if (strcmp(module
->name
, "artnet") == 0) {
6102 /* Handle old names for ARTNET preferences. */
6103 if (strcmp(dotp
, "artnet.udp_port") == 0)
6104 pref
= prefs_find_preference(module
, "udp_port");
6105 } else if (strcmp(module
->name
, "mapi") == 0) {
6106 /* Handle old names for MAPI preferences. */
6107 if (strcmp(dotp
, "mapi_decrypt") == 0)
6108 pref
= prefs_find_preference(module
, "decrypt");
6109 } else if (strcmp(module
->name
, "fc") == 0) {
6110 /* Handle old names for Fibre Channel preferences. */
6111 if (strcmp(dotp
, "reassemble_fc") == 0)
6112 pref
= prefs_find_preference(module
, "reassemble");
6113 else if (strcmp(dotp
, "fc_max_frame_size") == 0)
6114 pref
= prefs_find_preference(module
, "max_frame_size");
6115 } else if (strcmp(module
->name
, "fcip") == 0) {
6116 /* Handle old names for Fibre Channel-over-IP preferences. */
6117 if (strcmp(dotp
, "desegment_fcip_messages") == 0)
6118 pref
= prefs_find_preference(module
, "desegment");
6119 else if (strcmp(dotp
, "fcip_port") == 0)
6120 pref
= prefs_find_preference(module
, "target_port");
6121 } else if (strcmp(module
->name
, "gtp") == 0) {
6122 /* Handle old names for GTP preferences. */
6123 if (strcmp(dotp
, "gtpv0_port") == 0)
6124 pref
= prefs_find_preference(module
, "v0_port");
6125 else if (strcmp(dotp
, "gtpv1c_port") == 0)
6126 pref
= prefs_find_preference(module
, "v1c_port");
6127 else if (strcmp(dotp
, "gtpv1u_port") == 0)
6128 pref
= prefs_find_preference(module
, "v1u_port");
6129 else if (strcmp(dotp
, "gtp_dissect_tpdu") == 0)
6130 pref
= prefs_find_preference(module
, "dissect_tpdu");
6131 else if (strcmp(dotp
, "gtpv0_dissect_cdr_as") == 0)
6132 pref
= prefs_find_preference(module
, "v0_dissect_cdr_as");
6133 else if (strcmp(dotp
, "gtpv0_check_etsi") == 0)
6134 pref
= prefs_find_preference(module
, "v0_check_etsi");
6135 else if (strcmp(dotp
, "gtpv1_check_etsi") == 0)
6136 pref
= prefs_find_preference(module
, "v1_check_etsi");
6137 } else if (strcmp(module
->name
, "ip") == 0) {
6138 /* Handle old names for IP preferences. */
6139 if (strcmp(dotp
, "ip_summary_in_tree") == 0)
6140 pref
= prefs_find_preference(module
, "summary_in_tree");
6141 } else if (strcmp(module
->name
, "iscsi") == 0) {
6142 /* Handle old names for iSCSI preferences. */
6143 if (strcmp(dotp
, "iscsi_port") == 0)
6144 pref
= prefs_find_preference(module
, "target_port");
6145 } else if (strcmp(module
->name
, "lmp") == 0) {
6146 /* Handle old names for LMP preferences. */
6147 if (strcmp(dotp
, "lmp_version") == 0)
6148 pref
= prefs_find_preference(module
, "version");
6149 } else if (strcmp(module
->name
, "mtp3") == 0) {
6150 /* Handle old names for MTP3 preferences. */
6151 if (strcmp(dotp
, "mtp3_standard") == 0)
6152 pref
= prefs_find_preference(module
, "standard");
6153 else if (strcmp(dotp
, "net_addr_format") == 0)
6154 pref
= prefs_find_preference(module
, "addr_format");
6155 } else if (strcmp(module
->name
, "nlm") == 0) {
6156 /* Handle old names for NLM preferences. */
6157 if (strcmp(dotp
, "nlm_msg_res_matching") == 0)
6158 pref
= prefs_find_preference(module
, "msg_res_matching");
6159 } else if (strcmp(module
->name
, "ppp") == 0) {
6160 /* Handle old names for PPP preferences. */
6161 if (strcmp(dotp
, "ppp_fcs") == 0)
6162 pref
= prefs_find_preference(module
, "fcs_type");
6163 else if (strcmp(dotp
, "ppp_vj") == 0)
6164 pref
= prefs_find_preference(module
, "decompress_vj");
6165 } else if (strcmp(module
->name
, "rsvp") == 0) {
6166 /* Handle old names for RSVP preferences. */
6167 if (strcmp(dotp
, "rsvp_process_bundle") == 0)
6168 pref
= prefs_find_preference(module
, "process_bundle");
6169 } else if (strcmp(module
->name
, "tcp") == 0) {
6170 /* Handle old names for TCP preferences. */
6171 if (strcmp(dotp
, "tcp_summary_in_tree") == 0)
6172 pref
= prefs_find_preference(module
, "summary_in_tree");
6173 else if (strcmp(dotp
, "tcp_analyze_sequence_numbers") == 0)
6174 pref
= prefs_find_preference(module
, "analyze_sequence_numbers");
6175 else if (strcmp(dotp
, "tcp_relative_sequence_numbers") == 0)
6176 pref
= prefs_find_preference(module
, "relative_sequence_numbers");
6177 else if (strcmp(dotp
, "dissect_experimental_options_with_magic") == 0)
6178 pref
= prefs_find_preference(module
, "dissect_experimental_options_rfc6994");
6179 } else if (strcmp(module
->name
, "udp") == 0) {
6180 /* Handle old names for UDP preferences. */
6181 if (strcmp(dotp
, "udp_summary_in_tree") == 0)
6182 pref
= prefs_find_preference(module
, "summary_in_tree");
6183 } else if (strcmp(module
->name
, "ndps") == 0) {
6184 /* Handle old names for NDPS preferences. */
6185 if (strcmp(dotp
, "desegment_ndps") == 0)
6186 pref
= prefs_find_preference(module
, "desegment_tcp");
6187 } else if (strcmp(module
->name
, "http") == 0) {
6188 /* Handle old names for HTTP preferences. */
6189 if (strcmp(dotp
, "desegment_http_headers") == 0)
6190 pref
= prefs_find_preference(module
, "desegment_headers");
6191 else if (strcmp(dotp
, "desegment_http_body") == 0)
6192 pref
= prefs_find_preference(module
, "desegment_body");
6193 } else if (strcmp(module
->name
, "smpp") == 0) {
6194 /* Handle preferences that moved from SMPP. */
6195 module_t
*new_module
= prefs_find_module("gsm-sms-ud");
6197 if (strcmp(dotp
, "port_number_udh_means_wsp") == 0) {
6198 pref
= prefs_find_preference(new_module
, "port_number_udh_means_wsp");
6199 containing_module
= new_module
;
6200 } else if (strcmp(dotp
, "try_dissect_1st_fragment") == 0) {
6201 pref
= prefs_find_preference(new_module
, "try_dissect_1st_fragment");
6202 containing_module
= new_module
;
6205 } else if (strcmp(module
->name
, "asn1") == 0) {
6206 /* Handle old generic ASN.1 preferences (it's not really a
6207 rename, as the new preferences support multiple ports,
6208 but we might as well copy them over). */
6209 if (strcmp(dotp
, "tcp_port") == 0)
6210 pref
= prefs_find_preference(module
, "tcp_ports");
6211 else if (strcmp(dotp
, "udp_port") == 0)
6212 pref
= prefs_find_preference(module
, "udp_ports");
6213 else if (strcmp(dotp
, "sctp_port") == 0)
6214 pref
= prefs_find_preference(module
, "sctp_ports");
6215 } else if (strcmp(module
->name
, "llcgprs") == 0) {
6216 if (strcmp(dotp
, "ignore_cipher_bit") == 0)
6217 pref
= prefs_find_preference(module
, "autodetect_cipher_bit");
6218 } else if (strcmp(module
->name
, "erf") == 0) {
6219 if (strcmp(dotp
, "erfeth") == 0) {
6220 /* Handle the old "erfeth" preference; map it to the new
6221 "ethfcs" preference, and map the values to those for
6222 the new preference. */
6223 pref
= prefs_find_preference(module
, "ethfcs");
6224 if (strcmp(value
, "ethfcs") == 0 || strcmp(value
, "Ethernet with FCS") == 0)
6226 else if (strcmp(value
, "eth") == 0 || strcmp(value
, "Ethernet") == 0)
6228 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6230 } else if (strcmp(dotp
, "erfatm") == 0) {
6231 /* Handle the old "erfatm" preference; map it to the new
6232 "aal5_type" preference, and map the values to those for
6233 the new preference. */
6234 pref
= prefs_find_preference(module
, "aal5_type");
6235 if (strcmp(value
, "atm") == 0 || strcmp(value
, "ATM") == 0)
6237 else if (strcmp(value
, "llc") == 0 || strcmp(value
, "LLC") == 0)
6239 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6241 } else if (strcmp(dotp
, "erfhdlc") == 0) {
6242 /* Handle the old "erfhdlc" preference; map it to the new
6243 "hdlc_type" preference, and map the values to those for
6244 the new preference. */
6245 pref
= prefs_find_preference(module
, "hdlc_type");
6246 if (strcmp(value
, "chdlc") == 0 || strcmp(value
, "Cisco HDLC") == 0)
6248 else if (strcmp(value
, "ppp") == 0 || strcmp(value
, "PPP serial") == 0)
6250 else if (strcmp(value
, "fr") == 0 || strcmp(value
, "Frame Relay") == 0)
6252 else if (strcmp(value
, "mtp2") == 0 || strcmp(value
, "SS7 MTP2") == 0)
6254 else if (strcmp(value
, "raw") == 0 || strcmp(value
, "Raw data") == 0)
6257 } else if (strcmp(module
->name
, "eth") == 0) {
6258 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
6259 if (strcmp(dotp
, "qinq_ethertype") == 0) {
6260 module_t
*new_module
= prefs_find_module("vlan");
6262 pref
= prefs_find_preference(new_module
, "qinq_ethertype");
6263 containing_module
= new_module
;
6266 } else if (strcmp(module
->name
, "taps") == 0) {
6267 /* taps preferences moved to "statistics" module */
6268 if (strcmp(dotp
, "update_interval") == 0)
6269 pref
= prefs_find_preference(stats_module
, dotp
);
6270 } else if (strcmp(module
->name
, "packet_list") == 0) {
6271 /* packet_list preferences moved to protocol module */
6272 if (strcmp(dotp
, "display_hidden_proto_items") == 0)
6273 pref
= prefs_find_preference(protocols_module
, dotp
);
6274 } else if (strcmp(module
->name
, "stream") == 0) {
6275 /* stream preferences moved to gui color module */
6276 if ((strcmp(dotp
, "client.fg") == 0) ||
6277 (strcmp(dotp
, "client.bg") == 0) ||
6278 (strcmp(dotp
, "server.fg") == 0) ||
6279 (strcmp(dotp
, "server.bg") == 0))
6280 pref
= prefs_find_preference(gui_color_module
, pref_name
);
6281 } else if (strcmp(module
->name
, "nameres") == 0) {
6282 if (strcmp(pref_name
, "name_resolve_concurrency") == 0) {
6283 pref
= prefs_find_preference(nameres_module
, pref_name
);
6284 } else if (strcmp(pref_name
, "name_resolve_load_smi_modules") == 0) {
6285 pref
= prefs_find_preference(nameres_module
, "load_smi_modules");
6286 } else if (strcmp(pref_name
, "name_resolve_suppress_smi_errors") == 0) {
6287 pref
= prefs_find_preference(nameres_module
, "suppress_smi_errors");
6289 } else if (strcmp(module
->name
, "extcap") == 0) {
6290 /* Handle the old "sshdump.remotesudo" preference; map it to the new
6291 "sshdump.remotepriv" preference, and map the boolean values to the
6292 appropriate strings of the new preference. */
6293 if (strcmp(dotp
, "sshdump.remotesudo") == 0) {
6294 pref
= prefs_find_preference(module
, "sshdump.remotepriv");
6295 if (g_ascii_strcasecmp(value
, "true") == 0)
6302 converted_pref
= true;
6305 if (pref
== NULL
) {
6306 if (strcmp(module
->name
, "extcap") == 0 && g_list_length(module
->prefs
) <= 1) {
6308 * Assume that we've skipped extcap preference registration
6309 * and that only extcap.gui_save_on_start is loaded.
6311 return PREFS_SET_OK
;
6313 return PREFS_SET_NO_SUCH_PREF
; /* no such preference */
6316 if (target_module
&& target_module
!= containing_module
) {
6318 return PREFS_SET_OK
;
6322 if (IS_PREF_OBSOLETE(type
)) {
6323 return PREFS_SET_OBSOLETE
; /* no such preference any more */
6325 RESET_PREF_OBSOLETE(type
);
6328 if (converted_pref
) {
6329 ws_warning("Preference \"%s\" has been converted to \"%s.%s\"\n"
6330 "Save your preferences to make this change permanent.",
6331 pref_name
, module
->name
? module
->name
: module
->parent
->name
, prefs_get_name(pref
));
6337 if (!ws_basestrtou32(value
, NULL
, &uval
, pref
->info
.base
))
6338 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6339 if (*pref
->varp
.uint
!= uval
) {
6340 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6341 *pref
->varp
.uint
= uval
;
6345 /* XXX - give an error if it's neither "true" nor "false"? */
6346 if (g_ascii_strcasecmp(value
, "true") == 0)
6350 if (*pref
->varp
.boolp
!= bval
) {
6351 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6352 *pref
->varp
.boolp
= bval
;
6357 /* XXX - give an error if it doesn't match? */
6358 enum_val
= find_val_for_string(value
, pref
->info
.enum_info
.enumvals
,
6360 if (*pref
->varp
.enump
!= enum_val
) {
6361 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6362 *pref
->varp
.enump
= enum_val
;
6367 case PREF_SAVE_FILENAME
:
6368 case PREF_OPEN_FILENAME
:
6370 case PREF_DISSECTOR
:
6371 containing_module
->prefs_changed_flags
|= prefs_set_string_value(pref
, value
, pref_current
);
6375 /* Read value is every time empty */
6376 containing_module
->prefs_changed_flags
|= prefs_set_string_value(pref
, "", pref_current
);
6381 if (!prefs_set_range_value_work(pref
, value
, return_range_errors
,
6382 &containing_module
->prefs_changed_flags
))
6383 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6386 case PREF_DECODE_AS_RANGE
:
6388 /* This is for backwards compatibility in case any of the preferences
6389 that shared the "Decode As" preference name and used to be PREF_RANGE
6390 are now applied directly to the Decode As funtionality */
6392 dissector_table_t sub_dissectors
;
6393 dissector_handle_t handle
;
6396 if (range_convert_str_work(wmem_epan_scope(), &newrange
, value
, pref
->info
.max_value
,
6397 return_range_errors
) != CVT_NO_ERROR
) {
6398 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6401 if (!ranges_are_equal(*pref
->varp
.range
, newrange
)) {
6402 wmem_free(wmem_epan_scope(), *pref
->varp
.range
);
6403 *pref
->varp
.range
= newrange
;
6404 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6406 const char* table_name
= prefs_get_dissector_table(pref
);
6407 sub_dissectors
= find_dissector_table(table_name
);
6408 if (sub_dissectors
!= NULL
) {
6409 handle
= dissector_table_get_dissector_handle(sub_dissectors
, module
->title
);
6410 if (handle
!= NULL
) {
6411 /* Delete all of the old values from the dissector table */
6412 for (i
= 0; i
< (*pref
->varp
.range
)->nranges
; i
++) {
6413 for (j
= (*pref
->varp
.range
)->ranges
[i
].low
; j
< (*pref
->varp
.range
)->ranges
[i
].high
; j
++) {
6414 dissector_delete_uint(table_name
, j
, handle
);
6415 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
6418 dissector_delete_uint(table_name
, (*pref
->varp
.range
)->ranges
[i
].high
, handle
);
6419 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER((*pref
->varp
.range
)->ranges
[i
].high
), NULL
, NULL
);
6422 /* Add new values to the dissector table */
6423 for (i
= 0; i
< newrange
->nranges
; i
++) {
6424 for (j
= newrange
->ranges
[i
].low
; j
< newrange
->ranges
[i
].high
; j
++) {
6425 dissector_change_uint(table_name
, j
, handle
);
6426 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(j
), NULL
, NULL
);
6429 dissector_change_uint(table_name
, newrange
->ranges
[i
].high
, handle
);
6430 decode_build_reset_list(table_name
, dissector_table_get_type(sub_dissectors
), GUINT_TO_POINTER(newrange
->ranges
[i
].high
), NULL
, NULL
);
6433 /* XXX - Do we save the decode_as_entries file here? */
6437 wmem_free(wmem_epan_scope(), newrange
);
6444 if (!ws_hexstrtou32(value
, NULL
, &cval
))
6445 return PREFS_SET_SYNTAX_ERR
; /* number was bad */
6446 if ((pref
->varp
.colorp
->red
!= RED_COMPONENT(cval
)) ||
6447 (pref
->varp
.colorp
->green
!= GREEN_COMPONENT(cval
)) ||
6448 (pref
->varp
.colorp
->blue
!= BLUE_COMPONENT(cval
))) {
6449 containing_module
->prefs_changed_flags
|= prefs_get_effect_flags(pref
);
6450 pref
->varp
.colorp
->red
= RED_COMPONENT(cval
);
6451 pref
->varp
.colorp
->green
= GREEN_COMPONENT(cval
);
6452 pref
->varp
.colorp
->blue
= BLUE_COMPONENT(cval
);
6458 return pref
->custom_cbs
.set_cb(pref
, value
, &containing_module
->prefs_changed_flags
);
6460 case PREF_STATIC_TEXT
:
6462 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6464 /* There's no point in setting the TCP sequence override
6465 * value from the command line, because the pref is different
6466 * for each frame and reset to the default (0) for each new
6474 return PREFS_SET_OK
;
6480 } write_gui_pref_arg_t
;
6483 prefs_pref_type_name(pref_t
*pref
)
6485 const char *type_name
= "[Unknown]";
6489 return type_name
; /* ...or maybe assert? */
6494 if (IS_PREF_OBSOLETE(type
)) {
6495 type_name
= "Obsolete";
6497 RESET_PREF_OBSOLETE(type
);
6503 switch (pref
->info
.base
) {
6506 type_name
= "Decimal";
6510 type_name
= "Octal";
6514 type_name
= "Hexadecimal";
6520 type_name
= "Boolean";
6524 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6525 type_name
= "Choice";
6529 type_name
= "String";
6532 case PREF_SAVE_FILENAME
:
6533 case PREF_OPEN_FILENAME
:
6534 type_name
= "Filename";
6538 type_name
= "Directory";
6542 type_name
= "Range";
6546 type_name
= "Color";
6550 if (pref
->custom_cbs
.type_name_cb
)
6551 return pref
->custom_cbs
.type_name_cb();
6552 type_name
= "Custom";
6555 case PREF_DECODE_AS_RANGE
:
6556 type_name
= "Range (for Decode As)";
6559 case PREF_STATIC_TEXT
:
6560 type_name
= "Static text";
6568 type_name
= "Password";
6571 case PREF_DISSECTOR
:
6572 type_name
= "Dissector";
6579 prefs_get_effect_flags(pref_t
*pref
)
6584 return pref
->effect_flags
;
6588 prefs_set_effect_flags(pref_t
*pref
, unsigned int flags
)
6592 ws_error("Setting \"%s\" preference effect flags to 0", pref
->name
);
6594 pref
->effect_flags
= flags
;
6599 prefs_set_effect_flags_by_name(module_t
* module
, const char *pref
, unsigned int flags
)
6601 prefs_set_effect_flags(prefs_find_preference(module
, pref
), flags
);
6605 prefs_get_module_effect_flags(module_t
* module
)
6610 return module
->effect_flags
;
6614 prefs_set_module_effect_flags(module_t
* module
, unsigned int flags
)
6616 if (module
!= NULL
) {
6618 ws_error("Setting module \"%s\" preference effect flags to 0", module
->name
);
6620 module
->effect_flags
= flags
;
6625 prefs_pref_type_description(pref_t
*pref
)
6627 const char *type_desc
= "An unknown preference type";
6631 return ws_strdup_printf("%s.", type_desc
); /* ...or maybe assert? */
6636 if (IS_PREF_OBSOLETE(type
)) {
6637 type_desc
= "An obsolete preference";
6639 RESET_PREF_OBSOLETE(type
);
6645 switch (pref
->info
.base
) {
6648 type_desc
= "A decimal number";
6652 type_desc
= "An octal number";
6656 type_desc
= "A hexadecimal number";
6662 type_desc
= "true or false (case-insensitive)";
6666 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6668 const enum_val_t
*enum_valp
= pref
->info
.enum_info
.enumvals
;
6669 GString
*enum_str
= g_string_new("One of: ");
6670 GString
*desc_str
= g_string_new("\nEquivalently, one of: ");
6671 bool distinct
= false;
6672 while (enum_valp
->name
!= NULL
) {
6673 g_string_append(enum_str
, enum_valp
->name
);
6674 g_string_append(desc_str
, enum_valp
->description
);
6675 if (g_strcmp0(enum_valp
->name
, enum_valp
->description
) != 0) {
6679 if (enum_valp
->name
!= NULL
) {
6680 g_string_append(enum_str
, ", ");
6681 g_string_append(desc_str
, ", ");
6685 g_string_append(enum_str
, desc_str
->str
);
6687 g_string_free(desc_str
, TRUE
);
6688 g_string_append(enum_str
, "\n(case-insensitive).");
6689 return g_string_free(enum_str
, FALSE
);
6693 type_desc
= "A string";
6696 case PREF_SAVE_FILENAME
:
6697 case PREF_OPEN_FILENAME
:
6698 type_desc
= "A path to a file";
6702 type_desc
= "A path to a directory";
6707 type_desc
= "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
6713 type_desc
= "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
6718 if (pref
->custom_cbs
.type_description_cb
)
6719 return pref
->custom_cbs
.type_description_cb();
6720 type_desc
= "A custom value";
6723 case PREF_DECODE_AS_RANGE
:
6724 type_desc
= "A string denoting an positive integer range for Decode As";
6727 case PREF_STATIC_TEXT
:
6728 type_desc
= "[Static text]";
6732 type_desc
= "Configuration data stored in its own file";
6736 type_desc
= "Password (never stored on disk)";
6739 case PREF_DISSECTOR
:
6740 type_desc
= "A dissector name";
6746 return g_strdup(type_desc
);
6750 prefs_pref_is_default(pref_t
*pref
)
6753 if (!pref
) return false;
6756 if (IS_PREF_OBSOLETE(type
)) {
6759 RESET_PREF_OBSOLETE(type
);
6765 if (pref
->default_val
.uint
== *pref
->varp
.uint
)
6770 if (pref
->default_val
.boolval
== *pref
->varp
.boolp
)
6775 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6776 if (pref
->default_val
.enumval
== *pref
->varp
.enump
)
6781 case PREF_SAVE_FILENAME
:
6782 case PREF_OPEN_FILENAME
:
6785 case PREF_DISSECTOR
:
6786 if (!(g_strcmp0(pref
->default_val
.string
, *pref
->varp
.string
)))
6790 case PREF_DECODE_AS_RANGE
:
6793 if ((ranges_are_equal(pref
->default_val
.range
, *pref
->varp
.range
)))
6800 if ((pref
->default_val
.color
.red
== pref
->varp
.colorp
->red
) &&
6801 (pref
->default_val
.color
.green
== pref
->varp
.colorp
->green
) &&
6802 (pref
->default_val
.color
.blue
== pref
->varp
.colorp
->blue
))
6808 return pref
->custom_cbs
.is_default_cb(pref
);
6810 case PREF_STATIC_TEXT
:
6813 /* ws_assert_not_reached(); */
6820 prefs_pref_to_str(pref_t
*pref
, pref_source_t source
) {
6821 const char *pref_text
= "[Unknown]";
6822 void *valp
; /* pointer to preference value */
6823 color_t
*pref_color
;
6824 char *tmp_value
, *ret_value
;
6828 return g_strdup(pref_text
);
6833 valp
= &pref
->default_val
;
6834 /* valp = &boolval, &enumval, etc. are implied by union property */
6835 pref_color
= &pref
->default_val
.color
;
6838 valp
= &pref
->stashed_val
;
6839 /* valp = &boolval, &enumval, etc. are implied by union property */
6840 pref_color
= &pref
->stashed_val
.color
;
6843 valp
= pref
->varp
.uint
;
6844 /* valp = boolval, enumval, etc. are implied by union property */
6845 pref_color
= pref
->varp
.colorp
;
6848 return g_strdup(pref_text
);
6852 if (IS_PREF_OBSOLETE(type
)) {
6853 pref_text
= "[Obsolete]";
6855 RESET_PREF_OBSOLETE(type
);
6862 unsigned pref_uint
= *(unsigned *) valp
;
6863 switch (pref
->info
.base
) {
6866 return ws_strdup_printf("%u", pref_uint
);
6869 return ws_strdup_printf("%#o", pref_uint
);
6872 return ws_strdup_printf("%#x", pref_uint
);
6878 return g_strdup((*(bool *) valp
) ? "TRUE" : "FALSE");
6881 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6883 int pref_enumval
= *(int *) valp
;
6884 const enum_val_t
*enum_valp
= pref
->info
.enum_info
.enumvals
;
6886 * TODO - We write the "description" value, because the "name" values
6887 * weren't validated to be command line friendly until 5.0, and a few
6888 * of them had to be changed. This allows older versions of Wireshark
6889 * to read preferences that they supported, as we supported either
6890 * the short name or the description when reading the preference files
6891 * or an "-o" option. Once 5.0 is the oldest supported version, switch
6892 * to writing the name below.
6894 while (enum_valp
->name
!= NULL
) {
6895 if (enum_valp
->value
== pref_enumval
)
6896 return g_strdup(enum_valp
->description
);
6903 case PREF_SAVE_FILENAME
:
6904 case PREF_OPEN_FILENAME
:
6907 case PREF_DISSECTOR
:
6908 return g_strdup(*(const char **) valp
);
6910 case PREF_DECODE_AS_RANGE
:
6912 /* Convert wmem to g_alloc memory */
6913 tmp_value
= range_convert_range(NULL
, *(range_t
**) valp
);
6914 ret_value
= g_strdup(tmp_value
);
6915 wmem_free(NULL
, tmp_value
);
6919 return ws_strdup_printf("%02x%02x%02x",
6920 (pref_color
->red
* 255 / 65535),
6921 (pref_color
->green
* 255 / 65535),
6922 (pref_color
->blue
* 255 / 65535));
6925 if (pref
->custom_cbs
.to_str_cb
)
6926 return pref
->custom_cbs
.to_str_cb(pref
, source
== pref_default
? true : false);
6927 pref_text
= "[Custom]";
6930 case PREF_STATIC_TEXT
:
6931 pref_text
= "[Static text]";
6936 uat_t
*uat
= pref
->varp
.uat
;
6937 if (uat
&& uat
->filename
)
6938 return ws_strdup_printf("[Managed in the file \"%s\"]", uat
->filename
);
6940 pref_text
= "[Managed in an unknown file]";
6947 return g_strdup(pref_text
);
6951 * Write out a single dissector preference.
6954 write_pref(void *data
, void *user_data
)
6956 pref_t
*pref
= (pref_t
*)data
;
6957 write_pref_arg_t
*arg
= (write_pref_arg_t
*)user_data
;
6964 if (IS_PREF_OBSOLETE(type
)) {
6966 * This preference is no longer supported; it's not a
6967 * real preference, so we don't write it out (i.e., we
6968 * treat it as if it weren't found in the list of
6969 * preferences, and we weren't called in the first place).
6973 RESET_PREF_OBSOLETE(type
);
6978 case PREF_STATIC_TEXT
:
6980 /* Nothing to do; don't bother printing the description */
6982 case PREF_DECODE_AS_RANGE
:
6983 /* Data is saved through Decode As mechanism and not part of preferences file */
6985 case PREF_PROTO_TCP_SNDAMB_ENUM
:
6986 /* Not written to the preference file because the override is only
6987 * for the lifetime of the capture file and there is no single
6995 if (pref
->type
!= PREF_CUSTOM
|| pref
->custom_cbs
.type_name_cb() != NULL
) {
6997 * The prefix will either be the module name or the parent
6998 * name if it's a subtree
7000 const char *name_prefix
= (arg
->module
->name
!= NULL
) ? arg
->module
->name
: arg
->module
->parent
->name
;
7001 char *type_desc
, *pref_text
;
7002 const char * def_prefix
= prefs_pref_is_default(pref
) ? "#" : "";
7004 if (pref
->type
== PREF_CUSTOM
)
7005 fprintf(arg
->pf
, "\n# %s", pref
->custom_cbs
.type_name_cb());
7006 fprintf(arg
->pf
, "\n");
7007 if (pref
->description
&&
7008 (g_ascii_strncasecmp(pref
->description
,"", 2) != 0)) {
7009 if (pref
->type
!= PREF_CUSTOM
) {
7010 /* We get duplicate lines otherwise. */
7012 desc_lines
= g_strsplit(pref
->description
, "\n", 0);
7013 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7014 fprintf(arg
->pf
, "# %s\n", desc_lines
[i
]);
7016 g_strfreev(desc_lines
);
7019 fprintf(arg
->pf
, "# No description\n");
7022 type_desc
= prefs_pref_type_description(pref
);
7023 desc_lines
= g_strsplit(type_desc
, "\n", 0);
7024 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7025 fprintf(arg
->pf
, "# %s\n", desc_lines
[i
]);
7027 g_strfreev(desc_lines
);
7030 pref_text
= prefs_pref_to_str(pref
, pref_current
);
7031 fprintf(arg
->pf
, "%s%s.%s: ", def_prefix
, name_prefix
, pref
->name
);
7032 if (pref
->type
!= PREF_PASSWORD
)
7034 desc_lines
= g_strsplit(pref_text
, "\n", 0);
7035 for (i
= 0; desc_lines
[i
] != NULL
; ++i
) {
7036 fprintf(arg
->pf
, "%s%s\n", i
== 0 ? "" : def_prefix
, desc_lines
[i
]);
7039 fprintf(arg
->pf
, "\n");
7040 g_strfreev(desc_lines
);
7042 /* We never store password value */
7043 fprintf(arg
->pf
, "\n");
7051 count_non_uat_pref(void *data
, void *user_data
)
7053 pref_t
*pref
= (pref_t
*)data
;
7054 int *arg
= (int *)user_data
;
7060 case PREF_DECODE_AS_RANGE
:
7061 case PREF_PROTO_TCP_SNDAMB_ENUM
:
7062 //These types are not written in preference file
7070 static int num_non_uat_prefs(module_t
*module
)
7074 g_list_foreach(module
->prefs
, count_non_uat_pref
, &num
);
7080 * Write out all preferences for a module.
7083 write_module_prefs(module_t
*module
, void *user_data
)
7085 write_gui_pref_arg_t
*gui_pref_arg
= (write_gui_pref_arg_t
*)user_data
;
7086 write_pref_arg_t arg
;
7088 /* The GUI module needs to be explicitly called out so it
7089 can be written out of order */
7090 if ((module
== gui_module
) && (gui_pref_arg
->is_gui_module
!= true))
7093 /* Write a header for the main modules and GUI sub-modules */
7094 if (((module
->parent
== NULL
) || (module
->parent
== gui_module
)) &&
7095 ((prefs_module_has_submodules(module
)) ||
7096 (num_non_uat_prefs(module
) > 0) ||
7097 (module
->name
== NULL
))) {
7098 if ((module
->name
== NULL
) && (module
->parent
!= NULL
)) {
7099 fprintf(gui_pref_arg
->pf
, "\n####### %s: %s ########\n", module
->parent
->title
, module
->title
);
7101 fprintf(gui_pref_arg
->pf
, "\n####### %s ########\n", module
->title
);
7105 arg
.module
= module
;
7106 arg
.pf
= gui_pref_arg
->pf
;
7107 g_list_foreach(arg
.module
->prefs
, write_pref
, &arg
);
7109 if (prefs_module_has_submodules(module
))
7110 return prefs_modules_foreach_submodules(module
, write_module_prefs
, user_data
);
7117 write_registry(void)
7124 ret
= RegCreateKeyExA(HKEY_CURRENT_USER
, REG_HKCU_WIRESHARK_KEY
, 0, NULL
,
7125 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
,
7127 if (ret
!= ERROR_SUCCESS
) {
7128 ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY
": 0x%lx", ret
);
7132 data
= ws_log_console_open
;
7133 data_size
= sizeof(DWORD
);
7134 ret
= RegSetValueExA(hTestKey
, LOG_HKCU_CONSOLE_OPEN
, 0, REG_DWORD
, (const BYTE
*)&data
, data_size
);
7135 if (ret
== ERROR_SUCCESS
) {
7136 ws_noisy("Wrote "LOG_HKCU_CONSOLE_OPEN
" to Windows registry: 0x%lu", data
);
7139 ws_noisy("Error writing registry key "LOG_HKCU_CONSOLE_OPEN
": 0x%lx", ret
);
7142 RegCloseKey(hTestKey
);
7146 /* Write out "prefs" to the user's preferences file, and return 0.
7148 If the preferences file path is NULL, write to stdout.
7150 If we got an error, stuff a pointer to the path of the preferences file
7151 into "*pf_path_return", and return the errno. */
7153 write_prefs(char **pf_path_return
)
7157 write_gui_pref_arg_t write_gui_pref_info
;
7159 /* Needed for "-G defaultprefs" */
7167 * - Split output lines longer than MAX_VAL_LEN
7168 * - Create a function for the preference directory check/creation
7169 * so that duplication can be avoided with filter.c
7172 if (pf_path_return
!= NULL
) {
7173 pf_path
= get_persconffile_path(PF_NAME
, true);
7174 if ((pf
= ws_fopen(pf_path
, "w")) == NULL
) {
7175 *pf_path_return
= pf_path
;
7184 * If the preferences file is being written, be sure to write UAT files
7185 * first that were migrated from the preferences file.
7187 if (pf_path_return
!= NULL
) {
7188 if (prefs
.filter_expressions_old
) {
7190 prefs
.filter_expressions_old
= false;
7191 if (!uat_save(uat_get_table_by_name("Display expressions"), &err
)) {
7192 ws_warning("Unable to save Display expressions: %s", err
);
7197 module_t
*extcap_module
= prefs_find_module("extcap");
7198 if (extcap_module
&& !prefs
.capture_no_extcap
) {
7199 char *ext_path
= get_persconffile_path("extcap.cfg", true);
7201 if ((extf
= ws_fopen(ext_path
, "w")) == NULL
) {
7202 if (errno
!= EISDIR
) {
7203 ws_warning("Unable to save extcap preferences \"%s\": %s",
7204 ext_path
, g_strerror(errno
));
7210 fputs("# Extcap configuration file for Wireshark " VERSION
".\n"
7212 "# This file is regenerated each time preferences are saved within\n"
7213 "# Wireshark. Making manual changes should be safe, however.\n"
7214 "# Preferences that have been commented out have not been\n"
7215 "# changed from their default value.\n", extf
);
7217 write_gui_pref_info
.pf
= extf
;
7218 write_gui_pref_info
.is_gui_module
= false;
7220 write_module_prefs(extcap_module
, &write_gui_pref_info
);
7227 fputs("# Configuration file for Wireshark " VERSION
".\n"
7229 "# This file is regenerated each time preferences are saved within\n"
7230 "# Wireshark. Making manual changes should be safe, however.\n"
7231 "# Preferences that have been commented out have not been\n"
7232 "# changed from their default value.\n", pf
);
7235 * For "backwards compatibility" the GUI module is written first as it's
7236 * at the top of the file. This is followed by all modules that can't
7237 * fit into the preferences read/write API. Finally the remaining modules
7238 * are written in alphabetical order (including of course the protocol preferences)
7240 write_gui_pref_info
.pf
= pf
;
7241 write_gui_pref_info
.is_gui_module
= true;
7243 write_module_prefs(gui_module
, &write_gui_pref_info
);
7245 write_gui_pref_info
.is_gui_module
= false;
7246 prefs_modules_foreach_submodules(NULL
, write_module_prefs
, &write_gui_pref_info
);
7250 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
7251 an error indication, or maybe write to a new preferences file and
7252 rename that file on top of the old one only if there are not I/O
7257 /** The col_list is only partly managed by the custom preference API
7258 * because its data is shared between multiple preferences, so
7262 free_col_info(GList
*list
)
7265 GList
*list_head
= list
;
7267 while (list
!= NULL
) {
7268 cfmt
= (fmt_data
*)list
->data
;
7270 g_free(cfmt
->title
);
7271 g_free(cfmt
->custom_fields
);
7273 list
= g_list_next(list
);
7275 g_list_free(list_head
);
7284 * indent-tabs-mode: nil
7287 * ex: set shiftwidth=4 tabstop=8 expandtab:
7288 * :indentSize=4:tabSize=8:noTabs=true: