Trim leading and trailing white space from the capture device in the
[obnox/wireshark/wip.git] / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id: prefs.h,v 1.38 2002/05/11 18:58:02 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  * 
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.
14  * 
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.
19  * 
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.
23  */
24
25 #ifndef __PREFS_H__
26 #define __PREFS_H__
27
28 #include <glib.h>
29
30 #include "color.h"
31
32 #define PR_DEST_CMD  0
33 #define PR_DEST_FILE 1
34
35 #define DEF_WIDTH 750
36 #define DEF_HEIGHT 550
37
38 /*
39  * Convert a string listing name resolution types to a bitmask of
40  * those types.
41  *
42  * Set "*name_resolve" to the bitmask, and return '\0', on success;
43  * return the bad character in the string on error.
44  */
45 char string_to_name_resolve(char *string, guint32 *name_resolve);
46
47 typedef struct _e_prefs {
48   gint     pr_format;
49   gint     pr_dest;
50   gchar   *pr_file;
51   gchar   *pr_cmd;
52   GList   *col_list;
53   gint     num_cols;
54   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
55   gboolean gui_scrollbar_on_right;
56   gboolean gui_plist_sel_browse;
57   gboolean gui_ptree_sel_browse;
58   gint     gui_ptree_line_style;
59   gint     gui_ptree_expander_style;
60   gboolean gui_hex_dump_highlight_style;
61   gchar   *gui_font_name;
62   color_t  gui_marked_fg;
63   color_t  gui_marked_bg;
64   gboolean gui_geometry_save_position;
65   gboolean gui_geometry_save_size;
66   gint     gui_geometry_main_x;
67   gint     gui_geometry_main_y;
68   gint     gui_geometry_main_width;
69   gint     gui_geometry_main_height;
70   guint32  name_resolve;
71   gchar   *capture_device;
72   gboolean capture_prom_mode;
73   gboolean capture_real_time;
74   gboolean capture_auto_scroll;
75 } e_prefs;
76
77 extern e_prefs prefs;
78
79 /*
80  * Routines to let modules that have preference settings register
81  * themselves by name, and to let them register preference settings
82  * by name.
83  */
84 struct pref_module;
85
86 typedef struct pref_module module_t;
87
88 /*
89  * Register a module that will have preferences.
90  * Specify the name used for the module in the preferences file, the
91  * title used in the tab for it in a preferences dialog box, and a
92  * routine to call back when we apply the preferences.
93  * Note:
94  * In case of dissectors, the specified name should be the protocol
95  * name specified at the proto_register_protocol() call in order to
96  * make the "Protocol Properties..." menu item work.
97  */
98 extern module_t *prefs_register_module(const char *name, const char *title,
99     void (*apply_cb)(void));
100
101 typedef void (*module_cb)(module_t *module, gpointer user_data);
102
103 /*
104  * Register that a protocol has preferences.
105  */
106 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
107
108 /*
109  * Register that a protocol used to have preferences but no longer does,
110  * by creating an "obsolete" module for it.
111  */
112 extern module_t *prefs_register_protocol_obsolete(int id);
113
114 /*
115  * Call a callback function, with a specified argument, for each module.
116  * Ignores "obsolete" modules; their sole purpose is to allow old
117  * preferences for dissectors that no longer have preferences to be
118  * silently ignored in preference files.
119  */
120 extern void prefs_module_foreach(module_cb callback, gpointer user_data);
121
122 /*
123  * Call the "apply" callback function for each module if any of its
124  * preferences have changed, and then clear the flag saying its
125  * preferences have changed, as the module has been notified of that
126  * fact.
127  */
128 extern void prefs_apply_all(void);
129
130 struct preference;
131
132 typedef struct preference pref_t;
133
134 /*
135  * Returns TRUE if the given protocol has registered preferences.
136  */
137 extern gboolean prefs_is_registered_protocol(char *name);
138
139 /*
140  * Returns the module title of a registered protocol (or NULL if unknown).
141  */
142 extern const char *prefs_get_title_by_name(char *name);
143
144 /*
145  * Register a preference with an unsigned integral value.
146  */
147 extern void prefs_register_uint_preference(module_t *module, const char *name,
148     const char *title, const char *description, guint base, guint *var);
149
150 /*
151  * Register a preference with an Boolean value.
152  */
153 extern void prefs_register_bool_preference(module_t *module, const char *name,
154     const char *title, const char *description, gboolean *var);
155
156 /*
157  * Register a preference with an enumerated value.
158  */
159 typedef struct {
160         char    *name;
161         gint    value;
162 } enum_val_t;
163
164 extern void prefs_register_enum_preference(module_t *module, const char *name,
165     const char *title, const char *description, gint *var,
166     const enum_val_t *enumvals, gboolean radio_buttons);
167
168 /*
169  * Register a preference with a character-string value.
170  */
171 extern void prefs_register_string_preference(module_t *module, const char *name,
172     const char *title, const char *description, char **var);
173
174 /*
175  * Register a preference that used to be supported but no longer is.
176  */
177 extern void prefs_register_obsolete_preference(module_t *module,
178     const char *name);
179
180 typedef void (*pref_cb)(pref_t *pref, gpointer user_data);
181
182 /*
183  * Call a callback function, with a specified argument, for each preference
184  * in a given module.
185  */
186 extern void prefs_pref_foreach(module_t *module, pref_cb callback,
187     gpointer user_data);
188
189 /*
190  * Register all non-dissector modules' preferences.
191  */
192 extern void prefs_register_modules(void);
193
194 /* Read the preferences file, fill in "prefs", and return a pointer to it.
195
196    If we got an error (other than "it doesn't exist") trying to read
197    the global preferences file, stuff the errno into "*gpf_errno_return"
198    and a pointer to the path of the file into "*gpf_path_return", and
199    return NULL.
200
201    If we got an error (other than "it doesn't exist") trying to read
202    the user's preferences file, stuff the errno into "*pf_errno_return"
203    and a pointer to the path of the file into "*pf_path_return", and
204    return NULL. */
205 extern e_prefs *read_prefs(int *, char **, int *, const char **);
206
207 /* Write out "prefs" to the user's preferences file, and return 0.
208
209    If we got an error, stuff a pointer to the path of the preferences file
210    into "*pf_path_return", and return the errno. */
211 extern int write_prefs(const char **);
212
213 /* Copy a set of preferences. */
214 extern void copy_prefs(e_prefs *dest, e_prefs *src);
215
216 /* Free a set of preferences. */
217 extern void free_prefs(e_prefs *pr);
218
219 /*
220  * Given a string of the form "<pref name>:<pref value>", as might appear
221  * as an argument to a "-o" option, parse it and set the preference in
222  * question.  Return an indication of whether it succeeded or failed
223  * in some fashion.
224  *
225  * XXX - should supply, for syntax errors, a detailed explanation of
226  * the syntax error.
227  */
228 #define PREFS_SET_OK            0       /* succeeded */
229 #define PREFS_SET_SYNTAX_ERR    1       /* syntax error in string */
230 #define PREFS_SET_NO_SUCH_PREF  2       /* no such preference */
231 #define PREFS_SET_OBSOLETE      3       /* preference used to exist but no longer does */
232
233 extern int prefs_set_pref(char *prefarg);
234
235 #endif /* prefs.h */