2 * Routines for handling preferences
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <wsutil/filesystem.h>
33 #include <epan/address.h>
34 #include <epan/addr_resolv.h>
35 #include <epan/oids.h>
37 #include <epan/geoip_db.h>
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
41 #include <epan/proto.h>
42 #include <epan/strutil.h>
43 #include <epan/column.h>
45 #include <wsutil/file_util.h>
47 #include <epan/prefs-int.h>
48 #include <epan/uat-int.h>
50 #include "epan/filter_expressions.h"
52 #include "epan/wmem/wmem.h"
53 #include <epan/stats_tree.h>
55 /* Internal functions */
56 static module_t *find_subtree(module_t *parent, const char *tilte);
57 static module_t *prefs_register_module_or_subtree(module_t *parent,
58 const char *name, const char *title, const char *description, gboolean is_subtree,
59 void (*apply_cb)(void), gboolean use_gui);
60 static void prefs_register_modules(void);
61 static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
62 static void free_col_info(GList *);
63 static void pre_init_prefs(void);
64 static gboolean prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt);
65 static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
66 static void try_convert_to_custom_column(gpointer *el_data);
68 #define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
69 #define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
70 #define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
72 #define PF_NAME "preferences"
73 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
75 static gboolean prefs_initialized = FALSE;
76 static gchar *gpf_path = NULL;
77 static gchar *cols_hidden_list = NULL;
80 * XXX - variables to allow us to attempt to interpret the first
81 * "mgcp.{tcp,udp}.port" in a preferences file as
82 * "mgcp.{tcp,udp}.gateway_port" and the second as
83 * "mgcp.{tcp,udp}.callagent_port".
85 static int mgcp_tcp_port_count;
86 static int mgcp_udp_port_count;
90 static const enum_val_t gui_ptree_line_style[] = {
92 {"SOLID", "SOLID", 1},
93 {"DOTTED", "DOTTED", 2},
94 {"TABBED", "TABBED", 3},
98 static const enum_val_t gui_ptree_expander_style[] = {
100 {"SQUARE", "SQUARE", 1},
101 {"TRIANGLE", "TRIANGLE", 2},
102 {"CIRCULAR", "CIRCULAR", 3},
106 static const enum_val_t gui_hex_dump_highlight_style[] = {
108 {"INVERSE", "INVERSE", 1},
112 static const enum_val_t gui_console_open_type[] = {
113 {"NEVER", "NEVER", console_open_never},
114 {"AUTOMATIC", "AUTOMATIC", console_open_auto},
115 {"ALWAYS", "ALWAYS", console_open_always},
119 static const enum_val_t gui_version_placement_type[] = {
120 {"WELCOME", "WELCOME", version_welcome_only},
121 {"TITLE", "TITLE", version_title_only},
122 {"BOTH", "BOTH", version_both},
123 {"NEITHER", "NEITHER", version_neither},
127 static const enum_val_t gui_fileopen_style[] = {
128 {"LAST_OPENED", "LAST_OPENED", 0},
129 {"SPECIFIED", "SPECIFIED", 1},
133 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
134 * as this may not work on other guis, we use only "both" in general here */
135 static const enum_val_t gui_toolbar_style[] = {
136 {"ICONS", "ICONS", 0},
142 static const enum_val_t gui_layout_content[] = {
144 {"PLIST", "PLIST", 1},
145 {"PDETAILS", "PDETAILS", 2},
146 {"PBYTES", "PBYTES", 3},
150 static const enum_val_t gui_update_channel[] = {
151 {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT},
152 {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE},
156 #if defined(HAVE_PCAP_CREATE)
157 /* Can set monitor mode and buffer size. */
158 static gint num_capture_cols = 7;
159 static const gchar *capture_cols[7] = {
168 #define CAPTURE_COL_TYPE_DESCRIPTION \
169 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
170 #elif defined(CAN_SET_CAPTURE_BUFFER_SIZE)
171 /* Can set buffer size but not monitor mode. */
172 static gint num_capture_cols = 6;
173 static const gchar *capture_cols[6] = {
181 #define CAPTURE_COL_TYPE_DESCRIPTION \
182 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, BUFFER, FILTER\n"
184 /* Can neither set buffer size nor monitor mode. */
185 static gint num_capture_cols = 5;
186 static const gchar *capture_cols[5] = {
193 #define CAPTURE_COL_TYPE_DESCRIPTION \
194 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, FILTER\n"
197 static const enum_val_t gui_packet_list_elide_mode[] = {
198 {"LEFT", "LEFT", ELIDE_LEFT},
199 {"RIGHT", "RIGHT", ELIDE_RIGHT},
200 {"MIDDLE", "MIDDLE", ELIDE_MIDDLE},
201 {"NONE", "NONE", ELIDE_NONE},
206 * List of all modules with preference settings.
208 static wmem_tree_t *prefs_modules = NULL;
211 * List of all modules that should show up at the top level of the
212 * tree in the preference dialog box.
214 static wmem_tree_t *prefs_top_level_modules = NULL;
216 /** Sets up memory used by proto routines. Called at program startup */
220 memset(&prefs, 0, sizeof(prefs));
221 prefs_modules = wmem_tree_new(wmem_epan_scope());
222 prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
226 * Free the strings for a string-like preference.
229 free_string_like_preference(pref_t *pref)
231 g_free(*pref->varp.string);
232 *pref->varp.string = NULL;
233 g_free(pref->default_val.string);
234 pref->default_val.string = NULL;
238 free_pref(gpointer data, gpointer user_data _U_)
240 pref_t *pref = (pref_t *)data;
241 int type = pref->type;
243 /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
244 RESET_PREF_OBSOLETE(type);
250 case PREF_STATIC_TEXT:
257 g_free(*pref->varp.string);
258 *pref->varp.string = NULL;
259 g_free(pref->default_val.string);
260 pref->default_val.string = NULL;
263 g_free(*pref->varp.range);
264 *pref->varp.range = NULL;
265 g_free(pref->default_val.range);
266 pref->default_val.range = NULL;
269 if (strcmp(pref->name, "columns") == 0)
270 pref->stashed_val.boolval = TRUE;
271 pref->custom_cbs.free_cb(pref);
279 free_module_prefs(module_t *module, gpointer data _U_)
282 g_list_foreach(module->prefs, free_pref, NULL);
283 g_list_free(module->prefs);
285 module->prefs = NULL;
286 module->numprefs = 0;
287 if (module->submodules) {
288 prefs_modules_foreach_submodules(module, free_module_prefs, NULL);
290 /* We don't free the actual module: its submodules pointer points to
291 a wmem_tree and the module itself is stored in a wmem_tree
297 /** Frees memory used by proto routines. Called at program shutdown */
301 /* This isn't strictly necessary since we're exiting anyway, but let's
302 * do what clean up we can.
304 prefs_modules_foreach(free_module_prefs, NULL);
308 * Register a module that will have preferences.
309 * Specify the module under which to register it or NULL to register it
310 * at the top level, the name used for the module in the preferences file,
311 * the title used in the tab for it in a preferences dialog box, and a
312 * routine to call back when we apply the preferences.
315 prefs_register_module(module_t *parent, const char *name, const char *title,
316 const char *description, void (*apply_cb)(void),
317 const gboolean use_gui)
319 return prefs_register_module_or_subtree(parent, name, title, description,
320 FALSE, apply_cb, use_gui);
324 prefs_deregister_module(module_t *parent, const char *name, const char *title)
326 /* Remove this module from the list of all modules */
327 module_t *module = (module_t *)wmem_tree_remove_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
332 if (parent == NULL) {
333 /* Remove from top */
334 wmem_tree_remove_string(prefs_top_level_modules, title, WMEM_TREE_STRING_NOCASE);
335 } else if (parent->submodules) {
336 /* Remove from parent */
337 wmem_tree_remove_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE);
340 free_module_prefs(module, NULL);
341 wmem_free(wmem_epan_scope(), module);
345 * Register a subtree that will have modules under it.
346 * Specify the module under which to register it or NULL to register it
347 * at the top level and the title used in the tab for it in a preferences
351 prefs_register_subtree(module_t *parent, const char *title, const char *description,
352 void (*apply_cb)(void))
354 return prefs_register_module_or_subtree(parent, NULL, title, description,
356 parent ? parent->use_gui : FALSE);
360 prefs_register_module_or_subtree(module_t *parent, const char *name,
361 const char *title, const char *description,
362 gboolean is_subtree, void (*apply_cb)(void),
369 /* this module may have been created as a subtree item previously */
370 if ((module = find_subtree(parent, title))) {
371 /* the module is currently a subtree */
373 module->apply_cb = apply_cb;
374 module->description = description;
376 if (prefs_find_module(name) == NULL) {
377 wmem_tree_insert_string(prefs_modules, name, module,
378 WMEM_TREE_STRING_NOCASE);
384 module = wmem_new(wmem_epan_scope(), module_t);
386 module->title = title;
387 module->description = description;
388 module->apply_cb = apply_cb;
389 module->prefs = NULL; /* no preferences, to start */
390 module->parent = parent;
391 module->submodules = NULL; /* no submodules, to start */
392 module->numprefs = 0;
393 module->prefs_changed = FALSE;
394 module->obsolete = FALSE;
395 module->use_gui = use_gui;
398 * Do we have a module name?
403 * Make sure that only lower-case ASCII letters, numbers,
404 * underscores, hyphens, and dots appear in the name.
406 * Crash if there is, as that's an error in the code;
407 * you can make the title a nice string with capitalization,
408 * white space, punctuation, etc., but the name can be used
409 * on the command line, and shouldn't require quoting,
412 for (p = name; (c = *p) != '\0'; p++)
413 g_assert(g_ascii_islower(c) || g_ascii_isdigit(c) || c == '_' ||
414 c == '-' || c == '.');
417 * Make sure there's not already a module with that
418 * name. Crash if there is, as that's an error in the
419 * code, and the code has to be fixed not to register
420 * more than one module with the same name.
422 * We search the list of all modules; the subtree stuff
423 * doesn't require preferences in subtrees to have names
424 * that reflect the subtree they're in (that would require
425 * protocol preferences to have a bogus "protocol.", or
426 * something such as that, to be added to all their names).
428 g_assert(prefs_find_module(name) == NULL);
431 * Insert this module in the list of all modules.
433 wmem_tree_insert_string(prefs_modules, name, module, WMEM_TREE_STRING_NOCASE);
436 * This has no name, just a title; check to make sure it's a
437 * subtree, and crash if it's not.
439 g_assert(is_subtree);
443 * Insert this module into the appropriate place in the display
446 if (parent == NULL) {
448 * It goes at the top.
450 wmem_tree_insert_string(prefs_top_level_modules, title, module, WMEM_TREE_STRING_NOCASE);
453 * It goes into the list for this module.
456 if (parent->submodules == NULL)
457 parent->submodules = wmem_tree_new(wmem_epan_scope());
459 wmem_tree_insert_string(parent->submodules, title, module, WMEM_TREE_STRING_NOCASE);
466 * Register that a protocol has preferences.
468 module_t *protocols_module = NULL;
471 prefs_register_protocol(int id, void (*apply_cb)(void))
473 protocol_t *protocol;
476 * Have we yet created the "Protocols" subtree?
478 if (protocols_module == NULL) {
480 * No. Register Protocols subtree as well as any preferences
481 * for non-dissector modules.
484 prefs_register_modules();
486 protocol = find_protocol_by_id(id);
487 return prefs_register_module(protocols_module,
488 proto_get_protocol_filter_name(id),
489 proto_get_protocol_short_name(protocol),
490 proto_get_protocol_name(id), apply_cb, TRUE);
494 prefs_deregister_protocol (int id)
496 protocol_t *protocol = find_protocol_by_id(id);
497 prefs_deregister_module (protocols_module,
498 proto_get_protocol_filter_name(id),
499 proto_get_protocol_short_name(protocol));
503 prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
505 protocol_t *protocol;
506 module_t *subtree_module;
507 module_t *new_module;
508 char *sep = NULL, *ptr = NULL, *orig = NULL;
511 * Have we yet created the "Protocols" subtree?
512 * XXX - can we just do this by registering Protocols/{subtree}?
515 if (protocols_module == NULL) {
517 * No. Register Protocols subtree as well as any preferences
518 * for non-dissector modules.
521 prefs_register_modules();
524 subtree_module = protocols_module;
527 /* take a copy of the buffer, orig keeps a base pointer while ptr
528 * walks through the string */
529 orig = ptr = g_strdup(subtree);
531 while (ptr && *ptr) {
533 if ((sep = strchr(ptr, '/')))
536 if (!(new_module = find_subtree(subtree_module, ptr))) {
538 * There's no such module; create it, with the description
539 * being the name (if it's later registered explicitly
540 * with a description, that will override it).
542 ptr = wmem_strdup(wmem_epan_scope(), ptr),
543 new_module = prefs_register_subtree(subtree_module, ptr, ptr, NULL);
546 subtree_module = new_module;
554 protocol = find_protocol_by_id(id);
555 return prefs_register_module(subtree_module,
556 proto_get_protocol_filter_name(id),
557 proto_get_protocol_short_name(protocol),
558 proto_get_protocol_name(id), apply_cb, TRUE);
563 * Register that a protocol used to have preferences but no longer does,
564 * by creating an "obsolete" module for it.
567 prefs_register_protocol_obsolete(int id)
570 protocol_t *protocol;
573 * Have we yet created the "Protocols" subtree?
575 if (protocols_module == NULL) {
577 * No. Register Protocols subtree as well as any preferences
578 * for non-dissector modules.
581 prefs_register_modules();
583 protocol = find_protocol_by_id(id);
584 module = prefs_register_module(protocols_module,
585 proto_get_protocol_filter_name(id),
586 proto_get_protocol_short_name(protocol),
587 proto_get_protocol_name(id), NULL, TRUE);
588 module->obsolete = TRUE;
593 * Register that a statistical tap has preferences.
595 * "name" is a name for the tap to use on the command line with "-o"
596 * and in preference files.
598 * "title" is a short human-readable name for the tap.
600 * "description" is a longer human-readable description of the tap.
602 module_t *stats_module = NULL;
605 prefs_register_stat(const char *name, const char *title,
606 const char *description, void (*apply_cb)(void))
609 * Have we yet created the "Statistics" subtree?
611 if (stats_module == NULL) {
613 * No. Register Statistics subtree as well as any preferences
614 * for non-dissector modules.
617 prefs_register_modules();
620 return prefs_register_module(stats_module, name, title, description,
625 prefs_find_module(const char *name)
627 return (module_t *)wmem_tree_lookup_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
631 find_subtree(module_t *parent, const char *name)
633 return (module_t *)wmem_tree_lookup_string(parent ? parent->submodules : prefs_top_level_modules, name, WMEM_TREE_STRING_NOCASE);
637 * Call a callback function, with a specified argument, for each module
638 * in a list of modules. If the list is NULL, searches the top-level
639 * list in the display tree of modules. If any callback returns a
640 * non-zero value, we stop and return that value, otherwise we
643 * Ignores "obsolete" modules; their sole purpose is to allow old
644 * preferences for dissectors that no longer have preferences to be
645 * silently ignored in preference files. Does not ignore subtrees,
646 * as this can be used when walking the display tree of modules.
656 call_foreach_cb(const void *key _U_, void *value, void *data)
658 module_t *module = (module_t*)value;
659 call_foreach_t *call_data = (call_foreach_t*)data;
661 if (!module->obsolete)
662 call_data->ret = (*call_data->callback)(module, call_data->user_data);
664 return (call_data->ret != 0);
668 prefs_module_list_foreach(wmem_tree_t *module_list, module_cb callback,
671 call_foreach_t call_data;
673 if (module_list == NULL)
674 module_list = prefs_top_level_modules;
676 call_data.callback = callback;
677 call_data.user_data = user_data;
679 wmem_tree_foreach(module_list, call_foreach_cb, &call_data);
680 return call_data.ret;
684 * Returns TRUE if module has any submodules
687 prefs_module_has_submodules(module_t *module)
689 if (module->submodules == NULL) {
693 if (wmem_tree_is_empty(module->submodules)) {
701 * Call a callback function, with a specified argument, for each module
702 * in the list of all modules. (This list does not include subtrees.)
704 * Ignores "obsolete" modules; their sole purpose is to allow old
705 * preferences for dissectors that no longer have preferences to be
706 * silently ignored in preference files.
709 prefs_modules_foreach(module_cb callback, gpointer user_data)
711 return prefs_module_list_foreach(prefs_modules, callback, user_data);
715 * Call a callback function, with a specified argument, for each submodule
716 * of specified modules. If the module is NULL, goes through the top-level
717 * list in the display tree of modules.
719 * Ignores "obsolete" modules; their sole purpose is to allow old
720 * preferences for dissectors that no longer have preferences to be
721 * silently ignored in preference files. Does not ignore subtrees,
722 * as this can be used when walking the display tree of modules.
725 prefs_modules_foreach_submodules(module_t *module, module_cb callback,
728 return prefs_module_list_foreach((module)?module->submodules:prefs_top_level_modules, callback, user_data);
732 call_apply_cb(const void *key _U_, void *value, void *data _U_)
734 module_t *module = (module_t *)value;
736 if (module->obsolete)
738 if (module->prefs_changed) {
739 if (module->apply_cb != NULL)
740 (*module->apply_cb)();
741 module->prefs_changed = FALSE;
743 if (module->submodules)
744 wmem_tree_foreach(module->submodules, call_apply_cb, NULL);
749 * Call the "apply" callback function for each module if any of its
750 * preferences have changed, and then clear the flag saying its
751 * preferences have changed, as the module has been notified of that
755 prefs_apply_all(void)
757 wmem_tree_foreach(prefs_modules, call_apply_cb, NULL);
761 * Call the "apply" callback function for a specific module if any of
762 * its preferences have changed, and then clear the flag saying its
763 * preferences have changed, as the module has been notified of that
767 prefs_apply(module_t *module)
769 if (module && module->prefs_changed)
770 call_apply_cb(NULL, module, NULL);
774 * Register a preference in a module's list of preferences.
775 * If it has a title, give it an ordinal number; otherwise, it's a
776 * preference that won't show up in the UI, so it shouldn't get an
777 * ordinal number (the ordinal should be the ordinal in the set of
778 * *visible* preferences).
781 register_preference(module_t *module, const char *name, const char *title,
782 const char *description, int type)
787 preference = g_new(pref_t,1);
788 preference->name = name;
789 preference->title = title;
790 preference->description = description;
791 preference->type = type;
792 preference->gui = GUI_ALL; /* default */
794 preference->ordinal = module->numprefs;
796 preference->ordinal = -1; /* no ordinal for you */
799 * Make sure that only lower-case ASCII letters, numbers,
800 * underscores, and dots appear in the preference name.
802 * Crash if there is, as that's an error in the code;
803 * you can make the title and description nice strings
804 * with capitalization, white space, punctuation, etc.,
805 * but the name can be used on the command line,
806 * and shouldn't require quoting, shifting, etc.
808 for (p = name; *p != '\0'; p++)
809 if (!(g_ascii_islower(*p) || g_ascii_isdigit(*p) || *p == '_' || *p == '.'))
810 g_error("Preference %s.%s contains invalid characters", module->name, name);
813 * Make sure there's not already a preference with that
814 * name. Crash if there is, as that's an error in the
815 * code, and the code has to be fixed not to register
816 * more than one preference with the same name.
818 if (prefs_find_preference(module, name) != NULL)
819 g_error("Preference %s has already been registered", name);
821 if ((!IS_PREF_OBSOLETE(type)) &&
822 /* Don't compare if it's a subtree */
823 (module->name != NULL)) {
825 * Make sure the preference name doesn't begin with the
826 * module name, as that's redundant and Just Silly.
828 if (!((strncmp(name, module->name, strlen(module->name)) != 0) ||
829 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_'))))
830 g_error("Preference %s begins with the module name", name);
834 * There isn't already one with that name, so add the
837 module->prefs = g_list_append(module->prefs, preference);
845 * Find a preference in a module's list of preferences, given the module
846 * and the preference's name.
855 preference_match(gconstpointer a, gconstpointer b)
857 const pref_t *pref = (const pref_t *)a;
858 const char *name = (const char *)b;
860 return strcmp(name, pref->name);
864 module_find_pref_cb(const void *key _U_, void *value, void *data)
866 find_pref_arg_t* arg = (find_pref_arg_t*)data;
868 module_t *module = (module_t *)value;
873 list_entry = g_list_find_custom(module->prefs, arg->name,
876 if (list_entry == NULL)
879 arg->list_entry = list_entry;
880 arg->submodule = module;
884 /* Tries to find a preference, setting containing_module to the (sub)module
885 * holding this preference. */
886 static struct preference *
887 prefs_find_preference_with_submodule(module_t *module, const char *name,
888 module_t **containing_module)
894 return NULL; /* invalid parameters */
896 list_entry = g_list_find_custom(module->prefs, name,
898 arg.submodule = NULL;
900 if (list_entry == NULL)
902 arg.list_entry = NULL;
903 if (module->submodules != NULL)
906 wmem_tree_foreach(module->submodules, module_find_pref_cb, &arg);
909 list_entry = arg.list_entry;
912 if (list_entry == NULL)
913 return NULL; /* no such preference */
915 if (containing_module)
916 *containing_module = arg.submodule ? arg.submodule : module;
918 return (struct preference *) list_entry->data;
922 prefs_find_preference(module_t *module, const char *name)
924 return prefs_find_preference_with_submodule(module, name, NULL);
928 * Returns TRUE if the given protocol has registered preferences
931 prefs_is_registered_protocol(const char *name)
933 module_t *m = prefs_find_module(name);
935 return (m != NULL && !m->obsolete);
939 * Returns the module title of a registered protocol
942 prefs_get_title_by_name(const char *name)
944 module_t *m = prefs_find_module(name);
946 return (m != NULL && !m->obsolete) ? m->title : NULL;
950 * Register a preference with an unsigned integral value.
953 prefs_register_uint_preference(module_t *module, const char *name,
954 const char *title, const char *description,
955 guint base, guint *var)
959 preference = register_preference(module, name, title, description,
961 preference->varp.uint = var;
962 preference->default_val.uint = *var;
963 g_assert(base > 0 && base != 1 && base < 37);
964 preference->info.base = base;
968 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
973 * Register a "custom" preference with a unsigned integral value.
974 * XXX - This should be temporary until we can find a better way
975 * to do "custom" preferences
978 prefs_register_uint_custom_preference(module_t *module, const char *name,
979 const char *title, const char *description,
980 struct pref_custom_cbs* custom_cbs, guint *var)
984 preference = register_preference(module, name, title, description,
987 preference->custom_cbs = *custom_cbs;
988 preference->varp.uint = var;
989 preference->default_val.uint = *var;
993 * Register a preference with an Boolean value.
996 prefs_register_bool_preference(module_t *module, const char *name,
997 const char *title, const char *description,
1002 preference = register_preference(module, name, title, description,
1004 preference->varp.boolp = var;
1005 preference->default_val.boolval = *var;
1009 * Register a preference with an enumerated value.
1012 prefs_register_enum_preference(module_t *module, const char *name,
1013 const char *title, const char *description,
1014 gint *var, const enum_val_t *enumvals,
1015 gboolean radio_buttons)
1019 preference = register_preference(module, name, title, description,
1021 preference->varp.enump = var;
1022 preference->default_val.enumval = *var;
1023 preference->info.enum_info.enumvals = enumvals;
1024 preference->info.enum_info.radio_buttons = radio_buttons;
1028 register_string_like_preference(module_t *module, const char *name,
1029 const char *title, const char *description,
1030 char **var, int type,
1031 struct pref_custom_cbs* custom_cbs,
1037 pref = register_preference(module, name, title, description, type);
1040 * String preference values should be non-null (as you can't
1041 * keep them null after using the preferences GUI, you can at best
1042 * have them be null strings) and freeable (as we free them
1043 * if we change them).
1045 * If the value is a null pointer, make it a copy of a null
1046 * string, otherwise make it a copy of the value.
1050 *var = g_strdup("");
1052 *var = g_strdup(*var);
1057 pref->varp.string = var;
1058 pref->default_val.string = g_strdup(*var);
1059 pref->stashed_val.string = NULL;
1060 if (type == PREF_CUSTOM) {
1061 g_assert(custom_cbs);
1062 pref->custom_cbs = *custom_cbs;
1067 * For use by UI code that sets preferences.
1070 prefs_set_string_like_value(pref_t *pref, const gchar *value, gboolean *changed)
1072 if (*pref->varp.string) {
1073 if (strcmp(*pref->varp.string, value) != 0) {
1075 g_free(*pref->varp.string);
1076 *pref->varp.string = g_strdup(value);
1079 *pref->varp.string = g_strdup(value);
1084 * Reset the value of a string-like preference.
1087 reset_string_like_preference(pref_t *pref)
1089 g_free(*pref->varp.string);
1090 *pref->varp.string = g_strdup(pref->default_val.string);
1094 * Register a preference with a character-string value.
1097 prefs_register_string_preference(module_t *module, const char *name,
1098 const char *title, const char *description,
1102 register_string_like_preference(module, name, title, description,
1103 (char **)var, PREF_STRING, NULL, FALSE);
1108 * Register a preference with a file name (string) value.
1111 prefs_register_filename_preference(module_t *module, const char *name,
1112 const char *title, const char *description,
1116 register_string_like_preference(module, name, title, description,
1117 (char **)var, PREF_FILENAME, NULL, FALSE);
1122 * Register a preference with a directory name (string) value.
1125 prefs_register_directory_preference(module_t *module, const char *name,
1126 const char *title, const char *description,
1130 register_string_like_preference(module, name, title, description,
1131 (char **)var, PREF_DIRNAME, NULL, FALSE);
1136 * Register a preference with a ranged value.
1139 prefs_register_range_preference(module_t *module, const char *name,
1140 const char *title, const char *description,
1141 range_t **var, guint32 max_value)
1145 preference = register_preference(module, name, title, description,
1147 preference->info.max_value = max_value;
1151 * Range preference values should be non-null (as you can't
1152 * keep them null after using the preferences GUI, you can at best
1153 * have them be empty ranges) and freeable (as we free them
1154 * if we change them).
1156 * If the value is a null pointer, make it an empty range.
1159 *var = range_empty();
1160 preference->varp.range = var;
1161 preference->default_val.range = range_copy(*var);
1162 preference->stashed_val.range = NULL;
1166 prefs_set_range_value_work(pref_t *pref, const gchar *value,
1167 gboolean return_range_errors, gboolean *changed)
1171 if (range_convert_str_work(&newrange, value, pref->info.max_value,
1172 return_range_errors) != CVT_NO_ERROR) {
1173 return FALSE; /* number was bad */
1176 if (!ranges_are_equal(*pref->varp.range, newrange)) {
1178 g_free(*pref->varp.range);
1179 *pref->varp.range = newrange;
1187 * For use by UI code that sets preferences.
1190 prefs_set_range_value(pref_t *pref, const gchar *value, gboolean *changed)
1192 return prefs_set_range_value_work(pref, value, TRUE, changed);
1196 * Register a static text 'preference'. It can be used to add explanatory
1197 * text inline with other preferences in the GUI.
1198 * Note: Static preferences are not saved to the preferences file.
1201 prefs_register_static_text_preference(module_t *module, const char *name,
1203 const char *description)
1205 register_preference(module, name, title, description, PREF_STATIC_TEXT);
1209 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1210 * preferences tab of the module.
1213 prefs_register_uat_preference(module_t *module, const char *name,
1214 const char *title, const char *description,
1218 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1220 preference->varp.uat = uat;
1224 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
1225 * preferences tab of the module.
1228 prefs_register_uat_preference_qt(module_t *module, const char *name,
1229 const char *title, const char *description,
1233 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1235 preference->varp.uat = uat;
1237 preference->gui = GUI_QT;
1241 * Register a color preference.
1244 prefs_register_color_preference(module_t *module, const char *name,
1245 const char *title, const char *description,
1248 pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
1250 preference->varp.colorp = color;
1251 preference->default_val.color = *color;
1255 * Register a "custom" preference with a list.
1256 * XXX - This should be temporary until we can find a better way
1257 * to do "custom" preferences
1259 typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
1262 prefs_register_list_custom_preference(module_t *module, const char *name,
1263 const char *title, const char *description,
1264 struct pref_custom_cbs* custom_cbs,
1265 pref_custom_list_init_cb init_cb,
1268 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1270 preference->custom_cbs = *custom_cbs;
1271 init_cb(preference, list);
1275 * Register a custom preference.
1278 prefs_register_custom_preference(module_t *module, const char *name,
1279 const char *title, const char *description,
1280 struct pref_custom_cbs* custom_cbs,
1281 void **custom_data _U_)
1283 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1285 preference->custom_cbs = *custom_cbs;
1286 /* XXX - wait until we can handle void** pointers
1287 preference->custom_cbs.init_cb(preference, custom_data);
1292 * Register a preference that used to be supported but no longer is.
1295 prefs_register_obsolete_preference(module_t *module, const char *name)
1297 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
1301 * Check to see if a preference is obsolete.
1304 prefs_get_preference_obsolete(pref_t *pref)
1307 return (IS_PREF_OBSOLETE(pref->type) ? TRUE : FALSE);
1313 * Make a preference obsolete.
1315 extern prefs_set_pref_e
1316 prefs_set_preference_obsolete(pref_t *pref)
1319 SET_PREF_OBSOLETE(pref->type);
1320 return PREFS_SET_OK;
1322 return PREFS_SET_NO_SUCH_PREF;
1326 /* Return the value assigned to the given uint preference. */
1328 prefs_get_uint_preference(pref_t *pref)
1330 if (pref && pref->type == PREF_UINT)
1331 return *pref->varp.uint;
1337 * Call a callback function, with a specified argument, for each preference
1338 * in a given module.
1340 * If any of the callbacks return a non-zero value, stop and return that
1341 * value, otherwise return 0.
1344 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
1350 for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
1351 pref = (pref_t *)elem->data;
1352 if (IS_PREF_OBSOLETE(pref->type)) {
1354 * This preference is no longer supported; it's
1355 * not a real preference, so we don't call the
1356 * callback for it (i.e., we treat it as if it
1357 * weren't found in the list of preferences,
1358 * and we weren't called in the first place).
1363 ret = (*callback)(pref, user_data);
1370 static const enum_val_t print_format_vals[] = {
1371 { "text", "Plain Text", PR_FMT_TEXT },
1372 { "postscript", "Postscript", PR_FMT_PS },
1376 static const enum_val_t print_dest_vals[] = {
1378 /* "PR_DEST_CMD" means "to printer" on Windows */
1379 { "command", "Printer", PR_DEST_CMD },
1381 { "command", "Command", PR_DEST_CMD },
1383 { "file", "File", PR_DEST_FILE },
1387 static const enum_val_t st_sort_col_vals[] = {
1388 { "name", "Node name (topic/item)", ST_SORT_COL_NAME },
1389 { "count", "Item count", ST_SORT_COL_COUNT },
1390 { "average", "Average value of the node", ST_SORT_COL_AVG },
1391 { "min", "Minimum value of the node", ST_SORT_COL_MIN },
1392 { "max", "Maximum value of the node", ST_SORT_COL_MAX },
1393 { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE },
1398 stats_callback(void)
1400 /* Test for a sane tap update interval */
1401 if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000)
1402 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
1404 #ifdef HAVE_LIBPORTAUDIO
1405 /* Test for a sane max channels entry */
1406 if (prefs.rtp_player_max_visible < 1 || prefs.rtp_player_max_visible > 10)
1407 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
1410 /* burst resolution can't be less than 1 (ms) */
1411 if (prefs.st_burst_resolution < 1) {
1412 prefs.st_burst_resolution = 1;
1414 else if (prefs.st_burst_resolution > ST_MAX_BURSTRES) {
1415 prefs.st_burst_resolution = ST_MAX_BURSTRES;
1417 /* make sure burst window value makes sense */
1418 if (prefs.st_burst_windowlen < prefs.st_burst_resolution) {
1419 prefs.st_burst_windowlen = prefs.st_burst_resolution;
1421 /* round burst window down to multiple of resolution */
1422 prefs.st_burst_windowlen -= prefs.st_burst_windowlen%prefs.st_burst_resolution;
1423 if ((prefs.st_burst_windowlen/prefs.st_burst_resolution) > ST_MAX_BURSTBUCKETS) {
1424 prefs.st_burst_windowlen = prefs.st_burst_resolution*ST_MAX_BURSTBUCKETS;
1431 /* Ensure there is at least one file count */
1432 if (prefs.gui_recent_files_count_max == 0)
1433 prefs.gui_recent_files_count_max = 10;
1435 /* Ensure there is at least one display filter entry */
1436 if (prefs.gui_recent_df_entries_max == 0)
1437 prefs.gui_recent_df_entries_max = 10;
1441 gui_layout_callback(void)
1443 if (prefs.gui_layout_type == layout_unused ||
1444 prefs.gui_layout_type >= layout_type_max) {
1445 /* XXX - report an error? It's not a syntax error - we'd need to
1446 add a way of reporting a *semantic* error. */
1447 prefs.gui_layout_type = layout_type_5;
1451 /******************************************************
1452 * All custom preference function callbacks
1453 ******************************************************/
1454 static void custom_pref_no_cb(pref_t* pref _U_) {}
1458 * Console log level custom preference functions
1461 console_log_level_reset_cb(pref_t* pref)
1463 *pref->varp.uint = pref->default_val.uint;
1466 static prefs_set_pref_e
1467 console_log_level_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1471 uval = (guint)strtoul(value, NULL, 10);
1473 if (*pref->varp.uint != uval) {
1475 *pref->varp.uint = uval;
1478 if (*pref->varp.uint & (G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG)) {
1480 * GLib >= 2.32 drops INFO and DEBUG messages by default. Tell
1481 * it not to do that.
1483 g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
1486 return PREFS_SET_OK;
1489 static const char * console_log_level_type_name_cb(void) {
1493 static char * console_log_level_type_description_cb(void) {
1494 return g_strdup_printf(
1495 "Console log level (for debugging)\n"
1496 "A bitmask of log levels:\n"
1505 static gboolean console_log_level_is_default_cb(pref_t* pref) {
1506 return *pref->varp.uint == pref->default_val.uint;
1509 static char * console_log_level_to_str_cb(pref_t* pref, gboolean default_val) {
1510 return g_strdup_printf("%u", default_val ? pref->default_val.uint : *pref->varp.uint);
1514 * Column preference functions
1516 #define PRS_COL_HIDDEN "column.hidden"
1517 #define PRS_COL_FMT "column.format"
1518 #define PRS_COL_NUM "column.number"
1519 static module_t *gui_column_module = NULL;
1521 static prefs_set_pref_e
1522 column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1526 pref_t *format_pref;
1528 prefs_set_string_like_value(pref, value, changed);
1531 * Set the "visible" flag for the existing columns; we need to
1532 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
1533 * after setting it (which might be the case if, for example, we
1534 * set PRS_COL_HIDDEN on the command line).
1536 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1537 for (clp = *format_pref->varp.list; clp != NULL; clp = clp->next) {
1538 cfmt = (fmt_data *)clp->data;
1539 cfmt->visible = prefs_is_column_visible(*pref->varp.string, cfmt);
1542 return PREFS_SET_OK;
1546 column_hidden_type_name_cb(void)
1548 return "Packet list hidden columns";
1552 column_hidden_type_description_cb(void)
1554 return g_strdup("List all columns to hide in the packet list.");
1558 column_hidden_to_str_cb(pref_t* pref, gboolean default_val)
1560 GString *cols_hidden = g_string_new ("");
1563 pref_t *format_pref;
1566 return g_strdup(pref->default_val.string);
1568 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1569 clp = (format_pref) ? *format_pref->varp.list : NULL;
1572 cfmt = (fmt_data *) clp->data;
1573 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
1574 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1575 col_format_to_string(cfmt->fmt),
1576 cfmt->custom_fields,
1577 cfmt->custom_occurrence,
1578 cfmt->resolved ? 'R' : 'U');
1580 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1582 if (!cfmt->visible) {
1583 if (cols_hidden->len)
1584 g_string_append (cols_hidden, ",");
1585 g_string_append (cols_hidden, prefs_fmt);
1591 return g_string_free (cols_hidden, FALSE);
1595 column_hidden_is_default_cb(pref_t* pref)
1597 char *cur_hidden_str = column_hidden_to_str_cb(pref, FALSE);
1598 gboolean is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
1600 g_free(cur_hidden_str);
1605 /* Number of columns "preference". This is only used internally and is not written to the
1609 column_num_reset_cb(pref_t* pref)
1611 *pref->varp.uint = pref->default_val.uint;
1614 static prefs_set_pref_e
1615 column_num_set_cb(pref_t* pref _U_, const gchar* value _U_, gboolean* changed _U_)
1617 /* Don't write this to the preferences file */
1618 return PREFS_SET_OK;
1622 column_num_type_name_cb(void)
1628 column_num_type_description_cb(void)
1630 return g_strdup("");
1634 column_num_is_default_cb(pref_t* pref _U_)
1640 column_num_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
1642 return g_strdup("");
1646 * Column format custom preference functions
1649 column_format_init_cb(pref_t* pref, GList** value)
1651 fmt_data *src_cfmt, *dest_cfmt;
1654 pref->varp.list = value;
1656 pref->default_val.list = NULL;
1657 for (entry = *pref->varp.list; entry != NULL; entry = g_list_next(entry)) {
1658 src_cfmt = (fmt_data *)entry->data;
1659 dest_cfmt = g_new(fmt_data,1);
1660 dest_cfmt->title = g_strdup(src_cfmt->title);
1661 dest_cfmt->fmt = src_cfmt->fmt;
1662 if (src_cfmt->custom_fields) {
1663 dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
1664 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1666 dest_cfmt->custom_fields = NULL;
1667 dest_cfmt->custom_occurrence = 0;
1669 dest_cfmt->visible = src_cfmt->visible;
1670 dest_cfmt->resolved = src_cfmt->resolved;
1671 pref->default_val.list = g_list_append(pref->default_val.list, dest_cfmt);
1676 column_format_free_cb(pref_t* pref)
1678 free_col_info(*pref->varp.list);
1679 free_col_info(pref->default_val.list);
1683 column_format_reset_cb(pref_t* pref)
1685 fmt_data *src_cfmt, *dest_cfmt;
1687 pref_t *col_num_pref;
1689 free_col_info(*pref->varp.list);
1690 *pref->varp.list = NULL;
1692 for (entry = pref->default_val.list; entry != NULL; entry = g_list_next(entry)) {
1693 src_cfmt = (fmt_data *)entry->data;
1694 dest_cfmt = g_new(fmt_data,1);
1695 dest_cfmt->title = g_strdup(src_cfmt->title);
1696 dest_cfmt->fmt = src_cfmt->fmt;
1697 if (src_cfmt->custom_fields) {
1698 dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
1699 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1701 dest_cfmt->custom_fields = NULL;
1702 dest_cfmt->custom_occurrence = 0;
1704 dest_cfmt->visible = src_cfmt->visible;
1705 dest_cfmt->resolved = src_cfmt->resolved;
1706 *pref->varp.list = g_list_append(*pref->varp.list, dest_cfmt);
1709 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1710 g_assert(col_num_pref != NULL); /* Should never happen */
1711 column_num_reset_cb(col_num_pref);
1714 static prefs_set_pref_e
1715 column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1717 GList *col_l, *col_l_elt;
1720 pref_t *hidden_pref, *col_num_pref;
1722 col_l = prefs_get_string_list(value);
1724 return PREFS_SET_SYNTAX_ERR;
1725 if ((g_list_length(col_l) % 2) != 0) {
1726 /* A title didn't have a matching format. */
1727 prefs_clear_string_list(col_l);
1728 return PREFS_SET_SYNTAX_ERR;
1730 /* Check to make sure all column formats are valid. */
1731 col_l_elt = g_list_first(col_l);
1733 fmt_data cfmt_check;
1735 /* Go past the title. */
1736 col_l_elt = col_l_elt->next;
1738 /* Parse the format to see if it's valid. */
1739 if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
1740 /* It's not a valid column format. */
1741 prefs_clear_string_list(col_l);
1742 return PREFS_SET_SYNTAX_ERR;
1744 if (cfmt_check.fmt != COL_CUSTOM) {
1745 /* Some predefined columns have been migrated to use custom columns.
1746 * We'll convert these silently here */
1747 try_convert_to_custom_column(&col_l_elt->data);
1749 /* We don't need the custom column field on this pass. */
1750 g_free(cfmt_check.custom_fields);
1753 /* Go past the format. */
1754 col_l_elt = col_l_elt->next;
1757 /* They're all valid; process them. */
1758 free_col_info(*pref->varp.list);
1759 *pref->varp.list = NULL;
1760 hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN);
1761 g_assert(hidden_pref != NULL); /* Should never happen */
1762 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1763 g_assert(col_num_pref != NULL); /* Should never happen */
1764 llen = g_list_length(col_l);
1765 *col_num_pref->varp.uint = llen / 2;
1766 col_l_elt = g_list_first(col_l);
1768 cfmt = g_new(fmt_data,1);
1769 cfmt->title = g_strdup((gchar *)col_l_elt->data);
1770 col_l_elt = col_l_elt->next;
1771 parse_column_format(cfmt, (char *)col_l_elt->data);
1772 cfmt->visible = prefs_is_column_visible(*hidden_pref->varp.string, cfmt);
1773 col_l_elt = col_l_elt->next;
1774 *pref->varp.list = g_list_append(*pref->varp.list, cfmt);
1777 prefs_clear_string_list(col_l);
1778 free_string_like_preference(hidden_pref);
1779 return PREFS_SET_OK;
1784 column_format_type_name_cb(void)
1786 return "Packet list column format";
1790 column_format_type_description_cb(void)
1792 return g_strdup("Each pair of strings consists of a column title and its format");
1796 column_format_is_default_cb(pref_t* pref)
1798 GList *clp = *pref->varp.list,
1799 *pref_col = g_list_first(clp),
1800 *def_col = g_list_first(pref->default_val.list);
1801 fmt_data *cfmt, *def_cfmt;
1802 gboolean is_default = TRUE;
1803 pref_t *col_num_pref;
1805 /* See if the column data has changed from the default */
1806 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1807 if (col_num_pref && *col_num_pref->varp.uint != col_num_pref->default_val.uint) {
1810 while (pref_col && def_col) {
1811 cfmt = (fmt_data *) pref_col->data;
1812 def_cfmt = (fmt_data *) def_col->data;
1813 if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
1814 (cfmt->fmt != def_cfmt->fmt) ||
1815 (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) &&
1816 ((g_strcmp0(cfmt->custom_fields, def_cfmt->custom_fields) != 0) ||
1817 (cfmt->resolved != def_cfmt->resolved)))) {
1822 pref_col = pref_col->next;
1823 def_col = def_col->next;
1831 column_format_to_str_cb(pref_t* pref, gboolean default_val)
1833 GList *pref_l = default_val ? pref->default_val.list : *pref->varp.list;
1834 GList *clp = g_list_first(pref_l);
1838 char *column_format_str;
1842 cfmt = (fmt_data *) clp->data;
1843 col_l = g_list_append(col_l, g_strdup(cfmt->title));
1844 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
1845 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1846 col_format_to_string(cfmt->fmt),
1847 cfmt->custom_fields,
1848 cfmt->custom_occurrence,
1849 cfmt->resolved ? 'R' : 'U');
1851 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1853 col_l = g_list_append(col_l, prefs_fmt);
1857 column_format_str = join_string_list(col_l);
1858 prefs_clear_string_list(col_l);
1859 return column_format_str;
1863 /****** Capture column custom preference functions ******/
1865 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
1866 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
1867 to prefs->default_val.list.
1870 capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
1872 GList *ccv_list = *capture_cols_values,
1877 dlist = g_list_append(dlist, g_strdup((gchar *)ccv_list->data));
1878 ccv_list = ccv_list->next;
1881 pref->default_val.list = dlist;
1882 pref->varp.list = &prefs.capture_columns;
1883 pref->stashed_val.boolval = FALSE;
1886 /* Free the prefs->capture_columns list strings and remove the list entries.
1887 Note that since pref->varp.list points to &prefs.capture_columns, it is
1891 capture_column_free_cb(pref_t* pref)
1893 prefs_clear_string_list(prefs.capture_columns);
1894 prefs.capture_columns = NULL;
1896 if (pref->stashed_val.boolval == TRUE) {
1897 prefs_clear_string_list(pref->default_val.list);
1898 pref->default_val.list = NULL;
1902 /* Copy pref->default_val.list to *pref->varp.list.
1905 capture_column_reset_cb(pref_t* pref)
1907 GList *vlist = NULL, *dlist;
1909 /* Free the column name strings and remove the links from *pref->varp.list */
1910 prefs_clear_string_list(*pref->varp.list);
1912 for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
1913 vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
1915 *pref->varp.list = vlist;
1918 static prefs_set_pref_e
1919 capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1921 GList *col_l = prefs_get_string_list(value);
1927 return PREFS_SET_SYNTAX_ERR;
1929 capture_column_free_cb(pref);
1931 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
1932 to the full list of valid capture column names. */
1933 col_l_elt = g_list_first(col_l);
1934 if (!(*(gchar *)col_l_elt->data)) {
1935 for (i = 0; i < num_capture_cols; i++) {
1936 col_name = g_strdup(capture_cols[i]);
1937 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1941 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
1944 gboolean found_match = FALSE;
1945 col_name = (gchar *)col_l_elt->data;
1947 for (i = 0; i < num_capture_cols; i++) {
1948 if (strcmp(col_name, capture_cols[i])==0) {
1954 /* One or more cols are invalid so use the entire list of valid cols. */
1955 for (i = 0; i < num_capture_cols; i++) {
1956 col_name = g_strdup(capture_cols[i]);
1957 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1959 pref->varp.list = &prefs.capture_columns;
1960 prefs_clear_string_list(col_l);
1961 return PREFS_SET_SYNTAX_ERR;
1963 col_l_elt = col_l_elt->next;
1966 col_l_elt = g_list_first(col_l);
1968 col_name = (gchar *)col_l_elt->data;
1969 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1970 col_l_elt = col_l_elt->next;
1972 pref->varp.list = &prefs.capture_columns;
1974 return PREFS_SET_OK;
1979 capture_column_type_name_cb(void)
1981 return "Column list";
1985 capture_column_type_description_cb(void)
1988 "List of columns to be displayed in the capture options dialog.\n"
1989 CAPTURE_COL_TYPE_DESCRIPTION);
1993 capture_column_is_default_cb(pref_t* pref)
1995 GList *pref_col = g_list_first(prefs.capture_columns),
1996 *def_col = g_list_first(pref->default_val.list);
1997 gboolean is_default = TRUE;
1999 /* See if the column data has changed from the default */
2000 while (pref_col && def_col) {
2001 if (strcmp((gchar *)pref_col->data, (gchar *)def_col->data) != 0) {
2005 pref_col = pref_col->next;
2006 def_col = def_col->next;
2009 /* Ensure the same column count */
2010 if (((pref_col == NULL) && (def_col != NULL)) ||
2011 ((pref_col != NULL) && (def_col == NULL)))
2018 capture_column_to_str_cb(pref_t* pref, gboolean default_val)
2021 GList *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
2022 GList *clp = g_list_first(pref_l);
2023 GList *col_l = NULL;
2025 char *capture_column_str;
2028 col = (gchar *) clp->data;
2029 col_l = g_list_append(col_l, g_strdup(col));
2033 capture_column_str = join_string_list(col_l);
2034 prefs_clear_string_list(col_l);
2035 return capture_column_str;
2038 static prefs_set_pref_e
2039 colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
2041 prefs_set_string_like_value(pref, value, changed);
2043 return PREFS_SET_OK;
2047 colorized_frame_type_name_cb(void)
2049 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
2050 * file until the colors can be changed in the GUI. Currently this is not really
2051 * possible since the STOCK-icons for these colors are hardcoded.
2053 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
2054 * add these 10 colors to the list of colors that can be changed through
2062 colorized_frame_type_description_cb(void)
2064 return g_strdup("");
2068 colorized_frame_is_default_cb(pref_t* pref _U_)
2074 colorized_frame_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
2076 return g_strdup("");
2080 * Register all non-dissector modules' preferences.
2082 static module_t *gui_module = NULL;
2083 static module_t *gui_color_module = NULL;
2084 static module_t *nameres_module = NULL;
2087 prefs_register_modules(void)
2089 module_t *printing, *capture_module, *console_module,
2090 *gui_layout_module, *gui_font_module;
2092 module_t *extcap_module;
2095 struct pref_custom_cbs custom_cbs;
2097 if (protocols_module != NULL) {
2098 /* Already setup preferences */
2104 * These are "simple" GUI preferences that can be read/written using the
2105 * preference module API. These preferences still use their own
2106 * configuration screens for access, but this cuts down on the
2107 * preference "string compare list" in set_pref()
2109 extcap_module = prefs_register_module(NULL, "extcap", "Extcap Utilities",
2110 "Extcap Utilities", NULL, FALSE);
2112 /* Setting default value to true */
2113 prefs.extcap_save_on_start = TRUE;
2114 prefs_register_bool_preference(extcap_module, "gui_save_on_start",
2115 "Save arguments on start of capture",
2116 "Save arguments on start of capture",
2117 &prefs.extcap_save_on_start);
2121 * These are "simple" GUI preferences that can be read/written using the
2122 * preference module API. These preferences still use their own
2123 * configuration screens for access, but this cuts down on the
2124 * preference "string compare list" in set_pref()
2126 gui_module = prefs_register_module(NULL, "gui", "User Interface",
2127 "User Interface", &gui_callback, FALSE);
2129 /* gui.console_open is placed first in the list so that any problems encountered
2130 * in the following prefs can be displayed in the console window.
2132 prefs_register_enum_preference(gui_module, "console_open",
2133 "Open a console window",
2134 "Open a console window (Windows only)",
2135 (gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
2137 prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
2138 prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
2139 prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
2141 prefs_register_bool_preference(gui_module, "tree_view_altern_colors",
2142 "Alternating colors in TreeViews",
2143 "Alternating colors in TreeViews?",
2144 &prefs.gui_altern_colors);
2146 prefs_register_bool_preference(gui_module, "expert_composite_eyecandy",
2147 "Display Icons on Expert Composite Dialog Tabs",
2148 "Display Icons on Expert Composite Dialog Tabs?",
2149 &prefs.gui_expert_composite_eyecandy);
2151 prefs_register_bool_preference(gui_module, "filter_toolbar_show_in_statusbar",
2152 "Place filter toolbar inside the statusbar",
2153 "Place filter toolbar inside the statusbar?",
2154 &prefs.filter_toolbar_show_in_statusbar);
2156 prefs_register_enum_preference(gui_module, "protocol_tree_line_style",
2157 "Protocol-tree line style",
2158 "Protocol-tree line style",
2159 &prefs.gui_ptree_line_style, gui_ptree_line_style, FALSE);
2161 prefs_register_enum_preference(gui_module, "protocol_tree_expander_style",
2162 "Protocol-tree expander style",
2163 "Protocol-tree expander style",
2164 &prefs.gui_ptree_expander_style, gui_ptree_expander_style, FALSE);
2166 prefs_register_enum_preference(gui_module, "hex_dump_highlight_style",
2167 "Hex dump highlight style",
2168 "Hex dump highlight style",
2169 &prefs.gui_hex_dump_highlight_style, gui_hex_dump_highlight_style, FALSE);
2171 gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
2173 custom_cbs.free_cb = free_string_like_preference;
2174 custom_cbs.reset_cb = reset_string_like_preference;
2175 custom_cbs.set_cb = column_hidden_set_cb;
2176 custom_cbs.type_name_cb = column_hidden_type_name_cb;
2177 custom_cbs.type_description_cb = column_hidden_type_description_cb;
2178 custom_cbs.is_default_cb = column_hidden_is_default_cb;
2179 custom_cbs.to_str_cb = column_hidden_to_str_cb;
2180 register_string_like_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
2181 "List all columns to hide in the packet list",
2182 &cols_hidden_list, PREF_CUSTOM, &custom_cbs, FALSE);
2184 custom_cbs.free_cb = column_format_free_cb;
2185 custom_cbs.reset_cb = column_format_reset_cb;
2186 custom_cbs.set_cb = column_format_set_cb;
2187 custom_cbs.type_name_cb = column_format_type_name_cb;
2188 custom_cbs.type_description_cb = column_format_type_description_cb;
2189 custom_cbs.is_default_cb = column_format_is_default_cb;
2190 custom_cbs.to_str_cb = column_format_to_str_cb;
2192 prefs_register_list_custom_preference(gui_column_module, PRS_COL_FMT, "Packet list column format",
2193 "Each pair of strings consists of a column title and its format", &custom_cbs,
2194 column_format_init_cb, &prefs.col_list);
2196 /* Number of columns. This is only used internally and is not written to the
2199 custom_cbs.free_cb = custom_pref_no_cb;
2200 custom_cbs.reset_cb = column_num_reset_cb;
2201 custom_cbs.set_cb = column_num_set_cb;
2202 custom_cbs.type_name_cb = column_num_type_name_cb;
2203 custom_cbs.type_description_cb = column_num_type_description_cb;
2204 custom_cbs.is_default_cb = column_num_is_default_cb;
2205 custom_cbs.to_str_cb = column_num_to_str_cb;
2206 prefs_register_uint_custom_preference(gui_column_module, PRS_COL_NUM, "Number of columns",
2207 "Number of columns in col_list", &custom_cbs, &prefs.num_cols);
2209 /* User Interface : Font */
2210 gui_font_module = prefs_register_subtree(gui_module, "Font", "Font", NULL);
2212 prefs_register_obsolete_preference(gui_font_module, "font_name");
2214 register_string_like_preference(gui_font_module, "gtk2.font_name", "Font name",
2215 "Font name for packet list, protocol tree, and hex dump panes. (GTK+)",
2216 &prefs.gui_gtk2_font_name, PREF_STRING, NULL, TRUE);
2218 register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
2219 "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
2220 &prefs.gui_qt_font_name, PREF_STRING, NULL, TRUE);
2222 /* User Interface : Colors */
2223 gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
2225 prefs_register_color_preference(gui_color_module, "marked_frame.fg", "Color preferences for a marked frame",
2226 "Color preferences for a marked frame", &prefs.gui_marked_fg);
2228 prefs_register_color_preference(gui_color_module, "marked_frame.bg", "Color preferences for a marked frame",
2229 "Color preferences for a marked frame", &prefs.gui_marked_bg);
2231 prefs_register_color_preference(gui_color_module, "ignored_frame.fg", "Color preferences for a ignored frame",
2232 "Color preferences for a ignored frame", &prefs.gui_ignored_fg);
2234 prefs_register_color_preference(gui_color_module, "ignored_frame.bg", "Color preferences for a ignored frame",
2235 "Color preferences for a ignored frame", &prefs.gui_ignored_bg);
2237 prefs_register_color_preference(gui_color_module, "stream.client.fg", "TCP stream window color preference",
2238 "TCP stream window color preference", &prefs.st_client_fg);
2240 prefs_register_color_preference(gui_color_module, "stream.client.bg", "TCP stream window color preference",
2241 "TCP stream window color preference", &prefs.st_client_bg);
2243 prefs_register_color_preference(gui_color_module, "stream.server.fg", "TCP stream window color preference",
2244 "TCP stream window color preference", &prefs.st_server_fg);
2246 prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
2247 "TCP stream window color preference", &prefs.st_server_bg);
2249 custom_cbs.free_cb = free_string_like_preference;
2250 custom_cbs.reset_cb = reset_string_like_preference;
2251 custom_cbs.set_cb = colorized_frame_set_cb;
2252 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2253 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2254 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2255 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2256 register_string_like_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
2257 "Filter Colorized Foreground",
2258 &prefs.gui_colorized_fg, PREF_CUSTOM, &custom_cbs, TRUE);
2260 custom_cbs.free_cb = free_string_like_preference;
2261 custom_cbs.reset_cb = reset_string_like_preference;
2262 custom_cbs.set_cb = colorized_frame_set_cb;
2263 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2264 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2265 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2266 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2267 register_string_like_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
2268 "Filter Colorized Background",
2269 &prefs.gui_colorized_bg, PREF_CUSTOM, &custom_cbs, TRUE);
2271 prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
2272 "Valid color filter background", &prefs.gui_text_valid);
2274 prefs_register_color_preference(gui_color_module, "color_filter_bg.invalid", "Invalid color filter background",
2275 "Invalid color filter background", &prefs.gui_text_invalid);
2277 prefs_register_color_preference(gui_color_module, "color_filter_bg.deprecated", "Deprecated color filter background",
2278 "Deprecated color filter background", &prefs.gui_text_deprecated);
2280 prefs_register_enum_preference(gui_module, "fileopen.style",
2281 "Where to start the File Open dialog box",
2282 "Where to start the File Open dialog box",
2283 &prefs.gui_fileopen_style, gui_fileopen_style, FALSE);
2285 prefs_register_uint_preference(gui_module, "recent_files_count.max",
2286 "The max. number of items in the open recent files list",
2287 "The max. number of items in the open recent files list",
2289 &prefs.gui_recent_files_count_max);
2291 prefs_register_uint_preference(gui_module, "recent_display_filter_entries.max",
2292 "The max. number of entries in the display filter list",
2293 "The max. number of entries in the display filter list",
2295 &prefs.gui_recent_df_entries_max);
2297 register_string_like_preference(gui_module, "fileopen.dir", "Start Directory",
2298 "Directory to start in when opening File Open dialog.",
2299 &prefs.gui_fileopen_dir, PREF_DIRNAME, NULL, TRUE);
2301 prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
2303 prefs_register_uint_preference(gui_module, "fileopen.preview",
2304 "The preview timeout in the File Open dialog",
2305 "The preview timeout in the File Open dialog",
2307 &prefs.gui_fileopen_preview);
2309 prefs_register_bool_preference(gui_module, "ask_unsaved",
2310 "Ask to save unsaved capture files",
2311 "Ask to save unsaved capture files?",
2312 &prefs.gui_ask_unsaved);
2314 prefs_register_bool_preference(gui_module, "find_wrap",
2315 "Wrap to beginning/end of file during search",
2316 "Wrap to beginning/end of file during search?",
2317 &prefs.gui_find_wrap);
2319 prefs_register_bool_preference(gui_module, "use_pref_save",
2320 "Settings dialogs use a save button",
2321 "Settings dialogs use a save button?",
2322 &prefs.gui_use_pref_save);
2324 prefs_register_bool_preference(gui_module, "geometry.save.position",
2325 "Save window position at exit",
2326 "Save window position at exit?",
2327 &prefs.gui_geometry_save_position);
2329 prefs_register_bool_preference(gui_module, "geometry.save.size",
2330 "Save window size at exit",
2331 "Save window size at exit?",
2332 &prefs.gui_geometry_save_size);
2334 prefs_register_bool_preference(gui_module, "geometry.save.maximized",
2335 "Save window maximized state at exit",
2336 "Save window maximized state at exit?",
2337 &prefs.gui_geometry_save_maximized);
2340 prefs_register_bool_preference(gui_module, "macosx_style",
2342 "Use OS X style (OS X with native GTK only)?",
2343 &prefs.gui_macosx_style);
2345 prefs_register_obsolete_preference(gui_module, "geometry.main.x");
2346 prefs_register_obsolete_preference(gui_module, "geometry.main.y");
2347 prefs_register_obsolete_preference(gui_module, "geometry.main.width");
2348 prefs_register_obsolete_preference(gui_module, "geometry.main.height");
2349 prefs_register_obsolete_preference(gui_module, "toolbar_main_show");
2351 prefs_register_enum_preference(gui_module, "toolbar_main_style",
2352 "Main Toolbar style",
2353 "Main Toolbar style",
2354 &prefs.gui_toolbar_main_style, gui_toolbar_style, FALSE);
2356 prefs_register_enum_preference(gui_module, "toolbar_filter_style",
2357 "Filter Toolbar style",
2358 "Filter Toolbar style",
2359 &prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
2361 register_string_like_preference(gui_module, "webbrowser", "The path to the webbrowser",
2362 "The path to the webbrowser (Ex: mozilla)",
2363 &prefs.gui_webbrowser, PREF_STRING, NULL, TRUE);
2365 prefs_register_bool_preference(gui_module, "update.enabled",
2366 "Check for updates",
2367 "Check for updates (Windows only)",
2368 &prefs.gui_update_enabled);
2370 prefs_register_enum_preference(gui_module, "update.channel",
2372 "The type of update to fetch. You should probably leave this set to UPDATE_CHANNEL_STABLE.",
2373 (gint*)(void*)(&prefs.gui_update_channel), gui_update_channel, FALSE);
2375 prefs_register_uint_preference(gui_module, "update.interval",
2376 "How often to check for software updates",
2377 "How often to check for software updates in seconds",
2379 &prefs.gui_update_interval);
2381 register_string_like_preference(gui_module, "window_title", "Custom window title",
2382 "Custom window title to be appended to the existing title\n%P = profile name\n%V = version info",
2383 &prefs.gui_window_title, PREF_STRING, NULL, TRUE);
2385 register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix",
2386 "Custom window title to be prepended to the existing title\n%P = profile name\n%V = version info",
2387 &prefs.gui_prepend_window_title, PREF_STRING, NULL, TRUE);
2389 register_string_like_preference(gui_module, "start_title", "Custom start page title",
2390 "Custom start page title",
2391 &prefs.gui_start_title, PREF_STRING, NULL, TRUE);
2393 prefs_register_enum_preference(gui_module, "version_placement",
2394 "Show version in the start page and/or main screen's title bar",
2395 "Show version in the start page and/or main screen's title bar",
2396 (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
2398 prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
2399 "Automatically scroll the recently expanded item",
2400 "Automatically scroll the recently expanded item",
2401 &prefs.gui_auto_scroll_on_expand);
2403 prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
2404 "The percentage down the view the recently expanded item should be scrolled",
2405 "The percentage down the view the recently expanded item should be scrolled",
2407 &prefs.gui_auto_scroll_percentage);
2409 /* User Interface : Layout */
2410 gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
2412 prefs_register_uint_preference(gui_layout_module, "layout_type",
2414 "Layout type (1-6)",
2416 (guint*)(void*)(&prefs.gui_layout_type));
2418 prefs_register_enum_preference(gui_layout_module, "layout_content_1",
2419 "Layout content of the pane 1",
2420 "Layout content of the pane 1",
2421 (gint*)(void*)(&prefs.gui_layout_content_1), gui_layout_content, FALSE);
2423 prefs_register_enum_preference(gui_layout_module, "layout_content_2",
2424 "Layout content of the pane 2",
2425 "Layout content of the pane 2",
2426 (gint*)(void*)(&prefs.gui_layout_content_2), gui_layout_content, FALSE);
2428 prefs_register_enum_preference(gui_layout_module, "layout_content_3",
2429 "Layout content of the pane 3",
2430 "Layout content of the pane 3",
2431 (gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
2433 prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
2434 "Enable Packet List Separator",
2435 "Enable Packet List Separator",
2436 &prefs.gui_qt_packet_list_separator);
2438 prefs_register_bool_preference(gui_module, "packet_editor.enabled",
2439 "Enable Packet Editor",
2440 "Enable Packet Editor (Experimental)",
2441 &prefs.gui_packet_editor);
2443 prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
2445 "The position of \"...\" in packet list text.",
2446 (gint*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, FALSE);
2448 prefs_register_bool_preference(gui_layout_module, "packet_list_show_related",
2449 "Show Related Packets",
2450 "Show related packet indicators in the first column",
2451 &prefs.gui_packet_list_show_related);
2453 prefs_register_bool_preference(gui_layout_module, "packet_list_show_minimap",
2454 "Enable Intelligent Scroll Bar",
2455 "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
2456 &prefs.gui_packet_list_show_minimap);
2459 * These are preferences that can be read/written using the
2460 * preference module API. These preferences still use their own
2461 * configuration screens for access, but this cuts down on the
2462 * preference "string compare list" in set_pref()
2464 console_module = prefs_register_module(NULL, "console", "Console",
2465 "CONSOLE", NULL, FALSE);
2467 custom_cbs.free_cb = custom_pref_no_cb;
2468 custom_cbs.reset_cb = console_log_level_reset_cb;
2469 custom_cbs.set_cb = console_log_level_set_cb;
2470 custom_cbs.type_name_cb = console_log_level_type_name_cb;
2471 custom_cbs.type_description_cb = console_log_level_type_description_cb;
2472 custom_cbs.is_default_cb = console_log_level_is_default_cb;
2473 custom_cbs.to_str_cb = console_log_level_to_str_cb;
2474 prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
2475 "A bitmask of glib log levels", &custom_cbs, &prefs.console_log_level);
2478 * These are preferences that can be read/written using the
2479 * preference module API. These preferences still use their own
2480 * configuration screens for access, but this cuts down on the
2481 * preference "string compare list" in set_pref()
2483 capture_module = prefs_register_module(NULL, "capture", "Capture",
2484 "CAPTURE", NULL, FALSE);
2486 register_string_like_preference(capture_module, "device", "Default capture device",
2487 "Default capture device",
2488 &prefs.capture_device, PREF_STRING, NULL, FALSE);
2490 register_string_like_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
2491 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
2492 &prefs.capture_devices_linktypes, PREF_STRING, NULL, FALSE);
2494 register_string_like_preference(capture_module, "devices_descr", "Interface descriptions",
2495 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
2496 &prefs.capture_devices_descr, PREF_STRING, NULL, FALSE);
2498 register_string_like_preference(capture_module, "devices_hide", "Hide interface",
2499 "Hide interface? (Ex: eth0,eth3,...)",
2500 &prefs.capture_devices_hide, PREF_STRING, NULL, FALSE);
2502 register_string_like_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
2503 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
2504 &prefs.capture_devices_monitor_mode, PREF_STRING, NULL, FALSE);
2506 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
2507 register_string_like_preference(capture_module, "devices_buffersize", "Interface buffer size",
2508 "Interface buffer size (Ex: en0(1),en1(143),...)",
2509 &prefs.capture_devices_buffersize, PREF_STRING, NULL, FALSE);
2512 register_string_like_preference(capture_module, "devices_snaplen", "Interface snap length",
2513 "Interface snap length (Ex: en0(65535),en1(1430),...)",
2514 &prefs.capture_devices_snaplen, PREF_STRING, NULL, FALSE);
2516 register_string_like_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
2517 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
2518 &prefs.capture_devices_pmode, PREF_STRING, NULL, FALSE);
2520 prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
2521 "Capture in promiscuous mode?", &prefs.capture_prom_mode);
2523 register_string_like_preference(capture_module, "devices_filter", "Interface capture filter",
2524 "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
2525 &prefs.capture_devices_filter, PREF_STRING, NULL, FALSE);
2527 prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
2528 "Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
2530 prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
2531 "Update packet list in real time during capture?", &prefs.capture_real_time);
2533 /* We might want to make this a "recent" setting. */
2534 prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
2535 "Scroll packet list during capture?", &prefs.capture_auto_scroll);
2538 prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
2539 "Show capture info dialog while capturing?", &prefs.capture_show_info);
2541 prefs_register_obsolete_preference(capture_module, "syntax_check_filter");
2543 custom_cbs.free_cb = capture_column_free_cb;
2544 custom_cbs.reset_cb = capture_column_reset_cb;
2545 custom_cbs.set_cb = capture_column_set_cb;
2546 custom_cbs.type_name_cb = capture_column_type_name_cb;
2547 custom_cbs.type_description_cb = capture_column_type_description_cb;
2548 custom_cbs.is_default_cb = capture_column_is_default_cb;
2549 custom_cbs.to_str_cb = capture_column_to_str_cb;
2550 prefs_register_list_custom_preference(capture_module, "columns", "Capture options dialog column list",
2551 "List of columns to be displayed", &custom_cbs, capture_column_init_cb, &prefs.capture_columns);
2553 /* Name Resolution */
2554 nameres_module = prefs_register_module(NULL, "nameres", "Name Resolution",
2555 "Name Resolution", NULL, TRUE);
2556 addr_resolve_pref_init(nameres_module);
2557 oid_pref_init(nameres_module);
2559 geoip_db_pref_init(nameres_module);
2563 printing = prefs_register_module(NULL, "print", "Printing",
2564 "Printing", NULL, TRUE);
2566 prefs_register_enum_preference(printing, "format",
2567 "Format", "Can be one of \"text\" or \"postscript\"",
2568 &prefs.pr_format, print_format_vals, TRUE);
2570 prefs_register_enum_preference(printing, "destination",
2571 "Print to", "Can be one of \"command\" or \"file\"",
2572 &prefs.pr_dest, print_dest_vals, TRUE);
2575 register_string_like_preference(printing, "command", "Command",
2576 "Output gets piped to this command when the destination is set to \"command\"",
2577 &prefs.pr_cmd, PREF_STRING, NULL, TRUE);
2580 register_string_like_preference(printing, "file", "File",
2581 "This is the file that gets written to when the destination is set to \"file\"",
2582 &prefs.pr_file, PREF_FILENAME, NULL, TRUE);
2585 stats_module = prefs_register_module(NULL, "statistics", "Statistics",
2586 "Statistics", &stats_callback, TRUE);
2588 prefs_register_uint_preference(stats_module, "update_interval",
2589 "Tap update interval in ms",
2590 "Determines time between tap updates",
2592 &prefs.tap_update_interval);
2594 #ifdef HAVE_LIBPORTAUDIO
2595 prefs_register_uint_preference(stats_module, "rtp_player_max_visible",
2596 "Max visible channels in RTP Player",
2597 "Determines maximum height of RTP Player window",
2599 &prefs.rtp_player_max_visible);
2602 prefs_register_bool_preference(stats_module, "st_enable_burstinfo",
2603 "Enable the calculation of burst information",
2604 "If enabled burst rates will be calcuted for statistics that use the stats_tree system. "
2605 "Burst rates are calculated over a much shorter time interval than the rate column.",
2606 &prefs.st_enable_burstinfo);
2608 prefs_register_bool_preference(stats_module, "st_burst_showcount",
2609 "Show burst count for item rather than rate",
2610 "If selected the stats_tree statistics nodes will show the count of events "
2611 "within the burst window instead of a burst rate. Burst rate is calculated "
2612 "as number of events within burst window divided by the burst windown length.",
2613 &prefs.st_burst_showcount);
2615 prefs_register_uint_preference(stats_module, "st_burst_resolution",
2616 "Burst rate resolution (ms)",
2617 "Sets the duration of the time interval into which events are grouped when calculating "
2618 "the burst rate. Higher resolution (smaller number) increases processing overhead.",
2619 10,&prefs.st_burst_resolution);
2621 prefs_register_uint_preference(stats_module, "st_burst_windowlen",
2622 "Burst rate window size (ms)",
2623 "Sets the duration of the sliding window during which the burst rate is "
2624 "measured. Longer window relative to burst rate resolution increases "
2625 "processing overhead. Will be truncated to a multiple of burst resolution.",
2626 10,&prefs.st_burst_windowlen);
2628 prefs_register_enum_preference(stats_module, "st_sort_defcolflag",
2629 "Default sort column for stats_tree stats",
2630 "Sets the default column by which stats based on the stats_tree "
2631 "system is sorted.",
2632 &prefs.st_sort_defcolflag, st_sort_col_vals, FALSE);
2634 prefs_register_bool_preference(stats_module, "st_sort_defdescending",
2635 "Default stats_tree sort order is descending",
2636 "When selected, statistics based on the stats_tree system will by default "
2637 "be sorted in descending order.",
2638 &prefs.st_sort_defdescending);
2640 prefs_register_bool_preference(stats_module, "st_sort_casesensitve",
2641 "Case sensitive sort of stats_tree item names",
2642 "When selected, the item/node names of statistics based on the stats_tree "
2643 "system will be sorted taking case into account. Else the case of the name "
2645 &prefs.st_sort_casesensitve);
2647 prefs_register_bool_preference(stats_module, "st_sort_rng_nameonly",
2648 "Always sort 'range' nodes by name",
2649 "When selected, the stats_tree nodes representing a range of values "
2650 "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
2651 "node). Else range nodes are sorted by the same column as the rest of "
2653 &prefs.st_sort_rng_nameonly);
2655 prefs_register_bool_preference(stats_module, "st_sort_rng_fixorder",
2656 "Always sort 'range' nodes in ascending order",
2657 "When selected, the stats_tree nodes representing a range of values "
2658 "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
2659 "the sort direction of the tree. Only effective if \"Always sort "
2660 "'range' nodes by name\" is also selected.",
2661 &prefs.st_sort_rng_fixorder);
2663 prefs_register_bool_preference(stats_module, "st_sort_showfullname",
2664 "Display the full stats_tree plug-in name",
2665 "When selected, the full name (including menu path) of the stats_tree "
2666 "plug-in is show in windows. If cleared the plug-in name is shown "
2667 "without menu path (only the part of the name after last '/' character.)",
2668 &prefs.st_sort_showfullname);
2671 protocols_module = prefs_register_module(NULL, "protocols", "Protocols",
2672 "Protocols", NULL, TRUE);
2674 prefs_register_bool_preference(protocols_module, "display_hidden_proto_items",
2675 "Display hidden protocol items",
2676 "Display all hidden protocol items in the packet list.",
2677 &prefs.display_hidden_proto_items);
2679 prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
2680 "Display byte fields with a space character between bytes",
2681 "Display all byte fields with a space character between each byte in the packet list.",
2682 &prefs.display_byte_fields_with_spaces);
2684 prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
2685 "Look for incomplete dissectors",
2686 "Look for dissectors that left some bytes undecoded.",
2687 &prefs.enable_incomplete_dissectors_check);
2689 /* Obsolete preferences
2690 * These "modules" were reorganized/renamed to correspond to their GUI
2691 * configuration screen within the preferences dialog
2694 /* taps is now part of the stats module */
2695 prefs_register_module(NULL, "taps", "TAPS", "TAPS", NULL, FALSE);
2696 /* packet_list is now part of the protocol (parent) module */
2697 prefs_register_module(NULL, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL, FALSE);
2698 /* stream is now part of the gui module */
2699 prefs_register_module(NULL, "stream", "STREAM", "STREAM", NULL, FALSE);
2703 /* Parse through a list of comma-separated, possibly quoted strings.
2704 Return a list of the string data. */
2706 prefs_get_string_list(const gchar *str)
2708 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
2710 gint state = PRE_STRING, i = 0, j = 0;
2711 gboolean backslash = FALSE;
2713 gchar *slstr = NULL;
2716 /* Allocate a buffer for the first string. */
2717 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2722 if (cur_c == '\0') {
2723 /* It's the end of the input, so it's the end of the string we
2724 were working on, and there's no more input. */
2725 if (state == IN_QUOT || backslash) {
2726 /* We were in the middle of a quoted string or backslash escape,
2727 and ran out of characters; that's an error. */
2729 prefs_clear_string_list(sl);
2733 sl = g_list_append(sl, slstr);
2736 if (cur_c == '"' && ! backslash) {
2739 /* We hadn't yet started processing a string; this starts the
2740 string, and we're now quoting. */
2744 /* We're in the middle of a quoted string, and we saw a quotation
2745 mark; we're no longer quoting. */
2746 state = NOT_IN_QUOT;
2749 /* We're working on a string, but haven't seen a quote; we're
2756 } else if (cur_c == '\\' && ! backslash) {
2757 /* We saw a backslash, and the previous character wasn't a
2758 backslash; escape the next character.
2760 This also means we've started a new string. */
2762 if (state == PRE_STRING)
2763 state = NOT_IN_QUOT;
2764 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
2765 /* We saw a comma, and we're not in the middle of a quoted string
2766 and it wasn't preceded by a backslash; it's the end of
2767 the string we were working on... */
2769 sl = g_list_append(sl, slstr);
2771 /* ...and the beginning of a new string. */
2773 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2775 } else if (!g_ascii_isspace(cur_c) || state != PRE_STRING) {
2776 /* Either this isn't a white-space character, or we've started a
2777 string (i.e., already seen a non-white-space character for that
2778 string and put it into the string).
2780 The character is to be put into the string; do so if there's
2782 if (j < COL_MAX_LEN) {
2787 /* If it was backslash-escaped, we're done with the backslash escape. */
2795 char *join_string_list(GList *sl)
2797 GString *joined_str = g_string_new("");
2801 guint item_count = 0;
2803 cur = first = g_list_first(sl);
2806 str = (gchar *)cur->data;
2809 g_string_append_c(joined_str, ',');
2811 if (item_count % 2) {
2812 /* Wrap the line. */
2813 g_string_append(joined_str, "\n\t");
2815 g_string_append_c(joined_str, ' ');
2817 quoted_str = g_strescape(str, "");
2818 g_string_append_printf(joined_str, "\"%s\"", quoted_str);
2823 return g_string_free(joined_str, FALSE);
2827 prefs_clear_string_list(GList *sl)
2829 /* g_list_free_full() only exists since 2.28. */
2830 g_list_foreach(sl, (GFunc)g_free, NULL);
2835 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
2837 * The array must be terminated by an entry with a null "name" string.
2839 * If the string matches a "name" string in an entry, the value from that
2840 * entry is returned.
2842 * Otherwise, if a string matches a "description" string in an entry, the
2843 * value from that entry is returned; we do that for backwards compatibility,
2844 * as we used to have only a "name" string that was used both for command-line
2845 * and configuration-file values and in the GUI (which meant either that
2846 * the GUI had what might be somewhat cryptic values to select from or that
2847 * the "-o" flag took long strings, often with spaces in them).
2849 * Otherwise, the default value that was passed as the third argument is
2853 find_val_for_string(const char *needle, const enum_val_t *haystack,
2858 for (i = 0; haystack[i].name != NULL; i++) {
2859 if (g_ascii_strcasecmp(needle, haystack[i].name) == 0) {
2860 return haystack[i].value;
2863 for (i = 0; haystack[i].name != NULL; i++) {
2864 if (g_ascii_strcasecmp(needle, haystack[i].description) == 0) {
2865 return haystack[i].value;
2868 return default_value;
2872 /* Array of columns that have been migrated to custom columns */
2873 struct deprecated_columns {
2874 const gchar *col_fmt;
2875 const gchar *col_expr;
2877 static struct deprecated_columns migrated_columns[] = {
2878 { /* COL_COS_VALUE */ "%U", "vlan.priority" },
2879 { /* COL_CIRCUIT_ID */ "%c", "iax2.call" },
2880 { /* COL_BSSGP_TLLI */ "%l", "bssgp.tlli" },
2881 { /* COL_HPUX_SUBSYS */ "%H", "nettl.subsys" },
2882 { /* COL_HPUX_DEVID */ "%P", "nettl.devid" },
2883 { /* COL_FR_DLCI */ "%C", "fr.dlci" },
2884 { /* COL_REL_CONV_TIME */ "%rct", "tcp.time_relative" },
2885 { /* COL_DELTA_CONV_TIME */ "%dct", "tcp.time_delta" },
2886 { /* COL_OXID */ "%XO", "fc.ox_id" },
2887 { /* COL_RXID */ "%XR", "fc.rx_id" },
2888 { /* COL_SRCIDX */ "%Xd", "mdshdr.srcidx" },
2889 { /* COL_DSTIDX */ "%Xs", "mdshdr.dstidx" },
2890 { /* COL_DCE_CTX */ "%z", "dcerpc.cn_ctx_id" }
2894 is_deprecated_column_format(const gchar* fmt)
2898 for (haystack_idx = 0;
2899 haystack_idx < G_N_ELEMENTS(migrated_columns);
2902 if (strcmp(migrated_columns[haystack_idx].col_fmt, fmt) == 0) {
2910 /* Preferences file format:
2911 * - Configuration directives start at the beginning of the line, and
2912 * are terminated with a colon.
2913 * - Directives can be continued on the next line by preceding them with
2918 # This is a comment line
2920 print.file: /a/very/long/path/
2925 #define DEF_NUM_COLS 7
2928 * Parse a column format, filling in the relevant fields of a fmt_data.
2931 parse_column_format(fmt_data *cfmt, const char *fmt)
2933 const gchar *cust_format = col_format_to_string(COL_CUSTOM);
2934 size_t cust_format_len = strlen(cust_format);
2935 gchar **cust_format_info;
2938 gchar *col_custom_fields = NULL;
2939 long col_custom_occurrence = 0;
2940 gboolean col_resolved = TRUE;
2943 * Is this a custom column?
2945 if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
2946 strncmp(fmt, cust_format, cust_format_len) == 0) {
2948 col_fmt = COL_CUSTOM;
2949 cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
2950 col_custom_fields = g_strdup(cust_format_info[0]);
2951 if (col_custom_fields && cust_format_info[1]) {
2952 col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
2953 if (p == cust_format_info[1] || *p != '\0') {
2954 /* Not a valid number. */
2955 g_free(col_custom_fields);
2956 g_strfreev(cust_format_info);
2960 if (col_custom_fields && cust_format_info[1] && cust_format_info[2]) {
2961 col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
2963 g_strfreev(cust_format_info);
2965 col_fmt = get_column_format_from_str(fmt);
2966 if ((col_fmt == -1) && (!is_deprecated_column_format(fmt)))
2970 cfmt->fmt = col_fmt;
2971 cfmt->custom_fields = col_custom_fields;
2972 cfmt->custom_occurrence = (int)col_custom_occurrence;
2973 cfmt->resolved = col_resolved;
2977 /* Initialize non-dissector preferences to wired-in default values Called
2978 * at program startup and any time the profile changes. (The dissector
2979 * preferences are assumed to be set to those values by the dissectors.)
2980 * They may be overridden by the global preferences file or the user's
2986 if (prefs_initialized)
2992 * Ensure the "global" preferences have been initialized so the
2993 * preference API has the proper default values to work from
2997 prefs_register_modules();
2999 filter_expression_init();
3001 prefs_initialized = TRUE;
3005 * Initialize non-dissector preferences used by the "register preference" API
3006 * to default values so the default values can be used when registered.
3008 * String, filename, and directory preferences will be g_freed so they must
3012 pre_init_prefs(void)
3017 static const gchar *col_fmt[DEF_NUM_COLS*2] = {
3018 "No.", "%m", "Time", "%t",
3019 "Source", "%s", "Destination", "%d",
3020 "Protocol", "%p", "Length", "%L",
3023 prefs.pr_format = PR_FMT_TEXT;
3024 prefs.pr_dest = PR_DEST_CMD;
3025 if (prefs.pr_file) g_free(prefs.pr_file);
3026 prefs.pr_file = g_strdup("wireshark.out");
3027 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
3028 prefs.pr_cmd = g_strdup("lpr");
3030 prefs.gui_altern_colors = FALSE;
3031 prefs.gui_expert_composite_eyecandy = FALSE;
3032 prefs.gui_ptree_line_style = 0;
3033 prefs.gui_ptree_expander_style = 1;
3034 prefs.gui_hex_dump_highlight_style = 1;
3035 prefs.filter_toolbar_show_in_statusbar = FALSE;
3036 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
3037 prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
3038 /* These will be g_freed, so they must be g_mallocated. */
3039 if (prefs.gui_gtk2_font_name) g_free(prefs.gui_gtk2_font_name);
3041 prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
3043 prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
3045 /* We try to find the best font in the Qt code */
3046 if (prefs.gui_qt_font_name) g_free(prefs.gui_qt_font_name);
3047 prefs.gui_qt_font_name = g_strdup("");
3048 prefs.gui_marked_fg.red = 65535;
3049 prefs.gui_marked_fg.green = 65535;
3050 prefs.gui_marked_fg.blue = 65535;
3051 prefs.gui_marked_bg.red = 0;
3052 prefs.gui_marked_bg.green = 8224;
3053 prefs.gui_marked_bg.blue = 10794;
3054 prefs.gui_ignored_fg.red = 32767;
3055 prefs.gui_ignored_fg.green = 32767;
3056 prefs.gui_ignored_fg.blue = 32767;
3057 prefs.gui_ignored_bg.red = 65535;
3058 prefs.gui_ignored_bg.green = 65535;
3059 prefs.gui_ignored_bg.blue = 65535;
3060 if (prefs.gui_colorized_fg) g_free(prefs.gui_colorized_fg);
3061 prefs.gui_colorized_fg = g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
3062 if (prefs.gui_colorized_bg) g_free(prefs.gui_colorized_bg);
3063 prefs.gui_colorized_bg = g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
3064 prefs.st_client_fg.red = 32767;
3065 prefs.st_client_fg.green = 0;
3066 prefs.st_client_fg.blue = 0;
3067 prefs.st_client_bg.red = 64507;
3068 prefs.st_client_bg.green = 60909;
3069 prefs.st_client_bg.blue = 60909;
3070 prefs.st_server_fg.red = 0;
3071 prefs.st_server_fg.green = 0;
3072 prefs.st_server_fg.blue = 32767;
3073 prefs.st_server_bg.red = 60909;
3074 prefs.st_server_bg.green = 60909;
3075 prefs.st_server_bg.blue = 64507;
3076 prefs.gui_text_valid.red = 0xAFFF; /* light green */
3077 prefs.gui_text_valid.green = 0xFFFF;
3078 prefs.gui_text_valid.blue = 0xAFFF;
3079 prefs.gui_text_invalid.red = 0xFFFF; /* light red */
3080 prefs.gui_text_invalid.green = 0xAFFF;
3081 prefs.gui_text_invalid.blue = 0xAFFF;
3082 prefs.gui_text_deprecated.red = 0xFFFF; /* light yellow */
3083 prefs.gui_text_deprecated.green = 0xFFFF;
3084 prefs.gui_text_deprecated.blue = 0xAFFF;
3085 prefs.gui_geometry_save_position = TRUE;
3086 prefs.gui_geometry_save_size = TRUE;
3087 prefs.gui_geometry_save_maximized= TRUE;
3088 prefs.gui_macosx_style = TRUE;
3089 prefs.gui_console_open = console_open_never;
3090 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
3091 prefs.gui_recent_df_entries_max = 10;
3092 prefs.gui_recent_files_count_max = 10;
3093 if (prefs.gui_fileopen_dir) g_free(prefs.gui_fileopen_dir);
3094 prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
3095 prefs.gui_fileopen_preview = 3;
3096 prefs.gui_ask_unsaved = TRUE;
3097 prefs.gui_find_wrap = TRUE;
3098 prefs.gui_use_pref_save = FALSE;
3099 prefs.gui_update_enabled = TRUE;
3100 prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
3101 prefs.gui_update_interval = 60*60*24; /* Seconds */
3102 if (prefs.gui_webbrowser) g_free(prefs.gui_webbrowser);
3104 prefs.gui_webbrowser = g_strdup(HTML_VIEWER " %s");
3106 prefs.gui_webbrowser = g_strdup("");
3108 if (prefs.gui_window_title) g_free(prefs.gui_window_title);
3109 prefs.gui_window_title = g_strdup("");
3110 if (prefs.gui_prepend_window_title) g_free(prefs.gui_prepend_window_title);
3111 prefs.gui_prepend_window_title = g_strdup("");
3112 if (prefs.gui_start_title) g_free(prefs.gui_start_title);
3113 prefs.gui_start_title = g_strdup("The World's Most Popular Network Protocol Analyzer");
3114 prefs.gui_version_placement = version_both;
3115 prefs.gui_auto_scroll_on_expand = FALSE;
3116 prefs.gui_auto_scroll_percentage = 0;
3117 prefs.gui_layout_type = layout_type_5;
3118 prefs.gui_layout_content_1 = layout_pane_content_plist;
3119 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
3120 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
3121 prefs.gui_packet_editor = FALSE;
3122 prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
3123 prefs.gui_packet_list_show_related = TRUE;
3124 prefs.gui_packet_list_show_minimap = TRUE;
3126 prefs.gui_qt_packet_list_separator = FALSE;
3128 if (prefs.col_list) {
3129 free_col_info(prefs.col_list);
3130 prefs.col_list = NULL;
3132 for (i = 0; i < DEF_NUM_COLS; i++) {
3133 cfmt = g_new(fmt_data,1);
3134 cfmt->title = g_strdup(col_fmt[i * 2]);
3135 parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
3136 cfmt->visible = TRUE;
3137 cfmt->resolved = TRUE;
3138 cfmt->custom_fields = NULL;
3139 cfmt->custom_occurrence = 0;
3140 prefs.col_list = g_list_append(prefs.col_list, cfmt);
3142 prefs.num_cols = DEF_NUM_COLS;
3144 /* set the default values for the capture dialog box */
3145 prefs.capture_prom_mode = TRUE;
3146 #ifdef PCAP_NG_DEFAULT
3147 prefs.capture_pcap_ng = TRUE;
3149 prefs.capture_pcap_ng = FALSE;
3151 prefs.capture_real_time = TRUE;
3152 prefs.capture_auto_scroll = TRUE;
3153 prefs.capture_show_info = FALSE;
3155 if (!prefs.capture_columns) {
3156 /* First time through */
3157 for (i = 0; i < num_capture_cols; i++) {
3158 col_name = g_strdup(capture_cols[i]);
3159 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3163 prefs.console_log_level =
3164 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
3166 /* set the default values for the tap/statistics dialog box */
3167 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
3168 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
3169 prefs.st_enable_burstinfo = TRUE;
3170 prefs.st_burst_showcount = FALSE;
3171 prefs.st_burst_resolution = ST_DEF_BURSTRES;
3172 prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
3173 prefs.st_sort_casesensitve = TRUE;
3174 prefs.st_sort_rng_fixorder = TRUE;
3175 prefs.st_sort_rng_nameonly = TRUE;
3176 prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
3177 prefs.st_sort_defdescending = TRUE;
3178 prefs.st_sort_showfullname = FALSE;
3179 prefs.display_hidden_proto_items = FALSE;
3180 prefs.display_byte_fields_with_spaces = FALSE;
3184 * Reset a single dissector preference.
3187 reset_pref(pref_t *pref)
3195 * This preference is no longer supported; it's not a
3196 * real preference, so we don't reset it (i.e., we
3197 * treat it as if it weren't found in the list of
3198 * preferences, and we weren't called in the first place).
3200 if (IS_PREF_OBSOLETE(type))
3203 RESET_PREF_OBSOLETE(type);
3208 *pref->varp.uint = pref->default_val.uint;
3212 *pref->varp.boolp = pref->default_val.boolval;
3217 * For now, we save the "description" value, so that if we
3218 * save the preferences older versions of Wireshark can at
3219 * least read preferences that they supported; we support
3220 * either the short name or the description when reading
3221 * the preferences file or a "-o" option.
3223 *pref->varp.enump = pref->default_val.enumval;
3229 reset_string_like_preference(pref);
3233 g_free(*pref->varp.range);
3234 *pref->varp.range = range_copy(pref->default_val.range);
3237 case PREF_STATIC_TEXT:
3243 *pref->varp.colorp = pref->default_val.color;
3247 pref->custom_cbs.reset_cb(pref);
3253 reset_pref_cb(gpointer data, gpointer user_data _U_)
3255 pref_t *pref = (pref_t *) data;
3264 * Reset all preferences for a module.
3267 reset_module_prefs(const void *key _U_, void *value, void *data _U_)
3269 reset_pref_arg_t arg;
3271 arg.module = (module_t *)value;
3272 g_list_foreach(arg.module->prefs, reset_pref_cb, &arg);
3276 /* Reset preferences */
3280 prefs_initialized = FALSE;
3281 g_free(prefs.saved_at_version);
3282 prefs.saved_at_version = NULL;
3285 * Unload all UAT preferences.
3290 * Unload any loaded MIBs.
3295 * Free the filter expression list.
3297 filter_expression_free(*pfilter_expression_head);
3298 *pfilter_expression_head = NULL;
3301 * Reset the non-dissector preferences.
3306 * Reset the non-UAT dissector preferences.
3308 wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
3311 /* Read the preferences file, fill in "prefs", and return a pointer to it.
3313 If we got an error (other than "it doesn't exist") trying to read
3314 the global preferences file, stuff the errno into "*gpf_errno_return"
3315 and a pointer to the path of the file into "*gpf_path_return", and
3318 If we got an error (other than "it doesn't exist") trying to read
3319 the user's preferences file, stuff the errno into "*pf_errno_return"
3320 and a pointer to the path of the file into "*pf_path_return", and
3323 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
3324 char **gpf_path_return, int *pf_errno_return,
3325 int *pf_read_errno_return, char **pf_path_return)
3331 /* clean up libsmi structures before reading prefs */
3337 * If we don't already have the pathname of the global preferences
3338 * file, construct it. Then, in either case, try to open the file.
3340 if (gpf_path == NULL) {
3342 * We don't have the path; try the new path first, and, if that
3343 * file doesn't exist, try the old path.
3345 gpf_path = get_datafile_path(PF_NAME);
3346 if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
3348 * It doesn't exist by the new name; try the old name.
3351 gpf_path = get_datafile_path(OLD_GPF_NAME);
3352 pf = ws_fopen(gpf_path, "r");
3356 * We have the path; try it.
3358 pf = ws_fopen(gpf_path, "r");
3362 * If we were able to open the file, read it.
3363 * XXX - if it failed for a reason other than "it doesn't exist",
3366 *gpf_path_return = NULL;
3369 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3372 mgcp_tcp_port_count = 0;
3373 mgcp_udp_port_count = 0;
3375 /* We succeeded in opening it; read it. */
3376 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
3378 /* We had an error reading the file; return the errno and the
3379 pathname, so our caller can report the error. */
3380 *gpf_errno_return = 0;
3381 *gpf_read_errno_return = err;
3382 *gpf_path_return = gpf_path;
3386 /* We failed to open it. If we failed for some reason other than
3387 "it doesn't exist", return the errno and the pathname, so our
3388 caller can report the error. */
3389 if (errno != ENOENT) {
3390 *gpf_errno_return = errno;
3391 *gpf_read_errno_return = 0;
3392 *gpf_path_return = gpf_path;
3396 /* Construct the pathname of the user's preferences file. */
3397 pf_path = get_persconffile_path(PF_NAME, TRUE);
3399 /* Read the user's preferences file, if it exists. */
3400 *pf_path_return = NULL;
3401 if ((pf = ws_fopen(pf_path, "r")) != NULL) {
3403 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3406 mgcp_tcp_port_count = 0;
3407 mgcp_udp_port_count = 0;
3409 /* We succeeded in opening it; read it. */
3410 err = read_prefs_file(pf_path, pf, set_pref, NULL);
3412 /* We had an error reading the file; return the errno and the
3413 pathname, so our caller can report the error. */
3414 *pf_errno_return = 0;
3415 *pf_read_errno_return = err;
3416 *pf_path_return = pf_path;
3421 /* We failed to open it. If we failed for some reason other than
3422 "it doesn't exist", return the errno and the pathname, so our
3423 caller can report the error. */
3424 if (errno != ENOENT) {
3425 *pf_errno_return = errno;
3426 *pf_read_errno_return = 0;
3427 *pf_path_return = pf_path;
3432 /* load SMI modules if needed */
3438 /* read the preferences file (or similar) and call the callback
3439 * function to set each key/value pair found */
3441 read_prefs_file(const char *pf_path, FILE *pf,
3442 pref_set_pair_cb pref_set_pair_fct, void *private_data)
3445 START, /* beginning of a line */
3446 IN_VAR, /* processing key name */
3447 PRE_VAL, /* finished processing key name, skipping white space befor evalue */
3448 IN_VAL, /* processing value */
3449 IN_SKIP /* skipping to the end of the line */
3454 gboolean got_val = FALSE;
3455 gint fline = 1, pline = 1;
3456 gchar hint[] = "(save preferences to remove this warning)";
3459 cur_val = g_string_new("");
3460 cur_var = g_string_new("");
3462 /* Try to read in the profile name in the first line of the preferences file. */
3463 if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
3464 /* Assume trailing period and remove it */
3465 g_free(prefs.saved_at_version);
3466 prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
3470 while ((got_c = getc(pf)) != EOF) {
3471 if (got_c == '\r') {
3472 /* Treat CR-LF at the end of a line like LF, so that if we're reading
3473 * a Windows-format file on UN*X, we handle it the same way we'd handle
3474 * a UN*X-format file. */
3478 if (got_c != '\n') {
3479 /* Put back the character after the CR, and process the CR normally. */
3484 if (got_c == '\n') {
3492 if (g_ascii_isalnum(got_c)) {
3493 if (cur_var->len > 0) {
3495 if (cur_val->len > 0) {
3496 if (cur_val->str[cur_val->len-1] == ',') {
3498 * If the pref has a trailing comma, eliminate it.
3500 cur_val->str[cur_val->len-1] = '\0';
3501 g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
3504 /* Call the routine to set the preference; it will parse
3505 the value as appropriate.
3507 Since we're reading a file, rather than processing
3508 explicit user input, for range preferences, silently
3509 lower values in excess of the range's maximum, rather
3510 than reporting errors and failing. */
3511 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3516 case PREFS_SET_SYNTAX_ERR:
3517 g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
3518 cur_var->str, pline, pf_path, hint);
3521 case PREFS_SET_NO_SUCH_PREF:
3523 * If "print.command" silently ignore it because it's valid
3524 * on non-Win32 platforms.
3526 if (strcmp(cur_var->str, "print.command") != 0)
3527 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3528 cur_var->str, pline, pf_path, hint);
3529 prefs.unknown_prefs = TRUE;
3532 case PREFS_SET_OBSOLETE:
3533 if (strcmp(cur_var->str, "print.command") != 0)
3534 /* If an attempt is made to save the preferences, a popup warning will be
3535 displayed stating that obsolete prefs have been detected and the user will
3536 be given the opportunity to save these prefs under a different profile name.
3537 The prefs in question need to be listed in the console window so that the
3538 user can make an informed choice.
3540 g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
3541 cur_var->str, pline, pf_path, hint);
3542 prefs.unknown_prefs = TRUE;
3546 g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
3551 g_string_truncate(cur_var, 0);
3552 g_string_append_c(cur_var, (gchar) got_c);
3554 } else if (g_ascii_isspace(got_c) && cur_var->len > 0 && got_val) {
3556 } else if (got_c == '#') {
3559 g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
3564 g_string_append_c(cur_var, (gchar) got_c);
3566 /* This is a colon (':') */
3568 g_string_truncate(cur_val, 0);
3570 * Set got_val to TRUE to accommodate prefs such as
3571 * "gui.fileopen.dir" that do not require a value.
3577 if (!g_ascii_isspace(got_c)) {
3579 g_string_append_c(cur_val, (gchar) got_c);
3583 g_string_append_c(cur_val, (gchar) got_c);
3589 if (cur_var->len > 0) {
3591 /* Call the routine to set the preference; it will parse
3592 the value as appropriate.
3594 Since we're reading a file, rather than processing
3595 explicit user input, for range preferences, silently
3596 lower values in excess of the range's maximum, rather
3597 than reporting errors and failing. */
3598 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3603 case PREFS_SET_SYNTAX_ERR:
3604 g_warning ("Syntax error in preference %s at line %d of\n%s %s",
3605 cur_var->str, pline, pf_path, hint);
3608 case PREFS_SET_NO_SUCH_PREF:
3609 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3610 cur_var->str, pline, pf_path, hint);
3611 prefs.unknown_prefs = TRUE;
3614 case PREFS_SET_OBSOLETE:
3615 prefs.unknown_prefs = TRUE;
3619 g_warning ("Incomplete preference at line %d of\n%s %s",
3620 pline, pf_path, hint);
3624 g_string_free(cur_val, TRUE);
3625 g_string_free(cur_var, TRUE);
3634 * If we were handed a preference starting with "uat:", try to turn it into
3635 * a valid uat entry.
3638 prefs_set_uat_pref(char *uat_entry) {
3644 colonp = strchr(uat_entry, ':');
3652 * Skip over any white space (there probably won't be any, but
3653 * as we allow it in the preferences file, we might as well
3656 while (g_ascii_isspace(*p))
3660 * Put the colon back, so if our caller uses, in an
3661 * error message, the string they passed us, the message
3668 uat = uat_find(uat_entry);
3674 ret = uat_load_str(uat, p, &err);
3680 * Given a string of the form "<pref name>:<pref value>", as might appear
3681 * as an argument to a "-o" option, parse it and set the preference in
3682 * question. Return an indication of whether it succeeded or failed
3686 prefs_set_pref(char *prefarg)
3689 prefs_set_pref_e ret;
3692 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
3693 * seen to values that keep us from trying to interpret them
3694 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
3695 * as, from the command line, we have no way of guessing which
3696 * the user had in mind.
3698 mgcp_tcp_port_count = -1;
3699 mgcp_udp_port_count = -1;
3701 colonp = strchr(prefarg, ':');
3703 return PREFS_SET_SYNTAX_ERR;
3709 * Skip over any white space (there probably won't be any, but
3710 * as we allow it in the preferences file, we might as well
3713 while (g_ascii_isspace(*p))
3717 * Put the colon back, so if our caller uses, in an
3718 * error message, the string they passed us, the message
3722 return PREFS_SET_SYNTAX_ERR;
3724 if (strcmp(prefarg, "uat")) {
3725 ret = set_pref(prefarg, p, NULL, TRUE);
3727 ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
3729 *colonp = ':'; /* put the colon back */
3734 * Returns TRUE if the given device is hidden
3737 prefs_is_capture_device_hidden(const char *name)
3739 gchar *tok, *devices;
3742 if (prefs.capture_devices_hide && name) {
3743 devices = g_strdup (prefs.capture_devices_hide);
3744 len = strlen (name);
3745 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3746 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3758 * Returns TRUE if the given column is visible (not hidden)
3761 prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
3764 fmt_data cfmt_hidden;
3767 * Do we have a list of hidden columns?
3771 * Yes - check the column against each of the ones in the
3774 cols = g_strdup(cols_hidden);
3775 for (tok = strtok(cols, ","); tok; tok = strtok(NULL, ",")) {
3776 tok = g_strstrip(tok);
3779 * Parse this column format.
3781 if (!parse_column_format(&cfmt_hidden, tok)) {
3783 * It's not valid; ignore it.
3789 * Does it match the column?
3791 if (cfmt->fmt != cfmt_hidden.fmt) {
3793 g_free(cfmt_hidden.custom_fields);
3794 cfmt_hidden.custom_fields = NULL;
3797 if (cfmt->fmt == COL_CUSTOM) {
3799 * A custom column has to have the
3800 * same custom field and occurrence.
3802 if (cfmt_hidden.custom_fields && cfmt->custom_fields) {
3803 if (strcmp(cfmt->custom_fields,
3804 cfmt_hidden.custom_fields) != 0) {
3805 /* Different fields. */
3806 g_free(cfmt_hidden.custom_fields);
3807 cfmt_hidden.custom_fields = NULL;
3810 if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
3811 /* Different occurrences. */
3812 g_free(cfmt_hidden.custom_fields);
3813 cfmt_hidden.custom_fields = NULL;
3820 * OK, they match, so it's one of the hidden fields,
3821 * hence not visible.
3823 g_free(cfmt_hidden.custom_fields);
3831 * No - either there are no hidden columns or this isn't one
3832 * of them - so it is visible.
3838 * Returns TRUE if the given device should capture in monitor mode by default
3841 prefs_capture_device_monitor_mode(const char *name)
3843 gchar *tok, *devices;
3846 if (prefs.capture_devices_monitor_mode && name) {
3847 devices = g_strdup (prefs.capture_devices_monitor_mode);
3848 len = strlen (name);
3849 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3850 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3862 * Returns TRUE if the user has marked this column as visible
3865 prefs_capture_options_dialog_column_is_visible(const gchar *column)
3870 for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
3871 col = (gchar *)curr->data;
3872 if (col && (g_ascii_strcasecmp(col, column) == 0)) {
3879 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
3880 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
3881 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
3884 * Extract the red, green, and blue components of a 24-bit RGB value
3885 * and convert them from [0,255] to [0,65535].
3887 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
3888 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
3889 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
3892 string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
3896 memset(name_resolve, 0, sizeof(e_addr_resolve));
3897 while ((c = *string++) != '\0') {
3900 name_resolve->mac_name = TRUE;
3903 name_resolve->network_name = TRUE;
3906 name_resolve->use_external_net_name_resolver = TRUE;
3909 name_resolve->transport_name = TRUE;
3912 name_resolve->concurrent_dns = TRUE;
3915 name_resolve->dns_pkt_addr_resolution = TRUE;
3919 * Unrecognized letter.
3928 try_convert_to_custom_column(gpointer *el_data)
3932 gchar **fmt = (gchar **) el_data;
3934 for (haystack_idx = 0;
3935 haystack_idx < G_N_ELEMENTS(migrated_columns);
3938 if (strcmp(migrated_columns[haystack_idx].col_fmt, *fmt) == 0) {
3939 gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
3940 migrated_columns[haystack_idx].col_expr);
3949 deprecated_heur_dissector_pref(gchar *pref_name, const gchar *value)
3951 struct heur_pref_name
3953 const char* pref_name;
3954 const char* short_name;
3955 gboolean more_dissectors; /* For multiple dissectors controlled by the same preference */
3958 struct heur_pref_name heur_prefs[] = {
3959 {"acn.heuristic_acn", "acn_udp", 0},
3960 {"bfcp.enable", "bfcp_tcp", 1},
3961 {"bfcp.enable", "bfcp_udp", 0},
3962 {"bt-dht.enable", "bittorrent_dht_udp", 0},
3963 {"bt-utp.enable", "bt_utp_udp", 0},
3964 {"cattp.enable", "cattp_udp", 0},
3965 {"cfp.enable", "fp_eth", 0},
3966 {"dicom.heuristic", "dicom_tcp", 0},
3967 {"dnp3.heuristics", "dnp3_tcp", 1},
3968 {"dnp3.heuristics", "dnp3_udp", 0},
3969 {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
3970 {"esl.enable", "esl_eth", 0},
3971 {"fp.udp_heur", "fp_udp", 0},
3972 {"gvsp.enable_heuristic", "gvsp_udp", 0},
3973 {"hdcp2.enable", "hdcp2_tcp", 0},
3974 {"hislip.enable_heuristic", "hislip_tcp", 0},
3975 {"jxta.udp.heuristic", "jxta_udp", 0},
3976 {"jxta.tcp.heuristic", "jxta_tcp", 0},
3977 {"jxta.sctp.heuristic", "jxta_sctp", 0},
3978 {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
3979 {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
3980 {"norm.heuristic_norm", "rmt_norm_udp", 0},
3981 {"openflow.heuristic", "openflow_tcp", 0},
3982 {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
3983 {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
3984 {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
3985 {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
3986 {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
3987 {"rtp.heuristic_rtp", "rtp_udp", 1},
3988 {"rtp.heuristic_rtp", "rtp_stun", 0},
3989 {"teredo.heuristic_teredo", "teredo_udp", 0},
3990 {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
3991 {"xml.heuristic", "xml_http", 1},
3992 {"xml.heuristic", "xml_sip", 1},
3993 {"xml.heuristic", "xml_media", 0},
3994 {"xml.heuristic_tcp", "xml_tcp", 0},
3995 {"xml.heuristic_udp", "xml_udp", 0},
3999 heur_dtbl_entry_t* heuristic;
4002 for (i = 0; i < sizeof(heur_prefs)/sizeof(struct heur_pref_name); i++)
4004 if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
4006 heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
4007 if (heuristic != NULL) {
4008 heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE);
4011 if (!heur_prefs[i].more_dissectors)
4020 static prefs_set_pref_e
4021 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
4022 gboolean return_range_errors)
4024 unsigned long int cval;
4029 gchar *dotp, *last_dotp;
4030 static gchar *filter_label = NULL;
4031 static gboolean filter_enabled = FALSE;
4032 gchar *filter_expr = NULL;
4033 module_t *module, *containing_module;
4037 if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
4038 filter_label = g_strdup(value);
4039 } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
4040 filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
4041 } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
4042 filter_expr = g_strdup(value);
4043 filter_expression_new(filter_label, filter_expr, filter_enabled);
4044 g_free(filter_label);
4045 g_free(filter_expr);
4046 } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
4047 /* Convert deprecated value to closest current equivalent */
4048 if (g_ascii_strcasecmp(value, "true") == 0) {
4049 prefs.gui_version_placement = version_both;
4051 prefs.gui_version_placement = version_neither;
4053 } else if (strcmp(pref_name, "name_resolve") == 0 ||
4054 strcmp(pref_name, "capture.name_resolve") == 0) {
4056 * Handle the deprecated name resolution options.
4058 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
4059 * RESOLV_ALL and RESOLV_NONE.
4061 * Otherwise, we treat it as a list of name types we want to resolve.
4063 if (g_ascii_strcasecmp(value, "true") == 0) {
4064 gbl_resolv_flags.mac_name = TRUE;
4065 gbl_resolv_flags.network_name = TRUE;
4066 gbl_resolv_flags.transport_name = TRUE;
4067 gbl_resolv_flags.concurrent_dns = TRUE;
4069 else if (g_ascii_strcasecmp(value, "false") == 0) {
4070 disable_name_resolution();
4073 /* start out with none set */
4074 disable_name_resolution();
4075 if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
4076 return PREFS_SET_SYNTAX_ERR;
4078 } else if (deprecated_heur_dissector_pref(pref_name, value)) {
4079 /* Handled within deprecated_heur_dissector_pref() if found */
4081 /* Handle deprecated "global" options that don't have a module
4082 * associated with them
4084 if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
4085 (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
4086 (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
4087 module = nameres_module;
4090 /* To which module does this preference belong? */
4092 last_dotp = pref_name;
4094 dotp = strchr(last_dotp, '.');
4096 /* Either there's no such module, or no module was specified.
4097 In either case, that means there's no such preference. */
4098 return PREFS_SET_NO_SUCH_PREF;
4100 *dotp = '\0'; /* separate module and preference name */
4101 module = prefs_find_module(pref_name);
4104 * XXX - "Diameter" rather than "diameter" was used in earlier
4105 * versions of Wireshark; if we didn't find the module, and its name
4106 * was "Diameter", look for "diameter" instead.
4108 * In addition, the BEEP protocol used to be the BXXP protocol,
4109 * so if we didn't find the module, and its name was "bxxp",
4110 * look for "beep" instead.
4112 * Also, the preferences for GTP v0 and v1 were combined under
4113 * a single "gtp" heading, and the preferences for SMPP were
4114 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
4115 * However, SMPP now has its own preferences, so we just map
4116 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
4118 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
4119 * and "nsip" to "gprs_ns".
4121 * The SynOptics Network Management Protocol (SONMP) is now known by
4122 * its modern name, the Nortel Discovery Protocol (NDP).
4124 if (module == NULL) {
4125 if (strcmp(pref_name, "column") == 0)
4126 module = gui_column_module;
4127 else if (strcmp(pref_name, "Diameter") == 0)
4128 module = prefs_find_module("diameter");
4129 else if (strcmp(pref_name, "bxxp") == 0)
4130 module = prefs_find_module("beep");
4131 else if (strcmp(pref_name, "gtpv0") == 0 ||
4132 strcmp(pref_name, "gtpv1") == 0)
4133 module = prefs_find_module("gtp");
4134 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
4135 module = prefs_find_module("gsm-sms-ud");
4136 else if (strcmp(pref_name, "dcp") == 0)
4137 module = prefs_find_module("dccp");
4138 else if (strcmp(pref_name, "x.25") == 0)
4139 module = prefs_find_module("x25");
4140 else if (strcmp(pref_name, "x411") == 0)
4141 module = prefs_find_module("p1");
4142 else if (strcmp(pref_name, "nsip") == 0)
4143 module = prefs_find_module("gprs-ns");
4144 else if (strcmp(pref_name, "sonmp") == 0)
4145 module = prefs_find_module("ndp");
4146 else if (strcmp(pref_name, "etheric") == 0 ||
4147 strcmp(pref_name, "isup_thin") == 0) {
4148 /* This protocol was removed 7. July 2009 */
4149 return PREFS_SET_OBSOLETE;
4152 g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
4153 "Save your preferences to make this change permanent.",
4154 pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
4155 prefs.unknown_prefs = TRUE;
4158 *dotp = '.'; /* put the preference string back */
4159 dotp++; /* skip past separator to preference name */
4164 /* The pref is located in the module or a submodule.
4165 * Assume module, then search for a submodule holding the pref. */
4166 containing_module = module;
4167 pref = prefs_find_preference_with_submodule(module, dotp, &containing_module);
4170 prefs.unknown_prefs = TRUE;
4172 /* "gui" prefix was added to column preferences for better organization
4173 * within the preferences file
4175 if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
4176 (strcmp(pref_name, PRS_COL_FMT) == 0)) {
4177 /* While this has a subtree, there is no apply callback, so no
4178 * need to use prefs_find_preference_with_submodule. */
4179 pref = prefs_find_preference(module, pref_name);
4181 else if (strcmp(module->name, "mgcp") == 0) {
4183 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
4184 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
4185 * were used in earlier versions of Wireshark; if we didn't find the
4186 * preference, it was an MGCP preference, and its name was
4187 * "display raw text toggle" or "display dissect tree", look for
4188 * "display_raw_text" or "display_dissect_tree" instead.
4190 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
4191 * the gateway and callagent ports were given those names; we interpret
4192 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
4193 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
4194 * they were registered by the MCCP dissector and thus that's the
4195 * order in which they were written to the preferences file. (If
4196 * we're not reading the preferences file, but are handling stuff
4197 * from a "-o" command-line option, we have no clue which the user
4198 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
4199 * or "mgcp.{tcp,udp}.callagent_port" instead.)
4201 if (strcmp(dotp, "display raw text toggle") == 0)
4202 pref = prefs_find_preference(module, "display_raw_text");
4203 else if (strcmp(dotp, "display dissect tree") == 0)
4204 pref = prefs_find_preference(module, "display_dissect_tree");
4205 else if (strcmp(dotp, "tcp.port") == 0) {
4206 mgcp_tcp_port_count++;
4207 if (mgcp_tcp_port_count == 1) {
4208 /* It's the first one */
4209 pref = prefs_find_preference(module, "tcp.gateway_port");
4210 } else if (mgcp_tcp_port_count == 2) {
4211 /* It's the second one */
4212 pref = prefs_find_preference(module, "tcp.callagent_port");
4214 /* Otherwise it's from the command line, and we don't bother
4216 } else if (strcmp(dotp, "udp.port") == 0) {
4217 mgcp_udp_port_count++;
4218 if (mgcp_udp_port_count == 1) {
4219 /* It's the first one */
4220 pref = prefs_find_preference(module, "udp.gateway_port");
4221 } else if (mgcp_udp_port_count == 2) {
4222 /* It's the second one */
4223 pref = prefs_find_preference(module, "udp.callagent_port");
4225 /* Otherwise it's from the command line, and we don't bother
4228 } else if (strcmp(module->name, "smb") == 0) {
4229 /* Handle old names for SMB preferences. */
4230 if (strcmp(dotp, "smb.trans.reassembly") == 0)
4231 pref = prefs_find_preference(module, "trans_reassembly");
4232 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
4233 pref = prefs_find_preference(module, "dcerpc_reassembly");
4234 } else if (strcmp(module->name, "ndmp") == 0) {
4235 /* Handle old names for NDMP preferences. */
4236 if (strcmp(dotp, "ndmp.desegment") == 0)
4237 pref = prefs_find_preference(module, "desegment");
4238 } else if (strcmp(module->name, "diameter") == 0) {
4239 /* Handle old names for Diameter preferences. */
4240 if (strcmp(dotp, "diameter.desegment") == 0)
4241 pref = prefs_find_preference(module, "desegment");
4242 } else if (strcmp(module->name, "pcli") == 0) {
4243 /* Handle old names for PCLI preferences. */
4244 if (strcmp(dotp, "pcli.udp_port") == 0)
4245 pref = prefs_find_preference(module, "udp_port");
4246 } else if (strcmp(module->name, "artnet") == 0) {
4247 /* Handle old names for ARTNET preferences. */
4248 if (strcmp(dotp, "artnet.udp_port") == 0)
4249 pref = prefs_find_preference(module, "udp_port");
4250 } else if (strcmp(module->name, "mapi") == 0) {
4251 /* Handle old names for MAPI preferences. */
4252 if (strcmp(dotp, "mapi_decrypt") == 0)
4253 pref = prefs_find_preference(module, "decrypt");
4254 } else if (strcmp(module->name, "fc") == 0) {
4255 /* Handle old names for Fibre Channel preferences. */
4256 if (strcmp(dotp, "reassemble_fc") == 0)
4257 pref = prefs_find_preference(module, "reassemble");
4258 else if (strcmp(dotp, "fc_max_frame_size") == 0)
4259 pref = prefs_find_preference(module, "max_frame_size");
4260 } else if (strcmp(module->name, "fcip") == 0) {
4261 /* Handle old names for Fibre Channel-over-IP preferences. */
4262 if (strcmp(dotp, "desegment_fcip_messages") == 0)
4263 pref = prefs_find_preference(module, "desegment");
4264 else if (strcmp(dotp, "fcip_port") == 0)
4265 pref = prefs_find_preference(module, "target_port");
4266 } else if (strcmp(module->name, "gtp") == 0) {
4267 /* Handle old names for GTP preferences. */
4268 if (strcmp(dotp, "gtpv0_port") == 0)
4269 pref = prefs_find_preference(module, "v0_port");
4270 else if (strcmp(dotp, "gtpv1c_port") == 0)
4271 pref = prefs_find_preference(module, "v1c_port");
4272 else if (strcmp(dotp, "gtpv1u_port") == 0)
4273 pref = prefs_find_preference(module, "v1u_port");
4274 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
4275 pref = prefs_find_preference(module, "dissect_tpdu");
4276 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
4277 pref = prefs_find_preference(module, "v0_dissect_cdr_as");
4278 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
4279 pref = prefs_find_preference(module, "v0_check_etsi");
4280 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
4281 pref = prefs_find_preference(module, "v1_check_etsi");
4282 } else if (strcmp(module->name, "ip") == 0) {
4283 /* Handle old names for IP preferences. */
4284 if (strcmp(dotp, "ip_summary_in_tree") == 0)
4285 pref = prefs_find_preference(module, "summary_in_tree");
4286 } else if (strcmp(module->name, "iscsi") == 0) {
4287 /* Handle old names for iSCSI preferences. */
4288 if (strcmp(dotp, "iscsi_port") == 0)
4289 pref = prefs_find_preference(module, "target_port");
4290 } else if (strcmp(module->name, "lmp") == 0) {
4291 /* Handle old names for LMP preferences. */
4292 if (strcmp(dotp, "lmp_version") == 0)
4293 pref = prefs_find_preference(module, "version");
4294 } else if (strcmp(module->name, "mtp3") == 0) {
4295 /* Handle old names for MTP3 preferences. */
4296 if (strcmp(dotp, "mtp3_standard") == 0)
4297 pref = prefs_find_preference(module, "standard");
4298 else if (strcmp(dotp, "net_addr_format") == 0)
4299 pref = prefs_find_preference(module, "addr_format");
4300 } else if (strcmp(module->name, "nlm") == 0) {
4301 /* Handle old names for NLM preferences. */
4302 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
4303 pref = prefs_find_preference(module, "msg_res_matching");
4304 } else if (strcmp(module->name, "ppp") == 0) {
4305 /* Handle old names for PPP preferences. */
4306 if (strcmp(dotp, "ppp_fcs") == 0)
4307 pref = prefs_find_preference(module, "fcs_type");
4308 else if (strcmp(dotp, "ppp_vj") == 0)
4309 pref = prefs_find_preference(module, "decompress_vj");
4310 } else if (strcmp(module->name, "rsvp") == 0) {
4311 /* Handle old names for RSVP preferences. */
4312 if (strcmp(dotp, "rsvp_process_bundle") == 0)
4313 pref = prefs_find_preference(module, "process_bundle");
4314 } else if (strcmp(module->name, "tcp") == 0) {
4315 /* Handle old names for TCP preferences. */
4316 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
4317 pref = prefs_find_preference(module, "summary_in_tree");
4318 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
4319 pref = prefs_find_preference(module, "analyze_sequence_numbers");
4320 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
4321 pref = prefs_find_preference(module, "relative_sequence_numbers");
4322 } else if (strcmp(module->name, "udp") == 0) {
4323 /* Handle old names for UDP preferences. */
4324 if (strcmp(dotp, "udp_summary_in_tree") == 0)
4325 pref = prefs_find_preference(module, "summary_in_tree");
4326 } else if (strcmp(module->name, "ndps") == 0) {
4327 /* Handle old names for NDPS preferences. */
4328 if (strcmp(dotp, "desegment_ndps") == 0)
4329 pref = prefs_find_preference(module, "desegment_tcp");
4330 } else if (strcmp(module->name, "http") == 0) {
4331 /* Handle old names for HTTP preferences. */
4332 if (strcmp(dotp, "desegment_http_headers") == 0)
4333 pref = prefs_find_preference(module, "desegment_headers");
4334 else if (strcmp(dotp, "desegment_http_body") == 0)
4335 pref = prefs_find_preference(module, "desegment_body");
4336 } else if (strcmp(module->name, "smpp") == 0) {
4337 /* Handle preferences that moved from SMPP. */
4338 module_t *new_module = prefs_find_module("gsm-sms-ud");
4340 if (strcmp(dotp, "port_number_udh_means_wsp") == 0) {
4341 pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
4342 containing_module = new_module;
4343 } else if (strcmp(dotp, "try_dissect_1st_fragment") == 0) {
4344 pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
4345 containing_module = new_module;
4348 } else if (strcmp(module->name, "asn1") == 0) {
4349 /* Handle old generic ASN.1 preferences (it's not really a
4350 rename, as the new preferences support multiple ports,
4351 but we might as well copy them over). */
4352 if (strcmp(dotp, "tcp_port") == 0)
4353 pref = prefs_find_preference(module, "tcp_ports");
4354 else if (strcmp(dotp, "udp_port") == 0)
4355 pref = prefs_find_preference(module, "udp_ports");
4356 else if (strcmp(dotp, "sctp_port") == 0)
4357 pref = prefs_find_preference(module, "sctp_ports");
4358 } else if (strcmp(module->name, "llcgprs") == 0) {
4359 if (strcmp(dotp, "ignore_cipher_bit") == 0)
4360 pref = prefs_find_preference(module, "autodetect_cipher_bit");
4361 } else if (strcmp(module->name, "erf") == 0) {
4362 if (strcmp(dotp, "erfeth") == 0) {
4363 /* Handle the old "erfeth" preference; map it to the new
4364 "ethfcs" preference, and map the values to those for
4365 the new preference. */
4366 pref = prefs_find_preference(module, "ethfcs");
4367 if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
4369 else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
4371 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4373 } else if (strcmp(dotp, "erfatm") == 0) {
4374 /* Handle the old "erfatm" preference; map it to the new
4375 "aal5_type" preference, and map the values to those for
4376 the new preference. */
4377 pref = prefs_find_preference(module, "aal5_type");
4378 if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
4380 else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
4382 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4384 } else if (strcmp(dotp, "erfhdlc") == 0) {
4385 /* Handle the old "erfhdlc" preference; map it to the new
4386 "hdlc_type" preference, and map the values to those for
4387 the new preference. */
4388 pref = prefs_find_preference(module, "hdlc_type");
4389 if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
4391 else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
4393 else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
4395 else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
4397 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4400 } else if (strcmp(module->name, "eth") == 0) {
4401 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
4402 if (strcmp(dotp, "qinq_ethertype") == 0) {
4403 module_t *new_module = prefs_find_module("vlan");
4405 pref = prefs_find_preference(new_module, "qinq_ethertype");
4406 containing_module = new_module;
4409 } else if (strcmp(module->name, "taps") == 0) {
4410 /* taps preferences moved to "statistics" module */
4411 if (strcmp(dotp, "update_interval") == 0 ||
4412 strcmp(dotp, "rtp_player_max_visible") == 0)
4413 pref = prefs_find_preference(stats_module, dotp);
4414 } else if (strcmp(module->name, "packet_list") == 0) {
4415 /* packet_list preferences moved to protocol module */
4416 if (strcmp(dotp, "display_hidden_proto_items") == 0)
4417 pref = prefs_find_preference(protocols_module, dotp);
4418 } else if (strcmp(module->name, "stream") == 0) {
4419 /* stream preferences moved to gui color module */
4420 if ((strcmp(dotp, "client.fg") == 0) ||
4421 (strcmp(dotp, "client.bg") == 0) ||
4422 (strcmp(dotp, "server.fg") == 0) ||
4423 (strcmp(dotp, "server.bg") == 0))
4424 pref = prefs_find_preference(gui_color_module, pref_name);
4425 } else if (strcmp(module->name, "nameres") == 0) {
4426 if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
4427 pref = prefs_find_preference(nameres_module, pref_name);
4428 } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
4429 pref = prefs_find_preference(nameres_module, "load_smi_modules");
4430 } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
4431 pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
4436 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
4439 if (IS_PREF_OBSOLETE(type)) {
4440 return PREFS_SET_OBSOLETE; /* no such preference any more */
4442 RESET_PREF_OBSOLETE(type);
4448 /* XXX - give an error if it doesn't fit in a guint? */
4449 uval = (guint)strtoul(value, &p, pref->info.base);
4450 if (p == value || *p != '\0')
4451 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4452 if (*pref->varp.uint != uval) {
4453 containing_module->prefs_changed = TRUE;
4454 *pref->varp.uint = uval;
4459 /* XXX - give an error if it's neither "true" nor "false"? */
4460 if (g_ascii_strcasecmp(value, "true") == 0)
4464 if (*pref->varp.boolp != bval) {
4465 containing_module->prefs_changed = TRUE;
4466 *pref->varp.boolp = bval;
4471 /* XXX - give an error if it doesn't match? */
4472 enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
4474 if (*pref->varp.enump != enum_val) {
4475 containing_module->prefs_changed = TRUE;
4476 *pref->varp.enump = enum_val;
4483 prefs_set_string_like_value(pref, value, &containing_module->prefs_changed);
4488 if (!prefs_set_range_value_work(pref, value, return_range_errors,
4489 &containing_module->prefs_changed))
4490 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4496 cval = strtoul(value, NULL, 16);
4497 if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
4498 (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
4499 (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
4500 containing_module->prefs_changed = TRUE;
4501 pref->varp.colorp->red = RED_COMPONENT(cval);
4502 pref->varp.colorp->green = GREEN_COMPONENT(cval);
4503 pref->varp.colorp->blue = BLUE_COMPONENT(cval);
4509 return pref->custom_cbs.set_cb(pref, value, &containing_module->prefs_changed);
4511 case PREF_STATIC_TEXT:
4519 return PREFS_SET_OK;
4524 gboolean is_gui_module;
4525 } write_gui_pref_arg_t;
4528 prefs_pref_type_name(pref_t *pref)
4530 const char *type_name = "[Unknown]";
4534 return type_name; /* ...or maybe assert? */
4539 if (IS_PREF_OBSOLETE(type)) {
4540 type_name = "Obsolete";
4542 RESET_PREF_OBSOLETE(type);
4548 switch (pref->info.base) {
4551 type_name = "Decimal";
4555 type_name = "Octal";
4559 type_name = "Hexadecimal";
4565 type_name = "Boolean";
4569 type_name = "Choice";
4573 type_name = "String";
4577 type_name = "Filename";
4581 type_name = "Directory";
4585 type_name = "Range";
4589 type_name = "Color";
4593 if (pref->custom_cbs.type_name_cb)
4594 return pref->custom_cbs.type_name_cb();
4595 type_name = "Custom";
4598 case PREF_STATIC_TEXT:
4599 type_name = "Static text";
4610 prefs_pref_type_description(pref_t *pref)
4612 const char *type_desc = "An unknown preference type";
4616 return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
4621 if (IS_PREF_OBSOLETE(type)) {
4622 type_desc = "An obsolete preference";
4624 RESET_PREF_OBSOLETE(type);
4630 switch (pref->info.base) {
4633 type_desc = "A decimal number";
4637 type_desc = "An octal number";
4641 type_desc = "A hexadecimal number";
4647 type_desc = "TRUE or FALSE (case-insensitive)";
4652 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4653 GString *enum_str = g_string_new("One of: ");
4654 while (enum_valp->name != NULL) {
4655 g_string_append(enum_str, enum_valp->description);
4657 if (enum_valp->name != NULL)
4658 g_string_append(enum_str, ", ");
4660 g_string_append(enum_str, "\n(case-insensitive).");
4661 return g_string_free(enum_str, FALSE);
4666 type_desc = "A string";
4670 type_desc = "A path to a file";
4674 type_desc = "A path to a directory";
4679 type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
4685 type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
4690 if (pref->custom_cbs.type_description_cb)
4691 return pref->custom_cbs.type_description_cb();
4692 type_desc = "A custom value";
4695 case PREF_STATIC_TEXT:
4696 type_desc = "[Static text]";
4700 type_desc = "Configuration data stored in its own file";
4706 return g_strdup(type_desc);
4710 prefs_pref_is_default(pref_t *pref)
4713 if (!pref) return FALSE;
4716 if (IS_PREF_OBSOLETE(type)) {
4719 RESET_PREF_OBSOLETE(type);
4725 if (pref->default_val.uint == *pref->varp.uint)
4730 if (pref->default_val.boolval == *pref->varp.boolp)
4735 if (pref->default_val.enumval == *pref->varp.enump)
4742 if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
4748 if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
4755 if ((pref->default_val.color.red == pref->varp.colorp->red) &&
4756 (pref->default_val.color.green == pref->varp.colorp->green) &&
4757 (pref->default_val.color.blue == pref->varp.colorp->blue))
4763 return pref->custom_cbs.is_default_cb(pref);
4765 case PREF_STATIC_TEXT:
4768 /* g_assert_not_reached(); */
4775 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
4776 const char *pref_text = "[Unknown]";
4777 void *valp; /* pointer to preference value */
4778 color_t *pref_color;
4779 gchar *tmp_value, *ret_value;
4783 return g_strdup(pref_text);
4788 valp = &pref->default_val;
4789 /* valp = &boolval, &enumval, etc. are implied by union property */
4790 pref_color = &pref->default_val.color;
4793 valp = &pref->stashed_val;
4794 /* valp = &boolval, &enumval, etc. are implied by union property */
4795 pref_color = &pref->stashed_val.color;
4798 valp = pref->varp.uint;
4799 /* valp = boolval, enumval, etc. are implied by union property */
4800 pref_color = pref->varp.colorp;
4803 return g_strdup(pref_text);
4807 if (IS_PREF_OBSOLETE(type)) {
4808 pref_text = "[Obsolete]";
4810 RESET_PREF_OBSOLETE(type);
4817 guint pref_uint = *(guint *) valp;
4818 switch (pref->info.base) {
4821 return g_strdup_printf("%u", pref_uint);
4824 return g_strdup_printf("%#o", pref_uint);
4827 return g_strdup_printf("%#x", pref_uint);
4833 return g_strdup_printf("%s", (*(gboolean *) valp) ? "TRUE" : "FALSE");
4837 gint pref_enumval = *(gint *) valp;
4839 * For now, we return the "description" value, so that if we
4840 * save the preferences older versions of Wireshark can at
4841 * least read preferences that they supported; we support
4842 * either the short name or the description when reading
4843 * the preferences file or a "-o" option.
4845 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4846 while (enum_valp->name != NULL) {
4847 if (enum_valp->value == pref_enumval)
4848 return g_strdup(enum_valp->description);
4857 return g_strdup(*(const char **) valp);
4860 /* Convert wmem to g_alloc memory */
4861 tmp_value = range_convert_range(NULL, *(range_t **) valp);
4862 ret_value = g_strdup(tmp_value);
4863 wmem_free(NULL, tmp_value);
4867 return g_strdup_printf("%02x%02x%02x",
4868 (pref_color->red * 255 / 65535),
4869 (pref_color->green * 255 / 65535),
4870 (pref_color->blue * 255 / 65535));
4873 if (pref->custom_cbs.to_str_cb)
4874 return pref->custom_cbs.to_str_cb(pref, source == pref_default ? TRUE : FALSE);
4875 pref_text = "[Custom]";
4878 case PREF_STATIC_TEXT:
4879 pref_text = "[Static text]";
4884 uat_t *uat = pref->varp.uat;
4885 if (uat && uat->filename)
4886 return g_strdup_printf("[Managed in the file \"%s\"]", uat->filename);
4888 pref_text = "[Managed in an unknown file]";
4895 return g_strdup(pref_text);
4899 * Write out a single dissector preference.
4902 write_pref(gpointer data, gpointer user_data)
4904 pref_t *pref = (pref_t *)data;
4905 write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
4911 if (IS_PREF_OBSOLETE(type)) {
4913 * This preference is no longer supported; it's not a
4914 * real preference, so we don't write it out (i.e., we
4915 * treat it as if it weren't found in the list of
4916 * preferences, and we weren't called in the first place).
4920 RESET_PREF_OBSOLETE(type);
4925 case PREF_STATIC_TEXT:
4927 /* Nothing to do; don't bother printing the description */
4933 if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL) {
4935 * The prefix will either be the module name or the parent
4936 * name if it's a subtree
4938 const char *name_prefix = (arg->module->name != NULL) ? arg->module->name : arg->module->parent->name;
4939 char *type_desc, *pref_text;
4940 const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
4942 if (pref->type == PREF_CUSTOM) fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
4943 fprintf(arg->pf, "\n");
4944 if (pref->description &&
4945 (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
4946 if (pref->type != PREF_CUSTOM) {
4947 /* We get duplicate lines otherwise. */
4949 desc_lines = g_strsplit(pref->description,"\n",0);
4950 for (i = 0; desc_lines[i] != NULL; ++i) {
4951 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4953 g_strfreev(desc_lines);
4956 fprintf(arg->pf, "# No description\n");
4959 type_desc = prefs_pref_type_description(pref);
4960 desc_lines = g_strsplit(type_desc,"\n",0);
4961 for (i = 0; desc_lines[i] != NULL; ++i) {
4962 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4964 g_strfreev(desc_lines);
4967 pref_text = prefs_pref_to_str(pref, pref_current);
4968 fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
4969 desc_lines = g_strsplit(pref_text,"\n",0);
4970 for (i = 0; desc_lines[i] != NULL; ++i) {
4971 fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
4973 if (i == 0) fprintf(arg->pf, "\n");
4974 g_strfreev(desc_lines);
4981 * Write out all preferences for a module.
4984 write_module_prefs(module_t *module, gpointer user_data)
4986 write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
4987 write_pref_arg_t arg;
4989 /* The GUI module needs to be explicitly called out so it
4990 can be written out of order */
4991 if ((module == gui_module) && (gui_pref_arg->is_gui_module != TRUE))
4994 /* Write a header for the main modules and GUI sub-modules */
4995 if (((module->parent == NULL) || (module->parent == gui_module)) &&
4996 ((prefs_module_has_submodules(module)) ||
4997 (module->numprefs > 0) ||
4998 (module->name == NULL))) {
4999 if ((module->name == NULL) && (module->parent != NULL)) {
5000 fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
5002 fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
5006 arg.module = module;
5007 arg.pf = gui_pref_arg->pf;
5008 g_list_foreach(arg.module->prefs, write_pref, &arg);
5010 if (prefs_module_has_submodules(module))
5011 return prefs_modules_foreach_submodules(module, write_module_prefs, user_data);
5016 /* Write out "prefs" to the user's preferences file, and return 0.
5018 If the preferences file path is NULL, write to stdout.
5020 If we got an error, stuff a pointer to the path of the preferences file
5021 into "*pf_path_return", and return the errno. */
5023 write_prefs(char **pf_path_return)
5027 write_gui_pref_arg_t write_gui_pref_info;
5029 /* Needed for "-G defaultprefs" */
5033 * - Split output lines longer than MAX_VAL_LEN
5034 * - Create a function for the preference directory check/creation
5035 * so that duplication can be avoided with filter.c
5038 if (pf_path_return != NULL) {
5039 pf_path = get_persconffile_path(PF_NAME, TRUE);
5040 if ((pf = ws_fopen(pf_path, "w")) == NULL) {
5041 *pf_path_return = pf_path;
5049 fputs("# Configuration file for Wireshark " VERSION ".\n"
5051 "# This file is regenerated each time preferences are saved within\n"
5052 "# Wireshark. Making manual changes should be safe, however.\n"
5053 "# Preferences that have been commented out have not been\n"
5054 "# changed from their default value.\n", pf);
5057 * For "backwards compatibility" the GUI module is written first as it's
5058 * at the top of the file. This is followed by all modules that can't
5059 * fit into the preferences read/write API. Finally the remaining modules
5060 * are written in alphabetical order (including of course the protocol preferences)
5062 write_gui_pref_info.pf = pf;
5063 write_gui_pref_info.is_gui_module = TRUE;
5065 write_module_prefs(gui_module, &write_gui_pref_info);
5068 struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
5071 fprintf(pf, "\n####### Filter Expressions ########\n\n");
5073 while (fe != NULL) {
5074 if (fe->deleted == FALSE) {
5075 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
5076 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
5077 fe->enabled == TRUE ? "TRUE" : "FALSE");
5078 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
5084 write_gui_pref_info.is_gui_module = FALSE;
5085 prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
5089 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
5090 an error indication, or maybe write to a new preferences file and
5091 rename that file on top of the old one only if there are not I/O
5096 /** The col_list is only partly managed by the custom preference API
5097 * because its data is shared between multiple preferences, so
5101 free_col_info(GList *list)
5104 GList *list_head = list;
5106 while (list != NULL) {
5107 cfmt = (fmt_data *)list->data;
5109 g_free(cfmt->title);
5110 g_free(cfmt->custom_fields);
5112 list = g_list_next(list);
5114 g_list_free(list_head);
5123 * indent-tabs-mode: nil
5126 * ex: set shiftwidth=4 tabstop=8 expandtab:
5127 * :indentSize=4:tabSize=8:noTabs=true: