From Tom Brezinski:
[obnox/wireshark/wip.git] / epan / prefs.h
1 /* prefs.h
2  * Definitions for preference handling routines
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <glib.h>
33
34 #include "color.h"
35
36 #include <epan/params.h>
37 #include <epan/range.h>
38
39 #define PR_DEST_CMD  0
40 #define PR_DEST_FILE 1
41
42 #define DEF_WIDTH 750
43 #define DEF_HEIGHT 550
44
45 #define MAX_VAL_LEN  1024
46
47 #define RTP_PLAYER_DEFAULT_VISIBLE 4
48 #define TAP_UPDATE_DEFAULT_INTERVAL 3000
49
50 /*
51  * Convert a string listing name resolution types to a bitmask of
52  * those types.
53  *
54  * Set "*name_resolve" to the bitmask, and return '\0', on success;
55  * return the bad character in the string on error.
56  */
57 char string_to_name_resolve(char *string, guint32 *name_resolve);
58
59 /*
60  * Modes for the starting directory in File Open dialogs.
61  */
62 #define FO_STYLE_LAST_OPENED    0       /* start in last directory we looked at */
63 #define FO_STYLE_SPECIFIED      1       /* start in specified directory */
64
65 /*
66  * Toolbar styles.
67  */
68 #define TB_STYLE_ICONS          0
69 #define TB_STYLE_TEXT           1
70 #define TB_STYLE_BOTH           2
71
72 /*
73  * Types of layout of summary/details/hex panes.
74  */
75 typedef enum {
76     layout_unused,  /* entry currently unused */
77     layout_type_5,
78     layout_type_2,
79     layout_type_1,
80     layout_type_4,
81     layout_type_3,
82     layout_type_6,
83     layout_type_max
84 } layout_type_e;
85
86 /*
87  * Types of pane.
88  */
89 typedef enum {
90     layout_pane_content_none,
91     layout_pane_content_plist,
92     layout_pane_content_pdetails,
93     layout_pane_content_pbytes
94 } layout_pane_content_e;
95
96 /*
97  * open console behaviour (win32 only)
98  */
99 typedef enum {
100     console_open_never,
101     console_open_auto,
102     console_open_always
103 } console_open_e;
104
105
106 typedef struct _e_prefs {
107   gint     pr_format;
108   gint     pr_dest;
109   gchar   *pr_file;
110   gchar   *pr_cmd;
111   GList   *col_list;
112   gint     num_cols;
113   color_t  st_client_fg, st_client_bg, st_server_fg, st_server_bg;
114   gboolean gui_scrollbar_on_right;
115   gboolean gui_plist_sel_browse;
116   gboolean gui_ptree_sel_browse;
117   gboolean gui_altern_colors;
118   gboolean gui_expert_composite_eyecandy;
119   gboolean filter_toolbar_show_in_statusbar;
120   gint     gui_ptree_line_style;
121   gint     gui_ptree_expander_style;
122   gboolean gui_hex_dump_highlight_style;
123   gint     gui_toolbar_main_style;
124   gint     gui_toolbar_filter_style;
125   gchar   *gui_font_name;
126   color_t  gui_marked_fg;
127   color_t  gui_marked_bg;
128   color_t  gui_ignored_fg;
129   color_t  gui_ignored_bg;
130   gchar   *gui_colorized_fg;
131   gchar   *gui_colorized_bg;
132   gboolean gui_geometry_save_position;
133   gboolean gui_geometry_save_size;
134   gboolean gui_geometry_save_maximized;
135   gboolean gui_macosx_style;
136   console_open_e gui_console_open;
137   guint    gui_recent_df_entries_max;
138   guint    gui_recent_files_count_max;
139   guint    gui_fileopen_style;
140   gchar    *gui_fileopen_dir;
141   guint    gui_fileopen_preview;
142   gboolean gui_ask_unsaved;
143   gboolean gui_find_wrap;
144   gboolean gui_use_pref_save;
145   gchar   *gui_webbrowser;
146   gchar   *gui_window_title;
147   gchar   *gui_start_title;
148   gboolean gui_version_in_start_page;
149   gboolean gui_auto_scroll_on_expand;
150   guint    gui_auto_scroll_percentage;
151   layout_type_e gui_layout_type;
152   layout_pane_content_e gui_layout_content_1;
153   layout_pane_content_e gui_layout_content_2;
154   layout_pane_content_e gui_layout_content_3;
155   gint     console_log_level;
156   guint32  name_resolve;
157   gint     name_resolve_concurrency;
158   gboolean load_smi_modules;
159   gboolean suppress_smi_errors;
160   gchar   *capture_device;
161   gchar   *capture_devices_linktypes;
162   gchar   *capture_devices_descr;
163   gchar   *capture_devices_hide;
164   gchar   *capture_devices_monitor_mode;
165   gboolean capture_prom_mode;
166   gboolean capture_pcap_ng;
167   gboolean capture_real_time;
168   gboolean capture_auto_scroll;
169   gboolean capture_show_info;
170   guint    rtp_player_max_visible;
171   guint    tap_update_interval;
172   gboolean display_hidden_proto_items;
173   gpointer filter_expressions;  /* Actually points to &head */
174 } e_prefs;
175
176 WS_VAR_IMPORT e_prefs prefs;
177
178 /*
179  * Routines to let modules that have preference settings register
180  * themselves by name, and to let them register preference settings
181  * by name.
182  */
183 struct pref_module;
184
185 typedef struct pref_module module_t;
186
187 /** Sets up memory used by proto routines. Called at program startup */
188 extern void prefs_init(void);
189
190 /** Reset preferences to default values.  Called at profile change */
191 extern void prefs_reset(void);
192
193 /** Frees memory used by proto routines. Called at program shutdown */
194 extern void prefs_cleanup(void);
195
196 /*
197  * Register a module that will have preferences.
198  * Specify the module under which to register it or NULL to register it
199  * at the top level, the name used for the module in the preferences file,
200  * the title used in the tab for it in a preferences dialog box, and a
201  * routine to call back when we apply the preferences.
202  *
203  * This should not be used for dissector preferences;
204  * "prefs_register_protocol()" should be used for that, so that the
205  * preferences go under the "Protocols" subtree, and so that the
206  * name is the protocol name specified at the "proto_register_protocol()"
207  * call so that the "Protocol Properties..." menu item works.
208  */
209 extern module_t *prefs_register_module(module_t *parent, const char *name,
210     const char *title, const char *description, void (*apply_cb)(void));
211
212 /*
213  * Register a subtree that will have modules under it.
214  * Specify the module under which to register it or NULL to register it
215  * at the top level and the title used in the tab for it in a preferences
216  * dialog box.
217  */
218 extern module_t *prefs_register_subtree(module_t *parent, const char *title,
219     const char *description);
220
221 /*
222  * Register that a protocol has preferences.
223  */
224 extern module_t *prefs_register_protocol(int id, void (*apply_cb)(void));
225
226 /*
227  * Register that a protocol has preferences and group it under a single
228  * subtree
229  */
230 #define PREFERENCE_GROUPING
231 extern module_t *prefs_register_protocol_subtree(const char *subtree, int id,
232                                                  void (*apply_cb)(void));
233
234 /*
235  * Register that a protocol used to have preferences but no longer does,
236  * by creating an "obsolete" module for it.
237  */
238 extern module_t *prefs_register_protocol_obsolete(int id);
239
240 /*
241  * Callback function for module list scanners.
242  */
243 typedef guint (*module_cb)(module_t *module, gpointer user_data);
244
245 /*
246  * Returns TRUE if module has any submodules
247  */
248 extern gboolean prefs_module_has_submodules(module_t *module);
249
250 /*
251  * Call a callback function, with a specified argument, for each module
252  * in the list of all modules.  (This list does not include subtrees.)
253  *
254  * Ignores "obsolete" modules; their sole purpose is to allow old
255  * preferences for dissectors that no longer have preferences to be
256  * silently ignored in preference files.
257  */
258 extern guint prefs_modules_foreach(module_cb callback, gpointer user_data);
259
260 /*
261  * Call a callback function, with a specified argument, for each submodule
262  * of specified modules.  If the module is NULL, goes through the top-level
263  * list in the display tree of modules.
264  *
265  * Ignores "obsolete" modules; their sole purpose is to allow old
266  * preferences for dissectors that no longer have preferences to be
267  * silently ignored in preference files.  Does not ignore subtrees,
268  * as this can be used when walking the display tree of modules.
269  */
270 extern guint prefs_modules_foreach_submodules(module_t *module, module_cb callback, gpointer user_data);
271
272 /*
273  * Call the "apply" callback function for each module if any of its
274  * preferences have changed, and then clear the flag saying its
275  * preferences have changed, as the module has been notified of that
276  * fact.
277  */
278 extern void prefs_apply_all(void);
279
280 /*
281  * Call the "apply" callback function for a specific module if any of
282  * its preferences have changed, and then clear the flag saying its
283  * preferences have changed, as the module has been notified of that
284  * fact.
285  */
286 extern void prefs_apply(module_t *module);
287
288
289 struct preference;
290
291 typedef struct preference pref_t;
292
293 /*
294  * Returns TRUE if the given protocol has registered preferences.
295  */
296 extern gboolean prefs_is_registered_protocol(const char *name);
297
298 /*
299  * Returns the module title of a registered protocol (or NULL if unknown).
300  */
301 extern const char *prefs_get_title_by_name(const char *name);
302
303 /** Given a module name, return a pointer to its pref_module struct,
304  * or NULL if it's not found.
305  *
306  * @param name The preference module name.  Usually the same as the protocol
307  * name, e.g. "tcp".
308  * @return A pointer to the corresponding preference module, or NULL if it
309  * wasn't found.
310  */
311 extern module_t *prefs_find_module(const char *name);
312
313 /** Given a module name, and a preference name return a pointer to the given
314  * module's given preference or NULL if it's not found.
315  *
316  * @param module The preference module name.  Usually the same as the protocol
317  * name, e.g. "tcp".
318  * @param pref The preference name, e.g. "desegment".
319  * @return A pointer to the corresponding preference, or NULL if it
320  * wasn't found.
321  */
322 extern pref_t *prefs_find_preference(module_t * module, const char *pref);
323
324 /*
325  * Register a preference with an unsigned integral value.
326  */
327 extern void prefs_register_uint_preference(module_t *module, const char *name,
328     const char *title, const char *description, guint base, guint *var);
329
330 /*
331  * Register a preference with an Boolean value.
332  * Note that the name must be in lowercase letters only (underscore allowed).
333  */
334 extern void prefs_register_bool_preference(module_t *module, const char *name,
335     const char *title, const char *description, gboolean *var);
336
337 /*
338  * Register a preference with an enumerated value.
339  */
340 extern void prefs_register_enum_preference(module_t *module, const char *name,
341     const char *title, const char *description, gint *var,
342     const enum_val_t *enumvals, gboolean radio_buttons);
343
344 /*
345  * Register a preference with a character-string value.
346  */
347 extern void prefs_register_string_preference(module_t *module, const char *name,
348     const char *title, const char *description, const char **var);
349
350 /*
351  * Register a preference with a ranged value.
352  */
353 extern void prefs_register_range_preference(module_t *module, const char *name,
354     const char *title, const char *description, range_t **var,
355     guint32 max_value);
356
357 /*
358  * Register a static text 'preference'. It can be used to add some info/explanation.
359  */
360 extern void prefs_register_static_text_preference(module_t *module, const char *name,
361     const char *title, const char *description);
362
363 /*
364  * Register a uat 'preference'. It adds a button that opens the uat's window in the
365  * preferences tab of the module.
366  */
367 extern void prefs_register_uat_preference(module_t *module,
368                                                                                   const char *name,
369                                                                                   const char* title,
370                                                                                   const char *description,
371                                                                                   void* uat);
372
373 /*
374  * Register a preference that used to be supported but no longer is.
375  */
376 extern void prefs_register_obsolete_preference(module_t *module,
377     const char *name);
378
379
380 typedef guint (*pref_cb)(pref_t *pref, gpointer user_data);
381
382 /*
383  * Call a callback function, with a specified argument, for each preference
384  * in a given module.
385  *
386  * If any of the callbacks return a non-zero value, stop and return that
387  * value, otherwise return 0.
388  */
389 extern guint prefs_pref_foreach(module_t *module, pref_cb callback,
390     gpointer user_data);
391
392 /* Parse through a list of comma-separated, possibly quoted strings.
393  *  Return a list of the string data.
394  */
395 extern GList *prefs_get_string_list(gchar *str);
396
397 /* Clear the given list of string data. */
398 extern void prefs_clear_string_list(GList *sl);
399
400 /*
401  * Register all non-dissector modules' preferences.
402  */
403 extern void prefs_register_modules(void);
404
405 /* Read the preferences file, fill in "prefs", and return a pointer to it.
406
407    If we got an error (other than "it doesn't exist") trying to read
408    the global preferences file, stuff the errno into "*gpf_errno_return"
409    on an open error and into "*gpf_read_errno_return" on a read error,
410    stuff a pointer to the path of the file into "*gpf_path_return", and
411    return NULL.
412
413    If we got an error (other than "it doesn't exist") trying to read
414    the user's preferences file, stuff the errno into "*pf_errno_return"
415    on an open error and into "*pf_read_errno_return" on a read error,
416    stuff a pointer to the path of the file into "*pf_path_return", and
417    return NULL. */
418 extern e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
419
420 /* Write out "prefs" to the user's preferences file, and return 0.
421
422    If we got an error, stuff a pointer to the path of the preferences file
423    into "*pf_path_return", and return the errno. */
424 extern int write_prefs(char **);
425
426 /* Copy a set of preferences. */
427 extern void copy_prefs(e_prefs *dest, e_prefs *src);
428
429 /* Free a set of preferences. */
430 extern void free_prefs(e_prefs *pr);
431
432 /*
433  * Given a string of the form "<pref name>:<pref value>", as might appear
434  * as an argument to a "-o" option, parse it and set the preference in
435  * question.  Return an indication of whether it succeeded or failed
436  * in some fashion.
437  *
438  * XXX - should supply, for syntax errors, a detailed explanation of
439  * the syntax error.
440  */
441 typedef enum {
442     PREFS_SET_OK,               /* succeeded */
443     PREFS_SET_SYNTAX_ERR,       /* syntax error in string */
444     PREFS_SET_NO_SUCH_PREF,     /* no such preference */
445     PREFS_SET_OBSOLETE          /* preference used to exist but no longer does */
446 } prefs_set_pref_e;
447
448 extern prefs_set_pref_e prefs_set_pref(char *prefarg);
449
450 /*
451  * Get or set a preference's obsolete status. These can be used to make a
452  * preference obsolete after startup so that we can fetch its value but
453  * keep it from showing up in the prefrences dialog.
454  */
455 extern gboolean prefs_get_preference_obsolete(pref_t *pref);
456 extern prefs_set_pref_e prefs_set_preference_obsolete(pref_t *pref);
457
458
459 /*
460  * Returns TRUE if the given device is hidden
461  */
462 extern gboolean prefs_is_capture_device_hidden(const char *name);
463
464 /*
465  * Returns TRUE if the given device should capture in monitor mode by default
466  */
467 extern gboolean prefs_capture_device_monitor_mode(const char *name);
468
469 #ifdef __cplusplus
470 }
471 #endif /* __cplusplus */
472
473 #endif /* prefs.h */