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)
2647 prefs_register_modules();
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 /* These string prefs will be strduped shortly, so we can safely cast away
2686 * their constness in these assignments */
2688 prefs.gui_gtk2_font_name = (char *) "Lucida Console 10";
2690 prefs.gui_gtk2_font_name = (char *) "Monospace 10";
2692 /* We try to find the best font in the Qt code */
2693 prefs.gui_qt_font_name = (char *) "";
2694 prefs.gui_marked_fg.pixel = 65535;
2695 prefs.gui_marked_fg.red = 65535;
2696 prefs.gui_marked_fg.green = 65535;
2697 prefs.gui_marked_fg.blue = 65535;
2698 prefs.gui_marked_bg.pixel = 0;
2699 prefs.gui_marked_bg.red = 0;
2700 prefs.gui_marked_bg.green = 8224;
2701 prefs.gui_marked_bg.blue = 10794;
2702 prefs.gui_ignored_fg.pixel = 32767;
2703 prefs.gui_ignored_fg.red = 32767;
2704 prefs.gui_ignored_fg.green = 32767;
2705 prefs.gui_ignored_fg.blue = 32767;
2706 prefs.gui_ignored_bg.pixel = 65535;
2707 prefs.gui_ignored_bg.red = 65535;
2708 prefs.gui_ignored_bg.green = 65535;
2709 prefs.gui_ignored_bg.blue = 65535;
2710 prefs.gui_colorized_fg = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
2711 prefs.gui_colorized_bg = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
2712 prefs.st_client_fg.pixel = 0;
2713 prefs.st_client_fg.red = 32767;
2714 prefs.st_client_fg.green = 0;
2715 prefs.st_client_fg.blue = 0;
2716 prefs.st_client_bg.pixel = 0;
2717 prefs.st_client_bg.red = 64507;
2718 prefs.st_client_bg.green = 60909;
2719 prefs.st_client_bg.blue = 60909;
2720 prefs.st_server_fg.pixel = 0;
2721 prefs.st_server_fg.red = 0;
2722 prefs.st_server_fg.green = 0;
2723 prefs.st_server_fg.blue = 32767;
2724 prefs.st_server_bg.pixel = 0;
2725 prefs.st_server_bg.red = 60909;
2726 prefs.st_server_bg.green = 60909;
2727 prefs.st_server_bg.blue = 64507;
2728 prefs.gui_text_valid.pixel = 0; /* light green */
2729 prefs.gui_text_valid.red = 0xAFFF;
2730 prefs.gui_text_valid.green = 0xFFFF;
2731 prefs.gui_text_valid.blue = 0xAFFF;
2732 prefs.gui_text_invalid.pixel = 0; /* light red */
2733 prefs.gui_text_invalid.red = 0xFFFF;
2734 prefs.gui_text_invalid.green = 0xAFFF;
2735 prefs.gui_text_invalid.blue = 0xAFFF;
2736 prefs.gui_text_deprecated.pixel = 0; /* light yellow */
2737 prefs.gui_text_deprecated.red = 0xFFFF;
2738 prefs.gui_text_deprecated.green = 0xFFFF;
2739 prefs.gui_text_deprecated.blue = 0xAFFF;
2740 prefs.gui_geometry_save_position = TRUE;
2741 prefs.gui_geometry_save_size = TRUE;
2742 prefs.gui_geometry_save_maximized= TRUE;
2743 prefs.gui_macosx_style = TRUE;
2744 prefs.gui_console_open = console_open_never;
2745 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
2746 prefs.gui_recent_df_entries_max = 10;
2747 prefs.gui_recent_files_count_max = 10;
2748 prefs.gui_fileopen_dir = (char *) get_persdatafile_dir();
2749 prefs.gui_fileopen_preview = 3;
2750 prefs.gui_ask_unsaved = TRUE;
2751 prefs.gui_find_wrap = TRUE;
2752 prefs.gui_use_pref_save = FALSE;
2753 prefs.gui_update_enabled = TRUE;
2754 prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
2755 prefs.gui_update_interval = 60*60*24; /* Seconds */
2756 prefs.gui_webbrowser = (char *) HTML_VIEWER " %s";
2757 prefs.gui_window_title = (char *) "";
2758 prefs.gui_start_title = "The World's Most Popular Network Protocol Analyzer";
2759 prefs.gui_version_placement = version_both;
2760 prefs.gui_auto_scroll_on_expand = FALSE;
2761 prefs.gui_auto_scroll_percentage = 0;
2762 prefs.gui_layout_type = layout_type_5;
2763 prefs.gui_layout_content_1 = layout_pane_content_plist;
2764 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
2765 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
2767 prefs.col_list = NULL;
2768 for (i = 0; i < DEF_NUM_COLS; i++) {
2769 cfmt = g_new(fmt_data,1);
2770 cfmt->title = g_strdup(col_fmt[i * 2]);
2771 parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
2772 cfmt->visible = TRUE;
2773 cfmt->resolved = TRUE;
2774 cfmt->custom_field = NULL;
2775 cfmt->custom_occurrence = 0;
2776 prefs.col_list = g_list_append(prefs.col_list, cfmt);
2778 prefs.num_cols = DEF_NUM_COLS;
2780 /* set the default values for the capture dialog box */
2781 prefs.capture_prom_mode = TRUE;
2782 #ifdef PCAP_NG_DEFAULT
2783 prefs.capture_pcap_ng = TRUE;
2785 prefs.capture_pcap_ng = FALSE;
2787 prefs.capture_real_time = TRUE;
2788 prefs.capture_auto_scroll = TRUE;
2789 prefs.capture_show_info = FALSE;
2791 prefs.capture_columns = NULL;
2792 for (i = 0; i < num_capture_cols; i++) {
2793 col_name = g_strdup(capture_cols[i]);
2794 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
2797 prefs.console_log_level =
2798 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
2800 /* set the default values for the tap/statistics dialog box */
2801 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
2802 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
2804 prefs.display_hidden_proto_items = FALSE;
2806 prefs_pre_initialized = TRUE;
2810 * Reset a single dissector preference.
2813 reset_pref(pref_t *pref)
2817 switch (pref->type) {
2820 *pref->varp.uint = pref->default_val.uint;
2824 *pref->varp.boolp = pref->default_val.boolval;
2829 * For now, we save the "description" value, so that if we
2830 * save the preferences older versions of Wireshark can at
2831 * least read preferences that they supported; we support
2832 * either the short name or the description when reading
2833 * the preferences file or a "-o" option.
2835 *pref->varp.enump = pref->default_val.enumval;
2841 g_free((void *)*pref->varp.string);
2842 *pref->varp.string = g_strdup(pref->default_val.string);
2846 g_free(*pref->varp.range);
2847 *pref->varp.range = range_copy(pref->default_val.range);
2850 case PREF_STATIC_TEXT:
2856 *pref->varp.colorp = pref->default_val.color;
2860 pref->custom_cbs.reset_cb(pref);
2865 * This preference is no longer supported; it's not a
2866 * real preference, so we don't reset it (i.e., we
2867 * treat it as if it weren't found in the list of
2868 * preferences, and we weren't called in the first place).
2875 reset_pref_cb(gpointer data, gpointer user_data _U_)
2877 pref_t *pref = (pref_t *) data;
2886 * Reset all preferences for a module.
2889 reset_module_prefs(void *value, void *data _U_)
2891 reset_pref_arg_t arg;
2893 arg.module = (module_t *)value;
2894 g_list_foreach(arg.module->prefs, reset_pref_cb, &arg);
2898 /* Reset preferences */
2902 prefs_initialized = FALSE;
2903 g_free(prefs.saved_at_version);
2905 * Unload all UAT preferences.
2910 * Unload any loaded MIBs.
2915 * Reset the non-dissector preferences.
2920 * Reset the non-UAT dissector preferences.
2922 pe_tree_foreach(prefs_modules, reset_module_prefs, NULL);
2925 /* Read the preferences file, fill in "prefs", and return a pointer to it.
2927 If we got an error (other than "it doesn't exist") trying to read
2928 the global preferences file, stuff the errno into "*gpf_errno_return"
2929 and a pointer to the path of the file into "*gpf_path_return", and
2932 If we got an error (other than "it doesn't exist") trying to read
2933 the user's preferences file, stuff the errno into "*pf_errno_return"
2934 and a pointer to the path of the file into "*pf_path_return", and
2937 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
2938 char **gpf_path_return, int *pf_errno_return,
2939 int *pf_read_errno_return, char **pf_path_return)
2945 /* clean up libsmi structures before reading prefs */
2951 * If we don't already have the pathname of the global preferences
2952 * file, construct it. Then, in either case, try to open the file.
2954 if (gpf_path == NULL) {
2956 * We don't have the path; try the new path first, and, if that
2957 * file doesn't exist, try the old path.
2959 gpf_path = get_datafile_path(PF_NAME);
2960 if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
2962 * It doesn't exist by the new name; try the old name.
2965 gpf_path = get_datafile_path(OLD_GPF_NAME);
2966 pf = ws_fopen(gpf_path, "r");
2970 * We have the path; try it.
2972 pf = ws_fopen(gpf_path, "r");
2976 * If we were able to open the file, read it.
2977 * XXX - if it failed for a reason other than "it doesn't exist",
2980 *gpf_path_return = NULL;
2983 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
2986 mgcp_tcp_port_count = 0;
2987 mgcp_udp_port_count = 0;
2989 /* We succeeded in opening it; read it. */
2990 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
2992 /* We had an error reading the file; return the errno and the
2993 pathname, so our caller can report the error. */
2994 *gpf_errno_return = 0;
2995 *gpf_read_errno_return = err;
2996 *gpf_path_return = gpf_path;
3000 /* We failed to open it. If we failed for some reason other than
3001 "it doesn't exist", return the errno and the pathname, so our
3002 caller can report the error. */
3003 if (errno != ENOENT) {
3004 *gpf_errno_return = errno;
3005 *gpf_read_errno_return = 0;
3006 *gpf_path_return = gpf_path;
3010 /* Construct the pathname of the user's preferences file. */
3011 pf_path = get_persconffile_path(PF_NAME, TRUE);
3013 /* Read the user's preferences file, if it exists. */
3014 *pf_path_return = NULL;
3015 if ((pf = ws_fopen(pf_path, "r")) != NULL) {
3017 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3020 mgcp_tcp_port_count = 0;
3021 mgcp_udp_port_count = 0;
3023 /* We succeeded in opening it; read it. */
3024 err = read_prefs_file(pf_path, pf, set_pref, NULL);
3026 /* We had an error reading the file; return the errno and the
3027 pathname, so our caller can report the error. */
3028 *pf_errno_return = 0;
3029 *pf_read_errno_return = err;
3030 *pf_path_return = pf_path;
3035 /* We failed to open it. If we failed for some reason other than
3036 "it doesn't exist", return the errno and the pathname, so our
3037 caller can report the error. */
3038 if (errno != ENOENT) {
3039 *pf_errno_return = errno;
3040 *pf_read_errno_return = 0;
3041 *pf_path_return = pf_path;
3046 /* load SMI modules if needed */
3052 /* read the preferences file (or similiar) and call the callback
3053 * function to set each key/value pair found */
3055 read_prefs_file(const char *pf_path, FILE *pf,
3056 pref_set_pair_cb pref_set_pair_fct, void *private_data)
3058 enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
3059 int got_c, state = START;
3062 gboolean got_val = FALSE;
3063 gint fline = 1, pline = 1;
3064 gchar hint[] = "(save preferences to remove this warning)";
3066 cur_val = g_string_new("");
3067 cur_var = g_string_new("");
3069 /* Try to read in the profile name in the first line of the preferences file. */
3072 GString *firstl = (GString *)pf;
3074 if (strncmp(firstl->str, " Configuration file for ", 24) == 0) {
3079 eol = strchr((char *) firstl->str, '\n');
3080 len = eol - firstl->str - 1;
3081 prefs.saved_at_version = g_strndup((const gchar *)firstl->str, len);
3086 while ((got_c = getc(pf)) != EOF) {
3087 if (got_c == '\n') {
3095 if (isalnum(got_c)) {
3096 if (cur_var->len > 0) {
3098 if (cur_val->len > 0) {
3099 if (cur_val->str[cur_val->len-1] == ',') {
3101 * If the pref has a trailing comma, eliminate it.
3103 cur_val->str[cur_val->len-1] = '\0';
3104 g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
3107 /* Call the routine to set the preference; it will parse
3108 the value as appropriate. */
3109 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3114 case PREFS_SET_SYNTAX_ERR:
3115 g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
3116 cur_var->str, pline, pf_path, hint);
3119 case PREFS_SET_NO_SUCH_PREF:
3121 * If "print.command" silently ignore it because it's valid
3122 * on non-Win32 platforms.
3124 if (strcmp(cur_var->str, "print.command") != 0)
3125 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3126 cur_var->str, pline, pf_path, hint);
3127 prefs.unknown_prefs = TRUE;
3130 case PREFS_SET_OBSOLETE:
3131 if (strcmp(cur_var->str, "print.command") != 0)
3132 /* If an attempt is made to save the preferences, a popup warning will be
3133 displayed stating that obsolete prefs have been detected and the user will
3134 be given the opportunity to save these prefs under a different profile name.
3135 The prefs in question need to be listed in the console window so that the
3136 user can make an informed choice.
3138 g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
3139 cur_var->str, pline, pf_path, hint);
3140 prefs.unknown_prefs = TRUE;
3144 g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
3149 g_string_truncate(cur_var, 0);
3150 g_string_append_c(cur_var, (gchar) got_c);
3152 } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
3154 } else if (got_c == '#') {
3157 g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
3162 g_string_append_c(cur_var, (gchar) got_c);
3164 /* This is a colon (':') */
3166 g_string_truncate(cur_val, 0);
3168 * Set got_val to TRUE to accommodate prefs such as
3169 * "gui.fileopen.dir" that do not require a value.
3175 if (!isspace(got_c)) {
3177 g_string_append_c(cur_val, (gchar) got_c);
3181 g_string_append_c(cur_val, (gchar) got_c);
3185 if (cur_var->len > 0) {
3187 /* Convert the string to a range. Since we're reading the
3188 * preferences file, silently lower values in excess of the
3191 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3196 case PREFS_SET_SYNTAX_ERR:
3197 g_warning ("Syntax error in preference %s at line %d of\n%s %s",
3198 cur_var->str, pline, pf_path, hint);
3201 case PREFS_SET_NO_SUCH_PREF:
3202 g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3203 cur_var->str, pline, pf_path, hint);
3204 prefs.unknown_prefs = TRUE;
3207 case PREFS_SET_OBSOLETE:
3208 prefs.unknown_prefs = TRUE;
3212 g_warning ("Incomplete preference at line %d of\n%s %s",
3213 pline, pf_path, hint);
3217 g_string_free(cur_val, TRUE);
3218 g_string_free(cur_var, TRUE);
3227 * If we were handed a preference starting with "uat:", try to turn it into
3228 * a valid uat entry.
3231 prefs_set_uat_pref(char *uat_entry) {
3236 colonp = strchr(uat_entry, ':');
3244 * Skip over any white space (there probably won't be any, but
3245 * as we allow it in the preferences file, we might as well
3248 while (isspace((guchar)*p))
3252 * Put the colon back, so if our caller uses, in an
3253 * error message, the string they passed us, the message
3260 uat = uat_find(uat_entry);
3266 if (uat_load_str(uat, p, &err)) {
3273 * Given a string of the form "<pref name>:<pref value>", as might appear
3274 * as an argument to a "-o" option, parse it and set the preference in
3275 * question. Return an indication of whether it succeeded or failed
3279 prefs_set_pref(char *prefarg)
3282 prefs_set_pref_e ret;
3285 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
3286 * seen to values that keep us from trying to interpret tham
3287 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
3288 * as, from the command line, we have no way of guessing which
3289 * the user had in mind.
3291 mgcp_tcp_port_count = -1;
3292 mgcp_udp_port_count = -1;
3294 colonp = strchr(prefarg, ':');
3296 return PREFS_SET_SYNTAX_ERR;
3302 * Skip over any white space (there probably won't be any, but
3303 * as we allow it in the preferences file, we might as well
3306 while (isspace((guchar)*p))
3310 * Put the colon back, so if our caller uses, in an
3311 * error message, the string they passed us, the message
3315 return PREFS_SET_SYNTAX_ERR;
3317 if (strcmp(prefarg, "uat")) {
3318 ret = set_pref(prefarg, p, NULL, TRUE);
3320 ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
3322 *colonp = ':'; /* put the colon back */
3327 * Returns TRUE if the given device is hidden
3330 prefs_is_capture_device_hidden(const char *name)
3332 gchar *tok, *devices;
3335 if (prefs.capture_devices_hide && name) {
3336 devices = g_strdup (prefs.capture_devices_hide);
3337 len = strlen (name);
3338 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3339 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3351 * Returns TRUE if the given column is visible (not hidden)
3354 prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
3357 fmt_data cfmt_hidden;
3360 * Do we have a list of hidden columns?
3364 * Yes - check the column against each of the ones in the
3367 cols = g_strdup(cols_hidden);
3368 for (tok = strtok(cols, ","); tok; tok = strtok(NULL, ",")) {
3369 tok = g_strstrip(tok);
3372 * Parse this column format.
3374 if (!parse_column_format(&cfmt_hidden, tok)) {
3376 * It's not valid; ignore it.
3382 * Does it match the column?
3384 if (cfmt->fmt != cfmt_hidden.fmt) {
3386 g_free(cfmt_hidden.custom_field);
3389 if (cfmt->fmt == COL_CUSTOM) {
3391 * A custom column has to have the
3392 * same custom field and occurrence.
3394 if (strcmp(cfmt->custom_field,
3395 cfmt_hidden.custom_field) != 0) {
3396 /* Different fields. */
3397 g_free(cfmt_hidden.custom_field);
3400 if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
3401 /* Different occurrences. */
3402 g_free(cfmt_hidden.custom_field);
3408 * OK, they match, so it's one of the hidden fields,
3409 * hence not visible.
3411 g_free(cfmt_hidden.custom_field);
3419 * No - either there are no hidden columns or this isn't one
3420 * of them - so it is visible.
3426 * Returns TRUE if the given device should capture in monitor mode by default
3429 prefs_capture_device_monitor_mode(const char *name)
3431 gchar *tok, *devices;
3434 if (prefs.capture_devices_monitor_mode && name) {
3435 devices = g_strdup (prefs.capture_devices_monitor_mode);
3436 len = strlen (name);
3437 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3438 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3450 * Returns TRUE if the user has marked this column as visible
3453 prefs_capture_options_dialog_column_is_visible(const gchar *column)
3458 for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
3459 col = (gchar *)curr->data;
3460 if (col && (g_ascii_strcasecmp(col, column) == 0)) {
3467 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
3468 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
3469 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
3471 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
3472 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
3473 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
3476 string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
3480 memset(name_resolve, 0, sizeof(e_addr_resolve));
3481 while ((c = *string++) != '\0') {
3484 name_resolve->mac_name = TRUE;
3487 name_resolve->network_name = TRUE;
3490 name_resolve->use_external_net_name_resolver = TRUE;
3493 name_resolve->transport_name = TRUE;
3496 name_resolve->concurrent_dns = TRUE;
3500 * Unrecognized letter.
3510 try_convert_to_custom_column(gpointer *el_data)
3512 /* Array of columns that have been migrated to custom columns */
3515 const gchar *col_expr;
3516 } migrated_columns[] = {
3517 { COL_COS_VALUE, "vlan.priority" },
3518 { COL_CIRCUIT_ID, "iax2.call" },
3519 { COL_BSSGP_TLLI, "bssgp.tlli" },
3520 { COL_HPUX_SUBSYS, "nettl.subsys" },
3521 { COL_HPUX_DEVID, "nettl.devid" },
3522 { COL_FR_DLCI, "fr.dlci" },
3523 { COL_REL_CONV_TIME, "tcp.time_relative" },
3524 { COL_DELTA_CONV_TIME, "tcp.time_delta" },
3525 { COL_OXID, "fc.ox_id" },
3526 { COL_RXID, "fc.rx_id" },
3527 { COL_SRCIDX, "mdshdr.srcidx" },
3528 { COL_DSTIDX, "mdshdr.dstidx" },
3529 { COL_DCE_CTX, "dcerpc.cn_ctx_id" }
3533 const gchar *haystack_fmt;
3535 gchar **fmt = (gchar **) el_data;
3537 for (haystack_idx = 0;
3538 haystack_idx < G_N_ELEMENTS(migrated_columns);
3541 haystack_fmt = col_format_to_string(migrated_columns[haystack_idx].el);
3542 if (strcmp(haystack_fmt, *fmt) == 0) {
3543 gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
3544 migrated_columns[haystack_idx].col_expr);
3552 static prefs_set_pref_e
3553 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
3554 gboolean return_range_errors)
3556 unsigned long int cval;
3561 gchar *dotp, *last_dotp;
3562 static gchar *filter_label = NULL;
3563 static gboolean filter_enabled = FALSE;
3564 gchar *filter_expr = NULL;
3569 if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
3570 filter_label = g_strdup(value);
3571 } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
3572 filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
3573 } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
3574 filter_expr = g_strdup(value);
3575 filter_expression_new(filter_label, filter_expr, filter_enabled);
3576 g_free(filter_label);
3577 g_free(filter_expr);
3578 } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
3579 /* Convert deprecated value to closest current equivalent */
3580 if (g_ascii_strcasecmp(value, "true") == 0) {
3581 prefs.gui_version_placement = version_both;
3583 prefs.gui_version_placement = version_neither;
3585 } else if (strcmp(pref_name, "name_resolve") == 0 ||
3586 strcmp(pref_name, "capture.name_resolve") == 0) {
3588 * Handle the deprecated name resolution options.
3590 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
3591 * RESOLV_ALL and RESOLV_NONE.
3593 * Otherwise, we treat it as a list of name types we want to resolve.
3595 if (g_ascii_strcasecmp(value, "true") == 0) {
3596 gbl_resolv_flags.mac_name = TRUE;
3597 gbl_resolv_flags.network_name = TRUE;
3598 gbl_resolv_flags.transport_name = TRUE;
3599 gbl_resolv_flags.concurrent_dns = TRUE;
3601 else if (g_ascii_strcasecmp(value, "false") == 0) {
3602 gbl_resolv_flags.mac_name = FALSE;
3603 gbl_resolv_flags.network_name = FALSE;
3604 gbl_resolv_flags.transport_name = FALSE;
3605 gbl_resolv_flags.concurrent_dns = FALSE;
3608 /* start out with none set */
3609 gbl_resolv_flags.mac_name = FALSE;
3610 gbl_resolv_flags.network_name = FALSE;
3611 gbl_resolv_flags.transport_name = FALSE;
3612 gbl_resolv_flags.concurrent_dns = FALSE;
3613 if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
3614 return PREFS_SET_SYNTAX_ERR;
3617 /* Handle deprecated "global" options that don't have a module
3618 * associated with them
3620 if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
3621 (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
3622 (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
3623 module = nameres_module;
3626 /* To which module does this preference belong? */
3628 last_dotp = pref_name;
3631 dotp = strchr(last_dotp, '.');
3634 /* no such module */
3635 return PREFS_SET_NO_SUCH_PREF;
3638 /* no ".", so no module/name separator */
3639 return PREFS_SET_SYNTAX_ERR;
3645 *dotp = '\0'; /* separate module and preference name */
3646 module = prefs_find_module(pref_name);
3649 * XXX - "Diameter" rather than "diameter" was used in earlier
3650 * versions of Wireshark; if we didn't find the module, and its name
3651 * was "Diameter", look for "diameter" instead.
3653 * In addition, the BEEP protocol used to be the BXXP protocol,
3654 * so if we didn't find the module, and its name was "bxxp",
3655 * look for "beep" instead.
3657 * Also, the preferences for GTP v0 and v1 were combined under
3658 * a single "gtp" heading, and the preferences for SMPP were
3659 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
3660 * However, SMPP now has its own preferences, so we just map
3661 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
3663 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
3664 * and "nsip" to "gprs_ns".
3666 * The SynOptics Network Management Protocol (SONMP) is now known by
3667 * its modern name, the Nortel Discovery Protocol (NDP).
3669 if (module == NULL) {
3670 if (strcmp(pref_name, "column") == 0)
3671 module = gui_column_module;
3672 else if (strcmp(pref_name, "Diameter") == 0)
3673 module = prefs_find_module("diameter");
3674 else if (strcmp(pref_name, "bxxp") == 0)
3675 module = prefs_find_module("beep");
3676 else if (strcmp(pref_name, "gtpv0") == 0 ||
3677 strcmp(pref_name, "gtpv1") == 0)
3678 module = prefs_find_module("gtp");
3679 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
3680 module = prefs_find_module("gsm-sms-ud");
3681 else if (strcmp(pref_name, "dcp") == 0)
3682 module = prefs_find_module("dccp");
3683 else if (strcmp(pref_name, "x.25") == 0)
3684 module = prefs_find_module("x25");
3685 else if (strcmp(pref_name, "x411") == 0)
3686 module = prefs_find_module("p1");
3687 else if (strcmp(pref_name, "nsip") == 0)
3688 module = prefs_find_module("gprs-ns");
3689 else if (strcmp(pref_name, "sonmp") == 0)
3690 module = prefs_find_module("ndp");
3691 else if (strcmp(pref_name, "etheric") == 0 ||
3692 strcmp(pref_name, "isup_thin") == 0) {
3693 /* This protocol was removed 7. July 2009 */
3694 return PREFS_SET_OBSOLETE;
3697 g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
3698 "Save your preferences to make this change permanent.",
3699 pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
3700 prefs.unknown_prefs = TRUE;
3703 *dotp = '.'; /* put the preference string back */
3704 dotp++; /* skip past separator to preference name */
3709 pref = prefs_find_preference(module, dotp);
3712 prefs.unknown_prefs = TRUE;
3714 /* "gui" prefix was added to column preferences for better organization
3715 * within the preferences file
3717 if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
3718 (strcmp(pref_name, PRS_COL_FMT) == 0)) {
3719 pref = prefs_find_preference(module, pref_name);
3721 else if (strcmp(module->name, "mgcp") == 0) {
3723 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
3724 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
3725 * were used in earlier versions of Wireshark; if we didn't find the
3726 * preference, it was an MGCP preference, and its name was
3727 * "display raw text toggle" or "display dissect tree", look for
3728 * "display_raw_text" or "display_dissect_tree" instead.
3730 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
3731 * the gateway and callagent ports were given those names; we interpret
3732 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
3733 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
3734 * they were registered by the MCCP dissector and thus that's the
3735 * order in which they were written to the preferences file. (If
3736 * we're not reading the preferences file, but are handling stuff
3737 * from a "-o" command-line option, we have no clue which the user
3738 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
3739 * or "mgcp.{tcp,udp}.callagent_port" instead.)
3741 if (strcmp(dotp, "display raw text toggle") == 0)
3742 pref = prefs_find_preference(module, "display_raw_text");
3743 else if (strcmp(dotp, "display dissect tree") == 0)
3744 pref = prefs_find_preference(module, "display_dissect_tree");
3745 else if (strcmp(dotp, "tcp.port") == 0) {
3746 mgcp_tcp_port_count++;
3747 if (mgcp_tcp_port_count == 1) {
3748 /* It's the first one */
3749 pref = prefs_find_preference(module, "tcp.gateway_port");
3750 } else if (mgcp_tcp_port_count == 2) {
3751 /* It's the second one */
3752 pref = prefs_find_preference(module, "tcp.callagent_port");
3754 /* Otherwise it's from the command line, and we don't bother
3756 } else if (strcmp(dotp, "udp.port") == 0) {
3757 mgcp_udp_port_count++;
3758 if (mgcp_udp_port_count == 1) {
3759 /* It's the first one */
3760 pref = prefs_find_preference(module, "udp.gateway_port");
3761 } else if (mgcp_udp_port_count == 2) {
3762 /* It's the second one */
3763 pref = prefs_find_preference(module, "udp.callagent_port");
3765 /* Otherwise it's from the command line, and we don't bother
3768 } else if (strcmp(module->name, "smb") == 0) {
3769 /* Handle old names for SMB preferences. */
3770 if (strcmp(dotp, "smb.trans.reassembly") == 0)
3771 pref = prefs_find_preference(module, "trans_reassembly");
3772 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
3773 pref = prefs_find_preference(module, "dcerpc_reassembly");
3774 } else if (strcmp(module->name, "ndmp") == 0) {
3775 /* Handle old names for NDMP preferences. */
3776 if (strcmp(dotp, "ndmp.desegment") == 0)
3777 pref = prefs_find_preference(module, "desegment");
3778 } else if (strcmp(module->name, "diameter") == 0) {
3779 /* Handle old names for Diameter preferences. */
3780 if (strcmp(dotp, "diameter.desegment") == 0)
3781 pref = prefs_find_preference(module, "desegment");
3782 } else if (strcmp(module->name, "pcli") == 0) {
3783 /* Handle old names for PCLI preferences. */
3784 if (strcmp(dotp, "pcli.udp_port") == 0)
3785 pref = prefs_find_preference(module, "udp_port");
3786 } else if (strcmp(module->name, "artnet") == 0) {
3787 /* Handle old names for ARTNET preferences. */
3788 if (strcmp(dotp, "artnet.udp_port") == 0)
3789 pref = prefs_find_preference(module, "udp_port");
3790 } else if (strcmp(module->name, "mapi") == 0) {
3791 /* Handle old names for MAPI preferences. */
3792 if (strcmp(dotp, "mapi_decrypt") == 0)
3793 pref = prefs_find_preference(module, "decrypt");
3794 } else if (strcmp(module->name, "fc") == 0) {
3795 /* Handle old names for Fibre Channel preferences. */
3796 if (strcmp(dotp, "reassemble_fc") == 0)
3797 pref = prefs_find_preference(module, "reassemble");
3798 else if (strcmp(dotp, "fc_max_frame_size") == 0)
3799 pref = prefs_find_preference(module, "max_frame_size");
3800 } else if (strcmp(module->name, "fcip") == 0) {
3801 /* Handle old names for Fibre Channel-over-IP preferences. */
3802 if (strcmp(dotp, "desegment_fcip_messages") == 0)
3803 pref = prefs_find_preference(module, "desegment");
3804 else if (strcmp(dotp, "fcip_port") == 0)
3805 pref = prefs_find_preference(module, "target_port");
3806 } else if (strcmp(module->name, "gtp") == 0) {
3807 /* Handle old names for GTP preferences. */
3808 if (strcmp(dotp, "gtpv0_port") == 0)
3809 pref = prefs_find_preference(module, "v0_port");
3810 else if (strcmp(dotp, "gtpv1c_port") == 0)
3811 pref = prefs_find_preference(module, "v1c_port");
3812 else if (strcmp(dotp, "gtpv1u_port") == 0)
3813 pref = prefs_find_preference(module, "v1u_port");
3814 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
3815 pref = prefs_find_preference(module, "dissect_tpdu");
3816 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
3817 pref = prefs_find_preference(module, "v0_dissect_cdr_as");
3818 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
3819 pref = prefs_find_preference(module, "v0_check_etsi");
3820 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
3821 pref = prefs_find_preference(module, "v1_check_etsi");
3822 } else if (strcmp(module->name, "ip") == 0) {
3823 /* Handle old names for IP preferences. */
3824 if (strcmp(dotp, "ip_summary_in_tree") == 0)
3825 pref = prefs_find_preference(module, "summary_in_tree");
3826 } else if (strcmp(module->name, "iscsi") == 0) {
3827 /* Handle old names for iSCSI preferences. */
3828 if (strcmp(dotp, "iscsi_port") == 0)
3829 pref = prefs_find_preference(module, "target_port");
3830 } else if (strcmp(module->name, "lmp") == 0) {
3831 /* Handle old names for LMP preferences. */
3832 if (strcmp(dotp, "lmp_version") == 0)
3833 pref = prefs_find_preference(module, "version");
3834 } else if (strcmp(module->name, "mtp3") == 0) {
3835 /* Handle old names for MTP3 preferences. */
3836 if (strcmp(dotp, "mtp3_standard") == 0)
3837 pref = prefs_find_preference(module, "standard");
3838 else if (strcmp(dotp, "net_addr_format") == 0)
3839 pref = prefs_find_preference(module, "addr_format");
3840 } else if (strcmp(module->name, "nlm") == 0) {
3841 /* Handle old names for NLM preferences. */
3842 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
3843 pref = prefs_find_preference(module, "msg_res_matching");
3844 } else if (strcmp(module->name, "ppp") == 0) {
3845 /* Handle old names for PPP preferences. */
3846 if (strcmp(dotp, "ppp_fcs") == 0)
3847 pref = prefs_find_preference(module, "fcs_type");
3848 else if (strcmp(dotp, "ppp_vj") == 0)
3849 pref = prefs_find_preference(module, "decompress_vj");
3850 } else if (strcmp(module->name, "rsvp") == 0) {
3851 /* Handle old names for RSVP preferences. */
3852 if (strcmp(dotp, "rsvp_process_bundle") == 0)
3853 pref = prefs_find_preference(module, "process_bundle");
3854 } else if (strcmp(module->name, "tcp") == 0) {
3855 /* Handle old names for TCP preferences. */
3856 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
3857 pref = prefs_find_preference(module, "summary_in_tree");
3858 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
3859 pref = prefs_find_preference(module, "analyze_sequence_numbers");
3860 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
3861 pref = prefs_find_preference(module, "relative_sequence_numbers");
3862 } else if (strcmp(module->name, "udp") == 0) {
3863 /* Handle old names for UDP preferences. */
3864 if (strcmp(dotp, "udp_summary_in_tree") == 0)
3865 pref = prefs_find_preference(module, "summary_in_tree");
3866 } else if (strcmp(module->name, "ndps") == 0) {
3867 /* Handle old names for NDPS preferences. */
3868 if (strcmp(dotp, "desegment_ndps") == 0)
3869 pref = prefs_find_preference(module, "desegment_tcp");
3870 } else if (strcmp(module->name, "http") == 0) {
3871 /* Handle old names for HTTP preferences. */
3872 if (strcmp(dotp, "desegment_http_headers") == 0)
3873 pref = prefs_find_preference(module, "desegment_headers");
3874 else if (strcmp(dotp, "desegment_http_body") == 0)
3875 pref = prefs_find_preference(module, "desegment_body");
3876 } else if (strcmp(module->name, "smpp") == 0) {
3877 /* Handle preferences that moved from SMPP. */
3878 module_t *new_module = prefs_find_module("gsm-sms-ud");
3880 if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
3881 pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
3882 else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
3883 pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
3885 } else if (strcmp(module->name, "asn1") == 0) {
3886 /* Handle old generic ASN.1 preferences (it's not really a
3887 rename, as the new preferences support multiple ports,
3888 but we might as well copy them over). */
3889 if (strcmp(dotp, "tcp_port") == 0)
3890 pref = prefs_find_preference(module, "tcp_ports");
3891 else if (strcmp(dotp, "udp_port") == 0)
3892 pref = prefs_find_preference(module, "udp_ports");
3893 else if (strcmp(dotp, "sctp_port") == 0)
3894 pref = prefs_find_preference(module, "sctp_ports");
3895 } else if (strcmp(module->name, "llcgprs") == 0) {
3896 if (strcmp(dotp, "ignore_cipher_bit") == 0)
3897 pref = prefs_find_preference(module, "autodetect_cipher_bit");
3898 } else if (strcmp(module->name, "erf") == 0) {
3899 if (strcmp(dotp, "erfeth") == 0) {
3900 /* Handle the old "erfeth" preference; map it to the new
3901 "ethfcs" preference, and map the values to those for
3902 the new preference. */
3903 pref = prefs_find_preference(module, "ethfcs");
3904 if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
3906 else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
3908 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3910 } else if (strcmp(dotp, "erfatm") == 0) {
3911 /* Handle the old "erfatm" preference; map it to the new
3912 "aal5_type" preference, and map the values to those for
3913 the new preference. */
3914 pref = prefs_find_preference(module, "aal5_type");
3915 if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
3917 else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
3919 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3921 } else if (strcmp(dotp, "erfhdlc") == 0) {
3922 /* Handle the old "erfhdlc" preference; map it to the new
3923 "hdlc_type" preference, and map the values to those for
3924 the new preference. */
3925 pref = prefs_find_preference(module, "hdlc_type");
3926 if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
3928 else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
3930 else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
3932 else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
3934 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
3937 } else if (strcmp(module->name, "eth") == 0) {
3938 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
3939 if (strcmp(dotp, "qinq_ethertype") == 0) {
3940 module_t *new_module = prefs_find_module("vlan");
3942 pref = prefs_find_preference(new_module, "qinq_ethertype");
3943 module = new_module;
3946 } else if (strcmp(module->name, "taps") == 0) {
3947 /* taps preferences moved to "statistics" module */
3948 if (strcmp(dotp, "update_interval") == 0 ||
3949 strcmp(dotp, "rtp_player_max_visible") == 0)
3950 pref = prefs_find_preference(stats_module, dotp);
3951 } else if (strcmp(module->name, "packet_list") == 0) {
3952 /* packet_list preferences moved to protocol module */
3953 if (strcmp(dotp, "display_hidden_proto_items") == 0)
3954 pref = prefs_find_preference(protocols_module, dotp);
3955 } else if (strcmp(module->name, "stream") == 0) {
3956 /* stream preferences moved to gui color module */
3957 if ((strcmp(dotp, "client.fg") == 0) ||
3958 (strcmp(dotp, "client.bg") == 0) ||
3959 (strcmp(dotp, "server.fg") == 0) ||
3960 (strcmp(dotp, "server.bg") == 0))
3961 pref = prefs_find_preference(gui_color_module, pref_name);
3962 } else if (strcmp(module->name, "nameres") == 0) {
3963 if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
3964 pref = prefs_find_preference(nameres_module, pref_name);
3965 } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
3966 pref = prefs_find_preference(nameres_module, "load_smi_modules");
3967 } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
3968 pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
3973 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
3975 switch (pref->type) {
3978 /* XXX - give an error if it doesn't fit in a guint? */
3979 uval = (guint)strtoul(value, &p, pref->info.base);
3980 if (p == value || *p != '\0')
3981 return PREFS_SET_SYNTAX_ERR; /* number was bad */
3982 if (*pref->varp.uint != uval) {
3983 module->prefs_changed = TRUE;
3984 *pref->varp.uint = uval;
3989 /* XXX - give an error if it's neither "true" nor "false"? */
3990 if (g_ascii_strcasecmp(value, "true") == 0)
3994 if (*pref->varp.boolp != bval) {
3995 module->prefs_changed = TRUE;
3996 *pref->varp.boolp = bval;
4001 /* XXX - give an error if it doesn't match? */
4002 enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
4004 if (*pref->varp.enump != enum_val) {
4005 module->prefs_changed = TRUE;
4006 *pref->varp.enump = enum_val;
4013 if (strcmp(*pref->varp.string, value) != 0) {
4014 module->prefs_changed = TRUE;
4015 g_free((void *)*pref->varp.string);
4016 *pref->varp.string = g_strdup(value);
4024 if (range_convert_str_work(&newrange, value, pref->info.max_value,
4025 return_range_errors) != CVT_NO_ERROR) {
4026 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4029 if (!ranges_are_equal(*pref->varp.range, newrange)) {
4030 module->prefs_changed = TRUE;
4031 g_free(*pref->varp.range);
4032 *pref->varp.range = newrange;
4041 cval = strtoul(value, NULL, 16);
4042 pref->varp.colorp->pixel = 0;
4043 if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
4044 (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
4045 (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
4046 module->prefs_changed = TRUE;
4047 pref->varp.colorp->red = RED_COMPONENT(cval);
4048 pref->varp.colorp->green = GREEN_COMPONENT(cval);
4049 pref->varp.colorp->blue = BLUE_COMPONENT(cval);
4055 return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
4057 case PREF_STATIC_TEXT:
4064 return PREFS_SET_OBSOLETE; /* no such preference any more */
4068 return PREFS_SET_OK;
4073 gboolean is_gui_module;
4074 } write_gui_pref_arg_t;
4077 prefs_pref_type_name(pref_t *pref)
4079 const char *type_name = "[Unknown]";
4082 return type_name; /* ...or maybe assert? */
4085 switch (pref->type) {
4088 switch (pref->info.base) {
4091 type_name = "Decimal";
4095 type_name = "Octal";
4099 type_name = "Hexadecimal";
4105 type_name = "Boolean";
4109 type_name = "Choice";
4113 type_name = "String";
4117 type_name = "Filename";
4121 type_name = "Directory";
4125 type_name = "Range";
4129 type_name = "Color";
4133 if (pref->custom_cbs.type_name_cb)
4134 return pref->custom_cbs.type_name_cb();
4135 type_name = "Custom";
4139 type_name = "Obsolete";
4142 case PREF_STATIC_TEXT:
4143 type_name = "Static text";
4154 prefs_pref_type_description(pref_t *pref)
4156 const char *type_desc = "An unkown preference type";
4159 return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
4162 switch (pref->type) {
4165 switch (pref->info.base) {
4168 type_desc = "A decimal number";
4172 type_desc = "An octal number";
4176 type_desc = "A hexadecimal number";
4182 type_desc = "TRUE or FALSE (case-insensitive)";
4187 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4188 GString *enum_str = g_string_new("One of: ");
4189 while (enum_valp->name != NULL) {
4190 g_string_append(enum_str, enum_valp->description);
4192 if (enum_valp->name != NULL)
4193 g_string_append(enum_str, ", ");
4195 g_string_append(enum_str, "\n(case-insensitive).");
4196 return g_string_free(enum_str, FALSE);
4201 type_desc = "A string";
4205 type_desc = "A path to a file";
4209 type_desc = "A path to a directory";
4214 type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
4220 type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
4225 if (pref->custom_cbs.type_description_cb)
4226 return pref->custom_cbs.type_description_cb();
4227 type_desc = "A custom value";
4231 type_desc = "An obsolete preference";
4234 case PREF_STATIC_TEXT:
4235 type_desc = "[Static text]";
4239 type_desc = "Configuration data stored in its own file";
4245 return g_strdup(type_desc);
4249 prefs_pref_is_default(pref_t *pref) {
4250 if (!pref) return FALSE;
4252 switch (pref->type) {
4255 if (pref->default_val.uint == *pref->varp.uint)
4260 if (pref->default_val.boolval == *pref->varp.boolp)
4265 if (pref->default_val.enumval == *pref->varp.enump)
4272 if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
4278 if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
4285 if ((pref->default_val.color.red == pref->varp.colorp->red) &&
4286 (pref->default_val.color.green == pref->varp.colorp->green) &&
4287 (pref->default_val.color.blue == pref->varp.colorp->blue))
4293 return pref->custom_cbs.is_default_cb(pref);
4296 case PREF_STATIC_TEXT:
4299 /* g_assert_not_reached(); */
4306 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
4307 const char *pref_text = "[Unknown]";
4309 gboolean pref_boolval;
4311 const char *pref_string;
4312 range_t *pref_range;
4313 color_t *pref_color;
4316 return g_strdup(pref_text);
4321 pref_uint = pref->default_val.uint;
4322 pref_boolval = pref->default_val.boolval;
4323 pref_enumval = pref->default_val.enumval;
4324 pref_string = pref->default_val.string;
4325 pref_range = pref->default_val.range;
4326 pref_color = &pref->default_val.color;
4329 pref_uint = pref->stashed_val.uint;
4330 pref_boolval = pref->stashed_val.boolval;
4331 pref_enumval = pref->stashed_val.enumval;
4332 pref_string = pref->stashed_val.string;
4333 pref_range = pref->stashed_val.range;
4334 pref_color = &pref->stashed_val.color;
4337 pref_uint = *pref->varp.uint;
4338 pref_boolval = *pref->varp.boolp;
4339 pref_enumval = *pref->varp.enump;
4340 pref_string = *pref->varp.string;
4341 pref_range = *pref->varp.range;
4342 pref_color = pref->varp.colorp;
4345 return g_strdup(pref_text);
4348 switch (pref->type) {
4351 switch (pref->info.base) {
4354 return g_strdup_printf("%u", pref_uint);
4358 return g_strdup_printf("%#o", pref_uint);
4362 return g_strdup_printf("%#x", pref_uint);
4368 return g_strdup_printf("%s", pref_boolval ? "TRUE" : "FALSE");
4374 * For now, we return the "description" value, so that if we
4375 * save the preferences older versions of Wireshark can at
4376 * least read preferences that they supported; we support
4377 * either the short name or the description when reading
4378 * the preferences file or a "-o" option.
4380 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
4381 while (enum_valp->name != NULL) {
4382 if (enum_valp->value == pref_enumval)
4383 return g_strdup(enum_valp->description);
4392 return g_strdup(pref_string);
4396 pref_text = range_convert_range(pref_range);
4400 return g_strdup_printf("%02x%02x%02x",
4401 (pref_color->red * 255 / 65535),
4402 (pref_color->green * 255 / 65535),
4403 (pref_color->blue * 255 / 65535));
4407 if (pref->custom_cbs.to_str_cb)
4408 return pref->custom_cbs.to_str_cb(pref, source == pref_default ? TRUE : FALSE);
4409 pref_text = "[Custom]";
4413 pref_text = "[Obsolete]";
4416 case PREF_STATIC_TEXT:
4417 pref_text = "[Static text]";
4422 uat_t *uat = (uat_t *) pref->varp.uat;
4423 if (uat && uat->filename)
4424 return g_strdup_printf("[Managed in the file \"%s\"]", uat->filename);
4426 pref_text = "[Managed in an unknown file]";
4433 return g_strdup(pref_text);
4437 * Write out a single dissector preference.
4440 write_pref(gpointer data, gpointer user_data)
4442 pref_t *pref = (pref_t *)data;
4443 write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
4447 switch (pref->type) {
4450 * This preference is no longer supported; it's not a
4451 * real preference, so we don't write it out (i.e., we
4452 * treat it as if it weren't found in the list of
4453 * preferences, and we weren't called in the first place).
4457 case PREF_STATIC_TEXT:
4459 /* Nothing to do; don't bother printing the description */
4465 if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL) {
4467 * The prefix will either be the module name or the parent
4468 * name if it's a subtree
4470 const char *name_prefix = (arg->module->name != NULL) ? arg->module->name : arg->module->parent->name;
4471 char *type_desc, *pref_text;
4472 const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
4474 if (pref->type == PREF_CUSTOM) fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
4475 fprintf(arg->pf, "\n");
4476 if (pref->description &&
4477 (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
4478 if (pref->type != PREF_CUSTOM) {
4479 /* We get duplicate lines otherwise. */
4481 desc_lines = g_strsplit(pref->description,"\n",0);
4482 for (i = 0; desc_lines[i] != NULL; ++i) {
4483 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4485 g_strfreev(desc_lines);
4488 fprintf(arg->pf, "# No description\n");
4491 type_desc = prefs_pref_type_description(pref);
4492 desc_lines = g_strsplit(type_desc,"\n",0);
4493 for (i = 0; desc_lines[i] != NULL; ++i) {
4494 fprintf(arg->pf, "# %s\n", desc_lines[i]);
4496 g_strfreev(desc_lines);
4499 pref_text = prefs_pref_to_str(pref, pref_current);
4500 fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
4501 desc_lines = g_strsplit(pref_text,"\n",0);
4502 for (i = 0; desc_lines[i] != NULL; ++i) {
4503 fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
4505 if (i == 0) fprintf(arg->pf, "\n");
4506 g_strfreev(desc_lines);
4513 * Write out all preferences for a module.
4516 write_module_prefs(module_t *module, gpointer user_data)
4518 write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
4519 write_pref_arg_t arg;
4521 /* The GUI module needs to be explicitly called out so it
4522 can be written out of order */
4523 if ((module == gui_module) && (gui_pref_arg->is_gui_module != TRUE))
4526 /* Write a header for the main modules and GUI sub-modules */
4527 if (((module->parent == NULL) || (module->parent == gui_module)) &&
4528 ((prefs_module_has_submodules(module)) ||
4529 (module->numprefs > 0) ||
4530 (module->name == NULL))) {
4531 if ((module->name == NULL) && (module->parent != NULL)) {
4532 fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
4534 fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
4538 arg.module = module;
4539 arg.pf = gui_pref_arg->pf;
4540 g_list_foreach(arg.module->prefs, write_pref, &arg);
4542 if(prefs_module_has_submodules(module))
4543 return prefs_modules_foreach_submodules(module, write_module_prefs, user_data);
4548 /* Write out "prefs" to the user's preferences file, and return 0.
4550 If the preferences file path is NULL, write to stdout.
4552 If we got an error, stuff a pointer to the path of the preferences file
4553 into "*pf_path_return", and return the errno. */
4555 write_prefs(char **pf_path_return)
4559 write_gui_pref_arg_t write_gui_pref_info;
4561 /* Needed for "-G defaultprefs" */
4565 * - Split output lines longer than MAX_VAL_LEN
4566 * - Create a function for the preference directory check/creation
4567 * so that duplication can be avoided with filter.c
4570 if (pf_path_return != NULL) {
4571 pf_path = get_persconffile_path(PF_NAME, TRUE);
4572 if ((pf = ws_fopen(pf_path, "w")) == NULL) {
4573 *pf_path_return = pf_path;
4580 fputs("# Configuration file for Wireshark " VERSION ".\n"
4582 "# This file is regenerated each time preferences are saved within\n"
4583 "# Wireshark. Making manual changes should be safe, however.\n"
4584 "# Preferences that have been commented out have not been\n"
4585 "# changed from their default value.\n", pf);
4588 * For "backwards compatibility" the GUI module is written first as it's
4589 * at the top of the file. This is followed by all modules that can't
4590 * fit into the preferences read/write API. Finally the remaining modules
4591 * are written in alphabetical order (including of course the protocol preferences)
4593 write_gui_pref_info.pf = pf;
4594 write_gui_pref_info.is_gui_module = TRUE;
4596 write_module_prefs(gui_module, &write_gui_pref_info);
4599 struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
4602 fprintf(pf, "\n####### Filter Expressions ########\n");
4604 while (fe != NULL) {
4605 if (fe->deleted == FALSE) {
4606 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
4607 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
4608 fe->enabled == TRUE ? "TRUE" : "FALSE");
4609 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
4615 write_gui_pref_info.is_gui_module = FALSE;
4616 prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
4620 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
4621 an error indication, or maybe write to a new preferences file and
4622 rename that file on top of the old one only if there are not I/O
4627 /** The col_list is only partly managed by the custom preference API
4628 * because its data is shared between multiple preferences, so
4632 free_col_info(GList * list)
4636 while (list != NULL) {
4637 cfmt = (fmt_data *)list->data;
4639 g_free(cfmt->title);
4640 g_free(cfmt->custom_field);
4642 list = g_list_remove_link(list, list);
4654 * indent-tabs-mode: nil
4657 * ex: set shiftwidth=4 tabstop=8 expandtab:
4658 * :indentSize=4:tabSize=8:noTabs=true: