Also add the new dissectors
[obnox/wireshark/wip.git] / epan / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id$
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 #include <epan/range.h>
33
34 #define PR_DEST_CMD  0
35 #define PR_DEST_FILE 1
36
37 #define DEF_WIDTH 750
38 #define DEF_HEIGHT 550
39
40 #define MAX_VAL_LEN  1024
41
42 /* only GTK1 *or* GTK2 font_name should be used */
43 #if GTK_MAJOR_VERSION < 2
44 #define PREFS_GUI_FONT_NAME gui_font_name1
45 #else
46 #define PREFS_GUI_FONT_NAME gui_font_name2
47 #endif
48
49 /*
50  * Convert a string listing name resolution types to a bitmask of
51  * those types.
52  *
53  * Set "*name_resolve" to the bitmask, and return '\0', on success;
54  * return the bad character in the string on error.
55  */
56 char string_to_name_resolve(char *string, guint32 *name_resolve);
57
58 /*
59  * Modes for the starting directory in File Open dialogs.
60  */
61 #define FO_STYLE_LAST_OPENED    0       /* start in last directory we looked at */
62 #define FO_STYLE_SPECIFIED      1       /* start in specified directory */
63
64 /*
65  * Toolbar styles.
66  */
67 #define TB_STYLE_ICONS          0
68 #define TB_STYLE_TEXT           1
69 #define TB_STYLE_BOTH           2
70
71 /*
72  * Types of layout of summary/details/hex panes.
73  */
74 typedef enum {
75     layout_unused,  /* entry currently unused */
76     layout_type_5,
77     layout_type_2,
78     layout_type_1,
79     layout_type_4,
80     layout_type_3,
81     layout_type_6,
82     layout_type_max
83 } layout_type_e;
84
85 /*
86  * Types of pane.
87  */
88 typedef enum {
89     layout_pane_content_none,
90     layout_pane_content_plist,
91     layout_pane_content_pdetails,
92     layout_pane_content_pbytes
93 } layout_pane_content_e;
94
95 /*
96  * open console behaviour (win32 only)
97  */
98 typedef enum {
99     console_open_never,
100     console_open_auto,
101     console_open_always
102 } console_open_e;
103
104
105 typedef struct _e_prefs {
106   gint     pr_format;
107   gint     pr_dest;
108   gchar   *pr_file;
109   gchar   *pr_cmd;
110   GList   *col_list;
111   gint     num_cols;
112   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
113   gboolean gui_scrollbar_on_right;
114   gboolean gui_plist_sel_browse;
115   gboolean gui_ptree_sel_browse;
116   gboolean gui_altern_colors;
117   gboolean filter_toolbar_show_in_statusbar;
118   gint     gui_ptree_line_style;
119   gint     gui_ptree_expander_style;
120   gboolean gui_hex_dump_highlight_style;
121   gint     gui_toolbar_main_style;
122   gchar   *gui_font_name1;
123   gchar   *gui_font_name2;
124   color_t  gui_marked_fg;
125   color_t  gui_marked_bg;
126   gboolean gui_geometry_save_position;
127   gboolean gui_geometry_save_size;
128   gboolean gui_geometry_save_maximized;
129   console_open_e gui_console_open;
130   guint    gui_recent_files_count_max;
131   guint    gui_fileopen_style;
132   gchar    *gui_fileopen_dir;
133   guint    gui_fileopen_preview;
134   gboolean gui_ask_unsaved;
135   gboolean gui_find_wrap;
136   gchar   *gui_webbrowser;
137   gchar   *gui_window_title;
138   layout_type_e gui_layout_type;
139   layout_pane_content_e gui_layout_content_1;
140   layout_pane_content_e gui_layout_content_2;
141   layout_pane_content_e gui_layout_content_3;
142   gint     console_log_level;
143   guint32  name_resolve;
144   gint     name_resolve_concurrency;
145   gchar   *capture_device;
146   gchar   *capture_devices_descr;
147   gchar   *capture_devices_hide;
148   gboolean capture_prom_mode;
149   gboolean capture_real_time;
150   gboolean capture_auto_scroll;
151   gboolean capture_show_info;
152 } e_prefs;
153
154 ETH_VAR_IMPORT e_prefs prefs;
155
156 /*
157  * Routines to let modules that have preference settings register
158  * themselves by name, and to let them register preference settings
159  * by name.
160  */
161 struct pref_module;
162
163 typedef struct pref_module module_t;
164
165 /*
166  * Register a module that will have preferences.
167  * Specify the module under which to register it or NULL to register it
168  * at the top level, the name used for the module in the preferences file,
169  * the title used in the tab for it in a preferences dialog box, and a
170  * routine to call back when we apply the preferences.
171  *
172  * This should not be used for dissector preferences;
173  * "prefs_register_protocol()" should be used for that, so that the
174  * preferences go under the "Protocols" subtree, and so that the
175  * name is the protocol name specified at the "proto_register_protocol()"
176  * call so that the "Protocol Properties..." menu item works.
177  */
178 extern module_t *prefs_register_module(module_t *parent, const char *name,
179     const char *title, void (*apply_cb)(void));
180
181 /*
182  * Register a subtree that will have modules under it.
183  * Specify the module under which to register it or NULL to register it
184  * at the top level and the title used in the tab for it in a preferences
185  * dialog box.
186  */
187 extern module_t *prefs_register_subtree(module_t *parent, const char *title);
188
189 /*
190  * Register that a protocol has preferences.
191  */
192 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
193
194 /*
195  * Register that a protocol used to have preferences but no longer does,
196  * by creating an "obsolete" module for it.
197  */
198 extern module_t *prefs_register_protocol_obsolete(int id);
199
200 /*
201  * Callback function for module list scanners.
202  */
203 typedef guint (*module_cb)(module_t *module, gpointer user_data);
204
205 /*
206  * Call a callback function, with a specified argument, for each module
207  * in a list of modules.  If the list is NULL, searches the top-level
208  * list in the display tree of modules.
209  *
210  * Ignores "obsolete" modules; their sole purpose is to allow old
211  * preferences for dissectors that no longer have preferences to be
212  * silently ignored in preference files.  Does not ignore subtrees,
213  * as this can be used when walking the display tree of modules.
214  */
215 extern guint prefs_module_list_foreach(GList *module_list, module_cb callback,
216     gpointer user_data);
217
218 /*
219  * Call a callback function, with a specified argument, for each module
220  * in the list of all modules.  (This list does not include subtrees.)
221  *
222  * Ignores "obsolete" modules; their sole purpose is to allow old
223  * preferences for dissectors that no longer have preferences to be
224  * silently ignored in preference files.
225  */
226 extern guint prefs_modules_foreach(module_cb callback, gpointer user_data);
227
228 /*
229  * Call the "apply" callback function for each module if any of its
230  * preferences have changed, and then clear the flag saying its
231  * preferences have changed, as the module has been notified of that
232  * fact.
233  */
234 extern void prefs_apply_all(void);
235
236 struct preference;
237
238 typedef struct preference pref_t;
239
240 /*
241  * Returns TRUE if the given protocol has registered preferences.
242  */
243 extern gboolean prefs_is_registered_protocol(const char *name);
244
245 /*
246  * Returns the module title of a registered protocol (or NULL if unknown).
247  */
248 extern const char *prefs_get_title_by_name(const char *name);
249
250 /*
251  * Register a preference with an unsigned integral value.
252  */
253 extern void prefs_register_uint_preference(module_t *module, const char *name,
254     const char *title, const char *description, guint base, guint *var);
255
256 /*
257  * Register a preference with an Boolean value.
258  */
259 extern void prefs_register_bool_preference(module_t *module, const char *name,
260     const char *title, const char *description, gboolean *var);
261
262 /*
263  * Register a preference with an enumerated value.
264  */
265 typedef struct {
266         const char      *name;
267         const char      *description;
268         gint            value;
269 } enum_val_t;
270
271 extern void prefs_register_enum_preference(module_t *module, const char *name,
272     const char *title, const char *description, gint *var,
273     const enum_val_t *enumvals, gboolean radio_buttons);
274
275 /*
276  * Register a preference with a character-string value.
277  */
278 extern void prefs_register_string_preference(module_t *module, const char *name,
279     const char *title, const char *description, const char **var);
280
281 /*
282  * Register a preference with a ranged value.
283  */
284 extern void prefs_register_range_preference(module_t *module, const char *name,
285     const char *title, const char *description, range_t **var,
286     guint32 max_value);
287
288 /*
289  * Register a preference that used to be supported but no longer is.
290  */
291 extern void prefs_register_obsolete_preference(module_t *module,
292     const char *name);
293
294 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
295
296 /*
297  * Call a callback function, with a specified argument, for each preference
298  * in a given module.
299  *
300  * If any of the callbacks return a non-zero value, stop and return that
301  * value, otherwise return 0.
302  */
303 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
304     gpointer user_data);
305
306 /*
307  * Register all non-dissector modules' preferences.
308  */
309 extern void prefs_register_modules(void);
310
311 /* Read the preferences file, fill in "prefs", and return a pointer to it.
312
313    If we got an error (other than "it doesn't exist") trying to read
314    the global preferences file, stuff the errno into "*gpf_errno_return"
315    on an open error and into "*gpf_read_errno_return" on a read error,
316    stuff a pointer to the path of the file into "*gpf_path_return", and
317    return NULL.
318
319    If we got an error (other than "it doesn't exist") trying to read
320    the user's preferences file, stuff the errno into "*pf_errno_return"
321    on an open error and into "*pf_read_errno_return" on a read error,
322    stuff a pointer to the path of the file into "*pf_path_return", and
323    return NULL. */
324 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
325
326 /* Write out "prefs" to the user's preferences file, and return 0.
327
328    If we got an error, stuff a pointer to the path of the preferences file
329    into "*pf_path_return", and return the errno. */
330 extern int write_prefs(char **);
331
332 /* Copy a set of preferences. */
333 extern void copy_prefs(e_prefs *dest, e_prefs *src);
334
335 /* Free a set of preferences. */
336 extern void free_prefs(e_prefs *pr);
337
338 /*
339  * Given a string of the form "<pref name>:<pref value>", as might appear
340  * as an argument to a "-o" option, parse it and set the preference in
341  * question.  Return an indication of whether it succeeded or failed
342  * in some fashion.
343  *
344  * XXX - should supply, for syntax errors, a detailed explanation of
345  * the syntax error.
346  */
347 #define PREFS_SET_OK            0       /* succeeded */
348 #define PREFS_SET_SYNTAX_ERR    1       /* syntax error in string */
349 #define PREFS_SET_NO_SUCH_PREF  2       /* no such preference */
350 #define PREFS_SET_OBSOLETE      3       /* preference used to exist but no longer does */
351
352 extern int prefs_set_pref(char *prefarg);
353
354 #endif /* prefs.h */