2 * Routines for handling preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39 #include <epan/filesystem.h>
40 #include <epan/address.h>
41 #include <epan/addr_resolv.h>
42 #include <epan/oids.h>
44 #include <epan/geoip_db.h>
46 #include <epan/packet.h>
47 #include <epan/prefs.h>
48 #include <epan/proto.h>
49 #include <epan/strutil.h>
50 #include <epan/column.h>
52 #include <wsutil/file_util.h>
54 #include <epan/prefs-int.h>
55 #include <epan/uat-int.h>
57 #include "epan/filter_expressions.h"
59 #include "epan/wmem/wmem.h"
61 /* Internal functions */
62 static module_t *find_subtree(module_t *parent, const char *tilte);
63 static module_t *prefs_register_module_or_subtree(module_t *parent,
64 const char *name, const char *title, const char *description, gboolean is_subtree,
65 void (*apply_cb)(void), gboolean use_gui);
66 static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
67 static char * join_string_list(GList *);
68 static void free_col_info(GList *);
69 static void pre_init_prefs(void);
70 static gboolean prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt);
71 static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
72 static void try_convert_to_custom_column(gpointer *el_data);
75 #define PF_NAME "preferences"
76 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
78 static gboolean prefs_initialized = FALSE;
79 static gboolean prefs_pre_initialized = FALSE;
80 static gchar *gpf_path = NULL;
81 static gchar *cols_hidden_list = NULL;
84 * XXX - variables to allow us to attempt to interpret the first
85 * "mgcp.{tcp,udp}.port" in a preferences file as
86 * "mgcp.{tcp,udp}.gateway_port" and the second as
87 * "mgcp.{tcp,udp}.callagent_port".
89 static int mgcp_tcp_port_count;
90 static int mgcp_udp_port_count;
94 static const enum_val_t gui_ptree_line_style[] = {
96 {"SOLID", "SOLID", 1},
97 {"DOTTED", "DOTTED", 2},
98 {"TABBED", "TABBED", 3},
102 static const enum_val_t gui_ptree_expander_style[] = {
104 {"SQUARE", "SQUARE", 1},
105 {"TRIANGLE", "TRIANGLE", 2},
106 {"CIRCULAR", "CIRCULAR", 3},
110 static const enum_val_t gui_hex_dump_highlight_style[] = {
112 {"INVERSE", "INVERSE", 1},
116 static const enum_val_t gui_console_open_type[] = {
117 {"NEVER", "NEVER", console_open_never},
118 {"AUTOMATIC", "AUTOMATIC", console_open_auto},
119 {"ALWAYS", "ALWAYS", console_open_always},
123 static const enum_val_t gui_version_placement_type[] = {
124 {"WELCOME", "WELCOME", version_welcome_only},
125 {"TITLE", "TITLE", version_title_only},
126 {"BOTH", "BOTH", version_both},
127 {"NEITHER", "NEITHER", version_neither},
131 static const enum_val_t gui_fileopen_style[] = {
132 {"LAST_OPENED", "LAST_OPENED", 0},
133 {"SPECIFIED", "SPECIFIED", 1},
137 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
138 * as this may not work on other guis, we use only "both" in general here */
139 static const enum_val_t gui_toolbar_style[] = {
140 {"ICONS", "ICONS", 0},
146 static const enum_val_t gui_layout_content[] = {
148 {"PLIST", "PLIST", 1},
149 {"PDETAILS", "PDETAILS", 2},
150 {"PBYTES", "PBYTES", 3},
154 static const enum_val_t gui_update_channel[] = {
155 {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT},
156 {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE},
160 #if defined(HAVE_PCAP_CREATE)
161 static gint num_capture_cols = 7;
162 static const gchar *capture_cols[7] = {
170 #elif defined(_WIN32) && !defined (HAVE_PCAP_CREATE)
171 static gint num_capture_cols = 6;
172 static const gchar *capture_cols[6] = {
180 static gint num_capture_cols = 5;
181 static const gchar *capture_cols[5] = {
190 * List of all modules with preference settings.
192 static emem_tree_t *prefs_modules = NULL;
195 * List of all modules that should show up at the top level of the
196 * tree in the preference dialog box.
198 static emem_tree_t *prefs_top_level_modules = NULL;
200 /** Sets up memory used by proto routines. Called at program startup */
204 prefs_modules = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK, "prefs_modules");
205 prefs_top_level_modules = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK, "prefs_top_level_modules");
209 free_pref(gpointer data, gpointer user_data _U_)
211 pref_t *pref = (pref_t *)data;
213 switch (pref->type) {
218 case PREF_STATIC_TEXT:
225 g_free((char *)*pref->varp.string);
226 *pref->varp.string = NULL;
227 g_free(pref->default_val.string);
228 pref->default_val.string = NULL;
231 g_free(*pref->varp.range);
232 *pref->varp.range = NULL;
233 g_free(pref->default_val.range);
234 pref->default_val.range = NULL;
237 if (strcmp(pref->name, "columns") == 0)
238 pref->stashed_val.boolval = TRUE;
239 pref->custom_cbs.free_cb(pref);
247 free_module_prefs(module_t *module, gpointer data _U_)
249 g_list_foreach(module->prefs, free_pref, NULL);
250 g_list_free(module->prefs);
251 module->prefs = NULL;
252 module->numprefs = 0;
253 /* We don't free the actual module: its submodules pointer points to
254 a pe_tree and the module itself is stored in a pe_tree
260 /** Frees memory used by proto routines. Called at program shutdown */
264 /* This isn't strictly necessary since we're exiting anyway, but let's
265 * do what clean up we can.
267 prefs_modules_foreach(free_module_prefs, NULL);
271 * Register a module that will have preferences.
272 * Specify the module under which to register it or NULL to register it
273 * at the top level, the name used for the module in the preferences file,
274 * the title used in the tab for it in a preferences dialog box, and a
275 * routine to call back when we apply the preferences.
278 prefs_register_module(module_t *parent, const char *name, const char *title,
279 const char *description, void (*apply_cb)(void),
280 const gboolean use_gui)
282 return prefs_register_module_or_subtree(parent, name, title, description,
283 FALSE, apply_cb, use_gui);
287 * Register a subtree that will have modules under it.
288 * Specify the module under which to register it or NULL to register it
289 * at the top level and the title used in the tab for it in a preferences
293 prefs_register_subtree(module_t *parent, const char *title, const char *description,
294 void (*apply_cb)(void))
296 return prefs_register_module_or_subtree(parent, NULL, title, description,
298 parent ? parent->use_gui : FALSE);
302 prefs_register_module_or_subtree(module_t *parent, const char *name,
303 const char *title, const char *description,
304 gboolean is_subtree, void (*apply_cb)(void),
311 /* this module may have been created as a subtree item previously */
312 if((module = find_subtree(parent, title))) {
313 /* the module is currently a subtree */
315 module->apply_cb = apply_cb;
316 module->description = description;
318 if (prefs_find_module(name) == NULL) {
319 pe_tree_insert_string(prefs_modules, name, module,
320 EMEM_TREE_STRING_NOCASE);
326 module = g_new(module_t,1);
328 module->title = title;
329 module->description = description;
330 module->apply_cb = apply_cb;
331 module->prefs = NULL; /* no preferences, to start */
332 module->parent = parent;
333 module->submodules = NULL; /* no submodules, to start */
334 module->numprefs = 0;
335 module->prefs_changed = FALSE;
336 module->obsolete = FALSE;
337 module->use_gui = use_gui;
340 * Do we have a module name?
345 * Make sure that only lower-case ASCII letters, numbers,
346 * underscores, hyphens, and dots appear in the name.
348 * Crash if there is, as that's an error in the code;
349 * you can make the title a nice string with capitalization,
350 * white space, punctuation, etc., but the name can be used
351 * on the command line, and shouldn't require quoting,
354 for (p = name; (c = *p) != '\0'; p++)
355 g_assert(isascii(c) &&
356 (islower(c) || isdigit(c) || c == '_' ||
357 c == '-' || c == '.'));
360 * Make sure there's not already a module with that
361 * name. Crash if there is, as that's an error in the
362 * code, and the code has to be fixed not to register
363 * more than one module with the same name.
365 * We search the list of all modules; the subtree stuff
366 * doesn't require preferences in subtrees to have names
367 * that reflect the subtree they're in (that would require
368 * protocol preferences to have a bogus "protocol.", or
369 * something such as that, to be added to all their names).
371 g_assert(prefs_find_module(name) == NULL);
374 * Insert this module in the list of all modules.
376 pe_tree_insert_string(prefs_modules, name, module, EMEM_TREE_STRING_NOCASE);
379 * This has no name, just a title; check to make sure it's a
380 * subtree, and crash if it's not.
382 g_assert(is_subtree);
386 * Insert this module into the appropriate place in the display
389 if (parent == NULL) {
391 * It goes at the top.
393 pe_tree_insert_string(prefs_top_level_modules, title, module, EMEM_TREE_STRING_NOCASE);
396 * It goes into the list for this module.
399 if (parent->submodules == NULL)
400 parent->submodules = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK, "prefs_submodules");
402 pe_tree_insert_string(parent->submodules, title, module, EMEM_TREE_STRING_NOCASE);
409 * Register that a protocol has preferences.
411 module_t *protocols_module = NULL;
414 prefs_register_protocol(int id, void (*apply_cb)(void))
416 protocol_t *protocol;
419 * Have we yet created the "Protocols" subtree?
421 if (protocols_module == NULL) {
423 * No. Register Protocols subtree as well as any preferences
424 * for non-dissector modules.
426 prefs_register_modules();
428 protocol = find_protocol_by_id(id);
429 return prefs_register_module(protocols_module,
430 proto_get_protocol_filter_name(id),
431 proto_get_protocol_short_name(protocol),
432 proto_get_protocol_name(id), apply_cb, TRUE);
436 prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
438 protocol_t *protocol;
439 module_t *subtree_module;
440 module_t *new_module;
441 char *sep = NULL, *ptr = NULL, *orig = NULL;
444 * Have we yet created the "Protocols" subtree?
445 * XXX - can we just do this by registering Protocols/{subtree}?
448 if (protocols_module == NULL) {
450 * No. Register Protocols subtree as well as any preferences
451 * for non-dissector modules.
453 prefs_register_modules();
456 subtree_module = protocols_module;
459 /* take a copy of the buffer, orig keeps a base pointer while ptr
460 * walks through the string */
461 orig = ptr = g_strdup(subtree);
465 if((sep = strchr(ptr, '/')))
468 if(!(new_module = find_subtree(subtree_module, ptr))) {
470 * There's no such module; create it, with the description
471 * being the name (if it's later registered explicitly
472 * with a description, that will override it).
474 ptr = wmem_strdup(wmem_epan_scope(), ptr),
475 new_module = prefs_register_subtree(subtree_module, ptr, ptr, NULL);
478 subtree_module = new_module;
486 protocol = find_protocol_by_id(id);
487 return prefs_register_module(subtree_module,
488 proto_get_protocol_filter_name(id),
489 proto_get_protocol_short_name(protocol),
490 proto_get_protocol_name(id), apply_cb, TRUE);
495 * Register that a protocol used to have preferences but no longer does,
496 * by creating an "obsolete" module for it.
499 prefs_register_protocol_obsolete(int id)
502 protocol_t *protocol;
505 * Have we yet created the "Protocols" subtree?
507 if (protocols_module == NULL) {
509 * No. Register Protocols subtree as well as any preferences
510 * for non-dissector modules.
512 prefs_register_modules();
514 protocol = find_protocol_by_id(id);
515 module = prefs_register_module(protocols_module,
516 proto_get_protocol_filter_name(id),
517 proto_get_protocol_short_name(protocol),
518 proto_get_protocol_name(id), NULL, TRUE);
519 module->obsolete = TRUE;
524 * Register that a statistical tap has preferences.
526 * "name" is a name for the tap to use on the command line with "-o"
527 * and in preference files.
529 * "title" is a short human-readable name for the tap.
531 * "description" is a longer human-readable description of the tap.
533 module_t *stats_module = NULL;
536 prefs_register_stat(const char *name, const char *title,
537 const char *description, void (*apply_cb)(void))
540 * Have we yet created the "Statistics" subtree?
542 if (stats_module == NULL) {
544 * No. Register Statistics subtree as well as any preferences
545 * for non-dissector modules.
547 prefs_register_modules();
550 return prefs_register_module(stats_module, name, title, description,
555 prefs_find_module(const char *name)
557 return (module_t *)pe_tree_lookup_string(prefs_modules, name, EMEM_TREE_STRING_NOCASE);
561 find_subtree(module_t *parent, const char *name)
563 return (module_t *)pe_tree_lookup_string(parent ? parent->submodules : prefs_top_level_modules, name, EMEM_TREE_STRING_NOCASE);
567 * Call a callback function, with a specified argument, for each module
568 * in a list of modules. If the list is NULL, searches the top-level
569 * list in the display tree of modules. If any callback returns a
570 * non-zero value, we stop and return that value, otherwise we
573 * Ignores "obsolete" modules; their sole purpose is to allow old
574 * preferences for dissectors that no longer have preferences to be
575 * silently ignored in preference files. Does not ignore subtrees,
576 * as this can be used when walking the display tree of modules.
586 call_foreach_cb(void *value, void *data)
588 module_t *module = (module_t*)value;
589 call_foreach_t *call_data = (call_foreach_t*)data;
591 if (!module->obsolete) {
592 call_data->ret = (*call_data->callback)(module, call_data->user_data);
594 return (call_data->ret != 0);
598 prefs_module_list_foreach(emem_tree_t *module_list, module_cb callback,
601 call_foreach_t call_data;
603 if (module_list == NULL)
604 module_list = prefs_top_level_modules;
606 call_data.callback = callback;
607 call_data.user_data = user_data;
609 pe_tree_foreach(module_list, call_foreach_cb, &call_data);
610 return call_data.ret;
614 * Returns TRUE if module has any submodules
617 prefs_module_has_submodules(module_t *module)
619 if (module->submodules == NULL) {
623 if (module->submodules->tree == NULL) {
631 * Call a callback function, with a specified argument, for each module
632 * in the list of all modules. (This list does not include subtrees.)
634 * Ignores "obsolete" modules; their sole purpose is to allow old
635 * preferences for dissectors that no longer have preferences to be
636 * silently ignored in preference files.
639 prefs_modules_foreach(module_cb callback, gpointer user_data)
641 return prefs_module_list_foreach(prefs_modules, callback, user_data);
645 * Call a callback function, with a specified argument, for each submodule
646 * of specified modules. If the module is NULL, goes through the top-level
647 * list in the display tree of modules.
649 * Ignores "obsolete" modules; their sole purpose is to allow old
650 * preferences for dissectors that no longer have preferences to be
651 * silently ignored in preference files. Does not ignore subtrees,
652 * as this can be used when walking the display tree of modules.
655 prefs_modules_foreach_submodules(module_t *module, module_cb callback,
658 return prefs_module_list_foreach((module)?module->submodules:prefs_top_level_modules, callback, user_data);
662 call_apply_cb(void *value, void *data _U_)
664 module_t *module = (module_t *)value;
666 if (module->obsolete)
668 if (module->prefs_changed) {
669 if (module->apply_cb != NULL)
670 (*module->apply_cb)();
671 module->prefs_changed = FALSE;
677 * Call the "apply" callback function for each module if any of its
678 * preferences have changed, and then clear the flag saying its
679 * preferences have changed, as the module has been notified of that
683 prefs_apply_all(void)
685 pe_tree_foreach(prefs_modules, call_apply_cb, NULL);
689 * Call the "apply" callback function for a specific module if any of
690 * its preferences have changed, and then clear the flag saying its
691 * preferences have changed, as the module has been notified of that
695 prefs_apply(module_t *module)
697 if (module && module->prefs_changed)
698 call_apply_cb(module, NULL);
702 * Register a preference in a module's list of preferences.
703 * If it has a title, give it an ordinal number; otherwise, it's a
704 * preference that won't show up in the UI, so it shouldn't get an
705 * ordinal number (the ordinal should be the ordinal in the set of
706 * *visible* preferences).
709 register_preference(module_t *module, const char *name, const char *title,
710 const char *description, pref_type_t type)
715 preference = g_new(pref_t,1);
716 preference->name = name;
717 preference->title = title;
718 preference->description = description;
719 preference->type = type;
721 preference->ordinal = module->numprefs;
723 preference->ordinal = -1; /* no ordinal for you */
726 * Make sure that only lower-case ASCII letters, numbers,
727 * underscores, and dots appear in the preference name.
729 * Crash if there is, as that's an error in the code;
730 * you can make the title and description nice strings
731 * with capitalization, white space, punctuation, etc.,
732 * but the name can be used on the command line,
733 * and shouldn't require quoting, shifting, etc.
735 for (p = name; *p != '\0'; p++)
736 if (!(isascii((guchar)*p) &&
737 (islower((guchar)*p) || isdigit((guchar)*p) || *p == '_' || *p == '.')))
738 g_error("Preference %s.%s contains invalid characters", module->name, name);
741 * Make sure there's not already a preference with that
742 * name. Crash if there is, as that's an error in the
743 * code, and the code has to be fixed not to register
744 * more than one preference with the same name.
746 if (prefs_find_preference(module, name) != NULL)
747 g_error("Preference %s has already been registered", name);
749 if ((type != PREF_OBSOLETE) &&
750 /* Don't compare if it's a subtree */
751 (module->name != NULL)) {
753 * Make sure the preference name doesn't begin with the
754 * module name, as that's redundant and Just Silly.
756 if(!((strncmp(name, module->name, strlen(module->name)) != 0) ||
757 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_'))))
758 g_error("Preference %s begins with the module name", name);
762 * There isn't already one with that name, so add the
765 module->prefs = g_list_append(module->prefs, preference);
773 * Find a preference in a module's list of preferences, given the module
774 * and the preference's name.
782 preference_match(gconstpointer a, gconstpointer b)
784 const pref_t *pref = (const pref_t *)a;
785 const char *name = (const char *)b;
787 return strcmp(name, pref->name);
790 static gboolean module_find_pref_cb(void *value, void *data)
792 find_pref_arg_t* arg = (find_pref_arg_t*)data;
794 module_t *module = (module_t *)value;
799 list_entry = g_list_find_custom(module->prefs, arg->name,
802 if (list_entry == NULL)
805 arg->list_entry = list_entry;
810 prefs_find_preference(module_t *module, const char *name)
816 return NULL; /* invalid parameters */
818 list_entry = g_list_find_custom(module->prefs, name,
821 if (list_entry == NULL)
823 arg.list_entry = NULL;
824 if (module->submodules != NULL)
827 pe_tree_foreach(module->submodules, module_find_pref_cb, &arg);
830 list_entry = arg.list_entry;
833 if (list_entry == NULL)
835 return NULL; /* no such preference */
838 return (struct preference *) list_entry->data;
842 * Returns TRUE if the given protocol has registered preferences
845 prefs_is_registered_protocol(const char *name)
847 module_t *m = prefs_find_module(name);
849 return (m != NULL && !m->obsolete);
853 * Returns the module title of a registered protocol
856 prefs_get_title_by_name(const char *name)
858 module_t *m = prefs_find_module(name);
860 return (m != NULL && !m->obsolete) ? m->title : NULL;
864 * Register a preference with an unsigned integral value.
867 prefs_register_uint_preference(module_t *module, const char *name,
868 const char *title, const char *description,
869 guint base, guint *var)
873 preference = register_preference(module, name, title, description,
875 preference->varp.uint = var;
876 preference->default_val.uint = *var;
877 g_assert(base > 0 && base != 1 && base < 37);
878 preference->info.base = base;
882 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
887 * Register a "custom" preference with a unsigned integral value.
888 * XXX - This should be temporary until we can find a better way
889 * to do "custom" preferences
892 prefs_register_uint_custom_preference(module_t *module, const char *name,
893 const char *title, const char *description,
894 struct pref_custom_cbs* custom_cbs, guint *var)
898 preference = register_preference(module, name, title, description,
901 preference->custom_cbs = *custom_cbs;
902 preference->varp.uint = var;
903 preference->default_val.uint = *var;
907 * Register a preference with an Boolean value.
910 prefs_register_bool_preference(module_t *module, const char *name,
911 const char *title, const char *description,
916 preference = register_preference(module, name, title, description,
918 preference->varp.boolp = var;
919 preference->default_val.boolval = *var;
923 * Register a preference with an enumerated value.
926 prefs_register_enum_preference(module_t *module, const char *name,
927 const char *title, const char *description,
928 gint *var, const enum_val_t *enumvals,
929 gboolean radio_buttons)
933 preference = register_preference(module, name, title, description,
935 preference->varp.enump = var;
936 preference->default_val.enumval = *var;
937 preference->info.enum_info.enumvals = enumvals;
938 preference->info.enum_info.radio_buttons = radio_buttons;
942 register_string_like_preference(module_t *module, const char *name,
943 const char *title, const char *description,
944 const char **var, pref_type_t type)
949 preference = register_preference(module, name, title, description,
953 * String preference values should be non-null (as you can't
954 * keep them null after using the preferences GUI, you can at best
955 * have them be null strings) and freeable (as we free them
956 * if we change them).
958 * If the value is a null pointer, make it a copy of a null
959 * string, otherwise make it a copy of the value.
963 varcopy = g_strdup("");
965 *var = g_strdup(*var);
966 varcopy = g_strdup(*var);
968 preference->varp.string = var;
969 preference->default_val.string = varcopy;
970 preference->stashed_val.string = NULL;
976 * Register a preference with a character-string value.
979 prefs_register_string_preference(module_t *module, const char *name,
980 const char *title, const char *description,
983 register_string_like_preference(module, name, title, description, var,
988 * Register a "custom" preference with a character-string value.
989 * XXX - This should be temporary until we can find a better way
990 * to do "custom" preferences
993 void prefs_register_string_custom_preference(module_t *module, const char *name,
994 const char *title, const char *description,
995 struct pref_custom_cbs* custom_cbs, const char **var)
999 preference = register_string_like_preference(module, name, title, description, var,
1002 preference->custom_cbs = *custom_cbs;
1007 * Register a preference with a file name (string) value.
1010 prefs_register_filename_preference(module_t *module, const char *name,
1011 const char *title, const char *description,
1014 register_string_like_preference(module, name, title, description, var,
1019 * Register a preference with a directory name (string) value.
1022 prefs_register_directory_preference(module_t *module, const char *name,
1023 const char *title, const char *description,
1026 register_string_like_preference(module, name, title, description, var,
1031 * Register a preference with a ranged value.
1034 prefs_register_range_preference(module_t *module, const char *name,
1035 const char *title, const char *description,
1036 range_t **var, guint32 max_value)
1040 preference = register_preference(module, name, title, description,
1042 preference->info.max_value = max_value;
1046 * Range preference values should be non-null (as you can't
1047 * keep them null after using the preferences GUI, you can at best
1048 * have them be empty ranges) and freeable (as we free them
1049 * if we change them).
1051 * If the value is a null pointer, make it an empty range.
1054 *var = range_empty();
1055 preference->varp.range = var;
1056 preference->default_val.range = range_copy(*var);
1057 preference->stashed_val.range = NULL;
1061 * Register a static text 'preference'. It can be used to add explanatory
1062 * text inline with other preferences in the GUI.
1063 * Note: Static preferences are not saved to the preferences file.
1066 prefs_register_static_text_preference(module_t *module, const char *name,
1068 const char *description)
1070 register_preference(module, name, title, description, PREF_STATIC_TEXT);
1074 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1075 * preferences tab of the module.
1078 prefs_register_uat_preference(module_t *module, const char *name,
1079 const char *title, const char *description,
1083 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1085 preference->varp.uat = uat;
1089 * Register a color preference.
1091 void prefs_register_color_preference(module_t *module, const char *name,
1092 const char *title, const char *description, color_t *color)
1094 pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
1096 preference->varp.colorp = color;
1097 preference->default_val.color = *color;
1101 * Register a "custom" preference with a list.
1102 * XXX - This should be temporary until we can find a better way
1103 * to do "custom" preferences
1105 typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
1108 void prefs_register_list_custom_preference(module_t *module, const char *name,
1109 const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
1110 pref_custom_list_init_cb init_cb, GList** list)
1112 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1114 preference->custom_cbs = *custom_cbs;
1115 init_cb(preference, list);
1119 * Register a custom preference.
1121 void prefs_register_custom_preference(module_t *module, const char *name,
1122 const char *title, const char *description, struct pref_custom_cbs* custom_cbs,
1123 void** custom_data _U_)
1125 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1127 preference->custom_cbs = *custom_cbs;
1128 /* XXX - wait until we can handle void** pointers
1129 preference->custom_cbs.init_cb(preference, custom_data);
1134 * Register a preference that used to be supported but no longer is.
1137 prefs_register_obsolete_preference(module_t *module, const char *name)
1139 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
1143 * Check to see if a preference is obsolete.
1146 prefs_get_preference_obsolete(pref_t *pref)
1149 return pref->type == PREF_OBSOLETE ? TRUE : FALSE;
1155 * Make a preference obsolete.
1157 extern prefs_set_pref_e
1158 prefs_set_preference_obsolete(pref_t *pref)
1161 pref->type = PREF_OBSOLETE;
1162 return PREFS_SET_OK;
1164 return PREFS_SET_NO_SUCH_PREF;
1167 /* Return the value assigned to the given uint preference. */
1168 guint prefs_get_uint_preference(pref_t *pref)
1170 if (pref && pref->type == PREF_UINT)
1171 return *pref->varp.uint;
1176 * Call a callback function, with a specified argument, for each preference
1177 * in a given module.
1179 * If any of the callbacks return a non-zero value, stop and return that
1180 * value, otherwise return 0.
1183 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
1189 for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
1190 pref = (pref_t *)elem->data;
1191 if (pref->type == PREF_OBSOLETE) {
1193 * This preference is no longer supported; it's
1194 * not a real preference, so we don't call the
1195 * callback for it (i.e., we treat it as if it
1196 * weren't found in the list of preferences,
1197 * and we weren't called in the first place).
1202 ret = (*callback)(pref, user_data);
1209 static const enum_val_t print_format_vals[] = {
1210 { "text", "Plain Text", PR_FMT_TEXT },
1211 { "postscript", "Postscript", PR_FMT_PS },
1215 static const enum_val_t print_dest_vals[] = {
1217 /* "PR_DEST_CMD" means "to printer" on Windows */
1218 { "command", "Printer", PR_DEST_CMD },
1220 { "command", "Command", PR_DEST_CMD },
1222 { "file", "File", PR_DEST_FILE },
1226 static void stats_callback(void)
1228 /* Test for a sane tap update interval */
1229 if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000) {
1230 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
1233 #ifdef HAVE_LIBPORTAUDIO
1234 /* Test for a sane max channels entry */
1235 if (prefs.rtp_player_max_visible < 1 || prefs.rtp_player_max_visible > 10)
1236 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
1241 static void gui_callback(void)
1243 /* Ensure there is at least one file count */
1244 if (prefs.gui_recent_files_count_max == 0)
1245 prefs.gui_recent_files_count_max = 10;
1247 /* Ensure there is at least one display filter entry */
1248 if (prefs.gui_recent_df_entries_max == 0)
1249 prefs.gui_recent_df_entries_max = 10;
1252 static void gui_layout_callback(void)
1254 if (prefs.gui_layout_type == layout_unused ||
1255 prefs.gui_layout_type >= layout_type_max) {
1256 /* XXX - report an error? It's not a syntax error - we'd need to
1257 add a way of reporting a *semantic* error. */
1258 prefs.gui_layout_type = layout_type_5;
1262 /******************************************************
1263 * All custom preference function callbacks
1264 ******************************************************/
1265 static void custom_pref_no_cb(pref_t* pref _U_) {}
1269 * Console log level custom preference functions
1271 static void console_log_level_reset_cb(pref_t* pref)
1273 *pref->varp.uint = pref->default_val.uint;
1276 static prefs_set_pref_e console_log_level_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1280 uval = (guint)strtoul(value, NULL, 10);
1282 if (*pref->varp.uint != uval) {
1284 *pref->varp.uint = uval;
1287 if (*pref->varp.uint & (G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG)) {
1289 * GLib >= 2.32 drops INFO and DEBUG messages by default. Tell
1290 * it not to do that.
1292 g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
1295 return PREFS_SET_OK;
1298 static const char * console_log_level_type_name_cb(void) {
1302 static char * console_log_level_type_description_cb(void) {
1303 return g_strdup_printf(
1304 "Console log level (for debugging)\n"
1305 "A bitmask of log levels:\n"
1314 static gboolean console_log_level_is_default_cb(pref_t* pref) {
1315 return *pref->varp.uint == pref->default_val.uint;
1318 static char * console_log_level_to_str_cb(pref_t* pref, gboolean default_val) {
1319 return g_strdup_printf("%u", default_val ? pref->default_val.uint : *pref->varp.uint);
1323 * Column preference functions
1325 #define PRS_COL_HIDDEN "column.hidden"
1326 #define PRS_COL_FMT "column.format"
1327 #define PRS_COL_NUM "column.number"
1328 static module_t *gui_column_module = NULL;
1330 static void column_hidden_free_cb(pref_t* pref)
1332 g_free((char *)*pref->varp.string);
1333 *pref->varp.string = NULL;
1334 g_free(pref->default_val.string);
1335 pref->default_val.string = NULL;
1338 static void column_hidden_reset_cb(pref_t* pref)
1340 g_free((void *)*pref->varp.string);
1341 *pref->varp.string = g_strdup(pref->default_val.string);
1344 static prefs_set_pref_e column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1348 pref_t *format_pref;
1350 if (*pref->varp.string) {
1351 if (strcmp(*pref->varp.string, value) != 0) {
1353 g_free((void *)*pref->varp.string);
1354 *pref->varp.string = g_strdup(value);
1357 *pref->varp.string = g_strdup(value);
1361 * Set the "visible" flag for the existing columns; we need to
1362 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
1363 * after setting it (which might be the case if, for example, we
1364 * set PRS_COL_HIDDEN on the command line).
1366 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1367 for (clp = *format_pref->varp.list; clp != NULL; clp = clp->next) {
1368 cfmt = (fmt_data *)clp->data;
1369 cfmt->visible = prefs_is_column_visible(*pref->varp.string, cfmt);
1372 return PREFS_SET_OK;
1375 static const char * column_hidden_type_name_cb(void) {
1376 return "Packet list hidden columns";
1379 static char * column_hidden_type_description_cb(void) {
1380 return g_strdup("List all columns to hide in the packet list.");
1383 static char * column_hidden_to_str_cb(pref_t* pref, gboolean default_val) {
1384 GString *cols_hidden = g_string_new ("");
1387 pref_t *format_pref;
1390 return g_strdup(pref->default_val.string);
1392 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1393 clp = (format_pref) ? *format_pref->varp.list : NULL;
1396 cfmt = (fmt_data *) clp->data;
1397 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
1398 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1399 col_format_to_string(cfmt->fmt),
1401 cfmt->custom_occurrence,
1402 cfmt->resolved ? 'R' : 'U');
1404 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1406 if (!cfmt->visible) {
1407 if (cols_hidden->len) {
1408 g_string_append (cols_hidden, ",");
1410 g_string_append (cols_hidden, prefs_fmt);
1415 return g_string_free (cols_hidden, FALSE);
1418 static gboolean column_hidden_is_default_cb(pref_t* pref) {
1419 char *cur_hidden_str = column_hidden_to_str_cb(pref, FALSE);
1420 gboolean is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
1422 g_free(cur_hidden_str);
1427 /* Number of columns "preference". This is only used internally and is not written to the
1430 static void column_num_reset_cb(pref_t* pref)
1432 *pref->varp.uint = pref->default_val.uint;
1435 static prefs_set_pref_e column_num_set_cb(pref_t* pref _U_, const gchar* value _U_, gboolean* changed _U_)
1437 /* Don't write this to the preferences file */
1438 return PREFS_SET_OK;
1441 static const char * column_num_type_name_cb(void) {
1445 static char * column_num_type_description_cb(void) {
1446 return g_strdup("");
1449 static gboolean column_num_is_default_cb(pref_t* pref _U_) {
1453 static char * column_num_to_str_cb(pref_t* pref _U_, gboolean default_val _U_) {
1454 return g_strdup("");
1458 * Column format custom preference functions
1460 static void column_format_init_cb(pref_t* pref, GList** value)
1462 fmt_data *src_cfmt, *dest_cfmt;
1465 pref->varp.list = value;
1467 pref->default_val.list = NULL;
1468 for (entry = *pref->varp.list; entry != NULL; entry = g_list_next(entry)) {
1469 src_cfmt = (fmt_data *)entry->data;
1470 dest_cfmt = g_new(fmt_data,1);
1471 dest_cfmt->title = g_strdup(src_cfmt->title);
1472 dest_cfmt->fmt = src_cfmt->fmt;
1473 if (src_cfmt->custom_field) {
1474 dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
1475 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1477 dest_cfmt->custom_field = NULL;
1478 dest_cfmt->custom_occurrence = 0;
1480 dest_cfmt->visible = src_cfmt->visible;
1481 dest_cfmt->resolved = src_cfmt->resolved;
1482 pref->default_val.list = g_list_append(pref->default_val.list, dest_cfmt);
1486 static void column_format_free_cb(pref_t* pref)
1488 free_col_info(*pref->varp.list);
1489 free_col_info(pref->default_val.list);
1492 static void column_format_reset_cb(pref_t* pref)
1494 fmt_data *src_cfmt, *dest_cfmt;
1496 pref_t *col_num_pref;
1498 free_col_info(*pref->varp.list);
1499 *pref->varp.list = NULL;
1501 for (entry = pref->default_val.list; entry != NULL; entry = g_list_next(entry)) {
1502 src_cfmt = (fmt_data *)entry->data;
1503 dest_cfmt = g_new(fmt_data,1);
1504 dest_cfmt->title = g_strdup(src_cfmt->title);
1505 dest_cfmt->fmt = src_cfmt->fmt;
1506 if (src_cfmt->custom_field) {
1507 dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
1508 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1510 dest_cfmt->custom_field = NULL;
1511 dest_cfmt->custom_occurrence = 0;
1513 dest_cfmt->visible = src_cfmt->visible;
1514 dest_cfmt->resolved = src_cfmt->resolved;
1515 *pref->varp.list = g_list_append(*pref->varp.list, dest_cfmt);
1518 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1519 column_num_reset_cb(col_num_pref);
1522 static prefs_set_pref_e column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1524 GList *col_l, *col_l_elt;
1527 pref_t *hidden_pref, *col_num_pref;
1529 col_l = prefs_get_string_list(value);
1531 return PREFS_SET_SYNTAX_ERR;
1532 if ((g_list_length(col_l) % 2) != 0) {
1533 /* A title didn't have a matching format. */
1534 prefs_clear_string_list(col_l);
1535 return PREFS_SET_SYNTAX_ERR;
1537 /* Check to make sure all column formats are valid. */
1538 col_l_elt = g_list_first(col_l);
1540 fmt_data cfmt_check;
1542 /* Go past the title. */
1543 col_l_elt = col_l_elt->next;
1545 /* Parse the format to see if it's valid. */
1546 if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
1547 /* It's not a valid column format. */
1548 prefs_clear_string_list(col_l);
1549 return PREFS_SET_SYNTAX_ERR;
1551 if (cfmt_check.fmt != COL_CUSTOM) {
1552 /* Some predefined columns have been migrated to use custom columns.
1553 * We'll convert these silently here */
1554 try_convert_to_custom_column(&col_l_elt->data);
1556 /* We don't need the custom column field on this pass. */
1557 g_free(cfmt_check.custom_field);
1560 /* Go past the format. */
1561 col_l_elt = col_l_elt->next;
1564 /* They're all valid; process them. */
1565 free_col_info(*pref->varp.list);
1566 *pref->varp.list = NULL;
1567 hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN);
1568 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1569 llen = g_list_length(col_l);
1570 *col_num_pref->varp.uint = llen / 2;
1571 col_l_elt = g_list_first(col_l);
1573 cfmt = g_new(fmt_data,1);
1574 cfmt->title = g_strdup((gchar *)col_l_elt->data);
1575 col_l_elt = col_l_elt->next;
1576 parse_column_format(cfmt, (char *)col_l_elt->data);
1577 cfmt->visible = prefs_is_column_visible((gchar*)(*hidden_pref->varp.string), cfmt);
1578 col_l_elt = col_l_elt->next;
1579 *pref->varp.list = g_list_append(*pref->varp.list, cfmt);
1582 prefs_clear_string_list(col_l);
1583 column_hidden_free_cb(hidden_pref);
1584 return PREFS_SET_OK;
1588 static const char * column_format_type_name_cb(void) {
1589 return "Packet list column format";
1592 static char * column_format_type_description_cb(void) {
1593 return g_strdup("Each pair of strings consists of a column title and its format");
1596 static gboolean column_format_is_default_cb(pref_t* pref) {
1597 GList *clp = *pref->varp.list,
1598 *pref_col = g_list_first(clp),
1599 *def_col = g_list_first(pref->default_val.list);
1600 fmt_data *cfmt, *def_cfmt;
1601 gboolean is_default = TRUE;
1602 pref_t *col_num_pref;
1604 /* See if the column data has changed from the default */
1605 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1606 if (col_num_pref && *col_num_pref->varp.uint != col_num_pref->default_val.uint) {
1609 while (pref_col && def_col) {
1610 cfmt = (fmt_data *) pref_col->data;
1611 def_cfmt = (fmt_data *) def_col->data;
1612 if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
1613 (cfmt->fmt != def_cfmt->fmt) ||
1614 (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) &&
1615 ((g_strcmp0(cfmt->custom_field, def_cfmt->custom_field) != 0) ||
1616 (cfmt->resolved != def_cfmt->resolved)))) {
1621 pref_col = pref_col->next;
1622 def_col = def_col->next;
1629 static char * column_format_to_str_cb(pref_t* pref, gboolean default_val) {
1630 GList *pref_l = default_val ? pref->default_val.list : *pref->varp.list;
1631 GList *clp = g_list_first(pref_l);
1635 char *column_format_str;
1639 cfmt = (fmt_data *) clp->data;
1640 col_l = g_list_append(col_l, g_strdup(cfmt->title));
1641 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
1642 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1643 col_format_to_string(cfmt->fmt),
1645 cfmt->custom_occurrence,
1646 cfmt->resolved ? 'R' : 'U');
1648 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1650 col_l = g_list_append(col_l, prefs_fmt);
1654 column_format_str = join_string_list(col_l);
1656 /* This frees the list of strings, but not the strings to which it
1657 refers; they are free'ed in join_string_list(). */
1659 return column_format_str;
1663 /****** Capture column custom preference functions ******/
1665 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
1666 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
1667 to prefs->default_val.list.
1669 static void capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
1671 GList *ccv_list = *capture_cols_values,
1676 dlist = g_list_append(dlist, g_strdup((gchar *)ccv_list->data));
1677 ccv_list = ccv_list->next;
1680 pref->default_val.list = dlist;
1681 pref->varp.list = &prefs.capture_columns;
1682 pref->stashed_val.boolval = FALSE;
1685 /* Free the prefs->capture_columns list strings and remove the list entries.
1686 Note that since pref->varp.list points to &prefs.capture_columns, it is
1689 static void capture_column_free_cb(pref_t* pref)
1691 GList *clist = prefs.capture_columns;
1695 col_name = (gchar *)clist->data;
1697 clist = g_list_remove_link(clist, clist);
1700 prefs.capture_columns = NULL;
1702 if (pref->stashed_val.boolval == TRUE) {
1706 dlist = pref->default_val.list;
1707 while (dlist != NULL) {
1708 col = (gchar *)dlist->data;
1710 dlist = g_list_remove_link(dlist, dlist);
1717 /* Copy pref->default_val.list to *pref->varp.list.
1719 static void capture_column_reset_cb(pref_t* pref)
1721 GList *vlist, *dlist;
1724 /* Free the column name strings and remove the links from *pref->varp.list */
1725 vlist = *pref->varp.list;
1726 while (vlist != NULL) {
1727 vcol = (gchar *)vlist->data;
1729 vlist = g_list_remove_link(vlist, vlist);
1734 for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
1735 vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
1737 *pref->varp.list = vlist;
1740 static prefs_set_pref_e capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1742 GList *col_l = prefs_get_string_list(value);
1748 return PREFS_SET_SYNTAX_ERR;
1750 capture_column_free_cb(pref);
1752 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
1753 to the full list of valid capture column names. */
1754 col_l_elt = g_list_first(col_l);
1755 if (!(*(gchar *)col_l_elt->data)) {
1756 for (i = 0; i < num_capture_cols; i++) {
1757 col_name = g_strdup(capture_cols[i]);
1758 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1762 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
1765 gboolean found_match = FALSE;
1766 col_name = (gchar *)col_l_elt->data;
1768 for (i = 0; i < num_capture_cols; i++) {
1769 if (strcmp(col_name, capture_cols[i])==0) {
1775 /* One or more cols are invalid so use the entire list of valid cols. */
1776 for (i = 0; i < num_capture_cols; i++) {
1777 col_name = g_strdup(capture_cols[i]);
1778 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1780 pref->varp.list = &prefs.capture_columns;
1781 return PREFS_SET_SYNTAX_ERR;
1783 col_l_elt = col_l_elt->next;
1786 col_l_elt = g_list_first(col_l);
1788 col_name = (gchar *)col_l_elt->data;
1789 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1790 col_l_elt = col_l_elt->next;
1792 pref->varp.list = &prefs.capture_columns;
1793 return PREFS_SET_OK;
1797 static const char * capture_column_type_name_cb(void) {
1798 return "Column list";
1801 static char * capture_column_type_description_cb(void) {
1802 return g_strdup_printf(
1803 "List of columns to be displayed in the capture options dialog.\n"
1804 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n");
1807 static gboolean capture_column_is_default_cb(pref_t* pref) {
1808 GList *pref_col = g_list_first(prefs.capture_columns),
1809 *def_col = g_list_first(pref->default_val.list);
1810 gboolean is_default = TRUE;
1812 /* See if the column data has changed from the default */
1813 while (pref_col && def_col) {
1814 if (strcmp((gchar *)pref_col->data, (gchar *)def_col->data) != 0) {
1818 pref_col = pref_col->next;
1819 def_col = def_col->next;
1822 /* Ensure the same column count */
1823 if (((pref_col == NULL) && (def_col != NULL)) ||
1824 ((pref_col != NULL) && (def_col == NULL)))
1830 static char * capture_column_to_str_cb(pref_t* pref, gboolean default_val) {
1832 GList *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
1833 GList *clp = g_list_first(pref_l);
1834 GList *col_l = NULL;
1835 gchar *col, *capture_column_str;
1839 col = (gchar *) clp->data;
1840 col_l = g_list_append(col_l, g_strdup(col));
1844 capture_column_str = join_string_list(col_l);
1845 /* This frees the list of strings, but not the strings to which it
1846 refers; they are free'ed in write_string_list(). */
1848 return capture_column_str;
1852 static void colorized_frame_free_cb(pref_t* pref)
1854 g_free((char *)*pref->varp.string);
1855 *pref->varp.string = NULL;
1856 g_free(pref->default_val.string);
1857 pref->default_val.string = NULL;
1861 static void colorized_frame_reset_cb(pref_t* pref)
1863 g_free((void *)*pref->varp.string);
1864 *pref->varp.string = g_strdup(pref->default_val.string);
1867 static prefs_set_pref_e colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1869 if (strcmp(*pref->varp.string, value) != 0) {
1871 g_free((void *)*pref->varp.string);
1872 *pref->varp.string = g_strdup(value);
1875 return PREFS_SET_OK;
1878 static const char * colorized_frame_type_name_cb(void) {
1879 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
1880 * file until the colors can be changed in the GUI. Currently this is not really
1881 * possible since the STOCK-icons for these colors are hardcoded.
1883 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
1884 * add these 10 colors to the list of colors that can be changed through
1891 static char * colorized_frame_type_description_cb(void) {
1892 return g_strdup("");
1895 static gboolean colorized_frame_is_default_cb(pref_t* pref _U_) {
1899 static char * colorized_frame_to_str_cb(pref_t* pref _U_, gboolean default_val _U_) {
1900 return g_strdup("");
1904 * Register all non-dissector modules' preferences.
1906 static module_t *gui_module = NULL;
1907 static module_t *gui_color_module = NULL;
1908 static module_t *nameres_module = NULL;
1911 prefs_register_modules(void)
1913 module_t *printing, *capture_module, *console_module,
1914 *gui_layout_module, *gui_font_module;
1915 struct pref_custom_cbs custom_cbs;
1917 if (protocols_module != NULL) {
1918 /* Already setup preferences */
1922 /* Ensure the "global" preferences have been initialized so the
1923 * preference API has the proper default values to work from
1928 * These are "simple" GUI preferences that can be read/written using the
1929 * preference module API. These preferences still use their own
1930 * configuration screens for access, but this cuts down on the
1931 * preference "string compare list" in set_pref()
1933 gui_module = prefs_register_module(NULL, "gui", "User Interface",
1934 "User Interface", &gui_callback, FALSE);
1936 /* gui.console_open is placed first in the list so that any problems encountered
1937 * in the following prefs can be displayed in the console window.
1939 prefs_register_enum_preference(gui_module, "console_open",
1940 "Open a console window",
1941 "Open a console window (WIN32 only)",
1942 (gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
1944 prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
1945 prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
1946 prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
1948 prefs_register_bool_preference(gui_module, "tree_view_altern_colors",
1949 "Alternating colors in TreeViews",
1950 "Alternating colors in TreeViews?",
1951 &prefs.gui_altern_colors);
1953 prefs_register_bool_preference(gui_module, "expert_composite_eyecandy",
1954 "Display Icons on Expert Composite Dialog Tabs",
1955 "Display Icons on Expert Composite Dialog Tabs?",
1956 &prefs.gui_expert_composite_eyecandy);
1958 prefs_register_bool_preference(gui_module, "filter_toolbar_show_in_statusbar",
1959 "Place filter toolbar inside the statusbar",
1960 "Place filter toolbar inside the statusbar?",
1961 &prefs.filter_toolbar_show_in_statusbar);
1963 prefs_register_enum_preference(gui_module, "protocol_tree_line_style",
1964 "Protocol-tree line style",
1965 "Protocol-tree line style",
1966 &prefs.gui_ptree_line_style, gui_ptree_line_style, FALSE);
1968 prefs_register_enum_preference(gui_module, "protocol_tree_expander_style",
1969 "Protocol-tree expander style",
1970 "Protocol-tree expander style",
1971 &prefs.gui_ptree_expander_style, gui_ptree_expander_style, FALSE);
1973 prefs_register_enum_preference(gui_module, "hex_dump_highlight_style",
1974 "Hex dump highlight style",
1975 "Hex dump highlight style",
1976 &prefs.gui_hex_dump_highlight_style, gui_hex_dump_highlight_style, FALSE);
1978 gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
1980 custom_cbs.free_cb = column_hidden_free_cb;
1981 custom_cbs.reset_cb = column_hidden_reset_cb;
1982 custom_cbs.set_cb = column_hidden_set_cb;
1983 custom_cbs.type_name_cb = column_hidden_type_name_cb;
1984 custom_cbs.type_description_cb = column_hidden_type_description_cb;
1985 custom_cbs.is_default_cb = column_hidden_is_default_cb;
1986 custom_cbs.to_str_cb = column_hidden_to_str_cb;
1987 prefs_register_string_custom_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
1988 "List all columns to hide in the packet list", &custom_cbs, (const char **)&cols_hidden_list);
1990 custom_cbs.free_cb = column_format_free_cb;
1991 custom_cbs.reset_cb = column_format_reset_cb;
1992 custom_cbs.set_cb = column_format_set_cb;
1993 custom_cbs.type_name_cb = column_format_type_name_cb;
1994 custom_cbs.type_description_cb = column_format_type_description_cb;
1995 custom_cbs.is_default_cb = column_format_is_default_cb;
1996 custom_cbs.to_str_cb = column_format_to_str_cb;
1998 prefs_register_list_custom_preference(gui_column_module, PRS_COL_FMT, "Packet list column format",
1999 "Each pair of strings consists of a column title and its format", &custom_cbs,
2000 column_format_init_cb, &prefs.col_list);
2002 /* Number of columns. This is only used internally and is not written to the
2005 custom_cbs.free_cb = custom_pref_no_cb;
2006 custom_cbs.reset_cb = column_num_reset_cb;
2007 custom_cbs.set_cb = column_num_set_cb;
2008 custom_cbs.type_name_cb = column_num_type_name_cb;
2009 custom_cbs.type_description_cb = column_num_type_description_cb;
2010 custom_cbs.is_default_cb = column_num_is_default_cb;
2011 custom_cbs.to_str_cb = column_num_to_str_cb;
2012 prefs_register_uint_custom_preference(gui_column_module, PRS_COL_NUM, "Number of columns",
2013 "Number of columns in col_list", &custom_cbs, &prefs.num_cols);
2015 /* User Interface : Font */
2016 gui_font_module = prefs_register_subtree(gui_module, "Font", "Font", NULL);
2018 prefs_register_obsolete_preference(gui_font_module, "font_name");
2020 prefs_register_string_preference(gui_font_module, "gtk2.font_name", "Font name",
2021 "Font name for packet list, protocol tree, and hex dump panes. (GTK+)", (const char**)(&prefs.gui_gtk2_font_name));
2023 prefs_register_string_preference(gui_font_module, "qt.font_name", "Font name",
2024 "Font name for packet list, protocol tree, and hex dump panes. (Qt)", (const char**)(&prefs.gui_qt_font_name));
2026 /* User Interface : Colors */
2027 gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
2029 prefs_register_color_preference(gui_color_module, "marked_frame.fg", "Color preferences for a marked frame",
2030 "Color preferences for a marked frame", &prefs.gui_marked_fg);
2032 prefs_register_color_preference(gui_color_module, "marked_frame.bg", "Color preferences for a marked frame",
2033 "Color preferences for a marked frame", &prefs.gui_marked_bg);
2035 prefs_register_color_preference(gui_color_module, "ignored_frame.fg", "Color preferences for a ignored frame",
2036 "Color preferences for a ignored frame", &prefs.gui_ignored_fg);
2038 prefs_register_color_preference(gui_color_module, "ignored_frame.bg", "Color preferences for a ignored frame",
2039 "Color preferences for a ignored frame", &prefs.gui_ignored_bg);
2041 prefs_register_color_preference(gui_color_module, "stream.client.fg", "TCP stream window color preference",
2042 "TCP stream window color preference", &prefs.st_client_fg);
2044 prefs_register_color_preference(gui_color_module, "stream.client.bg", "TCP stream window color preference",
2045 "TCP stream window color preference", &prefs.st_client_bg);
2047 prefs_register_color_preference(gui_color_module, "stream.server.fg", "TCP stream window color preference",
2048 "TCP stream window color preference", &prefs.st_server_fg);
2050 prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
2051 "TCP stream window color preference", &prefs.st_server_bg);
2053 custom_cbs.free_cb = colorized_frame_free_cb;
2054 custom_cbs.reset_cb = colorized_frame_reset_cb;
2055 custom_cbs.set_cb = colorized_frame_set_cb;
2056 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2057 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2058 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2059 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2060 prefs_register_string_custom_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
2061 "Filter Colorized Foreground", &custom_cbs, (const char **)&prefs.gui_colorized_fg);
2063 custom_cbs.free_cb = colorized_frame_free_cb;
2064 custom_cbs.reset_cb = colorized_frame_reset_cb;
2065 custom_cbs.set_cb = colorized_frame_set_cb;
2066 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2067 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2068 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2069 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2070 prefs_register_string_custom_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
2071 "Filter Colorized Background", &custom_cbs, (const char **)&prefs.gui_colorized_bg);
2073 prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
2074 "Valid color filter background", &prefs.gui_text_valid);
2076 prefs_register_color_preference(gui_color_module, "color_filter_bg.invalid", "Invalid color filter background",
2077 "Invalid color filter background", &prefs.gui_text_invalid);
2079 prefs_register_color_preference(gui_color_module, "color_filter_bg.deprecated", "Deprecated color filter background",
2080 "Deprecated color filter background", &prefs.gui_text_deprecated);
2082 prefs_register_enum_preference(gui_module, "fileopen.style",
2083 "Where to start the File Open dialog box",
2084 "Where to start the File Open dialog box",
2085 &prefs.gui_fileopen_style, gui_fileopen_style, FALSE);
2087 prefs_register_uint_preference(gui_module, "recent_files_count.max",
2088 "The max. number of items in the open recent files list",
2089 "The max. number of items in the open recent files list",
2091 &prefs.gui_recent_files_count_max);
2093 prefs_register_uint_preference(gui_module, "recent_display_filter_entries.max",
2094 "The max. number of entries in the display filter list",
2095 "The max. number of entries in the display filter list",
2097 &prefs.gui_recent_df_entries_max);
2099 prefs_register_directory_preference(gui_module, "fileopen.dir", "Start Directory",
2100 "Directory to start in when opening File Open dialog.", (const char**)(&prefs.gui_fileopen_dir));
2102 prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
2104 prefs_register_uint_preference(gui_module, "fileopen.preview",
2105 "The preview timeout in the File Open dialog",
2106 "The preview timeout in the File Open dialog",
2108 &prefs.gui_fileopen_preview);
2110 prefs_register_bool_preference(gui_module, "ask_unsaved",
2111 "Ask to save unsaved capture files",
2112 "Ask to save unsaved capture files?",
2113 &prefs.gui_ask_unsaved);
2115 prefs_register_bool_preference(gui_module, "find_wrap",
2116 "Wrap to beginning/end of file during search",
2117 "Wrap to beginning/end of file during search?",
2118 &prefs.gui_find_wrap);
2120 prefs_register_bool_preference(gui_module, "use_pref_save",
2121 "Settings dialogs use a save button",
2122 "Settings dialogs use a save button?",
2123 &prefs.gui_use_pref_save);
2125 prefs_register_bool_preference(gui_module, "geometry.save.position",
2126 "Save window position at exit",
2127 "Save window position at exit?",
2128 &prefs.gui_geometry_save_position);
2130 prefs_register_bool_preference(gui_module, "geometry.save.size",
2131 "Save window size at exit",
2132 "Save window size at exit?",
2133 &prefs.gui_geometry_save_size);
2135 prefs_register_bool_preference(gui_module, "geometry.save.maximized",
2136 "Save window maximized state at exit",
2137 "Save window maximized state at exit?",
2138 &prefs.gui_geometry_save_maximized);
2140 prefs_register_bool_preference(gui_module, "macosx_style",
2141 "Use Mac OS X style",
2142 "Use Mac OS X style (Mac OS X with native GTK only)?",
2143 &prefs.gui_macosx_style);
2145 prefs_register_obsolete_preference(gui_module, "geometry.main.x");
2146 prefs_register_obsolete_preference(gui_module, "geometry.main.y");
2147 prefs_register_obsolete_preference(gui_module, "geometry.main.width");
2148 prefs_register_obsolete_preference(gui_module, "geometry.main.height");
2149 prefs_register_obsolete_preference(gui_module, "toolbar_main_show");
2151 prefs_register_enum_preference(gui_module, "toolbar_main_style",
2152 "Main Toolbar style",
2153 "Main Toolbar style",
2154 &prefs.gui_toolbar_main_style, gui_toolbar_style, FALSE);
2156 prefs_register_enum_preference(gui_module, "toolbar_filter_style",
2157 "Filter Toolbar style",
2158 "Filter Toolbar style",
2159 &prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
2161 prefs_register_string_preference(gui_module, "webbrowser", "The path to the webbrowser",
2162 "The path to the webbrowser (Ex: mozilla)", (const char**)(&prefs.gui_webbrowser));
2164 prefs_register_bool_preference(gui_module, "update.enabled",
2165 "Check for updates",
2166 "Check for updates (Windows only)",
2167 &prefs.gui_update_enabled);
2169 prefs_register_enum_preference(gui_module, "update.channel",
2171 "The type of update to fetch. You should probably leave this set to UPDATE_CHANNEL_STABLE.",
2172 (gint*)(void*)(&prefs.gui_update_channel), gui_update_channel, FALSE);
2174 prefs_register_uint_preference(gui_module, "update.interval",
2175 "How often to check for software updates",
2176 "How often to check for software updates in seconds",
2178 &prefs.gui_update_interval);
2180 prefs_register_string_preference(gui_module, "window_title", "Custom window title",
2181 "Custom window title. (Appended to existing titles.)", (const char**)(&prefs.gui_window_title));
2183 prefs_register_string_preference(gui_module, "start_title", "Custom start page title",
2184 "Custom start page title", (const char**)(&prefs.gui_start_title));
2186 prefs_register_enum_preference(gui_module, "version_placement",
2187 "Show version in the start page and/or main screen's title bar",
2188 "Show version in the start page and/or main screen's title bar",
2189 (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
2191 prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
2192 "Automatically scroll the recently expanded item",
2193 "Automatically scroll the recently expanded item",
2194 &prefs.gui_auto_scroll_on_expand);
2196 prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
2197 "The percentage down the view the recently expanded item should be scrolled",
2198 "The percentage down the view the recently expanded item should be scrolled",
2200 &prefs.gui_auto_scroll_percentage);
2202 /* User Interface : Layout */
2203 gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
2205 prefs_register_uint_preference(gui_layout_module, "layout_type",
2207 "Layout type (1-6)",
2209 (guint*)(void*)(&prefs.gui_layout_type));
2211 prefs_register_enum_preference(gui_layout_module, "layout_content_1",
2212 "Layout content of the pane 1",
2213 "Layout content of the pane 1",
2214 (gint*)(void*)(&prefs.gui_layout_content_1), gui_layout_content, FALSE);
2216 prefs_register_enum_preference(gui_layout_module, "layout_content_2",
2217 "Layout content of the pane 2",
2218 "Layout content of the pane 2",
2219 (gint*)(void*)(&prefs.gui_layout_content_2), gui_layout_content, FALSE);
2221 prefs_register_enum_preference(gui_layout_module, "layout_content_3",
2222 "Layout content of the pane 3",
2223 "Layout content of the pane 3",
2224 (gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
2227 * These are preferences that can be read/written using the
2228 * preference module API. These preferences still use their own
2229 * configuration screens for access, but this cuts down on the
2230 * preference "string compare list" in set_pref()
2232 console_module = prefs_register_module(NULL, "console", "Console",
2233 "CONSOLE", NULL, FALSE);
2235 custom_cbs.free_cb = custom_pref_no_cb;
2236 custom_cbs.reset_cb = console_log_level_reset_cb;
2237 custom_cbs.set_cb = console_log_level_set_cb;
2238 custom_cbs.type_name_cb = console_log_level_type_name_cb;
2239 custom_cbs.type_description_cb = console_log_level_type_description_cb;
2240 custom_cbs.is_default_cb = console_log_level_is_default_cb;
2241 custom_cbs.to_str_cb = console_log_level_to_str_cb;
2242 prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
2243 "A bitmask of glib log levels", &custom_cbs, &prefs.console_log_level);
2246 * These are preferences that can be read/written using the
2247 * preference module API. These preferences still use their own
2248 * configuration screens for access, but this cuts down on the
2249 * preference "string compare list" in set_pref()
2251 capture_module = prefs_register_module(NULL, "capture", "Capture",
2252 "CAPTURE", NULL, FALSE);
2254 prefs_register_string_preference(capture_module, "device", "Default capture device",
2255 "Default capture device", (const char**)(&prefs.capture_device));
2257 prefs_register_string_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
2258 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
2259 (const char**)(&prefs.capture_devices_linktypes));
2261 prefs_register_string_preference(capture_module, "devices_descr", "Interface descriptions",
2262 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
2263 (const char**)(&prefs.capture_devices_descr));
2265 prefs_register_string_preference(capture_module, "devices_hide", "Hide interface",
2266 "Hide interface? (Ex: eth0,eth3,...)", (const char**)(&prefs.capture_devices_hide));
2268 prefs_register_string_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
2269 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
2270 (const char**)(&prefs.capture_devices_monitor_mode));
2272 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
2273 prefs_register_string_preference(capture_module, "devices_buffersize", "Interface buffer size",
2274 "Interface buffer size (Ex: en0(1),en1(143),...)",
2275 (const char**)(&prefs.capture_devices_buffersize));
2278 prefs_register_string_preference(capture_module, "devices_snaplen", "Interface snap length",
2279 "Interface snap length (Ex: en0(65535),en1(1430),...)",
2280 (const char**)(&prefs.capture_devices_snaplen));
2282 prefs_register_string_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
2283 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
2284 (const char**)(&prefs.capture_devices_pmode));
2286 prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
2287 "Capture in promiscuous mode?", &prefs.capture_prom_mode);
2289 prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
2290 "Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
2292 prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
2293 "Update packet list in real time during capture?", &prefs.capture_real_time);
2295 prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
2296 "Scroll packet list during capture?", &prefs.capture_auto_scroll);
2298 prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
2299 "Show capture info dialog while capturing?", &prefs.capture_show_info);
2301 prefs_register_obsolete_preference(capture_module, "syntax_check_filter");
2303 custom_cbs.free_cb = capture_column_free_cb;
2304 custom_cbs.reset_cb = capture_column_reset_cb;
2305 custom_cbs.set_cb = capture_column_set_cb;
2306 custom_cbs.type_name_cb = capture_column_type_name_cb;
2307 custom_cbs.type_description_cb = capture_column_type_description_cb;
2308 custom_cbs.is_default_cb = capture_column_is_default_cb;
2309 custom_cbs.to_str_cb = capture_column_to_str_cb;
2310 prefs_register_list_custom_preference(capture_module, "columns", "Capture options dialog column list",
2311 "List of columns to be displayed", &custom_cbs, capture_column_init_cb, &prefs.capture_columns);
2313 /* Name Resolution */
2314 nameres_module = prefs_register_module(NULL, "nameres", "Name Resolution",
2315 "Name Resolution", NULL, TRUE);
2316 addr_resolve_pref_init(nameres_module);
2317 oid_pref_init(nameres_module);
2319 geoip_db_pref_init(nameres_module);
2323 printing = prefs_register_module(NULL, "print", "Printing",
2324 "Printing", NULL, TRUE);
2326 prefs_register_enum_preference(printing, "format",
2327 "Format", "Can be one of \"text\" or \"postscript\"",
2328 &prefs.pr_format, print_format_vals, TRUE);
2330 prefs_register_enum_preference(printing, "destination",
2331 "Print to", "Can be one of \"command\" or \"file\"",
2332 &prefs.pr_dest, print_dest_vals, TRUE);
2335 prefs_register_string_preference(printing, "command", "Command",
2336 "Output gets piped to this command when the destination is set to \"command\"", (const char**)(&prefs.pr_cmd));
2339 prefs_register_filename_preference(printing, "file", "File",
2340 "This is the file that gets written to when the destination is set to \"file\"", (const char**)(&prefs.pr_file));
2344 stats_module = prefs_register_module(NULL, "statistics", "Statistics",
2345 "Statistics", &stats_callback, TRUE);
2347 prefs_register_uint_preference(stats_module, "update_interval",
2348 "Tap update interval in ms",
2349 "Determines time between tap updates",
2351 &prefs.tap_update_interval);
2353 #ifdef HAVE_LIBPORTAUDIO
2354 prefs_register_uint_preference(stats_module, "rtp_player_max_visible",
2355 "Max visible channels in RTP Player",
2356 "Determines maximum height of RTP Player window",
2358 &prefs.rtp_player_max_visible);
2363 protocols_module = prefs_register_module(NULL, "protocols", "Protocols",
2364 "Protocols", NULL, TRUE);
2366 prefs_register_bool_preference(protocols_module, "display_hidden_proto_items",
2367 "Display hidden protocol items",
2368 "Display all hidden protocol items in the packet list.",
2369 &prefs.display_hidden_proto_items);
2371 /* Obsolete preferences
2372 * These "modules" were reorganized/renamed to correspond to their GUI
2373 * configuration screen within the preferences dialog
2376 /* taps is now part of the stats module */
2377 prefs_register_module(NULL, "taps", "TAPS", "TAPS", NULL, FALSE);
2378 /* packet_list is now part of the protocol (parent) module */
2379 prefs_register_module(NULL, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL, FALSE);
2380 /* stream is now part of the gui module */
2381 prefs_register_module(NULL, "stream", "STREAM", "STREAM", NULL, FALSE);
2385 /* Parse through a list of comma-separated, possibly quoted strings.
2386 Return a list of the string data. */
2388 prefs_get_string_list(const gchar *str)
2390 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
2392 gint state = PRE_STRING, i = 0, j = 0;
2393 gboolean backslash = FALSE;
2395 gchar *slstr = NULL;
2398 /* Allocate a buffer for the first string. */
2399 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2404 if (cur_c == '\0') {
2405 /* It's the end of the input, so it's the end of the string we
2406 were working on, and there's no more input. */
2407 if (state == IN_QUOT || backslash) {
2408 /* We were in the middle of a quoted string or backslash escape,
2409 and ran out of characters; that's an error. */
2411 prefs_clear_string_list(sl);
2415 sl = g_list_append(sl, slstr);
2418 if (cur_c == '"' && ! backslash) {
2421 /* We hadn't yet started processing a string; this starts the
2422 string, and we're now quoting. */
2426 /* We're in the middle of a quoted string, and we saw a quotation
2427 mark; we're no longer quoting. */
2428 state = NOT_IN_QUOT;
2431 /* We're working on a string, but haven't seen a quote; we're
2438 } else if (cur_c == '\\' && ! backslash) {
2439 /* We saw a backslash, and the previous character wasn't a
2440 backslash; escape the next character.
2442 This also means we've started a new string. */
2444 if (state == PRE_STRING)
2445 state = NOT_IN_QUOT;
2446 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
2447 /* We saw a comma, and we're not in the middle of a quoted string
2448 and it wasn't preceded by a backslash; it's the end of
2449 the string we were working on... */
2451 sl = g_list_append(sl, slstr);
2453 /* ...and the beginning of a new string. */
2455 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2457 } else if (!isspace(cur_c) || state != PRE_STRING) {
2458 /* Either this isn't a white-space character, or we've started a
2459 string (i.e., already seen a non-white-space character for that
2460 string and put it into the string).
2462 The character is to be put into the string; do so if there's
2464 if (j < COL_MAX_LEN) {
2469 /* If it was backslash-escaped, we're done with the backslash escape. */
2478 join_string_list(GList *sl)
2480 GString *joined_str = g_string_new("");
2484 guint item_count = 0;
2486 cur = first = g_list_first(sl);
2489 str = (gchar *)cur->data;
2492 g_string_append_c(joined_str, ',');
2495 if (item_count % 2) {
2496 /* Wrap the line. */
2497 g_string_append(joined_str, "\n\t");
2499 g_string_append_c(joined_str, ' ');
2502 quoted_str = g_strescape(str, "");
2503 g_string_append_printf(joined_str, "\"%s\"", quoted_str);
2508 return g_string_free(joined_str, FALSE);
2512 prefs_clear_string_list(GList *sl)
2518 l = g_list_remove_link(l, l);
2523 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
2525 * The array must be terminated by an entry with a null "name" string.
2527 * If the string matches a "name" string in an entry, the value from that
2528 * entry is returned.
2530 * Otherwise, if a string matches a "desctiption" string in an entry, the
2531 * value from that entry is returned; we do that for backwards compatibility,
2532 * as we used to have only a "name" string that was used both for command-line
2533 * and configuration-file values and in the GUI (which meant either that
2534 * the GUI had what might be somewhat cryptic values to select from or that
2535 * the "-o" flag took long strings, often with spaces in them).
2537 * Otherwise, the default value that was passed as the third argument is
2541 find_val_for_string(const char *needle, const enum_val_t *haystack,
2546 for (i = 0; haystack[i].name != NULL; i++) {
2547 if (g_ascii_strcasecmp(needle, haystack[i].name) == 0) {
2548 return haystack[i].value;
2551 for (i = 0; haystack[i].name != NULL; i++) {
2552 if (g_ascii_strcasecmp(needle, haystack[i].description) == 0) {
2553 return haystack[i].value;
2556 return default_value;
2559 /* Preferences file format:
2560 * - Configuration directives start at the beginning of the line, and
2561 * are terminated with a colon.
2562 * - Directives can be continued on the next line by preceding them with
2567 # This is a comment line
2569 print.file: /a/very/long/path/
2574 #define DEF_NUM_COLS 7
2577 * Parse a column format, filling in the relevant fields of a fmt_data.
2580 parse_column_format(fmt_data *cfmt, const char *fmt)
2582 const gchar *cust_format = col_format_to_string(COL_CUSTOM);
2583 size_t cust_format_len = strlen(cust_format);
2584 gchar **cust_format_info;
2587 gchar *col_custom_field;
2588 long col_custom_occurrence;
2589 gboolean col_resolved;
2592 * Is this a custom column?
2594 if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
2595 strncmp(fmt, cust_format, cust_format_len) == 0) {
2597 col_fmt = COL_CUSTOM;
2598 cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
2599 col_custom_field = g_strdup(cust_format_info[0]);
2600 if (col_custom_field && cust_format_info[1]) {
2601 col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
2602 if (p == cust_format_info[1] || *p != '\0') {
2603 /* Not a valid number. */
2604 g_free(col_custom_field);
2605 g_strfreev(cust_format_info);
2609 col_custom_occurrence = 0;
2611 if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
2612 col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
2614 col_resolved = TRUE;
2616 g_strfreev(cust_format_info);
2618 col_fmt = get_column_format_from_str(fmt);
2621 col_custom_field = NULL;
2622 col_custom_occurrence = 0;
2623 col_resolved = TRUE;
2626 cfmt->fmt = col_fmt;
2627 cfmt->custom_field = col_custom_field;
2628 cfmt->custom_occurrence = (int)col_custom_occurrence;
2629 cfmt->resolved = col_resolved;
2633 /* Initialize non-dissector preferences to wired-in default values.
2634 * (The dissector preferences are assumed to be set to those values
2635 * by the dissectors.)
2636 * They may be overridden by the global preferences file or the
2637 * user's preferences file.
2642 if (prefs_initialized)
2649 filter_expression_init(TRUE);
2651 prefs_initialized = TRUE;
2654 /* Initialize non-dissector preferences used by the "register preference" API
2655 * to default values so the default values can be used when registered
2658 pre_init_prefs(void)
2663 static const gchar *col_fmt[DEF_NUM_COLS*2] = {
2664 "No.", "%m", "Time", "%t",
2665 "Source", "%s", "Destination", "%d",
2666 "Protocol", "%p", "Length", "%L",
2669 if (prefs_pre_initialized)
2672 prefs.pr_format = PR_FMT_TEXT;
2673 prefs.pr_dest = PR_DEST_CMD;
2674 prefs.pr_file = "wireshark.out";
2675 prefs.pr_cmd = "lpr";
2677 prefs.gui_altern_colors = FALSE;
2678 prefs.gui_expert_composite_eyecandy = FALSE;
2679 prefs.gui_ptree_line_style = 0;
2680 prefs.gui_ptree_expander_style = 1;
2681 prefs.gui_hex_dump_highlight_style = 1;
2682 prefs.filter_toolbar_show_in_statusbar = FALSE;
2683 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
2684 prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
2685 /* This can be g_freed, so it must be g_mallocated. */
2687 prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
2689 prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
2691 /* We try to find the best font in the Qt code */
2692 prefs.gui_qt_font_name = g_strdup("");
2693 prefs.gui_marked_fg.pixel = 65535;
2694 prefs.gui_marked_fg.red = 65535;
2695 prefs.gui_marked_fg.green = 65535;
2696 prefs.gui_marked_fg.blue = 65535;
2697 prefs.gui_marked_bg.pixel = 0;
2698 prefs.gui_marked_bg.red = 0;
2699 prefs.gui_marked_bg.green = 8224;
2700 prefs.gui_marked_bg.blue = 10794;
2701 prefs.gui_ignored_fg.pixel = 32767;
2702 prefs.gui_ignored_fg.red = 32767;
2703 prefs.gui_ignored_fg.green = 32767;
2704 prefs.gui_ignored_fg.blue = 32767;
2705 prefs.gui_ignored_bg.pixel = 65535;
2706 prefs.gui_ignored_bg.red = 65535;
2707 prefs.gui_ignored_bg.green = 65535;
2708 prefs.gui_ignored_bg.blue = 65535;
2709 prefs.gui_colorized_fg = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
2710 prefs.gui_colorized_bg = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
2711 prefs.st_client_fg.pixel = 0;
2712 prefs.st_client_fg.red = 32767;
2713 prefs.st_client_fg.green = 0;
2714 prefs.st_client_fg.blue = 0;
2715 prefs.st_client_bg.pixel = 0;
2716 prefs.st_client_bg.red = 64507;
2717 prefs.st_client_bg.green = 60909;
2718 prefs.st_client_bg.blue = 60909;
2719 prefs.st_server_fg.pixel = 0;
2720 prefs.st_server_fg.red = 0;
2721 prefs.st_server_fg.green = 0;
2722 prefs.st_server_fg.blue = 32767;
2723 prefs.st_server_bg.pixel = 0;
2724 prefs.st_server_bg.red = 60909;
2725 prefs.st_server_bg.green = 60909;
2726 prefs.st_server_bg.blue = 64507;
2727 prefs.gui_text_valid.pixel = 0; /* light green */
2728 prefs.gui_text_valid.red = 0xAFFF;
2729 prefs.gui_text_valid.green = 0xFFFF;
2730 prefs.gui_text_valid.blue = 0xAFFF;
2731 prefs.gui_text_invalid.pixel = 0; /* light red */
2732 prefs.gui_text_invalid.red = 0xFFFF;
2733 prefs.gui_text_invalid.green = 0xAFFF;
2734 prefs.gui_text_invalid.blue = 0xAFFF;
2735 prefs.gui_text_deprecated.pixel = 0; /* light yellow */
2736 prefs.gui_text_deprecated.red = 0xFFFF;
2737 prefs.gui_text_deprecated.green = 0xFFFF;
2738 prefs.gui_text_deprecated.blue = 0xAFFF;
2739 prefs.gui_geometry_save_position = TRUE;
2740 prefs.gui_geometry_save_size = TRUE;
2741 prefs.gui_geometry_save_maximized= TRUE;
2742 prefs.gui_macosx_style = TRUE;
2743 prefs.gui_console_open = console_open_never;
2744 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
2745 prefs.gui_recent_df_entries_max = 10;
2746 prefs.gui_recent_files_count_max = 10;
2747 prefs.gui_fileopen_dir = wmem_strdup(wmem_epan_scope(), get_persdatafile_dir());
2748 prefs.gui_fileopen_preview = 3;
2749 prefs.gui_ask_unsaved = TRUE;
2750 prefs.gui_find_wrap = TRUE;
2751 prefs.gui_use_pref_save = FALSE;
2752 prefs.gui_update_enabled = TRUE;
2753 prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
2754 prefs.gui_update_interval = 60*60*24; /* Seconds */
2755 /* This can be g_freed, so it must be g_mallocated. */
2756 prefs.gui_webbrowser = g_strdup(HTML_VIEWER " %s");
2757 /* This can be g_freed, so it must be g_mallocated. */
2758 prefs.gui_window_title = g_strdup("");
2759 prefs.gui_start_title = "The World's Most Popular Network Protocol Analyzer";
2760 prefs.gui_version_placement = version_both;
2761 prefs.gui_auto_scroll_on_expand = FALSE;
2762 prefs.gui_auto_scroll_percentage = 0;
2763 prefs.gui_layout_type = layout_type_5;
2764 prefs.gui_layout_content_1 = layout_pane_content_plist;
2765 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
2766 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
2768 prefs.col_list = NULL;
2769 for (i = 0; i < DEF_NUM_COLS; i++) {
2770 cfmt = g_new(fmt_data,1);
2771 cfmt->title = g_strdup(col_fmt[i * 2]);
2772 parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
2773 cfmt->visible = TRUE;
2774 cfmt->resolved = TRUE;
2775 cfmt->custom_field = NULL;
2776 cfmt->custom_occurrence = 0;
2777 prefs.col_list = g_list_append(prefs.col_list, cfmt);
2779 prefs.num_cols = DEF_NUM_COLS;
2781 /* set the default values for the capture dialog box */
2782 prefs.capture_prom_mode = TRUE;
2783 #ifdef PCAP_NG_DEFAULT
2784 prefs.capture_pcap_ng = TRUE;
2786 prefs.capture_pcap_ng = FALSE;
2788 prefs.capture_real_time = TRUE;
2789 prefs.capture_auto_scroll = TRUE;
2790 prefs.capture_show_info = FALSE;
2792 prefs.capture_columns = NULL;
2793 for (i = 0; i < num_capture_cols; i++) {
2794 col_name = g_strdup(capture_cols[i]);
2795 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
2798 prefs.console_log_level =
2799 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
2801 /* set the default values for the tap/statistics dialog box */
2802 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
2803 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
2805 prefs.display_hidden_proto_items = FALSE;
2807 prefs_pre_initialized = TRUE;
2811 * Reset a single dissector preference.
2814 reset_pref(pref_t *pref)
2818 switch (pref->type) {
2821 *pref->varp.uint = pref->default_val.uint;
2825 *pref->varp.boolp = pref->default_val.boolval;
2830 * For now, we save the "description" value, so that if we
2831 * save the preferences older versions of Wireshark can at
2832 * least read preferences that they supported; we support
2833 * either the short name or the description when reading
2834 * the preferences file or a "-o" option.
2836 *pref->varp.enump = pref->default_val.enumval;
2842 g_free((void *)*pref->varp.string);
2843 *pref->varp.string = g_strdup(pref->default_val.string);
2847 g_free(*pref->varp.range);
2848 *pref->varp.range = range_copy(pref->default_val.range);
2851 case PREF_STATIC_TEXT:
2857 *pref->varp.colorp = pref->default_val.color;
2861 pref->custom_cbs.reset_cb(pref);
2866 * This preference is no longer supported; it's not a
2867 * real preference, so we don't reset it (i.e., we
2868 * treat it as if it weren't found in the list of
2869 * preferences, and we weren't called in the first place).
2876 reset_pref_cb(gpointer data, gpointer user_data _U_)
2878 pref_t *pref = (pref_t *) data;
2887 * Reset all preferences for a module.
2890 reset_module_prefs(void *value, void *data _U_)
2892 reset_pref_arg_t arg;
2894 arg.module = (module_t *)value;
2895 g_list_foreach(arg.module->prefs, reset_pref_cb, &arg);
2899 /* Reset preferences */
2903 prefs_initialized = FALSE;
2906 * Unload all UAT preferences.
2911 * Unload any loaded MIBs.
2916 * Reset the non-dissector preferences.
2921 * Reset the non-UAT dissector preferences.
2923 pe_tree_foreach(prefs_modules, reset_module_prefs, NULL);
2926 /* Read the preferences file, fill in "prefs", and return a pointer to it.
2928 If we got an error (other than "it doesn't exist") trying to read
2929 the global preferences file, stuff the errno into "*gpf_errno_return"
2930 and a pointer to the path of the file into "*gpf_path_return", and
2933 If we got an error (other than "it doesn't exist") trying to read
2934 the user's preferences file, stuff the errno into "*pf_errno_return"
2935 and a pointer to the path of the file into "*pf_path_return", and
2938 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
2939 char **gpf_path_return, int *pf_errno_return,
2940 int *pf_read_errno_return, char **pf_path_return)
2946 /* clean up libsmi structures before reading prefs */
2952 * If we don't already have the pathname of the global preferences
2953 * file, construct it. Then, in either case, try to open the file.
2955 if (gpf_path == NULL) {
2957 * We don't have the path; try the new path first, and, if that
2958 * file doesn't exist, try the old path.
2960 gpf_path = get_datafile_path(PF_NAME);
2961 if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
2963 * It doesn't exist by the new name; try the old name.
2966 gpf_path = get_datafile_path(OLD_GPF_NAME);
2967 pf = ws_fopen(gpf_path, "r");
2971 * We have the path; try it.
2973 pf = ws_fopen(gpf_path, "r");
2977 * If we were able to open the file, read it.
2978 * XXX - if it failed for a reason other than "it doesn't exist",
2981 *gpf_path_return = NULL;
2984 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
2987 mgcp_tcp_port_count = 0;
2988 mgcp_udp_port_count = 0;
2990 /* We succeeded in opening it; read it. */
2991 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
2993 /* We had an error reading the file; return the errno and the
2994 pathname, so our caller can report the error. */
2995 *gpf_errno_return = 0;
2996 *gpf_read_errno_return = err;
2997 *gpf_path_return = gpf_path;
3001 /* We failed to open it. If we failed for some reason other than
3002 "it doesn't exist", return the errno and the pathname, so our
3003 caller can report the error. */
3004 if (errno != ENOENT) {
3005 *gpf_errno_return = errno;
3006 *gpf_read_errno_return = 0;
3007 *gpf_path_return = gpf_path;
3011 /* Construct the pathname of the user's preferences file. */
3012 pf_path = get_persconffile_path(PF_NAME, TRUE);
3014 /* Read the user's preferences file, if it exists. */
3015 *pf_path_return = NULL;
3016 if ((pf = ws_fopen(pf_path, "r")) != NULL) {
3018 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3021 mgcp_tcp_port_count = 0;
3022 mgcp_udp_port_count = 0;
3024 /* We succeeded in opening it; read it. */
3025 err = read_prefs_file(pf_path, pf, set_pref, NULL);
3027 /* We had an error reading the file; return the errno and the
3028 pathname, so our caller can report the error. */
3029 *pf_errno_return = 0;
3030 *pf_read_errno_return = err;
3031 *pf_path_return = pf_path;
3036 /* We failed to open it. If we failed for some reason other than
3037 "it doesn't exist", return the errno and the pathname, so our
3038 caller can report the error. */
3039 if (errno != ENOENT) {
3040 *pf_errno_return = errno;
3041 *pf_read_errno_return = 0;
3042 *pf_path_return = pf_path;
3047 /* load SMI modules if needed */
3053 /* read the preferences file (or similiar) and call the callback
3054 * function to set each key/value pair found */
3056 read_prefs_file(const char *pf_path, FILE *pf,
3057 pref_set_pair_cb pref_set_pair_fct, void *private_data)
3059 enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
3060 int got_c, state = START;
3063 gboolean got_val = FALSE;
3064 gint fline = 1, pline = 1;
3065 gchar hint[] = "(applying your preferences once should remove this warning)";
3067 cur_val = g_string_new("");
3068 cur_var = g_string_new("");
3070 while ((got_c = getc(pf)) != EOF) {
3071 if (got_c == '\n') {
3079 if (isalnum(got_c)) {
3080 if (cur_var->len > 0) {
3082 if (cur_val->len > 0) {
3083 if (cur_val->str[cur_val->len-1] == ',') {
3085 * If the pref has a trailing comma, eliminate it.
3087 cur_val->str[cur_val->len-1] = '\0';
3088 g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
3091 /* Call the routine to set the preference; it will parse
3092 the value as appropriate. */
3093 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3098 case PREFS_SET_SYNTAX_ERR:
3099 g_warning ("%s line %d: Syntax error in preference \"%s\" %s",
3100 pf_path, pline, cur_var->str, hint);
3103 case PREFS_SET_NO_SUCH_PREF:
3105 * If "print.command" silently ignore it because it's valid
3106 * on non-Win32 platforms.
3108 if (strcmp(cur_var->str, "print.command") != 0)
3109 g_warning ("%s line %d: No such preference \"%s\" %s",
3110 pf_path, pline, cur_var->str, hint);
3113 case PREFS_SET_OBSOLETE:
3114 /* We silently ignore attempts to set these; it's
3115 probably not the user's fault that it's in there -
3116 they may have saved preferences with a release that
3121 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
3126 g_string_truncate(cur_var, 0);
3127 g_string_append_c(cur_var, (gchar) got_c);
3129 } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
3131 } else if (got_c == '#') {
3134 g_warning ("%s line %d: Malformed line %s", pf_path, fline, hint);
3139 g_string_append_c(cur_var, (gchar) got_c);
3141 /* This is a colon (':') */
3143 g_string_truncate(cur_val, 0);
3145 * Set got_val to TRUE to accommodate prefs such as
3146 * "gui.fileopen.dir" that do not require a value.
3152 if (!isspace(got_c)) {
3154 g_string_append_c(cur_val, (gchar) got_c);
3158 g_string_append_c(cur_val, (gchar) got_c);
3162 if (cur_var->len > 0) {
3164 /* Convert the string to a range. Since we're reading the
3165 * preferences file, silently lower values in excess of the
3168 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3173 case PREFS_SET_SYNTAX_ERR:
3174 g_warning ("%s line %d: Syntax error in preference %s %s", pf_path, pline, cur_var->str, hint);
3177 case PREFS_SET_NO_SUCH_PREF:
3178 g_warning ("%s line %d: No such preference \"%s\" %s", pf_path,
3179 pline, cur_var->str, hint);
3182 case PREFS_SET_OBSOLETE:
3183 /* We silently ignore attempts to set these; it's probably not
3184 the user's fault that it's in there - they may have saved
3185 preferences with a release that supported it. */
3189 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
3193 g_string_free(cur_val, TRUE);
3194 g_string_free(cur_var, TRUE);
3203 * If we were handed a preference starting with "uat:", try to turn it into
3204 * a valid uat entry.
3207 prefs_set_uat_pref(char *uat_entry) {
3212 colonp = strchr(uat_entry, ':');
3220 * Skip over any white space (there probably won't be any, but
3221 * as we allow it in the preferences file, we might as well
3224 while (isspace((guchar)*p))
3228 * Put the colon back, so if our caller uses, in an
3229 * error message, the string they passed us, the message
3236 uat = uat_find(uat_entry);
3242 if (uat_load_str(uat, p, &err)) {
3249 * Given a string of the form "<pref name>:<pref value>", as might appear
3250 * as an argument to a "-o" option, parse it and set the preference in
3251 * question. Return an indication of whether it succeeded or failed
3255 prefs_set_pref(char *prefarg)
3258 prefs_set_pref_e ret;
3261 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
3262 * seen to values that keep us from trying to interpret tham
3263 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
3264 * as, from the command line, we have no way of guessing which
3265 * the user had in mind.
3267 mgcp_tcp_port_count = -1;
3268 mgcp_udp_port_count = -1;
3270 colonp = strchr(prefarg, ':');
3272 return PREFS_SET_SYNTAX_ERR;
3278 * Skip over any white space (there probably won't be any, but
3279 * as we allow it in the preferences file, we might as well
3282 while (isspace((guchar)*p))
3286 * Put the colon back, so if our caller uses, in an
3287 * error message, the string they passed us, the message
3291 return PREFS_SET_SYNTAX_ERR;
3293 if (strcmp(prefarg, "uat")) {
3294 ret = set_pref(prefarg, p, NULL, TRUE);
3296 ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
3298 *colonp = ':'; /* put the colon back */
3303 * Returns TRUE if the given device is hidden
3306 prefs_is_capture_device_hidden(const char *name)
3308 gchar *tok, *devices;
3311 if (prefs.capture_devices_hide && name) {
3312 devices = g_strdup (prefs.capture_devices_hide);
3313 len = strlen (name);
3314 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3315 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3327 * Returns TRUE if the given column is visible (not hidden)
3330 prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
3333 fmt_data cfmt_hidden;
3336 * Do we have a list of hidden columns?
3340 * Yes - check the column against each of the ones in the
3343 cols = g_strdup(cols_hidden);
3344 for (tok = strtok(cols, ","); tok; tok = strtok(NULL, ",")) {
3345 tok = g_strstrip(tok);
3348 * Parse this column format.
3350 if (!parse_column_format(&cfmt_hidden, tok)) {
3352 * It's not valid; ignore it.
3358 * Does it match the column?
3360 if (cfmt->fmt != cfmt_hidden.fmt) {
3362 g_free(cfmt_hidden.custom_field);
3365 if (cfmt->fmt == COL_CUSTOM) {
3367 * A custom column has to have the
3368 * same custom field and occurrence.
3370 if (strcmp(cfmt->custom_field,
3371 cfmt_hidden.custom_field) != 0) {
3372 /* Different fields. */
3373 g_free(cfmt_hidden.custom_field);
3376 if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
3377 /* Different occurrences. */
3378 g_free(cfmt_hidden.custom_field);
3384 * OK, they match, so it's one of the hidden fields,
3385 * hence not visible.
3387 g_free(cfmt_hidden.custom_field);
3395 * No - either there are no hidden columns or this isn't one
3396 * of them - so it is visible.
3402 * Returns TRUE if the given device should capture in monitor mode by default
3405 prefs_capture_device_monitor_mode(const char *name)
3407 gchar *tok, *devices;
3410 if (prefs.capture_devices_monitor_mode && name) {
3411 devices = g_strdup (prefs.capture_devices_monitor_mode);
3412 len = strlen (name);
3413 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3414 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3426 * Returns TRUE if the user has marked this column as visible
3429 prefs_capture_options_dialog_column_is_visible(const gchar *column)
3434 for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
3435 col = (gchar *)curr->data;
3436 if (col && (g_ascii_strcasecmp(col, column) == 0)) {
3443 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
3444 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
3445 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
3447 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
3448 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
3449 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
3452 string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
3456 memset(name_resolve, 0, sizeof(e_addr_resolve));
3457 while ((c = *string++) != '\0') {
3460 name_resolve->mac_name = TRUE;
3463 name_resolve->network_name = TRUE;
3466 name_resolve->use_external_net_name_resolver = TRUE;
3469 name_resolve->transport_name = TRUE;
3472 name_resolve->concurrent_dns = TRUE;
3476 * Unrecognized letter.
3486 try_convert_to_custom_column(gpointer *el_data)
3488 /* Array of columns that have been migrated to custom columns */
3491 const gchar *col_expr;
3492 } migrated_columns[] = {
3493 { COL_COS_VALUE, "vlan.priority" },
3494 { COL_CIRCUIT_ID, "iax2.call" },
3495 { COL_BSSGP_TLLI, "bssgp.tlli" },
3496 { COL_HPUX_SUBSYS, "nettl.subsys" },
3497 { COL_HPUX_DEVID, "nettl.devid" },
3498 { COL_FR_DLCI, "fr.dlci" },
3499 { COL_REL_CONV_TIME, "tcp.time_relative" },
3500 { COL_DELTA_CONV_TIME, "tcp.time_delta" },
3501 { COL_OXID, "fc.ox_id" },
3502 { COL_RXID, "fc.rx_id" },
3503 { COL_SRCIDX, "mdshdr.srcidx" },
3504 { COL_DSTIDX, "mdshdr.dstidx" },
3505 { COL_DCE_CTX, "dcerpc.cn_ctx_id" }
3509 const gchar *haystack_fmt;
3511 gchar **fmt = (gchar **) el_data;
3513 for (haystack_idx = 0;
3514 haystack_idx < G_N_ELEMENTS(migrated_columns);
3517 haystack_fmt = col_format_to_string(migrated_columns[haystack_idx].el);
3518 if (strcmp(haystack_fmt, *fmt) == 0) {
3519 gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
3520 migrated_columns[haystack_idx].col_expr);
3528 static prefs_set_pref_e
3529 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
3530 gboolean return_range_errors)
3532 unsigned long int cval;
3537 gchar *dotp, *last_dotp;
3538 static gchar *filter_label = NULL;
3539 static gboolean filter_enabled = FALSE;
3540 gchar *filter_expr = NULL;
3545 if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
3546 filter_label = g_strdup(value);
3547 } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
3548 filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
3549 } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
3550 filter_expr = g_strdup(value);
3551 filter_expression_new(filter_label, filter_expr, filter_enabled);
3552 g_free(filter_label);
3553 g_free(filter_expr);
3554 } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
3555 /* Convert deprecated value to closest current equivalent */
3556 if (g_ascii_strcasecmp(value, "true") == 0) {
3557 prefs.gui_version_placement = version_both;
3559 prefs.gui_version_placement = version_neither;
3561 } else if (strcmp(pref_name, "name_resolve") == 0 ||
3562 strcmp(pref_name, "capture.name_resolve") == 0) {
3564 * Handle the deprecated name resolution options.
3566 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
3567 * RESOLV_ALL and RESOLV_NONE.
3569 * Otherwise, we treat it as a list of name types we want to resolve.
3571 if (g_ascii_strcasecmp(value, "true") == 0) {
3572 gbl_resolv_flags.mac_name = TRUE;
3573 gbl_resolv_flags.network_name = TRUE;
3574 gbl_resolv_flags.transport_name = TRUE;
3575 gbl_resolv_flags.concurrent_dns = TRUE;
3577 else if (g_ascii_strcasecmp(value, "false") == 0) {
3578 gbl_resolv_flags.mac_name = FALSE;
3579 gbl_resolv_flags.network_name = FALSE;
3580 gbl_resolv_flags.transport_name = FALSE;
3581 gbl_resolv_flags.concurrent_dns = FALSE;
3584 /* start out with none set */
3585 gbl_resolv_flags.mac_name = FALSE;
3586 gbl_resolv_flags.network_name = FALSE;
3587 gbl_resolv_flags.transport_name = FALSE;
3588 gbl_resolv_flags.concurrent_dns = FALSE;
3589 if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
3590 return PREFS_SET_SYNTAX_ERR;
3593 /* Handle deprecated "global" options that don't have a module
3594 * associated with them
3596 if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
3597 (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
3598 (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
3599 module = nameres_module;
3602 /* To which module does this preference belong? */
3604 last_dotp = pref_name;
3607 dotp = strchr(last_dotp, '.');
3610 /* no such module */
3611 return PREFS_SET_NO_SUCH_PREF;
3614 /* no ".", so no module/name separator */
3615 return PREFS_SET_SYNTAX_ERR;
3621 *dotp = '\0'; /* separate module and preference name */
3622 module = prefs_find_module(pref_name);
3625 * XXX - "Diameter" rather than "diameter" was used in earlier
3626 * versions of Wireshark; if we didn't find the module, and its name
3627 * was "Diameter", look for "diameter" instead.
3629 * In addition, the BEEP protocol used to be the BXXP protocol,
3630 * so if we didn't find the module, and its name was "bxxp",
3631 * look for "beep" instead.
3633 * Also, the preferences for GTP v0 and v1 were combined under
3634 * a single "gtp" heading, and the preferences for SMPP were
3635 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
3636 * However, SMPP now has its own preferences, so we just map
3637 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
3639 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
3640 * and "nsip" to "gprs_ns".
3642 * The SynOptics Network Management Protocol (SONMP) is now known by
3643 * its modern name, the Nortel Discovery Protocol (NDP).
3645 if (module == NULL) {
3646 if (strcmp(pref_name, "column") == 0)
3647 module = gui_column_module;
3648 else if (strcmp(pref_name, "Diameter") == 0)
3649 module = prefs_find_module("diameter");
3650 else if (strcmp(pref_name, "bxxp") == 0)
3651 module = prefs_find_module("beep");
3652 else if (strcmp(pref_name, "gtpv0") == 0 ||
3653 strcmp(pref_name, "gtpv1") == 0)
3654 module = prefs_find_module("gtp");
3655 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
3656 module = prefs_find_module("gsm-sms-ud");
3657 else if (strcmp(pref_name, "dcp") == 0)
3658 module = prefs_find_module("dccp");
3659 else if (strcmp(pref_name, "x.25") == 0)
3660 module = prefs_find_module("x25");
3661 else if (strcmp(pref_name, "x411") == 0)
3662 module = prefs_find_module("p1");
3663 else if (strcmp(pref_name, "nsip") == 0)
3664 module = prefs_find_module("gprs-ns");
3665 else if (strcmp(pref_name, "sonmp") == 0)
3666 module = prefs_find_module("ndp");
3667 else if (strcmp(pref_name, "etheric") == 0 ||
3668 strcmp(pref_name, "isup_thin") == 0)
3669 /* This protocol was removed 7. July 2009 */
3670 return PREFS_SET_OBSOLETE;
3672 *dotp = '.'; /* put the preference string back */
3673 dotp++; /* skip past separator to preference name */
3678 pref = prefs_find_preference(module, dotp);
3681 /* "gui" prefix was added to column preferences for better organization
3682 * within the preferences file
3684 if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
3685 (strcmp(pref_name, PRS_COL_FMT) == 0)) {
3686 pref = prefs_find_preference(module, pref_name);
3688 else if (strcmp(module->name, "mgcp") == 0) {
3690 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
3691 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
3692 * were used in earlier versions of Wireshark; if we didn't find the
3693 * preference, it was an MGCP preference, and its name was
3694 * "display raw text toggle" or "display dissect tree", look for
3695 * "display_raw_text" or "display_dissect_tree" instead.
3697 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
3698 * the gateway and callagent ports were given those names; we interpret
3699 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
3700 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
3701 * they were registered by the MCCP dissector and thus that's the
3702 * order in which they were written to the preferences file. (If
3703 * we're not reading the preferences file, but are handling stuff
3704 * from a "-o" command-line option, we have no clue which the user
3705 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
3706 * or "mgcp.{tcp,udp}.callagent_port" instead.)
3708 if (strcmp(dotp, "display raw text toggle") == 0)
3709 pref = prefs_find_preference(module, "display_raw_text");
3710 else if (strcmp(dotp, "display dissect tree") == 0)
3711 pref = prefs_find_preference(module, "display_dissect_tree");
3712 else if (strcmp(dotp, "tcp.port") == 0) {
3713 mgcp_tcp_port_count++;
3714 if (mgcp_tcp_port_count == 1) {
3715 /* It's the first one */
3716 pref = prefs_find_preference(module, "tcp.gateway_port");
3717 } else if (mgcp_tcp_port_count == 2) {
3718 /* It's the second one */
3719 pref = prefs_find_preference(module, "tcp.callagent_port");
3721 /* Otherwise it's from the command line, and we don't bother
3723 } else if (strcmp(dotp, "udp.port") == 0) {
3724 mgcp_udp_port_count++;
3725 if (mgcp_udp_port_count == 1) {
3726 /* It's the first one */
3727 pref = prefs_find_preference(module, "udp.gateway_port");
3728 } else if (mgcp_udp_port_count == 2) {
3729 /* It's the second one */
3730 pref = prefs_find_preference(module, "udp.callagent_port");
3732 /* Otherwise it's from the command line, and we don't bother
3735 } else if (strcmp(module->name, "smb") == 0) {
3736 /* Handle old names for SMB preferences. */
3737 if (strcmp(dotp, "smb.trans.reassembly") == 0)
3738 pref = prefs_find_preference(module, "trans_reassembly");
3739 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
3740 pref = prefs_find_preference(module, "dcerpc_reassembly");
3741 } else if (strcmp(module->name, "ndmp") == 0) {
3742 /* Handle old names for NDMP preferences. */
3743 if (strcmp(dotp, "ndmp.desegment") == 0)
3744 pref = prefs_find_preference(module, "desegment");
3745 } else if (strcmp(module->name, "diameter") == 0) {
3746 /* Handle old names for Diameter preferences. */
3747 if (strcmp(dotp, "diameter.desegment") == 0)
3748 pref = prefs_find_preference(module, "desegment");
3749 } else if (strcmp(module->name, "pcli") == 0) {
3750 /* Handle old names for PCLI preferences. */
3751 if (strcmp(dotp, "pcli.udp_port") == 0)
3752 pref = prefs_find_preference(module, "udp_port");
3753 } else if (strcmp(module->name, "artnet") == 0) {
3754 /* Handle old names for ARTNET preferences. */
3755 if (strcmp(dotp, "artnet.udp_port") == 0)
3756 pref = prefs_find_preference(module, "udp_port");
3757 } else if (strcmp(module->name, "mapi") == 0) {
3758 /* Handle old names for MAPI preferences. */
3759 if (strcmp(dotp, "mapi_decrypt") == 0)
3760 pref = prefs_find_preference(module, "decrypt");
3761 } else if (strcmp(module->name, "fc") == 0) {
3762 /* Handle old names for Fibre Channel preferences. */
3763 if (strcmp(dotp, "reassemble_fc") == 0)
3764 pref = prefs_find_preference(module, "reassemble");
3765 else if (strcmp(dotp, "fc_max_frame_size") == 0)
3766 pref = prefs_find_preference(module, "max_frame_size");
3767 } else if (strcmp(module->name, "fcip") == 0) {
3768 /* Handle old names for Fibre Channel-over-IP preferences. */
3769 if (strcmp(dotp, "desegment_fcip_messages") == 0)
3770 pref = prefs_find_preference(module, "desegment");
3771 else if (strcmp(dotp, "fcip_port") == 0)
3772 pref = prefs_find_preference(module, "target_port");
3773 } else if (strcmp(module->name, "gtp") == 0) {
3774 /* Handle old names for GTP preferences. */
3775 if (strcmp(dotp, "gtpv0_port") == 0)
3776 pref = prefs_find_preference(module, "v0_port");
3777 else if (strcmp(dotp, "gtpv1c_port") == 0)
3778 pref = prefs_find_preference(module, "v1c_port");
3779 else if (strcmp(dotp, "gtpv1u_port") == 0)
3780 pref = prefs_find_preference(module, "v1u_port");
3781 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
3782 pref = prefs_find_preference(module, "dissect_tpdu");
3783 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
3784 pref = prefs_find_preference(module, "v0_dissect_cdr_as");
3785 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
3786 pref = prefs_find_preference(module, "v0_check_etsi");
3787 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
3788 pref = prefs_find_preference(module, "v1_check_etsi");
3789 } else if (strcmp(module->name, "ip") == 0) {
3790 /* Handle old names for IP preferences. */
3791 if (strcmp(dotp, "ip_summary_in_tree") == 0)
3792 pref = prefs_find_preference(module, "summary_in_tree");
3793 } else if (strcmp(module->name, "iscsi") == 0) {
3794 /* Handle old names for iSCSI preferences. */
3795 if (strcmp(dotp, "iscsi_port") == 0)
3796 pref = prefs_find_preference(module, "target_port");
3797 } else if (strcmp(module->name, "lmp") == 0) {
3798 /* Handle old names for LMP preferences. */
3799 if (strcmp(dotp, "lmp_version") == 0)
3800 pref = prefs_find_preference(module, "version");
3801 } else if (strcmp(module->name, "mtp3") == 0) {
3802 /* Handle old names for MTP3 preferences. */
3803 if (strcmp(dotp, "mtp3_standard") == 0)
3804 pref = prefs_find_preference(module, "standard");
3805 else if (strcmp(dotp, "net_addr_format") == 0)
3806 pref = prefs_find_preference(module, "addr_format");
3807 } else if (strcmp(module->name, "nlm") == 0) {
3808 /* Handle old names for NLM preferences. */
3809 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
3810 pref = prefs_find_preference(module, "msg_res_matching");
3811 } else if (strcmp(module->name, "ppp") == 0) {
3812 /* Handle old names for PPP preferences. */
3813 if (strcmp(dotp, "ppp_fcs") == 0)
3814 pref = prefs_find_preference(module, "fcs_type");
3815 else if (strcmp(dotp, "ppp_vj") == 0)
3816 pref = prefs_find_preference(module, "decompress_vj");
3817 } else if (strcmp(module->name, "rsvp") == 0) {
3818 /* Handle old names for RSVP preferences. */
3819 if (strcmp(dotp, "rsvp_process_bundle") == 0)
3820 pref = prefs_find_preference(module, "process_bundle");
3821 } else if (strcmp(module->name, "tcp") == 0) {
3822 /* Handle old names for TCP preferences. */
3823 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
3824 pref = prefs_find_preference(module, "summary_in_tree");
3825 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
3826 pref = prefs_find_preference(module, "analyze_sequence_numbers");
3827 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
3828 pref = prefs_find_preference(module, "relative_sequence_numbers");
3829 } else if (strcmp(module->name, "udp") == 0) {
3830 /* Handle old names for UDP preferences. */
3831 if (strcmp(dotp, "udp_summary_in_tree") == 0)
3832 pref = prefs_find_preference(module, "summary_in_tree");
3833 } else if (strcmp(module->name, "ndps") == 0) {
3834 /* Handle old names for NDPS preferences. */
3835 if (strcmp(dotp, "desegment_ndps") == 0)
3836 pref = prefs_find_preference(module, "desegment_tcp");
3837 } else if (strcmp(module->name, "http") == 0) {
3838 /* Handle old names for HTTP preferences. */
3839 if (strcmp(dotp, "desegment_http_headers") == 0)
3840 pref = prefs_find_preference(module, "desegment_headers");
3841 else if (strcmp(dotp, "desegment_http_body") == 0)
3842 pref = prefs_find_preference(module, "desegment_body");
3843 } else if (strcmp(module->name, "smpp") == 0) {
3844 /* Handle preferences that moved from SMPP. */
3845 module_t *new_module = prefs_find_module("gsm-sms-ud");
3847 if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
3848 pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
3849 else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
3850 pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
3852 } else if (strcmp(module->name, "asn1") == 0) {
3853 /* Handle old generic ASN.1 preferences (it's not really a
3854 rename, as the new preferences support multiple ports,
3855 but we might as well copy them over). */
3856 if (strcmp(dotp, "tcp_port") == 0)
3857 pref = prefs_find_preference(module, "tcp_ports");
3858 else if (strcmp(dotp, "udp_port") == 0)
3859 pref = prefs_find_preference(module, "udp_ports");
3860 else if (strcmp(dotp, "sctp_port") == 0)
3861 pref = prefs_find_preference(module, "sctp_ports");
3862 } else if (strcmp(module->name, "llcgprs") == 0) {
3863 if (strcmp(dotp, "ignore_cipher_bit") == 0)
3864 pref = prefs_find_preference(module, "autodetect_cipher_bit");
3865 } else if (strcmp(module->name, "erf") == 0) {
3866 if (strcmp(dotp, "erfeth") == 0) {
3867 /* Handle the old "erfeth" preference; map it to the new
3868 "ethfcs" preference, and map the values to those for
3869 the new preference. */
3870 pref = prefs_find_preference(module, "ethfcs");
3871 if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
3873 else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
3875 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3877 } else if (strcmp(dotp, "erfatm") == 0) {
3878 /* Handle the old "erfatm" preference; map it to the new
3879 "aal5_type" preference, and map the values to those for
3880 the new preference. */
3881 pref = prefs_find_preference(module, "aal5_type");
3882 if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
3884 else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
3886 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3888 } else if (strcmp(dotp, "erfhdlc") == 0) {
3889 /* Handle the old "erfhdlc" preference; map it to the new
3890 "hdlc_type" preference, and map the values to those for
3891 the new preference. */
3892 pref = prefs_find_preference(module, "hdlc_type");
3893 if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
3895 else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
3897 else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
3899 else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
3901 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3904 } else if (strcmp(module->name, "eth") == 0) {
3905 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
3906 if (strcmp(dotp, "qinq_ethertype") == 0) {
3907 module_t *new_module = prefs_find_module("vlan");
3909 pref = prefs_find_preference(new_module, "qinq_ethertype");
3910 module = new_module;
3913 } else if (strcmp(module->name, "taps") == 0) {
3914 /* taps preferences moved to "statistics" module */
3915 if (strcmp(dotp, "update_interval") == 0 ||
3916 strcmp(dotp, "rtp_player_max_visible") == 0)
3917 pref = prefs_find_preference(stats_module, dotp);
3918 } else if (strcmp(module->name, "packet_list") == 0) {
3919 /* packet_list preferences moved to protocol module */
3920 if (strcmp(dotp, "display_hidden_proto_items") == 0)
3921 pref = prefs_find_preference(protocols_module, dotp);
3922 } else if (strcmp(module->name, "stream") == 0) {
3923 /* stream preferences moved to gui color module */
3924 if ((strcmp(dotp, "client.fg") == 0) ||
3925 (strcmp(dotp, "client.bg") == 0) ||
3926 (strcmp(dotp, "server.fg") == 0) ||
3927 (strcmp(dotp, "server.bg") == 0))
3928 pref = prefs_find_preference(gui_color_module, pref_name);
3929 } else if (strcmp(module->name, "nameres") == 0) {
3930 if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
3931 pref = prefs_find_preference(nameres_module, pref_name);
3932 } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
3933 pref = prefs_find_preference(nameres_module, "load_smi_modules");
3934 } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
3935 pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
3940 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
3942 switch (pref->type) {
3945 /* XXX - give an error if it doesn't fit in a guint? */
3946 uval = (guint)strtoul(value, &p, pref->info.base);
3947 if (p == value || *p != '\0')
3948 return PREFS_SET_SYNTAX_ERR; /* number was bad */
3949 if (*pref->varp.uint != uval) {
3950 module->prefs_changed = TRUE;
3951 *pref->varp.uint = uval;
3956 /* XXX - give an error if it's neither "true" nor "false"? */
3957 if (g_ascii_strcasecmp(value, "true") == 0)
3961 if (*pref->varp.boolp != bval) {
3962 module->prefs_changed = TRUE;
3963 *pref->varp.boolp = bval;
3968 /* XXX - give an error if it doesn't match? */
3969 enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
3971 if (*pref->varp.enump != enum_val) {
3972 module->prefs_changed = TRUE;
3973 *pref->varp.enump = enum_val;
3980 if (strcmp(*pref->varp.string, value) != 0) {
3981 module->prefs_changed = TRUE;
3982 g_free((void *)*pref->varp.string);
3983 *pref->varp.string = g_strdup(value);
3991 if (range_convert_str_work(&newrange, value, pref->info.max_value,
3992 return_range_errors) != CVT_NO_ERROR) {
3993 return PREFS_SET_SYNTAX_ERR; /* number was bad */
3996 if (!ranges_are_equal(*pref->varp.range, newrange)) {
3997 module->prefs_changed = TRUE;
3998 g_free(*pref->varp.range);
3999 *pref->varp.range = newrange;
4008 cval = strtoul(value, NULL, 16);
4009 pref->varp.colorp->pixel = 0;
4010 if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
4011 (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
4012 (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
4013 module->prefs_changed = TRUE;
4014 pref->varp.colorp->red = RED_COMPONENT(cval);
4015 pref->varp.colorp->green = GREEN_COMPONENT(cval);
4016 pref->varp.colorp->blue = BLUE_COMPONENT(cval);
4022 return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
4024 case PREF_STATIC_TEXT:
4031 return PREFS_SET_OBSOLETE; /* no such preference any more */
4035 return PREFS_SET_OK;
4040 gboolean is_gui_module;
4041 } write_gui_pref_arg_t;
4044 prefs_pref_type_name(pref_t *pref)
4046 const char *type_name = "[Unknown]";
4049 return type_name; /* ...or maybe assert? */
4052 switch (pref->type) {
4055 switch (pref->info.base) {
4058 type_name = "Decimal";
4062 type_name = "Octal";
4066 type_name = "Hexadecimal";
4072 type_name = "Boolean";
4076 type_name = "Choice";
4080 type_name = "String";
4084 type_name = "Filename";
4088 type_name = "Directory";
4092 type_name = "Range";
4096 type_name = "Color";
4100 if (pref->custom_cbs.type_name_cb)
4101 return pref->custom_cbs.type_name_cb();
4102 type_name = "Custom";
4106 type_name = "Obsolete";
4109 case PREF_STATIC_TEXT:
4110 type_name = "Static text";
4121 prefs_pref_type_description(pref_t *pref)
4123 const char *type_desc = "An unkown preference type";
4126 return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
4129 switch (pref->type) {
4132 switch (pref->info.base) {
4135 type_desc = "A decimal number";
4139 type_desc = "An octal number";
4143 type_desc = "A hexadecimal number";
4149 type_desc = "TRUE or FALSE (case-insensitive)";
4154 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4155 GString *enum_str = g_string_new("One of: ");
4156 while (enum_valp->name != NULL) {
4157 g_string_append(enum_str, enum_valp->description);
4159 if (enum_valp->name != NULL)
4160 g_string_append(enum_str, ", ");
4162 g_string_append(enum_str, "\n(case-insensitive).");
4163 return g_string_free(enum_str, FALSE);
4168 type_desc = "A string";
4172 type_desc = "A path to a file";
4176 type_desc = "A path to a directory";
4181 type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
4187 type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
4192 if (pref->custom_cbs.type_description_cb)
4193 return pref->custom_cbs.type_description_cb();
4194 type_desc = "A custom value";
4198 type_desc = "An obsolete preference";
4201 case PREF_STATIC_TEXT:
4202 type_desc = "[Static text]";
4206 type_desc = "Configuration data stored in its own file";
4212 return g_strdup(type_desc);
4216 prefs_pref_is_default(pref_t *pref) {
4217 if (!pref) return FALSE;
4219 switch (pref->type) {
4222 if (pref->default_val.uint == *pref->varp.uint)
4227 if (pref->default_val.boolval == *pref->varp.boolp)
4232 if (pref->default_val.enumval == *pref->varp.enump)
4239 if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
4245 if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
4252 if ((pref->default_val.color.red == pref->varp.colorp->red) &&
4253 (pref->default_val.color.green == pref->varp.colorp->green) &&
4254 (pref->default_val.color.blue == pref->varp.colorp->blue))
4260 return pref->custom_cbs.is_default_cb(pref);
4263 case PREF_STATIC_TEXT:
4266 /* g_assert_not_reached(); */
4273 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
4274 const char *pref_text = "[Unknown]";
4276 gboolean pref_boolval;
4278 const char *pref_string;
4279 range_t *pref_range;
4280 color_t *pref_color;
4283 return g_strdup(pref_text);
4288 pref_uint = pref->default_val.uint;
4289 pref_boolval = pref->default_val.boolval;
4290 pref_enumval = pref->default_val.enumval;
4291 pref_string = pref->default_val.string;
4292 pref_range = pref->default_val.range;
4293 pref_color = &pref->default_val.color;
4296 pref_uint = pref->stashed_val.uint;
4297 pref_boolval = pref->stashed_val.boolval;
4298 pref_enumval = pref->stashed_val.enumval;
4299 pref_string = pref->stashed_val.string;
4300 pref_range = pref->stashed_val.range;
4301 pref_color = &pref->stashed_val.color;
4304 pref_uint = *pref->varp.uint;
4305 pref_boolval = *pref->varp.boolp;
4306 pref_enumval = *pref->varp.enump;
4307 pref_string = *pref->varp.string;
4308 pref_range = *pref->varp.range;
4309 pref_color = pref->varp.colorp;
4312 return g_strdup(pref_text);
4315 switch (pref->type) {
4318 switch (pref->info.base) {
4321 return g_strdup_printf("%u", pref_uint);
4325 return g_strdup_printf("%#o", pref_uint);
4329 return g_strdup_printf("%#x", pref_uint);
4335 return g_strdup_printf("%s", pref_boolval ? "TRUE" : "FALSE");
4341 * For now, we return the "description" value, so that if we
4342 * save the preferences older versions of Wireshark can at
4343 * least read preferences that they supported; we support
4344 * either the short name or the description when reading
4345 * the preferences file or a "-o" option.
4347 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4348 while (enum_valp->name != NULL) {
4349 if (enum_valp->value == pref_enumval)
4350 return g_strdup(enum_valp->description);
4359 return g_strdup(pref_string);
4363 pref_text = range_convert_range(pref_range);
4367 return g_strdup_printf("%02x%02x%02x",
4368 (pref_color->red * 255 / 65535),
4369 (pref_color->green * 255 / 65535),
4370 (pref_color->blue * 255 / 65535));
4374 if (pref->custom_cbs.to_str_cb)
4375 return pref->custom_cbs.to_str_cb(pref, source == pref_default ? TRUE : FALSE);
4376 pref_text = "[Custom]";
4380 pref_text = "[Obsolete]";
4383 case PREF_STATIC_TEXT:
4384 pref_text = "[Static text]";
4389 uat_t *uat = (uat_t *) pref->varp.uat;
4390 if (uat && uat->filename)
4391 return g_strdup_printf("[Managed in the file \"%s\"]", uat->filename);
4393 pref_text = "[Managed in an unknown file]";
4400 return g_strdup(pref_text);
4404 * Write out a single dissector preference.
4407 write_pref(gpointer data, gpointer user_data)
4409 pref_t *pref = (pref_t *)data;
4410 write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
4414 switch (pref->type) {
4417 * This preference is no longer supported; it's not a
4418 * real preference, so we don't write it out (i.e., we
4419 * treat it as if it weren't found in the list of
4420 * preferences, and we weren't called in the first place).
4424 case PREF_STATIC_TEXT:
4426 /* Nothing to do; don't bother printing the description */
4432 if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL) {
4434 * The prefix will either be the module name or the parent
4435 * name if it's a subtree
4437 const char *name_prefix = (arg->module->name != NULL) ? arg->module->name : arg->module->parent->name;
4438 char *type_desc, *pref_text;
4439 const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
4441 if (pref->type == PREF_CUSTOM) fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
4442 fprintf(arg->pf, "\n");
4443 if (pref->description &&
4444 (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
4445 if (pref->type != PREF_CUSTOM) {
4446 /* We get duplicate lines otherwise. */
4448 desc_lines = g_strsplit(pref->description,"\n",0);
4449 for (i = 0; desc_lines[i] != NULL; ++i) {
4450 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4452 g_strfreev(desc_lines);
4455 fprintf(arg->pf, "# No description\n");
4458 type_desc = prefs_pref_type_description(pref);
4459 desc_lines = g_strsplit(type_desc,"\n",0);
4460 for (i = 0; desc_lines[i] != NULL; ++i) {
4461 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4463 g_strfreev(desc_lines);
4466 pref_text = prefs_pref_to_str(pref, pref_current);
4467 fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
4468 desc_lines = g_strsplit(pref_text,"\n",0);
4469 for (i = 0; desc_lines[i] != NULL; ++i) {
4470 fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
4472 if (i == 0) fprintf(arg->pf, "\n");
4473 g_strfreev(desc_lines);
4480 * Write out all preferences for a module.
4483 write_module_prefs(module_t *module, gpointer user_data)
4485 write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
4486 write_pref_arg_t arg;
4488 /* The GUI module needs to be explicitly called out so it
4489 can be written out of order */
4490 if ((module == gui_module) && (gui_pref_arg->is_gui_module != TRUE))
4493 /* Write a header for the main modules and GUI sub-modules */
4494 if (((module->parent == NULL) || (module->parent == gui_module)) &&
4495 ((prefs_module_has_submodules(module)) ||
4496 (module->numprefs > 0) ||
4497 (module->name == NULL))) {
4498 if ((module->name == NULL) && (module->parent != NULL)) {
4499 fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
4501 fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
4505 arg.module = module;
4506 arg.pf = gui_pref_arg->pf;
4507 g_list_foreach(arg.module->prefs, write_pref, &arg);
4509 if(prefs_module_has_submodules(module))
4510 return prefs_modules_foreach_submodules(module, write_module_prefs, user_data);
4515 /* Write out "prefs" to the user's preferences file, and return 0.
4517 If the preferences file path is NULL, write to stdout.
4519 If we got an error, stuff a pointer to the path of the preferences file
4520 into "*pf_path_return", and return the errno. */
4522 write_prefs(char **pf_path_return)
4526 write_gui_pref_arg_t write_gui_pref_info;
4528 /* Needed for "-G defaultprefs" */
4532 * - Split output lines longer than MAX_VAL_LEN
4533 * - Create a function for the preference directory check/creation
4534 * so that duplication can be avoided with filter.c
4537 if (pf_path_return != NULL) {
4538 pf_path = get_persconffile_path(PF_NAME, TRUE);
4539 if ((pf = ws_fopen(pf_path, "w")) == NULL) {
4540 *pf_path_return = pf_path;
4547 fputs("# Configuration file for Wireshark " VERSION ".\n"
4549 "# This file is regenerated each time preferences are saved within\n"
4550 "# Wireshark. Making manual changes should be safe, however.\n"
4551 "# Preferences that have been commented out have not been\n"
4552 "# changed from their default value.\n", pf);
4555 * For "backwards compatibility" the GUI module is written first as it's
4556 * at the top of the file. This is followed by all modules that can't
4557 * fit into the preferences read/write API. Finally the remaining modules
4558 * are written in alphabetical order (including of course the protocol preferences)
4560 write_gui_pref_info.pf = pf;
4561 write_gui_pref_info.is_gui_module = TRUE;
4563 write_module_prefs(gui_module, &write_gui_pref_info);
4566 struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
4569 fprintf(pf, "\n####### Filter Expressions ########\n");
4571 while (fe != NULL) {
4572 if (fe->deleted == FALSE) {
4573 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
4574 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
4575 fe->enabled == TRUE ? "TRUE" : "FALSE");
4576 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
4582 write_gui_pref_info.is_gui_module = FALSE;
4583 prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
4587 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
4588 an error indication, or maybe write to a new preferences file and
4589 rename that file on top of the old one only if there are not I/O
4594 /** The col_list is only partly managed by the custom preference API
4595 * because its data is shared between multiple preferences, so
4599 free_col_info(GList * list)
4603 while (list != NULL) {
4604 cfmt = (fmt_data *)list->data;
4606 g_free(cfmt->title);
4607 g_free(cfmt->custom_field);
4609 list = g_list_remove_link(list, list);
4621 * indent-tabs-mode: nil
4624 * ex: set shiftwidth=4 tabstop=8 expandtab:
4625 * :indentSize=4:tabSize=8:noTabs=true: