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