2001-02-01 20:21:25 +00:00
|
|
|
/* ftypes.h
|
|
|
|
* Definitions for field types
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-02-01 20:21:25 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-02-01 20:21:25 +00:00
|
|
|
* Copyright 2001 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:21:25 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:21:25 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2001-02-01 20:21:25 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FTYPES_H
|
|
|
|
#define FTYPES_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
2003-12-02 09:47:23 +00:00
|
|
|
#include "../slab.h"
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
/* field types */
|
|
|
|
enum ftenum {
|
|
|
|
FT_NONE, /* used for text labels with no value */
|
|
|
|
FT_PROTOCOL,
|
|
|
|
FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
|
|
|
|
FT_UINT8,
|
|
|
|
FT_UINT16,
|
|
|
|
FT_UINT24, /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
|
|
|
|
FT_UINT32,
|
2001-10-29 21:13:13 +00:00
|
|
|
FT_UINT64,
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_INT8,
|
|
|
|
FT_INT16,
|
2001-11-02 10:09:51 +00:00
|
|
|
FT_INT24, /* same as for UINT24 */
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_INT32,
|
2001-11-02 10:09:51 +00:00
|
|
|
FT_INT64,
|
2002-08-24 19:45:28 +00:00
|
|
|
FT_FLOAT,
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_DOUBLE,
|
|
|
|
FT_ABSOLUTE_TIME,
|
|
|
|
FT_RELATIVE_TIME,
|
|
|
|
FT_STRING,
|
|
|
|
FT_STRINGZ, /* for use with proto_tree_add_item() */
|
2007-11-19 21:27:01 +00:00
|
|
|
FT_EBCDIC, /* for use with proto_tree_add_item() */
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_UINT_STRING, /* for use with proto_tree_add_item() */
|
2002-02-15 09:01:21 +00:00
|
|
|
/*FT_UCS2_LE, */ /* Unicode, 2 byte, Little Endian */
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_ETHER,
|
|
|
|
FT_BYTES,
|
2002-05-09 23:50:34 +00:00
|
|
|
FT_UINT_BYTES,
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_IPv4,
|
|
|
|
FT_IPv6,
|
|
|
|
FT_IPXNET,
|
2002-12-19 02:58:53 +00:00
|
|
|
FT_FRAMENUM, /* a UINT32, but if selected lets you go to frame with that numbe */
|
2003-12-09 23:02:40 +00:00
|
|
|
FT_PCRE, /* a compiled Perl-Compatible Regular Expression object */
|
2005-07-04 13:04:53 +00:00
|
|
|
FT_GUID, /* GUID, UUID */
|
2005-12-02 13:16:58 +00:00
|
|
|
FT_OID, /* OBJECT IDENTIFIER */
|
2001-02-01 20:21:25 +00:00
|
|
|
FT_NUM_TYPES /* last item number plus one */
|
|
|
|
};
|
|
|
|
|
2008-06-28 17:23:07 +00:00
|
|
|
#define IS_FT_INT(ft) ((ft)==FT_INT8||(ft)==FT_INT16||(ft)==FT_INT24||(ft)==FT_INT32||(ft)==FT_INT64)
|
|
|
|
#define IS_FT_UINT(ft) ((ft)==FT_UINT8||(ft)==FT_UINT16||(ft)==FT_UINT24||(ft)==FT_UINT32||(ft)==FT_UINT64||(ft)==FT_FRAMENUM)
|
2004-06-24 21:50:05 +00:00
|
|
|
#define IS_FT_TIME(ft) ((ft)==FT_ABSOLUTE_TIME||(ft)==FT_RELATIVE_TIME)
|
|
|
|
#define IS_FT_STRING(ft) ((ft)==FT_STRING||(ft)==FT_STRINGZ)
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
typedef enum ftenum ftenum_t;
|
|
|
|
typedef struct _ftype_t ftype_t;
|
|
|
|
|
2003-06-11 21:24:54 +00:00
|
|
|
/* String representation types. */
|
|
|
|
enum ftrepr {
|
|
|
|
FTREPR_DISPLAY,
|
|
|
|
FTREPR_DFILTER
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum ftrepr ftrepr_t;
|
|
|
|
|
2003-12-09 23:02:40 +00:00
|
|
|
#ifdef HAVE_LIBPCRE
|
2003-12-10 21:12:02 +00:00
|
|
|
typedef struct _pcre_tuple_t pcre_tuple_t;
|
2003-12-09 23:02:40 +00:00
|
|
|
#endif /* HAVE_LIBPCRE */
|
2003-07-25 03:44:05 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* Initialize the ftypes subsytem. Called once. */
|
|
|
|
void
|
|
|
|
ftypes_initialize(void);
|
|
|
|
|
|
|
|
/* ---------------- FTYPE ----------------- */
|
|
|
|
|
|
|
|
/* Return a string representing the name of the type */
|
|
|
|
const char*
|
|
|
|
ftype_name(ftenum_t ftype);
|
|
|
|
|
|
|
|
/* Return a string presenting a "pretty" representation of the
|
|
|
|
* name of the type. The pretty name means more to the user than
|
|
|
|
* that "FT_*" name. */
|
|
|
|
const char*
|
|
|
|
ftype_pretty_name(ftenum_t ftype);
|
|
|
|
|
|
|
|
/* Returns length of field in packet, or 0 if not determinable/defined. */
|
|
|
|
int
|
|
|
|
ftype_length(ftenum_t ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_slice(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_eq(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_ne(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_gt(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_ge(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_lt(enum ftenum ftype);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
ftype_can_le(enum ftenum ftype);
|
|
|
|
|
2004-02-27 12:00:32 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_bitwise_and(enum ftenum ftype);
|
|
|
|
|
2003-08-27 15:23:11 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_contains(enum ftenum ftype);
|
|
|
|
|
2003-12-06 16:35:20 +00:00
|
|
|
gboolean
|
|
|
|
ftype_can_matches(enum ftenum ftype);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
/* ---------------- FVALUE ----------------- */
|
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/ipv4.h>
|
2006-03-10 11:58:22 +00:00
|
|
|
#include <epan/guid-utils.h>
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/tvbuff.h>
|
|
|
|
#include <epan/nstime.h>
|
|
|
|
#include <epan/dfilter/drange.h>
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2003-11-25 08:50:38 +00:00
|
|
|
typedef struct _fvalue_t {
|
2003-12-03 09:28:26 +00:00
|
|
|
ftype_t *ftype;
|
2001-02-01 20:21:25 +00:00
|
|
|
union {
|
|
|
|
/* Put a few basic types in here */
|
|
|
|
gpointer pointer;
|
2007-01-18 11:02:26 +00:00
|
|
|
guint32 uinteger;
|
|
|
|
gint32 sinteger;
|
2004-08-22 00:31:58 +00:00
|
|
|
guint64 integer64;
|
2001-02-01 20:21:25 +00:00
|
|
|
gdouble floating;
|
|
|
|
gchar *string;
|
2004-02-01 02:35:30 +00:00
|
|
|
guchar *ustring;
|
2001-02-01 20:21:25 +00:00
|
|
|
GByteArray *bytes;
|
2004-01-25 17:22:57 +00:00
|
|
|
GString *gstring;
|
2001-02-01 20:21:25 +00:00
|
|
|
ipv4_addr ipv4;
|
2006-03-10 11:58:22 +00:00
|
|
|
e_guid_t guid;
|
2001-09-14 07:10:13 +00:00
|
|
|
nstime_t time;
|
2001-02-01 20:21:25 +00:00
|
|
|
tvbuff_t *tvb;
|
2003-12-09 23:02:40 +00:00
|
|
|
#ifdef HAVE_LIBPCRE
|
|
|
|
pcre_tuple_t *re;
|
|
|
|
#endif /* HAVE_LIBPCRE */
|
2001-02-01 20:21:25 +00:00
|
|
|
} value;
|
2003-08-27 15:23:11 +00:00
|
|
|
|
|
|
|
/* The following is provided for private use
|
|
|
|
* by the fvalue. */
|
|
|
|
gboolean fvalue_gboolean1;
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
} fvalue_t;
|
|
|
|
|
2003-11-25 13:20:36 +00:00
|
|
|
typedef void (*FvalueNewFunc)(fvalue_t*);
|
|
|
|
typedef void (*FvalueFreeFunc)(fvalue_t*);
|
2005-07-23 06:19:08 +00:00
|
|
|
typedef void (*LogFunc)(const char*,...);
|
2003-11-25 13:20:36 +00:00
|
|
|
|
|
|
|
typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, char*, gboolean, LogFunc);
|
|
|
|
typedef gboolean (*FvalueFromString)(fvalue_t*, char*, LogFunc);
|
|
|
|
typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, char*);
|
|
|
|
typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t);
|
|
|
|
|
|
|
|
typedef void (*FvalueSetFunc)(fvalue_t*, gpointer, gboolean);
|
2007-01-18 11:02:26 +00:00
|
|
|
typedef void (*FvalueSetUnsignedIntegerFunc)(fvalue_t*, guint32);
|
|
|
|
typedef void (*FvalueSetSignedIntegerFunc)(fvalue_t*, gint32);
|
2004-08-22 00:31:58 +00:00
|
|
|
typedef void (*FvalueSetInteger64Func)(fvalue_t*, guint64);
|
2003-11-25 13:20:36 +00:00
|
|
|
typedef void (*FvalueSetFloatingFunc)(fvalue_t*, gdouble);
|
|
|
|
|
|
|
|
typedef gpointer (*FvalueGetFunc)(fvalue_t*);
|
2007-01-18 11:02:26 +00:00
|
|
|
typedef guint32 (*FvalueGetUnsignedIntegerFunc)(fvalue_t*);
|
|
|
|
typedef gint32 (*FvalueGetSignedIntegerFunc)(fvalue_t*);
|
2004-08-22 00:31:58 +00:00
|
|
|
typedef guint64 (*FvalueGetInteger64Func)(fvalue_t*);
|
2003-11-25 13:20:36 +00:00
|
|
|
typedef double (*FvalueGetFloatingFunc)(fvalue_t*);
|
|
|
|
|
|
|
|
typedef gboolean (*FvalueCmp)(fvalue_t*, fvalue_t*);
|
|
|
|
|
|
|
|
typedef guint (*FvalueLen)(fvalue_t*);
|
|
|
|
typedef void (*FvalueSlice)(fvalue_t*, GByteArray *, guint offset, guint length);
|
|
|
|
|
|
|
|
struct _ftype_t {
|
2006-05-02 14:26:17 +00:00
|
|
|
ftenum_t ftype;
|
2003-11-25 13:20:36 +00:00
|
|
|
const char *name;
|
|
|
|
const char *pretty_name;
|
|
|
|
int wire_size;
|
|
|
|
FvalueNewFunc new_value;
|
|
|
|
FvalueFreeFunc free_value;
|
|
|
|
FvalueFromUnparsed val_from_unparsed;
|
|
|
|
FvalueFromString val_from_string;
|
|
|
|
FvalueToStringRepr val_to_string_repr;
|
|
|
|
FvalueStringReprLen len_string_repr;
|
|
|
|
|
|
|
|
/* could be union */
|
|
|
|
FvalueSetFunc set_value;
|
2007-01-18 11:02:26 +00:00
|
|
|
FvalueSetUnsignedIntegerFunc set_value_uinteger;
|
|
|
|
FvalueSetSignedIntegerFunc set_value_sinteger;
|
2004-08-22 00:31:58 +00:00
|
|
|
FvalueSetInteger64Func set_value_integer64;
|
2003-11-25 13:20:36 +00:00
|
|
|
FvalueSetFloatingFunc set_value_floating;
|
|
|
|
|
|
|
|
/* could be union */
|
|
|
|
FvalueGetFunc get_value;
|
2007-01-18 11:02:26 +00:00
|
|
|
FvalueGetUnsignedIntegerFunc get_value_uinteger;
|
|
|
|
FvalueGetSignedIntegerFunc get_value_sinteger;
|
2004-08-22 00:31:58 +00:00
|
|
|
FvalueGetInteger64Func get_value_integer64;
|
2003-11-25 13:20:36 +00:00
|
|
|
FvalueGetFloatingFunc get_value_floating;
|
|
|
|
|
|
|
|
FvalueCmp cmp_eq;
|
|
|
|
FvalueCmp cmp_ne;
|
|
|
|
FvalueCmp cmp_gt;
|
|
|
|
FvalueCmp cmp_ge;
|
|
|
|
FvalueCmp cmp_lt;
|
|
|
|
FvalueCmp cmp_le;
|
2004-02-27 12:00:32 +00:00
|
|
|
FvalueCmp cmp_bitwise_and;
|
2003-11-25 13:20:36 +00:00
|
|
|
FvalueCmp cmp_contains;
|
2003-12-06 16:35:20 +00:00
|
|
|
FvalueCmp cmp_matches;
|
2003-11-25 13:20:36 +00:00
|
|
|
|
|
|
|
FvalueLen len;
|
|
|
|
FvalueSlice slice;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_t*
|
|
|
|
fvalue_new(ftenum_t ftype);
|
|
|
|
|
2003-12-02 21:15:49 +00:00
|
|
|
void
|
|
|
|
fvalue_init(fvalue_t *fv, ftenum_t ftype);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2006-12-22 09:01:12 +00:00
|
|
|
/* Define type needed for the fvalue_t free list. */
|
|
|
|
SLAB_ITEM_TYPE_DEFINE(fvalue_t)
|
|
|
|
|
|
|
|
/* Free all memory used by an fvalue_t. With MSVC and a
|
|
|
|
* libwireshark.dll, we need a special declaration.
|
|
|
|
*/
|
|
|
|
WS_VAR_IMPORT SLAB_FREE_LIST_DECLARE(fvalue_t)
|
|
|
|
|
|
|
|
|
|
|
|
#define FVALUE_CLEANUP(fv) \
|
|
|
|
{ \
|
|
|
|
register FvalueFreeFunc free_value; \
|
|
|
|
free_value = (fv)->ftype->free_value; \
|
|
|
|
if (free_value) { \
|
|
|
|
free_value((fv)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FVALUE_FREE(fv) \
|
|
|
|
{ \
|
|
|
|
FVALUE_CLEANUP(fv) \
|
|
|
|
SLAB_FREE(fv, fvalue_t); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-25 03:44:05 +00:00
|
|
|
fvalue_t*
|
2003-08-27 15:23:11 +00:00
|
|
|
fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogFunc logfunc);
|
2003-07-25 03:44:05 +00:00
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_t*
|
2003-08-27 15:23:11 +00:00
|
|
|
fvalue_from_string(ftenum_t ftype, char *s, LogFunc logfunc);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2003-06-11 21:24:54 +00:00
|
|
|
/* Returns the length of the string required to hold the
|
|
|
|
* string representation of the the field value.
|
2008-11-11 13:32:51 +00:00
|
|
|
*
|
|
|
|
* Returns -1 if the string cannot be represented in the given rtype.
|
|
|
|
*
|
2003-06-11 21:24:54 +00:00
|
|
|
* The length DOES NOT include the terminating NUL. */
|
2003-02-08 04:22:37 +00:00
|
|
|
int
|
2003-06-11 21:24:54 +00:00
|
|
|
fvalue_string_repr_len(fvalue_t *fv, ftrepr_t rtype);
|
|
|
|
|
|
|
|
/* Creates the string representation of the field value.
|
|
|
|
* If given non-NULL 'buf', the string is written at the memory
|
|
|
|
* location pointed to by 'buf'. If 'buf' is NULL, new memory
|
|
|
|
* is malloc'ed and the string representation is written there.
|
|
|
|
* The pointer to the beginning of the string representation is
|
|
|
|
* returned. If 'buf' was NULL, this points to the newly-allocated
|
|
|
|
* memory. if 'buf' was non-NULL, then the return value will be
|
2008-11-11 13:32:51 +00:00
|
|
|
* 'buf'.
|
|
|
|
*
|
|
|
|
* Returns NULL if the string cannot be represented in the given rtype.*/
|
2004-12-11 00:13:27 +00:00
|
|
|
extern char *
|
2003-06-11 21:24:54 +00:00
|
|
|
fvalue_to_string_repr(fvalue_t *fv, ftrepr_t rtype, char *buf);
|
2003-02-08 04:22:37 +00:00
|
|
|
|
2006-05-02 14:26:17 +00:00
|
|
|
ftype_t*
|
|
|
|
fvalue_ftype(fvalue_t *fv);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
const char*
|
|
|
|
fvalue_type_name(fvalue_t *fv);
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied);
|
|
|
|
|
|
|
|
void
|
2007-01-18 11:02:26 +00:00
|
|
|
fvalue_set_uinteger(fvalue_t *fv, guint32 value);
|
|
|
|
|
|
|
|
void
|
|
|
|
fvalue_set_sinteger(fvalue_t *fv, gint32 value);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
void
|
|
|
|
fvalue_set_integer64(fvalue_t *fv, guint64 value);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
void
|
|
|
|
fvalue_set_floating(fvalue_t *fv, gdouble value);
|
|
|
|
|
|
|
|
gpointer
|
|
|
|
fvalue_get(fvalue_t *fv);
|
|
|
|
|
2004-12-11 00:13:27 +00:00
|
|
|
extern guint32
|
2007-01-18 11:02:26 +00:00
|
|
|
fvalue_get_uinteger(fvalue_t *fv);
|
|
|
|
|
|
|
|
extern gint32
|
|
|
|
fvalue_get_sinteger(fvalue_t *fv);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
2004-08-22 00:31:58 +00:00
|
|
|
guint64
|
|
|
|
fvalue_get_integer64(fvalue_t *fv);
|
|
|
|
|
2004-12-11 00:13:27 +00:00
|
|
|
extern double
|
2001-02-01 20:21:25 +00:00
|
|
|
fvalue_get_floating(fvalue_t *fv);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_eq(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_ne(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_gt(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_ge(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_lt(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
fvalue_le(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
2004-02-27 12:00:32 +00:00
|
|
|
gboolean
|
|
|
|
fvalue_bitwise_and(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
2003-08-27 15:23:11 +00:00
|
|
|
gboolean
|
|
|
|
fvalue_contains(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
2003-12-06 16:35:20 +00:00
|
|
|
gboolean
|
|
|
|
fvalue_matches(fvalue_t *a, fvalue_t *b);
|
|
|
|
|
2001-02-01 20:21:25 +00:00
|
|
|
guint
|
|
|
|
fvalue_length(fvalue_t *fv);
|
|
|
|
|
|
|
|
fvalue_t*
|
2004-10-01 12:31:52 +00:00
|
|
|
fvalue_slice(fvalue_t *fv, drange *dr);
|
2001-02-01 20:21:25 +00:00
|
|
|
|
|
|
|
#endif /* ftypes.h */
|