2 * Definitions for field types
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 2001 Gerald Combs
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.
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.
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.
34 FT_NONE, /* used for text labels with no value */
36 FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
39 FT_UINT24, /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
44 FT_INT24, /* same as for UINT24 */
52 FT_STRINGZ, /* for use with proto_tree_add_item() */
53 FT_UINT_STRING, /* for use with proto_tree_add_item() */
54 /*FT_UCS2_LE, */ /* Unicode, 2 byte, Little Endian */
61 FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that numbe */
62 FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */
63 FT_NUM_TYPES /* last item number plus one */
66 #define IS_FT_INT(ft) ((ft)==FT_INT8||(ft)==FT_INT16||(ft)==FT_INT24||(ft)==FT_INT32)
67 #define IS_FT_UINT(ft) ((ft)==FT_UINT8||(ft)==FT_UINT16||(ft)==FT_UINT24||(ft)==FT_UINT32||(ft)==FT_FRAMENUM)
68 #define IS_FT_TIME(ft) ((ft)==FT_ABSOLUTE_TIME||(ft)==FT_RELATIVE_TIME)
69 #define IS_FT_STRING(ft) ((ft)==FT_STRING||(ft)==FT_STRINGZ)
71 typedef enum ftenum ftenum_t;
72 typedef struct _ftype_t ftype_t;
74 /* String representation types. */
80 typedef enum ftrepr ftrepr_t;
83 typedef struct _pcre_tuple_t pcre_tuple_t;
84 #endif /* HAVE_LIBPCRE */
86 /* Initialize the ftypes subsytem. Called once. */
88 ftypes_initialize(void);
90 /* ---------------- FTYPE ----------------- */
92 /* Return a string representing the name of the type */
94 ftype_name(ftenum_t ftype);
96 /* Return a string presenting a "pretty" representation of the
97 * name of the type. The pretty name means more to the user than
98 * that "FT_*" name. */
100 ftype_pretty_name(ftenum_t ftype);
102 /* Returns length of field in packet, or 0 if not determinable/defined. */
104 ftype_length(ftenum_t ftype);
107 ftype_can_slice(enum ftenum ftype);
110 ftype_can_eq(enum ftenum ftype);
113 ftype_can_ne(enum ftenum ftype);
116 ftype_can_gt(enum ftenum ftype);
119 ftype_can_ge(enum ftenum ftype);
122 ftype_can_lt(enum ftenum ftype);
125 ftype_can_le(enum ftenum ftype);
128 ftype_can_bitwise_and(enum ftenum ftype);
131 ftype_can_contains(enum ftenum ftype);
134 ftype_can_matches(enum ftenum ftype);
136 /* ---------------- FVALUE ----------------- */
138 #include <epan/ipv4.h>
140 #include <epan/tvbuff.h>
141 #include <epan/nstime.h>
142 #include <epan/dfilter/drange.h>
144 typedef struct _fvalue_t {
147 /* Put a few basic types in here */
160 #endif /* HAVE_LIBPCRE */
163 /* The following is provided for private use
165 gboolean fvalue_gboolean1;
169 typedef void (*FvalueNewFunc)(fvalue_t*);
170 typedef void (*FvalueFreeFunc)(fvalue_t*);
171 typedef void (*LogFunc)(char*,...);
173 typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, char*, gboolean, LogFunc);
174 typedef gboolean (*FvalueFromString)(fvalue_t*, char*, LogFunc);
175 typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, char*);
176 typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t);
178 typedef void (*FvalueSetFunc)(fvalue_t*, gpointer, gboolean);
179 typedef void (*FvalueSetIntegerFunc)(fvalue_t*, guint32);
180 typedef void (*FvalueSetFloatingFunc)(fvalue_t*, gdouble);
182 typedef gpointer (*FvalueGetFunc)(fvalue_t*);
183 typedef guint32 (*FvalueGetIntegerFunc)(fvalue_t*);
184 typedef double (*FvalueGetFloatingFunc)(fvalue_t*);
186 typedef gboolean (*FvalueCmp)(fvalue_t*, fvalue_t*);
188 typedef guint (*FvalueLen)(fvalue_t*);
189 typedef void (*FvalueSlice)(fvalue_t*, GByteArray *, guint offset, guint length);
193 const char *pretty_name;
195 FvalueNewFunc new_value;
196 FvalueFreeFunc free_value;
197 FvalueFromUnparsed val_from_unparsed;
198 FvalueFromString val_from_string;
199 FvalueToStringRepr val_to_string_repr;
200 FvalueStringReprLen len_string_repr;
203 FvalueSetFunc set_value;
204 FvalueSetIntegerFunc set_value_integer;
205 FvalueSetFloatingFunc set_value_floating;
208 FvalueGetFunc get_value;
209 FvalueGetIntegerFunc get_value_integer;
210 FvalueGetFloatingFunc get_value_floating;
218 FvalueCmp cmp_bitwise_and;
219 FvalueCmp cmp_contains;
220 FvalueCmp cmp_matches;
228 fvalue_new(ftenum_t ftype);
231 fvalue_init(fvalue_t *fv, ftenum_t ftype);
234 /* Define type needed for the fvalue_t free list. */
235 SLAB_ITEM_TYPE_DEFINE(fvalue_t)
237 /* Free all memory used by an fvalue_t. With MSVC and a
238 * libethereal.dll, we need a special declaration.
240 ETH_VAR_IMPORT SLAB_FREE_LIST_DECLARE(fvalue_t)
243 #define FVALUE_CLEANUP(fv) \
245 register FvalueFreeFunc free_value; \
246 free_value = (fv)->ftype->free_value; \
252 #define FVALUE_FREE(fv) \
255 SLAB_FREE(fv, fvalue_t); \
260 fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogFunc logfunc);
263 fvalue_from_string(ftenum_t ftype, char *s, LogFunc logfunc);
265 /* Returns the length of the string required to hold the
266 * string representation of the the field value.
267 * The length DOES NOT include the terminating NUL. */
269 fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype);
271 /* Creates the string representation of the field value.
272 * If given non-NULL 'buf', the string is written at the memory
273 * location pointed to by 'buf'. If 'buf' is NULL, new memory
274 * is malloc'ed and the string representation is written there.
275 * The pointer to the beginning of the string representation is
276 * returned. If 'buf' was NULL, this points to the newly-allocated
277 * memory. if 'buf' was non-NULL, then the return value will be
280 fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, char *buf);
283 fvalue_type_name(fvalue_t *fv);
286 fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied);
289 fvalue_set_integer(fvalue_t *fv, guint32 value);
292 fvalue_set_floating(fvalue_t *fv, gdouble value);
295 fvalue_get(fvalue_t *fv);
298 fvalue_get_integer(fvalue_t *fv);
301 fvalue_get_floating(fvalue_t *fv);
304 fvalue_eq(fvalue_t *a, fvalue_t *b);
307 fvalue_ne(fvalue_t *a, fvalue_t *b);
310 fvalue_gt(fvalue_t *a, fvalue_t *b);
313 fvalue_ge(fvalue_t *a, fvalue_t *b);
316 fvalue_lt(fvalue_t *a, fvalue_t *b);
319 fvalue_le(fvalue_t *a, fvalue_t *b);
322 fvalue_bitwise_and(fvalue_t *a, fvalue_t *b);
325 fvalue_contains(fvalue_t *a, fvalue_t *b);
328 fvalue_matches(fvalue_t *a, fvalue_t *b);
331 fvalue_length(fvalue_t *fv);
334 fvalue_slice(fvalue_t *fv, drange *drange);
336 #endif /* ftypes.h */