ftypes: move set_value_uinteger into the union
[metze/wireshark/wip.git] / epan / ftypes / ftypes-int.h
1 /*
2  * Wireshark - Network traffic analyzer
3  * By Gerald Combs <gerald@wireshark.org>
4  * Copyright 2001 Gerald Combs
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef FTYPES_INT_H
22 #define FTYPES_INT_H
23
24 #include <epan/packet.h>
25 #include "ftypes.h"
26
27
28 void
29 ftype_register(enum ftenum ftype, ftype_t *ft);
30
31 /* These are the ftype registration functions that need to be called.
32  * This list and the initialization function could be produced
33  * via a script, like the dissector registration, but there's so few
34  * that I don't mind doing it by hand for now. */
35 void ftype_register_bytes(void);
36 void ftype_register_double(void);
37 void ftype_register_ieee_11073_float(void);
38 void ftype_register_fc(void);
39 void ftype_register_integers(void);
40 void ftype_register_ipv4(void);
41 void ftype_register_ipv6(void);
42 void ftype_register_guid(void);
43 void ftype_register_none(void);
44 void ftype_register_string(void);
45 void ftype_register_time(void);
46 void ftype_register_tvbuff(void);
47 void ftype_register_pcre(void);
48
49 typedef void (*FvalueNewFunc)(fvalue_t*);
50 typedef void (*FvalueFreeFunc)(fvalue_t*);
51
52 typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, const char*, gboolean, gchar **);
53 typedef gboolean (*FvalueFromString)(fvalue_t*, const char*, gchar **);
54 typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, int field_display, char*volatile, unsigned int);
55 typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t, int field_display);
56
57 typedef void (*FvalueSetByteArrayFunc)(fvalue_t*, GByteArray *);
58 typedef void (*FvalueSetBytesFunc)(fvalue_t*, const guint8 *);
59 typedef void (*FvalueSetGuidFunc)(fvalue_t*, const e_guid_t *);
60 typedef void (*FvalueSetTimeFunc)(fvalue_t*, const nstime_t *);
61 typedef void (*FvalueSetStringFunc)(fvalue_t*, const gchar *value);
62 typedef void (*FvalueSetProtocolFunc)(fvalue_t*, tvbuff_t *value, const gchar *name);
63 typedef void (*FvalueSetUnsignedIntegerFunc)(fvalue_t*, guint32);
64 typedef void (*FvalueSetSignedIntegerFunc)(fvalue_t*, gint32);
65 typedef void (*FvalueSetUnsignedInteger64Func)(fvalue_t*, guint64);
66 typedef void (*FvalueSetSignedInteger64Func)(fvalue_t*, gint64);
67 typedef void (*FvalueSetFloatingFunc)(fvalue_t*, gdouble);
68
69 typedef gpointer (*FvalueGetFunc)(fvalue_t*);
70 typedef guint32 (*FvalueGetUnsignedIntegerFunc)(fvalue_t*);
71 typedef gint32  (*FvalueGetSignedIntegerFunc)(fvalue_t*);
72 typedef guint64 (*FvalueGetUnsignedInteger64Func)(fvalue_t*);
73 typedef gint64 (*FvalueGetSignedInteger64Func)(fvalue_t*);
74 typedef double (*FvalueGetFloatingFunc)(fvalue_t*);
75
76 typedef gboolean (*FvalueCmp)(const fvalue_t*, const fvalue_t*);
77
78 typedef guint (*FvalueLen)(fvalue_t*);
79 typedef void (*FvalueSlice)(fvalue_t*, GByteArray *, guint offset, guint length);
80
81 struct _ftype_t {
82         ftenum_t                ftype;
83         const char              *name;
84         const char              *pretty_name;
85         int                     wire_size;
86         FvalueNewFunc           new_value;
87         FvalueFreeFunc          free_value;
88         FvalueFromUnparsed      val_from_unparsed;
89         FvalueFromString        val_from_string;
90         FvalueToStringRepr      val_to_string_repr;
91         FvalueStringReprLen     len_string_repr;
92
93         union {
94                 FvalueSetByteArrayFunc  set_value_byte_array;
95                 FvalueSetBytesFunc      set_value_bytes;
96                 FvalueSetGuidFunc       set_value_guid;
97                 FvalueSetTimeFunc       set_value_time;
98                 FvalueSetStringFunc     set_value_string;
99                 FvalueSetProtocolFunc   set_value_protocol;
100                 FvalueSetUnsignedIntegerFunc    set_value_uinteger;
101         } set_value;
102
103         /* could be union */
104         FvalueSetSignedIntegerFunc              set_value_sinteger;
105         FvalueSetUnsignedInteger64Func  set_value_uinteger64;
106         FvalueSetSignedInteger64Func            set_value_sinteger64;
107         FvalueSetFloatingFunc   set_value_floating;
108
109         /* could be union */
110         FvalueGetFunc           get_value;
111         FvalueGetUnsignedIntegerFunc    get_value_uinteger;
112         FvalueGetSignedIntegerFunc              get_value_sinteger;
113         FvalueGetUnsignedInteger64Func  get_value_uinteger64;
114         FvalueGetSignedInteger64Func    get_value_sinteger64;
115         FvalueGetFloatingFunc   get_value_floating;
116
117         FvalueCmp               cmp_eq;
118         FvalueCmp               cmp_ne;
119         FvalueCmp               cmp_gt;
120         FvalueCmp               cmp_ge;
121         FvalueCmp               cmp_lt;
122         FvalueCmp               cmp_le;
123         FvalueCmp               cmp_bitwise_and;
124         FvalueCmp               cmp_contains;
125         FvalueCmp               cmp_matches;
126
127         FvalueLen               len;
128         FvalueSlice             slice;
129 };
130
131 /* Free all memory used by an fvalue_t. With MSVC and a
132  * libwireshark.dll, we need a special declaration.
133  */
134
135 #define FVALUE_CLEANUP(fv)                                      \
136         {                                                       \
137                 register FvalueFreeFunc free_value;             \
138                 free_value = (fv)->ftype->free_value;   \
139                 if (free_value) {                               \
140                         free_value((fv));                       \
141                 }                                               \
142         }
143
144 #define FVALUE_FREE(fv)                                         \
145         {                                                       \
146                 FVALUE_CLEANUP(fv)                              \
147                 g_slice_free(fvalue_t, fv);                     \
148         }
149
150 #endif
151
152 /*
153  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
154  *
155  * Local variables:
156  * c-basic-offset: 8
157  * tab-width: 8
158  * indent-tabs-mode: t
159  * End:
160  *
161  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
162  * :indentSize=8:tabSize=8:noTabs=false:
163  */