2 * Routines for handling preferences
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <wsutil/filesystem.h>
33 #include <epan/address.h>
34 #include <epan/addr_resolv.h>
35 #include <epan/oids.h>
37 #include <epan/geoip_db.h>
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
41 #include <epan/proto.h>
42 #include <epan/strutil.h>
43 #include <epan/column.h>
44 #include <epan/decode_as.h>
46 #include <wsutil/file_util.h>
47 #include <wsutil/ws_printf.h> /* ws_g_warning */
49 #include <epan/prefs-int.h>
50 #include <epan/uat-int.h>
52 #include "epan/filter_expressions.h"
54 #include "epan/wmem/wmem.h"
55 #include <epan/stats_tree.h>
57 /* Internal functions */
58 static module_t *find_subtree(module_t *parent, const char *tilte);
59 static module_t *prefs_register_module_or_subtree(module_t *parent,
60 const char *name, const char *title, const char *description, gboolean is_subtree,
61 void (*apply_cb)(void), gboolean use_gui);
62 static void prefs_register_modules(void);
63 static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
64 static void free_col_info(GList *);
65 static void pre_init_prefs(void);
66 static gboolean prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt);
67 static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
68 static void try_convert_to_custom_column(gpointer *el_data);
70 #define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
71 #define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
72 #define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
74 #define PF_NAME "preferences"
75 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
77 static gboolean prefs_initialized = FALSE;
78 static gchar *gpf_path = NULL;
79 static gchar *cols_hidden_list = NULL;
82 * XXX - variables to allow us to attempt to interpret the first
83 * "mgcp.{tcp,udp}.port" in a preferences file as
84 * "mgcp.{tcp,udp}.gateway_port" and the second as
85 * "mgcp.{tcp,udp}.callagent_port".
87 static int mgcp_tcp_port_count;
88 static int mgcp_udp_port_count;
92 static const enum_val_t gui_ptree_line_style[] = {
94 {"SOLID", "SOLID", 1},
95 {"DOTTED", "DOTTED", 2},
96 {"TABBED", "TABBED", 3},
100 static const enum_val_t gui_ptree_expander_style[] = {
102 {"SQUARE", "SQUARE", 1},
103 {"TRIANGLE", "TRIANGLE", 2},
104 {"CIRCULAR", "CIRCULAR", 3},
108 static const enum_val_t gui_hex_dump_highlight_style[] = {
110 {"INVERSE", "INVERSE", 1},
114 static const enum_val_t gui_console_open_type[] = {
115 {"NEVER", "NEVER", console_open_never},
116 {"AUTOMATIC", "AUTOMATIC", console_open_auto},
117 {"ALWAYS", "ALWAYS", console_open_always},
121 static const enum_val_t gui_version_placement_type[] = {
122 {"WELCOME", "WELCOME", version_welcome_only},
123 {"TITLE", "TITLE", version_title_only},
124 {"BOTH", "BOTH", version_both},
125 {"NEITHER", "NEITHER", version_neither},
129 static const enum_val_t gui_fileopen_style[] = {
130 {"LAST_OPENED", "LAST_OPENED", 0},
131 {"SPECIFIED", "SPECIFIED", 1},
135 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
136 * as this may not work on other guis, we use only "both" in general here */
137 static const enum_val_t gui_toolbar_style[] = {
138 {"ICONS", "ICONS", 0},
144 static const enum_val_t gui_layout_content[] = {
146 {"PLIST", "PLIST", 1},
147 {"PDETAILS", "PDETAILS", 2},
148 {"PBYTES", "PBYTES", 3},
152 static const enum_val_t gui_update_channel[] = {
153 {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT},
154 {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE},
158 #if defined(HAVE_PCAP_CREATE)
159 /* Can set monitor mode and buffer size. */
160 static gint num_capture_cols = 7;
161 static const gchar *capture_cols[7] = {
170 #define CAPTURE_COL_TYPE_DESCRIPTION \
171 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
172 #elif defined(CAN_SET_CAPTURE_BUFFER_SIZE)
173 /* Can set buffer size but not monitor mode. */
174 static gint num_capture_cols = 6;
175 static const gchar *capture_cols[6] = {
183 #define CAPTURE_COL_TYPE_DESCRIPTION \
184 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, BUFFER, FILTER\n"
186 /* Can neither set buffer size nor monitor mode. */
187 static gint num_capture_cols = 5;
188 static const gchar *capture_cols[5] = {
195 #define CAPTURE_COL_TYPE_DESCRIPTION \
196 "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, FILTER\n"
199 static const enum_val_t gui_packet_list_elide_mode[] = {
200 {"LEFT", "LEFT", ELIDE_LEFT},
201 {"RIGHT", "RIGHT", ELIDE_RIGHT},
202 {"MIDDLE", "MIDDLE", ELIDE_MIDDLE},
203 {"NONE", "NONE", ELIDE_NONE},
208 * List of all modules with preference settings.
210 static wmem_tree_t *prefs_modules = NULL;
213 * List of all modules that should show up at the top level of the
214 * tree in the preference dialog box.
216 static wmem_tree_t *prefs_top_level_modules = NULL;
218 /** Sets up memory used by proto routines. Called at program startup */
222 memset(&prefs, 0, sizeof(prefs));
223 prefs_modules = wmem_tree_new(wmem_epan_scope());
224 prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
228 * Free the strings for a string-like preference.
231 free_string_like_preference(pref_t *pref)
233 g_free(*pref->varp.string);
234 *pref->varp.string = NULL;
235 g_free(pref->default_val.string);
236 pref->default_val.string = NULL;
240 free_pref(gpointer data, gpointer user_data _U_)
242 pref_t *pref = (pref_t *)data;
243 int type = pref->type;
245 /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
246 RESET_PREF_OBSOLETE(type);
252 case PREF_DECODE_AS_UINT:
253 case PREF_STATIC_TEXT:
260 g_free(*pref->varp.string);
261 *pref->varp.string = NULL;
262 g_free(pref->default_val.string);
263 pref->default_val.string = NULL;
266 case PREF_DECODE_AS_RANGE:
267 g_free(*pref->varp.range);
268 *pref->varp.range = NULL;
269 g_free(pref->default_val.range);
270 pref->default_val.range = NULL;
273 if (strcmp(pref->name, "columns") == 0)
274 pref->stashed_val.boolval = TRUE;
275 pref->custom_cbs.free_cb(pref);
283 free_module_prefs(module_t *module, gpointer data _U_)
286 g_list_foreach(module->prefs, free_pref, NULL);
287 g_list_free(module->prefs);
289 module->prefs = NULL;
290 module->numprefs = 0;
291 if (module->submodules) {
292 prefs_modules_foreach_submodules(module, free_module_prefs, NULL);
294 /* We don't free the actual module: its submodules pointer points to
295 a wmem_tree and the module itself is stored in a wmem_tree
301 /** Frees memory used by proto routines. Called at program shutdown */
305 /* This isn't strictly necessary since we're exiting anyway, but let's
306 * do what clean up we can.
308 prefs_modules_foreach(free_module_prefs, NULL);
312 * Register a module that will have preferences.
313 * Specify the module under which to register it or NULL to register it
314 * at the top level, the name used for the module in the preferences file,
315 * the title used in the tab for it in a preferences dialog box, and a
316 * routine to call back when we apply the preferences.
319 prefs_register_module(module_t *parent, const char *name, const char *title,
320 const char *description, void (*apply_cb)(void),
321 const gboolean use_gui)
323 return prefs_register_module_or_subtree(parent, name, title, description,
324 FALSE, apply_cb, use_gui);
328 prefs_deregister_module(module_t *parent, const char *name, const char *title)
330 /* Remove this module from the list of all modules */
331 module_t *module = (module_t *)wmem_tree_remove_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
336 if (parent == NULL) {
337 /* Remove from top */
338 wmem_tree_remove_string(prefs_top_level_modules, title, WMEM_TREE_STRING_NOCASE);
339 } else if (parent->submodules) {
340 /* Remove from parent */
341 wmem_tree_remove_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE);
344 free_module_prefs(module, NULL);
345 wmem_free(wmem_epan_scope(), module);
349 * Register a subtree that will have modules under it.
350 * Specify the module under which to register it or NULL to register it
351 * at the top level and the title used in the tab for it in a preferences
355 prefs_register_subtree(module_t *parent, const char *title, const char *description,
356 void (*apply_cb)(void))
358 return prefs_register_module_or_subtree(parent, NULL, title, description,
360 parent ? parent->use_gui : FALSE);
364 prefs_register_module_or_subtree(module_t *parent, const char *name,
365 const char *title, const char *description,
366 gboolean is_subtree, void (*apply_cb)(void),
373 /* this module may have been created as a subtree item previously */
374 if ((module = find_subtree(parent, title))) {
375 /* the module is currently a subtree */
377 module->apply_cb = apply_cb;
378 module->description = description;
380 if (prefs_find_module(name) == NULL) {
381 wmem_tree_insert_string(prefs_modules, name, module,
382 WMEM_TREE_STRING_NOCASE);
388 module = wmem_new(wmem_epan_scope(), module_t);
390 module->title = title;
391 module->description = description;
392 module->apply_cb = apply_cb;
393 module->prefs = NULL; /* no preferences, to start */
394 module->parent = parent;
395 module->submodules = NULL; /* no submodules, to start */
396 module->numprefs = 0;
397 module->prefs_changed = FALSE;
398 module->obsolete = FALSE;
399 module->use_gui = use_gui;
402 * Do we have a module name?
407 * Make sure that only lower-case ASCII letters, numbers,
408 * underscores, hyphens, and dots appear in the name.
410 * Crash if there is, as that's an error in the code;
411 * you can make the title a nice string with capitalization,
412 * white space, punctuation, etc., but the name can be used
413 * on the command line, and shouldn't require quoting,
416 for (p = name; (c = *p) != '\0'; p++)
417 g_assert(g_ascii_islower(c) || g_ascii_isdigit(c) || c == '_' ||
418 c == '-' || c == '.');
421 * Make sure there's not already a module with that
422 * name. Crash if there is, as that's an error in the
423 * code, and the code has to be fixed not to register
424 * more than one module with the same name.
426 * We search the list of all modules; the subtree stuff
427 * doesn't require preferences in subtrees to have names
428 * that reflect the subtree they're in (that would require
429 * protocol preferences to have a bogus "protocol.", or
430 * something such as that, to be added to all their names).
432 g_assert(prefs_find_module(name) == NULL);
435 * Insert this module in the list of all modules.
437 wmem_tree_insert_string(prefs_modules, name, module, WMEM_TREE_STRING_NOCASE);
440 * This has no name, just a title; check to make sure it's a
441 * subtree, and crash if it's not.
443 g_assert(is_subtree);
447 * Insert this module into the appropriate place in the display
450 if (parent == NULL) {
452 * It goes at the top.
454 wmem_tree_insert_string(prefs_top_level_modules, title, module, WMEM_TREE_STRING_NOCASE);
457 * It goes into the list for this module.
460 if (parent->submodules == NULL)
461 parent->submodules = wmem_tree_new(wmem_epan_scope());
463 wmem_tree_insert_string(parent->submodules, title, module, WMEM_TREE_STRING_NOCASE);
470 * Register that a protocol has preferences.
472 module_t *protocols_module = NULL;
475 prefs_register_protocol(int id, void (*apply_cb)(void))
477 protocol_t *protocol;
480 * Have we yet created the "Protocols" subtree?
482 if (protocols_module == NULL) {
484 * No. Register Protocols subtree as well as any preferences
485 * for non-dissector modules.
488 prefs_register_modules();
490 protocol = find_protocol_by_id(id);
491 return prefs_register_module(protocols_module,
492 proto_get_protocol_filter_name(id),
493 proto_get_protocol_short_name(protocol),
494 proto_get_protocol_name(id), apply_cb, TRUE);
498 prefs_deregister_protocol (int id)
500 protocol_t *protocol = find_protocol_by_id(id);
501 prefs_deregister_module (protocols_module,
502 proto_get_protocol_filter_name(id),
503 proto_get_protocol_short_name(protocol));
507 prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
509 protocol_t *protocol;
510 module_t *subtree_module;
511 module_t *new_module;
512 char *sep = NULL, *ptr = NULL, *orig = NULL;
515 * Have we yet created the "Protocols" subtree?
516 * XXX - can we just do this by registering Protocols/{subtree}?
519 if (protocols_module == NULL) {
521 * No. Register Protocols subtree as well as any preferences
522 * for non-dissector modules.
525 prefs_register_modules();
528 subtree_module = protocols_module;
531 /* take a copy of the buffer, orig keeps a base pointer while ptr
532 * walks through the string */
533 orig = ptr = g_strdup(subtree);
535 while (ptr && *ptr) {
537 if ((sep = strchr(ptr, '/')))
540 if (!(new_module = find_subtree(subtree_module, ptr))) {
542 * There's no such module; create it, with the description
543 * being the name (if it's later registered explicitly
544 * with a description, that will override it).
546 ptr = wmem_strdup(wmem_epan_scope(), ptr),
547 new_module = prefs_register_subtree(subtree_module, ptr, ptr, NULL);
550 subtree_module = new_module;
558 protocol = find_protocol_by_id(id);
559 return prefs_register_module(subtree_module,
560 proto_get_protocol_filter_name(id),
561 proto_get_protocol_short_name(protocol),
562 proto_get_protocol_name(id), apply_cb, TRUE);
567 * Register that a protocol used to have preferences but no longer does,
568 * by creating an "obsolete" module for it.
571 prefs_register_protocol_obsolete(int id)
574 protocol_t *protocol;
577 * Have we yet created the "Protocols" subtree?
579 if (protocols_module == NULL) {
581 * No. Register Protocols subtree as well as any preferences
582 * for non-dissector modules.
585 prefs_register_modules();
587 protocol = find_protocol_by_id(id);
588 module = prefs_register_module(protocols_module,
589 proto_get_protocol_filter_name(id),
590 proto_get_protocol_short_name(protocol),
591 proto_get_protocol_name(id), NULL, TRUE);
592 module->obsolete = TRUE;
597 * Register that a statistical tap has preferences.
599 * "name" is a name for the tap to use on the command line with "-o"
600 * and in preference files.
602 * "title" is a short human-readable name for the tap.
604 * "description" is a longer human-readable description of the tap.
606 module_t *stats_module = NULL;
609 prefs_register_stat(const char *name, const char *title,
610 const char *description, void (*apply_cb)(void))
613 * Have we yet created the "Statistics" subtree?
615 if (stats_module == NULL) {
617 * No. Register Statistics subtree as well as any preferences
618 * for non-dissector modules.
621 prefs_register_modules();
624 return prefs_register_module(stats_module, name, title, description,
629 prefs_find_module(const char *name)
631 return (module_t *)wmem_tree_lookup_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
635 find_subtree(module_t *parent, const char *name)
637 return (module_t *)wmem_tree_lookup_string(parent ? parent->submodules : prefs_top_level_modules, name, WMEM_TREE_STRING_NOCASE);
641 * Call a callback function, with a specified argument, for each module
642 * in a list of modules. If the list is NULL, searches the top-level
643 * list in the display tree of modules. If any callback returns a
644 * non-zero value, we stop and return that value, otherwise we
647 * Ignores "obsolete" modules; their sole purpose is to allow old
648 * preferences for dissectors that no longer have preferences to be
649 * silently ignored in preference files. Does not ignore subtrees,
650 * as this can be used when walking the display tree of modules.
660 call_foreach_cb(const void *key _U_, void *value, void *data)
662 module_t *module = (module_t*)value;
663 call_foreach_t *call_data = (call_foreach_t*)data;
665 if (!module->obsolete)
666 call_data->ret = (*call_data->callback)(module, call_data->user_data);
668 return (call_data->ret != 0);
672 prefs_module_list_foreach(wmem_tree_t *module_list, module_cb callback,
675 call_foreach_t call_data;
677 if (module_list == NULL)
678 module_list = prefs_top_level_modules;
680 call_data.callback = callback;
681 call_data.user_data = user_data;
683 wmem_tree_foreach(module_list, call_foreach_cb, &call_data);
684 return call_data.ret;
688 * Returns TRUE if module has any submodules
691 prefs_module_has_submodules(module_t *module)
693 if (module->submodules == NULL) {
697 if (wmem_tree_is_empty(module->submodules)) {
705 * Call a callback function, with a specified argument, for each module
706 * in the list of all modules. (This list does not include subtrees.)
708 * Ignores "obsolete" modules; their sole purpose is to allow old
709 * preferences for dissectors that no longer have preferences to be
710 * silently ignored in preference files.
713 prefs_modules_foreach(module_cb callback, gpointer user_data)
715 return prefs_module_list_foreach(prefs_modules, callback, user_data);
719 * Call a callback function, with a specified argument, for each submodule
720 * of specified modules. If the module is NULL, goes through the top-level
721 * list in the display tree of modules.
723 * Ignores "obsolete" modules; their sole purpose is to allow old
724 * preferences for dissectors that no longer have preferences to be
725 * silently ignored in preference files. Does not ignore subtrees,
726 * as this can be used when walking the display tree of modules.
729 prefs_modules_foreach_submodules(module_t *module, module_cb callback,
732 return prefs_module_list_foreach((module)?module->submodules:prefs_top_level_modules, callback, user_data);
736 call_apply_cb(const void *key _U_, void *value, void *data _U_)
738 module_t *module = (module_t *)value;
740 if (module->obsolete)
742 if (module->prefs_changed) {
743 if (module->apply_cb != NULL)
744 (*module->apply_cb)();
745 module->prefs_changed = FALSE;
747 if (module->submodules)
748 wmem_tree_foreach(module->submodules, call_apply_cb, NULL);
753 * Call the "apply" callback function for each module if any of its
754 * preferences have changed, and then clear the flag saying its
755 * preferences have changed, as the module has been notified of that
759 prefs_apply_all(void)
761 wmem_tree_foreach(prefs_modules, call_apply_cb, NULL);
765 * Call the "apply" callback function for a specific module if any of
766 * its preferences have changed, and then clear the flag saying its
767 * preferences have changed, as the module has been notified of that
771 prefs_apply(module_t *module)
773 if (module && module->prefs_changed)
774 call_apply_cb(NULL, module, NULL);
778 * Register a preference in a module's list of preferences.
779 * If it has a title, give it an ordinal number; otherwise, it's a
780 * preference that won't show up in the UI, so it shouldn't get an
781 * ordinal number (the ordinal should be the ordinal in the set of
782 * *visible* preferences).
785 register_preference(module_t *module, const char *name, const char *title,
786 const char *description, int type)
791 preference = g_new(pref_t,1);
792 preference->name = name;
793 preference->title = title;
794 preference->description = description;
795 preference->type = type;
796 preference->gui = GUI_ALL; /* default */
798 preference->ordinal = module->numprefs;
800 preference->ordinal = -1; /* no ordinal for you */
803 * Make sure that only lower-case ASCII letters, numbers,
804 * underscores, and dots appear in the preference name.
806 * Crash if there is, as that's an error in the code;
807 * you can make the title and description nice strings
808 * with capitalization, white space, punctuation, etc.,
809 * but the name can be used on the command line,
810 * and shouldn't require quoting, shifting, etc.
812 for (p = name; *p != '\0'; p++)
813 if (!(g_ascii_islower(*p) || g_ascii_isdigit(*p) || *p == '_' || *p == '.'))
814 g_error("Preference %s.%s contains invalid characters", module->name, name);
817 * Make sure there's not already a preference with that
818 * name. Crash if there is, as that's an error in the
819 * code, and the code has to be fixed not to register
820 * more than one preference with the same name.
822 if (prefs_find_preference(module, name) != NULL)
823 g_error("Preference %s has already been registered", name);
825 if ((!IS_PREF_OBSOLETE(type)) &&
826 /* Don't compare if it's a subtree */
827 (module->name != NULL)) {
829 * Make sure the preference name doesn't begin with the
830 * module name, as that's redundant and Just Silly.
832 if (!((strncmp(name, module->name, strlen(module->name)) != 0) ||
833 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_'))))
834 g_error("Preference %s begins with the module name", name);
838 * There isn't already one with that name, so add the
841 module->prefs = g_list_append(module->prefs, preference);
849 * Find a preference in a module's list of preferences, given the module
850 * and the preference's name.
859 preference_match(gconstpointer a, gconstpointer b)
861 const pref_t *pref = (const pref_t *)a;
862 const char *name = (const char *)b;
864 return strcmp(name, pref->name);
868 module_find_pref_cb(const void *key _U_, void *value, void *data)
870 find_pref_arg_t* arg = (find_pref_arg_t*)data;
872 module_t *module = (module_t *)value;
877 list_entry = g_list_find_custom(module->prefs, arg->name,
880 if (list_entry == NULL)
883 arg->list_entry = list_entry;
884 arg->submodule = module;
888 /* Tries to find a preference, setting containing_module to the (sub)module
889 * holding this preference. */
890 static struct preference *
891 prefs_find_preference_with_submodule(module_t *module, const char *name,
892 module_t **containing_module)
898 return NULL; /* invalid parameters */
900 list_entry = g_list_find_custom(module->prefs, name,
902 arg.submodule = NULL;
904 if (list_entry == NULL)
906 arg.list_entry = NULL;
907 if (module->submodules != NULL)
910 wmem_tree_foreach(module->submodules, module_find_pref_cb, &arg);
913 list_entry = arg.list_entry;
916 if (list_entry == NULL)
917 return NULL; /* no such preference */
919 if (containing_module)
920 *containing_module = arg.submodule ? arg.submodule : module;
922 return (struct preference *) list_entry->data;
926 prefs_find_preference(module_t *module, const char *name)
928 return prefs_find_preference_with_submodule(module, name, NULL);
932 * Returns TRUE if the given protocol has registered preferences
935 prefs_is_registered_protocol(const char *name)
937 module_t *m = prefs_find_module(name);
939 return (m != NULL && !m->obsolete);
943 * Returns the module title of a registered protocol
946 prefs_get_title_by_name(const char *name)
948 module_t *m = prefs_find_module(name);
950 return (m != NULL && !m->obsolete) ? m->title : NULL;
954 * Register a preference with an unsigned integral value.
957 prefs_register_uint_preference(module_t *module, const char *name,
958 const char *title, const char *description,
959 guint base, guint *var)
963 preference = register_preference(module, name, title, description,
965 preference->varp.uint = var;
966 preference->default_val.uint = *var;
967 g_assert(base > 0 && base != 1 && base < 37);
968 preference->info.base = base;
972 * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
977 * Register a "custom" preference with a unsigned integral value.
978 * XXX - This should be temporary until we can find a better way
979 * to do "custom" preferences
982 prefs_register_uint_custom_preference(module_t *module, const char *name,
983 const char *title, const char *description,
984 struct pref_custom_cbs* custom_cbs, guint *var)
988 preference = register_preference(module, name, title, description,
991 preference->custom_cbs = *custom_cbs;
992 preference->varp.uint = var;
993 preference->default_val.uint = *var;
997 * Register a preference with an Boolean value.
1000 prefs_register_bool_preference(module_t *module, const char *name,
1001 const char *title, const char *description,
1006 preference = register_preference(module, name, title, description,
1008 preference->varp.boolp = var;
1009 preference->default_val.boolval = *var;
1013 * Register a preference with an enumerated value.
1016 prefs_register_enum_preference(module_t *module, const char *name,
1017 const char *title, const char *description,
1018 gint *var, const enum_val_t *enumvals,
1019 gboolean radio_buttons)
1023 preference = register_preference(module, name, title, description,
1025 preference->varp.enump = var;
1026 preference->default_val.enumval = *var;
1027 preference->info.enum_info.enumvals = enumvals;
1028 preference->info.enum_info.radio_buttons = radio_buttons;
1032 register_string_like_preference(module_t *module, const char *name,
1033 const char *title, const char *description,
1034 char **var, int type,
1035 struct pref_custom_cbs* custom_cbs,
1041 pref = register_preference(module, name, title, description, type);
1044 * String preference values should be non-null (as you can't
1045 * keep them null after using the preferences GUI, you can at best
1046 * have them be null strings) and freeable (as we free them
1047 * if we change them).
1049 * If the value is a null pointer, make it a copy of a null
1050 * string, otherwise make it a copy of the value.
1054 *var = g_strdup("");
1056 *var = g_strdup(*var);
1061 pref->varp.string = var;
1062 pref->default_val.string = g_strdup(*var);
1063 pref->stashed_val.string = NULL;
1064 if (type == PREF_CUSTOM) {
1065 g_assert(custom_cbs);
1066 pref->custom_cbs = *custom_cbs;
1071 * For use by UI code that sets preferences.
1074 prefs_set_string_like_value(pref_t *pref, const gchar *value, gboolean *changed)
1076 if (*pref->varp.string) {
1077 if (strcmp(*pref->varp.string, value) != 0) {
1079 g_free(*pref->varp.string);
1080 *pref->varp.string = g_strdup(value);
1083 *pref->varp.string = g_strdup(value);
1088 * Reset the value of a string-like preference.
1091 reset_string_like_preference(pref_t *pref)
1093 g_free(*pref->varp.string);
1094 *pref->varp.string = g_strdup(pref->default_val.string);
1098 * Register a preference with a character-string value.
1101 prefs_register_string_preference(module_t *module, const char *name,
1102 const char *title, const char *description,
1106 register_string_like_preference(module, name, title, description,
1107 (char **)var, PREF_STRING, NULL, FALSE);
1112 * Register a preference with a file name (string) value.
1115 prefs_register_filename_preference(module_t *module, const char *name,
1116 const char *title, const char *description,
1120 register_string_like_preference(module, name, title, description,
1121 (char **)var, PREF_FILENAME, NULL, FALSE);
1126 * Register a preference with a directory name (string) value.
1129 prefs_register_directory_preference(module_t *module, const char *name,
1130 const char *title, const char *description,
1134 register_string_like_preference(module, name, title, description,
1135 (char **)var, PREF_DIRNAME, NULL, FALSE);
1139 /* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
1141 prefs_register_range_preference_common(module_t *module, const char *name,
1142 const char *title, const char *description,
1143 range_t **var, guint32 max_value, int type)
1147 preference = register_preference(module, name, title, description, type);
1148 preference->info.max_value = max_value;
1151 * Range preference values should be non-null (as you can't
1152 * keep them null after using the preferences GUI, you can at best
1153 * have them be empty ranges) and freeable (as we free them
1154 * if we change them).
1156 * If the value is a null pointer, make it an empty range.
1159 *var = range_empty();
1160 preference->varp.range = var;
1161 preference->default_val.range = range_copy(*var);
1162 preference->stashed_val.range = NULL;
1166 * Register a preference with a ranged value.
1169 prefs_register_range_preference(module_t *module, const char *name,
1170 const char *title, const char *description,
1171 range_t **var, guint32 max_value)
1173 prefs_register_range_preference_common(module, name, title,
1174 description, var, max_value, PREF_RANGE);
1178 prefs_set_range_value_work(pref_t *pref, const gchar *value,
1179 gboolean return_range_errors, gboolean *changed)
1183 if (range_convert_str_work(&newrange, value, pref->info.max_value,
1184 return_range_errors) != CVT_NO_ERROR) {
1185 return FALSE; /* number was bad */
1188 if (!ranges_are_equal(*pref->varp.range, newrange)) {
1190 g_free(*pref->varp.range);
1191 *pref->varp.range = newrange;
1199 * For use by UI code that sets preferences.
1202 prefs_set_range_value(pref_t *pref, const gchar *value, gboolean *changed)
1204 return prefs_set_range_value_work(pref, value, TRUE, changed);
1208 * Register a static text 'preference'. It can be used to add explanatory
1209 * text inline with other preferences in the GUI.
1210 * Note: Static preferences are not saved to the preferences file.
1213 prefs_register_static_text_preference(module_t *module, const char *name,
1215 const char *description)
1217 register_preference(module, name, title, description, PREF_STATIC_TEXT);
1221 * Register a uat 'preference'. It adds a button that opens the uat's window in the
1222 * preferences tab of the module.
1225 prefs_register_uat_preference(module_t *module, const char *name,
1226 const char *title, const char *description,
1230 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1232 preference->varp.uat = uat;
1236 * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
1237 * preferences tab of the module.
1240 prefs_register_uat_preference_qt(module_t *module, const char *name,
1241 const char *title, const char *description,
1245 pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
1247 preference->varp.uat = uat;
1249 preference->gui = GUI_QT;
1253 * Register a color preference.
1256 prefs_register_color_preference(module_t *module, const char *name,
1257 const char *title, const char *description,
1260 pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
1262 preference->varp.colorp = color;
1263 preference->default_val.color = *color;
1267 * Register a "custom" preference with a list.
1268 * XXX - This should be temporary until we can find a better way
1269 * to do "custom" preferences
1271 typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
1274 prefs_register_list_custom_preference(module_t *module, const char *name,
1275 const char *title, const char *description,
1276 struct pref_custom_cbs* custom_cbs,
1277 pref_custom_list_init_cb init_cb,
1280 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1282 preference->custom_cbs = *custom_cbs;
1283 init_cb(preference, list);
1287 * Register a custom preference.
1290 prefs_register_custom_preference(module_t *module, const char *name,
1291 const char *title, const char *description,
1292 struct pref_custom_cbs* custom_cbs,
1293 void **custom_data _U_)
1295 pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
1297 preference->custom_cbs = *custom_cbs;
1298 /* XXX - wait until we can handle void** pointers
1299 preference->custom_cbs.init_cb(preference, custom_data);
1304 * Register a (internal) "Decode As" preference with a ranged value.
1306 void prefs_register_decode_as_range_preference(module_t *module, const char *name,
1307 const char *title, const char *description, range_t **var,
1310 prefs_register_range_preference_common(module, name, title,
1311 description, var, max_value, PREF_DECODE_AS_RANGE);
1315 * Register a (internal) "Decode As" preference with an unsigned integral value
1316 * for a dissector table.
1318 void prefs_register_decode_as_preference(module_t *module, const char *name,
1319 const char *title, const char *description, guint *var)
1323 preference = register_preference(module, name, title, description,
1324 PREF_DECODE_AS_UINT);
1325 preference->varp.uint = var;
1326 preference->default_val.uint = *var;
1327 /* XXX - Presume base 10 for now */
1328 preference->info.base = 10;
1332 * Register a preference that used to be supported but no longer is.
1335 prefs_register_obsolete_preference(module_t *module, const char *name)
1337 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
1341 * Check to see if a preference is obsolete.
1344 prefs_get_preference_obsolete(pref_t *pref)
1347 return (IS_PREF_OBSOLETE(pref->type) ? TRUE : FALSE);
1353 * Make a preference obsolete.
1355 extern prefs_set_pref_e
1356 prefs_set_preference_obsolete(pref_t *pref)
1359 SET_PREF_OBSOLETE(pref->type);
1360 return PREFS_SET_OK;
1362 return PREFS_SET_NO_SUCH_PREF;
1366 /* Return the value assigned to the given uint preference. */
1368 prefs_get_uint_preference(pref_t *pref)
1370 if (pref && pref->type == PREF_UINT)
1371 return *pref->varp.uint;
1377 * Call a callback function, with a specified argument, for each preference
1378 * in a given module.
1380 * If any of the callbacks return a non-zero value, stop and return that
1381 * value, otherwise return 0.
1384 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
1390 for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
1391 pref = (pref_t *)elem->data;
1392 if (IS_PREF_OBSOLETE(pref->type)) {
1394 * This preference is no longer supported; it's
1395 * not a real preference, so we don't call the
1396 * callback for it (i.e., we treat it as if it
1397 * weren't found in the list of preferences,
1398 * and we weren't called in the first place).
1403 ret = (*callback)(pref, user_data);
1410 static const enum_val_t print_format_vals[] = {
1411 { "text", "Plain Text", PR_FMT_TEXT },
1412 { "postscript", "Postscript", PR_FMT_PS },
1416 static const enum_val_t print_dest_vals[] = {
1418 /* "PR_DEST_CMD" means "to printer" on Windows */
1419 { "command", "Printer", PR_DEST_CMD },
1421 { "command", "Command", PR_DEST_CMD },
1423 { "file", "File", PR_DEST_FILE },
1427 static const enum_val_t st_sort_col_vals[] = {
1428 { "name", "Node name (topic/item)", ST_SORT_COL_NAME },
1429 { "count", "Item count", ST_SORT_COL_COUNT },
1430 { "average", "Average value of the node", ST_SORT_COL_AVG },
1431 { "min", "Minimum value of the node", ST_SORT_COL_MIN },
1432 { "max", "Maximum value of the node", ST_SORT_COL_MAX },
1433 { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE },
1438 stats_callback(void)
1440 /* Test for a sane tap update interval */
1441 if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000)
1442 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
1444 #ifdef HAVE_LIBPORTAUDIO
1445 /* Test for a sane max channels entry */
1446 if (prefs.rtp_player_max_visible < 1 || prefs.rtp_player_max_visible > 10)
1447 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
1450 /* burst resolution can't be less than 1 (ms) */
1451 if (prefs.st_burst_resolution < 1) {
1452 prefs.st_burst_resolution = 1;
1454 else if (prefs.st_burst_resolution > ST_MAX_BURSTRES) {
1455 prefs.st_burst_resolution = ST_MAX_BURSTRES;
1457 /* make sure burst window value makes sense */
1458 if (prefs.st_burst_windowlen < prefs.st_burst_resolution) {
1459 prefs.st_burst_windowlen = prefs.st_burst_resolution;
1461 /* round burst window down to multiple of resolution */
1462 prefs.st_burst_windowlen -= prefs.st_burst_windowlen%prefs.st_burst_resolution;
1463 if ((prefs.st_burst_windowlen/prefs.st_burst_resolution) > ST_MAX_BURSTBUCKETS) {
1464 prefs.st_burst_windowlen = prefs.st_burst_resolution*ST_MAX_BURSTBUCKETS;
1471 /* Ensure there is at least one file count */
1472 if (prefs.gui_recent_files_count_max == 0)
1473 prefs.gui_recent_files_count_max = 10;
1475 /* Ensure there is at least one display filter entry */
1476 if (prefs.gui_recent_df_entries_max == 0)
1477 prefs.gui_recent_df_entries_max = 10;
1481 gui_layout_callback(void)
1483 if (prefs.gui_layout_type == layout_unused ||
1484 prefs.gui_layout_type >= layout_type_max) {
1485 /* XXX - report an error? It's not a syntax error - we'd need to
1486 add a way of reporting a *semantic* error. */
1487 prefs.gui_layout_type = layout_type_5;
1491 /******************************************************
1492 * All custom preference function callbacks
1493 ******************************************************/
1494 static void custom_pref_no_cb(pref_t* pref _U_) {}
1498 * Console log level custom preference functions
1501 console_log_level_reset_cb(pref_t* pref)
1503 *pref->varp.uint = pref->default_val.uint;
1506 static prefs_set_pref_e
1507 console_log_level_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1511 uval = (guint)strtoul(value, NULL, 10);
1513 if (*pref->varp.uint != uval) {
1515 *pref->varp.uint = uval;
1518 if (*pref->varp.uint & (G_LOG_LEVEL_INFO|G_LOG_LEVEL_DEBUG)) {
1520 * GLib >= 2.32 drops INFO and DEBUG messages by default. Tell
1521 * it not to do that.
1523 g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
1526 return PREFS_SET_OK;
1529 static const char * console_log_level_type_name_cb(void) {
1533 static char * console_log_level_type_description_cb(void) {
1534 return g_strdup_printf(
1535 "Console log level (for debugging)\n"
1536 "A bitmask of log levels:\n"
1545 static gboolean console_log_level_is_default_cb(pref_t* pref) {
1546 return *pref->varp.uint == pref->default_val.uint;
1549 static char * console_log_level_to_str_cb(pref_t* pref, gboolean default_val) {
1550 return g_strdup_printf("%u", default_val ? pref->default_val.uint : *pref->varp.uint);
1554 * Column preference functions
1556 #define PRS_COL_HIDDEN "column.hidden"
1557 #define PRS_COL_FMT "column.format"
1558 #define PRS_COL_NUM "column.number"
1559 static module_t *gui_column_module = NULL;
1561 static prefs_set_pref_e
1562 column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
1566 pref_t *format_pref;
1568 prefs_set_string_like_value(pref, value, changed);
1571 * Set the "visible" flag for the existing columns; we need to
1572 * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
1573 * after setting it (which might be the case if, for example, we
1574 * set PRS_COL_HIDDEN on the command line).
1576 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1577 for (clp = *format_pref->varp.list; clp != NULL; clp = clp->next) {
1578 cfmt = (fmt_data *)clp->data;
1579 cfmt->visible = prefs_is_column_visible(*pref->varp.string, cfmt);
1582 return PREFS_SET_OK;
1586 column_hidden_type_name_cb(void)
1588 return "Packet list hidden columns";
1592 column_hidden_type_description_cb(void)
1594 return g_strdup("List all columns to hide in the packet list.");
1598 column_hidden_to_str_cb(pref_t* pref, gboolean default_val)
1600 GString *cols_hidden = g_string_new ("");
1603 pref_t *format_pref;
1606 return g_strdup(pref->default_val.string);
1608 format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT);
1609 clp = (format_pref) ? *format_pref->varp.list : NULL;
1612 cfmt = (fmt_data *) clp->data;
1613 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
1614 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1615 col_format_to_string(cfmt->fmt),
1616 cfmt->custom_fields,
1617 cfmt->custom_occurrence,
1618 cfmt->resolved ? 'R' : 'U');
1620 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1622 if (!cfmt->visible) {
1623 if (cols_hidden->len)
1624 g_string_append (cols_hidden, ",");
1625 g_string_append (cols_hidden, prefs_fmt);
1631 return g_string_free (cols_hidden, FALSE);
1635 column_hidden_is_default_cb(pref_t* pref)
1637 char *cur_hidden_str = column_hidden_to_str_cb(pref, FALSE);
1638 gboolean is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
1640 g_free(cur_hidden_str);
1645 /* Number of columns "preference". This is only used internally and is not written to the
1649 column_num_reset_cb(pref_t* pref)
1651 *pref->varp.uint = pref->default_val.uint;
1654 static prefs_set_pref_e
1655 column_num_set_cb(pref_t* pref _U_, const gchar* value _U_, gboolean* changed _U_)
1657 /* Don't write this to the preferences file */
1658 return PREFS_SET_OK;
1662 column_num_type_name_cb(void)
1668 column_num_type_description_cb(void)
1670 return g_strdup("");
1674 column_num_is_default_cb(pref_t* pref _U_)
1680 column_num_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
1682 return g_strdup("");
1686 * Column format custom preference functions
1689 column_format_init_cb(pref_t* pref, GList** value)
1691 fmt_data *src_cfmt, *dest_cfmt;
1694 pref->varp.list = value;
1696 pref->default_val.list = NULL;
1697 for (entry = *pref->varp.list; entry != NULL; entry = g_list_next(entry)) {
1698 src_cfmt = (fmt_data *)entry->data;
1699 dest_cfmt = g_new(fmt_data,1);
1700 dest_cfmt->title = g_strdup(src_cfmt->title);
1701 dest_cfmt->fmt = src_cfmt->fmt;
1702 if (src_cfmt->custom_fields) {
1703 dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
1704 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1706 dest_cfmt->custom_fields = NULL;
1707 dest_cfmt->custom_occurrence = 0;
1709 dest_cfmt->visible = src_cfmt->visible;
1710 dest_cfmt->resolved = src_cfmt->resolved;
1711 pref->default_val.list = g_list_append(pref->default_val.list, dest_cfmt);
1716 column_format_free_cb(pref_t* pref)
1718 free_col_info(*pref->varp.list);
1719 free_col_info(pref->default_val.list);
1723 column_format_reset_cb(pref_t* pref)
1725 fmt_data *src_cfmt, *dest_cfmt;
1727 pref_t *col_num_pref;
1729 free_col_info(*pref->varp.list);
1730 *pref->varp.list = NULL;
1732 for (entry = pref->default_val.list; entry != NULL; entry = g_list_next(entry)) {
1733 src_cfmt = (fmt_data *)entry->data;
1734 dest_cfmt = g_new(fmt_data,1);
1735 dest_cfmt->title = g_strdup(src_cfmt->title);
1736 dest_cfmt->fmt = src_cfmt->fmt;
1737 if (src_cfmt->custom_fields) {
1738 dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
1739 dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
1741 dest_cfmt->custom_fields = NULL;
1742 dest_cfmt->custom_occurrence = 0;
1744 dest_cfmt->visible = src_cfmt->visible;
1745 dest_cfmt->resolved = src_cfmt->resolved;
1746 *pref->varp.list = g_list_append(*pref->varp.list, dest_cfmt);
1749 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1750 g_assert(col_num_pref != NULL); /* Should never happen */
1751 column_num_reset_cb(col_num_pref);
1754 static prefs_set_pref_e
1755 column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1757 GList *col_l, *col_l_elt;
1760 pref_t *hidden_pref, *col_num_pref;
1762 col_l = prefs_get_string_list(value);
1764 return PREFS_SET_SYNTAX_ERR;
1765 if ((g_list_length(col_l) % 2) != 0) {
1766 /* A title didn't have a matching format. */
1767 prefs_clear_string_list(col_l);
1768 return PREFS_SET_SYNTAX_ERR;
1770 /* Check to make sure all column formats are valid. */
1771 col_l_elt = g_list_first(col_l);
1773 fmt_data cfmt_check;
1775 /* Go past the title. */
1776 col_l_elt = col_l_elt->next;
1778 /* Parse the format to see if it's valid. */
1779 if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
1780 /* It's not a valid column format. */
1781 prefs_clear_string_list(col_l);
1782 return PREFS_SET_SYNTAX_ERR;
1784 if (cfmt_check.fmt != COL_CUSTOM) {
1785 /* Some predefined columns have been migrated to use custom columns.
1786 * We'll convert these silently here */
1787 try_convert_to_custom_column(&col_l_elt->data);
1789 /* We don't need the custom column field on this pass. */
1790 g_free(cfmt_check.custom_fields);
1793 /* Go past the format. */
1794 col_l_elt = col_l_elt->next;
1797 /* They're all valid; process them. */
1798 free_col_info(*pref->varp.list);
1799 *pref->varp.list = NULL;
1800 hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN);
1801 g_assert(hidden_pref != NULL); /* Should never happen */
1802 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1803 g_assert(col_num_pref != NULL); /* Should never happen */
1804 llen = g_list_length(col_l);
1805 *col_num_pref->varp.uint = llen / 2;
1806 col_l_elt = g_list_first(col_l);
1808 cfmt = g_new(fmt_data,1);
1809 cfmt->title = g_strdup((gchar *)col_l_elt->data);
1810 col_l_elt = col_l_elt->next;
1811 parse_column_format(cfmt, (char *)col_l_elt->data);
1812 cfmt->visible = prefs_is_column_visible(*hidden_pref->varp.string, cfmt);
1813 col_l_elt = col_l_elt->next;
1814 *pref->varp.list = g_list_append(*pref->varp.list, cfmt);
1817 prefs_clear_string_list(col_l);
1818 free_string_like_preference(hidden_pref);
1819 return PREFS_SET_OK;
1824 column_format_type_name_cb(void)
1826 return "Packet list column format";
1830 column_format_type_description_cb(void)
1832 return g_strdup("Each pair of strings consists of a column title and its format");
1836 column_format_is_default_cb(pref_t* pref)
1838 GList *clp = *pref->varp.list,
1839 *pref_col = g_list_first(clp),
1840 *def_col = g_list_first(pref->default_val.list);
1841 fmt_data *cfmt, *def_cfmt;
1842 gboolean is_default = TRUE;
1843 pref_t *col_num_pref;
1845 /* See if the column data has changed from the default */
1846 col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM);
1847 if (col_num_pref && *col_num_pref->varp.uint != col_num_pref->default_val.uint) {
1850 while (pref_col && def_col) {
1851 cfmt = (fmt_data *) pref_col->data;
1852 def_cfmt = (fmt_data *) def_col->data;
1853 if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
1854 (cfmt->fmt != def_cfmt->fmt) ||
1855 (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) &&
1856 ((g_strcmp0(cfmt->custom_fields, def_cfmt->custom_fields) != 0) ||
1857 (cfmt->resolved != def_cfmt->resolved)))) {
1862 pref_col = pref_col->next;
1863 def_col = def_col->next;
1871 column_format_to_str_cb(pref_t* pref, gboolean default_val)
1873 GList *pref_l = default_val ? pref->default_val.list : *pref->varp.list;
1874 GList *clp = g_list_first(pref_l);
1878 char *column_format_str;
1882 cfmt = (fmt_data *) clp->data;
1883 col_l = g_list_append(col_l, g_strdup(cfmt->title));
1884 if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
1885 prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
1886 col_format_to_string(cfmt->fmt),
1887 cfmt->custom_fields,
1888 cfmt->custom_occurrence,
1889 cfmt->resolved ? 'R' : 'U');
1891 prefs_fmt = g_strdup(col_format_to_string(cfmt->fmt));
1893 col_l = g_list_append(col_l, prefs_fmt);
1897 column_format_str = join_string_list(col_l);
1898 prefs_clear_string_list(col_l);
1899 return column_format_str;
1903 /****** Capture column custom preference functions ******/
1905 /* This routine is only called when Wireshark is started, NOT when another profile is selected.
1906 Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
1907 to prefs->default_val.list.
1910 capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
1912 GList *ccv_list = *capture_cols_values,
1917 dlist = g_list_append(dlist, g_strdup((gchar *)ccv_list->data));
1918 ccv_list = ccv_list->next;
1921 pref->default_val.list = dlist;
1922 pref->varp.list = &prefs.capture_columns;
1923 pref->stashed_val.boolval = FALSE;
1926 /* Free the prefs->capture_columns list strings and remove the list entries.
1927 Note that since pref->varp.list points to &prefs.capture_columns, it is
1931 capture_column_free_cb(pref_t* pref)
1933 prefs_clear_string_list(prefs.capture_columns);
1934 prefs.capture_columns = NULL;
1936 if (pref->stashed_val.boolval == TRUE) {
1937 prefs_clear_string_list(pref->default_val.list);
1938 pref->default_val.list = NULL;
1942 /* Copy pref->default_val.list to *pref->varp.list.
1945 capture_column_reset_cb(pref_t* pref)
1947 GList *vlist = NULL, *dlist;
1949 /* Free the column name strings and remove the links from *pref->varp.list */
1950 prefs_clear_string_list(*pref->varp.list);
1952 for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
1953 vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
1955 *pref->varp.list = vlist;
1958 static prefs_set_pref_e
1959 capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
1961 GList *col_l = prefs_get_string_list(value);
1967 return PREFS_SET_SYNTAX_ERR;
1969 capture_column_free_cb(pref);
1971 /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
1972 to the full list of valid capture column names. */
1973 col_l_elt = g_list_first(col_l);
1974 if (!(*(gchar *)col_l_elt->data)) {
1975 for (i = 0; i < num_capture_cols; i++) {
1976 col_name = g_strdup(capture_cols[i]);
1977 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1981 /* Verify that all the column names are valid. If not, use the entire list of valid columns.
1984 gboolean found_match = FALSE;
1985 col_name = (gchar *)col_l_elt->data;
1987 for (i = 0; i < num_capture_cols; i++) {
1988 if (strcmp(col_name, capture_cols[i])==0) {
1994 /* One or more cols are invalid so use the entire list of valid cols. */
1995 for (i = 0; i < num_capture_cols; i++) {
1996 col_name = g_strdup(capture_cols[i]);
1997 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
1999 pref->varp.list = &prefs.capture_columns;
2000 prefs_clear_string_list(col_l);
2001 return PREFS_SET_SYNTAX_ERR;
2003 col_l_elt = col_l_elt->next;
2006 col_l_elt = g_list_first(col_l);
2008 col_name = (gchar *)col_l_elt->data;
2009 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
2010 col_l_elt = col_l_elt->next;
2012 pref->varp.list = &prefs.capture_columns;
2014 return PREFS_SET_OK;
2019 capture_column_type_name_cb(void)
2021 return "Column list";
2025 capture_column_type_description_cb(void)
2028 "List of columns to be displayed in the capture options dialog.\n"
2029 CAPTURE_COL_TYPE_DESCRIPTION);
2033 capture_column_is_default_cb(pref_t* pref)
2035 GList *pref_col = g_list_first(prefs.capture_columns),
2036 *def_col = g_list_first(pref->default_val.list);
2037 gboolean is_default = TRUE;
2039 /* See if the column data has changed from the default */
2040 while (pref_col && def_col) {
2041 if (strcmp((gchar *)pref_col->data, (gchar *)def_col->data) != 0) {
2045 pref_col = pref_col->next;
2046 def_col = def_col->next;
2049 /* Ensure the same column count */
2050 if (((pref_col == NULL) && (def_col != NULL)) ||
2051 ((pref_col != NULL) && (def_col == NULL)))
2058 capture_column_to_str_cb(pref_t* pref, gboolean default_val)
2061 GList *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
2062 GList *clp = g_list_first(pref_l);
2063 GList *col_l = NULL;
2065 char *capture_column_str;
2068 col = (gchar *) clp->data;
2069 col_l = g_list_append(col_l, g_strdup(col));
2073 capture_column_str = join_string_list(col_l);
2074 prefs_clear_string_list(col_l);
2075 return capture_column_str;
2078 static prefs_set_pref_e
2079 colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
2081 prefs_set_string_like_value(pref, value, changed);
2083 return PREFS_SET_OK;
2087 colorized_frame_type_name_cb(void)
2089 /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
2090 * file until the colors can be changed in the GUI. Currently this is not really
2091 * possible since the STOCK-icons for these colors are hardcoded.
2093 * XXX Find a way to change the colors of the STOCK-icons on the fly and then
2094 * add these 10 colors to the list of colors that can be changed through
2102 colorized_frame_type_description_cb(void)
2104 return g_strdup("");
2108 colorized_frame_is_default_cb(pref_t* pref _U_)
2114 colorized_frame_to_str_cb(pref_t* pref _U_, gboolean default_val _U_)
2116 return g_strdup("");
2120 * Register all non-dissector modules' preferences.
2122 static module_t *gui_module = NULL;
2123 static module_t *gui_color_module = NULL;
2124 static module_t *nameres_module = NULL;
2127 prefs_register_modules(void)
2129 module_t *printing, *capture_module, *console_module,
2130 *gui_layout_module, *gui_font_module;
2132 module_t *extcap_module;
2135 struct pref_custom_cbs custom_cbs;
2137 if (protocols_module != NULL) {
2138 /* Already setup preferences */
2144 * These are "simple" GUI preferences that can be read/written using the
2145 * preference module API. These preferences still use their own
2146 * configuration screens for access, but this cuts down on the
2147 * preference "string compare list" in set_pref()
2149 extcap_module = prefs_register_module(NULL, "extcap", "Extcap Utilities",
2150 "Extcap Utilities", NULL, FALSE);
2152 /* Setting default value to true */
2153 prefs.extcap_save_on_start = TRUE;
2154 prefs_register_bool_preference(extcap_module, "gui_save_on_start",
2155 "Save arguments on start of capture",
2156 "Save arguments on start of capture",
2157 &prefs.extcap_save_on_start);
2161 * These are "simple" GUI preferences that can be read/written using the
2162 * preference module API. These preferences still use their own
2163 * configuration screens for access, but this cuts down on the
2164 * preference "string compare list" in set_pref()
2166 gui_module = prefs_register_module(NULL, "gui", "User Interface",
2167 "User Interface", &gui_callback, FALSE);
2169 /* gui.console_open is placed first in the list so that any problems encountered
2170 * in the following prefs can be displayed in the console window.
2172 prefs_register_enum_preference(gui_module, "console_open",
2173 "Open a console window",
2174 "Open a console window (Windows only)",
2175 (gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
2177 prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
2178 prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
2179 prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
2181 prefs_register_bool_preference(gui_module, "tree_view_altern_colors",
2182 "Alternating colors in TreeViews",
2183 "Alternating colors in TreeViews?",
2184 &prefs.gui_altern_colors);
2186 prefs_register_bool_preference(gui_module, "expert_composite_eyecandy",
2187 "Display Icons on Expert Composite Dialog Tabs",
2188 "Display Icons on Expert Composite Dialog Tabs?",
2189 &prefs.gui_expert_composite_eyecandy);
2191 prefs_register_bool_preference(gui_module, "filter_toolbar_show_in_statusbar",
2192 "Place filter toolbar inside the statusbar",
2193 "Place filter toolbar inside the statusbar?",
2194 &prefs.filter_toolbar_show_in_statusbar);
2196 prefs_register_enum_preference(gui_module, "protocol_tree_line_style",
2197 "Protocol-tree line style",
2198 "Protocol-tree line style",
2199 &prefs.gui_ptree_line_style, gui_ptree_line_style, FALSE);
2201 prefs_register_enum_preference(gui_module, "protocol_tree_expander_style",
2202 "Protocol-tree expander style",
2203 "Protocol-tree expander style",
2204 &prefs.gui_ptree_expander_style, gui_ptree_expander_style, FALSE);
2206 prefs_register_enum_preference(gui_module, "hex_dump_highlight_style",
2207 "Hex dump highlight style",
2208 "Hex dump highlight style",
2209 &prefs.gui_hex_dump_highlight_style, gui_hex_dump_highlight_style, FALSE);
2211 gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
2213 custom_cbs.free_cb = free_string_like_preference;
2214 custom_cbs.reset_cb = reset_string_like_preference;
2215 custom_cbs.set_cb = column_hidden_set_cb;
2216 custom_cbs.type_name_cb = column_hidden_type_name_cb;
2217 custom_cbs.type_description_cb = column_hidden_type_description_cb;
2218 custom_cbs.is_default_cb = column_hidden_is_default_cb;
2219 custom_cbs.to_str_cb = column_hidden_to_str_cb;
2220 register_string_like_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
2221 "List all columns to hide in the packet list",
2222 &cols_hidden_list, PREF_CUSTOM, &custom_cbs, FALSE);
2224 custom_cbs.free_cb = column_format_free_cb;
2225 custom_cbs.reset_cb = column_format_reset_cb;
2226 custom_cbs.set_cb = column_format_set_cb;
2227 custom_cbs.type_name_cb = column_format_type_name_cb;
2228 custom_cbs.type_description_cb = column_format_type_description_cb;
2229 custom_cbs.is_default_cb = column_format_is_default_cb;
2230 custom_cbs.to_str_cb = column_format_to_str_cb;
2232 prefs_register_list_custom_preference(gui_column_module, PRS_COL_FMT, "Packet list column format",
2233 "Each pair of strings consists of a column title and its format", &custom_cbs,
2234 column_format_init_cb, &prefs.col_list);
2236 /* Number of columns. This is only used internally and is not written to the
2239 custom_cbs.free_cb = custom_pref_no_cb;
2240 custom_cbs.reset_cb = column_num_reset_cb;
2241 custom_cbs.set_cb = column_num_set_cb;
2242 custom_cbs.type_name_cb = column_num_type_name_cb;
2243 custom_cbs.type_description_cb = column_num_type_description_cb;
2244 custom_cbs.is_default_cb = column_num_is_default_cb;
2245 custom_cbs.to_str_cb = column_num_to_str_cb;
2246 prefs_register_uint_custom_preference(gui_column_module, PRS_COL_NUM, "Number of columns",
2247 "Number of columns in col_list", &custom_cbs, &prefs.num_cols);
2249 /* User Interface : Font */
2250 gui_font_module = prefs_register_subtree(gui_module, "Font", "Font", NULL);
2252 prefs_register_obsolete_preference(gui_font_module, "font_name");
2254 register_string_like_preference(gui_font_module, "gtk2.font_name", "Font name",
2255 "Font name for packet list, protocol tree, and hex dump panes. (GTK+)",
2256 &prefs.gui_gtk2_font_name, PREF_STRING, NULL, TRUE);
2258 register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
2259 "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
2260 &prefs.gui_qt_font_name, PREF_STRING, NULL, TRUE);
2262 /* User Interface : Colors */
2263 gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
2265 prefs_register_color_preference(gui_color_module, "marked_frame.fg", "Color preferences for a marked frame",
2266 "Color preferences for a marked frame", &prefs.gui_marked_fg);
2268 prefs_register_color_preference(gui_color_module, "marked_frame.bg", "Color preferences for a marked frame",
2269 "Color preferences for a marked frame", &prefs.gui_marked_bg);
2271 prefs_register_color_preference(gui_color_module, "ignored_frame.fg", "Color preferences for a ignored frame",
2272 "Color preferences for a ignored frame", &prefs.gui_ignored_fg);
2274 prefs_register_color_preference(gui_color_module, "ignored_frame.bg", "Color preferences for a ignored frame",
2275 "Color preferences for a ignored frame", &prefs.gui_ignored_bg);
2277 prefs_register_color_preference(gui_color_module, "stream.client.fg", "TCP stream window color preference",
2278 "TCP stream window color preference", &prefs.st_client_fg);
2280 prefs_register_color_preference(gui_color_module, "stream.client.bg", "TCP stream window color preference",
2281 "TCP stream window color preference", &prefs.st_client_bg);
2283 prefs_register_color_preference(gui_color_module, "stream.server.fg", "TCP stream window color preference",
2284 "TCP stream window color preference", &prefs.st_server_fg);
2286 prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
2287 "TCP stream window color preference", &prefs.st_server_bg);
2289 custom_cbs.free_cb = free_string_like_preference;
2290 custom_cbs.reset_cb = reset_string_like_preference;
2291 custom_cbs.set_cb = colorized_frame_set_cb;
2292 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2293 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2294 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2295 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2296 register_string_like_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
2297 "Filter Colorized Foreground",
2298 &prefs.gui_colorized_fg, PREF_CUSTOM, &custom_cbs, TRUE);
2300 custom_cbs.free_cb = free_string_like_preference;
2301 custom_cbs.reset_cb = reset_string_like_preference;
2302 custom_cbs.set_cb = colorized_frame_set_cb;
2303 custom_cbs.type_name_cb = colorized_frame_type_name_cb;
2304 custom_cbs.type_description_cb = colorized_frame_type_description_cb;
2305 custom_cbs.is_default_cb = colorized_frame_is_default_cb;
2306 custom_cbs.to_str_cb = colorized_frame_to_str_cb;
2307 register_string_like_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
2308 "Filter Colorized Background",
2309 &prefs.gui_colorized_bg, PREF_CUSTOM, &custom_cbs, TRUE);
2311 prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
2312 "Valid color filter background", &prefs.gui_text_valid);
2314 prefs_register_color_preference(gui_color_module, "color_filter_bg.invalid", "Invalid color filter background",
2315 "Invalid color filter background", &prefs.gui_text_invalid);
2317 prefs_register_color_preference(gui_color_module, "color_filter_bg.deprecated", "Deprecated color filter background",
2318 "Deprecated color filter background", &prefs.gui_text_deprecated);
2320 prefs_register_enum_preference(gui_module, "fileopen.style",
2321 "Where to start the File Open dialog box",
2322 "Where to start the File Open dialog box",
2323 &prefs.gui_fileopen_style, gui_fileopen_style, FALSE);
2325 prefs_register_uint_preference(gui_module, "recent_files_count.max",
2326 "The max. number of items in the open recent files list",
2327 "The max. number of items in the open recent files list",
2329 &prefs.gui_recent_files_count_max);
2331 prefs_register_uint_preference(gui_module, "recent_display_filter_entries.max",
2332 "The max. number of entries in the display filter list",
2333 "The max. number of entries in the display filter list",
2335 &prefs.gui_recent_df_entries_max);
2337 register_string_like_preference(gui_module, "fileopen.dir", "Start Directory",
2338 "Directory to start in when opening File Open dialog.",
2339 &prefs.gui_fileopen_dir, PREF_DIRNAME, NULL, TRUE);
2341 prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
2343 prefs_register_uint_preference(gui_module, "fileopen.preview",
2344 "The preview timeout in the File Open dialog",
2345 "The preview timeout in the File Open dialog",
2347 &prefs.gui_fileopen_preview);
2349 prefs_register_bool_preference(gui_module, "ask_unsaved",
2350 "Ask to save unsaved capture files",
2351 "Ask to save unsaved capture files?",
2352 &prefs.gui_ask_unsaved);
2354 prefs_register_bool_preference(gui_module, "find_wrap",
2355 "Wrap to beginning/end of file during search",
2356 "Wrap to beginning/end of file during search?",
2357 &prefs.gui_find_wrap);
2359 prefs_register_bool_preference(gui_module, "use_pref_save",
2360 "Settings dialogs use a save button",
2361 "Settings dialogs use a save button?",
2362 &prefs.gui_use_pref_save);
2364 prefs_register_bool_preference(gui_module, "geometry.save.position",
2365 "Save window position at exit",
2366 "Save window position at exit?",
2367 &prefs.gui_geometry_save_position);
2369 prefs_register_bool_preference(gui_module, "geometry.save.size",
2370 "Save window size at exit",
2371 "Save window size at exit?",
2372 &prefs.gui_geometry_save_size);
2374 prefs_register_bool_preference(gui_module, "geometry.save.maximized",
2375 "Save window maximized state at exit",
2376 "Save window maximized state at exit?",
2377 &prefs.gui_geometry_save_maximized);
2380 prefs_register_bool_preference(gui_module, "macosx_style",
2382 "Use OS X style (OS X with native GTK only)?",
2383 &prefs.gui_macosx_style);
2385 prefs_register_obsolete_preference(gui_module, "geometry.main.x");
2386 prefs_register_obsolete_preference(gui_module, "geometry.main.y");
2387 prefs_register_obsolete_preference(gui_module, "geometry.main.width");
2388 prefs_register_obsolete_preference(gui_module, "geometry.main.height");
2389 prefs_register_obsolete_preference(gui_module, "toolbar_main_show");
2391 prefs_register_enum_preference(gui_module, "toolbar_main_style",
2392 "Main Toolbar style",
2393 "Main Toolbar style",
2394 &prefs.gui_toolbar_main_style, gui_toolbar_style, FALSE);
2396 prefs_register_enum_preference(gui_module, "toolbar_filter_style",
2397 "Filter Toolbar style",
2398 "Filter Toolbar style",
2399 &prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
2401 register_string_like_preference(gui_module, "webbrowser", "The path to the webbrowser",
2402 "The path to the webbrowser (Ex: mozilla)",
2403 &prefs.gui_webbrowser, PREF_STRING, NULL, TRUE);
2405 prefs_register_bool_preference(gui_module, "update.enabled",
2406 "Check for updates",
2407 "Check for updates (Windows only)",
2408 &prefs.gui_update_enabled);
2410 prefs_register_enum_preference(gui_module, "update.channel",
2412 "The type of update to fetch. You should probably leave this set to UPDATE_CHANNEL_STABLE.",
2413 (gint*)(void*)(&prefs.gui_update_channel), gui_update_channel, FALSE);
2415 prefs_register_uint_preference(gui_module, "update.interval",
2416 "How often to check for software updates",
2417 "How often to check for software updates in seconds",
2419 &prefs.gui_update_interval);
2421 register_string_like_preference(gui_module, "window_title", "Custom window title",
2422 "Custom window title to be appended to the existing title\n%P = profile name\n%V = version info",
2423 &prefs.gui_window_title, PREF_STRING, NULL, TRUE);
2425 register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix",
2426 "Custom window title to be prepended to the existing title\n%P = profile name\n%V = version info",
2427 &prefs.gui_prepend_window_title, PREF_STRING, NULL, TRUE);
2429 register_string_like_preference(gui_module, "start_title", "Custom start page title",
2430 "Custom start page title",
2431 &prefs.gui_start_title, PREF_STRING, NULL, TRUE);
2433 prefs_register_enum_preference(gui_module, "version_placement",
2434 "Show version in the start page and/or main screen's title bar",
2435 "Show version in the start page and/or main screen's title bar",
2436 (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
2438 prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
2439 "Automatically scroll the recently expanded item",
2440 "Automatically scroll the recently expanded item",
2441 &prefs.gui_auto_scroll_on_expand);
2443 prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
2444 "The percentage down the view the recently expanded item should be scrolled",
2445 "The percentage down the view the recently expanded item should be scrolled",
2447 &prefs.gui_auto_scroll_percentage);
2449 /* User Interface : Layout */
2450 gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
2452 prefs_register_uint_preference(gui_layout_module, "layout_type",
2454 "Layout type (1-6)",
2456 (guint*)(void*)(&prefs.gui_layout_type));
2458 prefs_register_enum_preference(gui_layout_module, "layout_content_1",
2459 "Layout content of the pane 1",
2460 "Layout content of the pane 1",
2461 (gint*)(void*)(&prefs.gui_layout_content_1), gui_layout_content, FALSE);
2463 prefs_register_enum_preference(gui_layout_module, "layout_content_2",
2464 "Layout content of the pane 2",
2465 "Layout content of the pane 2",
2466 (gint*)(void*)(&prefs.gui_layout_content_2), gui_layout_content, FALSE);
2468 prefs_register_enum_preference(gui_layout_module, "layout_content_3",
2469 "Layout content of the pane 3",
2470 "Layout content of the pane 3",
2471 (gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
2473 prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
2474 "Enable Packet List Separator",
2475 "Enable Packet List Separator",
2476 &prefs.gui_qt_packet_list_separator);
2478 prefs_register_bool_preference(gui_module, "packet_editor.enabled",
2479 "Enable Packet Editor",
2480 "Enable Packet Editor (Experimental)",
2481 &prefs.gui_packet_editor);
2483 prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
2485 "The position of \"...\" in packet list text.",
2486 (gint*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, FALSE);
2488 prefs_register_bool_preference(gui_layout_module, "packet_list_show_related",
2489 "Show Related Packets",
2490 "Show related packet indicators in the first column",
2491 &prefs.gui_packet_list_show_related);
2493 prefs_register_bool_preference(gui_layout_module, "packet_list_show_minimap",
2494 "Enable Intelligent Scroll Bar",
2495 "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
2496 &prefs.gui_packet_list_show_minimap);
2498 register_string_like_preference(gui_module, "interfaces_hidden_types", "Hide interface types in list",
2499 "Hide the given interface types in the startup list",
2500 &prefs.gui_interfaces_hide_types, PREF_STRING, NULL, TRUE);
2503 * These are preferences that can be read/written using the
2504 * preference module API. These preferences still use their own
2505 * configuration screens for access, but this cuts down on the
2506 * preference "string compare list" in set_pref()
2508 console_module = prefs_register_module(NULL, "console", "Console",
2509 "Console logging and debugging output", NULL, FALSE);
2511 custom_cbs.free_cb = custom_pref_no_cb;
2512 custom_cbs.reset_cb = console_log_level_reset_cb;
2513 custom_cbs.set_cb = console_log_level_set_cb;
2514 custom_cbs.type_name_cb = console_log_level_type_name_cb;
2515 custom_cbs.type_description_cb = console_log_level_type_description_cb;
2516 custom_cbs.is_default_cb = console_log_level_is_default_cb;
2517 custom_cbs.to_str_cb = console_log_level_to_str_cb;
2518 prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
2519 "A bitmask of GLib log levels", &custom_cbs, &prefs.console_log_level);
2521 prefs_register_bool_preference(console_module, "incomplete_dissectors_check_debug",
2522 "Print debug line for incomplete dissectors",
2523 "Look for dissectors that left some bytes undecoded (debug)",
2524 &prefs.incomplete_dissectors_check_debug);
2527 * These are preferences that can be read/written using the
2528 * preference module API. These preferences still use their own
2529 * configuration screens for access, but this cuts down on the
2530 * preference "string compare list" in set_pref()
2532 capture_module = prefs_register_module(NULL, "capture", "Capture",
2533 "Capture preferences", NULL, FALSE);
2535 register_string_like_preference(capture_module, "device", "Default capture device",
2536 "Default capture device",
2537 &prefs.capture_device, PREF_STRING, NULL, FALSE);
2539 register_string_like_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
2540 "Interface link-layer header types (Ex: en0(1),en1(143),...)",
2541 &prefs.capture_devices_linktypes, PREF_STRING, NULL, FALSE);
2543 register_string_like_preference(capture_module, "devices_descr", "Interface descriptions",
2544 "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
2545 &prefs.capture_devices_descr, PREF_STRING, NULL, FALSE);
2547 register_string_like_preference(capture_module, "devices_hide", "Hide interface",
2548 "Hide interface? (Ex: eth0,eth3,...)",
2549 &prefs.capture_devices_hide, PREF_STRING, NULL, FALSE);
2551 register_string_like_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
2552 "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
2553 &prefs.capture_devices_monitor_mode, PREF_STRING, NULL, FALSE);
2555 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
2556 register_string_like_preference(capture_module, "devices_buffersize", "Interface buffer size",
2557 "Interface buffer size (Ex: en0(1),en1(143),...)",
2558 &prefs.capture_devices_buffersize, PREF_STRING, NULL, FALSE);
2561 register_string_like_preference(capture_module, "devices_snaplen", "Interface snap length",
2562 "Interface snap length (Ex: en0(65535),en1(1430),...)",
2563 &prefs.capture_devices_snaplen, PREF_STRING, NULL, FALSE);
2565 register_string_like_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
2566 "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
2567 &prefs.capture_devices_pmode, PREF_STRING, NULL, FALSE);
2569 prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
2570 "Capture in promiscuous mode?", &prefs.capture_prom_mode);
2572 register_string_like_preference(capture_module, "devices_filter", "Interface capture filter",
2573 "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
2574 &prefs.capture_devices_filter, PREF_STRING, NULL, FALSE);
2576 prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
2577 "Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
2579 prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
2580 "Update packet list in real time during capture?", &prefs.capture_real_time);
2582 /* We might want to make this a "recent" setting. */
2583 prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
2584 "Scroll packet list during capture?", &prefs.capture_auto_scroll);
2587 prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
2588 "Show capture info dialog while capturing?", &prefs.capture_show_info);
2590 prefs_register_obsolete_preference(capture_module, "syntax_check_filter");
2592 custom_cbs.free_cb = capture_column_free_cb;
2593 custom_cbs.reset_cb = capture_column_reset_cb;
2594 custom_cbs.set_cb = capture_column_set_cb;
2595 custom_cbs.type_name_cb = capture_column_type_name_cb;
2596 custom_cbs.type_description_cb = capture_column_type_description_cb;
2597 custom_cbs.is_default_cb = capture_column_is_default_cb;
2598 custom_cbs.to_str_cb = capture_column_to_str_cb;
2599 prefs_register_list_custom_preference(capture_module, "columns", "Capture options dialog column list",
2600 "List of columns to be displayed", &custom_cbs, capture_column_init_cb, &prefs.capture_columns);
2602 /* Name Resolution */
2603 nameres_module = prefs_register_module(NULL, "nameres", "Name Resolution",
2604 "Name Resolution", NULL, TRUE);
2605 addr_resolve_pref_init(nameres_module);
2606 oid_pref_init(nameres_module);
2608 geoip_db_pref_init(nameres_module);
2612 printing = prefs_register_module(NULL, "print", "Printing",
2613 "Printing", NULL, TRUE);
2615 prefs_register_enum_preference(printing, "format",
2616 "Format", "Can be one of \"text\" or \"postscript\"",
2617 &prefs.pr_format, print_format_vals, TRUE);
2619 prefs_register_enum_preference(printing, "destination",
2620 "Print to", "Can be one of \"command\" or \"file\"",
2621 &prefs.pr_dest, print_dest_vals, TRUE);
2624 register_string_like_preference(printing, "command", "Command",
2625 "Output gets piped to this command when the destination is set to \"command\"",
2626 &prefs.pr_cmd, PREF_STRING, NULL, TRUE);
2629 register_string_like_preference(printing, "file", "File",
2630 "This is the file that gets written to when the destination is set to \"file\"",
2631 &prefs.pr_file, PREF_FILENAME, NULL, TRUE);
2634 stats_module = prefs_register_module(NULL, "statistics", "Statistics",
2635 "Statistics", &stats_callback, TRUE);
2637 prefs_register_uint_preference(stats_module, "update_interval",
2638 "Tap update interval in ms",
2639 "Determines time between tap updates",
2641 &prefs.tap_update_interval);
2643 #ifdef HAVE_LIBPORTAUDIO
2644 prefs_register_uint_preference(stats_module, "rtp_player_max_visible",
2645 "Max visible channels in RTP Player",
2646 "Determines maximum height of RTP Player window",
2648 &prefs.rtp_player_max_visible);
2651 prefs_register_bool_preference(stats_module, "st_enable_burstinfo",
2652 "Enable the calculation of burst information",
2653 "If enabled burst rates will be calcuted for statistics that use the stats_tree system. "
2654 "Burst rates are calculated over a much shorter time interval than the rate column.",
2655 &prefs.st_enable_burstinfo);
2657 prefs_register_bool_preference(stats_module, "st_burst_showcount",
2658 "Show burst count for item rather than rate",
2659 "If selected the stats_tree statistics nodes will show the count of events "
2660 "within the burst window instead of a burst rate. Burst rate is calculated "
2661 "as number of events within burst window divided by the burst windown length.",
2662 &prefs.st_burst_showcount);
2664 prefs_register_uint_preference(stats_module, "st_burst_resolution",
2665 "Burst rate resolution (ms)",
2666 "Sets the duration of the time interval into which events are grouped when calculating "
2667 "the burst rate. Higher resolution (smaller number) increases processing overhead.",
2668 10,&prefs.st_burst_resolution);
2670 prefs_register_uint_preference(stats_module, "st_burst_windowlen",
2671 "Burst rate window size (ms)",
2672 "Sets the duration of the sliding window during which the burst rate is "
2673 "measured. Longer window relative to burst rate resolution increases "
2674 "processing overhead. Will be truncated to a multiple of burst resolution.",
2675 10,&prefs.st_burst_windowlen);
2677 prefs_register_enum_preference(stats_module, "st_sort_defcolflag",
2678 "Default sort column for stats_tree stats",
2679 "Sets the default column by which stats based on the stats_tree "
2680 "system is sorted.",
2681 &prefs.st_sort_defcolflag, st_sort_col_vals, FALSE);
2683 prefs_register_bool_preference(stats_module, "st_sort_defdescending",
2684 "Default stats_tree sort order is descending",
2685 "When selected, statistics based on the stats_tree system will by default "
2686 "be sorted in descending order.",
2687 &prefs.st_sort_defdescending);
2689 prefs_register_bool_preference(stats_module, "st_sort_casesensitve",
2690 "Case sensitive sort of stats_tree item names",
2691 "When selected, the item/node names of statistics based on the stats_tree "
2692 "system will be sorted taking case into account. Else the case of the name "
2694 &prefs.st_sort_casesensitve);
2696 prefs_register_bool_preference(stats_module, "st_sort_rng_nameonly",
2697 "Always sort 'range' nodes by name",
2698 "When selected, the stats_tree nodes representing a range of values "
2699 "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
2700 "node). Else range nodes are sorted by the same column as the rest of "
2702 &prefs.st_sort_rng_nameonly);
2704 prefs_register_bool_preference(stats_module, "st_sort_rng_fixorder",
2705 "Always sort 'range' nodes in ascending order",
2706 "When selected, the stats_tree nodes representing a range of values "
2707 "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
2708 "the sort direction of the tree. Only effective if \"Always sort "
2709 "'range' nodes by name\" is also selected.",
2710 &prefs.st_sort_rng_fixorder);
2712 prefs_register_bool_preference(stats_module, "st_sort_showfullname",
2713 "Display the full stats_tree plug-in name",
2714 "When selected, the full name (including menu path) of the stats_tree "
2715 "plug-in is show in windows. If cleared the plug-in name is shown "
2716 "without menu path (only the part of the name after last '/' character.)",
2717 &prefs.st_sort_showfullname);
2720 protocols_module = prefs_register_module(NULL, "protocols", "Protocols",
2721 "Protocols", NULL, TRUE);
2723 prefs_register_bool_preference(protocols_module, "display_hidden_proto_items",
2724 "Display hidden protocol items",
2725 "Display all hidden protocol items in the packet list.",
2726 &prefs.display_hidden_proto_items);
2728 prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
2729 "Display byte fields with a space character between bytes",
2730 "Display all byte fields with a space character between each byte in the packet list.",
2731 &prefs.display_byte_fields_with_spaces);
2733 prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
2734 "Look for incomplete dissectors",
2735 "Look for dissectors that left some bytes undecoded.",
2736 &prefs.enable_incomplete_dissectors_check);
2738 /* Obsolete preferences
2739 * These "modules" were reorganized/renamed to correspond to their GUI
2740 * configuration screen within the preferences dialog
2743 /* taps is now part of the stats module */
2744 prefs_register_module(NULL, "taps", "TAPS", "TAPS", NULL, FALSE);
2745 /* packet_list is now part of the protocol (parent) module */
2746 prefs_register_module(NULL, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL, FALSE);
2747 /* stream is now part of the gui module */
2748 prefs_register_module(NULL, "stream", "STREAM", "STREAM", NULL, FALSE);
2752 /* Parse through a list of comma-separated, possibly quoted strings.
2753 Return a list of the string data. */
2755 prefs_get_string_list(const gchar *str)
2757 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
2759 gint state = PRE_STRING, i = 0, j = 0;
2760 gboolean backslash = FALSE;
2762 gchar *slstr = NULL;
2765 /* Allocate a buffer for the first string. */
2766 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2771 if (cur_c == '\0') {
2772 /* It's the end of the input, so it's the end of the string we
2773 were working on, and there's no more input. */
2774 if (state == IN_QUOT || backslash) {
2775 /* We were in the middle of a quoted string or backslash escape,
2776 and ran out of characters; that's an error. */
2778 prefs_clear_string_list(sl);
2782 sl = g_list_append(sl, slstr);
2785 if (cur_c == '"' && ! backslash) {
2788 /* We hadn't yet started processing a string; this starts the
2789 string, and we're now quoting. */
2793 /* We're in the middle of a quoted string, and we saw a quotation
2794 mark; we're no longer quoting. */
2795 state = NOT_IN_QUOT;
2798 /* We're working on a string, but haven't seen a quote; we're
2805 } else if (cur_c == '\\' && ! backslash) {
2806 /* We saw a backslash, and the previous character wasn't a
2807 backslash; escape the next character.
2809 This also means we've started a new string. */
2811 if (state == PRE_STRING)
2812 state = NOT_IN_QUOT;
2813 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
2814 /* We saw a comma, and we're not in the middle of a quoted string
2815 and it wasn't preceded by a backslash; it's the end of
2816 the string we were working on... */
2818 sl = g_list_append(sl, slstr);
2820 /* ...and the beginning of a new string. */
2822 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2824 } else if (!g_ascii_isspace(cur_c) || state != PRE_STRING) {
2825 /* Either this isn't a white-space character, or we've started a
2826 string (i.e., already seen a non-white-space character for that
2827 string and put it into the string).
2829 The character is to be put into the string; do so if there's
2831 if (j < COL_MAX_LEN) {
2836 /* If it was backslash-escaped, we're done with the backslash escape. */
2844 char *join_string_list(GList *sl)
2846 GString *joined_str = g_string_new("");
2850 guint item_count = 0;
2852 cur = first = g_list_first(sl);
2855 str = (gchar *)cur->data;
2858 g_string_append_c(joined_str, ',');
2860 if (item_count % 2) {
2861 /* Wrap the line. */
2862 g_string_append(joined_str, "\n\t");
2864 g_string_append_c(joined_str, ' ');
2866 quoted_str = g_strescape(str, "");
2867 g_string_append_printf(joined_str, "\"%s\"", quoted_str);
2872 return g_string_free(joined_str, FALSE);
2876 prefs_clear_string_list(GList *sl)
2878 /* g_list_free_full() only exists since 2.28. */
2879 g_list_foreach(sl, (GFunc)g_free, NULL);
2884 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
2886 * The array must be terminated by an entry with a null "name" string.
2888 * If the string matches a "name" string in an entry, the value from that
2889 * entry is returned.
2891 * Otherwise, if a string matches a "description" string in an entry, the
2892 * value from that entry is returned; we do that for backwards compatibility,
2893 * as we used to have only a "name" string that was used both for command-line
2894 * and configuration-file values and in the GUI (which meant either that
2895 * the GUI had what might be somewhat cryptic values to select from or that
2896 * the "-o" flag took long strings, often with spaces in them).
2898 * Otherwise, the default value that was passed as the third argument is
2902 find_val_for_string(const char *needle, const enum_val_t *haystack,
2907 for (i = 0; haystack[i].name != NULL; i++) {
2908 if (g_ascii_strcasecmp(needle, haystack[i].name) == 0) {
2909 return haystack[i].value;
2912 for (i = 0; haystack[i].name != NULL; i++) {
2913 if (g_ascii_strcasecmp(needle, haystack[i].description) == 0) {
2914 return haystack[i].value;
2917 return default_value;
2921 /* Array of columns that have been migrated to custom columns */
2922 struct deprecated_columns {
2923 const gchar *col_fmt;
2924 const gchar *col_expr;
2926 static struct deprecated_columns migrated_columns[] = {
2927 { /* COL_COS_VALUE */ "%U", "vlan.priority" },
2928 { /* COL_CIRCUIT_ID */ "%c", "iax2.call" },
2929 { /* COL_BSSGP_TLLI */ "%l", "bssgp.tlli" },
2930 { /* COL_HPUX_SUBSYS */ "%H", "nettl.subsys" },
2931 { /* COL_HPUX_DEVID */ "%P", "nettl.devid" },
2932 { /* COL_FR_DLCI */ "%C", "fr.dlci" },
2933 { /* COL_REL_CONV_TIME */ "%rct", "tcp.time_relative" },
2934 { /* COL_DELTA_CONV_TIME */ "%dct", "tcp.time_delta" },
2935 { /* COL_OXID */ "%XO", "fc.ox_id" },
2936 { /* COL_RXID */ "%XR", "fc.rx_id" },
2937 { /* COL_SRCIDX */ "%Xd", "mdshdr.srcidx" },
2938 { /* COL_DSTIDX */ "%Xs", "mdshdr.dstidx" },
2939 { /* COL_DCE_CTX */ "%z", "dcerpc.cn_ctx_id" }
2943 is_deprecated_column_format(const gchar* fmt)
2947 for (haystack_idx = 0;
2948 haystack_idx < G_N_ELEMENTS(migrated_columns);
2951 if (strcmp(migrated_columns[haystack_idx].col_fmt, fmt) == 0) {
2959 /* Preferences file format:
2960 * - Configuration directives start at the beginning of the line, and
2961 * are terminated with a colon.
2962 * - Directives can be continued on the next line by preceding them with
2967 # This is a comment line
2969 print.file: /a/very/long/path/
2974 #define DEF_NUM_COLS 7
2977 * Parse a column format, filling in the relevant fields of a fmt_data.
2980 parse_column_format(fmt_data *cfmt, const char *fmt)
2982 const gchar *cust_format = col_format_to_string(COL_CUSTOM);
2983 size_t cust_format_len = strlen(cust_format);
2984 gchar **cust_format_info;
2987 gchar *col_custom_fields = NULL;
2988 long col_custom_occurrence = 0;
2989 gboolean col_resolved = TRUE;
2992 * Is this a custom column?
2994 if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
2995 strncmp(fmt, cust_format, cust_format_len) == 0) {
2997 col_fmt = COL_CUSTOM;
2998 cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
2999 col_custom_fields = g_strdup(cust_format_info[0]);
3000 if (col_custom_fields && cust_format_info[1]) {
3001 col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
3002 if (p == cust_format_info[1] || *p != '\0') {
3003 /* Not a valid number. */
3004 g_free(col_custom_fields);
3005 g_strfreev(cust_format_info);
3009 if (col_custom_fields && cust_format_info[1] && cust_format_info[2]) {
3010 col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
3012 g_strfreev(cust_format_info);
3014 col_fmt = get_column_format_from_str(fmt);
3015 if ((col_fmt == -1) && (!is_deprecated_column_format(fmt)))
3019 cfmt->fmt = col_fmt;
3020 cfmt->custom_fields = col_custom_fields;
3021 cfmt->custom_occurrence = (int)col_custom_occurrence;
3022 cfmt->resolved = col_resolved;
3026 /* Initialize non-dissector preferences to wired-in default values Called
3027 * at program startup and any time the profile changes. (The dissector
3028 * preferences are assumed to be set to those values by the dissectors.)
3029 * They may be overridden by the global preferences file or the user's
3035 if (prefs_initialized)
3041 * Ensure the "global" preferences have been initialized so the
3042 * preference API has the proper default values to work from
3046 prefs_register_modules();
3048 filter_expression_init();
3050 prefs_initialized = TRUE;
3054 * Initialize non-dissector preferences used by the "register preference" API
3055 * to default values so the default values can be used when registered.
3057 * String, filename, and directory preferences will be g_freed so they must
3061 pre_init_prefs(void)
3066 static const gchar *col_fmt[DEF_NUM_COLS*2] = {
3067 "No.", "%m", "Time", "%t",
3068 "Source", "%s", "Destination", "%d",
3069 "Protocol", "%p", "Length", "%L",
3072 prefs.pr_format = PR_FMT_TEXT;
3073 prefs.pr_dest = PR_DEST_CMD;
3074 if (prefs.pr_file) g_free(prefs.pr_file);
3075 prefs.pr_file = g_strdup("wireshark.out");
3076 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
3077 prefs.pr_cmd = g_strdup("lpr");
3079 prefs.gui_altern_colors = FALSE;
3080 prefs.gui_expert_composite_eyecandy = FALSE;
3081 prefs.gui_ptree_line_style = 0;
3082 prefs.gui_ptree_expander_style = 1;
3083 prefs.gui_hex_dump_highlight_style = 1;
3084 prefs.filter_toolbar_show_in_statusbar = FALSE;
3085 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
3086 prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
3087 /* These will be g_freed, so they must be g_mallocated. */
3088 if (prefs.gui_gtk2_font_name) g_free(prefs.gui_gtk2_font_name);
3090 prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
3092 prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
3094 /* We try to find the best font in the Qt code */
3095 if (prefs.gui_qt_font_name) g_free(prefs.gui_qt_font_name);
3096 prefs.gui_qt_font_name = g_strdup("");
3097 prefs.gui_marked_fg.red = 65535;
3098 prefs.gui_marked_fg.green = 65535;
3099 prefs.gui_marked_fg.blue = 65535;
3100 prefs.gui_marked_bg.red = 0;
3101 prefs.gui_marked_bg.green = 8224;
3102 prefs.gui_marked_bg.blue = 10794;
3103 prefs.gui_ignored_fg.red = 32767;
3104 prefs.gui_ignored_fg.green = 32767;
3105 prefs.gui_ignored_fg.blue = 32767;
3106 prefs.gui_ignored_bg.red = 65535;
3107 prefs.gui_ignored_bg.green = 65535;
3108 prefs.gui_ignored_bg.blue = 65535;
3109 if (prefs.gui_colorized_fg) g_free(prefs.gui_colorized_fg);
3110 prefs.gui_colorized_fg = g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
3111 if (prefs.gui_colorized_bg) g_free(prefs.gui_colorized_bg);
3112 prefs.gui_colorized_bg = g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
3113 prefs.st_client_fg.red = 32767;
3114 prefs.st_client_fg.green = 0;
3115 prefs.st_client_fg.blue = 0;
3116 prefs.st_client_bg.red = 64507;
3117 prefs.st_client_bg.green = 60909;
3118 prefs.st_client_bg.blue = 60909;
3119 prefs.st_server_fg.red = 0;
3120 prefs.st_server_fg.green = 0;
3121 prefs.st_server_fg.blue = 32767;
3122 prefs.st_server_bg.red = 60909;
3123 prefs.st_server_bg.green = 60909;
3124 prefs.st_server_bg.blue = 64507;
3125 prefs.gui_text_valid.red = 0xAFFF; /* light green */
3126 prefs.gui_text_valid.green = 0xFFFF;
3127 prefs.gui_text_valid.blue = 0xAFFF;
3128 prefs.gui_text_invalid.red = 0xFFFF; /* light red */
3129 prefs.gui_text_invalid.green = 0xAFFF;
3130 prefs.gui_text_invalid.blue = 0xAFFF;
3131 prefs.gui_text_deprecated.red = 0xFFFF; /* light yellow */
3132 prefs.gui_text_deprecated.green = 0xFFFF;
3133 prefs.gui_text_deprecated.blue = 0xAFFF;
3134 prefs.gui_geometry_save_position = TRUE;
3135 prefs.gui_geometry_save_size = TRUE;
3136 prefs.gui_geometry_save_maximized= TRUE;
3137 prefs.gui_macosx_style = TRUE;
3138 prefs.gui_console_open = console_open_never;
3139 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
3140 prefs.gui_recent_df_entries_max = 10;
3141 prefs.gui_recent_files_count_max = 10;
3142 if (prefs.gui_fileopen_dir) g_free(prefs.gui_fileopen_dir);
3143 prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
3144 prefs.gui_fileopen_preview = 3;
3145 prefs.gui_ask_unsaved = TRUE;
3146 prefs.gui_find_wrap = TRUE;
3147 prefs.gui_use_pref_save = FALSE;
3148 prefs.gui_update_enabled = TRUE;
3149 prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
3150 prefs.gui_update_interval = 60*60*24; /* Seconds */
3151 if (prefs.gui_webbrowser) g_free(prefs.gui_webbrowser);
3152 prefs.gui_webbrowser = g_strdup("");
3153 if (prefs.gui_window_title) g_free(prefs.gui_window_title);
3154 prefs.gui_window_title = g_strdup("");
3155 if (prefs.gui_prepend_window_title) g_free(prefs.gui_prepend_window_title);
3156 prefs.gui_prepend_window_title = g_strdup("");
3157 if (prefs.gui_start_title) g_free(prefs.gui_start_title);
3158 prefs.gui_start_title = g_strdup("The World's Most Popular Network Protocol Analyzer");
3159 prefs.gui_version_placement = version_both;
3160 prefs.gui_auto_scroll_on_expand = FALSE;
3161 prefs.gui_auto_scroll_percentage = 0;
3162 prefs.gui_layout_type = layout_type_5;
3163 prefs.gui_layout_content_1 = layout_pane_content_plist;
3164 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
3165 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
3166 prefs.gui_packet_editor = FALSE;
3167 prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
3168 prefs.gui_packet_list_show_related = TRUE;
3169 prefs.gui_packet_list_show_minimap = TRUE;
3170 if (prefs.gui_interfaces_hide_types) g_free (prefs.gui_interfaces_hide_types);
3171 prefs.gui_interfaces_hide_types = g_strdup("");
3173 prefs.gui_qt_packet_list_separator = FALSE;
3175 if (prefs.col_list) {
3176 free_col_info(prefs.col_list);
3177 prefs.col_list = NULL;
3179 for (i = 0; i < DEF_NUM_COLS; i++) {
3180 cfmt = g_new(fmt_data,1);
3181 cfmt->title = g_strdup(col_fmt[i * 2]);
3182 parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
3183 cfmt->visible = TRUE;
3184 cfmt->resolved = TRUE;
3185 cfmt->custom_fields = NULL;
3186 cfmt->custom_occurrence = 0;
3187 prefs.col_list = g_list_append(prefs.col_list, cfmt);
3189 prefs.num_cols = DEF_NUM_COLS;
3191 /* set the default values for the capture dialog box */
3192 prefs.capture_prom_mode = TRUE;
3193 #ifdef PCAP_NG_DEFAULT
3194 prefs.capture_pcap_ng = TRUE;
3196 prefs.capture_pcap_ng = FALSE;
3198 prefs.capture_real_time = TRUE;
3199 prefs.capture_auto_scroll = TRUE;
3200 prefs.capture_show_info = FALSE;
3202 if (!prefs.capture_columns) {
3203 /* First time through */
3204 for (i = 0; i < num_capture_cols; i++) {
3205 col_name = g_strdup(capture_cols[i]);
3206 prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3210 prefs.console_log_level =
3211 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
3213 /* set the default values for the tap/statistics dialog box */
3214 prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL;
3215 prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
3216 prefs.st_enable_burstinfo = TRUE;
3217 prefs.st_burst_showcount = FALSE;
3218 prefs.st_burst_resolution = ST_DEF_BURSTRES;
3219 prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
3220 prefs.st_sort_casesensitve = TRUE;
3221 prefs.st_sort_rng_fixorder = TRUE;
3222 prefs.st_sort_rng_nameonly = TRUE;
3223 prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
3224 prefs.st_sort_defdescending = TRUE;
3225 prefs.st_sort_showfullname = FALSE;
3226 prefs.display_hidden_proto_items = FALSE;
3227 prefs.display_byte_fields_with_spaces = FALSE;
3231 * Reset a single dissector preference.
3234 reset_pref(pref_t *pref)
3242 * This preference is no longer supported; it's not a
3243 * real preference, so we don't reset it (i.e., we
3244 * treat it as if it weren't found in the list of
3245 * preferences, and we weren't called in the first place).
3247 if (IS_PREF_OBSOLETE(type))
3250 RESET_PREF_OBSOLETE(type);
3255 case PREF_DECODE_AS_UINT:
3256 *pref->varp.uint = pref->default_val.uint;
3260 *pref->varp.boolp = pref->default_val.boolval;
3265 * For now, we save the "description" value, so that if we
3266 * save the preferences older versions of Wireshark can at
3267 * least read preferences that they supported; we support
3268 * either the short name or the description when reading
3269 * the preferences file or a "-o" option.
3271 *pref->varp.enump = pref->default_val.enumval;
3277 reset_string_like_preference(pref);
3281 case PREF_DECODE_AS_RANGE:
3282 g_free(*pref->varp.range);
3283 *pref->varp.range = range_copy(pref->default_val.range);
3286 case PREF_STATIC_TEXT:
3292 *pref->varp.colorp = pref->default_val.color;
3296 pref->custom_cbs.reset_cb(pref);
3302 reset_pref_cb(gpointer data, gpointer user_data _U_)
3304 pref_t *pref = (pref_t *) data;
3313 * Reset all preferences for a module.
3316 reset_module_prefs(const void *key _U_, void *value, void *data _U_)
3318 reset_pref_arg_t arg;
3320 arg.module = (module_t *)value;
3321 g_list_foreach(arg.module->prefs, reset_pref_cb, &arg);
3325 /* Reset preferences */
3329 prefs_initialized = FALSE;
3330 g_free(prefs.saved_at_version);
3331 prefs.saved_at_version = NULL;
3334 * Unload all UAT preferences.
3339 * Unload any loaded MIBs.
3344 * Free the filter expression list.
3346 filter_expression_free(*pfilter_expression_head);
3347 *pfilter_expression_head = NULL;
3350 * Reset the non-dissector preferences.
3355 * Reset the non-UAT dissector preferences.
3357 wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
3360 /* Read the preferences file, fill in "prefs", and return a pointer to it.
3362 If we got an error (other than "it doesn't exist") trying to read
3363 the global preferences file, stuff the errno into "*gpf_errno_return"
3364 and a pointer to the path of the file into "*gpf_path_return", and
3367 If we got an error (other than "it doesn't exist") trying to read
3368 the user's preferences file, stuff the errno into "*pf_errno_return"
3369 and a pointer to the path of the file into "*pf_path_return", and
3372 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
3373 char **gpf_path_return, int *pf_errno_return,
3374 int *pf_read_errno_return, char **pf_path_return)
3380 /* clean up libsmi structures before reading prefs */
3386 * If we don't already have the pathname of the global preferences
3387 * file, construct it. Then, in either case, try to open the file.
3389 if (gpf_path == NULL) {
3391 * We don't have the path; try the new path first, and, if that
3392 * file doesn't exist, try the old path.
3394 gpf_path = get_datafile_path(PF_NAME);
3395 if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
3397 * It doesn't exist by the new name; try the old name.
3400 gpf_path = get_datafile_path(OLD_GPF_NAME);
3401 pf = ws_fopen(gpf_path, "r");
3405 * We have the path; try it.
3407 pf = ws_fopen(gpf_path, "r");
3411 * If we were able to open the file, read it.
3412 * XXX - if it failed for a reason other than "it doesn't exist",
3415 *gpf_path_return = NULL;
3418 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3421 mgcp_tcp_port_count = 0;
3422 mgcp_udp_port_count = 0;
3424 /* We succeeded in opening it; read it. */
3425 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
3427 /* We had an error reading the file; return the errno and the
3428 pathname, so our caller can report the error. */
3429 *gpf_errno_return = 0;
3430 *gpf_read_errno_return = err;
3431 *gpf_path_return = gpf_path;
3435 /* We failed to open it. If we failed for some reason other than
3436 "it doesn't exist", return the errno and the pathname, so our
3437 caller can report the error. */
3438 if (errno != ENOENT) {
3439 *gpf_errno_return = errno;
3440 *gpf_read_errno_return = 0;
3441 *gpf_path_return = gpf_path;
3445 /* Construct the pathname of the user's preferences file. */
3446 pf_path = get_persconffile_path(PF_NAME, TRUE);
3448 /* Read the user's preferences file, if it exists. */
3449 *pf_path_return = NULL;
3450 if ((pf = ws_fopen(pf_path, "r")) != NULL) {
3452 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
3455 mgcp_tcp_port_count = 0;
3456 mgcp_udp_port_count = 0;
3458 /* We succeeded in opening it; read it. */
3459 err = read_prefs_file(pf_path, pf, set_pref, NULL);
3461 /* We had an error reading the file; return the errno and the
3462 pathname, so our caller can report the error. */
3463 *pf_errno_return = 0;
3464 *pf_read_errno_return = err;
3465 *pf_path_return = pf_path;
3470 /* We failed to open it. If we failed for some reason other than
3471 "it doesn't exist", return the errno and the pathname, so our
3472 caller can report the error. */
3473 if (errno != ENOENT) {
3474 *pf_errno_return = errno;
3475 *pf_read_errno_return = 0;
3476 *pf_path_return = pf_path;
3481 /* load SMI modules if needed */
3487 /* read the preferences file (or similar) and call the callback
3488 * function to set each key/value pair found */
3490 read_prefs_file(const char *pf_path, FILE *pf,
3491 pref_set_pair_cb pref_set_pair_fct, void *private_data)
3494 START, /* beginning of a line */
3495 IN_VAR, /* processing key name */
3496 PRE_VAL, /* finished processing key name, skipping white space befor evalue */
3497 IN_VAL, /* processing value */
3498 IN_SKIP /* skipping to the end of the line */
3503 gboolean got_val = FALSE;
3504 gint fline = 1, pline = 1;
3505 gchar hint[] = "(save preferences to remove this warning)";
3508 cur_val = g_string_new("");
3509 cur_var = g_string_new("");
3511 /* Try to read in the profile name in the first line of the preferences file. */
3512 if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
3513 /* Assume trailing period and remove it */
3514 g_free(prefs.saved_at_version);
3515 prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
3519 while ((got_c = ws_getc_unlocked(pf)) != EOF) {
3520 if (got_c == '\r') {
3521 /* Treat CR-LF at the end of a line like LF, so that if we're reading
3522 * a Windows-format file on UN*X, we handle it the same way we'd handle
3523 * a UN*X-format file. */
3524 got_c = ws_getc_unlocked(pf);
3527 if (got_c != '\n') {
3528 /* Put back the character after the CR, and process the CR normally. */
3533 if (got_c == '\n') {
3541 if (g_ascii_isalnum(got_c)) {
3542 if (cur_var->len > 0) {
3544 if (cur_val->len > 0) {
3545 if (cur_val->str[cur_val->len-1] == ',') {
3547 * If the pref has a trailing comma, eliminate it.
3549 cur_val->str[cur_val->len-1] = '\0';
3550 ws_g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
3553 /* Call the routine to set the preference; it will parse
3554 the value as appropriate.
3556 Since we're reading a file, rather than processing
3557 explicit user input, for range preferences, silently
3558 lower values in excess of the range's maximum, rather
3559 than reporting errors and failing. */
3560 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3565 case PREFS_SET_SYNTAX_ERR:
3566 ws_g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
3567 cur_var->str, pline, pf_path, hint);
3570 case PREFS_SET_NO_SUCH_PREF:
3572 * If "print.command" silently ignore it because it's valid
3573 * on non-Win32 platforms.
3575 if (strcmp(cur_var->str, "print.command") != 0)
3576 ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3577 cur_var->str, pline, pf_path, hint);
3578 prefs.unknown_prefs = TRUE;
3581 case PREFS_SET_OBSOLETE:
3582 if (strcmp(cur_var->str, "print.command") != 0)
3583 /* If an attempt is made to save the preferences, a popup warning will be
3584 displayed stating that obsolete prefs have been detected and the user will
3585 be given the opportunity to save these prefs under a different profile name.
3586 The prefs in question need to be listed in the console window so that the
3587 user can make an informed choice.
3589 ws_g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
3590 cur_var->str, pline, pf_path, hint);
3591 prefs.unknown_prefs = TRUE;
3595 ws_g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
3600 g_string_truncate(cur_var, 0);
3601 g_string_append_c(cur_var, (gchar) got_c);
3603 } else if (g_ascii_isspace(got_c) && cur_var->len > 0 && got_val) {
3605 } else if (got_c == '#') {
3608 ws_g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
3613 g_string_append_c(cur_var, (gchar) got_c);
3615 /* This is a colon (':') */
3617 g_string_truncate(cur_val, 0);
3619 * Set got_val to TRUE to accommodate prefs such as
3620 * "gui.fileopen.dir" that do not require a value.
3626 if (!g_ascii_isspace(got_c)) {
3628 g_string_append_c(cur_val, (gchar) got_c);
3632 g_string_append_c(cur_val, (gchar) got_c);
3638 if (cur_var->len > 0) {
3640 /* Call the routine to set the preference; it will parse
3641 the value as appropriate.
3643 Since we're reading a file, rather than processing
3644 explicit user input, for range preferences, silently
3645 lower values in excess of the range's maximum, rather
3646 than reporting errors and failing. */
3647 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
3652 case PREFS_SET_SYNTAX_ERR:
3653 ws_g_warning ("Syntax error in preference %s at line %d of\n%s %s",
3654 cur_var->str, pline, pf_path, hint);
3657 case PREFS_SET_NO_SUCH_PREF:
3658 ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
3659 cur_var->str, pline, pf_path, hint);
3660 prefs.unknown_prefs = TRUE;
3663 case PREFS_SET_OBSOLETE:
3664 prefs.unknown_prefs = TRUE;
3668 ws_g_warning("Incomplete preference at line %d of\n%s %s",
3669 pline, pf_path, hint);
3673 g_string_free(cur_val, TRUE);
3674 g_string_free(cur_var, TRUE);
3683 * If we were handed a preference starting with "uat:", try to turn it into
3684 * a valid uat entry.
3687 prefs_set_uat_pref(char *uat_entry) {
3693 colonp = strchr(uat_entry, ':');
3701 * Skip over any white space (there probably won't be any, but
3702 * as we allow it in the preferences file, we might as well
3705 while (g_ascii_isspace(*p))
3709 * Put the colon back, so if our caller uses, in an
3710 * error message, the string they passed us, the message
3717 uat = uat_find(uat_entry);
3723 ret = uat_load_str(uat, p, &err);
3729 * Given a string of the form "<pref name>:<pref value>", as might appear
3730 * as an argument to a "-o" option, parse it and set the preference in
3731 * question. Return an indication of whether it succeeded or failed
3735 prefs_set_pref(char *prefarg)
3738 prefs_set_pref_e ret;
3741 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
3742 * seen to values that keep us from trying to interpret them
3743 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
3744 * as, from the command line, we have no way of guessing which
3745 * the user had in mind.
3747 mgcp_tcp_port_count = -1;
3748 mgcp_udp_port_count = -1;
3750 colonp = strchr(prefarg, ':');
3752 return PREFS_SET_SYNTAX_ERR;
3758 * Skip over any white space (there probably won't be any, but
3759 * as we allow it in the preferences file, we might as well
3762 while (g_ascii_isspace(*p))
3766 * Put the colon back, so if our caller uses, in an
3767 * error message, the string they passed us, the message
3771 return PREFS_SET_SYNTAX_ERR;
3773 if (strcmp(prefarg, "uat")) {
3774 ret = set_pref(prefarg, p, NULL, TRUE);
3776 ret = prefs_set_uat_pref(p) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
3778 *colonp = ':'; /* put the colon back */
3783 * Returns TRUE if the given device is hidden
3786 prefs_is_capture_device_hidden(const char *name)
3788 gchar *tok, *devices;
3791 if (prefs.capture_devices_hide && name) {
3792 devices = g_strdup (prefs.capture_devices_hide);
3793 len = strlen (name);
3794 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3795 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3807 * Returns TRUE if the given column is visible (not hidden)
3810 prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
3813 fmt_data cfmt_hidden;
3816 * Do we have a list of hidden columns?
3820 * Yes - check the column against each of the ones in the
3823 cols = g_strdup(cols_hidden);
3824 for (tok = strtok(cols, ","); tok; tok = strtok(NULL, ",")) {
3825 tok = g_strstrip(tok);
3828 * Parse this column format.
3830 if (!parse_column_format(&cfmt_hidden, tok)) {
3832 * It's not valid; ignore it.
3838 * Does it match the column?
3840 if (cfmt->fmt != cfmt_hidden.fmt) {
3842 g_free(cfmt_hidden.custom_fields);
3843 cfmt_hidden.custom_fields = NULL;
3846 if (cfmt->fmt == COL_CUSTOM) {
3848 * A custom column has to have the
3849 * same custom field and occurrence.
3851 if (cfmt_hidden.custom_fields && cfmt->custom_fields) {
3852 if (strcmp(cfmt->custom_fields,
3853 cfmt_hidden.custom_fields) != 0) {
3854 /* Different fields. */
3855 g_free(cfmt_hidden.custom_fields);
3856 cfmt_hidden.custom_fields = NULL;
3859 if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
3860 /* Different occurrences. */
3861 g_free(cfmt_hidden.custom_fields);
3862 cfmt_hidden.custom_fields = NULL;
3869 * OK, they match, so it's one of the hidden fields,
3870 * hence not visible.
3872 g_free(cfmt_hidden.custom_fields);
3880 * No - either there are no hidden columns or this isn't one
3881 * of them - so it is visible.
3887 * Returns TRUE if the given device should capture in monitor mode by default
3890 prefs_capture_device_monitor_mode(const char *name)
3892 gchar *tok, *devices;
3895 if (prefs.capture_devices_monitor_mode && name) {
3896 devices = g_strdup (prefs.capture_devices_monitor_mode);
3897 len = strlen (name);
3898 for (tok = strtok (devices, ","); tok; tok = strtok(NULL, ",")) {
3899 if (strlen (tok) == len && strcmp (name, tok) == 0) {
3911 * Returns TRUE if the user has marked this column as visible
3914 prefs_capture_options_dialog_column_is_visible(const gchar *column)
3919 for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
3920 col = (gchar *)curr->data;
3921 if (col && (g_ascii_strcasecmp(col, column) == 0)) {
3928 #define PRS_GUI_FILTER_LABEL "gui.filter_expressions.label"
3929 #define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
3930 #define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
3933 * Extract the red, green, and blue components of a 24-bit RGB value
3934 * and convert them from [0,255] to [0,65535].
3936 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
3937 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
3938 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
3941 string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
3945 memset(name_resolve, 0, sizeof(e_addr_resolve));
3946 while ((c = *string++) != '\0') {
3949 name_resolve->mac_name = TRUE;
3952 name_resolve->network_name = TRUE;
3955 name_resolve->use_external_net_name_resolver = TRUE;
3958 name_resolve->transport_name = TRUE;
3962 /* name_resolve->concurrent_dns */
3965 name_resolve->dns_pkt_addr_resolution = TRUE;
3968 name_resolve->vlan_name = TRUE;
3972 * Unrecognized letter.
3981 try_convert_to_custom_column(gpointer *el_data)
3985 gchar **fmt = (gchar **) el_data;
3987 for (haystack_idx = 0;
3988 haystack_idx < G_N_ELEMENTS(migrated_columns);
3991 if (strcmp(migrated_columns[haystack_idx].col_fmt, *fmt) == 0) {
3992 gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
3993 migrated_columns[haystack_idx].col_expr);
4002 deprecated_heur_dissector_pref(gchar *pref_name, const gchar *value)
4004 struct heur_pref_name
4006 const char* pref_name;
4007 const char* short_name;
4008 gboolean more_dissectors; /* For multiple dissectors controlled by the same preference */
4011 struct heur_pref_name heur_prefs[] = {
4012 {"acn.heuristic_acn", "acn_udp", 0},
4013 {"bfcp.enable", "bfcp_tcp", 1},
4014 {"bfcp.enable", "bfcp_udp", 0},
4015 {"bt-dht.enable", "bittorrent_dht_udp", 0},
4016 {"bt-utp.enable", "bt_utp_udp", 0},
4017 {"cattp.enable", "cattp_udp", 0},
4018 {"cfp.enable", "fp_eth", 0},
4019 {"dicom.heuristic", "dicom_tcp", 0},
4020 {"dnp3.heuristics", "dnp3_tcp", 1},
4021 {"dnp3.heuristics", "dnp3_udp", 0},
4022 {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
4023 {"esl.enable", "esl_eth", 0},
4024 {"fp.udp_heur", "fp_udp", 0},
4025 {"gvsp.enable_heuristic", "gvsp_udp", 0},
4026 {"hdcp2.enable", "hdcp2_tcp", 0},
4027 {"hislip.enable_heuristic", "hislip_tcp", 0},
4028 {"jxta.udp.heuristic", "jxta_udp", 0},
4029 {"jxta.tcp.heuristic", "jxta_tcp", 0},
4030 {"jxta.sctp.heuristic", "jxta_sctp", 0},
4031 {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
4032 {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
4033 {"norm.heuristic_norm", "rmt_norm_udp", 0},
4034 {"openflow.heuristic", "openflow_tcp", 0},
4035 {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
4036 {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
4037 {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
4038 {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
4039 {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
4040 {"rtp.heuristic_rtp", "rtp_udp", 1},
4041 {"rtp.heuristic_rtp", "rtp_stun", 0},
4042 {"teredo.heuristic_teredo", "teredo_udp", 0},
4043 {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
4044 {"xml.heuristic", "xml_http", 1},
4045 {"xml.heuristic", "xml_sip", 1},
4046 {"xml.heuristic", "xml_media", 0},
4047 {"xml.heuristic_tcp", "xml_tcp", 0},
4048 {"xml.heuristic_udp", "xml_udp", 0},
4052 heur_dtbl_entry_t* heuristic;
4055 for (i = 0; i < sizeof(heur_prefs)/sizeof(struct heur_pref_name); i++)
4057 if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
4059 heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
4060 if (heuristic != NULL) {
4061 heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE);
4064 if (!heur_prefs[i].more_dissectors)
4074 deprecated_port_pref(gchar *pref_name, const gchar *value)
4076 struct port_pref_name
4078 const char* pref_name;
4079 const char* module_name;
4080 const char* table_name;
4084 struct obsolete_pref_name
4086 const char* pref_name;
4089 /* For now this is only supporting TCP/UDP port dissector preferences
4090 which are assumed to be decimal */
4091 struct port_pref_name port_prefs[] = {
4093 {"cmp.tcp_alternate_port", "CMP", "tcp.port", 10},
4094 {"h248.tcp_port", "H248", "tcp.port", 10},
4095 {"cops.tcp.cops_port", "COPS", "tcp.port", 10},
4096 {"dhcpfo.tcp_port", "DHCPFO", "tcp.port", 10},
4097 {"enttec.tcp_port", "ENTTEC", "tcp.port", 10},
4098 {"forces.tcp_alternate_port", "ForCES", "tcp.port", 10},
4099 {"ged125.tcp_port", "GED125", "tcp.port", 10},
4100 {"hpfeeds.dissector_port", "HPFEEDS", "tcp.port", 10},
4101 {"lsc.port", "LSC", "tcp.port", 10},
4102 {"megaco.tcp.txt_port", "MEGACO", "tcp.port", 10},
4103 {"netsync.tcp_port", "Netsync", "tcp.port", 10},
4104 {"osi.tpkt_port", "OSI", "tcp.port", 10},
4105 {"rsync.tcp_port", "RSYNC", "tcp.port", 10},
4106 {"sametime.tcp_port", "SAMETIME", "tcp.port", 10},
4107 {"sigcomp.tcp.port2", "SIGCOMP", "tcp.port", 10},
4108 {"synphasor.tcp_port", "SYNCHROPHASOR", "tcp.port", 10},
4109 {"tipc.alternate_port", "TIPC", "tcp.port", 10},
4110 {"vnc.alternate_port", "VNC", "tcp.port", 10},
4111 {"scop.port", "SCoP", "tcp.port", 10},
4112 {"scop.port_secure", "SCoP", "tcp.port", 10},
4114 {"h248.udp_port", "H248", "udp.port", 10},
4115 {"actrace.udp_port", "ACtrace", "udp.port", 10},
4116 {"brp.port", "BRP", "udp.port", 10},
4117 {"bvlc.additional_udp_port", "BVLC", "udp.port", 10},
4118 {"capwap.udp.port.control", "CAPWAP-CONTROL", "udp.port", 10},
4119 {"capwap.udp.port.data", "CAPWAP-CONTROL", "udp.port", 10},
4120 {"coap.udp_port", "CoAP", "udp.port", 10},
4121 {"enttec.udp_port", "ENTTEC", "udp.port", 10},
4122 {"forces.udp_alternate_port", "ForCES", "udp.port", 10},
4123 {"ldss.udp_port", "LDSS", "udp.port", 10},
4124 {"lmp.udp_port", "LMP", "udp.port", 10},
4125 {"ltp.port", "LTP", "udp.port", 10},
4126 {"lwres.udp.lwres_port", "LWRES", "udp.port", 10},
4127 {"megaco.udp.txt_port", "MEGACO", "udp.port", 10},
4128 {"pgm.udp.encap_ucast_port", "PGM", "udp.port", 10},
4129 {"pgm.udp.encap_mcast_port", "PGM", "udp.port", 10},
4130 {"quic.udp.quic.port", "QUIC", "udp.port", 10},
4131 {"quic.udp.quics.port", "QUIC", "udp.port", 10},
4132 {"radius.alternate_port", "RADIUS", "udp.port", 10},
4133 {"rdt.default_udp_port", "RDT", "udp.port", 10},
4134 {"alc.default.udp_port", "ALC", "udp.port", 10},
4135 {"sigcomp.udp.port2", "SIGCOMP", "udp.port", 10},
4136 {"synphasor.udp_port", "SYNCHROPHASOR", "udp.port", 10},
4137 {"tdmop.udpport", "TDMoP", "udp.port", 10},
4138 {"uaudp.port1", "UAUDP", "udp.port", 10},
4139 {"uaudp.port2", "UAUDP", "udp.port", 10},
4140 {"uaudp.port3", "UAUDP", "udp.port", 10},
4141 {"uaudp.port4", "UAUDP", "udp.port", 10},
4142 {"uhd.dissector_port", "UHD", "udp.port", 10},
4143 {"vrt.dissector_port", "VITA 49", "udp.port", 10},
4144 {"vuze-dht.udp_port", "Vuze-DHT", "udp.port", 10},
4145 {"wimaxasncp.udp.wimax_port", "WiMAX ASN CP", "udp.port", 10},
4148 struct port_pref_name port_range_prefs[] = {
4150 {"couchbase.tcp.ports", "Couchbase", "tcp.port", 10},
4151 {"gsm_ipa.tcp_ports", "GSM over IP", "tcp.port", 10},
4152 {"kafka.tcp.ports", "Kafka", "tcp.port", 10},
4153 {"kt.tcp.ports", "Kyoto Tycoon", "tcp.port", 10},
4154 {"memcache.tcp.ports", "MEMCACHE", "tcp.port", 10},
4155 {"mrcpv2.tcp.port_range", "MRCPv2", "tcp.port", 10},
4156 {"rtsp.tcp.port_range", "RTSP", "tcp.port", 10},
4157 {"sip.tcp.ports", "SIP", "tcp.port", 10},
4158 {"tds.tcp_ports", "TDS", "tcp.port", 10},
4159 {"uma.tcp.ports", "UMA", "tcp.port", 10},
4161 {"aruba_erm.udp.ports", "ARUBA_ERM", "udp.port", 10},
4162 {"diameter.udp.ports", "DIAMETER", "udp.port", 10},
4163 {"dmp.udp_ports", "DMP", "udp.port", 10},
4164 {"dns.udp.ports", "DNS", "udp.port", 10},
4165 {"gsm_ipa.udp_ports", "GSM over IP", "udp.port", 10},
4166 {"hcrt.dissector_udp_port", "HCrt", "udp.port", 10},
4167 {"memcache.udp.ports", "MEMCACHE", "udp.port", 10},
4168 {"nb_rtpmux.udp_ports", "NB_RTPMUX", "udp.port", 10},
4169 {"gprs-ns.udp.ports", "GPRS-NS", "udp.port", 10},
4170 {"p_mul.udp_ports", "P_MUL", "udp.port", 10},
4171 {"radius.ports", "RADIUS", "udp.port", 10},
4172 {"sflow.ports", "sFlow", "udp.port", 10},
4173 {"sscop.udp.ports", "SSCOP", "udp.port", 10},
4174 {"tftp.udp_ports", "TFTP", "udp.port", 10},
4175 {"tipc.udp.ports", "TIPC", "udp.port", 10},
4178 /* These are subdissectors of TPKT/OSITP that used to have a
4179 TCP port preference even though they were never
4180 directly on TCP. Convert them to use Decode As
4181 with the TPKT dissector handle */
4182 struct port_pref_name tpkt_subdissector_port_prefs[] = {
4183 {"dap.tcp.port", "DAP", "tcp.port", 10},
4184 {"disp.tcp.port", "DISP", "tcp.port", 10},
4185 {"dop.tcp.port", "DOP", "tcp.port", 10},
4186 {"dsp.tcp.port", "DSP", "tcp.port", 10},
4187 {"p1.tcp.port", "P1", "tcp.port", 10},
4188 {"p7.tcp.port", "P7", "tcp.port", 10},
4189 {"rdp.tcp.port", "RDP", "tcp.port", 10},
4192 /* These are obsolete preferences from the dissectors' view,
4193 (typically because of a switch from a single value to a
4194 range value) but the name of the preference conflicts
4195 with the generated preference name from the dissector table.
4196 Don't allow the obsolete preference through to be handled */
4197 struct obsolete_pref_name obsolete_prefs[] = {
4198 {"diameter.tcp.port"},
4200 {"mrcpv2.tcp.port"},
4209 dissector_table_t sub_dissectors;
4210 dissector_handle_t handle, tpkt_handle;
4212 for (i = 0; i < sizeof(port_prefs)/sizeof(struct port_pref_name); i++)
4214 if (strcmp(pref_name, port_prefs[i].pref_name) == 0)
4216 /* XXX - give an error if it doesn't fit in a guint? */
4217 uval = (guint)strtoul(value, &p, port_prefs[i].base);
4218 if (p == value || *p != '\0')
4219 return FALSE; /* number was bad */
4221 /* If the value is zero, it wouldn't add to the Decode As tables */
4224 sub_dissectors = find_dissector_table(port_prefs[i].table_name);
4225 if (sub_dissectors != NULL) {
4226 handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_prefs[i].module_name);
4227 if (handle != NULL) {
4228 dissector_change_uint(port_prefs[i].table_name, uval, handle);
4229 decode_build_reset_list(port_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
4238 for (i = 0; i < sizeof(port_range_prefs)/sizeof(struct port_pref_name); i++)
4240 if (strcmp(pref_name, port_range_prefs[i].pref_name) == 0)
4243 guint32 range_i, range_j;
4244 guint32 max_value = 0;
4246 sub_dissectors = find_dissector_table(port_range_prefs[i].table_name);
4247 if (sub_dissectors != NULL) {
4248 /* Max value is based on datatype of dissector table */
4249 switch (dissector_table_get_type(sub_dissectors)) {
4257 max_value = 0xFFFFFF;
4260 max_value = 0xFFFFFFFF;
4264 g_error("The dissector table %s (%s) is not an integer type - are you using a buggy plugin?", port_range_prefs[i].table_name, get_dissector_table_ui_name(port_range_prefs[i].table_name));
4265 g_assert_not_reached();
4268 if (range_convert_str_work(&newrange, value, max_value,
4269 TRUE) != CVT_NO_ERROR) {
4270 return FALSE; /* number was bad */
4273 handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_range_prefs[i].module_name);
4274 if (handle != NULL) {
4276 for (range_i = 0; range_i < newrange->nranges; range_i++) {
4277 for (range_j = newrange->ranges[range_i].low; range_j < newrange->ranges[range_i].high; range_j++) {
4278 dissector_change_uint(port_range_prefs[i].table_name, range_j, handle);
4279 decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(range_j), NULL, NULL);
4282 dissector_change_uint(port_range_prefs[i].table_name, newrange->ranges[range_i].high, handle);
4283 decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[range_i].high), NULL, NULL);
4294 for (i = 0; i < sizeof(tpkt_subdissector_port_prefs)/sizeof(struct port_pref_name); i++)
4296 if (strcmp(pref_name, tpkt_subdissector_port_prefs[i].pref_name) == 0)
4298 /* XXX - give an error if it doesn't fit in a guint? */
4299 uval = (guint)strtoul(value, &p, tpkt_subdissector_port_prefs[i].base);
4300 if (p == value || *p != '\0')
4301 return FALSE; /* number was bad */
4303 /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
4304 if ((uval != 0) && (uval != 102))
4306 tpkt_handle = find_dissector("tpkt");
4307 if (tpkt_handle != NULL) {
4308 dissector_change_uint(tpkt_subdissector_port_prefs[i].table_name, uval, tpkt_handle);
4316 for (i = 0; i < sizeof(obsolete_prefs)/sizeof(struct obsolete_pref_name); i++)
4318 if (strcmp(pref_name, obsolete_prefs[i].pref_name) == 0)
4320 /* Just ignore the preference */
4327 static prefs_set_pref_e
4328 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
4329 gboolean return_range_errors)
4331 unsigned long int cval;
4336 gchar *dotp, *last_dotp;
4337 static gchar *filter_label = NULL;
4338 static gboolean filter_enabled = FALSE;
4339 gchar *filter_expr = NULL;
4340 module_t *module, *containing_module;
4344 if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
4345 filter_label = g_strdup(value);
4346 } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
4347 filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
4348 } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
4349 filter_expr = g_strdup(value);
4350 filter_expression_new(filter_label, filter_expr, filter_enabled);
4351 g_free(filter_label);
4352 g_free(filter_expr);
4353 } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
4354 /* Convert deprecated value to closest current equivalent */
4355 if (g_ascii_strcasecmp(value, "true") == 0) {
4356 prefs.gui_version_placement = version_both;
4358 prefs.gui_version_placement = version_neither;
4360 } else if (strcmp(pref_name, "name_resolve") == 0 ||
4361 strcmp(pref_name, "capture.name_resolve") == 0) {
4363 * Handle the deprecated name resolution options.
4365 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
4366 * RESOLV_ALL and RESOLV_NONE.
4368 * Otherwise, we treat it as a list of name types we want to resolve.
4370 if (g_ascii_strcasecmp(value, "true") == 0) {
4371 gbl_resolv_flags.mac_name = TRUE;
4372 gbl_resolv_flags.network_name = TRUE;
4373 gbl_resolv_flags.transport_name = TRUE;
4375 else if (g_ascii_strcasecmp(value, "false") == 0) {
4376 disable_name_resolution();
4379 /* start out with none set */
4380 disable_name_resolution();
4381 if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
4382 return PREFS_SET_SYNTAX_ERR;
4384 } else if (deprecated_heur_dissector_pref(pref_name, value)) {
4385 /* Handled within deprecated_heur_dissector_pref() if found */
4386 } else if (deprecated_port_pref(pref_name, value)) {
4387 /* Handled within deprecated_port_pref() if found */
4389 /* Handle deprecated "global" options that don't have a module
4390 * associated with them
4392 if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
4393 (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) ||
4394 (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
4395 module = nameres_module;
4398 /* To which module does this preference belong? */
4400 last_dotp = pref_name;
4402 dotp = strchr(last_dotp, '.');
4404 /* Either there's no such module, or no module was specified.
4405 In either case, that means there's no such preference. */
4406 return PREFS_SET_NO_SUCH_PREF;
4408 *dotp = '\0'; /* separate module and preference name */
4409 module = prefs_find_module(pref_name);
4412 * XXX - "Diameter" rather than "diameter" was used in earlier
4413 * versions of Wireshark; if we didn't find the module, and its name
4414 * was "Diameter", look for "diameter" instead.
4416 * In addition, the BEEP protocol used to be the BXXP protocol,
4417 * so if we didn't find the module, and its name was "bxxp",
4418 * look for "beep" instead.
4420 * Also, the preferences for GTP v0 and v1 were combined under
4421 * a single "gtp" heading, and the preferences for SMPP were
4422 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
4423 * However, SMPP now has its own preferences, so we just map
4424 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
4426 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
4427 * and "nsip" to "gprs_ns".
4429 * The SynOptics Network Management Protocol (SONMP) is now known by
4430 * its modern name, the Nortel Discovery Protocol (NDP).
4432 if (module == NULL) {
4433 if (strcmp(pref_name, "column") == 0)
4434 module = gui_column_module;
4435 else if (strcmp(pref_name, "Diameter") == 0)
4436 module = prefs_find_module("diameter");
4437 else if (strcmp(pref_name, "bxxp") == 0)
4438 module = prefs_find_module("beep");
4439 else if (strcmp(pref_name, "gtpv0") == 0 ||
4440 strcmp(pref_name, "gtpv1") == 0)
4441 module = prefs_find_module("gtp");
4442 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
4443 module = prefs_find_module("gsm-sms-ud");
4444 else if (strcmp(pref_name, "dcp") == 0)
4445 module = prefs_find_module("dccp");
4446 else if (strcmp(pref_name, "x.25") == 0)
4447 module = prefs_find_module("x25");
4448 else if (strcmp(pref_name, "x411") == 0)
4449 module = prefs_find_module("p1");
4450 else if (strcmp(pref_name, "nsip") == 0)
4451 module = prefs_find_module("gprs-ns");
4452 else if (strcmp(pref_name, "sonmp") == 0)
4453 module = prefs_find_module("ndp");
4454 else if (strcmp(pref_name, "etheric") == 0 ||
4455 strcmp(pref_name, "isup_thin") == 0) {
4456 /* This protocol was removed 7. July 2009 */
4457 return PREFS_SET_OBSOLETE;
4460 ws_g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
4461 "Save your preferences to make this change permanent.",
4462 pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
4463 prefs.unknown_prefs = TRUE;
4466 *dotp = '.'; /* put the preference string back */
4467 dotp++; /* skip past separator to preference name */
4472 /* The pref is located in the module or a submodule.
4473 * Assume module, then search for a submodule holding the pref. */
4474 containing_module = module;
4475 pref = prefs_find_preference_with_submodule(module, dotp, &containing_module);
4478 prefs.unknown_prefs = TRUE;
4480 /* "gui" prefix was added to column preferences for better organization
4481 * within the preferences file
4483 if (module == gui_column_module) {
4484 /* While this has a subtree, there is no apply callback, so no
4485 * need to use prefs_find_preference_with_submodule to update
4486 * containing_module. It would not be useful. */
4487 pref = prefs_find_preference(module, pref_name);
4489 else if (strcmp(module->name, "mgcp") == 0) {
4491 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
4492 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
4493 * were used in earlier versions of Wireshark; if we didn't find the
4494 * preference, it was an MGCP preference, and its name was
4495 * "display raw text toggle" or "display dissect tree", look for
4496 * "display_raw_text" or "display_dissect_tree" instead.
4498 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
4499 * the gateway and callagent ports were given those names; we interpret
4500 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
4501 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
4502 * they were registered by the MCCP dissector and thus that's the
4503 * order in which they were written to the preferences file. (If
4504 * we're not reading the preferences file, but are handling stuff
4505 * from a "-o" command-line option, we have no clue which the user
4506 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
4507 * or "mgcp.{tcp,udp}.callagent_port" instead.)
4509 if (strcmp(dotp, "display raw text toggle") == 0)
4510 pref = prefs_find_preference(module, "display_raw_text");
4511 else if (strcmp(dotp, "display dissect tree") == 0)
4512 pref = prefs_find_preference(module, "display_dissect_tree");
4513 else if (strcmp(dotp, "tcp.port") == 0) {
4514 mgcp_tcp_port_count++;
4515 if (mgcp_tcp_port_count == 1) {
4516 /* It's the first one */
4517 pref = prefs_find_preference(module, "tcp.gateway_port");
4518 } else if (mgcp_tcp_port_count == 2) {
4519 /* It's the second one */
4520 pref = prefs_find_preference(module, "tcp.callagent_port");
4522 /* Otherwise it's from the command line, and we don't bother
4524 } else if (strcmp(dotp, "udp.port") == 0) {
4525 mgcp_udp_port_count++;
4526 if (mgcp_udp_port_count == 1) {
4527 /* It's the first one */
4528 pref = prefs_find_preference(module, "udp.gateway_port");
4529 } else if (mgcp_udp_port_count == 2) {
4530 /* It's the second one */
4531 pref = prefs_find_preference(module, "udp.callagent_port");
4533 /* Otherwise it's from the command line, and we don't bother
4536 } else if (strcmp(module->name, "smb") == 0) {
4537 /* Handle old names for SMB preferences. */
4538 if (strcmp(dotp, "smb.trans.reassembly") == 0)
4539 pref = prefs_find_preference(module, "trans_reassembly");
4540 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
4541 pref = prefs_find_preference(module, "dcerpc_reassembly");
4542 } else if (strcmp(module->name, "ndmp") == 0) {
4543 /* Handle old names for NDMP preferences. */
4544 if (strcmp(dotp, "ndmp.desegment") == 0)
4545 pref = prefs_find_preference(module, "desegment");
4546 } else if (strcmp(module->name, "diameter") == 0) {
4547 /* Handle old names for Diameter preferences. */
4548 if (strcmp(dotp, "diameter.desegment") == 0)
4549 pref = prefs_find_preference(module, "desegment");
4550 } else if (strcmp(module->name, "pcli") == 0) {
4551 /* Handle old names for PCLI preferences. */
4552 if (strcmp(dotp, "pcli.udp_port") == 0)
4553 pref = prefs_find_preference(module, "udp_port");
4554 } else if (strcmp(module->name, "artnet") == 0) {
4555 /* Handle old names for ARTNET preferences. */
4556 if (strcmp(dotp, "artnet.udp_port") == 0)
4557 pref = prefs_find_preference(module, "udp_port");
4558 } else if (strcmp(module->name, "mapi") == 0) {
4559 /* Handle old names for MAPI preferences. */
4560 if (strcmp(dotp, "mapi_decrypt") == 0)
4561 pref = prefs_find_preference(module, "decrypt");
4562 } else if (strcmp(module->name, "fc") == 0) {
4563 /* Handle old names for Fibre Channel preferences. */
4564 if (strcmp(dotp, "reassemble_fc") == 0)
4565 pref = prefs_find_preference(module, "reassemble");
4566 else if (strcmp(dotp, "fc_max_frame_size") == 0)
4567 pref = prefs_find_preference(module, "max_frame_size");
4568 } else if (strcmp(module->name, "fcip") == 0) {
4569 /* Handle old names for Fibre Channel-over-IP preferences. */
4570 if (strcmp(dotp, "desegment_fcip_messages") == 0)
4571 pref = prefs_find_preference(module, "desegment");
4572 else if (strcmp(dotp, "fcip_port") == 0)
4573 pref = prefs_find_preference(module, "target_port");
4574 } else if (strcmp(module->name, "gtp") == 0) {
4575 /* Handle old names for GTP preferences. */
4576 if (strcmp(dotp, "gtpv0_port") == 0)
4577 pref = prefs_find_preference(module, "v0_port");
4578 else if (strcmp(dotp, "gtpv1c_port") == 0)
4579 pref = prefs_find_preference(module, "v1c_port");
4580 else if (strcmp(dotp, "gtpv1u_port") == 0)
4581 pref = prefs_find_preference(module, "v1u_port");
4582 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
4583 pref = prefs_find_preference(module, "dissect_tpdu");
4584 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
4585 pref = prefs_find_preference(module, "v0_dissect_cdr_as");
4586 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
4587 pref = prefs_find_preference(module, "v0_check_etsi");
4588 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
4589 pref = prefs_find_preference(module, "v1_check_etsi");
4590 } else if (strcmp(module->name, "ip") == 0) {
4591 /* Handle old names for IP preferences. */
4592 if (strcmp(dotp, "ip_summary_in_tree") == 0)
4593 pref = prefs_find_preference(module, "summary_in_tree");
4594 } else if (strcmp(module->name, "iscsi") == 0) {
4595 /* Handle old names for iSCSI preferences. */
4596 if (strcmp(dotp, "iscsi_port") == 0)
4597 pref = prefs_find_preference(module, "target_port");
4598 } else if (strcmp(module->name, "lmp") == 0) {
4599 /* Handle old names for LMP preferences. */
4600 if (strcmp(dotp, "lmp_version") == 0)
4601 pref = prefs_find_preference(module, "version");
4602 } else if (strcmp(module->name, "mtp3") == 0) {
4603 /* Handle old names for MTP3 preferences. */
4604 if (strcmp(dotp, "mtp3_standard") == 0)
4605 pref = prefs_find_preference(module, "standard");
4606 else if (strcmp(dotp, "net_addr_format") == 0)
4607 pref = prefs_find_preference(module, "addr_format");
4608 } else if (strcmp(module->name, "nlm") == 0) {
4609 /* Handle old names for NLM preferences. */
4610 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
4611 pref = prefs_find_preference(module, "msg_res_matching");
4612 } else if (strcmp(module->name, "ppp") == 0) {
4613 /* Handle old names for PPP preferences. */
4614 if (strcmp(dotp, "ppp_fcs") == 0)
4615 pref = prefs_find_preference(module, "fcs_type");
4616 else if (strcmp(dotp, "ppp_vj") == 0)
4617 pref = prefs_find_preference(module, "decompress_vj");
4618 } else if (strcmp(module->name, "rsvp") == 0) {
4619 /* Handle old names for RSVP preferences. */
4620 if (strcmp(dotp, "rsvp_process_bundle") == 0)
4621 pref = prefs_find_preference(module, "process_bundle");
4622 } else if (strcmp(module->name, "tcp") == 0) {
4623 /* Handle old names for TCP preferences. */
4624 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
4625 pref = prefs_find_preference(module, "summary_in_tree");
4626 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
4627 pref = prefs_find_preference(module, "analyze_sequence_numbers");
4628 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
4629 pref = prefs_find_preference(module, "relative_sequence_numbers");
4630 } else if (strcmp(module->name, "udp") == 0) {
4631 /* Handle old names for UDP preferences. */
4632 if (strcmp(dotp, "udp_summary_in_tree") == 0)
4633 pref = prefs_find_preference(module, "summary_in_tree");
4634 } else if (strcmp(module->name, "ndps") == 0) {
4635 /* Handle old names for NDPS preferences. */
4636 if (strcmp(dotp, "desegment_ndps") == 0)
4637 pref = prefs_find_preference(module, "desegment_tcp");
4638 } else if (strcmp(module->name, "http") == 0) {
4639 /* Handle old names for HTTP preferences. */
4640 if (strcmp(dotp, "desegment_http_headers") == 0)
4641 pref = prefs_find_preference(module, "desegment_headers");
4642 else if (strcmp(dotp, "desegment_http_body") == 0)
4643 pref = prefs_find_preference(module, "desegment_body");
4644 } else if (strcmp(module->name, "smpp") == 0) {
4645 /* Handle preferences that moved from SMPP. */
4646 module_t *new_module = prefs_find_module("gsm-sms-ud");
4648 if (strcmp(dotp, "port_number_udh_means_wsp") == 0) {
4649 pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
4650 containing_module = new_module;
4651 } else if (strcmp(dotp, "try_dissect_1st_fragment") == 0) {
4652 pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
4653 containing_module = new_module;
4656 } else if (strcmp(module->name, "asn1") == 0) {
4657 /* Handle old generic ASN.1 preferences (it's not really a
4658 rename, as the new preferences support multiple ports,
4659 but we might as well copy them over). */
4660 if (strcmp(dotp, "tcp_port") == 0)
4661 pref = prefs_find_preference(module, "tcp_ports");
4662 else if (strcmp(dotp, "udp_port") == 0)
4663 pref = prefs_find_preference(module, "udp_ports");
4664 else if (strcmp(dotp, "sctp_port") == 0)
4665 pref = prefs_find_preference(module, "sctp_ports");
4666 } else if (strcmp(module->name, "llcgprs") == 0) {
4667 if (strcmp(dotp, "ignore_cipher_bit") == 0)
4668 pref = prefs_find_preference(module, "autodetect_cipher_bit");
4669 } else if (strcmp(module->name, "erf") == 0) {
4670 if (strcmp(dotp, "erfeth") == 0) {
4671 /* Handle the old "erfeth" preference; map it to the new
4672 "ethfcs" preference, and map the values to those for
4673 the new preference. */
4674 pref = prefs_find_preference(module, "ethfcs");
4675 if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
4677 else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
4679 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4681 } else if (strcmp(dotp, "erfatm") == 0) {
4682 /* Handle the old "erfatm" preference; map it to the new
4683 "aal5_type" preference, and map the values to those for
4684 the new preference. */
4685 pref = prefs_find_preference(module, "aal5_type");
4686 if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
4688 else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
4690 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4692 } else if (strcmp(dotp, "erfhdlc") == 0) {
4693 /* Handle the old "erfhdlc" preference; map it to the new
4694 "hdlc_type" preference, and map the values to those for
4695 the new preference. */
4696 pref = prefs_find_preference(module, "hdlc_type");
4697 if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
4699 else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
4701 else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
4703 else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
4705 else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
4708 } else if (strcmp(module->name, "eth") == 0) {
4709 /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
4710 if (strcmp(dotp, "qinq_ethertype") == 0) {
4711 module_t *new_module = prefs_find_module("vlan");
4713 pref = prefs_find_preference(new_module, "qinq_ethertype");
4714 containing_module = new_module;
4717 } else if (strcmp(module->name, "taps") == 0) {
4718 /* taps preferences moved to "statistics" module */
4719 if (strcmp(dotp, "update_interval") == 0 ||
4720 strcmp(dotp, "rtp_player_max_visible") == 0)
4721 pref = prefs_find_preference(stats_module, dotp);
4722 } else if (strcmp(module->name, "packet_list") == 0) {
4723 /* packet_list preferences moved to protocol module */
4724 if (strcmp(dotp, "display_hidden_proto_items") == 0)
4725 pref = prefs_find_preference(protocols_module, dotp);
4726 } else if (strcmp(module->name, "stream") == 0) {
4727 /* stream preferences moved to gui color module */
4728 if ((strcmp(dotp, "client.fg") == 0) ||
4729 (strcmp(dotp, "client.bg") == 0) ||
4730 (strcmp(dotp, "server.fg") == 0) ||
4731 (strcmp(dotp, "server.bg") == 0))
4732 pref = prefs_find_preference(gui_color_module, pref_name);
4733 } else if (strcmp(module->name, "nameres") == 0) {
4734 if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
4735 pref = prefs_find_preference(nameres_module, pref_name);
4736 } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
4737 pref = prefs_find_preference(nameres_module, "load_smi_modules");
4738 } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
4739 pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
4744 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
4747 if (IS_PREF_OBSOLETE(type)) {
4748 return PREFS_SET_OBSOLETE; /* no such preference any more */
4750 RESET_PREF_OBSOLETE(type);
4756 /* XXX - give an error if it doesn't fit in a guint? */
4757 uval = (guint)strtoul(value, &p, pref->info.base);
4758 if (p == value || *p != '\0')
4759 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4760 if (*pref->varp.uint != uval) {
4761 containing_module->prefs_changed = TRUE;
4762 *pref->varp.uint = uval;
4765 case PREF_DECODE_AS_UINT:
4767 /* This is for backwards compatibility in case any of the preferences
4768 that shared the "Decode As" preference name and used to be PREF_UINT
4769 are now applied directly to the Decode As funtionality */
4771 dissector_table_t sub_dissectors;
4772 dissector_handle_t handle;
4774 /* XXX - give an error if it doesn't fit in a guint? */
4775 uval = (guint)strtoul(value, &p, pref->info.base);
4776 if (p == value || *p != '\0')
4777 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4779 if (*pref->varp.uint != uval) {
4780 containing_module->prefs_changed = TRUE;
4781 *pref->varp.uint = uval;
4783 /* Name of preference is the dissector table */
4784 sub_dissectors = find_dissector_table(pref->name);
4785 if (sub_dissectors != NULL) {
4786 handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
4787 if (handle != NULL) {
4789 dissector_change_uint(pref->name, uval, handle);
4790 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
4792 dissector_delete_uint(pref->name, *pref->varp.uint, handle);
4793 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), pref->varp.uint, NULL, NULL);
4796 /* XXX - Do we save the decode_as_entries file here? */
4803 /* XXX - give an error if it's neither "true" nor "false"? */
4804 if (g_ascii_strcasecmp(value, "true") == 0)
4808 if (*pref->varp.boolp != bval) {
4809 containing_module->prefs_changed = TRUE;
4810 *pref->varp.boolp = bval;
4815 /* XXX - give an error if it doesn't match? */
4816 enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
4818 if (*pref->varp.enump != enum_val) {
4819 containing_module->prefs_changed = TRUE;
4820 *pref->varp.enump = enum_val;
4827 prefs_set_string_like_value(pref, value, &containing_module->prefs_changed);
4832 if (!prefs_set_range_value_work(pref, value, return_range_errors,
4833 &containing_module->prefs_changed))
4834 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4837 case PREF_DECODE_AS_RANGE:
4839 /* This is for backwards compatibility in case any of the preferences
4840 that shared the "Decode As" preference name and used to be PREF_RANGE
4841 are now applied directly to the Decode As funtionality */
4843 dissector_table_t sub_dissectors;
4844 dissector_handle_t handle;
4847 if (range_convert_str_work(&newrange, value, pref->info.max_value,
4848 return_range_errors) != CVT_NO_ERROR) {
4849 return PREFS_SET_SYNTAX_ERR; /* number was bad */
4852 if (!ranges_are_equal(*pref->varp.range, newrange)) {
4853 g_free(*pref->varp.range);
4854 *pref->varp.range = newrange;
4855 containing_module->prefs_changed = TRUE;
4857 /* Name of preference is the dissector table */
4858 sub_dissectors = find_dissector_table(pref->name);
4859 if (sub_dissectors != NULL) {
4860 handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
4861 if (handle != NULL) {
4862 /* Delete all of the old values from the dissector table */
4863 for (i = 0; i < (*pref->varp.range)->nranges; i++) {
4864 for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
4865 dissector_delete_uint(pref->name, j, handle);
4866 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
4869 dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
4870 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
4873 /* Add new values to the dissector table */
4874 for (i = 0; i < newrange->nranges; i++) {
4875 for (j = newrange->ranges[i].low; j < newrange->ranges[i].high; j++) {
4876 dissector_change_uint(pref->name, j, handle);
4877 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
4880 dissector_change_uint(pref->name, newrange->ranges[i].high, handle);
4881 decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[i].high), NULL, NULL);
4884 /* XXX - Do we save the decode_as_entries file here? */
4895 cval = strtoul(value, NULL, 16);
4896 if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
4897 (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
4898 (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
4899 containing_module->prefs_changed = TRUE;
4900 pref->varp.colorp->red = RED_COMPONENT(cval);
4901 pref->varp.colorp->green = GREEN_COMPONENT(cval);
4902 pref->varp.colorp->blue = BLUE_COMPONENT(cval);
4908 return pref->custom_cbs.set_cb(pref, value, &containing_module->prefs_changed);
4910 case PREF_STATIC_TEXT:
4918 return PREFS_SET_OK;
4923 gboolean is_gui_module;
4924 } write_gui_pref_arg_t;
4927 prefs_pref_type_name(pref_t *pref)
4929 const char *type_name = "[Unknown]";
4933 return type_name; /* ...or maybe assert? */
4938 if (IS_PREF_OBSOLETE(type)) {
4939 type_name = "Obsolete";
4941 RESET_PREF_OBSOLETE(type);
4947 switch (pref->info.base) {
4950 type_name = "Decimal";
4954 type_name = "Octal";
4958 type_name = "Hexadecimal";
4964 type_name = "Boolean";
4968 type_name = "Choice";
4972 type_name = "String";
4976 type_name = "Filename";
4980 type_name = "Directory";
4984 type_name = "Range";
4988 type_name = "Color";
4992 if (pref->custom_cbs.type_name_cb)
4993 return pref->custom_cbs.type_name_cb();
4994 type_name = "Custom";
4997 case PREF_DECODE_AS_UINT:
4998 type_name = "Decode As value";
5001 case PREF_DECODE_AS_RANGE:
5002 type_name = "Range (for Decode As)";
5005 case PREF_STATIC_TEXT:
5006 type_name = "Static text";
5017 prefs_pref_type_description(pref_t *pref)
5019 const char *type_desc = "An unknown preference type";
5023 return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
5028 if (IS_PREF_OBSOLETE(type)) {
5029 type_desc = "An obsolete preference";
5031 RESET_PREF_OBSOLETE(type);
5037 switch (pref->info.base) {
5040 type_desc = "A decimal number";
5044 type_desc = "An octal number";
5048 type_desc = "A hexadecimal number";
5054 type_desc = "TRUE or FALSE (case-insensitive)";
5059 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
5060 GString *enum_str = g_string_new("One of: ");
5061 while (enum_valp->name != NULL) {
5062 g_string_append(enum_str, enum_valp->description);
5064 if (enum_valp->name != NULL)
5065 g_string_append(enum_str, ", ");
5067 g_string_append(enum_str, "\n(case-insensitive).");
5068 return g_string_free(enum_str, FALSE);
5073 type_desc = "A string";
5077 type_desc = "A path to a file";
5081 type_desc = "A path to a directory";
5086 type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
5092 type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
5097 if (pref->custom_cbs.type_description_cb)
5098 return pref->custom_cbs.type_description_cb();
5099 type_desc = "A custom value";
5102 case PREF_DECODE_AS_UINT:
5103 type_desc = "An integer value used in Decode As";
5106 case PREF_DECODE_AS_RANGE:
5107 type_desc = "A string denoting an positive integer range for Decode As";
5110 case PREF_STATIC_TEXT:
5111 type_desc = "[Static text]";
5115 type_desc = "Configuration data stored in its own file";
5121 return g_strdup(type_desc);
5125 prefs_pref_is_default(pref_t *pref)
5128 if (!pref) return FALSE;
5131 if (IS_PREF_OBSOLETE(type)) {
5134 RESET_PREF_OBSOLETE(type);
5139 case PREF_DECODE_AS_UINT:
5140 if (pref->default_val.uint == *pref->varp.uint)
5145 if (pref->default_val.uint == *pref->varp.uint)
5150 if (pref->default_val.boolval == *pref->varp.boolp)
5155 if (pref->default_val.enumval == *pref->varp.enump)
5162 if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
5166 case PREF_DECODE_AS_RANGE:
5169 if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
5176 if ((pref->default_val.color.red == pref->varp.colorp->red) &&
5177 (pref->default_val.color.green == pref->varp.colorp->green) &&
5178 (pref->default_val.color.blue == pref->varp.colorp->blue))
5184 return pref->custom_cbs.is_default_cb(pref);
5186 case PREF_STATIC_TEXT:
5189 /* g_assert_not_reached(); */
5196 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
5197 const char *pref_text = "[Unknown]";
5198 void *valp; /* pointer to preference value */
5199 color_t *pref_color;
5200 gchar *tmp_value, *ret_value;
5204 return g_strdup(pref_text);
5209 valp = &pref->default_val;
5210 /* valp = &boolval, &enumval, etc. are implied by union property */
5211 pref_color = &pref->default_val.color;
5214 valp = &pref->stashed_val;
5215 /* valp = &boolval, &enumval, etc. are implied by union property */
5216 pref_color = &pref->stashed_val.color;
5219 valp = pref->varp.uint;
5220 /* valp = boolval, enumval, etc. are implied by union property */
5221 pref_color = pref->varp.colorp;
5224 return g_strdup(pref_text);
5228 if (IS_PREF_OBSOLETE(type)) {
5229 pref_text = "[Obsolete]";
5231 RESET_PREF_OBSOLETE(type);
5236 case PREF_DECODE_AS_UINT:
5239 guint pref_uint = *(guint *) valp;
5240 switch (pref->info.base) {
5243 return g_strdup_printf("%u", pref_uint);
5246 return g_strdup_printf("%#o", pref_uint);
5249 return g_strdup_printf("%#x", pref_uint);
5255 return g_strdup((*(gboolean *) valp) ? "TRUE" : "FALSE");
5259 gint pref_enumval = *(gint *) valp;
5261 * For now, we return the "description" value, so that if we
5262 * save the preferences older versions of Wireshark can at
5263 * least read preferences that they supported; we support
5264 * either the short name or the description when reading
5265 * the preferences file or a "-o" option.
5267 const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
5268 while (enum_valp->name != NULL) {
5269 if (enum_valp->value == pref_enumval)
5270 return g_strdup(enum_valp->description);
5279 return g_strdup(*(const char **) valp);
5281 case PREF_DECODE_AS_RANGE:
5283 /* Convert wmem to g_alloc memory */
5284 tmp_value = range_convert_range(NULL, *(range_t **) valp);
5285 ret_value = g_strdup(tmp_value);
5286 wmem_free(NULL, tmp_value);
5290 return g_strdup_printf("%02x%02x%02x",
5291 (pref_color->red * 255 / 65535),
5292 (pref_color->green * 255 / 65535),
5293 (pref_color->blue * 255 / 65535));
5296 if (pref->custom_cbs.to_str_cb)
5297 return pref->custom_cbs.to_str_cb(pref, source == pref_default ? TRUE : FALSE);
5298 pref_text = "[Custom]";
5301 case PREF_STATIC_TEXT:
5302 pref_text = "[Static text]";
5307 uat_t *uat = pref->varp.uat;
5308 if (uat && uat->filename)
5309 return g_strdup_printf("[Managed in the file \"%s\"]", uat->filename);
5311 pref_text = "[Managed in an unknown file]";
5318 return g_strdup(pref_text);
5322 * Write out a single dissector preference.
5325 write_pref(gpointer data, gpointer user_data)
5327 pref_t *pref = (pref_t *)data;
5328 write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
5334 if (IS_PREF_OBSOLETE(type)) {
5336 * This preference is no longer supported; it's not a
5337 * real preference, so we don't write it out (i.e., we
5338 * treat it as if it weren't found in the list of
5339 * preferences, and we weren't called in the first place).
5343 RESET_PREF_OBSOLETE(type);
5348 case PREF_STATIC_TEXT:
5350 /* Nothing to do; don't bother printing the description */
5352 case PREF_DECODE_AS_UINT:
5353 case PREF_DECODE_AS_RANGE:
5354 /* Data is saved through Decode As mechanism and not part of preferences file */
5360 if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL) {
5362 * The prefix will either be the module name or the parent
5363 * name if it's a subtree
5365 const char *name_prefix = (arg->module->name != NULL) ? arg->module->name : arg->module->parent->name;
5366 char *type_desc, *pref_text;
5367 const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
5369 if (pref->type == PREF_CUSTOM) fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
5370 fprintf(arg->pf, "\n");
5371 if (pref->description &&
5372 (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
5373 if (pref->type != PREF_CUSTOM) {
5374 /* We get duplicate lines otherwise. */
5376 desc_lines = g_strsplit(pref->description,"\n",0);
5377 for (i = 0; desc_lines[i] != NULL; ++i) {
5378 fprintf(arg->pf, "# %s\n", desc_lines[i]);
5380 g_strfreev(desc_lines);
5383 fprintf(arg->pf, "# No description\n");
5386 type_desc = prefs_pref_type_description(pref);
5387 desc_lines = g_strsplit(type_desc,"\n",0);
5388 for (i = 0; desc_lines[i] != NULL; ++i) {
5389 fprintf(arg->pf, "# %s\n", desc_lines[i]);
5391 g_strfreev(desc_lines);
5394 pref_text = prefs_pref_to_str(pref, pref_current);
5395 fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
5396 desc_lines = g_strsplit(pref_text,"\n",0);
5397 for (i = 0; desc_lines[i] != NULL; ++i) {
5398 fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
5400 if (i == 0) fprintf(arg->pf, "\n");
5401 g_strfreev(desc_lines);
5408 * Write out all preferences for a module.
5411 write_module_prefs(module_t *module, gpointer user_data)
5413 write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
5414 write_pref_arg_t arg;
5416 /* The GUI module needs to be explicitly called out so it
5417 can be written out of order */
5418 if ((module == gui_module) && (gui_pref_arg->is_gui_module != TRUE))
5421 /* Write a header for the main modules and GUI sub-modules */
5422 if (((module->parent == NULL) || (module->parent == gui_module)) &&
5423 ((prefs_module_has_submodules(module)) ||
5424 (module->numprefs > 0) ||
5425 (module->name == NULL))) {
5426 if ((module->name == NULL) && (module->parent != NULL)) {
5427 fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
5429 fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
5433 arg.module = module;
5434 arg.pf = gui_pref_arg->pf;
5435 g_list_foreach(arg.module->prefs, write_pref, &arg);
5437 if (prefs_module_has_submodules(module))
5438 return prefs_modules_foreach_submodules(module, write_module_prefs, user_data);
5443 /* Write out "prefs" to the user's preferences file, and return 0.
5445 If the preferences file path is NULL, write to stdout.
5447 If we got an error, stuff a pointer to the path of the preferences file
5448 into "*pf_path_return", and return the errno. */
5450 write_prefs(char **pf_path_return)
5454 write_gui_pref_arg_t write_gui_pref_info;
5456 /* Needed for "-G defaultprefs" */
5460 * - Split output lines longer than MAX_VAL_LEN
5461 * - Create a function for the preference directory check/creation
5462 * so that duplication can be avoided with filter.c
5465 if (pf_path_return != NULL) {
5466 pf_path = get_persconffile_path(PF_NAME, TRUE);
5467 if ((pf = ws_fopen(pf_path, "w")) == NULL) {
5468 *pf_path_return = pf_path;
5476 fputs("# Configuration file for Wireshark " VERSION ".\n"
5478 "# This file is regenerated each time preferences are saved within\n"
5479 "# Wireshark. Making manual changes should be safe, however.\n"
5480 "# Preferences that have been commented out have not been\n"
5481 "# changed from their default value.\n", pf);
5484 * For "backwards compatibility" the GUI module is written first as it's
5485 * at the top of the file. This is followed by all modules that can't
5486 * fit into the preferences read/write API. Finally the remaining modules
5487 * are written in alphabetical order (including of course the protocol preferences)
5489 write_gui_pref_info.pf = pf;
5490 write_gui_pref_info.is_gui_module = TRUE;
5492 write_module_prefs(gui_module, &write_gui_pref_info);
5495 struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
5498 fprintf(pf, "\n####### Filter Expressions ########\n\n");
5500 while (fe != NULL) {
5501 if (fe->deleted == FALSE) {
5502 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
5503 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
5504 fe->enabled == TRUE ? "TRUE" : "FALSE");
5505 fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
5511 write_gui_pref_info.is_gui_module = FALSE;
5512 prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
5516 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
5517 an error indication, or maybe write to a new preferences file and
5518 rename that file on top of the old one only if there are not I/O
5523 /** The col_list is only partly managed by the custom preference API
5524 * because its data is shared between multiple preferences, so
5528 free_col_info(GList *list)
5531 GList *list_head = list;
5533 while (list != NULL) {
5534 cfmt = (fmt_data *)list->data;
5536 g_free(cfmt->title);
5537 g_free(cfmt->custom_fields);
5539 list = g_list_next(list);
5541 g_list_free(list_head);
5550 * indent-tabs-mode: nil
5553 * ex: set shiftwidth=4 tabstop=8 expandtab:
5554 * :indentSize=4:tabSize=8:noTabs=true: