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.
36 #include <wsutil/filesystem.h>
37 #include <epan/address.h>
38 #include <epan/addr_resolv.h>
39 #include <epan/oids.h>
41 #include <epan/geoip_db.h>
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/proto.h>
46 #include <epan/strutil.h>
47 #include <epan/column.h>
49 #include <wsutil/file_util.h>
51 #include <epan/prefs-int.h>
52 #include <epan/uat-int.h>
54 #include "epan/filter_expressions.h"
56 #include "epan/wmem/wmem.h"
57 #include <epan/stats_tree.h>
59 /* Internal functions */
60 static module_t *find_subtree(module_t *parent, const char *tilte);
61 static module_t *prefs_register_module_or_subtree(module_t *parent,
62 const char *name, const char *title, const char *description, gboolean is_subtree,
63 void (*apply_cb)(void), gboolean use_gui);
64 static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
65 static void free_col_info(GList *);
66 static void pre_init_prefs(void);
67 static gboolean prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt);
68 static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
69 static void try_convert_to_custom_column(gpointer *el_data);
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_pref(gpointer data, gpointer user_data _U_)
228 pref_t *pref = (pref_t *)data;
230 switch (pref->type) {
235 case PREF_STATIC_TEXT:
242 g_free((char *)*pref->varp.string);
243 *pref->varp.string = NULL;
244 g_free(pref->default_val.string);
245 pref->default_val.string = NULL;
248 g_free(*pref->varp.range);
249 *pref->varp.range = NULL;
250 g_free(pref->default_val.range);
251 pref->default_val.range = NULL;
254 if (strcmp(pref->name, "columns") == 0)
255 pref->stashed_val.boolval = TRUE;
256 pref->custom_cbs.free_cb(pref);
264 free_module_prefs(module_t *module, gpointer data _U_)
267 g_list_foreach(module->prefs, free_pref, NULL);
268 g_list_free(module->prefs);
270 module->prefs = NULL;
271 module->numprefs = 0;
272 if (module->submodules) {
273 prefs_modules_foreach_submodules(module, free_module_prefs, NULL);
275 /* We don't free the actual module: its submodules pointer points to
276 a wmem_tree and the module itself is stored in a wmem_tree
282 /** Frees memory used by proto routines. Called at program shutdown */
286 /* This isn't strictly necessary since we're exiting anyway, but let's
287 * do what clean up we can.
289 prefs_modules_foreach(free_module_prefs, NULL);
293 * Register a module that will have preferences.
294 * Specify the module under which to register it or NULL to register it
295 * at the top level, the name used for the module in the preferences file,
296 * the title used in the tab for it in a preferences dialog box, and a
297 * routine to call back when we apply the preferences.
300 prefs_register_module(module_t *parent, const char *name, const char *title,
301 const char *description, void (*apply_cb)(void),
302 const gboolean use_gui)
304 return prefs_register_module_or_subtree(parent, name, title, description,
305 FALSE, apply_cb, use_gui);
309 prefs_deregister_module(module_t *parent, const char *name, const char *title)
311 /* Remove this module from the list of all modules */
312 module_t *module = (module_t *)wmem_tree_remove_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
317 if (parent == NULL) {
318 /* Remove from top */
319 wmem_tree_remove_string(prefs_top_level_modules, title, WMEM_TREE_STRING_NOCASE);
320 } else if (parent->submodules) {
321 /* Remove from parent */
322 wmem_tree_remove_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE);
325 free_module_prefs(module, NULL);
326 wmem_free(wmem_epan_scope(), module);
330 * Register a subtree that will have modules under it.
331 * Specify the module under which to register it or NULL to register it
332 * at the top level and the title used in the tab for it in a preferences
336 prefs_register_subtree(module_t *parent, const char *title, const char *description,
337 void (*apply_cb)(void))
339 return prefs_register_module_or_subtree(parent, NULL, title, description,
341 parent ? parent->use_gui : FALSE);
345 prefs_register_module_or_subtree(module_t *parent, const char *name,
346 const char *title, const char *description,
347 gboolean is_subtree, void (*apply_cb)(void),
354 /* this module may have been created as a subtree item previously */
355 if ((module = find_subtree(parent, title))) {
356 /* the module is currently a subtree */
358 module->apply_cb = apply_cb;
359 module->description = description;
361 if (prefs_find_module(name) == NULL) {
362 wmem_tree_insert_string(prefs_modules, name, module,
363 WMEM_TREE_STRING_NOCASE);
369 module = wmem_new(wmem_epan_scope(), module_t);
371 module->title = title;
372 module->description = description;
373 module->apply_cb = apply_cb;
374 module->prefs = NULL; /* no preferences, to start */
375 module->parent = parent;
376 module->submodules = NULL; /* no submodules, to start */
377 module->numprefs = 0;
378 module->prefs_changed = FALSE;
379 module->obsolete = FALSE;
380 module->use_gui = use_gui;
383 * Do we have a module name?
388 * Make sure that only lower-case ASCII letters, numbers,
389 * underscores, hyphens, and dots appear in the name.
391 * Crash if there is, as that's an error in the code;
392 * you can make the title a nice string with capitalization,
393 * white space, punctuation, etc., but the name can be used
394 * on the command line, and shouldn't require quoting,
397 for (p = name; (c = *p) != '\0'; p++)
398 g_assert(g_ascii_islower(c) || g_ascii_isdigit(c) || c == '_' ||
399 c == '-' || c == '.');
402 * Make sure there's not already a module with that
403 * name. Crash if there is, as that's an error in the
404 * code, and the code has to be fixed not to register
405 * more than one module with the same name.
407 * We search the list of all modules; the subtree stuff
408 * doesn't require preferences in subtrees to have names
409 * that reflect the subtree they're in (that would require
410 * protocol preferences to have a bogus "protocol.", or
411 * something such as that, to be added to all their names).
413 g_assert(prefs_find_module(name) == NULL);
416 * Insert this module in the list of all modules.
418 wmem_tree_insert_string(prefs_modules, name, module, WMEM_TREE_STRING_NOCASE);
421 * This has no name, just a title; check to make sure it's a
422 * subtree, and crash if it's not.
424 g_assert(is_subtree);
428 * Insert this module into the appropriate place in the display
431 if (parent == NULL) {
433 * It goes at the top.
435 wmem_tree_insert_string(prefs_top_level_modules, title, module, WMEM_TREE_STRING_NOCASE);
438 * It goes into the list for this module.
441 if (parent->submodules == NULL)
442 parent->submodules = wmem_tree_new(wmem_epan_scope());
444 wmem_tree_insert_string(parent->submodules, title, module, WMEM_TREE_STRING_NOCASE);
451 * Register that a protocol has preferences.
453 module_t *protocols_module = NULL;
456 prefs_register_protocol(int id, void (*apply_cb)(void))
458 protocol_t *protocol;
461 * Have we yet created the "Protocols" subtree?
463 if (protocols_module == NULL) {
465 * No. Register Protocols subtree as well as any preferences
466 * for non-dissector modules.
469 prefs_register_modules();
471 protocol = find_protocol_by_id(id);
472 return prefs_register_module(protocols_module,
473 proto_get_protocol_filter_name(id),
474 proto_get_protocol_short_name(protocol),
475 proto_get_protocol_name(id), apply_cb, TRUE);
479 prefs_deregister_protocol (int id)
481 protocol_t *protocol = find_protocol_by_id(id);
482 prefs_deregister_module (protocols_module,
483 proto_get_protocol_filter_name(id),
484 proto_get_protocol_short_name(protocol));
488 prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
490 protocol_t *protocol;
491 module_t *subtree_module;
492 module_t *new_module;
493 char *sep = NULL, *ptr = NULL, *orig = NULL;
496 * Have we yet created the "Protocols" subtree?
497 * XXX - can we just do this by registering Protocols/{subtree}?
500 if (protocols_module == NULL) {
502 * No. Register Protocols subtree as well as any preferences
503 * for non-dissector modules.
506 prefs_register_modules();
509 subtree_module = protocols_module;
512 /* take a copy of the buffer, orig keeps a base pointer while ptr
513 * walks through the string */
514 orig = ptr = g_strdup(subtree);
516 while (ptr && *ptr) {
518 if ((sep = strchr(ptr, '/')))
521 if (!(new_module = find_subtree(subtree_module, ptr))) {
523 * There's no such module; create it, with the description
524 * being the name (if it's later registered explicitly
525 * with a description, that will override it).
527 ptr = wmem_strdup(wmem_epan_scope(), ptr),
528 new_module = prefs_register_subtree(subtree_module, ptr, ptr, NULL);
531 subtree_module = new_module;
539 protocol = find_protocol_by_id(id);
540 return prefs_register_module(subtree_module,
541 proto_get_protocol_filter_name(id),
542 proto_get_protocol_short_name(protocol),
543 proto_get_protocol_name(id), apply_cb, TRUE);
548 * Register that a protocol used to have preferences but no longer does,
549 * by creating an "obsolete" module for it.
552 prefs_register_protocol_obsolete(int id)
555 protocol_t *protocol;
558 * Have we yet created the "Protocols" subtree?
560 if (protocols_module == NULL) {
562 * No. Register Protocols subtree as well as any preferences
563 * for non-dissector modules.
566 prefs_register_modules();
568 protocol = find_protocol_by_id(id);
569 module = prefs_register_module(protocols_module,
570 proto_get_protocol_filter_name(id),
571 proto_get_protocol_short_name(protocol),
572 proto_get_protocol_name(id), NULL, TRUE);
573 module->obsolete = TRUE;
578 * Register that a statistical tap has preferences.
580 * "name" is a name for the tap to use on the command line with "-o"
581 * and in preference files.
583 * "title" is a short human-readable name for the tap.
585 * "description" is a longer human-readable description of the tap.
587 module_t *stats_module = NULL;
590 prefs_register_stat(const char *name, const char *title,
591 const char *description, void (*apply_cb)(void))
594 * Have we yet created the "Statistics" subtree?
596 if (stats_module == NULL) {
598 * No. Register Statistics subtree as well as any preferences
599 * for non-dissector modules.
602 prefs_register_modules();
605 return prefs_register_module(stats_module, name, title, description,
610 prefs_find_module(const char *name)
612 return (module_t *)wmem_tree_lookup_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
616 find_subtree(module_t *parent, const char *name)
618 return (module_t *)wmem_tree_lookup_string(parent ? parent->submodules : prefs_top_level_modules, name, WMEM_TREE_STRING_NOCASE);
622 * Call a callback function, with a specified argument, for each module
623 * in a list of modules. If the list is NULL, searches the top-level
624 * list in the display tree of modules. If any callback returns a
625 * non-zero value, we stop and return that value, otherwise we
628 * Ignores "obsolete" modules; their sole purpose is to allow old
629 * preferences for dissectors that no longer have preferences to be
630 * silently ignored in preference files. Does not ignore subtrees,
631 * as this can be used when walking the display tree of modules.
641 call_foreach_cb(void *value, void *data)
643 module_t *module = (module_t*)value;
644 call_foreach_t *call_data = (call_foreach_t*)data;
646 if (!module->obsolete)
647 call_data->ret = (*call_data->callback)(module, call_data->user_data);
649 return (call_data->ret != 0);
653 prefs_module_list_foreach(wmem_tree_t *module_list, module_cb callback,
656 call_foreach_t call_data;
658 if (module_list == NULL)
659 module_list = prefs_top_level_modules;
661 call_data.callback = callback;
662 call_data.user_data = user_data;
664 wmem_tree_foreach(module_list, call_foreach_cb, &call_data);
665 return call_data.ret;
669 * Returns TRUE if module has any submodules
672 prefs_module_has_submodules(module_t *module)
674 if (module->submodules == NULL) {
678 if (wmem_tree_is_empty(module->submodules)) {
686 * Call a callback function, with a specified argument, for each module
687 * in the list of all modules. (This list does not include subtrees.)
689 * Ignores "obsolete" modules; their sole purpose is to allow old
690 * preferences for dissectors that no longer have preferences to be
691 * silently ignored in preference files.
694 prefs_modules_foreach(module_cb callback, gpointer user_data)
696 return prefs_module_list_foreach(prefs_modules, callback, user_data);
700 * Call a callback function, with a specified argument, for each submodule
701 * of specified modules. If the module is NULL, goes through the top-level
702 * list in the display tree of modules.
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. Does not ignore subtrees,
707 * as this can be used when walking the display tree of modules.
710 prefs_modules_foreach_submodules(module_t *module, module_cb callback,
713 return prefs_module_list_foreach((module)?module->submodules:prefs_top_level_modules, callback, user_data);
717 call_apply_cb(void *value, void *data _U_)
719 module_t *module = (module_t *)value;
721 if (module->obsolete)
723 if (module->prefs_changed) {
724 if (module->apply_cb != NULL)
725 (*module->apply_cb)();
726 module->prefs_changed = FALSE;
732 * Call the "apply" callback function for each module if any of its
733 * preferences have changed, and then clear the flag saying its
734 * preferences have changed, as the module has been notified of that
738 prefs_apply_all(void)
740 wmem_tree_foreach(prefs_modules, call_apply_cb, NULL);
744 * Call the "apply" callback function for a specific module if any of
745 * its preferences have changed, and then clear the flag saying its
746 * preferences have changed, as the module has been notified of that
750 prefs_apply(module_t *module)
752 if (module && module->prefs_changed)
753 call_apply_cb(module, NULL);
757 * Register a preference in a module's list of preferences.
758 * If it has a title, give it an ordinal number; otherwise, it's a
759 * preference that won't show up in the UI, so it shouldn't get an
760 * ordinal number (the ordinal should be the ordinal in the set of
761 * *visible* preferences).
764 register_preference(module_t *module, const char *name, const char *title,
765 const char *description, pref_type_t type)
770 preference = g_new(pref_t,1);
771 preference->name = name;
772 preference->title = title;
773 preference->description = description;
774 preference->type = type;
775 preference->gui = GUI_ALL; /* default */
777 preference->ordinal = module->numprefs;
779 preference->ordinal = -1; /* no ordinal for you */
782 * Make sure that only lower-case ASCII letters, numbers,
783 * underscores, and dots appear in the preference name.
785 * Crash if there is, as that's an error in the code;
786 * you can make the title and description nice strings
787 * with capitalization, white space, punctuation, etc.,
788 * but the name can be used on the command line,
789 * and shouldn't require quoting, shifting, etc.
791 for (p = name; *p != '\0'; p++)
792 if (!(g_ascii_islower(*p) || g_ascii_isdigit(*p) || *p == '_' || *p == '.'))
793 g_error("Preference %s.%s contains invalid characters", module->name, name);
796 * Make sure there's not already a preference with that
797 * name. Crash if there is, as that's an error in the
798 * code, and the code has to be fixed not to register
799 * more than one preference with the same name.
801 if (prefs_find_preference(module, name) != NULL)
802 g_error("Preference %s has already been registered", name);
804 if ((type != PREF_OBSOLETE) &&
805 /* Don't compare if it's a subtree */
806 (module->name != NULL)) {
808 * Make sure the preference name doesn't begin with the
809 * module name, as that's redundant and Just Silly.
811 if (!((strncmp(name, module->name, strlen(module->name)) != 0) ||
812 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_'))))
813 g_error("Preference %s begins with the module name", name);
817 * There isn't already one with that name, so add the
820 module->prefs = g_list_append(module->prefs, preference);
828 * Find a preference in a module's list of preferences, given the module
829 * and the preference's name.
837 preference_match(gconstpointer a, gconstpointer b)
839 const pref_t *pref = (const pref_t *)a;
840 const char *name = (const char *)b;
842 return strcmp(name, pref->name);
846 module_find_pref_cb(void *value, void *data)
848 find_pref_arg_t* arg = (find_pref_arg_t*)data;
850 module_t *module = (module_t *)value;
855 list_entry = g_list_find_custom(module->prefs, arg->name,
858 if (list_entry == NULL)
861 arg->list_entry = list_entry;
866 prefs_find_preference(module_t *module, const char *name)
872 return NULL; /* invalid parameters */
874 list_entry = g_list_find_custom(module->prefs, name,
877 if (list_entry == NULL)
879 arg.list_entry = NULL;
880 if (module->submodules != NULL)
883 wmem_tree_foreach(module->submodules, module_find_pref_cb, &arg);
886 list_entry = arg.list_entry;
889 if (list_entry == NULL)
890 return NULL; /* no such preference */
892 return (struct preference *) list_entry->data;
896 * Returns TRUE if the given protocol has registered preferences
899 prefs_is_registered_protocol(const char *name)
901 module_t *m = prefs_find_module(name);
903 return (m != NULL && !m->obsolete);
907 * Returns the module title of a registered protocol
910 prefs_get_title_by_name(const char *name)
912 module_t *m = prefs_find_module(name);
914 return (m != NULL && !m->obsolete) ? m->title : NULL;
918 * Register a preference with an unsigned integral value.
921 prefs_register_uint_preference(module_t *module, const char *name,
922 const char *title, const char *description,
923 guint base, guint *var)
927 preference = register_preference(module, name, title, description,
929 preference->varp.uint = var;
930 preference->default_val.uint = *var;
931 g_assert(base > 0 && base != 1 && base < 37);
932 preference->info.base = base;
936 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
941 * Register a "custom" preference with a unsigned integral value.
942 * XXX - This should be temporary until we can find a better way
943 * to do "custom" preferences
946 prefs_register_uint_custom_preference(module_t *module, const char *name,
947 const char *title, const char *description,
948 struct pref_custom_cbs* custom_cbs, guint *var)
952 preference = register_preference(module, name, title, description,
955 preference->custom_cbs = *custom_cbs;
956 preference->varp.uint = var;
957 preference->default_val.uint = *var;
961 * Register a preference with an Boolean value.
964 prefs_register_bool_preference(module_t *module, const char *name,
965 const char *title, const char *description,
970 preference = register_preference(module, name, title, description,
972 preference->varp.boolp = var;
973 preference->default_val.boolval = *var;
977 * Register a preference with an enumerated value.
980 prefs_register_enum_preference(module_t *module, const char *name,
981 const char *title, const char *description,
982 gint *var, const enum_val_t *enumvals,
983 gboolean radio_buttons)
987 preference = register_preference(module, name, title, description,
989 preference->varp.enump = var;
990 preference->default_val.enumval = *var;
991 preference->info.enum_info.enumvals = enumvals;
992 preference->info.enum_info.radio_buttons = radio_buttons;
996 register_string_like_preference(module_t *module, const char *name,
997 const char *title, const char *description,
998 const char **var, pref_type_t type)
1003 preference = register_preference(module, name, title, description,
1007 * String preference values should be non-null (as you can't
1008 * keep them null after using the preferences GUI, you can at best
1009 * have them be null strings) and freeable (as we free them
1010 * if we change them).
1012 * If the value is a null pointer, make it a copy of a null
1013 * string, otherwise make it a copy of the value.
1016 *var = g_strdup("");
1017 varcopy = g_strdup("");
1019 *var = g_strdup(*var);
1020 varcopy = g_strdup(*var);
1022 preference->varp.string = var;
1023 preference->default_val.string = varcopy;
1024 preference->stashed_val.string = NULL;
1030 * Register a preference with a character-string value.
1033 prefs_register_string_preference(module_t *module, const char *name,
1034 const char *title, const char *description,
1037 register_string_like_preference(module, name, title, description, var,
1042 * Register a "custom" preference with a character-string value.
1043 * XXX - This should be temporary until we can find a better way
1044 * to do "custom" preferences
1047 prefs_register_string_custom_preference(module_t *module, const char *name,
1048 const char *title, const char *description,
1049 struct pref_custom_cbs* custom_cbs, const char **var)
1053 preference = register_string_like_preference(module, name, title, description, var,
1056 preference->custom_cbs = *custom_cbs;
1061 * Register a preference with a file name (string) value.
1064 prefs_register_filename_preference(module_t *module, const char *name,
1065 const char *title, const char *description,
1068 register_string_like_preference(module, name, title, description, var,
1073 * Register a preference with a directory name (string) value.
1076 prefs_register_directory_preference(module_t *module, const char *name,
1077 const char *title, const char *description,
1080 register_string_like_preference(module, name, title, description, var,
1085 * Register a preference with a ranged value.
1088 prefs_register_range_preference(module_t *module, const char *name,
1089 const char *title, const char *description,
1090 range_t **var, guint32 max_value)
1094 preference = register_preference(module, name, title, description,
1096 preference->info.max_value = max_value;
1100 * Range preference values should be non-null (as you can't
1101 * keep them null after using the preferences GUI, you can at best
1102 * have them be empty ranges) and freeable (as we free them
1103 * if we change them).
1105 * If the value is a null pointer, make it an empty range.
1108 *var = range_empty();
1109 preference->varp.range = var;
1110 preference->default_val.range = range_copy(*var);
1111 preference->stashed_val.range = NULL;
1115 * Register a static text 'preference'. It can be used to add explanatory
1116 * text inline with other preferences in the GUI.
1117 * Note: Static preferences are not saved to the preferences file.
1120 prefs_register_static_text_preference(module_t *module, const char *name,
1122 const char *description)
1124 register_preference(module, name, title, description, PREF_STATIC_TEXT);
1128 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1129 * preferences tab of the module.
1132 prefs_register_uat_preference(module_t *module, const char *name,
1133 const char *title, const char *description,
1137 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1139 preference->varp.uat = uat;
1143 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
1144 * preferences tab of the module.
1147 prefs_register_uat_preference_qt(module_t *module, const char *name,
1148 const char *title, const char *description,
1152 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1154 preference->varp.uat = uat;
1156 preference->gui = GUI_QT;
1160 * Register a color preference.
1163 prefs_register_color_preference(module_t *module, const char *name,
1164 const char *title, const char *description,
1167 pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
1169 preference->varp.colorp = color;
1170 preference->default_val.color = *color;
1174 * Register a "custom" preference with a list.
1175 * XXX - This should be temporary until we can find a better way
1176 * to do "custom" preferences
1178 typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
1181 prefs_register_list_custom_preference(module_t *module, const char *name,
1182 const char *title, const char *description,
1183 struct pref_custom_cbs* custom_cbs,
1184 pref_custom_list_init_cb init_cb,
1187 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1189 preference->custom_cbs = *custom_cbs;
1190 init_cb(preference, list);
1194 * Register a custom preference.
1197 prefs_register_custom_preference(module_t *module, const char *name,
1198 const char *title, const char *description,
1199 struct pref_custom_cbs* custom_cbs,
1200 void **custom_data _U_)
1202 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1204 preference->custom_cbs = *custom_cbs;
1205 /* XXX - wait until we can handle void** pointers
1206 preference->custom_cbs.init_cb(preference, custom_data);
1211 * Register a preference that used to be supported but no longer is.
1214 prefs_register_obsolete_preference(module_t *module, const char *name)
1216 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
1220 * Check to see if a preference is obsolete.
1223 prefs_get_preference_obsolete(pref_t *pref)
1226 return pref->type == PREF_OBSOLETE ? TRUE : FALSE;
1232 * Make a preference obsolete.
1234 extern prefs_set_pref_e
1235 prefs_set_preference_obsolete(pref_t *pref)
1238 pref->type = PREF_OBSOLETE;
1239 return PREFS_SET_OK;
1241 return PREFS_SET_NO_SUCH_PREF;
1245 /* Return the value assigned to the given uint preference. */
1247 prefs_get_uint_preference(pref_t *pref)
1249 if (pref && pref->type == PREF_UINT)
1250 return *pref->varp.uint;
1256 * Call a callback function, with a specified argument, for each preference
1257 * in a given module.
1259 * If any of the callbacks return a non-zero value, stop and return that
1260 * value, otherwise return 0.
1263 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
1269 for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
1270 pref = (pref_t *)elem->data;
1271 if (pref->type == PREF_OBSOLETE) {
1273 * This preference is no longer supported; it's
1274 * not a real preference, so we don't call the
1275 * callback for it (i.e., we treat it as if it
1276 * weren't found in the list of preferences,
1277 * and we weren't called in the first place).
1282 ret = (*callback)(pref, user_data);
1289 static const enum_val_t print_format_vals[] = {
1290 { "text", "Plain Text", PR_FMT_TEXT },
1291 { "postscript", "Postscript", PR_FMT_PS },
1295 static const enum_val_t print_dest_vals[] = {
1297 /* "PR_DEST_CMD" means "to printer" on Windows */
1298 { "command", "Printer", PR_DEST_CMD },
1300 { "command", "Command", PR_DEST_CMD },
1302 { "file", "File", PR_DEST_FILE },
1306 static const enum_val_t st_sort_col_vals[] = {
1307 { "name", "Node name (topic/item)", ST_SORT_COL_NAME },
1308 { "count", "Item count", ST_SORT_COL_COUNT },
1309 { "average", "Average value of the node", ST_SORT_COL_AVG },
1310 { "min", "Minimum value of the node", ST_SORT_COL_MIN },
1311 { "max", "Maximum value of the node", ST_SORT_COL_MAX },
1312 { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE },
1317 stats_callback(void)
1319 /* Test for a sane tap update interval */
1320 if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000)
1321 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
1323 #ifdef HAVE_LIBPORTAUDIO
1324 /* Test for a sane max channels entry */
1325 if (prefs.rtp_player_max_visible < 1 || prefs.rtp_player_max_visible > 10)
1326 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
1329 /* burst resolution can't be less than 1 (ms) */
1330 if (prefs.st_burst_resolution < 1) {
1331 prefs.st_burst_resolution = 1;
1333 else if (prefs.st_burst_resolution > ST_MAX_BURSTRES) {
1334 prefs.st_burst_resolution = ST_MAX_BURSTRES;
1336 /* make sure burst window value makes sense */
1337 if (prefs.st_burst_windowlen < prefs.st_burst_resolution) {
1338 prefs.st_burst_windowlen = prefs.st_burst_resolution;
1340 /* round burst window down to multiple of resolution */
1341 prefs.st_burst_windowlen -= prefs.st_burst_windowlen%prefs.st_burst_resolution;
1342 if ((prefs.st_burst_windowlen/prefs.st_burst_resolution) > ST_MAX_BURSTBUCKETS) {
1343 prefs.st_burst_windowlen = prefs.st_burst_resolution*ST_MAX_BURSTBUCKETS;
1350 /* Ensure there is at least one file count */
1351 if (prefs.gui_recent_files_count_max == 0)
1352 prefs.gui_recent_files_count_max = 10;
1354 /* Ensure there is at least one display filter entry */
1355 if (prefs.gui_recent_df_entries_max == 0)
1356 prefs.gui_recent_df_entries_max = 10;
1360 gui_layout_callback(void)
1362 if (prefs.gui_layout_type == layout_unused ||
1363 prefs.gui_layout_type >= layout_type_max) {
1364 /* XXX - report an error? It's not a syntax error - we'd need to
1365 add a way of reporting a *semantic* error. */
1366 prefs.gui_layout_type = layout_type_5;
1370 /******************************************************
1371 * All custom preference function callbacks
1372 ******************************************************/
1373 static void custom_pref_no_cb(pref_t* pref _U_) {}
1377 * Console log level custom preference functions
1380 console_log_level_reset_cb(pref_t* pref)
1382 *pref->varp.uint = pref->default_val.uint;
1385 static prefs_set_pref_e
1386 console_log_level_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1390 uval = (guint)strtoul(value, NULL, 10);
1392 if (*pref->varp.uint != uval) {
1394 *pref->varp.uint = uval;
1397 if (*pref->varp.uint & (G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG)) {
1399 * GLib >= 2.32 drops INFO and DEBUG messages by default. Tell
1400 * it not to do that.
1402 g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
1405 return PREFS_SET_OK;
1408 static const char * console_log_level_type_name_cb(void) {
1412 static char * console_log_level_type_description_cb(void) {
1413 return g_strdup_printf(
1414 "Console log level (for debugging)\n"
1415 "A bitmask of log levels:\n"
1424 static gboolean console_log_level_is_default_cb(pref_t* pref) {
1425 return *pref->varp.uint == pref->default_val.uint;
1428 static char * console_log_level_to_str_cb(pref_t* pref, gboolean default_val) {
1429 return g_strdup_printf("%u", default_val ? pref->default_val.uint : *pref->varp.uint);
1433 * Column preference functions
1435 #define PRS_COL_HIDDEN "column.hidden"
1436 #define PRS_COL_FMT "column.format"
1437 #define PRS_COL_NUM "column.number"
1438 static module_t *gui_column_module = NULL;
1441 column_hidden_free_cb(pref_t* pref)
1443 g_free((char *)*pref->varp.string);
1444 *pref->varp.string = NULL;
1445 g_free(pref->default_val.string);
1446 pref->default_val.string = NULL;
1450 column_hidden_reset_cb(pref_t* pref)
1452 g_free((void *)*pref->varp.string);
1453 *pref->varp.string = g_strdup(pref->default_val.string);
1456 static prefs_set_pref_e
1457 column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1461 pref_t *format_pref;
1463 if (*pref->varp.string) {
1464 if (strcmp(*pref->varp.string, value) != 0) {
1466 g_free((void *)*pref->varp.string);
1467 *pref->varp.string = g_strdup(value);
1470 *pref->varp.string = g_strdup(value);
1474 * Set the "visible" flag for the existing columns; we need to
1475 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
1476 * after setting it (which might be the case if, for example, we
1477 * set PRS_COL_HIDDEN on the command line).
1479 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1480 for (clp = *format_pref->varp.list; clp != NULL; clp = clp->next) {
1481 cfmt = (fmt_data *)clp->data;
1482 cfmt->visible = prefs_is_column_visible(*pref->varp.string, cfmt);
1485 return PREFS_SET_OK;
1489 column_hidden_type_name_cb(void)
1491 return "Packet list hidden columns";
1495 column_hidden_type_description_cb(void)
1497 return g_strdup("List all columns to hide in the packet list.");
1501 column_hidden_to_str_cb(pref_t* pref, gboolean default_val)
1503 GString *cols_hidden = g_string_new ("");
1506 pref_t *format_pref;
1509 return g_strdup(pref->default_val.string);
1511 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1512 clp = (format_pref) ? *format_pref->varp.list : NULL;
1515 cfmt = (fmt_data *) clp->data;
1516 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
1517 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1518 col_format_to_string(cfmt->fmt),
1520 cfmt->custom_occurrence,
1521 cfmt->resolved ? 'R' : 'U');
1523 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1525 if (!cfmt->visible) {
1526 if (cols_hidden->len)
1527 g_string_append (cols_hidden, ",");
1528 g_string_append (cols_hidden, prefs_fmt);
1534 return g_string_free (cols_hidden, FALSE);
1538 column_hidden_is_default_cb(pref_t* pref)
1540 char *cur_hidden_str = column_hidden_to_str_cb(pref, FALSE);
1541 gboolean is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
1543 g_free(cur_hidden_str);
1548 /* Number of columns "preference". This is only used internally and is not written to the
1552 column_num_reset_cb(pref_t* pref)
1554 *pref->varp.uint = pref->default_val.uint;
1557 static prefs_set_pref_e
1558 column_num_set_cb(pref_t* pref _U_, const gchar* value _U_, gboolean* changed _U_)
1560 /* Don't write this to the preferences file */
1561 return PREFS_SET_OK;
1565 column_num_type_name_cb(void)
1571 column_num_type_description_cb(void)
1573 return g_strdup("");
1577 column_num_is_default_cb(pref_t* pref _U_)
1583 column_num_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
1585 return g_strdup("");
1589 * Column format custom preference functions
1592 column_format_init_cb(pref_t* pref, GList** value)
1594 fmt_data *src_cfmt, *dest_cfmt;
1597 pref->varp.list = value;
1599 pref->default_val.list = NULL;
1600 for (entry = *pref->varp.list; entry != NULL; entry = g_list_next(entry)) {
1601 src_cfmt = (fmt_data *)entry->data;
1602 dest_cfmt = g_new(fmt_data,1);
1603 dest_cfmt->title = g_strdup(src_cfmt->title);
1604 dest_cfmt->fmt = src_cfmt->fmt;
1605 if (src_cfmt->custom_field) {
1606 dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
1607 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1609 dest_cfmt->custom_field = NULL;
1610 dest_cfmt->custom_occurrence = 0;
1612 dest_cfmt->visible = src_cfmt->visible;
1613 dest_cfmt->resolved = src_cfmt->resolved;
1614 pref->default_val.list = g_list_append(pref->default_val.list, dest_cfmt);
1619 column_format_free_cb(pref_t* pref)
1621 free_col_info(*pref->varp.list);
1622 free_col_info(pref->default_val.list);
1626 column_format_reset_cb(pref_t* pref)
1628 fmt_data *src_cfmt, *dest_cfmt;
1630 pref_t *col_num_pref;
1632 free_col_info(*pref->varp.list);
1633 *pref->varp.list = NULL;
1635 for (entry = pref->default_val.list; entry != NULL; entry = g_list_next(entry)) {
1636 src_cfmt = (fmt_data *)entry->data;
1637 dest_cfmt = g_new(fmt_data,1);
1638 dest_cfmt->title = g_strdup(src_cfmt->title);
1639 dest_cfmt->fmt = src_cfmt->fmt;
1640 if (src_cfmt->custom_field) {
1641 dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
1642 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1644 dest_cfmt->custom_field = NULL;
1645 dest_cfmt->custom_occurrence = 0;
1647 dest_cfmt->visible = src_cfmt->visible;
1648 dest_cfmt->resolved = src_cfmt->resolved;
1649 *pref->varp.list = g_list_append(*pref->varp.list, dest_cfmt);
1652 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1653 g_assert(col_num_pref != NULL); /* Should never happen */
1654 column_num_reset_cb(col_num_pref);
1657 static prefs_set_pref_e
1658 column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1660 GList *col_l, *col_l_elt;
1663 pref_t *hidden_pref, *col_num_pref;
1665 col_l = prefs_get_string_list(value);
1667 return PREFS_SET_SYNTAX_ERR;
1668 if ((g_list_length(col_l) % 2) != 0) {
1669 /* A title didn't have a matching format. */
1670 prefs_clear_string_list(col_l);
1671 return PREFS_SET_SYNTAX_ERR;
1673 /* Check to make sure all column formats are valid. */
1674 col_l_elt = g_list_first(col_l);
1676 fmt_data cfmt_check;
1678 /* Go past the title. */
1679 col_l_elt = col_l_elt->next;
1681 /* Parse the format to see if it's valid. */
1682 if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
1683 /* It's not a valid column format. */
1684 prefs_clear_string_list(col_l);
1685 return PREFS_SET_SYNTAX_ERR;
1687 if (cfmt_check.fmt != COL_CUSTOM) {
1688 /* Some predefined columns have been migrated to use custom columns.
1689 * We'll convert these silently here */
1690 try_convert_to_custom_column(&col_l_elt->data);
1692 /* We don't need the custom column field on this pass. */
1693 g_free(cfmt_check.custom_field);
1696 /* Go past the format. */
1697 col_l_elt = col_l_elt->next;
1700 /* They're all valid; process them. */
1701 free_col_info(*pref->varp.list);
1702 *pref->varp.list = NULL;
1703 hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN);
1704 g_assert(hidden_pref != NULL); /* Should never happen */
1705 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1706 g_assert(col_num_pref != NULL); /* Should never happen */
1707 llen = g_list_length(col_l);
1708 *col_num_pref->varp.uint = llen / 2;
1709 col_l_elt = g_list_first(col_l);
1711 cfmt = g_new(fmt_data,1);
1712 cfmt->title = g_strdup((gchar *)col_l_elt->data);
1713 col_l_elt = col_l_elt->next;
1714 parse_column_format(cfmt, (char *)col_l_elt->data);
1715 cfmt->visible = prefs_is_column_visible(*hidden_pref->varp.string, cfmt);
1716 col_l_elt = col_l_elt->next;
1717 *pref->varp.list = g_list_append(*pref->varp.list, cfmt);
1720 prefs_clear_string_list(col_l);
1721 column_hidden_free_cb(hidden_pref);
1722 return PREFS_SET_OK;
1727 column_format_type_name_cb(void)
1729 return "Packet list column format";
1733 column_format_type_description_cb(void)
1735 return g_strdup("Each pair of strings consists of a column title and its format");
1739 column_format_is_default_cb(pref_t* pref)
1741 GList *clp = *pref->varp.list,
1742 *pref_col = g_list_first(clp),
1743 *def_col = g_list_first(pref->default_val.list);
1744 fmt_data *cfmt, *def_cfmt;
1745 gboolean is_default = TRUE;
1746 pref_t *col_num_pref;
1748 /* See if the column data has changed from the default */
1749 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1750 if (col_num_pref && *col_num_pref->varp.uint != col_num_pref->default_val.uint) {
1753 while (pref_col && def_col) {
1754 cfmt = (fmt_data *) pref_col->data;
1755 def_cfmt = (fmt_data *) def_col->data;
1756 if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
1757 (cfmt->fmt != def_cfmt->fmt) ||
1758 (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) &&
1759 ((g_strcmp0(cfmt->custom_field, def_cfmt->custom_field) != 0) ||
1760 (cfmt->resolved != def_cfmt->resolved)))) {
1765 pref_col = pref_col->next;
1766 def_col = def_col->next;
1774 column_format_to_str_cb(pref_t* pref, gboolean default_val)
1776 GList *pref_l = default_val ? pref->default_val.list : *pref->varp.list;
1777 GList *clp = g_list_first(pref_l);
1781 char *column_format_str;
1785 cfmt = (fmt_data *) clp->data;
1786 col_l = g_list_append(col_l, g_strdup(cfmt->title));
1787 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
1788 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1789 col_format_to_string(cfmt->fmt),
1791 cfmt->custom_occurrence,
1792 cfmt->resolved ? 'R' : 'U');
1794 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1796 col_l = g_list_append(col_l, prefs_fmt);
1800 column_format_str = join_string_list(col_l);
1801 prefs_clear_string_list(col_l);
1802 return column_format_str;
1806 /****** Capture column custom preference functions ******/
1808 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
1809 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
1810 to prefs->default_val.list.
1813 capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
1815 GList *ccv_list = *capture_cols_values,
1820 dlist = g_list_append(dlist, g_strdup((gchar *)ccv_list->data));
1821 ccv_list = ccv_list->next;
1824 pref->default_val.list = dlist;
1825 pref->varp.list = &prefs.capture_columns;
1826 pref->stashed_val.boolval = FALSE;
1829 /* Free the prefs->capture_columns list strings and remove the list entries.
1830 Note that since pref->varp.list points to &prefs.capture_columns, it is
1834 capture_column_free_cb(pref_t* pref)
1836 prefs_clear_string_list(prefs.capture_columns);
1837 prefs.capture_columns = NULL;
1839 if (pref->stashed_val.boolval == TRUE) {
1840 prefs_clear_string_list(pref->default_val.list);
1841 pref->default_val.list = NULL;
1845 /* Copy pref->default_val.list to *pref->varp.list.
1848 capture_column_reset_cb(pref_t* pref)
1850 GList *vlist = NULL, *dlist;
1852 /* Free the column name strings and remove the links from *pref->varp.list */
1853 prefs_clear_string_list(*pref->varp.list);
1855 for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
1856 vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
1858 *pref->varp.list = vlist;
1861 static prefs_set_pref_e
1862 capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1864 GList *col_l = prefs_get_string_list(value);
1870 return PREFS_SET_SYNTAX_ERR;
1872 capture_column_free_cb(pref);
1874 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
1875 to the full list of valid capture column names. */
1876 col_l_elt = g_list_first(col_l);
1877 if (!(*(gchar *)col_l_elt->data)) {
1878 for (i = 0; i < num_capture_cols; i++) {
1879 col_name = g_strdup(capture_cols[i]);
1880 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1884 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
1887 gboolean found_match = FALSE;
1888 col_name = (gchar *)col_l_elt->data;
1890 for (i = 0; i < num_capture_cols; i++) {
1891 if (strcmp(col_name, capture_cols[i])==0) {
1897 /* One or more cols are invalid so use the entire list of valid cols. */
1898 for (i = 0; i < num_capture_cols; i++) {
1899 col_name = g_strdup(capture_cols[i]);
1900 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1902 pref->varp.list = &prefs.capture_columns;
1903 prefs_clear_string_list(col_l);
1904 return PREFS_SET_SYNTAX_ERR;
1906 col_l_elt = col_l_elt->next;
1909 col_l_elt = g_list_first(col_l);
1911 col_name = (gchar *)col_l_elt->data;
1912 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1913 col_l_elt = col_l_elt->next;
1915 pref->varp.list = &prefs.capture_columns;
1917 return PREFS_SET_OK;
1922 capture_column_type_name_cb(void)
1924 return "Column list";
1928 capture_column_type_description_cb(void)
1931 "List of columns to be displayed in the capture options dialog.\n"
1932 CAPTURE_COL_TYPE_DESCRIPTION);
1936 capture_column_is_default_cb(pref_t* pref)
1938 GList *pref_col = g_list_first(prefs.capture_columns),
1939 *def_col = g_list_first(pref->default_val.list);
1940 gboolean is_default = TRUE;
1942 /* See if the column data has changed from the default */
1943 while (pref_col && def_col) {
1944 if (strcmp((gchar *)pref_col->data, (gchar *)def_col->data) != 0) {
1948 pref_col = pref_col->next;
1949 def_col = def_col->next;
1952 /* Ensure the same column count */
1953 if (((pref_col == NULL) && (def_col != NULL)) ||
1954 ((pref_col != NULL) && (def_col == NULL)))
1961 capture_column_to_str_cb(pref_t* pref, gboolean default_val)
1964 GList *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
1965 GList *clp = g_list_first(pref_l);
1966 GList *col_l = NULL;
1968 char *capture_column_str;
1971 col = (gchar *) clp->data;
1972 col_l = g_list_append(col_l, g_strdup(col));
1976 capture_column_str = join_string_list(col_l);
1977 prefs_clear_string_list(col_l);
1978 return capture_column_str;
1983 colorized_frame_free_cb(pref_t* pref)
1985 g_free((char *)*pref->varp.string);
1986 *pref->varp.string = NULL;
1987 g_free(pref->default_val.string);
1988 pref->default_val.string = NULL;
1993 colorized_frame_reset_cb(pref_t* pref)
1995 g_free((void *)*pref->varp.string);
1996 *pref->varp.string = g_strdup(pref->default_val.string);
1999 static prefs_set_pref_e
2000 colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
2002 if (strcmp(*pref->varp.string, value) != 0) {
2004 g_free((void *)*pref->varp.string);
2005 *pref->varp.string = g_strdup(value);
2008 return PREFS_SET_OK;
2012 colorized_frame_type_name_cb(void)
2014 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
2015 * file until the colors can be changed in the GUI. Currently this is not really
2016 * possible since the STOCK-icons for these colors are hardcoded.
2018 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
2019 * add these 10 colors to the list of colors that can be changed through
2027 colorized_frame_type_description_cb(void)
2029 return g_strdup("");
2033 colorized_frame_is_default_cb(pref_t* pref _U_)
2039 colorized_frame_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
2041 return g_strdup("");
2045 * Register all non-dissector modules' preferences.
2047 static module_t *gui_module = NULL;
2048 static module_t *gui_color_module = NULL;
2049 static module_t *nameres_module = NULL;
2052 prefs_register_modules(void)
2054 module_t *printing, *capture_module, *console_module,
2055 *gui_layout_module, *gui_font_module;
2056 struct pref_custom_cbs custom_cbs;
2059 if (protocols_module != NULL) {
2060 /* Already setup preferences */
2065 * These are "simple" GUI preferences that can be read/written using the
2066 * preference module API. These preferences still use their own
2067 * configuration screens for access, but this cuts down on the
2068 * preference "string compare list" in set_pref()
2070 gui_module = prefs_register_module(NULL, "gui", "User Interface",
2071 "User Interface", &gui_callback, FALSE);
2073 /* gui.console_open is placed first in the list so that any problems encountered
2074 * in the following prefs can be displayed in the console window.
2076 prefs_register_enum_preference(gui_module, "console_open",
2077 "Open a console window",
2078 "Open a console window (Windows only)",
2079 (gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
2081 prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
2082 prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
2083 prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
2085 prefs_register_bool_preference(gui_module, "tree_view_altern_colors",
2086 "Alternating colors in TreeViews",
2087 "Alternating colors in TreeViews?",
2088 &prefs.gui_altern_colors);
2090 prefs_register_bool_preference(gui_module, "expert_composite_eyecandy",
2091 "Display Icons on Expert Composite Dialog Tabs",
2092 "Display Icons on Expert Composite Dialog Tabs?",
2093 &prefs.gui_expert_composite_eyecandy);
2095 prefs_register_bool_preference(gui_module, "filter_toolbar_show_in_statusbar",
2096 "Place filter toolbar inside the statusbar",
2097 "Place filter toolbar inside the statusbar?",
2098 &prefs.filter_toolbar_show_in_statusbar);
2100 prefs_register_enum_preference(gui_module, "protocol_tree_line_style",
2101 "Protocol-tree line style",
2102 "Protocol-tree line style",
2103 &prefs.gui_ptree_line_style, gui_ptree_line_style, FALSE);
2105 prefs_register_enum_preference(gui_module, "protocol_tree_expander_style",
2106 "Protocol-tree expander style",
2107 "Protocol-tree expander style",
2108 &prefs.gui_ptree_expander_style, gui_ptree_expander_style, FALSE);
2110 prefs_register_enum_preference(gui_module, "hex_dump_highlight_style",
2111 "Hex dump highlight style",
2112 "Hex dump highlight style",
2113 &prefs.gui_hex_dump_highlight_style, gui_hex_dump_highlight_style, FALSE);
2115 gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
2117 custom_cbs.free_cb = column_hidden_free_cb;
2118 custom_cbs.reset_cb = column_hidden_reset_cb;
2119 custom_cbs.set_cb = column_hidden_set_cb;
2120 custom_cbs.type_name_cb = column_hidden_type_name_cb;
2121 custom_cbs.type_description_cb = column_hidden_type_description_cb;
2122 custom_cbs.is_default_cb = column_hidden_is_default_cb;
2123 custom_cbs.to_str_cb = column_hidden_to_str_cb;
2124 prefs_register_string_custom_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
2125 "List all columns to hide in the packet list", &custom_cbs, (const char **)&cols_hidden_list);
2127 custom_cbs.free_cb = column_format_free_cb;
2128 custom_cbs.reset_cb = column_format_reset_cb;
2129 custom_cbs.set_cb = column_format_set_cb;
2130 custom_cbs.type_name_cb = column_format_type_name_cb;
2131 custom_cbs.type_description_cb = column_format_type_description_cb;
2132 custom_cbs.is_default_cb = column_format_is_default_cb;
2133 custom_cbs.to_str_cb = column_format_to_str_cb;
2135 prefs_register_list_custom_preference(gui_column_module, PRS_COL_FMT, "Packet list column format",
2136 "Each pair of strings consists of a column title and its format", &custom_cbs,
2137 column_format_init_cb, &prefs.col_list);
2139 /* Number of columns. This is only used internally and is not written to the
2142 custom_cbs.free_cb = custom_pref_no_cb;
2143 custom_cbs.reset_cb = column_num_reset_cb;
2144 custom_cbs.set_cb = column_num_set_cb;
2145 custom_cbs.type_name_cb = column_num_type_name_cb;
2146 custom_cbs.type_description_cb = column_num_type_description_cb;
2147 custom_cbs.is_default_cb = column_num_is_default_cb;
2148 custom_cbs.to_str_cb = column_num_to_str_cb;
2149 prefs_register_uint_custom_preference(gui_column_module, PRS_COL_NUM, "Number of columns",
2150 "Number of columns in col_list", &custom_cbs, &prefs.num_cols);
2152 /* User Interface : Font */
2153 gui_font_module = prefs_register_subtree(gui_module, "Font", "Font", NULL);
2155 prefs_register_obsolete_preference(gui_font_module, "font_name");
2157 tmp = prefs.gui_gtk2_font_name;
2158 prefs_register_string_preference(gui_font_module, "gtk2.font_name", "Font name",
2159 "Font name for packet list, protocol tree, and hex dump panes. (GTK+)", (const char **)&prefs.gui_gtk2_font_name);
2162 tmp = prefs.gui_qt_font_name;
2163 prefs_register_string_preference(gui_font_module, "qt.font_name", "Font name",
2164 "Font name for packet list, protocol tree, and hex dump panes. (Qt)", (const char **)&prefs.gui_qt_font_name);
2167 /* User Interface : Colors */
2168 gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
2170 prefs_register_color_preference(gui_color_module, "marked_frame.fg", "Color preferences for a marked frame",
2171 "Color preferences for a marked frame", &prefs.gui_marked_fg);
2173 prefs_register_color_preference(gui_color_module, "marked_frame.bg", "Color preferences for a marked frame",
2174 "Color preferences for a marked frame", &prefs.gui_marked_bg);
2176 prefs_register_color_preference(gui_color_module, "ignored_frame.fg", "Color preferences for a ignored frame",
2177 "Color preferences for a ignored frame", &prefs.gui_ignored_fg);
2179 prefs_register_color_preference(gui_color_module, "ignored_frame.bg", "Color preferences for a ignored frame",
2180 "Color preferences for a ignored frame", &prefs.gui_ignored_bg);
2182 prefs_register_color_preference(gui_color_module, "stream.client.fg", "TCP stream window color preference",
2183 "TCP stream window color preference", &prefs.st_client_fg);
2185 prefs_register_color_preference(gui_color_module, "stream.client.bg", "TCP stream window color preference",
2186 "TCP stream window color preference", &prefs.st_client_bg);
2188 prefs_register_color_preference(gui_color_module, "stream.server.fg", "TCP stream window color preference",
2189 "TCP stream window color preference", &prefs.st_server_fg);
2191 prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
2192 "TCP stream window color preference", &prefs.st_server_bg);
2194 custom_cbs.free_cb = colorized_frame_free_cb;
2195 custom_cbs.reset_cb = colorized_frame_reset_cb;
2196 custom_cbs.set_cb = colorized_frame_set_cb;
2197 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2198 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2199 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2200 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2201 tmp = prefs.gui_colorized_fg;
2202 prefs_register_string_custom_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
2203 "Filter Colorized Foreground", &custom_cbs, (const char **)&prefs.gui_colorized_fg);
2206 custom_cbs.free_cb = colorized_frame_free_cb;
2207 custom_cbs.reset_cb = colorized_frame_reset_cb;
2208 custom_cbs.set_cb = colorized_frame_set_cb;
2209 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2210 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2211 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2212 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2213 tmp = prefs.gui_colorized_bg;
2214 prefs_register_string_custom_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
2215 "Filter Colorized Background", &custom_cbs, (const char **)&prefs.gui_colorized_bg);
2218 prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
2219 "Valid color filter background", &prefs.gui_text_valid);
2221 prefs_register_color_preference(gui_color_module, "color_filter_bg.invalid", "Invalid color filter background",
2222 "Invalid color filter background", &prefs.gui_text_invalid);
2224 prefs_register_color_preference(gui_color_module, "color_filter_bg.deprecated", "Deprecated color filter background",
2225 "Deprecated color filter background", &prefs.gui_text_deprecated);
2227 prefs_register_enum_preference(gui_module, "fileopen.style",
2228 "Where to start the File Open dialog box",
2229 "Where to start the File Open dialog box",
2230 &prefs.gui_fileopen_style, gui_fileopen_style, FALSE);
2232 prefs_register_uint_preference(gui_module, "recent_files_count.max",
2233 "The max. number of items in the open recent files list",
2234 "The max. number of items in the open recent files list",
2236 &prefs.gui_recent_files_count_max);
2238 prefs_register_uint_preference(gui_module, "recent_display_filter_entries.max",
2239 "The max. number of entries in the display filter list",
2240 "The max. number of entries in the display filter list",
2242 &prefs.gui_recent_df_entries_max);
2244 tmp = prefs.gui_fileopen_dir;
2245 prefs_register_directory_preference(gui_module, "fileopen.dir", "Start Directory",
2246 "Directory to start in when opening File Open dialog.", (const char **)&prefs.gui_fileopen_dir);
2249 prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
2251 prefs_register_uint_preference(gui_module, "fileopen.preview",
2252 "The preview timeout in the File Open dialog",
2253 "The preview timeout in the File Open dialog",
2255 &prefs.gui_fileopen_preview);
2257 prefs_register_bool_preference(gui_module, "ask_unsaved",
2258 "Ask to save unsaved capture files",
2259 "Ask to save unsaved capture files?",
2260 &prefs.gui_ask_unsaved);
2262 prefs_register_bool_preference(gui_module, "find_wrap",
2263 "Wrap to beginning/end of file during search",
2264 "Wrap to beginning/end of file during search?",
2265 &prefs.gui_find_wrap);
2267 prefs_register_bool_preference(gui_module, "use_pref_save",
2268 "Settings dialogs use a save button",
2269 "Settings dialogs use a save button?",
2270 &prefs.gui_use_pref_save);
2272 prefs_register_bool_preference(gui_module, "geometry.save.position",
2273 "Save window position at exit",
2274 "Save window position at exit?",
2275 &prefs.gui_geometry_save_position);
2277 prefs_register_bool_preference(gui_module, "geometry.save.size",
2278 "Save window size at exit",
2279 "Save window size at exit?",
2280 &prefs.gui_geometry_save_size);
2282 prefs_register_bool_preference(gui_module, "geometry.save.maximized",
2283 "Save window maximized state at exit",
2284 "Save window maximized state at exit?",
2285 &prefs.gui_geometry_save_maximized);
2287 prefs_register_bool_preference(gui_module, "macosx_style",
2288 "Use Mac OS X style",
2289 "Use Mac OS X style (Mac OS X with native GTK only)?",
2290 &prefs.gui_macosx_style);
2292 prefs_register_obsolete_preference(gui_module, "geometry.main.x");
2293 prefs_register_obsolete_preference(gui_module, "geometry.main.y");
2294 prefs_register_obsolete_preference(gui_module, "geometry.main.width");
2295 prefs_register_obsolete_preference(gui_module, "geometry.main.height");
2296 prefs_register_obsolete_preference(gui_module, "toolbar_main_show");
2298 prefs_register_enum_preference(gui_module, "toolbar_main_style",
2299 "Main Toolbar style",
2300 "Main Toolbar style",
2301 &prefs.gui_toolbar_main_style, gui_toolbar_style, FALSE);
2303 prefs_register_enum_preference(gui_module, "toolbar_filter_style",
2304 "Filter Toolbar style",
2305 "Filter Toolbar style",
2306 &prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
2308 tmp = prefs.gui_webbrowser;
2309 prefs_register_string_preference(gui_module, "webbrowser", "The path to the webbrowser",
2310 "The path to the webbrowser (Ex: mozilla)", (const char **)&prefs.gui_webbrowser);
2313 prefs_register_bool_preference(gui_module, "update.enabled",
2314 "Check for updates",
2315 "Check for updates (Windows only)",
2316 &prefs.gui_update_enabled);
2318 prefs_register_enum_preference(gui_module, "update.channel",
2320 "The type of update to fetch. You should probably leave this set to UPDATE_CHANNEL_STABLE.",
2321 (gint*)(void*)(&prefs.gui_update_channel), gui_update_channel, FALSE);
2323 prefs_register_uint_preference(gui_module, "update.interval",
2324 "How often to check for software updates",
2325 "How often to check for software updates in seconds",
2327 &prefs.gui_update_interval);
2329 tmp = prefs.gui_window_title;
2330 prefs_register_string_preference(gui_module, "window_title", "Custom window title",
2331 "Custom window title. (Appended to existing titles.)", (const char **)&prefs.gui_window_title);
2334 tmp = prefs.gui_start_title;
2335 prefs_register_string_preference(gui_module, "start_title", "Custom start page title",
2336 "Custom start page title", (const char**)(&prefs.gui_start_title));
2339 prefs_register_enum_preference(gui_module, "version_placement",
2340 "Show version in the start page and/or main screen's title bar",
2341 "Show version in the start page and/or main screen's title bar",
2342 (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
2344 prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
2345 "Automatically scroll the recently expanded item",
2346 "Automatically scroll the recently expanded item",
2347 &prefs.gui_auto_scroll_on_expand);
2349 prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
2350 "The percentage down the view the recently expanded item should be scrolled",
2351 "The percentage down the view the recently expanded item should be scrolled",
2353 &prefs.gui_auto_scroll_percentage);
2355 /* User Interface : Layout */
2356 gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
2358 prefs_register_uint_preference(gui_layout_module, "layout_type",
2360 "Layout type (1-6)",
2362 (guint*)(void*)(&prefs.gui_layout_type));
2364 prefs_register_enum_preference(gui_layout_module, "layout_content_1",
2365 "Layout content of the pane 1",
2366 "Layout content of the pane 1",
2367 (gint*)(void*)(&prefs.gui_layout_content_1), gui_layout_content, FALSE);
2369 prefs_register_enum_preference(gui_layout_module, "layout_content_2",
2370 "Layout content of the pane 2",
2371 "Layout content of the pane 2",
2372 (gint*)(void*)(&prefs.gui_layout_content_2), gui_layout_content, FALSE);
2374 prefs_register_enum_preference(gui_layout_module, "layout_content_3",
2375 "Layout content of the pane 3",
2376 "Layout content of the pane 3",
2377 (gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
2379 prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
2380 "Enable Packet List Separator",
2381 "Enable Packet List Separator",
2382 &prefs.gui_qt_packet_list_separator);
2384 prefs_register_bool_preference(gui_module, "packet_editor.enabled",
2385 "Enable Packet Editor",
2386 "Enable Packet Editor (Experimental)",
2387 &prefs.gui_packet_editor);
2389 prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
2391 "The position of \"...\" in packet list text.",
2392 (gint*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, FALSE);
2395 * These are preferences that can be read/written using the
2396 * preference module API. These preferences still use their own
2397 * configuration screens for access, but this cuts down on the
2398 * preference "string compare list" in set_pref()
2400 console_module = prefs_register_module(NULL, "console", "Console",
2401 "CONSOLE", NULL, FALSE);
2403 custom_cbs.free_cb = custom_pref_no_cb;
2404 custom_cbs.reset_cb = console_log_level_reset_cb;
2405 custom_cbs.set_cb = console_log_level_set_cb;
2406 custom_cbs.type_name_cb = console_log_level_type_name_cb;
2407 custom_cbs.type_description_cb = console_log_level_type_description_cb;
2408 custom_cbs.is_default_cb = console_log_level_is_default_cb;
2409 custom_cbs.to_str_cb = console_log_level_to_str_cb;
2410 prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
2411 "A bitmask of glib log levels", &custom_cbs, &prefs.console_log_level);
2414 * These are preferences that can be read/written using the
2415 * preference module API. These preferences still use their own
2416 * configuration screens for access, but this cuts down on the
2417 * preference "string compare list" in set_pref()
2419 capture_module = prefs_register_module(NULL, "capture", "Capture",
2420 "CAPTURE", NULL, FALSE);
2422 prefs_register_string_preference(capture_module, "device", "Default capture device",
2423 "Default capture device", (const char **)&prefs.capture_device);
2425 prefs_register_string_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
2426 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
2427 (const char **)&prefs.capture_devices_linktypes);
2429 prefs_register_string_preference(capture_module, "devices_descr", "Interface descriptions",
2430 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
2431 (const char **)&prefs.capture_devices_descr);
2433 prefs_register_string_preference(capture_module, "devices_hide", "Hide interface",
2434 "Hide interface? (Ex: eth0,eth3,...)", (const char **)&prefs.capture_devices_hide);
2436 prefs_register_string_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
2437 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
2438 (const char **)&prefs.capture_devices_monitor_mode);
2440 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
2441 prefs_register_string_preference(capture_module, "devices_buffersize", "Interface buffer size",
2442 "Interface buffer size (Ex: en0(1),en1(143),...)",
2443 ((const char **)&prefs.capture_devices_buffersize));
2446 prefs_register_string_preference(capture_module, "devices_snaplen", "Interface snap length",
2447 "Interface snap length (Ex: en0(65535),en1(1430),...)",
2448 (const char **)&prefs.capture_devices_snaplen);
2450 prefs_register_string_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
2451 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
2452 (const char **)&prefs.capture_devices_pmode);
2454 prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
2455 "Capture in promiscuous mode?", &prefs.capture_prom_mode);
2457 prefs_register_string_preference(capture_module, "devices_filter", "Interface capture filter",
2458 "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
2459 (const char **)&prefs.capture_devices_filter);
2461 prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
2462 "Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
2464 prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
2465 "Update packet list in real time during capture?", &prefs.capture_real_time);
2467 /* We might want to make this a "recent" setting. */
2468 prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
2469 "Scroll packet list during capture?", &prefs.capture_auto_scroll);
2471 prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
2472 "Show capture info dialog while capturing?", &prefs.capture_show_info);
2474 prefs_register_obsolete_preference(capture_module, "syntax_check_filter");
2476 custom_cbs.free_cb = capture_column_free_cb;
2477 custom_cbs.reset_cb = capture_column_reset_cb;
2478 custom_cbs.set_cb = capture_column_set_cb;
2479 custom_cbs.type_name_cb = capture_column_type_name_cb;
2480 custom_cbs.type_description_cb = capture_column_type_description_cb;
2481 custom_cbs.is_default_cb = capture_column_is_default_cb;
2482 custom_cbs.to_str_cb = capture_column_to_str_cb;
2483 prefs_register_list_custom_preference(capture_module, "columns", "Capture options dialog column list",
2484 "List of columns to be displayed", &custom_cbs, capture_column_init_cb, &prefs.capture_columns);
2486 /* Name Resolution */
2487 nameres_module = prefs_register_module(NULL, "nameres", "Name Resolution",
2488 "Name Resolution", NULL, TRUE);
2489 addr_resolve_pref_init(nameres_module);
2490 oid_pref_init(nameres_module);
2492 geoip_db_pref_init(nameres_module);
2496 printing = prefs_register_module(NULL, "print", "Printing",
2497 "Printing", NULL, TRUE);
2499 prefs_register_enum_preference(printing, "format",
2500 "Format", "Can be one of \"text\" or \"postscript\"",
2501 &prefs.pr_format, print_format_vals, TRUE);
2503 prefs_register_enum_preference(printing, "destination",
2504 "Print to", "Can be one of \"command\" or \"file\"",
2505 &prefs.pr_dest, print_dest_vals, TRUE);
2509 prefs_register_string_preference(printing, "command", "Command",
2510 "Output gets piped to this command when the destination is set to \"command\"", (const char**)(&prefs.pr_cmd));
2514 tmp = prefs.pr_file;
2515 prefs_register_filename_preference(printing, "file", "File",
2516 "This is the file that gets written to when the destination is set to \"file\"", (const char**)(&prefs.pr_file));
2520 stats_module = prefs_register_module(NULL, "statistics", "Statistics",
2521 "Statistics", &stats_callback, TRUE);
2523 prefs_register_uint_preference(stats_module, "update_interval",
2524 "Tap update interval in ms",
2525 "Determines time between tap updates",
2527 &prefs.tap_update_interval);
2529 #ifdef HAVE_LIBPORTAUDIO
2530 prefs_register_uint_preference(stats_module, "rtp_player_max_visible",
2531 "Max visible channels in RTP Player",
2532 "Determines maximum height of RTP Player window",
2534 &prefs.rtp_player_max_visible);
2537 prefs_register_bool_preference(stats_module, "st_enable_burstinfo",
2538 "Enable the calculation of burst information",
2539 "If enabled burst rates will be calcuted for statistics that use the stats_tree system. "
2540 "Burst rates are calculated over a much shorter time interval than the rate column.",
2541 &prefs.st_enable_burstinfo);
2543 prefs_register_bool_preference(stats_module, "st_burst_showcount",
2544 "Show burst count for item rather than rate",
2545 "If selected the stats_tree statistics nodes will show the count of events "
2546 "within the burst window instead of a burst rate. Burst rate is calculated "
2547 "as number of events within burst window divided by the burst windown length.",
2548 &prefs.st_burst_showcount);
2550 prefs_register_uint_preference(stats_module, "st_burst_resolution",
2551 "Burst rate resolution (ms)",
2552 "Sets the duration of the time interval into which events are grouped when calculating "
2553 "the burst rate. Higher resolution (smaller number) increases processing overhead.",
2554 10,&prefs.st_burst_resolution);
2556 prefs_register_uint_preference(stats_module, "st_burst_windowlen",
2557 "Burst rate window size (ms)",
2558 "Sets the duration of the sliding window during which the burst rate is "
2559 "measured. Longer window relative to burst rate resolution increases "
2560 "processing overhead. Will be truncated to a multiple of burst resolution.",
2561 10,&prefs.st_burst_windowlen);
2563 prefs_register_enum_preference(stats_module, "st_sort_defcolflag",
2564 "Default sort column for stats_tree stats",
2565 "Sets the default column by which stats based on the stats_tree "
2566 "system is sorted.",
2567 &prefs.st_sort_defcolflag, st_sort_col_vals, FALSE);
2569 prefs_register_bool_preference(stats_module, "st_sort_defdescending",
2570 "Default stats_tree sort order is descending",
2571 "When selected, statistics based on the stats_tree system will by default "
2572 "be sorted in descending order.",
2573 &prefs.st_sort_defdescending);
2575 prefs_register_bool_preference(stats_module, "st_sort_casesensitve",
2576 "Case sensitive sort of stats_tree item names",
2577 "When selected, the item/node names of statistics based on the stats_tree "
2578 "system will be sorted taking case into account. Else the case of the name "
2580 &prefs.st_sort_casesensitve);
2582 prefs_register_bool_preference(stats_module, "st_sort_rng_nameonly",
2583 "Always sort 'range' nodes by name",
2584 "When selected, the stats_tree nodes representing a range of values "
2585 "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
2586 "node). Else range nodes are sorted by the same column as the rest of "
2588 &prefs.st_sort_rng_nameonly);
2590 prefs_register_bool_preference(stats_module, "st_sort_rng_fixorder",
2591 "Always sort 'range' nodes in ascending order",
2592 "When selected, the stats_tree nodes representing a range of values "
2593 "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
2594 "the sort direction of the tree. Only effective if \"Always sort "
2595 "'range' nodes by name\" is also selected.",
2596 &prefs.st_sort_rng_fixorder);
2598 prefs_register_bool_preference(stats_module, "st_sort_showfullname",
2599 "Display the full stats_tree plug-in name",
2600 "When selected, the full name (including menu path) of the stats_tree "
2601 "plug-in is show in windows. If cleared the plug-in name is shown "
2602 "without menu path (only the part of the name after last '/' character.)",
2603 &prefs.st_sort_showfullname);
2606 protocols_module = prefs_register_module(NULL, "protocols", "Protocols",
2607 "Protocols", NULL, TRUE);
2609 prefs_register_bool_preference(protocols_module, "display_hidden_proto_items",
2610 "Display hidden protocol items",
2611 "Display all hidden protocol items in the packet list.",
2612 &prefs.display_hidden_proto_items);
2614 prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
2615 "Display byte fields with a space character between bytes",
2616 "Display all byte fields with a space character between each byte in the packet list.",
2617 &prefs.display_byte_fields_with_spaces);
2619 prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
2620 "Look for incomplete dissectors",
2621 "Look for dissectors that left some bytes undecoded.",
2622 &prefs.enable_incomplete_dissectors_check);
2624 /* Obsolete preferences
2625 * These "modules" were reorganized/renamed to correspond to their GUI
2626 * configuration screen within the preferences dialog
2629 /* taps is now part of the stats module */
2630 prefs_register_module(NULL, "taps", "TAPS", "TAPS", NULL, FALSE);
2631 /* packet_list is now part of the protocol (parent) module */
2632 prefs_register_module(NULL, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL, FALSE);
2633 /* stream is now part of the gui module */
2634 prefs_register_module(NULL, "stream", "STREAM", "STREAM", NULL, FALSE);
2638 /* Parse through a list of comma-separated, possibly quoted strings.
2639 Return a list of the string data. */
2641 prefs_get_string_list(const gchar *str)
2643 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
2645 gint state = PRE_STRING, i = 0, j = 0;
2646 gboolean backslash = FALSE;
2648 gchar *slstr = NULL;
2651 /* Allocate a buffer for the first string. */
2652 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2657 if (cur_c == '\0') {
2658 /* It's the end of the input, so it's the end of the string we
2659 were working on, and there's no more input. */
2660 if (state == IN_QUOT || backslash) {
2661 /* We were in the middle of a quoted string or backslash escape,
2662 and ran out of characters; that's an error. */
2664 prefs_clear_string_list(sl);
2668 sl = g_list_append(sl, slstr);
2671 if (cur_c == '"' && ! backslash) {
2674 /* We hadn't yet started processing a string; this starts the
2675 string, and we're now quoting. */
2679 /* We're in the middle of a quoted string, and we saw a quotation
2680 mark; we're no longer quoting. */
2681 state = NOT_IN_QUOT;
2684 /* We're working on a string, but haven't seen a quote; we're
2691 } else if (cur_c == '\\' && ! backslash) {
2692 /* We saw a backslash, and the previous character wasn't a
2693 backslash; escape the next character.
2695 This also means we've started a new string. */
2697 if (state == PRE_STRING)
2698 state = NOT_IN_QUOT;
2699 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
2700 /* We saw a comma, and we're not in the middle of a quoted string
2701 and it wasn't preceded by a backslash; it's the end of
2702 the string we were working on... */
2704 sl = g_list_append(sl, slstr);
2706 /* ...and the beginning of a new string. */
2708 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2710 } else if (!g_ascii_isspace(cur_c) || state != PRE_STRING) {
2711 /* Either this isn't a white-space character, or we've started a
2712 string (i.e., already seen a non-white-space character for that
2713 string and put it into the string).
2715 The character is to be put into the string; do so if there's
2717 if (j < COL_MAX_LEN) {
2722 /* If it was backslash-escaped, we're done with the backslash escape. */
2730 char *join_string_list(GList *sl)
2732 GString *joined_str = g_string_new("");
2736 guint item_count = 0;
2738 cur = first = g_list_first(sl);
2741 str = (gchar *)cur->data;
2744 g_string_append_c(joined_str, ',');
2746 if (item_count % 2) {
2747 /* Wrap the line. */
2748 g_string_append(joined_str, "\n\t");
2750 g_string_append_c(joined_str, ' ');
2752 quoted_str = g_strescape(str, "");
2753 g_string_append_printf(joined_str, "\"%s\"", quoted_str);
2758 return g_string_free(joined_str, FALSE);
2762 prefs_clear_string_list(GList *sl)
2764 /* g_list_free_full() only exists since 2.28. */
2765 g_list_foreach(sl, (GFunc)g_free, NULL);
2770 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
2772 * The array must be terminated by an entry with a null "name" string.
2774 * If the string matches a "name" string in an entry, the value from that
2775 * entry is returned.
2777 * Otherwise, if a string matches a "description" string in an entry, the
2778 * value from that entry is returned; we do that for backwards compatibility,
2779 * as we used to have only a "name" string that was used both for command-line
2780 * and configuration-file values and in the GUI (which meant either that
2781 * the GUI had what might be somewhat cryptic values to select from or that
2782 * the "-o" flag took long strings, often with spaces in them).
2784 * Otherwise, the default value that was passed as the third argument is
2788 find_val_for_string(const char *needle, const enum_val_t *haystack,
2793 for (i = 0; haystack[i].name != NULL; i++) {
2794 if (g_ascii_strcasecmp(needle, haystack[i].name) == 0) {
2795 return haystack[i].value;
2798 for (i = 0; haystack[i].name != NULL; i++) {
2799 if (g_ascii_strcasecmp(needle, haystack[i].description) == 0) {
2800 return haystack[i].value;
2803 return default_value;
2806 /* Preferences file format:
2807 * - Configuration directives start at the beginning of the line, and
2808 * are terminated with a colon.
2809 * - Directives can be continued on the next line by preceding them with
2814 # This is a comment line
2816 print.file: /a/very/long/path/
2821 #define DEF_NUM_COLS 7
2824 * Parse a column format, filling in the relevant fields of a fmt_data.
2827 parse_column_format(fmt_data *cfmt, const char *fmt)
2829 const gchar *cust_format = col_format_to_string(COL_CUSTOM);
2830 size_t cust_format_len = strlen(cust_format);
2831 gchar **cust_format_info;
2834 gchar *col_custom_field = NULL;
2835 long col_custom_occurrence = 0;
2836 gboolean col_resolved = TRUE;
2839 * Is this a custom column?
2841 if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
2842 strncmp(fmt, cust_format, cust_format_len) == 0) {
2844 col_fmt = COL_CUSTOM;
2845 cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
2846 col_custom_field = g_strdup(cust_format_info[0]);
2847 if (col_custom_field && cust_format_info[1]) {
2848 col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
2849 if (p == cust_format_info[1] || *p != '\0') {
2850 /* Not a valid number. */
2851 g_free(col_custom_field);
2852 g_strfreev(cust_format_info);
2856 if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
2857 col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
2859 g_strfreev(cust_format_info);
2861 col_fmt = get_column_format_from_str(fmt);
2866 cfmt->fmt = col_fmt;
2867 cfmt->custom_field = col_custom_field;
2868 cfmt->custom_occurrence = (int)col_custom_occurrence;
2869 cfmt->resolved = col_resolved;
2873 /* Initialize non-dissector preferences to wired-in default values Called
2874 * at program startup and any time the profile changes. (The dissector
2875 * preferences are assumed to be set to those values by the dissectors.)
2876 * They may be overridden by the global preferences file or the user's
2882 if (prefs_initialized)
2888 * Ensure the "global" preferences have been initialized so the
2889 * preference API has the proper default values to work from
2893 prefs_register_modules();
2895 filter_expression_init(TRUE);
2897 prefs_initialized = TRUE;
2901 * Initialize non-dissector preferences used by the "register preference" API
2902 * to default values so the default values can be used when registered.
2904 * String, filename, and directory preferences will be g_freed so they must
2908 pre_init_prefs(void)
2913 static const gchar *col_fmt[DEF_NUM_COLS*2] = {
2914 "No.", "%m", "Time", "%t",
2915 "Source", "%s", "Destination", "%d",
2916 "Protocol", "%p", "Length", "%L",
2919 prefs.pr_format = PR_FMT_TEXT;
2920 prefs.pr_dest = PR_DEST_CMD;
2921 if (prefs.pr_file) g_free(prefs.pr_file);
2922 prefs.pr_file = g_strdup("wireshark.out");
2923 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
2924 prefs.pr_cmd = g_strdup("lpr");
2926 prefs.gui_altern_colors = FALSE;
2927 prefs.gui_expert_composite_eyecandy = FALSE;
2928 prefs.gui_ptree_line_style = 0;
2929 prefs.gui_ptree_expander_style = 1;
2930 prefs.gui_hex_dump_highlight_style = 1;
2931 prefs.filter_toolbar_show_in_statusbar = FALSE;
2932 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
2933 prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
2934 /* These will be g_freed, so they must be g_mallocated. */
2935 if (prefs.gui_gtk2_font_name) g_free(prefs.gui_gtk2_font_name);
2937 prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
2939 prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
2941 /* We try to find the best font in the Qt code */
2942 if (prefs.gui_qt_font_name) g_free(prefs.gui_qt_font_name);
2943 prefs.gui_qt_font_name = g_strdup("");
2944 prefs.gui_marked_fg.pixel = 65535;
2945 prefs.gui_marked_fg.red = 65535;
2946 prefs.gui_marked_fg.green = 65535;
2947 prefs.gui_marked_fg.blue = 65535;
2948 prefs.gui_marked_bg.pixel = 0;
2949 prefs.gui_marked_bg.red = 0;
2950 prefs.gui_marked_bg.green = 8224;
2951 prefs.gui_marked_bg.blue = 10794;
2952 prefs.gui_ignored_fg.pixel = 32767;
2953 prefs.gui_ignored_fg.red = 32767;
2954 prefs.gui_ignored_fg.green = 32767;
2955 prefs.gui_ignored_fg.blue = 32767;
2956 prefs.gui_ignored_bg.pixel = 65535;
2957 prefs.gui_ignored_bg.red = 65535;
2958 prefs.gui_ignored_bg.green = 65535;
2959 prefs.gui_ignored_bg.blue = 65535;
2960 if (prefs.gui_colorized_fg) g_free(prefs.gui_colorized_fg);
2961 prefs.gui_colorized_fg = g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
2962 if (prefs.gui_colorized_bg) g_free(prefs.gui_colorized_bg);
2963 prefs.gui_colorized_bg = g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
2964 prefs.st_client_fg.pixel = 0;
2965 prefs.st_client_fg.red = 32767;
2966 prefs.st_client_fg.green = 0;
2967 prefs.st_client_fg.blue = 0;
2968 prefs.st_client_bg.pixel = 0;
2969 prefs.st_client_bg.red = 64507;
2970 prefs.st_client_bg.green = 60909;
2971 prefs.st_client_bg.blue = 60909;
2972 prefs.st_server_fg.pixel = 0;
2973 prefs.st_server_fg.red = 0;
2974 prefs.st_server_fg.green = 0;
2975 prefs.st_server_fg.blue = 32767;
2976 prefs.st_server_bg.pixel = 0;
2977 prefs.st_server_bg.red = 60909;
2978 prefs.st_server_bg.green = 60909;
2979 prefs.st_server_bg.blue = 64507;
2980 prefs.gui_text_valid.pixel = 0; /* light green */
2981 prefs.gui_text_valid.red = 0xAFFF;
2982 prefs.gui_text_valid.green = 0xFFFF;
2983 prefs.gui_text_valid.blue = 0xAFFF;
2984 prefs.gui_text_invalid.pixel = 0; /* light red */
2985 prefs.gui_text_invalid.red = 0xFFFF;
2986 prefs.gui_text_invalid.green = 0xAFFF;
2987 prefs.gui_text_invalid.blue = 0xAFFF;
2988 prefs.gui_text_deprecated.pixel = 0; /* light yellow */
2989 prefs.gui_text_deprecated.red = 0xFFFF;
2990 prefs.gui_text_deprecated.green = 0xFFFF;
2991 prefs.gui_text_deprecated.blue = 0xAFFF;
2992 prefs.gui_geometry_save_position = TRUE;
2993 prefs.gui_geometry_save_size = TRUE;
2994 prefs.gui_geometry_save_maximized= TRUE;
2995 prefs.gui_macosx_style = TRUE;
2996 prefs.gui_console_open = console_open_never;
2997 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
2998 prefs.gui_recent_df_entries_max = 10;
2999 prefs.gui_recent_files_count_max = 10;
3000 if (prefs.gui_fileopen_dir) g_free(prefs.gui_fileopen_dir);
3001 prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
3002 prefs.gui_fileopen_preview = 3;
3003 prefs.gui_ask_unsaved = TRUE;
3004 prefs.gui_find_wrap = TRUE;
3005 prefs.gui_use_pref_save = FALSE;
3006 prefs.gui_update_enabled = TRUE;
3007 prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
3008 prefs.gui_update_interval = 60*60*24; /* Seconds */
3009 if (prefs.gui_webbrowser) g_free(prefs.gui_webbrowser);
3011 prefs.gui_webbrowser = g_strdup(HTML_VIEWER " %s");
3013 prefs.gui_webbrowser = g_strdup("");
3015 if (prefs.gui_window_title) g_free(prefs.gui_window_title);
3016 prefs.gui_window_title = g_strdup("");
3017 if (prefs.gui_start_title) g_free(prefs.gui_start_title);
3018 prefs.gui_start_title = g_strdup("The World's Most Popular Network Protocol Analyzer");
3019 prefs.gui_version_placement = version_both;
3020 prefs.gui_auto_scroll_on_expand = FALSE;
3021 prefs.gui_auto_scroll_percentage = 0;
3022 prefs.gui_layout_type = layout_type_5;
3023 prefs.gui_layout_content_1 = layout_pane_content_plist;
3024 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
3025 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
3026 prefs.gui_packet_editor = FALSE;
3027 prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
3029 prefs.gui_qt_packet_list_separator = FALSE;
3031 if (!prefs.col_list) {
3032 /* First time through */
3033 for (i = 0; i < DEF_NUM_COLS; i++) {
3034 cfmt = g_new(fmt_data,1);
3035 cfmt->title = g_strdup(col_fmt[i * 2]);
3036 parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
3037 cfmt->visible = TRUE;
3038 cfmt->resolved = TRUE;
3039 cfmt->custom_field = NULL;
3040 cfmt->custom_occurrence = 0;
3041 prefs.col_list = g_list_append(prefs.col_list, cfmt);
3043 prefs.num_cols = DEF_NUM_COLS;
3046 /* set the default values for the capture dialog box */
3047 prefs.capture_prom_mode = TRUE;
3048 #ifdef PCAP_NG_DEFAULT
3049 prefs.capture_pcap_ng = TRUE;
3051 prefs.capture_pcap_ng = FALSE;
3053 prefs.capture_real_time = TRUE;
3054 prefs.capture_auto_scroll = TRUE;
3055 prefs.capture_show_info = FALSE;
3057 if (!prefs.capture_columns) {
3058 /* First time through */
3059 for (i = 0; i < num_capture_cols; i++) {
3060 col_name = g_strdup(capture_cols[i]);
3061 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3065 prefs.console_log_level =
3066 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
3068 /* set the default values for the tap/statistics dialog box */
3069 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
3070 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
3071 prefs.st_enable_burstinfo = TRUE;
3072 prefs.st_burst_showcount = FALSE;
3073 prefs.st_burst_resolution = ST_DEF_BURSTRES;
3074 prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
3075 prefs.st_sort_casesensitve = TRUE;
3076 prefs.st_sort_rng_fixorder = TRUE;
3077 prefs.st_sort_rng_nameonly = TRUE;
3078 prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
3079 prefs.st_sort_defdescending = TRUE;
3080 prefs.st_sort_showfullname = FALSE;
3081 prefs.display_hidden_proto_items = FALSE;
3082 prefs.display_byte_fields_with_spaces = FALSE;
3086 * Reset a single dissector preference.
3089 reset_pref(pref_t *pref)
3093 switch (pref->type) {
3096 *pref->varp.uint = pref->default_val.uint;
3100 *pref->varp.boolp = pref->default_val.boolval;
3105 * For now, we save the "description" value, so that if we
3106 * save the preferences older versions of Wireshark can at
3107 * least read preferences that they supported; we support
3108 * either the short name or the description when reading
3109 * the preferences file or a "-o" option.
3111 *pref->varp.enump = pref->default_val.enumval;
3117 g_free((void *)*pref->varp.string);
3118 *pref->varp.string = g_strdup(pref->default_val.string);
3122 g_free(*pref->varp.range);
3123 *pref->varp.range = range_copy(pref->default_val.range);
3126 case PREF_STATIC_TEXT:
3132 *pref->varp.colorp = pref->default_val.color;
3136 pref->custom_cbs.reset_cb(pref);
3141 * This preference is no longer supported; it's not a
3142 * real preference, so we don't reset it (i.e., we
3143 * treat it as if it weren't found in the list of
3144 * preferences, and we weren't called in the first place).
3151 reset_pref_cb(gpointer data, gpointer user_data _U_)
3153 pref_t *pref = (pref_t *) data;
3162 * Reset all preferences for a module.
3165 reset_module_prefs(void *value, void *data _U_)
3167 reset_pref_arg_t arg;
3169 arg.module = (module_t *)value;
3170 g_list_foreach(arg.module->prefs, reset_pref_cb, &arg);
3174 /* Reset preferences */
3178 prefs_initialized = FALSE;
3179 g_free(prefs.saved_at_version);
3180 prefs.saved_at_version = NULL;
3183 * Unload all UAT preferences.
3188 * Unload any loaded MIBs.
3193 * Free the filter expression list.
3196 filter_expression_free(*pfilter_expression_head);
3197 *pfilter_expression_head = NULL;
3200 * Reset the non-dissector preferences.
3205 * Reset the non-UAT dissector preferences.
3207 wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
3210 /* Read the preferences file, fill in "prefs", and return a pointer to it.
3212 If we got an error (other than "it doesn't exist") trying to read
3213 the global preferences file, stuff the errno into "*gpf_errno_return"
3214 and a pointer to the path of the file into "*gpf_path_return", and
3217 If we got an error (other than "it doesn't exist") trying to read
3218 the user's preferences file, stuff the errno into "*pf_errno_return"
3219 and a pointer to the path of the file into "*pf_path_return", and
3223 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
3224 char **gpf_path_return, int *pf_errno_return,
3225 int *pf_read_errno_return, char **pf_path_return)
3231 /* clean up libsmi structures before reading prefs */
3237 * If we don't already have the pathname of the global preferences
3238 * file, construct it. Then, in either case, try to open the file.
3240 if (gpf_path == NULL) {
3242 * We don't have the path; try the new path first, and, if that
3243 * file doesn't exist, try the old path.
3245 gpf_path = get_datafile_path(PF_NAME);
3246 if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
3248 * It doesn't exist by the new name; try the old name.
3251 gpf_path = get_datafile_path(OLD_GPF_NAME);
3252 pf = ws_fopen(gpf_path, "r");
3256 * We have the path; try it.
3258 pf = ws_fopen(gpf_path, "r");
3262 * If we were able to open the file, read it.
3263 * XXX - if it failed for a reason other than "it doesn't exist",
3266 *gpf_path_return = NULL;
3269 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3272 mgcp_tcp_port_count = 0;
3273 mgcp_udp_port_count = 0;
3275 /* We succeeded in opening it; read it. */
3276 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
3278 /* We had an error reading the file; return the errno and the
3279 pathname, so our caller can report the error. */
3280 *gpf_errno_return = 0;
3281 *gpf_read_errno_return = err;
3282 *gpf_path_return = gpf_path;
3286 /* We failed to open it. If we failed for some reason other than
3287 "it doesn't exist", return the errno and the pathname, so our
3288 caller can report the error. */
3289 if (errno != ENOENT) {
3290 *gpf_errno_return = errno;
3291 *gpf_read_errno_return = 0;
3292 *gpf_path_return = gpf_path;
3296 /* Construct the pathname of the user's preferences file. */
3297 pf_path = get_persconffile_path(PF_NAME, TRUE);
3299 /* Read the user's preferences file, if it exists. */
3300 *pf_path_return = NULL;
3301 if ((pf = ws_fopen(pf_path, "r")) != NULL) {
3303 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3306 mgcp_tcp_port_count = 0;
3307 mgcp_udp_port_count = 0;
3309 /* We succeeded in opening it; read it. */
3310 err = read_prefs_file(pf_path, pf, set_pref, NULL);
3312 /* We had an error reading the file; return the errno and the
3313 pathname, so our caller can report the error. */
3314 *pf_errno_return = 0;
3315 *pf_read_errno_return = err;
3316 *pf_path_return = pf_path;
3321 /* We failed to open it. If we failed for some reason other than
3322 "it doesn't exist", return the errno and the pathname, so our
3323 caller can report the error. */
3324 if (errno != ENOENT) {
3325 *pf_errno_return = errno;
3326 *pf_read_errno_return = 0;
3327 *pf_path_return = pf_path;
3332 /* load SMI modules if needed */
3338 /* read the preferences file (or similiar) and call the callback
3339 * function to set each key/value pair found */
3341 read_prefs_file(const char *pf_path, FILE *pf,
3342 pref_set_pair_cb pref_set_pair_fct, void *private_data)
3345 START, /* beginning of a line */
3346 IN_VAR, /* processing key name */
3347 PRE_VAL, /* finished processing key name, skipping white space befor evalue */
3348 IN_VAL, /* processing value */
3349 IN_SKIP /* skipping to the end of the line */
3354 gboolean got_val = FALSE;
3355 gint fline = 1, pline = 1;
3356 gchar hint[] = "(save preferences to remove this warning)";
3359 cur_val = g_string_new("");
3360 cur_var = g_string_new("");
3362 /* Try to read in the profile name in the first line of the preferences file. */
3363 if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
3364 /* Assume trailing period and remove it */
3365 g_free(prefs.saved_at_version);
3366 prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
3370 while ((got_c = getc(pf)) != EOF) {
3371 if (got_c == '\r') {
3372 /* Treat CR-LF at the end of a line like LF, so that if we're reading
3373 * a Windows-format file on UN*X, we handle it the same way we'd handle
3374 * a UN*X-format file. */
3378 if (got_c != '\n') {
3379 /* Put back the character after the CR, and process the CR normally. */
3384 if (got_c == '\n') {
3392 if (g_ascii_isalnum(got_c)) {
3393 if (cur_var->len > 0) {
3395 if (cur_val->len > 0) {
3396 if (cur_val->str[cur_val->len-1] == ',') {
3398 * If the pref has a trailing comma, eliminate it.
3400 cur_val->str[cur_val->len-1] = '\0';
3401 g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
3404 /* Call the routine to set the preference; it will parse
3405 the value as appropriate.
3407 Since we're reading a file, rather than processing
3408 explicit user input, for range preferences, silently
3409 lower values in excess of the range's maximum, rather
3410 than reporting errors and failing. */
3411 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3416 case PREFS_SET_SYNTAX_ERR:
3417 g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
3418 cur_var->str, pline, pf_path, hint);
3421 case PREFS_SET_NO_SUCH_PREF:
3423 * If "print.command" silently ignore it because it's valid
3424 * on non-Win32 platforms.
3426 if (strcmp(cur_var->str, "print.command") != 0)
3427 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3428 cur_var->str, pline, pf_path, hint);
3429 prefs.unknown_prefs = TRUE;
3432 case PREFS_SET_OBSOLETE:
3433 if (strcmp(cur_var->str, "print.command") != 0)
3434 /* If an attempt is made to save the preferences, a popup warning will be
3435 displayed stating that obsolete prefs have been detected and the user will
3436 be given the opportunity to save these prefs under a different profile name.
3437 The prefs in question need to be listed in the console window so that the
3438 user can make an informed choice.
3440 g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
3441 cur_var->str, pline, pf_path, hint);
3442 prefs.unknown_prefs = TRUE;
3446 g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
3451 g_string_truncate(cur_var, 0);
3452 g_string_append_c(cur_var, (gchar) got_c);
3454 } else if (g_ascii_isspace(got_c) && cur_var->len > 0 && got_val) {
3456 } else if (got_c == '#') {
3459 g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
3464 g_string_append_c(cur_var, (gchar) got_c);
3466 /* This is a colon (':') */
3468 g_string_truncate(cur_val, 0);
3470 * Set got_val to TRUE to accommodate prefs such as
3471 * "gui.fileopen.dir" that do not require a value.
3477 if (!g_ascii_isspace(got_c)) {
3479 g_string_append_c(cur_val, (gchar) got_c);
3483 g_string_append_c(cur_val, (gchar) got_c);
3489 if (cur_var->len > 0) {
3491 /* Call the routine to set the preference; it will parse
3492 the value as appropriate.
3494 Since we're reading a file, rather than processing
3495 explicit user input, for range preferences, silently
3496 lower values in excess of the range's maximum, rather
3497 than reporting errors and failing. */
3498 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3503 case PREFS_SET_SYNTAX_ERR:
3504 g_warning ("Syntax error in preference %s at line %d of\n%s %s",
3505 cur_var->str, pline, pf_path, hint);
3508 case PREFS_SET_NO_SUCH_PREF:
3509 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3510 cur_var->str, pline, pf_path, hint);
3511 prefs.unknown_prefs = TRUE;
3514 case PREFS_SET_OBSOLETE:
3515 prefs.unknown_prefs = TRUE;
3519 g_warning ("Incomplete preference at line %d of\n%s %s",
3520 pline, pf_path, hint);
3524 g_string_free(cur_val, TRUE);
3525 g_string_free(cur_var, TRUE);
3534 * If we were handed a preference starting with "uat:", try to turn it into
3535 * a valid uat entry.
3538 prefs_set_uat_pref(char *uat_entry) {
3544 colonp = strchr(uat_entry, ':');
3552 * Skip over any white space (there probably won't be any, but
3553 * as we allow it in the preferences file, we might as well
3556 while (g_ascii_isspace(*p))
3560 * Put the colon back, so if our caller uses, in an
3561 * error message, the string they passed us, the message
3568 uat = uat_find(uat_entry);
3574 ret = uat_load_str(uat, p, &err);
3580 * Given a string of the form "<pref name>:<pref value>", as might appear
3581 * as an argument to a "-o" option, parse it and set the preference in
3582 * question. Return an indication of whether it succeeded or failed
3586 prefs_set_pref(char *prefarg)
3589 prefs_set_pref_e ret;
3592 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
3593 * seen to values that keep us from trying to interpret them
3594 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
3595 * as, from the command line, we have no way of guessing which
3596 * the user had in mind.
3598 mgcp_tcp_port_count = -1;
3599 mgcp_udp_port_count = -1;
3601 colonp = strchr(prefarg, ':');
3603 return PREFS_SET_SYNTAX_ERR;
3609 * Skip over any white space (there probably won't be any, but
3610 * as we allow it in the preferences file, we might as well
3613 while (g_ascii_isspace(*p))
3617 * Put the colon back, so if our caller uses, in an
3618 * error message, the string they passed us, the message
3622 return PREFS_SET_SYNTAX_ERR;
3624 if (strcmp(prefarg, "uat")) {
3625 ret = set_pref(prefarg, p, NULL, TRUE);
3627 ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
3629 *colonp = ':'; /* put the colon back */
3634 * Returns TRUE if the given device is hidden
3637 prefs_is_capture_device_hidden(const char *name)
3639 gchar *tok, *devices;
3642 if (prefs.capture_devices_hide && name) {
3643 devices = g_strdup (prefs.capture_devices_hide);
3644 len = strlen (name);
3645 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3646 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3658 * Returns TRUE if the given column is visible (not hidden)
3661 prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
3664 fmt_data cfmt_hidden;
3667 * Do we have a list of hidden columns?
3671 * Yes - check the column against each of the ones in the
3674 cols = g_strdup(cols_hidden);
3675 for (tok = strtok(cols, ","); tok; tok = strtok(NULL, ",")) {
3676 tok = g_strstrip(tok);
3679 * Parse this column format.
3681 if (!parse_column_format(&cfmt_hidden, tok)) {
3683 * It's not valid; ignore it.
3689 * Does it match the column?
3691 if (cfmt->fmt != cfmt_hidden.fmt) {
3693 g_free(cfmt_hidden.custom_field);
3694 cfmt_hidden.custom_field = NULL;
3697 if (cfmt->fmt == COL_CUSTOM) {
3699 * A custom column has to have the
3700 * same custom field and occurrence.
3702 if (cfmt_hidden.custom_field && cfmt->custom_field) {
3703 if (strcmp(cfmt->custom_field,
3704 cfmt_hidden.custom_field) != 0) {
3705 /* Different fields. */
3706 g_free(cfmt_hidden.custom_field);
3707 cfmt_hidden.custom_field = NULL;
3710 if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
3711 /* Different occurrences. */
3712 g_free(cfmt_hidden.custom_field);
3713 cfmt_hidden.custom_field = NULL;
3720 * OK, they match, so it's one of the hidden fields,
3721 * hence not visible.
3723 g_free(cfmt_hidden.custom_field);
3731 * No - either there are no hidden columns or this isn't one
3732 * of them - so it is visible.
3738 * Returns TRUE if the given device should capture in monitor mode by default
3741 prefs_capture_device_monitor_mode(const char *name)
3743 gchar *tok, *devices;
3746 if (prefs.capture_devices_monitor_mode && name) {
3747 devices = g_strdup (prefs.capture_devices_monitor_mode);
3748 len = strlen (name);
3749 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3750 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3762 * Returns TRUE if the user has marked this column as visible
3765 prefs_capture_options_dialog_column_is_visible(const gchar *column)
3770 for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
3771 col = (gchar *)curr->data;
3772 if (col && (g_ascii_strcasecmp(col, column) == 0)) {
3779 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
3780 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
3781 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
3783 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
3784 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
3785 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
3788 string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
3792 memset(name_resolve, 0, sizeof(e_addr_resolve));
3793 while ((c = *string++) != '\0') {
3796 name_resolve->mac_name = TRUE;
3799 name_resolve->network_name = TRUE;
3802 name_resolve->use_external_net_name_resolver = TRUE;
3805 name_resolve->transport_name = TRUE;
3808 name_resolve->concurrent_dns = TRUE;
3811 name_resolve->dns_pkt_addr_resolution = TRUE;
3815 * Unrecognized letter.
3825 try_convert_to_custom_column(gpointer *el_data)
3827 /* Array of columns that have been migrated to custom columns */
3830 const gchar *col_expr;
3831 } migrated_columns[] = {
3832 { COL_COS_VALUE, "vlan.priority" },
3833 { COL_CIRCUIT_ID, "iax2.call" },
3834 { COL_BSSGP_TLLI, "bssgp.tlli" },
3835 { COL_HPUX_SUBSYS, "nettl.subsys" },
3836 { COL_HPUX_DEVID, "nettl.devid" },
3837 { COL_FR_DLCI, "fr.dlci" },
3838 { COL_REL_CONV_TIME, "tcp.time_relative" },
3839 { COL_DELTA_CONV_TIME, "tcp.time_delta" },
3840 { COL_OXID, "fc.ox_id" },
3841 { COL_RXID, "fc.rx_id" },
3842 { COL_SRCIDX, "mdshdr.srcidx" },
3843 { COL_DSTIDX, "mdshdr.dstidx" },
3844 { COL_DCE_CTX, "dcerpc.cn_ctx_id" }
3848 const gchar *haystack_fmt;
3850 gchar **fmt = (gchar **) el_data;
3852 for (haystack_idx = 0;
3853 haystack_idx < G_N_ELEMENTS(migrated_columns);
3856 haystack_fmt = col_format_to_string(migrated_columns[haystack_idx].el);
3857 if (strcmp(haystack_fmt, *fmt) == 0) {
3858 gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
3859 migrated_columns[haystack_idx].col_expr);
3868 deprecated_heur_dissector_pref(gchar *pref_name, const gchar *value)
3870 struct heur_pref_name
3872 const char* pref_name;
3873 const char* short_name;
3874 gboolean more_dissectors; /* For multiple dissectors controlled by the same preference */
3877 struct heur_pref_name heur_prefs[] = {
3878 {"acn.heuristic_acn", "acn_udp", 0},
3879 {"bfcp.enable", "bfcp_tcp", 1},
3880 {"bfcp.enable", "bfcp_udp", 0},
3881 {"bt-dht.enable", "bittorrent_dht_udp", 0},
3882 {"bt-utp.enable", "bt_utp_udp", 0},
3883 {"cattp.enable", "cattp_udp", 0},
3884 {"cfp.enable", "fp_eth", 0},
3885 {"dicom.heuristic", "dicom_tcp", 0},
3886 {"dnp3.heuristics", "dnp3_tcp", 1},
3887 {"dnp3.heuristics", "dnp3_udp", 0},
3888 {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
3889 {"esl.enable", "esl_eth", 0},
3890 {"fp.udp_heur", "fp_udp", 0},
3891 {"gvsp.enable_heuristic", "gvsp_udp", 0},
3892 {"hdcp2.enable", "hdcp2_tcp", 0},
3893 {"hislip.enable_heuristic", "hislip_tcp", 0},
3894 {"jxta.udp.heuristic", "jxta_udp", 0},
3895 {"jxta.tcp.heuristic", "jxta_tcp", 0},
3896 {"jxta.sctp.heuristic", "jxta_sctp", 0},
3897 {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
3898 {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
3899 {"norm.heuristic_norm", "rmt_norm_udp", 0},
3900 {"openflow.heuristic", "openflow_tcp", 0},
3901 {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
3902 {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
3903 {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
3904 {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
3905 {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
3906 {"rtp.heuristic_rtp", "rtp_udp", 1},
3907 {"rtp.heuristic_rtp", "rtp_stun", 0},
3908 {"teredo.heuristic_teredo", "teredo_udp", 0},
3909 {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
3910 {"xml.heuristic", "xml_http", 1},
3911 {"xml.heuristic", "xml_sip", 1},
3912 {"xml.heuristic", "xml_media", 0},
3913 {"xml.heuristic_tcp", "xml_tcp", 0},
3914 {"xml.heuristic_udp", "xml_udp", 0},
3918 heur_dtbl_entry_t* heuristic;
3921 for (i = 0; i < sizeof(heur_prefs)/sizeof(struct heur_pref_name); i++)
3923 if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
3925 heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
3926 if (heuristic != NULL) {
3927 heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE);
3930 if (!heur_prefs[i].more_dissectors)
3939 static prefs_set_pref_e
3940 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
3941 gboolean return_range_errors)
3943 unsigned long int cval;
3948 gchar *dotp, *last_dotp;
3949 static gchar *filter_label = NULL;
3950 static gboolean filter_enabled = FALSE;
3951 gchar *filter_expr = NULL;
3955 if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
3956 filter_label = g_strdup(value);
3957 } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
3958 filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
3959 } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
3960 filter_expr = g_strdup(value);
3961 filter_expression_new(filter_label, filter_expr, filter_enabled);
3962 g_free(filter_label);
3963 g_free(filter_expr);
3964 } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
3965 /* Convert deprecated value to closest current equivalent */
3966 if (g_ascii_strcasecmp(value, "true") == 0) {
3967 prefs.gui_version_placement = version_both;
3969 prefs.gui_version_placement = version_neither;
3971 } else if (strcmp(pref_name, "name_resolve") == 0 ||
3972 strcmp(pref_name, "capture.name_resolve") == 0) {
3974 * Handle the deprecated name resolution options.
3976 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
3977 * RESOLV_ALL and RESOLV_NONE.
3979 * Otherwise, we treat it as a list of name types we want to resolve.
3981 if (g_ascii_strcasecmp(value, "true") == 0) {
3982 gbl_resolv_flags.mac_name = TRUE;
3983 gbl_resolv_flags.network_name = TRUE;
3984 gbl_resolv_flags.transport_name = TRUE;
3985 gbl_resolv_flags.concurrent_dns = TRUE;
3987 else if (g_ascii_strcasecmp(value, "false") == 0) {
3988 disable_name_resolution();
3991 /* start out with none set */
3992 disable_name_resolution();
3993 if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
3994 return PREFS_SET_SYNTAX_ERR;
3996 } else if (deprecated_heur_dissector_pref(pref_name, value)) {
3997 /* Handled within deprecated_heur_dissector_pref() if found */
3999 /* Handle deprecated "global" options that don't have a module
4000 * associated with them
4002 if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
4003 (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
4004 (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
4005 module = nameres_module;
4008 /* To which module does this preference belong? */
4010 last_dotp = pref_name;
4012 dotp = strchr(last_dotp, '.');
4014 /* Either there's no such module, or no module was specified.
4015 In either case, that means there's no such preference. */
4016 return PREFS_SET_NO_SUCH_PREF;
4018 *dotp = '\0'; /* separate module and preference name */
4019 module = prefs_find_module(pref_name);
4022 * XXX - "Diameter" rather than "diameter" was used in earlier
4023 * versions of Wireshark; if we didn't find the module, and its name
4024 * was "Diameter", look for "diameter" instead.
4026 * In addition, the BEEP protocol used to be the BXXP protocol,
4027 * so if we didn't find the module, and its name was "bxxp",
4028 * look for "beep" instead.
4030 * Also, the preferences for GTP v0 and v1 were combined under
4031 * a single "gtp" heading, and the preferences for SMPP were
4032 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
4033 * However, SMPP now has its own preferences, so we just map
4034 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
4036 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
4037 * and "nsip" to "gprs_ns".
4039 * The SynOptics Network Management Protocol (SONMP) is now known by
4040 * its modern name, the Nortel Discovery Protocol (NDP).
4042 if (module == NULL) {
4043 if (strcmp(pref_name, "column") == 0)
4044 module = gui_column_module;
4045 else if (strcmp(pref_name, "Diameter") == 0)
4046 module = prefs_find_module("diameter");
4047 else if (strcmp(pref_name, "bxxp") == 0)
4048 module = prefs_find_module("beep");
4049 else if (strcmp(pref_name, "gtpv0") == 0 ||
4050 strcmp(pref_name, "gtpv1") == 0)
4051 module = prefs_find_module("gtp");
4052 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
4053 module = prefs_find_module("gsm-sms-ud");
4054 else if (strcmp(pref_name, "dcp") == 0)
4055 module = prefs_find_module("dccp");
4056 else if (strcmp(pref_name, "x.25") == 0)
4057 module = prefs_find_module("x25");
4058 else if (strcmp(pref_name, "x411") == 0)
4059 module = prefs_find_module("p1");
4060 else if (strcmp(pref_name, "nsip") == 0)
4061 module = prefs_find_module("gprs-ns");
4062 else if (strcmp(pref_name, "sonmp") == 0)
4063 module = prefs_find_module("ndp");
4064 else if (strcmp(pref_name, "etheric") == 0 ||
4065 strcmp(pref_name, "isup_thin") == 0) {
4066 /* This protocol was removed 7. July 2009 */
4067 return PREFS_SET_OBSOLETE;
4070 g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
4071 "Save your preferences to make this change permanent.",
4072 pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
4073 prefs.unknown_prefs = TRUE;
4076 *dotp = '.'; /* put the preference string back */
4077 dotp++; /* skip past separator to preference name */
4082 pref = prefs_find_preference(module, dotp);
4085 prefs.unknown_prefs = TRUE;
4087 /* "gui" prefix was added to column preferences for better organization
4088 * within the preferences file
4090 if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
4091 (strcmp(pref_name, PRS_COL_FMT) == 0)) {
4092 pref = prefs_find_preference(module, pref_name);
4094 else if (strcmp(module->name, "mgcp") == 0) {
4096 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
4097 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
4098 * were used in earlier versions of Wireshark; if we didn't find the
4099 * preference, it was an MGCP preference, and its name was
4100 * "display raw text toggle" or "display dissect tree", look for
4101 * "display_raw_text" or "display_dissect_tree" instead.
4103 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
4104 * the gateway and callagent ports were given those names; we interpret
4105 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
4106 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
4107 * they were registered by the MCCP dissector and thus that's the
4108 * order in which they were written to the preferences file. (If
4109 * we're not reading the preferences file, but are handling stuff
4110 * from a "-o" command-line option, we have no clue which the user
4111 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
4112 * or "mgcp.{tcp,udp}.callagent_port" instead.)
4114 if (strcmp(dotp, "display raw text toggle") == 0)
4115 pref = prefs_find_preference(module, "display_raw_text");
4116 else if (strcmp(dotp, "display dissect tree") == 0)
4117 pref = prefs_find_preference(module, "display_dissect_tree");
4118 else if (strcmp(dotp, "tcp.port") == 0) {
4119 mgcp_tcp_port_count++;
4120 if (mgcp_tcp_port_count == 1) {
4121 /* It's the first one */
4122 pref = prefs_find_preference(module, "tcp.gateway_port");
4123 } else if (mgcp_tcp_port_count == 2) {
4124 /* It's the second one */
4125 pref = prefs_find_preference(module, "tcp.callagent_port");
4127 /* Otherwise it's from the command line, and we don't bother
4129 } else if (strcmp(dotp, "udp.port") == 0) {
4130 mgcp_udp_port_count++;
4131 if (mgcp_udp_port_count == 1) {
4132 /* It's the first one */
4133 pref = prefs_find_preference(module, "udp.gateway_port");
4134 } else if (mgcp_udp_port_count == 2) {
4135 /* It's the second one */
4136 pref = prefs_find_preference(module, "udp.callagent_port");
4138 /* Otherwise it's from the command line, and we don't bother
4141 } else if (strcmp(module->name, "smb") == 0) {
4142 /* Handle old names for SMB preferences. */
4143 if (strcmp(dotp, "smb.trans.reassembly") == 0)
4144 pref = prefs_find_preference(module, "trans_reassembly");
4145 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
4146 pref = prefs_find_preference(module, "dcerpc_reassembly");
4147 } else if (strcmp(module->name, "ndmp") == 0) {
4148 /* Handle old names for NDMP preferences. */
4149 if (strcmp(dotp, "ndmp.desegment") == 0)
4150 pref = prefs_find_preference(module, "desegment");
4151 } else if (strcmp(module->name, "diameter") == 0) {
4152 /* Handle old names for Diameter preferences. */
4153 if (strcmp(dotp, "diameter.desegment") == 0)
4154 pref = prefs_find_preference(module, "desegment");
4155 } else if (strcmp(module->name, "pcli") == 0) {
4156 /* Handle old names for PCLI preferences. */
4157 if (strcmp(dotp, "pcli.udp_port") == 0)
4158 pref = prefs_find_preference(module, "udp_port");
4159 } else if (strcmp(module->name, "artnet") == 0) {
4160 /* Handle old names for ARTNET preferences. */
4161 if (strcmp(dotp, "artnet.udp_port") == 0)
4162 pref = prefs_find_preference(module, "udp_port");
4163 } else if (strcmp(module->name, "mapi") == 0) {
4164 /* Handle old names for MAPI preferences. */
4165 if (strcmp(dotp, "mapi_decrypt") == 0)
4166 pref = prefs_find_preference(module, "decrypt");
4167 } else if (strcmp(module->name, "fc") == 0) {
4168 /* Handle old names for Fibre Channel preferences. */
4169 if (strcmp(dotp, "reassemble_fc") == 0)
4170 pref = prefs_find_preference(module, "reassemble");
4171 else if (strcmp(dotp, "fc_max_frame_size") == 0)
4172 pref = prefs_find_preference(module, "max_frame_size");
4173 } else if (strcmp(module->name, "fcip") == 0) {
4174 /* Handle old names for Fibre Channel-over-IP preferences. */
4175 if (strcmp(dotp, "desegment_fcip_messages") == 0)
4176 pref = prefs_find_preference(module, "desegment");
4177 else if (strcmp(dotp, "fcip_port") == 0)
4178 pref = prefs_find_preference(module, "target_port");
4179 } else if (strcmp(module->name, "gtp") == 0) {
4180 /* Handle old names for GTP preferences. */
4181 if (strcmp(dotp, "gtpv0_port") == 0)
4182 pref = prefs_find_preference(module, "v0_port");
4183 else if (strcmp(dotp, "gtpv1c_port") == 0)
4184 pref = prefs_find_preference(module, "v1c_port");
4185 else if (strcmp(dotp, "gtpv1u_port") == 0)
4186 pref = prefs_find_preference(module, "v1u_port");
4187 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
4188 pref = prefs_find_preference(module, "dissect_tpdu");
4189 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
4190 pref = prefs_find_preference(module, "v0_dissect_cdr_as");
4191 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
4192 pref = prefs_find_preference(module, "v0_check_etsi");
4193 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
4194 pref = prefs_find_preference(module, "v1_check_etsi");
4195 } else if (strcmp(module->name, "ip") == 0) {
4196 /* Handle old names for IP preferences. */
4197 if (strcmp(dotp, "ip_summary_in_tree") == 0)
4198 pref = prefs_find_preference(module, "summary_in_tree");
4199 } else if (strcmp(module->name, "iscsi") == 0) {
4200 /* Handle old names for iSCSI preferences. */
4201 if (strcmp(dotp, "iscsi_port") == 0)
4202 pref = prefs_find_preference(module, "target_port");
4203 } else if (strcmp(module->name, "lmp") == 0) {
4204 /* Handle old names for LMP preferences. */
4205 if (strcmp(dotp, "lmp_version") == 0)
4206 pref = prefs_find_preference(module, "version");
4207 } else if (strcmp(module->name, "mtp3") == 0) {
4208 /* Handle old names for MTP3 preferences. */
4209 if (strcmp(dotp, "mtp3_standard") == 0)
4210 pref = prefs_find_preference(module, "standard");
4211 else if (strcmp(dotp, "net_addr_format") == 0)
4212 pref = prefs_find_preference(module, "addr_format");
4213 } else if (strcmp(module->name, "nlm") == 0) {
4214 /* Handle old names for NLM preferences. */
4215 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
4216 pref = prefs_find_preference(module, "msg_res_matching");
4217 } else if (strcmp(module->name, "ppp") == 0) {
4218 /* Handle old names for PPP preferences. */
4219 if (strcmp(dotp, "ppp_fcs") == 0)
4220 pref = prefs_find_preference(module, "fcs_type");
4221 else if (strcmp(dotp, "ppp_vj") == 0)
4222 pref = prefs_find_preference(module, "decompress_vj");
4223 } else if (strcmp(module->name, "rsvp") == 0) {
4224 /* Handle old names for RSVP preferences. */
4225 if (strcmp(dotp, "rsvp_process_bundle") == 0)
4226 pref = prefs_find_preference(module, "process_bundle");
4227 } else if (strcmp(module->name, "tcp") == 0) {
4228 /* Handle old names for TCP preferences. */
4229 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
4230 pref = prefs_find_preference(module, "summary_in_tree");
4231 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
4232 pref = prefs_find_preference(module, "analyze_sequence_numbers");
4233 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
4234 pref = prefs_find_preference(module, "relative_sequence_numbers");
4235 } else if (strcmp(module->name, "udp") == 0) {
4236 /* Handle old names for UDP preferences. */
4237 if (strcmp(dotp, "udp_summary_in_tree") == 0)
4238 pref = prefs_find_preference(module, "summary_in_tree");
4239 } else if (strcmp(module->name, "ndps") == 0) {
4240 /* Handle old names for NDPS preferences. */
4241 if (strcmp(dotp, "desegment_ndps") == 0)
4242 pref = prefs_find_preference(module, "desegment_tcp");
4243 } else if (strcmp(module->name, "http") == 0) {
4244 /* Handle old names for HTTP preferences. */
4245 if (strcmp(dotp, "desegment_http_headers") == 0)
4246 pref = prefs_find_preference(module, "desegment_headers");
4247 else if (strcmp(dotp, "desegment_http_body") == 0)
4248 pref = prefs_find_preference(module, "desegment_body");
4249 } else if (strcmp(module->name, "smpp") == 0) {
4250 /* Handle preferences that moved from SMPP. */
4251 module_t *new_module = prefs_find_module("gsm-sms-ud");
4253 if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
4254 pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
4255 else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
4256 pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
4258 } else if (strcmp(module->name, "asn1") == 0) {
4259 /* Handle old generic ASN.1 preferences (it's not really a
4260 rename, as the new preferences support multiple ports,
4261 but we might as well copy them over). */
4262 if (strcmp(dotp, "tcp_port") == 0)
4263 pref = prefs_find_preference(module, "tcp_ports");
4264 else if (strcmp(dotp, "udp_port") == 0)
4265 pref = prefs_find_preference(module, "udp_ports");
4266 else if (strcmp(dotp, "sctp_port") == 0)
4267 pref = prefs_find_preference(module, "sctp_ports");
4268 } else if (strcmp(module->name, "llcgprs") == 0) {
4269 if (strcmp(dotp, "ignore_cipher_bit") == 0)
4270 pref = prefs_find_preference(module, "autodetect_cipher_bit");
4271 } else if (strcmp(module->name, "erf") == 0) {
4272 if (strcmp(dotp, "erfeth") == 0) {
4273 /* Handle the old "erfeth" preference; map it to the new
4274 "ethfcs" preference, and map the values to those for
4275 the new preference. */
4276 pref = prefs_find_preference(module, "ethfcs");
4277 if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
4279 else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
4281 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4283 } else if (strcmp(dotp, "erfatm") == 0) {
4284 /* Handle the old "erfatm" preference; map it to the new
4285 "aal5_type" preference, and map the values to those for
4286 the new preference. */
4287 pref = prefs_find_preference(module, "aal5_type");
4288 if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
4290 else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
4292 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4294 } else if (strcmp(dotp, "erfhdlc") == 0) {
4295 /* Handle the old "erfhdlc" preference; map it to the new
4296 "hdlc_type" preference, and map the values to those for
4297 the new preference. */
4298 pref = prefs_find_preference(module, "hdlc_type");
4299 if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
4301 else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
4303 else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
4305 else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
4307 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4310 } else if (strcmp(module->name, "eth") == 0) {
4311 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
4312 if (strcmp(dotp, "qinq_ethertype") == 0) {
4313 module_t *new_module = prefs_find_module("vlan");
4315 pref = prefs_find_preference(new_module, "qinq_ethertype");
4316 module = new_module;
4319 } else if (strcmp(module->name, "taps") == 0) {
4320 /* taps preferences moved to "statistics" module */
4321 if (strcmp(dotp, "update_interval") == 0 ||
4322 strcmp(dotp, "rtp_player_max_visible") == 0)
4323 pref = prefs_find_preference(stats_module, dotp);
4324 } else if (strcmp(module->name, "packet_list") == 0) {
4325 /* packet_list preferences moved to protocol module */
4326 if (strcmp(dotp, "display_hidden_proto_items") == 0)
4327 pref = prefs_find_preference(protocols_module, dotp);
4328 } else if (strcmp(module->name, "stream") == 0) {
4329 /* stream preferences moved to gui color module */
4330 if ((strcmp(dotp, "client.fg") == 0) ||
4331 (strcmp(dotp, "client.bg") == 0) ||
4332 (strcmp(dotp, "server.fg") == 0) ||
4333 (strcmp(dotp, "server.bg") == 0))
4334 pref = prefs_find_preference(gui_color_module, pref_name);
4335 } else if (strcmp(module->name, "nameres") == 0) {
4336 if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
4337 pref = prefs_find_preference(nameres_module, pref_name);
4338 } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
4339 pref = prefs_find_preference(nameres_module, "load_smi_modules");
4340 } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
4341 pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
4346 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
4348 switch (pref->type) {
4351 /* XXX - give an error if it doesn't fit in a guint? */
4352 uval = (guint)strtoul(value, &p, pref->info.base);
4353 if (p == value || *p != '\0')
4354 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4355 if (*pref->varp.uint != uval) {
4356 module->prefs_changed = TRUE;
4357 *pref->varp.uint = uval;
4362 /* XXX - give an error if it's neither "true" nor "false"? */
4363 if (g_ascii_strcasecmp(value, "true") == 0)
4367 if (*pref->varp.boolp != bval) {
4368 module->prefs_changed = TRUE;
4369 *pref->varp.boolp = bval;
4374 /* XXX - give an error if it doesn't match? */
4375 enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
4377 if (*pref->varp.enump != enum_val) {
4378 module->prefs_changed = TRUE;
4379 *pref->varp.enump = enum_val;
4386 if (strcmp(*pref->varp.string, value) != 0) {
4387 module->prefs_changed = TRUE;
4388 g_free((void *)*pref->varp.string);
4389 *pref->varp.string = g_strdup(value);
4397 if (range_convert_str_work(&newrange, value, pref->info.max_value,
4398 return_range_errors) != CVT_NO_ERROR) {
4399 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4402 if (!ranges_are_equal(*pref->varp.range, newrange)) {
4403 module->prefs_changed = TRUE;
4404 g_free(*pref->varp.range);
4405 *pref->varp.range = newrange;
4414 cval = strtoul(value, NULL, 16);
4415 pref->varp.colorp->pixel = 0;
4416 if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
4417 (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
4418 (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
4419 module->prefs_changed = TRUE;
4420 pref->varp.colorp->red = RED_COMPONENT(cval);
4421 pref->varp.colorp->green = GREEN_COMPONENT(cval);
4422 pref->varp.colorp->blue = BLUE_COMPONENT(cval);
4428 return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
4430 case PREF_STATIC_TEXT:
4437 return PREFS_SET_OBSOLETE; /* no such preference any more */
4441 return PREFS_SET_OK;
4446 gboolean is_gui_module;
4447 } write_gui_pref_arg_t;
4450 prefs_pref_type_name(pref_t *pref)
4452 const char *type_name = "[Unknown]";
4455 return type_name; /* ...or maybe assert? */
4458 switch (pref->type) {
4461 switch (pref->info.base) {
4464 type_name = "Decimal";
4468 type_name = "Octal";
4472 type_name = "Hexadecimal";
4478 type_name = "Boolean";
4482 type_name = "Choice";
4486 type_name = "String";
4490 type_name = "Filename";
4494 type_name = "Directory";
4498 type_name = "Range";
4502 type_name = "Color";
4506 if (pref->custom_cbs.type_name_cb)
4507 return pref->custom_cbs.type_name_cb();
4508 type_name = "Custom";
4512 type_name = "Obsolete";
4515 case PREF_STATIC_TEXT:
4516 type_name = "Static text";
4527 prefs_pref_type_description(pref_t *pref)
4529 const char *type_desc = "An unkown preference type";
4532 return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
4535 switch (pref->type) {
4538 switch (pref->info.base) {
4541 type_desc = "A decimal number";
4545 type_desc = "An octal number";
4549 type_desc = "A hexadecimal number";
4555 type_desc = "TRUE or FALSE (case-insensitive)";
4560 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4561 GString *enum_str = g_string_new("One of: ");
4562 while (enum_valp->name != NULL) {
4563 g_string_append(enum_str, enum_valp->description);
4565 if (enum_valp->name != NULL)
4566 g_string_append(enum_str, ", ");
4568 g_string_append(enum_str, "\n(case-insensitive).");
4569 return g_string_free(enum_str, FALSE);
4574 type_desc = "A string";
4578 type_desc = "A path to a file";
4582 type_desc = "A path to a directory";
4587 type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
4593 type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
4598 if (pref->custom_cbs.type_description_cb)
4599 return pref->custom_cbs.type_description_cb();
4600 type_desc = "A custom value";
4604 type_desc = "An obsolete preference";
4607 case PREF_STATIC_TEXT:
4608 type_desc = "[Static text]";
4612 type_desc = "Configuration data stored in its own file";
4618 return g_strdup(type_desc);
4622 prefs_pref_is_default(pref_t *pref) {
4623 if (!pref) return FALSE;
4625 switch (pref->type) {
4628 if (pref->default_val.uint == *pref->varp.uint)
4633 if (pref->default_val.boolval == *pref->varp.boolp)
4638 if (pref->default_val.enumval == *pref->varp.enump)
4645 if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
4651 if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
4658 if ((pref->default_val.color.red == pref->varp.colorp->red) &&
4659 (pref->default_val.color.green == pref->varp.colorp->green) &&
4660 (pref->default_val.color.blue == pref->varp.colorp->blue))
4666 return pref->custom_cbs.is_default_cb(pref);
4669 case PREF_STATIC_TEXT:
4672 /* g_assert_not_reached(); */
4679 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
4680 const char *pref_text = "[Unknown]";
4681 void *valp; /* pointer to preference value */
4682 color_t *pref_color;
4683 gchar *tmp_value, *ret_value;
4686 return g_strdup(pref_text);
4691 valp = &pref->default_val;
4692 /* valp = &boolval, &enumval, etc. are implied by union property */
4693 pref_color = &pref->default_val.color;
4696 valp = &pref->stashed_val;
4697 /* valp = &boolval, &enumval, etc. are implied by union property */
4698 pref_color = &pref->stashed_val.color;
4701 valp = pref->varp.uint;
4702 /* valp = boolval, enumval, etc. are implied by union property */
4703 pref_color = pref->varp.colorp;
4706 return g_strdup(pref_text);
4709 switch (pref->type) {
4713 guint pref_uint = *(guint *) valp;
4714 switch (pref->info.base) {
4717 return g_strdup_printf("%u", pref_uint);
4720 return g_strdup_printf("%#o", pref_uint);
4723 return g_strdup_printf("%#x", pref_uint);
4729 return g_strdup_printf("%s", (*(gboolean *) valp) ? "TRUE" : "FALSE");
4733 gint pref_enumval = *(gint *) valp;
4735 * For now, we return the "description" value, so that if we
4736 * save the preferences older versions of Wireshark can at
4737 * least read preferences that they supported; we support
4738 * either the short name or the description when reading
4739 * the preferences file or a "-o" option.
4741 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4742 while (enum_valp->name != NULL) {
4743 if (enum_valp->value == pref_enumval)
4744 return g_strdup(enum_valp->description);
4753 return g_strdup(*(const char **) valp);
4756 /* Convert wmem to g_alloc memory */
4757 tmp_value = range_convert_range(NULL, *(range_t **) valp);
4758 ret_value = g_strdup(tmp_value);
4759 wmem_free(NULL, tmp_value);
4763 return g_strdup_printf("%02x%02x%02x",
4764 (pref_color->red * 255 / 65535),
4765 (pref_color->green * 255 / 65535),
4766 (pref_color->blue * 255 / 65535));
4769 if (pref->custom_cbs.to_str_cb)
4770 return pref->custom_cbs.to_str_cb(pref, source == pref_default ? TRUE : FALSE);
4771 pref_text = "[Custom]";
4775 pref_text = "[Obsolete]";
4778 case PREF_STATIC_TEXT:
4779 pref_text = "[Static text]";
4784 uat_t *uat = pref->varp.uat;
4785 if (uat && uat->filename)
4786 return g_strdup_printf("[Managed in the file \"%s\"]", uat->filename);
4788 pref_text = "[Managed in an unknown file]";
4795 return g_strdup(pref_text);
4799 * Write out a single dissector preference.
4802 write_pref(gpointer data, gpointer user_data)
4804 pref_t *pref = (pref_t *)data;
4805 write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
4809 switch (pref->type) {
4812 * This preference is no longer supported; it's not a
4813 * real preference, so we don't write it out (i.e., we
4814 * treat it as if it weren't found in the list of
4815 * preferences, and we weren't called in the first place).
4819 case PREF_STATIC_TEXT:
4821 /* Nothing to do; don't bother printing the description */
4827 if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL) {
4829 * The prefix will either be the module name or the parent
4830 * name if it's a subtree
4832 const char *name_prefix = (arg->module->name != NULL) ? arg->module->name : arg->module->parent->name;
4833 char *type_desc, *pref_text;
4834 const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
4836 if (pref->type == PREF_CUSTOM) fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
4837 fprintf(arg->pf, "\n");
4838 if (pref->description &&
4839 (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
4840 if (pref->type != PREF_CUSTOM) {
4841 /* We get duplicate lines otherwise. */
4843 desc_lines = g_strsplit(pref->description,"\n",0);
4844 for (i = 0; desc_lines[i] != NULL; ++i) {
4845 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4847 g_strfreev(desc_lines);
4850 fprintf(arg->pf, "# No description\n");
4853 type_desc = prefs_pref_type_description(pref);
4854 desc_lines = g_strsplit(type_desc,"\n",0);
4855 for (i = 0; desc_lines[i] != NULL; ++i) {
4856 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4858 g_strfreev(desc_lines);
4861 pref_text = prefs_pref_to_str(pref, pref_current);
4862 fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
4863 desc_lines = g_strsplit(pref_text,"\n",0);
4864 for (i = 0; desc_lines[i] != NULL; ++i) {
4865 fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
4867 if (i == 0) fprintf(arg->pf, "\n");
4868 g_strfreev(desc_lines);
4875 * Write out all preferences for a module.
4878 write_module_prefs(module_t *module, gpointer user_data)
4880 write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
4881 write_pref_arg_t arg;
4883 /* The GUI module needs to be explicitly called out so it
4884 can be written out of order */
4885 if ((module == gui_module) && (gui_pref_arg->is_gui_module != TRUE))
4888 /* Write a header for the main modules and GUI sub-modules */
4889 if (((module->parent == NULL) || (module->parent == gui_module)) &&
4890 ((prefs_module_has_submodules(module)) ||
4891 (module->numprefs > 0) ||
4892 (module->name == NULL))) {
4893 if ((module->name == NULL) && (module->parent != NULL)) {
4894 fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
4896 fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
4900 arg.module = module;
4901 arg.pf = gui_pref_arg->pf;
4902 g_list_foreach(arg.module->prefs, write_pref, &arg);
4904 if (prefs_module_has_submodules(module))
4905 return prefs_modules_foreach_submodules(module, write_module_prefs, user_data);
4910 /* Write out "prefs" to the user's preferences file, and return 0.
4912 If the preferences file path is NULL, write to stdout.
4914 If we got an error, stuff a pointer to the path of the preferences file
4915 into "*pf_path_return", and return the errno. */
4917 write_prefs(char **pf_path_return)
4921 write_gui_pref_arg_t write_gui_pref_info;
4923 /* Needed for "-G defaultprefs" */
4927 * - Split output lines longer than MAX_VAL_LEN
4928 * - Create a function for the preference directory check/creation
4929 * so that duplication can be avoided with filter.c
4932 if (pf_path_return != NULL) {
4933 pf_path = get_persconffile_path(PF_NAME, TRUE);
4934 if ((pf = ws_fopen(pf_path, "w")) == NULL) {
4935 *pf_path_return = pf_path;
4942 fputs("# Configuration file for Wireshark " VERSION ".\n"
4944 "# This file is regenerated each time preferences are saved within\n"
4945 "# Wireshark. Making manual changes should be safe, however.\n"
4946 "# Preferences that have been commented out have not been\n"
4947 "# changed from their default value.\n", pf);
4950 * For "backwards compatibility" the GUI module is written first as it's
4951 * at the top of the file. This is followed by all modules that can't
4952 * fit into the preferences read/write API. Finally the remaining modules
4953 * are written in alphabetical order (including of course the protocol preferences)
4955 write_gui_pref_info.pf = pf;
4956 write_gui_pref_info.is_gui_module = TRUE;
4958 write_module_prefs(gui_module, &write_gui_pref_info);
4961 struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
4964 fprintf(pf, "\n####### Filter Expressions ########\n");
4966 while (fe != NULL) {
4967 if (fe->deleted == FALSE) {
4968 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
4969 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
4970 fe->enabled == TRUE ? "TRUE" : "FALSE");
4971 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
4977 write_gui_pref_info.is_gui_module = FALSE;
4978 prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
4982 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
4983 an error indication, or maybe write to a new preferences file and
4984 rename that file on top of the old one only if there are not I/O
4989 /** The col_list is only partly managed by the custom preference API
4990 * because its data is shared between multiple preferences, so
4994 free_col_info(GList *list)
4997 GList *list_head = list;
4999 while (list != NULL) {
5000 cfmt = (fmt_data *)list->data;
5002 g_free(cfmt->title);
5003 g_free(cfmt->custom_field);
5005 list = g_list_next(list);
5007 g_list_free(list_head);
5016 * indent-tabs-mode: nil
5019 * ex: set shiftwidth=4 tabstop=8 expandtab:
5020 * :indentSize=4:tabSize=8:noTabs=true: