MBIM: add an option to force SMS PDU decoding format if MBIM_DEVICE_CAPS_INFO message...
[metze/wireshark/wip.git] / epan / prefs-int.h
1 /* prefs-int.h
2  * Definitions for implementation of preference handling routines;
3  * used by "friends" of the preferences type.
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef __PREFS_INT_H__
25 #define __PREFS_INT_H__
26
27 #include <stdio.h>
28 #include "ws_symbol_export.h"
29 #include <epan/wmem/wmem.h>
30
31 /**
32  *@file
33  */
34
35 struct pref_module {
36     const char *name;           /**< name of module */
37     const char *title;          /**< title of module (displayed in preferences list) */
38     const char *description;    /**< Description of module (displayed in preferences notebook) */
39     void (*apply_cb)(void);     /**< routine to call when preferences applied */
40     GList *prefs;               /**< list of its preferences */
41     struct pref_module *parent; /**< parent module */
42     wmem_tree_t *submodules;    /**< list of its submodules */
43     int numprefs;               /**< number of non-obsolete preferences */
44     gboolean prefs_changed;     /**< if TRUE, a preference has changed since we last checked */
45     gboolean obsolete;          /**< if TRUE, this is a module that used to
46                                  * exist but no longer does
47                                  */
48     gboolean use_gui;           /**< Determines whether or not the module will use the generic
49                                   * GUI interface/APIs with the preference value or if its own
50                                   * independent GUI will be provided.  This allows all preferences
51                                   * to have a common API for reading/writing, but not require them to
52                                   * use simple GUI controls to change the options.  In general, the "general"
53                                   * Wireshark preferences should have this set to FALSE, while the protocol
54                                   * modules will have this set to TRUE */
55 };
56
57 typedef struct {
58     module_t *module;
59     FILE     *pf;
60 } write_pref_arg_t;
61
62 /**
63  * Module used for protocol preferences.
64  * With MSVC and a libwireshark.dll, we need a special declaration.
65  */
66 WS_DLL_PUBLIC module_t *protocols_module;
67
68 typedef void (*pref_custom_free_cb) (pref_t* pref);
69 typedef void (*pref_custom_reset_cb) (pref_t* pref);
70 typedef prefs_set_pref_e (*pref_custom_set_cb) (pref_t* pref, const gchar* value, gboolean* changed);
71 /* typedef void (*pref_custom_write_cb) (pref_t* pref, write_pref_arg_t* arg); Deprecated. */
72 /* pref_custom_type_name_cb should return NULL for internal / hidden preferences. */
73 typedef const char * (*pref_custom_type_name_cb) (void);
74 typedef char * (*pref_custom_type_description_cb) (void);
75 typedef gboolean (*pref_custom_is_default_cb) (pref_t* pref);
76 typedef char * (*pref_custom_to_str_cb) (pref_t* pref, gboolean default_val);
77
78 /** Structure to hold callbacks for PREF_CUSTOM type */
79 struct pref_custom_cbs {
80     pref_custom_free_cb free_cb;
81     pref_custom_reset_cb reset_cb;
82     pref_custom_set_cb set_cb;
83     /* pref_custom_write_cb write_cb; Deprecated. */
84     pref_custom_type_name_cb type_name_cb;
85     pref_custom_type_description_cb type_description_cb;
86     pref_custom_is_default_cb is_default_cb;
87     pref_custom_to_str_cb to_str_cb;
88 };
89
90 /**
91  * PREF_OBSOLETE is used for preferences that a module used to support
92  * but no longer supports; we give different error messages for them.
93  */
94 typedef enum {
95     PREF_UINT,
96     PREF_BOOL,
97     PREF_ENUM,
98     PREF_STRING,
99     PREF_RANGE,
100     PREF_STATIC_TEXT,
101     PREF_UAT,
102     PREF_FILENAME,
103     PREF_COLOR,     /* XXX - These are only supported for "internal" (non-protocol) */
104     PREF_CUSTOM,    /* use and not as a generic protocol preference */
105     PREF_OBSOLETE,
106     PREF_DIRNAME
107 } pref_type_t;
108
109 typedef enum {
110         GUI_ALL,
111         GUI_GTK,
112         GUI_QT
113 } gui_type_t;
114
115 /** Struct to hold preference data */
116 struct preference {
117     const char *name;                /**< name of preference */
118     const char *title;               /**< title to use in GUI */
119     const char *description;         /**< human-readable description of preference */
120     int ordinal;                     /**< ordinal number of this preference */
121     pref_type_t type;                /**< type of that preference */
122     gui_type_t gui;                  /**< type of the GUI (QT, GTK or both) the preference is registered for */
123     union {                          /* The Qt preference code assumes that these will all be pointers (and unique) */
124         guint *uint;
125         gboolean *boolp;
126         gint *enump;
127         const char **string;
128         range_t **range;
129         struct epan_uat* uat;
130         color_t *colorp;
131         GList** list;
132     } varp;                          /**< pointer to variable storing the value */
133     union {
134         guint uint;
135         gboolean boolval;
136         gint enumval;
137         char *string;
138         range_t *range;
139         color_t color;
140         GList* list;
141     } stashed_val;                     /**< original value, when editing from the GUI */
142     union {
143         guint uint;
144         gboolean boolval;
145         gint enumval;
146         char *string;
147         range_t *range;
148         color_t color;
149         GList* list;
150     } default_val;                   /**< the default value of the preference */
151     union {
152       guint base;                    /**< input/output base, for PREF_UINT */
153       guint32 max_value;             /**< maximum value of a range */
154       struct {
155         const enum_val_t *enumvals;  /**< list of name & values */
156         gboolean radio_buttons;      /**< TRUE if it should be shown as
157                                           radio buttons rather than as an
158                                           option menu or combo box in
159                                           the preferences tab */
160       } enum_info;                   /**< for PREF_ENUM */
161     } info;                          /**< display/text file information */
162     struct pref_custom_cbs custom_cbs;   /**< for PREF_CUSTOM */
163     void    *control;                /**< handle for GUI control for this preference */
164 };
165
166 /* read_prefs_file: read in a generic config file and do a callback to */
167 /* pref_set_pair_fct() for every key/value pair found */
168 /**
169  * Given a string of the form "<pref name>:<pref value>", as might appear
170  * as an argument to a "-o" option, parse it and set the preference in
171  * question.
172  * @return an indication of whether it succeeded or failed
173  * in some fashion.
174  */
175 typedef prefs_set_pref_e (*pref_set_pair_cb) (gchar *key, const gchar *value, void *private_data, gboolean return_range_errors);
176
177 /** read the preferences file (or similiar) and call the callback
178  * function to set each key/value pair found
179  */
180 WS_DLL_PUBLIC
181 int
182 read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data);
183
184 #endif /* prefs-int.h */