2 * Routines for handling preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #include <epan/filesystem.h>
41 #include <epan/address.h>
42 #include <epan/addr_resolv.h>
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/proto.h>
46 #include <epan/column.h>
48 #include <wiretap/file_util.h>
50 #include <epan/prefs-int.h>
52 /* Internal functions */
53 static module_t *prefs_register_module_or_subtree(module_t *parent,
54 const char *name, const char *title, const char *description, gboolean is_subtree,
55 void (*apply_cb)(void));
56 static struct preference *find_preference(module_t *, const char *);
57 static prefs_set_pref_e set_pref(gchar*, gchar*, void *);
58 static GList *get_string_list(gchar *);
59 static gchar *put_string_list(GList *);
60 static void clear_string_list(GList *);
61 static void free_col_info(e_prefs *);
63 #define PF_NAME "preferences"
64 #define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
66 static gboolean prefs_initialized = FALSE;
67 static gchar *gpf_path = NULL;
70 * XXX - variables to allow us to attempt to interpret the first
71 * "mgcp.{tcp,udp}.port" in a preferences file as
72 * "mgcp.{tcp,udp}.gateway_port" and the second as
73 * "mgcp.{tcp,udp}.callagent_port".
75 static int mgcp_tcp_port_count;
76 static int mgcp_udp_port_count;
80 static const gchar *gui_ptree_line_style_text[] =
81 { "NONE", "SOLID", "DOTTED", "TABBED", NULL };
83 static const gchar *gui_ptree_expander_style_text[] =
84 { "NONE", "SQUARE", "TRIANGLE", "CIRCULAR", NULL };
86 static const gchar *gui_hex_dump_highlight_style_text[] =
87 { "BOLD", "INVERSE", NULL };
89 static const gchar *gui_console_open_text[] =
90 { "NEVER", "AUTOMATIC", "ALWAYS", NULL };
92 static const gchar *gui_fileopen_style_text[] =
93 { "LAST_OPENED", "SPECIFIED", NULL };
95 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
96 * as this may not work on other guis, we use only "both" in general here */
97 static const gchar *gui_toolbar_style_text[] =
98 { "ICONS", "TEXT", "BOTH", NULL };
100 static const gchar *gui_layout_content_text[] =
101 { "NONE", "PLIST", "PDETAILS", "PBYTES", NULL };
104 * List of all modules with preference settings.
106 static GList *modules;
109 * List of all modules that should show up at the top level of the
110 * tree in the preference dialog box.
112 static GList *top_level_modules;
115 module_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
117 const module_t *p1 = p1_arg;
118 const module_t *p2 = p2_arg;
120 return g_strcasecmp(p1->name, p2->name);
124 module_compare_title(gconstpointer p1_arg, gconstpointer p2_arg)
126 const module_t *p1 = p1_arg;
127 const module_t *p2 = p2_arg;
129 return g_strcasecmp(p1->title, p2->title);
133 * Register a module that will have preferences.
134 * Specify the module under which to register it or NULL to register it
135 * at the top level, the name used for the module in the preferences file,
136 * the title used in the tab for it in a preferences dialog box, and a
137 * routine to call back when we apply the preferences.
140 prefs_register_module(module_t *parent, const char *name, const char *title,
141 const char *description, void (*apply_cb)(void))
143 return prefs_register_module_or_subtree(parent, name, title, description,
148 * Register a subtree that will have modules under it.
149 * Specify the module under which to register it or NULL to register it
150 * at the top level and the title used in the tab for it in a preferences
154 prefs_register_subtree(module_t *parent, const char *title, const char *description)
156 return prefs_register_module_or_subtree(parent, NULL, title, description, TRUE,
161 prefs_register_module_or_subtree(module_t *parent, const char *name,
162 const char *title, const char *description, gboolean is_subtree, void (*apply_cb)(void))
168 module = g_malloc(sizeof (module_t));
170 module->title = title;
171 module->description = description;
172 module->is_subtree = is_subtree;
173 module->apply_cb = apply_cb;
174 module->prefs = NULL; /* no preferences, to start */
175 module->numprefs = 0;
176 module->prefs_changed = FALSE;
177 module->obsolete = FALSE;
180 * Do we have a module name?
185 * Make sure that only lower-case ASCII letters, numbers,
186 * underscores, hyphens, and dots appear in the name.
188 * Crash if there is, as that's an error in the code;
189 * you can make the title a nice string with capitalization,
190 * white space, punctuation, etc., but the name can be used
191 * on the command line, and shouldn't require quoting,
194 for (p = name; (c = *p) != '\0'; p++)
195 g_assert(isascii(c) &&
196 (islower(c) || isdigit(c) || c == '_' ||
197 c == '-' || c == '.'));
200 * Make sure there's not already a module with that
201 * name. Crash if there is, as that's an error in the
202 * code, and the code has to be fixed not to register
203 * more than one module with the same name.
205 * We search the list of all modules; the subtree stuff
206 * doesn't require preferences in subtrees to have names
207 * that reflect the subtree they're in (that would require
208 * protocol preferences to have a bogus "protocol.", or
209 * something such as that, to be added to all their names).
211 g_assert(prefs_find_module(name) == NULL);
214 * Insert this module in the list of all modules.
216 modules = g_list_insert_sorted(modules, module,
217 module_compare_name);
220 * This has no name, just a title; check to make sure it's a
221 * subtree, and crash if it's not.
223 g_assert(is_subtree);
227 * Insert this module into the appropriate place in the display
230 if (parent == NULL) {
232 * It goes at the top.
234 top_level_modules = g_list_insert_sorted(top_level_modules,
235 module, module_compare_title);
238 * It goes into the list for this module.
240 parent->prefs = g_list_insert_sorted(parent->prefs, module,
241 module_compare_title);
248 * Register that a protocol has preferences.
250 module_t *protocols_module;
253 prefs_register_protocol(int id, void (*apply_cb)(void))
255 protocol_t *protocol;
258 * Have we yet created the "Protocols" subtree?
260 if (protocols_module == NULL) {
264 protocols_module = prefs_register_subtree(NULL, "Protocols", NULL);
266 protocol = find_protocol_by_id(id);
267 return prefs_register_module(protocols_module,
268 proto_get_protocol_filter_name(id),
269 proto_get_protocol_short_name(protocol),
270 proto_get_protocol_name(id), apply_cb);
274 * Register that a protocol used to have preferences but no longer does,
275 * by creating an "obsolete" module for it.
278 prefs_register_protocol_obsolete(int id)
281 protocol_t *protocol;
284 * Have we yet created the "Protocols" subtree?
286 if (protocols_module == NULL) {
290 protocols_module = prefs_register_subtree(NULL, "Protocols", NULL);
292 protocol = find_protocol_by_id(id);
293 module = prefs_register_module(protocols_module,
294 proto_get_protocol_filter_name(id),
295 proto_get_protocol_short_name(protocol),
296 proto_get_protocol_name(id), NULL);
297 module->obsolete = TRUE;
302 * Find a module, given its name.
305 module_match(gconstpointer a, gconstpointer b)
307 const module_t *module = a;
308 const char *name = b;
310 return strcmp(name, module->name);
314 prefs_find_module(const char *name)
318 list_entry = g_list_find_custom(modules, name, module_match);
319 if (list_entry == NULL)
320 return NULL; /* no such module */
321 return (module_t *) list_entry->data;
325 * Call a callback function, with a specified argument, for each module
326 * in a list of modules. If the list is NULL, searches the top-level
327 * list in the display tree of modules. If any callback returns a
328 * non-zero value, we stop and return that value, otherwise we
331 * Ignores "obsolete" modules; their sole purpose is to allow old
332 * preferences for dissectors that no longer have preferences to be
333 * silently ignored in preference files. Does not ignore subtrees,
334 * as this can be used when walking the display tree of modules.
337 prefs_module_list_foreach(GList *module_list, module_cb callback,
344 if (module_list == NULL)
345 module_list = top_level_modules;
347 for (elem = g_list_first(module_list); elem != NULL;
348 elem = g_list_next(elem)) {
350 if (!module->obsolete) {
351 ret = (*callback)(module, user_data);
360 * Call a callback function, with a specified argument, for each module
361 * in the list of all modules. (This list does not include subtrees.)
363 * Ignores "obsolete" modules; their sole purpose is to allow old
364 * preferences for dissectors that no longer have preferences to be
365 * silently ignored in preference files.
368 prefs_modules_foreach(module_cb callback, gpointer user_data)
370 return prefs_module_list_foreach(modules, callback, user_data);
374 call_apply_cb(gpointer data, gpointer user_data _U_)
376 module_t *module = data;
378 if (module->obsolete)
380 if (module->prefs_changed) {
381 if (module->apply_cb != NULL)
382 (*module->apply_cb)();
383 module->prefs_changed = FALSE;
388 * Call the "apply" callback function for each module if any of its
389 * preferences have changed, and then clear the flag saying its
390 * preferences have changed, as the module has been notified of that
394 prefs_apply_all(void)
396 g_list_foreach(modules, call_apply_cb, NULL);
400 * Call the "apply" callback function for a specific module if any of
401 * its preferences have changed, and then clear the flag saying its
402 * preferences have changed, as the module has been notified of that
406 prefs_apply(module_t *module)
408 if (module && module->prefs_changed)
409 call_apply_cb(module, NULL);
413 * Register a preference in a module's list of preferences.
414 * If it has a title, give it an ordinal number; otherwise, it's a
415 * preference that won't show up in the UI, so it shouldn't get an
416 * ordinal number (the ordinal should be the ordinal in the set of
417 * *visible* preferences).
420 register_preference(module_t *module, const char *name, const char *title,
421 const char *description, pref_type_t type)
426 preference = g_malloc(sizeof (pref_t));
427 preference->name = name;
428 preference->title = title;
429 preference->description = description;
430 preference->type = type;
432 preference->ordinal = module->numprefs;
434 preference->ordinal = -1; /* no ordinal for you */
437 * Make sure that only lower-case ASCII letters, numbers,
438 * underscores, and dots appear in the preference name.
440 * Crash if there is, as that's an error in the code;
441 * you can make the title and description nice strings
442 * with capitalization, white space, punctuation, etc.,
443 * but the name can be used on the command line,
444 * and shouldn't require quoting, shifting, etc.
446 for (p = name; *p != '\0'; p++)
447 g_assert(isascii((guchar)*p) &&
448 (islower((guchar)*p) || isdigit((guchar)*p) || *p == '_' || *p == '.'));
451 * Make sure there's not already a preference with that
452 * name. Crash if there is, as that's an error in the
453 * code, and the code has to be fixed not to register
454 * more than one preference with the same name.
456 g_assert(find_preference(module, name) == NULL);
458 if (type != PREF_OBSOLETE) {
460 * Make sure the preference name doesn't begin with the
461 * module name, as that's redundant and Just Silly.
463 g_assert((strncmp(name, module->name, strlen(module->name)) != 0) ||
464 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_')));
468 * There isn't already one with that name, so add the
471 module->prefs = g_list_append(module->prefs, preference);
479 * Find a preference in a module's list of preferences, given the module
480 * and the preference's name.
483 preference_match(gconstpointer a, gconstpointer b)
485 const pref_t *pref = a;
486 const char *name = b;
488 return strcmp(name, pref->name);
491 static struct preference *
492 find_preference(module_t *module, const char *name)
496 list_entry = g_list_find_custom(module->prefs, name,
498 if (list_entry == NULL)
499 return NULL; /* no such preference */
500 return (struct preference *) list_entry->data;
504 * Returns TRUE if the given protocol has registered preferences
507 prefs_is_registered_protocol(const char *name)
509 module_t *m = prefs_find_module(name);
511 return (m != NULL && !m->obsolete);
515 * Returns the module title of a registered protocol
518 prefs_get_title_by_name(const char *name)
520 module_t *m = prefs_find_module(name);
522 return (m != NULL && !m->obsolete) ? m->title : NULL;
526 * Register a preference with an unsigned integral value.
529 prefs_register_uint_preference(module_t *module, const char *name,
530 const char *title, const char *description, guint base, guint *var)
534 preference = register_preference(module, name, title, description,
536 preference->varp.uint = var;
537 preference->info.base = base;
541 * Register a preference with an Boolean value.
544 prefs_register_bool_preference(module_t *module, const char *name,
545 const char *title, const char *description, gboolean *var)
549 preference = register_preference(module, name, title, description,
551 preference->varp.boolp = var;
555 * Register a preference with an enumerated value.
558 prefs_register_enum_preference(module_t *module, const char *name,
559 const char *title, const char *description, gint *var,
560 const enum_val_t *enumvals, gboolean radio_buttons)
564 preference = register_preference(module, name, title, description,
566 preference->varp.enump = var;
567 preference->info.enum_info.enumvals = enumvals;
568 preference->info.enum_info.radio_buttons = radio_buttons;
572 * Register a preference with a character-string value.
575 prefs_register_string_preference(module_t *module, const char *name,
576 const char *title, const char *description, const char **var)
580 preference = register_preference(module, name, title, description,
584 * String preference values should be non-null (as you can't
585 * keep them null after using the preferences GUI, you can at best
586 * have them be null strings) and freeable (as we free them
587 * if we change them).
589 * If the value is a null pointer, make it a copy of a null
590 * string, otherwise make it a copy of the value.
595 *var = g_strdup(*var);
596 preference->varp.string = var;
597 preference->saved_val.string = NULL;
601 * Register a preference with a ranged value.
604 prefs_register_range_preference(module_t *module, const char *name,
605 const char *title, const char *description, range_t **var,
610 preference = register_preference(module, name, title, description,
612 preference->info.max_value = max_value;
616 * Range preference values should be non-null (as you can't
617 * keep them null after using the preferences GUI, you can at best
618 * have them be empty ranges) and freeable (as we free them
619 * if we change them).
621 * If the value is a null pointer, make it an empty range.
624 *var = range_empty();
625 preference->varp.range = var;
626 preference->saved_val.range = NULL;
630 * Register a static text 'preference'. It can be used to add explanatory
631 * text inline with other preferences in the GUI.
632 * Note: Static preferences are not saved to the preferences file.
634 void prefs_register_static_text_preference(module_t *module, const char *name,
635 const char *title, const char *description)
637 register_preference(module, name, title, description, PREF_STATIC_TEXT);
641 * Register a preference that used to be supported but no longer is.
644 prefs_register_obsolete_preference(module_t *module, const char *name)
646 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
650 * Call a callback function, with a specified argument, for each preference
653 * If any of the callbacks return a non-zero value, stop and return that
654 * value, otherwise return 0.
657 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
663 for (elem = g_list_first(module->prefs); elem != NULL;
664 elem = g_list_next(elem)) {
666 if (pref->type == PREF_OBSOLETE) {
668 * This preference is no longer supported; it's
669 * not a real preference, so we don't call the
670 * callback for it (i.e., we treat it as if it
671 * weren't found in the list of preferences,
672 * and we weren't called in the first place).
677 ret = (*callback)(pref, user_data);
685 * Register all non-dissector modules' preferences.
688 prefs_register_modules(void)
692 /* Parse through a list of comma-separated, possibly quoted strings.
693 Return a list of the string data. */
695 get_string_list(gchar *str)
697 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
699 gint state = PRE_STRING, i = 0, j = 0;
700 gboolean backslash = FALSE;
705 /* Allocate a buffer for the first string. */
706 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
712 /* It's the end of the input, so it's the end of the string we
713 were working on, and there's no more input. */
714 if (state == IN_QUOT || backslash) {
715 /* We were in the middle of a quoted string or backslash escape,
716 and ran out of characters; that's an error. */
718 clear_string_list(sl);
722 sl = g_list_append(sl, slstr);
725 if (cur_c == '"' && ! backslash) {
728 /* We hadn't yet started processing a string; this starts the
729 string, and we're now quoting. */
733 /* We're in the middle of a quoted string, and we saw a quotation
734 mark; we're no longer quoting. */
738 /* We're working on a string, but haven't seen a quote; we're
745 } else if (cur_c == '\\' && ! backslash) {
746 /* We saw a backslash, and the previous character wasn't a
747 backslash; escape the next character.
749 This also means we've started a new string. */
751 if (state == PRE_STRING)
753 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
754 /* We saw a comma, and we're not in the middle of a quoted string
755 and it wasn't preceded by a backslash; it's the end of
756 the string we were working on... */
758 sl = g_list_append(sl, slstr);
760 /* ...and the beginning of a new string. */
762 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
764 } else if (!isspace(cur_c) || state != PRE_STRING) {
765 /* Either this isn't a white-space character, or we've started a
766 string (i.e., already seen a non-white-space character for that
767 string and put it into the string).
769 The character is to be put into the string; do so if there's
771 if (j < COL_MAX_LEN) {
776 /* If it was backslash-escaped, we're done with the backslash escape. */
784 #define MAX_FMT_PREF_LEN 1024
785 #define MAX_FMT_PREF_LINE_LEN 60
787 put_string_list(GList *sl)
789 static gchar pref_str[MAX_FMT_PREF_LEN] = "";
790 GList *clp = g_list_first(sl);
792 int cur_pos = 0, cur_len = 0;
795 gchar *strp, *quoted_strp, c;
801 /* Allocate a buffer big enough to hold the entire string, with each
802 character quoted (that's the worst case). */
803 str_len = strlen(str);
804 quoted_str = g_malloc(str_len*2 + 1);
806 /* Now quote any " or \ characters in it. */
808 quoted_strp = quoted_str;
809 while ((c = *strp++) != '\0') {
810 if (c == '"' || c == '\\') {
811 /* It has to be backslash-quoted. */
812 *quoted_strp++ = '\\';
818 fmt_len = strlen(quoted_str) + 4;
819 if ((fmt_len + cur_len) < (MAX_FMT_PREF_LEN - 1)) {
820 if ((fmt_len + cur_pos) > MAX_FMT_PREF_LINE_LEN) {
824 pref_str[cur_len] = '\n'; cur_len++;
825 pref_str[cur_len] = '\t'; cur_len++;
827 sprintf(&pref_str[cur_len], "\"%s\", ", quoted_str);
835 /* If the string is at least two characters long, the last two characters
836 are ", ", and should be discarded, as there are no more items in the
839 pref_str[cur_len - 2] = '\0';
845 clear_string_list(GList *sl)
851 l = g_list_remove_link(l, l);
856 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
858 * The array must be terminated by an entry with a null "name" string.
860 * If the string matches a "name" string in an entry, the value from that
863 * Otherwise, if a string matches a "desctiption" string in an entry, the
864 * value from that entry is returned; we do that for backwards compatibility,
865 * as we used to have only a "name" string that was used both for command-line
866 * and configuration-file values and in the GUI (which meant either that
867 * the GUI had what might be somewhat cryptic values to select from or that
868 * the "-o" flag took long strings, often with spaces in them).
870 * Otherwise, the default value that was passed as the third argument is
874 find_val_for_string(const char *needle, const enum_val_t *haystack,
879 for (i = 0; haystack[i].name != NULL; i++) {
880 if (strcasecmp(needle, haystack[i].name) == 0) {
881 return haystack[i].value;
884 for (i = 0; haystack[i].name != NULL; i++) {
885 if (strcasecmp(needle, haystack[i].description) == 0) {
886 return haystack[i].value;
889 return default_value;
892 /* Takes an string and a pointer to an array of strings, and a default int value.
893 * The array must be terminated by a NULL string. If the string is found in the array
894 * of strings, the index of that string in the array is returned. Otherwise, the
895 * default value that was passed as the third argument is returned.
898 find_index_from_string_array(char *needle, const char **haystack, int default_value)
902 while (haystack[i] != NULL) {
903 if (strcmp(needle, haystack[i]) == 0) {
908 return default_value;
911 /* Preferences file format:
912 * - Configuration directives start at the beginning of the line, and
913 * are terminated with a colon.
914 * - Directives can be continued on the next line by preceding them with
919 # This is a comment line
921 print.file: /a/very/long/path/
926 #define DEF_NUM_COLS 6
928 /* Initialize preferences to wired-in default values.
929 * They may be overridden by the global preferences file or the
930 * user's preferences file.
936 const gchar *col_fmt[] = {"No.", "%m", "Time", "%t",
937 "Source", "%s", "Destination", "%d",
938 "Protocol", "%p", "Info", "%i"};
940 if (prefs_initialized)
943 prefs.pr_format = PR_FMT_TEXT;
944 prefs.pr_dest = PR_DEST_CMD;
945 prefs.pr_file = g_strdup("wireshark.out");
946 prefs.pr_cmd = g_strdup("lpr");
947 prefs.col_list = NULL;
948 for (i = 0; i < DEF_NUM_COLS; i++) {
949 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
950 cfmt->title = g_strdup(col_fmt[i * 2]);
951 cfmt->fmt = g_strdup(col_fmt[(i * 2) + 1]);
952 prefs.col_list = g_list_append(prefs.col_list, cfmt);
954 prefs.num_cols = DEF_NUM_COLS;
955 prefs.st_client_fg.pixel = 0;
956 prefs.st_client_fg.red = 32767;
957 prefs.st_client_fg.green = 0;
958 prefs.st_client_fg.blue = 0;
959 prefs.st_client_bg.pixel = 0;
960 prefs.st_client_bg.red = 64507;
961 prefs.st_client_bg.green = 60909;
962 prefs.st_client_bg.blue = 60909;
963 prefs.st_server_fg.pixel = 0;
964 prefs.st_server_fg.red = 0;
965 prefs.st_server_fg.green = 0;
966 prefs.st_server_fg.blue = 32767;
967 prefs.st_server_bg.pixel = 0;
968 prefs.st_server_bg.red = 60909;
969 prefs.st_server_bg.green = 60909;
970 prefs.st_server_bg.blue = 64507;
971 prefs.gui_scrollbar_on_right = TRUE;
972 prefs.gui_plist_sel_browse = FALSE;
973 prefs.gui_ptree_sel_browse = FALSE;
974 prefs.gui_altern_colors = FALSE;
975 prefs.gui_ptree_line_style = 0;
976 prefs.gui_ptree_expander_style = 1;
977 prefs.gui_hex_dump_highlight_style = 1;
978 prefs.filter_toolbar_show_in_statusbar = FALSE;
979 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
981 /* XXX - not sure, if it must be "Lucida Console" or "lucida console"
982 * for gui_font_name1. Maybe it's dependant on the windows version running?!
983 * verified on XP: "Lucida Console"
984 * unknown for other windows versions.
986 * Problem: if we have no preferences file, and the default font name is unknown,
987 * we cannot save Preferences as an error dialog pops up "You have not selected a font".
989 prefs.gui_font_name1 = g_strdup("-*-Lucida Console-medium-r-*-*-*-100-*-*-*-*-*-*");
990 prefs.gui_font_name2 = g_strdup("Lucida Console 10");
993 * XXX - for now, we make the initial font name a pattern that matches
994 * only ISO 8859/1 fonts, so that we don't match 2-byte fonts such
995 * as ISO 10646 fonts.
997 * Users in locales using other one-byte fonts will have to choose
998 * a different font from the preferences dialog - or put the font
999 * selection in the global preferences file to make that font the
1000 * default for all users who don't explicitly specify a different
1003 * Making this a font set rather than a font has two problems:
1005 * 1) as far as I know, you can't select font sets with the
1006 * font selection dialog;
1008 * 2) if you use a font set, the text to be drawn must be a
1009 * multi-byte string in the appropriate locale, but
1010 * Wireshark does *NOT* guarantee that's the case - in
1011 * the hex-dump window, each character in the text portion
1012 * of the display must be a *single* byte, and in the
1013 * packet-list and protocol-tree windows, text extracted
1014 * from the packet is not necessarily in the right format.
1016 * "Doing this right" may, for the packet-list and protocol-tree
1017 * windows, require that dissectors know what the locale is
1018 * *AND* know what locale and text representation is used in
1019 * the packets they're dissecting, and may be impossible in
1020 * the hex-dump window (except by punting and displaying only
1021 * ASCII characters).
1023 * GTK+ 2.0 may simplify part of the problem, as it will, as I
1024 * understand it, use UTF-8-encoded Unicode as its internal
1025 * character set; however, we'd still have to know whatever
1026 * character set and encoding is used in the packet (which
1027 * may differ for different protocols, e.g. SMB might use
1028 * PC code pages for some strings and Unicode for others, whilst
1029 * NFS might use some UNIX character set encoding, e.g. ISO 8859/x,
1030 * or one of the EUC character sets for Asian languages, or one
1031 * of the other multi-byte character sets, or UTF-8, or...).
1033 * I.e., as far as I can tell, "internationalizing" the packet-list,
1034 * protocol-tree, and hex-dump windows involves a lot more than, say,
1035 * just using font sets rather than fonts.
1037 prefs.gui_font_name1 = g_strdup("-misc-fixed-medium-r-semicondensed-*-*-100-*-*-*-*-iso8859-1");
1038 /* XXX- is this the correct default font name for GTK2 none win32? */
1039 prefs.gui_font_name2 = g_strdup("Monospace 10");
1041 prefs.gui_marked_fg.pixel = 65535;
1042 prefs.gui_marked_fg.red = 65535;
1043 prefs.gui_marked_fg.green = 65535;
1044 prefs.gui_marked_fg.blue = 65535;
1045 prefs.gui_marked_bg.pixel = 0;
1046 prefs.gui_marked_bg.red = 0;
1047 prefs.gui_marked_bg.green = 0;
1048 prefs.gui_marked_bg.blue = 0;
1049 prefs.gui_geometry_save_position = 0;
1050 prefs.gui_geometry_save_size = 1;
1051 prefs.gui_geometry_save_maximized= 1;
1052 prefs.gui_console_open = console_open_never;
1053 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
1054 prefs.gui_recent_files_count_max = 10;
1055 prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
1056 prefs.gui_fileopen_preview = 3;
1057 prefs.gui_ask_unsaved = TRUE;
1058 prefs.gui_find_wrap = TRUE;
1059 prefs.gui_use_pref_save = FALSE;
1060 prefs.gui_webbrowser = g_strdup(HTML_VIEWER " %s");
1061 prefs.gui_window_title = g_strdup("");
1062 prefs.gui_layout_type = layout_type_5;
1063 prefs.gui_layout_content_1 = layout_pane_content_plist;
1064 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
1065 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
1066 prefs.console_log_level =
1067 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
1069 /* set the default values for the capture dialog box */
1070 prefs.capture_device = NULL;
1071 prefs.capture_devices_descr = NULL;
1072 prefs.capture_devices_hide = NULL;
1073 prefs.capture_prom_mode = TRUE;
1074 prefs.capture_real_time = TRUE;
1075 prefs.capture_auto_scroll = TRUE;
1076 prefs.capture_show_info = FALSE;
1077 prefs.name_resolve = RESOLV_ALL ^ RESOLV_NETWORK;
1078 prefs.name_resolve_concurrency = 500;
1080 prefs_initialized = TRUE;
1084 /* Read the preferences file, fill in "prefs", and return a pointer to it.
1086 If we got an error (other than "it doesn't exist") trying to read
1087 the global preferences file, stuff the errno into "*gpf_errno_return"
1088 and a pointer to the path of the file into "*gpf_path_return", and
1091 If we got an error (other than "it doesn't exist") trying to read
1092 the user's preferences file, stuff the errno into "*pf_errno_return"
1093 and a pointer to the path of the file into "*pf_path_return", and
1096 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
1097 char **gpf_path_return, int *pf_errno_return,
1098 int *pf_read_errno_return, char **pf_path_return)
1107 * If we don't already have the pathname of the global preferences
1108 * file, construct it. Then, in either case, try to open the file.
1110 if (gpf_path == NULL) {
1112 * We don't have the path; try the new path first, and, if that
1113 * file doesn't exist, try the old path.
1115 gpf_path = get_datafile_path(PF_NAME);
1116 if ((pf = eth_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
1118 * It doesn't exist by the new name; try the old name.
1121 gpf_path = get_datafile_path(OLD_GPF_NAME);
1122 pf = eth_fopen(gpf_path, "r");
1126 * We have the path; try it.
1128 pf = eth_fopen(gpf_path, "r");
1132 * If we were able to open the file, read it.
1133 * XXX - if it failed for a reason other than "it doesn't exist",
1136 *gpf_path_return = NULL;
1139 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
1142 mgcp_tcp_port_count = 0;
1143 mgcp_udp_port_count = 0;
1145 /* We succeeded in opening it; read it. */
1146 err = read_prefs_file(gpf_path, pf, set_pref, NULL);
1148 /* We had an error reading the file; return the errno and the
1149 pathname, so our caller can report the error. */
1150 *gpf_errno_return = 0;
1151 *gpf_read_errno_return = err;
1152 *gpf_path_return = gpf_path;
1156 /* We failed to open it. If we failed for some reason other than
1157 "it doesn't exist", return the errno and the pathname, so our
1158 caller can report the error. */
1159 if (errno != ENOENT) {
1160 *gpf_errno_return = errno;
1161 *gpf_read_errno_return = 0;
1162 *gpf_path_return = gpf_path;
1166 /* Construct the pathname of the user's preferences file. */
1167 pf_path = get_persconffile_path(PF_NAME, FALSE);
1169 /* Read the user's preferences file, if it exists. */
1170 *pf_path_return = NULL;
1171 if ((pf = eth_fopen(pf_path, "r")) != NULL) {
1173 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
1176 mgcp_tcp_port_count = 0;
1177 mgcp_udp_port_count = 0;
1179 /* We succeeded in opening it; read it. */
1180 err = read_prefs_file(pf_path, pf, set_pref, NULL);
1182 /* We had an error reading the file; return the errno and the
1183 pathname, so our caller can report the error. */
1184 *pf_errno_return = 0;
1185 *pf_read_errno_return = err;
1186 *pf_path_return = pf_path;
1191 /* We failed to open it. If we failed for some reason other than
1192 "it doesn't exist", return the errno and the pathname, so our
1193 caller can report the error. */
1194 if (errno != ENOENT) {
1195 *pf_errno_return = errno;
1196 *pf_read_errno_return = 0;
1197 *pf_path_return = pf_path;
1205 /* read the preferences file (or similiar) and call the callback
1206 * function to set each key/value pair found */
1208 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data)
1210 enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
1211 int got_c, state = START;
1214 gboolean got_val = FALSE;
1215 gint fline = 1, pline = 1;
1216 gchar hint[] = "(applying your preferences once should remove this warning)";
1218 cur_val = g_string_new("");
1219 cur_var = g_string_new("");
1221 while ((got_c = getc(pf)) != EOF) {
1222 if (got_c == '\n') {
1230 if (isalnum(got_c)) {
1231 if (cur_var->len > 0) {
1233 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data)) {
1238 case PREFS_SET_SYNTAX_ERR:
1239 g_warning ("%s line %d: Syntax error %s", pf_path, pline, hint);
1242 case PREFS_SET_NO_SUCH_PREF:
1243 g_warning ("%s line %d: No such preference \"%s\" %s", pf_path,
1244 pline, cur_var->str, hint);
1247 case PREFS_SET_OBSOLETE:
1248 /* We silently ignore attempts to set these; it's
1249 probably not the user's fault that it's in there -
1250 they may have saved preferences with a release that
1255 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
1260 g_string_truncate(cur_var, 0);
1261 g_string_append_c(cur_var, (gchar) got_c);
1263 } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
1265 } else if (got_c == '#') {
1268 g_warning ("%s line %d: Malformed line %s", pf_path, fline, hint);
1273 g_string_append_c(cur_var, (gchar) got_c);
1276 g_string_truncate(cur_val, 0);
1281 if (!isspace(got_c)) {
1283 g_string_append_c(cur_val, (gchar) got_c);
1288 g_string_append_c(cur_val, (gchar) got_c);
1290 while (isspace((guchar)cur_val->str[cur_val->len]) && cur_val->len > 0)
1291 g_string_truncate(cur_val, cur_val->len - 1);
1297 if (cur_var->len > 0) {
1299 switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data)) {
1304 case PREFS_SET_SYNTAX_ERR:
1305 g_warning ("%s line %d: Syntax error %s", pf_path, pline, hint);
1308 case PREFS_SET_NO_SUCH_PREF:
1309 g_warning ("%s line %d: No such preference \"%s\" %s", pf_path,
1310 pline, cur_var->str, hint);
1313 case PREFS_SET_OBSOLETE:
1314 /* We silently ignore attempts to set these; it's probably not
1315 the user's fault that it's in there - they may have saved
1316 preferences with a release that supported it. */
1320 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
1324 g_string_free(cur_val, TRUE);
1325 g_string_free(cur_var, TRUE);
1334 * Given a string of the form "<pref name>:<pref value>", as might appear
1335 * as an argument to a "-o" option, parse it and set the preference in
1336 * question. Return an indication of whether it succeeded or failed
1340 prefs_set_pref(char *prefarg)
1343 prefs_set_pref_e ret;
1346 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
1347 * seen to values that keep us from trying to interpret tham
1348 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
1349 * as, from the command line, we have no way of guessing which
1350 * the user had in mind.
1352 mgcp_tcp_port_count = -1;
1353 mgcp_udp_port_count = -1;
1355 colonp = strchr(prefarg, ':');
1357 return PREFS_SET_SYNTAX_ERR;
1363 * Skip over any white space (there probably won't be any, but
1364 * as we allow it in the preferences file, we might as well
1367 while (isspace((guchar)*p))
1371 * Put the colon back, so if our caller uses, in an
1372 * error message, the string they passed us, the message
1376 return PREFS_SET_SYNTAX_ERR;
1379 ret = set_pref(prefarg, p, NULL);
1380 *colonp = ':'; /* put the colon back */
1384 #define PRS_PRINT_FMT "print.format"
1385 #define PRS_PRINT_DEST "print.destination"
1386 #define PRS_PRINT_FILE "print.file"
1387 #define PRS_PRINT_CMD "print.command"
1388 #define PRS_COL_FMT "column.format"
1389 #define PRS_STREAM_CL_FG "stream.client.fg"
1390 #define PRS_STREAM_CL_BG "stream.client.bg"
1391 #define PRS_STREAM_SR_FG "stream.server.fg"
1392 #define PRS_STREAM_SR_BG "stream.server.bg"
1393 #define PRS_GUI_SCROLLBAR_ON_RIGHT "gui.scrollbar_on_right"
1394 #define PRS_GUI_PLIST_SEL_BROWSE "gui.packet_list_sel_browse"
1395 #define PRS_GUI_PTREE_SEL_BROWSE "gui.protocol_tree_sel_browse"
1396 #define PRS_GUI_ALTERN_COLORS "gui.tree_view_altern_colors"
1397 #define PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR "gui.filter_toolbar_show_in_statusbar"
1398 #define PRS_GUI_PTREE_LINE_STYLE "gui.protocol_tree_line_style"
1399 #define PRS_GUI_PTREE_EXPANDER_STYLE "gui.protocol_tree_expander_style"
1400 #define PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE "gui.hex_dump_highlight_style"
1401 #define PRS_GUI_FONT_NAME_1 "gui.font_name"
1402 #define PRS_GUI_FONT_NAME_2 "gui.gtk2.font_name"
1403 #define PRS_GUI_MARKED_FG "gui.marked_frame.fg"
1404 #define PRS_GUI_MARKED_BG "gui.marked_frame.bg"
1405 #define PRS_GUI_CONSOLE_OPEN "gui.console_open"
1406 #define PRS_GUI_FILEOPEN_STYLE "gui.fileopen.style"
1407 #define PRS_GUI_RECENT_COUNT_MAX "gui.recent_files_count.max"
1408 #define PRS_GUI_FILEOPEN_DIR "gui.fileopen.dir"
1409 #define PRS_GUI_FILEOPEN_REMEMBERED_DIR "gui.fileopen.remembered_dir"
1410 #define PRS_GUI_FILEOPEN_PREVIEW "gui.fileopen.preview"
1411 #define PRS_GUI_ASK_UNSAVED "gui.ask_unsaved"
1412 #define PRS_GUI_FIND_WRAP "gui.find_wrap"
1413 #define PRS_GUI_USE_PREF_SAVE "gui.use_pref_save"
1414 #define PRS_GUI_GEOMETRY_SAVE_POSITION "gui.geometry.save.position"
1415 #define PRS_GUI_GEOMETRY_SAVE_SIZE "gui.geometry.save.size"
1416 #define PRS_GUI_GEOMETRY_SAVE_MAXIMIZED "gui.geometry.save.maximized"
1417 #define PRS_GUI_GEOMETRY_MAIN_X "gui.geometry.main.x"
1418 #define PRS_GUI_GEOMETRY_MAIN_Y "gui.geometry.main.y"
1419 #define PRS_GUI_GEOMETRY_MAIN_WIDTH "gui.geometry.main.width"
1420 #define PRS_GUI_GEOMETRY_MAIN_HEIGHT "gui.geometry.main.height"
1421 #define PRS_GUI_TOOLBAR_MAIN_SHOW "gui.toolbar_main_show"
1422 #define PRS_GUI_TOOLBAR_MAIN_STYLE "gui.toolbar_main_style"
1423 #define PRS_GUI_WEBBROWSER "gui.webbrowser"
1424 #define PRS_GUI_WINDOW_TITLE "gui.window_title"
1425 #define PRS_GUI_LAYOUT_TYPE "gui.layout_type"
1426 #define PRS_GUI_LAYOUT_CONTENT_1 "gui.layout_content_1"
1427 #define PRS_GUI_LAYOUT_CONTENT_2 "gui.layout_content_2"
1428 #define PRS_GUI_LAYOUT_CONTENT_3 "gui.layout_content_3"
1429 #define PRS_CONSOLE_LOG_LEVEL "console.log.level"
1432 * This applies to more than just captures, so it's not "capture.name_resolve";
1433 * "capture.name_resolve" is supported on input for backwards compatibility.
1435 * It's not a preference for a particular part of Wireshark, it's used all
1436 * over the place, so its name doesn't have two components.
1438 #define PRS_NAME_RESOLVE "name_resolve"
1439 #define PRS_NAME_RESOLVE_CONCURRENCY "name_resolve_concurrency"
1440 #define PRS_CAP_NAME_RESOLVE "capture.name_resolve"
1442 /* values for the capture dialog box */
1443 #define PRS_CAP_DEVICE "capture.device"
1444 #define PRS_CAP_DEVICES_DESCR "capture.devices_descr"
1445 #define PRS_CAP_DEVICES_HIDE "capture.devices_hide"
1446 #define PRS_CAP_PROM_MODE "capture.prom_mode"
1447 #define PRS_CAP_REAL_TIME "capture.real_time_update"
1448 #define PRS_CAP_AUTO_SCROLL "capture.auto_scroll"
1449 #define PRS_CAP_SHOW_INFO "capture.show_info"
1451 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
1452 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
1453 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
1455 static const gchar *pr_formats[] = { "text", "postscript" };
1456 static const gchar *pr_dests[] = { "command", "file" };
1461 } name_resolve_opt_t;
1463 static name_resolve_opt_t name_resolve_opt[] = {
1464 { 'm', RESOLV_MAC },
1465 { 'n', RESOLV_NETWORK },
1466 { 't', RESOLV_TRANSPORT },
1467 { 'C', RESOLV_CONCURRENT },
1470 #define N_NAME_RESOLVE_OPT (sizeof name_resolve_opt / sizeof name_resolve_opt[0])
1473 name_resolve_to_string(guint32 name_resolve)
1475 static char string[N_NAME_RESOLVE_OPT+1];
1478 gboolean all_opts_set = TRUE;
1480 if (name_resolve == RESOLV_NONE)
1483 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1484 if (name_resolve & name_resolve_opt[i].value)
1485 *p++ = name_resolve_opt[i].letter;
1487 all_opts_set = FALSE;
1496 string_to_name_resolve(char *string, guint32 *name_resolve)
1502 while ((c = *string++) != '\0') {
1503 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1504 if (c == name_resolve_opt[i].letter) {
1505 *name_resolve |= name_resolve_opt[i].value;
1509 if (i == N_NAME_RESOLVE_OPT) {
1511 * Unrecognized letter.
1519 static prefs_set_pref_e
1520 set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
1522 GList *col_l, *col_l_elt;
1525 unsigned long int cval;
1530 gchar *dotp, *last_dotp;
1535 if (strcmp(pref_name, PRS_PRINT_FMT) == 0) {
1536 if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) {
1537 prefs.pr_format = PR_FMT_TEXT;
1538 } else if (strcmp(value, pr_formats[PR_FMT_PS]) == 0) {
1539 prefs.pr_format = PR_FMT_PS;
1541 return PREFS_SET_SYNTAX_ERR;
1543 } else if (strcmp(pref_name, PRS_PRINT_DEST) == 0) {
1544 if (strcmp(value, pr_dests[PR_DEST_CMD]) == 0) {
1545 prefs.pr_dest = PR_DEST_CMD;
1546 } else if (strcmp(value, pr_dests[PR_DEST_FILE]) == 0) {
1547 prefs.pr_dest = PR_DEST_FILE;
1549 return PREFS_SET_SYNTAX_ERR;
1551 } else if (strcmp(pref_name, PRS_PRINT_FILE) == 0) {
1552 if (prefs.pr_file) g_free(prefs.pr_file);
1553 prefs.pr_file = g_strdup(value);
1554 } else if (strcmp(pref_name, PRS_PRINT_CMD) == 0) {
1555 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
1556 prefs.pr_cmd = g_strdup(value);
1557 } else if (strcmp(pref_name, PRS_COL_FMT) == 0) {
1558 col_l = get_string_list(value);
1560 return PREFS_SET_SYNTAX_ERR;
1561 if ((g_list_length(col_l) % 2) != 0) {
1562 /* A title didn't have a matching format. */
1563 clear_string_list(col_l);
1564 return PREFS_SET_SYNTAX_ERR;
1566 /* Check to make sure all column formats are valid. */
1567 col_l_elt = g_list_first(col_l);
1569 /* Make sure the title isn't empty. */
1570 if (strcmp(col_l_elt->data, "") == 0) {
1572 clear_string_list(col_l);
1573 return PREFS_SET_SYNTAX_ERR;
1576 /* Go past the title. */
1577 col_l_elt = col_l_elt->next;
1579 /* Check the format. */
1580 if (get_column_format_from_str(col_l_elt->data) == -1) {
1581 /* It's not a valid column format. */
1582 clear_string_list(col_l);
1583 return PREFS_SET_SYNTAX_ERR;
1586 /* Go past the format. */
1587 col_l_elt = col_l_elt->next;
1589 free_col_info(&prefs);
1590 prefs.col_list = NULL;
1591 llen = g_list_length(col_l);
1592 prefs.num_cols = llen / 2;
1593 col_l_elt = g_list_first(col_l);
1595 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
1596 cfmt->title = g_strdup(col_l_elt->data);
1597 col_l_elt = col_l_elt->next;
1598 cfmt->fmt = g_strdup(col_l_elt->data);
1599 col_l_elt = col_l_elt->next;
1600 prefs.col_list = g_list_append(prefs.col_list, cfmt);
1602 clear_string_list(col_l);
1603 } else if (strcmp(pref_name, PRS_STREAM_CL_FG) == 0) {
1604 cval = strtoul(value, NULL, 16);
1605 prefs.st_client_fg.pixel = 0;
1606 prefs.st_client_fg.red = RED_COMPONENT(cval);
1607 prefs.st_client_fg.green = GREEN_COMPONENT(cval);
1608 prefs.st_client_fg.blue = BLUE_COMPONENT(cval);
1609 } else if (strcmp(pref_name, PRS_STREAM_CL_BG) == 0) {
1610 cval = strtoul(value, NULL, 16);
1611 prefs.st_client_bg.pixel = 0;
1612 prefs.st_client_bg.red = RED_COMPONENT(cval);
1613 prefs.st_client_bg.green = GREEN_COMPONENT(cval);
1614 prefs.st_client_bg.blue = BLUE_COMPONENT(cval);
1615 } else if (strcmp(pref_name, PRS_STREAM_SR_FG) == 0) {
1616 cval = strtoul(value, NULL, 16);
1617 prefs.st_server_fg.pixel = 0;
1618 prefs.st_server_fg.red = RED_COMPONENT(cval);
1619 prefs.st_server_fg.green = GREEN_COMPONENT(cval);
1620 prefs.st_server_fg.blue = BLUE_COMPONENT(cval);
1621 } else if (strcmp(pref_name, PRS_STREAM_SR_BG) == 0) {
1622 cval = strtoul(value, NULL, 16);
1623 prefs.st_server_bg.pixel = 0;
1624 prefs.st_server_bg.red = RED_COMPONENT(cval);
1625 prefs.st_server_bg.green = GREEN_COMPONENT(cval);
1626 prefs.st_server_bg.blue = BLUE_COMPONENT(cval);
1627 } else if (strcmp(pref_name, PRS_GUI_SCROLLBAR_ON_RIGHT) == 0) {
1628 if (strcasecmp(value, "true") == 0) {
1629 prefs.gui_scrollbar_on_right = TRUE;
1632 prefs.gui_scrollbar_on_right = FALSE;
1634 } else if (strcmp(pref_name, PRS_GUI_PLIST_SEL_BROWSE) == 0) {
1635 if (strcasecmp(value, "true") == 0) {
1636 prefs.gui_plist_sel_browse = TRUE;
1639 prefs.gui_plist_sel_browse = FALSE;
1641 } else if (strcmp(pref_name, PRS_GUI_PTREE_SEL_BROWSE) == 0) {
1642 if (strcasecmp(value, "true") == 0) {
1643 prefs.gui_ptree_sel_browse = TRUE;
1646 prefs.gui_ptree_sel_browse = FALSE;
1648 } else if (strcmp(pref_name, PRS_GUI_ALTERN_COLORS) == 0) {
1649 if (strcasecmp(value, "true") == 0) {
1650 prefs.gui_altern_colors = TRUE;
1653 prefs.gui_altern_colors = FALSE;
1655 } else if (strcmp(pref_name, PRS_GUI_PTREE_LINE_STYLE) == 0) {
1656 prefs.gui_ptree_line_style =
1657 find_index_from_string_array(value, gui_ptree_line_style_text, 0);
1658 } else if (strcmp(pref_name, PRS_GUI_PTREE_EXPANDER_STYLE) == 0) {
1659 prefs.gui_ptree_expander_style =
1660 find_index_from_string_array(value, gui_ptree_expander_style_text, 1);
1661 } else if (strcmp(pref_name, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE) == 0) {
1662 prefs.gui_hex_dump_highlight_style =
1663 find_index_from_string_array(value, gui_hex_dump_highlight_style_text, 1);
1664 } else if (strcmp(pref_name, PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR) == 0) {
1665 if (strcasecmp(value, "true") == 0) {
1666 prefs.filter_toolbar_show_in_statusbar = TRUE;
1669 prefs.filter_toolbar_show_in_statusbar = FALSE;
1671 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_SHOW) == 0) {
1672 /* obsoleted by recent setting */
1673 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_STYLE) == 0) {
1674 /* see toolbar.c for details, "icons only" is default */
1675 prefs.gui_toolbar_main_style =
1676 find_index_from_string_array(value, gui_toolbar_style_text,
1678 } else if (strcmp(pref_name, PRS_GUI_FONT_NAME_1) == 0) {
1679 if (prefs.gui_font_name1 != NULL)
1680 g_free(prefs.gui_font_name1);
1681 prefs.gui_font_name1 = g_strdup(value);
1682 } else if (strcmp(pref_name, PRS_GUI_FONT_NAME_2) == 0) {
1683 if (prefs.gui_font_name2 != NULL)
1684 g_free(prefs.gui_font_name2);
1685 prefs.gui_font_name2 = g_strdup(value);
1686 } else if (strcmp(pref_name, PRS_GUI_MARKED_FG) == 0) {
1687 cval = strtoul(value, NULL, 16);
1688 prefs.gui_marked_fg.pixel = 0;
1689 prefs.gui_marked_fg.red = RED_COMPONENT(cval);
1690 prefs.gui_marked_fg.green = GREEN_COMPONENT(cval);
1691 prefs.gui_marked_fg.blue = BLUE_COMPONENT(cval);
1692 } else if (strcmp(pref_name, PRS_GUI_MARKED_BG) == 0) {
1693 cval = strtoul(value, NULL, 16);
1694 prefs.gui_marked_bg.pixel = 0;
1695 prefs.gui_marked_bg.red = RED_COMPONENT(cval);
1696 prefs.gui_marked_bg.green = GREEN_COMPONENT(cval);
1697 prefs.gui_marked_bg.blue = BLUE_COMPONENT(cval);
1698 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_POSITION) == 0) {
1699 if (strcasecmp(value, "true") == 0) {
1700 prefs.gui_geometry_save_position = TRUE;
1703 prefs.gui_geometry_save_position = FALSE;
1705 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_SIZE) == 0) {
1706 if (strcasecmp(value, "true") == 0) {
1707 prefs.gui_geometry_save_size = TRUE;
1710 prefs.gui_geometry_save_size = FALSE;
1712 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_MAXIMIZED) == 0) {
1713 if (strcasecmp(value, "true") == 0) {
1714 prefs.gui_geometry_save_maximized = TRUE;
1717 prefs.gui_geometry_save_maximized = FALSE;
1719 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_X) == 0) { /* deprecated */
1720 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_Y) == 0) { /* deprecated */
1721 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_WIDTH) == 0) { /* deprecated */
1722 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_HEIGHT) == 0) { /* deprecated */
1723 } else if (strcmp(pref_name, PRS_GUI_CONSOLE_OPEN) == 0) {
1724 prefs.gui_console_open =
1725 find_index_from_string_array(value, gui_console_open_text,
1726 console_open_never);
1727 } else if (strcmp(pref_name, PRS_GUI_RECENT_COUNT_MAX) == 0) {
1728 prefs.gui_recent_files_count_max = strtoul(value, NULL, 10);
1729 if (prefs.gui_recent_files_count_max == 0) {
1730 /* We really should put up a dialog box here ... */
1731 prefs.gui_recent_files_count_max = 10;
1733 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_STYLE) == 0) {
1734 prefs.gui_fileopen_style =
1735 find_index_from_string_array(value, gui_fileopen_style_text,
1736 FO_STYLE_LAST_OPENED);
1737 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_DIR) == 0) {
1738 if (prefs.gui_fileopen_dir != NULL)
1739 g_free(prefs.gui_fileopen_dir);
1740 prefs.gui_fileopen_dir = g_strdup(value);
1741 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_REMEMBERED_DIR) == 0) { /* deprecated */
1742 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_PREVIEW) == 0) {
1743 prefs.gui_fileopen_preview = strtoul(value, NULL, 10);
1744 } else if (strcmp(pref_name, PRS_GUI_ASK_UNSAVED) == 0) {
1745 if (strcasecmp(value, "true") == 0) {
1746 prefs.gui_ask_unsaved = TRUE;
1749 prefs.gui_ask_unsaved = FALSE;
1751 } else if (strcmp(pref_name, PRS_GUI_FIND_WRAP) == 0) {
1752 if (strcasecmp(value, "true") == 0) {
1753 prefs.gui_find_wrap = TRUE;
1756 prefs.gui_find_wrap = FALSE;
1758 } else if (strcmp(pref_name, PRS_GUI_USE_PREF_SAVE) == 0) {
1759 if (strcasecmp(value, "true") == 0) {
1760 prefs.gui_use_pref_save = TRUE;
1763 prefs.gui_use_pref_save = FALSE;
1765 } else if (strcmp(pref_name, PRS_GUI_WEBBROWSER) == 0) {
1766 g_free(prefs.gui_webbrowser);
1767 prefs.gui_webbrowser = g_strdup(value);
1768 } else if (strcmp(pref_name, PRS_GUI_WINDOW_TITLE) == 0) {
1769 if (prefs.gui_window_title != NULL)
1770 g_free(prefs.gui_window_title);
1771 prefs.gui_window_title = g_strdup(value);
1772 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_TYPE) == 0) {
1773 prefs.gui_layout_type = strtoul(value, NULL, 10);
1774 if (prefs.gui_layout_type == layout_unused ||
1775 prefs.gui_layout_type >= layout_type_max) {
1776 /* XXX - report an error? It's not a syntax error - we'd need to
1777 add a way of reporting a *semantic* error. */
1778 prefs.gui_layout_type = layout_type_5;
1780 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_1) == 0) {
1781 prefs.gui_layout_content_1 =
1782 find_index_from_string_array(value, gui_layout_content_text, 0);
1783 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_2) == 0) {
1784 prefs.gui_layout_content_2 =
1785 find_index_from_string_array(value, gui_layout_content_text, 0);
1786 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_3) == 0) {
1787 prefs.gui_layout_content_3 =
1788 find_index_from_string_array(value, gui_layout_content_text, 0);
1789 } else if (strcmp(pref_name, PRS_CONSOLE_LOG_LEVEL) == 0) {
1790 prefs.console_log_level = strtoul(value, NULL, 10);
1792 /* handle the capture options */
1793 } else if (strcmp(pref_name, PRS_CAP_DEVICE) == 0) {
1794 if (prefs.capture_device != NULL)
1795 g_free(prefs.capture_device);
1796 prefs.capture_device = g_strdup(value);
1797 } else if (strcmp(pref_name, PRS_CAP_DEVICES_DESCR) == 0) {
1798 if (prefs.capture_devices_descr != NULL)
1799 g_free(prefs.capture_devices_descr);
1800 prefs.capture_devices_descr = g_strdup(value);
1801 } else if (strcmp(pref_name, PRS_CAP_DEVICES_HIDE) == 0) {
1802 if (prefs.capture_devices_hide != NULL)
1803 g_free(prefs.capture_devices_hide);
1804 prefs.capture_devices_hide = g_strdup(value);
1805 } else if (strcmp(pref_name, PRS_CAP_PROM_MODE) == 0) {
1806 prefs.capture_prom_mode = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1807 } else if (strcmp(pref_name, PRS_CAP_REAL_TIME) == 0) {
1808 prefs.capture_real_time = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1809 } else if (strcmp(pref_name, PRS_CAP_AUTO_SCROLL) == 0) {
1810 prefs.capture_auto_scroll = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1811 } else if (strcmp(pref_name, PRS_CAP_SHOW_INFO) == 0) {
1812 prefs.capture_show_info = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1814 /* handle the global options */
1815 } else if (strcmp(pref_name, PRS_NAME_RESOLVE) == 0 ||
1816 strcmp(pref_name, PRS_CAP_NAME_RESOLVE) == 0) {
1818 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
1819 * RESOLV_ALL and RESOLV_NONE.
1821 * Otherwise, we treat it as a list of name types we want to resolve.
1823 if (strcasecmp(value, "true") == 0)
1824 prefs.name_resolve = RESOLV_ALL;
1825 else if (strcasecmp(value, "false") == 0)
1826 prefs.name_resolve = RESOLV_NONE;
1828 prefs.name_resolve = RESOLV_NONE; /* start out with none set */
1829 if (string_to_name_resolve(value, &prefs.name_resolve) != '\0')
1830 return PREFS_SET_SYNTAX_ERR;
1832 } else if (strcmp(pref_name, PRS_NAME_RESOLVE_CONCURRENCY) == 0) {
1833 prefs.name_resolve_concurrency = strtol(value, NULL, 10);
1835 /* To which module does this preference belong? */
1837 last_dotp = pref_name;
1840 dotp = strchr(last_dotp, '.');
1843 /* no such module */
1844 return PREFS_SET_NO_SUCH_PREF;
1847 /* no ".", so no module/name separator */
1848 return PREFS_SET_SYNTAX_ERR;
1854 *dotp = '\0'; /* separate module and preference name */
1855 module = prefs_find_module(pref_name);
1858 * XXX - "Diameter" rather than "diameter" was used in earlier
1859 * versions of Wireshark; if we didn't find the module, and its name
1860 * was "Diameter", look for "diameter" instead.
1862 * In addition, the BEEP protocol used to be the BXXP protocol,
1863 * so if we didn't find the module, and its name was "bxxp",
1864 * look for "beep" instead.
1866 * Also, the preferences for GTP v0 and v1 were combined under
1867 * a single "gtp" heading, and the preferences for SMPP were
1868 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
1869 * However, SMPP now has its own preferences, so we just map
1870 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
1872 if (module == NULL) {
1873 if (strcmp(pref_name, "Diameter") == 0)
1874 module = prefs_find_module("diameter");
1875 else if (strcmp(pref_name, "bxxp") == 0)
1876 module = prefs_find_module("beep");
1877 else if (strcmp(pref_name, "gtpv0") == 0 ||
1878 strcmp(pref_name, "gtpv1") == 0)
1879 module = prefs_find_module("gtp");
1880 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
1881 module = prefs_find_module("gsm-sms-ud");
1883 *dotp = '.'; /* put the preference string back */
1884 dotp++; /* skip past separator to preference name */
1888 pref = find_preference(module, dotp);
1891 if (strcmp(module->name, "mgcp") == 0) {
1893 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
1894 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
1895 * were used in earlier versions of Wireshark; if we didn't find the
1896 * preference, it was an MGCP preference, and its name was
1897 * "display raw text toggle" or "display dissect tree", look for
1898 * "display_raw_text" or "display_dissect_tree" instead.
1900 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
1901 * the gateway and callagent ports were given those names; we interpret
1902 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
1903 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
1904 * they were registered by the MCCP dissector and thus that's the
1905 * order in which they were written to the preferences file. (If
1906 * we're not reading the preferences file, but are handling stuff
1907 * from a "-o" command-line option, we have no clue which the user
1908 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
1909 * or "mgcp.{tcp,udp}.callagent_port" instead.)
1911 if (strcmp(dotp, "display raw text toggle") == 0)
1912 pref = find_preference(module, "display_raw_text");
1913 else if (strcmp(dotp, "display dissect tree") == 0)
1914 pref = find_preference(module, "display_dissect_tree");
1915 else if (strcmp(dotp, "tcp.port") == 0) {
1916 mgcp_tcp_port_count++;
1917 if (mgcp_tcp_port_count == 1) {
1918 /* It's the first one */
1919 pref = find_preference(module, "tcp.gateway_port");
1920 } else if (mgcp_tcp_port_count == 2) {
1921 /* It's the second one */
1922 pref = find_preference(module, "tcp.callagent_port");
1924 /* Otherwise it's from the command line, and we don't bother
1926 } else if (strcmp(dotp, "udp.port") == 0) {
1927 mgcp_udp_port_count++;
1928 if (mgcp_udp_port_count == 1) {
1929 /* It's the first one */
1930 pref = find_preference(module, "udp.gateway_port");
1931 } else if (mgcp_udp_port_count == 2) {
1932 /* It's the second one */
1933 pref = find_preference(module, "udp.callagent_port");
1935 /* Otherwise it's from the command line, and we don't bother
1938 } else if (strcmp(module->name, "smb") == 0) {
1939 /* Handle old names for SMB preferences. */
1940 if (strcmp(dotp, "smb.trans.reassembly") == 0)
1941 pref = find_preference(module, "trans_reassembly");
1942 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
1943 pref = find_preference(module, "dcerpc_reassembly");
1944 } else if (strcmp(module->name, "ndmp") == 0) {
1945 /* Handle old names for NDMP preferences. */
1946 if (strcmp(dotp, "ndmp.desegment") == 0)
1947 pref = find_preference(module, "desegment");
1948 } else if (strcmp(module->name, "diameter") == 0) {
1949 /* Handle old names for Diameter preferences. */
1950 if (strcmp(dotp, "diameter.desegment") == 0)
1951 pref = find_preference(module, "desegment");
1952 } else if (strcmp(module->name, "pcli") == 0) {
1953 /* Handle old names for PCLI preferences. */
1954 if (strcmp(dotp, "pcli.udp_port") == 0)
1955 pref = find_preference(module, "udp_port");
1956 } else if (strcmp(module->name, "artnet") == 0) {
1957 /* Handle old names for ARTNET preferences. */
1958 if (strcmp(dotp, "artnet.udp_port") == 0)
1959 pref = find_preference(module, "udp_port");
1960 } else if (strcmp(module->name, "mapi") == 0) {
1961 /* Handle old names for MAPI preferences. */
1962 if (strcmp(dotp, "mapi_decrypt") == 0)
1963 pref = find_preference(module, "decrypt");
1964 } else if (strcmp(module->name, "fc") == 0) {
1965 /* Handle old names for Fibre Channel preferences. */
1966 if (strcmp(dotp, "reassemble_fc") == 0)
1967 pref = find_preference(module, "reassemble");
1968 else if (strcmp(dotp, "fc_max_frame_size") == 0)
1969 pref = find_preference(module, "max_frame_size");
1970 } else if (strcmp(module->name, "fcip") == 0) {
1971 /* Handle old names for Fibre Channel-over-IP preferences. */
1972 if (strcmp(dotp, "desegment_fcip_messages") == 0)
1973 pref = find_preference(module, "desegment");
1974 else if (strcmp(dotp, "fcip_port") == 0)
1975 pref = find_preference(module, "target_port");
1976 } else if (strcmp(module->name, "gtp") == 0) {
1977 /* Handle old names for GTP preferences. */
1978 if (strcmp(dotp, "gtpv0_port") == 0)
1979 pref = find_preference(module, "v0_port");
1980 else if (strcmp(dotp, "gtpv1c_port") == 0)
1981 pref = find_preference(module, "v1c_port");
1982 else if (strcmp(dotp, "gtpv1u_port") == 0)
1983 pref = find_preference(module, "v1u_port");
1984 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
1985 pref = find_preference(module, "dissect_tpdu");
1986 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
1987 pref = find_preference(module, "v0_dissect_cdr_as");
1988 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
1989 pref = find_preference(module, "v0_check_etsi");
1990 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
1991 pref = find_preference(module, "v1_check_etsi");
1992 } else if (strcmp(module->name, "ip") == 0) {
1993 /* Handle old names for IP preferences. */
1994 if (strcmp(dotp, "ip_summary_in_tree") == 0)
1995 pref = find_preference(module, "summary_in_tree");
1996 } else if (strcmp(module->name, "iscsi") == 0) {
1997 /* Handle old names for iSCSI preferences. */
1998 if (strcmp(dotp, "iscsi_port") == 0)
1999 pref = find_preference(module, "target_port");
2000 } else if (strcmp(module->name, "lmp") == 0) {
2001 /* Handle old names for LMP preferences. */
2002 if (strcmp(dotp, "lmp_version") == 0)
2003 pref = find_preference(module, "version");
2004 } else if (strcmp(module->name, "mtp3") == 0) {
2005 /* Handle old names for MTP3 preferences. */
2006 if (strcmp(dotp, "mtp3_standard") == 0)
2007 pref = find_preference(module, "standard");
2008 else if (strcmp(dotp, "net_addr_format") == 0)
2009 pref = find_preference(module, "addr_format");
2010 } else if (strcmp(module->name, "nlm") == 0) {
2011 /* Handle old names for NLM preferences. */
2012 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
2013 pref = find_preference(module, "msg_res_matching");
2014 } else if (strcmp(module->name, "ppp") == 0) {
2015 /* Handle old names for PPP preferences. */
2016 if (strcmp(dotp, "ppp_fcs") == 0)
2017 pref = find_preference(module, "fcs_type");
2018 else if (strcmp(dotp, "ppp_vj") == 0)
2019 pref = find_preference(module, "decompress_vj");
2020 } else if (strcmp(module->name, "rsvp") == 0) {
2021 /* Handle old names for RSVP preferences. */
2022 if (strcmp(dotp, "rsvp_process_bundle") == 0)
2023 pref = find_preference(module, "process_bundle");
2024 } else if (strcmp(module->name, "tcp") == 0) {
2025 /* Handle old names for TCP preferences. */
2026 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
2027 pref = find_preference(module, "summary_in_tree");
2028 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
2029 pref = find_preference(module, "analyze_sequence_numbers");
2030 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
2031 pref = find_preference(module, "relative_sequence_numbers");
2032 } else if (strcmp(module->name, "udp") == 0) {
2033 /* Handle old names for UDP preferences. */
2034 if (strcmp(dotp, "udp_summary_in_tree") == 0)
2035 pref = find_preference(module, "summary_in_tree");
2036 } else if (strcmp(module->name, "ndps") == 0) {
2037 /* Handle old names for NDPS preferences. */
2038 if (strcmp(dotp, "desegment_ndps") == 0)
2039 pref = find_preference(module, "desegment_tcp");
2040 } else if (strcmp(module->name, "http") == 0) {
2041 /* Handle old names for HTTP preferences. */
2042 if (strcmp(dotp, "desegment_http_headers") == 0)
2043 pref = find_preference(module, "desegment_headers");
2044 else if (strcmp(dotp, "desegment_http_body") == 0)
2045 pref = find_preference(module, "desegment_body");
2046 } else if (strcmp(module->name, "smpp") == 0) {
2047 /* Handle preferences that moved from SMPP. */
2048 module_t *new_module = prefs_find_module("gsm-sms-ud");
2050 if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
2051 pref = find_preference(new_module, "port_number_udh_means_wsp");
2052 else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
2053 pref = find_preference(new_module, "try_dissect_1st_fragment");
2055 } else if (strcmp(module->name, "asn1") == 0) {
2056 /* Handle old generic ASN.1 preferences (it's not really a
2057 rename, as the new preferences support multiple ports,
2058 but we might as well copy them over). */
2059 if (strcmp(dotp, "tcp_port") == 0)
2060 pref = find_preference(module, "tcp_ports");
2061 else if (strcmp(dotp, "udp_port") == 0)
2062 pref = find_preference(module, "udp_ports");
2063 else if (strcmp(dotp, "sctp_port") == 0)
2064 pref = find_preference(module, "sctp_ports");
2065 } else if (strcmp(module->name, "llcgprs") == 0) {
2066 if (strcmp(dotp, "ignore_cipher_bit") == 0)
2067 pref = find_preference(module, "autodetect_cipher_bit");
2071 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
2073 switch (pref->type) {
2076 uval = strtoul(value, &p, pref->info.base);
2077 if (p == value || *p != '\0')
2078 return PREFS_SET_SYNTAX_ERR; /* number was bad */
2079 if (*pref->varp.uint != uval) {
2080 module->prefs_changed = TRUE;
2081 *pref->varp.uint = uval;
2086 /* XXX - give an error if it's neither "true" nor "false"? */
2087 if (strcasecmp(value, "true") == 0)
2091 if (*pref->varp.boolp != bval) {
2092 module->prefs_changed = TRUE;
2093 *pref->varp.boolp = bval;
2098 /* XXX - give an error if it doesn't match? */
2099 enum_val = find_val_for_string(value,
2100 pref->info.enum_info.enumvals, 1);
2101 if (*pref->varp.enump != enum_val) {
2102 module->prefs_changed = TRUE;
2103 *pref->varp.enump = enum_val;
2108 if (strcmp(*pref->varp.string, value) != 0) {
2109 module->prefs_changed = TRUE;
2110 g_free((void *)*pref->varp.string);
2111 *pref->varp.string = g_strdup(value);
2119 if (range_convert_str(&newrange, value, pref->info.max_value) !=
2121 /* XXX - distinguish between CVT_SYNTAX_ERROR and
2122 CVT_NUMBER_TOO_BIG */
2123 return PREFS_SET_SYNTAX_ERR; /* number was bad */
2126 if (!ranges_are_equal(*pref->varp.range, newrange)) {
2127 module->prefs_changed = TRUE;
2128 g_free(*pref->varp.range);
2129 *pref->varp.range = newrange;
2134 case PREF_STATIC_TEXT:
2140 return PREFS_SET_OBSOLETE; /* no such preference any more */
2144 return PREFS_SET_OK;
2153 * Write out a single preference.
2156 write_pref(gpointer data, gpointer user_data)
2158 pref_t *pref = data;
2159 write_pref_arg_t *arg = user_data;
2160 const enum_val_t *enum_valp;
2161 const char *val_string;
2163 if (pref->type == PREF_OBSOLETE) {
2165 * This preference is no longer supported; it's not a
2166 * real preference, so we don't write it out (i.e., we
2167 * treat it as if it weren't found in the list of
2168 * preferences, and we weren't called in the first place).
2173 fprintf(arg->pf, "\n# %s\n", pref->description);
2175 switch (pref->type) {
2178 switch (pref->info.base) {
2181 fprintf(arg->pf, "# A decimal number.\n");
2182 fprintf(arg->pf, "%s.%s: %u\n", arg->module->name,
2183 pref->name, *pref->varp.uint);
2187 fprintf(arg->pf, "# An octal number.\n");
2188 fprintf(arg->pf, "%s.%s: %#o\n", arg->module->name,
2189 pref->name, *pref->varp.uint);
2193 fprintf(arg->pf, "# A hexadecimal number.\n");
2194 fprintf(arg->pf, "%s.%s: %#x\n", arg->module->name,
2195 pref->name, *pref->varp.uint);
2201 fprintf(arg->pf, "# TRUE or FALSE (case-insensitive).\n");
2202 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2203 *pref->varp.boolp ? "TRUE" : "FALSE");
2208 * For now, we save the "description" value, so that if we
2209 * save the preferences older versions of Wireshark can at
2210 * least read preferences that they supported; we support
2211 * either the short name or the description when reading
2212 * the preferences file or a "-o" option.
2214 fprintf(arg->pf, "# One of: ");
2215 enum_valp = pref->info.enum_info.enumvals;
2217 while (enum_valp->name != NULL) {
2218 if (enum_valp->value == *pref->varp.enump)
2219 val_string = enum_valp->description;
2220 fprintf(arg->pf, "%s", enum_valp->description);
2222 if (enum_valp->name == NULL)
2223 fprintf(arg->pf, "\n");
2225 fprintf(arg->pf, ", ");
2227 fprintf(arg->pf, "# (case-insensitive).\n");
2228 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name,
2229 pref->name, val_string);
2233 fprintf(arg->pf, "# A string.\n");
2234 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2235 *pref->varp.string);
2242 range_string = range_convert_range(*pref->varp.range);
2243 fprintf(arg->pf, "# A string denoting an positive integer range (e.g., \"1-20,30-40\").\n");
2244 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2249 case PREF_STATIC_TEXT:
2256 g_assert_not_reached();
2262 write_module_prefs(gpointer data, gpointer user_data)
2264 write_pref_arg_t arg;
2268 g_list_foreach(arg.module->prefs, write_pref, &arg);
2271 /* Write out "prefs" to the user's preferences file, and return 0.
2273 If the preferences file path is NULL, write to stdout.
2275 If we got an error, stuff a pointer to the path of the preferences file
2276 into "*pf_path_return", and return the errno. */
2278 write_prefs(char **pf_path_return)
2285 /* Needed for "-G defaultprefs" */
2289 * - Split output lines longer than MAX_VAL_LEN
2290 * - Create a function for the preference directory check/creation
2291 * so that duplication can be avoided with filter.c
2294 if (pf_path_return != NULL) {
2295 pf_path = get_persconffile_path(PF_NAME, TRUE);
2296 if ((pf = eth_fopen(pf_path, "w")) == NULL) {
2297 *pf_path_return = pf_path;
2304 fputs("# Configuration file for Wireshark " VERSION ".\n"
2306 "# This file is regenerated each time preferences are saved within\n"
2307 "# Wireshark. Making manual changes should be safe, however.\n", pf);
2309 fprintf (pf, "\n######## User Interface ########\n");
2311 fprintf(pf, "\n# Vertical scrollbars should be on right side?\n");
2312 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2313 fprintf(pf, PRS_GUI_SCROLLBAR_ON_RIGHT ": %s\n",
2314 prefs.gui_scrollbar_on_right == TRUE ? "TRUE" : "FALSE");
2316 fprintf(pf, "\n# Packet-list selection bar can be used to browse w/o selecting?\n");
2317 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2318 fprintf(pf, PRS_GUI_PLIST_SEL_BROWSE ": %s\n",
2319 prefs.gui_plist_sel_browse == TRUE ? "TRUE" : "FALSE");
2321 fprintf(pf, "\n# Protocol-tree selection bar can be used to browse w/o selecting?\n");
2322 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2323 fprintf(pf, PRS_GUI_PTREE_SEL_BROWSE ": %s\n",
2324 prefs.gui_ptree_sel_browse == TRUE ? "TRUE" : "FALSE");
2326 fprintf(pf, "\n# Alternating colors in TreeViews?\n");
2327 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2328 fprintf(pf, PRS_GUI_ALTERN_COLORS ": %s\n",
2329 prefs.gui_altern_colors == TRUE ? "TRUE" : "FALSE");
2331 fprintf(pf, "\n# Place filter toolbar inside the statusbar?\n");
2332 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2333 fprintf(pf, PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR ": %s\n",
2334 prefs.filter_toolbar_show_in_statusbar == TRUE ? "TRUE" : "FALSE");
2336 fprintf(pf, "\n# Protocol-tree line style.\n");
2337 fprintf(pf, "# One of: NONE, SOLID, DOTTED, TABBED\n");
2338 fprintf(pf, PRS_GUI_PTREE_LINE_STYLE ": %s\n",
2339 gui_ptree_line_style_text[prefs.gui_ptree_line_style]);
2341 fprintf(pf, "\n# Protocol-tree expander style.\n");
2342 fprintf(pf, "# One of: NONE, SQUARE, TRIANGLE, CIRCULAR\n");
2343 fprintf(pf, PRS_GUI_PTREE_EXPANDER_STYLE ": %s\n",
2344 gui_ptree_expander_style_text[prefs.gui_ptree_expander_style]);
2346 fprintf(pf, "\n# Hex dump highlight style.\n");
2347 fprintf(pf, "# One of: BOLD, INVERSE\n");
2348 fprintf(pf, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE ": %s\n",
2349 gui_hex_dump_highlight_style_text[prefs.gui_hex_dump_highlight_style]);
2351 fprintf(pf, "\n# Main Toolbar style.\n");
2352 fprintf(pf, "# One of: ICONS, TEXT, BOTH\n");
2353 fprintf(pf, PRS_GUI_TOOLBAR_MAIN_STYLE ": %s\n",
2354 gui_toolbar_style_text[prefs.gui_toolbar_main_style]);
2356 fprintf(pf, "\n# Save window position at exit?\n");
2357 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2358 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_POSITION ": %s\n",
2359 prefs.gui_geometry_save_position == TRUE ? "TRUE" : "FALSE");
2361 fprintf(pf, "\n# Save window size at exit?\n");
2362 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2363 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_SIZE ": %s\n",
2364 prefs.gui_geometry_save_size == TRUE ? "TRUE" : "FALSE");
2366 fprintf(pf, "\n# Save window maximized state at exit (GTK2 only)?\n");
2367 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2368 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_MAXIMIZED ": %s\n",
2369 prefs.gui_geometry_save_maximized == TRUE ? "TRUE" : "FALSE");
2371 fprintf(pf, "\n# Open a console window (WIN32 only)?\n");
2372 fprintf(pf, "# One of: NEVER, AUTOMATIC, ALWAYS\n");
2373 fprintf(pf, PRS_GUI_CONSOLE_OPEN ": %s\n",
2374 gui_console_open_text[prefs.gui_console_open]);
2376 fprintf(pf, "\n# The max. number of items in the open recent files list.\n");
2377 fprintf(pf, "# A decimal number.\n");
2378 fprintf(pf, PRS_GUI_RECENT_COUNT_MAX ": %d\n",
2379 prefs.gui_recent_files_count_max);
2381 fprintf(pf, "\n# Where to start the File Open dialog box.\n");
2382 fprintf(pf, "# One of: LAST_OPENED, SPECIFIED\n");
2383 fprintf(pf, PRS_GUI_FILEOPEN_STYLE ": %s\n",
2384 gui_fileopen_style_text[prefs.gui_fileopen_style]);
2386 if (prefs.gui_fileopen_dir != NULL) {
2387 fprintf(pf, "\n# Directory to start in when opening File Open dialog.\n");
2388 fprintf(pf, PRS_GUI_FILEOPEN_DIR ": %s\n",
2389 prefs.gui_fileopen_dir);
2392 fprintf(pf, "\n# The preview timeout in the File Open dialog.\n");
2393 fprintf(pf, "# A decimal number (in seconds).\n");
2394 fprintf(pf, PRS_GUI_FILEOPEN_PREVIEW ": %d\n",
2395 prefs.gui_fileopen_preview);
2397 fprintf(pf, "\n# Ask to save unsaved capture files?\n");
2398 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2399 fprintf(pf, PRS_GUI_ASK_UNSAVED ": %s\n",
2400 prefs.gui_ask_unsaved == TRUE ? "TRUE" : "FALSE");
2402 fprintf(pf, "\n# Wrap to beginning/end of file during search?\n");
2403 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2404 fprintf(pf, PRS_GUI_FIND_WRAP ": %s\n",
2405 prefs.gui_find_wrap == TRUE ? "TRUE" : "FALSE");
2407 fprintf(pf, "\n# Settings dialogs use a save button?\n");
2408 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2409 fprintf(pf, PRS_GUI_USE_PREF_SAVE ": %s\n",
2410 prefs.gui_use_pref_save == TRUE ? "TRUE" : "FALSE");
2412 fprintf(pf, "\n# The path to the webbrowser.\n");
2413 fprintf(pf, "# Ex: mozilla %%s\n");
2414 fprintf(pf, PRS_GUI_WEBBROWSER ": %s\n", prefs.gui_webbrowser);
2416 fprintf(pf, "\n# Custom window title. (Prepended to existing titles.)\n");
2417 fprintf(pf, PRS_GUI_WINDOW_TITLE ": %s\n",
2418 prefs.gui_window_title);
2420 fprintf (pf, "\n######## User Interface: Layout ########\n");
2422 fprintf(pf, "\n# Layout type (1-6).\n");
2423 fprintf(pf, PRS_GUI_LAYOUT_TYPE ": %d\n",
2424 prefs.gui_layout_type);
2426 fprintf(pf, "\n# Layout content of the panes (1-3).\n");
2427 fprintf(pf, "# One of: NONE, PLIST, PDETAILS, PBYTES\n");
2428 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_1 ": %s\n",
2429 gui_layout_content_text[prefs.gui_layout_content_1]);
2430 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_2 ": %s\n",
2431 gui_layout_content_text[prefs.gui_layout_content_2]);
2432 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_3 ": %s\n",
2433 gui_layout_content_text[prefs.gui_layout_content_3]);
2435 fprintf (pf, "\n######## User Interface: Columns ########\n");
2437 clp = prefs.col_list;
2440 cfmt = (fmt_data *) clp->data;
2441 col_l = g_list_append(col_l, cfmt->title);
2442 col_l = g_list_append(col_l, cfmt->fmt);
2445 fprintf (pf, "\n# Packet list column format.\n");
2446 fprintf (pf, "# Each pair of strings consists of a column title and its format.\n");
2447 fprintf (pf, "%s: %s\n", PRS_COL_FMT, put_string_list(col_l));
2448 /* This frees the list of strings, but not the strings to which it
2449 refers; that's what we want, as we haven't copied those strings,
2450 we just referred to them. */
2453 fprintf (pf, "\n######## User Interface: Font ########\n");
2455 fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes (GTK version 1).\n");
2456 fprintf(pf, PRS_GUI_FONT_NAME_1 ": %s\n", prefs.gui_font_name1);
2458 fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes (GTK version 2).\n");
2459 fprintf(pf, PRS_GUI_FONT_NAME_2 ": %s\n", prefs.gui_font_name2);
2461 fprintf (pf, "\n######## User Interface: Colors ########\n");
2463 fprintf (pf, "\n# Color preferences for a marked frame.\n");
2464 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2465 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_FG,
2466 (prefs.gui_marked_fg.red * 255 / 65535),
2467 (prefs.gui_marked_fg.green * 255 / 65535),
2468 (prefs.gui_marked_fg.blue * 255 / 65535));
2469 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_BG,
2470 (prefs.gui_marked_bg.red * 255 / 65535),
2471 (prefs.gui_marked_bg.green * 255 / 65535),
2472 (prefs.gui_marked_bg.blue * 255 / 65535));
2474 fprintf (pf, "\n# TCP stream window color preferences.\n");
2475 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2476 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_FG,
2477 (prefs.st_client_fg.red * 255 / 65535),
2478 (prefs.st_client_fg.green * 255 / 65535),
2479 (prefs.st_client_fg.blue * 255 / 65535));
2480 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_BG,
2481 (prefs.st_client_bg.red * 255 / 65535),
2482 (prefs.st_client_bg.green * 255 / 65535),
2483 (prefs.st_client_bg.blue * 255 / 65535));
2484 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_FG,
2485 (prefs.st_server_fg.red * 255 / 65535),
2486 (prefs.st_server_fg.green * 255 / 65535),
2487 (prefs.st_server_fg.blue * 255 / 65535));
2488 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_BG,
2489 (prefs.st_server_bg.red * 255 / 65535),
2490 (prefs.st_server_bg.green * 255 / 65535),
2491 (prefs.st_server_bg.blue * 255 / 65535));
2493 fprintf(pf, "\n######## Console: logging level ########\n");
2494 fprintf(pf, "# (debugging only, not in the Preferences dialog)\n");
2495 fprintf(pf, "# A bitmask of glib log levels:\n"
2496 "# G_LOG_LEVEL_ERROR = 4\n"
2497 "# G_LOG_LEVEL_CRITICAL = 8\n"
2498 "# G_LOG_LEVEL_WARNING = 16\n"
2499 "# G_LOG_LEVEL_MESSAGE = 32\n"
2500 "# G_LOG_LEVEL_INFO = 64\n"
2501 "# G_LOG_LEVEL_DEBUG = 128\n");
2503 fprintf(pf, PRS_CONSOLE_LOG_LEVEL ": %u\n",
2504 prefs.console_log_level);
2506 fprintf(pf, "\n####### Capture ########\n");
2508 if (prefs.capture_device != NULL) {
2509 fprintf(pf, "\n# Default capture device\n");
2510 fprintf(pf, PRS_CAP_DEVICE ": %s\n", prefs.capture_device);
2513 if (prefs.capture_devices_descr != NULL) {
2514 fprintf(pf, "\n# Interface descriptions.\n");
2515 fprintf(pf, "# Ex: eth0(eth0 descr),eth1(eth1 descr),...\n");
2516 fprintf(pf, PRS_CAP_DEVICES_DESCR ": %s\n", prefs.capture_devices_descr);
2519 if (prefs.capture_devices_hide != NULL) {
2520 fprintf(pf, "\n# Hide interface?\n");
2521 fprintf(pf, "# Ex: eth0,eth3,...\n");
2522 fprintf(pf, PRS_CAP_DEVICES_HIDE ": %s\n", prefs.capture_devices_hide);
2525 fprintf(pf, "\n# Capture in promiscuous mode?\n");
2526 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2527 fprintf(pf, PRS_CAP_PROM_MODE ": %s\n",
2528 prefs.capture_prom_mode == TRUE ? "TRUE" : "FALSE");
2530 fprintf(pf, "\n# Update packet list in real time during capture?\n");
2531 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2532 fprintf(pf, PRS_CAP_REAL_TIME ": %s\n",
2533 prefs.capture_real_time == TRUE ? "TRUE" : "FALSE");
2535 fprintf(pf, "\n# Scroll packet list during capture?\n");
2536 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2537 fprintf(pf, PRS_CAP_AUTO_SCROLL ": %s\n",
2538 prefs.capture_auto_scroll == TRUE ? "TRUE" : "FALSE");
2540 fprintf(pf, "\n# Show capture info dialog while capturing?\n");
2541 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2542 fprintf(pf, PRS_CAP_SHOW_INFO ": %s\n",
2543 prefs.capture_show_info == TRUE ? "TRUE" : "FALSE");
2545 fprintf (pf, "\n######## Printing ########\n");
2547 fprintf (pf, "\n# Can be one of \"text\" or \"postscript\".\n"
2548 "print.format: %s\n", pr_formats[prefs.pr_format]);
2550 fprintf (pf, "\n# Can be one of \"command\" or \"file\".\n"
2551 "print.destination: %s\n", pr_dests[prefs.pr_dest]);
2553 fprintf (pf, "\n# This is the file that gets written to when the "
2554 "destination is set to \"file\"\n"
2555 "%s: %s\n", PRS_PRINT_FILE, prefs.pr_file);
2557 fprintf (pf, "\n# Output gets piped to this command when the destination "
2558 "is set to \"command\"\n"
2559 "%s: %s\n", PRS_PRINT_CMD, prefs.pr_cmd);
2561 fprintf(pf, "\n####### Name Resolution ########\n");
2563 fprintf(pf, "\n# Resolve addresses to names?\n");
2564 fprintf(pf, "# TRUE or FALSE (case-insensitive), or a list of address types to resolve.\n");
2565 fprintf(pf, PRS_NAME_RESOLVE ": %s\n",
2566 name_resolve_to_string(prefs.name_resolve));
2568 fprintf(pf, "\n# Name resolution concurrency.\n");
2569 fprintf(pf, "# A decimal number.\n");
2570 fprintf(pf, PRS_NAME_RESOLVE_CONCURRENCY ": %d\n",
2571 prefs.name_resolve_concurrency);
2573 fprintf(pf, "\n####### Protocols ########\n");
2575 g_list_foreach(modules, write_module_prefs, pf);
2579 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
2580 an error indication, or maybe write to a new preferences file and
2581 rename that file on top of the old one only if there are not I/O
2586 /* Copy a set of preferences. */
2588 copy_prefs(e_prefs *dest, e_prefs *src)
2590 fmt_data *src_cfmt, *dest_cfmt;
2593 dest->pr_format = src->pr_format;
2594 dest->pr_dest = src->pr_dest;
2595 dest->pr_file = g_strdup(src->pr_file);
2596 dest->pr_cmd = g_strdup(src->pr_cmd);
2597 dest->col_list = NULL;
2598 for (entry = src->col_list; entry != NULL; entry = g_list_next(entry)) {
2599 src_cfmt = entry->data;
2600 dest_cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
2601 dest_cfmt->title = g_strdup(src_cfmt->title);
2602 dest_cfmt->fmt = g_strdup(src_cfmt->fmt);
2603 dest->col_list = g_list_append(dest->col_list, dest_cfmt);
2605 dest->num_cols = src->num_cols;
2606 dest->st_client_fg = src->st_client_fg;
2607 dest->st_client_bg = src->st_client_bg;
2608 dest->st_server_fg = src->st_server_fg;
2609 dest->st_server_bg = src->st_server_bg;
2610 dest->gui_scrollbar_on_right = src->gui_scrollbar_on_right;
2611 dest->gui_plist_sel_browse = src->gui_plist_sel_browse;
2612 dest->gui_ptree_sel_browse = src->gui_ptree_sel_browse;
2613 dest->gui_altern_colors = src->gui_altern_colors;
2614 dest->filter_toolbar_show_in_statusbar = src->filter_toolbar_show_in_statusbar;
2615 dest->gui_ptree_line_style = src->gui_ptree_line_style;
2616 dest->gui_ptree_expander_style = src->gui_ptree_expander_style;
2617 dest->gui_hex_dump_highlight_style = src->gui_hex_dump_highlight_style;
2618 dest->gui_toolbar_main_style = src->gui_toolbar_main_style;
2619 dest->gui_fileopen_dir = g_strdup(src->gui_fileopen_dir);
2620 dest->gui_console_open = src->gui_console_open;
2621 dest->gui_fileopen_style = src->gui_fileopen_style;
2622 dest->gui_fileopen_preview = src->gui_fileopen_preview;
2623 dest->gui_ask_unsaved = src->gui_ask_unsaved;
2624 dest->gui_find_wrap = src->gui_find_wrap;
2625 dest->gui_use_pref_save = src->gui_use_pref_save;
2626 dest->gui_layout_type = src->gui_layout_type;
2627 dest->gui_layout_content_1 = src->gui_layout_content_1;
2628 dest->gui_layout_content_2 = src->gui_layout_content_2;
2629 dest->gui_layout_content_3 = src->gui_layout_content_3;
2630 dest->gui_font_name1 = g_strdup(src->gui_font_name1);
2631 dest->gui_font_name2 = g_strdup(src->gui_font_name2);
2632 dest->gui_marked_fg = src->gui_marked_fg;
2633 dest->gui_marked_bg = src->gui_marked_bg;
2634 dest->gui_geometry_save_position = src->gui_geometry_save_position;
2635 dest->gui_geometry_save_size = src->gui_geometry_save_size;
2636 dest->gui_geometry_save_maximized = src->gui_geometry_save_maximized;
2637 dest->gui_webbrowser = g_strdup(src->gui_webbrowser);
2638 dest->gui_window_title = g_strdup(src->gui_window_title);
2639 dest->console_log_level = src->console_log_level;
2640 /* values for the capture dialog box */
2641 dest->capture_device = g_strdup(src->capture_device);
2642 dest->capture_devices_descr = g_strdup(src->capture_devices_descr);
2643 dest->capture_devices_hide = g_strdup(src->capture_devices_hide);
2644 dest->capture_prom_mode = src->capture_prom_mode;
2645 dest->capture_real_time = src->capture_real_time;
2646 dest->capture_auto_scroll = src->capture_auto_scroll;
2647 dest->capture_show_info = src->capture_show_info;
2648 dest->name_resolve = src->name_resolve;
2649 dest->name_resolve_concurrency = src->name_resolve_concurrency;
2653 /* Free a set of preferences. */
2655 free_prefs(e_prefs *pr)
2657 if (pr->pr_file != NULL) {
2658 g_free(pr->pr_file);
2661 if (pr->pr_cmd != NULL) {
2666 if (pr->gui_font_name1 != NULL) {
2667 g_free(pr->gui_font_name1);
2668 pr->gui_font_name1 = NULL;
2670 if (pr->gui_font_name2 != NULL) {
2671 g_free(pr->gui_font_name2);
2672 pr->gui_font_name2 = NULL;
2674 if (pr->gui_fileopen_dir != NULL) {
2675 g_free(pr->gui_fileopen_dir);
2676 pr->gui_fileopen_dir = NULL;
2678 g_free(pr->gui_webbrowser);
2679 pr->gui_webbrowser = NULL;
2680 if (pr->gui_window_title != NULL) {
2681 g_free(pr->gui_window_title);
2682 pr->gui_window_title = NULL;
2684 if (pr->capture_device != NULL) {
2685 g_free(pr->capture_device);
2686 pr->capture_device = NULL;
2688 if (pr->capture_devices_descr != NULL) {
2689 g_free(pr->capture_devices_descr);
2690 pr->capture_devices_descr = NULL;
2692 if (pr->capture_devices_hide != NULL) {
2693 g_free(pr->capture_devices_hide);
2694 pr->capture_devices_hide = NULL;
2699 free_col_info(e_prefs *pr)
2703 while (pr->col_list != NULL) {
2704 cfmt = pr->col_list->data;
2705 g_free(cfmt->title);
2708 pr->col_list = g_list_remove_link(pr->col_list, pr->col_list);
2710 g_list_free(pr->col_list);
2711 pr->col_list = NULL;