2 * Routines for handling preferences
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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/addr_resolv.h>
42 #include <epan/packet.h>
43 #include <epan/prefs.h>
44 #include <epan/proto.h>
45 #include <epan/column.h>
48 #include <epan/prefs-int.h>
50 /* Internal functions */
51 static module_t *find_module(const char *name);
52 static module_t *prefs_register_module_or_subtree(module_t *parent,
53 const char *name, const char *title, gboolean is_subtree,
54 void (*apply_cb)(void));
55 static struct preference *find_preference(module_t *, const char *);
56 static int set_pref(gchar*, gchar*);
57 static GList *get_string_list(gchar *);
58 static gchar *put_string_list(GList *);
59 static void clear_string_list(GList *);
60 static void free_col_info(e_prefs *);
62 #define GPF_NAME "ethereal.conf"
63 #define PF_NAME "preferences"
65 static gboolean init_prefs = TRUE;
66 static gchar *gpf_path = NULL;
69 * XXX - variables to allow us to attempt to interpret the first
70 * "mgcp.{tcp,udp}.port" in a preferences file as
71 * "mgcp.{tcp,udp}.gateway_port" and the second as
72 * "mgcp.{tcp,udp}.callagent_port".
74 static int mgcp_tcp_port_count;
75 static int mgcp_udp_port_count;
79 static gchar *gui_ptree_line_style_text[] =
80 { "NONE", "SOLID", "DOTTED", "TABBED", NULL };
82 static gchar *gui_ptree_expander_style_text[] =
83 { "NONE", "SQUARE", "TRIANGLE", "CIRCULAR", NULL };
85 static gchar *gui_hex_dump_highlight_style_text[] =
86 { "BOLD", "INVERSE", NULL };
88 static gchar *gui_console_open_text[] =
89 { "NEVER", "AUTOMATIC", "ALWAYS", NULL };
91 static gchar *gui_fileopen_style_text[] =
92 { "LAST_OPENED", "SPECIFIED", NULL };
94 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
95 * as this may not work on other guis, we use only "both" in general here */
96 static gchar *gui_toolbar_style_text[] =
97 { "ICONS", "TEXT", "BOTH", NULL };
99 static gchar *gui_layout_content_text[] =
100 { "NONE", "PLIST", "PDETAILS", "PBYTES", NULL };
103 * List of all modules with preference settings.
105 static GList *modules;
108 * List of all modules that should show up at the top level of the
109 * tree in the preference dialog box.
111 static GList *top_level_modules;
114 module_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
116 const module_t *p1 = p1_arg;
117 const module_t *p2 = p2_arg;
119 return g_strcasecmp(p1->name, p2->name);
123 module_compare_title(gconstpointer p1_arg, gconstpointer p2_arg)
125 const module_t *p1 = p1_arg;
126 const module_t *p2 = p2_arg;
128 return g_strcasecmp(p1->title, p2->title);
132 * Register a module that will have preferences.
133 * Specify the module under which to register it or NULL to register it
134 * at the top level, the name used for the module in the preferences file,
135 * the title used in the tab for it in a preferences dialog box, and a
136 * routine to call back when we apply the preferences.
139 prefs_register_module(module_t *parent, const char *name, const char *title,
140 void (*apply_cb)(void))
142 return prefs_register_module_or_subtree(parent, name, title, FALSE,
147 * Register a subtree that will have modules under it.
148 * Specify the module under which to register it or NULL to register it
149 * at the top level and the title used in the tab for it in a preferences
153 prefs_register_subtree(module_t *parent, const char *title)
155 return prefs_register_module_or_subtree(parent, NULL, title, TRUE,
160 prefs_register_module_or_subtree(module_t *parent, const char *name,
161 const char *title, gboolean is_subtree, void (*apply_cb)(void))
166 module = g_malloc(sizeof (module_t));
168 module->title = title;
169 module->is_subtree = is_subtree;
170 module->apply_cb = apply_cb;
171 module->prefs = NULL; /* no preferences, to start */
172 module->numprefs = 0;
173 module->prefs_changed = FALSE;
174 module->obsolete = FALSE;
177 * Do we have a module name?
182 * Make sure that only lower-case ASCII letters, numbers,
183 * underscores, hyphens, and dots appear in the name.
185 * Crash if there is, as that's an error in the code;
186 * you can make the title a nice string with capitalization,
187 * white space, punctuation, etc., but the name can be used
188 * on the command line, and shouldn't require quoting,
191 for (p = name; *p != '\0'; p++)
192 g_assert(isascii(*p) &&
193 (islower(*p) || isdigit(*p) || *p == '_' ||
194 *p == '-' || *p == '.'));
197 * Make sure there's not already a module with that
198 * name. Crash if there is, as that's an error in the
199 * code, and the code has to be fixed not to register
200 * more than one module with the same name.
202 * We search the list of all modules; the subtree stuff
203 * doesn't require preferences in subtrees to have names
204 * that reflect the subtree they're in (that would require
205 * protocol preferences to have a bogus "protocol.", or
206 * something such as that, to be added to all their names).
208 g_assert(find_module(name) == NULL);
211 * Insert this module in the list of all modules.
213 modules = g_list_insert_sorted(modules, module,
214 module_compare_name);
217 * This has no name, just a title; check to make sure it's a
218 * subtree, and crash if it's not.
220 g_assert(is_subtree);
224 * Insert this module into the appropriate place in the display
227 if (parent == NULL) {
229 * It goes at the top.
231 top_level_modules = g_list_insert_sorted(top_level_modules,
232 module, module_compare_title);
235 * It goes into the list for this module.
237 parent->prefs = g_list_insert_sorted(parent->prefs, module,
238 module_compare_title);
245 * Register that a protocol has preferences.
247 module_t *protocols_module;
250 prefs_register_protocol(int id, void (*apply_cb)(void))
252 protocol_t *protocol;
255 * Have we yet created the "Protocols" subtree?
257 if (protocols_module == NULL) {
261 protocols_module = prefs_register_subtree(NULL, "Protocols");
263 protocol = find_protocol_by_id(id);
264 return prefs_register_module(protocols_module,
265 proto_get_protocol_filter_name(id),
266 proto_get_protocol_short_name(protocol), apply_cb);
270 * Register that a protocol used to have preferences but no longer does,
271 * by creating an "obsolete" module for it.
274 prefs_register_protocol_obsolete(int id)
277 protocol_t *protocol;
280 * Have we yet created the "Protocols" subtree?
282 if (protocols_module == NULL) {
286 protocols_module = prefs_register_subtree(NULL, "Protocols");
288 protocol = find_protocol_by_id(id);
289 module = prefs_register_module(protocols_module,
290 proto_get_protocol_filter_name(id),
291 proto_get_protocol_short_name(protocol), NULL);
292 module->obsolete = TRUE;
297 * Find a module, given its name.
300 module_match(gconstpointer a, gconstpointer b)
302 const module_t *module = a;
303 const char *name = b;
305 return strcmp(name, module->name);
309 find_module(const char *name)
313 list_entry = g_list_find_custom(modules, (gpointer)name, module_match);
314 if (list_entry == NULL)
315 return NULL; /* no such module */
316 return (module_t *) list_entry->data;
320 * Call a callback function, with a specified argument, for each module
321 * in a list of modules. If the list is NULL, searches the top-level
322 * list in the display tree of modules. If any callback returns a
323 * non-zero value, we stop and return that value, otherwise we
326 * Ignores "obsolete" modules; their sole purpose is to allow old
327 * preferences for dissectors that no longer have preferences to be
328 * silently ignored in preference files. Does not ignore subtrees,
329 * as this can be used when walking the display tree of modules.
332 prefs_module_list_foreach(GList *module_list, module_cb callback,
339 if (module_list == NULL)
340 module_list = top_level_modules;
342 for (elem = g_list_first(module_list); elem != NULL;
343 elem = g_list_next(elem)) {
345 if (!module->obsolete) {
346 ret = (*callback)(module, user_data);
355 * Call a callback function, with a specified argument, for each module
356 * in the list of all modules. (This list does not include subtrees.)
358 * Ignores "obsolete" modules; their sole purpose is to allow old
359 * preferences for dissectors that no longer have preferences to be
360 * silently ignored in preference files.
363 prefs_modules_foreach(module_cb callback, gpointer user_data)
365 return prefs_module_list_foreach(modules, callback, user_data);
369 call_apply_cb(gpointer data, gpointer user_data _U_)
371 module_t *module = data;
373 if (module->obsolete)
375 if (module->prefs_changed) {
376 if (module->apply_cb != NULL)
377 (*module->apply_cb)();
378 module->prefs_changed = FALSE;
383 * Call the "apply" callback function for each module if any of its
384 * preferences have changed, and then clear the flag saying its
385 * preferences have changed, as the module has been notified of that
389 prefs_apply_all(void)
391 g_list_foreach(modules, call_apply_cb, NULL);
395 * Register a preference in a module's list of preferences.
396 * If it has a title, give it an ordinal number; otherwise, it's a
397 * preference that won't show up in the UI, so it shouldn't get an
398 * ordinal number (the ordinal should be the ordinal in the set of
399 * *visible* preferences).
402 register_preference(module_t *module, const char *name, const char *title,
403 const char *description, pref_type_t type)
408 preference = g_malloc(sizeof (pref_t));
409 preference->name = name;
410 preference->title = title;
411 preference->description = description;
412 preference->type = type;
414 preference->ordinal = module->numprefs;
416 preference->ordinal = -1; /* no ordinal for you */
419 * Make sure that only lower-case ASCII letters, numbers,
420 * underscores, and dots appear in the preference name.
422 * Crash if there is, as that's an error in the code;
423 * you can make the title and description nice strings
424 * with capitalization, white space, punctuation, etc.,
425 * but the name can be used on the command line,
426 * and shouldn't require quoting, shifting, etc.
428 for (p = name; *p != '\0'; p++)
429 g_assert(isascii(*p) &&
430 (islower(*p) || isdigit(*p) || *p == '_' || *p == '.'));
433 * Make sure there's not already a preference with that
434 * name. Crash if there is, as that's an error in the
435 * code, and the code has to be fixed not to register
436 * more than one preference with the same name.
438 g_assert(find_preference(module, name) == NULL);
440 if (type != PREF_OBSOLETE) {
442 * Make sure the preference name doesn't begin with the
443 * module name, as that's redundant and Just Silly.
445 g_assert((strncmp(name, module->name, strlen(module->name)) != 0) ||
446 (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_')));
450 * There isn't already one with that name, so add the
453 module->prefs = g_list_append(module->prefs, preference);
461 * Find a preference in a module's list of preferences, given the module
462 * and the preference's name.
465 preference_match(gconstpointer a, gconstpointer b)
467 const pref_t *pref = a;
468 const char *name = b;
470 return strcmp(name, pref->name);
473 static struct preference *
474 find_preference(module_t *module, const char *name)
478 list_entry = g_list_find_custom(module->prefs, (gpointer)name,
480 if (list_entry == NULL)
481 return NULL; /* no such preference */
482 return (struct preference *) list_entry->data;
486 * Returns TRUE if the given protocol has registered preferences
489 prefs_is_registered_protocol(char *name)
491 module_t *m = find_module(name);
493 return (m != NULL && !m->obsolete);
497 * Returns the module title of a registered protocol
500 prefs_get_title_by_name(char *name)
502 module_t *m = find_module(name);
504 return (m != NULL && !m->obsolete) ? m->title : NULL;
508 * Register a preference with an unsigned integral value.
511 prefs_register_uint_preference(module_t *module, const char *name,
512 const char *title, const char *description, guint base, guint *var)
516 preference = register_preference(module, name, title, description,
518 preference->varp.uint = var;
519 preference->info.base = base;
523 * Register a preference with an Boolean value.
526 prefs_register_bool_preference(module_t *module, const char *name,
527 const char *title, const char *description, gboolean *var)
531 preference = register_preference(module, name, title, description,
533 preference->varp.boolp = var;
537 * Register a preference with an enumerated value.
540 prefs_register_enum_preference(module_t *module, const char *name,
541 const char *title, const char *description, gint *var,
542 const enum_val_t *enumvals, gboolean radio_buttons)
546 preference = register_preference(module, name, title, description,
548 preference->varp.enump = var;
549 preference->info.enum_info.enumvals = enumvals;
550 preference->info.enum_info.radio_buttons = radio_buttons;
554 * Register a preference with a character-string value.
557 prefs_register_string_preference(module_t *module, const char *name,
558 const char *title, const char *description, char **var)
562 preference = register_preference(module, name, title, description,
566 * String preference values should be non-null (as you can't
567 * keep them null after using the preferences GUI, you can at best
568 * have them be null strings) and freeable (as we free them
569 * if we change them).
571 * If the value is a null pointer, make it a copy of a null
572 * string, otherwise make it a copy of the value.
577 *var = g_strdup(*var);
578 preference->varp.string = var;
579 preference->saved_val.string = NULL;
583 * Register a preference with a ranged value.
586 prefs_register_range_preference(module_t *module, const char *name,
587 const char *title, const char *description, range_t **var,
592 preference = register_preference(module, name, title, description,
594 preference->info.max_value = max_value;
598 * Range preference values should be non-null (as you can't
599 * keep them null after using the preferences GUI, you can at best
600 * have them be empty ranges) and freeable (as we free them
601 * if we change them).
603 * If the value is a null pointer, make it an empty range.
606 *var = range_empty();
607 preference->varp.range = var;
608 preference->saved_val.range = NULL;
612 * Register a preference that used to be supported but no longer is.
615 prefs_register_obsolete_preference(module_t *module, const char *name)
617 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
621 * Call a callback function, with a specified argument, for each preference
624 * If any of the callbacks return a non-zero value, stop and return that
625 * value, otherwise return 0.
628 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
634 for (elem = g_list_first(module->prefs); elem != NULL;
635 elem = g_list_next(elem)) {
637 if (pref->type == PREF_OBSOLETE) {
639 * This preference is no longer supported; it's
640 * not a real preference, so we don't call the
641 * callback for it (i.e., we treat it as if it
642 * weren't found in the list of preferences,
643 * and we weren't called in the first place).
648 ret = (*callback)(pref, user_data);
656 * Register all non-dissector modules' preferences.
659 prefs_register_modules(void)
663 /* Parse through a list of comma-separated, possibly quoted strings.
664 Return a list of the string data. */
666 get_string_list(gchar *str)
668 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
670 gint state = PRE_STRING, i = 0, j = 0;
671 gboolean backslash = FALSE;
676 /* Allocate a buffer for the first string. */
677 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
683 /* It's the end of the input, so it's the end of the string we
684 were working on, and there's no more input. */
685 if (state == IN_QUOT || backslash) {
686 /* We were in the middle of a quoted string or backslash escape,
687 and ran out of characters; that's an error. */
689 clear_string_list(sl);
693 sl = g_list_append(sl, slstr);
696 if (cur_c == '"' && ! backslash) {
699 /* We hadn't yet started processing a string; this starts the
700 string, and we're now quoting. */
704 /* We're in the middle of a quoted string, and we saw a quotation
705 mark; we're no longer quoting. */
709 /* We're working on a string, but haven't seen a quote; we're
716 } else if (cur_c == '\\' && ! backslash) {
717 /* We saw a backslash, and the previous character wasn't a
718 backslash; escape the next character.
720 This also means we've started a new string. */
722 if (state == PRE_STRING)
724 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
725 /* We saw a comma, and we're not in the middle of a quoted string
726 and it wasn't preceded by a backslash; it's the end of
727 the string we were working on... */
729 sl = g_list_append(sl, slstr);
731 /* ...and the beginning of a new string. */
733 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
735 } else if (!isspace(cur_c) || state != PRE_STRING) {
736 /* Either this isn't a white-space character, or we've started a
737 string (i.e., already seen a non-white-space character for that
738 string and put it into the string).
740 The character is to be put into the string; do so if there's
742 if (j < COL_MAX_LEN) {
747 /* If it was backslash-escaped, we're done with the backslash escape. */
755 #define MAX_FMT_PREF_LEN 1024
756 #define MAX_FMT_PREF_LINE_LEN 60
758 put_string_list(GList *sl)
760 static gchar pref_str[MAX_FMT_PREF_LEN] = "";
761 GList *clp = g_list_first(sl);
763 int cur_pos = 0, cur_len = 0;
766 gchar *strp, *quoted_strp, c;
772 /* Allocate a buffer big enough to hold the entire string, with each
773 character quoted (that's the worst case). */
774 str_len = strlen(str);
775 quoted_str = g_malloc(str_len*2 + 1);
777 /* Now quote any " or \ characters in it. */
779 quoted_strp = quoted_str;
780 while ((c = *strp++) != '\0') {
781 if (c == '"' || c == '\\') {
782 /* It has to be backslash-quoted. */
783 *quoted_strp++ = '\\';
789 fmt_len = strlen(quoted_str) + 4;
790 if ((fmt_len + cur_len) < (MAX_FMT_PREF_LEN - 1)) {
791 if ((fmt_len + cur_pos) > MAX_FMT_PREF_LINE_LEN) {
795 pref_str[cur_len] = '\n'; cur_len++;
796 pref_str[cur_len] = '\t'; cur_len++;
798 sprintf(&pref_str[cur_len], "\"%s\", ", quoted_str);
806 /* If the string is at least two characters long, the last two characters
807 are ", ", and should be discarded, as there are no more items in the
810 pref_str[cur_len - 2] = '\0';
816 clear_string_list(GList *sl)
822 l = g_list_remove_link(l, l);
827 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
829 * The array must be terminated by an entry with a null "name" string.
831 * If the string matches a "name" string in an entry, the value from that
834 * Otherwise, if a string matches a "desctiption" string in an entry, the
835 * value from that entry is returned; we do that for backwards compatibility,
836 * as we used to have only a "name" string that was used both for command-line
837 * and configuration-file values and in the GUI (which meant either that
838 * the GUI had what might be somewhat cryptic values to select from or that
839 * the "-o" flag took long strings, often with spaces in them).
841 * Otherwise, the default value that was passed as the third argument is
845 find_val_for_string(const char *needle, const enum_val_t *haystack,
850 for (i = 0; haystack[i].name != NULL; i++) {
851 if (strcasecmp(needle, haystack[i].name) == 0) {
852 return haystack[i].value;
855 for (i = 0; haystack[i].name != NULL; i++) {
856 if (strcasecmp(needle, haystack[i].description) == 0) {
857 return haystack[i].value;
860 return default_value;
863 /* Takes an string and a pointer to an array of strings, and a default int value.
864 * The array must be terminated by a NULL string. If the string is found in the array
865 * of strings, the index of that string in the array is returned. Otherwise, the
866 * default value that was passed as the third argument is returned.
869 find_index_from_string_array(char *needle, char **haystack, int default_value)
873 while (haystack[i] != NULL) {
874 if (strcmp(needle, haystack[i]) == 0) {
879 return default_value;
882 /* Preferences file format:
883 * - Configuration directives start at the beginning of the line, and
884 * are terminated with a colon.
885 * - Directives can be continued on the next line by preceding them with
890 # This is a comment line
892 print.file: /a/very/long/path/
897 #define MAX_VAR_LEN 48
899 #define DEF_NUM_COLS 6
902 /* Read the preferences file, fill in "prefs", and return a pointer to it.
904 If we got an error (other than "it doesn't exist") trying to read
905 the global preferences file, stuff the errno into "*gpf_errno_return"
906 and a pointer to the path of the file into "*gpf_path_return", and
909 If we got an error (other than "it doesn't exist") trying to read
910 the user's preferences file, stuff the errno into "*pf_errno_return"
911 and a pointer to the path of the file into "*pf_path_return", and
914 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
915 char **gpf_path_return, int *pf_errno_return,
916 int *pf_read_errno_return, char **pf_path_return)
923 gchar *col_fmt[] = {"No.", "%m", "Time", "%t",
924 "Source", "%s", "Destination", "%d",
925 "Protocol", "%p", "Info", "%i"};
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. */
932 prefs.pr_format = PR_FMT_TEXT;
933 prefs.pr_dest = PR_DEST_CMD;
934 prefs.pr_file = g_strdup("ethereal.out");
935 prefs.pr_cmd = g_strdup("lpr");
936 prefs.col_list = NULL;
937 for (i = 0; i < DEF_NUM_COLS; i++) {
938 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
939 cfmt->title = g_strdup(col_fmt[i * 2]);
940 cfmt->fmt = g_strdup(col_fmt[(i * 2) + 1]);
941 prefs.col_list = g_list_append(prefs.col_list, cfmt);
943 prefs.num_cols = DEF_NUM_COLS;
944 prefs.st_client_fg.pixel = 0;
945 prefs.st_client_fg.red = 32767;
946 prefs.st_client_fg.green = 0;
947 prefs.st_client_fg.blue = 0;
948 prefs.st_client_bg.pixel = 0;
949 prefs.st_client_bg.red = 64507;
950 prefs.st_client_bg.green = 60909;
951 prefs.st_client_bg.blue = 60909;
952 prefs.st_server_fg.pixel = 0;
953 prefs.st_server_fg.red = 0;
954 prefs.st_server_fg.green = 0;
955 prefs.st_server_fg.blue = 32767;
956 prefs.st_server_bg.pixel = 0;
957 prefs.st_server_bg.red = 60909;
958 prefs.st_server_bg.green = 60909;
959 prefs.st_server_bg.blue = 64507;
960 prefs.gui_scrollbar_on_right = TRUE;
961 prefs.gui_plist_sel_browse = FALSE;
962 prefs.gui_ptree_sel_browse = FALSE;
963 prefs.gui_altern_colors = FALSE;
964 prefs.gui_ptree_line_style = 0;
965 prefs.gui_ptree_expander_style = 1;
966 prefs.gui_hex_dump_highlight_style = 1;
967 prefs.filter_toolbar_show_in_statusbar = FALSE;
968 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
970 /* XXX - not sure, if it must be "Lucida Console" or "lucida console"
971 * for gui_font_name1. Maybe it's dependant on the windows version running?!
972 * verified on XP: "Lucida Console"
973 * unknown for other windows versions.
975 * Problem: if we have no preferences file, and the default font name is unknown,
976 * we cannot save Preferences as an error dialog pops up "You have not selected a font".
978 prefs.gui_font_name1 = g_strdup("-*-Lucida Console-medium-r-*-*-*-100-*-*-*-*-*-*");
979 prefs.gui_font_name2 = g_strdup("Lucida Console 10");
982 * XXX - for now, we make the initial font name a pattern that matches
983 * only ISO 8859/1 fonts, so that we don't match 2-byte fonts such
984 * as ISO 10646 fonts.
986 * Users in locales using other one-byte fonts will have to choose
987 * a different font from the preferences dialog - or put the font
988 * selection in the global preferences file to make that font the
989 * default for all users who don't explicitly specify a different
992 * Making this a font set rather than a font has two problems:
994 * 1) as far as I know, you can't select font sets with the
995 * font selection dialog;
997 * 2) if you use a font set, the text to be drawn must be a
998 * multi-byte string in the appropriate locale, but
999 * Ethereal does *NOT* guarantee that's the case - in
1000 * the hex-dump window, each character in the text portion
1001 * of the display must be a *single* byte, and in the
1002 * packet-list and protocol-tree windows, text extracted
1003 * from the packet is not necessarily in the right format.
1005 * "Doing this right" may, for the packet-list and protocol-tree
1006 * windows, require that dissectors know what the locale is
1007 * *AND* know what locale and text representation is used in
1008 * the packets they're dissecting, and may be impossible in
1009 * the hex-dump window (except by punting and displaying only
1010 * ASCII characters).
1012 * GTK+ 2.0 may simplify part of the problem, as it will, as I
1013 * understand it, use UTF-8-encoded Unicode as its internal
1014 * character set; however, we'd still have to know whatever
1015 * character set and encoding is used in the packet (which
1016 * may differ for different protocols, e.g. SMB might use
1017 * PC code pages for some strings and Unicode for others, whilst
1018 * NFS might use some UNIX character set encoding, e.g. ISO 8859/x,
1019 * or one of the EUC character sets for Asian languages, or one
1020 * of the other multi-byte character sets, or UTF-8, or...).
1022 * I.e., as far as I can tell, "internationalizing" the packet-list,
1023 * protocol-tree, and hex-dump windows involves a lot more than, say,
1024 * just using font sets rather than fonts.
1026 prefs.gui_font_name1 = g_strdup("-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-1");
1027 /* XXX- is this the correct default font name for GTK2 none win32? */
1028 prefs.gui_font_name2 = g_strdup("fixed medium 12");
1030 prefs.gui_marked_fg.pixel = 65535;
1031 prefs.gui_marked_fg.red = 65535;
1032 prefs.gui_marked_fg.green = 65535;
1033 prefs.gui_marked_fg.blue = 65535;
1034 prefs.gui_marked_bg.pixel = 0;
1035 prefs.gui_marked_bg.red = 0;
1036 prefs.gui_marked_bg.green = 0;
1037 prefs.gui_marked_bg.blue = 0;
1038 prefs.gui_geometry_save_position = 0;
1039 prefs.gui_geometry_save_size = 1;
1040 prefs.gui_geometry_save_maximized= 1;
1041 prefs.gui_console_open = console_open_never;
1042 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
1043 prefs.gui_recent_files_count_max = 10;
1044 prefs.gui_fileopen_dir = g_strdup("");
1045 prefs.gui_fileopen_preview = 3;
1046 prefs.gui_ask_unsaved = TRUE;
1047 prefs.gui_find_wrap = TRUE;
1048 prefs.gui_webbrowser = g_strdup("mozilla %s");
1049 prefs.gui_layout_type = layout_type_5;
1050 prefs.gui_layout_content_1 = layout_pane_content_plist;
1051 prefs.gui_layout_content_2 = layout_pane_content_pdetails;
1052 prefs.gui_layout_content_3 = layout_pane_content_pbytes;
1054 /* set the default values for the capture dialog box */
1055 prefs.capture_device = NULL;
1056 prefs.capture_devices_descr = NULL;
1057 prefs.capture_devices_hide = NULL;
1058 prefs.capture_prom_mode = TRUE;
1059 prefs.capture_real_time = FALSE;
1060 prefs.capture_auto_scroll = FALSE;
1061 prefs.capture_show_info = TRUE;
1062 prefs.name_resolve = RESOLV_ALL ^ RESOLV_NETWORK;
1063 prefs.name_resolve_concurrency = 500;
1066 /* Construct the pathname of the global preferences file. */
1068 gpf_path = get_datafile_path(GPF_NAME);
1070 /* Read the global preferences file, if it exists. */
1071 *gpf_path_return = NULL;
1072 if ((pf = fopen(gpf_path, "r")) != NULL) {
1074 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
1077 mgcp_tcp_port_count = 0;
1078 mgcp_udp_port_count = 0;
1080 /* We succeeded in opening it; read it. */
1081 err = read_prefs_file(gpf_path, pf, set_pref);
1083 /* We had an error reading the file; return the errno and the
1084 pathname, so our caller can report the error. */
1085 *gpf_errno_return = 0;
1086 *gpf_read_errno_return = err;
1087 *gpf_path_return = gpf_path;
1091 /* We failed to open it. If we failed for some reason other than
1092 "it doesn't exist", return the errno and the pathname, so our
1093 caller can report the error. */
1094 if (errno != ENOENT) {
1095 *gpf_errno_return = errno;
1096 *gpf_read_errno_return = 0;
1097 *gpf_path_return = gpf_path;
1101 /* Construct the pathname of the user's preferences file. */
1102 pf_path = get_persconffile_path(PF_NAME, FALSE);
1104 /* Read the user's preferences file, if it exists. */
1105 *pf_path_return = NULL;
1106 if ((pf = fopen(pf_path, "r")) != NULL) {
1108 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
1111 mgcp_tcp_port_count = 0;
1112 mgcp_udp_port_count = 0;
1114 /* We succeeded in opening it; read it. */
1115 err = read_prefs_file(pf_path, pf, set_pref);
1117 /* We had an error reading the file; return the errno and the
1118 pathname, so our caller can report the error. */
1119 *pf_errno_return = 0;
1120 *pf_read_errno_return = err;
1121 *pf_path_return = pf_path;
1126 /* We failed to open it. If we failed for some reason other than
1127 "it doesn't exist", return the errno and the pathname, so our
1128 caller can report the error. */
1129 if (errno != ENOENT) {
1130 *pf_errno_return = errno;
1131 *pf_read_errno_return = 0;
1132 *pf_path_return = pf_path;
1139 /* read the preferences file (or similiar) and call the callback
1140 * function to set each key/value pair found */
1142 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct)
1144 enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
1145 gchar cur_var[MAX_VAR_LEN], cur_val[MAX_VAL_LEN];
1146 int got_c, state = START;
1147 gboolean got_val = FALSE;
1148 gint var_len = 0, val_len = 0, fline = 1, pline = 1;
1149 gchar hint[] = "(saving your preferences once should remove this warning)";
1152 while ((got_c = getc(pf)) != EOF) {
1153 if (got_c == '\n') {
1158 if (var_len >= MAX_VAR_LEN) {
1159 g_warning ("%s line %d: Variable too long %s", pf_path, fline, hint);
1164 if (val_len >= MAX_VAL_LEN) {
1165 g_warning ("%s line %d: Value too long %s", pf_path, fline, hint);
1173 if (isalnum(got_c)) {
1176 cur_var[var_len] = '\0';
1177 cur_val[val_len] = '\0';
1178 switch (pref_set_pair_fct(cur_var, cur_val)) {
1180 case PREFS_SET_SYNTAX_ERR:
1181 g_warning ("%s line %d: Syntax error %s", pf_path, pline, hint);
1184 case PREFS_SET_NO_SUCH_PREF:
1185 g_warning ("%s line %d: No such preference \"%s\" %s", pf_path,
1186 pline, cur_var, hint);
1189 case PREFS_SET_OBSOLETE:
1190 /* We silently ignore attempts to set these; it's
1191 probably not the user's fault that it's in there -
1192 they may have saved preferences with a release that
1197 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
1205 } else if (isspace(got_c) && var_len > 0 && got_val) {
1207 } else if (got_c == '#') {
1210 g_warning ("%s line %d: Malformed line %s", pf_path, fline, hint);
1215 cur_var[var_len] = got_c;
1224 if (!isspace(got_c)) {
1226 cur_val[val_len] = got_c;
1232 cur_val[val_len] = got_c;
1235 while (isspace((guchar)cur_val[val_len]) && val_len > 0)
1244 cur_var[var_len] = '\0';
1245 cur_val[val_len] = '\0';
1246 switch (pref_set_pair_fct(cur_var, cur_val)) {
1248 case PREFS_SET_SYNTAX_ERR:
1249 g_warning ("%s line %d: Syntax error %s", pf_path, pline, hint);
1252 case PREFS_SET_NO_SUCH_PREF:
1253 g_warning ("%s line %d: No such preference \"%s\" %s", pf_path,
1254 pline, cur_var, hint);
1257 case PREFS_SET_OBSOLETE:
1258 /* We silently ignore attempts to set these; it's probably not
1259 the user's fault that it's in there - they may have saved
1260 preferences with a release that supported it. */
1264 g_warning ("%s line %d: Incomplete preference %s", pf_path, pline, hint);
1274 * Given a string of the form "<pref name>:<pref value>", as might appear
1275 * as an argument to a "-o" option, parse it and set the preference in
1276 * question. Return an indication of whether it succeeded or failed
1280 prefs_set_pref(char *prefarg)
1286 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
1287 * seen to values that keep us from trying to interpret tham
1288 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
1289 * as, from the command line, we have no way of guessing which
1290 * the user had in mind.
1292 mgcp_tcp_port_count = -1;
1293 mgcp_udp_port_count = -1;
1295 colonp = strchr(prefarg, ':');
1297 return PREFS_SET_SYNTAX_ERR;
1303 * Skip over any white space (there probably won't be any, but
1304 * as we allow it in the preferences file, we might as well
1311 * Put the colon back, so if our caller uses, in an
1312 * error message, the string they passed us, the message
1316 return PREFS_SET_SYNTAX_ERR;
1319 ret = set_pref(prefarg, p);
1320 *colonp = ':'; /* put the colon back */
1324 #define PRS_PRINT_FMT "print.format"
1325 #define PRS_PRINT_DEST "print.destination"
1326 #define PRS_PRINT_FILE "print.file"
1327 #define PRS_PRINT_CMD "print.command"
1328 #define PRS_COL_FMT "column.format"
1329 #define PRS_STREAM_CL_FG "stream.client.fg"
1330 #define PRS_STREAM_CL_BG "stream.client.bg"
1331 #define PRS_STREAM_SR_FG "stream.server.fg"
1332 #define PRS_STREAM_SR_BG "stream.server.bg"
1333 #define PRS_GUI_SCROLLBAR_ON_RIGHT "gui.scrollbar_on_right"
1334 #define PRS_GUI_PLIST_SEL_BROWSE "gui.packet_list_sel_browse"
1335 #define PRS_GUI_PTREE_SEL_BROWSE "gui.protocol_tree_sel_browse"
1336 #define PRS_GUI_ALTERN_COLORS "gui.tree_view_altern_colors"
1337 #define PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR "gui.filter_toolbar_show_in_statusbar"
1338 #define PRS_GUI_PTREE_LINE_STYLE "gui.protocol_tree_line_style"
1339 #define PRS_GUI_PTREE_EXPANDER_STYLE "gui.protocol_tree_expander_style"
1340 #define PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE "gui.hex_dump_highlight_style"
1341 #define PRS_GUI_FONT_NAME_1 "gui.font_name"
1342 #define PRS_GUI_FONT_NAME_2 "gui.gtk2.font_name"
1343 #define PRS_GUI_MARKED_FG "gui.marked_frame.fg"
1344 #define PRS_GUI_MARKED_BG "gui.marked_frame.bg"
1345 #define PRS_GUI_CONSOLE_OPEN "gui.console_open"
1346 #define PRS_GUI_FILEOPEN_STYLE "gui.fileopen.style"
1347 #define PRS_GUI_RECENT_COUNT_MAX "gui.recent_files_count.max"
1348 #define PRS_GUI_FILEOPEN_DIR "gui.fileopen.dir"
1349 #define PRS_GUI_FILEOPEN_REMEMBERED_DIR "gui.fileopen.remembered_dir"
1350 #define PRS_GUI_FILEOPEN_PREVIEW "gui.fileopen.preview"
1351 #define PRS_GUI_ASK_UNSAVED "gui.ask_unsaved"
1352 #define PRS_GUI_FIND_WRAP "gui.find_wrap"
1353 #define PRS_GUI_GEOMETRY_SAVE_POSITION "gui.geometry.save.position"
1354 #define PRS_GUI_GEOMETRY_SAVE_SIZE "gui.geometry.save.size"
1355 #define PRS_GUI_GEOMETRY_SAVE_MAXIMIZED "gui.geometry.save.maximized"
1356 #define PRS_GUI_GEOMETRY_MAIN_X "gui.geometry.main.x"
1357 #define PRS_GUI_GEOMETRY_MAIN_Y "gui.geometry.main.y"
1358 #define PRS_GUI_GEOMETRY_MAIN_WIDTH "gui.geometry.main.width"
1359 #define PRS_GUI_GEOMETRY_MAIN_HEIGHT "gui.geometry.main.height"
1360 #define PRS_GUI_TOOLBAR_MAIN_SHOW "gui.toolbar_main_show"
1361 #define PRS_GUI_TOOLBAR_MAIN_STYLE "gui.toolbar_main_style"
1362 #define PRS_GUI_WEBBROWSER "gui.webbrowser"
1363 #define PRS_GUI_LAYOUT_TYPE "gui.layout_type"
1364 #define PRS_GUI_LAYOUT_CONTENT_1 "gui.layout_content_1"
1365 #define PRS_GUI_LAYOUT_CONTENT_2 "gui.layout_content_2"
1366 #define PRS_GUI_LAYOUT_CONTENT_3 "gui.layout_content_3"
1369 * This applies to more than just captures, so it's not "capture.name_resolve";
1370 * "capture.name_resolve" is supported on input for backwards compatibility.
1372 * It's not a preference for a particular part of Ethereal, it's used all
1373 * over the place, so its name doesn't have two components.
1375 #define PRS_NAME_RESOLVE "name_resolve"
1376 #define PRS_NAME_RESOLVE_CONCURRENCY "name_resolve_concurrency"
1377 #define PRS_CAP_NAME_RESOLVE "capture.name_resolve"
1379 /* values for the capture dialog box */
1380 #define PRS_CAP_DEVICE "capture.device"
1381 #define PRS_CAP_DEVICES_DESCR "capture.devices_descr"
1382 #define PRS_CAP_DEVICES_HIDE "capture.devices_hide"
1383 #define PRS_CAP_PROM_MODE "capture.prom_mode"
1384 #define PRS_CAP_REAL_TIME "capture.real_time_update"
1385 #define PRS_CAP_AUTO_SCROLL "capture.auto_scroll"
1386 #define PRS_CAP_SHOW_INFO "capture.show_info"
1388 #define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
1389 #define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
1390 #define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
1392 static gchar *pr_formats[] = { "text", "postscript" };
1393 static gchar *pr_dests[] = { "command", "file" };
1398 } name_resolve_opt_t;
1400 static name_resolve_opt_t name_resolve_opt[] = {
1401 { 'm', RESOLV_MAC },
1402 { 'n', RESOLV_NETWORK },
1403 { 't', RESOLV_TRANSPORT },
1404 { 'C', RESOLV_CONCURRENT },
1407 #define N_NAME_RESOLVE_OPT (sizeof name_resolve_opt / sizeof name_resolve_opt[0])
1410 name_resolve_to_string(guint32 name_resolve)
1412 static char string[N_NAME_RESOLVE_OPT+1];
1415 gboolean all_opts_set = TRUE;
1417 if (name_resolve == RESOLV_NONE)
1420 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1421 if (name_resolve & name_resolve_opt[i].value)
1422 *p++ = name_resolve_opt[i].letter;
1424 all_opts_set = FALSE;
1433 string_to_name_resolve(char *string, guint32 *name_resolve)
1439 while ((c = *string++) != '\0') {
1440 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1441 if (c == name_resolve_opt[i].letter) {
1442 *name_resolve |= name_resolve_opt[i].value;
1446 if (i == N_NAME_RESOLVE_OPT) {
1448 * Unrecognized letter.
1457 set_pref(gchar *pref_name, gchar *value)
1459 GList *col_l, *col_l_elt;
1462 unsigned long int cval;
1467 gchar *dotp, *last_dotp;
1472 if (strcmp(pref_name, PRS_PRINT_FMT) == 0) {
1473 if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) {
1474 prefs.pr_format = PR_FMT_TEXT;
1475 } else if (strcmp(value, pr_formats[PR_FMT_PS]) == 0) {
1476 prefs.pr_format = PR_FMT_PS;
1478 return PREFS_SET_SYNTAX_ERR;
1480 } else if (strcmp(pref_name, PRS_PRINT_DEST) == 0) {
1481 if (strcmp(value, pr_dests[PR_DEST_CMD]) == 0) {
1482 prefs.pr_dest = PR_DEST_CMD;
1483 } else if (strcmp(value, pr_dests[PR_DEST_FILE]) == 0) {
1484 prefs.pr_dest = PR_DEST_FILE;
1486 return PREFS_SET_SYNTAX_ERR;
1488 } else if (strcmp(pref_name, PRS_PRINT_FILE) == 0) {
1489 if (prefs.pr_file) g_free(prefs.pr_file);
1490 prefs.pr_file = g_strdup(value);
1491 } else if (strcmp(pref_name, PRS_PRINT_CMD) == 0) {
1492 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
1493 prefs.pr_cmd = g_strdup(value);
1494 } else if (strcmp(pref_name, PRS_COL_FMT) == 0) {
1495 col_l = get_string_list(value);
1497 return PREFS_SET_SYNTAX_ERR;
1498 if ((g_list_length(col_l) % 2) != 0) {
1499 /* A title didn't have a matching format. */
1500 clear_string_list(col_l);
1501 return PREFS_SET_SYNTAX_ERR;
1503 /* Check to make sure all column formats are valid. */
1504 col_l_elt = g_list_first(col_l);
1506 /* Make sure the title isn't empty. */
1507 if (strcmp(col_l_elt->data, "") == 0) {
1509 clear_string_list(col_l);
1510 return PREFS_SET_SYNTAX_ERR;
1513 /* Go past the title. */
1514 col_l_elt = col_l_elt->next;
1516 /* Check the format. */
1517 if (get_column_format_from_str(col_l_elt->data) == -1) {
1518 /* It's not a valid column format. */
1519 clear_string_list(col_l);
1520 return PREFS_SET_SYNTAX_ERR;
1523 /* Go past the format. */
1524 col_l_elt = col_l_elt->next;
1526 free_col_info(&prefs);
1527 prefs.col_list = NULL;
1528 llen = g_list_length(col_l);
1529 prefs.num_cols = llen / 2;
1530 col_l_elt = g_list_first(col_l);
1532 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
1533 cfmt->title = g_strdup(col_l_elt->data);
1534 col_l_elt = col_l_elt->next;
1535 cfmt->fmt = g_strdup(col_l_elt->data);
1536 col_l_elt = col_l_elt->next;
1537 prefs.col_list = g_list_append(prefs.col_list, cfmt);
1539 clear_string_list(col_l);
1540 } else if (strcmp(pref_name, PRS_STREAM_CL_FG) == 0) {
1541 cval = strtoul(value, NULL, 16);
1542 prefs.st_client_fg.pixel = 0;
1543 prefs.st_client_fg.red = RED_COMPONENT(cval);
1544 prefs.st_client_fg.green = GREEN_COMPONENT(cval);
1545 prefs.st_client_fg.blue = BLUE_COMPONENT(cval);
1546 } else if (strcmp(pref_name, PRS_STREAM_CL_BG) == 0) {
1547 cval = strtoul(value, NULL, 16);
1548 prefs.st_client_bg.pixel = 0;
1549 prefs.st_client_bg.red = RED_COMPONENT(cval);
1550 prefs.st_client_bg.green = GREEN_COMPONENT(cval);
1551 prefs.st_client_bg.blue = BLUE_COMPONENT(cval);
1552 } else if (strcmp(pref_name, PRS_STREAM_SR_FG) == 0) {
1553 cval = strtoul(value, NULL, 16);
1554 prefs.st_server_fg.pixel = 0;
1555 prefs.st_server_fg.red = RED_COMPONENT(cval);
1556 prefs.st_server_fg.green = GREEN_COMPONENT(cval);
1557 prefs.st_server_fg.blue = BLUE_COMPONENT(cval);
1558 } else if (strcmp(pref_name, PRS_STREAM_SR_BG) == 0) {
1559 cval = strtoul(value, NULL, 16);
1560 prefs.st_server_bg.pixel = 0;
1561 prefs.st_server_bg.red = RED_COMPONENT(cval);
1562 prefs.st_server_bg.green = GREEN_COMPONENT(cval);
1563 prefs.st_server_bg.blue = BLUE_COMPONENT(cval);
1564 } else if (strcmp(pref_name, PRS_GUI_SCROLLBAR_ON_RIGHT) == 0) {
1565 if (strcasecmp(value, "true") == 0) {
1566 prefs.gui_scrollbar_on_right = TRUE;
1569 prefs.gui_scrollbar_on_right = FALSE;
1571 } else if (strcmp(pref_name, PRS_GUI_PLIST_SEL_BROWSE) == 0) {
1572 if (strcasecmp(value, "true") == 0) {
1573 prefs.gui_plist_sel_browse = TRUE;
1576 prefs.gui_plist_sel_browse = FALSE;
1578 } else if (strcmp(pref_name, PRS_GUI_PTREE_SEL_BROWSE) == 0) {
1579 if (strcasecmp(value, "true") == 0) {
1580 prefs.gui_ptree_sel_browse = TRUE;
1583 prefs.gui_ptree_sel_browse = FALSE;
1585 } else if (strcmp(pref_name, PRS_GUI_ALTERN_COLORS) == 0) {
1586 if (strcasecmp(value, "true") == 0) {
1587 prefs.gui_altern_colors = TRUE;
1590 prefs.gui_altern_colors = FALSE;
1592 } else if (strcmp(pref_name, PRS_GUI_PTREE_LINE_STYLE) == 0) {
1593 prefs.gui_ptree_line_style =
1594 find_index_from_string_array(value, gui_ptree_line_style_text, 0);
1595 } else if (strcmp(pref_name, PRS_GUI_PTREE_EXPANDER_STYLE) == 0) {
1596 prefs.gui_ptree_expander_style =
1597 find_index_from_string_array(value, gui_ptree_expander_style_text, 1);
1598 } else if (strcmp(pref_name, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE) == 0) {
1599 prefs.gui_hex_dump_highlight_style =
1600 find_index_from_string_array(value, gui_hex_dump_highlight_style_text, 1);
1601 } else if (strcmp(pref_name, PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR) == 0) {
1602 if (strcasecmp(value, "true") == 0) {
1603 prefs.filter_toolbar_show_in_statusbar = TRUE;
1606 prefs.filter_toolbar_show_in_statusbar = FALSE;
1608 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_SHOW) == 0) {
1609 /* obsoleted by recent setting */
1610 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_STYLE) == 0) {
1611 /* see toolbar.c for details, "icons only" is default */
1612 prefs.gui_toolbar_main_style =
1613 find_index_from_string_array(value, gui_toolbar_style_text,
1615 } else if (strcmp(pref_name, PRS_GUI_FONT_NAME_1) == 0) {
1616 if (prefs.gui_font_name1 != NULL)
1617 g_free(prefs.gui_font_name1);
1618 prefs.gui_font_name1 = g_strdup(value);
1619 } else if (strcmp(pref_name, PRS_GUI_FONT_NAME_2) == 0) {
1620 if (prefs.gui_font_name2 != NULL)
1621 g_free(prefs.gui_font_name2);
1622 prefs.gui_font_name2 = g_strdup(value);
1623 } else if (strcmp(pref_name, PRS_GUI_MARKED_FG) == 0) {
1624 cval = strtoul(value, NULL, 16);
1625 prefs.gui_marked_fg.pixel = 0;
1626 prefs.gui_marked_fg.red = RED_COMPONENT(cval);
1627 prefs.gui_marked_fg.green = GREEN_COMPONENT(cval);
1628 prefs.gui_marked_fg.blue = BLUE_COMPONENT(cval);
1629 } else if (strcmp(pref_name, PRS_GUI_MARKED_BG) == 0) {
1630 cval = strtoul(value, NULL, 16);
1631 prefs.gui_marked_bg.pixel = 0;
1632 prefs.gui_marked_bg.red = RED_COMPONENT(cval);
1633 prefs.gui_marked_bg.green = GREEN_COMPONENT(cval);
1634 prefs.gui_marked_bg.blue = BLUE_COMPONENT(cval);
1635 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_POSITION) == 0) {
1636 if (strcasecmp(value, "true") == 0) {
1637 prefs.gui_geometry_save_position = TRUE;
1640 prefs.gui_geometry_save_position = FALSE;
1642 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_SIZE) == 0) {
1643 if (strcasecmp(value, "true") == 0) {
1644 prefs.gui_geometry_save_size = TRUE;
1647 prefs.gui_geometry_save_size = FALSE;
1649 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_MAXIMIZED) == 0) {
1650 if (strcasecmp(value, "true") == 0) {
1651 prefs.gui_geometry_save_maximized = TRUE;
1654 prefs.gui_geometry_save_maximized = FALSE;
1656 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_X) == 0) { /* deprecated */
1657 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_Y) == 0) { /* deprecated */
1658 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_WIDTH) == 0) { /* deprecated */
1659 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_HEIGHT) == 0) { /* deprecated */
1660 } else if (strcmp(pref_name, PRS_GUI_CONSOLE_OPEN) == 0) {
1661 prefs.gui_console_open =
1662 find_index_from_string_array(value, gui_console_open_text,
1663 console_open_never);
1664 } else if (strcmp(pref_name, PRS_GUI_RECENT_COUNT_MAX) == 0) {
1665 prefs.gui_recent_files_count_max = strtoul(value, NULL, 10);
1666 if (prefs.gui_recent_files_count_max == 0) {
1667 /* We really should put up a dialog box here ... */
1668 prefs.gui_recent_files_count_max = 10;
1670 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_STYLE) == 0) {
1671 prefs.gui_fileopen_style =
1672 find_index_from_string_array(value, gui_fileopen_style_text,
1673 FO_STYLE_LAST_OPENED);
1674 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_DIR) == 0) {
1675 if (prefs.gui_fileopen_dir != NULL)
1676 g_free(prefs.gui_fileopen_dir);
1677 prefs.gui_fileopen_dir = g_strdup(value);
1678 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_REMEMBERED_DIR) == 0) { /* deprecated */
1679 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_PREVIEW) == 0) {
1680 prefs.gui_fileopen_preview = strtoul(value, NULL, 10);
1681 } else if (strcmp(pref_name, PRS_GUI_ASK_UNSAVED) == 0) {
1682 if (strcasecmp(value, "true") == 0) {
1683 prefs.gui_ask_unsaved = TRUE;
1686 prefs.gui_ask_unsaved = FALSE;
1688 } else if (strcmp(pref_name, PRS_GUI_FIND_WRAP) == 0) {
1689 if (strcasecmp(value, "true") == 0) {
1690 prefs.gui_find_wrap = TRUE;
1693 prefs.gui_find_wrap = FALSE;
1695 } else if (strcmp(pref_name, PRS_GUI_WEBBROWSER) == 0) {
1696 g_free(prefs.gui_webbrowser);
1697 prefs.gui_webbrowser = g_strdup(value);
1698 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_TYPE) == 0) {
1699 prefs.gui_layout_type = strtoul(value, NULL, 10);
1700 if (prefs.gui_layout_type == layout_unused ||
1701 prefs.gui_layout_type >= layout_type_max) {
1702 /* XXX - report an error? It's not a syntax error - we'd need to
1703 add a way of reporting a *semantic* error. */
1704 prefs.gui_layout_type = layout_type_5;
1706 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_1) == 0) {
1707 prefs.gui_layout_content_1 =
1708 find_index_from_string_array(value, gui_layout_content_text, 0);
1709 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_2) == 0) {
1710 prefs.gui_layout_content_2 =
1711 find_index_from_string_array(value, gui_layout_content_text, 0);
1712 } else if (strcmp(pref_name, PRS_GUI_LAYOUT_CONTENT_3) == 0) {
1713 prefs.gui_layout_content_3 =
1714 find_index_from_string_array(value, gui_layout_content_text, 0);
1716 /* handle the capture options */
1717 } else if (strcmp(pref_name, PRS_CAP_DEVICE) == 0) {
1718 if (prefs.capture_device != NULL)
1719 g_free(prefs.capture_device);
1720 prefs.capture_device = g_strdup(value);
1721 } else if (strcmp(pref_name, PRS_CAP_DEVICES_DESCR) == 0) {
1722 if (prefs.capture_devices_descr != NULL)
1723 g_free(prefs.capture_devices_descr);
1724 prefs.capture_devices_descr = g_strdup(value);
1725 } else if (strcmp(pref_name, PRS_CAP_DEVICES_HIDE) == 0) {
1726 if (prefs.capture_devices_hide != NULL)
1727 g_free(prefs.capture_devices_hide);
1728 prefs.capture_devices_hide = g_strdup(value);
1729 } else if (strcmp(pref_name, PRS_CAP_PROM_MODE) == 0) {
1730 prefs.capture_prom_mode = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1731 } else if (strcmp(pref_name, PRS_CAP_REAL_TIME) == 0) {
1732 prefs.capture_real_time = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1733 } else if (strcmp(pref_name, PRS_CAP_AUTO_SCROLL) == 0) {
1734 prefs.capture_auto_scroll = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1735 } else if (strcmp(pref_name, PRS_CAP_SHOW_INFO) == 0) {
1736 prefs.capture_show_info = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1738 /* handle the global options */
1739 } else if (strcmp(pref_name, PRS_NAME_RESOLVE) == 0 ||
1740 strcmp(pref_name, PRS_CAP_NAME_RESOLVE) == 0) {
1742 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
1743 * RESOLV_ALL and RESOLV_NONE.
1745 * Otherwise, we treat it as a list of name types we want to resolve.
1747 if (strcasecmp(value, "true") == 0)
1748 prefs.name_resolve = RESOLV_ALL;
1749 else if (strcasecmp(value, "false") == 0)
1750 prefs.name_resolve = RESOLV_NONE;
1752 prefs.name_resolve = RESOLV_NONE; /* start out with none set */
1753 if (string_to_name_resolve(value, &prefs.name_resolve) != '\0')
1754 return PREFS_SET_SYNTAX_ERR;
1756 } else if (strcmp(pref_name, PRS_NAME_RESOLVE_CONCURRENCY) == 0) {
1757 prefs.name_resolve_concurrency = strtol(value, NULL, 10);
1759 /* To which module does this preference belong? */
1761 last_dotp = pref_name;
1764 dotp = strchr(last_dotp, '.');
1767 /* no such module */
1768 return PREFS_SET_NO_SUCH_PREF;
1771 /* no ".", so no module/name separator */
1772 return PREFS_SET_SYNTAX_ERR;
1778 *dotp = '\0'; /* separate module and preference name */
1779 module = find_module(pref_name);
1782 * XXX - "Diameter" rather than "diameter" was used in earlier
1783 * versions of Ethereal; if we didn't find the module, and its name
1784 * was "Diameter", look for "diameter" instead.
1786 * In addition, the BEEP protocol used to be the BXXP protocol,
1787 * so if we didn't find the module, and its name was "bxxp",
1788 * look for "beep" instead.
1790 * Also, the preferences for GTP v0 and v1 were combined under
1791 * a single "gtp" heading, and the preferences for SMPP were
1792 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
1793 * However, SMPP now has its own preferences, so we just map
1794 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
1796 if (module == NULL) {
1797 if (strcmp(pref_name, "Diameter") == 0)
1798 module = find_module("diameter");
1799 else if (strcmp(pref_name, "bxxp") == 0)
1800 module = find_module("beep");
1801 else if (strcmp(pref_name, "gtpv0") == 0 ||
1802 strcmp(pref_name, "gtpv1") == 0)
1803 module = find_module("gtp");
1804 else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
1805 module = find_module("gsm-sms-ud");
1807 *dotp = '.'; /* put the preference string back */
1808 dotp++; /* skip past separator to preference name */
1812 pref = find_preference(module, dotp);
1815 if (strcmp(module->name, "mgcp") == 0) {
1817 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
1818 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
1819 * were used in earlier versions of Ethereal; if we didn't find the
1820 * preference, it was an MGCP preference, and its name was
1821 * "display raw text toggle" or "display dissect tree", look for
1822 * "display_raw_text" or "display_dissect_tree" instead.
1824 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
1825 * the gateway and callagent ports were given those names; we interpret
1826 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
1827 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
1828 * they were registered by the MCCP dissector and thus that's the
1829 * order in which they were written to the preferences file. (If
1830 * we're not reading the preferences file, but are handling stuff
1831 * from a "-o" command-line option, we have no clue which the user
1832 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
1833 * or "mgcp.{tcp,udp}.callagent_port" instead.)
1835 if (strcmp(dotp, "display raw text toggle") == 0)
1836 pref = find_preference(module, "display_raw_text");
1837 else if (strcmp(dotp, "display dissect tree") == 0)
1838 pref = find_preference(module, "display_dissect_tree");
1839 else if (strcmp(dotp, "tcp.port") == 0) {
1840 mgcp_tcp_port_count++;
1841 if (mgcp_tcp_port_count == 1) {
1842 /* It's the first one */
1843 pref = find_preference(module, "tcp.gateway_port");
1844 } else if (mgcp_tcp_port_count == 2) {
1845 /* It's the second one */
1846 pref = find_preference(module, "tcp.callagent_port");
1848 /* Otherwise it's from the command line, and we don't bother
1850 } else if (strcmp(dotp, "udp.port") == 0) {
1851 mgcp_udp_port_count++;
1852 if (mgcp_udp_port_count == 1) {
1853 /* It's the first one */
1854 pref = find_preference(module, "udp.gateway_port");
1855 } else if (mgcp_udp_port_count == 2) {
1856 /* It's the second one */
1857 pref = find_preference(module, "udp.callagent_port");
1859 /* Otherwise it's from the command line, and we don't bother
1862 } else if (strcmp(module->name, "smb") == 0) {
1863 /* Handle old names for SMB preferences. */
1864 if (strcmp(dotp, "smb.trans.reassembly") == 0)
1865 pref = find_preference(module, "trans_reassembly");
1866 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
1867 pref = find_preference(module, "dcerpc_reassembly");
1868 } else if (strcmp(module->name, "ndmp") == 0) {
1869 /* Handle old names for NDMP preferences. */
1870 if (strcmp(dotp, "ndmp.desegment") == 0)
1871 pref = find_preference(module, "desegment");
1872 } else if (strcmp(module->name, "diameter") == 0) {
1873 /* Handle old names for Diameter preferences. */
1874 if (strcmp(dotp, "diameter.desegment") == 0)
1875 pref = find_preference(module, "desegment");
1876 } else if (strcmp(module->name, "pcli") == 0) {
1877 /* Handle old names for PCLI preferences. */
1878 if (strcmp(dotp, "pcli.udp_port") == 0)
1879 pref = find_preference(module, "udp_port");
1880 } else if (strcmp(module->name, "artnet") == 0) {
1881 /* Handle old names for ARTNET preferences. */
1882 if (strcmp(dotp, "artnet.udp_port") == 0)
1883 pref = find_preference(module, "udp_port");
1884 } else if (strcmp(module->name, "mapi") == 0) {
1885 /* Handle old names for MAPI preferences. */
1886 if (strcmp(dotp, "mapi_decrypt") == 0)
1887 pref = find_preference(module, "decrypt");
1888 } else if (strcmp(module->name, "fc") == 0) {
1889 /* Handle old names for Fibre Channel preferences. */
1890 if (strcmp(dotp, "reassemble_fc") == 0)
1891 pref = find_preference(module, "reassemble");
1892 else if (strcmp(dotp, "fc_max_frame_size") == 0)
1893 pref = find_preference(module, "max_frame_size");
1894 } else if (strcmp(module->name, "fcip") == 0) {
1895 /* Handle old names for Fibre Channel-over-IP preferences. */
1896 if (strcmp(dotp, "desegment_fcip_messages") == 0)
1897 pref = find_preference(module, "desegment");
1898 else if (strcmp(dotp, "fcip_port") == 0)
1899 pref = find_preference(module, "target_port");
1900 } else if (strcmp(module->name, "gtp") == 0) {
1901 /* Handle old names for GTP preferences. */
1902 if (strcmp(dotp, "gtpv0_port") == 0)
1903 pref = find_preference(module, "v0_port");
1904 else if (strcmp(dotp, "gtpv1c_port") == 0)
1905 pref = find_preference(module, "v1c_port");
1906 else if (strcmp(dotp, "gtpv1u_port") == 0)
1907 pref = find_preference(module, "v1u_port");
1908 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
1909 pref = find_preference(module, "dissect_tpdu");
1910 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
1911 pref = find_preference(module, "v0_dissect_cdr_as");
1912 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
1913 pref = find_preference(module, "v0_check_etsi");
1914 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
1915 pref = find_preference(module, "v1_check_etsi");
1916 } else if (strcmp(module->name, "ip") == 0) {
1917 /* Handle old names for IP preferences. */
1918 if (strcmp(dotp, "ip_summary_in_tree") == 0)
1919 pref = find_preference(module, "summary_in_tree");
1920 } else if (strcmp(module->name, "iscsi") == 0) {
1921 /* Handle old names for iSCSI preferences. */
1922 if (strcmp(dotp, "iscsi_port") == 0)
1923 pref = find_preference(module, "target_port");
1924 } else if (strcmp(module->name, "lmp") == 0) {
1925 /* Handle old names for LMP preferences. */
1926 if (strcmp(dotp, "lmp_version") == 0)
1927 pref = find_preference(module, "version");
1928 } else if (strcmp(module->name, "mtp3") == 0) {
1929 /* Handle old names for MTP3 preferences. */
1930 if (strcmp(dotp, "mtp3_standard") == 0)
1931 pref = find_preference(module, "standard");
1932 } else if (strcmp(module->name, "nlm") == 0) {
1933 /* Handle old names for NLM preferences. */
1934 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
1935 pref = find_preference(module, "msg_res_matching");
1936 } else if (strcmp(module->name, "ppp") == 0) {
1937 /* Handle old names for PPP preferences. */
1938 if (strcmp(dotp, "ppp_fcs") == 0)
1939 pref = find_preference(module, "fcs_type");
1940 else if (strcmp(dotp, "ppp_vj") == 0)
1941 pref = find_preference(module, "decompress_vj");
1942 } else if (strcmp(module->name, "rsvp") == 0) {
1943 /* Handle old names for RSVP preferences. */
1944 if (strcmp(dotp, "rsvp_process_bundle") == 0)
1945 pref = find_preference(module, "process_bundle");
1946 } else if (strcmp(module->name, "tcp") == 0) {
1947 /* Handle old names for TCP preferences. */
1948 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
1949 pref = find_preference(module, "summary_in_tree");
1950 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
1951 pref = find_preference(module, "analyze_sequence_numbers");
1952 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
1953 pref = find_preference(module, "relative_sequence_numbers");
1954 } else if (strcmp(module->name, "udp") == 0) {
1955 /* Handle old names for UDP preferences. */
1956 if (strcmp(dotp, "udp_summary_in_tree") == 0)
1957 pref = find_preference(module, "summary_in_tree");
1958 } else if (strcmp(module->name, "ndps") == 0) {
1959 /* Handle old names for NDPS preferences. */
1960 if (strcmp(dotp, "desegment_ndps") == 0)
1961 pref = find_preference(module, "desegment_tcp");
1962 } else if (strcmp(module->name, "http") == 0) {
1963 /* Handle old names for HTTP preferences. */
1964 if (strcmp(dotp, "desegment_http_headers") == 0)
1965 pref = find_preference(module, "desegment_headers");
1966 else if (strcmp(dotp, "desegment_http_body") == 0)
1967 pref = find_preference(module, "desegment_body");
1968 } else if (strcmp(module->name, "smpp") == 0) {
1969 /* Handle preferences that moved from SMPP. */
1970 module_t *new_module = find_module("gsm-sms-ud");
1971 if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
1972 pref = find_preference(new_module, "port_number_udh_means_wsp");
1973 else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
1974 pref = find_preference(new_module, "try_dissect_1st_fragment");
1975 } else if (strcmp(module->name, "asn1") == 0) {
1976 /* Handle old generic ASN.1 preferences (it's not really a
1977 rename, as the new preferences support multiple ports,
1978 but we might as well copy them over). */
1979 if (strcmp(dotp, "tcp_port") == 0)
1980 pref = find_preference(module, "tcp_ports");
1981 else if (strcmp(dotp, "udp_port") == 0)
1982 pref = find_preference(module, "udp_ports");
1983 else if (strcmp(dotp, "sctp_port") == 0)
1984 pref = find_preference(module, "sctp_ports");
1988 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
1990 switch (pref->type) {
1993 uval = strtoul(value, &p, pref->info.base);
1994 if (p == value || *p != '\0')
1995 return PREFS_SET_SYNTAX_ERR; /* number was bad */
1996 if (*pref->varp.uint != uval) {
1997 module->prefs_changed = TRUE;
1998 *pref->varp.uint = uval;
2003 /* XXX - give an error if it's neither "true" nor "false"? */
2004 if (strcasecmp(value, "true") == 0)
2008 if (*pref->varp.boolp != bval) {
2009 module->prefs_changed = TRUE;
2010 *pref->varp.boolp = bval;
2015 /* XXX - give an error if it doesn't match? */
2016 enum_val = find_val_for_string(value,
2017 pref->info.enum_info.enumvals, 1);
2018 if (*pref->varp.enump != enum_val) {
2019 module->prefs_changed = TRUE;
2020 *pref->varp.enump = enum_val;
2025 if (strcmp(*pref->varp.string, value) != 0) {
2026 module->prefs_changed = TRUE;
2027 g_free(*pref->varp.string);
2028 *pref->varp.string = g_strdup(value);
2036 if (range_convert_str(&newrange, value, pref->info.max_value) !=
2038 /* XXX - distinguish between CVT_SYNTAX_ERROR and
2039 CVT_NUMBER_TOO_BIG */
2040 return PREFS_SET_SYNTAX_ERR; /* number was bad */
2043 if (!ranges_are_equal(*pref->varp.range, newrange)) {
2044 module->prefs_changed = TRUE;
2045 g_free(*pref->varp.range);
2046 *pref->varp.range = newrange;
2052 return PREFS_SET_OBSOLETE; /* no such preference any more */
2056 return PREFS_SET_OK;
2065 * Write out a single preference.
2068 write_pref(gpointer data, gpointer user_data)
2070 pref_t *pref = data;
2071 write_pref_arg_t *arg = user_data;
2072 const enum_val_t *enum_valp;
2073 const char *val_string;
2075 if (pref->type == PREF_OBSOLETE) {
2077 * This preference is no longer supported; it's not a
2078 * real preference, so we don't write it out (i.e., we
2079 * treat it as if it weren't found in the list of
2080 * preferences, and we weren't called in the first place).
2085 fprintf(arg->pf, "\n# %s\n", pref->description);
2087 switch (pref->type) {
2090 switch (pref->info.base) {
2093 fprintf(arg->pf, "# A decimal number.\n");
2094 fprintf(arg->pf, "%s.%s: %u\n", arg->module->name,
2095 pref->name, *pref->varp.uint);
2099 fprintf(arg->pf, "# An octal number.\n");
2100 fprintf(arg->pf, "%s.%s: %#o\n", arg->module->name,
2101 pref->name, *pref->varp.uint);
2105 fprintf(arg->pf, "# A hexadecimal number.\n");
2106 fprintf(arg->pf, "%s.%s: %#x\n", arg->module->name,
2107 pref->name, *pref->varp.uint);
2113 fprintf(arg->pf, "# TRUE or FALSE (case-insensitive).\n");
2114 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2115 *pref->varp.boolp ? "TRUE" : "FALSE");
2120 * For now, we save the "description" value, so that if we
2121 * save the preferences older versions of Ethereal can at
2122 * least read preferences that they supported; we support
2123 * either the short name or the description when reading
2124 * the preferences file or a "-o" option.
2126 fprintf(arg->pf, "# One of: ");
2127 enum_valp = pref->info.enum_info.enumvals;
2129 while (enum_valp->name != NULL) {
2130 if (enum_valp->value == *pref->varp.enump)
2131 val_string = enum_valp->description;
2132 fprintf(arg->pf, "%s", enum_valp->description);
2134 if (enum_valp->name == NULL)
2135 fprintf(arg->pf, "\n");
2137 fprintf(arg->pf, ", ");
2139 fprintf(arg->pf, "# (case-insensitive).\n");
2140 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name,
2141 pref->name, val_string);
2145 fprintf(arg->pf, "# A string.\n");
2146 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2147 *pref->varp.string);
2152 char range_string[MAXRANGESTRING];
2154 fprintf(arg->pf, "# A string denoting an positive integer range (e.g., \"1-20,30-40\").\n");
2155 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
2156 range_convert_range(*pref->varp.range, range_string));
2161 g_assert_not_reached();
2167 write_module_prefs(gpointer data, gpointer user_data)
2169 write_pref_arg_t arg;
2173 g_list_foreach(arg.module->prefs, write_pref, &arg);
2176 /* Write out "prefs" to the user's preferences file, and return 0.
2178 If we got an error, stuff a pointer to the path of the preferences file
2179 into "*pf_path_return", and return the errno. */
2181 write_prefs(char **pf_path_return)
2189 * - Split output lines longer than MAX_VAL_LEN
2190 * - Create a function for the preference directory check/creation
2191 * so that duplication can be avoided with filter.c
2194 pf_path = get_persconffile_path(PF_NAME, TRUE);
2195 if ((pf = fopen(pf_path, "w")) == NULL) {
2196 *pf_path_return = pf_path;
2200 fputs("# Configuration file for Ethereal " VERSION ".\n"
2202 "# This file is regenerated each time preferences are saved within\n"
2203 "# Ethereal. Making manual changes should be safe, however.\n", pf);
2205 fprintf (pf, "\n######## User Interface ########\n");
2207 fprintf(pf, "\n# Vertical scrollbars should be on right side?\n");
2208 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2209 fprintf(pf, PRS_GUI_SCROLLBAR_ON_RIGHT ": %s\n",
2210 prefs.gui_scrollbar_on_right == TRUE ? "TRUE" : "FALSE");
2212 fprintf(pf, "\n# Packet-list selection bar can be used to browse w/o selecting?\n");
2213 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2214 fprintf(pf, PRS_GUI_PLIST_SEL_BROWSE ": %s\n",
2215 prefs.gui_plist_sel_browse == TRUE ? "TRUE" : "FALSE");
2217 fprintf(pf, "\n# Protocol-tree selection bar can be used to browse w/o selecting?\n");
2218 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2219 fprintf(pf, PRS_GUI_PTREE_SEL_BROWSE ": %s\n",
2220 prefs.gui_ptree_sel_browse == TRUE ? "TRUE" : "FALSE");
2222 fprintf(pf, "\n# Alternating colors in TreeViews?\n");
2223 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2224 fprintf(pf, PRS_GUI_ALTERN_COLORS ": %s\n",
2225 prefs.gui_altern_colors == TRUE ? "TRUE" : "FALSE");
2227 fprintf(pf, "\n# Place filter toolbar inside the statusbar?\n");
2228 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2229 fprintf(pf, PRS_GUI_FILTER_TOOLBAR_IN_STATUSBAR ": %s\n",
2230 prefs.filter_toolbar_show_in_statusbar == TRUE ? "TRUE" : "FALSE");
2232 fprintf(pf, "\n# Protocol-tree line style.\n");
2233 fprintf(pf, "# One of: NONE, SOLID, DOTTED, TABBED\n");
2234 fprintf(pf, PRS_GUI_PTREE_LINE_STYLE ": %s\n",
2235 gui_ptree_line_style_text[prefs.gui_ptree_line_style]);
2237 fprintf(pf, "\n# Protocol-tree expander style.\n");
2238 fprintf(pf, "# One of: NONE, SQUARE, TRIANGLE, CIRCULAR\n");
2239 fprintf(pf, PRS_GUI_PTREE_EXPANDER_STYLE ": %s\n",
2240 gui_ptree_expander_style_text[prefs.gui_ptree_expander_style]);
2242 fprintf(pf, "\n# Hex dump highlight style.\n");
2243 fprintf(pf, "# One of: BOLD, INVERSE\n");
2244 fprintf(pf, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE ": %s\n",
2245 gui_hex_dump_highlight_style_text[prefs.gui_hex_dump_highlight_style]);
2247 fprintf(pf, "\n# Main Toolbar style.\n");
2248 fprintf(pf, "# One of: ICONS, TEXT, BOTH\n");
2249 fprintf(pf, PRS_GUI_TOOLBAR_MAIN_STYLE ": %s\n",
2250 gui_toolbar_style_text[prefs.gui_toolbar_main_style]);
2252 fprintf(pf, "\n# Save window position at exit?\n");
2253 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2254 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_POSITION ": %s\n",
2255 prefs.gui_geometry_save_position == TRUE ? "TRUE" : "FALSE");
2257 fprintf(pf, "\n# Save window size at exit?\n");
2258 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2259 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_SIZE ": %s\n",
2260 prefs.gui_geometry_save_size == TRUE ? "TRUE" : "FALSE");
2262 fprintf(pf, "\n# Save window maximized state at exit (GTK2 only)?\n");
2263 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2264 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_MAXIMIZED ": %s\n",
2265 prefs.gui_geometry_save_maximized == TRUE ? "TRUE" : "FALSE");
2267 fprintf(pf, "\n# Open a console window (WIN32 only)?\n");
2268 fprintf(pf, "# One of: NEVER, AUTOMATIC, ALWAYS\n");
2269 fprintf(pf, PRS_GUI_CONSOLE_OPEN ": %s\n",
2270 gui_console_open_text[prefs.gui_console_open]);
2272 fprintf(pf, "\n# The max. number of items in the open recent files list.\n");
2273 fprintf(pf, "# A decimal number.\n");
2274 fprintf(pf, PRS_GUI_RECENT_COUNT_MAX ": %d\n",
2275 prefs.gui_recent_files_count_max);
2277 fprintf(pf, "\n# Where to start the File Open dialog box.\n");
2278 fprintf(pf, "# One of: LAST_OPENED, SPECIFIED\n");
2279 fprintf(pf, PRS_GUI_FILEOPEN_STYLE ": %s\n",
2280 gui_fileopen_style_text[prefs.gui_fileopen_style]);
2282 if (prefs.gui_fileopen_dir != NULL) {
2283 fprintf(pf, "\n# Directory to start in when opening File Open dialog.\n");
2284 fprintf(pf, PRS_GUI_FILEOPEN_DIR ": %s\n",
2285 prefs.gui_fileopen_dir);
2288 fprintf(pf, "\n# The preview timeout in the File Open dialog.\n");
2289 fprintf(pf, "# A decimal number (in seconds).\n");
2290 fprintf(pf, PRS_GUI_FILEOPEN_PREVIEW ": %d\n",
2291 prefs.gui_fileopen_preview);
2293 fprintf(pf, "\n# Ask to save unsaved capture files?\n");
2294 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2295 fprintf(pf, PRS_GUI_ASK_UNSAVED ": %s\n",
2296 prefs.gui_ask_unsaved == TRUE ? "TRUE" : "FALSE");
2298 fprintf(pf, "\n# Wrap to beginning/end of file during search?\n");
2299 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2300 fprintf(pf, PRS_GUI_FIND_WRAP ": %s\n",
2301 prefs.gui_find_wrap == TRUE ? "TRUE" : "FALSE");
2303 fprintf(pf, "\n# The path to the webbrowser.\n");
2304 fprintf(pf, "# Ex: mozilla %%s\n");
2305 fprintf(pf, PRS_GUI_WEBBROWSER ": %s\n", prefs.gui_webbrowser);
2307 fprintf (pf, "\n######## User Interface: Layout ########\n");
2309 fprintf(pf, "\n# Layout type (1-6).\n");
2310 fprintf(pf, PRS_GUI_LAYOUT_TYPE ": %d\n",
2311 prefs.gui_layout_type);
2313 fprintf(pf, "\n# Layout content of the panes (1-3).\n");
2314 fprintf(pf, "# One of: NONE, PLIST, PDETAILS, PBYTES\n");
2315 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_1 ": %s\n",
2316 gui_layout_content_text[prefs.gui_layout_content_1]);
2317 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_2 ": %s\n",
2318 gui_layout_content_text[prefs.gui_layout_content_2]);
2319 fprintf(pf, PRS_GUI_LAYOUT_CONTENT_3 ": %s\n",
2320 gui_layout_content_text[prefs.gui_layout_content_3]);
2322 fprintf (pf, "\n######## User Interface: Columns ########\n");
2324 clp = prefs.col_list;
2327 cfmt = (fmt_data *) clp->data;
2328 col_l = g_list_append(col_l, cfmt->title);
2329 col_l = g_list_append(col_l, cfmt->fmt);
2332 fprintf (pf, "\n# Packet list column format.\n");
2333 fprintf (pf, "# Each pair of strings consists of a column title and its format.\n");
2334 fprintf (pf, "%s: %s\n", PRS_COL_FMT, put_string_list(col_l));
2335 /* This frees the list of strings, but not the strings to which it
2336 refers; that's what we want, as we haven't copied those strings,
2337 we just referred to them. */
2340 fprintf (pf, "\n######## User Interface: Font ########\n");
2342 fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes (GTK version 1).\n");
2343 fprintf(pf, PRS_GUI_FONT_NAME_1 ": %s\n", prefs.gui_font_name1);
2345 fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes (GTK version 2).\n");
2346 fprintf(pf, PRS_GUI_FONT_NAME_2 ": %s\n", prefs.gui_font_name2);
2348 fprintf (pf, "\n######## User Interface: Colors ########\n");
2350 fprintf (pf, "\n# Color preferences for a marked frame.\n");
2351 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2352 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_FG,
2353 (prefs.gui_marked_fg.red * 255 / 65535),
2354 (prefs.gui_marked_fg.green * 255 / 65535),
2355 (prefs.gui_marked_fg.blue * 255 / 65535));
2356 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_BG,
2357 (prefs.gui_marked_bg.red * 255 / 65535),
2358 (prefs.gui_marked_bg.green * 255 / 65535),
2359 (prefs.gui_marked_bg.blue * 255 / 65535));
2361 fprintf (pf, "\n# TCP stream window color preferences.\n");
2362 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2363 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_FG,
2364 (prefs.st_client_fg.red * 255 / 65535),
2365 (prefs.st_client_fg.green * 255 / 65535),
2366 (prefs.st_client_fg.blue * 255 / 65535));
2367 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_BG,
2368 (prefs.st_client_bg.red * 255 / 65535),
2369 (prefs.st_client_bg.green * 255 / 65535),
2370 (prefs.st_client_bg.blue * 255 / 65535));
2371 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_FG,
2372 (prefs.st_server_fg.red * 255 / 65535),
2373 (prefs.st_server_fg.green * 255 / 65535),
2374 (prefs.st_server_fg.blue * 255 / 65535));
2375 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_BG,
2376 (prefs.st_server_bg.red * 255 / 65535),
2377 (prefs.st_server_bg.green * 255 / 65535),
2378 (prefs.st_server_bg.blue * 255 / 65535));
2380 fprintf(pf, "\n####### Capture ########\n");
2382 if (prefs.capture_device != NULL) {
2383 fprintf(pf, "\n# Default capture device\n");
2384 fprintf(pf, PRS_CAP_DEVICE ": %s\n", prefs.capture_device);
2387 if (prefs.capture_devices_descr != NULL) {
2388 fprintf(pf, "\n# Interface descriptions.\n");
2389 fprintf(pf, "# Ex: eth0(eth0 descr),eth1(eth1 descr),...\n");
2390 fprintf(pf, PRS_CAP_DEVICES_DESCR ": %s\n", prefs.capture_devices_descr);
2393 if (prefs.capture_devices_hide != NULL) {
2394 fprintf(pf, "\n# Hide interface?\n");
2395 fprintf(pf, "# Ex: eth0,eth3,...\n");
2396 fprintf(pf, PRS_CAP_DEVICES_HIDE ": %s\n", prefs.capture_devices_hide);
2399 fprintf(pf, "\n# Capture in promiscuous mode?\n");
2400 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2401 fprintf(pf, PRS_CAP_PROM_MODE ": %s\n",
2402 prefs.capture_prom_mode == TRUE ? "TRUE" : "FALSE");
2404 fprintf(pf, "\n# Update packet list in real time during capture?\n");
2405 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2406 fprintf(pf, PRS_CAP_REAL_TIME ": %s\n",
2407 prefs.capture_real_time == TRUE ? "TRUE" : "FALSE");
2409 fprintf(pf, "\n# Scroll packet list during capture?\n");
2410 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2411 fprintf(pf, PRS_CAP_AUTO_SCROLL ": %s\n",
2412 prefs.capture_auto_scroll == TRUE ? "TRUE" : "FALSE");
2414 fprintf(pf, "\n# Show capture info dialog while capturing?\n");
2415 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2416 fprintf(pf, PRS_CAP_SHOW_INFO ": %s\n",
2417 prefs.capture_show_info == TRUE ? "TRUE" : "FALSE");
2419 fprintf (pf, "\n######## Printing ########\n");
2421 fprintf (pf, "\n# Can be one of \"text\" or \"postscript\".\n"
2422 "print.format: %s\n", pr_formats[prefs.pr_format]);
2424 fprintf (pf, "\n# Can be one of \"command\" or \"file\".\n"
2425 "print.destination: %s\n", pr_dests[prefs.pr_dest]);
2427 fprintf (pf, "\n# This is the file that gets written to when the "
2428 "destination is set to \"file\"\n"
2429 "%s: %s\n", PRS_PRINT_FILE, prefs.pr_file);
2431 fprintf (pf, "\n# Output gets piped to this command when the destination "
2432 "is set to \"command\"\n"
2433 "%s: %s\n", PRS_PRINT_CMD, prefs.pr_cmd);
2435 fprintf(pf, "\n####### Name Resolution ########\n");
2437 fprintf(pf, "\n# Resolve addresses to names?\n");
2438 fprintf(pf, "# TRUE or FALSE (case-insensitive), or a list of address types to resolve.\n");
2439 fprintf(pf, PRS_NAME_RESOLVE ": %s\n",
2440 name_resolve_to_string(prefs.name_resolve));
2442 fprintf(pf, "\n# Name resolution concurrency.\n");
2443 fprintf(pf, "# A decimal number.\n");
2444 fprintf(pf, PRS_NAME_RESOLVE_CONCURRENCY ": %d\n",
2445 prefs.name_resolve_concurrency);
2447 fprintf(pf, "\n####### Protocols ########\n");
2449 g_list_foreach(modules, write_module_prefs, pf);
2453 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
2454 an error indication, or maybe write to a new preferences file and
2455 rename that file on top of the old one only if there are not I/O
2460 /* Copy a set of preferences. */
2462 copy_prefs(e_prefs *dest, e_prefs *src)
2464 fmt_data *src_cfmt, *dest_cfmt;
2467 dest->pr_format = src->pr_format;
2468 dest->pr_dest = src->pr_dest;
2469 dest->pr_file = g_strdup(src->pr_file);
2470 dest->pr_cmd = g_strdup(src->pr_cmd);
2471 dest->col_list = NULL;
2472 for (entry = src->col_list; entry != NULL; entry = g_list_next(entry)) {
2473 src_cfmt = entry->data;
2474 dest_cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
2475 dest_cfmt->title = g_strdup(src_cfmt->title);
2476 dest_cfmt->fmt = g_strdup(src_cfmt->fmt);
2477 dest->col_list = g_list_append(dest->col_list, dest_cfmt);
2479 dest->num_cols = src->num_cols;
2480 dest->st_client_fg = src->st_client_fg;
2481 dest->st_client_bg = src->st_client_bg;
2482 dest->st_server_fg = src->st_server_fg;
2483 dest->st_server_bg = src->st_server_bg;
2484 dest->gui_scrollbar_on_right = src->gui_scrollbar_on_right;
2485 dest->gui_plist_sel_browse = src->gui_plist_sel_browse;
2486 dest->gui_ptree_sel_browse = src->gui_ptree_sel_browse;
2487 dest->gui_altern_colors = src->gui_altern_colors;
2488 dest->filter_toolbar_show_in_statusbar = src->filter_toolbar_show_in_statusbar;
2489 dest->gui_ptree_line_style = src->gui_ptree_line_style;
2490 dest->gui_ptree_expander_style = src->gui_ptree_expander_style;
2491 dest->gui_hex_dump_highlight_style = src->gui_hex_dump_highlight_style;
2492 dest->gui_toolbar_main_style = src->gui_toolbar_main_style;
2493 dest->gui_fileopen_dir = g_strdup(src->gui_fileopen_dir);
2494 dest->gui_console_open = src->gui_console_open;
2495 dest->gui_fileopen_style = src->gui_fileopen_style;
2496 dest->gui_fileopen_preview = src->gui_fileopen_preview;
2497 dest->gui_ask_unsaved = src->gui_ask_unsaved;
2498 dest->gui_find_wrap = src->gui_find_wrap;
2499 dest->gui_layout_type = src->gui_layout_type;
2500 dest->gui_layout_content_1 = src->gui_layout_content_1;
2501 dest->gui_layout_content_2 = src->gui_layout_content_2;
2502 dest->gui_layout_content_3 = src->gui_layout_content_3;
2503 dest->gui_font_name1 = g_strdup(src->gui_font_name1);
2504 dest->gui_font_name2 = g_strdup(src->gui_font_name2);
2505 dest->gui_marked_fg = src->gui_marked_fg;
2506 dest->gui_marked_bg = src->gui_marked_bg;
2507 dest->gui_geometry_save_position = src->gui_geometry_save_position;
2508 dest->gui_geometry_save_size = src->gui_geometry_save_size;
2509 dest->gui_geometry_save_maximized = src->gui_geometry_save_maximized;
2510 dest->gui_webbrowser = g_strdup(src->gui_webbrowser);
2511 /* values for the capture dialog box */
2512 dest->capture_device = g_strdup(src->capture_device);
2513 dest->capture_devices_descr = g_strdup(src->capture_devices_descr);
2514 dest->capture_devices_hide = g_strdup(src->capture_devices_hide);
2515 dest->capture_prom_mode = src->capture_prom_mode;
2516 dest->capture_real_time = src->capture_real_time;
2517 dest->capture_auto_scroll = src->capture_auto_scroll;
2518 dest->capture_show_info = src->capture_show_info;
2519 dest->name_resolve = src->name_resolve;
2520 dest->name_resolve_concurrency = src->name_resolve_concurrency;
2524 /* Free a set of preferences. */
2526 free_prefs(e_prefs *pr)
2528 if (pr->pr_file != NULL) {
2529 g_free(pr->pr_file);
2532 if (pr->pr_cmd != NULL) {
2537 if (pr->gui_font_name1 != NULL) {
2538 g_free(pr->gui_font_name1);
2539 pr->gui_font_name1 = NULL;
2541 if (pr->gui_font_name2 != NULL) {
2542 g_free(pr->gui_font_name2);
2543 pr->gui_font_name2 = NULL;
2545 if (pr->gui_fileopen_dir != NULL) {
2546 g_free(pr->gui_fileopen_dir);
2547 pr->gui_fileopen_dir = NULL;
2549 g_free(pr->gui_webbrowser);
2550 pr->gui_webbrowser = NULL;
2551 if (pr->capture_device != NULL) {
2552 g_free(pr->capture_device);
2553 pr->capture_device = NULL;
2555 if (pr->capture_devices_descr != NULL) {
2556 g_free(pr->capture_devices_descr);
2557 pr->capture_devices_descr = NULL;
2559 if (pr->capture_devices_hide != NULL) {
2560 g_free(pr->capture_devices_hide);
2561 pr->capture_devices_hide = NULL;
2566 free_col_info(e_prefs *pr)
2570 while (pr->col_list != NULL) {
2571 cfmt = pr->col_list->data;
2572 g_free(cfmt->title);
2575 pr->col_list = g_list_remove_link(pr->col_list, pr->col_list);
2577 g_list_free(pr->col_list);
2578 pr->col_list = NULL;