2 * Routines for handling preferences
4 * $Id: prefs.c,v 1.113 2003/11/16 23:17:22 guy Exp $
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>
42 #include <epan/resolv.h>
43 #include <epan/packet.h>
46 #include <epan/proto.h>
50 #include "prefs-int.h"
52 /* Internal functions */
53 static module_t *find_module(const char *name);
54 static module_t *prefs_register_module_or_subtree(module_t *parent,
55 const char *name, const char *title, gboolean is_subtree,
56 void (*apply_cb)(void));
57 static struct preference *find_preference(module_t *, const char *);
58 static int set_pref(gchar*, gchar*);
59 static GList *get_string_list(gchar *);
60 static gchar *put_string_list(GList *);
61 static void clear_string_list(GList *);
62 static void free_col_info(e_prefs *);
64 #define GPF_NAME "ethereal.conf"
65 #define PF_NAME "preferences"
67 static gboolean init_prefs = TRUE;
68 static gchar *gpf_path = NULL;
71 * XXX - variables to allow us to attempt to interpret the first
72 * "mgcp.{tcp,udp}.port" in a preferences file as
73 * "mgcp.{tcp,udp}.gateway_port" and the second as
74 * "mgcp.{tcp,udp}.callagent_port".
76 static int mgcp_tcp_port_count;
77 static int mgcp_udp_port_count;
81 static gchar *gui_ptree_line_style_text[] =
82 { "NONE", "SOLID", "DOTTED", "TABBED", NULL };
84 static gchar *gui_ptree_expander_style_text[] =
85 { "NONE", "SQUARE", "TRIANGLE", "CIRCULAR", NULL };
87 static gchar *gui_hex_dump_highlight_style_text[] =
88 { "BOLD", "INVERSE", NULL };
90 static gchar *gui_fileopen_style_text[] =
91 { "LAST_OPENED", "SPECIFIED", NULL };
93 /* GTK knows of two ways representing "both", vertical and horizontal aligned.
94 * as this may not work on other guis, we use only "both" in general here */
95 static gchar *gui_toolbar_style_text[] =
96 { "ICONS", "TEXT", "BOTH", NULL };
99 * List of all modules with preference settings.
101 static GList *modules;
104 * List of all modules that should show up at the top level of the
105 * tree in the preference dialog box.
107 static GList *top_level_modules;
110 module_compare_name(gconstpointer p1_arg, gconstpointer p2_arg)
112 const module_t *p1 = p1_arg;
113 const module_t *p2 = p2_arg;
115 return g_strcasecmp(p1->name, p2->name);
119 module_compare_title(gconstpointer p1_arg, gconstpointer p2_arg)
121 const module_t *p1 = p1_arg;
122 const module_t *p2 = p2_arg;
124 return g_strcasecmp(p1->title, p2->title);
128 * Register a module that will have preferences.
129 * Specify the module under which to register it or NULL to register it
130 * at the top level, the name used for the module in the preferences file,
131 * the title used in the tab for it in a preferences dialog box, and a
132 * routine to call back when we apply the preferences.
135 prefs_register_module(module_t *parent, const char *name, const char *title,
136 void (*apply_cb)(void))
138 return prefs_register_module_or_subtree(parent, name, title, FALSE,
143 * Register a subtree that will have modules under it.
144 * Specify the module under which to register it or NULL to register it
145 * at the top level and the title used in the tab for it in a preferences
149 prefs_register_subtree(module_t *parent, const char *title)
151 return prefs_register_module_or_subtree(parent, NULL, title, TRUE,
156 prefs_register_module_or_subtree(module_t *parent, const char *name,
157 const char *title, gboolean is_subtree, void (*apply_cb)(void))
162 module = g_malloc(sizeof (module_t));
164 module->title = title;
165 module->is_subtree = is_subtree;
166 module->apply_cb = apply_cb;
167 module->prefs = NULL; /* no preferences, to start */
168 module->numprefs = 0;
169 module->prefs_changed = FALSE;
170 module->obsolete = FALSE;
173 * Do we have a module name?
178 * Make sure that only lower-case ASCII letters, numbers,
179 * underscores, hyphens, and dots appear in the name.
181 * Crash if there is, as that's an error in the code;
182 * you can make the title a nice string with capitalization,
183 * white space, punctuation, etc., but the name can be used
184 * on the command line, and shouldn't require quoting,
187 for (p = name; *p != '\0'; p++)
188 g_assert(isascii(*p) &&
189 (islower(*p) || isdigit(*p) || *p == '_' ||
190 *p == '-' || *p == '.'));
193 * Make sure there's not already a module with that
194 * name. Crash if there is, as that's an error in the
195 * code, and the code has to be fixed not to register
196 * more than one module with the same name.
198 * We search the list of all modules; the subtree stuff
199 * doesn't require preferences in subtrees to have names
200 * that reflect the subtree they're in (that would require
201 * protocol preferences to have a bogus "protocol.", or
202 * something such as that, to be added to all their names).
204 g_assert(find_module(name) == NULL);
207 * Insert this module in the list of all modules.
209 modules = g_list_insert_sorted(modules, module,
210 module_compare_name);
213 * This has no name, just a title; check to make sure it's a
214 * subtree, and crash if it's not.
216 g_assert(is_subtree);
220 * Insert this module into the appropriate place in the display
223 if (parent == NULL) {
225 * It goes at the top.
227 top_level_modules = g_list_insert_sorted(top_level_modules,
228 module, module_compare_title);
231 * It goes into the list for this module.
233 parent->prefs = g_list_insert_sorted(parent->prefs, module,
234 module_compare_title);
241 * Register that a protocol has preferences.
243 module_t *protocols_module;
246 prefs_register_protocol(int id, void (*apply_cb)(void))
248 protocol_t *protocol;
251 * Have we yet created the "Protocols" subtree?
253 if (protocols_module == NULL) {
257 protocols_module = prefs_register_subtree(NULL, "Protocols");
259 protocol = find_protocol_by_id(id);
260 return prefs_register_module(protocols_module,
261 proto_get_protocol_filter_name(id),
262 proto_get_protocol_short_name(protocol), apply_cb);
266 * Register that a protocol used to have preferences but no longer does,
267 * by creating an "obsolete" module for it.
270 prefs_register_protocol_obsolete(int id)
273 protocol_t *protocol;
276 * Have we yet created the "Protocols" subtree?
278 if (protocols_module == NULL) {
282 protocols_module = prefs_register_subtree(NULL, "Protocols");
284 protocol = find_protocol_by_id(id);
285 module = prefs_register_module(protocols_module,
286 proto_get_protocol_filter_name(id),
287 proto_get_protocol_short_name(protocol), NULL);
288 module->obsolete = TRUE;
293 * Find a module, given its name.
296 module_match(gconstpointer a, gconstpointer b)
298 const module_t *module = a;
299 const char *name = b;
301 return strcmp(name, module->name);
305 find_module(const char *name)
309 list_entry = g_list_find_custom(modules, (gpointer)name, module_match);
310 if (list_entry == NULL)
311 return NULL; /* no such module */
312 return (module_t *) list_entry->data;
321 do_module_callback(gpointer data, gpointer user_data)
323 module_t *module = data;
324 module_cb_arg_t *arg = user_data;
326 if (!module->obsolete)
327 (*arg->callback)(module, arg->user_data);
331 * Call a callback function, with a specified argument, for each module
332 * in a list of modules. If the list is NULL, searches the top-level
333 * list in the display tree of modules.
335 * Ignores "obsolete" modules; their sole purpose is to allow old
336 * preferences for dissectors that no longer have preferences to be
337 * silently ignored in preference files. Does not ignore subtrees,
338 * as this can be used when walking the display tree of modules.
341 prefs_module_list_foreach(GList *module_list, module_cb callback,
346 if (module_list == NULL)
347 module_list = top_level_modules;
349 arg.callback = callback;
350 arg.user_data = user_data;
351 g_list_foreach(module_list, do_module_callback, &arg);
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 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
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 that used to be supported but no longer is.
586 prefs_register_obsolete_preference(module_t *module, const char *name)
588 register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
592 * Call a callback function, with a specified argument, for each preference
595 * If any of the callbacks return a non-zero value, stop and return that
596 * value, otherwise return 0.
599 prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
605 for (elem = g_list_first(module->prefs); elem != NULL;
606 elem = g_list_next(elem)) {
608 if (pref->type == PREF_OBSOLETE) {
610 * This preference is no longer supported; it's
611 * not a real preference, so we don't call the
612 * callback for it (i.e., we treat it as if it
613 * weren't found in the list of preferences,
614 * and we weren't called in the first place).
619 ret = (*callback)(pref, user_data);
627 * Register all non-dissector modules' preferences.
630 prefs_register_modules(void)
634 /* Parse through a list of comma-separated, possibly quoted strings.
635 Return a list of the string data. */
637 get_string_list(gchar *str)
639 enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
641 gint state = PRE_STRING, i = 0, j = 0;
642 gboolean backslash = FALSE;
647 /* Allocate a buffer for the first string. */
648 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
654 /* It's the end of the input, so it's the end of the string we
655 were working on, and there's no more input. */
656 if (state == IN_QUOT || backslash) {
657 /* We were in the middle of a quoted string or backslash escape,
658 and ran out of characters; that's an error. */
660 clear_string_list(sl);
664 sl = g_list_append(sl, slstr);
667 if (cur_c == '"' && ! backslash) {
670 /* We hadn't yet started processing a string; this starts the
671 string, and we're now quoting. */
675 /* We're in the middle of a quoted string, and we saw a quotation
676 mark; we're no longer quoting. */
680 /* We're working on a string, but haven't seen a quote; we're
687 } else if (cur_c == '\\' && ! backslash) {
688 /* We saw a backslash, and the previous character wasn't a
689 backslash; escape the next character.
691 This also means we've started a new string. */
693 if (state == PRE_STRING)
695 } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
696 /* We saw a comma, and we're not in the middle of a quoted string
697 and it wasn't preceded by a backslash; it's the end of
698 the string we were working on... */
700 sl = g_list_append(sl, slstr);
702 /* ...and the beginning of a new string. */
704 slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
706 } else if (!isspace(cur_c) || state != PRE_STRING) {
707 /* Either this isn't a white-space character, or we've started a
708 string (i.e., already seen a non-white-space character for that
709 string and put it into the string).
711 The character is to be put into the string; do so if there's
713 if (j < COL_MAX_LEN) {
718 /* If it was backslash-escaped, we're done with the backslash escape. */
726 #define MAX_FMT_PREF_LEN 1024
727 #define MAX_FMT_PREF_LINE_LEN 60
729 put_string_list(GList *sl)
731 static gchar pref_str[MAX_FMT_PREF_LEN] = "";
732 GList *clp = g_list_first(sl);
734 int cur_pos = 0, cur_len = 0;
737 gchar *strp, *quoted_strp, c;
743 /* Allocate a buffer big enough to hold the entire string, with each
744 character quoted (that's the worst case). */
745 str_len = strlen(str);
746 quoted_str = g_malloc(str_len*2 + 1);
748 /* Now quote any " or \ characters in it. */
750 quoted_strp = quoted_str;
751 while ((c = *strp++) != '\0') {
752 if (c == '"' || c == '\\') {
753 /* It has to be backslash-quoted. */
754 *quoted_strp++ = '\\';
760 fmt_len = strlen(quoted_str) + 4;
761 if ((fmt_len + cur_len) < (MAX_FMT_PREF_LEN - 1)) {
762 if ((fmt_len + cur_pos) > MAX_FMT_PREF_LINE_LEN) {
766 pref_str[cur_len] = '\n'; cur_len++;
767 pref_str[cur_len] = '\t'; cur_len++;
769 sprintf(&pref_str[cur_len], "\"%s\", ", quoted_str);
777 /* If the string is at least two characters long, the last two characters
778 are ", ", and should be discarded, as there are no more items in the
781 pref_str[cur_len - 2] = '\0';
787 clear_string_list(GList *sl)
793 l = g_list_remove_link(l, l);
798 * Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
800 * The array must be terminated by an entry with a null "name" string.
801 * If the string matches a "name" strings in an entry, the value from that
802 * entry is returned. Otherwise, the default value that was passed as the
803 * third argument is returned.
806 find_val_for_string(const char *needle, const enum_val_t *haystack,
811 while (haystack[i].name != NULL) {
812 if (strcasecmp(needle, haystack[i].name) == 0) {
813 return haystack[i].value;
817 return default_value;
820 /* Takes an string and a pointer to an array of strings, and a default int value.
821 * The array must be terminated by a NULL string. If the string is found in the array
822 * of strings, the index of that string in the array is returned. Otherwise, the
823 * default value that was passed as the third argument is returned.
826 find_index_from_string_array(char *needle, char **haystack, int default_value)
830 while (haystack[i] != NULL) {
831 if (strcmp(needle, haystack[i]) == 0) {
836 return default_value;
839 /* Preferences file format:
840 * - Configuration directives start at the beginning of the line, and
841 * are terminated with a colon.
842 * - Directives can be continued on the next line by preceding them with
847 # This is a comment line
849 print.file: /a/very/long/path/
854 #define MAX_VAR_LEN 48
856 #define DEF_NUM_COLS 6
858 static int read_prefs_file(const char *pf_path, FILE *pf);
860 /* Read the preferences file, fill in "prefs", and return a pointer to it.
862 If we got an error (other than "it doesn't exist") trying to read
863 the global preferences file, stuff the errno into "*gpf_errno_return"
864 and a pointer to the path of the file into "*gpf_path_return", and
867 If we got an error (other than "it doesn't exist") trying to read
868 the user's preferences file, stuff the errno into "*pf_errno_return"
869 and a pointer to the path of the file into "*pf_path_return", and
872 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
873 char **gpf_path_return, int *pf_errno_return,
874 int *pf_read_errno_return, char **pf_path_return)
881 gchar *col_fmt[] = {"No.", "%m", "Time", "%t",
882 "Source", "%s", "Destination", "%d",
883 "Protocol", "%p", "Info", "%i"};
886 /* Initialize preferences to wired-in default values.
887 They may be overridded by the global preferences file or the
888 user's preferences file. */
890 prefs.pr_format = PR_FMT_TEXT;
891 prefs.pr_dest = PR_DEST_CMD;
892 prefs.pr_file = g_strdup("ethereal.out");
893 prefs.pr_cmd = g_strdup("lpr");
894 prefs.col_list = NULL;
895 for (i = 0; i < DEF_NUM_COLS; i++) {
896 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
897 cfmt->title = g_strdup(col_fmt[i * 2]);
898 cfmt->fmt = g_strdup(col_fmt[(i * 2) + 1]);
899 prefs.col_list = g_list_append(prefs.col_list, cfmt);
901 prefs.num_cols = DEF_NUM_COLS;
902 prefs.st_client_fg.pixel = 0;
903 prefs.st_client_fg.red = 32767;
904 prefs.st_client_fg.green = 0;
905 prefs.st_client_fg.blue = 0;
906 prefs.st_client_bg.pixel = 65535;
907 prefs.st_client_bg.red = 65535;
908 prefs.st_client_bg.green = 65535;
909 prefs.st_client_bg.blue = 65535;
910 prefs.st_server_fg.pixel = 0;
911 prefs.st_server_fg.red = 0;
912 prefs.st_server_fg.green = 0;
913 prefs.st_server_fg.blue = 32767;
914 prefs.st_server_bg.pixel = 65535;
915 prefs.st_server_bg.red = 65535;
916 prefs.st_server_bg.green = 65535;
917 prefs.st_server_bg.blue = 65535;
918 prefs.gui_scrollbar_on_right = TRUE;
919 prefs.gui_plist_sel_browse = FALSE;
920 prefs.gui_ptree_sel_browse = FALSE;
921 prefs.gui_altern_colors = FALSE;
922 prefs.gui_ptree_line_style = 0;
923 prefs.gui_ptree_expander_style = 1;
924 prefs.gui_hex_dump_highlight_style = 1;
925 prefs.gui_toolbar_main_show = TRUE;
926 prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
928 prefs.gui_font_name = g_strdup("-*-lucida console-medium-r-*-*-*-100-*-*-*-*-*-*");
931 * XXX - for now, we make the initial font name a pattern that matches
932 * only ISO 8859/1 fonts, so that we don't match 2-byte fonts such
933 * as ISO 10646 fonts.
935 * Users in locales using other one-byte fonts will have to choose
936 * a different font from the preferences dialog - or put the font
937 * selection in the global preferences file to make that font the
938 * default for all users who don't explicitly specify a different
941 * Making this a font set rather than a font has two problems:
943 * 1) as far as I know, you can't select font sets with the
944 * font selection dialog;
946 * 2) if you use a font set, the text to be drawn must be a
947 * multi-byte string in the appropriate locale, but
948 * Ethereal does *NOT* guarantee that's the case - in
949 * the hex-dump window, each character in the text portion
950 * of the display must be a *single* byte, and in the
951 * packet-list and protocol-tree windows, text extracted
952 * from the packet is not necessarily in the right format.
954 * "Doing this right" may, for the packet-list and protocol-tree
955 * windows, require that dissectors know what the locale is
956 * *AND* know what locale and text representation is used in
957 * the packets they're dissecting, and may be impossible in
958 * the hex-dump window (except by punting and displaying only
961 * GTK+ 2.0 may simplify part of the problem, as it will, as I
962 * understand it, use UTF-8-encoded Unicode as its internal
963 * character set; however, we'd still have to know whatever
964 * character set and encoding is used in the packet (which
965 * may differ for different protocols, e.g. SMB might use
966 * PC code pages for some strings and Unicode for others, whilst
967 * NFS might use some UNIX character set encoding, e.g. ISO 8859/x,
968 * or one of the EUC character sets for Asian languages, or one
969 * of the other multi-byte character sets, or UTF-8, or...).
971 * I.e., as far as I can tell, "internationalizing" the packet-list,
972 * protocol-tree, and hex-dump windows involves a lot more than, say,
973 * just using font sets rather than fonts.
975 prefs.gui_font_name = g_strdup("-*-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-1");
977 prefs.gui_marked_fg.pixel = 65535;
978 prefs.gui_marked_fg.red = 65535;
979 prefs.gui_marked_fg.green = 65535;
980 prefs.gui_marked_fg.blue = 65535;
981 prefs.gui_marked_bg.pixel = 0;
982 prefs.gui_marked_bg.red = 0;
983 prefs.gui_marked_bg.green = 0;
984 prefs.gui_marked_bg.blue = 0;
985 prefs.gui_geometry_save_position = 0;
986 prefs.gui_geometry_save_size = 1;
987 prefs.gui_geometry_main_x = 20;
988 prefs.gui_geometry_main_y = 20;
989 prefs.gui_geometry_main_width = DEF_WIDTH;
990 prefs.gui_geometry_main_height = -1;
991 prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
992 prefs.gui_fileopen_dir = g_strdup("");
993 prefs.gui_fileopen_remembered_dir = NULL;
995 /* set the default values for the capture dialog box */
996 prefs.capture_device = NULL;
997 prefs.capture_devices_descr = NULL;
998 prefs.capture_devices_hide = NULL;
999 prefs.capture_prom_mode = TRUE;
1000 prefs.capture_real_time = FALSE;
1001 prefs.capture_auto_scroll = FALSE;
1002 prefs.name_resolve = RESOLV_ALL ^ RESOLV_NETWORK;
1003 prefs.name_resolve_concurrency = 500;
1006 /* Construct the pathname of the global preferences file. */
1008 gpf_path = get_datafile_path(GPF_NAME);
1010 /* Read the global preferences file, if it exists. */
1011 *gpf_path_return = NULL;
1012 if ((pf = fopen(gpf_path, "r")) != NULL) {
1013 /* We succeeded in opening it; read it. */
1014 err = read_prefs_file(gpf_path, pf);
1016 /* We had an error reading the file; return the errno and the
1017 pathname, so our caller can report the error. */
1018 *gpf_errno_return = 0;
1019 *gpf_read_errno_return = err;
1020 *gpf_path_return = gpf_path;
1024 /* We failed to open it. If we failed for some reason other than
1025 "it doesn't exist", return the errno and the pathname, so our
1026 caller can report the error. */
1027 if (errno != ENOENT) {
1028 *gpf_errno_return = errno;
1029 *gpf_read_errno_return = 0;
1030 *gpf_path_return = gpf_path;
1034 /* Construct the pathname of the user's preferences file. */
1035 pf_path = get_persconffile_path(PF_NAME, FALSE);
1037 /* Read the user's preferences file, if it exists. */
1038 *pf_path_return = NULL;
1039 if ((pf = fopen(pf_path, "r")) != NULL) {
1040 /* We succeeded in opening it; read it. */
1041 err = read_prefs_file(pf_path, pf);
1043 /* We had an error reading the file; return the errno and the
1044 pathname, so our caller can report the error. */
1045 *pf_errno_return = 0;
1046 *pf_read_errno_return = err;
1047 *pf_path_return = pf_path;
1052 /* We failed to open it. If we failed for some reason other than
1053 "it doesn't exist", return the errno and the pathname, so our
1054 caller can report the error. */
1055 if (errno != ENOENT) {
1056 *pf_errno_return = errno;
1057 *pf_read_errno_return = 0;
1058 *pf_path_return = pf_path;
1066 read_prefs_file(const char *pf_path, FILE *pf)
1068 enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
1069 gchar cur_var[MAX_VAR_LEN], cur_val[MAX_VAL_LEN];
1070 int got_c, state = START;
1071 gboolean got_val = FALSE;
1072 gint var_len = 0, val_len = 0, fline = 1, pline = 1;
1075 * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
1078 mgcp_tcp_port_count = 0;
1079 mgcp_udp_port_count = 0;
1081 while ((got_c = getc(pf)) != EOF) {
1082 if (got_c == '\n') {
1087 if (var_len >= MAX_VAR_LEN) {
1088 g_warning ("%s line %d: Variable too long", pf_path, fline);
1093 if (val_len >= MAX_VAL_LEN) {
1094 g_warning ("%s line %d: Value too long", pf_path, fline);
1102 if (isalnum(got_c)) {
1105 cur_var[var_len] = '\0';
1106 cur_val[val_len] = '\0';
1107 switch (set_pref(cur_var, cur_val)) {
1109 case PREFS_SET_SYNTAX_ERR:
1110 g_warning ("%s line %d: Syntax error", pf_path, pline);
1113 case PREFS_SET_NO_SUCH_PREF:
1114 g_warning ("%s line %d: No such preference \"%s\"", pf_path,
1118 case PREFS_SET_OBSOLETE:
1119 /* We silently ignore attempts to set these; it's
1120 probably not the user's fault that it's in there -
1121 they may have saved preferences with a release that
1126 g_warning ("%s line %d: Incomplete preference", pf_path, pline);
1134 } else if (isspace(got_c) && var_len > 0 && got_val) {
1136 } else if (got_c == '#') {
1139 g_warning ("%s line %d: Malformed line", pf_path, fline);
1144 cur_var[var_len] = got_c;
1153 if (!isspace(got_c)) {
1155 cur_val[val_len] = got_c;
1161 cur_val[val_len] = got_c;
1164 while (isspace((guchar)cur_val[val_len]) && val_len > 0)
1173 cur_var[var_len] = '\0';
1174 cur_val[val_len] = '\0';
1175 switch (set_pref(cur_var, cur_val)) {
1177 case PREFS_SET_SYNTAX_ERR:
1178 g_warning ("%s line %d: Syntax error", pf_path, pline);
1181 case PREFS_SET_NO_SUCH_PREF:
1182 g_warning ("%s line %d: No such preference \"%s\"", pf_path,
1186 case PREFS_SET_OBSOLETE:
1187 /* We silently ignore attempts to set these; it's probably not
1188 the user's fault that it's in there - they may have saved
1189 preferences with a release that supported it. */
1193 g_warning ("%s line %d: Incomplete preference", pf_path, pline);
1203 * Given a string of the form "<pref name>:<pref value>", as might appear
1204 * as an argument to a "-o" option, parse it and set the preference in
1205 * question. Return an indication of whether it succeeded or failed
1209 prefs_set_pref(char *prefarg)
1215 * Set the counters of "mgcp.{tcp,udp}.port" entries we've
1216 * seen to values that keep us from trying to interpret tham
1217 * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
1218 * as, from the command line, we have no way of guessing which
1219 * the user had in mind.
1221 mgcp_tcp_port_count = -1;
1222 mgcp_udp_port_count = -1;
1224 colonp = strchr(prefarg, ':');
1226 return PREFS_SET_SYNTAX_ERR;
1232 * Skip over any white space (there probably won't be any, but
1233 * as we allow it in the preferences file, we might as well
1240 * Put the colon back, so if our caller uses, in an
1241 * error message, the string they passed us, the message
1245 return PREFS_SET_SYNTAX_ERR;
1248 ret = set_pref(prefarg, p);
1249 *colonp = ':'; /* put the colon back */
1253 #define PRS_PRINT_FMT "print.format"
1254 #define PRS_PRINT_DEST "print.destination"
1255 #define PRS_PRINT_FILE "print.file"
1256 #define PRS_PRINT_CMD "print.command"
1257 #define PRS_COL_FMT "column.format"
1258 #define PRS_STREAM_CL_FG "stream.client.fg"
1259 #define PRS_STREAM_CL_BG "stream.client.bg"
1260 #define PRS_STREAM_SR_FG "stream.server.fg"
1261 #define PRS_STREAM_SR_BG "stream.server.bg"
1262 #define PRS_GUI_SCROLLBAR_ON_RIGHT "gui.scrollbar_on_right"
1263 #define PRS_GUI_PLIST_SEL_BROWSE "gui.packet_list_sel_browse"
1264 #define PRS_GUI_PTREE_SEL_BROWSE "gui.protocol_tree_sel_browse"
1265 #define PRS_GUI_ALTERN_COLORS "gui.tree_view_altern_colors"
1266 #define PRS_GUI_PTREE_LINE_STYLE "gui.protocol_tree_line_style"
1267 #define PRS_GUI_PTREE_EXPANDER_STYLE "gui.protocol_tree_expander_style"
1268 #define PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE "gui.hex_dump_highlight_style"
1269 #define PRS_GUI_FONT_NAME "gui.font_name"
1270 #define PRS_GUI_MARKED_FG "gui.marked_frame.fg"
1271 #define PRS_GUI_MARKED_BG "gui.marked_frame.bg"
1272 #define PRS_GUI_FILEOPEN_STYLE "gui.fileopen.style"
1273 #define PRS_GUI_FILEOPEN_DIR "gui.fileopen.dir"
1274 #define PRS_GUI_FILEOPEN_REMEMBERED_DIR "gui.fileopen.remembered_dir"
1275 #define PRS_GUI_GEOMETRY_SAVE_POSITION "gui.geometry.save.position"
1276 #define PRS_GUI_GEOMETRY_SAVE_SIZE "gui.geometry.save.size"
1277 #define PRS_GUI_GEOMETRY_MAIN_X "gui.geometry.main.x"
1278 #define PRS_GUI_GEOMETRY_MAIN_Y "gui.geometry.main.y"
1279 #define PRS_GUI_GEOMETRY_MAIN_WIDTH "gui.geometry.main.width"
1280 #define PRS_GUI_GEOMETRY_MAIN_HEIGHT "gui.geometry.main.height"
1281 #define PRS_GUI_TOOLBAR_MAIN_SHOW "gui.toolbar_main_show"
1282 #define PRS_GUI_TOOLBAR_MAIN_STYLE "gui.toolbar_main_style"
1285 * This applies to more than just captures, so it's not "capture.name_resolve";
1286 * "capture.name_resolve" is supported on input for backwards compatibility.
1288 * It's not a preference for a particular part of Ethereal, it's used all
1289 * over the place, so its name doesn't have two components.
1291 #define PRS_NAME_RESOLVE "name_resolve"
1292 #define PRS_NAME_RESOLVE_CONCURRENCY "name_resolve_concurrency"
1293 #define PRS_CAP_NAME_RESOLVE "capture.name_resolve"
1295 /* values for the capture dialog box */
1296 #define PRS_CAP_DEVICE "capture.device"
1297 #define PRS_CAP_DEVICES_DESCR "capture.devices_descr"
1298 #define PRS_CAP_DEVICES_HIDE "capture.devices_hide"
1299 #define PRS_CAP_PROM_MODE "capture.prom_mode"
1300 #define PRS_CAP_REAL_TIME "capture.real_time_update"
1301 #define PRS_CAP_AUTO_SCROLL "capture.auto_scroll"
1303 #define RED_COMPONENT(x) ((((x) >> 16) & 0xff) * 65535 / 255)
1304 #define GREEN_COMPONENT(x) ((((x) >> 8) & 0xff) * 65535 / 255)
1305 #define BLUE_COMPONENT(x) (((x) & 0xff) * 65535 / 255)
1307 static gchar *pr_formats[] = { "text", "postscript" };
1308 static gchar *pr_dests[] = { "command", "file" };
1313 } name_resolve_opt_t;
1315 static name_resolve_opt_t name_resolve_opt[] = {
1316 { 'm', RESOLV_MAC },
1317 { 'n', RESOLV_NETWORK },
1318 { 't', RESOLV_TRANSPORT },
1319 { 'C', RESOLV_CONCURRENT },
1322 #define N_NAME_RESOLVE_OPT (sizeof name_resolve_opt / sizeof name_resolve_opt[0])
1325 name_resolve_to_string(guint32 name_resolve)
1327 static char string[N_NAME_RESOLVE_OPT+1];
1330 gboolean all_opts_set = TRUE;
1332 if (name_resolve == RESOLV_NONE)
1335 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1336 if (name_resolve & name_resolve_opt[i].value)
1337 *p++ = name_resolve_opt[i].letter;
1339 all_opts_set = FALSE;
1348 string_to_name_resolve(char *string, guint32 *name_resolve)
1354 while ((c = *string++) != '\0') {
1355 for (i = 0; i < N_NAME_RESOLVE_OPT; i++) {
1356 if (c == name_resolve_opt[i].letter) {
1357 *name_resolve |= name_resolve_opt[i].value;
1361 if (i == N_NAME_RESOLVE_OPT) {
1363 * Unrecognized letter.
1372 set_pref(gchar *pref_name, gchar *value)
1374 GList *col_l, *col_l_elt;
1377 unsigned long int cval;
1382 gchar *dotp, *last_dotp;
1387 if (strcmp(pref_name, PRS_PRINT_FMT) == 0) {
1388 if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) {
1389 prefs.pr_format = PR_FMT_TEXT;
1390 } else if (strcmp(value, pr_formats[PR_FMT_PS]) == 0) {
1391 prefs.pr_format = PR_FMT_PS;
1393 return PREFS_SET_SYNTAX_ERR;
1395 } else if (strcmp(pref_name, PRS_PRINT_DEST) == 0) {
1396 if (strcmp(value, pr_dests[PR_DEST_CMD]) == 0) {
1397 prefs.pr_dest = PR_DEST_CMD;
1398 } else if (strcmp(value, pr_dests[PR_DEST_FILE]) == 0) {
1399 prefs.pr_dest = PR_DEST_FILE;
1401 return PREFS_SET_SYNTAX_ERR;
1403 } else if (strcmp(pref_name, PRS_PRINT_FILE) == 0) {
1404 if (prefs.pr_file) g_free(prefs.pr_file);
1405 prefs.pr_file = g_strdup(value);
1406 } else if (strcmp(pref_name, PRS_PRINT_CMD) == 0) {
1407 if (prefs.pr_cmd) g_free(prefs.pr_cmd);
1408 prefs.pr_cmd = g_strdup(value);
1409 } else if (strcmp(pref_name, PRS_COL_FMT) == 0) {
1410 col_l = get_string_list(value);
1412 return PREFS_SET_SYNTAX_ERR;
1413 if ((g_list_length(col_l) % 2) != 0) {
1414 /* A title didn't have a matching format. */
1415 clear_string_list(col_l);
1416 return PREFS_SET_SYNTAX_ERR;
1418 /* Check to make sure all column formats are valid. */
1419 col_l_elt = g_list_first(col_l);
1421 /* Make sure the title isn't empty. */
1422 if (strcmp(col_l_elt->data, "") == 0) {
1424 clear_string_list(col_l);
1425 return PREFS_SET_SYNTAX_ERR;
1428 /* Go past the title. */
1429 col_l_elt = col_l_elt->next;
1431 /* Check the format. */
1432 if (get_column_format_from_str(col_l_elt->data) == -1) {
1433 /* It's not a valid column format. */
1434 clear_string_list(col_l);
1435 return PREFS_SET_SYNTAX_ERR;
1438 /* Go past the format. */
1439 col_l_elt = col_l_elt->next;
1441 free_col_info(&prefs);
1442 prefs.col_list = NULL;
1443 llen = g_list_length(col_l);
1444 prefs.num_cols = llen / 2;
1445 col_l_elt = g_list_first(col_l);
1447 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
1448 cfmt->title = g_strdup(col_l_elt->data);
1449 col_l_elt = col_l_elt->next;
1450 cfmt->fmt = g_strdup(col_l_elt->data);
1451 col_l_elt = col_l_elt->next;
1452 prefs.col_list = g_list_append(prefs.col_list, cfmt);
1454 clear_string_list(col_l);
1455 } else if (strcmp(pref_name, PRS_STREAM_CL_FG) == 0) {
1456 cval = strtoul(value, NULL, 16);
1457 prefs.st_client_fg.pixel = 0;
1458 prefs.st_client_fg.red = RED_COMPONENT(cval);
1459 prefs.st_client_fg.green = GREEN_COMPONENT(cval);
1460 prefs.st_client_fg.blue = BLUE_COMPONENT(cval);
1461 } else if (strcmp(pref_name, PRS_STREAM_CL_BG) == 0) {
1462 cval = strtoul(value, NULL, 16);
1463 prefs.st_client_bg.pixel = 0;
1464 prefs.st_client_bg.red = RED_COMPONENT(cval);
1465 prefs.st_client_bg.green = GREEN_COMPONENT(cval);
1466 prefs.st_client_bg.blue = BLUE_COMPONENT(cval);
1467 } else if (strcmp(pref_name, PRS_STREAM_SR_FG) == 0) {
1468 cval = strtoul(value, NULL, 16);
1469 prefs.st_server_fg.pixel = 0;
1470 prefs.st_server_fg.red = RED_COMPONENT(cval);
1471 prefs.st_server_fg.green = GREEN_COMPONENT(cval);
1472 prefs.st_server_fg.blue = BLUE_COMPONENT(cval);
1473 } else if (strcmp(pref_name, PRS_STREAM_SR_BG) == 0) {
1474 cval = strtoul(value, NULL, 16);
1475 prefs.st_server_bg.pixel = 0;
1476 prefs.st_server_bg.red = RED_COMPONENT(cval);
1477 prefs.st_server_bg.green = GREEN_COMPONENT(cval);
1478 prefs.st_server_bg.blue = BLUE_COMPONENT(cval);
1479 } else if (strcmp(pref_name, PRS_GUI_SCROLLBAR_ON_RIGHT) == 0) {
1480 if (strcasecmp(value, "true") == 0) {
1481 prefs.gui_scrollbar_on_right = TRUE;
1484 prefs.gui_scrollbar_on_right = FALSE;
1486 } else if (strcmp(pref_name, PRS_GUI_PLIST_SEL_BROWSE) == 0) {
1487 if (strcasecmp(value, "true") == 0) {
1488 prefs.gui_plist_sel_browse = TRUE;
1491 prefs.gui_plist_sel_browse = FALSE;
1493 } else if (strcmp(pref_name, PRS_GUI_PTREE_SEL_BROWSE) == 0) {
1494 if (strcasecmp(value, "true") == 0) {
1495 prefs.gui_ptree_sel_browse = TRUE;
1498 prefs.gui_ptree_sel_browse = FALSE;
1500 } else if (strcmp(pref_name, PRS_GUI_ALTERN_COLORS) == 0) {
1501 if (strcasecmp(value, "true") == 0) {
1502 prefs.gui_altern_colors = TRUE;
1505 prefs.gui_altern_colors = FALSE;
1507 } else if (strcmp(pref_name, PRS_GUI_PTREE_LINE_STYLE) == 0) {
1508 prefs.gui_ptree_line_style =
1509 find_index_from_string_array(value, gui_ptree_line_style_text, 0);
1510 } else if (strcmp(pref_name, PRS_GUI_PTREE_EXPANDER_STYLE) == 0) {
1511 prefs.gui_ptree_expander_style =
1512 find_index_from_string_array(value, gui_ptree_expander_style_text, 1);
1513 } else if (strcmp(pref_name, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE) == 0) {
1514 prefs.gui_hex_dump_highlight_style =
1515 find_index_from_string_array(value, gui_hex_dump_highlight_style_text, 1);
1516 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_SHOW) == 0) {
1517 /* see toolbar.c for details */
1518 if (strcasecmp(value, "true") == 0) {
1519 prefs.gui_toolbar_main_show = TRUE;
1522 prefs.gui_toolbar_main_show = FALSE;
1524 } else if (strcmp(pref_name, PRS_GUI_TOOLBAR_MAIN_STYLE) == 0) {
1525 /* see toolbar.c for details, "icons only" is default */
1526 prefs.gui_toolbar_main_style =
1527 find_index_from_string_array(value, gui_toolbar_style_text,
1529 } else if (strcmp(pref_name, PRS_GUI_FONT_NAME) == 0) {
1530 if (prefs.gui_font_name != NULL)
1531 g_free(prefs.gui_font_name);
1532 prefs.gui_font_name = g_strdup(value);
1533 } else if (strcmp(pref_name, PRS_GUI_MARKED_FG) == 0) {
1534 cval = strtoul(value, NULL, 16);
1535 prefs.gui_marked_fg.pixel = 0;
1536 prefs.gui_marked_fg.red = RED_COMPONENT(cval);
1537 prefs.gui_marked_fg.green = GREEN_COMPONENT(cval);
1538 prefs.gui_marked_fg.blue = BLUE_COMPONENT(cval);
1539 } else if (strcmp(pref_name, PRS_GUI_MARKED_BG) == 0) {
1540 cval = strtoul(value, NULL, 16);
1541 prefs.gui_marked_bg.pixel = 0;
1542 prefs.gui_marked_bg.red = RED_COMPONENT(cval);
1543 prefs.gui_marked_bg.green = GREEN_COMPONENT(cval);
1544 prefs.gui_marked_bg.blue = BLUE_COMPONENT(cval);
1545 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_POSITION) == 0) {
1546 if (strcasecmp(value, "true") == 0) {
1547 prefs.gui_geometry_save_position = TRUE;
1550 prefs.gui_geometry_save_position = FALSE;
1552 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_SAVE_SIZE) == 0) {
1553 if (strcasecmp(value, "true") == 0) {
1554 prefs.gui_geometry_save_size = TRUE;
1557 prefs.gui_geometry_save_size = FALSE;
1559 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_X) == 0) {
1560 prefs.gui_geometry_main_x = strtol(value, NULL, 10);
1561 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_Y) == 0) {
1562 prefs.gui_geometry_main_y = strtol(value, NULL, 10);
1563 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_WIDTH) == 0) {
1564 prefs.gui_geometry_main_width = strtol(value, NULL, 10);
1565 } else if (strcmp(pref_name, PRS_GUI_GEOMETRY_MAIN_HEIGHT) == 0) {
1566 prefs.gui_geometry_main_height = strtol(value, NULL, 10);
1567 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_STYLE) == 0) {
1568 prefs.gui_fileopen_style =
1569 find_index_from_string_array(value, gui_fileopen_style_text,
1570 FO_STYLE_LAST_OPENED);
1571 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_DIR) == 0) {
1572 if (prefs.gui_fileopen_dir != NULL)
1573 g_free(prefs.gui_fileopen_dir);
1574 prefs.gui_fileopen_dir = g_strdup(value);
1575 } else if (strcmp(pref_name, PRS_GUI_FILEOPEN_REMEMBERED_DIR) == 0) {
1576 if (prefs.gui_fileopen_remembered_dir != NULL)
1577 g_free(prefs.gui_fileopen_remembered_dir);
1578 prefs.gui_fileopen_remembered_dir = g_strdup(value);
1580 /* handle the capture options */
1581 } else if (strcmp(pref_name, PRS_CAP_DEVICE) == 0) {
1582 if (prefs.capture_device != NULL)
1583 g_free(prefs.capture_device);
1584 prefs.capture_device = g_strdup(value);
1585 } else if (strcmp(pref_name, PRS_CAP_DEVICES_DESCR) == 0) {
1586 if (prefs.capture_devices_descr != NULL)
1587 g_free(prefs.capture_devices_descr);
1588 prefs.capture_devices_descr = g_strdup(value);
1589 } else if (strcmp(pref_name, PRS_CAP_DEVICES_HIDE) == 0) {
1590 if (prefs.capture_devices_hide != NULL)
1591 g_free(prefs.capture_devices_hide);
1592 prefs.capture_devices_hide = g_strdup(value);
1593 } else if (strcmp(pref_name, PRS_CAP_PROM_MODE) == 0) {
1594 prefs.capture_prom_mode = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1595 } else if (strcmp(pref_name, PRS_CAP_REAL_TIME) == 0) {
1596 prefs.capture_real_time = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1597 } else if (strcmp(pref_name, PRS_CAP_AUTO_SCROLL) == 0) {
1598 prefs.capture_auto_scroll = ((strcasecmp(value, "true") == 0)?TRUE:FALSE);
1600 /* handle the global options */
1601 } else if (strcmp(pref_name, PRS_NAME_RESOLVE) == 0 ||
1602 strcmp(pref_name, PRS_CAP_NAME_RESOLVE) == 0) {
1604 * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
1605 * RESOLV_ALL and RESOLV_NONE.
1607 * Otherwise, we treat it as a list of name types we want to resolve.
1609 if (strcasecmp(value, "true") == 0)
1610 prefs.name_resolve = RESOLV_ALL;
1611 else if (strcasecmp(value, "false") == 0)
1612 prefs.name_resolve = RESOLV_NONE;
1614 prefs.name_resolve = RESOLV_NONE; /* start out with none set */
1615 if (string_to_name_resolve(value, &prefs.name_resolve) != '\0')
1616 return PREFS_SET_SYNTAX_ERR;
1618 } else if (strcmp(pref_name, PRS_NAME_RESOLVE_CONCURRENCY) == 0) {
1619 prefs.name_resolve_concurrency = strtol(value, NULL, 10);
1621 /* To which module does this preference belong? */
1623 last_dotp = pref_name;
1626 dotp = strchr(last_dotp, '.');
1629 /* no such module */
1630 return PREFS_SET_NO_SUCH_PREF;
1633 /* no ".", so no module/name separator */
1634 return PREFS_SET_SYNTAX_ERR;
1640 *dotp = '\0'; /* separate module and preference name */
1641 module = find_module(pref_name);
1644 * XXX - "Diameter" rather than "diameter" was used in earlier
1645 * versions of Ethereal; if we didn't find the module, and its name
1646 * was "Diameter", look for "diameter" instead.
1648 * In addition, the BEEP protocol used to be the BXXP protocol,
1649 * so if we didn't find the module, and its name was "bxxp",
1650 * look for "beep" instead.
1652 * Also, the preferences for GTP v0 and v1 were combined under
1653 * a single "gtp" heading.
1655 if (module == NULL) {
1656 if (strcmp(pref_name, "Diameter") == 0)
1657 module = find_module("diameter");
1658 else if (strcmp(pref_name, "bxxp") == 0)
1659 module = find_module("beep");
1660 else if (strcmp(pref_name, "gtpv0") == 0 ||
1661 strcmp(pref_name, "gtpv1") == 0)
1662 module = find_module("gtp");
1664 *dotp = '.'; /* put the preference string back */
1665 dotp++; /* skip past separator to preference name */
1669 pref = find_preference(module, dotp);
1672 if (strcmp(module->name, "mgcp") == 0) {
1674 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
1675 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
1676 * were used in earlier versions of Ethereal; if we didn't find the
1677 * preference, it was an MGCP preference, and its name was
1678 * "display raw text toggle" or "display dissect tree", look for
1679 * "display_raw_text" or "display_dissect_tree" instead.
1681 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
1682 * the gateway and callagent ports were given those names; we interpret
1683 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
1684 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
1685 * they were registered by the MCCP dissector and thus that's the
1686 * order in which they were written to the preferences file. (If
1687 * we're not reading the preferences file, but are handling stuff
1688 * from a "-o" command-line option, we have no clue which the user
1689 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
1690 * or "mgcp.{tcp,udp}.callagent_port" instead.)
1692 if (strcmp(dotp, "display raw text toggle") == 0)
1693 pref = find_preference(module, "display_raw_text");
1694 else if (strcmp(dotp, "display dissect tree") == 0)
1695 pref = find_preference(module, "display_dissect_tree");
1696 else if (strcmp(dotp, "tcp.port") == 0) {
1697 mgcp_tcp_port_count++;
1698 if (mgcp_tcp_port_count == 1) {
1699 /* It's the first one */
1700 pref = find_preference(module, "tcp.gateway_port");
1701 } else if (mgcp_tcp_port_count == 2) {
1702 /* It's the second one */
1703 pref = find_preference(module, "tcp.callagent_port");
1705 /* Otherwise it's from the command line, and we don't bother
1707 } else if (strcmp(dotp, "udp.port") == 0) {
1708 mgcp_udp_port_count++;
1709 if (mgcp_udp_port_count == 1) {
1710 /* It's the first one */
1711 pref = find_preference(module, "udp.gateway_port");
1712 } else if (mgcp_udp_port_count == 2) {
1713 /* It's the second one */
1714 pref = find_preference(module, "udp.callagent_port");
1716 /* Otherwise it's from the command line, and we don't bother
1719 } else if (strcmp(module->name, "smb") == 0) {
1720 /* Handle old names for SMB preferences. */
1721 if (strcmp(dotp, "smb.trans.reassembly") == 0)
1722 pref = find_preference(module, "trans_reassembly");
1723 else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
1724 pref = find_preference(module, "dcerpc_reassembly");
1725 } else if (strcmp(module->name, "ndmp") == 0) {
1726 /* Handle old names for NDMP preferences. */
1727 if (strcmp(dotp, "ndmp.desegment") == 0)
1728 pref = find_preference(module, "desegment");
1729 } else if (strcmp(module->name, "diameter") == 0) {
1730 /* Handle old names for Diameter preferences. */
1731 if (strcmp(dotp, "diameter.desegment") == 0)
1732 pref = find_preference(module, "desegment");
1733 } else if (strcmp(module->name, "pcli") == 0) {
1734 /* Handle old names for PCLI preferences. */
1735 if (strcmp(dotp, "pcli.udp_port") == 0)
1736 pref = find_preference(module, "udp_port");
1737 } else if (strcmp(module->name, "artnet") == 0) {
1738 /* Handle old names for ARTNET preferences. */
1739 if (strcmp(dotp, "artnet.udp_port") == 0)
1740 pref = find_preference(module, "udp_port");
1741 } else if (strcmp(module->name, "mapi") == 0) {
1742 /* Handle old names for MAPI preferences. */
1743 if (strcmp(dotp, "mapi_decrypt") == 0)
1744 pref = find_preference(module, "decrypt");
1745 } else if (strcmp(module->name, "fc") == 0) {
1746 /* Handle old names for Fibre Channel preferences. */
1747 if (strcmp(dotp, "reassemble_fc") == 0)
1748 pref = find_preference(module, "reassemble");
1749 else if (strcmp(dotp, "fc_max_frame_size") == 0)
1750 pref = find_preference(module, "max_frame_size");
1751 } else if (strcmp(module->name, "fcip") == 0) {
1752 /* Handle old names for Fibre Channel-over-IP preferences. */
1753 if (strcmp(dotp, "desegment_fcip_messages") == 0)
1754 pref = find_preference(module, "desegment");
1755 else if (strcmp(dotp, "fcip_port") == 0)
1756 pref = find_preference(module, "target_port");
1757 } else if (strcmp(module->name, "gtp") == 0) {
1758 /* Handle old names for GTP preferences. */
1759 if (strcmp(dotp, "gtpv0_port") == 0)
1760 pref = find_preference(module, "v0_port");
1761 else if (strcmp(dotp, "gtpv1c_port") == 0)
1762 pref = find_preference(module, "v1c_port");
1763 else if (strcmp(dotp, "gtpv1u_port") == 0)
1764 pref = find_preference(module, "v1u_port");
1765 else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
1766 pref = find_preference(module, "dissect_tpdu");
1767 else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
1768 pref = find_preference(module, "v0_dissect_cdr_as");
1769 else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
1770 pref = find_preference(module, "v0_check_etsi");
1771 else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
1772 pref = find_preference(module, "v1_check_etsi");
1773 } else if (strcmp(module->name, "ip") == 0) {
1774 /* Handle old names for IP preferences. */
1775 if (strcmp(dotp, "ip_summary_in_tree") == 0)
1776 pref = find_preference(module, "summary_in_tree");
1777 } else if (strcmp(module->name, "iscsi") == 0) {
1778 /* Handle old names for iSCSI preferences. */
1779 if (strcmp(dotp, "iscsi_port") == 0)
1780 pref = find_preference(module, "target_port");
1781 } else if (strcmp(module->name, "lmp") == 0) {
1782 /* Handle old names for LMP preferences. */
1783 if (strcmp(dotp, "lmp_version") == 0)
1784 pref = find_preference(module, "version");
1785 } else if (strcmp(module->name, "mtp3") == 0) {
1786 /* Handle old names for MTP3 preferences. */
1787 if (strcmp(dotp, "mtp3_standard") == 0)
1788 pref = find_preference(module, "standard");
1789 } else if (strcmp(module->name, "nlm") == 0) {
1790 /* Handle old names for NLM preferences. */
1791 if (strcmp(dotp, "nlm_msg_res_matching") == 0)
1792 pref = find_preference(module, "msg_res_matching");
1793 } else if (strcmp(module->name, "ppp") == 0) {
1794 /* Handle old names for PPP preferences. */
1795 if (strcmp(dotp, "ppp_fcs") == 0)
1796 pref = find_preference(module, "fcs_type");
1797 else if (strcmp(dotp, "ppp_vj") == 0)
1798 pref = find_preference(module, "decompress_vj");
1799 } else if (strcmp(module->name, "rsvp") == 0) {
1800 /* Handle old names for RSVP preferences. */
1801 if (strcmp(dotp, "rsvp_process_bundle") == 0)
1802 pref = find_preference(module, "process_bundle");
1803 } else if (strcmp(module->name, "tcp") == 0) {
1804 /* Handle old names for TCP preferences. */
1805 if (strcmp(dotp, "tcp_summary_in_tree") == 0)
1806 pref = find_preference(module, "summary_in_tree");
1807 else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
1808 pref = find_preference(module, "analyze_sequence_numbers");
1809 else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
1810 pref = find_preference(module, "relative_sequence_numbers");
1811 } else if (strcmp(module->name, "udp") == 0) {
1812 /* Handle old names for UDP preferences. */
1813 if (strcmp(dotp, "udp_summary_in_tree") == 0)
1814 pref = find_preference(module, "summary_in_tree");
1815 } else if (strcmp(module->name, "ndps") == 0) {
1816 /* Handle old names for NDPS preferences. */
1817 if (strcmp(dotp, "desegment_ndps") == 0)
1818 pref = find_preference(module, "desegment_tcp");
1822 return PREFS_SET_NO_SUCH_PREF; /* no such preference */
1824 switch (pref->type) {
1827 uval = strtoul(value, &p, pref->info.base);
1828 if (p == value || *p != '\0')
1829 return PREFS_SET_SYNTAX_ERR; /* number was bad */
1830 if (*pref->varp.uint != uval) {
1831 module->prefs_changed = TRUE;
1832 *pref->varp.uint = uval;
1837 /* XXX - give an error if it's neither "true" nor "false"? */
1838 if (strcasecmp(value, "true") == 0)
1842 if (*pref->varp.boolp != bval) {
1843 module->prefs_changed = TRUE;
1844 *pref->varp.boolp = bval;
1849 /* XXX - give an error if it doesn't match? */
1850 enum_val = find_val_for_string(value,
1851 pref->info.enum_info.enumvals, 1);
1852 if (*pref->varp.enump != enum_val) {
1853 module->prefs_changed = TRUE;
1854 *pref->varp.enump = enum_val;
1859 if (strcmp(*pref->varp.string, value) != 0) {
1860 module->prefs_changed = TRUE;
1861 g_free(*pref->varp.string);
1862 *pref->varp.string = g_strdup(value);
1867 return PREFS_SET_OBSOLETE; /* no such preference any more */
1871 return PREFS_SET_OK;
1880 * Write out a single preference.
1883 write_pref(gpointer data, gpointer user_data)
1885 pref_t *pref = data;
1886 write_pref_arg_t *arg = user_data;
1887 const enum_val_t *enum_valp;
1888 const char *val_string;
1890 if (pref->type == PREF_OBSOLETE) {
1892 * This preference is no longer supported; it's not a
1893 * real preference, so we don't write it out (i.e., we
1894 * treat it as if it weren't found in the list of
1895 * preferences, and we weren't called in the first place).
1900 fprintf(arg->pf, "\n# %s\n", pref->description);
1902 switch (pref->type) {
1905 switch (pref->info.base) {
1908 fprintf(arg->pf, "# A decimal number.\n");
1909 fprintf(arg->pf, "%s.%s: %u\n", arg->module->name,
1910 pref->name, *pref->varp.uint);
1914 fprintf(arg->pf, "# An octal number.\n");
1915 fprintf(arg->pf, "%s.%s: %#o\n", arg->module->name,
1916 pref->name, *pref->varp.uint);
1920 fprintf(arg->pf, "# A hexadecimal number.\n");
1921 fprintf(arg->pf, "%s.%s: %#x\n", arg->module->name,
1922 pref->name, *pref->varp.uint);
1928 fprintf(arg->pf, "# TRUE or FALSE (case-insensitive).\n");
1929 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
1930 *pref->varp.boolp ? "TRUE" : "FALSE");
1934 fprintf(arg->pf, "# One of: ");
1935 enum_valp = pref->info.enum_info.enumvals;
1937 while (enum_valp->name != NULL) {
1938 if (enum_valp->value == *pref->varp.enump)
1939 val_string = enum_valp->name;
1940 fprintf(arg->pf, "%s", enum_valp->name);
1942 if (enum_valp->name == NULL)
1943 fprintf(arg->pf, "\n");
1945 fprintf(arg->pf, ", ");
1947 fprintf(arg->pf, "# (case-insensitive).\n");
1948 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
1953 fprintf(arg->pf, "# A string.\n");
1954 fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
1955 *pref->varp.string);
1959 g_assert_not_reached();
1965 write_module_prefs(gpointer data, gpointer user_data)
1967 write_pref_arg_t arg;
1971 g_list_foreach(arg.module->prefs, write_pref, &arg);
1974 /* Write out "prefs" to the user's preferences file, and return 0.
1976 If we got an error, stuff a pointer to the path of the preferences file
1977 into "*pf_path_return", and return the errno. */
1979 write_prefs(char **pf_path_return)
1987 * - Split output lines longer than MAX_VAL_LEN
1988 * - Create a function for the preference directory check/creation
1989 * so that duplication can be avoided with filter.c
1992 pf_path = get_persconffile_path(PF_NAME, TRUE);
1993 if ((pf = fopen(pf_path, "w")) == NULL) {
1994 *pf_path_return = pf_path;
1998 fputs("# Configuration file for Ethereal " VERSION ".\n"
2000 "# This file is regenerated each time preferences are saved within\n"
2001 "# Ethereal. Making manual changes should be safe, however.\n"
2003 "######## Printing ########\n", pf);
2005 fprintf (pf, "\n# Can be one of \"text\" or \"postscript\".\n"
2006 "print.format: %s\n", pr_formats[prefs.pr_format]);
2008 fprintf (pf, "\n# Can be one of \"command\" or \"file\".\n"
2009 "print.destination: %s\n", pr_dests[prefs.pr_dest]);
2011 fprintf (pf, "\n# This is the file that gets written to when the "
2012 "destination is set to \"file\"\n"
2013 "%s: %s\n", PRS_PRINT_FILE, prefs.pr_file);
2015 fprintf (pf, "\n# Output gets piped to this command when the destination "
2016 "is set to \"command\"\n"
2017 "%s: %s\n", PRS_PRINT_CMD, prefs.pr_cmd);
2019 fprintf (pf, "\n######## Columns ########\n");
2021 clp = prefs.col_list;
2024 cfmt = (fmt_data *) clp->data;
2025 col_l = g_list_append(col_l, cfmt->title);
2026 col_l = g_list_append(col_l, cfmt->fmt);
2029 fprintf (pf, "\n# Packet list column format.\n");
2030 fprintf (pf, "# Each pair of strings consists of a column title and its format.\n");
2031 fprintf (pf, "%s: %s\n", PRS_COL_FMT, put_string_list(col_l));
2032 /* This frees the list of strings, but not the strings to which it
2033 refers; that's what we want, as we haven't copied those strings,
2034 we just referred to them. */
2037 fprintf (pf, "\n######## TCP Stream Window ########\n");
2039 fprintf (pf, "\n# TCP stream window color preferences.\n");
2040 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2041 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_FG,
2042 (prefs.st_client_fg.red * 255 / 65535),
2043 (prefs.st_client_fg.green * 255 / 65535),
2044 (prefs.st_client_fg.blue * 255 / 65535));
2045 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_CL_BG,
2046 (prefs.st_client_bg.red * 255 / 65535),
2047 (prefs.st_client_bg.green * 255 / 65535),
2048 (prefs.st_client_bg.blue * 255 / 65535));
2049 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_FG,
2050 (prefs.st_server_fg.red * 255 / 65535),
2051 (prefs.st_server_fg.green * 255 / 65535),
2052 (prefs.st_server_fg.blue * 255 / 65535));
2053 fprintf (pf, "%s: %02x%02x%02x\n", PRS_STREAM_SR_BG,
2054 (prefs.st_server_bg.red * 255 / 65535),
2055 (prefs.st_server_bg.green * 255 / 65535),
2056 (prefs.st_server_bg.blue * 255 / 65535));
2058 fprintf (pf, "\n######## User Interface ########\n");
2060 fprintf(pf, "\n# Vertical scrollbars should be on right side?\n");
2061 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2062 fprintf(pf, PRS_GUI_SCROLLBAR_ON_RIGHT ": %s\n",
2063 prefs.gui_scrollbar_on_right == TRUE ? "TRUE" : "FALSE");
2065 fprintf(pf, "\n# Packet-list selection bar can be used to browse w/o selecting?\n");
2066 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2067 fprintf(pf, PRS_GUI_PLIST_SEL_BROWSE ": %s\n",
2068 prefs.gui_plist_sel_browse == TRUE ? "TRUE" : "FALSE");
2070 fprintf(pf, "\n# Protocol-tree selection bar can be used to browse w/o selecting?\n");
2071 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2072 fprintf(pf, PRS_GUI_PTREE_SEL_BROWSE ": %s\n",
2073 prefs.gui_ptree_sel_browse == TRUE ? "TRUE" : "FALSE");
2075 fprintf(pf, "\n# Alternating colors in TreeViews?\n");
2076 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2077 fprintf(pf, PRS_GUI_ALTERN_COLORS ": %s\n",
2078 prefs.gui_altern_colors == TRUE ? "TRUE" : "FALSE");
2080 fprintf(pf, "\n# Protocol-tree line style.\n");
2081 fprintf(pf, "# One of: NONE, SOLID, DOTTED, TABBED\n");
2082 fprintf(pf, PRS_GUI_PTREE_LINE_STYLE ": %s\n",
2083 gui_ptree_line_style_text[prefs.gui_ptree_line_style]);
2085 fprintf(pf, "\n# Protocol-tree expander style.\n");
2086 fprintf(pf, "# One of: NONE, SQUARE, TRIANGLE, CIRCULAR\n");
2087 fprintf(pf, PRS_GUI_PTREE_EXPANDER_STYLE ": %s\n",
2088 gui_ptree_expander_style_text[prefs.gui_ptree_expander_style]);
2090 fprintf(pf, "\n# Hex dump highlight style.\n");
2091 fprintf(pf, "# One of: BOLD, INVERSE\n");
2092 fprintf(pf, PRS_GUI_HEX_DUMP_HIGHLIGHT_STYLE ": %s\n",
2093 gui_hex_dump_highlight_style_text[prefs.gui_hex_dump_highlight_style]);
2095 fprintf(pf, "\n# Main Toolbar show/hide.\n");
2096 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2097 fprintf(pf, PRS_GUI_TOOLBAR_MAIN_SHOW ": %s\n",
2098 prefs.gui_toolbar_main_show == TRUE ? "TRUE" : "FALSE");
2100 fprintf(pf, "\n# Main Toolbar style.\n");
2101 fprintf(pf, "# One of: ICONS, TEXT, BOTH\n");
2102 fprintf(pf, PRS_GUI_TOOLBAR_MAIN_STYLE ": %s\n",
2103 gui_toolbar_style_text[prefs.gui_toolbar_main_style]);
2105 fprintf(pf, "\n# Font name for packet list, protocol tree, and hex dump panes.\n");
2106 fprintf(pf, PRS_GUI_FONT_NAME ": %s\n", prefs.gui_font_name);
2108 fprintf (pf, "\n# Color preferences for a marked frame.\n");
2109 fprintf (pf, "# Each value is a six digit hexadecimal color value in the form rrggbb.\n");
2110 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_FG,
2111 (prefs.gui_marked_fg.red * 255 / 65535),
2112 (prefs.gui_marked_fg.green * 255 / 65535),
2113 (prefs.gui_marked_fg.blue * 255 / 65535));
2114 fprintf (pf, "%s: %02x%02x%02x\n", PRS_GUI_MARKED_BG,
2115 (prefs.gui_marked_bg.red * 255 / 65535),
2116 (prefs.gui_marked_bg.green * 255 / 65535),
2117 (prefs.gui_marked_bg.blue * 255 / 65535));
2119 fprintf(pf, "\n# Save window position at exit?\n");
2120 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2121 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_POSITION ": %s\n",
2122 prefs.gui_geometry_save_position == TRUE ? "TRUE" : "FALSE");
2124 fprintf(pf, "\n# Save window size at exit?\n");
2125 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2126 fprintf(pf, PRS_GUI_GEOMETRY_SAVE_SIZE ": %s\n",
2127 prefs.gui_geometry_save_size == TRUE ? "TRUE" : "FALSE");
2129 fprintf(pf, "\n# Where to start the File Open dialog box.\n");
2130 fprintf(pf, "# One of: LAST_OPENED, SPECIFIED\n");
2131 fprintf (pf, PRS_GUI_FILEOPEN_STYLE ": %s\n",
2132 gui_fileopen_style_text[prefs.gui_fileopen_style]);
2134 if (prefs.gui_fileopen_dir != NULL) {
2135 fprintf(pf, "\n# Directory to start in when opening File Open dialog.\n");
2136 fprintf(pf, PRS_GUI_FILEOPEN_DIR ": %s\n",
2137 prefs.gui_fileopen_dir);
2140 if (prefs.gui_fileopen_remembered_dir != NULL) {
2141 fprintf(pf, "\n# Last directory navigated to in File Open dialog.\n");
2142 fprintf(pf, PRS_GUI_FILEOPEN_REMEMBERED_DIR ": %s\n",
2143 prefs.gui_fileopen_remembered_dir);
2146 fprintf(pf, "\n# Main window geometry.\n");
2147 fprintf(pf, "# Decimal integers.\n");
2148 fprintf(pf, PRS_GUI_GEOMETRY_MAIN_X ": %d\n", prefs.gui_geometry_main_x);
2149 fprintf(pf, PRS_GUI_GEOMETRY_MAIN_Y ": %d\n", prefs.gui_geometry_main_y);
2150 fprintf(pf, PRS_GUI_GEOMETRY_MAIN_WIDTH ": %d\n",
2151 prefs.gui_geometry_main_width);
2152 fprintf(pf, PRS_GUI_GEOMETRY_MAIN_HEIGHT ": %d\n",
2153 prefs.gui_geometry_main_height);
2155 fprintf(pf, "\n####### Name Resolution ########\n");
2157 fprintf(pf, "\n# Resolve addresses to names?\n");
2158 fprintf(pf, "# TRUE or FALSE (case-insensitive), or a list of address types to resolve.\n");
2159 fprintf(pf, PRS_NAME_RESOLVE ": %s\n",
2160 name_resolve_to_string(prefs.name_resolve));
2162 fprintf(pf, "\n# Name resolution concurrency.\n");
2163 fprintf(pf, "# A decimal number.\n");
2164 fprintf(pf, PRS_NAME_RESOLVE_CONCURRENCY ": %d\n",
2165 prefs.name_resolve_concurrency);
2167 /* write the capture options */
2168 fprintf(pf, "\n####### Capture Options ########\n");
2170 if (prefs.capture_device != NULL) {
2171 fprintf(pf, "\n# Default capture device\n");
2172 fprintf(pf, PRS_CAP_DEVICE ": %s\n", prefs.capture_device);
2175 if (prefs.capture_devices_descr != NULL) {
2176 fprintf(pf, "\n# Interface descriptions.\n");
2177 fprintf(pf, "# Ex: eth0(eth0 descr),eth1(eth1 descr),...\n");
2178 fprintf(pf, PRS_CAP_DEVICES_DESCR ": %s\n", prefs.capture_devices_descr);
2181 if (prefs.capture_devices_hide != NULL) {
2182 fprintf(pf, "\n# Hide interface?\n");
2183 fprintf(pf, "# Ex: eth0,eth3,...\n");
2184 fprintf(pf, PRS_CAP_DEVICES_HIDE ": %s\n", prefs.capture_devices_hide);
2187 fprintf(pf, "\n# Capture in promiscuous mode?\n");
2188 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2189 fprintf(pf, PRS_CAP_PROM_MODE ": %s\n",
2190 prefs.capture_prom_mode == TRUE ? "TRUE" : "FALSE");
2192 fprintf(pf, "\n# Update packet list in real time during capture?\n");
2193 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2194 fprintf(pf, PRS_CAP_REAL_TIME ": %s\n",
2195 prefs.capture_real_time == TRUE ? "TRUE" : "FALSE");
2197 fprintf(pf, "\n# Scroll packet list during capture?\n");
2198 fprintf(pf, "# TRUE or FALSE (case-insensitive).\n");
2199 fprintf(pf, PRS_CAP_AUTO_SCROLL ": %s\n",
2200 prefs.capture_auto_scroll == TRUE ? "TRUE" : "FALSE");
2202 g_list_foreach(modules, write_module_prefs, pf);
2206 /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
2207 an error indication, or maybe write to a new preferences file and
2208 rename that file on top of the old one only if there are not I/O
2213 /* Copy a set of preferences. */
2215 copy_prefs(e_prefs *dest, e_prefs *src)
2217 fmt_data *src_cfmt, *dest_cfmt;
2220 dest->pr_format = src->pr_format;
2221 dest->pr_dest = src->pr_dest;
2222 dest->pr_file = g_strdup(src->pr_file);
2223 dest->pr_cmd = g_strdup(src->pr_cmd);
2224 dest->col_list = NULL;
2225 for (entry = src->col_list; entry != NULL; entry = g_list_next(entry)) {
2226 src_cfmt = entry->data;
2227 dest_cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
2228 dest_cfmt->title = g_strdup(src_cfmt->title);
2229 dest_cfmt->fmt = g_strdup(src_cfmt->fmt);
2230 dest->col_list = g_list_append(dest->col_list, dest_cfmt);
2232 dest->num_cols = src->num_cols;
2233 dest->st_client_fg = src->st_client_fg;
2234 dest->st_client_bg = src->st_client_bg;
2235 dest->st_server_fg = src->st_server_fg;
2236 dest->st_server_bg = src->st_server_bg;
2237 dest->gui_scrollbar_on_right = src->gui_scrollbar_on_right;
2238 dest->gui_plist_sel_browse = src->gui_plist_sel_browse;
2239 dest->gui_ptree_sel_browse = src->gui_ptree_sel_browse;
2240 dest->gui_altern_colors = src->gui_altern_colors;
2241 dest->gui_ptree_line_style = src->gui_ptree_line_style;
2242 dest->gui_ptree_expander_style = src->gui_ptree_expander_style;
2243 dest->gui_hex_dump_highlight_style = src->gui_hex_dump_highlight_style;
2244 dest->gui_toolbar_main_show = src->gui_toolbar_main_show;
2245 dest->gui_toolbar_main_style = src->gui_toolbar_main_style;
2246 dest->gui_fileopen_dir = g_strdup(src->gui_fileopen_dir);
2247 dest->gui_fileopen_remembered_dir = g_strdup(src->gui_fileopen_remembered_dir);
2248 dest->gui_fileopen_style = src->gui_fileopen_style;
2249 dest->gui_font_name = g_strdup(src->gui_font_name);
2250 dest->gui_marked_fg = src->gui_marked_fg;
2251 dest->gui_marked_bg = src->gui_marked_bg;
2252 dest->gui_geometry_save_position = src->gui_geometry_save_position;
2253 dest->gui_geometry_save_size = src->gui_geometry_save_size;
2254 dest->gui_geometry_main_x = src->gui_geometry_main_x;
2255 dest->gui_geometry_main_y = src->gui_geometry_main_y;
2256 dest->gui_geometry_main_width = src->gui_geometry_main_width;
2257 dest->gui_geometry_main_height = src->gui_geometry_main_height;
2258 /* values for the capture dialog box */
2259 dest->capture_device = g_strdup(src->capture_device);
2260 dest->capture_devices_descr = g_strdup(src->capture_devices_descr);
2261 dest->capture_devices_hide = g_strdup(src->capture_devices_hide);
2262 dest->capture_prom_mode = src->capture_prom_mode;
2263 dest->capture_real_time = src->capture_real_time;
2264 dest->capture_auto_scroll = src->capture_auto_scroll;
2265 dest->name_resolve = src->name_resolve;
2266 dest->name_resolve_concurrency = src->name_resolve_concurrency;
2270 /* Free a set of preferences. */
2272 free_prefs(e_prefs *pr)
2274 if (pr->pr_file != NULL) {
2275 g_free(pr->pr_file);
2278 if (pr->pr_cmd != NULL) {
2283 if (pr->gui_font_name != NULL) {
2284 g_free(pr->gui_font_name);
2285 pr->gui_font_name = NULL;
2287 if (pr->gui_fileopen_dir != NULL) {
2288 g_free(pr->gui_fileopen_dir);
2289 pr->gui_fileopen_dir = NULL;
2291 if (pr->gui_fileopen_remembered_dir != NULL) {
2292 g_free(pr->gui_fileopen_remembered_dir);
2293 pr->gui_fileopen_remembered_dir = NULL;
2295 if (pr->capture_device != NULL) {
2296 g_free(pr->capture_device);
2297 pr->capture_device = NULL;
2299 if (pr->capture_devices_descr != NULL) {
2300 g_free(pr->capture_devices_descr);
2301 pr->capture_devices_descr = NULL;
2303 if (pr->capture_devices_hide != NULL) {
2304 g_free(pr->capture_devices_hide);
2305 pr->capture_devices_hide = NULL;
2310 free_col_info(e_prefs *pr)
2314 while (pr->col_list != NULL) {
2315 cfmt = pr->col_list->data;
2316 g_free(cfmt->title);
2319 pr->col_list = g_list_remove_link(pr->col_list, pr->col_list);
2321 g_list_free(pr->col_list);
2322 pr->col_list = NULL;